libnl 3.5.0

netfilter.c
1 /* SPDX-License-Identifier: LGPL-2.1-only */
2 /*
3 * lib/netfilter/netfilter.c Netfilter Generic Functions
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation version 2.1
8 * of the License.
9 *
10 * Copyright (c) 2008 Patrick McHardy <kaber@trash.net>
11 */
12
13 #include <netlink-private/netlink.h>
14 #include <netlink/netfilter/netfilter.h>
15 #include <linux/netfilter.h>
16
17 static const struct trans_tbl nfnl_verdicts[] = {
18 __ADD(NF_DROP, NF_DROP),
19 __ADD(NF_ACCEPT, NF_ACCEPT),
20 __ADD(NF_STOLEN, NF_STOLEN),
21 __ADD(NF_QUEUE, NF_QUEUE),
22 __ADD(NF_REPEAT, NF_REPEAT),
23 __ADD(NF_STOP, NF_STOP),
24 };
25
26 char *nfnl_verdict2str(unsigned int verdict, char *buf, size_t len)
27 {
28 return __type2str(verdict, buf, len, nfnl_verdicts,
29 ARRAY_SIZE(nfnl_verdicts));
30 }
31
32 unsigned int nfnl_str2verdict(const char *name)
33 {
34 return __str2type(name, nfnl_verdicts, ARRAY_SIZE(nfnl_verdicts));
35 }
36
37 static const struct trans_tbl nfnl_inet_hooks[] = {
38 __ADD(NF_INET_PRE_ROUTING, NF_INET_PREROUTING),
39 __ADD(NF_INET_LOCAL_IN, NF_INET_LOCAL_IN),
40 __ADD(NF_INET_FORWARD, NF_INET_FORWARD),
41 __ADD(NF_INET_LOCAL_OUT, NF_INET_LOCAL_OUT),
42 __ADD(NF_INET_POST_ROUTING, NF_INET_POST_ROUTING),
43 };
44
45 char *nfnl_inet_hook2str(unsigned int hook, char *buf, size_t len)
46 {
47 return __type2str(hook, buf, len, nfnl_inet_hooks,
48 ARRAY_SIZE(nfnl_inet_hooks));
49 }
50
51 unsigned int nfnl_str2inet_hook(const char *name)
52 {
53 return __str2type(name, nfnl_inet_hooks, ARRAY_SIZE(nfnl_inet_hooks));
54 }