libnl: /data/src/libnl3/lib/netfilter/netfilter.c Source File

libnl 3.7.0

netfilter.c
1 /* SPDX-License-Identifier: LGPL-2.1-only */
2 /*
3 * Copyright (c) 2008 Patrick McHardy <kaber@trash.net>
4 */
5
6 #include <netlink-private/netlink.h>
7 #include <netlink/netfilter/netfilter.h>
8 #include <linux/netfilter.h>
9
10 static const struct trans_tbl nfnl_verdicts[] = {
11 __ADD(NF_DROP, NF_DROP),
12 __ADD(NF_ACCEPT, NF_ACCEPT),
13 __ADD(NF_STOLEN, NF_STOLEN),
14 __ADD(NF_QUEUE, NF_QUEUE),
15 __ADD(NF_REPEAT, NF_REPEAT),
16 __ADD(NF_STOP, NF_STOP),
17 };
18
19 char *nfnl_verdict2str(unsigned int verdict, char *buf, size_t len)
20 {
21 return __type2str(verdict, buf, len, nfnl_verdicts,
22 ARRAY_SIZE(nfnl_verdicts));
23 }
24
25 unsigned int nfnl_str2verdict(const char *name)
26 {
27 return __str2type(name, nfnl_verdicts, ARRAY_SIZE(nfnl_verdicts));
28 }
29
30 static const struct trans_tbl nfnl_inet_hooks[] = {
31 __ADD(NF_INET_PRE_ROUTING, NF_INET_PREROUTING),
32 __ADD(NF_INET_LOCAL_IN, NF_INET_LOCAL_IN),
33 __ADD(NF_INET_FORWARD, NF_INET_FORWARD),
34 __ADD(NF_INET_LOCAL_OUT, NF_INET_LOCAL_OUT),
35 __ADD(NF_INET_POST_ROUTING, NF_INET_POST_ROUTING),
36 };
37
38 char *nfnl_inet_hook2str(unsigned int hook, char *buf, size_t len)
39 {
40 return __type2str(hook, buf, len, nfnl_inet_hooks,
41 ARRAY_SIZE(nfnl_inet_hooks));
42 }
43
44 unsigned int nfnl_str2inet_hook(const char *name)
45 {
46 return __str2type(name, nfnl_inet_hooks, ARRAY_SIZE(nfnl_inet_hooks));
47 }