1 /* Shared library add-on to iptables to add AH support. */
9 #include <linux/netfilter_ipv4/ipt_ah.h>
11 /* Function which prints out usage message. */
17 " --ahspi [!] spi[:spi]\n"
18 " match spi (range)\n",
22 static struct option opts[] = {
23 { "ahspi", 1, 0, '1' },
28 parse_ah_spi(const char *spistr)
30 unsigned long int spi;
33 spi = strtoul(spistr,&ep,0) ;
36 exit_error(PARAMETER_PROBLEM,
37 "AH no valid digits in spi `%s'", spistr);
39 if ( spi == ULONG_MAX && errno == ERANGE ) {
40 exit_error(PARAMETER_PROBLEM,
41 "spi `%s' specified too big: would overflow", spistr);
43 if ( *spistr != '\0' && *ep != '\0' ) {
44 exit_error(PARAMETER_PROBLEM,
45 "AH error parsing spi `%s'", spistr);
47 return (u_int32_t) spi;
51 parse_ah_spis(const char *spistring, u_int32_t *spis)
56 buffer = strdup(spistring);
57 if ((cp = strchr(buffer, ':')) == NULL)
58 spis[0] = spis[1] = parse_ah_spi(buffer);
63 spis[0] = buffer[0] ? parse_ah_spi(buffer) : 0;
64 spis[1] = cp[0] ? parse_ah_spi(cp) : 0xFFFFFFFF;
69 /* Initialize the match. */
71 init(struct ipt_entry_match *m, unsigned int *nfcache)
73 struct ipt_ah *ahinfo = (struct ipt_ah *)m->data;
75 ahinfo->spis[1] = 0xFFFFFFFF;
80 /* Function which parses command options; returns true if it
83 parse(int c, char **argv, int invert, unsigned int *flags,
84 const struct ipt_entry *entry,
85 unsigned int *nfcache,
86 struct ipt_entry_match **match)
88 struct ipt_ah *ahinfo = (struct ipt_ah *)(*match)->data;
93 exit_error(PARAMETER_PROBLEM,
94 "Only one `--ahspi' allowed");
95 check_inverse(optarg, &invert, &optind, 0);
96 parse_ah_spis(argv[optind-1], ahinfo->spis);
98 ahinfo->invflags |= IPT_AH_INV_SPI;
108 /* Final check; we don't care. */
110 final_check(unsigned int flags)
115 print_spis(const char *name, u_int32_t min, u_int32_t max,
118 const char *inv = invert ? "!" : "";
120 if (min != 0 || max != 0xFFFFFFFF || invert) {
135 /* Prints out the union ipt_matchinfo. */
137 print(const struct ipt_ip *ip,
138 const struct ipt_entry_match *match, int numeric)
140 const struct ipt_ah *ah = (struct ipt_ah *)match->data;
143 print_spis("spi", ah->spis[0], ah->spis[1],
144 ah->invflags & IPT_AH_INV_SPI);
145 if (ah->invflags & ~IPT_AH_INV_MASK)
146 printf("Unknown invflags: 0x%X ",
147 ah->invflags & ~IPT_AH_INV_MASK);
150 /* Saves the union ipt_matchinfo in parsable form to stdout. */
151 static void save(const struct ipt_ip *ip, const struct ipt_entry_match *match)
153 const struct ipt_ah *ahinfo = (struct ipt_ah *)match->data;
155 if (!(ahinfo->spis[0] == 0
156 && ahinfo->spis[1] == 0xFFFFFFFF)) {
158 (ahinfo->invflags & IPT_AH_INV_SPI) ? "! " : "");
171 static struct iptables_match ah = {
174 .version = IPTABLES_VERSION,
175 .size = IPT_ALIGN(sizeof(struct ipt_ah)),
176 .userspacesize = IPT_ALIGN(sizeof(struct ipt_ah)),
180 .final_check = &final_check,