Skip to contentSkip to conversation

introduce rt expression

PATCH New Anders K. Pedersen | Cohaesio 1 participant 1 message Oct 16, 2016 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 introduce rt expression

From: Anders K. Pedersen <[email protected]>

Introduce support for rt expression for routing related data as implemented in kernel.

---
 include/libnftnl/expr.h             |  12 ++
 include/linux/netfilter/nf_tables.h |  26 ++++
 src/Makefile.am                     |   1 +
 src/expr/rt.c                       | 268 ++++++++++++++++++++++++++++++++++++
 src/expr_ops.c                      |   2 +
 5 files changed, 309 insertions(+)
include/libnftnl/expr.h +12 -0
index 4ce2592..e02e5b7 100644
@@ -64,6 +64,12 @@ enum {
 };
 
 enum {
+	NFTNL_EXPR_RT_KEY	= NFTNL_EXPR_BASE,
+	NFTNL_EXPR_RT_DREG,
+	NFTNL_EXPR_RT_FAMILY,
+};
+
+enum {
 	NFTNL_EXPR_CMP_SREG	= NFTNL_EXPR_BASE,
 	NFTNL_EXPR_CMP_OP,
 	NFTNL_EXPR_CMP_DATA,
@@ -265,6 +271,12 @@ enum {
 };
 
 enum {
+	NFT_EXPR_RT_KEY		= NFT_RULE_EXPR_ATTR_BASE,
+	NFT_EXPR_RT_DREG,
+	NFT_EXPR_RT_FAMILY,
+};
+
+enum {
 	NFT_EXPR_CMP_SREG	= NFT_RULE_EXPR_ATTR_BASE,
 	NFT_EXPR_CMP_OP,
 	NFT_EXPR_CMP_DATA,
include/linux/netfilter/nf_tables.h +26 -0
index 681082e..81ee4f0 100644
@@ -724,6 +724,16 @@ enum nft_meta_keys {
 };
 
 /**
+ * enum nft_rt_keys - nf_tables routing expression keys
+ *
+ * @NFT_META_NEXTHOP: routing nexthop
+ */
+enum nft_rt_keys {
+	NFT_RT_CLASSID,
+	NFT_RT_NEXTHOP,
+};
+
+/**
  * enum nft_hash_attributes - nf_tables hash expression netlink attributes
  *
  * @NFTA_HASH_SREG: source register (NLA_U32)
@@ -762,6 +772,22 @@ enum nft_meta_attributes {
 #define NFTA_META_MAX		(__NFTA_META_MAX - 1)
 
 /**
+ * enum nft_rt_attributes - nf_tables routing expression netlink attributes
+ *
+ * @NFTA_RT_DREG: destination register (NLA_U32)
+ * @NFTA_RT_KEY: meta data item to load (NLA_U32: nft_rt_keys)
+ * @NFTA_RT_FAMILY: Address family (NLA_U32)
+ */
+enum nft_rt_attributes {
+	NFTA_RT_UNSPEC,
+	NFTA_RT_DREG,
+	NFTA_RT_KEY,
+	NFTA_RT_FAMILY,
+	__NFTA_RT_MAX
+};
+#define NFTA_RT_MAX		(__NFTA_RT_MAX - 1)
+
+/**
  * enum nft_ct_keys - nf_tables ct expression keys
  *
  * @NFT_CT_STATE: conntrack state (bitmask of enum ip_conntrack_info)
src/Makefile.am +1 -0
index 4ab8fca..48ff85a 100644
@@ -43,6 +43,7 @@ libnftnl_la_SOURCES = utils.c		\
 		      expr/queue.c	\
 		      expr/quota.c	\
 		      expr/reject.c	\
+		      expr/rt.c		\
 		      expr/target.c	\
 		      expr/masq.c	\
 		      expr/redir.c	\
src/expr/rt.c new file +268 -0

268 lines not on this page · raw message

src/expr_ops.c +2 -0
index 2a047d2..7c0e891 100644
@@ -24,6 +24,7 @@ extern struct expr_ops expr_ops_nat;
 extern struct expr_ops expr_ops_payload;
 extern struct expr_ops expr_ops_redir;
 extern struct expr_ops expr_ops_reject;
+extern struct expr_ops expr_ops_rt;
 extern struct expr_ops expr_ops_queue;
 extern struct expr_ops expr_ops_quota;
 extern struct expr_ops expr_ops_target;
@@ -51,6 +52,7 @@ static struct expr_ops *expr_ops[] = {
 	&expr_ops_payload,
 	&expr_ops_redir,
 	&expr_ops_reject,
+	&expr_ops_rt,
 	&expr_ops_queue,
 	&expr_ops_quota,
 	&expr_ops_target,