Skip to contentSkip to conversation

src: Export nftnl_set_clone symbol

PATCH In review chlorodose 3 participants 6 messages Mar 18 – Mar 19 netfilter

lore
Share & tools
lore

chlorodose

author
#0 lore raw

PATCH 1/1 src: Export nftnl_set_clone symbol

Seems that nftnl_set_clone is forgot to be exported, we add it back.

---
 src/set.c | 1 +
 1 file changed, 1 insertion(+)
src/set.c +1 -0
index 54674bc..e5e51b6 100644
@@ -360,6 +360,7 @@ uint64_t nftnl_set_get_u64(const struct nftnl_set *s, uint16_t attr)
 	return val ? *val : 0;
 }
 
+EXPORT_SYMBOL(nftnl_set_clone);
 struct nftnl_set *nftnl_set_clone(const struct nftnl_set *set)
 {
 	struct nftnl_set *newset;
Signature · 1 line
2.52.0
reviewer
#1 lore raw

Hi chlorodose,

Quoted 12 lines · chlorodose

Seems that nftnl_set_clone is forgot to be exported, we add it back.

---
 src/set.c | 1 +
 1 file changed, 1 insertion(+)
src/set.c +0 -0
index 54674bc..e5e51b6 100644

src/set.c uint64_t nftnl_set_get_u64(const struct nftnl_set *s, uint16_t attr) · line 366

Quoted 7 lines
src/set.c +1 -0
@@ -360,6 +360,7 @@ uint64_t nftnl_set_get_u64(const struct nftnl_set *s, uint16_t attr)
 	return val ? *val : 0;
 }
 
+EXPORT_SYMBOL(nftnl_set_clone);
 struct nftnl_set *nftnl_set_clone(const struct nftnl_set *set)
 {
 	struct nftnl_set *newset;

Don't you also have to add it to src/libnftnl.map? How did you test this patch?

Looking at the function itself, I fear the code is not correct anymore. E.g., it does not clone expr_list or user.data. If I was to decide, I'd rather drop it entirely instead of polishing it up. What's your use-case?

Cheers, Phil

#2 lore raw
Quoted 26 lines · Phil Sutter

Hi chlorodose,

Quoted 12 lines · chlorodose

Seems that nftnl_set_clone is forgot to be exported, we add it back.

---
 src/set.c | 1 +
 1 file changed, 1 insertion(+)
src/set.c +0 -0
index 54674bc..e5e51b6 100644

src/set.c uint64_t nftnl_set_get_u64(const struct nftnl_set *s, uint16_t attr) · line 366

Quoted 7 lines
src/set.c +1 -0
@@ -360,6 +360,7 @@ uint64_t nftnl_set_get_u64(const struct nftnl_set *s, uint16_t attr)
 	return val ? *val : 0;
 }
 
+EXPORT_SYMBOL(nftnl_set_clone);
 struct nftnl_set *nftnl_set_clone(const struct nftnl_set *set)
 {
 	struct nftnl_set *newset;

Don't you also have to add it to src/libnftnl.map? How did you test this patch?

Quoted 4 lines

Looking at the function itself, I fear the code is not correct anymore. E.g., it does not clone expr_list or user.data. If I was to decide, I'd rather drop it entirely instead of polishing it up. What's your use-case?

Indeed, this function is internal and it is incomplete. it does not provide a full clone.

reviewer
#3 lore raw
Quoted 27 lines · Pablo Neira Ayuso
Quoted 26 lines · Phil Sutter

Hi chlorodose,

Quoted 12 lines · chlorodose

Seems that nftnl_set_clone is forgot to be exported, we add it back.

---
 src/set.c | 1 +
 1 file changed, 1 insertion(+)
src/set.c +0 -0
index 54674bc..e5e51b6 100644

src/set.c uint64_t nftnl_set_get_u64(const struct nftnl_set *s, uint16_t attr) · line 366

Quoted 7 lines
src/set.c +1 -0
@@ -360,6 +360,7 @@ uint64_t nftnl_set_get_u64(const struct nftnl_set *s, uint16_t attr)
 	return val ? *val : 0;
 }
 
+EXPORT_SYMBOL(nftnl_set_clone);
 struct nftnl_set *nftnl_set_clone(const struct nftnl_set *set)
 {
 	struct nftnl_set *newset;

Don't you also have to add it to src/libnftnl.map? How did you test this patch?

Quoted 7 lines
Quoted 4 lines

Looking at the function itself, I fear the code is not correct anymore. E.g., it does not clone expr_list or user.data. If I was to decide, I'd rather drop it entirely instead of polishing it up. What's your use-case?

Indeed, this function is internal and it is incomplete. it does not provide a full clone.

I don't see it called inside libnftnl, though. Ah, it seems to have been used by the JSON API dropped in commit 80077787f8f21 ("src: remove json support"). And since we did not export it yet, we're safe to drop it unless chlorodose has a proper use-case for it.

Cheers, Phil

#4 lore raw

I have a use case where I want to construct a daemon that keeps a reference to an nft_set and repeatedly uses it to handle requests to add elems. I assume I must clone the nft_set from a clean copy each time, otherwise I'll resend all previous elements to the kernel. But I'm just starting to learn nftables, so I'm not sure my understanding is correct. Am I misunderstanding something here?

reviewer
#5 lore raw

Hi Chloro,

Quoted 6 lines · Chloro Dose

I have a use case where I want to construct a daemon that keeps a reference to an nft_set and repeatedly uses it to handle requests to add elems. I assume I must clone the nft_set from a clean copy each time, otherwise I'll resend all previous elements to the kernel. But I'm just starting to learn nftables, so I'm not sure my understanding is correct. Am I misunderstanding something here?

All you need to keep record of is the set's name and that of the table it belongs to as well as the latter's family. With this data you may generate a NFT_MSG_NEWSETELEM-type message for the kernel to add one or many elements to an existing set. For reference, mnl_nft_setelem_batch() in nftables.git/src/mnl.c should be a good example of how to do this using libnftnl and libmnl.

Cheers, Phil