libnftnl/include/str_array.h
Phil Sutter 0576274ad5 Introduce struct nftnl_str_array
This data structure holds an array of allocated strings for use in
nftnl_chain and nftnl_flowtable structs. For convenience, implement
functions to clear, populate and iterate over contents.

While at it, extend chain and flowtable tests to cover these attributes,
too.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Reviewed-by: Pablo Neira Ayuso <pablo@netfilter.org>
2024-10-29 23:26:43 +01:00

23 lines
555 B
C

#ifndef LIBNFTNL_STR_ARRAY_H
#define LIBNFTNL_STR_ARRAY_H 1
#include <stdint.h>
struct nlattr;
struct nftnl_str_array {
char **array;
uint32_t len;
};
void nftnl_str_array_clear(struct nftnl_str_array *sa);
int nftnl_str_array_set(struct nftnl_str_array *sa, const char * const *array);
int nftnl_parse_devs(struct nftnl_str_array *sa, const struct nlattr *nest);
#define nftnl_str_array_foreach(ptr, sa, idx) \
for (idx = 0, ptr = (sa)->array[idx]; \
idx < (sa)->len; \
ptr = (sa)->array[++idx])
#endif /* LIBNFTNL_STR_ARRAY_H */