Skip to contentSkip to conversation

netfilter: conntrack: label helpers conditional compilation updates

PATCH In review Simon Horman 3 participants 12 messages Sep 16, 2024 – Sep 19, 2024

Subsystems (3)
lore
Share & tools
lore

Simon Horman

author reviewer
#0 lore raw

cover netfilter: conntrack: label helpers conditional compilation updates

Hi,

This short series updates conditional compilation of label helpers to:

1) Compile them regardless of if CONFIG_NF_CONNTRACK_LABELS is enabled or not. It is safe to do so as the functions will always return 0 if CONFIG_NF_CONNTRACK_LABELS is not enabled. And the compiler should optimise waway the code. Which is the desired behaviour.

2) Only compile ctnetlink_label_size if CONFIG_NF_CONNTRACK_EVENTS is enabled. This addresses a warning about this function being unused in this case.

Found by inspection.
Patches have been compile tested only.

---
Simon Horman (2):
netfilter: conntrack: compile label helpers unconditionally
netfilter: conntrack: conditionally compile ctnetlink_label_size

 net/netfilter/nf_conntrack_netlink.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

base-commit: d5c4546062fd6f5dbce575c7ea52ad66d1968678

author reviewer
#1 lore raw

PATCH 1/2 netfilter: conntrack: compile label helpers unconditionally

The condition on CONFIG_NF_CONNTRACK_LABELS being removed by this patch guards compilation of non-trivial implementations of ctnetlink_dump_labels() and ctnetlink_label_size().

However, this is not necessary as each of these functions will always return 0 if CONFIG_NF_CONNTRACK_LABELS is not defined as each function starts with the equivalent of:

	struct nf_conn_labels *labels = nf_ct_labels_find(ct);

	if (!labels)
		return 0;

And nf_ct_labels_find always returns NULL if CONFIG_NF_CONNTRACK_LABELS is not enabled. So I believe that the compiler optimises the code away in such cases anyway.

Some advantages of this approach are:

1. Fewer #ifdefs, fewer headaches
2. The trivial implementations can be dropped
3. A follow-up patch, to conditionally compile ctnetlink_label_size only when it is used becomes simpler (see point 1)

Found by inspection.
Compile tested only.

---
 net/netfilter/nf_conntrack_netlink.c | 5 -----
 1 file changed, 5 deletions(-)
net/netfilter/nf_conntrack_netlink.c +0 -5
index 123e2e933e9b..f1f7dff08953 100644
@@ -382,7 +382,6 @@ static int ctnetlink_dump_secctx(struct sk_buff *skb, const struct nf_conn *ct)
 #define ctnetlink_dump_secctx(a, b) (0)
 #endif
 
-#ifdef CONFIG_NF_CONNTRACK_LABELS
 static inline int ctnetlink_label_size(const struct nf_conn *ct)
 {
 	struct nf_conn_labels *labels = nf_ct_labels_find(ct);
@@ -411,10 +410,6 @@ ctnetlink_dump_labels(struct sk_buff *skb, const struct nf_conn *ct)
 
 	return 0;
 }
-#else
-#define ctnetlink_dump_labels(a, b) (0)
-#define ctnetlink_label_size(a)	(0)
-#endif
 
 #define master_tuple(ct) &(ct->master->tuplehash[IP_CT_DIR_ORIGINAL].tuple)
 
Signature · 1 line
2.45.2
author reviewer
#2 lore raw

PATCH 2/2 netfilter: conntrack: conditionally compile ctnetlink_label_size

In reply to Simon Horman

Only provide ctnetlink_label_size when it is used, which is when CONFIG_NF_CONNTRACK_EVENTS is configured.

Flagged by clang-18 W=1 builds as:

.../nf_conntrack_netlink.c:385:19: warning: unused function 'ctnetlink_label_size' [-Wunused-function]
385 | static inline int ctnetlink_label_size(const struct nf_conn *ct)

      |                   ^~~~~~~~~~~~~~~~~~~~

Found by manually tweaking .config.
Compile tested only.

---
 net/netfilter/nf_conntrack_netlink.c | 2 ++
 1 file changed, 2 insertions(+)
net/netfilter/nf_conntrack_netlink.c +2 -0
index f1f7dff08953..cac48277a7d5 100644
@@ -382,6 +382,7 @@ static int ctnetlink_dump_secctx(struct sk_buff *skb, const struct nf_conn *ct)
 #define ctnetlink_dump_secctx(a, b) (0)
 #endif
 
