| 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */cxx . . $ `<file>/src/expr/queue.c`/ |
| 2 | /* |
| 3 | * (C) 2013 by Eric Leblond <[email protected]> |
| 4 | */ |
| 5 | |
| 6 | #include <stdio.h> |
| 7 | #include <stdint.h> |
| 8 | #include <string.h> |
| 9 | #include <arpa/inet.h> |
| 10 | #include <errno.h> |
| 11 | #include <linux/netfilter/nf_tables.h>cxx . . $ `<file>/include/linux/netfilter/nf_tables.h`/ |
| 12 | |
| 13 | #include "internal.h"cxx . . $ `<file>/include/internal.h`/ |
| 14 | #include <libmnl/libmnl.h> |
| 15 | #include <libnftnl/expr.h>cxx . . $ `<file>/include/libnftnl/expr.h`/ |
| 16 | #include <libnftnl/rule.h>cxx . . $ `<file>/include/libnftnl/rule.h`/ |
| 17 | |
| 18 | struct nftnl_expr_queuecxx . . $ nftnl_expr_queue# { |
| 19 | enum nft_registerscxx . . $ nft_registers# sreg_qnumcxx . . $ nftnl_expr_queue#sreg_qnum.; |
| 20 | uint16_tcxx . . $ uint16_t# queuenumcxx . . $ nftnl_expr_queue#queuenum.; |
| 21 | uint16_tcxx . . $ uint16_t# queues_totalcxx . . $ nftnl_expr_queue#queues_total.; |
| 22 | uint16_tcxx . . $ uint16_t# flagscxx . . $ nftnl_expr_queue#flags.; |
| 23 | }; |
| 24 | |
| 25 | static int |
| 26 | nftnl_expr_queue_setcxx . . $ nftnl_expr_queue_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_queuecxx . . $ nftnl_expr_queue# *queue = nftnl_expr_datacxx . . $ `include/expr_ops.h:31:9`!(e); |
| 30 | |
| 31 | switch(type) { |
| 32 | case NFTNL_EXPR_QUEUE_NUMcxx . . $ NFTNL_EXPR_QUEUE_NUM.: |
| 33 | memcpycxx . . $ memcpy(cc817cb175f282d).(&queue->queuenumcxx . . $ nftnl_expr_queue#queuenum., data, data_len); |
| 34 | break; |
| 35 | case NFTNL_EXPR_QUEUE_TOTALcxx . . $ NFTNL_EXPR_QUEUE_TOTAL.: |
| 36 | memcpycxx . . $ memcpy(cc817cb175f282d).(&queue->queues_totalcxx . . $ nftnl_expr_queue#queues_total., data, data_len); |
| 37 | break; |
| 38 | case NFTNL_EXPR_QUEUE_FLAGScxx . . $ NFTNL_EXPR_QUEUE_FLAGS.: |
| 39 | memcpycxx . . $ memcpy(cc817cb175f282d).(&queue->flagscxx . . $ nftnl_expr_queue#flags., data, data_len); |
| 40 | break; |
| 41 | case NFTNL_EXPR_QUEUE_SREG_QNUMcxx . . $ NFTNL_EXPR_QUEUE_SREG_QNUM.: |
| 42 | memcpycxx . . $ memcpy(cc817cb175f282d).(&queue->sreg_qnumcxx . . $ nftnl_expr_queue#sreg_qnum., data, data_len); |
| 43 | break; |
| 44 | } |
| 45 | return 0; |
| 46 | } |
| 47 | |
| 48 | static const void * |
| 49 | nftnl_expr_queue_getcxx . . $ nftnl_expr_queue_get(9de263c4f9e71c4b).(const struct nftnl_exprcxx . . $ nftnl_expr# *e, uint16_tcxx . . $ uint16_t# type, |
| 50 | uint32_tcxx . . $ uint32_t# *data_len) |
| 51 | { |
| 52 | struct nftnl_expr_queuecxx . . $ nftnl_expr_queue# *queue = nftnl_expr_datacxx . . $ `include/expr_ops.h:31:9`!(e); |
| 53 | |
| 54 | switch(type) { |
| 55 | case NFTNL_EXPR_QUEUE_NUMcxx . . $ NFTNL_EXPR_QUEUE_NUM.: |
| 56 | *data_len = sizeof(queue->queuenumcxx . . $ nftnl_expr_queue#queuenum.); |
| 57 | return &queue->queuenumcxx . . $ nftnl_expr_queue#queuenum.; |
| 58 | case NFTNL_EXPR_QUEUE_TOTALcxx . . $ NFTNL_EXPR_QUEUE_TOTAL.: |
| 59 | *data_len = sizeof(queue->queues_totalcxx . . $ nftnl_expr_queue#queues_total.); |
| 60 | return &queue->queues_totalcxx . . $ nftnl_expr_queue#queues_total.; |
| 61 | case NFTNL_EXPR_QUEUE_FLAGScxx . . $ NFTNL_EXPR_QUEUE_FLAGS.: |
| 62 | *data_len = sizeof(queue->flagscxx . . $ nftnl_expr_queue#flags.); |
| 63 | return &queue->flagscxx . . $ nftnl_expr_queue#flags.; |
| 64 | case NFTNL_EXPR_QUEUE_SREG_QNUMcxx . . $ NFTNL_EXPR_QUEUE_SREG_QNUM.: |
| 65 | *data_len = sizeof(queue->sreg_qnumcxx . . $ nftnl_expr_queue#sreg_qnum.); |
| 66 | return &queue->sreg_qnumcxx . . $ nftnl_expr_queue#sreg_qnum.; |
| 67 | } |
| 68 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 69 | } |
| 70 | |
| 71 | static int nftnl_expr_queue_cbcxx . . $ nftnl_expr_queue_cb(de2ef18c48fd675c).(const struct nlattrcxx . . $ nlattr# *attr, void *data) |
| 72 | { |
| 73 | const struct nlattrcxx . . $ nlattr# **tb = data; |
| 74 | int type = mnl_attr_get_typecxx . . $ mnl_attr_get_type(1da47bcc4c4b975).(attr); |
| 75 | |
| 76 | if (mnl_attr_type_validcxx . . $ mnl_attr_type_valid(47df1cce1c7be855).(attr, NFTA_QUEUE_MAXcxx . . $ `include/linux/netfilter/nf_tables.h:1356:9`!) < 0) |
| 77 | return MNL_CB_OKcxx . . $ `<external>/12386019527593959648/libmnl.h:174:9`!; |
| 78 | |
| 79 | switch(type) { |
| 80 | case NFTA_QUEUE_NUMcxx . . $ NFTA_QUEUE_NUM.: |
| 81 | case NFTA_QUEUE_TOTALcxx . . $ NFTA_QUEUE_TOTAL.: |
| 82 | case NFTA_QUEUE_FLAGScxx . . $ NFTA_QUEUE_FLAGS.: |
| 83 | if (mnl_attr_validatecxx . . $ mnl_attr_validate(e419697a5e1ae2b1).(attr, MNL_TYPE_U16cxx . . $ MNL_TYPE_U16.) < 0) |
| 84 | abi_breakagecxx . . $ `include/utils.h:28:9`!(); |
| 85 | break; |
| 86 | case NFTA_QUEUE_SREG_QNUMcxx . . $ NFTA_QUEUE_SREG_QNUM.: |
| 87 | if (mnl_attr_validatecxx . . $ mnl_attr_validate(e419697a5e1ae2b1).(attr, MNL_TYPE_U32cxx . . $ MNL_TYPE_U32.) < 0) |
| 88 | abi_breakagecxx . . $ `include/utils.h:28:9`!(); |
| 89 | break; |
| 90 | } |
| 91 | |
| 92 | tb[type] = attr; |
| 93 | return MNL_CB_OKcxx . . $ `<external>/12386019527593959648/libmnl.h:174:9`!; |
| 94 | } |
| 95 | |
| 96 | static void |
| 97 | nftnl_expr_queue_buildcxx . . $ nftnl_expr_queue_build(93c7528a9cf90b41).(struct nlmsghdrcxx . . $ nlmsghdr# *nlh, const struct nftnl_exprcxx . . $ nftnl_expr# *e) |
| 98 | { |
| 99 | struct nftnl_expr_queuecxx . . $ nftnl_expr_queue# *queue = nftnl_expr_datacxx . . $ `include/expr_ops.h:31:9`!(e); |
| 100 | |
| 101 | if (e->flagscxx . . $ nftnl_expr#flags. & (1 << NFTNL_EXPR_QUEUE_NUMcxx . . $ NFTNL_EXPR_QUEUE_NUM.)) |
| 102 | mnl_attr_put_u16cxx . . $ mnl_attr_put_u16(951fb5ebe92f4b45).(nlh, NFTA_QUEUE_NUMcxx . . $ NFTA_QUEUE_NUM., htonscxx . . $ `<external>/9581057695539925927/in.h:431:12`!(queue->queuenum)); |
| 103 | if (e->flagscxx . . $ nftnl_expr#flags. & (1 << NFTNL_EXPR_QUEUE_TOTALcxx . . $ NFTNL_EXPR_QUEUE_TOTAL.)) |
| 104 | mnl_attr_put_u16cxx . . $ mnl_attr_put_u16(951fb5ebe92f4b45).(nlh, NFTA_QUEUE_TOTALcxx . . $ NFTA_QUEUE_TOTAL., htonscxx . . $ `<external>/9581057695539925927/in.h:431:12`!(queue->queues_total)); |
| 105 | if (e->flagscxx . . $ nftnl_expr#flags. & (1 << NFTNL_EXPR_QUEUE_FLAGScxx . . $ NFTNL_EXPR_QUEUE_FLAGS.)) |
| 106 | mnl_attr_put_u16cxx . . $ mnl_attr_put_u16(951fb5ebe92f4b45).(nlh, NFTA_QUEUE_FLAGScxx . . $ NFTA_QUEUE_FLAGS., htonscxx . . $ `<external>/9581057695539925927/in.h:431:12`!(queue->flags)); |
| 107 | if (e->flagscxx . . $ nftnl_expr#flags. & (1 << NFTNL_EXPR_QUEUE_SREG_QNUMcxx . . $ NFTNL_EXPR_QUEUE_SREG_QNUM.)) |
| 108 | mnl_attr_put_u32cxx . . $ mnl_attr_put_u32(b46fd0aeb0cfb96d).(nlh, NFTA_QUEUE_SREG_QNUMcxx . . $ NFTA_QUEUE_SREG_QNUM., htonlcxx . . $ `<external>/9581057695539925927/in.h:430:12`!(queue->sreg_qnum)); |
| 109 | } |
| 110 | |
| 111 | static int |
| 112 | nftnl_expr_queue_parsecxx . . $ nftnl_expr_queue_parse(ed61207049d8af9a).(struct nftnl_exprcxx . . $ nftnl_expr# *e, struct nlattrcxx . . $ nlattr# *attr) |
| 113 | { |
| 114 | struct nftnl_expr_queuecxx . . $ nftnl_expr_queue# *queue = nftnl_expr_datacxx . . $ `include/expr_ops.h:31:9`!(e); |
| 115 | struct nlattrcxx . . $ nlattr# *tb[NFTA_QUEUE_MAXcxx . . $ `include/linux/netfilter/nf_tables.h:1356:9`!+1] = {}; |
| 116 | |
| 117 | if (mnl_attr_parse_nestedcxx . . $ mnl_attr_parse_nested(f99c0e9fa94f99d9).(attr, nftnl_expr_queue_cbcxx . . $ nftnl_expr_queue_cb(de2ef18c48fd675c)., tb) < 0) |
| 118 | return -1; |
| 119 | |
| 120 | if (tb[NFTA_QUEUE_NUMcxx . . $ NFTA_QUEUE_NUM.]) { |
| 121 | queue->queuenumcxx . . $ nftnl_expr_queue#queuenum. = ntohscxx . . $ `<external>/9581057695539925927/in.h:429:12`!(mnl_attr_get_u16(tb[NFTA_QUEUE_NUM])); |
| 122 | e->flagscxx . . $ nftnl_expr#flags. |= (1 << NFTNL_EXPR_QUEUE_NUMcxx . . $ NFTNL_EXPR_QUEUE_NUM.); |
| 123 | } |
| 124 | if (tb[NFTA_QUEUE_TOTALcxx . . $ NFTA_QUEUE_TOTAL.]) { |
| 125 | queue->queues_totalcxx . . $ nftnl_expr_queue#queues_total. = ntohscxx . . $ `<external>/9581057695539925927/in.h:429:12`!(mnl_attr_get_u16(tb[NFTA_QUEUE_TOTAL])); |
| 126 | e->flagscxx . . $ nftnl_expr#flags. |= (1 << NFTNL_EXPR_QUEUE_TOTALcxx . . $ NFTNL_EXPR_QUEUE_TOTAL.); |
| 127 | } |
| 128 | if (tb[NFTA_QUEUE_FLAGScxx . . $ NFTA_QUEUE_FLAGS.]) { |
| 129 | queue->flagscxx . . $ nftnl_expr_queue#flags. = ntohscxx . . $ `<external>/9581057695539925927/in.h:429:12`!(mnl_attr_get_u16(tb[NFTA_QUEUE_FLAGS])); |
| 130 | e->flagscxx . . $ nftnl_expr#flags. |= (1 << NFTNL_EXPR_QUEUE_FLAGScxx . . $ NFTNL_EXPR_QUEUE_FLAGS.); |
| 131 | } |
| 132 | if (tb[NFTA_QUEUE_SREG_QNUMcxx . . $ NFTA_QUEUE_SREG_QNUM.]) { |
| 133 | queue->sreg_qnumcxx . . $ nftnl_expr_queue#sreg_qnum. = ntohlcxx . . $ `<external>/9581057695539925927/in.h:428:12`!(mnl_attr_get_u32(tb[NFTA_QUEUE_SREG_QNUM])); |
| 134 | e->flagscxx . . $ nftnl_expr#flags. |= (1 << NFTNL_EXPR_QUEUE_SREG_QNUMcxx . . $ NFTNL_EXPR_QUEUE_SREG_QNUM.); |
| 135 | } |
| 136 | |
| 137 | return 0; |
| 138 | } |
| 139 | |
| 140 | static int |
| 141 | nftnl_expr_queue_snprintfcxx . . $ nftnl_expr_queue_snprintf(2b4af69501aef780).(char *buf, size_t remain, |
| 142 | uint32_tcxx . . $ uint32_t# flags, const struct nftnl_exprcxx . . $ nftnl_expr# *e) |
| 143 | { |
| 144 | struct nftnl_expr_queuecxx . . $ nftnl_expr_queue# *queue = nftnl_expr_datacxx . . $ `include/expr_ops.h:31:9`!(e); |
| 145 | uint16_tcxx . . $ uint16_t# total_queues; |
| 146 | int ret, offset = 0; |
| 147 | |
| 148 | if (e->flagscxx . . $ nftnl_expr#flags. & (1 << NFTNL_EXPR_QUEUE_NUMcxx . . $ NFTNL_EXPR_QUEUE_NUM.)) { |
| 149 | total_queues = queue->queuenumcxx . . $ nftnl_expr_queue#queuenum. + queue->queues_totalcxx . . $ nftnl_expr_queue#queues_total. - 1; |
| 150 | |
| 151 | ret = snprintfcxx . . $ snprintf(ea502d73e74c754c).(buf + offset, remain, "num %u", queue->queuenumcxx . . $ nftnl_expr_queue#queuenum.); |
| 152 | SNPRINTF_BUFFER_SIZEcxx . . $ `include/utils.h:55:9`!(ret, remain, offset); |
| 153 | |
| 154 | if (queue->queues_totalcxx . . $ nftnl_expr_queue#queues_total. && total_queues != queue->queuenumcxx . . $ nftnl_expr_queue#queuenum.) { |
| 155 | ret = snprintfcxx . . $ snprintf(ea502d73e74c754c).(buf + offset, remain, "-%u", total_queues); |
| 156 | SNPRINTF_BUFFER_SIZEcxx . . $ `include/utils.h:55:9`!(ret, remain, offset); |
| 157 | } |
| 158 | |
| 159 | ret = snprintfcxx . . $ snprintf(ea502d73e74c754c).(buf + offset, remain, " "); |
| 160 | SNPRINTF_BUFFER_SIZEcxx . . $ `include/utils.h:55:9`!(ret, remain, offset); |
| 161 | } |
| 162 | |
| 163 | if (e->flagscxx . . $ nftnl_expr#flags. & (1 << NFTNL_EXPR_QUEUE_SREG_QNUMcxx . . $ NFTNL_EXPR_QUEUE_SREG_QNUM.)) { |
| 164 | ret = snprintfcxx . . $ snprintf(ea502d73e74c754c).(buf + offset, remain, "sreg_qnum %u ", |
| 165 | queue->sreg_qnumcxx . . $ nftnl_expr_queue#sreg_qnum.); |
| 166 | SNPRINTF_BUFFER_SIZEcxx . . $ `include/utils.h:55:9`!(ret, remain, offset); |
| 167 | } |
| 168 | |
| 169 | if (e->flagscxx . . $ nftnl_expr#flags. & (1 << NFTNL_EXPR_QUEUE_FLAGScxx . . $ NFTNL_EXPR_QUEUE_FLAGS.)) { |
| 170 | if (queue->flagscxx . . $ nftnl_expr_queue#flags. & (NFT_QUEUE_FLAG_BYPASScxx . . $ `include/linux/netfilter/nf_tables.h:1358:9`!)) { |
| 171 | ret = snprintfcxx . . $ snprintf(ea502d73e74c754c).(buf + offset, remain, "bypass "); |
| 172 | SNPRINTF_BUFFER_SIZEcxx . . $ `include/utils.h:55:9`!(ret, remain, offset); |
| 173 | } |
| 174 | if (queue->flagscxx . . $ nftnl_expr_queue#flags. & (NFT_QUEUE_FLAG_CPU_FANOUTcxx . . $ `include/linux/netfilter/nf_tables.h:1359:9`!)) { |
| 175 | ret = snprintfcxx . . $ snprintf(ea502d73e74c754c).(buf + offset, remain, "fanout "); |
| 176 | SNPRINTF_BUFFER_SIZEcxx . . $ `include/utils.h:55:9`!(ret, remain, offset); |
| 177 | } |
| 178 | } |
| 179 | return offset; |
| 180 | } |
| 181 | |
| 182 | static struct attr_policycxx . . $ attr_policy# queue_attr_policycxx . . $ queue_attr_policy.[__NFTNL_EXPR_QUEUE_MAXcxx . . $ __NFTNL_EXPR_QUEUE_MAX.] = { |
| 183 | [NFTNL_EXPR_QUEUE_NUMcxx . . $ NFTNL_EXPR_QUEUE_NUM.] = { .maxlen = sizeof(uint16_tcxx . . $ uint16_t#) }, |
| 184 | [NFTNL_EXPR_QUEUE_TOTALcxx . . $ NFTNL_EXPR_QUEUE_TOTAL.] = { .maxlen = sizeof(uint16_tcxx . . $ uint16_t#) }, |
| 185 | [NFTNL_EXPR_QUEUE_FLAGScxx . . $ NFTNL_EXPR_QUEUE_FLAGS.] = { .maxlen = sizeof(uint16_tcxx . . $ uint16_t#) }, |
| 186 | [NFTNL_EXPR_QUEUE_SREG_QNUMcxx . . $ NFTNL_EXPR_QUEUE_SREG_QNUM.] = { .maxlen = sizeof(uint32_tcxx . . $ uint32_t#) }, |
| 187 | }; |
| 188 | |
| 189 | struct expr_opscxx . . $ expr_ops# expr_ops_queuecxx . . $ expr_ops_queue. = { |
| 190 | .name = "queue", |
| 191 | .alloc_len = sizeof(struct nftnl_expr_queuecxx . . $ nftnl_expr_queue#), |
| 192 | .nftnl_max_attr = __NFTNL_EXPR_QUEUE_MAXcxx . . $ __NFTNL_EXPR_QUEUE_MAX. - 1, |
| 193 | .attr_policy = queue_attr_policycxx . . $ queue_attr_policy., |
| 194 | .set = nftnl_expr_queue_setcxx . . $ nftnl_expr_queue_set(211371a3e3842127)., |
| 195 | .get = nftnl_expr_queue_getcxx . . $ nftnl_expr_queue_get(9de263c4f9e71c4b)., |
| 196 | .parse = nftnl_expr_queue_parsecxx . . $ nftnl_expr_queue_parse(ed61207049d8af9a)., |
| 197 | .build = nftnl_expr_queue_buildcxx . . $ nftnl_expr_queue_build(93c7528a9cf90b41)., |
| 198 | .output = nftnl_expr_queue_snprintfcxx . . $ nftnl_expr_queue_snprintf(2b4af69501aef780)., |
| 199 | }; |