| 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */cxx . . $ `<file>/src/expr/reject.c`/ |
| 2 | /* |
| 3 | * (C) 2013 by Pablo Neira Ayuso <[email protected]> |
| 4 | * |
| 5 | * This code has been sponsored by Sophos Astaro <http://www.sophos.com> |
| 6 | */ |
| 7 | |
| 8 | #include <stdio.h> |
| 9 | #include <stdint.h> |
| 10 | #include <string.h> |
| 11 | #include <arpa/inet.h> |
| 12 | #include <errno.h> |
| 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/expr.h>cxx . . $ `<file>/include/libnftnl/expr.h`/ |
| 18 | #include <libnftnl/rule.h>cxx . . $ `<file>/include/libnftnl/rule.h`/ |
| 19 | |
| 20 | struct nftnl_expr_rejectcxx . . $ nftnl_expr_reject# { |
| 21 | uint32_tcxx . . $ uint32_t# typecxx . . $ nftnl_expr_reject#type.; |
| 22 | uint8_tcxx . . $ uint8_t# icmp_codecxx . . $ nftnl_expr_reject#icmp_code.; |
| 23 | }; |
| 24 | |
| 25 | static int |
| 26 | nftnl_expr_reject_setcxx . . $ nftnl_expr_reject_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_rejectcxx . . $ nftnl_expr_reject# *reject = nftnl_expr_datacxx . . $ `include/expr_ops.h:31:9`!(e); |
| 30 | |
| 31 | switch(type) { |
| 32 | case NFTNL_EXPR_REJECT_TYPEcxx . . $ NFTNL_EXPR_REJECT_TYPE.: |
| 33 | memcpycxx . . $ memcpy(cc817cb175f282d).(&reject->typecxx . . $ nftnl_expr_reject#type., data, data_len); |
| 34 | break; |
| 35 | case NFTNL_EXPR_REJECT_CODEcxx . . $ NFTNL_EXPR_REJECT_CODE.: |
| 36 | memcpycxx . . $ memcpy(cc817cb175f282d).(&reject->icmp_codecxx . . $ nftnl_expr_reject#icmp_code., data, data_len); |
| 37 | break; |
| 38 | } |
| 39 | return 0; |
| 40 | } |
| 41 | |
| 42 | static const void * |
| 43 | nftnl_expr_reject_getcxx . . $ nftnl_expr_reject_get(9de263c4f9e71c4b).(const struct nftnl_exprcxx . . $ nftnl_expr# *e, uint16_tcxx . . $ uint16_t# type, |
| 44 | uint32_tcxx . . $ uint32_t# *data_len) |
| 45 | { |
| 46 | struct nftnl_expr_rejectcxx . . $ nftnl_expr_reject# *reject = nftnl_expr_datacxx . . $ `include/expr_ops.h:31:9`!(e); |
| 47 | |
| 48 | switch(type) { |
| 49 | case NFTNL_EXPR_REJECT_TYPEcxx . . $ NFTNL_EXPR_REJECT_TYPE.: |
| 50 | *data_len = sizeof(reject->typecxx . . $ nftnl_expr_reject#type.); |
| 51 | return &reject->typecxx . . $ nftnl_expr_reject#type.; |
| 52 | case NFTNL_EXPR_REJECT_CODEcxx . . $ NFTNL_EXPR_REJECT_CODE.: |
| 53 | *data_len = sizeof(reject->icmp_codecxx . . $ nftnl_expr_reject#icmp_code.); |
| 54 | return &reject->icmp_codecxx . . $ nftnl_expr_reject#icmp_code.; |
| 55 | } |
| 56 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 57 | } |
| 58 | |
| 59 | static int nftnl_expr_reject_cbcxx . . $ nftnl_expr_reject_cb(de2ef18c48fd675c).(const struct nlattrcxx . . $ nlattr# *attr, void *data) |
| 60 | { |
| 61 | const struct nlattrcxx . . $ nlattr# **tb = data; |
| 62 | int type = mnl_attr_get_typecxx . . $ mnl_attr_get_type(1da47bcc4c4b975).(attr); |
| 63 | |
| 64 | if (mnl_attr_type_validcxx . . $ mnl_attr_type_valid(47df1cce1c7be855).(attr, NFTA_REJECT_MAXcxx . . $ `include/linux/netfilter/nf_tables.h:1443:9`!) < 0) |
| 65 | return MNL_CB_OKcxx . . $ `<external>/12386019527593959648/libmnl.h:174:9`!; |
| 66 | |
| 67 | switch(type) { |
| 68 | case NFTA_REJECT_TYPEcxx . . $ NFTA_REJECT_TYPE.: |
| 69 | if (mnl_attr_validatecxx . . $ mnl_attr_validate(e419697a5e1ae2b1).(attr, MNL_TYPE_U32cxx . . $ MNL_TYPE_U32.) < 0) |
| 70 | abi_breakagecxx . . $ `include/utils.h:28:9`!(); |
| 71 | break; |
| 72 | case NFTA_REJECT_ICMP_CODEcxx . . $ NFTA_REJECT_ICMP_CODE.: |
| 73 | if (mnl_attr_validatecxx . . $ mnl_attr_validate(e419697a5e1ae2b1).(attr, MNL_TYPE_U8cxx . . $ MNL_TYPE_U8.) < 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_expr_reject_buildcxx . . $ nftnl_expr_reject_build(93c7528a9cf90b41).(struct nlmsghdrcxx . . $ nlmsghdr# *nlh, const struct nftnl_exprcxx . . $ nftnl_expr# *e) |
| 84 | { |
| 85 | struct nftnl_expr_rejectcxx . . $ nftnl_expr_reject# *reject = nftnl_expr_datacxx . . $ `include/expr_ops.h:31:9`!(e); |
| 86 | |
| 87 | if (e->flagscxx . . $ nftnl_expr#flags. & (1 << NFTNL_EXPR_REJECT_TYPEcxx . . $ NFTNL_EXPR_REJECT_TYPE.)) |
| 88 | mnl_attr_put_u32cxx . . $ mnl_attr_put_u32(b46fd0aeb0cfb96d).(nlh, NFTA_REJECT_TYPEcxx . . $ NFTA_REJECT_TYPE., htonlcxx . . $ `<external>/9581057695539925927/in.h:430:12`!(reject->type)); |
| 89 | if (e->flagscxx . . $ nftnl_expr#flags. & (1 << NFTNL_EXPR_REJECT_CODEcxx . . $ NFTNL_EXPR_REJECT_CODE.)) |
| 90 | mnl_attr_put_u8cxx . . $ mnl_attr_put_u8(897b09f57801d77).(nlh, NFTA_REJECT_ICMP_CODEcxx . . $ NFTA_REJECT_ICMP_CODE., reject->icmp_codecxx . . $ nftnl_expr_reject#icmp_code.); |
| 91 | } |
| 92 | |
| 93 | static int |
| 94 | nftnl_expr_reject_parsecxx . . $ nftnl_expr_reject_parse(ed61207049d8af9a).(struct nftnl_exprcxx . . $ nftnl_expr# *e, struct nlattrcxx . . $ nlattr# *attr) |
| 95 | { |
| 96 | struct nftnl_expr_rejectcxx . . $ nftnl_expr_reject# *reject = nftnl_expr_datacxx . . $ `include/expr_ops.h:31:9`!(e); |
| 97 | struct nlattrcxx . . $ nlattr# *tb[NFTA_REJECT_MAXcxx . . $ `include/linux/netfilter/nf_tables.h:1443:9`!+1] = {}; |
| 98 | |
| 99 | if (mnl_attr_parse_nestedcxx . . $ mnl_attr_parse_nested(f99c0e9fa94f99d9).(attr, nftnl_expr_reject_cbcxx . . $ nftnl_expr_reject_cb(de2ef18c48fd675c)., tb) < 0) |
| 100 | return -1; |
| 101 | |
| 102 | if (tb[NFTA_REJECT_TYPEcxx . . $ NFTA_REJECT_TYPE.]) { |
| 103 | reject->typecxx . . $ nftnl_expr_reject#type. = ntohlcxx . . $ `<external>/9581057695539925927/in.h:428:12`!(mnl_attr_get_u32(tb[NFTA_REJECT_TYPE])); |
| 104 | e->flagscxx . . $ nftnl_expr#flags. |= (1 << NFTNL_EXPR_REJECT_TYPEcxx . . $ NFTNL_EXPR_REJECT_TYPE.); |
| 105 | } |
| 106 | if (tb[NFTA_REJECT_ICMP_CODEcxx . . $ NFTA_REJECT_ICMP_CODE.]) { |
| 107 | reject->icmp_codecxx . . $ nftnl_expr_reject#icmp_code. = mnl_attr_get_u8cxx . . $ mnl_attr_get_u8(68d72702597f1127).(tb[NFTA_REJECT_ICMP_CODEcxx . . $ NFTA_REJECT_ICMP_CODE.]); |
| 108 | e->flagscxx . . $ nftnl_expr#flags. |= (1 << NFTNL_EXPR_REJECT_CODEcxx . . $ NFTNL_EXPR_REJECT_CODE.); |
| 109 | } |
| 110 | |
| 111 | return 0; |
| 112 | } |
| 113 | |
| 114 | static int |
| 115 | nftnl_expr_reject_snprintfcxx . . $ nftnl_expr_reject_snprintf(2b4af69501aef780).(char *buf, size_t len, |
| 116 | uint32_tcxx . . $ uint32_t# flags, const struct nftnl_exprcxx . . $ nftnl_expr# *e) |
| 117 | { |
| 118 | struct nftnl_expr_rejectcxx . . $ nftnl_expr_reject# *reject = nftnl_expr_datacxx . . $ `include/expr_ops.h:31:9`!(e); |
| 119 | |
| 120 | return snprintfcxx . . $ snprintf(ea502d73e74c754c).(buf, len, "type %u code %u ", |
| 121 | reject->typecxx . . $ nftnl_expr_reject#type., reject->icmp_codecxx . . $ nftnl_expr_reject#icmp_code.); |
| 122 | } |
| 123 | |
| 124 | static struct attr_policycxx . . $ attr_policy# reject_attr_policycxx . . $ reject_attr_policy.[__NFTNL_EXPR_REJECT_MAXcxx . . $ __NFTNL_EXPR_REJECT_MAX.] = { |
| 125 | [NFTNL_EXPR_REJECT_TYPEcxx . . $ NFTNL_EXPR_REJECT_TYPE.] = { .maxlen = sizeof(uint32_tcxx . . $ uint32_t#) }, |
| 126 | [NFTNL_EXPR_REJECT_CODEcxx . . $ NFTNL_EXPR_REJECT_CODE.] = { .maxlen = sizeof(uint8_tcxx . . $ uint8_t#) }, |
| 127 | }; |
| 128 | |
| 129 | struct expr_opscxx . . $ expr_ops# expr_ops_rejectcxx . . $ expr_ops_reject. = { |
| 130 | .name = "reject", |
| 131 | .alloc_len = sizeof(struct nftnl_expr_rejectcxx . . $ nftnl_expr_reject#), |
| 132 | .nftnl_max_attr = __NFTNL_EXPR_REJECT_MAXcxx . . $ __NFTNL_EXPR_REJECT_MAX. - 1, |
| 133 | .attr_policy = reject_attr_policycxx . . $ reject_attr_policy., |
| 134 | .set = nftnl_expr_reject_setcxx . . $ nftnl_expr_reject_set(211371a3e3842127)., |
| 135 | .get = nftnl_expr_reject_getcxx . . $ nftnl_expr_reject_get(9de263c4f9e71c4b)., |
| 136 | .parse = nftnl_expr_reject_parsecxx . . $ nftnl_expr_reject_parse(ed61207049d8af9a)., |
| 137 | .build = nftnl_expr_reject_buildcxx . . $ nftnl_expr_reject_build(93c7528a9cf90b41)., |
| 138 | .output = nftnl_expr_reject_snprintfcxx . . $ nftnl_expr_reject_snprintf(2b4af69501aef780)., |
| 139 | }; |