History

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

wenxu committed 7 years ago

Commit 0fb4d211 parent ba3fbe62 files · +16 −0Browse files

Showing the changes to include/uapi/linux (1 of 2 files). Show all

Unified · Split

include/uapi/linux/netfilter/nf_tables.h+4−0
@@ -791,6 +791,8 @@ enum nft_exthdr_attributes { · 790 unmodified lines
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 { · 22 unmodified lines
819821 NFT_META_CGROUP,
820822 NFT_META_PRANDOM,
821823 NFT_META_SECPATH,
824+ NFT_META_IIFKIND,
825+ NFT_META_OIFKIND,
822826 };
823827
824828 /**