+#ifdef CONFIG_NF_CONNTRACK_EVENTS
 static inline int ctnetlink_label_size(const struct nf_conn *ct)
 {
 	struct nf_conn_labels *labels = nf_ct_labels_find(ct);
@@ -390,6 +391,7 @@ static inline int ctnetlink_label_size(const struct nf_conn *ct)
 		return 0;
 	return nla_total_size(sizeof(labels->bits));
 }
+#endif
 
 static int
 ctnetlink_dump_labels(struct sk_buff *skb, const struct nf_conn *ct)
Signature · 1 line
2.45.2
Reviewed-by on the v1 series
#3 lore raw
In reply to Simon Horman
Quoted 4 lines · Simon Horman

Hi,

This short series updates conditional compilation of label helpers to:

Quoted 8 lines

1) Compile them regardless of if CONFIG_NF_CONNTRACK_LABELS is enabled or not. It is safe to do so as the functions will always return 0 if CONFIG_NF_CONNTRACK_LABELS is not enabled. And the compiler should optimise waway the code. Which is the desired behaviour.

2) Only compile ctnetlink_label_size if CONFIG_NF_CONNTRACK_EVENTS is enabled. This addresses a warning about this function being unused in this case.

Both make sense to me, FWIW,

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw
In reply to Simon Horman
Quoted 4 lines · Simon Horman

Hi,

This short series updates conditional compilation of label helpers to:

Quoted 8 lines

1) Compile them regardless of if CONFIG_NF_CONNTRACK_LABELS is enabled or not. It is safe to do so as the functions will always return 0 if CONFIG_NF_CONNTRACK_LABELS is not enabled. And the compiler should optimise waway the code. Which is the desired behaviour.

2) Only compile ctnetlink_label_size if CONFIG_NF_CONNTRACK_EVENTS is enabled. This addresses a warning about this function being unused in this case.

Patch 1)

-#ifdef CONFIG_NF_CONNTRACK_LABELS
static inline int ctnetlink_label_size(const struct nf_conn *ct)

Patch 2)

+#ifdef CONFIG_NF_CONNTRACK_EVENTS
static inline int ctnetlink_label_size(const struct nf_conn *ct)

They both refer to ctnetlink_label_size(), #ifdef check is not correct.

Would you mind if I collapsed these two patches before applying?

Thanks Simon.

#5 lore raw
Quoted 19 lines · Pablo Neira Ayuso
Quoted 4 lines · Simon Horman

Hi,

This short series updates conditional compilation of label helpers to:

Quoted 8 lines

1) Compile them regardless of if CONFIG_NF_CONNTRACK_LABELS is enabled or not. It is safe to do so as the functions will always return 0 if CONFIG_NF_CONNTRACK_LABELS is not enabled. And the compiler should optimise waway the code. Which is the desired behaviour.

2) Only compile ctnetlink_label_size if CONFIG_NF_CONNTRACK_EVENTS is enabled. This addresses a warning about this function being unused in this case.

Patch 1)

-#ifdef CONFIG_NF_CONNTRACK_LABELS
static inline int ctnetlink_label_size(const struct nf_conn *ct)

Quoted 7 lines

Patch 2)

+#ifdef CONFIG_NF_CONNTRACK_EVENTS
static inline int ctnetlink_label_size(const struct nf_conn *ct)

They both refer to ctnetlink_label_size(), #ifdef check is not correct.

But the first one touches more, no?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#6 lore raw
Quoted 22 lines · Andy Shevchenko
Quoted 21 lines · Pablo Neira Ayuso
Quoted 4 lines · Simon Horman

Hi,

This short series updates conditional compilation of label helpers to:

Quoted 8 lines

1) Compile them regardless of if CONFIG_NF_CONNTRACK_LABELS is enabled or not. It is safe to do so as the functions will always return 0 if CONFIG_NF_CONNTRACK_LABELS is not enabled. And the compiler should optimise waway the code. Which is the desired behaviour.

2) Only compile ctnetlink_label_size if CONFIG_NF_CONNTRACK_EVENTS is enabled. This addresses a warning about this function being unused in this case.

Patch 1)

-#ifdef CONFIG_NF_CONNTRACK_LABELS
static inline int ctnetlink_label_size(const struct nf_conn *ct)

Patch 2)

Quoted 7 lines
Quoted 5 lines

+#ifdef CONFIG_NF_CONNTRACK_EVENTS
static inline int ctnetlink_label_size(const struct nf_conn *ct)

They both refer to ctnetlink_label_size(), #ifdef check is not correct.

But the first one touches more, no?

Yes, it also remove a #define ctnetlink_label_size() macro in patch #1. I am fine with this series as is.

#7 lore raw
Quoted 26 lines · Pablo Neira Ayuso
Quoted 25 lines · Andy Shevchenko
Quoted 24 lines · Pablo Neira Ayuso
Quoted 4 lines · Simon Horman

