| 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */cxx . . $ `<file>/src/obj/counter.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 <libmnl/libmnl.h> |
| 15 | #include <libnftnl/object.h>cxx . . $ `<file>/include/libnftnl/object.h`/ |
| 16 | |
| 17 | #include "internal.h"cxx . . $ `<file>/include/internal.h`/ |
| 18 | #include "obj.h"cxx . . $ `<file>/include/obj.h`/ |
| 19 | |
| 20 | static int |
| 21 | nftnl_obj_counter_setcxx . . $ nftnl_obj_counter_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_countercxx . . $ nftnl_obj_counter# *ctr = nftnl_obj_datacxx . . $ `include/obj.h:117:9`!(e); |
| 25 | |
| 26 | switch(type) { |
| 27 | case NFTNL_OBJ_CTR_BYTEScxx . . $ NFTNL_OBJ_CTR_BYTES.: |
| 28 | memcpycxx . . $ memcpy(cc817cb175f282d).(&ctr->bytescxx . . $ nftnl_obj_counter#bytes., data, data_len); |
| 29 | break; |
| 30 | case NFTNL_OBJ_CTR_PKTScxx . . $ NFTNL_OBJ_CTR_PKTS.: |
| 31 | memcpycxx . . $ memcpy(cc817cb175f282d).(&ctr->pktscxx . . $ nftnl_obj_counter#pkts., data, data_len); |
| 32 | break; |
| 33 | } |
| 34 | return 0; |
| 35 | } |
| 36 | |
| 37 | static const void * |
| 38 | nftnl_obj_counter_getcxx . . $ nftnl_obj_counter_get(d22e54b888e7c4b).(const struct nftnl_objcxx . . $ nftnl_obj# *e, uint16_tcxx . . $ uint16_t# type, |
| 39 | uint32_tcxx . . $ uint32_t# *data_len) |
| 40 | { |
| 41 | struct nftnl_obj_countercxx . . $ nftnl_obj_counter# *ctr = nftnl_obj_datacxx . . $ `include/obj.h:117:9`!(e); |
| 42 | |
| 43 | switch(type) { |
| 44 | case NFTNL_OBJ_CTR_BYTEScxx . . $ NFTNL_OBJ_CTR_BYTES.: |
| 45 | *data_len = sizeof(ctr->bytescxx . . $ nftnl_obj_counter#bytes.); |
| 46 | return &ctr->bytescxx . . $ nftnl_obj_counter#bytes.; |
| 47 | case NFTNL_OBJ_CTR_PKTScxx . . $ NFTNL_OBJ_CTR_PKTS.: |
| 48 | *data_len = sizeof(ctr->pktscxx . . $ nftnl_obj_counter#pkts.); |
| 49 | return &ctr->pktscxx . . $ nftnl_obj_counter#pkts.; |
| 50 | } |
| 51 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 52 | } |
| 53 | |
| 54 | static int nftnl_obj_counter_cbcxx . . $ nftnl_obj_counter_cb(de2ef18c48fd675c).(const struct nlattrcxx . . $ nlattr# *attr, void *data) |
| 55 | { |
| 56 | const struct nlattrcxx . . $ nlattr# **tb = data; |
| 57 | int type = mnl_attr_get_typecxx . . $ mnl_attr_get_type(1da47bcc4c4b975).(attr); |
| 58 | |
| 59 | if (mnl_attr_type_validcxx . . $ mnl_attr_type_valid(47df1cce1c7be855).(attr, NFTA_COUNTER_MAXcxx . . $ `include/linux/netfilter/nf_tables.h:1274:9`!) < 0) |
| 60 | return MNL_CB_OKcxx . . $ `<external>/12386019527593959648/libmnl.h:174:9`!; |
| 61 | |
| 62 | switch(type) { |
| 63 | case NFTA_COUNTER_BYTEScxx . . $ NFTA_COUNTER_BYTES.: |
| 64 | case NFTA_COUNTER_PACKETScxx . . $ NFTA_COUNTER_PACKETS.: |
| 65 | if (mnl_attr_validatecxx . . $ mnl_attr_validate(e419697a5e1ae2b1).(attr, MNL_TYPE_U64cxx . . $ MNL_TYPE_U64.) < 0) |
| 66 | abi_breakagecxx . . $ `include/utils.h:28:9`!(); |
| 67 | break; |
| 68 | } |
| 69 | |
| 70 | tb[type] = attr; |
| 71 | return MNL_CB_OKcxx . . $ `<external>/12386019527593959648/libmnl.h:174:9`!; |
| 72 | } |
| 73 | |
| 74 | static void |
| 75 | nftnl_obj_counter_buildcxx . . $ nftnl_obj_counter_build(3650aba98805b449).(struct nlmsghdrcxx . . $ nlmsghdr# *nlh, const struct nftnl_objcxx . . $ nftnl_obj# *e) |
| 76 | { |
| 77 | struct nftnl_obj_countercxx . . $ nftnl_obj_counter# *ctr = nftnl_obj_datacxx . . $ `include/obj.h:117:9`!(e); |
| 78 | |
| 79 | if (e->flagscxx . . $ nftnl_obj#flags. & (1 << NFTNL_OBJ_CTR_BYTEScxx . . $ NFTNL_OBJ_CTR_BYTES.)) |
| 80 | mnl_attr_put_u64cxx . . $ mnl_attr_put_u64(6d753f4d486e3a2f).(nlh, NFTA_COUNTER_BYTEScxx . . $ NFTA_COUNTER_BYTES., htobe64cxx . . $ `<external>/15855202785537844739/endian.h:49:11`!(ctr->bytes)); |
| 81 | if (e->flagscxx . . $ nftnl_obj#flags. & (1 << NFTNL_OBJ_CTR_PKTScxx . . $ NFTNL_OBJ_CTR_PKTS.)) |
| 82 | mnl_attr_put_u64cxx . . $ mnl_attr_put_u64(6d753f4d486e3a2f).(nlh, NFTA_COUNTER_PACKETScxx . . $ NFTA_COUNTER_PACKETS., htobe64cxx . . $ `<external>/15855202785537844739/endian.h:49:11`!(ctr->pkts)); |
| 83 | } |
| 84 | |
| 85 | static int |
| 86 | nftnl_obj_counter_parsecxx . . $ nftnl_obj_counter_parse(f22ac2b7a2342b3a).(struct nftnl_objcxx . . $ nftnl_obj# *e, struct nlattrcxx . . $ nlattr# *attr) |
| 87 | { |
| 88 | struct nftnl_obj_countercxx . . $ nftnl_obj_counter# *ctr = nftnl_obj_datacxx . . $ `include/obj.h:117:9`!(e); |
| 89 | struct nlattrcxx . . $ nlattr# *tb[NFTA_COUNTER_MAXcxx . . $ `include/linux/netfilter/nf_tables.h:1274:9`!+1] = {}; |
| 90 | |
| 91 | if (mnl_attr_parse_nestedcxx . . $ mnl_attr_parse_nested(f99c0e9fa94f99d9).(attr, nftnl_obj_counter_cbcxx . . $ nftnl_obj_counter_cb(de2ef18c48fd675c)., tb) < 0) |
| 92 | return -1; |
| 93 | |
| 94 | if (tb[NFTA_COUNTER_BYTEScxx . . $ NFTA_COUNTER_BYTES.]) { |
| 95 | ctr->bytescxx . . $ nftnl_obj_counter#bytes. = be64tohcxx . . $ `<external>/15855202785537844739/endian.h:51:11`!(mnl_attr_get_u64(tb[NFTA_COUNTER_BYTES])); |
| 96 | e->flagscxx . . $ nftnl_obj#flags. |= (1 << NFTNL_OBJ_CTR_BYTEScxx . . $ NFTNL_OBJ_CTR_BYTES.); |
| 97 | } |
| 98 | if (tb[NFTA_COUNTER_PACKETScxx . . $ NFTA_COUNTER_PACKETS.]) { |
| 99 | ctr->pktscxx . . $ nftnl_obj_counter#pkts. = be64tohcxx . . $ `<external>/15855202785537844739/endian.h:51:11`!(mnl_attr_get_u64(tb[NFTA_COUNTER_PACKETS])); |
| 100 | e->flagscxx . . $ nftnl_obj#flags. |= (1 << NFTNL_OBJ_CTR_PKTScxx . . $ NFTNL_OBJ_CTR_PKTS.); |
| 101 | } |
| 102 | |
| 103 | return 0; |
| 104 | } |
| 105 | |
| 106 | static int nftnl_obj_counter_snprintfcxx . . $ nftnl_obj_counter_snprintf(58da6fcd2536b16e).(char *buf, size_t len, uint32_tcxx . . $ uint32_t# flags, |
| 107 | const struct nftnl_objcxx . . $ nftnl_obj# *e) |
| 108 | { |
| 109 | struct nftnl_obj_countercxx . . $ nftnl_obj_counter# *ctr = nftnl_obj_datacxx . . $ `include/obj.h:117:9`!(e); |
| 110 | |
| 111 | return snprintfcxx . . $ snprintf(ea502d73e74c754c).(buf, len, "pkts %"PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:110:10`!" bytes %"PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:110:10`!" ", |
| 112 | ctr->pktscxx . . $ nftnl_obj_counter#pkts., ctr->bytescxx . . $ nftnl_obj_counter#bytes.); |
| 113 | } |
| 114 | |
| 115 | static struct attr_policycxx . . $ attr_policy# obj_ctr_attr_policycxx . . $ obj_ctr_attr_policy.[__NFTNL_OBJ_CTR_MAXcxx . . $ __NFTNL_OBJ_CTR_MAX.] = { |
| 116 | [NFTNL_OBJ_CTR_BYTEScxx . . $ NFTNL_OBJ_CTR_BYTES.] = { .maxlen = sizeof(uint64_tcxx . . $ uint64_t#) }, |
| 117 | [NFTNL_OBJ_CTR_PKTScxx . . $ NFTNL_OBJ_CTR_PKTS.] = { .maxlen = sizeof(uint64_tcxx . . $ uint64_t#) }, |
| 118 | }; |
| 119 | |
| 120 | struct obj_opscxx . . $ obj_ops# obj_ops_countercxx . . $ obj_ops_counter. = { |
| 121 | .name = "counter", |
| 122 | .type = NFT_OBJECT_COUNTERcxx . . $ `include/linux/netfilter/nf_tables.h:1659:9`!, |
| 123 | .alloc_len = sizeof(struct nftnl_obj_countercxx . . $ nftnl_obj_counter#), |
| 124 | .nftnl_max_attr = __NFTNL_OBJ_CTR_MAXcxx . . $ __NFTNL_OBJ_CTR_MAX. - 1, |
| 125 | .attr_policy = obj_ctr_attr_policycxx . . $ obj_ctr_attr_policy., |
| 126 | .set = nftnl_obj_counter_setcxx . . $ nftnl_obj_counter_set(96c901c785434bf1)., |
| 127 | .get = nftnl_obj_counter_getcxx . . $ nftnl_obj_counter_get(d22e54b888e7c4b)., |
| 128 | .parse = nftnl_obj_counter_parsecxx . . $ nftnl_obj_counter_parse(f22ac2b7a2342b3a)., |
| 129 | .build = nftnl_obj_counter_buildcxx . . $ nftnl_obj_counter_build(3650aba98805b449)., |
| 130 | .output = nftnl_obj_counter_snprintfcxx . . $ nftnl_obj_counter_snprintf(58da6fcd2536b16e)., |
| 131 | }; |