src: split internal.h is smaller files
Pablo Neira Ayuso
maintainerPATCH 1/1 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 with more and more definitions, 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 <[email protected]>
--- include/Makefile.am | 15 ++- include/common.h | 32 +++++++ include/data_reg.h | 31 +++++++ include/expr.h | 13 +++ include/expr_ops.h | 34 +++++++ include/internal.h | 18 ++++ include/json.h | 58 ++++++++++++ include/set.h | 32 +++++++ include/set_elem.h | 14 +++ include/utils.h | 83 +++++++++++++++++ include/xml.h | 58 ++++++++++++ src/Makefile.am | 2 - src/common.c | 1 + src/expr.c | 3 - src/expr/bitwise.c | 3 - src/expr/byteorder.c | 3 - src/expr/cmp.c | 3 - src/expr/counter.c | 2 - src/expr/ct.c | 2 - src/expr/data_reg.c | 16 +--- src/expr/data_reg.h | 38 -------- src/expr/exthdr.c | 3 - src/expr/immediate.c | 3 - src/expr/limit.c | 2 - src/expr/log.c | 2 - src/expr/lookup.c | 3 - src/expr/masq.c | 2 - src/expr/match.c | 3 - src/expr/meta.c | 2 - src/expr/nat.c | 2 - src/expr/payload.c | 3 - src/expr/queue.c | 2 - src/expr/redir.c | 2 - src/expr/reject.c | 2 - src/expr/target.c | 3 - src/expr_ops.h | 43 --------- src/internal.h | 248 -------------------------------------------------- src/mxml.c | 2 +- src/rule.c | 3 - src/set.c | 3 - src/set_elem.c | 3 - src/utils.c | 3 +- 42 files changed, 392 insertions(+), 408 deletions(-) create mode 100644 include/common.h create mode 100644 include/data_reg.h create mode 100644 include/expr.h create mode 100644 include/expr_ops.h create mode 100644 include/internal.h create mode 100644 include/json.h create mode 100644 include/set.h create mode 100644 include/set_elem.h create mode 100644 include/utils.h create mode 100644 include/xml.h delete mode 100644 src/expr/data_reg.h delete mode 100644 src/expr_ops.h delete mode 100644 src/internal.h
include/Makefile.am +13 -2
@@ -1,4 +1,15 @@ SUBDIRS = libnftnl linux -noinst_HEADERS = linux_list.h \ - buffer.h +noinst_HEADERS = internal.h \ + linux_list.h \ + buffer.h \ + data_reg.h \ + expr_ops.h \ + linux_list.h \ + set.h \ + xml.h \ + common.h \ + expr.h \ + json.h \ + set_elem.h \ + utils.h
include/common.h new file +32 -0
@@ -0,0 +1,32 @@ +#ifndef _LIBNFTNL_COMMON_INTERNAL_H +#define _LIBNFTNL_COMMON_INTERNAL_H + +#define BASE_DEC 10 +#define BASE_HEX 16 + +#define NFT_SNPRINTF_BUFSIZ 4096 + +struct nft_parse_err { +int line; +int column; +int error; +const char *node_name; +}; + +enum nft_parse_input { +NFT_PARSE_BUFFER , +NFT_PARSE_FILE , +}; + +#include <stdio.h> + +int nft_cmd_header_snprintf (char *buf,size_t bufsize,uint32_t cmd, +uint32_t format,uint32_t flags); +int nft_cmd_header_fprintf (FILE *fp,uint32_t cmd,uint32_t format, +uint32_t flags); +int nft_cmd_footer_snprintf (char *buf,size_t bufsize,uint32_t cmd, +uint32_t format,uint32_t flags); +int nft_cmd_footer_fprintf (FILE *fp,uint32_t cmd,uint32_t format, +uint32_t flags); + +#endif
include/data_reg.h new file +31 -0
@@ -0,0 +1,31 @@ +#ifndef _DATA_H_ +#define _DATA_H_ + +#include <stdint.h> +#include <unistd.h> + +enum { +DATA_NONE , +DATA_VALUE , +DATA_VERDICT , +DATA_CHAIN , +}; + +union nft_data_reg { +struct { +uint32_t val[4 ]; +uint32_t len; + }; +struct { +int verdict; +const char *chain; + }; +}; + +int nft_data_reg_snprintf (char *buf,size_t size,union nft_data_reg *reg, +uint32_t output_format,uint32_t flags,int reg_type); +struct nlattr ; + +int nft_parse_data (union nft_data_reg *data,struct nlattr *attr,int *type); + +#endif
include/expr.h new file +13 -0
@@ -0,0 +1,13 @@ +#ifndef _LIBNFTNL_EXPR_INTERNAL_H_ +#define _LIBNFTNL_EXPR_INTERNAL_H_ + +struct expr_ops ; + +struct nft_rule_expr { +struct list_head head; +uint32_t flags; +struct expr_ops *ops; +uint8_t data[]; +}; + +#endif
include/expr_ops.h new file +34 -0
@@ -0,0 +1,34 @@ +#ifndef _EXPR_OPS_H_ +#define _EXPR_OPS_H_ + +#include <stdint.h> +#include "internal.h" + +struct nlattr ; +struct nlmsghdr ; +struct nft_rule_expr ; + +struct expr_ops { +struct list_head head; + +const char *name; +uint32_t alloc_len; +int max_attr; +void (*free)(struct nft_rule_expr *e); +int (*set)(struct nft_rule_expr *e,uint16_t type,const void *data,uint32_t data_len); +const void *(*get)(const struct nft_rule_expr *e,uint16_t type,uint32_t *data_len); +int (*parse)(struct nft_rule_expr *e,struct nlattr *attr); +void (*build)(struct nlmsghdr *nlh,struct nft_rule_expr *e); +int (*snprintf)(char *buf,size_t len,uint32_t type,uint32_t flags,struct nft_rule_expr *e); +int (*xml_parse)(struct nft_rule_expr *e,mxml_node_t *tree, +struct nft_parse_err *err); +int (*json_parse)(struct nft_rule_expr *e,json_t *data, +struct nft_parse_err *err); +}; + +void nft_expr_ops_register (struct expr_ops *ops); +struct expr_ops *nft_expr_ops_lookup (const char *name); + +#define nft_expr_data (ops) (void *)ops->data + +#endif
include/internal.h new file +18 -0
@@ -0,0 +1,18 @@ +#ifndef _LIBNFTNL_INTERNAL_H_ +#define _LIBNFTNL_INTERNAL_H_ + +/* The headers below are NOT exposed as part of the API. */ +#include "data_reg.h" +#include "linux_list.h" +#include "utils.h" +#include "common.h" +#include "xml.h" +#include "json.h" +#include "linux_list.h" +#include "set.h" +#include "set_elem.h" +#include "expr.h" +#include "expr_ops.h" +#include "buffer.h" + +#endif /* _LIBNFTNL_INTERNAL_H_ */
include/json.h new file +58 -0
58 lines not on this page · raw message
include/set.h new file +32 -0
@@ -0,0 +1,32 @@ +#ifndef _LIBNFTNL_SET_INTERNAL_H_ +#define _LIBNFTNL_SET_INTERNAL_H_ + +#include <linux/netfilter/nf_tables.h> + +struct nft_set { +struct list_head head; + +uint32_t family; +uint32_t set_flags; +const char *table; +const char *name; +uint32_t key_type; +uint32_t key_len; +uint32_t data_type; +uint32_t data_len; +uint32_t id; +enum nft_set_policies policy; +struct { +uint32_t size; + } desc; +struct list_head element_list; + +uint32_t flags; +}; + +struct nft_set_list ; +struct nft_rule_expr ; +int nft_set_lookup_id (struct nft_rule_expr *e,struct nft_set_list *set_list, +uint32_t *set_id); + +#endif
include/set_elem.h new file +14 -0
@@ -0,0 +1,14 @@ +#ifndef _LIBNFTNL_SET_ELEM_INTERNAL_H_ +#define _LIBNFTNL_SET_ELEM_INTERNAL_H_ + +#include <data_reg.h> + +struct nft_set_elem { +struct list_head head; +uint32_t set_elem_flags; +union nft_data_reg key; +union nft_data_reg data; +uint32_t flags; +}; + +#endif
include/utils.h new file +83 -0
83 lines not on this page · raw message
include/xml.h new file +58 -0
58 lines not on this page · raw message
src/Makefile.am +0 -2
@@ -39,7 +39,5 @@ libnftnl_la_SOURCES = utils.c \ expr/target.c \ expr/masq.c \ expr/redir.c \ - expr/data_reg.h \ libnftnl.map \ - expr_ops.h \ internal.h
src/common.c +1 -0
@@ -12,6 +12,7 @@#include <time.h> #include <linux/netlink.h> #include <linux/netfilter/nfnetlink.h> +#include <linux/netfilter/nf_tables.h> #include <libmnl/libmnl.h> #include <libnftnl/common.h>
src/expr.c +0 -3
@@ -9,7 +9,6 @@* This code has been sponsored by Sophos Astaro <http://www.sophos.com> */ #include "internal.h" -#include "expr_ops.h" #include <time.h> #include <endian.h>
@@ -24,8 +23,6 @@#include <libnftnl/expr.h> -#include "linux_list.h" -struct nft_rule_expr *nft_rule_expr_alloc (const char *name) {struct nft_rule_expr *expr;
src/expr/bitwise.c +0 -3
@@ -20,9 +20,6 @@#include <linux/netfilter/nf_tables.h> #include <libnftnl/expr.h> #include <libnftnl/rule.h> -#include "data_reg.h" -#include "expr_ops.h" -#include <buffer.h> struct nft_expr_bitwise {enum nft_registers sreg;
src/expr/byteorder.c +0 -3
@@ -20,9 +20,6 @@#include <linux/netfilter/nf_tables.h> #include <libnftnl/expr.h> #include <libnftnl/rule.h> -#include "data_reg.h" -#include "expr_ops.h" -#include <buffer.h> struct nft_expr_byteorder {enum nft_registers sreg;
src/expr/cmp.c +0 -3
@@ -21,9 +21,6 @@#include <linux/netfilter/nf_tables.h> #include <libnftnl/expr.h> #include <libnftnl/rule.h> -#include "expr_ops.h" -#include "data_reg.h" -#include <buffer.h> struct nft_expr_cmp {union nft_data_reg data;
src/expr/counter.c +0 -2
@@ -21,8 +21,6 @@#include <libmnl/libmnl.h> #include <libnftnl/expr.h> #include <libnftnl/rule.h> -#include "expr_ops.h" -#include <buffer.h> struct nft_expr_counter {uint64_t pkts;
src/expr/ct.c +0 -2
@@ -20,8 +20,6 @@#include <libmnl/libmnl.h> #include <libnftnl/expr.h> #include <libnftnl/rule.h> -#include "expr_ops.h" -#include <buffer.h> struct nft_expr_ct {enum nft_ct_keys key;
src/expr/data_reg.c +2 -14
@@ -22,8 +22,6 @@#include <linux/netfilter/nf_tables.h> #include <libnftnl/expr.h> #include <libnftnl/rule.h> -#include "expr_ops.h" -#include "data_reg.h" #include "internal.h" #ifdef JSON_PARSING
@@ -77,12 +75,10 @@ static int nft_data_reg_value_json_parse(union nft_data_reg *reg, json_t *data,return DATA_VALUE ; } -#endif int nft_data_reg_json_parse (union nft_data_reg *reg,json_t *data,struct nft_parse_err *err) { -#ifdef JSON_PARSING const char *type;
@@ -97,11 +93,8 @@ int nft_data_reg_json_parse(union nft_data_reg *reg, json_t *data,return nft_data_reg_verdict_json_parse (reg, data, err);return DATA_NONE ; -#else - errno =EOPNOTSUPP ; -return -1 ; -#endif } +#endif #ifdef XML_PARSING static int nft_data_reg_verdict_xml_parse(union nft_data_reg *reg,
@@ -160,12 +153,10 @@ static int nft_data_reg_value_xml_parse(union nft_data_reg *reg,return DATA_VALUE ; } -#endif int nft_data_reg_xml_parse (union nft_data_reg *reg,mxml_node_t *tree,struct nft_parse_err *err) { -#ifdef XML_PARSING const char *type;mxml_node_t *node;
@@ -190,11 +181,8 @@ err: err->node_name ="reg" ; err->error =NFT_PARSE_EMISSINGNODE ;return DATA_NONE ; -#else - errno =EOPNOTSUPP ; -return -1 ; -#endif } +#endif static int nft_data_reg_value_snprintf_json(char *buf, size_t size,
src/expr/data_reg.h deleted +0 -38
@@ -1,38 +0,0 @@ -#ifndef _DATA_H_ -#define _DATA_H_ - -enum { -DATA_NONE , -DATA_VALUE , -DATA_VERDICT , -DATA_CHAIN , -}; - -union nft_data_reg { -struct { -uint32_t val[4 ]; -uint32_t len; - }; -struct { -int verdict; -const char *chain; - }; -}; - -#ifndef JSON_PARSING -#define json_t void -#endif - -#ifndef XML_PARSING -#define mxml_node_t void -#endif - -int nft_data_reg_snprintf (char *buf,size_t size,union nft_data_reg *reg, -uint32_t output_format,uint32_t flags,int reg_type); -int nft_data_reg_xml_parse (union nft_data_reg *reg,mxml_node_t *tree, -struct nft_parse_err *err); -int nft_parse_data (union nft_data_reg *data,struct nlattr *attr,int *type); -int nft_data_reg_json_parse (union nft_data_reg *reg,json_t *data, -struct nft_parse_err *err); - -#endif
src/expr/exthdr.c +0 -3
@@ -24,9 +24,6 @@#include <libnftnl/expr.h> #include <libnftnl/rule.h> -#include "expr_ops.h" -#include <buffer.h> -#ifndef IPPROTO_MH #define IPPROTO_MH 135#endif
src/expr/immediate.c +0 -3
@@ -19,9 +19,6 @@#include <linux/netfilter/nf_tables.h> #include <libnftnl/expr.h> #include <libnftnl/rule.h> -#include "expr_ops.h" -#include "data_reg.h" -#include <buffer.h> struct nft_expr_immediate {union nft_data_reg data;
src/expr/limit.c +0 -2
@@ -21,8 +21,6 @@#include <libmnl/libmnl.h> #include <libnftnl/expr.h> #include <libnftnl/rule.h> -#include "expr_ops.h" -#include <buffer.h> struct nft_expr_limit {uint64_t rate;
src/expr/log.c +0 -2
@@ -20,8 +20,6 @@#include <libmnl/libmnl.h> #include <libnftnl/expr.h> #include <libnftnl/rule.h> -#include "expr_ops.h" -#include <buffer.h> struct nft_expr_log {uint32_t snaplen;
src/expr/lookup.c +0 -3
@@ -20,9 +20,6 @@#include <linux/netfilter/nf_tables.h> #include <libnftnl/rule.h> #include <libnftnl/expr.h> -#include "data_reg.h" -#include "expr_ops.h" -#include <buffer.h> #ifndef IFNAMSIZ #define IFNAMSIZ 16
src/expr/masq.c +0 -2
@@ -19,8 +19,6 @@#include <libmnl/libmnl.h> #include <libnftnl/expr.h> #include <libnftnl/rule.h> -#include "expr_ops.h" -#include <buffer.h> struct nft_expr_masq {uint32_t flags;
src/expr/match.c +0 -3
@@ -24,9 +24,6 @@#include <libnftnl/expr.h> #include <libnftnl/rule.h> -#include "expr_ops.h" -#include <buffer.h> -/* From include/linux/netfilter/x_tables.h */ #define XT_EXTENSION_MAXNAMELEN 29
src/expr/meta.c +0 -2
@@ -20,8 +20,6 @@#include <libmnl/libmnl.h> #include <libnftnl/expr.h> #include <libnftnl/rule.h> -#include "expr_ops.h" -#include <buffer.h> #ifndef NFT_META_MAX #define NFT_META_MAX (NFT_META_CGROUP + 1)
src/expr/nat.c +0 -2
@@ -23,8 +23,6 @@#include <linux/netfilter/nf_tables.h> #include <libnftnl/expr.h> #include <libnftnl/rule.h> -#include "expr_ops.h" -#include <buffer.h> struct nft_expr_nat {enum nft_registers sreg_addr_min;
src/expr/payload.c +0 -3
@@ -24,9 +24,6 @@#include <libnftnl/expr.h> #include <libnftnl/rule.h> -#include "expr_ops.h" -#include <buffer.h> -struct nft_expr_payload {enum nft_registers dreg;enum nft_payload_bases base;
src/expr/queue.c +0 -2
@@ -19,8 +19,6 @@#include <libmnl/libmnl.h> #include <libnftnl/expr.h> #include <libnftnl/rule.h> -#include "expr_ops.h" -#include <buffer.h> struct nft_expr_queue {uint16_t queuenum;
src/expr/redir.c +0 -2
@@ -19,8 +19,6 @@#include <libmnl/libmnl.h> #include <libnftnl/expr.h> #include <libnftnl/rule.h> -#include "expr_ops.h" -#include <buffer.h> struct nft_expr_redir {enum nft_registers sreg_proto_min;
src/expr/reject.c +0 -2
@@ -20,8 +20,6 @@#include <libmnl/libmnl.h> #include <libnftnl/expr.h> #include <libnftnl/rule.h> -#include "expr_ops.h" -#include <buffer.h> struct nft_expr_reject {uint32_t type;
src/expr/target.c +0 -3
@@ -24,9 +24,6 @@#include <libnftnl/expr.h> #include <libnftnl/rule.h> -#include "expr_ops.h" -#include <buffer.h> -/* From include/linux/netfilter/x_tables.h */ #define XT_EXTENSION_MAXNAMELEN 29
src/expr_ops.h deleted +0 -43
43 lines not on this page · raw message
src/internal.h deleted +0 -248
248 lines not on this page · raw message
src/mxml.c +1 -1
@@ -10,7 +10,7 @@* This code has been sponsored by Sophos Astaro <http://www.sophos.com> */ #include "internal.h" -#include "expr_ops.h" +#include <stdint.h> #include <limits.h>
src/rule.c +0 -3
@@ -29,9 +29,6 @@#include <libnftnl/set.h> #include <libnftnl/expr.h> -#include "linux_list.h" -#include "expr_ops.h" -struct nft_rule {struct list_head head;
src/set.c +0 -3
@@ -26,9 +26,6 @@#include <libnftnl/set.h> #include <libnftnl/expr.h> -#include "linux_list.h" -#include "expr/data_reg.h" -struct nft_set *nft_set_alloc (void ) {struct nft_set *s;
src/set_elem.c +0 -3
@@ -25,9 +25,6 @@#include <libnftnl/set.h> #include <libnftnl/rule.h> -#include "linux_list.h" -#include "expr/data_reg.h" -struct nft_set_elem *nft_set_elem_alloc (void ) {struct nft_set_elem *s;
src/utils.c +2 -1
@@ -16,7 +16,8 @@#include <arpa/inet.h> #include <errno.h> #include <inttypes.h> -#include <buffer.h> + +#include <libnftnl/common.h> #include <linux/netfilter.h> #include <linux/netfilter/nf_tables.h>
Signature · 1 line
1.7.10.4