| 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */cxx . . $ `<file>/src/obj/secmark.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_secmark_setcxx . . $ nftnl_obj_secmark_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_secmarkcxx . . $ nftnl_obj_secmark# *secmark = nftnl_obj_datacxx . . $ `include/obj.h:117:9`!(e); |
| 24 | |
| 25 | switch (type) { |
| 26 | case NFTNL_OBJ_SECMARK_CTXcxx . . $ NFTNL_OBJ_SECMARK_CTX.: |
| 27 | snprintfcxx . . $ snprintf(ea502d73e74c754c).(secmark->ctxcxx . . $ nftnl_obj_secmark#ctx., sizeof(secmark->ctxcxx . . $ nftnl_obj_secmark#ctx.), "%s", (const char *)data); |
| 28 | break; |
| 29 | } |
| 30 | return 0; |
| 31 | } |
| 32 | |
| 33 | static const void *nftnl_obj_secmark_getcxx . . $ nftnl_obj_secmark_get(d22e54b888e7c4b).(const struct nftnl_objcxx . . $ nftnl_obj# *e, |
| 34 | uint16_tcxx . . $ uint16_t# type, uint32_tcxx . . $ uint32_t# *data_len) |
| 35 | { |
| 36 | struct nftnl_obj_secmarkcxx . . $ nftnl_obj_secmark# *secmark = nftnl_obj_datacxx . . $ `include/obj.h:117:9`!(e); |
| 37 | |
| 38 | switch (type) { |
| 39 | case NFTNL_OBJ_SECMARK_CTXcxx . . $ NFTNL_OBJ_SECMARK_CTX.: |
| 40 | *data_len = strlencxx . . $ strlen(751346f8406fd082).(secmark->ctxcxx . . $ nftnl_obj_secmark#ctx.); |
| 41 | return secmark->ctxcxx . . $ nftnl_obj_secmark#ctx.; |
| 42 | } |
| 43 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 44 | } |
| 45 | |
| 46 | static int nftnl_obj_secmark_cbcxx . . $ nftnl_obj_secmark_cb(de2ef18c48fd675c).(const struct nlattrcxx . . $ nlattr# *attr, void *data) |
| 47 | { |
| 48 | const struct nftnl_obj_secmarkcxx . . $ nftnl_obj_secmark# *secmark = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 49 | int type = mnl_attr_get_typecxx . . $ mnl_attr_get_type(1da47bcc4c4b975).(attr); |
| 50 | const struct nlattrcxx . . $ nlattr# **tb = data; |
| 51 | |
| 52 | if (mnl_attr_type_validcxx . . $ mnl_attr_type_valid(47df1cce1c7be855).(attr, NFTA_SECMARK_MAXcxx . . $ `include/linux/netfilter/nf_tables.h:1394:9`!) < 0) |
| 53 | return MNL_CB_OKcxx . . $ `<external>/12386019527593959648/libmnl.h:174:9`!; |
| 54 | |
| 55 | switch(type) { |
| 56 | case NFTA_SECMARK_CTXcxx . . $ NFTA_SECMARK_CTX.: |
| 57 | if (mnl_attr_validatecxx . . $ mnl_attr_validate(e419697a5e1ae2b1).(attr, MNL_TYPE_STRINGcxx . . $ MNL_TYPE_STRING.) < 0) |
| 58 | abi_breakagecxx . . $ `include/utils.h:28:9`!(); |
| 59 | if (mnl_attr_get_payload_lencxx . . $ mnl_attr_get_payload_len(1da47bcc4c4b975).(attr) >= sizeof(secmark->ctxcxx . . $ nftnl_obj_secmark#ctx.)) |
| 60 | abi_breakagecxx . . $ `include/utils.h:28:9`!(); |
| 61 | break; |
| 62 | } |
| 63 | |
| 64 | tb[type] = attr; |
| 65 | return MNL_CB_OKcxx . . $ `<external>/12386019527593959648/libmnl.h:174:9`!; |
| 66 | } |
| 67 | |
| 68 | static void |
| 69 | nftnl_obj_secmark_buildcxx . . $ nftnl_obj_secmark_build(3650aba98805b449).(struct nlmsghdrcxx . . $ nlmsghdr# *nlh, const struct nftnl_objcxx . . $ nftnl_obj# *e) |
| 70 | { |
| 71 | struct nftnl_obj_secmarkcxx . . $ nftnl_obj_secmark# *secmark = nftnl_obj_datacxx . . $ `include/obj.h:117:9`!(e); |
| 72 | |
| 73 | if (e->flagscxx . . $ nftnl_obj#flags. & (1 << NFTNL_OBJ_SECMARK_CTXcxx . . $ NFTNL_OBJ_SECMARK_CTX.)) |
| 74 | mnl_attr_put_strcxx . . $ mnl_attr_put_str(eb76286d4bfc1a8d).(nlh, NFTA_SECMARK_CTXcxx . . $ NFTA_SECMARK_CTX., secmark->ctxcxx . . $ nftnl_obj_secmark#ctx.); |
| 75 | } |
| 76 | |
| 77 | static int |
| 78 | nftnl_obj_secmark_parsecxx . . $ nftnl_obj_secmark_parse(f22ac2b7a2342b3a).(struct nftnl_objcxx . . $ nftnl_obj# *e, struct nlattrcxx . . $ nlattr# *attr) |
| 79 | { |
| 80 | struct nftnl_obj_secmarkcxx . . $ nftnl_obj_secmark# *secmark = nftnl_obj_datacxx . . $ `include/obj.h:117:9`!(e); |
| 81 | struct nlattrcxx . . $ nlattr# *tb[NFTA_SECMARK_MAXcxx . . $ `include/linux/netfilter/nf_tables.h:1394:9`! + 1] = {}; |
| 82 | |
| 83 | if (mnl_attr_parse_nestedcxx . . $ mnl_attr_parse_nested(f99c0e9fa94f99d9).(attr, nftnl_obj_secmark_cbcxx . . $ nftnl_obj_secmark_cb(de2ef18c48fd675c)., tb) < 0) |
| 84 | return -1; |
| 85 | |
| 86 | if (tb[NFTA_SECMARK_CTXcxx . . $ NFTA_SECMARK_CTX.]) { |
| 87 | snprintfcxx . . $ snprintf(ea502d73e74c754c).(secmark->ctxcxx . . $ nftnl_obj_secmark#ctx., sizeof(secmark->ctxcxx . . $ nftnl_obj_secmark#ctx.), "%s", |
| 88 | mnl_attr_get_strcxx . . $ mnl_attr_get_str(c24cebeef6d84d59).(tb[NFTA_SECMARK_CTXcxx . . $ NFTA_SECMARK_CTX.])); |
| 89 | e->flagscxx . . $ nftnl_obj#flags. |= (1 << NFTNL_OBJ_SECMARK_CTXcxx . . $ NFTNL_OBJ_SECMARK_CTX.); |
| 90 | } |
| 91 | |
| 92 | return 0; |
| 93 | } |
| 94 | |
| 95 | static int nftnl_obj_secmark_snprintfcxx . . $ nftnl_obj_secmark_snprintf(58da6fcd2536b16e).(char *buf, size_t len, |
| 96 | uint32_tcxx . . $ uint32_t# flags, |
| 97 | const struct nftnl_objcxx . . $ nftnl_obj# *e) |
| 98 | { |
| 99 | struct nftnl_obj_secmarkcxx . . $ nftnl_obj_secmark# *secmark = nftnl_obj_datacxx . . $ `include/obj.h:117:9`!(e); |
| 100 | |
| 101 | return snprintfcxx . . $ snprintf(ea502d73e74c754c).(buf, len, "context %s ", secmark->ctxcxx . . $ nftnl_obj_secmark#ctx.); |
| 102 | } |
| 103 | |
| 104 | static struct attr_policycxx . . $ attr_policy# obj_secmark_attr_policycxx . . $ obj_secmark_attr_policy.[__NFTNL_OBJ_SECMARK_MAXcxx . . $ __NFTNL_OBJ_SECMARK_MAX.] = { |
| 105 | [NFTNL_OBJ_SECMARK_CTXcxx . . $ NFTNL_OBJ_SECMARK_CTX.] = { .maxlen = NFT_SECMARK_CTX_MAXLENcxx . . $ `include/linux/netfilter/nf_tables.h:1397:9`! }, |
| 106 | }; |
| 107 | |
| 108 | struct obj_opscxx . . $ obj_ops# obj_ops_secmarkcxx . . $ obj_ops_secmark. = { |
| 109 | .name = "secmark", |
| 110 | .type = NFT_OBJECT_SECMARKcxx . . $ `include/linux/netfilter/nf_tables.h:1666:9`!, |
| 111 | .alloc_len = sizeof(struct nftnl_obj_secmarkcxx . . $ nftnl_obj_secmark#), |
| 112 | .nftnl_max_attr = __NFTNL_OBJ_SECMARK_MAXcxx . . $ __NFTNL_OBJ_SECMARK_MAX. - 1, |
| 113 | .attr_policy = obj_secmark_attr_policycxx . . $ obj_secmark_attr_policy., |
| 114 | .set = nftnl_obj_secmark_setcxx . . $ nftnl_obj_secmark_set(96c901c785434bf1)., |
| 115 | .get = nftnl_obj_secmark_getcxx . . $ nftnl_obj_secmark_get(d22e54b888e7c4b)., |
| 116 | .parse = nftnl_obj_secmark_parsecxx . . $ nftnl_obj_secmark_parse(f22ac2b7a2342b3a)., |
| 117 | .build = nftnl_obj_secmark_buildcxx . . $ nftnl_obj_secmark_build(3650aba98805b449)., |
| 118 | .output = nftnl_obj_secmark_snprintfcxx . . $ nftnl_obj_secmark_snprintf(58da6fcd2536b16e)., |
| 119 | }; |