X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=extensions%2Flibipt_ttl.c;fp=extensions%2Flibipt_ttl.c;h=2391986841d37b65b85cfd527f5ba5ce5335f6c3;hb=6afea0b41dfbc3824956d11d960ad80097218feb;hp=4507fe9d60099bd88e10640e4257dabcd4e0b827;hpb=f7b70cf9e00324b89b02de213bcd0dde7044d035;p=iptables.git diff --git a/extensions/libipt_ttl.c b/extensions/libipt_ttl.c index 4507fe9..2391986 100644 --- a/extensions/libipt_ttl.c +++ b/extensions/libipt_ttl.c @@ -1,7 +1,7 @@ /* Shared library add-on to iptables to add TTL matching support * (C) 2000 by Harald Welte * - * $Id: libipt_ttl.c,v 1.6 2002/05/29 13:08:16 laforge Exp $ + * $Id: libipt_ttl.c 3687 2005-02-14 13:13:04Z /C=DE/ST=Berlin/L=Berlin/O=Netfilter Project/OU=Development/CN=kaber/emailAddress=kaber@netfilter.org $ * * This program is released under the terms of GNU GPL */ @@ -24,29 +24,19 @@ static void help(void) , IPTABLES_VERSION); } -static void init(struct ipt_entry_match *m, unsigned int *nfcache) -{ - /* caching not yet implemented */ - *nfcache |= NFC_UNKNOWN; -} - static int parse(int c, char **argv, int invert, unsigned int *flags, const struct ipt_entry *entry, unsigned int *nfcache, struct ipt_entry_match **match) { struct ipt_ttl_info *info = (struct ipt_ttl_info *) (*match)->data; - u_int8_t value; + int value; check_inverse(optarg, &invert, &optind, 0); - value = atoi(argv[optind-1]); - - if (*flags) - exit_error(PARAMETER_PROBLEM, - "Can't specify TTL option twice"); - if (!optarg) + if (string_to_number(optarg, 0, 255, &value) == -1) exit_error(PARAMETER_PROBLEM, - "ttl: You must specify a value"); + "ttl: Expected value between 0 and 255"); + switch (c) { case '2': if (invert) @@ -56,8 +46,6 @@ static int parse(int c, char **argv, int invert, unsigned int *flags, /* is 0 allowed? */ info->ttl = value; - *flags = 1; - break; case '3': if (invert) @@ -66,8 +54,6 @@ static int parse(int c, char **argv, int invert, unsigned int *flags, info->mode = IPT_TTL_LT; info->ttl = value; - *flags = 1; - break; case '4': if (invert) @@ -76,14 +62,17 @@ static int parse(int c, char **argv, int invert, unsigned int *flags, info->mode = IPT_TTL_GT; info->ttl = value; - *flags = 1; - break; default: return 0; } + if (*flags) + exit_error(PARAMETER_PROBLEM, + "Can't specify TTL option twice"); + *flags = 1; + return 1; } @@ -154,20 +143,18 @@ static struct option opts[] = { { 0 } }; -static -struct iptables_match ttl = { - NULL, - "ttl", - IPTABLES_VERSION, - IPT_ALIGN(sizeof(struct ipt_ttl_info)), - IPT_ALIGN(sizeof(struct ipt_ttl_info)), - &help, - &init, - &parse, - &final_check, - &print, - &save, - opts +static struct iptables_match ttl = { + .next = NULL, + .name = "ttl", + .version = IPTABLES_VERSION, + .size = IPT_ALIGN(sizeof(struct ipt_ttl_info)), + .userspacesize = IPT_ALIGN(sizeof(struct ipt_ttl_info)), + .help = &help, + .parse = &parse, + .final_check = &final_check, + .print = &print, + .save = &save, + .extra_opts = opts };