Debian Codegraph @

src/expr/fib.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-or-later */cxx . . $ `<file>/src/expr/fib.c`/
2 /*
3 * (C) 2016 Red Hat GmbH
4 * Author: Florian Westphal <[email protected]>
5 */
6
7 #include <stdio.h>
8 #include <stdint.h>
9 #include <inttypes.h>
10 #include <string.h>
11 #include <arpa/inet.h>
12 #include <errno.h>
13 #include <linux/netfilter/nf_tables.h>cxx . . $ `<file>/include/linux/netfilter/nf_tables.h`/
14
15 #include "internal.h"cxx . . $ `<file>/include/internal.h`/
16 #include <libmnl/libmnl.h>
17 #include <libnftnl/expr.h>cxx . . $ `<file>/include/libnftnl/expr.h`/
18 #include <libnftnl/rule.h>cxx . . $ `<file>/include/libnftnl/rule.h`/
19
20 struct nftnl_expr_fibcxx . . $ nftnl_expr_fib# {
21 uint32_tcxx . . $ uint32_t# flagscxx . . $ nftnl_expr_fib#flags.;
22 uint32_tcxx . . $ uint32_t# resultcxx . . $ nftnl_expr_fib#result.;
23 enum nft_registerscxx . . $ nft_registers# dregcxx . . $ nftnl_expr_fib#dreg.;
24 };
25
26 static int
27 nftnl_expr_fib_setcxx . . $ nftnl_expr_fib_set(211371a3e3842127).(struct nftnl_exprcxx . . $ nftnl_expr# *e, uint16_tcxx . . $ uint16_t# result,
28 const void *data, uint32_tcxx . . $ uint32_t# data_len, uint32_tcxx . . $ uint32_t# byteorder)
29 {
30 struct nftnl_expr_fibcxx . . $ nftnl_expr_fib# *fib = nftnl_expr_datacxx . . $ `include/expr_ops.h:31:9`!(e);
31
32 switch (result) {
33 case NFTNL_EXPR_FIB_RESULTcxx . . $ NFTNL_EXPR_FIB_RESULT.:
34 memcpycxx . . $ memcpy(cc817cb175f282d).(&fib->resultcxx . . $ nftnl_expr_fib#result., data, data_len);
35 break;
36 case NFTNL_EXPR_FIB_DREGcxx . . $ NFTNL_EXPR_FIB_DREG.:
37 memcpycxx . . $ memcpy(cc817cb175f282d).(&fib->dregcxx . . $ nftnl_expr_fib#dreg., data, data_len);
38 break;
39 case NFTNL_EXPR_FIB_FLAGScxx . . $ NFTNL_EXPR_FIB_FLAGS.:
40 memcpycxx . . $ memcpy(cc817cb175f282d).(&fib->flagscxx . . $ nftnl_expr_fib#flags., data, data_len);
41 break;
42 }
43 return 0;
44 }
45
46 static const void *
47 nftnl_expr_fib_getcxx . . $ nftnl_expr_fib_get(9de263c4f9e71c4b).(const struct nftnl_exprcxx . . $ nftnl_expr# *e, uint16_tcxx . . $ uint16_t# result,
48 uint32_tcxx . . $ uint32_t# *data_len)
49 {
50 struct nftnl_expr_fibcxx . . $ nftnl_expr_fib# *fib = nftnl_expr_datacxx . . $ `include/expr_ops.h:31:9`!(e);
51
52 switch (result) {
53 case NFTNL_EXPR_FIB_RESULTcxx . . $ NFTNL_EXPR_FIB_RESULT.:
54 *data_len = sizeof(fib->resultcxx . . $ nftnl_expr_fib#result.);
55 return &fib->resultcxx . . $ nftnl_expr_fib#result.;
56 case NFTNL_EXPR_FIB_DREGcxx . . $ NFTNL_EXPR_FIB_DREG.:
57 *data_len = sizeof(fib->dregcxx . . $ nftnl_expr_fib#dreg.);
58 return &fib->dregcxx . . $ nftnl_expr_fib#dreg.;
59 case NFTNL_EXPR_FIB_FLAGScxx . . $ NFTNL_EXPR_FIB_FLAGS.:
60 *data_len = sizeof(fib->flagscxx . . $ nftnl_expr_fib#flags.);
61 return &fib->flagscxx . . $ nftnl_expr_fib#flags.;
62 }
63 return NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!;
64 }
65
66 static int nftnl_expr_fib_cbcxx . . $ nftnl_expr_fib_cb(de2ef18c48fd675c).(const struct nlattrcxx . . $ nlattr# *attr, void *data)
67 {
68 const struct nlattrcxx . . $ nlattr# **tb = data;
69 int type = mnl_attr_get_typecxx . . $ mnl_attr_get_type(1da47bcc4c4b975).(attr);
70
71 if (mnl_attr_type_validcxx . . $ mnl_attr_type_valid(47df1cce1c7be855).(attr, NFTA_FIB_MAXcxx . . $ `include/linux/netfilter/nf_tables.h:1609:9`!) < 0)
72 return MNL_CB_OKcxx . . $ `<external>/12386019527593959648/libmnl.h:174:9`!;
73
74 switch (type) {
75 case NFTA_FIB_RESULTcxx . . $ NFTA_FIB_RESULT.:
76 case NFTA_FIB_DREGcxx . . $ NFTA_FIB_DREG.:
77 case NFTA_FIB_FLAGScxx . . $ NFTA_FIB_FLAGS.:
78 if (mnl_attr_validatecxx . . $ mnl_attr_validate(e419697a5e1ae2b1).(attr, MNL_TYPE_U32cxx . . $ MNL_TYPE_U32.) < 0)
79 abi_breakagecxx . . $ `include/utils.h:28:9`!();
80 break;
81 }
82
83 tb[type] = attr;
84 return MNL_CB_OKcxx . . $ `<external>/12386019527593959648/libmnl.h:174:9`!;
85 }
86
87 static void
88 nftnl_expr_fib_buildcxx . . $ nftnl_expr_fib_build(93c7528a9cf90b41).(struct nlmsghdrcxx . . $ nlmsghdr# *nlh, const struct nftnl_exprcxx . . $ nftnl_expr# *e)
89 {
90 struct nftnl_expr_fibcxx . . $ nftnl_expr_fib# *fib = nftnl_expr_datacxx . . $ `include/expr_ops.h:31:9`!(e);
91
92 if (e->flagscxx . . $ nftnl_expr#flags. & (1 << NFTNL_EXPR_FIB_FLAGScxx . . $ NFTNL_EXPR_FIB_FLAGS.))
93 mnl_attr_put_u32cxx . . $ mnl_attr_put_u32(b46fd0aeb0cfb96d).(nlh, NFTA_FIB_FLAGScxx . . $ NFTA_FIB_FLAGS., htonlcxx . . $ `<external>/9581057695539925927/in.h:430:12`!(fib->flags));
94 if (e->flagscxx . . $ nftnl_expr#flags. & (1 << NFTNL_EXPR_FIB_RESULTcxx . . $ NFTNL_EXPR_FIB_RESULT.))
95 mnl_attr_put_u32cxx . . $ mnl_attr_put_u32(b46fd0aeb0cfb96d).(nlh, NFTA_FIB_RESULTcxx . . $ NFTA_FIB_RESULT., htonlcxx . . $ `<external>/9581057695539925927/in.h:430:12`!(fib->result));
96 if (e->flagscxx . . $ nftnl_expr#flags. & (1 << NFTNL_EXPR_FIB_DREGcxx . . $ NFTNL_EXPR_FIB_DREG.))
97 mnl_attr_put_u32cxx . . $ mnl_attr_put_u32(b46fd0aeb0cfb96d).(nlh, NFTA_FIB_DREGcxx . . $ NFTA_FIB_DREG., htonlcxx . . $ `<external>/9581057695539925927/in.h:430:12`!(fib->dreg));
98 }
99
100 static int
101 nftnl_expr_fib_parsecxx . . $ nftnl_expr_fib_parse(ed61207049d8af9a).(struct nftnl_exprcxx . . $ nftnl_expr# *e, struct nlattrcxx . . $ nlattr# *attr)
102 {
103 struct nftnl_expr_fibcxx . . $ nftnl_expr_fib# *fib = nftnl_expr_datacxx . . $ `include/expr_ops.h:31:9`!(e);
104 struct nlattrcxx . . $ nlattr# *tb[NFTA_FIB_MAXcxx . . $ `include/linux/netfilter/nf_tables.h:1609:9`!+1] = {};
105 int ret = 0;
106
107 if (mnl_attr_parse_nestedcxx . . $ mnl_attr_parse_nested(f99c0e9fa94f99d9).(attr, nftnl_expr_fib_cbcxx . . $ nftnl_expr_fib_cb(de2ef18c48fd675c)., tb) < 0)
108 return -1;
109
110 if (tb[NFTA_FIB_RESULTcxx . . $ NFTA_FIB_RESULT.]) {
111 fib->resultcxx . . $ nftnl_expr_fib#result. = ntohlcxx . . $ `<external>/9581057695539925927/in.h:428:12`!(mnl_attr_get_u32(tb[NFTA_FIB_RESULT]));
112 e->flagscxx . . $ nftnl_expr#flags. |= (1 << NFTNL_EXPR_FIB_RESULTcxx . . $ NFTNL_EXPR_FIB_RESULT.);
113 }
114 if (tb[NFTA_FIB_DREGcxx . . $ NFTA_FIB_DREG.]) {
115 fib->dregcxx . . $ nftnl_expr_fib#dreg. = ntohlcxx . . $ `<external>/9581057695539925927/in.h:428:12`!(mnl_attr_get_u32(tb[NFTA_FIB_DREG]));
116 e->flagscxx . . $ nftnl_expr#flags. |= (1 << NFTNL_EXPR_FIB_DREGcxx . . $ NFTNL_EXPR_FIB_DREG.);
117 }
118 if (tb[NFTA_FIB_FLAGScxx . . $ NFTA_FIB_FLAGS.]) {
119 fib->flagscxx . . $ nftnl_expr_fib#flags. = ntohlcxx . . $ `<external>/9581057695539925927/in.h:428:12`!(mnl_attr_get_u32(tb[NFTA_FIB_FLAGS]));
120 e->flagscxx . . $ nftnl_expr#flags. |= (1 << NFTNL_EXPR_FIB_FLAGScxx . . $ NFTNL_EXPR_FIB_FLAGS.);
121 }
122 return ret;
123 }
124
125 static const char *fib_typecxx . . $ fib_type.[NFT_FIB_RESULT_MAXcxx . . $ `include/linux/netfilter/nf_tables.h:1618:9`! + 1] = {
126 [NFT_FIB_RESULT_OIFcxx . . $ NFT_FIB_RESULT_OIF.] = "oif",
127 [NFT_FIB_RESULT_OIFNAMEcxx . . $ NFT_FIB_RESULT_OIFNAME.] = "oifname",
128 [NFT_FIB_RESULT_ADDRTYPEcxx . . $ NFT_FIB_RESULT_ADDRTYPE.] = "type",
129 };
130
131 static const char *fib_type_strcxx . . $ fib_type_str(38548fbfcb37d9ff).(enum nft_fib_resultcxx . . $ nft_fib_result# r)
132 {
133 if (r <= NFT_FIB_RESULT_MAXcxx . . $ `include/linux/netfilter/nf_tables.h:1618:9`!)
134 return fib_typecxx . . $ fib_type.[r];
135
136 return "unknown";
137 }
138
139 static int
140 nftnl_expr_fib_snprintfcxx . . $ nftnl_expr_fib_snprintf(2b4af69501aef780).(char *buf, size_t remain,
141 uint32_tcxx . . $ uint32_t# printflags, const struct nftnl_exprcxx . . $ nftnl_expr# *e)
142 {
143 struct nftnl_expr_fibcxx . . $ nftnl_expr_fib# *fib = nftnl_expr_datacxx . . $ `include/expr_ops.h:31:9`!(e);
144 uint32_tcxx . . $ uint32_t# flags = fib->flagscxx . . $ nftnl_expr_fib#flags. & ~NFTA_FIB_F_PRESENTcxx . . $ NFTA_FIB_F_PRESENT.;
145 uint32_tcxx . . $ uint32_t# present_flag = fib->flagscxx . . $ nftnl_expr_fib#flags. & NFTA_FIB_F_PRESENTcxx . . $ NFTA_FIB_F_PRESENT.;
146 int offset = 0, ret, i;
147 static const structcxx . . $ nftnl_expr_fib_snprintf(2b4af69501aef780).$anonymous_type_0# {
148 int bitcxx . . $ nftnl_expr_fib_snprintf(2b4af69501aef780).$anonymous_type_0#bit.;
149 const char *namecxx . . $ nftnl_expr_fib_snprintf(2b4af69501aef780).$anonymous_type_0#name.;
150 } tab[] = {
151 { NFTA_FIB_F_SADDRcxx . . $ NFTA_FIB_F_SADDR., "saddr" },
152 { NFTA_FIB_F_DADDRcxx . . $ NFTA_FIB_F_DADDR., "daddr" },
153 { NFTA_FIB_F_MARKcxx . . $ NFTA_FIB_F_MARK., "mark" },
154 { NFTA_FIB_F_IIFcxx . . $ NFTA_FIB_F_IIF., "iif" },
155 { NFTA_FIB_F_OIFcxx . . $ NFTA_FIB_F_OIF., "oif" },
156 };
157
158 for (i = 0; i < (sizeof(tab) / sizeof(tab[0])); i++) {
159 if (flags & tab[i].bitcxx . . $ nftnl_expr_fib_snprintf(2b4af69501aef780).$anonymous_type_0#bit.) {
160 ret = snprintfcxx . . $ snprintf(ea502d73e74c754c).(buf + offset, remain, "%s ",
161 tab[i].namecxx . . $ nftnl_expr_fib_snprintf(2b4af69501aef780).$anonymous_type_0#name.);
162 SNPRINTF_BUFFER_SIZEcxx . . $ `include/utils.h:55:9`!(ret, remain, offset);
163
164 flags &= ~tab[i].bitcxx . . $ nftnl_expr_fib_snprintf(2b4af69501aef780).$anonymous_type_0#bit.;
165 if (flags) {
166 ret = snprintfcxx . . $ snprintf(ea502d73e74c754c).(buf + offset, remain, ". ");
167 SNPRINTF_BUFFER_SIZEcxx . . $ `include/utils.h:55:9`!(ret, remain, offset);
168 }
169 }
170 }
171
172 if (flags) {
173 ret = snprintfcxx . . $ snprintf(ea502d73e74c754c).(buf + offset, remain, "unknown 0x%" PRIx32cxx . . $ `<external>/15933738808807975373/inttypes.h:125:10`!,
174 flags);
175 SNPRINTF_BUFFER_SIZEcxx . . $ `include/utils.h:55:9`!(ret, remain, offset);
176 }
177
178 ret = snprintfcxx . . $ snprintf(ea502d73e74c754c).(buf + offset, remain, "%s%s => reg %d ",
179 fib_type_strcxx . . $ fib_type_str(38548fbfcb37d9ff).(fib->resultcxx . . $ nftnl_expr_fib#result.),
180 present_flag ? " present" : "",
181 fib->dregcxx . . $ nftnl_expr_fib#dreg.);
182 SNPRINTF_BUFFER_SIZEcxx . . $ `include/utils.h:55:9`!(ret, remain, offset);
183
184 return offset;
185 }
186
187 static struct attr_policycxx . . $ attr_policy# fib_attr_policycxx . . $ fib_attr_policy.[__NFTNL_EXPR_FIB_MAXcxx . . $ __NFTNL_EXPR_FIB_MAX.] = {
188 [NFTNL_EXPR_FIB_DREGcxx . . $ NFTNL_EXPR_FIB_DREG.] = { .maxlen = sizeof(uint32_tcxx . . $ uint32_t#) },
189 [NFTNL_EXPR_FIB_RESULTcxx . . $ NFTNL_EXPR_FIB_RESULT.] = { .maxlen = sizeof(uint32_tcxx . . $ uint32_t#) },
190 [NFTNL_EXPR_FIB_FLAGScxx . . $ NFTNL_EXPR_FIB_FLAGS.] = { .maxlen = sizeof(uint32_tcxx . . $ uint32_t#) },
191 };
192
193 struct expr_opscxx . . $ expr_ops# expr_ops_fibcxx . . $ expr_ops_fib. = {
194 .name = "fib",
195 .alloc_len = sizeof(struct nftnl_expr_fibcxx . . $ nftnl_expr_fib#),
196 .nftnl_max_attr = __NFTNL_EXPR_FIB_MAXcxx . . $ __NFTNL_EXPR_FIB_MAX. - 1,
197 .attr_policy = fib_attr_policycxx . . $ fib_attr_policy.,
198 .set = nftnl_expr_fib_setcxx . . $ nftnl_expr_fib_set(211371a3e3842127).,
199 .get = nftnl_expr_fib_getcxx . . $ nftnl_expr_fib_get(9de263c4f9e71c4b).,
200 .parse = nftnl_expr_fib_parsecxx . . $ nftnl_expr_fib_parse(ed61207049d8af9a).,
201 .build = nftnl_expr_fib_buildcxx . . $ nftnl_expr_fib_build(93c7528a9cf90b41).,
202 .output = nftnl_expr_fib_snprintfcxx . . $ nftnl_expr_fib_snprintf(2b4af69501aef780).,
203 };