test_connlabel.c
#include <assert.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <libmnl/libmnl.h>
#include <libnetfilter_conntrack/libnetfilter_conntrack.h>
static void print_label(struct nfct_labelmap *map)
{
int b = nfct_labelmap_get_bit(map, "test label 1");
assert(b == 1);
b = nfct_labelmap_get_bit(map, "zero");
assert(b == 0);
b = nfct_labelmap_get_bit(map, "test label 2");
assert(b == 2);
b = nfct_labelmap_get_bit(map, "duplicate");
assert(b < 0);
b = nfct_labelmap_get_bit(map, "invalid label");
assert(b < 0);
b = nfct_labelmap_get_bit(map, "T");
assert(b == 42);
}
static void dump_map(struct nfct_labelmap *map)
{
unsigned int i = 0;
for (;;) {
const char *name = nfct_labelmap_get_name(map, i);
if (!name)
break;
if (name[0])
printf("\t\"%s\", bit %d\n", name, i);
i++;
}
}
int main(void)
{
struct nfct_labelmap *l;
l = nfct_labelmap_new("/");
assert(l == NULL);
l = nfct_labelmap_new(NULL);
if (l) {
puts("default connlabel.conf:");
dump_map(l);
nfct_labelmap_destroy(l);
} else {
puts("no default config found");
}
l = nfct_labelmap_new("qa-connlabel.conf");
if (!l)
l = nfct_labelmap_new("tests/qa-connlabel.conf");
if (!l) {
char testconf[PATH_MAX];
snprintf(testconf, PATH_MAX,
"%s/qa-connlabel.conf", getenv("srcdir"));
l = nfct_labelmap_new(testconf);
}
assert(l);
puts("qa-connlabel.conf:");
dump_map(l);
print_label(l);
nfct_labelmap_destroy(l);
return 0;
}
nfct_labelmap_destroy
void nfct_labelmap_destroy(struct nfct_labelmap *map)
Definition conntrack/api.c:1638
nfct_labelmap_get_name
const char * nfct_labelmap_get_name(struct nfct_labelmap *m, unsigned int bit)
Definition conntrack/api.c:1600
nfct_labelmap_new
struct nfct_labelmap * nfct_labelmap_new(const char *mapfile)
Definition conntrack/api.c:1626
nfct_labelmap_get_bit
int nfct_labelmap_get_bit(struct nfct_labelmap *m, const char *name)
Definition conntrack/api.c:1613
nfct_labelmap
Definition labels.c:17