Skip to contentSkip to conversation

conntrack: label update requires a previous label in place

PATCH Superseded Pablo Neira Ayuso 2 participants 6 messages Oct 11, 2023 netfilter

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/1 conntrack: label update requires a previous label in place

You have to set an initial label if you plan to update it later on. If conntrack comes with no initial label, then it is not possible to attach it later because conntrack extensions are created by the time the new entry is created.

Skip entries with no label to skip ENOSPC error for conntracks that have no initial label (this is assuming a scenario with conntracks with and _without_ labels is possible, and the conntrack command line tool is used to update all entries regardless they have or not an initial label, e.g. conntrack -U --label-add "testlabel".

 # conntrack -U --label-add testlabel --dst 9.9.9.9
 icmp     1 13 src=192.168.2.130 dst=9.9.9.9 type=8 code=0 id=50997 src=9.9.9.9 dst=192.168.2.130 type=0 code=0 id=50997 mark=0 use=2 labels=default,testlabel
conntrack v1.4.8 (conntrack-tools): 1 flow entries have been updated.
 # conntrack -C
 8

Note the remaining 7 conntracks have no label, hence, they could not be updated.

Update manpage to document this behaviour.

---
 conntrack.8     | 2 ++
 src/conntrack.c | 4 ++++
 2 files changed, 6 insertions(+)
conntrack.8 +2 -0
index 031eaa4e9fef..97c60079889f 100644
@@ -193,6 +193,8 @@ Use multiple \-l options to specify multiple labels that need to be set.
 Specify the conntrack label to add to the selected conntracks.
 This option is only available in conjunction with "\-I, \-\-create",
 "\-A, \-\-add" or "\-U, \-\-update".
+You must set a default label for conntracks initially if you plan to update it
+later. "\-U, \-\-update" on conntracks with no initial entry will be ignored.
 .TP
 .BI "--label-del " "[LABEL]"
 Specify the conntrack label to delete from the selected conntracks.
src/conntrack.c +4 -0
index f9758d78d39b..06c2fee7ac4b 100644
@@ -2195,6 +2195,10 @@ static int mnl_nfct_update_cb(const struct nlmsghdr *nlh, void *data)
 		/* the entry has vanish in middle of the update */
 		if (errno == ENOENT)
 			goto destroy_ok;
+		else if (!(cmd->options & (CT_OPT_ADD_LABEL | CT_OPT_DEL_LABEL)) &&
+			 errno == ENOSPC)
+			goto destroy_ok;
+
 		exit_error(OTHER_PROBLEM,
 			   "Operation failed: %s",
 			   err2str(errno, CT_UPDATE));
Signature · 1 line
2.30.2
author maintainer
#1 lore raw
Quoted 10 lines · Pablo Neira Ayuso

You have to set an initial label if you plan to update it later on. If conntrack comes with no initial label, then it is not possible to attach it later because conntrack extensions are created by the time the new entry is created.

Skip entries with no label to skip ENOSPC error for conntracks that have no initial label (this is assuming a scenario with conntracks with and _without_ labels is possible, and the conntrack command line tool is used to update all entries regardless they have or not an initial label, e.g. conntrack -U --label-add "testlabel".

Still not fully correct.

Current behaviour is:

If there is at least one rule in the ruleset that uses the connlabel, then connlabel conntrack extension is always allocated.

I wonder if this needs a sysctl toggle just like nf_conntrack_timestamp. Otherwise I am not sure how to document this.

Quoted 36 lines
 # conntrack -U --label-add testlabel --dst 9.9.9.9
 icmp     1 13 src=192.168.2.130 dst=9.9.9.9 type=8 code=0 id=50997 src=9.9.9.9 dst=192.168.2.130 type=0 code=0 id=50997 mark=0 use=2 labels=default,testlabel
conntrack v1.4.8 (conntrack-tools): 1 flow entries have been updated.
 # conntrack -C
 8

Note the remaining 7 conntracks have no label, hence, they could not be updated.

Update manpage to document this behaviour.

---
 conntrack.8     | 2 ++
 src/conntrack.c | 4 ++++
 2 files changed, 6 insertions(+)
conntrack.8 +2 -0
index 031eaa4e9fef..97c60079889f 100644
@@ -193,6 +193,8 @@ Use multiple \-l options to specify multiple labels that need to be set.
 Specify the conntrack label to add to the selected conntracks.
 This option is only available in conjunction with "\-I, \-\-create",
 "\-A, \-\-add" or "\-U, \-\-update".
+You must set a default label for conntracks initially if you plan to update it
+later. "\-U, \-\-update" on conntracks with no initial entry will be ignored.
 .TP
 .BI "--label-del " "[LABEL]"
 Specify the conntrack label to delete from the selected conntracks.
src/conntrack.c +0 -0
index f9758d78d39b..06c2fee7ac4b 100644

src/conntrack.c static int mnl_nfct_update_cb(const struct nlmsghdr *nlh, void *data) · line 2199

Quoted 5 lines
src/conntrack.c +2 -0
@@ -2195,6 +2195,10 @@ static int mnl_nfct_update_cb(const struct nlmsghdr *nlh, void *data)
 		/* the entry has vanish in middle of the update */
 		if (errno == ENOENT)
 			goto destroy_ok;
+		else if (!(cmd->options & (CT_OPT_ADD_LABEL | CT_OPT_DEL_LABEL)) &&
+			 errno == ENOSPC)

This check is also not correct, this needs a v3. I have to check is ATTRS_CONNLABEL is set and cmd->options & (CT_OPT_ADD_LABEL | CT_OPT_DEL_LABEL) too, then check for ENOSPC, to avoid for bogus error reports to userspace.

Quoted 8 lines
src/conntrack.c +2 -0
+			goto destroy_ok;
+
 		exit_error(OTHER_PROBLEM,
 			   "Operation failed: %s",
 			   err2str(errno, CT_UPDATE));
Signature · 1 line
2.30.2
maintainer
#2 lore raw
Quoted 14 lines · Pablo Neira Ayuso
Quoted 10 lines · Pablo Neira Ayuso

You have to set an initial label if you plan to update it later on. If conntrack comes with no initial label, then it is not possible to attach it later because conntrack extensions are created by the time the new entry is created.

Skip entries with no label to skip ENOSPC error for conntracks that have no initial label (this is assuming a scenario with conntracks with and _without_ labels is possible, and the conntrack command line tool is used to update all entries regardless they have or not an initial label, e.g. conntrack -U --label-add "testlabel".

Still not fully correct.

Quoted 7 lines

Current behaviour is:

If there is at least one rule in the ruleset that uses the connlabel, then connlabel conntrack extension is always allocated.

I wonder if this needs a sysctl toggle just like nf_conntrack_timestamp. Otherwise I am not sure how to document this.

Rationale was that if you have no rules that check on labels then there is never a need to allocate the space.

I'm working on a patchset that will also set/enable the label extension if its enabled on the template. The idea is to convert ovs and act_ct to it, currently they point-blank increment net->ct.labels_used which means that all conntrack objects get the label area allocated.

But thats not what the counter was (originally) meant to convey, it was really 'number of connlabel rules'.

As soon as act_ct or ovs modules are loaded, then all the namespaces see 'I need conntrack labels', which completely voids all attempts to avoid ct->ext allocation.

author maintainer
#3 lore raw
Quoted 32 lines · Florian Westphal
Quoted 14 lines · Pablo Neira Ayuso
Quoted 10 lines · Pablo Neira Ayuso

You have to set an initial label if you plan to update it later on. If conntrack comes with no initial label, then it is not possible to attach it later because conntrack extensions are created by the time the new entry is created.

Skip entries with no label to skip ENOSPC error for conntracks that have no initial label (this is assuming a scenario with conntracks with and _without_ labels is possible, and the conntrack command line tool is used to update all entries regardless they have or not an initial label, e.g. conntrack -U --label-add "testlabel".

Still not fully correct.

Quoted 7 lines

Current behaviour is:

If there is at least one rule in the ruleset that uses the connlabel, then connlabel conntrack extension is always allocated.

I wonder if this needs a sysctl toggle just like nf_conntrack_timestamp. Otherwise I am not sure how to document this.

Rationale was that if you have no rules that check on labels then there is never a need to allocate the space.

I'm working on a patchset that will also set/enable the label extension if its enabled on the template. The idea is to convert ovs and act_ct to it, currently they point-blank increment net->ct.labels_used which means that all conntrack objects get the label area allocated.

Quoted 6 lines

But thats not what the counter was (originally) meant to convey, it was really 'number of connlabel rules'.

As soon as act_ct or ovs modules are loaded, then all the namespaces see 'I need conntrack labels', which completely voids all attempts to avoid ct->ext allocation.

OK, so instead a of per-netns sysctl toggle, you propose to use the conntrack template to selectively enable this.

maintainer
#4 lore raw
Quoted 12 lines · Pablo Neira Ayuso
Quoted 11 lines

Rationale was that if you have no rules that check on labels then there is never a need to allocate the space.

I'm working on a patchset that will also set/enable the label extension if its enabled on the template. The idea is to convert ovs and act_ct to it, currently they point-blank increment net->ct.labels_used which means that all conntrack objects get the label area allocated.

But thats not what the counter was (originally) meant to convey, it was really 'number of connlabel rules'.

Quoted 6 lines
Quoted 3 lines

As soon as act_ct or ovs modules are loaded, then all the namespaces see 'I need conntrack labels', which completely voids all attempts to avoid ct->ext allocation.

OK, so instead a of per-netns sysctl toggle, you propose to use the conntrack template to selectively enable this.

I think for iptables/nftables current approach is fine.

Otherwise someone has to explain to me what the use case is for setting connlabels from netlink but no rules in place that make any decision based on that.

author maintainer
#5 lore raw
Quoted 17 lines · Florian Westphal
Quoted 16 lines · Pablo Neira Ayuso
Quoted 15 lines

Rationale was that if you have no rules that check on labels then there is never a need to allocate the space.

I'm working on a patchset that will also set/enable the label extension if its enabled on the template. The idea is to convert ovs and act_ct to it, currently they point-blank increment net->ct.labels_used which means that all conntrack objects get the label area allocated.

But thats not what the counter was (originally) meant to convey, it was really 'number of connlabel rules'.

As soon as act_ct or ovs modules are loaded, then all the namespaces see 'I need conntrack labels', which completely voids all attempts to avoid ct->ext allocation.

Quoted 8 lines
Quoted 2 lines

OK, so instead a of per-netns sysctl toggle, you propose to use the conntrack template to selectively enable this.

I think for iptables/nftables current approach is fine.

Otherwise someone has to explain to me what the use case is for setting connlabels from netlink but no rules in place that make any decision based on that.

Agreed.

I don't need this myself. I just found this bugzilla ticket while reviewing recent reports. I think my patch for conntrack command line is fine by now (documentation plus deal with corner case that triggers ENOSPC from update path).

So yes, agreed, if anyone has a use case for no rules while having connlabel, they should come here and explain.