Hi,

This short series updates conditional compilation of label helpers to:

Quoted 8 lines

1) Compile them regardless of if CONFIG_NF_CONNTRACK_LABELS is enabled or not. It is safe to do so as the functions will always return 0 if CONFIG_NF_CONNTRACK_LABELS is not enabled. And the compiler should optimise waway the code. Which is the desired behaviour.

2) Only compile ctnetlink_label_size if CONFIG_NF_CONNTRACK_EVENTS is enabled. This addresses a warning about this function being unused in this case.

Patch 1)

-#ifdef CONFIG_NF_CONNTRACK_LABELS
static inline int ctnetlink_label_size(const struct nf_conn *ct)

Patch 2)

+#ifdef CONFIG_NF_CONNTRACK_EVENTS
static inline int ctnetlink_label_size(const struct nf_conn *ct)

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

They both refer to ctnetlink_label_size(), #ifdef check is not correct.

But the first one touches more, no?

Yes, it also remove a #define ctnetlink_label_size() macro in patch #1. I am fine with this series as is.

What I meant is that the original patch 1 takes care about definitions of two functions. Not just a single one.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#8 lore raw
Quoted 32 lines · Andy Shevchenko
Quoted 31 lines · Pablo Neira Ayuso
Quoted 29 lines · Andy Shevchenko
Quoted 19 lines · Pablo Neira Ayuso
Quoted 4 lines · Simon Horman

Hi,

This short series updates conditional compilation of label helpers to:

Quoted 8 lines

1) Compile them regardless of if CONFIG_NF_CONNTRACK_LABELS is enabled or not. It is safe to do so as the functions will always return 0 if CONFIG_NF_CONNTRACK_LABELS is not enabled. And the compiler should optimise waway the code. Which is the desired behaviour.

2) Only compile ctnetlink_label_size if CONFIG_NF_CONNTRACK_EVENTS is enabled. This addresses a warning about this function being unused in this case.

Patch 1)

-#ifdef CONFIG_NF_CONNTRACK_LABELS
static inline int ctnetlink_label_size(const struct nf_conn *ct)

Quoted 7 lines

Patch 2)

+#ifdef CONFIG_NF_CONNTRACK_EVENTS
static inline int ctnetlink_label_size(const struct nf_conn *ct)

They both refer to ctnetlink_label_size(), #ifdef check is not correct.

But the first one touches more, no?

Quoted 5 lines
Quoted 2 lines

Yes, it also remove a #define ctnetlink_label_size() macro in patch #1. I am fine with this series as is.

What I meant is that the original patch 1 takes care about definitions of two functions. Not just a single one.

My understanding is that #ifdef CONFIG_NF_CONNTRACK_LABELS that wraps ctnetlink_label_size() is not correct (patch 1), instead CONFIG_NF_CONNTRACK_EVENTS should be used (patch 2).

Then, as a side effect this goes away (patch 1):

-#else
-#define ctnetlink_dump_labels(a, b) (0)
-#define ctnetlink_label_size(a) (0)
-#endif

that is why I am proposing to coaleasce these two patches in one.

author reviewer
#9 lore raw
Quoted 50 lines · Pablo Neira Ayuso
Quoted 32 lines · Andy Shevchenko
Quoted 31 lines · Pablo Neira Ayuso
Quoted 29 lines · Andy Shevchenko
Quoted 19 lines · Pablo Neira Ayuso
Quoted 4 lines · Simon Horman

Hi,

This short series updates conditional compilation of label helpers to:

Quoted 8 lines

1) Compile them regardless of if CONFIG_NF_CONNTRACK_LABELS is enabled or not. It is safe to do so as the functions will always return 0 if CONFIG_NF_CONNTRACK_LABELS is not enabled. And the compiler should optimise waway the code. Which is the desired behaviour.

2) Only compile ctnetlink_label_size if CONFIG_NF_CONNTRACK_EVENTS is enabled. This addresses a warning about this function being unused in this case.

Patch 1)

-#ifdef CONFIG_NF_CONNTRACK_LABELS
static inline int ctnetlink_label_size(const struct nf_conn *ct)

Quoted 7 lines

Patch 2)

+#ifdef CONFIG_NF_CONNTRACK_EVENTS
static inline int ctnetlink_label_size(const struct nf_conn *ct)

They both refer to ctnetlink_label_size(), #ifdef check is not correct.

But the first one touches more, no?

Quoted 5 lines
Quoted 2 lines

Yes, it also remove a #define ctnetlink_label_size() macro in patch #1. I am fine with this series as is.

