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/x_tables.h> 9#include <linux/netfilter/xt_IMQ.h> 10 11/* Function which prints out usage message. */ 12static void IMQ_help(void) 13{ 14 printf( 15"IMQ target options:\n" 16" --todev <N> enqueue to imq<N>, defaults to 0\n"); 17 18} 19 20static struct option IMQ_opts[] = { 21 { "todev", 1, 0, '1' }, 22 { 0 } 23}; 24 25/* Initialize the target. */ 26static void IMQ_init(struct xt_entry_target *t) 27{ 28 struct xt_imq_info *mr = (struct xt_imq_info*)t->data; 29 30 mr->todev = 0; 31} 32 33/* Function which parses command options; returns true if it 34 ate an option */ 35static int IMQ_parse(int c, char **argv, int invert, unsigned int *flags, 36 const void *entry, struct xt_entry_target **target) 37{ 38 struct xt_imq_info *mr = (struct xt_imq_info*)(*target)->data; 39 40 switch(c) { 41 case '1': 42/* if (xtables_check_inverse(optarg, &invert, NULL, 0, argv)) 43 xtables_error(PARAMETER_PROBLEM, 44 "Unexpected `!' after --todev"); 45*/ 46 mr->todev=atoi(optarg); 47 break; 48 49 default: 50 return 0; 51 } 52 return 1; 53} 54 55/* Prints out the targinfo. */ 56static void IMQ_print(const void *ip, 57 const struct xt_entry_target *target, 58 int numeric) 59{ 60 struct xt_imq_info *mr = (struct xt_imq_info*)target->data; 61 62 printf("IMQ: todev %u ", mr->todev); 63} 64 65/* Saves the union ipt_targinfo in parsable form to stdout. */ 66static void IMQ_save(const void *ip, const struct xt_entry_target *target) 67{ 68 struct xt_imq_info *mr = (struct xt_imq_info*)target->data; 69 70 printf(" --todev %u", mr->todev); 71} 72 73static struct xtables_target imq_target = { 74 .name = "IMQ", 75 .version = XTABLES_VERSION, 76 .family = NFPROTO_IPV4, 77 .size = XT_ALIGN(sizeof(struct xt_imq_info)), 78 .userspacesize = XT_ALIGN(sizeof(struct xt_imq_info)), 79 .help = IMQ_help, 80 .init = IMQ_init, 81 .parse = IMQ_parse, 82 .print = IMQ_print, 83 .save = IMQ_save, 84 .extra_opts = IMQ_opts, 85}; 86 87static struct xtables_target imq_target6 = { 88 .name = "IMQ", 89 .version = XTABLES_VERSION, 90 .family = NFPROTO_IPV6, 91 .size = XT_ALIGN(sizeof(struct xt_imq_info)), 92 .userspacesize = XT_ALIGN(sizeof(struct xt_imq_info)), 93 .help = IMQ_help, 94 .init = IMQ_init, 95 .parse = IMQ_parse, 96 .print = IMQ_print, 97 .save = IMQ_save, 98 .extra_opts = IMQ_opts, 99}; 100 101// void __attribute((constructor)) nf_ext_init(void){ 102void _init(void){ 103 xtables_register_target(&imq_target); 104 xtables_register_target(&imq_target6); 105} 106