Debian Codegraph @

src/expr/rt.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-or-later */cxx . . $ `<file>/src/expr/rt.c`/
2 /*
3 * Copyright (c) 2016 Anders K. Pedersen <[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_rtcxx . . $ nftnl_expr_rt# {
19 enum nft_rt_keyscxx . . $ nft_rt_keys# keycxx . . $ nftnl_expr_rt#key.;
20 enum nft_registerscxx . . $ nft_registers# dregcxx . . $ nftnl_expr_rt#dreg.;
21 };
22
23 static int
24 nftnl_expr_rt_setcxx . . $ nftnl_expr_rt_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_rtcxx . . $ nftnl_expr_rt# *rt = nftnl_expr_datacxx . . $ `include/expr_ops.h:31:9`!(e);
28
29 switch (type) {
30 case NFTNL_EXPR_RT_KEYcxx . . $ NFTNL_EXPR_RT_KEY.:
31 memcpycxx . . $ memcpy(cc817cb175f282d).(&rt->keycxx . . $ nftnl_expr_rt#key., data, data_len);
32 break;
33 case NFTNL_EXPR_RT_DREGcxx . . $ NFTNL_EXPR_RT_DREG.:
34 memcpycxx . . $ memcpy(cc817cb175f282d).(&rt->dregcxx . . $ nftnl_expr_rt#dreg., data, data_len);
35 break;
36 }
37 return 0;
38 }
39
40 static const void *
41 nftnl_expr_rt_getcxx . . $ nftnl_expr_rt_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_rtcxx . . $ nftnl_expr_rt# *rt = nftnl_expr_datacxx . . $ `include/expr_ops.h:31:9`!(e);
45
46 switch (type) {
47 case NFTNL_EXPR_RT_KEYcxx . . $ NFTNL_EXPR_RT_KEY.:
48 *data_len = sizeof(rt->keycxx . . $ nftnl_expr_rt#key.);
49 return &rt->keycxx . . $ nftnl_expr_rt#key.;
50 case NFTNL_EXPR_RT_DREGcxx . . $ NFTNL_EXPR_RT_DREG.:
51 *data_len = sizeof(rt->dregcxx . . $ nftnl_expr_rt#dreg.);
52 return &rt->dregcxx . . $ nftnl_expr_rt#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_rt_cbcxx . . $ nftnl_expr_rt_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_RT_MAXcxx . . $ `include/linux/netfilter/nf_tables.h:1092:9`!) < 0)
63 return MNL_CB_OKcxx . . $ `<external>/12386019527593959648/libmnl.h:174:9`!;
64
65 switch (type) {
66 case NFTA_RT_KEYcxx . . $ NFTA_RT_KEY.:
67 case NFTA_RT_DREGcxx . . $ NFTA_RT_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_rt_buildcxx . . $ nftnl_expr_rt_build(93c7528a9cf90b41).(struct nlmsghdrcxx . . $ nlmsghdr# *nlh, const struct nftnl_exprcxx . . $ nftnl_expr# *e)
79 {
80 struct nftnl_expr_rtcxx . . $ nftnl_expr_rt# *rt = nftnl_expr_datacxx . . $ `include/expr_ops.h:31:9`!(e);
81
82 if (e->flagscxx . . $ nftnl_expr#flags. & (1 << NFTNL_EXPR_RT_KEYcxx . . $ NFTNL_EXPR_RT_KEY.))
83 mnl_attr_put_u32cxx . . $ mnl_attr_put_u32(b46fd0aeb0cfb96d).(nlh, NFTA_RT_KEYcxx . . $ NFTA_RT_KEY., htonlcxx . . $ `<external>/9581057695539925927/in.h:430:12`!(rt->key));
84 if (e->flagscxx . . $ nftnl_expr#flags. & (1 << NFTNL_EXPR_RT_DREGcxx . . $ NFTNL_EXPR_RT_DREG.))
85 mnl_attr_put_u32cxx . . $ mnl_attr_put_u32(b46fd0aeb0cfb96d).(nlh, NFTA_RT_DREGcxx . . $ NFTA_RT_DREG., htonlcxx . . $ `<external>/9581057695539925927/in.h:430:12`!(rt->dreg));
86 }
87
88 static int
89 nftnl_expr_rt_parsecxx . . $ nftnl_expr_rt_parse(ed61207049d8af9a).(struct nftnl_exprcxx . . $ nftnl_expr# *e, struct nlattrcxx . . $ nlattr# *attr)
90 {
91 struct nftnl_expr_rtcxx . . $ nftnl_expr_rt# *rt = nftnl_expr_datacxx . . $ `include/expr_ops.h:31:9`!(e);
92 struct nlattrcxx . . $ nlattr# *tb[NFTA_RT_MAXcxx . . $ `include/linux/netfilter/nf_tables.h:1092:9`!+1] = {};
93
94 if (mnl_attr_parse_nestedcxx . . $ mnl_attr_parse_nested(f99c0e9fa94f99d9).(attr, nftnl_expr_rt_cbcxx . . $ nftnl_expr_rt_cb(de2ef18c48fd675c)., tb) < 0)
95 return -1;
96
97 if (tb[NFTA_RT_KEYcxx . . $ NFTA_RT_KEY.]) {
98 rt->keycxx . . $ nftnl_expr_rt#key. = ntohlcxx . . $ `<external>/9581057695539925927/in.h:428:12`!(mnl_attr_get_u32(tb[NFTA_RT_KEY]));
99 e->flagscxx . . $ nftnl_expr#flags. |= (1 << NFTNL_EXPR_RT_KEYcxx . . $ NFTNL_EXPR_RT_KEY.);
100 }
101 if (tb[NFTA_RT_DREGcxx . . $ NFTA_RT_DREG.]) {
102 rt->dregcxx . . $ nftnl_expr_rt#dreg. = ntohlcxx . . $ `<external>/9581057695539925927/in.h:428:12`!(mnl_attr_get_u32(tb[NFTA_RT_DREG]));
103 e->flagscxx . . $ nftnl_expr#flags. |= (1 << NFTNL_EXPR_RT_DREGcxx . . $ NFTNL_EXPR_RT_DREG.);
104 }
105
106 return 0;
107 }
108
109 static const char *rt_key2str_arraycxx . . $ rt_key2str_array.[NFT_RT_MAXcxx . . $ `include/linux/netfilter/nf_tables.h:1023:9`! + 1] = {
110 [NFT_RT_CLASSIDcxx . . $ NFT_RT_CLASSID.] = "classid",
111 [NFT_RT_NEXTHOP4cxx . . $ NFT_RT_NEXTHOP4.] = "nexthop4",
112 [NFT_RT_NEXTHOP6cxx . . $ NFT_RT_NEXTHOP6.] = "nexthop6",
113 [NFT_RT_TCPMSScxx . . $ NFT_RT_TCPMSS.] = "tcpmss",
114 [NFT_RT_XFRMcxx . . $ NFT_RT_XFRM.] = "ipsec",
115 };
116
117 static const char *rt_key2strcxx . . $ rt_key2str(42624c5f3be67010).(uint8_tcxx . . $ uint8_t# key)
118 {
119 if (key <= NFT_RT_MAXcxx . . $ `include/linux/netfilter/nf_tables.h:1023:9`!)
120 return rt_key2str_arraycxx . . $ rt_key2str_array.[key];
121
122 return "unknown";
123 }
124
125 static int
126 nftnl_expr_rt_snprintfcxx . . $ nftnl_expr_rt_snprintf(2b4af69501aef780).(char *buf, size_t len,
127 uint32_tcxx . . $ uint32_t# flags, const struct nftnl_exprcxx . . $ nftnl_expr# *e)
128 {
129 struct nftnl_expr_rtcxx . . $ nftnl_expr_rt# *rt = nftnl_expr_datacxx . . $ `include/expr_ops.h:31:9`!(e);
130
131 if (e->flagscxx . . $ nftnl_expr#flags. & (1 << NFTNL_EXPR_RT_DREGcxx . . $ NFTNL_EXPR_RT_DREG.)) {
132 return snprintfcxx . . $ snprintf(ea502d73e74c754c).(buf, len, "load %s => reg %u ",
133 rt_key2strcxx . . $ rt_key2str(42624c5f3be67010).(rt->keycxx . . $ nftnl_expr_rt#key.), rt->dregcxx . . $ nftnl_expr_rt#dreg.);
134 }
135 return 0;
136 }
137
138 static struct attr_policycxx . . $ attr_policy# rt_attr_policycxx . . $ rt_attr_policy.[__NFTNL_EXPR_RT_MAXcxx . . $ __NFTNL_EXPR_RT_MAX.] = {
139 [NFTNL_EXPR_RT_KEYcxx . . $ NFTNL_EXPR_RT_KEY.] = { .maxlen = sizeof(uint32_tcxx . . $ uint32_t#) },
140 [NFTNL_EXPR_RT_DREGcxx . . $ NFTNL_EXPR_RT_DREG.] = { .maxlen = sizeof(uint32_tcxx . . $ uint32_t#) },
141 };
142
143 struct expr_opscxx . . $ expr_ops# expr_ops_rtcxx . . $ expr_ops_rt. = {
144 .name = "rt",
145 .alloc_len = sizeof(struct nftnl_expr_rtcxx . . $ nftnl_expr_rt#),
146 .nftnl_max_attr = __NFTNL_EXPR_RT_MAXcxx . . $ __NFTNL_EXPR_RT_MAX. - 1,
147 .attr_policy = rt_attr_policycxx . . $ rt_attr_policy.,
148 .set = nftnl_expr_rt_setcxx . . $ nftnl_expr_rt_set(211371a3e3842127).,
149 .get = nftnl_expr_rt_getcxx . . $ nftnl_expr_rt_get(9de263c4f9e71c4b).,
150 .parse = nftnl_expr_rt_parsecxx . . $ nftnl_expr_rt_parse(ed61207049d8af9a).,
151 .build = nftnl_expr_rt_buildcxx . . $ nftnl_expr_rt_build(93c7528a9cf90b41).,
152 .output = nftnl_expr_rt_snprintfcxx . . $ nftnl_expr_rt_snprintf(2b4af69501aef780).,
153 };