]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
Remove goto chain
authorStephen Hemminger <stephen.hemminger@vyatta.com>
Fri, 3 Apr 2009 16:38:56 +0000 (09:38 -0700)
committerStephen Hemminger <stephen.hemminger@vyatta.com>
Fri, 3 Apr 2009 16:44:04 +0000 (09:44 -0700)
The selector logic is clearer with if / else if

tc/f_u32.c

index 0bb57ce30488658f8d2ad19ec25447d1d3bbaba8..e5b8231f53c89ffa44ef1bb740e7578fc61a5f7e 100644 (file)
@@ -47,7 +47,7 @@ static void explain(void)
 
 #define usage() return(-1)
 
-int get_u32_handle(__u32 *handle, char *str)
+int get_u32_handle(__u32 *handle, const char *str)
 {
        __u32 htid=0, hash=0, nodeid=0;
        char *tmp = strchr(str, ':');
@@ -417,77 +417,49 @@ static int parse_ip(int *argc_p, char ***argv_p, struct tc_u32_sel *sel)
        if (strcmp(*argv, "src") == 0) {
                NEXT_ARG();
                res = parse_ip_addr(&argc, &argv, sel, 12);
-               goto done;
-       }
-       if (strcmp(*argv, "dst") == 0) {
+       } else if (strcmp(*argv, "dst") == 0) {
                NEXT_ARG();
                res = parse_ip_addr(&argc, &argv, sel, 16);
-               goto done;
-       }
-       if (strcmp(*argv, "tos") == 0 ||
+       } else if (strcmp(*argv, "tos") == 0 ||
            matches(*argv, "dsfield") == 0) {
                NEXT_ARG();
                res = parse_u8(&argc, &argv, sel, 1, 0);
-               goto done;
-       }
-       if (strcmp(*argv, "ihl") == 0) {
+       } else if (strcmp(*argv, "ihl") == 0) {
                NEXT_ARG();
                res = parse_u8(&argc, &argv, sel, 0, 0);
-               goto done;
-       }
-       if (strcmp(*argv, "protocol") == 0) {
+       } else if (strcmp(*argv, "protocol") == 0) {
                NEXT_ARG();
                res = parse_u8(&argc, &argv, sel, 9, 0);
-               goto done;
-       }
-       if (matches(*argv, "precedence") == 0) {
+       } else if (matches(*argv, "precedence") == 0) {
                NEXT_ARG();
                res = parse_u8(&argc, &argv, sel, 1, 0);
-               goto done;
-       }
-       if (strcmp(*argv, "nofrag") == 0) {
+       } else if (strcmp(*argv, "nofrag") == 0) {
                argc--; argv++;
                res = pack_key16(sel, 0, 0x3FFF, 6, 0);
-               goto done;
-       }
-       if (strcmp(*argv, "firstfrag") == 0) {
+       } else if (strcmp(*argv, "firstfrag") == 0) {
                argc--; argv++;
                res = pack_key16(sel, 0, 0x1FFF, 6, 0);
-               goto done;
-       }
-       if (strcmp(*argv, "df") == 0) {
+       } else if (strcmp(*argv, "df") == 0) {
                argc--; argv++;
                res = pack_key16(sel, 0x4000, 0x4000, 6, 0);
-               goto done;
-       }
-       if (strcmp(*argv, "mf") == 0) {
+       } else if (strcmp(*argv, "mf") == 0) {
                argc--; argv++;
                res = pack_key16(sel, 0x2000, 0x2000, 6, 0);
-               goto done;
-       }
-       if (strcmp(*argv, "dport") == 0) {
+       } else if (strcmp(*argv, "dport") == 0) {
                NEXT_ARG();
                res = parse_u16(&argc, &argv, sel, 22, 0);
-               goto done;
-       }
-       if (strcmp(*argv, "sport") == 0) {
+       } else if (strcmp(*argv, "sport") == 0) {
                NEXT_ARG();
                res = parse_u16(&argc, &argv, sel, 20, 0);
-               goto done;
-       }
-       if (strcmp(*argv, "icmp_type") == 0) {
+       } else if (strcmp(*argv, "icmp_type") == 0) {
                NEXT_ARG();
                res = parse_u8(&argc, &argv, sel, 20, 0);
-               goto done;
-       }
-       if (strcmp(*argv, "icmp_code") == 0) {
+       } else if (strcmp(*argv, "icmp_code") == 0) {
                NEXT_ARG();
                res = parse_u8(&argc, &argv, sel, 20, 1);
-               goto done;
-       }
-       return -1;
+       } else
+               return -1;
 
-done:
        *argc_p = argc;
        *argv_p = argv;
        return res;
