Harald Welte | daa1ef3 | 2005-07-19 21:44:58 +0000 | [diff] [blame] | 1 | /* Shared library add-on to iptables for NFQ |
| 2 | * |
| 3 | * (C) 2005 by Harald Welte <laforge@netfilter.org> |
| 4 | * |
| 5 | * This program is distributed under the terms of GNU GPL v2, 1991 |
| 6 | * |
| 7 | */ |
| 8 | #include <stdio.h> |
Yasuyuki KOZAKAI | a2e89cc | 2007-07-24 07:29:36 +0000 | [diff] [blame] | 9 | #include <xtables.h> |
Yasuyuki KOZAKAI | a2e89cc | 2007-07-24 07:29:36 +0000 | [diff] [blame] | 10 | #include <linux/netfilter/xt_NFQUEUE.h> |
Harald Welte | daa1ef3 | 2005-07-19 21:44:58 +0000 | [diff] [blame] | 11 | |
Jan Engelhardt | 478be25 | 2011-03-06 17:54:50 +0100 | [diff] [blame] | 12 | enum { |
| 13 | O_QUEUE_NUM = 0, |
| 14 | O_QUEUE_BALANCE, |
| 15 | O_QUEUE_BYPASS, |
holger@eitzenberger.org | ce7d061 | 2013-04-02 00:35:39 +0000 | [diff] [blame] | 16 | O_QUEUE_CPU_FANOUT, |
Jan Engelhardt | d878461 | 2011-05-25 00:26:01 +0200 | [diff] [blame] | 17 | F_QUEUE_NUM = 1 << O_QUEUE_NUM, |
| 18 | F_QUEUE_BALANCE = 1 << O_QUEUE_BALANCE, |
holger@eitzenberger.org | ce7d061 | 2013-04-02 00:35:39 +0000 | [diff] [blame] | 19 | F_QUEUE_CPU_FANOUT = 1 << O_QUEUE_CPU_FANOUT, |
Jan Engelhardt | 478be25 | 2011-03-06 17:54:50 +0100 | [diff] [blame] | 20 | }; |
| 21 | |
Jan Engelhardt | 932e648 | 2007-10-04 16:27:30 +0000 | [diff] [blame] | 22 | static void NFQUEUE_help(void) |
Harald Welte | daa1ef3 | 2005-07-19 21:44:58 +0000 | [diff] [blame] | 23 | { |
| 24 | printf( |
| 25 | "NFQUEUE target options\n" |
| 26 | " --queue-num value Send packet to QUEUE number <value>.\n" |
| 27 | " Valid queue numbers are 0-65535\n" |
| 28 | ); |
| 29 | } |
| 30 | |
Florian Westphal | 4282d89 | 2009-08-20 16:39:05 +0200 | [diff] [blame] | 31 | static void NFQUEUE_help_v1(void) |
| 32 | { |
Florian Westphal | 4282d89 | 2009-08-20 16:39:05 +0200 | [diff] [blame] | 33 | printf( |
Shivani Bhardwaj | d998de7 | 2016-04-14 20:56:49 +0530 | [diff] [blame] | 34 | "NFQUEUE target options\n" |
| 35 | " --queue-num value Send packet to QUEUE number <value>.\n" |
| 36 | " Valid queue numbers are 0-65535\n" |
Florian Westphal | 4282d89 | 2009-08-20 16:39:05 +0200 | [diff] [blame] | 37 | " --queue-balance first:last Balance flows between queues <value> to <value>.\n"); |
| 38 | } |
| 39 | |
Florian Westphal | 6924b49 | 2011-01-20 11:27:42 +0100 | [diff] [blame] | 40 | static void NFQUEUE_help_v2(void) |
| 41 | { |
Florian Westphal | 6924b49 | 2011-01-20 11:27:42 +0100 | [diff] [blame] | 42 | printf( |
Shivani Bhardwaj | d998de7 | 2016-04-14 20:56:49 +0530 | [diff] [blame] | 43 | "NFQUEUE target options\n" |
| 44 | " --queue-num value Send packet to QUEUE number <value>.\n" |
| 45 | " Valid queue numbers are 0-65535\n" |
| 46 | " --queue-balance first:last Balance flows between queues <value> to <value>.\n" |
holger@eitzenberger.org | ce7d061 | 2013-04-02 00:35:39 +0000 | [diff] [blame] | 47 | " --queue-bypass Bypass Queueing if no queue instance exists.\n" |
| 48 | " --queue-cpu-fanout Use current CPU (no hashing)\n"); |
| 49 | } |
| 50 | |
| 51 | static void NFQUEUE_help_v3(void) |
| 52 | { |
holger@eitzenberger.org | ce7d061 | 2013-04-02 00:35:39 +0000 | [diff] [blame] | 53 | printf( |
Shivani Bhardwaj | d998de7 | 2016-04-14 20:56:49 +0530 | [diff] [blame] | 54 | "NFQUEUE target options\n" |
| 55 | " --queue-num value Send packet to QUEUE number <value>.\n" |
| 56 | " Valid queue numbers are 0-65535\n" |
| 57 | " --queue-balance first:last Balance flows between queues <value> to <value>.\n" |
| 58 | " --queue-bypass Bypass Queueing if no queue instance exists.\n" |
holger@eitzenberger.org | ce7d061 | 2013-04-02 00:35:39 +0000 | [diff] [blame] | 59 | " --queue-cpu-fanout Use current CPU (no hashing)\n"); |
Florian Westphal | 6924b49 | 2011-01-20 11:27:42 +0100 | [diff] [blame] | 60 | } |
| 61 | |
Jan Engelhardt | 478be25 | 2011-03-06 17:54:50 +0100 | [diff] [blame] | 62 | #define s struct xt_NFQ_info |
| 63 | static const struct xt_option_entry NFQUEUE_opts[] = { |
| 64 | {.name = "queue-num", .id = O_QUEUE_NUM, .type = XTTYPE_UINT16, |
Jan Engelhardt | d878461 | 2011-05-25 00:26:01 +0200 | [diff] [blame] | 65 | .flags = XTOPT_PUT, XTOPT_POINTER(s, queuenum), |
| 66 | .excl = F_QUEUE_BALANCE}, |
Jan Engelhardt | 478be25 | 2011-03-06 17:54:50 +0100 | [diff] [blame] | 67 | {.name = "queue-balance", .id = O_QUEUE_BALANCE, |
Jan Engelhardt | d878461 | 2011-05-25 00:26:01 +0200 | [diff] [blame] | 68 | .type = XTTYPE_UINT16RC, .excl = F_QUEUE_NUM}, |
Jan Engelhardt | 478be25 | 2011-03-06 17:54:50 +0100 | [diff] [blame] | 69 | {.name = "queue-bypass", .id = O_QUEUE_BYPASS, .type = XTTYPE_NONE}, |
holger@eitzenberger.org | ce7d061 | 2013-04-02 00:35:39 +0000 | [diff] [blame] | 70 | {.name = "queue-cpu-fanout", .id = O_QUEUE_CPU_FANOUT, |
| 71 | .type = XTTYPE_NONE, .also = F_QUEUE_BALANCE}, |
Jan Engelhardt | 478be25 | 2011-03-06 17:54:50 +0100 | [diff] [blame] | 72 | XTOPT_TABLEEND, |
Harald Welte | daa1ef3 | 2005-07-19 21:44:58 +0000 | [diff] [blame] | 73 | }; |
Jan Engelhardt | 478be25 | 2011-03-06 17:54:50 +0100 | [diff] [blame] | 74 | #undef s |
Harald Welte | daa1ef3 | 2005-07-19 21:44:58 +0000 | [diff] [blame] | 75 | |
Jan Engelhardt | 478be25 | 2011-03-06 17:54:50 +0100 | [diff] [blame] | 76 | static void NFQUEUE_parse(struct xt_option_call *cb) |
Florian Westphal | 4282d89 | 2009-08-20 16:39:05 +0200 | [diff] [blame] | 77 | { |
Jan Engelhardt | 478be25 | 2011-03-06 17:54:50 +0100 | [diff] [blame] | 78 | xtables_option_parse(cb); |
| 79 | if (cb->entry->id == O_QUEUE_BALANCE) |
Florian Westphal | 4282d89 | 2009-08-20 16:39:05 +0200 | [diff] [blame] | 80 | xtables_error(PARAMETER_PROBLEM, "NFQUEUE target: " |
| 81 | "--queue-balance not supported (kernel too old?)"); |
Florian Westphal | 4282d89 | 2009-08-20 16:39:05 +0200 | [diff] [blame] | 82 | } |
| 83 | |
Jan Engelhardt | 478be25 | 2011-03-06 17:54:50 +0100 | [diff] [blame] | 84 | static void NFQUEUE_parse_v1(struct xt_option_call *cb) |
Florian Westphal | 4282d89 | 2009-08-20 16:39:05 +0200 | [diff] [blame] | 85 | { |
Jan Engelhardt | 478be25 | 2011-03-06 17:54:50 +0100 | [diff] [blame] | 86 | struct xt_NFQ_info_v1 *info = cb->data; |
| 87 | const uint16_t *r = cb->val.u16_range; |
Florian Westphal | 4282d89 | 2009-08-20 16:39:05 +0200 | [diff] [blame] | 88 | |
Jan Engelhardt | 478be25 | 2011-03-06 17:54:50 +0100 | [diff] [blame] | 89 | xtables_option_parse(cb); |
| 90 | switch (cb->entry->id) { |
| 91 | case O_QUEUE_BALANCE: |
| 92 | if (cb->nvals != 2) |
| 93 | xtables_error(PARAMETER_PROBLEM, |
| 94 | "Bad range \"%s\"", cb->arg); |
| 95 | if (r[0] >= r[1]) |
Florian Westphal | 4282d89 | 2009-08-20 16:39:05 +0200 | [diff] [blame] | 96 | xtables_error(PARAMETER_PROBLEM, "%u should be less than %u", |
Jan Engelhardt | 478be25 | 2011-03-06 17:54:50 +0100 | [diff] [blame] | 97 | r[0], r[1]); |
| 98 | info->queuenum = r[0]; |
| 99 | info->queues_total = r[1] - r[0] + 1; |
Florian Westphal | 4282d89 | 2009-08-20 16:39:05 +0200 | [diff] [blame] | 100 | break; |
Harald Welte | daa1ef3 | 2005-07-19 21:44:58 +0000 | [diff] [blame] | 101 | } |
Harald Welte | daa1ef3 | 2005-07-19 21:44:58 +0000 | [diff] [blame] | 102 | } |
| 103 | |
Jan Engelhardt | 478be25 | 2011-03-06 17:54:50 +0100 | [diff] [blame] | 104 | static void NFQUEUE_parse_v2(struct xt_option_call *cb) |
Florian Westphal | 6924b49 | 2011-01-20 11:27:42 +0100 | [diff] [blame] | 105 | { |
Jan Engelhardt | 478be25 | 2011-03-06 17:54:50 +0100 | [diff] [blame] | 106 | struct xt_NFQ_info_v2 *info = cb->data; |
Shivani Bhardwaj | d998de7 | 2016-04-14 20:56:49 +0530 | [diff] [blame] | 107 | const uint16_t *r = cb->val.u16_range; |
Jan Engelhardt | 478be25 | 2011-03-06 17:54:50 +0100 | [diff] [blame] | 108 | |
Shivani Bhardwaj | d998de7 | 2016-04-14 20:56:49 +0530 | [diff] [blame] | 109 | xtables_option_parse(cb); |
Jan Engelhardt | 478be25 | 2011-03-06 17:54:50 +0100 | [diff] [blame] | 110 | switch (cb->entry->id) { |
Shivani Bhardwaj | d998de7 | 2016-04-14 20:56:49 +0530 | [diff] [blame] | 111 | case O_QUEUE_BALANCE: |
| 112 | if (cb->nvals != 2) |
| 113 | xtables_error(PARAMETER_PROBLEM, |
| 114 | "Bad range \"%s\"", cb->arg); |
| 115 | if (r[0] >= r[1]) |
| 116 | xtables_error(PARAMETER_PROBLEM, |
| 117 | "%u should be less than %u", |
| 118 | r[0], r[1]); |
| 119 | info->queuenum = r[0]; |
| 120 | info->queues_total = r[1] - r[0] + 1; |
| 121 | break; |
Jan Engelhardt | 478be25 | 2011-03-06 17:54:50 +0100 | [diff] [blame] | 122 | case O_QUEUE_BYPASS: |
Shivani Bhardwaj | d1555a0 | 2016-04-14 20:55:58 +0530 | [diff] [blame] | 123 | info->bypass |= NFQ_FLAG_BYPASS; |
Jan Engelhardt | 478be25 | 2011-03-06 17:54:50 +0100 | [diff] [blame] | 124 | break; |
Florian Westphal | 6924b49 | 2011-01-20 11:27:42 +0100 | [diff] [blame] | 125 | } |
Florian Westphal | 6924b49 | 2011-01-20 11:27:42 +0100 | [diff] [blame] | 126 | } |
| 127 | |
holger@eitzenberger.org | ce7d061 | 2013-04-02 00:35:39 +0000 | [diff] [blame] | 128 | static void NFQUEUE_parse_v3(struct xt_option_call *cb) |
| 129 | { |
| 130 | struct xt_NFQ_info_v3 *info = cb->data; |
Shivani Bhardwaj | d998de7 | 2016-04-14 20:56:49 +0530 | [diff] [blame] | 131 | const uint16_t *r = cb->val.u16_range; |
holger@eitzenberger.org | ce7d061 | 2013-04-02 00:35:39 +0000 | [diff] [blame] | 132 | |
Shivani Bhardwaj | d998de7 | 2016-04-14 20:56:49 +0530 | [diff] [blame] | 133 | xtables_option_parse(cb); |
holger@eitzenberger.org | ce7d061 | 2013-04-02 00:35:39 +0000 | [diff] [blame] | 134 | switch (cb->entry->id) { |
Shivani Bhardwaj | d998de7 | 2016-04-14 20:56:49 +0530 | [diff] [blame] | 135 | case O_QUEUE_BALANCE: |
| 136 | if (cb->nvals != 2) |
| 137 | xtables_error(PARAMETER_PROBLEM, |
| 138 | "Bad range \"%s\"", cb->arg); |
| 139 | if (r[0] >= r[1]) |
| 140 | xtables_error(PARAMETER_PROBLEM, |
| 141 | "%u should be less than %u", |
| 142 | r[0], r[1]); |
| 143 | info->queuenum = r[0]; |
| 144 | info->queues_total = r[1] - r[0] + 1; |
| 145 | break; |
| 146 | case O_QUEUE_BYPASS: |
| 147 | info->flags |= NFQ_FLAG_BYPASS; |
| 148 | break; |
holger@eitzenberger.org | ce7d061 | 2013-04-02 00:35:39 +0000 | [diff] [blame] | 149 | case O_QUEUE_CPU_FANOUT: |
| 150 | info->flags |= NFQ_FLAG_CPU_FANOUT; |
| 151 | break; |
| 152 | } |
| 153 | } |
| 154 | |
Jan Engelhardt | 932e648 | 2007-10-04 16:27:30 +0000 | [diff] [blame] | 155 | static void NFQUEUE_print(const void *ip, |
| 156 | const struct xt_entry_target *target, int numeric) |
Harald Welte | daa1ef3 | 2005-07-19 21:44:58 +0000 | [diff] [blame] | 157 | { |
Yasuyuki KOZAKAI | a2e89cc | 2007-07-24 07:29:36 +0000 | [diff] [blame] | 158 | const struct xt_NFQ_info *tinfo = |
| 159 | (const struct xt_NFQ_info *)target->data; |
Jan Engelhardt | 7386635 | 2010-12-18 02:04:59 +0100 | [diff] [blame] | 160 | printf(" NFQUEUE num %u", tinfo->queuenum); |
Harald Welte | daa1ef3 | 2005-07-19 21:44:58 +0000 | [diff] [blame] | 161 | } |
| 162 | |
Florian Westphal | 4282d89 | 2009-08-20 16:39:05 +0200 | [diff] [blame] | 163 | static void NFQUEUE_print_v1(const void *ip, |
| 164 | const struct xt_entry_target *target, int numeric) |
| 165 | { |
| 166 | const struct xt_NFQ_info_v1 *tinfo = (const void *)target->data; |
| 167 | unsigned int last = tinfo->queues_total; |
| 168 | |
| 169 | if (last > 1) { |
| 170 | last += tinfo->queuenum - 1; |
Jan Engelhardt | 7386635 | 2010-12-18 02:04:59 +0100 | [diff] [blame] | 171 | printf(" NFQUEUE balance %u:%u", tinfo->queuenum, last); |
Florian Westphal | 4282d89 | 2009-08-20 16:39:05 +0200 | [diff] [blame] | 172 | } else { |
Jan Engelhardt | 7386635 | 2010-12-18 02:04:59 +0100 | [diff] [blame] | 173 | printf(" NFQUEUE num %u", tinfo->queuenum); |
Florian Westphal | 4282d89 | 2009-08-20 16:39:05 +0200 | [diff] [blame] | 174 | } |
| 175 | } |
| 176 | |
Florian Westphal | 6924b49 | 2011-01-20 11:27:42 +0100 | [diff] [blame] | 177 | static void NFQUEUE_print_v2(const void *ip, |
| 178 | const struct xt_entry_target *target, int numeric) |
| 179 | { |
| 180 | const struct xt_NFQ_info_v2 *info = (void *) target->data; |
Shivani Bhardwaj | d998de7 | 2016-04-14 20:56:49 +0530 | [diff] [blame] | 181 | unsigned int last = info->queues_total; |
Florian Westphal | 6924b49 | 2011-01-20 11:27:42 +0100 | [diff] [blame] | 182 | |
Shivani Bhardwaj | d998de7 | 2016-04-14 20:56:49 +0530 | [diff] [blame] | 183 | if (last > 1) { |
| 184 | last += info->queuenum - 1; |
| 185 | printf(" NFQUEUE balance %u:%u", info->queuenum, last); |
| 186 | } else |
| 187 | printf(" NFQUEUE num %u", info->queuenum); |
| 188 | |
holger@eitzenberger.org | ce7d061 | 2013-04-02 00:35:39 +0000 | [diff] [blame] | 189 | if (info->bypass & NFQ_FLAG_BYPASS) |
Florian Westphal | 6924b49 | 2011-01-20 11:27:42 +0100 | [diff] [blame] | 190 | printf(" bypass"); |
| 191 | } |
| 192 | |
holger@eitzenberger.org | ce7d061 | 2013-04-02 00:35:39 +0000 | [diff] [blame] | 193 | static void NFQUEUE_print_v3(const void *ip, |
| 194 | const struct xt_entry_target *target, int numeric) |
| 195 | { |
| 196 | const struct xt_NFQ_info_v3 *info = (void *)target->data; |
Shivani Bhardwaj | d998de7 | 2016-04-14 20:56:49 +0530 | [diff] [blame] | 197 | unsigned int last = info->queues_total; |
holger@eitzenberger.org | ce7d061 | 2013-04-02 00:35:39 +0000 | [diff] [blame] | 198 | |
Shivani Bhardwaj | d998de7 | 2016-04-14 20:56:49 +0530 | [diff] [blame] | 199 | if (last > 1) { |
| 200 | last += info->queuenum - 1; |
| 201 | printf(" NFQUEUE balance %u:%u", info->queuenum, last); |
| 202 | } else |
| 203 | printf(" NFQUEUE num %u", info->queuenum); |
| 204 | |
| 205 | if (info->flags & NFQ_FLAG_BYPASS) |
| 206 | printf(" bypass"); |
| 207 | |
holger@eitzenberger.org | ce7d061 | 2013-04-02 00:35:39 +0000 | [diff] [blame] | 208 | if (info->flags & NFQ_FLAG_CPU_FANOUT) |
| 209 | printf(" cpu-fanout"); |
| 210 | } |
| 211 | |
Jan Engelhardt | 932e648 | 2007-10-04 16:27:30 +0000 | [diff] [blame] | 212 | static void NFQUEUE_save(const void *ip, const struct xt_entry_target *target) |
Harald Welte | daa1ef3 | 2005-07-19 21:44:58 +0000 | [diff] [blame] | 213 | { |
Yasuyuki KOZAKAI | a2e89cc | 2007-07-24 07:29:36 +0000 | [diff] [blame] | 214 | const struct xt_NFQ_info *tinfo = |
| 215 | (const struct xt_NFQ_info *)target->data; |
Harald Welte | daa1ef3 | 2005-07-19 21:44:58 +0000 | [diff] [blame] | 216 | |
Jan Engelhardt | 7386635 | 2010-12-18 02:04:59 +0100 | [diff] [blame] | 217 | printf(" --queue-num %u", tinfo->queuenum); |
Harald Welte | daa1ef3 | 2005-07-19 21:44:58 +0000 | [diff] [blame] | 218 | } |
| 219 | |
Florian Westphal | 4282d89 | 2009-08-20 16:39:05 +0200 | [diff] [blame] | 220 | static void NFQUEUE_save_v1(const void *ip, const struct xt_entry_target *target) |
| 221 | { |
| 222 | const struct xt_NFQ_info_v1 *tinfo = (const void *)target->data; |
| 223 | unsigned int last = tinfo->queues_total; |
| 224 | |
| 225 | if (last > 1) { |
| 226 | last += tinfo->queuenum - 1; |
Jan Engelhardt | 7386635 | 2010-12-18 02:04:59 +0100 | [diff] [blame] | 227 | printf(" --queue-balance %u:%u", tinfo->queuenum, last); |
Florian Westphal | 4282d89 | 2009-08-20 16:39:05 +0200 | [diff] [blame] | 228 | } else { |
Jan Engelhardt | 7386635 | 2010-12-18 02:04:59 +0100 | [diff] [blame] | 229 | printf(" --queue-num %u", tinfo->queuenum); |
Florian Westphal | 4282d89 | 2009-08-20 16:39:05 +0200 | [diff] [blame] | 230 | } |
| 231 | } |
| 232 | |
Florian Westphal | 6924b49 | 2011-01-20 11:27:42 +0100 | [diff] [blame] | 233 | static void NFQUEUE_save_v2(const void *ip, const struct xt_entry_target *target) |
| 234 | { |
| 235 | const struct xt_NFQ_info_v2 *info = (void *) target->data; |
Shivani Bhardwaj | d998de7 | 2016-04-14 20:56:49 +0530 | [diff] [blame] | 236 | unsigned int last = info->queues_total; |
Florian Westphal | 6924b49 | 2011-01-20 11:27:42 +0100 | [diff] [blame] | 237 | |
Shivani Bhardwaj | d998de7 | 2016-04-14 20:56:49 +0530 | [diff] [blame] | 238 | if (last > 1) { |
| 239 | last += info->queuenum - 1; |
| 240 | printf(" --queue-balance %u:%u", info->queuenum, last); |
| 241 | } else |
| 242 | printf(" --queue-num %u", info->queuenum); |
Florian Westphal | 6924b49 | 2011-01-20 11:27:42 +0100 | [diff] [blame] | 243 | |
holger@eitzenberger.org | ce7d061 | 2013-04-02 00:35:39 +0000 | [diff] [blame] | 244 | if (info->bypass & NFQ_FLAG_BYPASS) |
Florian Westphal | 3c461ce | 2011-10-31 16:10:57 +0100 | [diff] [blame] | 245 | printf(" --queue-bypass"); |
Florian Westphal | 6924b49 | 2011-01-20 11:27:42 +0100 | [diff] [blame] | 246 | } |
| 247 | |
holger@eitzenberger.org | ce7d061 | 2013-04-02 00:35:39 +0000 | [diff] [blame] | 248 | static void NFQUEUE_save_v3(const void *ip, |
| 249 | const struct xt_entry_target *target) |
| 250 | { |
| 251 | const struct xt_NFQ_info_v3 *info = (void *)target->data; |
Shivani Bhardwaj | d998de7 | 2016-04-14 20:56:49 +0530 | [diff] [blame] | 252 | unsigned int last = info->queues_total; |
holger@eitzenberger.org | ce7d061 | 2013-04-02 00:35:39 +0000 | [diff] [blame] | 253 | |
Shivani Bhardwaj | d998de7 | 2016-04-14 20:56:49 +0530 | [diff] [blame] | 254 | if (last > 1) { |
| 255 | last += info->queuenum - 1; |
| 256 | printf(" --queue-balance %u:%u", info->queuenum, last); |
| 257 | } else |
| 258 | printf(" --queue-num %u", info->queuenum); |
| 259 | |
| 260 | if (info->flags & NFQ_FLAG_BYPASS) |
| 261 | printf(" --queue-bypass"); |
| 262 | |
holger@eitzenberger.org | ce7d061 | 2013-04-02 00:35:39 +0000 | [diff] [blame] | 263 | if (info->flags & NFQ_FLAG_CPU_FANOUT) |
| 264 | printf(" --queue-cpu-fanout"); |
| 265 | } |
| 266 | |
Florian Westphal | 4282d89 | 2009-08-20 16:39:05 +0200 | [diff] [blame] | 267 | static void NFQUEUE_init_v1(struct xt_entry_target *t) |
| 268 | { |
| 269 | struct xt_NFQ_info_v1 *tinfo = (void *)t->data; |
| 270 | tinfo->queues_total = 1; |
| 271 | } |
| 272 | |
Pablo Neira Ayuso | 7a0992d | 2016-07-24 12:45:53 +0200 | [diff] [blame] | 273 | static int NFQUEUE_xlate(struct xt_xlate *xl, |
| 274 | const struct xt_xlate_tg_params *params) |
Shivani Bhardwaj | 3bc0951 | 2016-02-09 14:23:10 +0530 | [diff] [blame] | 275 | { |
| 276 | const struct xt_NFQ_info *tinfo = |
Pablo Neira Ayuso | 7a0992d | 2016-07-24 12:45:53 +0200 | [diff] [blame] | 277 | (const struct xt_NFQ_info *)params->target->data; |
Shivani Bhardwaj | 3bc0951 | 2016-02-09 14:23:10 +0530 | [diff] [blame] | 278 | |
| 279 | xt_xlate_add(xl, "queue num %u ", tinfo->queuenum); |
| 280 | |
| 281 | return 1; |
| 282 | } |
| 283 | |
Pablo Neira Ayuso | 7a0992d | 2016-07-24 12:45:53 +0200 | [diff] [blame] | 284 | static int NFQUEUE_xlate_v1(struct xt_xlate *xl, |
| 285 | const struct xt_xlate_tg_params *params) |
Shivani Bhardwaj | 3bc0951 | 2016-02-09 14:23:10 +0530 | [diff] [blame] | 286 | { |
Pablo Neira Ayuso | 7a0992d | 2016-07-24 12:45:53 +0200 | [diff] [blame] | 287 | const struct xt_NFQ_info_v1 *tinfo = (const void *)params->target->data; |
Shivani Bhardwaj | 3bc0951 | 2016-02-09 14:23:10 +0530 | [diff] [blame] | 288 | unsigned int last = tinfo->queues_total; |
| 289 | |
| 290 | if (last > 1) { |
| 291 | last += tinfo->queuenum - 1; |
| 292 | xt_xlate_add(xl, "queue num %u-%u ", tinfo->queuenum, last); |
| 293 | } else { |
| 294 | xt_xlate_add(xl, "queue num %u ", tinfo->queuenum); |
| 295 | } |
| 296 | |
| 297 | return 1; |
| 298 | } |
| 299 | |
Pablo Neira Ayuso | 7a0992d | 2016-07-24 12:45:53 +0200 | [diff] [blame] | 300 | static int NFQUEUE_xlate_v2(struct xt_xlate *xl, |
| 301 | const struct xt_xlate_tg_params *params) |
Shivani Bhardwaj | 3bc0951 | 2016-02-09 14:23:10 +0530 | [diff] [blame] | 302 | { |
Pablo Neira Ayuso | 7a0992d | 2016-07-24 12:45:53 +0200 | [diff] [blame] | 303 | const struct xt_NFQ_info_v2 *info = (void *)params->target->data; |
Shivani Bhardwaj | d998de7 | 2016-04-14 20:56:49 +0530 | [diff] [blame] | 304 | unsigned int last = info->queues_total; |
Shivani Bhardwaj | 3bc0951 | 2016-02-09 14:23:10 +0530 | [diff] [blame] | 305 | |
Shivani Bhardwaj | d998de7 | 2016-04-14 20:56:49 +0530 | [diff] [blame] | 306 | if (last > 1) { |
| 307 | last += info->queuenum - 1; |
| 308 | xt_xlate_add(xl, "queue num %u-%u ", info->queuenum, last); |
| 309 | } else |
| 310 | xt_xlate_add(xl, "queue num %u ", info->queuenum); |
Shivani Bhardwaj | 3bc0951 | 2016-02-09 14:23:10 +0530 | [diff] [blame] | 311 | |
| 312 | if (info->bypass & NFQ_FLAG_BYPASS) |
| 313 | xt_xlate_add(xl, "bypass"); |
| 314 | |
| 315 | return 1; |
| 316 | } |
| 317 | |
Pablo Neira Ayuso | 7a0992d | 2016-07-24 12:45:53 +0200 | [diff] [blame] | 318 | static int NFQUEUE_xlate_v3(struct xt_xlate *xl, |
| 319 | const struct xt_xlate_tg_params *params) |
Shivani Bhardwaj | 3bc0951 | 2016-02-09 14:23:10 +0530 | [diff] [blame] | 320 | { |
Pablo Neira Ayuso | 7a0992d | 2016-07-24 12:45:53 +0200 | [diff] [blame] | 321 | const struct xt_NFQ_info_v3 *info = (void *)params->target->data; |
Shivani Bhardwaj | d998de7 | 2016-04-14 20:56:49 +0530 | [diff] [blame] | 322 | unsigned int last = info->queues_total; |
Shivani Bhardwaj | 3bc0951 | 2016-02-09 14:23:10 +0530 | [diff] [blame] | 323 | |
Shivani Bhardwaj | d998de7 | 2016-04-14 20:56:49 +0530 | [diff] [blame] | 324 | if (last > 1) { |
| 325 | last += info->queuenum - 1; |
| 326 | xt_xlate_add(xl, "queue num %u-%u ", info->queuenum, last); |
| 327 | } else |
| 328 | xt_xlate_add(xl, "queue num %u ", info->queuenum); |
| 329 | |
| 330 | if (info->flags & NFQ_FLAG_BYPASS) |
| 331 | xt_xlate_add(xl, "bypass"); |
| 332 | |
Shivani Bhardwaj | 3bc0951 | 2016-02-09 14:23:10 +0530 | [diff] [blame] | 333 | if (info->flags & NFQ_FLAG_CPU_FANOUT) |
Shivani Bhardwaj | d998de7 | 2016-04-14 20:56:49 +0530 | [diff] [blame] | 334 | xt_xlate_add(xl, "%sfanout ", |
| 335 | info->flags & NFQ_FLAG_BYPASS ? "," : ""); |
Shivani Bhardwaj | 3bc0951 | 2016-02-09 14:23:10 +0530 | [diff] [blame] | 336 | |
| 337 | return 1; |
| 338 | } |
| 339 | |
Florian Westphal | 6924b49 | 2011-01-20 11:27:42 +0100 | [diff] [blame] | 340 | static struct xtables_target nfqueue_targets[] = { |
| 341 | { |
Jan Engelhardt | c5e8573 | 2009-06-12 20:55:44 +0200 | [diff] [blame] | 342 | .family = NFPROTO_UNSPEC, |
Harald Welte | daa1ef3 | 2005-07-19 21:44:58 +0000 | [diff] [blame] | 343 | .name = "NFQUEUE", |
Jan Engelhardt | 8b7c64d | 2008-04-15 11:48:25 +0200 | [diff] [blame] | 344 | .version = XTABLES_VERSION, |
Yasuyuki KOZAKAI | a2e89cc | 2007-07-24 07:29:36 +0000 | [diff] [blame] | 345 | .size = XT_ALIGN(sizeof(struct xt_NFQ_info)), |
| 346 | .userspacesize = XT_ALIGN(sizeof(struct xt_NFQ_info)), |
Jan Engelhardt | 932e648 | 2007-10-04 16:27:30 +0000 | [diff] [blame] | 347 | .help = NFQUEUE_help, |
Jan Engelhardt | 932e648 | 2007-10-04 16:27:30 +0000 | [diff] [blame] | 348 | .print = NFQUEUE_print, |
| 349 | .save = NFQUEUE_save, |
Jan Engelhardt | 478be25 | 2011-03-06 17:54:50 +0100 | [diff] [blame] | 350 | .x6_parse = NFQUEUE_parse, |
Shivani Bhardwaj | 3bc0951 | 2016-02-09 14:23:10 +0530 | [diff] [blame] | 351 | .x6_options = NFQUEUE_opts, |
| 352 | .xlate = NFQUEUE_xlate, |
Florian Westphal | 6924b49 | 2011-01-20 11:27:42 +0100 | [diff] [blame] | 353 | },{ |
Florian Westphal | 4282d89 | 2009-08-20 16:39:05 +0200 | [diff] [blame] | 354 | .family = NFPROTO_UNSPEC, |
| 355 | .revision = 1, |
| 356 | .name = "NFQUEUE", |
| 357 | .version = XTABLES_VERSION, |
| 358 | .size = XT_ALIGN(sizeof(struct xt_NFQ_info_v1)), |
| 359 | .userspacesize = XT_ALIGN(sizeof(struct xt_NFQ_info_v1)), |
| 360 | .help = NFQUEUE_help_v1, |
| 361 | .init = NFQUEUE_init_v1, |
Florian Westphal | 4282d89 | 2009-08-20 16:39:05 +0200 | [diff] [blame] | 362 | .print = NFQUEUE_print_v1, |
| 363 | .save = NFQUEUE_save_v1, |
Jan Engelhardt | 478be25 | 2011-03-06 17:54:50 +0100 | [diff] [blame] | 364 | .x6_parse = NFQUEUE_parse_v1, |
| 365 | .x6_options = NFQUEUE_opts, |
Shivani Bhardwaj | 3bc0951 | 2016-02-09 14:23:10 +0530 | [diff] [blame] | 366 | .xlate = NFQUEUE_xlate_v1, |
Florian Westphal | 6924b49 | 2011-01-20 11:27:42 +0100 | [diff] [blame] | 367 | },{ |
| 368 | .family = NFPROTO_UNSPEC, |
| 369 | .revision = 2, |
| 370 | .name = "NFQUEUE", |
| 371 | .version = XTABLES_VERSION, |
| 372 | .size = XT_ALIGN(sizeof(struct xt_NFQ_info_v2)), |
| 373 | .userspacesize = XT_ALIGN(sizeof(struct xt_NFQ_info_v2)), |
| 374 | .help = NFQUEUE_help_v2, |
| 375 | .init = NFQUEUE_init_v1, |
Florian Westphal | 6924b49 | 2011-01-20 11:27:42 +0100 | [diff] [blame] | 376 | .print = NFQUEUE_print_v2, |
| 377 | .save = NFQUEUE_save_v2, |
Jan Engelhardt | 478be25 | 2011-03-06 17:54:50 +0100 | [diff] [blame] | 378 | .x6_parse = NFQUEUE_parse_v2, |
| 379 | .x6_options = NFQUEUE_opts, |
Shivani Bhardwaj | 3bc0951 | 2016-02-09 14:23:10 +0530 | [diff] [blame] | 380 | .xlate = NFQUEUE_xlate_v2, |
holger@eitzenberger.org | ce7d061 | 2013-04-02 00:35:39 +0000 | [diff] [blame] | 381 | },{ |
| 382 | .family = NFPROTO_UNSPEC, |
| 383 | .revision = 3, |
| 384 | .name = "NFQUEUE", |
| 385 | .version = XTABLES_VERSION, |
| 386 | .size = XT_ALIGN(sizeof(struct xt_NFQ_info_v3)), |
| 387 | .userspacesize = XT_ALIGN(sizeof(struct xt_NFQ_info_v3)), |
| 388 | .help = NFQUEUE_help_v3, |
| 389 | .init = NFQUEUE_init_v1, |
| 390 | .print = NFQUEUE_print_v3, |
| 391 | .save = NFQUEUE_save_v3, |
| 392 | .x6_parse = NFQUEUE_parse_v3, |
| 393 | .x6_options = NFQUEUE_opts, |
Shivani Bhardwaj | 3bc0951 | 2016-02-09 14:23:10 +0530 | [diff] [blame] | 394 | .xlate = NFQUEUE_xlate_v3, |
Florian Westphal | 6924b49 | 2011-01-20 11:27:42 +0100 | [diff] [blame] | 395 | } |
Florian Westphal | 4282d89 | 2009-08-20 16:39:05 +0200 | [diff] [blame] | 396 | }; |
| 397 | |
Harald Welte | daa1ef3 | 2005-07-19 21:44:58 +0000 | [diff] [blame] | 398 | void _init(void) |
| 399 | { |
Florian Westphal | 6924b49 | 2011-01-20 11:27:42 +0100 | [diff] [blame] | 400 | xtables_register_targets(nfqueue_targets, ARRAY_SIZE(nfqueue_targets)); |
Harald Welte | daa1ef3 | 2005-07-19 21:44:58 +0000 | [diff] [blame] | 401 | } |