Skip to contentSkip to conversation

Add support for ct set

PATCH In review Kristian Evensen 3 participants 14 messages Jan 10, 2014 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add support for ct set

From: Kristian Evensen <[email protected]>

This patch adds userspace support for setting properties of tracked connections. Currently, the connection mark is supported. This can be used to implemented the same functionality as iptables -j CONNMARK --save-mark.

v1->v2:
- Fixed a style error.
- Improved error handling. Fail if neither sreg nor dreg is set (was already present when parsing XML).

v2->v3:
- Set sreg type to enum nft_registers.
- Let user specify any combination of sreg and dreg, and let the kernel do the error checking (and return -EINVAL). We avoid masking any errors and users will know that they have to fix their code.

---
 include/libnftables/expr.h          |   1 +
 include/linux/netfilter/nf_tables.h |   2 +
 src/expr/ct.c                       | 120 ++++++++++++++++++++++++++++--------
 3 files changed, 99 insertions(+), 24 deletions(-)
include/libnftables/expr.h +1 -0
index 25455e4..653bbb0 100644
@@ -124,6 +124,7 @@ enum {
 	NFT_EXPR_CT_DREG	= NFT_RULE_EXPR_ATTR_BASE,
 	NFT_EXPR_CT_KEY,
 	NFT_EXPR_CT_DIR,
+	NFT_EXPR_CT_SREG,
 };
 
 enum {
include/linux/netfilter/nf_tables.h +2 -0
index e08f80e..1b6362c 100644
@@ -526,12 +526,14 @@ enum nft_ct_keys {
  * @NFTA_CT_DREG: destination register (NLA_U32)
  * @NFTA_CT_KEY: conntrack data item to load (NLA_U32: nft_ct_keys)
  * @NFTA_CT_DIRECTION: direction in case of directional keys (NLA_U8)
+ * @NFTA_CT_SREG: source register (NLA_U32)
  */
 enum nft_ct_attributes {
 	NFTA_CT_UNSPEC,
 	NFTA_CT_DREG,
 	NFTA_CT_KEY,
 	NFTA_CT_DIRECTION,
+	NFTA_CT_SREG,
 	__NFTA_CT_MAX
 };
 #define NFTA_CT_MAX		(__NFTA_CT_MAX - 1)
src/expr/ct.c +96 -24

200 lines not on this page · raw message

Signature · 1 line
1.8.3.2
#1 lore raw
Quoted 6 lines · Kristian Evensen

#define NFTA_CT_MAX (__NFTA_CT_MAX - 1)

src/expr/ct.c +0 -0
index 46e3cef..02a073e 100644

src/expr/ct.c line 30

Quoted 8 lines
src/expr/ct.c +2 -1
@@ -24,7 +24,8 @@
 
 struct nft_expr_ct {
 	enum nft_ct_keys        key;
-	uint32_t		dreg;	/* enum nft_registers */
+	enum nft_registers	dreg;
+	enum nft_registers	sreg;
 	uint8_t			dir;
 };

nftables uses statements for things that don't return a value. I think it would make sense to keep this consistent. An "set" expression (aka statement) can never be used in a match, so its something fundamentally different than an expression.

#2 lore raw

Hi,

Quoted 4 lines · Patrick McHardy

nftables uses statements for things that don't return a value. I think it would make sense to keep this consistent. An "set" expression (aka statement) can never be used in a match, so its something fundamentally different than an expression.

Are you discussing the removal of the union?

-Kristian

#3 lore raw
Quoted 9 lines · Kristian Evensen

Hi,

Quoted 4 lines · Patrick McHardy

nftables uses statements for things that don't return a value. I think it would make sense to keep this consistent. An "set" expression (aka statement) can never be used in a match, so its something fundamentally different than an expression.

Are you discussing the removal of the union?

No, I'm refering to the (ab)use of the expression. Anything not returning data is not an expression but a statement.

#4 lore raw

Hi,

Quoted 2 lines · Patrick McHardy

No, I'm refering to the (ab)use of the expression. Anything not returning data is not an expression but a statement.

Ok, then I follow :) I followed the naming in meta, but I agree. What would be a good naming convetion? I thought of something like nft_expr_stmt_*. It is a bit clumsy, but it is at least clear that the struct can be used to represent both an expression and a statement.

-Kristian

#5 lore raw
Quoted 10 lines · Kristian Evensen

Hi,

Quoted 2 lines · Patrick McHardy

No, I'm refering to the (ab)use of the expression. Anything not returning data is not an expression but a statement.

Ok, then I follow :) I followed the naming in meta, but I agree. What would be a good naming convetion? I thought of something like nft_expr_stmt_*. It is a bit clumsy, but it is at least clear that the struct can be used to represent both an expression and a statement.

nft_ct_stmt? This is what we use in nftables f.i. in case of meta.

#6 lore raw
Quoted 7 lines · Patrick McHardy
Quoted 6 lines · Kristian Evensen

Hi,

Quoted 2 lines · Patrick McHardy

No, I'm refering to the (ab)use of the expression. Anything not returning data is not an expression but a statement.

Quoted 6 lines
Quoted 4 lines

