From 262e67807dbd02f04c43706d79a71cbca5ffed5d Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Thu, 30 Oct 2008 20:52:26 +0100 Subject: API: add nfct_attr_is_set_array function This new function checks for the presence of a given set of attributes that are passed as an array. Signed-off-by: Pablo Neira Ayuso --- .../libnetfilter_conntrack.h | 4 ++++ src/conntrack/api.c | 28 ++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/include/libnetfilter_conntrack/libnetfilter_conntrack.h b/include/libnetfilter_conntrack/libnetfilter_conntrack.h index 2fde9a8..0c8b715 100644 --- a/include/libnetfilter_conntrack/libnetfilter_conntrack.h +++ b/include/libnetfilter_conntrack/libnetfilter_conntrack.h @@ -273,6 +273,10 @@ extern u_int32_t nfct_get_attr_u32(const struct nf_conntrack *ct, extern int nfct_attr_is_set(const struct nf_conntrack *ct, const enum nf_conntrack_attr type); +extern int nfct_attr_is_set_array(const struct nf_conntrack *ct, + const enum nf_conntrack_attr *type_array, + int size); + /* unsetter */ extern int nfct_attr_unset(struct nf_conntrack *ct, const enum nf_conntrack_attr type); diff --git a/src/conntrack/api.c b/src/conntrack/api.c index efd298e..a5ddbc2 100644 --- a/src/conntrack/api.c +++ b/src/conntrack/api.c @@ -362,6 +362,34 @@ int nfct_attr_is_set(const struct nf_conntrack *ct, return test_bit(type, ct->set); } +/** + * nfct_attr_is_set_array - check if an array if attribute types is set + * @ct: pointer to a valid conntrack object + * @array: attribute type array + * @size: size of the array + * + * On error, -1 is returned and errno is set appropiately, otherwise + * the value of the attribute is returned. + */ +int nfct_attr_is_set_array(const struct nf_conntrack *ct, + const enum nf_conntrack_attr *type_array, + int size) +{ + int i; + + assert(ct != NULL); + + for (i=0; i= ATTR_MAX)) { + errno = EINVAL; + return -1; + } + if (!test_bit(type_array[i], ct->set)) + return 0; + } + return 1; +} + /** * nfct_attr_unset - unset a certain attribute * @type: attribute type -- cgit v1.2.3