Debian Codegraph @

src/expr/connlimit.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-or-later */cxx . . $ `<file>/src/expr/connlimit.c`/
2 /*
3 * (C) 2018 by Pablo Neira Ayuso <[email protected]>
4 */
5
6 #include <stdio.h>
7 #include <stdint.h>
8 #include <arpa/inet.h>
9 #include <errno.h>
10 #include <inttypes.h>
11
12 #include <linux/netfilter/nf_tables.h>cxx . . $ `<file>/include/linux/netfilter/nf_tables.h`/
13
14 #include "internal.h"cxx . . $ `<file>/include/internal.h`/
15 #include <libmnl/libmnl.h>
16 #include <libnftnl/expr.h>cxx . . $ `<file>/include/libnftnl/expr.h`/
17 #include <libnftnl/rule.h>cxx . . $ `<file>/include/libnftnl/rule.h`/
18
19 struct nftnl_expr_connlimitcxx . . $ nftnl_expr_connlimit# {
20 uint32_tcxx . . $ uint32_t# countcxx . . $ nftnl_expr_connlimit#count.;
21 uint32_tcxx . . $ uint32_t# flagscxx . . $ nftnl_expr_connlimit#flags.;
22 };
23
24 static int
25 nftnl_expr_connlimit_setcxx . . $ nftnl_expr_connlimit_set(211371a3e3842127).(struct nftnl_exprcxx . . $ nftnl_expr# *e, uint16_tcxx . . $ uint16_t# type,
26 const void *data, uint32_tcxx . . $ uint32_t# data_len, uint32_tcxx . . $ uint32_t# byteorder)
27 {
28 struct nftnl_expr_connlimitcxx . . $ nftnl_expr_connlimit# *connlimit = nftnl_expr_datacxx . . $ `include/expr_ops.h:31:9`!(e);
29
30 switch(type) {
31 case NFTNL_EXPR_CONNLIMIT_COUNTcxx . . $ NFTNL_EXPR_CONNLIMIT_COUNT.:
32 memcpycxx . . $ memcpy(cc817cb175f282d).(&connlimit->countcxx . . $ nftnl_expr_connlimit#count., data, data_len);
33 break;
34 case NFTNL_EXPR_CONNLIMIT_FLAGScxx . . $ NFTNL_EXPR_CONNLIMIT_FLAGS.:
35 memcpycxx . . $ memcpy(cc817cb175f282d).(&connlimit->flagscxx . . $ nftnl_expr_connlimit#flags., data, data_len);
36 break;
37 }
38 return 0;
39 }
40
41 static const void *
42 nftnl_expr_connlimit_getcxx . . $ nftnl_expr_connlimit_get(9de263c4f9e71c4b).(const struct nftnl_exprcxx . . $ nftnl_expr# *e, uint16_tcxx . . $ uint16_t# type,
43 uint32_tcxx . . $ uint32_t# *data_len)
44 {
45 struct nftnl_expr_connlimitcxx . . $ nftnl_expr_connlimit# *connlimit = nftnl_expr_datacxx . . $ `include/expr_ops.h:31:9`!(e);
46
47 switch(type) {
48 case NFTNL_EXPR_CONNLIMIT_COUNTcxx . . $ NFTNL_EXPR_CONNLIMIT_COUNT.:
49 *data_len = sizeof(connlimit->countcxx . . $ nftnl_expr_connlimit#count.);
50 return &connlimit->countcxx . . $ nftnl_expr_connlimit#count.;
51 case NFTNL_EXPR_CONNLIMIT_FLAGScxx . . $ NFTNL_EXPR_CONNLIMIT_FLAGS.:
52 *data_len = sizeof(connlimit->flagscxx . . $ nftnl_expr_connlimit#flags.);
53 return &connlimit->flagscxx . . $ nftnl_expr_connlimit#flags.;
54 }
55 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
56 }
57
58 static int nftnl_expr_connlimit_cbcxx . . $ nftnl_expr_connlimit_cb(de2ef18c48fd675c).(const struct nlattrcxx . . $ nlattr# *attr, void *data)
59 {
60 const struct nlattrcxx . . $ nlattr# **tb = data;
61 int type = mnl_attr_get_typecxx . . $ mnl_attr_get_type(1da47bcc4c4b975).(attr);
62
63 if (mnl_attr_type_validcxx . . $ mnl_attr_type_valid(47df1cce1c7be855).(attr, NFTA_CONNLIMIT_MAXcxx . . $ `include/linux/netfilter/nf_tables.h:1259:9`!) < 0)
64 return MNL_CB_OKcxx . . $ `<external>/12386019527593959648/libmnl.h:174:9`!;
65
66 switch(type) {
67 case NFTA_CONNLIMIT_COUNTcxx . . $ NFTA_CONNLIMIT_COUNT.:
68 case NFTA_CONNLIMIT_FLAGScxx . . $ NFTA_CONNLIMIT_FLAGS.:
69 if (mnl_attr_validatecxx . . $ mnl_attr_validate(e419697a5e1ae2b1).(attr, MNL_TYPE_U32cxx . . $ MNL_TYPE_U32.) < 0)
70 abi_breakagecxx . . $ `include/utils.h:28:9`!();
71 break;
72 }
73
74 tb[type] = attr;
75 return MNL_CB_OKcxx . . $ `<external>/12386019527593959648/libmnl.h:174:9`!;
76 }
77
78 static void
79 nftnl_expr_connlimit_buildcxx . . $ nftnl_expr_connlimit_build(93c7528a9cf90b41).(struct nlmsghdrcxx . . $ nlmsghdr# *nlh, const struct nftnl_exprcxx . . $ nftnl_expr# *e)
80 {
81 struct nftnl_expr_connlimitcxx . . $ nftnl_expr_connlimit# *connlimit = nftnl_expr_datacxx . . $ `include/expr_ops.h:31:9`!(e);
82
83 if (e->flagscxx . . $ nftnl_expr#flags. & (1 << NFTNL_EXPR_CONNLIMIT_COUNTcxx . . $ NFTNL_EXPR_CONNLIMIT_COUNT.))
84 mnl_attr_put_u32cxx . . $ mnl_attr_put_u32(b46fd0aeb0cfb96d).(nlh, NFTA_CONNLIMIT_COUNTcxx . . $ NFTA_CONNLIMIT_COUNT.,
85 htonlcxx . . $ `<external>/9581057695539925927/in.h:430:12`!(connlimit->count));
86 if (e->flagscxx . . $ nftnl_expr#flags. & (1 << NFTNL_EXPR_CONNLIMIT_FLAGScxx . . $ NFTNL_EXPR_CONNLIMIT_FLAGS.))
87 mnl_attr_put_u32cxx . . $ mnl_attr_put_u32(b46fd0aeb0cfb96d).(nlh, NFTA_CONNLIMIT_FLAGScxx . . $ NFTA_CONNLIMIT_FLAGS.,
88 htonlcxx . . $ `<external>/9581057695539925927/in.h:430:12`!(connlimit->flags));
89 }
90
91 static int
92 nftnl_expr_connlimit_parsecxx . . $ nftnl_expr_connlimit_parse(ed61207049d8af9a).(struct nftnl_exprcxx . . $ nftnl_expr# *e, struct nlattrcxx . . $ nlattr# *attr)
93 {
94 struct nftnl_expr_connlimitcxx . . $ nftnl_expr_connlimit# *connlimit = nftnl_expr_datacxx . . $ `include/expr_ops.h:31:9`!(e);
95 struct nlattrcxx . . $ nlattr# *tb[NFTA_CONNLIMIT_MAXcxx . . $ `include/linux/netfilter/nf_tables.h:1259:9`!+1] = {};
96
97 if (mnl_attr_parse_nestedcxx . . $ mnl_attr_parse_nested(f99c0e9fa94f99d9).(attr, nftnl_expr_connlimit_cbcxx . . $ nftnl_expr_connlimit_cb(de2ef18c48fd675c)., tb) < 0)
98 return -1;
99
100 if (tb[NFTA_CONNLIMIT_COUNTcxx . . $ NFTA_CONNLIMIT_COUNT.]) {
101 connlimit->countcxx . . $ nftnl_expr_connlimit#count. =
102 ntohlcxx . . $ `<external>/9581057695539925927/in.h:428:12`!(mnl_attr_get_u32(tb[NFTA_CONNLIMIT_COUNT]));
103 e->flagscxx . . $ nftnl_expr#flags. |= (1 << NFTNL_EXPR_CONNLIMIT_COUNTcxx . . $ NFTNL_EXPR_CONNLIMIT_COUNT.);
104 }
105 if (tb[NFTA_CONNLIMIT_FLAGScxx . . $ NFTA_CONNLIMIT_FLAGS.]) {
106 connlimit->flagscxx . . $ nftnl_expr_connlimit#flags. =
107 ntohlcxx . . $ `<external>/9581057695539925927/in.h:428:12`!(mnl_attr_get_u32(tb[NFTA_CONNLIMIT_FLAGS]));
108 e->flagscxx . . $ nftnl_expr#flags. |= (1 << NFTNL_EXPR_CONNLIMIT_FLAGScxx . . $ NFTNL_EXPR_CONNLIMIT_FLAGS.);
109 }
110
111 return 0;
112 }
113
114 static int nftnl_expr_connlimit_snprintfcxx . . $ nftnl_expr_connlimit_snprintf(2b4af69501aef780).(char *buf, size_t len,
115 uint32_tcxx . . $ uint32_t# flags,
116 const struct nftnl_exprcxx . . $ nftnl_expr# *e)
117 {
118 struct nftnl_expr_connlimitcxx . . $ nftnl_expr_connlimit# *connlimit = nftnl_expr_datacxx . . $ `include/expr_ops.h:31:9`!(e);
119
120 return snprintfcxx . . $ snprintf(ea502d73e74c754c).(buf, len, "count %u flags %x ",
121 connlimit->countcxx . . $ nftnl_expr_connlimit#count., connlimit->flagscxx . . $ nftnl_expr_connlimit#flags.);
122 }
123
124 static struct attr_policycxx . . $ attr_policy# connlimit_attr_policycxx . . $ connlimit_attr_policy.[__NFTNL_EXPR_CONNLIMIT_MAXcxx . . $ __NFTNL_EXPR_CONNLIMIT_MAX.] = {
125 [NFTNL_EXPR_CONNLIMIT_COUNTcxx . . $ NFTNL_EXPR_CONNLIMIT_COUNT.] = { .maxlen = sizeof(uint32_tcxx . . $ uint32_t#) },
126 [NFTNL_EXPR_CONNLIMIT_FLAGScxx . . $ NFTNL_EXPR_CONNLIMIT_FLAGS.] = { .maxlen = sizeof(uint32_tcxx . . $ uint32_t#) },
127 };
128
129 struct expr_opscxx . . $ expr_ops# expr_ops_connlimitcxx . . $ expr_ops_connlimit. = {
130 .name = "connlimit",
131 .alloc_len = sizeof(struct nftnl_expr_connlimitcxx . . $ nftnl_expr_connlimit#),
132 .nftnl_max_attr = __NFTNL_EXPR_CONNLIMIT_MAXcxx . . $ __NFTNL_EXPR_CONNLIMIT_MAX. - 1,
133 .attr_policy = connlimit_attr_policycxx . . $ connlimit_attr_policy.,
134 .set = nftnl_expr_connlimit_setcxx . . $ nftnl_expr_connlimit_set(211371a3e3842127).,
135 .get = nftnl_expr_connlimit_getcxx . . $ nftnl_expr_connlimit_get(9de263c4f9e71c4b).,
136 .parse = nftnl_expr_connlimit_parsecxx . . $ nftnl_expr_connlimit_parse(ed61207049d8af9a).,
137 .build = nftnl_expr_connlimit_buildcxx . . $ nftnl_expr_connlimit_build(93c7528a9cf90b41).,
138 .output = nftnl_expr_connlimit_snprintfcxx . . $ nftnl_expr_connlimit_snprintf(2b4af69501aef780).,
139 };