Ok, then I follow :) I followed the naming in meta, but I agree. What would be a good naming convetion? I thought of something like nft_expr_stmt_*. It is a bit clumsy, but it is at least clear that the struct can be used to represent both an expression and a statement.

nft_ct_stmt? This is what we use in nftables f.i. in case of meta.

Just to be clear, I'm not only talking about the naming, a statement is something fundamentally different. Every expression has a value, which a statement doesn't have. Therefore every expression has a a value, destination register, byteorder, ..., all of which don't apply to statements. This is why we have an entire separate class for this in nftables, and this is what I'm also proposing for libnftables.

#7 lore raw

Hi,

Quoted 7 lines · Patrick McHardy

Just to be clear, I'm not only talking about the naming, a statement is something fundamentally different. Every expression has a value, which a statement doesn't have. Therefore every expression has a a value, destination register, byteorder, ..., all of which don't apply to statements. This is why we have an entire separate class for this in nftables, and this is what I'm also proposing for libnftables.

Thanks for the clarification and I agree. "ct set" is already part of ct_stmt in nftables, but I was unsure of how to transfer this to libnftables. I therefor decided to follow meta and store sreg in nf_expr_ct.

-Kristian

#8 lore raw
In reply to Patrick McHardy
Quoted 7 lines · Patrick McHardy
Quoted 6 lines · Kristian Evensen

Hi,

Quoted 2 lines · Patrick McHardy

No, I'm refering to the (ab)use of the expression. Anything not returning data is not an expression but a statement.

Quoted 6 lines
Quoted 4 lines

Ok, then I follow :) I followed the naming in meta, but I agree. What would be a good naming convetion? I thought of something like nft_expr_stmt_*. It is a bit clumsy, but it is at least clear that the struct can be used to represent both an expression and a statement.

nft_ct_stmt? This is what we use in nftables f.i. in case of meta.

Perhaps nft_ct_instr? So we can identify this as the nftables instruction-set.

#9 lore raw
Quoted 13 lines · Pablo Neira Ayuso
Quoted 12 lines · Patrick McHardy
Quoted 10 lines · Kristian Evensen

Hi,

Quoted 2 lines · Patrick McHardy

No, I'm refering to the (ab)use of the expression. Anything not returning data is not an expression but a statement.

Ok, then I follow :) I followed the naming in meta, but I agree. What would be a good naming convetion? I thought of something like nft_expr_stmt_*. It is a bit clumsy, but it is at least clear that the struct can be used to represent both an expression and a statement.

Quoted 4 lines
Quoted 1 line

nft_ct_stmt? This is what we use in nftables f.i. in case of meta.

Perhaps nft_ct_instr? So we can identify this as the nftables instruction-set.

Well, expressions also belong to the instruction set. A statement is is one (more specific) case of an instruction, as are expressions. Why introduce new terminology that isn't used anywhere else so far if statement is the exact description of what this is and is already used by nftables.

#10 lore raw
Quoted 16 lines · Patrick McHardy
Quoted 15 lines · Pablo Neira Ayuso
Quoted 13 lines · Patrick McHardy
Quoted 10 lines · Kristian Evensen

Hi,

Quoted 2 lines · Patrick McHardy

No, I'm refering to the (ab)use of the expression. Anything not returning data is not an expression but a statement.

Ok, then I follow :) I followed the naming in meta, but I agree. What would be a good naming convetion? I thought of something like nft_expr_stmt_*. It is a bit clumsy, but it is at least clear that the struct can be used to represent both an expression and a statement.

nft_ct_stmt? This is what we use in nftables f.i. in case of meta.

Quoted 8 lines
Quoted 2 lines

Perhaps nft_ct_instr? So we can identify this as the nftables instruction-set.

Well, expressions also belong to the instruction set. A statement is is one (more specific) case of an instruction, as are expressions. Why introduce new terminology that isn't used anywhere else so far if statement is the exact description of what this is and is already used by nftables.

So are you proposing to add a new object for statements in libnftables? That will require a new infrastructure which would be very similar to what we have in the current expressions.

To that extend, that would also require a new infrastructure in the kernel so we also have statements there. I think one of the good things of the nf_tables kernel side is that we didn't make any distinction between matches/targets (or call it expressions/statements).

#11 lore raw
Quoted 26 lines · Pablo Neira Ayuso
Quoted 16 lines · Patrick McHardy
Quoted 15 lines · Pablo Neira Ayuso
Quoted 13 lines · Patrick McHardy
Quoted 10 lines · Kristian Evensen

Hi,

Quoted 2 lines · Patrick McHardy

No, I'm refering to the (ab)use of the expression. Anything not returning data is not an expression but a statement.

Ok, then I follow :) I followed the naming in meta, but I agree. What would be a good naming convetion? I thought of something like nft_expr_stmt_*. It is a bit clumsy, but it is at least clear that the struct can be used to represent both an expression and a statement.

nft_ct_stmt? This is what we use in nftables f.i. in case of meta.

Quoted 8 lines
Quoted 2 lines

Perhaps nft_ct_instr? So we can identify this as the nftables instruction-set.

