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 <ip6tables.h> |
| 8 | #include <linux/netfilter_ipv6/ip6_tables.h> |
| 9 | #include <linux/netfilter_ipv6/ip6t_IMQ.h> |
| 10 | |
| 11 | /* Function which prints out usage message. */ |
| 12 | static void |
| 13 | help(void) |
| 14 | { |
| 15 | printf( |
| 16 | "IMQ target v%s options:\n" |
| 17 | " --todev <N> enqueue to imq<N>, defaults to 0\n", |
| 18 | IPTABLES_VERSION); |
| 19 | } |
| 20 | |
| 21 | static struct option opts[] = { |
| 22 | { "todev", 1, 0, '1' }, |
| 23 | { 0 } |
| 24 | }; |
| 25 | |
| 26 | /* Initialize the target. */ |
| 27 | static void |
| 28 | init(struct ip6t_entry_target *t, unsigned int *nfcache) |
| 29 | { |
| 30 | struct ip6t_imq_info *mr = (struct ip6t_imq_info*)t->data; |
| 31 | |
| 32 | mr->todev = 0; |
| 33 | *nfcache |= NFC_UNKNOWN; |
| 34 | } |
| 35 | |
| 36 | /* Function which parses command options; returns true if it |
| 37 | ate an option */ |
| 38 | static int |
| 39 | parse(int c, char **argv, int invert, unsigned int *flags, |
| 40 | const struct ip6t_entry *entry, |
| 41 | struct ip6t_entry_target **target) |
| 42 | { |
| 43 | struct ip6t_imq_info *mr = (struct ip6t_imq_info*)(*target)->data; |
| 44 | |
| 45 | switch(c) { |
| 46 | case '1': |
| 47 | if (check_inverse(optarg, &invert, NULL, 0)) |
| 48 | exit_error(PARAMETER_PROBLEM, |
| 49 | "Unexpected `!' after --todev"); |
| 50 | mr->todev=atoi(optarg); |
| 51 | break; |
| 52 | default: |
| 53 | return 0; |
| 54 | } |
| 55 | return 1; |
| 56 | } |
| 57 | |
| 58 | static void |
| 59 | final_check(unsigned int flags) |
| 60 | { |
| 61 | } |
| 62 | |
| 63 | /* Prints out the targinfo. */ |
| 64 | static void |
| 65 | print(const struct ip6t_ip6 *ip, |
| 66 | const struct ip6t_entry_target *target, |
| 67 | int numeric) |
| 68 | { |
| 69 | struct ip6t_imq_info *mr = (struct ip6t_imq_info*)target->data; |
| 70 | |
| 71 | printf("IMQ: todev %u ", mr->todev); |
| 72 | } |
| 73 | |
| 74 | /* Saves the union ipt_targinfo in parsable form to stdout. */ |
| 75 | static void |
| 76 | save(const struct ip6t_ip6 *ip, const struct ip6t_entry_target *target) |
| 77 | { |
| 78 | struct ip6t_imq_info *mr = (struct ip6t_imq_info*)target->data; |
| 79 | |
| 80 | printf("--todev %u", mr->todev); |
| 81 | } |
| 82 | |
| 83 | static |
| 84 | struct ip6tables_target imq |
| 85 | = { NULL, |
| 86 | "IMQ", |
| 87 | IPTABLES_VERSION, |
| 88 | IP6T_ALIGN(sizeof(struct ip6t_imq_info)), |
| 89 | IP6T_ALIGN(sizeof(struct ip6t_imq_info)), |
| 90 | &help, |
| 91 | &init, |
| 92 | &parse, |
| 93 | &final_check, |
| 94 | &print, |
| 95 | &save, |
| 96 | opts |
| 97 | }; |
| 98 | |
| 99 | void _init(void) |
| 100 | { |
| 101 | register_target6(&imq); |
| 102 | } |