What I meant is that the original patch 1 takes care about definitions of two functions. Not just a single one.

My understanding is that #ifdef CONFIG_NF_CONNTRACK_LABELS that wraps ctnetlink_label_size() is not correct (patch 1), instead CONFIG_NF_CONNTRACK_EVENTS should be used (patch 2).

Then, as a side effect this goes away (patch 1):

(quoted diff) +0 -4
-#else
-#define ctnetlink_dump_labels(a, b) (0)
-#define ctnetlink_label_size(a)     (0)
-#endif
Quoted 1 line

that is why I am proposing to coaleasce these two patches in one.

Thanks,

Just to clarify. I did think there is value in separating the two changes. But that was a subjective judgement on my part.

Your understanding of the overall change is correct.
And if it is preferred to have a single patch - as seems to be the case - then that is fine by me.

Going forward, I'll try to remember not to split-up patches for netfilter so much.

Kind regards,
Simon

#10 lore raw
Quoted 58 lines · Simon Horman
Quoted 50 lines · Pablo Neira Ayuso
Quoted 32 lines · Andy Shevchenko
Quoted 31 lines · Pablo Neira Ayuso
Quoted 29 lines · Andy Shevchenko
Quoted 19 lines · Pablo Neira Ayuso
Quoted 4 lines · Simon Horman

Hi,

This short series updates conditional compilation of label helpers to:

Quoted 8 lines

1) Compile them regardless of if CONFIG_NF_CONNTRACK_LABELS is enabled or not. It is safe to do so as the functions will always return 0 if CONFIG_NF_CONNTRACK_LABELS is not enabled. And the compiler should optimise waway the code. Which is the desired behaviour.

2) Only compile ctnetlink_label_size if CONFIG_NF_CONNTRACK_EVENTS is enabled. This addresses a warning about this function being unused in this case.

Patch 1)

-#ifdef CONFIG_NF_CONNTRACK_LABELS
static inline int ctnetlink_label_size(const struct nf_conn *ct)

Quoted 7 lines

Patch 2)

+#ifdef CONFIG_NF_CONNTRACK_EVENTS
static inline int ctnetlink_label_size(const struct nf_conn *ct)

They both refer to ctnetlink_label_size(), #ifdef check is not correct.

But the first one touches more, no?

Quoted 5 lines
Quoted 2 lines

Yes, it also remove a #define ctnetlink_label_size() macro in patch #1. I am fine with this series as is.

What I meant is that the original patch 1 takes care about definitions of two functions. Not just a single one.

My understanding is that #ifdef CONFIG_NF_CONNTRACK_LABELS that wraps ctnetlink_label_size() is not correct (patch 1), instead CONFIG_NF_CONNTRACK_EVENTS should be used (patch 2).

Then, as a side effect this goes away (patch 1):

(quoted diff) +0 -4
-#else
-#define ctnetlink_dump_labels(a, b) (0)
-#define ctnetlink_label_size(a)     (0)
-#endif
Quoted 1 line

that is why I am proposing to coaleasce these two patches in one.

Thanks,

Just to clarify. I did think there is value in separating the two changes. But that was a subjective judgement on my part.

Quoted 6 lines

Your understanding of the overall change is correct.
And if it is preferred to have a single patch - as seems to be the case - then that is fine by me.

Going forward, I'll try to remember not to split-up patches for netfilter so much.

Never mind too much, your splitting helps for reviewing.

This is also subjective judgement on my side.

author reviewer
#11 lore raw
In reply to Pablo Neira Ayuso
Quoted 21 lines · Pablo Neira Ayuso
Quoted 4 lines · Simon Horman

Hi,

This short series updates conditional compilation of label helpers to:

Quoted 8 lines

1) Compile them regardless of if CONFIG_NF_CONNTRACK_LABELS is enabled or not. It is safe to do so as the functions will always return 0 if CONFIG_NF_CONNTRACK_LABELS is not enabled. And the compiler should optimise waway the code. Which is the desired behaviour.

2) Only compile ctnetlink_label_size if CONFIG_NF_CONNTRACK_EVENTS is enabled. This addresses a warning about this function being unused in this case.

Patch 1)

-#ifdef CONFIG_NF_CONNTRACK_LABELS
static inline int ctnetlink_label_size(const struct nf_conn *ct)

Patch 2)

Quoted 7 lines

+#ifdef CONFIG_NF_CONNTRACK_EVENTS
static inline int ctnetlink_label_size(const struct nf_conn *ct)

They both refer to ctnetlink_label_size(), #ifdef check is not correct.

Would you mind if I collapsed these two patches before applying?

Sure, no problem.