Debian Codegraph @

src/expr/objref.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-or-later */cxx . . $ `<file>/src/expr/objref.c`/
2 /*
3 * (C) 2016 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_objrefcxx . . $ nftnl_expr_objref# {
20 structcxx . . $ nftnl_expr_objref#$anonymous_type_0# {
21 uint32_tcxx . . $ uint32_t# typecxx . . $ nftnl_expr_objref#$anonymous_type_0#type.;
22 const char *namecxx . . $ nftnl_expr_objref#$anonymous_type_0#name.;
23 } immcxx . . $ nftnl_expr_objref#imm.;
24 structcxx . . $ nftnl_expr_objref#$anonymous_type_1# {
25 uint32_tcxx . . $ uint32_t# sregcxx . . $ nftnl_expr_objref#$anonymous_type_1#sreg.;
26 const char *namecxx . . $ nftnl_expr_objref#$anonymous_type_1#name.;
27 uint32_tcxx . . $ uint32_t# idcxx . . $ nftnl_expr_objref#$anonymous_type_1#id.;
28 } setcxx . . $ nftnl_expr_objref#set.;
29 };
30
31 static int
32 nftnl_expr_objref_setcxx . . $ nftnl_expr_objref_set(211371a3e3842127).(struct nftnl_exprcxx . . $ nftnl_expr# *e, uint16_tcxx . . $ uint16_t# type,
33 const void *data, uint32_tcxx . . $ uint32_t# data_len, uint32_tcxx . . $ uint32_t# byteorder)
34 {
35 struct nftnl_expr_objrefcxx . . $ nftnl_expr_objref# *objref = nftnl_expr_datacxx . . $ `include/expr_ops.h:31:9`!(e);
36
37 switch(type) {
38 case NFTNL_EXPR_OBJREF_IMM_TYPEcxx . . $ NFTNL_EXPR_OBJREF_IMM_TYPE.:
39 memcpycxx . . $ memcpy(cc817cb175f282d).(&objref->immcxx . . $ nftnl_expr_objref#imm..typecxx . . $ nftnl_expr_objref#$anonymous_type_0#type., data, data_len);
40 break;
41 case NFTNL_EXPR_OBJREF_IMM_NAMEcxx . . $ NFTNL_EXPR_OBJREF_IMM_NAME.:
42 objref->immcxx . . $ nftnl_expr_objref#imm..namecxx . . $ nftnl_expr_objref#$anonymous_type_0#name. = strdupcxx . . $ strdup(a8b8e32347182212).(data);
43 if (!objref->immcxx . . $ nftnl_expr_objref#imm..namecxx . . $ nftnl_expr_objref#$anonymous_type_0#name.)
44 return -1;
45 break;
46 case NFTNL_EXPR_OBJREF_SET_SREGcxx . . $ NFTNL_EXPR_OBJREF_SET_SREG.:
47 memcpycxx . . $ memcpy(cc817cb175f282d).(&objref->setcxx . . $ nftnl_expr_objref#set..sregcxx . . $ nftnl_expr_objref#$anonymous_type_1#sreg., data, data_len);
48 break;
49 case NFTNL_EXPR_OBJREF_SET_NAMEcxx . . $ NFTNL_EXPR_OBJREF_SET_NAME.:
50 objref->setcxx . . $ nftnl_expr_objref#set..namecxx . . $ nftnl_expr_objref#$anonymous_type_1#name. = strdupcxx . . $ strdup(a8b8e32347182212).(data);
51 if (!objref->setcxx . . $ nftnl_expr_objref#set..namecxx . . $ nftnl_expr_objref#$anonymous_type_1#name.)
52 return -1;
53 break;
54 case NFTNL_EXPR_OBJREF_SET_IDcxx . . $ NFTNL_EXPR_OBJREF_SET_ID.:
55 memcpycxx . . $ memcpy(cc817cb175f282d).(&objref->setcxx . . $ nftnl_expr_objref#set..idcxx . . $ nftnl_expr_objref#$anonymous_type_1#id., data, data_len);
56 break;
57 }
58 return 0;
59 }
60
61 static const void *nftnl_expr_objref_getcxx . . $ nftnl_expr_objref_get(9de263c4f9e71c4b).(const struct nftnl_exprcxx . . $ nftnl_expr# *e,
62 uint16_tcxx . . $ uint16_t# type, uint32_tcxx . . $ uint32_t# *data_len)
63 {
64 struct nftnl_expr_objrefcxx . . $ nftnl_expr_objref# *objref = nftnl_expr_datacxx . . $ `include/expr_ops.h:31:9`!(e);
65
66 switch(type) {
67 case NFTNL_EXPR_OBJREF_IMM_TYPEcxx . . $ NFTNL_EXPR_OBJREF_IMM_TYPE.:
68 *data_len = sizeof(objref->immcxx . . $ nftnl_expr_objref#imm..typecxx . . $ nftnl_expr_objref#$anonymous_type_0#type.);
69 return &objref->immcxx . . $ nftnl_expr_objref#imm..typecxx . . $ nftnl_expr_objref#$anonymous_type_0#type.;
70 case NFTNL_EXPR_OBJREF_IMM_NAMEcxx . . $ NFTNL_EXPR_OBJREF_IMM_NAME.:
71 *data_len = strlencxx . . $ strlen(751346f8406fd082).(objref->immcxx . . $ nftnl_expr_objref#imm..namecxx . . $ nftnl_expr_objref#$anonymous_type_0#name.) + 1;
72 return objref->immcxx . . $ nftnl_expr_objref#imm..namecxx . . $ nftnl_expr_objref#$anonymous_type_0#name.;
73 case NFTNL_EXPR_OBJREF_SET_SREGcxx . . $ NFTNL_EXPR_OBJREF_SET_SREG.:
74 *data_len = sizeof(objref->setcxx . . $ nftnl_expr_objref#set..sregcxx . . $ nftnl_expr_objref#$anonymous_type_1#sreg.);
75 return &objref->setcxx . . $ nftnl_expr_objref#set..sregcxx . . $ nftnl_expr_objref#$anonymous_type_1#sreg.;
76 case NFTNL_EXPR_OBJREF_SET_NAMEcxx . . $ NFTNL_EXPR_OBJREF_SET_NAME.:
77 *data_len = strlencxx . . $ strlen(751346f8406fd082).(objref->setcxx . . $ nftnl_expr_objref#set..namecxx . . $ nftnl_expr_objref#$anonymous_type_1#name.) + 1;
78 return objref->setcxx . . $ nftnl_expr_objref#set..namecxx . . $ nftnl_expr_objref#$anonymous_type_1#name.;
79 case NFTNL_EXPR_OBJREF_SET_IDcxx . . $ NFTNL_EXPR_OBJREF_SET_ID.:
80 *data_len = sizeof(objref->setcxx . . $ nftnl_expr_objref#set..idcxx . . $ nftnl_expr_objref#$anonymous_type_1#id.);
81 return &objref->setcxx . . $ nftnl_expr_objref#set..idcxx . . $ nftnl_expr_objref#$anonymous_type_1#id.;
82 }
83 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
84 }
85
86 static int nftnl_expr_objref_cbcxx . . $ nftnl_expr_objref_cb(de2ef18c48fd675c).(const struct nlattrcxx . . $ nlattr# *attr, void *data)
87 {
88 int type = mnl_attr_get_typecxx . . $ mnl_attr_get_type(1da47bcc4c4b975).(attr);
89 const struct nlattrcxx . . $ nlattr# **tb = data;
90
91 if (mnl_attr_type_validcxx . . $ mnl_attr_type_valid(47df1cce1c7be855).(attr, NFTA_OBJREF_MAXcxx . . $ `include/linux/netfilter/nf_tables.h:1576:9`!) < 0)
92 return MNL_CB_OKcxx . . $ `<external>/12386019527593959648/libmnl.h:174:9`!;
93
94 switch(type) {
95 case NFTA_OBJREF_IMM_TYPEcxx . . $ NFTA_OBJREF_IMM_TYPE.:
96 if (mnl_attr_validatecxx . . $ mnl_attr_validate(e419697a5e1ae2b1).(attr, MNL_TYPE_U32cxx . . $ MNL_TYPE_U32.) < 0)
97 abi_breakagecxx . . $ `include/utils.h:28:9`!();
98 break;
99 case NFTA_OBJREF_IMM_NAMEcxx . . $ NFTA_OBJREF_IMM_NAME.:
100 case NFTA_OBJREF_SET_NAMEcxx . . $ NFTA_OBJREF_SET_NAME.:
101 if (mnl_attr_validatecxx . . $ mnl_attr_validate(e419697a5e1ae2b1).(attr, MNL_TYPE_STRINGcxx . . $ MNL_TYPE_STRING.) < 0)
102 abi_breakagecxx . . $ `include/utils.h:28:9`!();
103 break;
104 case NFTA_OBJREF_SET_SREGcxx . . $ NFTA_OBJREF_SET_SREG.:
105 case NFTA_OBJREF_SET_IDcxx . . $ NFTA_OBJREF_SET_ID.:
106 if (mnl_attr_validatecxx . . $ mnl_attr_validate(e419697a5e1ae2b1).(attr, MNL_TYPE_U32cxx . . $ MNL_TYPE_U32.) < 0)
107 abi_breakagecxx . . $ `include/utils.h:28:9`!();
108 break;
109 }
110
111 tb[type] = attr;
112 return MNL_CB_OKcxx . . $ `<external>/12386019527593959648/libmnl.h:174:9`!;
113 }
114
115 static void nftnl_expr_objref_buildcxx . . $ nftnl_expr_objref_build(93c7528a9cf90b41).(struct nlmsghdrcxx . . $ nlmsghdr# *nlh,
116 const struct nftnl_exprcxx . . $ nftnl_expr# *e)
117 {
118 struct nftnl_expr_objrefcxx . . $ nftnl_expr_objref# *objref = nftnl_expr_datacxx . . $ `include/expr_ops.h:31:9`!(e);
119
120 if (e->flagscxx . . $ nftnl_expr#flags. & (1 << NFTNL_EXPR_OBJREF_IMM_TYPEcxx . . $ NFTNL_EXPR_OBJREF_IMM_TYPE.))
121 mnl_attr_put_u32cxx . . $ mnl_attr_put_u32(b46fd0aeb0cfb96d).(nlh, NFTA_OBJREF_IMM_TYPEcxx . . $ NFTA_OBJREF_IMM_TYPE.,
122 htonlcxx . . $ `<external>/9581057695539925927/in.h:430:12`!(objref->imm.type));
123 if (e->flagscxx . . $ nftnl_expr#flags. & (1 << NFTNL_EXPR_OBJREF_IMM_NAMEcxx . . $ NFTNL_EXPR_OBJREF_IMM_NAME.))
124 mnl_attr_put_strcxx . . $ mnl_attr_put_str(eb76286d4bfc1a8d).(nlh, NFTA_OBJREF_IMM_NAMEcxx . . $ NFTA_OBJREF_IMM_NAME., objref->immcxx . . $ nftnl_expr_objref#imm..namecxx . . $ nftnl_expr_objref#$anonymous_type_0#name.);
125 if (e->flagscxx . . $ nftnl_expr#flags. & (1 << NFTNL_EXPR_OBJREF_SET_SREGcxx . . $ NFTNL_EXPR_OBJREF_SET_SREG.))
126 mnl_attr_put_u32cxx . . $ mnl_attr_put_u32(b46fd0aeb0cfb96d).(nlh, NFTA_OBJREF_SET_SREGcxx . . $ NFTA_OBJREF_SET_SREG.,
127 htonlcxx . . $ `<external>/9581057695539925927/in.h:430:12`!(objref->set.sreg));
128 if (e->flagscxx . . $ nftnl_expr#flags. & (1 << NFTNL_EXPR_OBJREF_SET_NAMEcxx . . $ NFTNL_EXPR_OBJREF_SET_NAME.))
129 mnl_attr_put_strcxx . . $ mnl_attr_put_str(eb76286d4bfc1a8d).(nlh, NFTA_OBJREF_SET_NAMEcxx . . $ NFTA_OBJREF_SET_NAME., objref->setcxx . . $ nftnl_expr_objref#set..namecxx . . $ nftnl_expr_objref#$anonymous_type_1#name.);
130 if (e->flagscxx . . $ nftnl_expr#flags. & (1 << NFTNL_EXPR_OBJREF_SET_IDcxx . . $ NFTNL_EXPR_OBJREF_SET_ID.))
131 mnl_attr_put_u32cxx . . $ mnl_attr_put_u32(b46fd0aeb0cfb96d).(nlh, NFTA_OBJREF_SET_IDcxx . . $ NFTA_OBJREF_SET_ID.,
132 htonlcxx . . $ `<external>/9581057695539925927/in.h:430:12`!(objref->set.id));
133 }
134
135 static int nftnl_expr_objref_parsecxx . . $ nftnl_expr_objref_parse(ed61207049d8af9a).(struct nftnl_exprcxx . . $ nftnl_expr# *e, struct nlattrcxx . . $ nlattr# *attr)
136 {
137 struct nftnl_expr_objrefcxx . . $ nftnl_expr_objref# *objref = nftnl_expr_datacxx . . $ `include/expr_ops.h:31:9`!(e);
138 struct nlattrcxx . . $ nlattr# *tb[NFTA_OBJREF_MAXcxx . . $ `include/linux/netfilter/nf_tables.h:1576:9`! + 1] = {};
139
140 if (mnl_attr_parse_nestedcxx . . $ mnl_attr_parse_nested(f99c0e9fa94f99d9).(attr, nftnl_expr_objref_cbcxx . . $ nftnl_expr_objref_cb(de2ef18c48fd675c)., tb) < 0)
141 return -1;
142
143 if (tb[NFTA_OBJREF_IMM_TYPEcxx . . $ NFTA_OBJREF_IMM_TYPE.]) {
144 objref->immcxx . . $ nftnl_expr_objref#imm..typecxx . . $ nftnl_expr_objref#$anonymous_type_0#type. =
145 ntohlcxx . . $ `<external>/9581057695539925927/in.h:428:12`!(mnl_attr_get_u32(tb[NFTA_OBJREF_IMM_TYPE]));
146 e->flagscxx . . $ nftnl_expr#flags. |= (1 << NFTNL_EXPR_OBJREF_IMM_TYPEcxx . . $ NFTNL_EXPR_OBJREF_IMM_TYPE.);
147 }
148 if (nftnl_parse_str_attrcxx . . $ nftnl_parse_str_attr(2002c8408bf98f7f).(tb[NFTA_OBJREF_IMM_NAMEcxx . . $ NFTA_OBJREF_IMM_NAME.],
149 NFTNL_EXPR_OBJREF_IMM_NAMEcxx . . $ NFTNL_EXPR_OBJREF_IMM_NAME.,
150 &objref->immcxx . . $ nftnl_expr_objref#imm..namecxx . . $ nftnl_expr_objref#$anonymous_type_0#name., &e->flagscxx . . $ nftnl_expr#flags.) < 0)
151 return -1;
152 if (tb[NFTA_OBJREF_SET_SREGcxx . . $ NFTA_OBJREF_SET_SREG.]) {
153 objref->setcxx . . $ nftnl_expr_objref#set..sregcxx . . $ nftnl_expr_objref#$anonymous_type_1#sreg. =
154 ntohlcxx . . $ `<external>/9581057695539925927/in.h:428:12`!(mnl_attr_get_u32(tb[NFTA_OBJREF_SET_SREG]));
155 e->flagscxx . . $ nftnl_expr#flags. |= (1 << NFTNL_EXPR_OBJREF_SET_SREGcxx . . $ NFTNL_EXPR_OBJREF_SET_SREG.);
156 }
157 if (nftnl_parse_str_attrcxx . . $ nftnl_parse_str_attr(2002c8408bf98f7f).(tb[NFTA_OBJREF_SET_NAMEcxx . . $ NFTA_OBJREF_SET_NAME.],
158 NFTNL_EXPR_OBJREF_SET_NAMEcxx . . $ NFTNL_EXPR_OBJREF_SET_NAME.,
159 &objref->setcxx . . $ nftnl_expr_objref#set..namecxx . . $ nftnl_expr_objref#$anonymous_type_1#name., &e->flagscxx . . $ nftnl_expr#flags.) < 0)
160 return -1;
161 if (tb[NFTA_OBJREF_SET_IDcxx . . $ NFTA_OBJREF_SET_ID.]) {
162 objref->setcxx . . $ nftnl_expr_objref#set..idcxx . . $ nftnl_expr_objref#$anonymous_type_1#id. =
163 ntohlcxx . . $ `<external>/9581057695539925927/in.h:428:12`!(mnl_attr_get_u32(tb[NFTA_OBJREF_SET_ID]));
164 e->flagscxx . . $ nftnl_expr#flags. |= (1 << NFTNL_EXPR_OBJREF_SET_IDcxx . . $ NFTNL_EXPR_OBJREF_SET_ID.);
165 }
166
167 return 0;
168 }
169
170 static int nftnl_expr_objref_snprintfcxx . . $ nftnl_expr_objref_snprintf(2b4af69501aef780).(char *buf, size_t len,
171 uint32_tcxx . . $ uint32_t# flags,
172 const struct nftnl_exprcxx . . $ nftnl_expr# *e)
173 {
174 struct nftnl_expr_objrefcxx . . $ nftnl_expr_objref# *objref = nftnl_expr_datacxx . . $ `include/expr_ops.h:31:9`!(e);
175
176 if (e->flagscxx . . $ nftnl_expr#flags. & (1 << NFTNL_EXPR_OBJREF_SET_SREGcxx . . $ NFTNL_EXPR_OBJREF_SET_SREG.))
177 return snprintfcxx . . $ snprintf(ea502d73e74c754c).(buf, len, "sreg %u set %s ",
178 objref->setcxx . . $ nftnl_expr_objref#set..sregcxx . . $ nftnl_expr_objref#$anonymous_type_1#sreg., objref->setcxx . . $ nftnl_expr_objref#set..namecxx . . $ nftnl_expr_objref#$anonymous_type_1#name.);
179 else
180 return snprintfcxx . . $ snprintf(ea502d73e74c754c).(buf, len, "type %u name %s ",
181 objref->immcxx . . $ nftnl_expr_objref#imm..typecxx . . $ nftnl_expr_objref#$anonymous_type_0#type., objref->immcxx . . $ nftnl_expr_objref#imm..namecxx . . $ nftnl_expr_objref#$anonymous_type_0#name.);
182 }
183
184 static void nftnl_expr_objref_freecxx . . $ nftnl_expr_objref_free(cbe1a28527736226).(const struct nftnl_exprcxx . . $ nftnl_expr# *e)
185 {
186 struct nftnl_expr_objrefcxx . . $ nftnl_expr_objref# *objref = nftnl_expr_datacxx . . $ `include/expr_ops.h:31:9`!(e);
187
188 xfreecxx . . $ `include/utils.h:22:9`!(objref->imm.name);
189 xfreecxx . . $ `include/utils.h:22:9`!(objref->set.name);
190 }
191
192 static struct attr_policycxx . . $ attr_policy# objref_attr_policycxx . . $ objref_attr_policy.[__NFTNL_EXPR_OBJREF_MAXcxx . . $ __NFTNL_EXPR_OBJREF_MAX.] = {
193 [NFTNL_EXPR_OBJREF_IMM_TYPEcxx . . $ NFTNL_EXPR_OBJREF_IMM_TYPE.] = { .maxlen = sizeof(uint32_tcxx . . $ uint32_t#) },
194 [NFTNL_EXPR_OBJREF_IMM_NAMEcxx . . $ NFTNL_EXPR_OBJREF_IMM_NAME.] = { .maxlen = NFT_NAME_MAXLENcxx . . $ `include/linux/netfilter/nf_tables.h:5:9`! },
195 [NFTNL_EXPR_OBJREF_SET_SREGcxx . . $ NFTNL_EXPR_OBJREF_SET_SREG.] = { .maxlen = sizeof(uint32_tcxx . . $ uint32_t#) },
196 [NFTNL_EXPR_OBJREF_SET_NAMEcxx . . $ NFTNL_EXPR_OBJREF_SET_NAME.] = { .maxlen = NFT_NAME_MAXLENcxx . . $ `include/linux/netfilter/nf_tables.h:5:9`! },
197 [NFTNL_EXPR_OBJREF_SET_IDcxx . . $ NFTNL_EXPR_OBJREF_SET_ID.] = { .maxlen = sizeof(uint32_tcxx . . $ uint32_t#) },
198 };
199
200 struct expr_opscxx . . $ expr_ops# expr_ops_objrefcxx . . $ expr_ops_objref. = {
201 .name = "objref",
202 .alloc_len = sizeof(struct nftnl_expr_objrefcxx . . $ nftnl_expr_objref#),
203 .nftnl_max_attr = __NFTNL_EXPR_OBJREF_MAXcxx . . $ __NFTNL_EXPR_OBJREF_MAX. - 1,
204 .attr_policy = objref_attr_policycxx . . $ objref_attr_policy.,
205 .free = nftnl_expr_objref_freecxx . . $ nftnl_expr_objref_free(cbe1a28527736226).,
206 .set = nftnl_expr_objref_setcxx . . $ nftnl_expr_objref_set(211371a3e3842127).,
207 .get = nftnl_expr_objref_getcxx . . $ nftnl_expr_objref_get(9de263c4f9e71c4b).,
208 .parse = nftnl_expr_objref_parsecxx . . $ nftnl_expr_objref_parse(ed61207049d8af9a).,
209 .build = nftnl_expr_objref_buildcxx . . $ nftnl_expr_objref_build(93c7528a9cf90b41).,
210 .output = nftnl_expr_objref_snprintfcxx . . $ nftnl_expr_objref_snprintf(2b4af69501aef780).,
211 };