drop backward compatibility with older iptables versions as new kernels only support v2
[iptables.git] / copy-xid.patch
1 commit 12aa2a62d05523e66b104b3f6840c592309d3a05
2 Author: S.Çağlar Onur <caglar@cs.princeton.edu>
3 Date:   Sat Apr 3 01:17:41 2010 -0400
4
5     copy-xid
6
7 diff --git a/extensions/libxt_CLASSIFY.c b/extensions/libxt_CLASSIFY.c
8 index 82b8f4e..09c15c0 100644
9 --- a/extensions/libxt_CLASSIFY.c
10 +++ b/extensions/libxt_CLASSIFY.c
11 @@ -15,11 +15,13 @@ CLASSIFY_help(void)
12  {
13         printf(
14  "CLASSIFY target options:\n"
15 -"--set-class MAJOR:MINOR    Set skb->priority value (always hexadecimal!)\n");
16 +"--set-class MAJOR:MINOR    Set skb->priority value (always hexadecimal!)\n"
17 +"  --add-mark                   Add value of skb->mark to skb->priority (PlanetLab specific)\n");
18  }
19  
20  static const struct option CLASSIFY_opts[] = {
21         { "set-class", 1, NULL, '1' },
22 +       { "add-mark", 0, 0, '2' },
23         { .name = NULL }
24  };
25  
26 @@ -42,6 +44,8 @@ CLASSIFY_parse(int c, char **argv, int invert, unsigned int *flags,
27         struct xt_classify_target_info *clinfo
28                 = (struct xt_classify_target_info *)(*target)->data;
29  
30 +       clinfo->add_mark = 0;
31 +
32         switch (c) {
33         case '1':
34                 if (CLASSIFY_string_to_priority(optarg, &clinfo->priority))
35 @@ -53,6 +57,10 @@ CLASSIFY_parse(int c, char **argv, int invert, unsigned int *flags,
36                 *flags = 1;
37                 break;
38  
39 +       case '2':
40 +               clinfo->add_mark = 1;
41 +               break;
42 +
43         default:
44                 return 0;
45         }
46 @@ -83,6 +91,9 @@ CLASSIFY_print(const void *ip,
47                 (const struct xt_classify_target_info *)target->data;
48         printf("CLASSIFY set ");
49         CLASSIFY_print_class(clinfo->priority, numeric);
50 +
51 +       if (clinfo->add_mark)
52 +               printf ("add-mark ");
53  }
54  
55  static void
56 @@ -93,6 +104,9 @@ CLASSIFY_save(const void *ip, const struct xt_entry_target *target)
57  
58         printf("--set-class %.4x:%.4x ",
59                TC_H_MAJ(clinfo->priority)>>16, TC_H_MIN(clinfo->priority));
60 +
61 +       if (clinfo->add_mark)
62 +               printf("--add-mark ");
63  }
64  
65  static struct xtables_target classify_target = { 
66 diff --git a/extensions/libxt_MARK.c b/extensions/libxt_MARK.c
67 index dbfc7c0..db58a1b 100644
68 --- a/extensions/libxt_MARK.c
69 +++ b/extensions/libxt_MARK.c
70 @@ -36,13 +37,15 @@ static void MARK_help(void)
71  "MARK target options:\n"
72  "  --set-mark value                   Set nfmark value\n"
73  "  --and-mark value                   Binary AND the nfmark with value\n"
74 -"  --or-mark  value                   Binary OR  the nfmark with value\n");
75 +"  --or-mark  value                   Binary OR  the nfmark with value\n"
76 +"  --copy-xid                         Set nfmark to be the connection xid (PlanetLab specific)\n");
77  }
78  
79  static const struct option MARK_opts[] = {
80         { "set-mark", 1, NULL, '1' },
81         { "and-mark", 1, NULL, '2' },
82         { "or-mark", 1, NULL, '3' },
83 +       { "copy-xid", 1, 0, '4' },
84         { .name = NULL }
85  };
86  
87 @@ -52,6 +55,7 @@ static const struct option mark_tg_opts[] = {
88         {.name = "and-mark",  .has_arg = true, .val = '&'},
89         {.name = "or-mark",   .has_arg = true, .val = '|'},
90         {.name = "xor-mark",  .has_arg = true, .val = '^'},
91 +       {.name = "copy-xid",  .has_arg = true, .val = '%'},
92         { .name = NULL }
93  };
94  
95 @@ -63,6 +67,7 @@ static void mark_tg_help(void)
96  "  --set-mark value[/mask]   Clear bits in mask and OR value into nfmark\n"
97  "  --and-mark bits           Binary AND the nfmark with bits\n"
98  "  --or-mark bits            Binary OR the nfmark with bits\n"
99 +"  --copy-xid                Set nfmark to be the connection xid (PlanetLab specific)\n"
100  "  --xor-mask bits           Binary XOR the nfmark with bits\n"
101  "\n");
102  }
103 @@ -194,6 +202,12 @@ static int mark_tg_parse(int c, char **argv, int invert, unsigned int *flags,
104                 info->mask = 0;
105                 break;
106  
107 +       case '%': /* --copy-xid */
108 +               xtables_param_act(XTF_ONE_ACTION, "MARK", *flags & F_MARK);
109 +               info->mark = ~0U; /* Consistency check */
110 +               info->mask = mask;
111 +               break;
112 +
113         default:
114                 return false;
115         }
116 @@ -206,7 +220,7 @@ static void mark_tg_check(unsigned int flags)
117  {
118         if (flags == 0)
119                 xtables_error(PARAMETER_PROBLEM, "MARK: One of the --set-xmark, "
120 -                          "--{and,or,xor,set}-mark options is required");
121 +                          "--{and,or,xor,set}-mark, or --copy-xid options is required");
122  }
123  
124  static void
125 @@ -258,7 +275,9 @@ static void mark_tg_print(const void *ip, const struct xt_entry_target *target,
126  {
127         const struct xt_mark_tginfo2 *info = (const void *)target->data;
128  
129 -       if (info->mark == 0)
130 +       if (info->mark == ~0U)
131 +               printf("MARK copy-xid");
132 +       else if (info->mark == 0)
133                 printf("MARK and 0x%x ", (unsigned int)(u_int32_t)~info->mask);
134         else if (info->mark == info->mask)
135                 printf("MARK or 0x%x ", info->mark);
136 @@ -293,7 +315,10 @@ static void mark_tg_save(const void *ip, const struct xt_entry_target *target)
137  {
138         const struct xt_mark_tginfo2 *info = (const void *)target->data;
139  
140 -       printf("--set-xmark 0x%x/0x%x ", info->mark, info->mask);
141 +       if (info->mark==~0U)
142 +               printf("--copy-xid 0x0");
143 +       else
144 +               printf("--set-xmark 0x%x/0x%x ", info->mark, info->mask);
145  }
146  
147  static struct xtables_target mark_tg_reg[] = {
148 diff --git a/include/linux/netfilter/xt_CLASSIFY.h b/include/linux/netfilter/xt_CLASSIFY.h
149 index a813bf1..c5cec1d 100644
150 --- a/include/linux/netfilter/xt_CLASSIFY.h
151 +++ b/include/linux/netfilter/xt_CLASSIFY.h
152 @@ -5,6 +5,7 @@
153  
154  struct xt_classify_target_info {
155         __u32 priority;
156 +       __u8 add_mark;
157  };
158  
159  #endif /*_XT_CLASSIFY_H */