Debian Codegraph @

src/obj/ct_helper.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-or-later */cxx . . $ `<file>/src/obj/ct_helper.c`/
2 /*
3 * (C) 2017 Red Hat GmbH
4 * Author: Florian Westphal <[email protected]>
5 */
6
7 #include <stdio.h>
8 #include <stdint.h>
9 #include <arpa/inet.h>
10 #include <errno.h>
11 #include <inttypes.h>
12
13 #include <linux/netfilter/nf_tables.h>cxx . . $ `<file>/include/linux/netfilter/nf_tables.h`/
14
15 #include "internal.h"cxx . . $ `<file>/include/internal.h`/
16 #include <libmnl/libmnl.h>
17 #include <libnftnl/object.h>cxx . . $ `<file>/include/libnftnl/object.h`/
18
19 #include "obj.h"cxx . . $ `<file>/include/obj.h`/
20
21 static int nftnl_obj_ct_helper_setcxx . . $ nftnl_obj_ct_helper_set(96c901c785434bf1).(struct nftnl_objcxx . . $ nftnl_obj# *e, uint16_tcxx . . $ uint16_t# type,
22 const void *data, uint32_tcxx . . $ uint32_t# data_len)
23 {
24 struct nftnl_obj_ct_helpercxx . . $ nftnl_obj_ct_helper# *helper = nftnl_obj_datacxx . . $ `include/obj.h:117:9`!(e);
25
26 switch (type) {
27 case NFTNL_OBJ_CT_HELPER_NAMEcxx . . $ NFTNL_OBJ_CT_HELPER_NAME.:
28 snprintfcxx . . $ snprintf(ea502d73e74c754c).(helper->namecxx . . $ nftnl_obj_ct_helper#name., sizeof(helper->namecxx . . $ nftnl_obj_ct_helper#name.), "%s", (const char *)data);
29 break;
30 case NFTNL_OBJ_CT_HELPER_L3PROTOcxx . . $ NFTNL_OBJ_CT_HELPER_L3PROTO.:
31 memcpycxx . . $ memcpy(cc817cb175f282d).(&helper->l3protocxx . . $ nftnl_obj_ct_helper#l3proto., data, data_len);
32 break;
33 case NFTNL_OBJ_CT_HELPER_L4PROTOcxx . . $ NFTNL_OBJ_CT_HELPER_L4PROTO.:
34 memcpycxx . . $ memcpy(cc817cb175f282d).(&helper->l4protocxx . . $ nftnl_obj_ct_helper#l4proto., data, data_len);
35 break;
36 }
37 return 0;
38 }
39
40 static const void *nftnl_obj_ct_helper_getcxx . . $ nftnl_obj_ct_helper_get(d22e54b888e7c4b).(const struct nftnl_objcxx . . $ nftnl_obj# *e,
41 uint16_tcxx . . $ uint16_t# type, uint32_tcxx . . $ uint32_t# *data_len)
42 {
43 struct nftnl_obj_ct_helpercxx . . $ nftnl_obj_ct_helper# *helper = nftnl_obj_datacxx . . $ `include/obj.h:117:9`!(e);
44
45 switch (type) {
46 case NFTNL_OBJ_CT_HELPER_NAMEcxx . . $ NFTNL_OBJ_CT_HELPER_NAME.:
47 *data_len = strlencxx . . $ strlen(751346f8406fd082).(helper->namecxx . . $ nftnl_obj_ct_helper#name.);
48 return helper->namecxx . . $ nftnl_obj_ct_helper#name.;
49 case NFTNL_OBJ_CT_HELPER_L3PROTOcxx . . $ NFTNL_OBJ_CT_HELPER_L3PROTO.:
50 *data_len = sizeof(helper->l3protocxx . . $ nftnl_obj_ct_helper#l3proto.);
51 return &helper->l3protocxx . . $ nftnl_obj_ct_helper#l3proto.;
52 case NFTNL_OBJ_CT_HELPER_L4PROTOcxx . . $ NFTNL_OBJ_CT_HELPER_L4PROTO.:
53 *data_len = sizeof(helper->l4protocxx . . $ nftnl_obj_ct_helper#l4proto.);
54 return &helper->l4protocxx . . $ nftnl_obj_ct_helper#l4proto.;
55 }
56 return NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!;
57 }
58
59 static int nftnl_obj_ct_helper_cbcxx . . $ nftnl_obj_ct_helper_cb(de2ef18c48fd675c).(const struct nlattrcxx . . $ nlattr# *attr, void *data)
60 {
61 const struct nftnl_obj_ct_helpercxx . . $ nftnl_obj_ct_helper# *helper = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!;
62 int type = mnl_attr_get_typecxx . . $ mnl_attr_get_type(1da47bcc4c4b975).(attr);
63 const struct nlattrcxx . . $ nlattr# **tb = data;
64
65 if (mnl_attr_type_validcxx . . $ mnl_attr_type_valid(47df1cce1c7be855).(attr, NFTA_CT_HELPER_MAXcxx . . $ `include/linux/netfilter/nf_tables.h:1636:9`!) < 0)
66 return MNL_CB_OKcxx . . $ `<external>/12386019527593959648/libmnl.h:174:9`!;
67
68 switch (type) {
69 case NFTA_CT_HELPER_NAMEcxx . . $ NFTA_CT_HELPER_NAME.:
70 if (mnl_attr_validatecxx . . $ mnl_attr_validate(e419697a5e1ae2b1).(attr, MNL_TYPE_STRINGcxx . . $ MNL_TYPE_STRING.) < 0)
71 abi_breakagecxx . . $ `include/utils.h:28:9`!();
72 if (mnl_attr_get_payload_lencxx . . $ mnl_attr_get_payload_len(1da47bcc4c4b975).(attr) >= sizeof(helper->namecxx . . $ nftnl_obj_ct_helper#name.))
73 abi_breakagecxx . . $ `include/utils.h:28:9`!();
74 break;
75 case NFTA_CT_HELPER_L3PROTOcxx . . $ NFTA_CT_HELPER_L3PROTO.:
76 if (mnl_attr_validatecxx . . $ mnl_attr_validate(e419697a5e1ae2b1).(attr, MNL_TYPE_U16cxx . . $ MNL_TYPE_U16.) < 0)
77 abi_breakagecxx . . $ `include/utils.h:28:9`!();
78 break;
79 case NFTA_CT_HELPER_L4PROTOcxx . . $ NFTA_CT_HELPER_L4PROTO.:
80 if (mnl_attr_validatecxx . . $ mnl_attr_validate(e419697a5e1ae2b1).(attr, MNL_TYPE_U8cxx . . $ MNL_TYPE_U8.) < 0)
81 abi_breakagecxx . . $ `include/utils.h:28:9`!();
82 break;
83 }
84
85 tb[type] = attr;
86 return MNL_CB_OKcxx . . $ `<external>/12386019527593959648/libmnl.h:174:9`!;
87 }
88
89 static void
90 nftnl_obj_ct_helper_buildcxx . . $ nftnl_obj_ct_helper_build(3650aba98805b449).(struct nlmsghdrcxx . . $ nlmsghdr# *nlh, const struct nftnl_objcxx . . $ nftnl_obj# *e)
91 {
92 struct nftnl_obj_ct_helpercxx . . $ nftnl_obj_ct_helper# *helper = nftnl_obj_datacxx . . $ `include/obj.h:117:9`!(e);
93
94 if (e->flagscxx . . $ nftnl_obj#flags. & (1 << NFTNL_OBJ_CT_HELPER_NAMEcxx . . $ NFTNL_OBJ_CT_HELPER_NAME.))
95 mnl_attr_put_strcxx . . $ mnl_attr_put_str(eb76286d4bfc1a8d).(nlh, NFTA_CT_HELPER_NAMEcxx . . $ NFTA_CT_HELPER_NAME., helper->namecxx . . $ nftnl_obj_ct_helper#name.);
96 if (e->flagscxx . . $ nftnl_obj#flags. & (1 << NFTNL_OBJ_CT_HELPER_L3PROTOcxx . . $ NFTNL_OBJ_CT_HELPER_L3PROTO.))
97 mnl_attr_put_u16cxx . . $ mnl_attr_put_u16(951fb5ebe92f4b45).(nlh, NFTA_CT_HELPER_L3PROTOcxx . . $ NFTA_CT_HELPER_L3PROTO., htonscxx . . $ `<external>/9581057695539925927/in.h:431:12`!(helper->l3proto));
98 if (e->flagscxx . . $ nftnl_obj#flags. & (1 << NFTNL_OBJ_CT_HELPER_L4PROTOcxx . . $ NFTNL_OBJ_CT_HELPER_L4PROTO.))
99 mnl_attr_put_u8cxx . . $ mnl_attr_put_u8(897b09f57801d77).(nlh, NFTA_CT_HELPER_L4PROTOcxx . . $ NFTA_CT_HELPER_L4PROTO., helper->l4protocxx . . $ nftnl_obj_ct_helper#l4proto.);
100 }
101
102 static int
103 nftnl_obj_ct_helper_parsecxx . . $ nftnl_obj_ct_helper_parse(f22ac2b7a2342b3a).(struct nftnl_objcxx . . $ nftnl_obj# *e, struct nlattrcxx . . $ nlattr# *attr)
104 {
105 struct nftnl_obj_ct_helpercxx . . $ nftnl_obj_ct_helper# *helper = nftnl_obj_datacxx . . $ `include/obj.h:117:9`!(e);
106 struct nlattrcxx . . $ nlattr# *tb[NFTA_CT_HELPER_MAXcxx . . $ `include/linux/netfilter/nf_tables.h:1636:9`! + 1] = {};
107
108 if (mnl_attr_parse_nestedcxx . . $ mnl_attr_parse_nested(f99c0e9fa94f99d9).(attr, nftnl_obj_ct_helper_cbcxx . . $ nftnl_obj_ct_helper_cb(de2ef18c48fd675c)., tb) < 0)
109 return -1;
110
111 if (tb[NFTA_CT_HELPER_NAMEcxx . . $ NFTA_CT_HELPER_NAME.]) {
112 snprintfcxx . . $ snprintf(ea502d73e74c754c).(helper->namecxx . . $ nftnl_obj_ct_helper#name., sizeof(helper->namecxx . . $ nftnl_obj_ct_helper#name.), "%s",
113 mnl_attr_get_strcxx . . $ mnl_attr_get_str(c24cebeef6d84d59).(tb[NFTA_CT_HELPER_NAMEcxx . . $ NFTA_CT_HELPER_NAME.]));
114 e->flagscxx . . $ nftnl_obj#flags. |= (1 << NFTNL_OBJ_CT_HELPER_NAMEcxx . . $ NFTNL_OBJ_CT_HELPER_NAME.);
115 }
116 if (tb[NFTA_CT_HELPER_L3PROTOcxx . . $ NFTA_CT_HELPER_L3PROTO.]) {
117 helper->l3protocxx . . $ nftnl_obj_ct_helper#l3proto. = ntohscxx . . $ `<external>/9581057695539925927/in.h:429:12`!(mnl_attr_get_u16(tb[NFTA_CT_HELPER_L3PROTO]));
118 e->flagscxx . . $ nftnl_obj#flags. |= (1 << NFTNL_OBJ_CT_HELPER_L3PROTOcxx . . $ NFTNL_OBJ_CT_HELPER_L3PROTO.);
119 }
120 if (tb[NFTA_CT_HELPER_L4PROTOcxx . . $ NFTA_CT_HELPER_L4PROTO.]) {
121 helper->l4protocxx . . $ nftnl_obj_ct_helper#l4proto. = mnl_attr_get_u8cxx . . $ mnl_attr_get_u8(68d72702597f1127).(tb[NFTA_CT_HELPER_L4PROTOcxx . . $ NFTA_CT_HELPER_L4PROTO.]);
122 e->flagscxx . . $ nftnl_obj#flags. |= (1 << NFTNL_OBJ_CT_HELPER_L4PROTOcxx . . $ NFTNL_OBJ_CT_HELPER_L4PROTO.);
123 }
124
125 return 0;
126 }
127
128 static int nftnl_obj_ct_helper_snprintfcxx . . $ nftnl_obj_ct_helper_snprintf(58da6fcd2536b16e).(char *buf, size_t len,
129 uint32_tcxx . . $ uint32_t# flags,
130 const struct nftnl_objcxx . . $ nftnl_obj# *e)
131 {
132 struct nftnl_obj_ct_helpercxx . . $ nftnl_obj_ct_helper# *helper = nftnl_obj_datacxx . . $ `include/obj.h:117:9`!(e);
133
134 return snprintfcxx . . $ snprintf(ea502d73e74c754c).(buf, len, "name %s family %d protocol %d ",
135 helper->namecxx . . $ nftnl_obj_ct_helper#name., helper->l3protocxx . . $ nftnl_obj_ct_helper#l3proto., helper->l4protocxx . . $ nftnl_obj_ct_helper#l4proto.);
136 }
137
138 /* from kernel's include/net/netfilter/nf_conntrack_helper.h */
139 #define NF_CT_HELPER_NAME_LENcxx . . $ `src/obj/ct_helper.c:139:9`! 16
140
141 static struct attr_policycxx . . $ attr_policy#
142 obj_ct_helper_attr_policycxx . . $ obj_ct_helper_attr_policy.[__NFTNL_OBJ_CT_HELPER_MAXcxx . . $ __NFTNL_OBJ_CT_HELPER_MAX.] = {
143 [NFTNL_OBJ_CT_HELPER_NAMEcxx . . $ NFTNL_OBJ_CT_HELPER_NAME.] = { .maxlen = NF_CT_HELPER_NAME_LENcxx . . $ `src/obj/ct_helper.c:139:9`! },
144 [NFTNL_OBJ_CT_HELPER_L3PROTOcxx . . $ NFTNL_OBJ_CT_HELPER_L3PROTO.] = { .maxlen = sizeof(uint16_tcxx . . $ uint16_t#) },
145 [NFTNL_OBJ_CT_HELPER_L4PROTOcxx . . $ NFTNL_OBJ_CT_HELPER_L4PROTO.] = { .maxlen = sizeof(uint8_tcxx . . $ uint8_t#) },
146 };
147
148 struct obj_opscxx . . $ obj_ops# obj_ops_ct_helpercxx . . $ obj_ops_ct_helper. = {
149 .name = "ct_helper",
150 .type = NFT_OBJECT_CT_HELPERcxx . . $ `include/linux/netfilter/nf_tables.h:1661:9`!,
151 .alloc_len = sizeof(struct nftnl_obj_ct_helpercxx . . $ nftnl_obj_ct_helper#),
152 .nftnl_max_attr = __NFTNL_OBJ_CT_HELPER_MAXcxx . . $ __NFTNL_OBJ_CT_HELPER_MAX. - 1,
153 .attr_policy = obj_ct_helper_attr_policycxx . . $ obj_ct_helper_attr_policy.,
154 .set = nftnl_obj_ct_helper_setcxx . . $ nftnl_obj_ct_helper_set(96c901c785434bf1).,
155 .get = nftnl_obj_ct_helper_getcxx . . $ nftnl_obj_ct_helper_get(d22e54b888e7c4b).,
156 .parse = nftnl_obj_ct_helper_parsecxx . . $ nftnl_obj_ct_helper_parse(f22ac2b7a2342b3a).,
157 .build = nftnl_obj_ct_helper_buildcxx . . $ nftnl_obj_ct_helper_build(3650aba98805b449).,
158 .output = nftnl_obj_ct_helper_snprintfcxx . . $ nftnl_obj_ct_helper_snprintf(58da6fcd2536b16e).,
159 };