Added the new version for dummynet.
[ipfw.git] / ipfw / ipfw2.c
index 5d70328..85979f8 100644 (file)
@@ -224,11 +224,14 @@ static struct _s_x rule_action_params[] = {
        { NULL, 0 }     /* terminator */
 };
 
-/* index of 'lookup ... ' keys in the kernel */
+/*                             
+ * The 'lookup' instruction accepts one of the following arguments.
+ * -1 is a terminator for the list.
+ * Arguments are passed as v[1] in O_DST_LOOKUP options.
+ */
 static int lookup_key[] = {
        TOK_DSTIP, TOK_SRCIP, TOK_DSTPORT, TOK_SRCPORT,
-       TOK_UID, TOK_GID, TOK_JAIL,
-       TOK_PROTO, TOK_MACTYPE, 0, };
+       TOK_UID, TOK_JAIL, -1 };
 
 static struct _s_x rule_options[] = {
        { "tagged",             TOK_TAGGED },
@@ -756,8 +759,8 @@ print_ip(ipfw_insn_ip *cmd, char const *s)
 
                if (d < sizeof(lookup_key)/sizeof(lookup_key[0]))
                        arg = match_value(rule_options, lookup_key[d]);
-               printf("%s lookup %s %d,%d", cmd->o.len & F_NOT ? " not": "",
-                       arg, cmd->o.arg1, a[0]);
+               printf("%s lookup %s %d", cmd->o.len & F_NOT ? " not": "",
+                       arg, cmd->o.arg1);
                return;
        }
        printf("%s%s ", cmd->o.len & F_NOT ? " not": "", s);
@@ -3518,26 +3521,21 @@ read_options:
                        int j;
 
                        if (ac < 2)
-                               errx(EX_USAGE, "format: lookup argument tablenum[,arg]");
+                               errx(EX_USAGE, "format: lookup argument tablenum");
                        cmd->opcode = O_IP_DST_LOOKUP;
                        cmd->len |= F_INSN_SIZE(ipfw_insn) + 2;
                        i = match_token(rule_options, *av);
-                       for (j = 0; lookup_key[j] ; j++) {
+                       for (j = 0; lookup_key[j] >= 0 ; j++) {
                                if (i == lookup_key[j])
                                        break;
                        }
-                       if (lookup_key[j] == 0)
+                       if (lookup_key[j] <= 0)
                                errx(EX_USAGE, "format: cannot lookup on %s", *av);
                        c->d[1] = j; // i converted to option
                        ac--; av++;
-                       p = strchr(*av, ',');
-                       if (p) {
-                               *p++ = '\0';
-                               c->d[0] = strtoul(p, NULL, 0);
-                       } else {
-                               c->d[0] = ~0;
-                       }
-                       cmd->arg1 = strtoul(*av, NULL, 0);
+                       cmd->arg1 = strtoul(*av, &p, 0);
+                       if (p && *p)
+                               errx(EX_USAGE, "format: lookup argument tablenum");
                        ac--; av++;
                    }
                        break;