netfilter: constify nf_loginfo structures
Subsystems (4)
Pablo Neira Ayuso
maintainerPATCH 23/47 netfilter: constify nf_loginfo structures
From: Julia Lawall <[email protected]>
The nf_loginfo structures are only passed as the seventh argument to nf_log_trace, which is declared as const or stored in a local const variable. Thus the nf_loginfo structures themselves can be const.
Done with the help of Coccinelle.
// <smpl>
@r disable optional_qualifier@
identifier i;
position p;
@@
static struct nf_loginfo i@p = { ... };
@ok1@
identifier r.i;
expression list[6] es;
position p;
@@
nf_log_trace(es,&i@p,...)
@ok2@
identifier r.i;
const struct nf_loginfo *e;
position p;
@@
e = &i@p
@bad@
position p != {r.p,ok1.p,ok2.p};
identifier r.i;
struct nf_loginfo e;
@@
e@i@p
@depends on !bad disable optional_qualifier@
identifier r.i;
@@
static
+const
struct nf_loginfo i = { ... };
// </smpl>
--- net/ipv4/netfilter/ip_tables.c | 2 +- net/ipv4/netfilter/nf_log_arp.c | 2 +- net/ipv4/netfilter/nf_log_ipv4.c | 2 +- net/ipv6/netfilter/ip6_tables.c | 2 +- net/ipv6/netfilter/nf_log_ipv6.c | 2 +- net/netfilter/nf_tables_core.c | 2 +- net/netfilter/nfnetlink_log.c | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-)
net/ipv4/netfilter/ip_tables.c +1 -1
@@ -151,7 +151,7 @@ static const char *const comments[] = { [NF_IP_TRACE_COMMENT_POLICY] = "policy", }; -static struct nf_loginfo trace_loginfo = { +static const struct nf_loginfo trace_loginfo = { .type =NF_LOG_TYPE_LOG , .u = { .log = {
net/ipv4/netfilter/nf_log_arp.c +1 -1
@@ -25,7 +25,7 @@#include <linux/netfilter/xt_LOG.h> #include <net/netfilter/nf_log.h> -static struct nf_loginfo default_loginfo = { +static const struct nf_loginfo default_loginfo = { .type =NF_LOG_TYPE_LOG , .u = { .log = {
net/ipv4/netfilter/nf_log_ipv4.c +1 -1
@@ -24,7 +24,7 @@#include <linux/netfilter/xt_LOG.h> #include <net/netfilter/nf_log.h> -static struct nf_loginfo default_loginfo = { +static const struct nf_loginfo default_loginfo = { .type =NF_LOG_TYPE_LOG , .u = { .log = {
net/ipv6/netfilter/ip6_tables.c +1 -1
@@ -176,7 +176,7 @@ static const char *const comments[] = { [NF_IP6_TRACE_COMMENT_POLICY] = "policy", }; -static struct nf_loginfo trace_loginfo = { +static const struct nf_loginfo trace_loginfo = { .type =NF_LOG_TYPE_LOG , .u = { .log = {
net/ipv6/netfilter/nf_log_ipv6.c +1 -1
@@ -25,7 +25,7 @@#include <linux/netfilter/xt_LOG.h> #include <net/netfilter/nf_log.h> -static struct nf_loginfo default_loginfo = { +static const struct nf_loginfo default_loginfo = { .type =NF_LOG_TYPE_LOG , .u = { .log = {
net/netfilter/nf_tables_core.c +1 -1
@@ -29,7 +29,7 @@ static const char *const comments[__NFT_TRACETYPE_MAX] = { [NFT_TRACETYPE_RULE] = "rule", }; -static struct nf_loginfo trace_loginfo = { +static const struct nf_loginfo trace_loginfo = { .type =NF_LOG_TYPE_LOG , .u = { .log = {
net/netfilter/nfnetlink_log.c +1 -1
@@ -606,7 +606,7 @@ __build_packet_message(struct nfnl_log_net *log,return -1 ; } -static struct nf_loginfo default_loginfo = { +static const struct nf_loginfo default_loginfo = { .type =NF_LOG_TYPE_ULOG , .u = { .ulog = {
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 24/47 netfilter: connlimit: merge root4 and root6.
From: Taehee Yoo <[email protected]>
The root4 variable is used only when connlimit extension module has been stored by the iptables command. and the roo6 variable is used only when connlimit extension module has been stored by the ip6tables command. So the root4 and roo6 variable does not be used at the same time.
--- net/netfilter/xt_connlimit.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-)
net/netfilter/xt_connlimit.c +8 -15
@@ -58,8 +58,7 @@ struct xt_connlimit_rb { static spinlock_t xt_connlimit_locks[CONNLIMIT_LOCK_SLOTS] __cacheline_aligned_in_smp;struct xt_connlimit_data { -struct rb_root climit_root4[CONNLIMIT_SLOTS ]; -struct rb_root climit_root6[CONNLIMIT_SLOTS ]; +struct rb_root climit_root[CONNLIMIT_SLOTS ]; };static u_int32_t connlimit_rnd__read_mostly ;
@@ -294,13 +293,11 @@ static int count_them(struct net *net,int count;u32 hash; -if (family ==NFPROTO_IPV6 ) { +if (family ==NFPROTO_IPV6 ) hash =connlimit_iphash6 (addr, mask); - root = &data->climit_root6[hash]; - }else { +else hash =connlimit_iphash (addr->ip & mask->ip); - root = &data->climit_root4[hash]; - } + root = &data->climit_root[hash];spin_lock_bh (&xt_connlimit_locks[hash %CONNLIMIT_LOCK_SLOTS ]);
@@ -379,10 +376,8 @@ static int connlimit_mt_check(const struct xt_mtchk_param *par)return -ENOMEM ; } -for (i =0 ; i <ARRAY_SIZE (info->data->climit_root4); ++i) - info->data->climit_root4[i] =RB_ROOT ; -for (i =0 ; i <ARRAY_SIZE (info->data->climit_root6); ++i) - info->data->climit_root6[i] =RB_ROOT ; +for (i =0 ; i <ARRAY_SIZE (info->data->climit_root); ++i) + info->data->climit_root[i] =RB_ROOT ;return 0 ; }
@@ -413,10 +408,8 @@ static void connlimit_mt_destroy(const struct xt_mtdtor_param *par)nf_ct_netns_put (par->net, par->family); -for (i =0 ; i <ARRAY_SIZE (info->data->climit_root4); ++i) -destroy_tree (&info->data->climit_root4[i]); -for (i =0 ; i <ARRAY_SIZE (info->data->climit_root6); ++i) -destroy_tree (&info->data->climit_root6[i]); +for (i =0 ; i <ARRAY_SIZE (info->data->climit_root); ++i) +destroy_tree (&info->data->climit_root[i]);kfree (info->data); }
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 25/47 netfilter: remove prototype of netfilter_queue_init
In reply to Pablo Neira AyusoFrom: Taehee Yoo <[email protected]>
The netfilter_queue_init() has been removed.
so we can remove the prototype of that.
--- net/netfilter/nf_internals.h | 1 - 1 file changed, 1 deletion(-)
net/netfilter/nf_internals.h +0 -1
@@ -15,7 +15,6 @@int nf_queue (struct sk_buff *skb,struct nf_hook_state *state,struct nf_hook_entry **entryp,unsigned int verdict);unsigned int nf_queue_nf_hook_drop (struct net *net); -int __init netfilter_queue_init (void );/* nf_log.c */ int __init netfilter_log_init (void );
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 26/47 netfilter: use audit_log()
In reply to Pablo Neira AyusoFrom: Geliang Tang <[email protected]>
Use audit_log() instead of open-coding it.
--- net/bridge/netfilter/ebtables.c | 13 ++++--------- net/netfilter/x_tables.c | 14 ++++---------- 2 files changed, 8 insertions(+), 19 deletions(-)
net/bridge/netfilter/ebtables.c +4 -9
@@ -1069,15 +1069,10 @@ static int do_replace_finish(struct net *net, struct ebt_replace *repl,#ifdef CONFIG_AUDIT if (audit_enabled) { -struct audit_buffer *ab; - - ab =audit_log_start (current->audit_context,GFP_KERNEL , -AUDIT_NETFILTER_CFG ); -if (ab) { -audit_log_format (ab,"table=%s family=%u entries=%u" , - repl->name,AF_BRIDGE , repl->nentries); -audit_log_end (ab); - } +audit_log (current->audit_context,GFP_KERNEL , +AUDIT_NETFILTER_CFG , +"table=%s family=%u entries=%u" , + repl->name,AF_BRIDGE , repl->nentries); }#endif return ret;
net/netfilter/x_tables.c +4 -10
@@ -1192,16 +1192,10 @@ xt_replace_table(struct xt_table *table,#ifdef CONFIG_AUDIT if (audit_enabled) { -struct audit_buffer *ab; - - ab =audit_log_start (current->audit_context,GFP_KERNEL , -AUDIT_NETFILTER_CFG ); -if (ab) { -audit_log_format (ab,"table=%s family=%u entries=%u" , - table->name, table->af, - private->number); -audit_log_end (ab); - } +audit_log (current->audit_context,GFP_KERNEL , +AUDIT_NETFILTER_CFG , +"table=%s family=%u entries=%u" , + table->name, table->af, private->number); }#endif
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 27/47 netfilter: exthdr: factor out tcp option access
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
--- net/netfilter/nft_exthdr.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-)
net/netfilter/nft_exthdr.c +21 -12
@@ -61,6 +61,26 @@ static void nft_exthdr_ipv6_eval(const struct nft_expr *expr, regs->verdict.code =NFT_BREAK ; } +static void * +nft_tcp_header_pointer (const struct nft_pktinfo *pkt, +unsigned int len,void *buffer,unsigned int *tcphdr_len) +{ +struct tcphdr *tcph; + +if (!pkt->tprot_set || pkt->tprot !=IPPROTO_TCP ) +return NULL ; + + tcph =skb_header_pointer (pkt->skb, pkt->xt.thoff,sizeof (*tcph), buffer); +if (!tcph) +return NULL ; + + *tcphdr_len =__tcp_hdrlen (tcph); +if (*tcphdr_len <sizeof (*tcph) || *tcphdr_len > len) +return NULL ; + +return skb_header_pointer (pkt->skb, pkt->xt.thoff, *tcphdr_len, buffer); +} +static void nft_exthdr_tcp_eval (const struct nft_expr *expr,struct nft_regs *regs,const struct nft_pktinfo *pkt)
@@ -72,18 +92,7 @@ static void nft_exthdr_tcp_eval(const struct nft_expr *expr,struct tcphdr *tcph;u8 *opt; -if (!pkt->tprot_set || pkt->tprot !=IPPROTO_TCP ) - goto err; - - tcph =skb_header_pointer (pkt->skb, pkt->xt.thoff,sizeof (*tcph), buff); -if (!tcph) - goto err; - - tcphdr_len =__tcp_hdrlen (tcph); -if (tcphdr_len <sizeof (*tcph)) - goto err; - - tcph =skb_header_pointer (pkt->skb, pkt->xt.thoff, tcphdr_len, buff); + tcph =nft_tcp_header_pointer (pkt,sizeof (buff), buff, &tcphdr_len);if (!tcph) goto err;
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 28/47 netfilter: exthdr: split netlink dump function
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
so eval and uncoming eval_set versions can reuse a common helper.
--- net/netfilter/nft_exthdr.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
net/netfilter/nft_exthdr.c +11 -5
@@ -180,12 +180,8 @@ static int nft_exthdr_init(const struct nft_ctx *ctx, NFT_DATA_VALUE, priv->len); } -static int nft_exthdr_dump (struct sk_buff *skb,const struct nft_expr *expr) +static int nft_exthdr_dump_common (struct sk_buff *skb,const struct nft_exthdr *priv) { -const struct nft_exthdr *priv =nft_expr_priv (expr); - -if (nft_dump_register (skb,NFTA_EXTHDR_DREG , priv->dreg)) - goto nla_put_failure;if (nla_put_u8 (skb,NFTA_EXTHDR_TYPE , priv->type)) goto nla_put_failure;if (nla_put_be32 (skb,NFTA_EXTHDR_OFFSET ,htonl (priv->offset)))
@@ -202,6 +198,16 @@ static int nft_exthdr_dump(struct sk_buff *skb, const struct nft_expr *expr)return -1 ; } +static int nft_exthdr_dump (struct sk_buff *skb,const struct nft_expr *expr) +{ +const struct nft_exthdr *priv =nft_expr_priv (expr); + +if (nft_dump_register (skb,NFTA_EXTHDR_DREG , priv->dreg)) +return -1 ; + +return nft_exthdr_dump_common (skb, priv); +} +static struct nft_expr_type nft_exthdr_type;static const struct nft_expr_ops nft_exthdr_ipv6_ops = { .type = &nft_exthdr_type,
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 29/47 netfilter: exthdr: tcp option set support
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
This allows setting 2 and 4 byte quantities in the tcp option space. Main purpose is to allow native replacement for xt_TCPMSS to work around pmtu blackholes.
Writes to kind and len are now allowed at the moment, it does not seem useful to do this as it causes corruption of the tcp option space.
We can always lift this restriction later if a use-case appears.
--- include/uapi/linux/netfilter/nf_tables.h | 4 +- net/netfilter/nft_exthdr.c | 164 ++++++++++++++++++++++++++++++- 2 files changed, 165 insertions(+), 3 deletions(-)
include/uapi/linux/netfilter/nf_tables.h +3 -1
@@ -732,7 +732,8 @@ enum nft_exthdr_op {* @NFTA_EXTHDR_OFFSET: extension header offset (NLA_U32) * @NFTA_EXTHDR_LEN: extension header length (NLA_U32) * @NFTA_EXTHDR_FLAGS: extension header flags (NLA_U32) -* @NFTA_EXTHDR_OP: option match type (NLA_U8) +* @NFTA_EXTHDR_OP: option match type (NLA_U32) +* @NFTA_EXTHDR_SREG: option match type (NLA_U32) */ enum nft_exthdr_attributes {NFTA_EXTHDR_UNSPEC ,
@@ -742,6 +743,7 @@ enum nft_exthdr_attributes {NFTA_EXTHDR_LEN ,NFTA_EXTHDR_FLAGS ,NFTA_EXTHDR_OP , +NFTA_EXTHDR_SREG , __NFTA_EXTHDR_MAX };#define NFTA_EXTHDR_MAX (__NFTA_EXTHDR_MAX - 1)
net/netfilter/nft_exthdr.c +162 -2
210 lines not on this page · raw message
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 30/47 netfilter: rt: add support to fetch path mss
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
to be used in combination with tcp option set support to mimic iptables TCPMSS --clamp-mss-to-pmtu.
v2: Eric Dumazet points out dst must be initialized.
--- include/uapi/linux/netfilter/nf_tables.h | 2 + net/netfilter/nft_rt.c | 66 ++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+)
include/uapi/linux/netfilter/nf_tables.h +2 -0
@@ -811,11 +811,13 @@ enum nft_meta_keys {* @NFT_RT_CLASSID: realm value of packet's route (skb->dst->tclassid) * @NFT_RT_NEXTHOP4: routing nexthop for IPv4 * @NFT_RT_NEXTHOP6: routing nexthop for IPv6 +* @NFT_RT_TCPMSS: fetch current path tcp mss */ enum nft_rt_keys {NFT_RT_CLASSID ,NFT_RT_NEXTHOP4 ,NFT_RT_NEXTHOP6 , +NFT_RT_TCPMSS , };/**
net/netfilter/nft_rt.c +66 -0
96 lines not on this page · raw message
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 31/47 netfilter: nf_nat_h323: fix logical-not-parentheses warning
In reply to Pablo Neira AyusoFrom: Nick Desaulniers <[email protected]>
Clang produces the following warning:
net/ipv4/netfilter/nf_nat_h323.c:553:6: error:
logical not is only applied to the left hand side of this comparison
[-Werror,-Wlogical-not-parentheses]
if (!set_h225_addr(skb, protoff, data, dataoff, taddr,
^
add parentheses after the '!' to evaluate the comparison first add parentheses around left hand side expression to silence this warning
There's not necessarily a bug here, but it's cleaner to return early, ex:
if (x)
return
...
rather than:
if (x == 0)
...
else
return
Also added a return code check that seemed to be missing in one instance.
--- net/ipv4/netfilter/nf_nat_h323.c | 57 +++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 27 deletions(-)
net/ipv4/netfilter/nf_nat_h323.c +30 -27
@@ -252,16 +252,16 @@ static int nat_rtp_rtcp(struct sk_buff *skb, struct nf_conn *ct,if (set_h245_addr (skb, protoff, data, dataoff, taddr, &ct->tuplehash[!dir].tuple.dst.u3,htons ((port &htons (1 )) ? nated_port +1 : - nated_port)) ==0 ) { -/* Save ports */ - info->rtp_port[i][dir] = rtp_port; - info->rtp_port[i][!dir] =htons (nated_port); - }else { + nated_port))) {nf_ct_unexpect_related (rtp_exp);nf_ct_unexpect_related (rtcp_exp);return -1 ; } +/* Save ports */ + info->rtp_port[i][dir] = rtp_port; + info->rtp_port[i][!dir] =htons (nated_port); +/* Success */ pr_debug("nf_nat_h323: expect RTP %pI4:%hu->%pI4:%hu\n", &rtp_exp->tuple.src.u3.ip,
@@ -370,15 +370,15 @@ static int nat_h245(struct sk_buff *skb, struct nf_conn *ct,/* Modify signal */ if (set_h225_addr (skb, protoff, data, dataoff, taddr, &ct->tuplehash[!dir].tuple.dst.u3, -htons (nated_port)) ==0 ) { -/* Save ports */ - info->sig_port[dir] = port; - info->sig_port[!dir] =htons (nated_port); - }else { +htons (nated_port))) {nf_ct_unexpect_related (exp);return -1 ; } +/* Save ports */ + info->sig_port[dir] = port; + info->sig_port[!dir] =htons (nated_port); + pr_debug("nf_nat_q931: expect H.245 %pI4:%hu->%pI4:%hu\n", &exp->tuple.src.u3.ip, ntohs(exp->tuple.src.u.tcp.port),
@@ -462,24 +462,27 @@ static int nat_q931(struct sk_buff *skb, struct nf_conn *ct,/* Modify signal */ if (set_h225_addr (skb, protoff, data,0 , &taddr[idx], &ct->tuplehash[!dir].tuple.dst.u3, -htons (nated_port)) ==0 ) { -/* Save ports */ - info->sig_port[dir] = port; - info->sig_port[!dir] =htons (nated_port); - -/* Fix for Gnomemeeting */ -if (idx >0 && -get_h225_addr (ct, *data, &taddr[0 ], &addr, &port) && - (ntohl (addr.ip) &0xff000000 ) ==0x7f000000 ) { -set_h225_addr (skb, protoff, data,0 , &taddr[0 ], - &ct->tuplehash[!dir].tuple.dst.u3, - info->sig_port[!dir]); - } - }else { +htons (nated_port))) {nf_ct_unexpect_related (exp);return -1 ; } +/* Save ports */ + info->sig_port[dir] = port; + info->sig_port[!dir] =htons (nated_port); + +/* Fix for Gnomemeeting */ +if (idx >0 && +get_h225_addr (ct, *data, &taddr[0 ], &addr, &port) && + (ntohl (addr.ip) &0xff000000 ) ==0x7f000000 ) { +if (set_h225_addr (skb, protoff, data,0 , &taddr[0 ], + &ct->tuplehash[!dir].tuple.dst.u3, + info->sig_port[!dir])) { +nf_ct_unexpect_related (exp); +return -1 ; + } + } +/* Success */ pr_debug("nf_nat_ras: expect Q.931 %pI4:%hu->%pI4:%hu\n", &exp->tuple.src.u3.ip,
@@ -550,9 +553,9 @@ static int nat_callforwarding(struct sk_buff *skb, struct nf_conn *ct, }/* Modify signal */ -if (!set_h225_addr (skb, protoff, data, dataoff, taddr, - &ct->tuplehash[!dir].tuple.dst.u3, -htons (nated_port)) ==0 ) { +if (set_h225_addr (skb, protoff, data, dataoff, taddr, + &ct->tuplehash[!dir].tuple.dst.u3, +htons (nated_port))) {nf_ct_unexpect_related (exp);return -1 ; }
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 32/47 netfilter: conntrack: compute l3proto nla size at compile time
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
avoids a pointer and allows struct to be const later on.
--- include/net/netfilter/nf_conntrack_l3proto.h | 19 ++++++++----------- net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c | 13 +++++++------ net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c | 14 ++++++++------ net/netfilter/nf_conntrack_netlink.c | 3 ++- net/netfilter/nf_conntrack_proto.c | 9 +++------ 5 files changed, 28 insertions(+), 30 deletions(-)
include/net/netfilter/nf_conntrack_l3proto.h +8 -11
@@ -20,6 +20,9 @@ struct nf_conntrack_l3proto {/* L3 Protocol Family number. ex) PF_INET */ u_int16_t l3proto; +/* size of tuple nlattr, fills a hole */ +u16 nla_size; +/* Protocol name */ const char *name;
@@ -49,23 +52,17 @@ struct nf_conntrack_l3proto {int (*get_l4proto)(const struct sk_buff *skb,unsigned int nhoff,unsigned int *dataoff,u_int8_t *protonum); +#if IS_ENABLED (CONFIG_NF_CT_NETLINK )int (*tuple_to_nlattr)(struct sk_buff *skb,const struct nf_conntrack_tuple *t); - -/* Called when netns wants to use connection tracking */ -int (*net_ns_get)(struct net *); -void (*net_ns_put)(struct net *); - -/* -* Calculate size of tuple nlattr -*/ -int (*nlattr_tuple_size)(void ); -int (*nlattr_to_tuple)(struct nlattr *tb[],struct nf_conntrack_tuple *t);const struct nla_policy *nla_policy; +#endif -size_t nla_size; +/* Called when netns wants to use connection tracking */ +int (*net_ns_get)(struct net *); +void (*net_ns_put)(struct net *);/* Module (if any) which this is connected to. */ struct module *me;
net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c +7 -6
@@ -303,11 +303,6 @@ static int ipv4_nlattr_to_tuple(struct nlattr *tb[],return 0 ; } - -static int ipv4_nlattr_tuple_size (void ) -{ -return nla_policy_len (ipv4_nla_policy,CTA_IP_MAX +1 ); -}#endif static struct nf_sockopt_ops so_getorigdst = {
@@ -365,9 +360,10 @@ struct nf_conntrack_l3proto nf_conntrack_l3proto_ipv4 __read_mostly = { .get_l4proto = ipv4_get_l4proto,#if IS_ENABLED (CONFIG_NF_CT_NETLINK ) .tuple_to_nlattr = ipv4_tuple_to_nlattr, - .nlattr_tuple_size = ipv4_nlattr_tuple_size, .nlattr_to_tuple = ipv4_nlattr_to_tuple, .nla_policy = ipv4_nla_policy, + .nla_size =NLA_ALIGN (NLA_HDRLEN +sizeof (u32)) +/* CTA_IP_V4_SRC */ +NLA_ALIGN (NLA_HDRLEN +sizeof (u32)),/* CTA_IP_V4_DST */ #endif .net_ns_get = ipv4_hooks_register, .net_ns_put = ipv4_hooks_unregister,
@@ -421,6 +417,11 @@ static int __init nf_conntrack_l3proto_ipv4_init(void)need_conntrack (); +#if IS_ENABLED (CONFIG_NF_CT_NETLINK ) +if (WARN_ON (nla_policy_len (ipv4_nla_policy,CTA_IP_MAX +1 ) != + nf_conntrack_l3proto_ipv4.nla_size)) +return -EINVAL ; +#endif ret =nf_register_sockopt (&so_getorigdst);if (ret <0 ) {pr_err ("Unable to register netfilter socket option\n" );
net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c +8 -6
@@ -308,11 +308,6 @@ static int ipv6_nlattr_to_tuple(struct nlattr *tb[], return 0; } - -static int ipv6_nlattr_tuple_size (void ) -{ -return nla_policy_len (ipv6_nla_policy,CTA_IP_MAX +1 ); -}#endif static int ipv6_hooks_register (struct net *net)
@@ -360,9 +355,10 @@ struct nf_conntrack_l3proto nf_conntrack_l3proto_ipv6 __read_mostly = { .get_l4proto = ipv6_get_l4proto,#if IS_ENABLED (CONFIG_NF_CT_NETLINK ) .tuple_to_nlattr = ipv6_tuple_to_nlattr, - .nlattr_tuple_size = ipv6_nlattr_tuple_size, .nlattr_to_tuple = ipv6_nlattr_to_tuple, .nla_policy = ipv6_nla_policy, + .nla_size =NLA_ALIGN (NLA_HDRLEN +sizeof (u32[4 ])) + + NLA_ALIGN(NLA_HDRLEN + sizeof(u32[4])), #endif .net_ns_get = ipv6_hooks_register, .net_ns_put = ipv6_hooks_unregister,
@@ -421,6 +417,12 @@ static int __init nf_conntrack_l3proto_ipv6_init(void)need_conntrack (); +#if IS_ENABLED (CONFIG_NF_CT_NETLINK ) +if (WARN_ON (nla_policy_len (ipv6_nla_policy,CTA_IP_MAX +1 ) != + nf_conntrack_l3proto_ipv6.nla_size)) +return -EINVAL ; +#endif + ret =nf_register_sockopt (&so_getorigdst6);if (ret <0 ) {pr_err ("Unable to register netfilter socket option\n" );
net/netfilter/nf_conntrack_netlink.c +2 -1
@@ -540,7 +540,8 @@ static inline size_t ctnetlink_proto_size(const struct nf_conn *ct)size_t len =0 ; l3proto =__nf_ct_l3proto_find (nf_ct_l3num (ct)); - len += l3proto->nla_size; + len = l3proto->nla_size; + len *=3u ;/* ORIG, REPLY, MASTER */ l4proto =__nf_ct_l4proto_find (nf_ct_l3num (ct),nf_ct_protonum (ct)); len += l4proto->nla_size;
net/netfilter/nf_conntrack_proto.c +3 -6
@@ -214,10 +214,10 @@ int nf_ct_l3proto_register(struct nf_conntrack_l3proto *proto)if (proto->l3proto >=NFPROTO_NUMPROTO )return -EBUSY ; - -if (proto->tuple_to_nlattr && !proto->nlattr_tuple_size) +#if IS_ENABLED (CONFIG_NF_CT_NETLINK ) +if (proto->tuple_to_nlattr && proto->nla_size ==0 )return -EINVAL ; - +#endif mutex_lock (&nf_ct_proto_mutex); old =rcu_dereference_protected (nf_ct_l3protos[proto->l3proto],lockdep_is_held (&nf_ct_proto_mutex));
@@ -226,9 +226,6 @@ int nf_ct_l3proto_register(struct nf_conntrack_l3proto *proto) goto out_unlock; } -if (proto->nlattr_tuple_size) - proto->nla_size =3 * proto->nlattr_tuple_size (); -rcu_assign_pointer (nf_ct_l3protos[proto->l3proto], proto); out_unlock:
Signature · 1 line
2.1.4