History

Merge git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf

Pablo Neira Ayuso says: ==================== Netfilter fixes for net The following patchset contains Netfilter fixes for net: 1) Wait for rcu grace period after releasing netns in ctnetlink, from Florian Westphal. 2) Incorrect command type in flowtable offload ndo invocation, from wenxu. 3) Incorrect callback type in flowtable offload flow tuple updates, also from wenxu. 4) Fix compile warning on flowtable offload infrastructure due to possible reference to uninitialized variable, from Nathan Chancellor. 5) Do not inline nf_ct_resolve_clash(), this is called from slow path / stress situations. From Florian Westphal. 6) Missing IPv6 flow selector description in flowtable offload. 7) Missing check for NETDEV_UNREGISTER in nf_tables offload infrastructure, from wenxu. 8) Update NAT selftest to use randomized netns names, from Florian Westphal. 9) Restore nfqueue bridge support, from Marco Oliverio. 10) Compilation warning in SCTP_CHUNKMAP_*() on xt_sctp header. From Phil Sutter. 11) Fix bogus lookup/get match for non-anonymous rbtree sets. 12) Missing netlink validation for NFT_SET_ELEM_INTERVAL_END elements. 13) Missing netlink validation for NFT_DATA_VALUE after nft_data_init(). 14) If rule specifies no actions, offload infrastructure returns EOPNOTSUPP. 15) Module refcount leak in object updates. 16) Missing sanitization for ARP traffic from br_netfilter, from Eric Dumazet. 17) Compilation breakage on big-endian due to incorrect memcpy() size in the flowtable offload infrastructure. ====================

David S. Miller committed 6 years ago

Commit 7da538c2 parents f8fc57e 7acd93713 files · +288 −213Browse files

Unified · Split

13 files
  1. include/uapi/linux/netfilter/xt_sctp.h +3 −3
  2. net/bridge/br_netfilter_hooks.c +3 −0
  3. net/netfilter/nf_conntrack_core.c +4 −3
  4. net/netfilter/nf_conntrack_netlink.c +3 −0
  5. net/netfilter/nf_flow_table_offload.c +45 −38
  6. net/netfilter/nf_queue.c +1 −1
  7. net/netfilter/nf_tables_api.c +13 −5
  8. net/netfilter/nf_tables_offload.c +6 −0
  9. net/netfilter/nft_bitwise.c +2 −2
  10. net/netfilter/nft_cmp.c +6 −0
  11. net/netfilter/nft_range.c +10 −0
  12. net/netfilter/nft_set_rbtree.c +16 −5
  13. tools/testing/selftests/netfilter/nft_nat.sh +176 −156
