Debian Codegraph @

src/obj/quota.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-or-later */cxx . . $ `<file>/src/obj/quota.c`/
2 /*
3 * (C) 2012-2016 by Pablo Neira Ayuso <[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_quota_setcxx . . $ nftnl_obj_quota_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_quotacxx . . $ nftnl_obj_quota# *quota = nftnl_obj_datacxx . . $ `include/obj.h:117:9`!(e);
24
25 switch (type) {
26 case NFTNL_OBJ_QUOTA_BYTEScxx . . $ NFTNL_OBJ_QUOTA_BYTES.:
27 memcpycxx . . $ memcpy(cc817cb175f282d).(&quota->bytescxx . . $ nftnl_obj_quota#bytes., data, data_len);
28 break;
29 case NFTNL_OBJ_QUOTA_CONSUMEDcxx . . $ NFTNL_OBJ_QUOTA_CONSUMED.:
30 memcpycxx . . $ memcpy(cc817cb175f282d).(&quota->consumedcxx . . $ nftnl_obj_quota#consumed., data, data_len);
31 break;
32 case NFTNL_OBJ_QUOTA_FLAGScxx . . $ NFTNL_OBJ_QUOTA_FLAGS.:
33 memcpycxx . . $ memcpy(cc817cb175f282d).(&quota->flagscxx . . $ nftnl_obj_quota#flags., data, data_len);
34 break;
35 }
36 return 0;
37 }
38
39 static const void *nftnl_obj_quota_getcxx . . $ nftnl_obj_quota_get(d22e54b888e7c4b).(const struct nftnl_objcxx . . $ nftnl_obj# *e,
40 uint16_tcxx . . $ uint16_t# type, uint32_tcxx . . $ uint32_t# *data_len)
41 {
42 struct nftnl_obj_quotacxx . . $ nftnl_obj_quota# *quota = nftnl_obj_datacxx . . $ `include/obj.h:117:9`!(e);
43
44 switch (type) {
45 case NFTNL_OBJ_QUOTA_BYTEScxx . . $ NFTNL_OBJ_QUOTA_BYTES.:
46 *data_len = sizeof(quota->bytescxx . . $ nftnl_obj_quota#bytes.);
47 return &quota->bytescxx . . $ nftnl_obj_quota#bytes.;
48 case NFTNL_OBJ_QUOTA_CONSUMEDcxx . . $ NFTNL_OBJ_QUOTA_CONSUMED.:
49 *data_len = sizeof(quota->consumedcxx . . $ nftnl_obj_quota#consumed.);
50 return &quota->consumedcxx . . $ nftnl_obj_quota#consumed.;
51 case NFTNL_OBJ_QUOTA_FLAGScxx . . $ NFTNL_OBJ_QUOTA_FLAGS.:
52 *data_len = sizeof(quota->flagscxx . . $ nftnl_obj_quota#flags.);
53 return &quota->flagscxx . . $ nftnl_obj_quota#flags.;
54 }
55 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
56 }
57
58 static int nftnl_obj_quota_cbcxx . . $ nftnl_obj_quota_cb(de2ef18c48fd675c).(const struct nlattrcxx . . $ nlattr# *attr, void *data)
59 {
60 int type = mnl_attr_get_typecxx . . $ mnl_attr_get_type(1da47bcc4c4b975).(attr);
61 const struct nlattrcxx . . $ nlattr# **tb = data;
62
63 if (mnl_attr_type_validcxx . . $ mnl_attr_type_valid(47df1cce1c7be855).(attr, NFTA_QUOTA_MAXcxx . . $ `include/linux/netfilter/nf_tables.h:1382:9`!) < 0)
64 return MNL_CB_OKcxx . . $ `<external>/12386019527593959648/libmnl.h:174:9`!;
65
66 switch(type) {
67 case NFTA_QUOTA_BYTEScxx . . $ NFTA_QUOTA_BYTES.:
68 case NFTA_QUOTA_CONSUMEDcxx . . $ NFTA_QUOTA_CONSUMED.:
69 if (mnl_attr_validatecxx . . $ mnl_attr_validate(e419697a5e1ae2b1).(attr, MNL_TYPE_U64cxx . . $ MNL_TYPE_U64.) < 0)
70 abi_breakagecxx . . $ `include/utils.h:28:9`!();
71 break;
72 case NFTA_QUOTA_FLAGScxx . . $ NFTA_QUOTA_FLAGS.:
73 if (mnl_attr_validatecxx . . $ mnl_attr_validate(e419697a5e1ae2b1).(attr, MNL_TYPE_U32cxx . . $ MNL_TYPE_U32.) < 0)
74 abi_breakagecxx . . $ `include/utils.h:28:9`!();
75 break;
76 }
77
78 tb[type] = attr;
79 return MNL_CB_OKcxx . . $ `<external>/12386019527593959648/libmnl.h:174:9`!;
80 }
81
82 static void
83 nftnl_obj_quota_buildcxx . . $ nftnl_obj_quota_build(3650aba98805b449).(struct nlmsghdrcxx . . $ nlmsghdr# *nlh, const struct nftnl_objcxx . . $ nftnl_obj# *e)
84 {
85 struct nftnl_obj_quotacxx . . $ nftnl_obj_quota# *quota = nftnl_obj_datacxx . . $ `include/obj.h:117:9`!(e);
86
87 if (e->flagscxx . . $ nftnl_obj#flags. & (1 << NFTNL_OBJ_QUOTA_BYTEScxx . . $ NFTNL_OBJ_QUOTA_BYTES.))
88 mnl_attr_put_u64cxx . . $ mnl_attr_put_u64(6d753f4d486e3a2f).(nlh, NFTA_QUOTA_BYTEScxx . . $ NFTA_QUOTA_BYTES., htobe64cxx . . $ `<external>/15855202785537844739/endian.h:49:11`!(quota->bytes));
89 if (e->flagscxx . . $ nftnl_obj#flags. & (1 << NFTNL_OBJ_QUOTA_CONSUMEDcxx . . $ NFTNL_OBJ_QUOTA_CONSUMED.))
90 mnl_attr_put_u64cxx . . $ mnl_attr_put_u64(6d753f4d486e3a2f).(nlh, NFTA_QUOTA_CONSUMEDcxx . . $ NFTA_QUOTA_CONSUMED.,
91 htobe64cxx . . $ `<external>/15855202785537844739/endian.h:49:11`!(quota->consumed));
92 if (e->flagscxx . . $ nftnl_obj#flags. & (1 << NFTNL_OBJ_QUOTA_FLAGScxx . . $ NFTNL_OBJ_QUOTA_FLAGS.))
93 mnl_attr_put_u32cxx . . $ mnl_attr_put_u32(b46fd0aeb0cfb96d).(nlh, NFTA_QUOTA_FLAGScxx . . $ NFTA_QUOTA_FLAGS., htonlcxx . . $ `<external>/9581057695539925927/in.h:430:12`!(quota->flags));
94 }
95
96 static int
97 nftnl_obj_quota_parsecxx . . $ nftnl_obj_quota_parse(f22ac2b7a2342b3a).(struct nftnl_objcxx . . $ nftnl_obj# *e, struct nlattrcxx . . $ nlattr# *attr)
98 {
99 struct nftnl_obj_quotacxx . . $ nftnl_obj_quota# *quota = nftnl_obj_datacxx . . $ `include/obj.h:117:9`!(e);
100 struct nlattrcxx . . $ nlattr# *tb[NFTA_QUOTA_MAXcxx . . $ `include/linux/netfilter/nf_tables.h:1382:9`! + 1] = {};
101
102 if (mnl_attr_parse_nestedcxx . . $ mnl_attr_parse_nested(f99c0e9fa94f99d9).(attr, nftnl_obj_quota_cbcxx . . $ nftnl_obj_quota_cb(de2ef18c48fd675c)., tb) < 0)
103 return -1;
104
105 if (tb[NFTA_QUOTA_BYTEScxx . . $ NFTA_QUOTA_BYTES.]) {
106 quota->bytescxx . . $ nftnl_obj_quota#bytes. = be64tohcxx . . $ `<external>/15855202785537844739/endian.h:51:11`!(mnl_attr_get_u64(tb[NFTA_QUOTA_BYTES]));
107 e->flagscxx . . $ nftnl_obj#flags. |= (1 << NFTNL_OBJ_QUOTA_BYTEScxx . . $ NFTNL_OBJ_QUOTA_BYTES.);
108 }
109 if (tb[NFTA_QUOTA_CONSUMEDcxx . . $ NFTA_QUOTA_CONSUMED.]) {
110 quota->consumedcxx . . $ nftnl_obj_quota#consumed. =
111 be64tohcxx . . $ `<external>/15855202785537844739/endian.h:51:11`!(mnl_attr_get_u64(tb[NFTA_QUOTA_CONSUMED]));
112 e->flagscxx . . $ nftnl_obj#flags. |= (1 << NFTNL_OBJ_QUOTA_CONSUMEDcxx . . $ NFTNL_OBJ_QUOTA_CONSUMED.);
113 }
114 if (tb[NFTA_QUOTA_FLAGScxx . . $ NFTA_QUOTA_FLAGS.]) {
115 quota->flagscxx . . $ nftnl_obj_quota#flags. = ntohlcxx . . $ `<external>/9581057695539925927/in.h:428:12`!(mnl_attr_get_u32(tb[NFTA_QUOTA_FLAGS]));
116 e->flagscxx . . $ nftnl_obj#flags. |= (1 << NFTNL_OBJ_QUOTA_FLAGScxx . . $ NFTNL_OBJ_QUOTA_FLAGS.);
117 }
118
119 return 0;
120 }
121
122 static int nftnl_obj_quota_snprintfcxx . . $ nftnl_obj_quota_snprintf(58da6fcd2536b16e).(char *buf, size_t len,
123 uint32_tcxx . . $ uint32_t# flags,
124 const struct nftnl_objcxx . . $ nftnl_obj# *e)
125 {
126 struct nftnl_obj_quotacxx . . $ nftnl_obj_quota# *quota = nftnl_obj_datacxx . . $ `include/obj.h:117:9`!(e);
127
128 return snprintfcxx . . $ snprintf(ea502d73e74c754c).(buf, len, "bytes %"PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:110:10`!" flags %u ",
129 quota->bytescxx . . $ nftnl_obj_quota#bytes., quota->flagscxx . . $ nftnl_obj_quota#flags.);
130 }
131
132 static struct attr_policycxx . . $ attr_policy# obj_quota_attr_policycxx . . $ obj_quota_attr_policy.[__NFTNL_OBJ_QUOTA_MAXcxx . . $ __NFTNL_OBJ_QUOTA_MAX.] = {
133 [NFTNL_OBJ_QUOTA_BYTEScxx . . $ NFTNL_OBJ_QUOTA_BYTES.] = { .maxlen = sizeof(uint64_tcxx . . $ uint64_t#) },
134 [NFTNL_OBJ_QUOTA_CONSUMEDcxx . . $ NFTNL_OBJ_QUOTA_CONSUMED.] = { .maxlen = sizeof(uint64_tcxx . . $ uint64_t#) },
135 [NFTNL_OBJ_QUOTA_FLAGScxx . . $ NFTNL_OBJ_QUOTA_FLAGS.] = { .maxlen = sizeof(uint32_tcxx . . $ uint32_t#) },
136 };
137
138 struct obj_opscxx . . $ obj_ops# obj_ops_quotacxx . . $ obj_ops_quota. = {
139 .name = "quota",
140 .type = NFT_OBJECT_QUOTAcxx . . $ `include/linux/netfilter/nf_tables.h:1660:9`!,
141 .alloc_len = sizeof(struct nftnl_obj_quotacxx . . $ nftnl_obj_quota#),
142 .nftnl_max_attr = __NFTNL_OBJ_QUOTA_MAXcxx . . $ __NFTNL_OBJ_QUOTA_MAX. - 1,
143 .attr_policy = obj_quota_attr_policycxx . . $ obj_quota_attr_policy.,
144 .set = nftnl_obj_quota_setcxx . . $ nftnl_obj_quota_set(96c901c785434bf1).,
145 .get = nftnl_obj_quota_getcxx . . $ nftnl_obj_quota_get(d22e54b888e7c4b).,
146 .parse = nftnl_obj_quota_parsecxx . . $ nftnl_obj_quota_parse(f22ac2b7a2342b3a).,
147 .build = nftnl_obj_quota_buildcxx . . $ nftnl_obj_quota_build(3650aba98805b449).,
148 .output = nftnl_obj_quota_snprintfcxx . . $ nftnl_obj_quota_snprintf(58da6fcd2536b16e).,
149 };