Sapan says vnet_tun is obsolete.
[iptables.git] / extensions / libxt_MARK.c
index 4be5633..8996ad4 100644 (file)
@@ -39,6 +39,7 @@ static const struct option mark_tg_opts[] = {
        {.name = "and-mark",  .has_arg = true, .val = '&'},
        {.name = "or-mark",   .has_arg = true, .val = '|'},
        {.name = "xor-mark",  .has_arg = true, .val = '^'},
+       {.name = "copy-xid",  .has_arg = true, .val = '%'},
        { .name = NULL }
 };
 
@@ -50,6 +51,7 @@ static void mark_tg_help(void)
 "  --set-mark value[/mask]   Clear bits in mask and OR value into nfmark\n"
 "  --and-mark bits           Binary AND the nfmark with bits\n"
 "  --or-mark bits            Binary OR the nfmark with bits\n"
+"  --copy-xid                Set nfmark to be the connection xid (PlanetLab specific)\n"
 "  --xor-mask bits           Binary XOR the nfmark with bits\n"
 "\n");
 }
@@ -184,6 +186,12 @@ static int mark_tg_parse(int c, char **argv, int invert, unsigned int *flags,
                info->mask = 0;
                break;
 
+    case '%': /* --copy-xid */
+        param_act(P_ONE_ACTION, "MARK", *flags & F_MARK);
+        info->mark = ~0U; /* Consistency check */
+        info->mask = mask;
+        break;
+
        default:
                return false;
        }
@@ -196,7 +204,7 @@ static void mark_tg_check(unsigned int flags)
 {
        if (flags == 0)
                exit_error(PARAMETER_PROBLEM, "MARK: One of the --set-xmark, "
-                          "--{and,or,xor,set}-mark options is required");
+                          "--{and,or,xor,set}-mark, or --copy-xid options is required");
 }
 
 static void
@@ -250,18 +258,20 @@ static void MARK_print_v1(const void *ip, const struct xt_entry_target *target,
 }
 
 static void mark_tg_print(const void *ip, const struct xt_entry_target *target,
-                          int numeric)
+        int numeric)
 {
-       const struct xt_mark_tginfo2 *info = (const void *)target->data;
-
-       if (info->mark == 0)
-               printf("MARK and 0x%x ", (unsigned int)(u_int32_t)~info->mask);
-       else if (info->mark == info->mask)
-               printf("MARK or 0x%x ", info->mark);
-       else if (info->mask == 0)
-               printf("MARK xor 0x%x ", info->mark);
-       else
-               printf("MARK xset 0x%x/0x%x ", info->mark, info->mask);
+    const struct xt_mark_tginfo2 *info = (const void *)target->data;
+
+    if (info->mark == ~0U) 
+        printf("MARK copy-xid");
+    else if (info->mark == 0)
+        printf("MARK and 0x%x ", (unsigned int)(u_int32_t)~info->mask);
+    else if (info->mark == info->mask)
+        printf("MARK or 0x%x ", info->mark);
+    else if (info->mask == 0)
+        printf("MARK xor 0x%x ", info->mark);
+    else
+        printf("MARK xset 0x%x/0x%x ", info->mark, info->mask);
 }
 
 /* Saves the union ipt_targinfo in parsable form to stdout. */
@@ -291,7 +301,10 @@ static void mark_tg_save(const void *ip, const struct xt_entry_target *target)
 {
        const struct xt_mark_tginfo2 *info = (const void *)target->data;
 
-       printf("--set-xmark 0x%x/0x%x ", info->mark, info->mask);
+    if (info->mark==~0U)
+        printf("--copy-xid 0x0");
+    else
+           printf("--set-xmark 0x%x/0x%x ", info->mark, info->mask);
 }
 
 static struct xtables_target mark_target_v0 = {