1 /* Shared library add-on to iptables to add AH support. */
9 #include <linux/netfilter_ipv4/ipt_ah.h>
11 static void ah_help(void)
15 "[!] --ahspi spi[:spi]\n"
16 " match spi (range)\n");
19 static const struct option ah_opts[] = {
20 { "ahspi", 1, NULL, '1' },
25 parse_ah_spi(const char *spistr)
27 unsigned long int spi;
30 spi = strtoul(spistr,&ep,0) ;
33 xtables_error(PARAMETER_PROBLEM,
34 "AH no valid digits in spi `%s'", spistr);
36 if ( spi == ULONG_MAX && errno == ERANGE ) {
37 xtables_error(PARAMETER_PROBLEM,
38 "spi `%s' specified too big: would overflow", spistr);
40 if ( *spistr != '\0' && *ep != '\0' ) {
41 xtables_error(PARAMETER_PROBLEM,
42 "AH error parsing spi `%s'", spistr);
48 parse_ah_spis(const char *spistring, u_int32_t *spis)
53 buffer = strdup(spistring);
54 if ((cp = strchr(buffer, ':')) == NULL)
55 spis[0] = spis[1] = parse_ah_spi(buffer);
60 spis[0] = buffer[0] ? parse_ah_spi(buffer) : 0;
61 spis[1] = cp[0] ? parse_ah_spi(cp) : 0xFFFFFFFF;
66 static void ah_init(struct xt_entry_match *m)
68 struct ipt_ah *ahinfo = (struct ipt_ah *)m->data;
70 ahinfo->spis[1] = 0xFFFFFFFF;
75 static int ah_parse(int c, char **argv, int invert, unsigned int *flags,
76 const void *entry, struct xt_entry_match **match)
78 struct ipt_ah *ahinfo = (struct ipt_ah *)(*match)->data;
83 xtables_error(PARAMETER_PROBLEM,
84 "Only one `--ahspi' allowed");
85 xtables_check_inverse(optarg, &invert, &optind, 0, argv);
86 parse_ah_spis(optarg, ahinfo->spis);
88 ahinfo->invflags |= IPT_AH_INV_SPI;
99 print_spis(const char *name, u_int32_t min, u_int32_t max,
102 const char *inv = invert ? "!" : "";
104 if (min != 0 || max != 0xFFFFFFFF || invert) {
119 static void ah_print(const void *ip, const struct xt_entry_match *match,
122 const struct ipt_ah *ah = (struct ipt_ah *)match->data;
125 print_spis("spi", ah->spis[0], ah->spis[1],
126 ah->invflags & IPT_AH_INV_SPI);
127 if (ah->invflags & ~IPT_AH_INV_MASK)
128 printf("Unknown invflags: 0x%X ",
129 ah->invflags & ~IPT_AH_INV_MASK);
132 static void ah_save(const void *ip, const struct xt_entry_match *match)
134 const struct ipt_ah *ahinfo = (struct ipt_ah *)match->data;
136 if (!(ahinfo->spis[0] == 0
137 && ahinfo->spis[1] == 0xFFFFFFFF)) {
139 (ahinfo->invflags & IPT_AH_INV_SPI) ? "! " : "");
152 static struct xtables_match ah_mt_reg = {
154 .version = XTABLES_VERSION,
155 .family = NFPROTO_IPV4,
156 .size = XT_ALIGN(sizeof(struct ipt_ah)),
157 .userspacesize = XT_ALIGN(sizeof(struct ipt_ah)),
163 .extra_opts = ah_opts,
169 xtables_register_match(&ah_mt_reg);