lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 1 | /* Shared library add-on to iptables to add IMQ target support. */ |
| 2 | #include <stdio.h> |
| 3 | #include <string.h> |
| 4 | #include <stdlib.h> |
| 5 | #include <getopt.h> |
| 6 | |
| 7 | #include <xtables.h> |
| 8 | #include <linux/netfilter_ipv4/ipt_IMQ.h> |
| 9 | |
| 10 | static void |
| 11 | help(void) |
| 12 | { |
| 13 | printf( |
| 14 | "IMQ target options:\n" |
| 15 | " --todev <N> enqueue to imq<N>, defaults to 0\n"); |
| 16 | } |
| 17 | |
| 18 | static struct option opts[] = { |
| 19 | { "todev", 1, 0, '1' }, |
| 20 | { .name = NULL } |
| 21 | }; |
| 22 | |
| 23 | static void |
| 24 | init(struct xt_entry_target *t) |
| 25 | { |
| 26 | struct ipt_imq_info *mr = (struct ipt_imq_info*)t->data; |
| 27 | |
| 28 | mr->todev = 0; |
| 29 | } |
| 30 | |
| 31 | static int |
| 32 | parse(int c, char **argv, int invert, unsigned int *flags, |
| 33 | const void *entry, |
| 34 | struct xt_entry_target **target) |
| 35 | { |
| 36 | struct ipt_imq_info *mr = (struct ipt_imq_info*)(*target)->data; |
| 37 | |
| 38 | switch(c) { |
| 39 | case '1': |
| 40 | if (xtables_check_inverse(optarg, &invert, NULL, 0)) |
| 41 | xtables_error(PARAMETER_PROBLEM, |
| 42 | "Unexpected `!' after --todev"); |
| 43 | mr->todev=atoi(optarg); |
| 44 | break; |
| 45 | default: |
| 46 | return 0; |
| 47 | } |
| 48 | return 1; |
| 49 | } |
| 50 | |
| 51 | static void |
| 52 | final_check(unsigned int flags) |
| 53 | { |
| 54 | } |
| 55 | |
| 56 | static void |
| 57 | print(const void *ip, |
| 58 | const struct xt_entry_target *target, |
| 59 | int numeric) |
| 60 | { |
| 61 | struct ipt_imq_info *mr = (struct ipt_imq_info*)target->data; |
| 62 | |
| 63 | printf("IMQ: todev %u ", mr->todev); |
| 64 | } |
| 65 | |
| 66 | static void |
| 67 | save(const void *ip, const struct xt_entry_target *target) |
| 68 | { |
| 69 | struct ipt_imq_info *mr = (struct ipt_imq_info*)target->data; |
| 70 | |
| 71 | printf("--todev %u", mr->todev); |
| 72 | } |
| 73 | |
| 74 | static |
| 75 | struct xtables_target imq |
| 76 | = { |
| 77 | .name = "IMQ", |
| 78 | .version = XTABLES_VERSION, |
| 79 | .family = NFPROTO_IPV4, |
| 80 | .size = XT_ALIGN(sizeof(struct ipt_imq_info)), |
| 81 | .userspacesize = XT_ALIGN(sizeof(struct ipt_imq_info)), |
| 82 | .help = &help, |
| 83 | .init = &init, |
| 84 | .parse = &parse, |
| 85 | .final_check = &final_check, |
| 86 | .print = &print, |
| 87 | .save = &save, |
| 88 | .extra_opts = opts |
| 89 | }; |
| 90 | |
| 91 | void _init(void) |
| 92 | { |
| 93 | xtables_register_target(&imq); |
| 94 | } |