]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
extensions: use UINT_MAX constants over open-coded numbers (2/2)
authorJan Engelhardt <jengelh@medozas.de>
Tue, 27 Jan 2009 17:14:21 +0000 (18:14 +0100)
committerJan Engelhardt <jengelh@medozas.de>
Tue, 27 Jan 2009 22:14:29 +0000 (23:14 +0100)
Use the handy constants for ranges.

Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
23 files changed:
extensions/libip6t_HL.c
extensions/libip6t_icmp6.c
extensions/libip6t_mh.c
extensions/libipt_TTL.c
extensions/libipt_icmp.c
extensions/libipt_ttl.c
extensions/libxt_DSCP.c
extensions/libxt_NFQUEUE.c
extensions/libxt_TCPMSS.c
extensions/libxt_TCPOPTSTRIP.c
extensions/libxt_TOS.c
extensions/libxt_TPROXY.c
extensions/libxt_dccp.c
extensions/libxt_dscp.c
extensions/libxt_hashlimit.c
extensions/libxt_length.c
extensions/libxt_statistic.c
extensions/libxt_tcp.c
extensions/libxt_tcpmss.c
extensions/tos_values.c
ip6tables.c
iptables.c
xtables.c

index 92266e49bc34481fe6defc36ed6540798d833b57..8f555722c569e9985caa6a3cc3ff87f14668ac79 100644 (file)
@@ -44,7 +44,7 @@ static int HL_parse(int c, char **argv, int invert, unsigned int *flags,
                exit_error(PARAMETER_PROBLEM,
                                "HL: unexpected `!'");
        
-       if (string_to_number(optarg, 0, 255, &value) == -1)     
+       if (string_to_number(optarg, 0, UINT8_MAX, &value) == -1)       
                exit_error(PARAMETER_PROBLEM,   
                           "HL: Expected value between 0 and 255");
 
index b87538f9b34a7dfdad3e5e23ade26fbefd3ea5db..17567dfbdee14d2c77f317a3c263c1757307c8ba 100644 (file)
@@ -123,12 +123,12 @@ parse_icmpv6(const char *icmpv6type, u_int8_t *type, u_int8_t code[])
                if (slash)
                        *slash = '\0';
 
-               if (string_to_number(buffer, 0, 255, &number) == -1)
+               if (string_to_number(buffer, 0, UINT8_MAX, &number) == -1)
                        exit_error(PARAMETER_PROBLEM,
                                   "Invalid ICMPv6 type `%s'\n", buffer);
                *type = number;
                if (slash) {
-                       if (string_to_number(slash+1, 0, 255, &number) == -1)
+                       if (string_to_number(slash+1, 0, UINT8_MAX, &number) == -1)
                                exit_error(PARAMETER_PROBLEM,
                                           "Invalid ICMPv6 code `%s'\n",
                                           slash+1);
index e76d7c366cef30c92772c0d6a5fd8fa1c9f3d06f..8b58bcdf896e9aff82868dc898a13d6a3a1c5495 100644 (file)
@@ -93,7 +93,7 @@ static unsigned int name_to_type(const char *name)
        } else {
                unsigned int number;
 
-               if (string_to_number(name, 0, 255, &number) == -1)
+               if (string_to_number(name, 0, UINT8_MAX, &number) == -1)
                        exit_error(PARAMETER_PROBLEM,
                                   "Invalid MH type `%s'\n", name);
                return number;
index 7647f2f7971d7679b068d793eaef48d760cb8df7..e124381e38b776fca0ef69b623a76965bbe345b6 100644 (file)
@@ -44,7 +44,7 @@ static int TTL_parse(int c, char **argv, int invert, unsigned int *flags,
                exit_error(PARAMETER_PROBLEM,
                                "TTL: unexpected `!'");
        
-       if (string_to_number(optarg, 0, 255, &value) == -1)
+       if (string_to_number(optarg, 0, UINT8_MAX, &value) == -1)
                exit_error(PARAMETER_PROBLEM,
                           "TTL: Expected value between 0 and 255");
 
index fa5a5409e44110e626a8b433d036d42264ea6bdd..7aff9caab1a9a44fd08c921fc768e086b5ec29a6 100644 (file)
@@ -147,12 +147,12 @@ parse_icmp(const char *icmptype, u_int8_t *type, u_int8_t code[])
                if (slash)
                        *slash = '\0';
 
-               if (string_to_number(buffer, 0, 255, &number) == -1)
+               if (string_to_number(buffer, 0, UINT8_MAX, &number) == -1)
                        exit_error(PARAMETER_PROBLEM,
                                   "Invalid ICMP type `%s'\n", buffer);
                *type = number;
                if (slash) {
-                       if (string_to_number(slash+1, 0, 255, &number) == -1)
+                       if (string_to_number(slash+1, 0, UINT8_MAX, &number) == -1)
                                exit_error(PARAMETER_PROBLEM,
                                           "Invalid ICMP code `%s'\n",
                                           slash+1);
index 055c92ee8429de2af79d00382e350491a54776e6..a8455e1d9be13df2bd1f2d28036590986a9dfeb6 100644 (file)
@@ -33,7 +33,7 @@ static int ttl_parse(int c, char **argv, int invert, unsigned int *flags,
 
        switch (c) {
                case '2':
-                       if (string_to_number(optarg, 0, 255, &value) == -1)
+                       if (string_to_number(optarg, 0, UINT8_MAX, &value) == -1)
                                exit_error(PARAMETER_PROBLEM,
                                           "ttl: Expected value between 0 and 255");
 
@@ -46,7 +46,7 @@ static int ttl_parse(int c, char **argv, int invert, unsigned int *flags,
                        info->ttl = value;
                        break;
                case '3':
-                       if (string_to_number(optarg, 0, 255, &value) == -1)
+                       if (string_to_number(optarg, 0, UINT8_MAX, &value) == -1)
                                exit_error(PARAMETER_PROBLEM,
                                           "ttl: Expected value between 0 and 255");
 
@@ -58,7 +58,7 @@ static int ttl_parse(int c, char **argv, int invert, unsigned int *flags,
                        info->ttl = value;
                        break;
                case '4':
-                       if (string_to_number(optarg, 0, 255, &value) == -1)
+                       if (string_to_number(optarg, 0, UINT8_MAX, &value) == -1)
                                exit_error(PARAMETER_PROBLEM,
                                           "ttl: Expected value between 0 and 255");
 
index 409fa1961f464e5a8ad44d6673a50e3579e6fc7b..92a6de5b9ece76e68e6c16efe3da87b67a117606 100644 (file)
@@ -48,7 +48,7 @@ parse_dscp(const char *s, struct xt_DSCP_info *dinfo)
 {
        unsigned int dscp;
        
-       if (string_to_number(s, 0, 255, &dscp) == -1)
+       if (string_to_number(s, 0, UINT8_MAX, &dscp) == -1)
                exit_error(PARAMETER_PROBLEM,
                           "Invalid dscp `%s'\n", s);
 
index 5880785368b7bb906af473b2edf7c2250842433f..1a58760b029c15a184b11e972cf0abc6617873c6 100644 (file)
@@ -33,7 +33,7 @@ parse_num(const char *s, struct xt_NFQ_info *tinfo)
 {
        unsigned int num;
        
-       if (string_to_number(s, 0, 65535, &num) == -1)
+       if (string_to_number(s, 0, UINT16_MAX, &num) == -1)
                exit_error(PARAMETER_PROBLEM,
                           "Invalid queue number `%s'\n", s);
 
index 2227eb48d16344522b1970549da2b59870d10780..9b62a56bfac56143a43a0c688e6563a09f7859af 100644 (file)
@@ -55,7 +55,7 @@ static int __TCPMSS_parse(int c, char **argv, int invert, unsigned int *flags,
                if (*flags)
                        exit_error(PARAMETER_PROBLEM,
                                   "TCPMSS target: Only one option may be specified");
-               if (string_to_number(optarg, 0, 65535 - hdrsize, &mssval) == -1)
+               if (string_to_number(optarg, 0, UINT16_MAX - hdrsize, &mssval) == -1)
                        exit_error(PARAMETER_PROBLEM, "Bad TCPMSS value `%s'", optarg);
                
                mssinfo->mss = mssval;
index 758f84765e5b5bc617dbff936eccae00bb5ad225..7211288ed670707f237db460c21ff58cbff60f69 100644 (file)
@@ -82,7 +82,7 @@ static void parse_list(struct xt_tcpoptstrip_target_info *info, char *arg)
                                break;
                        }
 
-               if (option == 0 && string_to_number(arg, 0, 255, &option) == -1)
+               if (option == 0 && string_to_number(arg, 0, UINT8_MAX, &option) == -1)
                        exit_error(PARAMETER_PROBLEM,
                                   "Bad TCP option value \"%s\"", arg);
 
index c185681737db5a5889d76d3c64b62e0769c94c3e..a04f741436f3828474aa9411958a3fd517bd9afc 100644 (file)
@@ -118,7 +118,7 @@ static int tos_tg_parse(int c, char **argv, int invert, unsigned int *flags,
        case '&': /* --and-tos */
                param_act(P_ONLY_ONCE, "TOS", "--and-tos", *flags & FLAG_TOS);
                param_act(P_NO_INVERT, "TOS", "--and-tos", invert);
-               if (!strtonum(optarg, NULL, &bits, 0, 0xFF))
+               if (!strtonum(optarg, NULL, &bits, 0, UINT8_MAX))
                        param_act(P_BAD_VALUE, "TOS", "--and-tos", optarg);
                info->tos_value = 0;
                info->tos_mask  = ~bits;
@@ -127,7 +127,7 @@ static int tos_tg_parse(int c, char **argv, int invert, unsigned int *flags,
        case '|': /* --or-tos */
                param_act(P_ONLY_ONCE, "TOS", "--or-tos", *flags & FLAG_TOS);
                param_act(P_NO_INVERT, "TOS", "--or-tos", invert);
-               if (!strtonum(optarg, NULL, &bits, 0, 0xFF))
+               if (!strtonum(optarg, NULL, &bits, 0, UINT8_MAX))
                        param_act(P_BAD_VALUE, "TOS", "--or-tos", optarg);
                info->tos_value = bits;
                info->tos_mask  = bits;
@@ -136,7 +136,7 @@ static int tos_tg_parse(int c, char **argv, int invert, unsigned int *flags,
        case '^': /* --xor-tos */
                param_act(P_ONLY_ONCE, "TOS", "--xor-tos", *flags & FLAG_TOS);
                param_act(P_NO_INVERT, "TOS", "--xor-tos", invert);
-               if (!strtonum(optarg, NULL, &bits, 0, 0xFF))
+               if (!strtonum(optarg, NULL, &bits, 0, UINT8_MAX))
                        param_act(P_BAD_VALUE, "TOS", "--xor-tos", optarg);
                info->tos_value = bits;
                info->tos_mask  = 0;
index e9a41a15e4af84063e07bb111bee62c0b7e39452..41ca24363037e32e2e6a6d97c6def83c8e28247e 100644 (file)
@@ -40,7 +40,7 @@ static void parse_tproxy_lport(const char *s, struct xt_tproxy_target_info *info
 {
        unsigned int lport;
 
-       if (string_to_number(s, 0, 65535, &lport) != -1)
+       if (string_to_number(s, 0, UINT16_MAX, &lport) != -1)
                info->lport = htons(lport);
        else
                param_act(P_BAD_VALUE, "TPROXY", "--on-port", s);
index b1ae62eed711791d97867803f7fc3bbf9beacf91..0eb95cefc6edcf8e1a1928d207fc3bb5cfbf5b1a 100644 (file)
@@ -121,7 +121,7 @@ static u_int8_t parse_dccp_option(char *optstring)
 {
        unsigned int ret;
 
-       if (string_to_number(optstring, 1, 255, &ret) == -1)
+       if (string_to_number(optstring, 1, UINT8_MAX, &ret) == -1)
                exit_error(PARAMETER_PROBLEM, "Bad DCCP option `%s'",
                           optstring);
 
index 315e219aad62c80bea6475e1244c5882d2c5ad2b..ae5a6248013f83507cbf44e9f64c25c89c7ef60a 100644 (file)
@@ -48,7 +48,7 @@ parse_dscp(const char *s, struct xt_dscp_info *dinfo)
 {
        unsigned int dscp;
        
-       if (string_to_number(s, 0, 255, &dscp) == -1)
+       if (string_to_number(s, 0, UINT8_MAX, &dscp) == -1)
                exit_error(PARAMETER_PROBLEM,
                           "Invalid dscp `%s'\n", s);
 
index 1c506852321d8c87a72b2de479dec95d66aa15bf..278e098ee3d9fbb2d428a7ca44a24fb4138cdc3b 100644 (file)
@@ -240,7 +240,7 @@ hashlimit_parse(int c, char **argv, int invert, unsigned int *flags,
                param_act(P_ONLY_ONCE, "hashlimit", "--hashlimit-htable-size",
                          *flags & PARAM_SIZE);
                if (check_inverse(argv[optind-1], &invert, &optind, 0)) break;
-               if (string_to_number(optarg, 0, 0xffffffff, &num) == -1)
+               if (string_to_number(optarg, 0, UINT32_MAX, &num) == -1)
                        exit_error(PARAMETER_PROBLEM,
                                "bad --hashlimit-htable-size: `%s'", optarg);
                r->cfg.size = num;
@@ -250,7 +250,7 @@ hashlimit_parse(int c, char **argv, int invert, unsigned int *flags,
                param_act(P_ONLY_ONCE, "hashlimit", "--hashlimit-htable-max",
                          *flags & PARAM_MAX);
                if (check_inverse(argv[optind-1], &invert, &optind, 0)) break;
-               if (string_to_number(optarg, 0, 0xffffffff, &num) == -1)
+               if (string_to_number(optarg, 0, UINT32_MAX, &num) == -1)
                        exit_error(PARAMETER_PROBLEM,
                                "bad --hashlimit-htable-max: `%s'", optarg);
                r->cfg.max = num;
@@ -261,7 +261,7 @@ hashlimit_parse(int c, char **argv, int invert, unsigned int *flags,
                          "--hashlimit-htable-gcinterval",
                          *flags & PARAM_GCINTERVAL);
                if (check_inverse(argv[optind-1], &invert, &optind, 0)) break;
-               if (string_to_number(optarg, 0, 0xffffffff, &num) == -1)
+               if (string_to_number(optarg, 0, UINT32_MAX, &num) == -1)
                        exit_error(PARAMETER_PROBLEM,
                                "bad --hashlimit-htable-gcinterval: `%s'", 
                                optarg);
@@ -273,7 +273,7 @@ hashlimit_parse(int c, char **argv, int invert, unsigned int *flags,
                param_act(P_ONLY_ONCE, "hashlimit",
                          "--hashlimit-htable-expire", *flags & PARAM_EXPIRE);
                if (check_inverse(argv[optind-1], &invert, &optind, 0)) break;
-               if (string_to_number(optarg, 0, 0xffffffff, &num) == -1)
+               if (string_to_number(optarg, 0, UINT32_MAX, &num) == -1)
                        exit_error(PARAMETER_PROBLEM,
                                "bad --hashlimit-htable-expire: `%s'", optarg);
                /* FIXME: not HZ dependent */
@@ -351,7 +351,7 @@ hashlimit_mt_parse(struct xt_hashlimit_mtinfo1 *info, unsigned int *flags,
        case '&': /* --hashlimit-htable-size */
                param_act(P_ONLY_ONCE, "hashlimit", "--hashlimit-htable-size",
                          *flags & PARAM_SIZE);
-               if (!strtonum(optarg, NULL, &num, 0, 0xffffffff))
+               if (!strtonum(optarg, NULL, &num, 0, UINT32_MAX))
                        param_act(P_BAD_VALUE, "hashlimit",
                                  "--hashlimit-htable-size", optarg);
                info->cfg.size = num;
@@ -361,7 +361,7 @@ hashlimit_mt_parse(struct xt_hashlimit_mtinfo1 *info, unsigned int *flags,
        case '*': /* --hashlimit-htable-max */
                param_act(P_ONLY_ONCE, "hashlimit", "--hashlimit-htable-max",
                          *flags & PARAM_MAX);
-               if (!strtonum(optarg, NULL, &num, 0, 0xffffffff))
+               if (!strtonum(optarg, NULL, &num, 0, UINT32_MAX))
                        param_act(P_BAD_VALUE, "hashlimit",
                                  "--hashlimit-htable-max", optarg);
                info->cfg.max = num;
@@ -372,7 +372,7 @@ hashlimit_mt_parse(struct xt_hashlimit_mtinfo1 *info, unsigned int *flags,
                param_act(P_ONLY_ONCE, "hashlimit",
                          "--hashlimit-htable-gcinterval",
                          *flags & PARAM_GCINTERVAL);
-               if (!strtonum(optarg, NULL, &num, 0, 0xffffffff))
+               if (!strtonum(optarg, NULL, &num, 0, UINT32_MAX))
                        param_act(P_BAD_VALUE, "hashlimit",
                                  "--hashlimit-htable-gcinterval", optarg);
                /* FIXME: not HZ dependent!! */
@@ -383,7 +383,7 @@ hashlimit_mt_parse(struct xt_hashlimit_mtinfo1 *info, unsigned int *flags,
        case ')': /* --hashlimit-htable-expire */
                param_act(P_ONLY_ONCE, "hashlimit",
                          "--hashlimit-htable-expire", *flags & PARAM_EXPIRE);
-               if (!strtonum(optarg, NULL, &num, 0, 0xffffffff))
+               if (!strtonum(optarg, NULL, &num, 0, UINT32_MAX))
                        param_act(P_BAD_VALUE, "hashlimit",
                                  "--hashlimit-htable-expire", optarg);
                /* FIXME: not HZ dependent */
index e350431c9612f92a1da76f913870a7c551966158..0e196d78466985c217df4ad7a8699a03a14e2e69 100644 (file)
@@ -26,7 +26,7 @@ parse_length(const char *s)
 {
        unsigned int len;
        
-       if (string_to_number(s, 0, 0xFFFF, &len) == -1)
+       if (string_to_number(s, 0, UINT16_MAX, &len) == -1)
                exit_error(PARAMETER_PROBLEM, "length invalid: `%s'\n", s);
        else
                return len;
index d85aacbd92957035713e2534a90b7a8ebc6aa06d..e43de7d23f666ad47805a368983e2dc9526bb7c0 100644 (file)
@@ -70,7 +70,7 @@ statistic_parse(int c, char **argv, int invert, unsigned int *flags,
        case '3':
                if (*flags & 0x4)
                        exit_error(PARAMETER_PROBLEM, "double --every");
-               if (string_to_number(optarg, 0, 0xFFFFFFFF,
+               if (string_to_number(optarg, 0, UINT32_MAX,
                                     &info->u.nth.every) == -1)
                        exit_error(PARAMETER_PROBLEM,
                                   "cannot parse --every `%s'", optarg);
@@ -82,7 +82,7 @@ statistic_parse(int c, char **argv, int invert, unsigned int *flags,
        case '4':
                if (*flags & 0x8)
                        exit_error(PARAMETER_PROBLEM, "double --packet");
-               if (string_to_number(optarg, 0, 0xFFFFFFFF,
+               if (string_to_number(optarg, 0, UINT32_MAX,
                                     &info->u.nth.packet) == -1)
                        exit_error(PARAMETER_PROBLEM,
                                   "cannot parse --packet `%s'", optarg);
index a9039f0b130a5b7a20ed0eb6cc648165960abeca..82954a4e740a37efe1135b38c1c3bf08e24a8c9f 100644 (file)
@@ -121,7 +121,7 @@ parse_tcp_option(const char *option, u_int8_t *result)
 {
        unsigned int ret;
 
-       if (string_to_number(option, 1, 255, &ret) == -1)
+       if (string_to_number(option, 1, UINT8_MAX, &ret) == -1)
                exit_error(PARAMETER_PROBLEM, "Bad TCP option `%s'", option);
 
        *result = ret;
index a720c425a557764f8cc803978aa1982a8f0d7141..e64a1b33cfef0b28fc91d08873bb84223ec2f96a 100644 (file)
@@ -26,7 +26,7 @@ parse_tcp_mssvalue(const char *mssvalue)
 {
        unsigned int mssvaluenum;
 
-       if (string_to_number(mssvalue, 0, 65535, &mssvaluenum) != -1)
+       if (string_to_number(mssvalue, 0, UINT16_MAX, &mssvaluenum) != -1)
                return mssvaluenum;
 
        exit_error(PARAMETER_PROBLEM,
index 0ab784da3103084e05744a28ff69cd9cec1718d3..2d5b4312dbb14c567bbd4a073dd8b29c3a25e774 100644 (file)
@@ -55,7 +55,7 @@ static bool tos_parse_numeric(const char *str, struct tos_value_mask *tvm,
 static bool tos_parse_symbolic(const char *str, struct tos_value_mask *tvm,
     unsigned int def_mask)
 {
-       const unsigned int max = 255;
+       const unsigned int max = UINT8_MAX;
        const struct tos_symbol_info *symbol;
        char *tmp;
 
index 3c45c0729e6ffbb63307ec20fea6fd853dcc4351..a30cb7be7ed4a30ba86e78b9cbce0a9a90a2c470 100644 (file)
@@ -484,7 +484,7 @@ find_proto(const char *pname, enum ip6t_tryload tryload, int nolookup, struct ip
 {
        unsigned int proto;
 
-       if (string_to_number(pname, 0, 255, &proto) != -1) {
+       if (string_to_number(pname, 0, UINT8_MAX, &proto) != -1) {
                char *protoname = proto_to_name(proto, nolookup);
 
                if (protoname)
@@ -500,7 +500,7 @@ parse_protocol(const char *s)
 {
        unsigned int proto;
 
-       if (string_to_number(s, 0, 255, &proto) == -1) {
+       if (string_to_number(s, 0, UINT8_MAX, &proto) == -1) {
                struct protoent *pent;
 
                /* first deal with the special case of 'all' to prevent
index b75df871a4e2092b4b258175450c344f57500db6..2b5a82eeacb66f4142b28776b53d25a093edbe01 100644 (file)
@@ -486,7 +486,7 @@ find_proto(const char *pname, enum ipt_tryload tryload, int nolookup, struct ipt
 {
        unsigned int proto;
 
-       if (string_to_number(pname, 0, 255, &proto) != -1) {
+       if (string_to_number(pname, 0, UINT8_MAX, &proto) != -1) {
                char *protoname = proto_to_name(proto, nolookup);
 
                if (protoname)
@@ -502,7 +502,7 @@ parse_protocol(const char *s)
 {
        unsigned int proto;
 
-       if (string_to_number(s, 0, 255, &proto) == -1) {
+       if (string_to_number(s, 0, UINT8_MAX, &proto) == -1) {
                struct protoent *pent;
 
                /* first deal with the special case of 'all' to prevent
index ecfbccf34d8e2e42acdd3b9c65438893f687c228..6719659387dc9a84ae5786a789aa9e1120d2a261 100644 (file)
--- a/xtables.c
+++ b/xtables.c
@@ -260,7 +260,7 @@ u_int16_t parse_port(const char *port, const char *proto)
 {
        unsigned int portnum;
 
-       if ((string_to_number(port, 0, 65535, &portnum)) != -1 ||
+       if (string_to_number(port, 0, UINT16_MAX, &portnum) != -1 ||
            (portnum = service_to_port(port, proto)) != (unsigned)-1)
                return portnum;
 
@@ -811,7 +811,7 @@ static struct in_addr *__numeric_to_ipaddr(const char *dotted, bool is_mask)
                                return NULL;
 
                        /* autocomplete, this is a network address */
-                       if (!strtonum(p, NULL, &onebyte, 0, 255))
+                       if (!strtonum(p, NULL, &onebyte, 0, UINT8_MAX))
                                return NULL;
 
                        addrp[i] = onebyte;
@@ -822,7 +822,7 @@ static struct in_addr *__numeric_to_ipaddr(const char *dotted, bool is_mask)
                }
 
                *q = '\0';
-               if (!strtonum(p, NULL, &onebyte, 0, 255))
+               if (!strtonum(p, NULL, &onebyte, 0, UINT8_MAX))
                        return NULL;
 
                addrp[i] = onebyte;
@@ -830,7 +830,7 @@ static struct in_addr *__numeric_to_ipaddr(const char *dotted, bool is_mask)
        }
 
        /* we have checked 3 bytes, now we check the last one */
-       if (!strtonum(p, NULL, &onebyte, 0, 255))
+       if (!strtonum(p, NULL, &onebyte, 0, UINT8_MAX))
                return NULL;
 
        addrp[3] = onebyte;