/* Shared library add-on to iptables to add VLAN address support. */ #include #include #include #include #include #if defined(__GLIBC__) && __GLIBC__ == 2 #include #else #include #endif #include #include /* Function which prints out usage message. */ static void help(void) { printf( "VLAN v%s options:\n" " --vlan [!] \n" " Match source VLAN id\n" "\n", IPTABLES_VERSION); } static struct option opts[] = { { "vlan", 1, 0, '1' }, {0} }; /* Function which parses command options; returns true if it ate an option */ static int parse(int c, char **argv, int invert, unsigned int *flags, const struct ipt_entry *entry, unsigned int *nfcache, struct ipt_entry_match **match) { struct ipt_vlan_info *vlaninfo = (struct ipt_vlan_info *)(*match)->data; switch (c) { case '1': check_inverse(optarg, &invert, &optind, 0); vlaninfo->vlan=atoi(argv[optind-1]); if (invert) vlaninfo->invert = 1; *flags = 1; break; default: return 0; } return 1; } /* Final check; must have specified --vlan. */ static void final_check(unsigned int flags) { if (!flags) exit_error(PARAMETER_PROBLEM, "You must specify `--vlan'"); } /* Prints out the matchinfo. */ static void print(const struct ipt_ip *ip, const struct ipt_entry_match *match, int numeric) { printf("vlan "); if (((struct ipt_vlan_info *)match->data)->invert) printf("! "); printf("%d ",((struct ipt_vlan_info *)match->data)->vlan); } /* Saves the union ipt_matchinfo in parsable form to stdout. */ static void save(const struct ipt_ip *ip, const struct ipt_entry_match *match) { if (((struct ipt_vlan_info *)match->data)->invert) printf("! "); printf("--vlan %d ",((struct ipt_vlan_info *)match->data)->vlan); } static struct iptables_match vlan = { .next = NULL, .name = "vlan", .version = IPTABLES_VERSION, .size = IPT_ALIGN(sizeof(struct ipt_vlan_info)), .userspacesize = IPT_ALIGN(sizeof(struct ipt_vlan_info)), .help = &help, .parse = &parse, .final_check = &final_check, .print = &print, .save = &save, .extra_opts = opts }; void _init(void) { register_match(&vlan); }