Debian Codegraph @

src/expr/last.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-or-later */cxx . . $ `<file>/src/expr/last.c`/
2 /*
3 * (C) 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/expr.h>cxx . . $ `<file>/include/libnftnl/expr.h`/
17 #include <libnftnl/rule.h>cxx . . $ `<file>/include/libnftnl/rule.h`/
18
19 struct nftnl_expr_lastcxx . . $ nftnl_expr_last# {
20 uint64_tcxx . . $ uint64_t# msecscxx . . $ nftnl_expr_last#msecs.;
21 uint32_tcxx . . $ uint32_t# setcxx . . $ nftnl_expr_last#set.;
22 };
23
24 static int
25 nftnl_expr_last_setcxx . . $ nftnl_expr_last_set(211371a3e3842127).(struct nftnl_exprcxx . . $ nftnl_expr# *e, uint16_tcxx . . $ uint16_t# type,
26 const void *data, uint32_tcxx . . $ uint32_t# data_len, uint32_tcxx . . $ uint32_t# byteorder)
27 {
28 struct nftnl_expr_lastcxx . . $ nftnl_expr_last# *last = nftnl_expr_datacxx . . $ `include/expr_ops.h:31:9`!(e);
29
30 switch (type) {
31 case NFTNL_EXPR_LAST_MSECScxx . . $ NFTNL_EXPR_LAST_MSECS.:
32 memcpycxx . . $ memcpy(cc817cb175f282d).(&last->msecscxx . . $ nftnl_expr_last#msecs., data, data_len);
33 break;
34 case NFTNL_EXPR_LAST_SETcxx . . $ NFTNL_EXPR_LAST_SET.:
35 memcpycxx . . $ memcpy(cc817cb175f282d).(&last->setcxx . . $ nftnl_expr_last#set., data, data_len);
36 break;
37 }
38 return 0;
39 }
40
41 static const void *nftnl_expr_last_getcxx . . $ nftnl_expr_last_get(9de263c4f9e71c4b).(const struct nftnl_exprcxx . . $ nftnl_expr# *e,
42 uint16_tcxx . . $ uint16_t# type, uint32_tcxx . . $ uint32_t# *data_len)
43 {
44 struct nftnl_expr_lastcxx . . $ nftnl_expr_last# *last = nftnl_expr_datacxx . . $ `include/expr_ops.h:31:9`!(e);
45
46 switch (type) {
47 case NFTNL_EXPR_LAST_MSECScxx . . $ NFTNL_EXPR_LAST_MSECS.:
48 *data_len = sizeof(last->msecscxx . . $ nftnl_expr_last#msecs.);
49 return &last->msecscxx . . $ nftnl_expr_last#msecs.;
50 case NFTNL_EXPR_LAST_SETcxx . . $ NFTNL_EXPR_LAST_SET.:
51 *data_len = sizeof(last->setcxx . . $ nftnl_expr_last#set.);
52 return &last->setcxx . . $ nftnl_expr_last#set.;
53 }
54 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
55 }
56
57 static int nftnl_expr_last_cbcxx . . $ nftnl_expr_last_cb(de2ef18c48fd675c).(const struct nlattrcxx . . $ nlattr# *attr, void *data)
58 {
59 int type = mnl_attr_get_typecxx . . $ mnl_attr_get_type(1da47bcc4c4b975).(attr);
60 const struct nlattrcxx . . $ nlattr# **tb = data;
61
62 if (mnl_attr_type_validcxx . . $ mnl_attr_type_valid(47df1cce1c7be855).(attr, NFTA_LAST_MAXcxx . . $ `include/linux/netfilter/nf_tables.h:1289:9`!) < 0)
63 return MNL_CB_OKcxx . . $ `<external>/12386019527593959648/libmnl.h:174:9`!;
64
65 switch(type) {
66 case NFTA_LAST_MSECScxx . . $ NFTA_LAST_MSECS.:
67 if (mnl_attr_validatecxx . . $ mnl_attr_validate(e419697a5e1ae2b1).(attr, MNL_TYPE_U64cxx . . $ MNL_TYPE_U64.) < 0)
68 abi_breakagecxx . . $ `include/utils.h:28:9`!();
69 break;
70 case NFTA_LAST_SETcxx . . $ NFTA_LAST_SET.:
71 if (mnl_attr_validatecxx . . $ mnl_attr_validate(e419697a5e1ae2b1).(attr, MNL_TYPE_U32cxx . . $ MNL_TYPE_U32.) < 0)
72 abi_breakagecxx . . $ `include/utils.h:28:9`!();
73 break;
74 }
75
76 tb[type] = attr;
77 return MNL_CB_OKcxx . . $ `<external>/12386019527593959648/libmnl.h:174:9`!;
78 }
79
80 static void
81 nftnl_expr_last_buildcxx . . $ nftnl_expr_last_build(93c7528a9cf90b41).(struct nlmsghdrcxx . . $ nlmsghdr# *nlh, const struct nftnl_exprcxx . . $ nftnl_expr# *e)
82 {
83 struct nftnl_expr_lastcxx . . $ nftnl_expr_last# *last = nftnl_expr_datacxx . . $ `include/expr_ops.h:31:9`!(e);
84
85 if (e->flagscxx . . $ nftnl_expr#flags. & (1 << NFTNL_EXPR_LAST_MSECScxx . . $ NFTNL_EXPR_LAST_MSECS.))
86 mnl_attr_put_u64cxx . . $ mnl_attr_put_u64(6d753f4d486e3a2f).(nlh, NFTA_LAST_MSECScxx . . $ NFTA_LAST_MSECS., htobe64cxx . . $ `<external>/15855202785537844739/endian.h:49:11`!(last->msecs));
87 if (e->flagscxx . . $ nftnl_expr#flags. & (1 << NFTNL_EXPR_LAST_SETcxx . . $ NFTNL_EXPR_LAST_SET.))
88 mnl_attr_put_u32cxx . . $ mnl_attr_put_u32(b46fd0aeb0cfb96d).(nlh, NFTA_LAST_SETcxx . . $ NFTA_LAST_SET., htonlcxx . . $ `<external>/9581057695539925927/in.h:430:12`!(last->set));
89 }
90
91 static int
92 nftnl_expr_last_parsecxx . . $ nftnl_expr_last_parse(ed61207049d8af9a).(struct nftnl_exprcxx . . $ nftnl_expr# *e, struct nlattrcxx . . $ nlattr# *attr)
93 {
94 struct nftnl_expr_lastcxx . . $ nftnl_expr_last# *last = nftnl_expr_datacxx . . $ `include/expr_ops.h:31:9`!(e);
95 struct nlattrcxx . . $ nlattr# *tb[NFTA_LAST_MAXcxx . . $ `include/linux/netfilter/nf_tables.h:1289:9`! + 1] = {};
96
97 if (mnl_attr_parse_nestedcxx . . $ mnl_attr_parse_nested(f99c0e9fa94f99d9).(attr, nftnl_expr_last_cbcxx . . $ nftnl_expr_last_cb(de2ef18c48fd675c)., tb) < 0)
98 return -1;
99
100 if (tb[NFTA_LAST_MSECScxx . . $ NFTA_LAST_MSECS.]) {
101 last->msecscxx . . $ nftnl_expr_last#msecs. = be64tohcxx . . $ `<external>/15855202785537844739/endian.h:51:11`!(mnl_attr_get_u64(tb[NFTA_LAST_MSECS]));
102 e->flagscxx . . $ nftnl_expr#flags. |= (1 << NFTNL_EXPR_LAST_MSECScxx . . $ NFTNL_EXPR_LAST_MSECS.);
103 }
104 if (tb[NFTA_LAST_SETcxx . . $ NFTA_LAST_SET.]) {
105 last->setcxx . . $ nftnl_expr_last#set. = ntohlcxx . . $ `<external>/9581057695539925927/in.h:428:12`!(mnl_attr_get_u32(tb[NFTA_LAST_SET]));
106 e->flagscxx . . $ nftnl_expr#flags. |= (1 << NFTNL_EXPR_LAST_SETcxx . . $ NFTNL_EXPR_LAST_SET.);
107 }
108
109 return 0;
110 }
111
112 static int nftnl_expr_last_snprintfcxx . . $ nftnl_expr_last_snprintf(2b4af69501aef780).(char *buf, size_t len,
113 uint32_tcxx . . $ uint32_t# flags,
114 const struct nftnl_exprcxx . . $ nftnl_expr# *e)
115 {
116 struct nftnl_expr_lastcxx . . $ nftnl_expr_last# *last = nftnl_expr_datacxx . . $ `include/expr_ops.h:31:9`!(e);
117
118 if (!last->setcxx . . $ nftnl_expr_last#set.)
119 return snprintfcxx . . $ snprintf(ea502d73e74c754c).(buf, len, "never ");
120
121 return snprintfcxx . . $ snprintf(ea502d73e74c754c).(buf, len, "%"PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:110:10`!" ", last->msecscxx . . $ nftnl_expr_last#msecs.);
122 }
123
124 static struct attr_policycxx . . $ attr_policy# last_attr_policycxx . . $ last_attr_policy.[__NFTNL_EXPR_LAST_MAXcxx . . $ __NFTNL_EXPR_LAST_MAX.] = {
125 [NFTNL_EXPR_LAST_MSECScxx . . $ NFTNL_EXPR_LAST_MSECS.] = { .maxlen = sizeof(uint64_tcxx . . $ uint64_t#) },
126 [NFTNL_EXPR_LAST_SETcxx . . $ NFTNL_EXPR_LAST_SET.] = { .maxlen = sizeof(uint32_tcxx . . $ uint32_t#) },
127 };
128
129 struct expr_opscxx . . $ expr_ops# expr_ops_lastcxx . . $ expr_ops_last. = {
130 .name = "last",
131 .alloc_len = sizeof(struct nftnl_expr_lastcxx . . $ nftnl_expr_last#),
132 .nftnl_max_attr = __NFTNL_EXPR_LAST_MAXcxx . . $ __NFTNL_EXPR_LAST_MAX. - 1,
133 .attr_policy = last_attr_policycxx . . $ last_attr_policy.,
134 .set = nftnl_expr_last_setcxx . . $ nftnl_expr_last_set(211371a3e3842127).,
135 .get = nftnl_expr_last_getcxx . . $ nftnl_expr_last_get(9de263c4f9e71c4b).,
136 .parse = nftnl_expr_last_parsecxx . . $ nftnl_expr_last_parse(ed61207049d8af9a).,
137 .build = nftnl_expr_last_buildcxx . . $ nftnl_expr_last_build(93c7528a9cf90b41).,
138 .output = nftnl_expr_last_snprintfcxx . . $ nftnl_expr_last_snprintf(2b4af69501aef780).,
139 };