Debian Codegraph @

src/expr/tproxy.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-or-later */cxx . . $ `<file>/src/expr/tproxy.c`/
2 /*
3 * Copyright (c) 2018 Máté Eckl <[email protected]>
4 */
5
6 #include "internal.h"cxx . . $ `<file>/include/internal.h`/
7
8 #include <stdio.h>
9 #include <stdint.h>
10 #include <limits.h>
11 #include <string.h>
12 #include <errno.h>
13 #include <arpa/inet.h>
14 #include <libmnl/libmnl.h>
15 #include <linux/netfilter/nf_tables.h>cxx . . $ `<file>/include/linux/netfilter/nf_tables.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_tproxycxx . . $ nftnl_expr_tproxy# {
20 enum nft_registerscxx . . $ nft_registers# sreg_addrcxx . . $ nftnl_expr_tproxy#sreg_addr.;
21 enum nft_registerscxx . . $ nft_registers# sreg_portcxx . . $ nftnl_expr_tproxy#sreg_port.;
22 int familycxx . . $ nftnl_expr_tproxy#family.;
23 };
24
25 static int
26 nftnl_expr_tproxy_setcxx . . $ nftnl_expr_tproxy_set(211371a3e3842127).(struct nftnl_exprcxx . . $ nftnl_expr# *e, uint16_tcxx . . $ uint16_t# type,
27 const void *data, uint32_tcxx . . $ uint32_t# data_len, uint32_tcxx . . $ uint32_t# byteorder)
28 {
29 struct nftnl_expr_tproxycxx . . $ nftnl_expr_tproxy# *tproxy = nftnl_expr_datacxx . . $ `include/expr_ops.h:31:9`!(e);
30
31 switch(type) {
32 case NFTNL_EXPR_TPROXY_FAMILYcxx . . $ NFTNL_EXPR_TPROXY_FAMILY.:
33 memcpycxx . . $ memcpy(cc817cb175f282d).(&tproxy->familycxx . . $ nftnl_expr_tproxy#family., data, data_len);
34 break;
35 case NFTNL_EXPR_TPROXY_REG_ADDRcxx . . $ NFTNL_EXPR_TPROXY_REG_ADDR.:
36 memcpycxx . . $ memcpy(cc817cb175f282d).(&tproxy->sreg_addrcxx . . $ nftnl_expr_tproxy#sreg_addr., data, data_len);
37 break;
38 case NFTNL_EXPR_TPROXY_REG_PORTcxx . . $ NFTNL_EXPR_TPROXY_REG_PORT.:
39 memcpycxx . . $ memcpy(cc817cb175f282d).(&tproxy->sreg_portcxx . . $ nftnl_expr_tproxy#sreg_port., data, data_len);
40 break;
41 }
42
43 return 0;
44 }
45
46 static const void *
47 nftnl_expr_tproxy_getcxx . . $ nftnl_expr_tproxy_get(9de263c4f9e71c4b).(const struct nftnl_exprcxx . . $ nftnl_expr# *e, uint16_tcxx . . $ uint16_t# type,
48 uint32_tcxx . . $ uint32_t# *data_len)
49 {
50 struct nftnl_expr_tproxycxx . . $ nftnl_expr_tproxy# *tproxy = nftnl_expr_datacxx . . $ `include/expr_ops.h:31:9`!(e);
51
52 switch(type) {
53 case NFTNL_EXPR_TPROXY_FAMILYcxx . . $ NFTNL_EXPR_TPROXY_FAMILY.:
54 *data_len = sizeof(tproxy->familycxx . . $ nftnl_expr_tproxy#family.);
55 return &tproxy->familycxx . . $ nftnl_expr_tproxy#family.;
56 case NFTNL_EXPR_TPROXY_REG_ADDRcxx . . $ NFTNL_EXPR_TPROXY_REG_ADDR.:
57 *data_len = sizeof(tproxy->sreg_addrcxx . . $ nftnl_expr_tproxy#sreg_addr.);
58 return &tproxy->sreg_addrcxx . . $ nftnl_expr_tproxy#sreg_addr.;
59 case NFTNL_EXPR_TPROXY_REG_PORTcxx . . $ NFTNL_EXPR_TPROXY_REG_PORT.:
60 *data_len = sizeof(tproxy->sreg_portcxx . . $ nftnl_expr_tproxy#sreg_port.);
61 return &tproxy->sreg_portcxx . . $ nftnl_expr_tproxy#sreg_port.;
62 }
63 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
64 }
65
66 static int nftnl_expr_tproxy_cbcxx . . $ nftnl_expr_tproxy_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_TPROXY_MAXcxx . . $ `include/linux/netfilter/nf_tables.h:1494:9`!) < 0)
72 return MNL_CB_OKcxx . . $ `<external>/12386019527593959648/libmnl.h:174:9`!;
73
74 switch(type) {
75 case NFTA_TPROXY_FAMILYcxx . . $ NFTA_TPROXY_FAMILY.:
76 case NFTA_TPROXY_REG_ADDRcxx . . $ NFTA_TPROXY_REG_ADDR.:
77 case NFTA_TPROXY_REG_PORTcxx . . $ NFTA_TPROXY_REG_PORT.:
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 int
88 nftnl_expr_tproxy_parsecxx . . $ nftnl_expr_tproxy_parse(ed61207049d8af9a).(struct nftnl_exprcxx . . $ nftnl_expr# *e, struct nlattrcxx . . $ nlattr# *attr)
89 {
90 struct nftnl_expr_tproxycxx . . $ nftnl_expr_tproxy# *tproxy = nftnl_expr_datacxx . . $ `include/expr_ops.h:31:9`!(e);
91 struct nlattrcxx . . $ nlattr# *tb[NFTA_TPROXY_MAXcxx . . $ `include/linux/netfilter/nf_tables.h:1494:9`! + 1] = {};
92
93 if (mnl_attr_parse_nestedcxx . . $ mnl_attr_parse_nested(f99c0e9fa94f99d9).(attr, nftnl_expr_tproxy_cbcxx . . $ nftnl_expr_tproxy_cb(de2ef18c48fd675c)., tb) < 0)
94 return -1;
95
96 if (tb[NFTA_TPROXY_FAMILYcxx . . $ NFTA_TPROXY_FAMILY.]) {
97 tproxy->familycxx . . $ nftnl_expr_tproxy#family. = ntohlcxx . . $ `<external>/9581057695539925927/in.h:428:12`!(mnl_attr_get_u32(tb[NFTA_TPROXY_FAMILY]));
98 e->flagscxx . . $ nftnl_expr#flags. |= (1 << NFTNL_EXPR_TPROXY_FAMILYcxx . . $ NFTNL_EXPR_TPROXY_FAMILY.);
99 }
100 if (tb[NFTA_TPROXY_REG_ADDRcxx . . $ NFTA_TPROXY_REG_ADDR.]) {
101 tproxy->sreg_addrcxx . . $ nftnl_expr_tproxy#sreg_addr. =
102 ntohlcxx . . $ `<external>/9581057695539925927/in.h:428:12`!(mnl_attr_get_u32(tb[NFTA_TPROXY_REG_ADDR]));
103 e->flagscxx . . $ nftnl_expr#flags. |= (1 << NFTNL_EXPR_TPROXY_REG_ADDRcxx . . $ NFTNL_EXPR_TPROXY_REG_ADDR.);
104 }
105 if (tb[NFTA_TPROXY_REG_PORTcxx . . $ NFTA_TPROXY_REG_PORT.]) {
106 tproxy->sreg_portcxx . . $ nftnl_expr_tproxy#sreg_port. =
107 ntohlcxx . . $ `<external>/9581057695539925927/in.h:428:12`!(mnl_attr_get_u32(tb[NFTA_TPROXY_REG_PORT]));
108 e->flagscxx . . $ nftnl_expr#flags. |= (1 << NFTNL_EXPR_TPROXY_REG_PORTcxx . . $ NFTNL_EXPR_TPROXY_REG_PORT.);
109 }
110
111 return 0;
112 }
113
114 static void
115 nftnl_expr_tproxy_buildcxx . . $ nftnl_expr_tproxy_build(93c7528a9cf90b41).(struct nlmsghdrcxx . . $ nlmsghdr# *nlh, const struct nftnl_exprcxx . . $ nftnl_expr# *e)
116 {
117 struct nftnl_expr_tproxycxx . . $ nftnl_expr_tproxy# *tproxy = nftnl_expr_datacxx . . $ `include/expr_ops.h:31:9`!(e);
118
119 if (e->flagscxx . . $ nftnl_expr#flags. & (1 << NFTNL_EXPR_TPROXY_FAMILYcxx . . $ NFTNL_EXPR_TPROXY_FAMILY.))
120 mnl_attr_put_u32cxx . . $ mnl_attr_put_u32(b46fd0aeb0cfb96d).(nlh, NFTA_TPROXY_FAMILYcxx . . $ NFTA_TPROXY_FAMILY., htonlcxx . . $ `<external>/9581057695539925927/in.h:430:12`!(tproxy->family));
121
122 if (e->flagscxx . . $ nftnl_expr#flags. & (1 << NFTNL_EXPR_TPROXY_REG_ADDRcxx . . $ NFTNL_EXPR_TPROXY_REG_ADDR.))
123 mnl_attr_put_u32cxx . . $ mnl_attr_put_u32(b46fd0aeb0cfb96d).(nlh, NFTA_TPROXY_REG_ADDRcxx . . $ NFTA_TPROXY_REG_ADDR.,
124 htonlcxx . . $ `<external>/9581057695539925927/in.h:430:12`!(tproxy->sreg_addr));
125
126 if (e->flagscxx . . $ nftnl_expr#flags. & (1 << NFTNL_EXPR_TPROXY_REG_PORTcxx . . $ NFTNL_EXPR_TPROXY_REG_PORT.))
127 mnl_attr_put_u32cxx . . $ mnl_attr_put_u32(b46fd0aeb0cfb96d).(nlh, NFTA_TPROXY_REG_PORTcxx . . $ NFTA_TPROXY_REG_PORT.,
128 htonlcxx . . $ `<external>/9581057695539925927/in.h:430:12`!(tproxy->sreg_port));
129 }
130
131 static int
132 nftnl_expr_tproxy_snprintfcxx . . $ nftnl_expr_tproxy_snprintf(2b4af69501aef780).(char *buf, size_t remain,
133 uint32_tcxx . . $ uint32_t# flags, const struct nftnl_exprcxx . . $ nftnl_expr# *e)
134 {
135 struct nftnl_expr_tproxycxx . . $ nftnl_expr_tproxy# *tproxy = nftnl_expr_datacxx . . $ `include/expr_ops.h:31:9`!(e);
136 int offset = 0, ret = 0;
137
138 if (tproxy->familycxx . . $ nftnl_expr_tproxy#family. != NFTA_TPROXY_UNSPECcxx . . $ NFTA_TPROXY_UNSPEC.) {
139 ret = snprintfcxx . . $ snprintf(ea502d73e74c754c).(buf + offset, remain, "%s ",
140 nftnl_family2strcxx . . $ nftnl_family2str(81a3ae90da26a711).(tproxy->familycxx . . $ nftnl_expr_tproxy#family.));
141 SNPRINTF_BUFFER_SIZEcxx . . $ `include/utils.h:55:9`!(ret, remain, offset);
142 }
143
144 if (e->flagscxx . . $ nftnl_expr#flags. & (1 << NFTNL_EXPR_TPROXY_REG_ADDRcxx . . $ NFTNL_EXPR_TPROXY_REG_ADDR.)) {
145 ret = snprintfcxx . . $ snprintf(ea502d73e74c754c).(buf + offset, remain,
146 "addr reg %u ", tproxy->sreg_addrcxx . . $ nftnl_expr_tproxy#sreg_addr.);
147 SNPRINTF_BUFFER_SIZEcxx . . $ `include/utils.h:55:9`!(ret, remain, offset);
148 }
149
150 if (e->flagscxx . . $ nftnl_expr#flags. & (1 << NFTNL_EXPR_TPROXY_REG_PORTcxx . . $ NFTNL_EXPR_TPROXY_REG_PORT.)) {
151 ret = snprintfcxx . . $ snprintf(ea502d73e74c754c).(buf + offset, remain,
152 "port reg %u ", tproxy->sreg_portcxx . . $ nftnl_expr_tproxy#sreg_port.);
153 SNPRINTF_BUFFER_SIZEcxx . . $ `include/utils.h:55:9`!(ret, remain, offset);
154 }
155
156 return offset;
157 }
158
159 static struct attr_policycxx . . $ attr_policy# tproxy_attr_policycxx . . $ tproxy_attr_policy.[__NFTNL_EXPR_TPROXY_MAXcxx . . $ __NFTNL_EXPR_TPROXY_MAX.] = {
160 [NFTNL_EXPR_TPROXY_FAMILYcxx . . $ NFTNL_EXPR_TPROXY_FAMILY.] = { .maxlen = sizeof(uint32_tcxx . . $ uint32_t#) },
161 [NFTNL_EXPR_TPROXY_REG_ADDRcxx . . $ NFTNL_EXPR_TPROXY_REG_ADDR.] = { .maxlen = sizeof(uint32_tcxx . . $ uint32_t#) },
162 [NFTNL_EXPR_TPROXY_REG_PORTcxx . . $ NFTNL_EXPR_TPROXY_REG_PORT.] = { .maxlen = sizeof(uint32_tcxx . . $ uint32_t#) },
163 };
164
165 struct expr_opscxx . . $ expr_ops# expr_ops_tproxycxx . . $ expr_ops_tproxy. = {
166 .name = "tproxy",
167 .alloc_len = sizeof(struct nftnl_expr_tproxycxx . . $ nftnl_expr_tproxy#),
168 .nftnl_max_attr = __NFTNL_EXPR_TPROXY_MAXcxx . . $ __NFTNL_EXPR_TPROXY_MAX. - 1,
169 .attr_policy = tproxy_attr_policycxx . . $ tproxy_attr_policy.,
170 .set = nftnl_expr_tproxy_setcxx . . $ nftnl_expr_tproxy_set(211371a3e3842127).,
171 .get = nftnl_expr_tproxy_getcxx . . $ nftnl_expr_tproxy_get(9de263c4f9e71c4b).,
172 .parse = nftnl_expr_tproxy_parsecxx . . $ nftnl_expr_tproxy_parse(ed61207049d8af9a).,
173 .build = nftnl_expr_tproxy_buildcxx . . $ nftnl_expr_tproxy_build(93c7528a9cf90b41).,
174 .output = nftnl_expr_tproxy_snprintfcxx . . $ nftnl_expr_tproxy_snprintf(2b4af69501aef780).,
175 };