Debian Codegraph @

src/expr/tunnel.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-or-later */cxx . . $ `<file>/src/expr/tunnel.c`/
2 /*
3 * (C) 2018 by Pablo Neira Ayuso <[email protected]>
4 */
5
6 #include <stdio.h>
7 #include <stdint.h>
8 #include <string.h>
9 #include <arpa/inet.h>
10 #include <errno.h>
11 #include <linux/netfilter/nf_tables.h>cxx . . $ `<file>/include/linux/netfilter/nf_tables.h`/
12
13 #include "internal.h"cxx . . $ `<file>/include/internal.h`/
14 #include <libmnl/libmnl.h>
15 #include <libnftnl/expr.h>cxx . . $ `<file>/include/libnftnl/expr.h`/
16 #include <libnftnl/rule.h>cxx . . $ `<file>/include/libnftnl/rule.h`/
17
18 struct nftnl_expr_tunnelcxx . . $ nftnl_expr_tunnel# {
19 enum nft_tunnel_keyscxx . . $ nft_tunnel_keys# keycxx . . $ nftnl_expr_tunnel#key.;
20 enum nft_registerscxx . . $ nft_registers# dregcxx . . $ nftnl_expr_tunnel#dreg.;
21 };
22
23 static int
24 nftnl_expr_tunnel_setcxx . . $ nftnl_expr_tunnel_set(211371a3e3842127).(struct nftnl_exprcxx . . $ nftnl_expr# *e, uint16_tcxx . . $ uint16_t# type,
25 const void *data, uint32_tcxx . . $ uint32_t# data_len, uint32_tcxx . . $ uint32_t# byteorder)
26 {
27 struct nftnl_expr_tunnelcxx . . $ nftnl_expr_tunnel# *tunnel = nftnl_expr_datacxx . . $ `include/expr_ops.h:31:9`!(e);
28
29 switch(type) {
30 case NFTNL_EXPR_TUNNEL_KEYcxx . . $ NFTNL_EXPR_TUNNEL_KEY.:
31 memcpycxx . . $ memcpy(cc817cb175f282d).(&tunnel->keycxx . . $ nftnl_expr_tunnel#key., data, data_len);
32 break;
33 case NFTNL_EXPR_TUNNEL_DREGcxx . . $ NFTNL_EXPR_TUNNEL_DREG.:
34 memcpycxx . . $ memcpy(cc817cb175f282d).(&tunnel->dregcxx . . $ nftnl_expr_tunnel#dreg., data, data_len);
35 break;
36 }
37 return 0;
38 }
39
40 static const void *
41 nftnl_expr_tunnel_getcxx . . $ nftnl_expr_tunnel_get(9de263c4f9e71c4b).(const struct nftnl_exprcxx . . $ nftnl_expr# *e, uint16_tcxx . . $ uint16_t# type,
42 uint32_tcxx . . $ uint32_t# *data_len)
43 {
44 struct nftnl_expr_tunnelcxx . . $ nftnl_expr_tunnel# *tunnel = nftnl_expr_datacxx . . $ `include/expr_ops.h:31:9`!(e);
45
46 switch(type) {
47 case NFTNL_EXPR_TUNNEL_KEYcxx . . $ NFTNL_EXPR_TUNNEL_KEY.:
48 *data_len = sizeof(tunnel->keycxx . . $ nftnl_expr_tunnel#key.);
49 return &tunnel->keycxx . . $ nftnl_expr_tunnel#key.;
50 case NFTNL_EXPR_TUNNEL_DREGcxx . . $ NFTNL_EXPR_TUNNEL_DREG.:
51 *data_len = sizeof(tunnel->dregcxx . . $ nftnl_expr_tunnel#dreg.);
52 return &tunnel->dregcxx . . $ nftnl_expr_tunnel#dreg.;
53 }
54 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
55 }
56
57 static int nftnl_expr_tunnel_cbcxx . . $ nftnl_expr_tunnel_cb(de2ef18c48fd675c).(const struct nlattrcxx . . $ nlattr# *attr, void *data)
58 {
59 const struct nlattrcxx . . $ nlattr# **tb = data;
60 int type = mnl_attr_get_typecxx . . $ mnl_attr_get_type(1da47bcc4c4b975).(attr);
61
62 if (mnl_attr_type_validcxx . . $ mnl_attr_type_valid(47df1cce1c7be855).(attr, NFTA_TUNNEL_MAXcxx . . $ `include/linux/netfilter/nf_tables.h:2016:9`!) < 0)
63 return MNL_CB_OKcxx . . $ `<external>/12386019527593959648/libmnl.h:174:9`!;
64
65 switch(type) {
66 case NFTA_TUNNEL_KEYcxx . . $ NFTA_TUNNEL_KEY.:
67 case NFTA_TUNNEL_DREGcxx . . $ NFTA_TUNNEL_DREG.:
68 if (mnl_attr_validatecxx . . $ mnl_attr_validate(e419697a5e1ae2b1).(attr, MNL_TYPE_U32cxx . . $ MNL_TYPE_U32.) < 0)
69 abi_breakagecxx . . $ `include/utils.h:28:9`!();
70 break;
71 }
72
73 tb[type] = attr;
74 return MNL_CB_OKcxx . . $ `<external>/12386019527593959648/libmnl.h:174:9`!;
75 }
76
77 static void
78 nftnl_expr_tunnel_buildcxx . . $ nftnl_expr_tunnel_build(93c7528a9cf90b41).(struct nlmsghdrcxx . . $ nlmsghdr# *nlh, const struct nftnl_exprcxx . . $ nftnl_expr# *e)
79 {
80 struct nftnl_expr_tunnelcxx . . $ nftnl_expr_tunnel# *tunnel = nftnl_expr_datacxx . . $ `include/expr_ops.h:31:9`!(e);
81
82 if (e->flagscxx . . $ nftnl_expr#flags. & (1 << NFTNL_EXPR_TUNNEL_KEYcxx . . $ NFTNL_EXPR_TUNNEL_KEY.))
83 mnl_attr_put_u32cxx . . $ mnl_attr_put_u32(b46fd0aeb0cfb96d).(nlh, NFTA_TUNNEL_KEYcxx . . $ NFTA_TUNNEL_KEY., htonlcxx . . $ `<external>/9581057695539925927/in.h:430:12`!(tunnel->key));
84 if (e->flagscxx . . $ nftnl_expr#flags. & (1 << NFTNL_EXPR_TUNNEL_DREGcxx . . $ NFTNL_EXPR_TUNNEL_DREG.))
85 mnl_attr_put_u32cxx . . $ mnl_attr_put_u32(b46fd0aeb0cfb96d).(nlh, NFTA_TUNNEL_DREGcxx . . $ NFTA_TUNNEL_DREG., htonlcxx . . $ `<external>/9581057695539925927/in.h:430:12`!(tunnel->dreg));
86 }
87
88 static int
89 nftnl_expr_tunnel_parsecxx . . $ nftnl_expr_tunnel_parse(ed61207049d8af9a).(struct nftnl_exprcxx . . $ nftnl_expr# *e, struct nlattrcxx . . $ nlattr# *attr)
90 {
91 struct nftnl_expr_tunnelcxx . . $ nftnl_expr_tunnel# *tunnel = nftnl_expr_datacxx . . $ `include/expr_ops.h:31:9`!(e);
92 struct nlattrcxx . . $ nlattr# *tb[NFTA_TUNNEL_MAXcxx . . $ `include/linux/netfilter/nf_tables.h:2016:9`! + 1] = {};
93
94 if (mnl_attr_parse_nestedcxx . . $ mnl_attr_parse_nested(f99c0e9fa94f99d9).(attr, nftnl_expr_tunnel_cbcxx . . $ nftnl_expr_tunnel_cb(de2ef18c48fd675c)., tb) < 0)
95 return -1;
96
97 if (tb[NFTA_TUNNEL_KEYcxx . . $ NFTA_TUNNEL_KEY.]) {
98 tunnel->keycxx . . $ nftnl_expr_tunnel#key. = ntohlcxx . . $ `<external>/9581057695539925927/in.h:428:12`!(mnl_attr_get_u32(tb[NFTA_TUNNEL_KEY]));
99 e->flagscxx . . $ nftnl_expr#flags. |= (1 << NFTNL_EXPR_TUNNEL_KEYcxx . . $ NFTNL_EXPR_TUNNEL_KEY.);
100 }
101 if (tb[NFTA_TUNNEL_DREGcxx . . $ NFTA_TUNNEL_DREG.]) {
102 tunnel->dregcxx . . $ nftnl_expr_tunnel#dreg. = ntohlcxx . . $ `<external>/9581057695539925927/in.h:428:12`!(mnl_attr_get_u32(tb[NFTA_TUNNEL_DREG]));
103 e->flagscxx . . $ nftnl_expr#flags. |= (1 << NFTNL_EXPR_TUNNEL_DREGcxx . . $ NFTNL_EXPR_TUNNEL_DREG.);
104 }
105
106 return 0;
107 }
108
109 static const char *tunnel_key2str_arraycxx . . $ tunnel_key2str_array.[NFT_TUNNEL_MAXcxx . . $ `include/linux/netfilter/nf_tables.h:1999:9`! + 1] = {
110 [NFT_TUNNEL_PATHcxx . . $ NFT_TUNNEL_PATH.] = "path",
111 [NFT_TUNNEL_IDcxx . . $ NFT_TUNNEL_ID.] = "id",
112 };
113
114 static const char *tunnel_key2strcxx . . $ tunnel_key2str(42624c5f3be67010).(uint8_tcxx . . $ uint8_t# key)
115 {
116 if (key <= NFT_TUNNEL_MAXcxx . . $ `include/linux/netfilter/nf_tables.h:1999:9`!)
117 return tunnel_key2str_arraycxx . . $ tunnel_key2str_array.[key];
118
119 return "unknown";
120 }
121
122 static int
123 nftnl_expr_tunnel_snprintfcxx . . $ nftnl_expr_tunnel_snprintf(2b4af69501aef780).(char *buf, size_t len,
124 uint32_tcxx . . $ uint32_t# flags, const struct nftnl_exprcxx . . $ nftnl_expr# *e)
125 {
126 struct nftnl_expr_tunnelcxx . . $ nftnl_expr_tunnel# *tunnel = nftnl_expr_datacxx . . $ `include/expr_ops.h:31:9`!(e);
127
128 if (e->flagscxx . . $ nftnl_expr#flags. & (1 << NFTNL_EXPR_TUNNEL_DREGcxx . . $ NFTNL_EXPR_TUNNEL_DREG.)) {
129 return snprintfcxx . . $ snprintf(ea502d73e74c754c).(buf, len, "load %s => reg %u ",
130 tunnel_key2strcxx . . $ tunnel_key2str(42624c5f3be67010).(tunnel->keycxx . . $ nftnl_expr_tunnel#key.), tunnel->dregcxx . . $ nftnl_expr_tunnel#dreg.);
131 }
132 return 0;
133 }
134
135 static struct attr_policycxx . . $ attr_policy# tunnel_attr_policycxx . . $ tunnel_attr_policy.[__NFTNL_EXPR_TUNNEL_MAXcxx . . $ __NFTNL_EXPR_TUNNEL_MAX.] = {
136 [NFTNL_EXPR_TUNNEL_KEYcxx . . $ NFTNL_EXPR_TUNNEL_KEY.] = { .maxlen = sizeof(uint32_tcxx . . $ uint32_t#) },
137 [NFTNL_EXPR_TUNNEL_DREGcxx . . $ NFTNL_EXPR_TUNNEL_DREG.] = { .maxlen = sizeof(uint32_tcxx . . $ uint32_t#) },
138 };
139
140 struct expr_opscxx . . $ expr_ops# expr_ops_tunnelcxx . . $ expr_ops_tunnel. = {
141 .name = "tunnel",
142 .alloc_len = sizeof(struct nftnl_expr_tunnelcxx . . $ nftnl_expr_tunnel#),
143 .nftnl_max_attr = __NFTNL_EXPR_TUNNEL_MAXcxx . . $ __NFTNL_EXPR_TUNNEL_MAX. - 1,
144 .attr_policy = tunnel_attr_policycxx . . $ tunnel_attr_policy.,
145 .set = nftnl_expr_tunnel_setcxx . . $ nftnl_expr_tunnel_set(211371a3e3842127).,
146 .get = nftnl_expr_tunnel_getcxx . . $ nftnl_expr_tunnel_get(9de263c4f9e71c4b).,
147 .parse = nftnl_expr_tunnel_parsecxx . . $ nftnl_expr_tunnel_parse(ed61207049d8af9a).,
148 .build = nftnl_expr_tunnel_buildcxx . . $ nftnl_expr_tunnel_build(93c7528a9cf90b41).,
149 .output = nftnl_expr_tunnel_snprintfcxx . . $ nftnl_expr_tunnel_snprintf(2b4af69501aef780).,
150 };