netfilter: conntrack: remove protocol name from l3proto struct
Subsystems (3)
Pablo Neira Ayuso
maintainerPATCH 33/47 netfilter: conntrack: remove protocol name from l3proto struct
From: Florian Westphal <[email protected]>
no need to waste storage for something that is only needed in one place and can be deduced from protocol number.
Signed-off-by Florian Westphal <[email protected]>
Signed-off-by Pablo Neira Ayuso <[email protected]>
--- include/net/netfilter/nf_conntrack_l3proto.h | 3 --- net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c | 1 - net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c | 1 - net/netfilter/nf_conntrack_l3proto_generic.c | 1 - net/netfilter/nf_conntrack_standalone.c | 12 +++++++++++- 5 files changed, 11 insertions(+), 7 deletions(-)
include/net/netfilter/nf_conntrack_l3proto.h +0 -3
@@ -23,9 +23,6 @@ struct nf_conntrack_l3proto {/* size of tuple nlattr, fills a hole */ u16 nla_size; -/* Protocol name */ -const char *name; -/* * Try to fill in the third arg: nhoff is offset of l3 proto * hdr. Return true if possible.
net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c +0 -1
@@ -353,7 +353,6 @@ static void ipv4_hooks_unregister(struct net *net)struct nf_conntrack_l3proto nf_conntrack_l3proto_ipv4__read_mostly = { .l3proto =PF_INET , - .name ="ipv4" , .pkt_to_tuple = ipv4_pkt_to_tuple, .invert_tuple = ipv4_invert_tuple, .print_tuple = ipv4_print_tuple,
net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c +0 -1
@@ -348,7 +348,6 @@ static void ipv6_hooks_unregister(struct net *net)struct nf_conntrack_l3proto nf_conntrack_l3proto_ipv6__read_mostly = { .l3proto =PF_INET6 , - .name ="ipv6" , .pkt_to_tuple = ipv6_pkt_to_tuple, .invert_tuple = ipv6_invert_tuple, .print_tuple = ipv6_print_tuple,
net/netfilter/nf_conntrack_l3proto_generic.c +0 -1
@@ -64,7 +64,6 @@ static int generic_get_l4proto(const struct sk_buff *skb, unsigned int nhoff,struct nf_conntrack_l3proto nf_conntrack_l3proto_generic__read_mostly = { .l3proto =PF_UNSPEC , - .name ="unknown" , .pkt_to_tuple = generic_pkt_to_tuple, .invert_tuple = generic_invert_tuple, .print_tuple = generic_print_tuple,
net/netfilter/nf_conntrack_standalone.c +11 -1
@@ -198,6 +198,16 @@ ct_show_delta_time(struct seq_file *s, const struct nf_conn *ct) }#endif +static const char *l3proto_name (u16 proto) +{ +switch (proto) { +case AF_INET :return "ipv4" ; +case AF_INET6 :return "ipv6" ; + } + +return "unknown" ; +} +/* return 0 on success, 1 in case of error */ static int ct_seq_show (struct seq_file *s,void *v) {
@@ -231,7 +241,7 @@ static int ct_seq_show(struct seq_file *s, void *v) ret = -ENOSPC ;seq_printf (s,"%-8s %u %-8s %u %ld " , - l3proto->name,nf_ct_l3num (ct), +l3proto_name (l3proto->l3proto),nf_ct_l3num (ct), l4proto->name,nf_ct_protonum (ct),nf_ct_expires (ct) /HZ );
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 34/47 netfilter: conntrack: remove protocol name from l4proto struct
From: Florian Westphal <[email protected]>
no need to waste storage for something that is only needed in one place and can be deduced from protocol number.
Signed-off-by Florian Westphal <[email protected]>
Signed-off-by Pablo Neira Ayuso <[email protected]>
--- include/net/netfilter/nf_conntrack_l4proto.h | 3 --- net/ipv4/netfilter/nf_conntrack_proto_icmp.c | 1 - net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c | 1 - net/netfilter/nf_conntrack_proto.c | 8 ++++---- net/netfilter/nf_conntrack_proto_dccp.c | 2 -- net/netfilter/nf_conntrack_proto_generic.c | 1 - net/netfilter/nf_conntrack_proto_gre.c | 1 - net/netfilter/nf_conntrack_proto_sctp.c | 2 -- net/netfilter/nf_conntrack_proto_tcp.c | 2 -- net/netfilter/nf_conntrack_proto_udp.c | 4 ---- net/netfilter/nf_conntrack_standalone.c | 17 ++++++++++++++++- 11 files changed, 20 insertions(+), 22 deletions(-)
include/net/netfilter/nf_conntrack_l4proto.h +0 -3
@@ -108,9 +108,6 @@ struct nf_conntrack_l4proto {/* Return the per-net protocol part. */ struct nf_proto_net *(*get_net_proto)(struct net *net); -/* Protocol name */ -const char *name; -/* Module (if any) which this is connected to. */ struct module *me; };
net/ipv4/netfilter/nf_conntrack_proto_icmp.c +0 -1
@@ -362,7 +362,6 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_icmp __read_mostly = { .l3proto = PF_INET, .l4proto = IPPROTO_ICMP, - .name = "icmp", .pkt_to_tuple = icmp_pkt_to_tuple, .invert_tuple = icmp_invert_tuple, .print_tuple = icmp_print_tuple,
net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c +0 -1
@@ -367,7 +367,6 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_icmpv6 __read_mostly = { .l3proto = PF_INET6, .l4proto = IPPROTO_ICMPV6, - .name = "icmpv6", .pkt_to_tuple = icmpv6_pkt_to_tuple, .invert_tuple = icmpv6_invert_tuple, .print_tuple = icmpv6_print_tuple,
net/netfilter/nf_conntrack_proto.c +4 -4
@@ -437,8 +437,8 @@ int nf_ct_l4proto_register(struct nf_conntrack_l4proto *l4proto[], }if (i != num_proto) { ver = l4proto[i]->l3proto ==PF_INET6 ?6 :4 ; -pr_err ("nf_conntrack_ipv%d: can't register %s%d proto.\n" , - ver, l4proto[i]->name, ver); +pr_err ("nf_conntrack_ipv%d: can't register l4 %d proto.\n" , + ver, l4proto[i]->l4proto);nf_ct_l4proto_unregister (l4proto, i); }return ret;
@@ -458,8 +458,8 @@ int nf_ct_l4proto_pernet_register(struct net *net,break ; }if (i != num_proto) { -pr_err ("nf_conntrack_%s%d: pernet registration failed\n" , - l4proto[i]->name, +pr_err ("nf_conntrack_proto_%d %d: pernet registration failed\n" , + l4proto[i]->l4proto, l4proto[i]->l3proto ==PF_INET6 ?6 :4 );nf_ct_l4proto_pernet_unregister (net, l4proto, i); }
net/netfilter/nf_conntrack_proto_dccp.c +0 -2
@@ -880,7 +880,6 @@ static struct nf_proto_net *dccp_get_net_proto(struct net *net)struct nf_conntrack_l4proto nf_conntrack_l4proto_dccp4__read_mostly = { .l3proto =AF_INET , .l4proto =IPPROTO_DCCP , - .name ="dccp" , .pkt_to_tuple = dccp_pkt_to_tuple, .invert_tuple = dccp_invert_tuple, .new = dccp_new,
@@ -916,7 +915,6 @@ EXPORT_SYMBOL_GPL(nf_conntrack_l4proto_dccp4);struct nf_conntrack_l4proto nf_conntrack_l4proto_dccp6__read_mostly = { .l3proto =AF_INET6 , .l4proto =IPPROTO_DCCP , - .name ="dccp" , .pkt_to_tuple = dccp_pkt_to_tuple, .invert_tuple = dccp_invert_tuple, .new = dccp_new,
net/netfilter/nf_conntrack_proto_generic.c +0 -1
@@ -187,7 +187,6 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_generic __read_mostly = { .l3proto = PF_UNSPEC, .l4proto = 255, - .name = "unknown", .pkt_to_tuple = generic_pkt_to_tuple, .invert_tuple = generic_invert_tuple, .print_tuple = generic_print_tuple,
net/netfilter/nf_conntrack_proto_gre.c +0 -1
@@ -364,7 +364,6 @@ static int gre_init_net(struct net *net, u_int16_t proto)static struct nf_conntrack_l4proto nf_conntrack_l4proto_gre4__read_mostly = { .l3proto =AF_INET , .l4proto =IPPROTO_GRE , - .name ="gre" , .pkt_to_tuple = gre_pkt_to_tuple, .invert_tuple = gre_invert_tuple, .print_tuple = gre_print_tuple,
net/netfilter/nf_conntrack_proto_sctp.c +0 -2
@@ -791,7 +791,6 @@ static struct nf_proto_net *sctp_get_net_proto(struct net *net)struct nf_conntrack_l4proto nf_conntrack_l4proto_sctp4__read_mostly = { .l3proto =PF_INET , .l4proto =IPPROTO_SCTP , - .name ="sctp" , .pkt_to_tuple = sctp_pkt_to_tuple, .invert_tuple = sctp_invert_tuple, .print_tuple = sctp_print_tuple,
@@ -828,7 +827,6 @@ EXPORT_SYMBOL_GPL(nf_conntrack_l4proto_sctp4);struct nf_conntrack_l4proto nf_conntrack_l4proto_sctp6__read_mostly = { .l3proto =PF_INET6 , .l4proto =IPPROTO_SCTP , - .name ="sctp" , .pkt_to_tuple = sctp_pkt_to_tuple, .invert_tuple = sctp_invert_tuple, .print_tuple = sctp_print_tuple,
net/netfilter/nf_conntrack_proto_tcp.c +0 -2
@@ -1556,7 +1556,6 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_tcp4 __read_mostly = { .l3proto = PF_INET, .l4proto = IPPROTO_TCP, - .name = "tcp", .pkt_to_tuple = tcp_pkt_to_tuple, .invert_tuple = tcp_invert_tuple, .print_tuple = tcp_print_tuple,
@@ -1594,7 +1593,6 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_tcp6 __read_mostly = { .l3proto = PF_INET6, .l4proto = IPPROTO_TCP, - .name = "tcp", .pkt_to_tuple = tcp_pkt_to_tuple, .invert_tuple = tcp_invert_tuple, .print_tuple = tcp_print_tuple,
net/netfilter/nf_conntrack_proto_udp.c +0 -4
@@ -313,7 +313,6 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_udp4 __read_mostly = { .l3proto = PF_INET, .l4proto = IPPROTO_UDP, - .name = "udp", .allow_clash = true, .pkt_to_tuple = udp_pkt_to_tuple, .invert_tuple = udp_invert_tuple,
@@ -347,7 +346,6 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_udplite4 __read_mostly = { .l3proto = PF_INET, .l4proto = IPPROTO_UDPLITE, - .name = "udplite", .allow_clash = true, .pkt_to_tuple = udp_pkt_to_tuple, .invert_tuple = udp_invert_tuple,
@@ -381,7 +379,6 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_udp6 __read_mostly = { .l3proto = PF_INET6, .l4proto = IPPROTO_UDP, - .name = "udp", .allow_clash = true, .pkt_to_tuple = udp_pkt_to_tuple, .invert_tuple = udp_invert_tuple,
@@ -415,7 +412,6 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_udplite6 __read_mostly = { .l3proto = PF_INET6, .l4proto = IPPROTO_UDPLITE, - .name = "udplite", .allow_clash = true, .pkt_to_tuple = udp_pkt_to_tuple, .invert_tuple = udp_invert_tuple,
net/netfilter/nf_conntrack_standalone.c +16 -1
@@ -208,6 +208,21 @@ static const char* l3proto_name(u16 proto)return "unknown" ; } +static const char *l4proto_name (u16 proto) +{ +switch (proto) { +case IPPROTO_ICMP :return "icmp" ; +case IPPROTO_TCP :return "tcp" ; +case IPPROTO_UDP :return "udp" ; +case IPPROTO_DCCP :return "dccp" ; +case IPPROTO_GRE :return "gre" ; +case IPPROTO_SCTP :return "sctp" ; +case IPPROTO_UDPLITE :return "udplite" ; + } + +return "unknown" ; +} +/* return 0 on success, 1 in case of error */ static int ct_seq_show (struct seq_file *s,void *v) {
@@ -242,7 +257,7 @@ static int ct_seq_show(struct seq_file *s, void *v) ret = -ENOSPC ;seq_printf (s,"%-8s %u %-8s %u %ld " ,l3proto_name (l3proto->l3proto),nf_ct_l3num (ct), - l4proto->name,nf_ct_protonum (ct), +l4proto_name (l4proto->l4proto),nf_ct_protonum (ct),nf_ct_expires (ct) /HZ );if (l4proto->print_conntrack)
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 35/47 netfilter: conntrack: reduce size of l4protocol trackers
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
can use u16 for both, shrinks size by another 8 bytes.
Signed-off-by Florian Westphal <[email protected]>
Signed-off-by Pablo Neira Ayuso <[email protected]>
--- include/net/netfilter/nf_conntrack_l4proto.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
include/net/netfilter/nf_conntrack_l4proto.h +2 -2
@@ -92,12 +92,12 @@ struct nf_conntrack_l4proto {#if IS_ENABLED (CONFIG_NF_CT_NETLINK_TIMEOUT )struct { -size_t obj_size;int (*nlattr_to_obj)(struct nlattr *tb[],struct net *net,void *data);int (*obj_to_nlattr)(struct sk_buff *skb,const void *data); -unsigned int nlattr_max; +u16 obj_size; +u16 nlattr_max;const struct nla_policy *nla_policy; } ctnl_timeout;#endif
Signature · 1 line
2.1.4