Skip to content

Commit 0fb4d21

Browse files
wenxuummakynes
authored andcommitted
netfilter: nft_meta: Add NFT_META_I/OIFKIND meta type
In the ip_rcv the skb goes through the PREROUTING hook first, then kicks in vrf device and go through the same hook again. When conntrack dnat works with vrf, there will be some conflict with rules because the packet goes through the hook twice with different nf status. ip link add user1 type vrf table 1 ip link add user2 type vrf table 2 ip l set dev tun1 master user1 ip l set dev tun2 master user2 nft add table firewall nft add chain firewall zones { type filter hook prerouting priority - 300 \; } nft add rule firewall zones counter ct zone set iif map { "tun1" : 1, "tun2" : 2 } nft add chain firewall rule-1000-ingress nft add rule firewall rule-1000-ingress ct zone 1 tcp dport 22 ct state new counter accept nft add rule firewall rule-1000-ingress counter drop nft add chain firewall rule-1000-egress nft add rule firewall rule-1000-egress tcp dport 22 ct state new counter drop nft add rule firewall rule-1000-egress counter accept nft add chain firewall rules-all { type filter hook prerouting priority - 150 \; } nft add rule firewall rules-all ip daddr vmap { "2.2.2.11" : jump rule-1000-ingress } nft add rule firewall rules-all ct zone vmap { 1 : jump rule-1000-egress } nft add rule firewall dnat-all ct zone vmap { 1 : jump dnat-1000 } nft add rule firewall dnat-1000 ip daddr 2.2.2.11 counter dnat to 10.0.0.7 For a package with ip daddr 2.2.2.11 and tcp dport 22, first time accept in the rule-1000-ingress and dnat to 10.0.0.7. Then second time the packet goto the wrong chain rule-1000-egress which leads the packet drop With this patch, userspace can add the 'don't re-do entire ruleset for vrf' policy itself via: nft add rule firewall rules-all meta iifkind "vrf" counter accept Signed-off-by: wenxu <wenxu@ucloud.cn> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent ba3fbe6 commit 0fb4d21

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

‎include/uapi/linux/netfilter/nf_tables.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,8 @@ enum nft_exthdr_attributes {
791791
* @NFT_META_CGROUP: socket control group (skb->sk->sk_classid)
792792
* @NFT_META_PRANDOM: a 32bit pseudo-random number
793793
* @NFT_META_SECPATH: boolean, secpath_exists (!!skb->sp)
794+
* @NFT_META_IIFKIND: packet input interface kind name (dev->rtnl_link_ops->kind)
795+
* @NFT_META_OIFKIND: packet output interface kind name (dev->rtnl_link_ops->kind)
794796
*/
795797
enum nft_meta_keys {
796798
NFT_META_LEN,
@@ -819,6 +821,8 @@ enum nft_meta_keys {
819821
NFT_META_CGROUP,
820822
NFT_META_PRANDOM,
821823
NFT_META_SECPATH,
824+
NFT_META_IIFKIND,
825+
NFT_META_OIFKIND,
822826
};
823827

824828
/**

‎net/netfilter/nft_meta.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,16 @@ void nft_meta_get_eval(const struct nft_expr *expr,
244244
strncpy((char *)dest, p->br->dev->name, IFNAMSIZ);
245245
return;
246246
#endif
247+
case NFT_META_IIFKIND:
248+
if (in == NULL || in->rtnl_link_ops == NULL)
249+
goto err;
250+
strncpy((char *)dest, in->rtnl_link_ops->kind, IFNAMSIZ);
251+
break;
252+
case NFT_META_OIFKIND:
253+
if (out == NULL || out->rtnl_link_ops == NULL)
254+
goto err;
255+
strncpy((char *)dest, out->rtnl_link_ops->kind, IFNAMSIZ);
256+
break;
247257
default:
248258
WARN_ON(1);
249259
goto err;
@@ -340,6 +350,8 @@ static int nft_meta_get_init(const struct nft_ctx *ctx,
340350
break;
341351
case NFT_META_IIFNAME:
342352
case NFT_META_OIFNAME:
353+
case NFT_META_IIFKIND:
354+
case NFT_META_OIFKIND:
343355
len = IFNAMSIZ;
344356
break;
345357
case NFT_META_PRANDOM:

0 commit comments

Comments
 (0)