History

netfilter: nf_tables: introduce routing expression

Introduces an nftables rt expression for routing related data with support for nexthop (i.e. the directly connected IP address that an outgoing packet is sent to), which can be used either for matching or accounting, eg. # nft add rule filter postrouting \ ip daddr 192.168.1.0/24 rt nexthop != 192.168.0.1 drop This will drop any traffic to 192.168.1.0/24 that is not routed via 192.168.0.1. # nft add rule filter postrouting \ flow table acct { rt nexthop timeout 600s counter } # nft add rule ip6 filter postrouting \ flow table acct { rt nexthop timeout 600s counter } These rules count outgoing traffic per nexthop. Note that the timeout releases an entry if no traffic is seen for this nexthop within 10 minutes. # nft add rule inet filter postrouting \ ether type ip \ flow table acct { rt nexthop timeout 600s counter } # nft add rule inet filter postrouting \ ether type ip6 \ flow table acct { rt nexthop timeout 600s counter } Same as above, but via the inet family, where the ether type must be specified explicitly. "rt classid" is also implemented identical to "meta rtclassid", since it is more logical to have this match in the routing expression going forward.

Anders K. Pedersen committed 10 years ago

Commit 2fa84191 parent 8db4c5b4 files · +187 −0Browse files

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

Unified · Split

include/uapi/linux/netfilter/nf_tables.h+27−0
@@ -758,6 +758,19 @@ enum nft_meta_keys { · 757 unmodified lines
758758 NFT_META_PRANDOM,
759759 };
760760
761+/**
762+ * enum nft_rt_keys - nf_tables routing expression keys
763+ *
764+ * @NFT_RT_CLASSID: realm value of packet's route (skb->dst->tclassid)
765+ * @NFT_RT_NEXTHOP4: routing nexthop for IPv4
766+ * @NFT_RT_NEXTHOP6: routing nexthop for IPv6
767+ */
768+enum nft_rt_keys {
769+ NFT_RT_CLASSID,
770+ NFT_RT_NEXTHOP4,
771+ NFT_RT_NEXTHOP6,
772+};
773+
761774 /**
762775 * enum nft_hash_attributes - nf_tables hash expression netlink attributes
763776 *
@@ -796,6 +809,20 @@ enum nft_meta_attributes { · 32 unmodified lines
796809 };
797810 #define NFTA_META_MAX (__NFTA_META_MAX - 1)
798811
812+/**
813+ * enum nft_rt_attributes - nf_tables routing expression netlink attributes
814+ *
815+ * @NFTA_RT_DREG: destination register (NLA_U32)
816+ * @NFTA_RT_KEY: routing data item to load (NLA_U32: nft_rt_keys)
817+ */
818+enum nft_rt_attributes {
819+ NFTA_RT_UNSPEC,
820+ NFTA_RT_DREG,
821+ NFTA_RT_KEY,
822+ __NFTA_RT_MAX
823+};
824+#define NFTA_RT_MAX (__NFTA_RT_MAX - 1)
825+
799826 /**
800827 * enum nft_ct_keys - nf_tables ct expression keys
801828 *