| 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */cxx . . $ `<file>/src/expr/masq.c`/ |
| 2 | /* |
| 3 | * (C) 2014 by Arturo Borrero Gonzalez <[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_masqcxx . . $ nftnl_expr_masq# { |
| 20 | uint32_tcxx . . $ uint32_t# flagscxx . . $ nftnl_expr_masq#flags.; |
| 21 | enum nft_registerscxx . . $ nft_registers# sreg_proto_mincxx . . $ nftnl_expr_masq#sreg_proto_min.; |
| 22 | enum nft_registerscxx . . $ nft_registers# sreg_proto_maxcxx . . $ nftnl_expr_masq#sreg_proto_max.; |
| 23 | }; |
| 24 | |
| 25 | static int |
| 26 | nftnl_expr_masq_setcxx . . $ nftnl_expr_masq_set(211371a3e3842127).(struct nftnl_exprcxx . . $ nftnl_expr# *e, uint16_tcxx . . $ uint16_t# type, |
| 27 | const void *data, uint32_tcxx . . $ uint32_t# data_len, uint32_tcxx . . $ uint32_t# byteorder) |
| 28 | { |
| 29 | struct nftnl_expr_masqcxx . . $ nftnl_expr_masq# *masq = nftnl_expr_datacxx . . $ `include/expr_ops.h:31:9`!(e); |
| 30 | |
| 31 | switch (type) { |
| 32 | case NFTNL_EXPR_MASQ_FLAGScxx . . $ NFTNL_EXPR_MASQ_FLAGS.: |
| 33 | memcpycxx . . $ memcpy(cc817cb175f282d).(&masq->flagscxx . . $ nftnl_expr_masq#flags., data, data_len); |
| 34 | break; |
| 35 | case NFTNL_EXPR_MASQ_REG_PROTO_MINcxx . . $ NFTNL_EXPR_MASQ_REG_PROTO_MIN.: |
| 36 | memcpycxx . . $ memcpy(cc817cb175f282d).(&masq->sreg_proto_mincxx . . $ nftnl_expr_masq#sreg_proto_min., data, data_len); |
| 37 | break; |
| 38 | case NFTNL_EXPR_MASQ_REG_PROTO_MAXcxx . . $ NFTNL_EXPR_MASQ_REG_PROTO_MAX.: |
| 39 | memcpycxx . . $ memcpy(cc817cb175f282d).(&masq->sreg_proto_maxcxx . . $ nftnl_expr_masq#sreg_proto_max., data, data_len); |
| 40 | break; |
| 41 | } |
| 42 | return 0; |
| 43 | } |
| 44 | |
| 45 | static const void * |
| 46 | nftnl_expr_masq_getcxx . . $ nftnl_expr_masq_get(9de263c4f9e71c4b).(const struct nftnl_exprcxx . . $ nftnl_expr# *e, uint16_tcxx . . $ uint16_t# type, |
| 47 | uint32_tcxx . . $ uint32_t# *data_len) |
| 48 | { |
| 49 | struct nftnl_expr_masqcxx . . $ nftnl_expr_masq# *masq = nftnl_expr_datacxx . . $ `include/expr_ops.h:31:9`!(e); |
| 50 | |
| 51 | switch (type) { |
| 52 | case NFTNL_EXPR_MASQ_FLAGScxx . . $ NFTNL_EXPR_MASQ_FLAGS.: |
| 53 | *data_len = sizeof(masq->flagscxx . . $ nftnl_expr_masq#flags.); |
| 54 | return &masq->flagscxx . . $ nftnl_expr_masq#flags.; |
| 55 | case NFTNL_EXPR_MASQ_REG_PROTO_MINcxx . . $ NFTNL_EXPR_MASQ_REG_PROTO_MIN.: |
| 56 | *data_len = sizeof(masq->sreg_proto_mincxx . . $ nftnl_expr_masq#sreg_proto_min.); |
| 57 | return &masq->sreg_proto_mincxx . . $ nftnl_expr_masq#sreg_proto_min.; |
| 58 | case NFTNL_EXPR_MASQ_REG_PROTO_MAXcxx . . $ NFTNL_EXPR_MASQ_REG_PROTO_MAX.: |
| 59 | *data_len = sizeof(masq->sreg_proto_maxcxx . . $ nftnl_expr_masq#sreg_proto_max.); |
| 60 | return &masq->sreg_proto_maxcxx . . $ nftnl_expr_masq#sreg_proto_max.; |
| 61 | } |
| 62 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 63 | } |
| 64 | |
| 65 | static int nftnl_expr_masq_cbcxx . . $ nftnl_expr_masq_cb(de2ef18c48fd675c).(const struct nlattrcxx . . $ nlattr# *attr, void *data) |
| 66 | { |
| 67 | const struct nlattrcxx . . $ nlattr# **tb = data; |
| 68 | int type = mnl_attr_get_typecxx . . $ mnl_attr_get_type(1da47bcc4c4b975).(attr); |
| 69 | |
| 70 | if (mnl_attr_type_validcxx . . $ mnl_attr_type_valid(47df1cce1c7be855).(attr, NFTA_MASQ_MAXcxx . . $ `include/linux/netfilter/nf_tables.h:1510:9`!) < 0) |
| 71 | return MNL_CB_OKcxx . . $ `<external>/12386019527593959648/libmnl.h:174:9`!; |
| 72 | |
| 73 | switch (type) { |
| 74 | case NFTA_MASQ_REG_PROTO_MINcxx . . $ NFTA_MASQ_REG_PROTO_MIN.: |
| 75 | case NFTA_MASQ_REG_PROTO_MAXcxx . . $ NFTA_MASQ_REG_PROTO_MAX.: |
| 76 | case NFTA_MASQ_FLAGScxx . . $ NFTA_MASQ_FLAGS.: |
| 77 | if (mnl_attr_validatecxx . . $ mnl_attr_validate(e419697a5e1ae2b1).(attr, MNL_TYPE_U32cxx . . $ MNL_TYPE_U32.) < 0) |
| 78 | abi_breakagecxx . . $ `include/utils.h:28:9`!(); |
| 79 | break; |
| 80 | } |
| 81 | |
| 82 | tb[type] = attr; |
| 83 | return MNL_CB_OKcxx . . $ `<external>/12386019527593959648/libmnl.h:174:9`!; |
| 84 | } |
| 85 | |
| 86 | static void |
| 87 | nftnl_expr_masq_buildcxx . . $ nftnl_expr_masq_build(93c7528a9cf90b41).(struct nlmsghdrcxx . . $ nlmsghdr# *nlh, const struct nftnl_exprcxx . . $ nftnl_expr# *e) |
| 88 | { |
| 89 | struct nftnl_expr_masqcxx . . $ nftnl_expr_masq# *masq = nftnl_expr_datacxx . . $ `include/expr_ops.h:31:9`!(e); |
| 90 | |
| 91 | if (e->flagscxx . . $ nftnl_expr#flags. & (1 << NFTNL_EXPR_MASQ_FLAGScxx . . $ NFTNL_EXPR_MASQ_FLAGS.)) |
| 92 | mnl_attr_put_u32cxx . . $ mnl_attr_put_u32(b46fd0aeb0cfb96d).(nlh, NFTA_MASQ_FLAGScxx . . $ NFTA_MASQ_FLAGS., htobe32cxx . . $ `<external>/15855202785537844739/endian.h:44:11`!(masq->flags)); |
| 93 | if (e->flagscxx . . $ nftnl_expr#flags. & (1 << NFTNL_EXPR_MASQ_REG_PROTO_MINcxx . . $ NFTNL_EXPR_MASQ_REG_PROTO_MIN.)) |
| 94 | mnl_attr_put_u32cxx . . $ mnl_attr_put_u32(b46fd0aeb0cfb96d).(nlh, NFTA_MASQ_REG_PROTO_MINcxx . . $ NFTA_MASQ_REG_PROTO_MIN., |
| 95 | htobe32cxx . . $ `<external>/15855202785537844739/endian.h:44:11`!(masq->sreg_proto_min)); |
| 96 | if (e->flagscxx . . $ nftnl_expr#flags. & (1 << NFTNL_EXPR_MASQ_REG_PROTO_MAXcxx . . $ NFTNL_EXPR_MASQ_REG_PROTO_MAX.)) |
| 97 | mnl_attr_put_u32cxx . . $ mnl_attr_put_u32(b46fd0aeb0cfb96d).(nlh, NFTA_MASQ_REG_PROTO_MAXcxx . . $ NFTA_MASQ_REG_PROTO_MAX., |
| 98 | htobe32cxx . . $ `<external>/15855202785537844739/endian.h:44:11`!(masq->sreg_proto_max)); |
| 99 | } |
| 100 | |
| 101 | static int |
| 102 | nftnl_expr_masq_parsecxx . . $ nftnl_expr_masq_parse(ed61207049d8af9a).(struct nftnl_exprcxx . . $ nftnl_expr# *e, struct nlattrcxx . . $ nlattr# *attr) |
| 103 | { |
| 104 | struct nftnl_expr_masqcxx . . $ nftnl_expr_masq# *masq = nftnl_expr_datacxx . . $ `include/expr_ops.h:31:9`!(e); |
| 105 | struct nlattrcxx . . $ nlattr# *tb[NFTA_MASQ_MAXcxx . . $ `include/linux/netfilter/nf_tables.h:1510:9`!+1] = {}; |
| 106 | |
| 107 | if (mnl_attr_parse_nestedcxx . . $ mnl_attr_parse_nested(f99c0e9fa94f99d9).(attr, nftnl_expr_masq_cbcxx . . $ nftnl_expr_masq_cb(de2ef18c48fd675c)., tb) < 0) |
| 108 | return -1; |
| 109 | |
| 110 | if (tb[NFTA_MASQ_FLAGScxx . . $ NFTA_MASQ_FLAGS.]) { |
| 111 | masq->flagscxx . . $ nftnl_expr_masq#flags. = be32tohcxx . . $ `<external>/15855202785537844739/endian.h:46:11`!(mnl_attr_get_u32(tb[NFTA_MASQ_FLAGS])); |
| 112 | e->flagscxx . . $ nftnl_expr#flags. |= (1 << NFTNL_EXPR_MASQ_FLAGScxx . . $ NFTNL_EXPR_MASQ_FLAGS.); |
| 113 | } |
| 114 | if (tb[NFTA_MASQ_REG_PROTO_MINcxx . . $ NFTA_MASQ_REG_PROTO_MIN.]) { |
| 115 | masq->sreg_proto_mincxx . . $ nftnl_expr_masq#sreg_proto_min. = |
| 116 | be32tohcxx . . $ `<external>/15855202785537844739/endian.h:46:11`!(mnl_attr_get_u32(tb[NFTA_MASQ_REG_PROTO_MIN])); |
| 117 | e->flagscxx . . $ nftnl_expr#flags. |= (1 << NFTNL_EXPR_MASQ_REG_PROTO_MINcxx . . $ NFTNL_EXPR_MASQ_REG_PROTO_MIN.); |
| 118 | } |
| 119 | if (tb[NFTA_MASQ_REG_PROTO_MAXcxx . . $ NFTA_MASQ_REG_PROTO_MAX.]) { |
| 120 | masq->sreg_proto_maxcxx . . $ nftnl_expr_masq#sreg_proto_max. = |
| 121 | be32tohcxx . . $ `<external>/15855202785537844739/endian.h:46:11`!(mnl_attr_get_u32(tb[NFTA_MASQ_REG_PROTO_MAX])); |
| 122 | e->flagscxx . . $ nftnl_expr#flags. |= (1 << NFTNL_EXPR_MASQ_REG_PROTO_MAXcxx . . $ NFTNL_EXPR_MASQ_REG_PROTO_MAX.); |
| 123 | } |
| 124 | |
| 125 | return 0; |
| 126 | } |
| 127 | |
| 128 | static int nftnl_expr_masq_snprintfcxx . . $ nftnl_expr_masq_snprintf(2b4af69501aef780).(char *buf, size_t remain, |
| 129 | uint32_tcxx . . $ uint32_t# flags, const struct nftnl_exprcxx . . $ nftnl_expr# *e) |
| 130 | { |
| 131 | struct nftnl_expr_masqcxx . . $ nftnl_expr_masq# *masq = nftnl_expr_datacxx . . $ `include/expr_ops.h:31:9`!(e); |
| 132 | int offset = 0, ret = 0; |
| 133 | |
| 134 | if (e->flagscxx . . $ nftnl_expr#flags. & (1 << NFTNL_EXPR_MASQ_REG_PROTO_MINcxx . . $ NFTNL_EXPR_MASQ_REG_PROTO_MIN.)) { |
| 135 | ret = snprintfcxx . . $ snprintf(ea502d73e74c754c).(buf + offset, remain, "proto_min reg %u ", |
| 136 | masq->sreg_proto_mincxx . . $ nftnl_expr_masq#sreg_proto_min.); |
| 137 | SNPRINTF_BUFFER_SIZEcxx . . $ `include/utils.h:55:9`!(ret, remain, offset); |
| 138 | } |
| 139 | if (e->flagscxx . . $ nftnl_expr#flags. & (1 << NFTNL_EXPR_MASQ_REG_PROTO_MAXcxx . . $ NFTNL_EXPR_MASQ_REG_PROTO_MAX.)) { |
| 140 | ret = snprintfcxx . . $ snprintf(ea502d73e74c754c).(buf + offset, remain, "proto_max reg %u ", |
| 141 | masq->sreg_proto_maxcxx . . $ nftnl_expr_masq#sreg_proto_max.); |
| 142 | SNPRINTF_BUFFER_SIZEcxx . . $ `include/utils.h:55:9`!(ret, remain, offset); |
| 143 | } |
| 144 | if (e->flagscxx . . $ nftnl_expr#flags. & (1 << NFTNL_EXPR_MASQ_FLAGScxx . . $ NFTNL_EXPR_MASQ_FLAGS.)) { |
| 145 | ret = snprintfcxx . . $ snprintf(ea502d73e74c754c).(buf + offset, remain, "flags 0x%x ", masq->flagscxx . . $ nftnl_expr_masq#flags.); |
| 146 | SNPRINTF_BUFFER_SIZEcxx . . $ `include/utils.h:55:9`!(ret, remain, offset); |
| 147 | } |
| 148 | |
| 149 | return offset; |
| 150 | } |
| 151 | |
| 152 | static struct attr_policycxx . . $ attr_policy# masq_attr_policycxx . . $ masq_attr_policy.[__NFTNL_EXPR_MASQ_MAXcxx . . $ __NFTNL_EXPR_MASQ_MAX.] = { |
| 153 | [NFTNL_EXPR_MASQ_FLAGScxx . . $ NFTNL_EXPR_MASQ_FLAGS.] = { .maxlen = sizeof(uint32_tcxx . . $ uint32_t#) }, |
| 154 | [NFTNL_EXPR_MASQ_REG_PROTO_MINcxx . . $ NFTNL_EXPR_MASQ_REG_PROTO_MIN.] = { .maxlen = sizeof(uint32_tcxx . . $ uint32_t#) }, |
| 155 | [NFTNL_EXPR_MASQ_REG_PROTO_MAXcxx . . $ NFTNL_EXPR_MASQ_REG_PROTO_MAX.] = { .maxlen = sizeof(uint32_tcxx . . $ uint32_t#) }, |
| 156 | }; |
| 157 | |
| 158 | struct expr_opscxx . . $ expr_ops# expr_ops_masqcxx . . $ expr_ops_masq. = { |
| 159 | .name = "masq", |
| 160 | .alloc_len = sizeof(struct nftnl_expr_masqcxx . . $ nftnl_expr_masq#), |
| 161 | .nftnl_max_attr = __NFTNL_EXPR_MASQ_MAXcxx . . $ __NFTNL_EXPR_MASQ_MAX. - 1, |
| 162 | .attr_policy = masq_attr_policycxx . . $ masq_attr_policy., |
| 163 | .set = nftnl_expr_masq_setcxx . . $ nftnl_expr_masq_set(211371a3e3842127)., |
| 164 | .get = nftnl_expr_masq_getcxx . . $ nftnl_expr_masq_get(9de263c4f9e71c4b)., |
| 165 | .parse = nftnl_expr_masq_parsecxx . . $ nftnl_expr_masq_parse(ed61207049d8af9a)., |
| 166 | .build = nftnl_expr_masq_buildcxx . . $ nftnl_expr_masq_build(93c7528a9cf90b41)., |
| 167 | .output = nftnl_expr_masq_snprintfcxx . . $ nftnl_expr_masq_snprintf(2b4af69501aef780)., |
| 168 | }; |