Debian Codegraph @

src/obj/limit.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-or-later */cxx . . $ `<file>/src/obj/limit.c`/
2 /*
3 * Copyright (c) 2017 Pablo M. Bermudo Garay <[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/object.h>cxx . . $ `<file>/include/libnftnl/object.h`/
17
18 #include "obj.h"cxx . . $ `<file>/include/obj.h`/
19
20 static int nftnl_obj_limit_setcxx . . $ nftnl_obj_limit_set(96c901c785434bf1).(struct nftnl_objcxx . . $ nftnl_obj# *e, uint16_tcxx . . $ uint16_t# type,
21 const void *data, uint32_tcxx . . $ uint32_t# data_len)
22 {
23 struct nftnl_obj_limitcxx . . $ nftnl_obj_limit# *limit = nftnl_obj_datacxx . . $ `include/obj.h:117:9`!(e);
24
25 switch (type) {
26 case NFTNL_OBJ_LIMIT_RATEcxx . . $ NFTNL_OBJ_LIMIT_RATE.:
27 memcpycxx . . $ memcpy(cc817cb175f282d).(&limit->ratecxx . . $ nftnl_obj_limit#rate., data, data_len);
28 break;
29 case NFTNL_OBJ_LIMIT_UNITcxx . . $ NFTNL_OBJ_LIMIT_UNIT.:
30 memcpycxx . . $ memcpy(cc817cb175f282d).(&limit->unitcxx . . $ nftnl_obj_limit#unit., data, data_len);
31 break;
32 case NFTNL_OBJ_LIMIT_BURSTcxx . . $ NFTNL_OBJ_LIMIT_BURST.:
33 memcpycxx . . $ memcpy(cc817cb175f282d).(&limit->burstcxx . . $ nftnl_obj_limit#burst., data, data_len);
34 break;
35 case NFTNL_OBJ_LIMIT_TYPEcxx . . $ NFTNL_OBJ_LIMIT_TYPE.:
36 memcpycxx . . $ memcpy(cc817cb175f282d).(&limit->typecxx . . $ nftnl_obj_limit#type., data, data_len);
37 break;
38 case NFTNL_OBJ_LIMIT_FLAGScxx . . $ NFTNL_OBJ_LIMIT_FLAGS.:
39 memcpycxx . . $ memcpy(cc817cb175f282d).(&limit->flagscxx . . $ nftnl_obj_limit#flags., data, data_len);
40 break;
41 }
42 return 0;
43 }
44
45 static const void *nftnl_obj_limit_getcxx . . $ nftnl_obj_limit_get(d22e54b888e7c4b).(const struct nftnl_objcxx . . $ nftnl_obj# *e,
46 uint16_tcxx . . $ uint16_t# type, uint32_tcxx . . $ uint32_t# *data_len)
47 {
48 struct nftnl_obj_limitcxx . . $ nftnl_obj_limit# *limit = nftnl_obj_datacxx . . $ `include/obj.h:117:9`!(e);
49
50 switch (type) {
51 case NFTNL_OBJ_LIMIT_RATEcxx . . $ NFTNL_OBJ_LIMIT_RATE.:
52 *data_len = sizeof(limit->ratecxx . . $ nftnl_obj_limit#rate.);
53 return &limit->ratecxx . . $ nftnl_obj_limit#rate.;
54 case NFTNL_OBJ_LIMIT_UNITcxx . . $ NFTNL_OBJ_LIMIT_UNIT.:
55 *data_len = sizeof(limit->unitcxx . . $ nftnl_obj_limit#unit.);
56 return &limit->unitcxx . . $ nftnl_obj_limit#unit.;
57 case NFTNL_OBJ_LIMIT_BURSTcxx . . $ NFTNL_OBJ_LIMIT_BURST.:
58 *data_len = sizeof(limit->burstcxx . . $ nftnl_obj_limit#burst.);
59 return &limit->burstcxx . . $ nftnl_obj_limit#burst.;
60 case NFTNL_OBJ_LIMIT_TYPEcxx . . $ NFTNL_OBJ_LIMIT_TYPE.:
61 *data_len = sizeof(limit->typecxx . . $ nftnl_obj_limit#type.);
62 return &limit->typecxx . . $ nftnl_obj_limit#type.;
63 case NFTNL_OBJ_LIMIT_FLAGScxx . . $ NFTNL_OBJ_LIMIT_FLAGS.:
64 *data_len = sizeof(limit->flagscxx . . $ nftnl_obj_limit#flags.);
65 return &limit->flagscxx . . $ nftnl_obj_limit#flags.;
66 }
67 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
68 }
69
70 static int nftnl_obj_limit_cbcxx . . $ nftnl_obj_limit_cb(de2ef18c48fd675c).(const struct nlattrcxx . . $ nlattr# *attr, void *data)
71 {
72 int type = mnl_attr_get_typecxx . . $ mnl_attr_get_type(1da47bcc4c4b975).(attr);
73 const struct nlattrcxx . . $ nlattr# **tb = data;
74
75 if (mnl_attr_type_validcxx . . $ mnl_attr_type_valid(47df1cce1c7be855).(attr, NFTA_LIMIT_MAXcxx . . $ `include/linux/netfilter/nf_tables.h:1241:9`!) < 0)
76 return MNL_CB_OKcxx . . $ `<external>/12386019527593959648/libmnl.h:174:9`!;
77
78 switch (type) {
79 case NFTA_LIMIT_RATEcxx . . $ NFTA_LIMIT_RATE.:
80 case NFTA_LIMIT_UNITcxx . . $ NFTA_LIMIT_UNIT.:
81 if (mnl_attr_validatecxx . . $ mnl_attr_validate(e419697a5e1ae2b1).(attr, MNL_TYPE_U64cxx . . $ MNL_TYPE_U64.) < 0)
82 abi_breakagecxx . . $ `include/utils.h:28:9`!();
83 break;
84 case NFTA_LIMIT_BURSTcxx . . $ NFTA_LIMIT_BURST.:
85 case NFTA_LIMIT_TYPEcxx . . $ NFTA_LIMIT_TYPE.:
86 case NFTA_LIMIT_FLAGScxx . . $ NFTA_LIMIT_FLAGS.:
87 if (mnl_attr_validatecxx . . $ mnl_attr_validate(e419697a5e1ae2b1).(attr, MNL_TYPE_U32cxx . . $ MNL_TYPE_U32.) < 0)
88 abi_breakagecxx . . $ `include/utils.h:28:9`!();
89 break;
90 }
91
92 tb[type] = attr;
93 return MNL_CB_OKcxx . . $ `<external>/12386019527593959648/libmnl.h:174:9`!;
94 }
95
96 static void nftnl_obj_limit_buildcxx . . $ nftnl_obj_limit_build(3650aba98805b449).(struct nlmsghdrcxx . . $ nlmsghdr# *nlh,
97 const struct nftnl_objcxx . . $ nftnl_obj# *e)
98 {
99 struct nftnl_obj_limitcxx . . $ nftnl_obj_limit# *limit = nftnl_obj_datacxx . . $ `include/obj.h:117:9`!(e);
100
101 if (e->flagscxx . . $ nftnl_obj#flags. & (1 << NFTNL_OBJ_LIMIT_RATEcxx . . $ NFTNL_OBJ_LIMIT_RATE.))
102 mnl_attr_put_u64cxx . . $ mnl_attr_put_u64(6d753f4d486e3a2f).(nlh, NFTA_LIMIT_RATEcxx . . $ NFTA_LIMIT_RATE., htobe64cxx . . $ `<external>/15855202785537844739/endian.h:49:11`!(limit->rate));
103 if (e->flagscxx . . $ nftnl_obj#flags. & (1 << NFTNL_OBJ_LIMIT_UNITcxx . . $ NFTNL_OBJ_LIMIT_UNIT.))
104 mnl_attr_put_u64cxx . . $ mnl_attr_put_u64(6d753f4d486e3a2f).(nlh, NFTA_LIMIT_UNITcxx . . $ NFTA_LIMIT_UNIT., htobe64cxx . . $ `<external>/15855202785537844739/endian.h:49:11`!(limit->unit));
105 if (e->flagscxx . . $ nftnl_obj#flags. & (1 << NFTNL_OBJ_LIMIT_BURSTcxx . . $ NFTNL_OBJ_LIMIT_BURST.))
106 mnl_attr_put_u32cxx . . $ mnl_attr_put_u32(b46fd0aeb0cfb96d).(nlh, NFTA_LIMIT_BURSTcxx . . $ NFTA_LIMIT_BURST., htonlcxx . . $ `<external>/9581057695539925927/in.h:430:12`!(limit->burst));
107 if (e->flagscxx . . $ nftnl_obj#flags. & (1 << NFTNL_OBJ_LIMIT_TYPEcxx . . $ NFTNL_OBJ_LIMIT_TYPE.))
108 mnl_attr_put_u32cxx . . $ mnl_attr_put_u32(b46fd0aeb0cfb96d).(nlh, NFTA_LIMIT_TYPEcxx . . $ NFTA_LIMIT_TYPE., htonlcxx . . $ `<external>/9581057695539925927/in.h:430:12`!(limit->type));
109 if (e->flagscxx . . $ nftnl_obj#flags. & (1 << NFTNL_OBJ_LIMIT_FLAGScxx . . $ NFTNL_OBJ_LIMIT_FLAGS.))
110 mnl_attr_put_u32cxx . . $ mnl_attr_put_u32(b46fd0aeb0cfb96d).(nlh, NFTA_LIMIT_FLAGScxx . . $ NFTA_LIMIT_FLAGS., htonlcxx . . $ `<external>/9581057695539925927/in.h:430:12`!(limit->flags));
111 }
112
113 static int nftnl_obj_limit_parsecxx . . $ nftnl_obj_limit_parse(f22ac2b7a2342b3a).(struct nftnl_objcxx . . $ nftnl_obj# *e, struct nlattrcxx . . $ nlattr# *attr)
114 {
115 struct nftnl_obj_limitcxx . . $ nftnl_obj_limit# *limit = nftnl_obj_datacxx . . $ `include/obj.h:117:9`!(e);
116 struct nlattrcxx . . $ nlattr# *tb[NFTA_LIMIT_MAXcxx . . $ `include/linux/netfilter/nf_tables.h:1241:9`! + 1] = {};
117
118 if (mnl_attr_parse_nestedcxx . . $ mnl_attr_parse_nested(f99c0e9fa94f99d9).(attr, nftnl_obj_limit_cbcxx . . $ nftnl_obj_limit_cb(de2ef18c48fd675c)., tb) < 0)
119 return -1;
120
121 if (tb[NFTA_LIMIT_RATEcxx . . $ NFTA_LIMIT_RATE.]) {
122 limit->ratecxx . . $ nftnl_obj_limit#rate. = be64tohcxx . . $ `<external>/15855202785537844739/endian.h:51:11`!(mnl_attr_get_u64(tb[NFTA_LIMIT_RATE]));
123 e->flagscxx . . $ nftnl_obj#flags. |= (1 << NFTNL_OBJ_LIMIT_RATEcxx . . $ NFTNL_OBJ_LIMIT_RATE.);
124 }
125 if (tb[NFTA_LIMIT_UNITcxx . . $ NFTA_LIMIT_UNIT.]) {
126 limit->unitcxx . . $ nftnl_obj_limit#unit. = be64tohcxx . . $ `<external>/15855202785537844739/endian.h:51:11`!(mnl_attr_get_u64(tb[NFTA_LIMIT_UNIT]));
127 e->flagscxx . . $ nftnl_obj#flags. |= (1 << NFTNL_OBJ_LIMIT_UNITcxx . . $ NFTNL_OBJ_LIMIT_UNIT.);
128 }
129 if (tb[NFTA_LIMIT_BURSTcxx . . $ NFTA_LIMIT_BURST.]) {
130 limit->burstcxx . . $ nftnl_obj_limit#burst. = ntohlcxx . . $ `<external>/9581057695539925927/in.h:428:12`!(mnl_attr_get_u32(tb[NFTA_LIMIT_BURST]));
131 e->flagscxx . . $ nftnl_obj#flags. |= (1 << NFTNL_OBJ_LIMIT_BURSTcxx . . $ NFTNL_OBJ_LIMIT_BURST.);
132 }
133 if (tb[NFTA_LIMIT_TYPEcxx . . $ NFTA_LIMIT_TYPE.]) {
134 limit->typecxx . . $ nftnl_obj_limit#type. = ntohlcxx . . $ `<external>/9581057695539925927/in.h:428:12`!(mnl_attr_get_u32(tb[NFTA_LIMIT_TYPE]));
135 e->flagscxx . . $ nftnl_obj#flags. |= (1 << NFTNL_OBJ_LIMIT_TYPEcxx . . $ NFTNL_OBJ_LIMIT_TYPE.);
136 }
137 if (tb[NFTA_LIMIT_FLAGScxx . . $ NFTA_LIMIT_FLAGS.]) {
138 limit->flagscxx . . $ nftnl_obj_limit#flags. = ntohlcxx . . $ `<external>/9581057695539925927/in.h:428:12`!(mnl_attr_get_u32(tb[NFTA_LIMIT_FLAGS]));
139 e->flagscxx . . $ nftnl_obj#flags. |= (1 << NFTNL_OBJ_LIMIT_FLAGScxx . . $ NFTNL_OBJ_LIMIT_FLAGS.);
140 }
141
142 return 0;
143 }
144
145 static int nftnl_obj_limit_snprintfcxx . . $ nftnl_obj_limit_snprintf(58da6fcd2536b16e).(char *buf, size_tcxx . . $ size_t# len,
146 uint32_tcxx . . $ uint32_t# flags,
147 const struct nftnl_objcxx . . $ nftnl_obj# *e)
148 {
149 struct nftnl_obj_limitcxx . . $ nftnl_obj_limit# *limit = nftnl_obj_datacxx . . $ `include/obj.h:117:9`!(e);
150
151 return snprintfcxx . . $ snprintf(ea502d73e74c754c).(buf, len, "rate %"PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:110:10`!" unit %"PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:110:10`!" burst %u "
152 "type %u flags %u ", limit->ratecxx . . $ nftnl_obj_limit#rate., limit->unitcxx . . $ nftnl_obj_limit#unit.,
153 limit->burstcxx . . $ nftnl_obj_limit#burst., limit->typecxx . . $ nftnl_obj_limit#type., limit->flagscxx . . $ nftnl_obj_limit#flags.);
154 }
155
156 static struct attr_policycxx . . $ attr_policy# obj_limit_attr_policycxx . . $ obj_limit_attr_policy.[__NFTNL_OBJ_LIMIT_MAXcxx . . $ __NFTNL_OBJ_LIMIT_MAX.] = {
157 [NFTNL_OBJ_LIMIT_RATEcxx . . $ NFTNL_OBJ_LIMIT_RATE.] = { .maxlen = sizeof(uint64_tcxx . . $ uint64_t#) },
158 [NFTNL_OBJ_LIMIT_UNITcxx . . $ NFTNL_OBJ_LIMIT_UNIT.] = { .maxlen = sizeof(uint64_tcxx . . $ uint64_t#) },
159 [NFTNL_OBJ_LIMIT_BURSTcxx . . $ NFTNL_OBJ_LIMIT_BURST.] = { .maxlen = sizeof(uint32_tcxx . . $ uint32_t#) },
160 [NFTNL_OBJ_LIMIT_TYPEcxx . . $ NFTNL_OBJ_LIMIT_TYPE.] = { .maxlen = sizeof(uint32_tcxx . . $ uint32_t#) },
161 [NFTNL_OBJ_LIMIT_FLAGScxx . . $ NFTNL_OBJ_LIMIT_FLAGS.] = { .maxlen = sizeof(uint32_tcxx . . $ uint32_t#) },
162 };
163
164 struct obj_opscxx . . $ obj_ops# obj_ops_limitcxx . . $ obj_ops_limit. = {
165 .name = "limit",
166 .type = NFT_OBJECT_LIMITcxx . . $ `include/linux/netfilter/nf_tables.h:1662:9`!,
167 .alloc_len = sizeof(struct nftnl_obj_limitcxx . . $ nftnl_obj_limit#),
168 .nftnl_max_attr = __NFTNL_OBJ_LIMIT_MAXcxx . . $ __NFTNL_OBJ_LIMIT_MAX. - 1,
169 .attr_policy = obj_limit_attr_policycxx . . $ obj_limit_attr_policy.,
170 .set = nftnl_obj_limit_setcxx . . $ nftnl_obj_limit_set(96c901c785434bf1).,
171 .get = nftnl_obj_limit_getcxx . . $ nftnl_obj_limit_get(d22e54b888e7c4b).,
172 .parse = nftnl_obj_limit_parsecxx . . $ nftnl_obj_limit_parse(f22ac2b7a2342b3a).,
173 .build = nftnl_obj_limit_buildcxx . . $ nftnl_obj_limit_build(3650aba98805b449).,
174 .output = nftnl_obj_limit_snprintfcxx . . $ nftnl_obj_limit_snprintf(58da6fcd2536b16e).,
175 };