Well, expressions also belong to the instruction set. A statement is is one (more specific) case of an instruction, as are expressions. Why introduce new terminology that isn't used anywhere else so far if statement is the exact description of what this is and is already used by nftables.

Quoted 3 lines

So are you proposing to add a new object for statements in libnftables? That will require a new infrastructure which would be very similar to what we have in the current expressions.

Well, the infrastructure should be pretty small. In fact you could probably map everything to expressions internally (although I don't think adding new infrastructure would be much effort), I would just rather not create an API that confuses fundamental types.

Quoted 5 lines

To that extend, that would also require a new infrastructure in the kernel so we also have statements there. I think one of the good things of the nf_tables kernel side is that we didn't make any distinction between matches/targets (or call it expressions/statements).

In the kernel that was deliberate and is only internal to the kernel (well, and libraries and so on). I considered it, but I think in the kernel its more important to keep the code base and APIs as small as possible.

#12 lore raw
Quoted 27 lines · Patrick McHardy
Quoted 26 lines · Pablo Neira Ayuso
Quoted 24 lines · Patrick McHardy
Quoted 13 lines · Pablo Neira Ayuso
Quoted 12 lines · Patrick McHardy
Quoted 10 lines · Kristian Evensen

Hi,

Quoted 2 lines · Patrick McHardy

No, I'm refering to the (ab)use of the expression. Anything not returning data is not an expression but a statement.

Ok, then I follow :) I followed the naming in meta, but I agree. What would be a good naming convetion? I thought of something like nft_expr_stmt_*. It is a bit clumsy, but it is at least clear that the struct can be used to represent both an expression and a statement.

Quoted 4 lines
Quoted 1 line

nft_ct_stmt? This is what we use in nftables f.i. in case of meta.

Perhaps nft_ct_instr? So we can identify this as the nftables instruction-set.

Well, expressions also belong to the instruction set. A statement is is one (more specific) case of an instruction, as are expressions. Why introduce new terminology that isn't used anywhere else so far if statement is the exact description of what this is and is already used by nftables.

Quoted 8 lines
Quoted 3 lines

So are you proposing to add a new object for statements in libnftables? That will require a new infrastructure which would be very similar to what we have in the current expressions.

Well, the infrastructure should be pretty small. In fact you could probably map everything to expressions internally (although I don't think adding new infrastructure would be much effort), I would just rather not create an API that confuses fundamental types.

libnftables is the very low level library, as it is very close to the kernel details, I would stick to the expression simplification that we have in the kernel.

Quoted 10 lines
Quoted 5 lines

To that extend, that would also require a new infrastructure in the kernel so we also have statements there. I think one of the good things of the nf_tables kernel side is that we didn't make any distinction between matches/targets (or call it expressions/statements).

In the kernel that was deliberate and is only internal to the kernel (well, and libraries and so on). I considered it, but I think in the kernel its more important to keep the code base and APIs as small as possible.

Anyone working with libnftables should be familiar with the kernel code, the current approach maps 1 to 1 what we have in the kernel.

I still think the statement/expression concept should remain in the scope of nft. We'll have a high level library at some point, I guess that will be based on the (generalized) nft code, so we can provide a nft_compile() function similar to what libpcap provides to translate nft syntax to rules.

My proposal is to leave the expressions / statements concepts to the scope of nft and the upcoming high level library. As said, libnftables is low level stuff, it is just mirroring what we have in the kernel.

#13 lore raw
Quoted 7 lines · Pablo Neira Ayuso
Quoted 6 lines · Patrick McHardy
Quoted 4 lines · Pablo Neira Ayuso

So are you proposing to add a new object for statements in libnftables? That will require a new infrastructure which would be very similar to what we have in the current expressions.

Quoted 8 lines
Quoted 4 lines

Well, the infrastructure should be pretty small. In fact you could probably map everything to expressions internally (although I don't think adding new infrastructure would be much effort), I would just rather not create an API that confuses fundamental types.

libnftables is the very low level library, as it is very close to the kernel details, I would stick to the expression simplification that we have in the kernel.

Ok sure. Just wanted to bring it up.

Quoted 20 lines
Quoted 10 lines
Quoted 5 lines

To that extend, that would also require a new infrastructure in the kernel so we also have statements there. I think one of the good things of the nf_tables kernel side is that we didn't make any distinction between matches/targets (or call it expressions/statements).

In the kernel that was deliberate and is only internal to the kernel (well, and libraries and so on). I considered it, but I think in the kernel its more important to keep the code base and APIs as small as possible.

Anyone working with libnftables should be familiar with the kernel code, the current approach maps 1 to 1 what we have in the kernel.

I still think the statement/expression concept should remain in the scope of nft. We'll have a high level library at some point, I guess that will be based on the (generalized) nft code, so we can provide a nft_compile() function similar to what libpcap provides to translate nft syntax to rules.

Quoted 3 lines

My proposal is to leave the expressions / statements concepts to the scope of nft and the upcoming high level library. As said, libnftables is low level stuff, it is just mirroring what we have in the kernel.

Ok that's fine with me for a low level library. Wondering whether the high layer library should actually be called libnftables though.