@@ -505,51 +477,33 @@ static int parse_ip6(int *argc_p, char ***argv_p, struct tc_u32_sel *sel)
        if (strcmp(*argv, "src") == 0) {
                NEXT_ARG();
                res = parse_ip6_addr(&argc, &argv, sel, 8);
-               goto done;
-       }
-       if (strcmp(*argv, "dst") == 0) {
+       } else if (strcmp(*argv, "dst") == 0) {
                NEXT_ARG();
                res = parse_ip6_addr(&argc, &argv, sel, 24);
-               goto done;
-       }
-       if (strcmp(*argv, "priority") == 0) {
+       } else if (strcmp(*argv, "priority") == 0) {
                NEXT_ARG();
                res = parse_u8(&argc, &argv, sel, 4, 0);
-               goto done;
-       }
-       if (strcmp(*argv, "protocol") == 0) {
+       } else if (strcmp(*argv, "protocol") == 0) {
                NEXT_ARG();
                res = parse_u8(&argc, &argv, sel, 6, 0);
-               goto done;
-       }
-       if (strcmp(*argv, "flowlabel") == 0) {
+       } else if (strcmp(*argv, "flowlabel") == 0) {
                NEXT_ARG();
                res = parse_u32(&argc, &argv, sel, 0, 0);
-               goto done;
-       }
-       if (strcmp(*argv, "dport") == 0) {
+       } else if (strcmp(*argv, "dport") == 0) {
                NEXT_ARG();
                res = parse_u16(&argc, &argv, sel, 42, 0);
-               goto done;
-       }
-       if (strcmp(*argv, "sport") == 0) {
+       } else if (strcmp(*argv, "sport") == 0) {
                NEXT_ARG();
                res = parse_u16(&argc, &argv, sel, 40, 0);
-               goto done;
-       }
-       if (strcmp(*argv, "icmp_type") == 0) {
+       } else if (strcmp(*argv, "icmp_type") == 0) {
                NEXT_ARG();
                res = parse_u8(&argc, &argv, sel, 40, 0);
-               goto done;
-       }
-       if (strcmp(*argv, "icmp_code") == 0) {
+       } else if (strcmp(*argv, "icmp_code") == 0) {
                NEXT_ARG();
                res = parse_u8(&argc, &argv, sel, 41, 1);
-               goto done;
-       }
-       return -1;
+       } else
+               return -1;
 
-done:
        *argc_p = argc;
        *argv_p = argv;
        return res;
@@ -568,16 +522,12 @@ static int parse_udp(int *argc_p, char ***argv_p, struct tc_u32_sel *sel)
        if (strcmp(*argv, "src") == 0) {
                NEXT_ARG();
                res = parse_u16(&argc, &argv, sel, 0, -1);
-               goto done;
-       }
-       if (strcmp(*argv, "dst") == 0) {
+       } else if (strcmp(*argv, "dst") == 0) {
                NEXT_ARG();
                res = parse_u16(&argc, &argv, sel, 2, -1);
-               goto done;
-       }
-       return -1;
+       } else
+               return -1;
 
-done:
        *argc_p = argc;
        *argv_p = argv;
        return res;
@@ -596,16 +546,12 @@ static int parse_icmp(int *argc_p, char ***argv_p, struct tc_u32_sel *sel)
        if (strcmp(*argv, "type") == 0) {
                NEXT_ARG();
                res = parse_u8(&argc, &argv, sel, 0, -1);
-               goto done;
-       }
-       if (strcmp(*argv, "code") == 0) {
+       } else if (strcmp(*argv, "code") == 0) {
                NEXT_ARG();
                res = parse_u8(&argc, &argv, sel, 1, -1);
-               goto done;
-       }
-       return -1;
+       } else
+               return -1;
 
-done:
        *argc_p = argc;
        *argv_p = argv;
        return res;
@@ -659,52 +605,33 @@ static int parse_selector(int *argc_p, char ***argv_p,
        if (matches(*argv, "u32") == 0) {
                NEXT_ARG();
                res = parse_u32(&argc, &argv, sel, 0, 0);
-               goto done;
-       }
-       if (matches(*argv, "u16") == 0) {
+       } else if (matches(*argv, "u16") == 0) {
                NEXT_ARG();
                res = parse_u16(&argc, &argv, sel, 0, 0);
-               goto done;
-       }
-       if (matches(*argv, "u8") == 0) {
+       } else if (matches(*argv, "u8") == 0) {
                NEXT_ARG();
                res = parse_u8(&argc, &argv, sel, 0, 0);
-               goto done;
-       }
-       if (matches(*argv, "ip") == 0) {
+       } else if (matches(*argv, "ip") == 0) {
                NEXT_ARG();
                res = parse_ip(&argc, &argv, sel);
-               goto done;
-       }
-       if (matches(*argv, "ip6") == 0) {
+       } else  if (matches(*argv, "ip6") == 0) {
                NEXT_ARG();
                res = parse_ip6(&argc, &argv, sel);
-               goto done;
-       }
-       if (matches(*argv, "udp") == 0) {
+       } else if (matches(*argv, "udp") == 0) {
                NEXT_ARG();
                res = parse_udp(&argc, &argv, sel);
-               goto done;
-       }
-       if (matches(*argv, "tcp") == 0) {
+       } else if (matches(*argv, "tcp") == 0) {
                NEXT_ARG();
                res = parse_tcp(&argc, &argv, sel);
-               goto done;
-       }
-       if (matches(*argv, "icmp") == 0) {
+       } else if (matches(*argv, "icmp") == 0) {
                NEXT_ARG();
                res = parse_icmp(&argc, &argv, sel);
-               goto done;
-       }
-       if (matches(*argv, "mark") == 0) {
+       } else if (matches(*argv, "mark") == 0) {
                NEXT_ARG();
                res = parse_mark(&argc, &argv, n);
-               goto done;
-       }
-
-       return -1;
+       } else 
+               return -1;
 
-done:
        *argc_p = argc;
        *argv_p = argv;
        return res;