netfilter: conntrack: place print_tuple in procfs part
Subsystems (5)
Pablo Neira Ayuso
maintainerPATCH 36/47 netfilter: conntrack: place print_tuple in procfs part
From: Florian Westphal <[email protected]>
CONFIG_NF_CONNTRACK_PROCFS is deprecated, no need to use a function pointer in the trackers for this. Place the printf formatting in the one place that uses it.
--- include/net/netfilter/nf_conntrack_l3proto.h | 4 -- include/net/netfilter/nf_conntrack_l4proto.h | 4 -- net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c | 8 ---- net/ipv4/netfilter/nf_conntrack_proto_icmp.c | 11 ----- net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c | 8 ---- net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c | 11 ----- net/netfilter/nf_conntrack_l3proto_generic.c | 6 --- net/netfilter/nf_conntrack_proto_dccp.c | 10 ----- net/netfilter/nf_conntrack_proto_generic.c | 7 ---- net/netfilter/nf_conntrack_proto_gre.c | 10 ----- net/netfilter/nf_conntrack_proto_sctp.c | 11 ----- net/netfilter/nf_conntrack_proto_tcp.c | 11 ----- net/netfilter/nf_conntrack_proto_udp.c | 13 ------ net/netfilter/nf_conntrack_standalone.c | 58 +++++++++++++++++++++++++- 14 files changed, 56 insertions(+), 116 deletions(-)
include/net/netfilter/nf_conntrack_l3proto.h +0 -4
@@ -37,10 +37,6 @@ struct nf_conntrack_l3proto {bool (*invert_tuple)(struct nf_conntrack_tuple *inverse,const struct nf_conntrack_tuple *orig); -/* Print out the per-protocol part of the tuple. */ -void (*print_tuple)(struct seq_file *s, -const struct nf_conntrack_tuple *); -/* * Called before tracking. * *dataoff: offset of protocol header (TCP, UDP,...) in skb
include/net/netfilter/nf_conntrack_l4proto.h +0 -4
@@ -61,10 +61,6 @@ struct nf_conntrack_l4proto {/* called by gc worker if table is full */ bool (*can_early_drop)(const struct nf_conn *ct); -/* Print out the per-protocol part of the tuple. Return like seq_* */ -void (*print_tuple)(struct seq_file *s, -const struct nf_conntrack_tuple *); -/* Print out the private part of the conntrack. */ void (*print_conntrack)(struct seq_file *s,struct nf_conn *);
net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c +0 -8
@@ -63,13 +63,6 @@ static bool ipv4_invert_tuple(struct nf_conntrack_tuple *tuple,return true; } -static void ipv4_print_tuple (struct seq_file *s, -const struct nf_conntrack_tuple *tuple) -{ -seq_printf (s,"src=%pI4 dst=%pI4 " , - &tuple->src.u3.ip, &tuple->dst.u3.ip); -} -static int ipv4_get_l4proto (const struct sk_buff *skb,unsigned int nhoff,unsigned int *dataoff,u_int8_t *protonum) {
@@ -355,7 +348,6 @@ struct nf_conntrack_l3proto nf_conntrack_l3proto_ipv4 __read_mostly = { .l3proto = PF_INET, .pkt_to_tuple = ipv4_pkt_to_tuple, .invert_tuple = ipv4_invert_tuple, - .print_tuple = ipv4_print_tuple, .get_l4proto = ipv4_get_l4proto, #if IS_ENABLED(CONFIG_NF_CT_NETLINK) .tuple_to_nlattr = ipv4_tuple_to_nlattr,
net/ipv4/netfilter/nf_conntrack_proto_icmp.c +0 -11
@@ -71,16 +71,6 @@ static bool icmp_invert_tuple(struct nf_conntrack_tuple *tuple,return true; } -/* Print out the per-protocol part of the tuple. */ -static void icmp_print_tuple (struct seq_file *s, -const struct nf_conntrack_tuple *tuple) -{ -seq_printf (s,"type=%u code=%u id=%u " , - tuple->dst.u.icmp.type, - tuple->dst.u.icmp.code, -ntohs (tuple->src.u.icmp.id)); -} -static unsigned int *icmp_get_timeouts (struct net *net) {return &icmp_pernet (net)->timeout;
@@ -364,7 +354,6 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_icmp __read_mostly = .l4proto = IPPROTO_ICMP, .pkt_to_tuple = icmp_pkt_to_tuple, .invert_tuple = icmp_invert_tuple, - .print_tuple = icmp_print_tuple, .packet = icmp_packet, .get_timeouts = icmp_get_timeouts, .new = icmp_new,
net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c +0 -8
@@ -67,13 +67,6 @@ static bool ipv6_invert_tuple(struct nf_conntrack_tuple *tuple,return true; } -static void ipv6_print_tuple (struct seq_file *s, -const struct nf_conntrack_tuple *tuple) -{ -seq_printf (s,"src=%pI6 dst=%pI6 " , - tuple->src.u3.ip6, tuple->dst.u3.ip6); -} -static int ipv6_get_l4proto (const struct sk_buff *skb,unsigned int nhoff,unsigned int *dataoff,u_int8_t *protonum) {
@@ -350,7 +343,6 @@ struct nf_conntrack_l3proto nf_conntrack_l3proto_ipv6 __read_mostly = { .l3proto = PF_INET6, .pkt_to_tuple = ipv6_pkt_to_tuple, .invert_tuple = ipv6_invert_tuple, - .print_tuple = ipv6_print_tuple, .get_l4proto = ipv6_get_l4proto, #if IS_ENABLED(CONFIG_NF_CT_NETLINK) .tuple_to_nlattr = ipv6_tuple_to_nlattr,
net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c +0 -11
@@ -84,16 +84,6 @@ static bool icmpv6_invert_tuple(struct nf_conntrack_tuple *tuple,return true; } -/* Print out the per-protocol part of the tuple. */ -static void icmpv6_print_tuple (struct seq_file *s, -const struct nf_conntrack_tuple *tuple) -{ -seq_printf (s,"type=%u code=%u id=%u " , - tuple->dst.u.icmp.type, - tuple->dst.u.icmp.code, -ntohs (tuple->src.u.icmp.id)); -} -static unsigned int *icmpv6_get_timeouts (struct net *net) {return &icmpv6_pernet (net)->timeout;
@@ -369,7 +359,6 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_icmpv6 __read_mostly = .l4proto = IPPROTO_ICMPV6, .pkt_to_tuple = icmpv6_pkt_to_tuple, .invert_tuple = icmpv6_invert_tuple, - .print_tuple = icmpv6_print_tuple, .packet = icmpv6_packet, .get_timeouts = icmpv6_get_timeouts, .new = icmpv6_new,
net/netfilter/nf_conntrack_l3proto_generic.c +0 -6
@@ -49,11 +49,6 @@ static bool generic_invert_tuple(struct nf_conntrack_tuple *tuple,return true; } -static void generic_print_tuple (struct seq_file *s, -const struct nf_conntrack_tuple *tuple) -{ -} -static int generic_get_l4proto (const struct sk_buff *skb,unsigned int nhoff,unsigned int *dataoff,u_int8_t *protonum) {
@@ -66,7 +61,6 @@ struct nf_conntrack_l3proto nf_conntrack_l3proto_generic __read_mostly = { .l3proto = PF_UNSPEC, .pkt_to_tuple = generic_pkt_to_tuple, .invert_tuple = generic_invert_tuple, - .print_tuple = generic_print_tuple, .get_l4proto = generic_get_l4proto, };EXPORT_SYMBOL_GPL (nf_conntrack_l3proto_generic);
net/netfilter/nf_conntrack_proto_dccp.c +0 -10
@@ -623,14 +623,6 @@ static bool dccp_can_early_drop(const struct nf_conn *ct)return false; } -static void dccp_print_tuple (struct seq_file *s, -const struct nf_conntrack_tuple *tuple) -{ -seq_printf (s,"sport=%hu dport=%hu " , -ntohs (tuple->src.u.dccp.port), -ntohs (tuple->dst.u.dccp.port)); -} -static void dccp_print_conntrack (struct seq_file *s,struct nf_conn *ct) {seq_printf (s,"%s " , dccp_state_names[ct->proto.dccp.state]);
@@ -887,7 +879,6 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_dccp4 __read_mostly = { .get_timeouts = dccp_get_timeouts, .error = dccp_error, .can_early_drop = dccp_can_early_drop, - .print_tuple = dccp_print_tuple, .print_conntrack = dccp_print_conntrack, #if IS_ENABLED(CONFIG_NF_CT_NETLINK) .to_nlattr = dccp_to_nlattr,
@@ -922,7 +913,6 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_dccp6 __read_mostly = { .get_timeouts = dccp_get_timeouts, .error = dccp_error, .can_early_drop = dccp_can_early_drop, - .print_tuple = dccp_print_tuple, .print_conntrack = dccp_print_conntrack, #if IS_ENABLED(CONFIG_NF_CT_NETLINK) .to_nlattr = dccp_to_nlattr,
net/netfilter/nf_conntrack_proto_generic.c +0 -7
@@ -62,12 +62,6 @@ static bool generic_invert_tuple(struct nf_conntrack_tuple *tuple,return true; } -/* Print out the per-protocol part of the tuple. */ -static void generic_print_tuple (struct seq_file *s, -const struct nf_conntrack_tuple *tuple) -{ -} -static unsigned int *generic_get_timeouts (struct net *net) {return &(generic_pernet (net)->timeout);
@@ -189,7 +183,6 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_generic __read_mostly = .l4proto = 255, .pkt_to_tuple = generic_pkt_to_tuple, .invert_tuple = generic_invert_tuple, - .print_tuple = generic_print_tuple, .packet = generic_packet, .get_timeouts = generic_get_timeouts, .new = generic_new,
net/netfilter/nf_conntrack_proto_gre.c +0 -10
@@ -224,15 +224,6 @@ static bool gre_pkt_to_tuple(const struct sk_buff *skb, unsigned int dataoff,return true; } -/* print gre part of tuple */ -static void gre_print_tuple (struct seq_file *s, -const struct nf_conntrack_tuple *tuple) -{ -seq_printf (s,"srckey=0x%x dstkey=0x%x " , -ntohs (tuple->src.u.gre.key), -ntohs (tuple->dst.u.gre.key)); -} -/* print private data for conntrack */ static void gre_print_conntrack (struct seq_file *s,struct nf_conn *ct) {
@@ -366,7 +357,6 @@ static struct nf_conntrack_l4proto nf_conntrack_l4proto_gre4 __read_mostly = { .l4proto = IPPROTO_GRE, .pkt_to_tuple = gre_pkt_to_tuple, .invert_tuple = gre_invert_tuple, - .print_tuple = gre_print_tuple, .print_conntrack = gre_print_conntrack, .get_timeouts = gre_get_timeouts, .packet = gre_packet,
net/netfilter/nf_conntrack_proto_sctp.c +0 -11
@@ -174,15 +174,6 @@ static bool sctp_invert_tuple(struct nf_conntrack_tuple *tuple,return true; } -/* Print out the per-protocol part of the tuple. */ -static void sctp_print_tuple (struct seq_file *s, -const struct nf_conntrack_tuple *tuple) -{ -seq_printf (s,"sport=%hu dport=%hu " , -ntohs (tuple->src.u.sctp.port), -ntohs (tuple->dst.u.sctp.port)); -} -/* Print out the private part of the conntrack. */ static void sctp_print_conntrack (struct seq_file *s,struct nf_conn *ct) {
@@ -793,7 +784,6 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_sctp4 __read_mostly = { .l4proto = IPPROTO_SCTP, .pkt_to_tuple = sctp_pkt_to_tuple, .invert_tuple = sctp_invert_tuple, - .print_tuple = sctp_print_tuple, .print_conntrack = sctp_print_conntrack, .packet = sctp_packet, .get_timeouts = sctp_get_timeouts,
@@ -829,7 +819,6 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_sctp6 __read_mostly = { .l4proto = IPPROTO_SCTP, .pkt_to_tuple = sctp_pkt_to_tuple, .invert_tuple = sctp_invert_tuple, - .print_tuple = sctp_print_tuple, .print_conntrack = sctp_print_conntrack, .packet = sctp_packet, .get_timeouts = sctp_get_timeouts,
net/netfilter/nf_conntrack_proto_tcp.c +0 -11
@@ -301,15 +301,6 @@ static bool tcp_invert_tuple(struct nf_conntrack_tuple *tuple,return true; } -/* Print out the per-protocol part of the tuple. */ -static void tcp_print_tuple (struct seq_file *s, -const struct nf_conntrack_tuple *tuple) -{ -seq_printf (s,"sport=%hu dport=%hu " , -ntohs (tuple->src.u.tcp.port), -ntohs (tuple->dst.u.tcp.port)); -} -/* Print out the private part of the conntrack. */ static void tcp_print_conntrack (struct seq_file *s,struct nf_conn *ct) {
@@ -1558,7 +1549,6 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_tcp4 __read_mostly = .l4proto = IPPROTO_TCP, .pkt_to_tuple = tcp_pkt_to_tuple, .invert_tuple = tcp_invert_tuple, - .print_tuple = tcp_print_tuple, .print_conntrack = tcp_print_conntrack, .packet = tcp_packet, .get_timeouts = tcp_get_timeouts,
@@ -1595,7 +1585,6 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_tcp6 __read_mostly = .l4proto = IPPROTO_TCP, .pkt_to_tuple = tcp_pkt_to_tuple, .invert_tuple = tcp_invert_tuple, - .print_tuple = tcp_print_tuple, .print_conntrack = tcp_print_conntrack, .packet = tcp_packet, .get_timeouts = tcp_get_timeouts,
net/netfilter/nf_conntrack_proto_udp.c +0 -13
@@ -63,15 +63,6 @@ static bool udp_invert_tuple(struct nf_conntrack_tuple *tuple,return true; } -/* Print out the per-protocol part of the tuple. */ -static void udp_print_tuple (struct seq_file *s, -const struct nf_conntrack_tuple *tuple) -{ -seq_printf (s,"sport=%hu dport=%hu " , -ntohs (tuple->src.u.udp.port), -ntohs (tuple->dst.u.udp.port)); -} -static unsigned int *udp_get_timeouts (struct net *net) {return udp_pernet (net)->timeouts;
@@ -316,7 +307,6 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_udp4 __read_mostly = .allow_clash = true, .pkt_to_tuple = udp_pkt_to_tuple, .invert_tuple = udp_invert_tuple, - .print_tuple = udp_print_tuple, .packet = udp_packet, .get_timeouts = udp_get_timeouts, .new = udp_new,
@@ -349,7 +339,6 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_udplite4 __read_mostly = .allow_clash = true, .pkt_to_tuple = udp_pkt_to_tuple, .invert_tuple = udp_invert_tuple, - .print_tuple = udp_print_tuple, .packet = udp_packet, .get_timeouts = udp_get_timeouts, .new = udp_new,
@@ -382,7 +371,6 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_udp6 __read_mostly = .allow_clash = true, .pkt_to_tuple = udp_pkt_to_tuple, .invert_tuple = udp_invert_tuple, - .print_tuple = udp_print_tuple, .packet = udp_packet, .get_timeouts = udp_get_timeouts, .new = udp_new,
@@ -415,7 +403,6 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_udplite6 __read_mostly = .allow_clash = true, .pkt_to_tuple = udp_pkt_to_tuple, .invert_tuple = udp_invert_tuple, - .print_tuple = udp_print_tuple, .packet = udp_packet, .get_timeouts = udp_get_timeouts, .new = udp_new,
net/netfilter/nf_conntrack_standalone.c +56 -2
64 lines not on this page · raw message
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 37/47 netfilter: conntrack: print_conntrack only needed if CONFIG_NF_CONNTRACK_PROCFS
From: Florian Westphal <[email protected]>
--- include/net/netfilter/nf_conntrack_l4proto.h | 7 ++++--- net/netfilter/nf_conntrack_proto_dccp.c | 6 ++++++ net/netfilter/nf_conntrack_proto_gre.c | 4 ++++ net/netfilter/nf_conntrack_proto_sctp.c | 6 ++++++ net/netfilter/nf_conntrack_proto_tcp.c | 6 ++++++ 5 files changed, 26 insertions(+), 3 deletions(-)
include/net/netfilter/nf_conntrack_l4proto.h +4 -3
@@ -61,9 +61,6 @@ struct nf_conntrack_l4proto {/* called by gc worker if table is full */ bool (*can_early_drop)(const struct nf_conn *ct); -/* Print out the private part of the conntrack. */ -void (*print_conntrack)(struct seq_file *s,struct nf_conn *); -/* Return the array of timeouts for this protocol. */ unsigned int *(*get_timeouts)(struct net *net);
@@ -97,6 +94,10 @@ struct nf_conntrack_l4proto { const struct nla_policy *nla_policy; } ctnl_timeout;#endif +#ifdef CONFIG_NF_CONNTRACK_PROCFS +/* Print out the private part of the conntrack. */ +void (*print_conntrack)(struct seq_file *s,struct nf_conn *); +#endif unsigned int *net_id;/* Init l4proto pernet data */ int (*init_net)(struct net *net,u_int16_t proto);
net/netfilter/nf_conntrack_proto_dccp.c +6 -0
@@ -623,10 +623,12 @@ static bool dccp_can_early_drop(const struct nf_conn *ct)return false; } +#ifdef CONFIG_NF_CONNTRACK_PROCFS static void dccp_print_conntrack (struct seq_file *s,struct nf_conn *ct) {seq_printf (s,"%s " , dccp_state_names[ct->proto.dccp.state]); } +#endif #if IS_ENABLED (CONFIG_NF_CT_NETLINK ) static int dccp_to_nlattr(struct sk_buff *skb, struct nlattr *nla,
@@ -879,7 +881,9 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_dccp4 __read_mostly = { .get_timeouts = dccp_get_timeouts, .error = dccp_error, .can_early_drop = dccp_can_early_drop, +#ifdef CONFIG_NF_CONNTRACK_PROCFS .print_conntrack = dccp_print_conntrack, +#endif #if IS_ENABLED (CONFIG_NF_CT_NETLINK ) .to_nlattr = dccp_to_nlattr, .nlattr_size = dccp_nlattr_size,
@@ -913,7 +917,9 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_dccp6 __read_mostly = { .get_timeouts = dccp_get_timeouts, .error = dccp_error, .can_early_drop = dccp_can_early_drop, +#ifdef CONFIG_NF_CONNTRACK_PROCFS .print_conntrack = dccp_print_conntrack, +#endif #if IS_ENABLED (CONFIG_NF_CT_NETLINK ) .to_nlattr = dccp_to_nlattr, .nlattr_size = dccp_nlattr_size,
net/netfilter/nf_conntrack_proto_gre.c +4 -0
@@ -224,6 +224,7 @@ static bool gre_pkt_to_tuple(const struct sk_buff *skb, unsigned int dataoff,return true; } +#ifdef CONFIG_NF_CONNTRACK_PROCFS /* print private data for conntrack */ static void gre_print_conntrack (struct seq_file *s,struct nf_conn *ct) {
@@ -231,6 +232,7 @@ static void gre_print_conntrack(struct seq_file *s, struct nf_conn *ct) (ct->proto.gre.timeout /HZ ), (ct->proto.gre.stream_timeout / HZ)); } +#endif static unsigned int *gre_get_timeouts (struct net *net) {
@@ -357,7 +359,9 @@ static struct nf_conntrack_l4proto nf_conntrack_l4proto_gre4 __read_mostly = { .l4proto = IPPROTO_GRE, .pkt_to_tuple = gre_pkt_to_tuple, .invert_tuple = gre_invert_tuple, +#ifdef CONFIG_NF_CONNTRACK_PROCFS .print_conntrack = gre_print_conntrack, +#endif .get_timeouts = gre_get_timeouts, .packet = gre_packet, .new = gre_new,
net/netfilter/nf_conntrack_proto_sctp.c +6 -0
@@ -174,11 +174,13 @@ static bool sctp_invert_tuple(struct nf_conntrack_tuple *tuple,return true; } +#ifdef CONFIG_NF_CONNTRACK_PROCFS /* Print out the private part of the conntrack. */ static void sctp_print_conntrack (struct seq_file *s,struct nf_conn *ct) {seq_printf (s,"%s " , sctp_conntrack_names[ct->proto.sctp.state]); } +#endif #define for_each_sctp_chunk (skb, sch, _sch, offset, dataoff, count) \ for ((offset) = (dataoff) + sizeof(struct sctphdr), (count) = 0; \
@@ -784,7 +786,9 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_sctp4 __read_mostly = { .l4proto = IPPROTO_SCTP, .pkt_to_tuple = sctp_pkt_to_tuple, .invert_tuple = sctp_invert_tuple, +#ifdef CONFIG_NF_CONNTRACK_PROCFS .print_conntrack = sctp_print_conntrack, +#endif .packet = sctp_packet, .get_timeouts = sctp_get_timeouts, .new = sctp_new,
@@ -819,7 +823,9 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_sctp6 __read_mostly = { .l4proto = IPPROTO_SCTP, .pkt_to_tuple = sctp_pkt_to_tuple, .invert_tuple = sctp_invert_tuple, +#ifdef CONFIG_NF_CONNTRACK_PROCFS .print_conntrack = sctp_print_conntrack, +#endif .packet = sctp_packet, .get_timeouts = sctp_get_timeouts, .new = sctp_new,
net/netfilter/nf_conntrack_proto_tcp.c +6 -0
@@ -301,11 +301,13 @@ static bool tcp_invert_tuple(struct nf_conntrack_tuple *tuple,return true; } +#ifdef CONFIG_NF_CONNTRACK_PROCFS /* Print out the private part of the conntrack. */ static void tcp_print_conntrack (struct seq_file *s,struct nf_conn *ct) {seq_printf (s,"%s " , tcp_conntrack_names[ct->proto.tcp.state]); } +#endif static unsigned int get_conntrack_index (const struct tcphdr *tcph) {
@@ -1549,7 +1551,9 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_tcp4 __read_mostly = .l4proto = IPPROTO_TCP, .pkt_to_tuple = tcp_pkt_to_tuple, .invert_tuple = tcp_invert_tuple, +#ifdef CONFIG_NF_CONNTRACK_PROCFS .print_conntrack = tcp_print_conntrack, +#endif .packet = tcp_packet, .get_timeouts = tcp_get_timeouts, .new = tcp_new,
@@ -1585,7 +1589,9 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_tcp6 __read_mostly = .l4proto = IPPROTO_TCP, .pkt_to_tuple = tcp_pkt_to_tuple, .invert_tuple = tcp_invert_tuple, +#ifdef CONFIG_NF_CONNTRACK_PROCFS .print_conntrack = tcp_print_conntrack, +#endif .packet = tcp_packet, .get_timeouts = tcp_get_timeouts, .new = tcp_new,
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 38/47 netfilter: conntrack: make protocol tracker pointers const
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Doesn't change generated code, but will make it easier to eventually make the actual trackers themselvers const.
--- include/net/netfilter/nf_conntrack_l3proto.h | 6 +++--- include/net/netfilter/nf_conntrack_l4proto.h | 4 ++-- include/net/netfilter/nf_conntrack_timeout.h | 2 +- net/netfilter/nf_conntrack_core.c | 12 ++++++------ net/netfilter/nf_conntrack_netlink.c | 22 +++++++++++----------- net/netfilter/nf_conntrack_proto.c | 20 ++++++++++---------- net/netfilter/nfnetlink_cttimeout.c | 14 +++++++------- net/netfilter/xt_CT.c | 2 +- net/openvswitch/conntrack.c | 4 ++-- 9 files changed, 43 insertions(+), 43 deletions(-)
include/net/netfilter/nf_conntrack_l3proto.h +3 -3
@@ -64,10 +64,10 @@ struct nf_conntrack_l3proto {extern struct nf_conntrack_l3proto __rcu *nf_ct_l3protos[NFPROTO_NUMPROTO ];/* Protocol global registration. */ -int nf_ct_l3proto_register (struct nf_conntrack_l3proto *proto); -void nf_ct_l3proto_unregister (struct nf_conntrack_l3proto *proto); +int nf_ct_l3proto_register (const struct nf_conntrack_l3proto *proto); +void nf_ct_l3proto_unregister (const struct nf_conntrack_l3proto *proto); -struct nf_conntrack_l3proto *nf_ct_l3proto_find_get (u_int16_t l3proto); +const struct nf_conntrack_l3proto *nf_ct_l3proto_find_get (u_int16_t l3proto);/* Existing built-in protocols */ extern struct nf_conntrack_l3proto nf_conntrack_l3proto_generic;
include/net/netfilter/nf_conntrack_l4proto.h +2 -2
@@ -114,10 +114,10 @@ extern struct nf_conntrack_l4proto nf_conntrack_l4proto_generic;#define MAX_NF_CT_PROTO 256 -struct nf_conntrack_l4proto *__nf_ct_l4proto_find (u_int16_t l3proto, +const struct nf_conntrack_l4proto *__nf_ct_l4proto_find (u_int16_t l3proto,u_int8_t l4proto); -struct nf_conntrack_l4proto *nf_ct_l4proto_find_get (u_int16_t l3proto, +const struct nf_conntrack_l4proto *nf_ct_l4proto_find_get (u_int16_t l3proto,u_int8_t l4proto);void nf_ct_l4proto_put (const struct nf_conntrack_l4proto *p);
include/net/netfilter/nf_conntrack_timeout.h +1 -1
@@ -16,7 +16,7 @@ struct ctnl_timeout {refcount_t refcnt;char name[CTNL_TIMEOUT_NAME_MAX ];__u16 l3num; -struct nf_conntrack_l4proto *l4proto; +const struct nf_conntrack_l4proto *l4proto;char data[0 ]; };
net/netfilter/nf_conntrack_core.c +6 -6
@@ -250,8 +250,8 @@ bool nf_ct_get_tuplepr(const struct sk_buff *skb, unsigned int nhoff,u_int16_t l3num, struct net *net, struct nf_conntrack_tuple *tuple) { - struct nf_conntrack_l3proto *l3proto; -struct nf_conntrack_l4proto *l4proto; + const struct nf_conntrack_l3proto *l3proto; +const struct nf_conntrack_l4proto *l4proto;unsigned int protoff;u_int8_t protonum;int ret;
@@ -400,7 +400,7 @@ static void destroy_conntrack(struct nf_conntrack *nfct) {struct nf_conn *ct = (struct nf_conn *)nfct; -struct nf_conntrack_l4proto *l4proto; +const struct nf_conntrack_l4proto *l4proto;pr_debug ("destroy_conntrack(%p)\n" , ct);NF_CT_ASSERT (atomic_read (&nfct->use) ==0 );
@@ -694,7 +694,7 @@ static int nf_ct_resolve_clash(struct net *net, struct sk_buff *skb, {/* This is the conntrack entry already in hashes that won race. */ struct nf_conn *ct =nf_ct_tuplehash_to_ctrack (h); -struct nf_conntrack_l4proto *l4proto; +const struct nf_conntrack_l4proto *l4proto; l4proto =__nf_ct_l4proto_find (nf_ct_l3num (ct),nf_ct_protonum (ct)); if (l4proto->allow_clash &&
@@ -1344,10 +1344,10 @@ unsigned int nf_conntrack_in(struct net *net, u_int8_t pf, unsigned int hooknum, struct sk_buff *skb) { + const struct nf_conntrack_l3proto *l3proto; +const struct nf_conntrack_l4proto *l4proto;struct nf_conn *ct, *tmpl;enum ip_conntrack_info ctinfo; -struct nf_conntrack_l3proto *l3proto; -struct nf_conntrack_l4proto *l4proto;unsigned int *timeouts;unsigned int dataoff;u_int8_t protonum;
net/netfilter/nf_conntrack_netlink.c +11 -11
@@ -109,9 +109,9 @@ static int ctnetlink_dump_tuples_ip(struct sk_buff *skb,static int ctnetlink_dump_tuples (struct sk_buff *skb,const struct nf_conntrack_tuple *tuple) { +const struct nf_conntrack_l3proto *l3proto; +const struct nf_conntrack_l4proto *l4proto;int ret; -struct nf_conntrack_l3proto *l3proto; -struct nf_conntrack_l4proto *l4proto;rcu_read_lock (); l3proto =__nf_ct_l3proto_find (tuple->src.l3num);
@@ -163,7 +163,7 @@ static int ctnetlink_dump_timeout(struct sk_buff *skb, const struct nf_conn *ct)static int ctnetlink_dump_protoinfo (struct sk_buff *skb,struct nf_conn *ct) { -struct nf_conntrack_l4proto *l4proto; +const struct nf_conntrack_l4proto *l4proto;struct nlattr *nest_proto;int ret;
@@ -535,9 +535,9 @@ ctnetlink_fill_info(struct sk_buff *skb, u32 portid, u32 seq, u32 type,static inline size_t ctnetlink_proto_size (const struct nf_conn *ct) { -struct nf_conntrack_l3proto *l3proto; -struct nf_conntrack_l4proto *l4proto; -size_t len =0 ; +const struct nf_conntrack_l3proto *l3proto; +const struct nf_conntrack_l4proto *l4proto; +size_t len; l3proto =__nf_ct_l3proto_find (nf_ct_l3num (ct)); len = l3proto->nla_size;
@@ -936,8 +936,8 @@ static const struct nla_policy proto_nla_policy[CTA_PROTO_MAX+1] = {static int ctnetlink_parse_tuple_proto (struct nlattr *attr,struct nf_conntrack_tuple *tuple) { +const struct nf_conntrack_l4proto *l4proto;struct nlattr *tb[CTA_PROTO_MAX +1 ]; -struct nf_conntrack_l4proto *l4proto;int ret =0 ; ret = nla_parse_nested(tb, CTA_PROTO_MAX, attr, proto_nla_policy,
@@ -1580,8 +1580,8 @@ static int ctnetlink_change_protoinfo(struct nf_conn *ct, const struct nlattr * const cda[]) {const struct nlattr *attr = cda[CTA_PROTOINFO ]; +const struct nf_conntrack_l4proto *l4proto;struct nlattr *tb[CTA_PROTOINFO_MAX +1 ]; -struct nf_conntrack_l4proto *l4proto;int err =0 ; err = nla_parse_nested(tb, CTA_PROTOINFO_MAX, attr, protoinfo_policy,
@@ -2475,11 +2475,11 @@ static int ctnetlink_exp_dump_mask(struct sk_buff *skb,const struct nf_conntrack_tuple *tuple, const struct nf_conntrack_tuple_mask *mask) { - int ret; -struct nf_conntrack_l3proto *l3proto; -struct nf_conntrack_l4proto *l4proto; + const struct nf_conntrack_l3proto *l3proto; +const struct nf_conntrack_l4proto *l4proto;struct nf_conntrack_tuple m;struct nlattr *nest_parms; +int ret;memset (&m,0xFF ,sizeof (m));memcpy (&m.src.u3, &mask->src.u3,sizeof (m.src.u3));
net/netfilter/nf_conntrack_proto.c +10 -10
@@ -65,7 +65,7 @@ nf_ct_unregister_sysctl(struct ctl_table_header **header, }#endif -struct nf_conntrack_l4proto * +const struct nf_conntrack_l4proto *__nf_ct_l4proto_find (u_int16_t l3proto,u_int8_t l4proto) {if (unlikely (l3proto >=NFPROTO_NUMPROTO || nf_ct_protos[l3proto] ==NULL ))
@@ -77,7 +77,7 @@ EXPORT_SYMBOL_GPL(__nf_ct_l4proto_find);/* this is guaranteed to always return a valid protocol helper, since * it falls back to generic_protocol */ -struct nf_conntrack_l3proto * +const struct nf_conntrack_l3proto *nf_ct_l3proto_find_get (u_int16_t l3proto) {struct nf_conntrack_l3proto *p;
@@ -95,8 +95,8 @@ EXPORT_SYMBOL_GPL(nf_ct_l3proto_find_get);int nf_ct_l3proto_try_module_get (unsigned short l3proto) { +const struct nf_conntrack_l3proto *p;int ret; -struct nf_conntrack_l3proto *p; retry: p =nf_ct_l3proto_find_get (l3proto);if (p == &nf_conntrack_l3proto_generic) {
@@ -173,10 +173,10 @@ void nf_ct_netns_put(struct net *net, u8 nfproto) }EXPORT_SYMBOL_GPL (nf_ct_netns_put); -struct nf_conntrack_l4proto * +const struct nf_conntrack_l4proto *nf_ct_l4proto_find_get (u_int16_t l3num,u_int8_t l4num) { -struct nf_conntrack_l4proto *p; +const struct nf_conntrack_l4proto *p;rcu_read_lock (); p =__nf_ct_l4proto_find (l3num, l4num);
@@ -196,18 +196,18 @@ EXPORT_SYMBOL_GPL(nf_ct_l4proto_put);static int kill_l3proto (struct nf_conn *i,void *data) { -return nf_ct_l3num (i) == ((struct nf_conntrack_l3proto *)data)->l3proto; +return nf_ct_l3num (i) == ((const struct nf_conntrack_l3proto *)data)->l3proto; }static int kill_l4proto (struct nf_conn *i,void *data) { -struct nf_conntrack_l4proto *l4proto; +const struct nf_conntrack_l4proto *l4proto; l4proto = data;return nf_ct_protonum (i) == l4proto->l4proto &&nf_ct_l3num (i) == l4proto->l3proto; } -int nf_ct_l3proto_register (struct nf_conntrack_l3proto *proto) +int nf_ct_l3proto_register (const struct nf_conntrack_l3proto *proto) {int ret =0 ;struct nf_conntrack_l3proto *old;
@@ -235,7 +235,7 @@ int nf_ct_l3proto_register(struct nf_conntrack_l3proto *proto) }EXPORT_SYMBOL_GPL (nf_ct_l3proto_register); -void nf_ct_l3proto_unregister (struct nf_conntrack_l3proto *proto) +void nf_ct_l3proto_unregister (const struct nf_conntrack_l3proto *proto) {BUG_ON (proto->l3proto >=NFPROTO_NUMPROTO );
@@ -249,7 +249,7 @@ void nf_ct_l3proto_unregister(struct nf_conntrack_l3proto *proto)synchronize_rcu ();/* Remove all contrack entries for this protocol */ -nf_ct_iterate_destroy (kill_l3proto, proto); +nf_ct_iterate_destroy (kill_l3proto, (void *)proto); }EXPORT_SYMBOL_GPL (nf_ct_l3proto_unregister);
net/netfilter/nfnetlink_cttimeout.c +7 -7
@@ -75,7 +75,7 @@ static int cttimeout_new_timeout(struct net *net, struct sock *ctnl, {__u16 l3num;__u8 l4num; -struct nf_conntrack_l4proto *l4proto; +const struct nf_conntrack_l4proto *l4proto;struct ctnl_timeout *timeout, *matching =NULL ;char *name;int ret;
@@ -159,7 +159,7 @@ ctnl_timeout_fill_info(struct sk_buff *skb, u32 portid, u32 seq, u32 type,struct nlmsghdr *nlh;struct nfgenmsg *nfmsg;unsigned int flags = portid ?NLM_F_MULTI :0 ; -struct nf_conntrack_l4proto *l4proto = timeout->l4proto; +const struct nf_conntrack_l4proto *l4proto = timeout->l4proto; event =nfnl_msg_type (NFNL_SUBSYS_CTNETLINK_TIMEOUT , event); nlh =nlmsg_put (skb, portid, seq, event,sizeof (*nfmsg), flags);
@@ -364,10 +364,10 @@ static int cttimeout_default_set(struct net *net, struct sock *ctnl,const struct nlattr *const cda[], struct netlink_ext_ack *extack) { + const struct nf_conntrack_l4proto *l4proto; +unsigned int *timeouts;__u16 l3num;__u8 l4num; -struct nf_conntrack_l4proto *l4proto; -unsigned int *timeouts;int ret; if (!cda[CTA_TIMEOUT_L3PROTO] ||
@@ -454,11 +454,11 @@ static int cttimeout_default_get(struct net *net, struct sock *ctnl,const struct nlattr *const cda[], struct netlink_ext_ack *extack) { - __u16 l3num; -__u8 l4num; -struct nf_conntrack_l4proto *l4proto; + const struct nf_conntrack_l4proto *l4proto;struct sk_buff *skb2;int ret, err; +__u16 l3num; +__u8 l4num;if (!cda[CTA_TIMEOUT_L3PROTO ] || !cda[CTA_TIMEOUT_L4PROTO ])return -EINVAL ;
net/netfilter/xt_CT.c +1 -1
@@ -121,9 +121,9 @@ xt_ct_set_timeout(struct nf_conn *ct, const struct xt_tgchk_param *par, {#ifdef CONFIG_NF_CONNTRACK_TIMEOUT typeof (nf_ct_timeout_find_get_hook) timeout_find_get; +const struct nf_conntrack_l4proto *l4proto;struct ctnl_timeout *timeout;struct nf_conn_timeout *timeout_ext; -struct nf_conntrack_l4proto *l4proto;int ret =0 ;u8 proto;
net/openvswitch/conntrack.c +2 -2
@@ -579,8 +579,8 @@ static struct nf_conn * ovs_ct_find_existing(struct net *net, const struct nf_conntrack_zone *zone, u8 l3num, struct sk_buff *skb, bool natted) { - struct nf_conntrack_l3proto *l3proto; -struct nf_conntrack_l4proto *l4proto; + const struct nf_conntrack_l3proto *l3proto; +const struct nf_conntrack_l4proto *l4proto;struct nf_conntrack_tuple tuple;struct nf_conntrack_tuple_hash *h;struct nf_conn *ct;
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 39/47 netfilter: ebtables: fix indent on if statements
In reply to Pablo Neira AyusoFrom: Colin Ian King <[email protected]>
The returns on some if statements are not indented correctly, add in the missing tab.
--- net/bridge/netfilter/ebt_ip.c | 4 ++-- net/bridge/netfilter/ebt_ip6.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
net/bridge/netfilter/ebt_ip.c +2 -2
@@ -64,14 +64,14 @@ ebt_ip_mt(const struct sk_buff *skb, struct xt_action_param *par)if (NF_INVF (info,EBT_IP_DPORT , dst < info->dport[0 ] || dst > info->dport[1 ])) -return false; +return false; }if (info->bitmask &EBT_IP_SPORT ) {u32 src =ntohs (pptr->src);if (NF_INVF (info,EBT_IP_SPORT , src < info->sport[0 ] || src > info->sport[1 ])) -return false; +return false; } }return true;
net/bridge/netfilter/ebt_ip6.c +1 -1
@@ -89,7 +89,7 @@ ebt_ip6_mt(const struct sk_buff *skb, struct xt_action_param *par)if (NF_INVF (info,EBT_IP6_SPORT , src < info->sport[0 ] || src > info->sport[1 ])) -return false; +return false; }if ((info->bitmask &EBT_IP6_ICMP6 ) && NF_INVF(info, EBT_IP6_ICMP6,
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 40/47 netfilter: fix a few (harmless) sparse warnings
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
net/netfilter/nft_payload.c:187:18: warning: incorrect type in return expression (expected bool got restricted __sum16 [usertype] check) net/netfilter/nft_exthdr.c:222:14: warning: cast to restricted __be32net/netfilter/nft_rt.c:49:23: warning: incorrect type in assignment (different base types expected unsigned int got restricted __be32) net/netfilter/nft_rt.c:70:25: warning: symbol 'nft_rt_policy' was not declared. Should it be static?
--- net/netfilter/nft_exthdr.c | 2 +- net/netfilter/nft_payload.c | 2 +- net/netfilter/nft_rt.c | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-)
net/netfilter/nft_exthdr.c +1 -1
@@ -388,7 +388,7 @@ nft_exthdr_select_ops(const struct nft_ctx *ctx,if (tb[NFTA_EXTHDR_SREG ] && tb[NFTA_EXTHDR_DREG ])return ERR_PTR (-EOPNOTSUPP ); - op =ntohl (nla_get_u32 (tb[NFTA_EXTHDR_OP ])); + op =ntohl (nla_get_be32 (tb[NFTA_EXTHDR_OP ]));switch (op) {case NFT_EXTHDR_OP_TCPOPT :if (tb[NFTA_EXTHDR_SREG ])
net/netfilter/nft_payload.c +1 -1
@@ -184,7 +184,7 @@ static bool nft_payload_udp_checksum(struct sk_buff *skb, unsigned int thoff)if (!uh)return false; -return uh->check; +return (__force bool )uh->check; } static int nft_payload_l4csum_offset(const struct nft_pktinfo *pkt,
net/netfilter/nft_rt.c +3 -3
@@ -82,8 +82,8 @@ static void nft_rt_get_eval(const struct nft_expr *expr,if (nft_pf (pkt) !=NFPROTO_IPV4 ) goto err; - *dest =rt_nexthop ((const struct rtable *)dst, -ip_hdr (skb)->daddr); + *dest = (__force u32 )rt_nexthop ((const struct rtable *)dst, +ip_hdr (skb)->daddr);break ;case NFT_RT_NEXTHOP6 :if (nft_pf (pkt) !=NFPROTO_IPV6 )
@@ -106,7 +106,7 @@ static void nft_rt_get_eval(const struct nft_expr *expr, regs->verdict.code =NFT_BREAK ; } -const struct nla_policy nft_rt_policy[NFTA_RT_MAX +1 ] = { +static const struct nla_policy nft_rt_policy[NFTA_RT_MAX +1 ] = { [NFTA_RT_DREG ] = { .type =NLA_U32 }, [NFTA_RT_KEY ] = { .type =NLA_U32 }, };
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 41/47 netfilter: convert hook list to an array
In reply to Pablo Neira AyusoFrom: Aaron Conole <[email protected]>
This converts the storage and layout of netfilter hook entries from a linked list to an array. After this commit, hook entries will be stored adjacent in memory. The next pointer is no longer required.
The ops pointers are stored at the end of the array as they are only used in the register/unregister path and in the legacy br_netfilter code.
nf_unregister_net_hooks() is slower than needed as it just calls nf_unregister_net_hook in a loop (i.e. at least n synchronize_net() calls), this will be addressed in followup patch.
Test setup:
- ixgbe 10gbit
- netperf UDP_STREAM, 64 byte packets
- 5 hooks: (raw + mangle prerouting, mangle+filter input, inet filter):
empty mangle and raw prerouting, mangle and filter input hooks:
353.9
this patch:
364.2
--- include/linux/netdevice.h | 2 +- include/linux/netfilter.h | 45 +++--- include/linux/netfilter_ingress.h | 4 +- include/net/netfilter/nf_queue.h | 2 +- include/net/netns/netfilter.h | 2 +- net/bridge/br_netfilter_hooks.c | 19 ++- net/netfilter/core.c | 297 ++++++++++++++++++++++++++++---------- net/netfilter/nf_internals.h | 3 +- net/netfilter/nf_queue.c | 67 +++++---- 9 files changed, 307 insertions(+), 134 deletions(-)
include/linux/netdevice.h +1 -1
@@ -1811,7 +1811,7 @@ struct net_device {#endif struct netdev_queue __rcu *ingress_queue;#ifdef CONFIG_NETFILTER_INGRESS -struct nf_hook_entry __rcu *nf_hooks_ingress; +struct nf_hook_entries __rcu *nf_hooks_ingress;#endif unsigned char broadcast[MAX_ADDR_LEN ];
include/linux/netfilter.h +23 -22
81 lines not on this page · raw message
include/linux/netfilter_ingress.h +2 -2
@@ -17,7 +17,7 @@ static inline bool nf_hook_ingress_active(const struct sk_buff *skb)/* caller must hold rcu_read_lock */ static inline int nf_hook_ingress (struct sk_buff *skb) { -struct nf_hook_entry *e =rcu_dereference (skb->dev->nf_hooks_ingress); +struct nf_hook_entries *e =rcu_dereference (skb->dev->nf_hooks_ingress);struct nf_hook_state state;int ret;
@@ -30,7 +30,7 @@ static inline int nf_hook_ingress(struct sk_buff *skb)nf_hook_state_init (&state,NF_NETDEV_INGRESS ,NFPROTO_NETDEV , skb->dev,NULL ,NULL ,dev_net (skb->dev),NULL ); - ret =nf_hook_slow (skb, &state, e); + ret =nf_hook_slow (skb, &state, e,0 );if (ret ==0 )return -1 ;
include/net/netfilter/nf_queue.h +1 -1
@@ -10,9 +10,9 @@ struct nf_queue_entry {struct list_head list;struct sk_buff *skb;unsigned int id; +unsigned int hook_index;/* index in hook_entries->hook[] */ struct nf_hook_state state; -struct nf_hook_entry *hook;u16 size;/* sizeof(entry) + saved route keys */ /* extra space to store route keys */
include/net/netns/netfilter.h +1 -1
@@ -16,7 +16,7 @@ struct netns_nf {#ifdef CONFIG_SYSCTL struct ctl_table_header *nf_log_dir_header;#endif -struct nf_hook_entry __rcu *hooks[NFPROTO_NUMPROTO ][NF_MAX_HOOKS ]; +struct nf_hook_entries __rcu *hooks[NFPROTO_NUMPROTO ][NF_MAX_HOOKS ];#if IS_ENABLED (CONFIG_NF_DEFRAG_IPV4 )bool defrag_ipv4;#endif
net/bridge/br_netfilter_hooks.c +11 -8
@@ -985,22 +985,25 @@ int br_nf_hook_thresh(unsigned int hook, struct net *net,int (*okfn)(struct net *,struct sock *, struct sk_buff *)) { -struct nf_hook_entry *elem; +const struct nf_hook_entries *e;struct nf_hook_state state; +struct nf_hook_ops **ops; +unsigned int i;int ret; -for (elem =rcu_dereference (net->nf.hooks[NFPROTO_BRIDGE ][hook]); - elem &&nf_hook_entry_priority (elem) <=NF_BR_PRI_BRNF ; - elem =rcu_dereference (elem->next)) - ; - -if (!elem) + e =rcu_dereference (net->nf.hooks[NFPROTO_BRIDGE ][hook]); +if (!e)return okfn (net, sk, skb); + ops =nf_hook_entries_get_hook_ops (e); +for (i =0 ; i < e->num_hook_entries && + ops[i]->priority <=NF_BR_PRI_BRNF ; i++) + ; +nf_hook_state_init (&state, hook,NFPROTO_BRIDGE , indev, outdev, sk, net, okfn); - ret =nf_hook_slow (skb, &state, elem); + ret =nf_hook_slow (skb, &state, e, i);if (ret ==1 ) ret =okfn (net, sk, skb);
net/netfilter/core.c +224 -73
393 lines not on this page · raw message
net/netfilter/nf_internals.h +2 -1
@@ -13,7 +13,8 @@/* nf_queue.c */ int nf_queue (struct sk_buff *skb,struct nf_hook_state *state, -struct nf_hook_entry **entryp,unsigned int verdict); +const struct nf_hook_entries *entries,unsigned int index, +unsigned int verdict);unsigned int nf_queue_nf_hook_drop (struct net *net);/* nf_log.c */
net/netfilter/nf_queue.c +42 -25
134 lines not on this page · raw message
Signature · 1 line
2.1.4
Re: [PATCH 41/47] netfilter: convert hook list to an array
Quoted 22 lines · Pablo Neira Ayuso
From: Aaron Conole <[email protected]>
This converts the storage and layout of netfilter hook entries from a linked list to an array. After this commit, hook entries will be stored adjacent in memory. The next pointer is no longer required.
The ops pointers are stored at the end of the array as they are only used in the register/unregister path and in the legacy
br_netfiltercode.
nf_unregister_net_hooks()is slower than needed as it just callsnf_unregister_net_hookin a loop (i.e. at least nsynchronize_net()calls), this will be addressed in followup patch.Test setup:
- ixgbe 10gbit
- netperfUDP_STREAM, 64 byte packets
- 5 hooks: (raw + mangle prerouting, mangle+filter input, inet filter):
empty mangle and raw prerouting, mangle and filter input hooks:
353.9
this patch:
364.2
Quoted 4 lines
Signed-off-by Aaron Conole <[email protected]>Signed-off-by Florian Westphal <[email protected]>Signed-off-by Pablo Neira Ayuso <[email protected]>---
Hi,
We experience a regression in server with iommu enabled. After installing kernel and rebooting the server, it crashes during boot. Please see trace below.
Bisecting points to this patch.
Any idea what's wrong?
Regards,
Tariq Toukan
[ 25.590816] RIP: 0010:_raw_read_lock_bh+0x15/0x40 [ 25.596160] RSP: 0018:ffffc90007db77a0 EFLAGS: 00010286 [ 25.602089] RAX: 0000000000000100 RBX: 0000000000000003 RCX: 0000000000000000 [ 25.610152] RDX: 0000000000000000 RSI: ffffc90007db7898 RDI: 000000000000003c [ 25.618470] RBP: ffffc90007db7840 R08: 0000000000000001 R09: 0000000087c10eef [ 25.626786] R10: ffff88180f21f040 R11: ffffea005feeaf00 R12: 0000000000000000 [ 25.635103] R13: ffffc90007db7898 R14: ffff8817fbabdc00 R15: ffff8817fbabdc00 [ 25.643421] FS: 00007fcdb7771740(0000) GS:ffff88180f200000(0000) knlGS:0000000000000000 [ 25.653056] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 25.659818] CR2: 000000000000003c CR3: 0000001809ae0001 CR4: 00000000001606e0 [ 25.668136] Call Trace: [ 25.671215] ? ebt_do_table+0x3d/0x6e8 [ebtables] [ 25.676817] ebt_nat_out+0x1f/0x30 [ebtable_nat] [ 25.682326] nf_hook_slow+0x3c/0xb0 [ 25.686576] __br_forward+0xb1/0x1b0 [bridge] [ 25.691786] ? br_dev_queue_push_xmit+0x170/0x170 [bridge] [ 25.704333] br_flood+0x130/0x1b0 [bridge] [ 25.709254] br_dev_xmit+0x1e5/0x2a0 [bridge] [ 25.714468] dev_hard_start_xmit+0xa1/0x210 [ 25.719485] __dev_queue_xmit+0x4f6/0x610 [ 25.724304] dev_queue_xmit+0x10/0x20 [ 25.728739] ip_finish_output2+0x233/0x320 [ 25.733656] ip_finish_output+0x12a/0x1d0 [ 25.738474] ? netif_rx_ni+0x33/0x80 [ 25.742805] ip_mc_output+0x84/0x250 [ 25.747140] ip_local_out+0x35/0x40 [ 25.751377] ip_send_skb+0x19/0x40 [ 25.755583] udp_send_skb+0x172/0x280 [ 25.760013] udp_sendmsg+0x2c0/0xa30 [ 25.764348] ? ip_reply_glue_bits+0x50/0x50 [ 25.769366] ? import_iovec+0x2c/0xc0 [ 25.773801] inet_sendmsg+0x31/0xb0 [ 25.778042] sock_sendmsg+0x38/0x50 [ 25.782276] ___sys_sendmsg+0x25c/0x270 [ 25.786904] ? file_update_time+0x3a/0xf0 [ 25.791727] ? __wake_up_sync_key+0x50/0x60 [ 25.796741] ? pipe_write+0x3cc/0x420 [ 25.801175] ? __vfs_write+0xd0/0x130 [ 25.805608] __sys_sendmsg+0x45/0x80 [ 25.809938] SyS_sendmsg+0x12/0x20 [ 25.814077] entry_SYSCALL_64_fastpath+0x1a/0xa5 [ 25.819577] RIP: 0033:0x7fcdb64ac7a0 [ 25.823908] RSP: 002b:00007ffe2b98cb98 EFLAGS: 00000246 ORIG_RAX: 000000000000002e [ 25.832961] RAX: ffffffffffffffda RBX: 00007ffe2b98c630 RCX: 00007fcdb64ac7a0 [ 25.841270] RDX: 0000000000000000 RSI: 00007ffe2b98cc50 RDI: 000000000000000c [ 25.849583] RBP: 00007fcdb69018f8 R08: 00007ffe2b98cbc3 R09: 0000000000000004 [ 25.857901] R10: 0000000000000019 R11: 0000000000000246 R12: 0000000000000000 [ 25.866213] R13: 0000000000000000 R14: 00007ffe2b98c6c0 R15: 00007ffe2b98c6e0 [ 25.874520] Code: 55 48 89 e5 e8 bd 74 82 ff 5d c3 66 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 65 81 05 68 78 74 7e 00 02 00 00 b8 00 01 00 00 <f0> 0f c1 07 8d b0 00 01 00 00 40 84 [ 25.896497] RIP: _raw_read_lock_bh+0x15/0x40 RSP: ffffc90007db77a0 [ 25.903744] CR2: 000000000000003c [ 25.907808] ---[ end trace 4f824a5c467b1872 ]--- [ 25.907811] BUG: unable to handle kernel NULL pointer dereference at 000000000000003c [ 25.907828] IP: _raw_read_lock_bh+0x15/0x40 [ 25.907830] PGD 0 P4D 0 [ 25.907834] Oops: 0002 [#2] SMP [ 25.907836] Modules linked in: ebtable_nat(+) ebtables ib_ucm mlx4_en mlx4_ib rpcrdma mlx4_core rdma_ucm ib_uverbs ib_iser ib_umad rdma_cm ib_ipoib iw_cm ib_cm mlx5_ib bridge stp llc sge [ 25.907895] CPU: 12 PID: 0 Comm: swapper/12 Tainted: G D 4.13.0-for-linust-perf-2017-09-10_06-48-01-64 #1 [ 25.907896] Hardware name: Dell Inc. PowerEdge R720/0HJK12, BIOS 2.2.3 05/20/2014 [ 25.907898] task: ffff880c0c2f8000 task.stack: ffffc90006318000 [ 25.907901] RIP: 0010:_raw_read_lock_bh+0x15/0x40 [ 25.907902] RSP: 0018:ffff880c0f9839d0 EFLAGS: 00010286 [ 25.907904] RAX: 0000000000000100 RBX: 0000000000000003 RCX: 0000000000000000 [ 25.907905] RDX: 0000000000000000 RSI: ffff880c0f983ac8 RDI: 000000000000003c [ 25.907906] RBP: ffff880c0f983a70 R08: 0000000000000001 R09: 0000000000000000 [ 25.907907] R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000000000 [ 25.907909] R13: ffff880c0f983ac8 R14: ffff880bfcfdda00 R15: ffff880bfcfdda00 [ 25.907911] FS: 0000000000000000(0000) GS:ffff880c0f980000(0000) knlGS:0000000000000000 [ 25.907912] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 25.907913] CR2: 000000000000003c CR3: 0000001809a5e001 CR4: 00000000001606e0 [ 25.907915] Call Trace: [ 25.907918] <IRQ> [ 25.907925] ? ebt_do_table+0x3d/0x6e8 [ebtables] [ 25.907929] ? lock_timer_base+0x7d/0xa0 [ 25.907932] ? mod_timer+0xa9/0x2c0 [ 25.907937] ebt_nat_out+0x1f/0x30 [ebtable_nat] [ 25.907946] nf_hook_slow+0x3c/0xb0 [ 25.907958] __br_forward+0xb1/0x1b0 [bridge] [ 25.907966] ? br_dev_queue_push_xmit+0x170/0x170 [bridge] [ 25.907972] br_flood+0x130/0x1b0 [bridge] [ 25.907979] br_dev_xmit+0x1e5/0x2a0 [bridge] [ 25.907987] dev_hard_start_xmit+0xa1/0x210 [ 25.907990] __dev_queue_xmit+0x4f6/0x610 [ 25.907993] ? _raw_read_unlock_bh+0x20/0x30 [ 25.907996] dev_queue_xmit+0x10/0x20 [ 25.908001] ip6_finish_output2+0x3b5/0x4c0 [ 25.908005] ip6_finish_output+0xa5/0x100 [ 25.908007] ip6_output+0x5b/0xf0 [ 25.908012] NF_HOOK.constprop.43+0x30/0x90 [ 25.908015] ? icmp6_dst_alloc+0xd2/0x110 [ 25.908018] mld_sendpack+0x168/0x220 [ 25.908021] mld_ifc_timer_expire+0x17f/0x290 [ 25.908024] ? mld_dad_timer_expire+0x60/0x60 [ 25.908026] call_timer_fn+0x35/0x140 [ 25.908028] run_timer_softirq+0x1ce/0x410 [ 25.908031] ? timerqueue_add+0x59/0x90 [ 25.908036] ? sched_clock+0x9/0x10 [ 25.908039] ? sched_clock_cpu+0x11/0xb0 [ 25.908042] __do_softirq+0xd1/0x27f [ 25.908046] irq_exit+0xb5/0xc0 [ 25.908048] smp_apic_timer_interrupt+0x69/0x130 [ 25.908050] apic_timer_interrupt+0x93/0xa0 [ 25.908052] </IRQ> [ 25.908056] RIP: 0010:cpuidle_enter_state+0xe9/0x280 [ 25.908057] RSP: 0018:ffffc9000631be88 EFLAGS: 00000246 ORIG_RAX: ffffffffffffff10 [ 25.908059] RAX: ffff880c0f99bdc0 RBX: ffffe8f400180270 RCX: 000000000000001f [ 25.908060] RDX: 0000000000000000 RSI: ffff7761f8923d16 RDI: 0000000000000000 [ 25.908061] RBP: ffffc9000631bec0 R08: 00000000000002a1 R09: 0000000000000390 [ 25.908062] R10: 000000000000037e R11: 0000000000000018 R12: 0000000000000004 [ 25.908063] R13: 000000000000000c R14: ffffe8f400180270 R15: 00000005f7b4d9b4 [ 25.908068] ? cpuidle_enter_state+0xc5/0x280 [ 25.908071] cpuidle_enter+0x17/0x20 [ 25.908074] call_cpuidle+0x23/0x40 [ 25.908077] do_idle+0x172/0x1e0 [ 25.908079] cpu_startup_entry+0x1d/0x30 [ 25.908084] start_secondary+0x103/0x130 [ 25.908087] secondary_startup_64+0xa5/0xa5 [ 25.908089] Code: 55 48 89 e5 e8 bd 74 82 ff 5d c3 66 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 65 81 05 68 78 74 7e 00 02 00 00 b8 00 01 00 00 <f0> 0f c1 07 8d b0 00 01 00 00 40 84 [ 25.908124] RIP: _raw_read_lock_bh+0x15/0x40 RSP: ffff880c0f9839d0 [ 25.908124] CR2: 000000000000003c [ 25.908154] ---[ end trace 4f824a5c467b1873 ]--- [ 25.913089] Kernel panic - not syncing: Fatal exception in interrupt [ 26.964216] Shutting down cpus with NMI [ 26.968841] Kernel Offset: disabled [ 26.975644] ---[ end Kernel panic - not syncing: Fatal exception in interrupt
Florian Westphal
maintainerRe: [PATCH 41/47] netfilter: convert hook list to an array
Quoted 28 lines · Tariq Toukan
Quoted 22 lines · Pablo Neira Ayuso
From: Aaron Conole <[email protected]>
This converts the storage and layout of netfilter hook entries from a linked list to an array. After this commit, hook entries will be stored adjacent in memory. The next pointer is no longer required.
The ops pointers are stored at the end of the array as they are only used in the register/unregister path and in the legacy
br_netfiltercode.
nf_unregister_net_hooks()is slower than needed as it just callsnf_unregister_net_hookin a loop (i.e. at least nsynchronize_net()calls), this will be addressed in followup patch.Test setup:
- ixgbe 10gbit
- netperfUDP_STREAM, 64 byte packets
- 5 hooks: (raw + mangle prerouting, mangle+filter input, inet filter):
empty mangle and raw prerouting, mangle and filter input hooks:
353.9
this patch:
364.2Quoted 4 lines
Signed-off-by Aaron Conole <[email protected]>Signed-off-by Florian Westphal <[email protected]>Signed-off-by Pablo Neira Ayuso <[email protected]>---
Quoted 7 lines
Hi,
We experience a regression in server with iommu enabled. After installing kernel and rebooting the server, it crashes during boot. Please see trace below.
Bisecting points to this patch.
Hmm, strange because
Quoted 3 lines
[ 25.907811] BUG: unable to handle kernel NULL pointer dereference at 000000000000003c [ 25.907828] IP: _raw_read_lock_bh+0x15/0x40
... this says that ebt_table is NULL (0x3c is the offset of the rwlock).
If you don't have that fix already, does
https://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git/commit/?id=e6b72ee88a56bcfe63f72e9c30766484c45bec72
netfilter: ebtables: fix race condition in frame_filter_net_init()
resolve this bug for you?
Re: [PATCH 41/47] netfilter: convert hook list to an array
Quoted 39 lines · Florian Westphal
Quoted 28 lines · Tariq Toukan
Quoted 22 lines · Pablo Neira Ayuso
From: Aaron Conole <[email protected]>
This converts the storage and layout of netfilter hook entries from a linked list to an array. After this commit, hook entries will be stored adjacent in memory. The next pointer is no longer required.
The ops pointers are stored at the end of the array as they are only used in the register/unregister path and in the legacy
br_netfiltercode.
nf_unregister_net_hooks()is slower than needed as it just callsnf_unregister_net_hookin a loop (i.e. at least nsynchronize_net()calls), this will be addressed in followup patch.Test setup:
- ixgbe 10gbit
- netperfUDP_STREAM, 64 byte packets
- 5 hooks: (raw + mangle prerouting, mangle+filter input, inet filter):
empty mangle and raw prerouting, mangle and filter input hooks:
353.9
this patch:
364.2Quoted 4 lines
Signed-off-by Aaron Conole <[email protected]>Signed-off-by Florian Westphal <[email protected]>Signed-off-by Pablo Neira Ayuso <[email protected]>---
Quoted 7 lines
Hi,
We experience a regression in server with iommu enabled. After installing kernel and rebooting the server, it crashes during boot. Please see trace below.
Bisecting points to this patch.
Hmm, strange because
Quoted 7 lines
Quoted 3 lines
[ 25.907811] BUG: unable to handle kernel NULL pointer dereference at 000000000000003c [ 25.907828] IP: _raw_read_lock_bh+0x15/0x40... this says that
ebt_tableis NULL (0x3cis the offset of the rwlock).If you don't have that fix already, does
No, didn't have it.
Quoted 6 lines
netfilter: ebtables: fix race condition in
frame_filter_net_init()resolve this bug for you?
Now I applied the fix and bug is resolved.
Many thanks!
Tariq
Pablo Neira Ayuso
maintainerPATCH 42/47 netfilter: debug: check for sorted array
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Make sure our grow/shrink routine places them in the correct order.
--- net/netfilter/core.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
net/netfilter/core.c +23 -0
@@ -157,6 +157,27 @@ nf_hook_entries_grow(const struct nf_hook_entries *old,return new; } +static void hooks_validate (const struct nf_hook_entries *hooks) +{ +#ifdef CONFIG_DEBUG_KERNEL +struct nf_hook_ops **orig_ops; +int prio =INT_MIN ; +size_t i =0 ; + + orig_ops =nf_hook_entries_get_hook_ops (hooks); + +for (i =0 ; i < hooks->num_hook_entries; i++) { +if (orig_ops[i] == &dummy_ops) +continue ; + +WARN_ON (orig_ops[i]->priority < prio); + +if (orig_ops[i]->priority > prio) + prio = orig_ops[i]->priority; + } +#endif +} +/* * __nf_hook_entries_try_shrink - try to shrink hook array *
@@ -210,6 +231,7 @@ static void *__nf_hook_entries_try_shrink(struct nf_hook_entries __rcu **pp) new_ops[j] = (void *)orig_ops[i]; j++; } +hooks_validate (new); out_assign:rcu_assign_pointer (*pp, new);return old;
@@ -261,6 +283,7 @@ int nf_register_net_hook(struct net *net, const struct nf_hook_ops *reg)if (IS_ERR (new_hooks))return PTR_ERR (new_hooks); +hooks_validate (new_hooks);#ifdef CONFIG_NETFILTER_INGRESS if (reg->pf ==NFPROTO_NETDEV && reg->hooknum ==NF_NETDEV_INGRESS )net_inc_ingress_queue ();
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 43/47 netfilter: core: batch nf_unregister_net_hooks synchronize_net calls
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
re-add batching in nf_unregister_net_hooks().
Similar as before, just store an array with to-be-free'd rule arrays on stack, then call synchronize_net once per batch.
--- net/netfilter/core.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 56 insertions(+), 3 deletions(-)
net/netfilter/core.c +56 -3
@@ -395,10 +395,63 @@ EXPORT_SYMBOL(nf_register_net_hooks);void nf_unregister_net_hooks (struct net *net,const struct nf_hook_ops *reg,unsigned int hookcount) { -unsigned int i; +struct nf_hook_entries *to_free[16 ], *p; +struct nf_hook_entries __rcu **pp; +unsigned int i, j, n; + +mutex_lock (&nf_hook_mutex); +for (i =0 ; i < hookcount; i++) { + pp =nf_hook_entry_head (net, ®[i]); +if (!pp) +continue ; + + p =nf_entry_dereference (*pp); +if (WARN_ON_ONCE (!p)) +continue ; +__nf_unregister_net_hook (p, ®[i]); + } +mutex_unlock (&nf_hook_mutex); + +do { + n = min_t(unsigned int, hookcount, ARRAY_SIZE(to_free)); + +mutex_lock (&nf_hook_mutex); + +for (i =0 , j =0 ; i < hookcount && j < n; i++) { + pp =nf_hook_entry_head (net, ®[i]); +if (!pp) +continue ; + + p =nf_entry_dereference (*pp); +if (!p) +continue ; + + to_free[j] =__nf_hook_entries_try_shrink (pp); +if (to_free[j]) + ++j; + } + +mutex_unlock (&nf_hook_mutex); + +if (j) { +unsigned int nfq; + +synchronize_net (); + +/* need 2nd synchronize_net() if nfqueue is used, skb +* can get reinjected right before nf_queue_hook_drop() +*/ + nfq =nf_queue_nf_hook_drop (net); +if (nfq) +synchronize_net (); + +for (i =0 ; i < j; i++) +kvfree (to_free[i]); + } -for (i =0 ; i < hookcount; i++) -nf_unregister_net_hook (net, ®[i]); + reg += n; + hookcount -= n; + }while (hookcount >0 ); }EXPORT_SYMBOL (nf_unregister_net_hooks);
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 44/47 netfilter: conntrack: don't log "invalid" icmpv6 connections
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
When enabling logging for invalid connections we currently also log most icmpv6 types, which we don't track intentionally (e.g. neigh discovery). "invalid" should really mean "invalid", i.e. short header or bad checksum.
We don't do any logging for icmp(v4) either, its just useless noise.
--- net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c | 5 ----- 1 file changed, 5 deletions(-)
net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c +0 -5
@@ -121,11 +121,6 @@ static bool icmpv6_new(struct nf_conn *ct, const struct sk_buff *skb,pr_debug ("icmpv6: can't create new conn with type %u\n" , type +128 );nf_ct_dump_tuple_ipv6 (&ct->tuplehash[0 ].tuple); -if (LOG_INVALID (nf_ct_net (ct),IPPROTO_ICMPV6 )) -nf_log_packet (nf_ct_net (ct),PF_INET6 ,0 , skb,NULL , -NULL ,NULL , -"nf_ct_icmpv6: invalid new with type %d " , - type +128 );return false; }return true;
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 45/47 netfilter: Remove NFDEBUG()
In reply to Pablo Neira AyusoFrom: Varsha Rao <[email protected]>
Remove NFDEBUG and use pr_debug() instead of it.
--- net/netfilter/nf_internals.h | 6 ------ net/netfilter/nf_sockopt.c | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-)
net/netfilter/nf_internals.h +0 -6
@@ -5,12 +5,6 @@#include <linux/skbuff.h> #include <linux/netdevice.h> -#ifdef CONFIG_NETFILTER_DEBUG -#define NFDEBUG(format, args...) printk(KERN_DEBUG format , ## args) -#else -#define NFDEBUG(format, args...) -#endif -/* nf_queue.c */ int nf_queue(struct sk_buff *skb, struct nf_hook_state *state, const struct nf_hook_entries *entries, unsigned int index,
net/netfilter/nf_sockopt.c +1 -1
@@ -33,7 +33,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg) reg->set_optmin, reg->set_optmax) || overlap(ops->get_optmin, ops->get_optmax, reg->get_optmin, reg->get_optmax))) { - NFDEBUG("nf_sock overlap: %u-%u/%u-%u v %u-%u/%u-%u\n", + pr_debug("nf_sock overlap: %u-%u/%u-%u v %u-%u/%u-%u\n", ops->set_optmin, ops->set_optmax, ops->get_optmin, ops->get_optmax, reg->set_optmin, reg->set_optmax,
Signature · 1 line
2.1.4