| 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */cxx . . $ `<file>/src/obj/connlimit.c`/ |
| 2 | /* |
| 3 | * (C) 2025 by Fernando Fernandez Mancera <[email protected]> |
| 4 | */ |
| 5 | |
| 6 | #include <stdio.h> |
| 7 | #include <stdint.h> |
| 8 | #include <arpa/inet.h> |
| 9 | |
| 10 | #include <linux/netfilter/nf_tables.h>cxx . . $ `<file>/include/linux/netfilter/nf_tables.h`/ |
| 11 | |
| 12 | #include <internal.h>cxx . . $ `<file>/include/internal.h`/ |
| 13 | #include <libmnl/libmnl.h> |
| 14 | #include <libnftnl/object.h>cxx . . $ `<file>/include/libnftnl/object.h`/ |
| 15 | |
| 16 | #include "obj.h"cxx . . $ `<file>/include/obj.h`/ |
| 17 | |
| 18 | static int nftnl_obj_connlimit_setcxx . . $ nftnl_obj_connlimit_set(96c901c785434bf1).(struct nftnl_objcxx . . $ nftnl_obj# *e, uint16_tcxx . . $ uint16_t# type, |
| 19 | const void *data, uint32_tcxx . . $ uint32_t# data_len) |
| 20 | { |
| 21 | struct nftnl_obj_connlimitcxx . . $ nftnl_obj_connlimit# *connlimit = nftnl_obj_datacxx . . $ `include/obj.h:117:9`!(e); |
| 22 | |
| 23 | switch(type) { |
| 24 | case NFTNL_OBJ_CONNLIMIT_COUNTcxx . . $ NFTNL_OBJ_CONNLIMIT_COUNT.: |
| 25 | memcpycxx . . $ memcpy(cc817cb175f282d).(&connlimit->countcxx . . $ nftnl_obj_connlimit#count., data, data_len); |
| 26 | break; |
| 27 | case NFTNL_OBJ_CONNLIMIT_FLAGScxx . . $ NFTNL_OBJ_CONNLIMIT_FLAGS.: |
| 28 | memcpycxx . . $ memcpy(cc817cb175f282d).(&connlimit->flagscxx . . $ nftnl_obj_connlimit#flags., data, data_len); |
| 29 | break; |
| 30 | } |
| 31 | return 0; |
| 32 | } |
| 33 | |
| 34 | static const void *nftnl_obj_connlimit_getcxx . . $ nftnl_obj_connlimit_get(d22e54b888e7c4b).(const struct nftnl_objcxx . . $ nftnl_obj# *e, |
| 35 | uint16_tcxx . . $ uint16_t# type, uint32_tcxx . . $ uint32_t# *data_len) |
| 36 | { |
| 37 | struct nftnl_obj_connlimitcxx . . $ nftnl_obj_connlimit# *connlimit = nftnl_obj_datacxx . . $ `include/obj.h:117:9`!(e); |
| 38 | |
| 39 | switch (type) { |
| 40 | case NFTNL_OBJ_CONNLIMIT_COUNTcxx . . $ NFTNL_OBJ_CONNLIMIT_COUNT.: |
| 41 | *data_len = sizeof(connlimit->countcxx . . $ nftnl_obj_connlimit#count.); |
| 42 | return &connlimit->countcxx . . $ nftnl_obj_connlimit#count.; |
| 43 | case NFTNL_OBJ_CONNLIMIT_FLAGScxx . . $ NFTNL_OBJ_CONNLIMIT_FLAGS.: |
| 44 | *data_len = sizeof(connlimit->flagscxx . . $ nftnl_obj_connlimit#flags.); |
| 45 | return &connlimit->flagscxx . . $ nftnl_obj_connlimit#flags.; |
| 46 | } |
| 47 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 48 | } |
| 49 | |
| 50 | static int nftnl_obj_connlimit_cbcxx . . $ nftnl_obj_connlimit_cb(de2ef18c48fd675c).(const struct nlattrcxx . . $ nlattr# *attr, void *data) |
| 51 | { |
| 52 | int type = mnl_attr_get_typecxx . . $ mnl_attr_get_type(1da47bcc4c4b975).(attr); |
| 53 | const struct nlattrcxx . . $ nlattr# **tb = data; |
| 54 | |
| 55 | if (mnl_attr_type_validcxx . . $ mnl_attr_type_valid(47df1cce1c7be855).(attr, NFTA_CONNLIMIT_MAXcxx . . $ `include/linux/netfilter/nf_tables.h:1259:9`!) < 0) |
| 56 | return MNL_CB_OKcxx . . $ `<external>/12386019527593959648/libmnl.h:174:9`!; |
| 57 | |
| 58 | switch (type) { |
| 59 | case NFTA_CONNLIMIT_COUNTcxx . . $ NFTA_CONNLIMIT_COUNT.: |
| 60 | case NFTA_CONNLIMIT_FLAGScxx . . $ NFTA_CONNLIMIT_FLAGS.: |
| 61 | if (mnl_attr_validatecxx . . $ mnl_attr_validate(e419697a5e1ae2b1).(attr, MNL_TYPE_U32cxx . . $ MNL_TYPE_U32.) < 0) |
| 62 | abi_breakagecxx . . $ `include/utils.h:28:9`!(); |
| 63 | break; |
| 64 | } |
| 65 | |
| 66 | tb[type] = attr; |
| 67 | return MNL_CB_OKcxx . . $ `<external>/12386019527593959648/libmnl.h:174:9`!; |
| 68 | } |
| 69 | |
| 70 | static void nftnl_obj_connlimit_buildcxx . . $ nftnl_obj_connlimit_build(3650aba98805b449).(struct nlmsghdrcxx . . $ nlmsghdr# *nlh, |
| 71 | const struct nftnl_objcxx . . $ nftnl_obj# *e) |
| 72 | { |
| 73 | struct nftnl_obj_connlimitcxx . . $ nftnl_obj_connlimit# *connlimit = nftnl_obj_datacxx . . $ `include/obj.h:117:9`!(e); |
| 74 | |
| 75 | if (e->flagscxx . . $ nftnl_obj#flags. & (1 << NFTNL_OBJ_CONNLIMIT_COUNTcxx . . $ NFTNL_OBJ_CONNLIMIT_COUNT.)) |
| 76 | mnl_attr_put_u32cxx . . $ mnl_attr_put_u32(b46fd0aeb0cfb96d).(nlh, NFTA_CONNLIMIT_COUNTcxx . . $ NFTA_CONNLIMIT_COUNT., |
| 77 | htonlcxx . . $ `<external>/9581057695539925927/in.h:430:12`!(connlimit->count)); |
| 78 | if (e->flagscxx . . $ nftnl_obj#flags. & (1 << NFTNL_OBJ_CONNLIMIT_FLAGScxx . . $ NFTNL_OBJ_CONNLIMIT_FLAGS.)) |
| 79 | mnl_attr_put_u32cxx . . $ mnl_attr_put_u32(b46fd0aeb0cfb96d).(nlh, NFTA_CONNLIMIT_FLAGScxx . . $ NFTA_CONNLIMIT_FLAGS., |
| 80 | htonlcxx . . $ `<external>/9581057695539925927/in.h:430:12`!(connlimit->flags)); |
| 81 | } |
| 82 | |
| 83 | static int nftnl_obj_connlimit_parsecxx . . $ nftnl_obj_connlimit_parse(f22ac2b7a2342b3a).(struct nftnl_objcxx . . $ nftnl_obj# *e, struct nlattrcxx . . $ nlattr# *attr) |
| 84 | { |
| 85 | struct nftnl_obj_connlimitcxx . . $ nftnl_obj_connlimit# *connlimit = nftnl_obj_datacxx . . $ `include/obj.h:117:9`!(e); |
| 86 | struct nlattrcxx . . $ nlattr# *tb[NFTA_CONNLIMIT_MAXcxx . . $ `include/linux/netfilter/nf_tables.h:1259:9`! + 1] = {}; |
| 87 | |
| 88 | if (mnl_attr_parse_nestedcxx . . $ mnl_attr_parse_nested(f99c0e9fa94f99d9).(attr, nftnl_obj_connlimit_cbcxx . . $ nftnl_obj_connlimit_cb(de2ef18c48fd675c)., tb) < 0) |
| 89 | return -1; |
| 90 | |
| 91 | if (tb[NFTA_CONNLIMIT_COUNTcxx . . $ NFTA_CONNLIMIT_COUNT.]) { |
| 92 | connlimit->countcxx . . $ nftnl_obj_connlimit#count. = ntohlcxx . . $ `<external>/9581057695539925927/in.h:428:12`!(mnl_attr_get_u32(tb[NFTA_CONNLIMIT_COUNT])); |
| 93 | e->flagscxx . . $ nftnl_obj#flags. |= (1 << NFTNL_OBJ_CONNLIMIT_COUNTcxx . . $ NFTNL_OBJ_CONNLIMIT_COUNT.); |
| 94 | } |
| 95 | if (tb[NFTA_CONNLIMIT_FLAGScxx . . $ NFTA_CONNLIMIT_FLAGS.]) { |
| 96 | connlimit->flagscxx . . $ nftnl_obj_connlimit#flags. = ntohlcxx . . $ `<external>/9581057695539925927/in.h:428:12`!(mnl_attr_get_u32(tb[NFTA_CONNLIMIT_FLAGS])); |
| 97 | e->flagscxx . . $ nftnl_obj#flags. |= (1 << NFTNL_OBJ_CONNLIMIT_FLAGScxx . . $ NFTNL_OBJ_CONNLIMIT_FLAGS.); |
| 98 | } |
| 99 | |
| 100 | return 0; |
| 101 | } |
| 102 | |
| 103 | static int nftnl_obj_connlimit_snprintfcxx . . $ nftnl_obj_connlimit_snprintf(58da6fcd2536b16e).(char *buf, size_t len, |
| 104 | uint32_tcxx . . $ uint32_t# flags, |
| 105 | const struct nftnl_objcxx . . $ nftnl_obj# *e) |
| 106 | { |
| 107 | struct nftnl_obj_connlimitcxx . . $ nftnl_obj_connlimit# *connlimit = nftnl_obj_datacxx . . $ `include/obj.h:117:9`!(e); |
| 108 | |
| 109 | return snprintfcxx . . $ snprintf(ea502d73e74c754c).(buf, len, "count %u flags %x ", |
| 110 | connlimit->countcxx . . $ nftnl_obj_connlimit#count., connlimit->flagscxx . . $ nftnl_obj_connlimit#flags.); |
| 111 | } |
| 112 | |
| 113 | static struct attr_policycxx . . $ attr_policy# obj_connlimit_attr_policycxx . . $ obj_connlimit_attr_policy.[__NFTNL_OBJ_CONNLIMIT_MAXcxx . . $ __NFTNL_OBJ_CONNLIMIT_MAX.] = { |
| 114 | [NFTNL_OBJ_CONNLIMIT_COUNTcxx . . $ NFTNL_OBJ_CONNLIMIT_COUNT.] = { .maxlen = sizeof(uint32_tcxx . . $ uint32_t#) }, |
| 115 | [NFTNL_OBJ_CONNLIMIT_FLAGScxx . . $ NFTNL_OBJ_CONNLIMIT_FLAGS.] = { .maxlen = sizeof(uint32_tcxx . . $ uint32_t#) }, |
| 116 | }; |
| 117 | |
| 118 | struct obj_opscxx . . $ obj_ops# obj_ops_connlimitcxx . . $ obj_ops_connlimit. = { |
| 119 | .name = "connlimit", |
| 120 | .type = NFT_OBJECT_CONNLIMITcxx . . $ `include/linux/netfilter/nf_tables.h:1663:9`!, |
| 121 | .alloc_len = sizeof(struct nftnl_obj_connlimitcxx . . $ nftnl_obj_connlimit#), |
| 122 | .nftnl_max_attr = __NFTNL_OBJ_CONNLIMIT_MAXcxx . . $ __NFTNL_OBJ_CONNLIMIT_MAX., |
| 123 | .attr_policy = obj_connlimit_attr_policycxx . . $ obj_connlimit_attr_policy., |
| 124 | .set = nftnl_obj_connlimit_setcxx . . $ nftnl_obj_connlimit_set(96c901c785434bf1)., |
| 125 | .get = nftnl_obj_connlimit_getcxx . . $ nftnl_obj_connlimit_get(d22e54b888e7c4b)., |
| 126 | .parse = nftnl_obj_connlimit_parsecxx . . $ nftnl_obj_connlimit_parse(f22ac2b7a2342b3a)., |
| 127 | .build = nftnl_obj_connlimit_buildcxx . . $ nftnl_obj_connlimit_build(3650aba98805b449)., |
| 128 | .output = nftnl_obj_connlimit_snprintfcxx . . $ nftnl_obj_connlimit_snprintf(58da6fcd2536b16e)., |
| 129 | }; |