History

netfilter: Add nfnl_msg_type() helper function

Add and use nfnl_msg_type() function to replace opencoded nfnetlink message type. I suggested this change, Arushi Singhal made an initial patch to address this but was missing several spots.

Pablo Neira Ayuso committed 9 years ago

Commit dedb67c1 parent 2c62e0b11 files · +33 −27Browse files

Unified · Split

11 files
  1. include/linux/netfilter/nfnetlink.h +5 −0
  2. net/netfilter/ipset/ip_set_core.c +1 −1
  3. net/netfilter/nf_conntrack_netlink.c +9 −7
  4. net/netfilter/nf_tables_api.c +9 −11
  5. net/netfilter/nf_tables_trace.c +2 −1
  6. net/netfilter/nfnetlink_acct.c +1 −1
  7. net/netfilter/nfnetlink_cthelper.c +1 −1
  8. net/netfilter/nfnetlink_cttimeout.c +2 −2
  9. net/netfilter/nfnetlink_log.c +1 −1
  10. net/netfilter/nfnetlink_queue.c +1 −1
  11. net/netfilter/nft_compat.c +1 −1
include/linux/netfilter/nfnetlink.h+5−0
@@ -41,6 +41,11 @@ int nfnetlink_set_err(struct net *net, u32 portid, u32 group, int error); · 40 unmodified lines
4141 int nfnetlink_unicast(struct sk_buff *skb, struct net *net, u32 portid,
4242 int flags);
4343
44+static inline u16 nfnl_msg_type(u8 subsys, u8 msg_type)
45+{
46+ return subsys << 8 | msg_type;
47+}
48+
4449 void nfnl_lock(__u8 subsys_id);
4550 void nfnl_unlock(__u8 subsys_id);
4651 #ifdef CONFIG_PROVE_LOCKING
net/netfilter/ipset/ip_set_core.c+1−1
@@ -769,7 +769,7 @@ start_msg(struct sk_buff *skb, u32 portid, u32 seq, unsigned int flags, · 768 unmodified lines
769769 struct nlmsghdr *nlh;
770770 struct nfgenmsg *nfmsg;
771771
772− nlh = nlmsg_put(skb, portid, seq, cmd | (NFNL_SUBSYS_IPSET << 8),
772+ nlh = nlmsg_put(skb, portid, seq, nfnl_msg_type(NFNL_SUBSYS_IPSET, cmd),
773773 sizeof(*nfmsg), flags);
774774 if (!nlh)
775775 return NULL;
net/netfilter/nf_conntrack_netlink.c+9−7
@@ -467,7 +467,7 @@ ctnetlink_fill_info(struct sk_buff *skb, u32 portid, u32 seq, u32 type, · 466 unmodified lines
467467 struct nlattr *nest_parms;
468468 unsigned int flags = portid ? NLM_F_MULTI : 0, event;
469469
470− event = (NFNL_SUBSYS_CTNETLINK << 8 | IPCTNL_MSG_CT_NEW);
470+ event = nfnl_msg_type(NFNL_SUBSYS_CTNETLINK, IPCTNL_MSG_CT_NEW);
471471 nlh = nlmsg_put(skb, portid, seq, event, sizeof(*nfmsg), flags);
472472 if (nlh == NULL)
473473 goto nlmsg_failure;
@@ -652,7 +652,7 @@ ctnetlink_conntrack_event(unsigned int events, struct nf_ct_event *item) · 178 unmodified lines
652652 if (skb == NULL)
653653 goto errout;
654654
655− type |= NFNL_SUBSYS_CTNETLINK << 8;
655+ type = nfnl_msg_type(NFNL_SUBSYS_CTNETLINK, type);
656656 nlh = nlmsg_put(skb, item->portid, 0, type, sizeof(*nfmsg), flags);
657657 if (nlh == NULL)
658658 goto nlmsg_failure;
@@ -1983,7 +1983,8 @@ ctnetlink_ct_stat_cpu_fill_info(struct sk_buff *skb, u32 portid, u32 seq, · 1324 unmodified lines
19831983 struct nfgenmsg *nfmsg;
19841984 unsigned int flags = portid ? NLM_F_MULTI : 0, event;
19851985
1986− event = (NFNL_SUBSYS_CTNETLINK << 8 | IPCTNL_MSG_CT_GET_STATS_CPU);
1986+ event = nfnl_msg_type(NFNL_SUBSYS_CTNETLINK,
1987+ IPCTNL_MSG_CT_GET_STATS_CPU);
19871988 nlh = nlmsg_put(skb, portid, seq, event, sizeof(*nfmsg), flags);
19881989 if (nlh == NULL)
19891990 goto nlmsg_failure;
@@ -2066,7 +2067,7 @@ ctnetlink_stat_ct_fill_info(struct sk_buff *skb, u32 portid, u32 seq, u32 type, · 76 unmodified lines
20662067 unsigned int flags = portid ? NLM_F_MULTI : 0, event;
20672068 unsigned int nr_conntracks = atomic_read(&net->ct.count);
20682069
2069− event = (NFNL_SUBSYS_CTNETLINK << 8 | IPCTNL_MSG_CT_GET_STATS);
2070+ event = nfnl_msg_type(NFNL_SUBSYS_CTNETLINK, IPCTNL_MSG_CT_GET_STATS);
20702071 nlh = nlmsg_put(skb, portid, seq, event, sizeof(*nfmsg), flags);
20712072 if (nlh == NULL)
20722073 goto nlmsg_failure;
@@ -2576,7 +2577,7 @@ ctnetlink_exp_fill_info(struct sk_buff *skb, u32 portid, u32 seq, · 503 unmodified lines
25762577 struct nfgenmsg *nfmsg;
25772578 unsigned int flags = portid ? NLM_F_MULTI : 0;
25782579
2579− event |= NFNL_SUBSYS_CTNETLINK_EXP << 8;
2580+ event = nfnl_msg_type(NFNL_SUBSYS_CTNETLINK_EXP, event);
25802581 nlh = nlmsg_put(skb, portid, seq, event, sizeof(*nfmsg), flags);
25812582 if (nlh == NULL)
25822583 goto nlmsg_failure;
@@ -2627,7 +2628,7 @@ ctnetlink_expect_event(unsigned int events, struct nf_exp_event *item) · 44 unmodified lines
26272628 if (skb == NULL)
26282629 goto errout;
26292630
2630− type |= NFNL_SUBSYS_CTNETLINK_EXP << 8;
2631+ type = nfnl_msg_type(NFNL_SUBSYS_CTNETLINK_EXP, type);
26312632 nlh = nlmsg_put(skb, item->portid, 0, type, sizeof(*nfmsg), flags);
26322633 if (nlh == NULL)
26332634 goto nlmsg_failure;
@@ -3212,7 +3213,8 @@ ctnetlink_exp_stat_fill_info(struct sk_buff *skb, u32 portid, u32 seq, int cpu, · 578 unmodified lines
32123213 struct nfgenmsg *nfmsg;
32133214 unsigned int flags = portid ? NLM_F_MULTI : 0, event;
32143215
3215− event = (NFNL_SUBSYS_CTNETLINK << 8 | IPCTNL_MSG_EXP_GET_STATS_CPU);
3216+ event = nfnl_msg_type(NFNL_SUBSYS_CTNETLINK,
3217+ IPCTNL_MSG_EXP_GET_STATS_CPU);
32163218 nlh = nlmsg_put(skb, portid, seq, event, sizeof(*nfmsg), flags);
32173219 if (nlh == NULL)
32183220 goto nlmsg_failure;
net/netfilter/nf_tables_api.c+9−11
@@ -438,7 +438,7 @@ static int nf_tables_fill_table_info(struct sk_buff *skb, struct net *net, · 437 unmodified lines
438438 struct nlmsghdr *nlh;
439439 struct nfgenmsg *nfmsg;
440440
441− event |= NFNL_SUBSYS_NFTABLES << 8;
441+ event = nfnl_msg_type(NFNL_SUBSYS_NFTABLES, event);
442442 nlh = nlmsg_put(skb, portid, seq, event, sizeof(struct nfgenmsg), flags);
443443 if (nlh == NULL)
444444 goto nla_put_failure;
@@ -989,7 +989,7 @@ static int nf_tables_fill_chain_info(struct sk_buff *skb, struct net *net, · 544 unmodified lines
989989 struct nlmsghdr *nlh;
990990 struct nfgenmsg *nfmsg;
991991
992− event |= NFNL_SUBSYS_NFTABLES << 8;
992+ event = nfnl_msg_type(NFNL_SUBSYS_NFTABLES, event);
993993 nlh = nlmsg_put(skb, portid, seq, event, sizeof(struct nfgenmsg), flags);
994994 if (nlh == NULL)
995995 goto nla_put_failure;
@@ -1885,10 +1885,9 @@ static int nf_tables_fill_rule_info(struct sk_buff *skb, struct net *net, · 889 unmodified lines
18851885 const struct nft_expr *expr, *next;
18861886 struct nlattr *list;
18871887 const struct nft_rule *prule;
1888− int type = event | NFNL_SUBSYS_NFTABLES << 8;
1888+ u16 type = nfnl_msg_type(NFNL_SUBSYS_NFTABLES, event);
18891889
1890− nlh = nlmsg_put(skb, portid, seq, type, sizeof(struct nfgenmsg),
1891− flags);
1890+ nlh = nlmsg_put(skb, portid, seq, type, sizeof(struct nfgenmsg), flags);
18921891 if (nlh == NULL)
18931892 goto nla_put_failure;
18941893
@@ -2645,7 +2644,7 @@ static int nf_tables_fill_set(struct sk_buff *skb, const struct nft_ctx *ctx, · 750 unmodified lines
26452644 u32 portid = ctx->portid;
26462645 u32 seq = ctx->seq;
26472646
2648− event |= NFNL_SUBSYS_NFTABLES << 8;
2647+ event = nfnl_msg_type(NFNL_SUBSYS_NFTABLES, event);
26492648 nlh = nlmsg_put(skb, portid, seq, event, sizeof(struct nfgenmsg),
26502649 flags);
26512650 if (nlh == NULL)
@@ -3395,8 +3394,7 @@ static int nf_tables_dump_set(struct sk_buff *skb, struct netlink_callback *cb) · 743 unmodified lines
33953394 if (IS_ERR(set))
33963395 return PTR_ERR(set);
33973396
3398− event = NFT_MSG_NEWSETELEM;
3399− event |= NFNL_SUBSYS_NFTABLES << 8;
3397+ event = nfnl_msg_type(NFNL_SUBSYS_NFTABLES, NFT_MSG_NEWSETELEM);
34003398 portid = NETLINK_CB(cb->skb).portid;
34013399 seq = cb->nlh->nlmsg_seq;
34023400
@@ -3481,7 +3479,7 @@ static int nf_tables_fill_setelem_info(struct sk_buff *skb, · 78 unmodified lines
34813479 struct nlattr *nest;
34823480 int err;
34833481
3484− event |= NFNL_SUBSYS_NFTABLES << 8;
3482+ event = nfnl_msg_type(NFNL_SUBSYS_NFTABLES, event);
34853483 nlh = nlmsg_put(skb, portid, seq, event, sizeof(struct nfgenmsg),
34863484 flags);
34873485 if (nlh == NULL)
@@ -4253,7 +4251,7 @@ static int nf_tables_fill_obj_info(struct sk_buff *skb, struct net *net, · 765 unmodified lines
42534251 struct nfgenmsg *nfmsg;
42544252 struct nlmsghdr *nlh;
42554253
4256− event |= NFNL_SUBSYS_NFTABLES << 8;
4254+ event = nfnl_msg_type(NFNL_SUBSYS_NFTABLES, event);
42574255 nlh = nlmsg_put(skb, portid, seq, event, sizeof(struct nfgenmsg), flags);
42584256 if (nlh == NULL)
42594257 goto nla_put_failure;
@@ -4526,7 +4524,7 @@ static int nf_tables_fill_gen_info(struct sk_buff *skb, struct net *net, · 266 unmodified lines
45264524 {
45274525 struct nlmsghdr *nlh;
45284526 struct nfgenmsg *nfmsg;
4529− int event = (NFNL_SUBSYS_NFTABLES << 8) | NFT_MSG_NEWGEN;
4527+ int event = nfnl_msg_type(NFNL_SUBSYS_NFTABLES, NFT_MSG_NEWGEN);
45304528
45314529 nlh = nlmsg_put(skb, portid, seq, event, sizeof(struct nfgenmsg), 0);
45324530 if (nlh == NULL)
net/netfilter/nf_tables_trace.c+2−1
@@ -169,7 +169,7 @@ void nft_trace_notify(struct nft_traceinfo *info) · 168 unmodified lines
169169 struct nlmsghdr *nlh;
170170 struct sk_buff *skb;
171171 unsigned int size;
172− int event = (NFNL_SUBSYS_NFTABLES << 8) | NFT_MSG_TRACE;
172+ u16 event;
173173
174174 if (!nfnetlink_has_listeners(nft_net(pkt), NFNLGRP_NFTRACE))
175175 return;
@@ -198,6 +198,7 @@ void nft_trace_notify(struct nft_traceinfo *info) · 22 unmodified lines
198198 if (!skb)
199199 return;
200200
201+ event = nfnl_msg_type(NFNL_SUBSYS_NFTABLES, NFT_MSG_TRACE);
201202 nlh = nlmsg_put(skb, 0, 0, event, sizeof(struct nfgenmsg), 0);
202203 if (!nlh)
203204 goto nla_put_failure;
net/netfilter/nfnetlink_acct.c+1−1
@@ -139,7 +139,7 @@ nfnl_acct_fill_info(struct sk_buff *skb, u32 portid, u32 seq, u32 type, · 138 unmodified lines
139139 u64 pkts, bytes;
140140 u32 old_flags;
141141
142− event |= NFNL_SUBSYS_ACCT << 8;
142+ event = nfnl_msg_type(NFNL_SUBSYS_ACCT, event);
143143 nlh = nlmsg_put(skb, portid, seq, event, sizeof(*nfmsg), flags);
144144 if (nlh == NULL)
145145 goto nlmsg_failure;
net/netfilter/nfnetlink_cthelper.c+1−1
@@ -507,7 +507,7 @@ nfnl_cthelper_fill_info(struct sk_buff *skb, u32 portid, u32 seq, u32 type, · 506 unmodified lines
507507 unsigned int flags = portid ? NLM_F_MULTI : 0;
508508 int status;
509509
510− event |= NFNL_SUBSYS_CTHELPER << 8;
510+ event = nfnl_msg_type(NFNL_SUBSYS_CTHELPER, event);
511511 nlh = nlmsg_put(skb, portid, seq, event, sizeof(*nfmsg), flags);
512512 if (nlh == NULL)
513513 goto nlmsg_failure;
net/netfilter/nfnetlink_cttimeout.c+2−2
@@ -158,7 +158,7 @@ ctnl_timeout_fill_info(struct sk_buff *skb, u32 portid, u32 seq, u32 type, · 157 unmodified lines
158158 unsigned int flags = portid ? NLM_F_MULTI : 0;
159159 struct nf_conntrack_l4proto *l4proto = timeout->l4proto;
160160
161− event |= NFNL_SUBSYS_CTNETLINK_TIMEOUT << 8;
161+ event = nfnl_msg_type(NFNL_SUBSYS_CTNETLINK_TIMEOUT, event);
162162 nlh = nlmsg_put(skb, portid, seq, event, sizeof(*nfmsg), flags);
163163 if (nlh == NULL)
164164 goto nlmsg_failure;
@@ -431,7 +431,7 @@ cttimeout_default_fill_info(struct net *net, struct sk_buff *skb, u32 portid, · 266 unmodified lines
431431 struct nfgenmsg *nfmsg;
432432 unsigned int flags = portid ? NLM_F_MULTI : 0;
433433
434− event |= NFNL_SUBSYS_CTNETLINK_TIMEOUT << 8;
434+ event = nfnl_msg_type(NFNL_SUBSYS_CTNETLINK_TIMEOUT, event);
435435 nlh = nlmsg_put(skb, portid, seq, event, sizeof(*nfmsg), flags);
436436 if (nlh == NULL)
437437 goto nlmsg_failure;
net/netfilter/nfnetlink_log.c+1−1
@@ -411,7 +411,7 @@ __build_packet_message(struct nfnl_log_net *log, · 410 unmodified lines
411411 const unsigned char *hwhdrp;
412412
413413 nlh = nlmsg_put(inst->skb, 0, 0,
414− NFNL_SUBSYS_ULOG << 8 | NFULNL_MSG_PACKET,
414+ nfnl_msg_type(NFNL_SUBSYS_ULOG, NFULNL_MSG_PACKET),
415415 sizeof(struct nfgenmsg), 0);
416416 if (!nlh)
417417 return -1;
net/netfilter/nfnetlink_queue.c+1−1
@@ -447,7 +447,7 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue, · 446 unmodified lines
447447 }
448448
449449 nlh = nlmsg_put(skb, 0, 0,
450− NFNL_SUBSYS_QUEUE << 8 | NFQNL_MSG_PACKET,
450+ nfnl_msg_type(NFNL_SUBSYS_QUEUE, NFQNL_MSG_PACKET),
451451 sizeof(struct nfgenmsg), 0);
452452 if (!nlh) {
453453 skb_tx_error(entskb);
net/netfilter/nft_compat.c+1−1
@@ -504,7 +504,7 @@ nfnl_compat_fill_info(struct sk_buff *skb, u32 portid, u32 seq, u32 type, · 503 unmodified lines
504504 struct nfgenmsg *nfmsg;
505505 unsigned int flags = portid ? NLM_F_MULTI : 0;
506506
507− event |= NFNL_SUBSYS_NFT_COMPAT << 8;
507+ event = nfnl_msg_type(NFNL_SUBSYS_NFT_COMPAT, event);
508508 nlh = nlmsg_put(skb, portid, seq, event, sizeof(*nfmsg), flags);
509509 if (nlh == NULL)
510510 goto nlmsg_failure;