fix conflict
[iptables.git] / copy-xid.patch
1 commit a796550d217a8fc06829cac7bad72ac1fe34f85d
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 ab5127c..477790e 100644
9 --- a/extensions/libxt_CLASSIFY.c
10 +++ b/extensions/libxt_CLASSIFY.c
11 @@ -16,11 +16,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         {.name = "set-class", .has_arg = true, .val = '1'},
22 +       {.name = "add-mark",  .has_arg = true, .val = '2'},
23         XT_GETOPT_TABLEEND,
24  };
25  
26 @@ -43,6 +45,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 @@ -54,6 +58,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 @@ -84,6 +92,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 @@ -94,6 +105,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 39996d0..09e13ca 100644
68 --- a/extensions/libxt_MARK.c
69 +++ b/extensions/libxt_MARK.c
70 @@ -19,6 +19,7 @@ enum {
71         XT_MARK_SET=0,
72         XT_MARK_AND,
73         XT_MARK_OR,
74 +       IPT_MARK_COPYXID,
75  };
76  
77  struct xt_mark_target_info_v1 {
78 @@ -36,13 +37,15 @@ static void MARK_help(void)
79  "MARK target options:\n"
80  "  --set-mark value                   Set nfmark value\n"
81  "  --and-mark value                   Binary AND the nfmark with value\n"
82 -"  --or-mark  value                   Binary OR  the nfmark with value\n");
83 +"  --or-mark  value                   Binary OR  the nfmark with value\n"
84 +"  --copy-xid                         Set nfmark to be the connection xid (PlanetLab specific)\n");
85  }
86  
87  static const struct option MARK_opts[] = {
88         {.name = "set-mark", .has_arg = true, .val = '1'},
89         {.name = "and-mark", .has_arg = true, .val = '2'},
90         {.name = "or-mark",  .has_arg = true, .val = '3'},
91 +       {.name = "copy-xid", .has_arg = true, .val = '4'},
92         XT_GETOPT_TABLEEND,
93  };
94  
95 @@ -52,6 +55,7 @@ static const struct option mark_tg_opts[] = {
96         {.name = "and-mark",  .has_arg = true, .val = '&'},
97         {.name = "or-mark",   .has_arg = true, .val = '|'},
98         {.name = "xor-mark",  .has_arg = true, .val = '^'},
99 +       {.name = "copy-xid",  .has_arg = true, .val = '%'},
100         XT_GETOPT_TABLEEND,
101  };
102  
103 @@ -63,6 +67,7 @@ static void mark_tg_help(void)
104  "  --set-mark value[/mask]   Clear bits in mask and OR value into nfmark\n"
105  "  --and-mark bits           Binary AND the nfmark with bits\n"
106  "  --or-mark bits            Binary OR the nfmark with bits\n"
107 +"  --copy-xid                Set nfmark to be the connection xid (PlanetLab specific)\n"
108  "  --xor-mask bits           Binary XOR the nfmark with bits\n"
109  "\n");
110  }
111 @@ -126,6 +131,9 @@ MARK_parse_v1(int c, char **argv, int invert, unsigned int *flags,
112         case '3':
113                 markinfo->mode = XT_MARK_OR;
114                 break;
115 +       case '4':
116 +               markinfo->mode = IPT_MARK_COPYXID;
117 +               break;
118         default:
119                 return 0;
120         }
121 @@ -194,6 +202,12 @@ static int mark_tg_parse(int c, char **argv, int invert, unsigned int *flags,
122                 info->mask = 0;
123                 break;
124  
125 +       case '%': /* --copy-xid */
126 +               xtables_param_act(XTF_ONE_ACTION, "MARK", *flags & F_MARK);
127 +               info->mark = ~0U; /* Consistency check */
128 +               info->mask = mask;
129 +               break;
130 +
131         default:
132                 return false;
133         }
134 @@ -206,7 +220,7 @@ static void mark_tg_check(unsigned int flags)
135  {
136         if (flags == 0)
137                 xtables_error(PARAMETER_PROBLEM, "MARK: One of the --set-xmark, "
138 -                          "--{and,or,xor,set}-mark options is required");
139 +                          "--{and,or,xor,set}-mark, or --copy-xid options is required");
140  }
141  
142  static void
143 @@ -249,6 +263,9 @@ static void MARK_print_v1(const void *ip, const struct xt_entry_target *target,
144         case XT_MARK_OR: 
145                 printf("MARK or ");
146                 break;
147 +       case IPT_MARK_COPYXID: 
148 +               printf("MARK copyxid ");
149 +               break;
150         }
151         print_mark(markinfo->mark);
152  }
153 @@ -258,7 +275,9 @@ static void mark_tg_print(const void *ip, const struct xt_entry_target *target,
154  {
155         const struct xt_mark_tginfo2 *info = (const void *)target->data;
156  
157 -       if (info->mark == 0)
158 +       if (info->mark == ~0U)
159 +               printf("MARK copy-xid");
160 +       else if (info->mark == 0)
161                 printf("MARK and 0x%x ", (unsigned int)(u_int32_t)~info->mask);
162         else if (info->mark == info->mask)
163                 printf("MARK or 0x%x ", info->mark);
164 @@ -285,6 +304,9 @@ static void MARK_save_v1(const void *ip, const struct xt_entry_target *target)
165         case XT_MARK_OR: 
166                 printf("--or-mark ");
167                 break;
168 +       case IPT_MARK_COPYXID:
169 +               printf("--copy-xid ");
170 +               break;
171         }
172         print_mark(markinfo->mark);
173  }
174 @@ -293,7 +315,10 @@ static void mark_tg_save(const void *ip, const struct xt_entry_target *target)
175  {
176         const struct xt_mark_tginfo2 *info = (const void *)target->data;
177  
178 -       printf("--set-xmark 0x%x/0x%x ", info->mark, info->mask);
179 +       if (info->mark==~0U)
180 +               printf("--copy-xid 0x0");
181 +       else
182 +               printf("--set-xmark 0x%x/0x%x ", info->mark, info->mask);
183  }
184  
185  static struct xtables_target mark_tg_reg[] = {
186 diff --git a/include/linux/netfilter/xt_CLASSIFY.h b/include/linux/netfilter/xt_CLASSIFY.h
187 index a813bf1..c5cec1d 100644
188 --- a/include/linux/netfilter/xt_CLASSIFY.h
189 +++ b/include/linux/netfilter/xt_CLASSIFY.h
190 @@ -5,6 +5,7 @@
191  
192  struct xt_classify_target_info {
193         __u32 priority;
194 +       __u8 add_mark;
195  };
196  
197  #endif /*_XT_CLASSIFY_H */