1 /* Shared library add-on to iptables to add realm matching support. */
7 #if defined(__GLIBC__) && __GLIBC__ == 2
8 #include <net/ethernet.h>
10 #include <linux/if_ether.h>
13 #include <linux/netfilter_ipv4/ipt_realm.h>
15 /* Function which prints out usage message. */
20 "REALM v%s options:\n"
21 " --realm [!] value[/mask]\n"
23 "\n", IPTABLES_VERSION);
26 static struct option opts[] = {
27 { "realm", 1, 0, '1' },
31 /* Initialize the match. */
33 init(struct ipt_entry_match *m, unsigned int *nfcache)
35 /* Can't cache this */
36 *nfcache |= NFC_UNKNOWN;
39 /* Function which parses command options; returns true if it
42 parse(int c, char **argv, int invert, unsigned int *flags,
43 const struct ipt_entry *entry,
44 unsigned int *nfcache,
45 struct ipt_entry_match **match)
47 struct ipt_realm_info *realminfo = (struct ipt_realm_info *)(*match)->data;
52 check_inverse(optarg, &invert, &optind, 0);
53 realminfo->id = strtoul(optarg, &end, 0);
55 realminfo->mask = strtoul(end+1, &end, 0);
57 realminfo->mask = 0xffffffff;
58 if (*end != '\0' || end == optarg)
59 exit_error(PARAMETER_PROBLEM, "Bad REALM value `%s'", optarg);
61 realminfo->invert = 1;
72 print_realm(unsigned long id, unsigned long mask, int invert, int numeric)
77 if(mask != 0xffffffff)
78 printf("0x%lx/0x%lx ", id, mask);
83 /* Prints out the matchinfo. */
85 print(const struct ipt_ip *ip,
86 const struct ipt_entry_match *match,
89 printf("REALM match ");
90 print_realm(((struct ipt_realm_info *)match->data)->id,
91 ((struct ipt_realm_info *)match->data)->mask,
92 ((struct ipt_realm_info *)match->data)->invert, numeric);
96 /* Saves the union ipt_matchinfo in parsable form to stdout. */
98 save(const struct ipt_ip *ip, const struct ipt_entry_match *match)
101 print_realm(((struct ipt_realm_info *)match->data)->id,
102 ((struct ipt_realm_info *)match->data)->mask,
103 ((struct ipt_realm_info *)match->data)->invert, 0);
106 /* Final check; must have specified --mark. */
108 final_check(unsigned int flags)
111 exit_error(PARAMETER_PROBLEM,
112 "REALM match: You must specify `--realm'");
115 struct iptables_match realm
119 IPT_ALIGN(sizeof(struct ipt_realm_info)),
120 IPT_ALIGN(sizeof(struct ipt_realm_info)),
132 register_match(&realm);