Skip to contentSkip to conversation

set: add helper to get the first set_elem

PATCH In review Arturo Borrero Gonzalez 3 participants 4 messages Apr 15, 2014 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 set: add helper to get the first set_elem

Add a helper that returns a pointer to the first set_elem in a given set.

This function is useful in situations where you know the set only have one element (ie, event reporting from the kernel).

---
 include/libnftnl/set.h |    1 +
 src/libnftnl.map       |    1 +
 src/set.c              |   16 ++++++++++++++++
 3 files changed, 18 insertions(+)
include/libnftnl/set.h +1 -0
index a975f1c..739fa2a 100644
@@ -89,6 +89,7 @@ struct nft_set_elem *nft_set_elem_alloc(void);
 void nft_set_elem_free(struct nft_set_elem *s);
 
 void nft_set_elem_add(struct nft_set *s, struct nft_set_elem *elem);
+struct nft_set_elem *nft_set_get_first_elem(struct nft_set *s);
 
 void nft_set_elem_attr_unset(struct nft_set_elem *s, uint16_t attr);
 void nft_set_elem_attr_set(struct nft_set_elem *s, uint16_t attr, const void *data, uint32_t data_len);
src/libnftnl.map +1 -0
index b11db67..b63c2d1 100644
@@ -151,6 +151,7 @@ global:
   nft_set_elem_alloc;
   nft_set_elem_free;
   nft_set_elem_add;
+  nft_set_get_first_elem;
   nft_set_elem_foreach;
   nft_set_elem_attr_is_set;
   nft_set_elem_attr_unset;
src/set.c +16 -0
index 550c262..50107d3 100644
@@ -737,6 +737,22 @@ void nft_set_elem_add(struct nft_set *s, struct nft_set_elem *elem)
 }
 EXPORT_SYMBOL(nft_set_elem_add);
 
+struct nft_set_elem *nft_set_get_first_elem(struct nft_set *s)
+{
+	struct nft_set_elems_iter *sei;
+	struct nft_set_elem *se;
+
+	sei = nft_set_elems_iter_create(nls);
+	if (sei == NULL)
+		return NULL;
+
+	se = nft_set_elems_iter_cur(sei);
+	nft_set_elems_iter_destroy(sei);
+
+	return se;
+}
+EXPORT_SYMBOL(nft_set_get_first_elem);
+
 struct nft_set_list {
 	struct list_head list;
 };
#1 lore raw
Quoted 4 lines · Arturo Borrero Gonzalez

Add a helper that returns a pointer to the first set_elem in a given set.

This function is useful in situations where you know the set only have one element (ie, event reporting from the kernel).

That doesn't seem right to me. As I said in my review of the notification patch, userspace *must* be prepared for multiple elements being reported at once since it is very likely that we will change the kernel side in the future for efficiency reasons.

#2 lore raw
Quoted 10 lines · Patrick McHardy
Quoted 4 lines · Arturo Borrero Gonzalez

Add a helper that returns a pointer to the first set_elem in a given set.

This function is useful in situations where you know the set only have one element (ie, event reporting from the kernel).

That doesn't seem right to me. As I said in my review of the notification patch, userspace *must* be prepared for multiple elements being reported at once since it is very likely that we will change the kernel side in the future for efficiency reasons.

I see. Arturo, you have to consider that the set may have more than one element in the event from userspace, even if currently we only have one single element. So use the set iterator to print all the elements in the set instead.

#3 lore raw
Quoted 12 lines · Pablo Neira Ayuso
Quoted 10 lines · Patrick McHardy
Quoted 4 lines · Arturo Borrero Gonzalez

Add a helper that returns a pointer to the first set_elem in a given set.

This function is useful in situations where you know the set only have one element (ie, event reporting from the kernel).

That doesn't seem right to me. As I said in my review of the notification patch, userspace *must* be prepared for multiple elements being reported at once since it is very likely that we will change the kernel side in the future for efficiency reasons.

Quoted 4 lines

I see. Arturo, you have to consider that the set may have more than one element in the event from userspace, even if currently we only have one single element. So use the set iterator to print all the elements in the set instead.

ok!

regards.

Signature · 5 lines
Arturo Borrero González
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html