include: Remove datatype_register(), __init and __exit macros.
cover include: Remove datatype_register(), __init and __exit macros.
This patchset removes datatype_register() function, __init and __exit macro definitions.
Varsha Rao (3):
include: Remove datatype_register().
include: Remove __init macro definition.
include: Remove __exit macro definition.
include/ct.h | 3 +++ include/datatype.h | 1 - include/exthdr.h | 1 + include/fib.h | 2 ++ include/meta.h | 7 ++++++- include/nftables.h | 18 ++++++++++++++++++ include/proto.h | 8 ++++++++ include/rt.h | 1 + include/utils.h | 2 -- src/ct.c | 17 +++++------------ src/datatype.c | 29 +++++++++++++++++++++-------- src/exthdr.c | 7 +------ src/fib.c | 7 +------ src/gmputil.c | 2 +- src/main.c | 26 ++++++++++++++++++++++++++ src/meta.c | 52 +++++++++------------------------------------------- src/netlink.c | 4 ++-- src/proto.c | 24 ++++++------------------ src/rt.c | 11 +++-------- src/xt.c | 2 +- 20 files changed, 115 insertions(+), 109 deletions(-)
Signature · 1 line
2.9.4
PATCH 1/3 include: Remove datatype_register().
Remove datatype_register() function and its calling __init functions. Add arguments of datatype_register() function to datatype array.
--- include/ct.h | 3 +++ include/datatype.h | 1 - include/exthdr.h | 1 + include/fib.h | 2 ++ include/meta.h | 7 ++++++- include/proto.h | 8 ++++++++ include/rt.h | 1 + src/ct.c | 13 +++---------- src/datatype.c | 25 +++++++++++++++++++------ src/exthdr.c | 7 +------ src/fib.c | 7 +------ src/meta.c | 44 +++++--------------------------------------- src/proto.c | 24 ++++++------------------ src/rt.c | 7 +------ 14 files changed, 57 insertions(+), 93 deletions(-)
include/ct.h +3 -0
@@ -23,6 +23,9 @@ struct ct_template { .len = (__len), \ } +extern const struct datatype ct_dir_type; +extern const struct datatype ct_state_type; +extern const struct datatype ct_status_type;extern struct expr *ct_expr_alloc (const struct location *loc,enum nft_ct_keys key,int8_t direction);extern void ct_expr_update_type (struct proto_ctx *ctx,struct expr *expr);
include/datatype.h +0 -1
@@ -152,7 +152,6 @@ struct datatype {const struct symbol_table *sym_tbl; }; -extern void datatype_register (const struct datatype *dtype);extern const struct datatype *datatype_lookup (enum datatypes type);extern const struct datatype *datatype_lookup_byname (const char *name);
include/exthdr.h +1 -0
@@ -89,5 +89,6 @@ extern const struct exthdr_desc exthdr_rt2;extern const struct exthdr_desc exthdr_frag;extern const struct exthdr_desc exthdr_dst;extern const struct exthdr_desc exthdr_mh; +extern const struct datatype mh_type_type;#endif /* NFTABLES_EXTHDR_H */
include/fib.h +2 -0
@@ -4,4 +4,6 @@extern struct expr *fib_expr_alloc (const struct location *loc,unsigned int flags,unsigned int result); +extern const struct datatype fib_addr_type; +#endif /* NFTABLES_FIB_H */
include/meta.h +6 -1
@@ -28,7 +28,12 @@ extern struct expr *meta_expr_alloc(const struct location *loc,struct stmt *meta_stmt_meta_iiftype (const struct location *loc,uint16_t type); -const struct datatype ifindex_type; +extern const struct datatype ifindex_type; +extern const struct datatype tchandle_type; +extern const struct datatype gid_type; +extern const struct datatype uid_type; +extern const struct datatype devgroup_type; +extern const struct datatype pkttype_type; struct error_record *meta_key_parse(const struct location *loc, const char *name,
include/proto.h +8 -0
@@ -322,4 +322,12 @@ extern const struct proto_desc proto_netdev;extern const struct proto_desc proto_unknown;extern const struct proto_hdr_template proto_unknown_template; +extern const struct datatype icmp_type_type; +extern const struct datatype tcp_flag_type; +extern const struct datatype dccp_pkttype_type; +extern const struct datatype arpop_type; +extern const struct datatype icmp6_type_type; +extern const struct datatype dscp_type; +extern const struct datatype ecn_type; +#endif /* NFTABLES_PROTO_H */
include/rt.h +1 -0
@@ -26,6 +26,7 @@ struct rt_template { .invalid = (__invalid), \ } +extern const struct datatype realm_type;extern struct expr *rt_expr_alloc (const struct location *loc,enum nft_rt_keys key,bool invalid);extern void rt_expr_update_type (struct proto_ctx *ctx,struct expr *expr);
src/ct.c +3 -10
@@ -44,7 +44,7 @@ static const struct symbol_table ct_state_tbl = { } }; -static const struct datatype ct_state_type = { +const struct datatype ct_state_type = { .type =TYPE_CT_STATE , .name ="ct_state" , .desc ="conntrack state" ,
@@ -63,7 +63,7 @@ static const struct symbol_table ct_dir_tbl = { } }; -static const struct datatype ct_dir_type = { +const struct datatype ct_dir_type = { .type =TYPE_CT_DIR , .name ="ct_dir" , .desc ="conntrack direction" ,
@@ -90,7 +90,7 @@ static const struct symbol_table ct_status_tbl = { }, }; -static const struct datatype ct_status_type = { +const struct datatype ct_status_type = { .type =TYPE_CT_STATUS , .name ="ct_status" , .desc ="conntrack status" ,
@@ -485,10 +485,3 @@ struct stmt *notrack_stmt_alloc(const struct location *loc) {return stmt_alloc (loc, ¬rack_stmt_ops); } - -static void __init ct_init (void ) -{ -datatype_register (&ct_state_type); -datatype_register (&ct_dir_type); -datatype_register (&ct_status_type); -}
src/datatype.c +19 -6
@@ -40,23 +40,36 @@ static const struct datatype *datatypes[TYPE_MAX + 1] = { [TYPE_IP6ADDR] = &ip6addr_type, [TYPE_ETHERADDR] = ðeraddr_type, [TYPE_ETHERTYPE] = ðertype_type, + [TYPE_ARPOP] = &arpop_type, [TYPE_INET_PROTOCOL] = &inet_protocol_type, [TYPE_INET_SERVICE] = &inet_service_type, + [TYPE_ICMP_TYPE] = &icmp_type_type, + [TYPE_TCP_FLAG] = &tcp_flag_type, + [TYPE_DCCP_PKTTYPE] = &dccp_pkttype_type, + [TYPE_MH_TYPE] = &mh_type_type, [TYPE_TIME] = &time_type, [TYPE_MARK] = &mark_type, + [TYPE_IFINDEX] = &ifindex_type, [TYPE_ARPHRD] = &arphrd_type, + [TYPE_REALM] = &realm_type, + [TYPE_CLASSID] = &tchandle_type, + [TYPE_UID] = &uid_type, + [TYPE_GID] = &gid_type, + [TYPE_CT_STATE] = &ct_state_type, + [TYPE_CT_DIR] = &ct_dir_type, + [TYPE_CT_STATUS] = &ct_status_type, + [TYPE_ICMP6_TYPE] = &icmp6_type_type, + [TYPE_PKTTYPE] = &pkttype_type, [TYPE_ICMP_CODE] = &icmp_code_type, [TYPE_ICMPV6_CODE] = &icmpv6_code_type, [TYPE_ICMPX_CODE] = &icmpx_code_type, + [TYPE_DEVGROUP] = &devgroup_type, + [TYPE_DSCP] = &dscp_type, + [TYPE_ECN] = &ecn_type, + [TYPE_FIB_ADDR] = &fib_addr_type, [TYPE_BOOLEAN] = &boolean_type, }; -void datatype_register (const struct datatype *dtype) -{ -BUILD_BUG_ON (TYPE_MAX & ~TYPE_MASK ); - datatypes[dtype->type] = dtype; -} -const struct datatype *datatype_lookup (enum datatypes type) {if (type >TYPE_MAX )
src/exthdr.c +1 -6
@@ -322,7 +322,7 @@ static const struct symbol_table mh_type_tbl = { }, }; -static const struct datatype mh_type_type = { +const struct datatype mh_type_type = { .type =TYPE_MH_TYPE , .name ="mh_type" , .desc ="Mobility Header Type" ,
@@ -343,8 +343,3 @@ const struct exthdr_desc exthdr_mh = { [MHHDR_CHECKSUM] = MH_FIELD("checksum", ip6mh_cksum, &integer_type), }, }; - -static void __init exthdr_init (void ) -{ -datatype_register (&mh_type_type); -}
src/fib.c +1 -6
@@ -42,7 +42,7 @@ static const struct symbol_table addrtype_tbl = { } }; -static const struct datatype fib_addr_type = { +const struct datatype fib_addr_type = { .type =TYPE_FIB_ADDR , .name ="fib_addrtype" , .desc ="fib address type" ,
@@ -141,8 +141,3 @@ struct expr *fib_expr_alloc(const struct location *loc,return expr; } - -static void __init fib_init (void ) -{ -datatype_register (&fib_addr_type); -}
src/meta.c +5 -39
86 lines not on this page · raw message
src/proto.c +6 -18
@@ -406,7 +406,7 @@ static const struct symbol_table tcp_flag_tbl = { }, }; -static const struct datatype tcp_flag_type = { +const struct datatype tcp_flag_type = { .type =TYPE_TCP_FLAG , .name ="tcp_flag" , .desc ="TCP flag" ,
@@ -467,7 +467,7 @@ static const struct symbol_table dccp_pkttype_tbl = { }, }; -static const struct datatype dccp_pkttype_type = { +const struct datatype dccp_pkttype_type = { .type =TYPE_DCCP_PKTTYPE , .name ="dccp_pkttype" , .desc ="DCCP packet type" ,
@@ -545,7 +545,7 @@ static const struct symbol_table dscp_type_tbl = { }, }; -static const struct datatype dscp_type = { +const struct datatype dscp_type = { .type =TYPE_DSCP , .name ="dscp" , .desc ="Differentiated Services Code Point" ,
@@ -567,7 +567,7 @@ static const struct symbol_table ecn_type_tbl = { }, }; -static const struct datatype ecn_type = { +const struct datatype ecn_type = { .type =TYPE_ECN , .name ="ecn" , .desc ="Explicit Congestion Notification" ,
@@ -662,7 +662,7 @@ static const struct symbol_table icmp6_type_tbl = { }, }; -static const struct datatype icmp6_type_type = { +const struct datatype icmp6_type_type = { .type =TYPE_ICMP6_TYPE , .name ="icmpv6_type" , .desc ="ICMPv6 type" ,
@@ -807,7 +807,7 @@ static const struct symbol_table arpop_tbl = { }, }; -static const struct datatype arpop_type = { +const struct datatype arpop_type = { .type =TYPE_ARPOP , .name ="arp_op" , .desc ="ARP operation" ,
@@ -960,15 +960,3 @@ const struct proto_desc proto_netdev = { [0] = PROTO_META_TEMPLATE("protocol", ðertype_type, NFT_META_PROTOCOL, 16), }, }; - -static void __init proto_init (void ) -{ -datatype_register (&icmp_type_type); -datatype_register (&tcp_flag_type); -datatype_register (&dccp_pkttype_type); -datatype_register (&arpop_type); -datatype_register (ðertype_type); -datatype_register (&icmp6_type_type); -datatype_register (&dscp_type); -datatype_register (&ecn_type); -}
src/rt.c +1 -6
@@ -45,7 +45,7 @@ static struct error_record *realm_type_parse(const struct expr *sym,return symbolic_constant_parse (sym, realm_tbl, res); } -static const struct datatype realm_type = { +const struct datatype realm_type = { .type =TYPE_REALM , .name ="realm" , .desc ="routing realm" ,
@@ -134,8 +134,3 @@ void rt_expr_update_type(struct proto_ctx *ctx, struct expr *expr)break ; } } - -static void __init rt_init (void ) -{ -datatype_register (&realm_type); -}
Signature · 1 line
2.9.4
Re: [PATCH nft 1/3] include: Remove datatype_register().
Quoted 2 lines · Varsha Rao
Remove
datatype_register()function and its calling__initfunctions. Add arguments ofdatatype_register()function to datatype array.
Applied, thanks Varsha.
PATCH 2/3 include: Remove __init macro definition.
In reply to Varsha RaoAdd nft_init function, which calls _init functions in main.c file. Remove __init macro definition as libnftables library will be created soon. Rename realm_table_init() function to avoid ambiguity as realm_table_rt_init() and realm_table_meta_init() in rt.c and meta.c files.
--- include/nftables.h | 9 +++++++++ include/utils.h | 1 - src/ct.c | 2 +- src/datatype.c | 2 +- src/gmputil.c | 2 +- src/main.c | 15 +++++++++++++++ src/meta.c | 4 ++-- src/netlink.c | 2 +- src/rt.c | 2 +- src/xt.c | 2 +- 10 files changed, 32 insertions(+), 9 deletions(-)
include/nftables.h +9 -0
@@ -117,5 +117,14 @@ struct parser_state;int nft_run (struct nft_ctx *nft,void *scanner,struct parser_state *state,struct list_head *msgs); +void ct_label_table_init (void ); +void mark_table_init (void ); +void gmp_init (void ); +void realm_table_rt_init (void ); +void devgroup_table_init (void ); +void netlink_open_sock (void ); +void realm_table_meta_init (void ); +void xt_init (void ); +void nft_init (void );#endif /* NFTABLES_NFTABLES_H */
include/utils.h +0 -1
@@ -32,7 +32,6 @@#define __gmp_fmtstring (x, y)#endif -#define __init __attribute__((constructor))#define __exit __attribute__((destructor))#define __must_check __attribute__((warn_unused_result))#define __noreturn __attribute__((__noreturn__))
src/ct.c +1 -1
@@ -205,7 +205,7 @@ static const struct datatype ct_label_type = { .parse = ct_label_type_parse, }; -static void __init ct_label_table_init (void ) +void ct_label_table_init (void ) { ct_label_tbl =rt_symbol_table_init (CONNLABEL_CONF ); }
src/datatype.c +1 -1
@@ -717,7 +717,7 @@ void rt_symbol_table_free(struct symbol_table *tbl) }static struct symbol_table *mark_tbl; -static void __init mark_table_init (void ) +void mark_table_init (void ) { mark_tbl =rt_symbol_table_init ("/etc/iproute2/rt_marks" ); }
src/gmputil.c +1 -1
@@ -207,7 +207,7 @@ static void *gmp_xrealloc(void *ptr, size_t old_size, size_t new_size)return xrealloc (ptr, new_size); } -static void __init gmp_init (void ) +void gmp_init (void ) {mp_set_memory_functions (xmalloc, gmp_xrealloc,NULL ); }
src/main.c +15 -0
@@ -262,6 +262,20 @@ err1:return ret; } +void nft_init (void ) +{ +mark_table_init (); +realm_table_rt_init (); +devgroup_table_init (); +realm_table_meta_init (); +ct_label_table_init (); +netlink_open_sock (); +gmp_init (); +#ifdef HAVE_LIBXTABLES +xt_init (); +#endif +} +int main (int argc,char *const *argv) {struct parser_state state;
@@ -272,6 +286,7 @@ int main(int argc, char * const *argv)bool interactive = false;int i, val, rc =NFT_EXIT_SUCCESS ; +nft_init ();while (1 ) { val =getopt_long (argc, argv,OPTSTRING , options,NULL );if (val ==-1 )
src/meta.c +2 -2
@@ -37,7 +37,7 @@#include <iface.h> static struct symbol_table *realm_tbl; -static void __init realm_table_init (void ) +void realm_table_meta_init (void ) { realm_tbl =rt_symbol_table_init ("/etc/iproute2/rt_realms" ); }
@@ -333,7 +333,7 @@ const struct datatype pkttype_type = { };static struct symbol_table *devgroup_tbl; -static void __init devgroup_table_init (void ) +void devgroup_table_init (void ) { devgroup_tbl =rt_symbol_table_init ("/etc/iproute2/group" ); }
src/netlink.c +1 -1
@@ -61,7 +61,7 @@ static struct mnl_socket *nfsock_open(void)return s; } -static void __init netlink_open_sock (void ) +void netlink_open_sock (void ) { nf_sock =nfsock_open ();fcntl (mnl_socket_get_fd (nf_sock),F_SETFL ,O_NONBLOCK );
src/rt.c +1 -1
@@ -24,7 +24,7 @@#include <rule.h> static struct symbol_table *realm_tbl; -static void __init realm_table_init (void ) +void realm_table_rt_init (void ) { realm_tbl =rt_symbol_table_init ("/etc/iproute2/rt_realms" ); }
src/xt.c +1 -1
@@ -351,7 +351,7 @@ static struct xtables_globals xt_nft_globals = { .compat_rev = nft_xt_compatible_revision, }; -static void __init xt_init (void ) +void xt_init (void ) {/* Default to IPv4, but this changes in runtime */ xtables_init_all (&xt_nft_globals,NFPROTO_IPV4 );
Signature · 1 line
2.9.4
Pablo Neira Ayuso
maintainerRe: [PATCH nft 2/3] include: Remove __init macro definition.
Quoted 25 lines · Varsha Rao
Add
nft_initfunction, which calls_initfunctions inmain.cfile. Remove__initmacro definition as libnftables library will be created soon. Renamerealm_table_init()function to avoid ambiguity asrealm_table_rt_init()andrealm_table_meta_init()inrt.candmeta.cfiles.Signed-off-by Varsha Rao <[email protected]>--- include/nftables.h | 9 +++++++++ include/utils.h | 1 - src/ct.c | 2 +- src/datatype.c | 2 +- src/gmputil.c | 2 +- src/main.c | 15 +++++++++++++++ src/meta.c | 4 ++-- src/netlink.c | 2 +- src/rt.c | 2 +- src/xt.c | 2 +- 10 files changed, 32 insertions(+), 9 deletions(-)include/nftables.h +0
-0
include/nftables.h struct parser_state; · line 125
Quoted 9 lines
include/nftables.h +6
-0@@ -117,5 +117,14 @@ struct parser_state;int nft_run (struct nft_ctx *nft,void *scanner,struct parser_state *state,struct list_head *msgs); +void ct_label_table_init (void ); +void mark_table_init (void ); +void gmp_init (void ); +void realm_table_rt_init (void ); +void devgroup_table_init (void ); +void netlink_open_sock (void );
OK, so before I apply this, I would like that we remove netlink_open_sock() from nft_init().
Could you make a patch that does the following (in steps):
1) Add a new struct mnl_socket * field to struct nft_ctx, you can name this new field as 'nf_sock'.
2) Call netlink_open_sock() from nft_netlink(), at the very beginning, so you set ctx->nf_sock.
3) Use ctx->nf_sock everywhere in src/netlink.c and src/mnl.c, so this is not global anymore.
All this in one single patch. As a result, we don't need to call netlink_open_sock() from nft_init() anymore.
PATCH 3/3 include: Remove __exit macro definition.
In reply to Varsha RaoAdd nft_exit function, which calls _exit functions in main.c file. Remove __exit macro definition as libnftables library will be created soon. Rename realm_table_exit() function to avoid ambiguity as realm_table_rt_exit() and realm_table_meta_exit() in rt.c and meta.c files.
--- include/nftables.h | 9 +++++++++ include/utils.h | 1 - src/ct.c | 2 +- src/datatype.c | 2 +- src/main.c | 11 +++++++++++ src/meta.c | 4 ++-- src/netlink.c | 2 +- src/rt.c | 2 +- 8 files changed, 26 insertions(+), 7 deletions(-)
include/nftables.h +9 -0
@@ -117,6 +117,7 @@ struct parser_state;int nft_run (struct nft_ctx *nft,void *scanner,struct parser_state *state,struct list_head *msgs); +void ct_label_table_init (void );void mark_table_init (void );void gmp_init (void );
@@ -127,4 +128,12 @@ void realm_table_meta_init(void);void xt_init (void );void nft_init (void ); +void ct_label_table_exit (void ); +void mark_table_exit (void ); +void realm_table_meta_exit (void ); +void devgroup_table_exit (void ); +void netlink_close_sock (void ); +void realm_table_rt_exit (void ); +void nft_exit (void ); +#endif /* NFTABLES_NFTABLES_H */
include/utils.h +0 -1
@@ -32,7 +32,6 @@#define __gmp_fmtstring (x, y)#endif -#define __exit __attribute__((destructor))#define __must_check __attribute__((warn_unused_result))#define __noreturn __attribute__((__noreturn__))
src/ct.c +1 -1
@@ -210,7 +210,7 @@ void ct_label_table_init(void) ct_label_tbl =rt_symbol_table_init (CONNLABEL_CONF ); } -static void __exit ct_label_table_exit(void) +void ct_label_table_exit (void ) {rt_symbol_table_free (ct_label_tbl); }
src/datatype.c +1 -1
@@ -722,7 +722,7 @@ void mark_table_init(void) mark_tbl =rt_symbol_table_init ("/etc/iproute2/rt_marks" ); } -static void __exit mark_table_exit(void) +void mark_table_exit (void ) {rt_symbol_table_free (mark_tbl); }
src/main.c +11 -0
@@ -276,6 +276,16 @@ void nft_init(void)#endif } +void nft_exit (void ) +{ +netlink_close_sock (); +ct_label_table_exit (); +realm_table_rt_exit (); +devgroup_table_exit (); +realm_table_meta_exit (); +mark_table_exit (); +} +int main (int argc,char *const *argv) {struct parser_state state;
@@ -412,6 +422,7 @@ out:xfree (buf);cache_release ();iface_cache_release (); +nft_exit ();return rc; }
src/meta.c +2 -2
@@ -42,7 +42,7 @@ void realm_table_meta_init(void) realm_tbl =rt_symbol_table_init ("/etc/iproute2/rt_realms" ); } -static void __exit realm_table_exit(void) +void realm_table_meta_exit (void ) {rt_symbol_table_free (realm_tbl); }
@@ -338,7 +338,7 @@ void devgroup_table_init(void) devgroup_tbl =rt_symbol_table_init ("/etc/iproute2/group" ); } -static void __exit devgroup_table_exit(void) +void devgroup_table_exit (void ) {rt_symbol_table_free (devgroup_tbl); }
src/netlink.c +1 -1
@@ -67,7 +67,7 @@ void netlink_open_sock(void)fcntl (mnl_socket_get_fd (nf_sock),F_SETFL ,O_NONBLOCK ); } -static void __exit netlink_close_sock(void) +void netlink_close_sock (void ) {if (nf_sock)mnl_socket_close (nf_sock);
src/rt.c +1 -1
@@ -29,7 +29,7 @@ void realm_table_rt_init(void) realm_tbl =rt_symbol_table_init ("/etc/iproute2/rt_realms" ); } -static void __exit realm_table_exit(void) +void realm_table_rt_exit (void ) {rt_symbol_table_free (realm_tbl); }
Signature · 1 line
2.9.4