set: add helper to get the first set_elem
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
@@ -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
@@ -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
@@ -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; };
Quoted 4 lines · Arturo Borrero Gonzalez
Add a helper that returns a pointer to the first
set_elemin 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.
Pablo Neira Ayuso
maintainerQuoted 10 lines · Patrick McHardy
Quoted 4 lines · Arturo Borrero Gonzalez
Add a helper that returns a pointer to the first
set_elemin 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.
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_elemin 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