include/uapi/linux/netfilter/xt_sctp.h+3−3
@@ -41,19 +41,19 @@ struct xt_sctp_info { · 40 unmodified lines
4141 #define SCTP_CHUNKMAP_SET(chunkmap, type) \
4242 do { \
4343 (chunkmap)[type / bytes(__u32)] |= \
44− 1 << (type % bytes(__u32)); \
44+ 1u << (type % bytes(__u32)); \
4545 } while (0)
4646
4747 #define SCTP_CHUNKMAP_CLEAR(chunkmap, type) \
4848 do { \
4949 (chunkmap)[type / bytes(__u32)] &= \
50− ~(1 << (type % bytes(__u32))); \
50+ ~(1u << (type % bytes(__u32))); \
5151 } while (0)
5252
5353 #define SCTP_CHUNKMAP_IS_SET(chunkmap, type) \
5454 ({ \
5555 ((chunkmap)[type / bytes (__u32)] & \
56− (1 << (type % bytes (__u32)))) ? 1: 0; \
56+ (1u << (type % bytes (__u32)))) ? 1: 0; \
5757 })
5858
5959 #define SCTP_CHUNKMAP_RESET(chunkmap) \
net/bridge/br_netfilter_hooks.c+3−0
@@ -662,6 +662,9 @@ static unsigned int br_nf_forward_arp(void *priv, · 661 unmodified lines
662662 nf_bridge_pull_encap_header(skb);
663663 }
664664
665+ if (unlikely(!pskb_may_pull(skb, sizeof(struct arphdr))))
666+ return NF_DROP;
667+
665668 if (arp_hdr(skb)->ar_pln != 4) {
666669 if (is_vlan_arp(skb, state->net))
667670 nf_bridge_push_encap_header(skb);
net/netfilter/nf_conntrack_core.c+4−3
@@ -895,9 +895,10 @@ static void nf_ct_acct_merge(struct nf_conn *ct, enum ip_conntrack_info ctinfo, · 894 unmodified lines
895895 }
896896
897897 /* Resolve race on insertion if this protocol allows this. */
898−static int nf_ct_resolve_clash(struct net *net, struct sk_buff *skb,
899− enum ip_conntrack_info ctinfo,
900− struct nf_conntrack_tuple_hash *h)
898+static __cold noinline int
899+nf_ct_resolve_clash(struct net *net, struct sk_buff *skb,
900+ enum ip_conntrack_info ctinfo,
901+ struct nf_conntrack_tuple_hash *h)
901902 {
902903 /* This is the conntrack entry already in hashes that won race. */
903904 struct nf_conn *ct = nf_ct_tuplehash_to_ctrack(h);
net/netfilter/nf_conntrack_netlink.c+3−0
@@ -3626,6 +3626,9 @@ static void __net_exit ctnetlink_net_exit_batch(struct list_head *net_exit_list) · 3625 unmodified lines
36263626
36273627 list_for_each_entry(net, net_exit_list, exit_list)
36283628 ctnetlink_net_exit(net);
3629+
3630+ /* wait for other cpus until they are done with ctnl_notifiers */
3631+ synchronize_rcu();
36293632 }
36303633
36313634 static struct pernet_operations ctnetlink_net_ops = {
net/netfilter/nf_flow_table_offload.c+45−38
@@ -28,6 +28,7 @@ struct nf_flow_key { · 27 unmodified lines
2828 struct flow_dissector_key_basic basic;
2929 union {
3030 struct flow_dissector_key_ipv4_addrs ipv4;
31+ struct flow_dissector_key_ipv6_addrs ipv6;
3132 };
3233 struct flow_dissector_key_tcp tcp;
3334 struct flow_dissector_key_ports tp;
@@ -57,6 +58,7 @@ static int nf_flow_rule_match(struct nf_flow_match *match, · 23 unmodified lines
5758 NF_FLOW_DISSECTOR(match, FLOW_DISSECTOR_KEY_CONTROL, control);
5859 NF_FLOW_DISSECTOR(match, FLOW_DISSECTOR_KEY_BASIC, basic);
5960 NF_FLOW_DISSECTOR(match, FLOW_DISSECTOR_KEY_IPV4_ADDRS, ipv4);
61+ NF_FLOW_DISSECTOR(match, FLOW_DISSECTOR_KEY_IPV6_ADDRS, ipv6);
6062 NF_FLOW_DISSECTOR(match, FLOW_DISSECTOR_KEY_TCP, tcp);
6163 NF_FLOW_DISSECTOR(match, FLOW_DISSECTOR_KEY_PORTS, tp);
6264
@@ -69,9 +71,18 @@ static int nf_flow_rule_match(struct nf_flow_match *match, · 6 unmodified lines
6971 key->ipv4.dst = tuple->dst_v4.s_addr;
7072 mask->ipv4.dst = 0xffffffff;
7173 break;
74+ case AF_INET6:
75+ key->control.addr_type = FLOW_DISSECTOR_KEY_IPV6_ADDRS;
76+ key->basic.n_proto = htons(ETH_P_IPV6);
77+ key->ipv6.src = tuple->src_v6;
78+ memset(&mask->ipv6.src, 0xff, sizeof(mask->ipv6.src));
79+ key->ipv6.dst = tuple->dst_v6;
80+ memset(&mask->ipv6.dst, 0xff, sizeof(mask->ipv6.dst));
81+ break;
7282 default:
7383 return -EOPNOTSUPP;
7484 }
85+ match->dissector.used_keys |= BIT(key->control.addr_type);
7586 mask->basic.n_proto = 0xffff;
7687
7788 switch (tuple->l4proto) {
@@ -96,14 +107,13 @@ static int nf_flow_rule_match(struct nf_flow_match *match, · 18 unmodified lines
96107
97108 match->dissector.used_keys |= BIT(FLOW_DISSECTOR_KEY_CONTROL) |
98109 BIT(FLOW_DISSECTOR_KEY_BASIC) |
99− BIT(FLOW_DISSECTOR_KEY_IPV4_ADDRS) |
100110 BIT(FLOW_DISSECTOR_KEY_PORTS);
101111 return 0;
102112 }
103113
104114 static void flow_offload_mangle(struct flow_action_entry *entry,
105− enum flow_action_mangle_base htype,
106− u32 offset, u8 *value, u8 *mask)
115+ enum flow_action_mangle_base htype, u32 offset,
116+ const __be32 *value, const __be32 *mask)
107117 {
108118 entry->id = FLOW_ACTION_MANGLE;
109119 entry->mangle.htype = htype;
@@ -140,12 +150,12 @@ static int flow_offload_eth_src(struct net *net, · 30 unmodified lines
140150 memcpy(&val16, dev->dev_addr, 2);
141151 val = val16 << 16;
142152 flow_offload_mangle(entry0, FLOW_ACT_MANGLE_HDR_TYPE_ETH, 4,
143− (u8 *)&val, (u8 *)&mask);
153+ &val, &mask);
144154
145155 mask = ~0xffffffff;
146156 memcpy(&val, dev->dev_addr + 2, 4);
147157 flow_offload_mangle(entry1, FLOW_ACT_MANGLE_HDR_TYPE_ETH, 8,
148− (u8 *)&val, (u8 *)&mask);
158+ &val, &mask);
149159 dev_put(dev);
150160
151161 return 0;
@@ -170,13 +180,13 @@ static int flow_offload_eth_dst(struct net *net, · 18 unmodified lines
170180 mask = ~0xffffffff;
171181 memcpy(&val, n->ha, 4);
172182 flow_offload_mangle(entry0, FLOW_ACT_MANGLE_HDR_TYPE_ETH, 0,
173− (u8 *)&val, (u8 *)&mask);
183+ &val, &mask);
174184
175185 mask = ~0x0000ffff;
176186 memcpy(&val16, n->ha + 4, 2);
177187 val = val16;
178188 flow_offload_mangle(entry1, FLOW_ACT_MANGLE_HDR_TYPE_ETH, 4,
179− (u8 *)&val, (u8 *)&mask);
189+ &val, &mask);
180190 neigh_release(n);
181191
182192 return 0;
@@ -206,7 +216,7 @@ static void flow_offload_ipv4_snat(struct net *net, · 23 unmodified lines
206216 }
207217
208218 flow_offload_mangle(entry, FLOW_ACT_MANGLE_HDR_TYPE_IP4, offset,
209− (u8 *)&addr, (u8 *)&mask);
219+ &addr, &mask);
210220 }
211221
212222 static void flow_offload_ipv4_dnat(struct net *net,
@@ -233,12 +243,12 @@ static void flow_offload_ipv4_dnat(struct net *net, · 20 unmodified lines
233243 }
234244
235245 flow_offload_mangle(entry, FLOW_ACT_MANGLE_HDR_TYPE_IP4, offset,
236− (u8 *)&addr, (u8 *)&mask);
246+ &addr, &mask);
237247 }
238248
239249 static void flow_offload_ipv6_mangle(struct nf_flow_rule *flow_rule,
240250 unsigned int offset,
241− u8 *addr, u8 *mask)
251+ const __be32 *addr, const __be32 *mask)
242252 {
243253 struct flow_action_entry *entry;
244254 int i;
@@ -246,8 +256,7 @@ static void flow_offload_ipv6_mangle(struct nf_flow_rule *flow_rule, · 1 unmodified line
246256 for (i = 0; i < sizeof(struct in6_addr) / sizeof(u32); i += sizeof(u32)) {
247257 entry = flow_action_entry_next(flow_rule);
248258 flow_offload_mangle(entry, FLOW_ACT_MANGLE_HDR_TYPE_IP6,
249− offset + i,
250− &addr[i], mask);
259+ offset + i, &addr[i], mask);
251260 }
252261 }
253262
@@ -257,23 +266,23 @@ static void flow_offload_ipv6_snat(struct net *net, · 3 unmodified lines
257266 struct nf_flow_rule *flow_rule)
258267 {
259268 u32 mask = ~htonl(0xffffffff);
260− const u8 *addr;
269+ const __be32 *addr;
261270 u32 offset;
262271
263272 switch (dir) {
264273 case FLOW_OFFLOAD_DIR_ORIGINAL:
265− addr = flow->tuplehash[FLOW_OFFLOAD_DIR_REPLY].tuple.dst_v6.s6_addr;
274+ addr = flow->tuplehash[FLOW_OFFLOAD_DIR_REPLY].tuple.dst_v6.s6_addr32;
266275 offset = offsetof(struct ipv6hdr, saddr);
267276 break;
268277 case FLOW_OFFLOAD_DIR_REPLY:
269− addr = flow->tuplehash[FLOW_OFFLOAD_DIR_ORIGINAL].tuple.src_v6.s6_addr;
278+ addr = flow->tuplehash[FLOW_OFFLOAD_DIR_ORIGINAL].tuple.src_v6.s6_addr32;
270279 offset = offsetof(struct ipv6hdr, daddr);
271280 break;
272281 default:
273282 return;
274283 }
275284
276− flow_offload_ipv6_mangle(flow_rule, offset, (u8 *)addr, (u8 *)&mask);
285+ flow_offload_ipv6_mangle(flow_rule, offset, addr, &mask);
277286 }
278287
279288 static void flow_offload_ipv6_dnat(struct net *net,
@@ -282,23 +291,23 @@ static void flow_offload_ipv6_dnat(struct net *net, · 2 unmodified lines
282291 struct nf_flow_rule *flow_rule)
283292 {
284293 u32 mask = ~htonl(0xffffffff);
285− const u8 *addr;
294+ const __be32 *addr;
286295 u32 offset;
287296
288297 switch (dir) {
289298 case FLOW_OFFLOAD_DIR_ORIGINAL:
290− addr = flow->tuplehash[FLOW_OFFLOAD_DIR_REPLY].tuple.src_v6.s6_addr;
299+ addr = flow->tuplehash[FLOW_OFFLOAD_DIR_REPLY].tuple.src_v6.s6_addr32;
291300 offset = offsetof(struct ipv6hdr, daddr);
292301 break;
293302 case FLOW_OFFLOAD_DIR_REPLY:
294− addr = flow->tuplehash[FLOW_OFFLOAD_DIR_ORIGINAL].tuple.dst_v6.s6_addr;
303+ addr = flow->tuplehash[FLOW_OFFLOAD_DIR_ORIGINAL].tuple.dst_v6.s6_addr32;
295304 offset = offsetof(struct ipv6hdr, saddr);
296305 break;
297306 default:
298307 return;
299308 }
300309
301− flow_offload_ipv6_mangle(flow_rule, offset, (u8 *)addr, (u8 *)&mask);
310+ flow_offload_ipv6_mangle(flow_rule, offset, addr, &mask);
302311 }
303312
304313 static int flow_offload_l4proto(const struct flow_offload *flow)
@@ -326,25 +335,24 @@ static void flow_offload_port_snat(struct net *net, · 21 unmodified lines
326335 struct nf_flow_rule *flow_rule)
327336 {
328337 struct flow_action_entry *entry = flow_action_entry_next(flow_rule);
329− u32 mask = ~htonl(0xffff0000);
330− __be16 port;
338+ u32 mask = ~htonl(0xffff0000), port;
331339 u32 offset;
332340
333341 switch (dir) {
334342 case FLOW_OFFLOAD_DIR_ORIGINAL:
335− port = flow->tuplehash[FLOW_OFFLOAD_DIR_REPLY].tuple.dst_port;
343+ port = ntohs(flow->tuplehash[FLOW_OFFLOAD_DIR_REPLY].tuple.dst_port);
336344 offset = 0; /* offsetof(struct tcphdr, source); */
337345 break;
338346 case FLOW_OFFLOAD_DIR_REPLY:
339− port = flow->tuplehash[FLOW_OFFLOAD_DIR_ORIGINAL].tuple.src_port;
347+ port = ntohs(flow->tuplehash[FLOW_OFFLOAD_DIR_ORIGINAL].tuple.src_port);
340348 offset = 0; /* offsetof(struct tcphdr, dest); */
341349 break;
342350 default:
343− break;
351+ return;
344352 }
345−
353+ port = htonl(port << 16);
346354 flow_offload_mangle(entry, flow_offload_l4proto(flow), offset,
347− (u8 *)&port, (u8 *)&mask);
355+ &port, &mask);
348356 }
349357
350358 static void flow_offload_port_dnat(struct net *net,
@@ -353,25 +361,24 @@ static void flow_offload_port_dnat(struct net *net, · 2 unmodified lines
353361 struct nf_flow_rule *flow_rule)
354362 {
355363 struct flow_action_entry *entry = flow_action_entry_next(flow_rule);
356− u32 mask = ~htonl(0xffff);
357− __be16 port;
364+ u32 mask = ~htonl(0xffff), port;
358365 u32 offset;
359366
360367 switch (dir) {
361368 case FLOW_OFFLOAD_DIR_ORIGINAL:
362− port = flow->tuplehash[FLOW_OFFLOAD_DIR_REPLY].tuple.dst_port;
369+ port = ntohs(flow->tuplehash[FLOW_OFFLOAD_DIR_REPLY].tuple.dst_port);
363370 offset = 0; /* offsetof(struct tcphdr, source); */
364371 break;
365372 case FLOW_OFFLOAD_DIR_REPLY:
366− port = flow->tuplehash[FLOW_OFFLOAD_DIR_ORIGINAL].tuple.src_port;
373+ port = ntohs(flow->tuplehash[FLOW_OFFLOAD_DIR_ORIGINAL].tuple.src_port);
367374 offset = 0; /* offsetof(struct tcphdr, dest); */
368375 break;
369376 default:
370− break;
377+ return;
371378 }
372−
379+ port = htonl(port);
373380 flow_offload_mangle(entry, flow_offload_l4proto(flow), offset,
374− (u8 *)&port, (u8 *)&mask);
381+ &port, &mask);
375382 }
376383
377384 static void flow_offload_ipv4_checksum(struct net *net,
@@ -574,7 +581,7 @@ static int flow_offload_tuple_add(struct flow_offload_work *offload, · 196 unmodified lines
574581 cls_flow.rule = flow_rule->rule;
575582
576583 list_for_each_entry(block_cb, &flowtable->flow_block.cb_list, list) {
577− err = block_cb->cb(TC_SETUP_FT, &cls_flow,
584+ err = block_cb->cb(TC_SETUP_CLSFLOWER, &cls_flow,
578585 block_cb->cb_priv);
579586 if (err < 0)
580587 continue;
@@ -599,7 +606,7 @@ static void flow_offload_tuple_del(struct flow_offload_work *offload, · 18 unmodified lines
599606 &offload->flow->tuplehash[dir].tuple, &extack);
600607
601608 list_for_each_entry(block_cb, &flowtable->flow_block.cb_list, list)
602− block_cb->cb(TC_SETUP_FT, &cls_flow, block_cb->cb_priv);
609+ block_cb->cb(TC_SETUP_CLSFLOWER, &cls_flow, block_cb->cb_priv);
603610
604611 offload->flow->flags |= FLOW_OFFLOAD_HW_DEAD;
605612 }
@@ -656,7 +663,7 @@ static void flow_offload_tuple_stats(struct flow_offload_work *offload, · 50 unmodified lines
656663 &offload->flow->tuplehash[dir].tuple, &extack);
657664
658665 list_for_each_entry(block_cb, &flowtable->flow_block.cb_list, list)
659− block_cb->cb(TC_SETUP_FT, &cls_flow, block_cb->cb_priv);
666+ block_cb->cb(TC_SETUP_CLSFLOWER, &cls_flow, block_cb->cb_priv);
660667 memcpy(stats, &cls_flow.stats, sizeof(*stats));
661668 }
662669
@@ -822,7 +829,7 @@ int nf_flow_table_offload_setup(struct nf_flowtable *flowtable, · 159 unmodified lines
822829 bo.extack = &extack;
823830 INIT_LIST_HEAD(&bo.cb_list);
824831
825− err = dev->netdev_ops->ndo_setup_tc(dev, TC_SETUP_BLOCK, &bo);
832+ err = dev->netdev_ops->ndo_setup_tc(dev, TC_SETUP_FT, &bo);
826833 if (err < 0)
827834 return err;
828835
net/netfilter/nf_queue.c+1−1
@@ -189,7 +189,7 @@ static int __nf_queue(struct sk_buff *skb, const struct nf_hook_state *state, · 188 unmodified lines
189189 goto err;
190190 }
191191
192− if (!skb_dst_force(skb) && state->hook != NF_INET_PRE_ROUTING) {
192+ if (skb_dst(skb) && !skb_dst_force(skb)) {
193193 status = -ENETDOWN;
194194 goto err;
195195 }
net/netfilter/nf_tables_api.c+13−5
@@ -4519,8 +4519,10 @@ static int nft_get_set_elem(struct nft_ctx *ctx, struct nft_set *set, · 4518 unmodified lines
45194519 return err;
45204520
45214521 err = -EINVAL;
4522− if (desc.type != NFT_DATA_VALUE || desc.len != set->klen)
4522+ if (desc.type != NFT_DATA_VALUE || desc.len != set->klen) {
4523+ nft_data_release(&elem.key.val, desc.type);
45234524 return err;
4525+ }
45244526
45254527 priv = set->ops->get(ctx->net, set, &elem, flags);
45264528 if (IS_ERR(priv))
@@ -4756,14 +4758,20 @@ static int nft_add_set_elem(struct nft_ctx *ctx, struct nft_set *set, · 229 unmodified lines
47564758 if (nla[NFTA_SET_ELEM_DATA] == NULL &&
47574759 !(flags & NFT_SET_ELEM_INTERVAL_END))
47584760 return -EINVAL;
4759− if (nla[NFTA_SET_ELEM_DATA] != NULL &&
4760− flags & NFT_SET_ELEM_INTERVAL_END)
4761− return -EINVAL;
47624761 } else {
47634762 if (nla[NFTA_SET_ELEM_DATA] != NULL)
47644763 return -EINVAL;
47654764 }
47664765
4766+ if ((flags & NFT_SET_ELEM_INTERVAL_END) &&
4767+ (nla[NFTA_SET_ELEM_DATA] ||
4768+ nla[NFTA_SET_ELEM_OBJREF] ||
4769+ nla[NFTA_SET_ELEM_TIMEOUT] ||
4770+ nla[NFTA_SET_ELEM_EXPIRATION] ||
4771+ nla[NFTA_SET_ELEM_USERDATA] ||
4772+ nla[NFTA_SET_ELEM_EXPR]))
4773+ return -EINVAL;
4774+
47674775 timeout = 0;
47684776 if (nla[NFTA_SET_ELEM_TIMEOUT] != NULL) {
47694777 if (!(set->flags & NFT_SET_TIMEOUT))
@@ -5476,7 +5484,7 @@ static int nf_tables_newobj(struct net *net, struct sock *nlsk, · 706 unmodified lines
54765484 if (nlh->nlmsg_flags & NLM_F_REPLACE)
54775485 return -EOPNOTSUPP;
54785486
5479− type = nft_obj_type_get(net, objtype);
5487+ type = __nft_obj_type_get(objtype);
54805488 nft_ctx_init(&ctx, net, skb, nlh, family, table, NULL, nla);
54815489
54825490 return nf_tables_updobj(&ctx, type, nla[NFTA_OBJ_DATA], obj);
net/netfilter/nf_tables_offload.c+6−0
@@ -44,6 +44,9 @@ struct nft_flow_rule *nft_flow_rule_create(struct net *net, · 43 unmodified lines
4444 expr = nft_expr_next(expr);
4545 }
4646
47+ if (num_actions == 0)
48+ return ERR_PTR(-EOPNOTSUPP);
49+
4750 flow = nft_flow_rule_alloc(num_actions);
4851 if (!flow)
4952 return ERR_PTR(-ENOMEM);
@@ -577,6 +580,9 @@ static int nft_offload_netdev_event(struct notifier_block *this, · 527 unmodified lines
577580 struct net *net = dev_net(dev);
578581 struct nft_chain *chain;
579582
583+ if (event != NETDEV_UNREGISTER)
584+ return NOTIFY_DONE;
585+
580586 mutex_lock(&net->nft.commit_mutex);
581587 chain = __nft_offload_get_chain(dev);
582588 if (chain)
net/netfilter/nft_bitwise.c+2−2
@@ -80,7 +80,7 @@ static int nft_bitwise_init(const struct nft_ctx *ctx, · 79 unmodified lines
8080 tb[NFTA_BITWISE_MASK]);
8181 if (err < 0)
8282 return err;
83− if (d1.len != priv->len) {
83+ if (d1.type != NFT_DATA_VALUE || d1.len != priv->len) {
8484 err = -EINVAL;
8585 goto err1;
8686 }
@@ -89,7 +89,7 @@ static int nft_bitwise_init(const struct nft_ctx *ctx, · 2 unmodified lines
8989 tb[NFTA_BITWISE_XOR]);
9090 if (err < 0)
9191 goto err1;
92− if (d2.len != priv->len) {
92+ if (d2.type != NFT_DATA_VALUE || d2.len != priv->len) {
9393 err = -EINVAL;
9494 goto err2;
9595 }
net/netfilter/nft_cmp.c+6−0
@@ -81,6 +81,12 @@ static int nft_cmp_init(const struct nft_ctx *ctx, const struct nft_expr *expr, · 80 unmodified lines
8181 if (err < 0)
8282 return err;
8383
84+ if (desc.type != NFT_DATA_VALUE) {
85+ err = -EINVAL;
86+ nft_data_release(&priv->data, desc.type);
87+ return err;
88+ }
89+
8490 priv->sreg = nft_parse_register(tb[NFTA_CMP_SREG]);
8591 err = nft_validate_register_load(priv->sreg, desc.len);
8692 if (err < 0)
net/netfilter/nft_range.c+10−0
@@ -66,11 +66,21 @@ static int nft_range_init(const struct nft_ctx *ctx, const struct nft_expr *expr · 65 unmodified lines
6666 if (err < 0)
6767 return err;
6868
69+ if (desc_from.type != NFT_DATA_VALUE) {
70+ err = -EINVAL;
71+ goto err1;
72+ }
73+
6974 err = nft_data_init(NULL, &priv->data_to, sizeof(priv->data_to),
7075 &desc_to, tb[NFTA_RANGE_TO_DATA]);
7176 if (err < 0)
7277 goto err1;
7378
79+ if (desc_to.type != NFT_DATA_VALUE) {
80+ err = -EINVAL;
81+ goto err2;
82+ }
83+
7484 if (desc_from.len != desc_to.len) {
7585 err = -EINVAL;
7686 goto err2;
net/netfilter/nft_set_rbtree.c+16−5
@@ -74,8 +74,13 @@ static bool __nft_rbtree_lookup(const struct net *net, const struct nft_set *set · 73 unmodified lines
7474 parent = rcu_dereference_raw(parent->rb_left);
7575 continue;
7676 }
77− if (nft_rbtree_interval_end(rbe))
78− goto out;
77+ if (nft_rbtree_interval_end(rbe)) {
78+ if (nft_set_is_anonymous(set))
79+ return false;
80+ parent = rcu_dereference_raw(parent->rb_left);
81+ interval = NULL;
82+ continue;
83+ }
7984
8085 *ext = &rbe->ext;
8186 return true;
@@ -88,7 +93,7 @@ static bool __nft_rbtree_lookup(const struct net *net, const struct nft_set *set · 6 unmodified lines
8893 *ext = &interval->ext;
8994 return true;
9095 }
91−out:
96+
9297 return false;
9398 }
9499
@@ -139,8 +144,10 @@ static bool __nft_rbtree_get(const struct net *net, const struct nft_set *set, · 44 unmodified lines
139144 if (flags & NFT_SET_ELEM_INTERVAL_END)
140145 interval = rbe;
141146 } else {
142− if (!nft_set_elem_active(&rbe->ext, genmask))
147+ if (!nft_set_elem_active(&rbe->ext, genmask)) {
143148 parent = rcu_dereference_raw(parent->rb_left);
149+ continue;
150+ }
144151
145152 if (!nft_set_ext_exists(&rbe->ext, NFT_SET_EXT_FLAGS) ||
146153 (*nft_set_ext_flags(&rbe->ext) & NFT_SET_ELEM_INTERVAL_END) ==
@@ -148,7 +155,11 @@ static bool __nft_rbtree_get(const struct net *net, const struct nft_set *set, · 1 unmodified line
148155 *elem = rbe;
149156 return true;
150157 }
151− return false;
158+
159+ if (nft_rbtree_interval_end(rbe))
160+ interval = NULL;
161+
162+ parent = rcu_dereference_raw(parent->rb_left);
152163 }
153164 }
154165
tools/testing/selftests/netfilter/nft_nat.sh+176−156
@@ -8,9 +8,14 @@ ksft_skip=4 · 7 unmodified lines
88 ret=0
99 test_inet_nat=true
1010
11+sfx=$(mktemp -u "XXXXXXXX")
12+ns0="ns0-$sfx"
13+ns1="ns1-$sfx"
14+ns2="ns2-$sfx"
15+
1116 cleanup()
1217 {
13− for i in 0 1 2; do ip netns del ns$i;done
18+ for i in 0 1 2; do ip netns del ns$i-"$sfx";done
1419 }
1520
1621 nft --version > /dev/null 2>&1
@@ -25,40 +30,49 @@ if [ $? -ne 0 ];then · 8 unmodified lines
2530 exit $ksft_skip
2631 fi
2732
28−ip netns add ns0
33+ip netns add "$ns0"
2934 if [ $? -ne 0 ];then
30− echo "SKIP: Could not create net namespace"
35+ echo "SKIP: Could not create net namespace $ns0"
3136 exit $ksft_skip
3237 fi
3338
3439 trap cleanup EXIT
3540
36−ip netns add ns1
37−ip netns add ns2
41+ip netns add "$ns1"
42+if [ $? -ne 0 ];then
43+ echo "SKIP: Could not create net namespace $ns1"
44+ exit $ksft_skip
45+fi
46+
47+ip netns add "$ns2"
48+if [ $? -ne 0 ];then
49+ echo "SKIP: Could not create net namespace $ns2"
50+ exit $ksft_skip
51+fi
3852
39−ip link add veth0 netns ns0 type veth peer name eth0 netns ns1 > /dev/null 2>&1
53+ip link add veth0 netns "$ns0" type veth peer name eth0 netns "$ns1" > /dev/null 2>&1
4054 if [ $? -ne 0 ];then
4155 echo "SKIP: No virtual ethernet pair device support in kernel"
4256 exit $ksft_skip
4357 fi
44−ip link add veth1 netns ns0 type veth peer name eth0 netns ns2
58+ip link add veth1 netns "$ns0" type veth peer name eth0 netns "$ns2"
4559
46−ip -net ns0 link set lo up
47−ip -net ns0 link set veth0 up
48−ip -net ns0 addr add 10.0.1.1/24 dev veth0
49−ip -net ns0 addr add dead:1::1/64 dev veth0
60+ip -net "$ns0" link set lo up
61+ip -net "$ns0" link set veth0 up
62+ip -net "$ns0" addr add 10.0.1.1/24 dev veth0
63+ip -net "$ns0" addr add dead:1::1/64 dev veth0
5064
51−ip -net ns0 link set veth1 up
52−ip -net ns0 addr add 10.0.2.1/24 dev veth1
53−ip -net ns0 addr add dead:2::1/64 dev veth1
65+ip -net "$ns0" link set veth1 up
66+ip -net "$ns0" addr add 10.0.2.1/24 dev veth1
67+ip -net "$ns0" addr add dead:2::1/64 dev veth1
5468
5569 for i in 1 2; do
56− ip -net ns$i link set lo up
57− ip -net ns$i link set eth0 up
58− ip -net ns$i addr add 10.0.$i.99/24 dev eth0
59− ip -net ns$i route add default via 10.0.$i.1
60− ip -net ns$i addr add dead:$i::99/64 dev eth0
61− ip -net ns$i route add default via dead:$i::1
70+ ip -net ns$i-$sfx link set lo up
71+ ip -net ns$i-$sfx link set eth0 up
72+ ip -net ns$i-$sfx addr add 10.0.$i.99/24 dev eth0
73+ ip -net ns$i-$sfx route add default via 10.0.$i.1
74+ ip -net ns$i-$sfx addr add dead:$i::99/64 dev eth0
75+ ip -net ns$i-$sfx route add default via dead:$i::1
6276 done
6377
6478 bad_counter()
@@ -66,8 +80,9 @@ bad_counter() · 1 unmodified line
6680 local ns=$1
6781 local counter=$2
6882 local expect=$3
83+ local tag=$4
6984
70− echo "ERROR: $counter counter in $ns has unexpected value (expected $expect)" 1>&2
85+ echo "ERROR: $counter counter in $ns has unexpected value (expected $expect) at $tag" 1>&2
7186 ip netns exec $ns nft list counter inet filter $counter 1>&2
7287 }
7388
@@ -78,24 +93,24 @@ check_counters() · 4 unmodified lines
7893
7994 cnt=$(ip netns exec $ns nft list counter inet filter ns0in | grep -q "packets 1 bytes 84")
8095 if [ $? -ne 0 ]; then
81− bad_counter $ns ns0in "packets 1 bytes 84"
96+ bad_counter $ns ns0in "packets 1 bytes 84" "check_counters 1"
8297 lret=1
8398 fi
8499 cnt=$(ip netns exec $ns nft list counter inet filter ns0out | grep -q "packets 1 bytes 84")
85100 if [ $? -ne 0 ]; then
86− bad_counter $ns ns0out "packets 1 bytes 84"
101+ bad_counter $ns ns0out "packets 1 bytes 84" "check_counters 2"
87102 lret=1
88103 fi
89104
90105 expect="packets 1 bytes 104"
91106 cnt=$(ip netns exec $ns nft list counter inet filter ns0in6 | grep -q "$expect")
92107 if [ $? -ne 0 ]; then
93− bad_counter $ns ns0in6 "$expect"
108+ bad_counter $ns ns0in6 "$expect" "check_counters 3"
94109 lret=1
95110 fi
96111 cnt=$(ip netns exec $ns nft list counter inet filter ns0out6 | grep -q "$expect")
97112 if [ $? -ne 0 ]; then
98− bad_counter $ns ns0out6 "$expect"
113+ bad_counter $ns ns0out6 "$expect" "check_counters 4"
99114 lret=1
100115 fi
101116
@@ -107,41 +122,41 @@ check_ns0_counters() · 5 unmodified lines
107122 local ns=$1
108123 local lret=0
109124
110− cnt=$(ip netns exec ns0 nft list counter inet filter ns0in | grep -q "packets 0 bytes 0")
125+ cnt=$(ip netns exec "$ns0" nft list counter inet filter ns0in | grep -q "packets 0 bytes 0")
111126 if [ $? -ne 0 ]; then
112− bad_counter ns0 ns0in "packets 0 bytes 0"
127+ bad_counter "$ns0" ns0in "packets 0 bytes 0" "check_ns0_counters 1"
113128 lret=1
114129 fi
115130
116− cnt=$(ip netns exec ns0 nft list counter inet filter ns0in6 | grep -q "packets 0 bytes 0")
131+ cnt=$(ip netns exec "$ns0" nft list counter inet filter ns0in6 | grep -q "packets 0 bytes 0")
117132 if [ $? -ne 0 ]; then
118− bad_counter ns0 ns0in6 "packets 0 bytes 0"
133+ bad_counter "$ns0" ns0in6 "packets 0 bytes 0"
119134 lret=1
120135 fi
121136
122− cnt=$(ip netns exec ns0 nft list counter inet filter ns0out | grep -q "packets 0 bytes 0")
137+ cnt=$(ip netns exec "$ns0" nft list counter inet filter ns0out | grep -q "packets 0 bytes 0")
123138 if [ $? -ne 0 ]; then
124− bad_counter ns0 ns0out "packets 0 bytes 0"
139+ bad_counter "$ns0" ns0out "packets 0 bytes 0" "check_ns0_counters 2"
125140 lret=1
126141 fi
127− cnt=$(ip netns exec ns0 nft list counter inet filter ns0out6 | grep -q "packets 0 bytes 0")
142+ cnt=$(ip netns exec "$ns0" nft list counter inet filter ns0out6 | grep -q "packets 0 bytes 0")
128143 if [ $? -ne 0 ]; then
129− bad_counter ns0 ns0out6 "packets 0 bytes 0"
144+ bad_counter "$ns0" ns0out6 "packets 0 bytes 0" "check_ns0_counters3 "
130145 lret=1
131146 fi
132147
133148 for dir in "in" "out" ; do
134149 expect="packets 1 bytes 84"
135− cnt=$(ip netns exec ns0 nft list counter inet filter ${ns}${dir} | grep -q "$expect")
150+ cnt=$(ip netns exec "$ns0" nft list counter inet filter ${ns}${dir} | grep -q "$expect")
136151 if [ $? -ne 0 ]; then
137− bad_counter ns0 $ns$dir "$expect"
152+ bad_counter "$ns0" $ns$dir "$expect" "check_ns0_counters 4"
138153 lret=1
139154 fi
140155
141156 expect="packets 1 bytes 104"
142− cnt=$(ip netns exec ns0 nft list counter inet filter ${ns}${dir}6 | grep -q "$expect")
157+ cnt=$(ip netns exec "$ns0" nft list counter inet filter ${ns}${dir}6 | grep -q "$expect")
143158 if [ $? -ne 0 ]; then
144− bad_counter ns0 $ns$dir6 "$expect"
159+ bad_counter "$ns0" $ns$dir6 "$expect" "check_ns0_counters 5"
145160 lret=1
146161 fi
147162 done
@@ -152,7 +167,7 @@ check_ns0_counters() · 4 unmodified lines
152167 reset_counters()
153168 {
154169 for i in 0 1 2;do
155− ip netns exec ns$i nft reset counters inet > /dev/null
170+ ip netns exec ns$i-$sfx nft reset counters inet > /dev/null
156171 done
157172 }
158173
@@ -166,7 +181,7 @@ test_local_dnat6() · 7 unmodified lines
166181 IPF="ip6"
167182 fi
168183
169−ip netns exec ns0 nft -f - <<EOF
184+ip netns exec "$ns0" nft -f /dev/stdin <<EOF
170185 table $family nat {
171186 chain output {
172187 type nat hook output priority 0; policy accept;
@@ -180,7 +195,7 @@ EOF · 7 unmodified lines
180195 fi
181196
182197 # ping netns1, expect rewrite to netns2
183− ip netns exec ns0 ping -q -c 1 dead:1::99 > /dev/null
198+ ip netns exec "$ns0" ping -q -c 1 dead:1::99 > /dev/null
184199 if [ $? -ne 0 ]; then
185200 lret=1
186201 echo "ERROR: ping6 failed"
@@ -189,18 +204,18 @@ EOF · 2 unmodified lines
189204
190205 expect="packets 0 bytes 0"
191206 for dir in "in6" "out6" ; do
192− cnt=$(ip netns exec ns0 nft list counter inet filter ns1${dir} | grep -q "$expect")
207+ cnt=$(ip netns exec "$ns0" nft list counter inet filter ns1${dir} | grep -q "$expect")
193208 if [ $? -ne 0 ]; then
194− bad_counter ns0 ns1$dir "$expect"
209+ bad_counter "$ns0" ns1$dir "$expect" "test_local_dnat6 1"
195210 lret=1
196211 fi
197212 done
198213
199214 expect="packets 1 bytes 104"
200215 for dir in "in6" "out6" ; do
201− cnt=$(ip netns exec ns0 nft list counter inet filter ns2${dir} | grep -q "$expect")
216+ cnt=$(ip netns exec "$ns0" nft list counter inet filter ns2${dir} | grep -q "$expect")
202217 if [ $? -ne 0 ]; then
203− bad_counter ns0 ns2$dir "$expect"
218+ bad_counter "$ns0" ns2$dir "$expect" "test_local_dnat6 2"
204219 lret=1
205220 fi
206221 done
@@ -208,9 +223,9 @@ EOF · 1 unmodified line
208223 # expect 0 count in ns1
209224 expect="packets 0 bytes 0"
210225 for dir in "in6" "out6" ; do
211− cnt=$(ip netns exec ns1 nft list counter inet filter ns0${dir} | grep -q "$expect")
226+ cnt=$(ip netns exec "$ns1" nft list counter inet filter ns0${dir} | grep -q "$expect")
212227 if [ $? -ne 0 ]; then
213− bad_counter ns1 ns0$dir "$expect"
228+ bad_counter "$ns1" ns0$dir "$expect" "test_local_dnat6 3"
214229 lret=1
215230 fi
216231 done
@@ -218,15 +233,15 @@ EOF · 1 unmodified line
218233 # expect 1 packet in ns2
219234 expect="packets 1 bytes 104"
220235 for dir in "in6" "out6" ; do
221− cnt=$(ip netns exec ns2 nft list counter inet filter ns0${dir} | grep -q "$expect")
236+ cnt=$(ip netns exec "$ns2" nft list counter inet filter ns0${dir} | grep -q "$expect")
222237 if [ $? -ne 0 ]; then
223− bad_counter ns2 ns0$dir "$expect"
238+ bad_counter "$ns2" ns0$dir "$expect" "test_local_dnat6 4"
224239 lret=1
225240 fi
226241 done
227242
228− test $lret -eq 0 && echo "PASS: ipv6 ping to ns1 was $family NATted to ns2"
229− ip netns exec ns0 nft flush chain ip6 nat output
243+ test $lret -eq 0 && echo "PASS: ipv6 ping to $ns1 was $family NATted to $ns2"
244+ ip netns exec "$ns0" nft flush chain ip6 nat output
230245
231246 return $lret
232247 }
@@ -241,7 +256,7 @@ test_local_dnat() · 8 unmodified lines
241256 IPF="ip"
242257 fi
243258
244−ip netns exec ns0 nft -f - <<EOF 2>/dev/null
259+ip netns exec "$ns0" nft -f /dev/stdin <<EOF 2>/dev/null
245260 table $family nat {
246261 chain output {
247262 type nat hook output priority 0; policy accept;
@@ -260,7 +275,7 @@ EOF · 12 unmodified lines
260275 fi
261276
262277 # ping netns1, expect rewrite to netns2
263− ip netns exec ns0 ping -q -c 1 10.0.1.99 > /dev/null
278+ ip netns exec "$ns0" ping -q -c 1 10.0.1.99 > /dev/null
264279 if [ $? -ne 0 ]; then
265280 lret=1
266281 echo "ERROR: ping failed"
@@ -269,18 +284,18 @@ EOF · 2 unmodified lines
269284
270285 expect="packets 0 bytes 0"
271286 for dir in "in" "out" ; do
272− cnt=$(ip netns exec ns0 nft list counter inet filter ns1${dir} | grep -q "$expect")
287+ cnt=$(ip netns exec "$ns0" nft list counter inet filter ns1${dir} | grep -q "$expect")
273288 if [ $? -ne 0 ]; then
274− bad_counter ns0 ns1$dir "$expect"
289+ bad_counter "$ns0" ns1$dir "$expect" "test_local_dnat 1"
275290 lret=1
276291 fi
277292 done
278293
279294 expect="packets 1 bytes 84"
280295 for dir in "in" "out" ; do
281− cnt=$(ip netns exec ns0 nft list counter inet filter ns2${dir} | grep -q "$expect")
296+ cnt=$(ip netns exec "$ns0" nft list counter inet filter ns2${dir} | grep -q "$expect")
282297 if [ $? -ne 0 ]; then
283− bad_counter ns0 ns2$dir "$expect"
298+ bad_counter "$ns0" ns2$dir "$expect" "test_local_dnat 2"
284299 lret=1
285300 fi
286301 done
@@ -288,9 +303,9 @@ EOF · 1 unmodified line
288303 # expect 0 count in ns1
289304 expect="packets 0 bytes 0"
290305 for dir in "in" "out" ; do
291− cnt=$(ip netns exec ns1 nft list counter inet filter ns0${dir} | grep -q "$expect")
306+ cnt=$(ip netns exec "$ns1" nft list counter inet filter ns0${dir} | grep -q "$expect")
292307 if [ $? -ne 0 ]; then
293− bad_counter ns1 ns0$dir "$expect"
308+ bad_counter "$ns1" ns0$dir "$expect" "test_local_dnat 3"
294309 lret=1
295310 fi
296311 done
@@ -298,19 +313,19 @@ EOF · 1 unmodified line
298313 # expect 1 packet in ns2
299314 expect="packets 1 bytes 84"
300315 for dir in "in" "out" ; do
301− cnt=$(ip netns exec ns2 nft list counter inet filter ns0${dir} | grep -q "$expect")
316+ cnt=$(ip netns exec "$ns2" nft list counter inet filter ns0${dir} | grep -q "$expect")
302317 if [ $? -ne 0 ]; then
303− bad_counter ns2 ns0$dir "$expect"
318+ bad_counter "$ns2" ns0$dir "$expect" "test_local_dnat 4"
304319 lret=1
305320 fi
306321 done
307322
308− test $lret -eq 0 && echo "PASS: ping to ns1 was $family NATted to ns2"
323+ test $lret -eq 0 && echo "PASS: ping to $ns1 was $family NATted to $ns2"
309324
310− ip netns exec ns0 nft flush chain $family nat output
325+ ip netns exec "$ns0" nft flush chain $family nat output
311326
312327 reset_counters
313− ip netns exec ns0 ping -q -c 1 10.0.1.99 > /dev/null
328+ ip netns exec "$ns0" ping -q -c 1 10.0.1.99 > /dev/null
314329 if [ $? -ne 0 ]; then
315330 lret=1
316331 echo "ERROR: ping failed"
@@ -319,17 +334,17 @@ EOF · 2 unmodified lines
319334
320335 expect="packets 1 bytes 84"
321336 for dir in "in" "out" ; do
322− cnt=$(ip netns exec ns0 nft list counter inet filter ns1${dir} | grep -q "$expect")
337+ cnt=$(ip netns exec "$ns0" nft list counter inet filter ns1${dir} | grep -q "$expect")
323338 if [ $? -ne 0 ]; then
324− bad_counter ns1 ns1$dir "$expect"
339+ bad_counter "$ns1" ns1$dir "$expect" "test_local_dnat 5"
325340 lret=1
326341 fi
327342 done
328343 expect="packets 0 bytes 0"
329344 for dir in "in" "out" ; do
330− cnt=$(ip netns exec ns0 nft list counter inet filter ns2${dir} | grep -q "$expect")
345+ cnt=$(ip netns exec "$ns0" nft list counter inet filter ns2${dir} | grep -q "$expect")
331346 if [ $? -ne 0 ]; then
332− bad_counter ns0 ns2$dir "$expect"
347+ bad_counter "$ns0" ns2$dir "$expect" "test_local_dnat 6"
333348 lret=1
334349 fi
335350 done
@@ -337,9 +352,9 @@ EOF · 1 unmodified line
337352 # expect 1 count in ns1
338353 expect="packets 1 bytes 84"
339354 for dir in "in" "out" ; do
340− cnt=$(ip netns exec ns1 nft list counter inet filter ns0${dir} | grep -q "$expect")
355+ cnt=$(ip netns exec "$ns1" nft list counter inet filter ns0${dir} | grep -q "$expect")
341356 if [ $? -ne 0 ]; then
342− bad_counter ns0 ns0$dir "$expect"
357+ bad_counter "$ns0" ns0$dir "$expect" "test_local_dnat 7"
343358 lret=1
344359 fi
345360 done
@@ -347,14 +362,14 @@ EOF · 1 unmodified line
347362 # expect 0 packet in ns2
348363 expect="packets 0 bytes 0"
349364 for dir in "in" "out" ; do
350− cnt=$(ip netns exec ns2 nft list counter inet filter ns0${dir} | grep -q "$expect")
365+ cnt=$(ip netns exec "$ns2" nft list counter inet filter ns0${dir} | grep -q "$expect")
351366 if [ $? -ne 0 ]; then
352− bad_counter ns2 ns2$dir "$expect"
367+ bad_counter "$ns2" ns0$dir "$expect" "test_local_dnat 8"
353368 lret=1
354369 fi
355370 done
356371
357− test $lret -eq 0 && echo "PASS: ping to ns1 OK after $family nat output chain flush"
372+ test $lret -eq 0 && echo "PASS: ping to $ns1 OK after $family nat output chain flush"
358373
359374 return $lret
360375 }
@@ -366,26 +381,26 @@ test_masquerade6() · 5 unmodified lines
366381 local natflags=$2
367382 local lret=0
368383
369− ip netns exec ns0 sysctl net.ipv6.conf.all.forwarding=1 > /dev/null
384+ ip netns exec "$ns0" sysctl net.ipv6.conf.all.forwarding=1 > /dev/null
370385
371− ip netns exec ns2 ping -q -c 1 dead:1::99 > /dev/null # ping ns2->ns1
386+ ip netns exec "$ns2" ping -q -c 1 dead:1::99 > /dev/null # ping ns2->ns1
372387 if [ $? -ne 0 ] ; then
373− echo "ERROR: cannot ping ns1 from ns2 via ipv6"
388+ echo "ERROR: cannot ping $ns1 from $ns2 via ipv6"
374389 return 1
375390 lret=1
376391 fi
377392
378393 expect="packets 1 bytes 104"
379394 for dir in "in6" "out6" ; do
380− cnt=$(ip netns exec ns1 nft list counter inet filter ns2${dir} | grep -q "$expect")
395+ cnt=$(ip netns exec "$ns1" nft list counter inet filter ns2${dir} | grep -q "$expect")
381396 if [ $? -ne 0 ]; then
382− bad_counter ns1 ns2$dir "$expect"
397+ bad_counter "$ns1" ns2$dir "$expect" "test_masquerade6 1"
383398 lret=1
384399 fi
385400
386− cnt=$(ip netns exec ns2 nft list counter inet filter ns1${dir} | grep -q "$expect")
401+ cnt=$(ip netns exec "$ns2" nft list counter inet filter ns1${dir} | grep -q "$expect")
387402 if [ $? -ne 0 ]; then
388− bad_counter ns2 ns1$dir "$expect"
403+ bad_counter "$ns2" ns1$dir "$expect" "test_masquerade6 2"
389404 lret=1
390405 fi
391406 done
@@ -393,7 +408,7 @@ test_masquerade6() · 1 unmodified line
393408 reset_counters
394409
395410 # add masquerading rule
396−ip netns exec ns0 nft -f - <<EOF
411+ip netns exec "$ns0" nft -f /dev/stdin <<EOF
397412 table $family nat {
398413 chain postrouting {
399414 type nat hook postrouting priority 0; policy accept;
@@ -406,24 +421,24 @@ EOF · 6 unmodified lines
406421 return $ksft_skip
407422 fi
408423
409− ip netns exec ns2 ping -q -c 1 dead:1::99 > /dev/null # ping ns2->ns1
424+ ip netns exec "$ns2" ping -q -c 1 dead:1::99 > /dev/null # ping ns2->ns1
410425 if [ $? -ne 0 ] ; then
411− echo "ERROR: cannot ping ns1 from ns2 with active $family masquerade $natflags"
426+ echo "ERROR: cannot ping $ns1 from $ns2 with active $family masquerade $natflags"
412427 lret=1
413428 fi
414429
415430 # ns1 should have seen packets from ns0, due to masquerade
416431 expect="packets 1 bytes 104"
417432 for dir in "in6" "out6" ; do
418− cnt=$(ip netns exec ns1 nft list counter inet filter ns0${dir} | grep -q "$expect")
433+ cnt=$(ip netns exec "$ns1" nft list counter inet filter ns0${dir} | grep -q "$expect")
419434 if [ $? -ne 0 ]; then
420− bad_counter ns1 ns0$dir "$expect"
435+ bad_counter "$ns1" ns0$dir "$expect" "test_masquerade6 3"
421436 lret=1
422437 fi
423438
424− cnt=$(ip netns exec ns2 nft list counter inet filter ns1${dir} | grep -q "$expect")
439+ cnt=$(ip netns exec "$ns2" nft list counter inet filter ns1${dir} | grep -q "$expect")
425440 if [ $? -ne 0 ]; then
426− bad_counter ns2 ns1$dir "$expect"
441+ bad_counter "$ns2" ns1$dir "$expect" "test_masquerade6 4"
427442 lret=1
428443 fi
429444 done
@@ -431,32 +446,32 @@ EOF · 1 unmodified line
431446 # ns1 should not have seen packets from ns2, due to masquerade
432447 expect="packets 0 bytes 0"
433448 for dir in "in6" "out6" ; do
434− cnt=$(ip netns exec ns1 nft list counter inet filter ns2${dir} | grep -q "$expect")
449+ cnt=$(ip netns exec "$ns1" nft list counter inet filter ns2${dir} | grep -q "$expect")
435450 if [ $? -ne 0 ]; then
436− bad_counter ns1 ns0$dir "$expect"
451+ bad_counter "$ns1" ns0$dir "$expect" "test_masquerade6 5"
437452 lret=1
438453 fi
439454
440− cnt=$(ip netns exec ns1 nft list counter inet filter ns2${dir} | grep -q "$expect")
455+ cnt=$(ip netns exec "$ns0" nft list counter inet filter ns1${dir} | grep -q "$expect")
441456 if [ $? -ne 0 ]; then
442− bad_counter ns2 ns1$dir "$expect"
457+ bad_counter "$ns0" ns1$dir "$expect" "test_masquerade6 6"
443458 lret=1
444459 fi
445460 done
446461
447− ip netns exec ns2 ping -q -c 1 dead:1::99 > /dev/null # ping ns2->ns1
462+ ip netns exec "$ns2" ping -q -c 1 dead:1::99 > /dev/null # ping ns2->ns1
448463 if [ $? -ne 0 ] ; then
449− echo "ERROR: cannot ping ns1 from ns2 with active ipv6 masquerade $natflags (attempt 2)"
464+ echo "ERROR: cannot ping $ns1 from $ns2 with active ipv6 masquerade $natflags (attempt 2)"
450465 lret=1
451466 fi
452467
453− ip netns exec ns0 nft flush chain $family nat postrouting
468+ ip netns exec "$ns0" nft flush chain $family nat postrouting
454469 if [ $? -ne 0 ]; then
455470 echo "ERROR: Could not flush $family nat postrouting" 1>&2
456471 lret=1
457472 fi
458473
459− test $lret -eq 0 && echo "PASS: $family IPv6 masquerade $natflags for ns2"
474+ test $lret -eq 0 && echo "PASS: $family IPv6 masquerade $natflags for $ns2"
460475
461476 return $lret
462477 }
@@ -467,26 +482,26 @@ test_masquerade() · 4 unmodified lines
467482 local natflags=$2
468483 local lret=0
469484
470− ip netns exec ns0 sysctl net.ipv4.conf.veth0.forwarding=1 > /dev/null
471− ip netns exec ns0 sysctl net.ipv4.conf.veth1.forwarding=1 > /dev/null
485+ ip netns exec "$ns0" sysctl net.ipv4.conf.veth0.forwarding=1 > /dev/null
486+ ip netns exec "$ns0" sysctl net.ipv4.conf.veth1.forwarding=1 > /dev/null
472487
473− ip netns exec ns2 ping -q -c 1 10.0.1.99 > /dev/null # ping ns2->ns1
488+ ip netns exec "$ns2" ping -q -c 1 10.0.1.99 > /dev/null # ping ns2->ns1
474489 if [ $? -ne 0 ] ; then
475− echo "ERROR: cannot ping ns1 from ns2 $natflags"
490+ echo "ERROR: cannot ping $ns1 from "$ns2" $natflags"
476491 lret=1
477492 fi
478493
479494 expect="packets 1 bytes 84"
480495 for dir in "in" "out" ; do
481− cnt=$(ip netns exec ns1 nft list counter inet filter ns2${dir} | grep -q "$expect")
496+ cnt=$(ip netns exec "$ns1" nft list counter inet filter ns2${dir} | grep -q "$expect")
482497 if [ $? -ne 0 ]; then
483− bad_counter ns1 ns2$dir "$expect"
498+ bad_counter "$ns1" ns2$dir "$expect" "test_masquerade 1"
484499 lret=1
485500 fi
486501
487− cnt=$(ip netns exec ns2 nft list counter inet filter ns1${dir} | grep -q "$expect")
502+ cnt=$(ip netns exec "$ns2" nft list counter inet filter ns1${dir} | grep -q "$expect")
488503 if [ $? -ne 0 ]; then
489− bad_counter ns2 ns1$dir "$expect"
504+ bad_counter "$ns2" ns1$dir "$expect" "test_masquerade 2"
490505 lret=1
491506 fi
492507 done
@@ -494,7 +509,7 @@ test_masquerade() · 1 unmodified line
494509 reset_counters
495510
496511 # add masquerading rule
497−ip netns exec ns0 nft -f - <<EOF
512+ip netns exec "$ns0" nft -f /dev/stdin <<EOF
498513 table $family nat {
499514 chain postrouting {
500515 type nat hook postrouting priority 0; policy accept;
@@ -507,24 +522,24 @@ EOF · 6 unmodified lines
507522 return $ksft_skip
508523 fi
509524
510− ip netns exec ns2 ping -q -c 1 10.0.1.99 > /dev/null # ping ns2->ns1
525+ ip netns exec "$ns2" ping -q -c 1 10.0.1.99 > /dev/null # ping ns2->ns1
511526 if [ $? -ne 0 ] ; then
512− echo "ERROR: cannot ping ns1 from ns2 with active $family masquerade $natflags"
527+ echo "ERROR: cannot ping $ns1 from $ns2 with active $family masquerade $natflags"
513528 lret=1
514529 fi
515530
516531 # ns1 should have seen packets from ns0, due to masquerade
517532 expect="packets 1 bytes 84"
518533 for dir in "in" "out" ; do
519− cnt=$(ip netns exec ns1 nft list counter inet filter ns0${dir} | grep -q "$expect")
534+ cnt=$(ip netns exec "$ns1" nft list counter inet filter ns0${dir} | grep -q "$expect")
520535 if [ $? -ne 0 ]; then
521− bad_counter ns1 ns0$dir "$expect"
536+ bad_counter "$ns1" ns0$dir "$expect" "test_masquerade 3"
522537 lret=1
523538 fi
524539
525− cnt=$(ip netns exec ns2 nft list counter inet filter ns1${dir} | grep -q "$expect")
540+ cnt=$(ip netns exec "$ns2" nft list counter inet filter ns1${dir} | grep -q "$expect")
526541 if [ $? -ne 0 ]; then
527− bad_counter ns2 ns1$dir "$expect"
542+ bad_counter "$ns2" ns1$dir "$expect" "test_masquerade 4"
528543 lret=1
529544 fi
530545 done
@@ -532,32 +547,32 @@ EOF · 1 unmodified line
532547 # ns1 should not have seen packets from ns2, due to masquerade
533548 expect="packets 0 bytes 0"
534549 for dir in "in" "out" ; do
535− cnt=$(ip netns exec ns1 nft list counter inet filter ns2${dir} | grep -q "$expect")
550+ cnt=$(ip netns exec "$ns1" nft list counter inet filter ns2${dir} | grep -q "$expect")
536551 if [ $? -ne 0 ]; then
537− bad_counter ns1 ns0$dir "$expect"
552+ bad_counter "$ns1" ns0$dir "$expect" "test_masquerade 5"
538553 lret=1
539554 fi
540555
541− cnt=$(ip netns exec ns1 nft list counter inet filter ns2${dir} | grep -q "$expect")
556+ cnt=$(ip netns exec "$ns0" nft list counter inet filter ns1${dir} | grep -q "$expect")
542557 if [ $? -ne 0 ]; then
543− bad_counter ns2 ns1$dir "$expect"
558+ bad_counter "$ns0" ns1$dir "$expect" "test_masquerade 6"
544559 lret=1
545560 fi
546561 done
547562
548− ip netns exec ns2 ping -q -c 1 10.0.1.99 > /dev/null # ping ns2->ns1
563+ ip netns exec "$ns2" ping -q -c 1 10.0.1.99 > /dev/null # ping ns2->ns1
549564 if [ $? -ne 0 ] ; then
550− echo "ERROR: cannot ping ns1 from ns2 with active ip masquerade $natflags (attempt 2)"
565+ echo "ERROR: cannot ping $ns1 from $ns2 with active ip masquerade $natflags (attempt 2)"
551566 lret=1
552567 fi
553568
554− ip netns exec ns0 nft flush chain $family nat postrouting
569+ ip netns exec "$ns0" nft flush chain $family nat postrouting
555570 if [ $? -ne 0 ]; then
556571 echo "ERROR: Could not flush $family nat postrouting" 1>&2
557572 lret=1
558573 fi
559574
560− test $lret -eq 0 && echo "PASS: $family IP masquerade $natflags for ns2"
575+ test $lret -eq 0 && echo "PASS: $family IP masquerade $natflags for $ns2"
561576
562577 return $lret
563578 }
@@ -567,25 +582,25 @@ test_redirect6() · 3 unmodified lines
567582 local family=$1
568583 local lret=0
569584
570− ip netns exec ns0 sysctl net.ipv6.conf.all.forwarding=1 > /dev/null
585+ ip netns exec "$ns0" sysctl net.ipv6.conf.all.forwarding=1 > /dev/null
571586
572− ip netns exec ns2 ping -q -c 1 dead:1::99 > /dev/null # ping ns2->ns1
587+ ip netns exec "$ns2" ping -q -c 1 dead:1::99 > /dev/null # ping ns2->ns1
573588 if [ $? -ne 0 ] ; then
574− echo "ERROR: cannnot ping ns1 from ns2 via ipv6"
589+ echo "ERROR: cannnot ping $ns1 from $ns2 via ipv6"
575590 lret=1
576591 fi
577592
578593 expect="packets 1 bytes 104"
579594 for dir in "in6" "out6" ; do
580− cnt=$(ip netns exec ns1 nft list counter inet filter ns2${dir} | grep -q "$expect")
595+ cnt=$(ip netns exec "$ns1" nft list counter inet filter ns2${dir} | grep -q "$expect")
581596 if [ $? -ne 0 ]; then
582− bad_counter ns1 ns2$dir "$expect"
597+ bad_counter "$ns1" ns2$dir "$expect" "test_redirect6 1"
583598 lret=1
584599 fi
585600
586− cnt=$(ip netns exec ns2 nft list counter inet filter ns1${dir} | grep -q "$expect")
601+ cnt=$(ip netns exec "$ns2" nft list counter inet filter ns1${dir} | grep -q "$expect")
587602 if [ $? -ne 0 ]; then
588− bad_counter ns2 ns1$dir "$expect"
603+ bad_counter "$ns2" ns1$dir "$expect" "test_redirect6 2"
589604 lret=1
590605 fi
591606 done
@@ -593,7 +608,7 @@ test_redirect6() · 1 unmodified line
593608 reset_counters
594609
595610 # add redirect rule
596−ip netns exec ns0 nft -f - <<EOF
611+ip netns exec "$ns0" nft -f /dev/stdin <<EOF
597612 table $family nat {
598613 chain prerouting {
599614 type nat hook prerouting priority 0; policy accept;
@@ -606,18 +621,18 @@ EOF · 6 unmodified lines
606621 return $ksft_skip
607622 fi
608623
609− ip netns exec ns2 ping -q -c 1 dead:1::99 > /dev/null # ping ns2->ns1
624+ ip netns exec "$ns2" ping -q -c 1 dead:1::99 > /dev/null # ping ns2->ns1
610625 if [ $? -ne 0 ] ; then
611− echo "ERROR: cannot ping ns1 from ns2 via ipv6 with active $family redirect"
626+ echo "ERROR: cannot ping $ns1 from $ns2 via ipv6 with active $family redirect"
612627 lret=1
613628 fi
614629
615630 # ns1 should have seen no packets from ns2, due to redirection
616631 expect="packets 0 bytes 0"
617632 for dir in "in6" "out6" ; do
618− cnt=$(ip netns exec ns1 nft list counter inet filter ns2${dir} | grep -q "$expect")
633+ cnt=$(ip netns exec "$ns1" nft list counter inet filter ns2${dir} | grep -q "$expect")
619634 if [ $? -ne 0 ]; then
620− bad_counter ns1 ns0$dir "$expect"
635+ bad_counter "$ns1" ns0$dir "$expect" "test_redirect6 3"
621636 lret=1
622637 fi
623638 done
@@ -625,20 +640,20 @@ EOF · 1 unmodified line
625640 # ns0 should have seen packets from ns2, due to masquerade
626641 expect="packets 1 bytes 104"
627642 for dir in "in6" "out6" ; do
628− cnt=$(ip netns exec ns0 nft list counter inet filter ns2${dir} | grep -q "$expect")
643+ cnt=$(ip netns exec "$ns0" nft list counter inet filter ns2${dir} | grep -q "$expect")
629644 if [ $? -ne 0 ]; then
630− bad_counter ns1 ns0$dir "$expect"
645+ bad_counter "$ns1" ns0$dir "$expect" "test_redirect6 4"
631646 lret=1
632647 fi
633648 done
634649
635− ip netns exec ns0 nft delete table $family nat
650+ ip netns exec "$ns0" nft delete table $family nat
636651 if [ $? -ne 0 ]; then
637652 echo "ERROR: Could not delete $family nat table" 1>&2
638653 lret=1
639654 fi
640655
641− test $lret -eq 0 && echo "PASS: $family IPv6 redirection for ns2"
656+ test $lret -eq 0 && echo "PASS: $family IPv6 redirection for $ns2"
642657
643658 return $lret
644659 }
@@ -648,26 +663,26 @@ test_redirect() · 3 unmodified lines
648663 local family=$1
649664 local lret=0
650665
651− ip netns exec ns0 sysctl net.ipv4.conf.veth0.forwarding=1 > /dev/null
652− ip netns exec ns0 sysctl net.ipv4.conf.veth1.forwarding=1 > /dev/null
666+ ip netns exec "$ns0" sysctl net.ipv4.conf.veth0.forwarding=1 > /dev/null
667+ ip netns exec "$ns0" sysctl net.ipv4.conf.veth1.forwarding=1 > /dev/null
653668
654− ip netns exec ns2 ping -q -c 1 10.0.1.99 > /dev/null # ping ns2->ns1
669+ ip netns exec "$ns2" ping -q -c 1 10.0.1.99 > /dev/null # ping ns2->ns1
655670 if [ $? -ne 0 ] ; then
656− echo "ERROR: cannot ping ns1 from ns2"
671+ echo "ERROR: cannot ping $ns1 from $ns2"
657672 lret=1
658673 fi
659674
660675 expect="packets 1 bytes 84"
661676 for dir in "in" "out" ; do
662− cnt=$(ip netns exec ns1 nft list counter inet filter ns2${dir} | grep -q "$expect")
677+ cnt=$(ip netns exec "$ns1" nft list counter inet filter ns2${dir} | grep -q "$expect")
663678 if [ $? -ne 0 ]; then
664− bad_counter ns1 ns2$dir "$expect"
679+ bad_counter "$ns1" $ns2$dir "$expect" "test_redirect 1"
665680 lret=1
666681 fi
667682
668− cnt=$(ip netns exec ns2 nft list counter inet filter ns1${dir} | grep -q "$expect")
683+ cnt=$(ip netns exec "$ns2" nft list counter inet filter ns1${dir} | grep -q "$expect")
669684 if [ $? -ne 0 ]; then
670− bad_counter ns2 ns1$dir "$expect"
685+ bad_counter "$ns2" ns1$dir "$expect" "test_redirect 2"
671686 lret=1
672687 fi
673688 done
@@ -675,7 +690,7 @@ test_redirect() · 1 unmodified line
675690 reset_counters
676691
677692 # add redirect rule
678−ip netns exec ns0 nft -f - <<EOF
693+ip netns exec "$ns0" nft -f /dev/stdin <<EOF
679694 table $family nat {
680695 chain prerouting {
681696 type nat hook prerouting priority 0; policy accept;
@@ -688,9 +703,9 @@ EOF · 6 unmodified lines
688703 return $ksft_skip
689704 fi
690705
691− ip netns exec ns2 ping -q -c 1 10.0.1.99 > /dev/null # ping ns2->ns1
706+ ip netns exec "$ns2" ping -q -c 1 10.0.1.99 > /dev/null # ping ns2->ns1
692707 if [ $? -ne 0 ] ; then
693− echo "ERROR: cannot ping ns1 from ns2 with active $family ip redirect"
708+ echo "ERROR: cannot ping $ns1 from $ns2 with active $family ip redirect"
694709 lret=1
695710 fi
696711
@@ -698,9 +713,9 @@ EOF · 1 unmodified line
698713 expect="packets 0 bytes 0"
699714 for dir in "in" "out" ; do
700715
701− cnt=$(ip netns exec ns1 nft list counter inet filter ns2${dir} | grep -q "$expect")
716+ cnt=$(ip netns exec "$ns1" nft list counter inet filter ns2${dir} | grep -q "$expect")
702717 if [ $? -ne 0 ]; then
703− bad_counter ns1 ns0$dir "$expect"
718+ bad_counter "$ns1" ns0$dir "$expect" "test_redirect 3"
704719 lret=1
705720 fi
706721 done
@@ -708,28 +723,28 @@ EOF · 1 unmodified line
708723 # ns0 should have seen packets from ns2, due to masquerade
709724 expect="packets 1 bytes 84"
710725 for dir in "in" "out" ; do
711− cnt=$(ip netns exec ns0 nft list counter inet filter ns2${dir} | grep -q "$expect")
726+ cnt=$(ip netns exec "$ns0" nft list counter inet filter ns2${dir} | grep -q "$expect")
712727 if [ $? -ne 0 ]; then
713− bad_counter ns1 ns0$dir "$expect"
728+ bad_counter "$ns0" ns0$dir "$expect" "test_redirect 4"
714729 lret=1
715730 fi
716731 done
717732
718− ip netns exec ns0 nft delete table $family nat
733+ ip netns exec "$ns0" nft delete table $family nat
719734 if [ $? -ne 0 ]; then
720735 echo "ERROR: Could not delete $family nat table" 1>&2
721736 lret=1
722737 fi
723738
724− test $lret -eq 0 && echo "PASS: $family IP redirection for ns2"
739+ test $lret -eq 0 && echo "PASS: $family IP redirection for $ns2"
725740
726741 return $lret
727742 }
728743
729744
730−# ip netns exec ns0 ping -c 1 -q 10.0.$i.99
745+# ip netns exec "$ns0" ping -c 1 -q 10.0.$i.99
731746 for i in 0 1 2; do
732−ip netns exec ns$i nft -f - <<EOF
747+ip netns exec ns$i-$sfx nft -f /dev/stdin <<EOF
733748 table inet filter {
734749 counter ns0in {}
735750 counter ns1in {}
@@ -796,18 +811,18 @@ done · 60 unmodified lines
796811 sleep 3
797812 # test basic connectivity
798813 for i in 1 2; do
799− ip netns exec ns0 ping -c 1 -q 10.0.$i.99 > /dev/null
814+ ip netns exec "$ns0" ping -c 1 -q 10.0.$i.99 > /dev/null
800815 if [ $? -ne 0 ];then
801816 echo "ERROR: Could not reach other namespace(s)" 1>&2
802817 ret=1
803818 fi
804819
805− ip netns exec ns0 ping -c 1 -q dead:$i::99 > /dev/null
820+ ip netns exec "$ns0" ping -c 1 -q dead:$i::99 > /dev/null
806821 if [ $? -ne 0 ];then
807822 echo "ERROR: Could not reach other namespace(s) via ipv6" 1>&2
808823 ret=1
809824 fi
810− check_counters ns$i
825+ check_counters ns$i-$sfx
811826 if [ $? -ne 0 ]; then
812827 ret=1
813828 fi
@@ -820,7 +835,7 @@ for i in 1 2; do · 6 unmodified lines
820835 done
821836
822837 if [ $ret -eq 0 ];then
823− echo "PASS: netns routing/connectivity: ns0 can reach ns1 and ns2"
838+ echo "PASS: netns routing/connectivity: $ns0 can reach $ns1 and $ns2"
824839 fi
825840
826841 reset_counters
@@ -846,4 +861,9 @@ reset_counters · 19 unmodified lines
846861 $test_inet_nat && test_redirect inet
847862 $test_inet_nat && test_redirect6 inet
848863
864+if [ $ret -ne 0 ];then
865+ echo -n "FAIL: "
866+ nft --version
867+fi
868+
849869 exit $ret

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t