1 #include <assert.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <time.h>
5
6 #include <libmnl/libmnl.h>
7 #include <libnetfilter_conntrack/libnetfilter_conntrack.h>
8
print_label(struct nfct_labelmap * map)9 static void print_label(struct nfct_labelmap *map)
10 {
11 int b = nfct_labelmap_get_bit(map, "test label 1");
12 assert(b == 1);
13
14 b = nfct_labelmap_get_bit(map, "zero");
15 assert(b == 0);
16
17 b = nfct_labelmap_get_bit(map, "test label 2");
18 assert(b == 2);
19
20 b = nfct_labelmap_get_bit(map, "duplicate");
21 assert(b < 0);
22
23 b = nfct_labelmap_get_bit(map, "invalid label");
24 assert(b < 0);
25
26 b = nfct_labelmap_get_bit(map, "T");
27 assert(b == 42);
28 }
29
dump_map(struct nfct_labelmap * map)30 static void dump_map(struct nfct_labelmap *map)
31 {
32 unsigned int i = 0;
33
34 for (;;) {
35 const char *name = nfct_labelmap_get_name(map, i);
36 if (!name)
37 break;
38 if (name[0])
39 printf("\t\"%s\", bit %d\n", name, i);
40 i++;
41 }
42 }
43
main(void)44 int main(void)
45 {
46 struct nfct_labelmap *l;
47
48 l = nfct_labelmap_new("/");
49 assert(l == NULL);
50
51 l = nfct_labelmap_new(NULL);
52 if (l) {
53 puts("default connlabel.conf:");
54 dump_map(l);
55 nfct_labelmap_destroy(l);
56 } else {
57 puts("no default config found");
58 }
59
60 l = nfct_labelmap_new("qa-connlabel.conf");
61 if (!l)
62 l = nfct_labelmap_new("qa/qa-connlabel.conf");
63 assert(l);
64 puts("qa-connlabel.conf:");
65 dump_map(l);
66 print_label(l);
67 nfct_labelmap_destroy(l);
68
69 return 0;
70 }
71