1 /* Shared library add-on to ip6tables to add ESP support. */
9 #include <linux/netfilter_ipv6/ip6t_esp.h>
11 /* Function which prints out usage message. */
17 " --espspi [!] spi[:spi] match spi (range)\n",
21 static struct option opts
[] = {
22 { .name
= "espspi", .has_arg
= 1, .flag
= 0, .val
= '1' },
27 parse_esp_spi(const char *spistr
)
29 unsigned long int spi
;
32 spi
= strtoul(spistr
, &ep
, 0);
35 exit_error(PARAMETER_PROBLEM
,
36 "ESP no valid digits in spi `%s'", spistr
);
38 if ( spi
== ULONG_MAX
&& errno
== ERANGE
) {
39 exit_error(PARAMETER_PROBLEM
,
40 "spi `%s' specified too big: would overflow", spistr
);
42 if ( *spistr
!= '\0' && *ep
!= '\0' ) {
43 exit_error(PARAMETER_PROBLEM
,
44 "ESP error parsing spi `%s'", spistr
);
46 return (u_int32_t
) spi
;
50 parse_esp_spis(const char *spistring
, u_int32_t
*spis
)
55 buffer
= strdup(spistring
);
56 if ((cp
= strchr(buffer
, ':')) == NULL
)
57 spis
[0] = spis
[1] = parse_esp_spi(buffer
);
62 spis
[0] = buffer
[0] ? parse_esp_spi(buffer
) : 0;
63 spis
[1] = cp
[0] ? parse_esp_spi(cp
) : 0xFFFFFFFF;
64 if (spis
[0] > spis
[1])
65 exit_error(PARAMETER_PROBLEM
,
66 "Invalid ESP spi range: %s", spistring
);
71 /* Initialize the match. */
73 init(struct ip6t_entry_match
*m
, unsigned int *nfcache
)
75 struct ip6t_esp
*espinfo
= (struct ip6t_esp
*)m
->data
;
77 espinfo
->spis
[1] = 0xFFFFFFFF;
82 /* Function which parses command options; returns true if it
85 parse(int c
, char **argv
, int invert
, unsigned int *flags
,
86 const struct ip6t_entry
*entry
,
87 unsigned int *nfcache
,
88 struct ip6t_entry_match
**match
)
90 struct ip6t_esp
*espinfo
= (struct ip6t_esp
*)(*match
)->data
;
95 exit_error(PARAMETER_PROBLEM
,
96 "Only one `--espspi' allowed");
97 check_inverse(optarg
, &invert
, &optind
, 0);
98 parse_esp_spis(argv
[optind
-1], espinfo
->spis
);
100 espinfo
->invflags
|= IP6T_ESP_INV_SPI
;
110 /* Final check; we don't care. */
112 final_check(unsigned int flags
)
117 print_spis(const char *name
, u_int32_t min
, u_int32_t max
,
120 const char *inv
= invert
? "!" : "";
122 if (min
!= 0 || max
!= 0xFFFFFFFF || invert
) {
124 printf("%s:%s%u ", name
, inv
, min
);
126 printf("%ss:%s%u:%u ", name
, inv
, min
, max
);
130 /* Prints out the union ip6t_matchinfo. */
132 print(const struct ip6t_ip6
*ip
,
133 const struct ip6t_entry_match
*match
, int numeric
)
135 const struct ip6t_esp
*esp
= (struct ip6t_esp
*)match
->data
;
138 print_spis("spi", esp
->spis
[0], esp
->spis
[1],
139 esp
->invflags
& IP6T_ESP_INV_SPI
);
140 if (esp
->invflags
& ~IP6T_ESP_INV_MASK
)
141 printf("Unknown invflags: 0x%X ",
142 esp
->invflags
& ~IP6T_ESP_INV_MASK
);
145 /* Saves the union ip6t_matchinfo in parsable form to stdout. */
146 static void save(const struct ip6t_ip6
*ip
, const struct ip6t_entry_match
*match
)
148 const struct ip6t_esp
*espinfo
= (struct ip6t_esp
*)match
->data
;
150 if (!(espinfo
->spis
[0] == 0
151 && espinfo
->spis
[1] == 0xFFFFFFFF)) {
152 printf("--espspi %s",
153 (espinfo
->invflags
& IP6T_ESP_INV_SPI
) ? "! " : "");
167 struct ip6tables_match esp
= {
169 .version
= IPTABLES_VERSION
,
170 .size
= IP6T_ALIGN(sizeof(struct ip6t_esp
)),
171 .userspacesize
= IP6T_ALIGN(sizeof(struct ip6t_esp
)),
175 .final_check
= &final_check
,
184 register_match6(&esp
);