summaryrefslogtreecommitdiffstats
path: root/include/utils.h
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2015-02-13 18:01:02 +0100
committerPablo Neira Ayuso <pablo@netfilter.org>2015-02-17 19:25:11 +0100
commit26c945057d742fc4b0f4dfdc07849074cb9264c1 (patch)
tree20facafe81106096f8ee1ca954fe0e59b8e8c664 /include/utils.h
parent007e93ea118436eb40a2e39d6ae185c14b74ecf1 (diff)
src: split internal.h is smaller files
The internal.h file started being a small file with private definitions. Its size has been increasing over time more and more, so let's split this in small header files that map to the corresponding class where the functions belong to. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'include/utils.h')
-rw-r--r--include/utils.h83
1 files changed, 83 insertions, 0 deletions
diff --git a/include/utils.h b/include/utils.h
new file mode 100644
index 0000000..1801108
--- /dev/null
+++ b/include/utils.h
@@ -0,0 +1,83 @@
+#ifndef LIBNFTNL_UTILS_H
+#define LIBNFTNL_UTILS_H 1
+
+#include <stdio.h>
+#include <stdint.h>
+#include <string.h>
+#include <stdlib.h>
+#include <libnftnl/common.h>
+
+#include "config.h"
+#ifdef HAVE_VISIBILITY_HIDDEN
+# define __visible __attribute__((visibility("default")))
+# define EXPORT_SYMBOL(x) typeof(x) (x) __visible
+#else
+# define EXPORT_SYMBOL
+#endif
+
+#define __init __attribute__((constructor))
+#define __noreturn __attribute__((__noreturn__))
+
+#define xfree(ptr) free((void *)ptr);
+
+#define div_round_up(n, d) (((n) + (d) - 1) / (d))
+
+void __noreturn __abi_breakage(const char *file, int line, const char *reason);
+
+#define abi_breakage() \
+ __abi_breakage(__FILE__, __LINE__, strerror(errno));
+
+void __nft_assert_fail(uint16_t attr, const char *filename, int line);
+
+#define nft_assert(val, attr, expr) \
+ ((!val || expr) \
+ ? (void)0 \
+ : __nft_assert_fail(attr, __FILE__, __LINE__))
+
+#define nft_assert_validate(data, _validate_array, _attr, _data_len) \
+({ \
+ if (!data) \
+ __nft_assert_fail(attr, __FILE__, __LINE__); \
+ if (_validate_array[_attr]) \
+ nft_assert(data, attr, _validate_array[_attr] == _data_len); \
+})
+
+#define SNPRINTF_BUFFER_SIZE(ret, size, len, offset) \
+ if (ret < 0) \
+ return ret; \
+ offset += ret; \
+ if (ret > len) \
+ ret = len; \
+ size += ret; \
+ len -= ret;
+
+const char *nft_family2str(uint32_t family);
+int nft_str2family(const char *family);
+
+enum nft_type {
+ NFT_TYPE_U8,
+ NFT_TYPE_U16,
+ NFT_TYPE_U32,
+ NFT_TYPE_U64,
+ NFT_TYPE_S8,
+ NFT_TYPE_S16,
+ NFT_TYPE_S32,
+ NFT_TYPE_S64,
+};
+
+int nft_strtoi(const char *string, int base, void *number, enum nft_type type);
+int nft_get_value(enum nft_type type, void *val, void *out);
+
+const char *nft_verdict2str(uint32_t verdict);
+int nft_str2verdict(const char *verdict, int *verdict_num);
+
+const char *nft_cmd2tag(enum nft_cmd_type cmd);
+uint32_t nft_str2cmd(const char *cmd);
+
+enum nft_cmd_type nft_flag2cmd(uint32_t flags);
+
+int nft_fprintf(FILE *fp, void *obj, uint32_t cmd, uint32_t type,
+ uint32_t flags, int (*snprintf_cb)(char *buf, size_t bufsiz,
+ void *obj, uint32_t cmd, uint32_t type, uint32_t flags));
+
+#endif