aboutsummaryrefslogtreecommitdiffstats
path: root/extensions/libip6t_rt.c
diff options
context:
space:
mode:
Diffstat (limited to 'extensions/libip6t_rt.c')
-rw-r--r--extensions/libip6t_rt.c144
1 files changed, 63 insertions, 81 deletions
diff --git a/extensions/libip6t_rt.c b/extensions/libip6t_rt.c
index 251604b..a04023d 100644
--- a/extensions/libip6t_rt.c
+++ b/extensions/libip6t_rt.c
@@ -5,38 +5,36 @@
#include <stdlib.h>
#include <getopt.h>
#include <errno.h>
-#include <ip6tables.h>
+#include <xtables.h>
/*#include <linux/in6.h>*/
#include <linux/netfilter_ipv6/ip6t_rt.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
-
+
/*#define DEBUG 1*/
-/* Function which prints out usage message. */
-static void
-help(void)
+static void rt_help(void)
{
printf(
-"RT v%s options:\n"
-" --rt-type [!] type match the type\n"
-" --rt-segsleft [!] num[:num] match the Segments Left field (range)\n"
-" --rt-len [!] length total length of this header\n"
+"rt match options:\n"
+"[!] --rt-type type match the type\n"
+"[!] --rt-segsleft num[:num] match the Segments Left field (range)\n"
+"[!] --rt-len length total length of this header\n"
" --rt-0-res check the reserved filed, too (type 0)\n"
" --rt-0-addrs ADDR[,ADDR...] Type=0 addresses (list, max: %d)\n"
" --rt-0-not-strict List of Type=0 addresses not a strict list\n",
-IPTABLES_VERSION, IP6T_RT_HOPS);
+IP6T_RT_HOPS);
}
-static struct option opts[] = {
- { "rt-type", 1, 0, '1' },
- { "rt-segsleft", 1, 0, '2' },
- { "rt-len", 1, 0, '3' },
- { "rt-0-res", 0, 0, '4' },
- { "rt-0-addrs", 1, 0, '5' },
- { "rt-0-not-strict", 0, 0, '6' },
- {0}
+static const struct option rt_opts[] = {
+ { "rt-type", 1, NULL, '1' },
+ { "rt-segsleft", 1, NULL, '2' },
+ { "rt-len", 1, NULL, '3' },
+ { "rt-0-res", 0, NULL, '4' },
+ { "rt-0-addrs", 1, NULL, '5' },
+ { "rt-0-not-strict", 0, NULL, '6' },
+ { .name = NULL }
};
static u_int32_t
@@ -48,19 +46,19 @@ parse_rt_num(const char *idstr, const char *typestr)
id = strtoul(idstr,&ep,0) ;
if ( idstr == ep ) {
- exit_error(PARAMETER_PROBLEM,
+ xtables_error(PARAMETER_PROBLEM,
"RT no valid digits in %s `%s'", typestr, idstr);
}
if ( id == ULONG_MAX && errno == ERANGE ) {
- exit_error(PARAMETER_PROBLEM,
+ xtables_error(PARAMETER_PROBLEM,
"%s `%s' specified too big: would overflow",
typestr, idstr);
}
if ( *idstr != '\0' && *ep != '\0' ) {
- exit_error(PARAMETER_PROBLEM,
+ xtables_error(PARAMETER_PROBLEM,
"RT error parsing %s `%s'", typestr, idstr);
}
- return (u_int32_t) id;
+ return id;
}
static void
@@ -100,7 +98,7 @@ numeric_to_addr(const char *num)
#ifdef DEBUG
fprintf(stderr, "\nnumeric2addr: %d\n", err);
#endif
- exit_error(PARAMETER_PROBLEM, "bad address: %s", num);
+ xtables_error(PARAMETER_PROBLEM, "bad address: %s", num);
return (struct in6_addr *)NULL;
}
@@ -113,7 +111,7 @@ parse_addresses(const char *addrstr, struct in6_addr *addrp)
unsigned int i;
buffer = strdup(addrstr);
- if (!buffer) exit_error(OTHER_PROBLEM, "strdup failed");
+ if (!buffer) xtables_error(OTHER_PROBLEM, "strdup failed");
for (cp=buffer, i=0; cp && i<IP6T_RT_HOPS; cp=next,i++)
{
@@ -126,7 +124,7 @@ parse_addresses(const char *addrstr, struct in6_addr *addrp)
printf("addr [%d]: %s\n", i, addr_to_numeric(&(addrp[i])));
#endif
}
- if (cp) exit_error(PARAMETER_PROBLEM, "too many addresses specified");
+ if (cp) xtables_error(PARAMETER_PROBLEM, "too many addresses specified");
free(buffer);
@@ -137,9 +135,7 @@ parse_addresses(const char *addrstr, struct in6_addr *addrp)
return i;
}
-/* Initialize the match. */
-static void
-init(struct ip6t_entry_match *m, unsigned int *nfcache)
+static void rt_init(struct xt_entry_match *m)
{
struct ip6t_rt *rtinfo = (struct ip6t_rt *)m->data;
@@ -152,23 +148,18 @@ init(struct ip6t_entry_match *m, unsigned int *nfcache)
rtinfo->addrnr = 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 ip6t_entry *entry,
- unsigned int *nfcache,
- struct ip6t_entry_match **match)
+static int rt_parse(int c, char **argv, int invert, unsigned int *flags,
+ const void *entry, struct xt_entry_match **match)
{
struct ip6t_rt *rtinfo = (struct ip6t_rt *)(*match)->data;
switch (c) {
case '1':
if (*flags & IP6T_RT_TYP)
- exit_error(PARAMETER_PROBLEM,
+ xtables_error(PARAMETER_PROBLEM,
"Only one `--rt-type' allowed");
- check_inverse(optarg, &invert, &optind, 0);
- rtinfo->rt_type = parse_rt_num(argv[optind-1], "type");
+ xtables_check_inverse(optarg, &invert, &optind, 0, argv);
+ rtinfo->rt_type = parse_rt_num(optarg, "type");
if (invert)
rtinfo->invflags |= IP6T_RT_INV_TYP;
rtinfo->flags |= IP6T_RT_TYP;
@@ -176,10 +167,10 @@ parse(int c, char **argv, int invert, unsigned int *flags,
break;
case '2':
if (*flags & IP6T_RT_SGS)
- exit_error(PARAMETER_PROBLEM,
+ xtables_error(PARAMETER_PROBLEM,
"Only one `--rt-segsleft' allowed");
- check_inverse(optarg, &invert, &optind, 0);
- parse_rt_segsleft(argv[optind-1], rtinfo->segsleft);
+ xtables_check_inverse(optarg, &invert, &optind, 0, argv);
+ parse_rt_segsleft(optarg, rtinfo->segsleft);
if (invert)
rtinfo->invflags |= IP6T_RT_INV_SGS;
rtinfo->flags |= IP6T_RT_SGS;
@@ -187,10 +178,10 @@ parse(int c, char **argv, int invert, unsigned int *flags,
break;
case '3':
if (*flags & IP6T_RT_LEN)
- exit_error(PARAMETER_PROBLEM,
+ xtables_error(PARAMETER_PROBLEM,
"Only one `--rt-len' allowed");
- check_inverse(optarg, &invert, &optind, 0);
- rtinfo->hdrlen = parse_rt_num(argv[optind-1], "length");
+ xtables_check_inverse(optarg, &invert, &optind, 0, argv);
+ rtinfo->hdrlen = parse_rt_num(optarg, "length");
if (invert)
rtinfo->invflags |= IP6T_RT_INV_LEN;
rtinfo->flags |= IP6T_RT_LEN;
@@ -198,35 +189,35 @@ parse(int c, char **argv, int invert, unsigned int *flags,
break;
case '4':
if (*flags & IP6T_RT_RES)
- exit_error(PARAMETER_PROBLEM,
+ xtables_error(PARAMETER_PROBLEM,
"Only one `--rt-0-res' allowed");
if ( !(*flags & IP6T_RT_TYP) || (rtinfo->rt_type != 0) || (rtinfo->invflags & IP6T_RT_INV_TYP) )
- exit_error(PARAMETER_PROBLEM,
+ xtables_error(PARAMETER_PROBLEM,
"`--rt-type 0' required before `--rt-0-res'");
rtinfo->flags |= IP6T_RT_RES;
*flags |= IP6T_RT_RES;
break;
case '5':
if (*flags & IP6T_RT_FST)
- exit_error(PARAMETER_PROBLEM,
+ xtables_error(PARAMETER_PROBLEM,
"Only one `--rt-0-addrs' allowed");
if ( !(*flags & IP6T_RT_TYP) || (rtinfo->rt_type != 0) || (rtinfo->invflags & IP6T_RT_INV_TYP) )
- exit_error(PARAMETER_PROBLEM,
+ xtables_error(PARAMETER_PROBLEM,
"`--rt-type 0' required before `--rt-0-addrs'");
- check_inverse(optarg, &invert, &optind, 0);
+ xtables_check_inverse(optarg, &invert, &optind, 0, argv);
if (invert)
- exit_error(PARAMETER_PROBLEM,
+ xtables_error(PARAMETER_PROBLEM,
" '!' not allowed with `--rt-0-addrs'");
- rtinfo->addrnr = parse_addresses(argv[optind-1], rtinfo->addrs);
+ rtinfo->addrnr = parse_addresses(optarg, rtinfo->addrs);
rtinfo->flags |= IP6T_RT_FST;
*flags |= IP6T_RT_FST;
break;
case '6':
if (*flags & IP6T_RT_FST_NSTRICT)
- exit_error(PARAMETER_PROBLEM,
+ xtables_error(PARAMETER_PROBLEM,
"Only one `--rt-0-not-strict' allowed");
if ( !(*flags & IP6T_RT_FST) )
- exit_error(PARAMETER_PROBLEM,
+ xtables_error(PARAMETER_PROBLEM,
"`--rt-0-addr ...' required before `--rt-0-not-strict'");
rtinfo->flags |= IP6T_RT_FST_NSTRICT;
*flags |= IP6T_RT_FST_NSTRICT;
@@ -238,12 +229,6 @@ parse(int c, char **argv, int invert, unsigned int *flags,
return 1;
}
-/* Final check; we don't care. */
-static void
-final_check(unsigned int flags)
-{
-}
-
static void
print_nums(const char *name, u_int32_t min, u_int32_t max,
int invert)
@@ -266,7 +251,7 @@ print_nums(const char *name, u_int32_t min, u_int32_t max,
}
static void
-print_addresses(int addrnr, struct in6_addr *addrp)
+print_addresses(unsigned int addrnr, struct in6_addr *addrp)
{
unsigned int i;
@@ -275,10 +260,8 @@ print_addresses(int addrnr, struct in6_addr *addrp)
}
}
-/* Prints out the union ip6t_matchinfo. */
-static void
-print(const struct ip6t_ip6 *ip,
- const struct ip6t_entry_match *match, int numeric)
+static void rt_print(const void *ip, const struct xt_entry_match *match,
+ int numeric)
{
const struct ip6t_rt *rtinfo = (struct ip6t_rt *)match->data;
@@ -303,20 +286,19 @@ print(const struct ip6t_ip6 *ip,
rtinfo->invflags & ~IP6T_RT_INV_MASK);
}
-/* Saves the union ip6t_matchinfo in parsable form to stdout. */
-static void save(const struct ip6t_ip6 *ip, const struct ip6t_entry_match *match)
+static void rt_save(const void *ip, const struct xt_entry_match *match)
{
const struct ip6t_rt *rtinfo = (struct ip6t_rt *)match->data;
if (rtinfo->flags & IP6T_RT_TYP) {
- printf("--rt-type %s%u ",
+ printf("%s--rt-type %u ",
(rtinfo->invflags & IP6T_RT_INV_TYP) ? "! " : "",
rtinfo->rt_type);
}
if (!(rtinfo->segsleft[0] == 0
&& rtinfo->segsleft[1] == 0xFFFFFFFF)) {
- printf("--rt-segsleft %s",
+ printf("%s--rt-segsleft ",
(rtinfo->invflags & IP6T_RT_INV_SGS) ? "! " : "");
if (rtinfo->segsleft[0]
!= rtinfo->segsleft[1])
@@ -329,7 +311,7 @@ static void save(const struct ip6t_ip6 *ip, const struct ip6t_entry_match *match
}
if (rtinfo->flags & IP6T_RT_LEN) {
- printf("--rt-len %s%u ",
+ printf("%s--rt-len %u ",
(rtinfo->invflags & IP6T_RT_INV_LEN) ? "! " : "",
rtinfo->hdrlen);
}
@@ -341,22 +323,22 @@ static void save(const struct ip6t_ip6 *ip, const struct ip6t_entry_match *match
}
-static struct ip6tables_match rt = {
+static struct xtables_match rt_mt6_reg = {
.name = "rt",
- .version = IPTABLES_VERSION,
- .size = IP6T_ALIGN(sizeof(struct ip6t_rt)),
- .userspacesize = IP6T_ALIGN(sizeof(struct ip6t_rt)),
- .help = &help,
- .init = &init,
- .parse = &parse,
- .final_check = &final_check,
- .print = &print,
- .save = &save,
- .extra_opts = opts,
+ .version = XTABLES_VERSION,
+ .family = NFPROTO_IPV6,
+ .size = XT_ALIGN(sizeof(struct ip6t_rt)),
+ .userspacesize = XT_ALIGN(sizeof(struct ip6t_rt)),
+ .help = rt_help,
+ .init = rt_init,
+ .parse = rt_parse,
+ .print = rt_print,
+ .save = rt_save,
+ .extra_opts = rt_opts,
};
void
_init(void)
{
- register_match6(&rt);
+ xtables_register_match(&rt_mt6_reg);
}