Diff markup
1 /* 1 /*
2 * net/sched/act_api.c Packet action API. 2 * net/sched/act_api.c Packet action API.
3 * 3 *
4 * This program is free software; 4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of t 5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Softw 6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your 7 * 2 of the License, or (at your option) any later version.
8 * 8 *
9 * Author: Jamal Hadi Salim 9 * Author: Jamal Hadi Salim
10 * 10 *
11 * 11 *
12 */ 12 */
13 13
14 #include <linux/types.h> 14 #include <linux/types.h>
15 #include <linux/kernel.h> 15 #include <linux/kernel.h>
16 #include <linux/string.h> 16 #include <linux/string.h>
17 #include <linux/errno.h> 17 #include <linux/errno.h>
18 #include <linux/skbuff.h> 18 #include <linux/skbuff.h>
19 #include <linux/init.h> 19 #include <linux/init.h>
20 #include <linux/kmod.h> 20 #include <linux/kmod.h>
21 #include <linux/err.h> 21 #include <linux/err.h>
22 #include <net/net_namespace.h> 22 #include <net/net_namespace.h>
23 #include <net/sock.h> 23 #include <net/sock.h>
24 #include <net/sch_generic.h> 24 #include <net/sch_generic.h>
25 #include <net/act_api.h> 25 #include <net/act_api.h>
26 #include <net/netlink.h> 26 #include <net/netlink.h>
27 27
28 void tcf_hash_destroy(struct tcf_common *p, st 28 void tcf_hash_destroy(struct tcf_common *p, struct tcf_hashinfo *hinfo)
29 { 29 {
30 unsigned int h = tcf_hash(p->tcfc_inde 30 unsigned int h = tcf_hash(p->tcfc_index, hinfo->hmask);
31 struct tcf_common **p1p; 31 struct tcf_common **p1p;
32 32
33 for (p1p = &hinfo->htab[h]; *p1p; p1p 33 for (p1p = &hinfo->htab[h]; *p1p; p1p = &(*p1p)->tcfc_next) {
34 if (*p1p == p) { 34 if (*p1p == p) {
35 write_lock_bh(hinfo->l 35 write_lock_bh(hinfo->lock);
36 *p1p = p->tcfc_next; 36 *p1p = p->tcfc_next;
37 write_unlock_bh(hinfo- 37 write_unlock_bh(hinfo->lock);
38 gen_kill_estimator(&p- 38 gen_kill_estimator(&p->tcfc_bstats,
39 &p- 39 &p->tcfc_rate_est);
40 kfree(p); 40 kfree(p);
41 return; 41 return;
42 } 42 }
43 } 43 }
44 BUG_TRAP(0); !! 44 WARN_ON(1);
45 } 45 }
46 EXPORT_SYMBOL(tcf_hash_destroy); 46 EXPORT_SYMBOL(tcf_hash_destroy);
47 47
48 int tcf_hash_release(struct tcf_common *p, int 48 int tcf_hash_release(struct tcf_common *p, int bind,
49 struct tcf_hashinfo *hinf 49 struct tcf_hashinfo *hinfo)
50 { 50 {
51 int ret = 0; 51 int ret = 0;
52 52
53 if (p) { 53 if (p) {
54 if (bind) 54 if (bind)
55 p->tcfc_bindcnt--; 55 p->tcfc_bindcnt--;
56 56
57 p->tcfc_refcnt--; 57 p->tcfc_refcnt--;
58 if (p->tcfc_bindcnt <= 0 && p- 58 if (p->tcfc_bindcnt <= 0 && p->tcfc_refcnt <= 0) {
59 tcf_hash_destroy(p, hi 59 tcf_hash_destroy(p, hinfo);
60 ret = 1; 60 ret = 1;
61 } 61 }
62 } 62 }
63 return ret; 63 return ret;
64 } 64 }
65 EXPORT_SYMBOL(tcf_hash_release); 65 EXPORT_SYMBOL(tcf_hash_release);
66 66
67 static int tcf_dump_walker(struct sk_buff *skb 67 static int tcf_dump_walker(struct sk_buff *skb, struct netlink_callback *cb,
68 struct tc_action *a 68 struct tc_action *a, struct tcf_hashinfo *hinfo)
69 { 69 {
70 struct tcf_common *p; 70 struct tcf_common *p;
71 int err = 0, index = -1,i = 0, s_i = 0 71 int err = 0, index = -1,i = 0, s_i = 0, n_i = 0;
72 struct nlattr *nest; 72 struct nlattr *nest;
73 73
74 read_lock_bh(hinfo->lock); 74 read_lock_bh(hinfo->lock);
75 75
76 s_i = cb->args[0]; 76 s_i = cb->args[0];
77 77
78 for (i = 0; i < (hinfo->hmask + 1); i+ 78 for (i = 0; i < (hinfo->hmask + 1); i++) {
79 p = hinfo->htab[tcf_hash(i, hi 79 p = hinfo->htab[tcf_hash(i, hinfo->hmask)];
80 80
81 for (; p; p = p->tcfc_next) { 81 for (; p; p = p->tcfc_next) {
82 index++; 82 index++;
83 if (index < s_i) 83 if (index < s_i)
84 continue; 84 continue;
85 a->priv = p; 85 a->priv = p;
86 a->order = n_i; 86 a->order = n_i;
87 87
88 nest = nla_nest_start( 88 nest = nla_nest_start(skb, a->order);
89 if (nest == NULL) 89 if (nest == NULL)
90 goto nla_put_f 90 goto nla_put_failure;
91 err = tcf_action_dump_ 91 err = tcf_action_dump_1(skb, a, 0, 0);
92 if (err < 0) { 92 if (err < 0) {
93 index--; 93 index--;
94 nlmsg_trim(skb 94 nlmsg_trim(skb, nest);
95 goto done; 95 goto done;
96 } 96 }
97 nla_nest_end(skb, nest 97 nla_nest_end(skb, nest);
98 n_i++; 98 n_i++;
99 if (n_i >= TCA_ACT_MAX 99 if (n_i >= TCA_ACT_MAX_PRIO)
100 goto done; 100 goto done;
101 } 101 }
102 } 102 }
103 done: 103 done:
104 read_unlock_bh(hinfo->lock); 104 read_unlock_bh(hinfo->lock);
105 if (n_i) 105 if (n_i)
106 cb->args[0] += n_i; 106 cb->args[0] += n_i;
107 return n_i; 107 return n_i;
108 108
109 nla_put_failure: 109 nla_put_failure:
110 nla_nest_cancel(skb, nest); 110 nla_nest_cancel(skb, nest);
111 goto done; 111 goto done;
112 } 112 }
113 113
114 static int tcf_del_walker(struct sk_buff *skb, 114 static int tcf_del_walker(struct sk_buff *skb, struct tc_action *a,
115 struct tcf_hashinfo 115 struct tcf_hashinfo *hinfo)
116 { 116 {
117 struct tcf_common *p, *s_p; 117 struct tcf_common *p, *s_p;
118 struct nlattr *nest; 118 struct nlattr *nest;
119 int i= 0, n_i = 0; 119 int i= 0, n_i = 0;
120 120
121 nest = nla_nest_start(skb, a->order); 121 nest = nla_nest_start(skb, a->order);
122 if (nest == NULL) 122 if (nest == NULL)
123 goto nla_put_failure; 123 goto nla_put_failure;
124 NLA_PUT_STRING(skb, TCA_KIND, a->ops-> 124 NLA_PUT_STRING(skb, TCA_KIND, a->ops->kind);
125 for (i = 0; i < (hinfo->hmask + 1); i+ 125 for (i = 0; i < (hinfo->hmask + 1); i++) {
126 p = hinfo->htab[tcf_hash(i, hi 126 p = hinfo->htab[tcf_hash(i, hinfo->hmask)];
127 127
128 while (p != NULL) { 128 while (p != NULL) {
129 s_p = p->tcfc_next; 129 s_p = p->tcfc_next;
130 if (ACT_P_DELETED == t 130 if (ACT_P_DELETED == tcf_hash_release(p, 0, hinfo))
131 module_put(a- 131 module_put(a->ops->owner);
132 n_i++; 132 n_i++;
133 p = s_p; 133 p = s_p;
134 } 134 }
135 } 135 }
136 NLA_PUT_U32(skb, TCA_FCNT, n_i); 136 NLA_PUT_U32(skb, TCA_FCNT, n_i);
137 nla_nest_end(skb, nest); 137 nla_nest_end(skb, nest);
138 138
139 return n_i; 139 return n_i;
140 nla_put_failure: 140 nla_put_failure:
141 nla_nest_cancel(skb, nest); 141 nla_nest_cancel(skb, nest);
142 return -EINVAL; 142 return -EINVAL;
143 } 143 }
144 144
145 int tcf_generic_walker(struct sk_buff *skb, st 145 int tcf_generic_walker(struct sk_buff *skb, struct netlink_callback *cb,
146 int type, struct tc_act 146 int type, struct tc_action *a)
147 { 147 {
148 struct tcf_hashinfo *hinfo = a->ops->h 148 struct tcf_hashinfo *hinfo = a->ops->hinfo;
149 149
150 if (type == RTM_DELACTION) { 150 if (type == RTM_DELACTION) {
151 return tcf_del_walker(skb, a, 151 return tcf_del_walker(skb, a, hinfo);
152 } else if (type == RTM_GETACTION) { 152 } else if (type == RTM_GETACTION) {
153 return tcf_dump_walker(skb, cb 153 return tcf_dump_walker(skb, cb, a, hinfo);
154 } else { 154 } else {
155 printk("tcf_generic_walker: un 155 printk("tcf_generic_walker: unknown action %d\n", type);
156 return -EINVAL; 156 return -EINVAL;
157 } 157 }
158 } 158 }
159 EXPORT_SYMBOL(tcf_generic_walker); 159 EXPORT_SYMBOL(tcf_generic_walker);
160 160
161 struct tcf_common *tcf_hash_lookup(u32 index, 161 struct tcf_common *tcf_hash_lookup(u32 index, struct tcf_hashinfo *hinfo)
162 { 162 {
163 struct tcf_common *p; 163 struct tcf_common *p;
164 164
165 read_lock_bh(hinfo->lock); 165 read_lock_bh(hinfo->lock);
166 for (p = hinfo->htab[tcf_hash(index, h 166 for (p = hinfo->htab[tcf_hash(index, hinfo->hmask)]; p;
167 p = p->tcfc_next) { 167 p = p->tcfc_next) {
168 if (p->tcfc_index == index) 168 if (p->tcfc_index == index)
169 break; 169 break;
170 } 170 }
171 read_unlock_bh(hinfo->lock); 171 read_unlock_bh(hinfo->lock);
172 172
173 return p; 173 return p;
174 } 174 }
175 EXPORT_SYMBOL(tcf_hash_lookup); 175 EXPORT_SYMBOL(tcf_hash_lookup);
176 176
177 u32 tcf_hash_new_index(u32 *idx_gen, struct tc 177 u32 tcf_hash_new_index(u32 *idx_gen, struct tcf_hashinfo *hinfo)
178 { 178 {
179 u32 val = *idx_gen; 179 u32 val = *idx_gen;
180 180
181 do { 181 do {
182 if (++val == 0) 182 if (++val == 0)
183 val = 1; 183 val = 1;
184 } while (tcf_hash_lookup(val, hinfo)); 184 } while (tcf_hash_lookup(val, hinfo));
185 185
186 return (*idx_gen = val); 186 return (*idx_gen = val);
187 } 187 }
188 EXPORT_SYMBOL(tcf_hash_new_index); 188 EXPORT_SYMBOL(tcf_hash_new_index);
189 189
190 int tcf_hash_search(struct tc_action *a, u32 i 190 int tcf_hash_search(struct tc_action *a, u32 index)
191 { 191 {
192 struct tcf_hashinfo *hinfo = a->ops->h 192 struct tcf_hashinfo *hinfo = a->ops->hinfo;
193 struct tcf_common *p = tcf_hash_lookup 193 struct tcf_common *p = tcf_hash_lookup(index, hinfo);
194 194
195 if (p) { 195 if (p) {
196 a->priv = p; 196 a->priv = p;
197 return 1; 197 return 1;
198 } 198 }
199 return 0; 199 return 0;
200 } 200 }
201 EXPORT_SYMBOL(tcf_hash_search); 201 EXPORT_SYMBOL(tcf_hash_search);
202 202
203 struct tcf_common *tcf_hash_check(u32 index, s 203 struct tcf_common *tcf_hash_check(u32 index, struct tc_action *a, int bind,
204 struct tcf_h 204 struct tcf_hashinfo *hinfo)
205 { 205 {
206 struct tcf_common *p = NULL; 206 struct tcf_common *p = NULL;
207 if (index && (p = tcf_hash_lookup(inde 207 if (index && (p = tcf_hash_lookup(index, hinfo)) != NULL) {
208 if (bind) { !! 208 if (bind)
209 p->tcfc_bindcnt++; 209 p->tcfc_bindcnt++;
210 p->tcfc_refcnt++; !! 210 p->tcfc_refcnt++;
211 } <<
212 a->priv = p; 211 a->priv = p;
213 } 212 }
214 return p; 213 return p;
215 } 214 }
216 EXPORT_SYMBOL(tcf_hash_check); 215 EXPORT_SYMBOL(tcf_hash_check);
217 216
218 struct tcf_common *tcf_hash_create(u32 index, !! 217 struct tcf_common *tcf_hash_create(u32 index, struct nlattr *est,
>> 218 struct tc_action *a, int size, int bind,
>> 219 u32 *idx_gen, struct tcf_hashinfo *hinfo)
219 { 220 {
220 struct tcf_common *p = kzalloc(size, G 221 struct tcf_common *p = kzalloc(size, GFP_KERNEL);
221 222
222 if (unlikely(!p)) 223 if (unlikely(!p))
223 return p; !! 224 return ERR_PTR(-ENOMEM);
224 p->tcfc_refcnt = 1; 225 p->tcfc_refcnt = 1;
225 if (bind) 226 if (bind)
226 p->tcfc_bindcnt = 1; 227 p->tcfc_bindcnt = 1;
227 228
228 spin_lock_init(&p->tcfc_lock); 229 spin_lock_init(&p->tcfc_lock);
229 p->tcfc_index = index ? index : tcf_ha 230 p->tcfc_index = index ? index : tcf_hash_new_index(idx_gen, hinfo);
230 p->tcfc_tm.install = jiffies; 231 p->tcfc_tm.install = jiffies;
231 p->tcfc_tm.lastuse = jiffies; 232 p->tcfc_tm.lastuse = jiffies;
232 if (est) !! 233 if (est) {
233 gen_new_estimator(&p->tcfc_bst !! 234 int err = gen_new_estimator(&p->tcfc_bstats, &p->tcfc_rate_est,
234 &p->tcfc_loc !! 235 &p->tcfc_lock, est);
>> 236 if (err) {
>> 237 kfree(p);
>> 238 return ERR_PTR(err);
>> 239 }
>> 240 }
>> 241
235 a->priv = (void *) p; 242 a->priv = (void *) p;
236 return p; 243 return p;
237 } 244 }
238 EXPORT_SYMBOL(tcf_hash_create); 245 EXPORT_SYMBOL(tcf_hash_create);
239 246
240 void tcf_hash_insert(struct tcf_common *p, str 247 void tcf_hash_insert(struct tcf_common *p, struct tcf_hashinfo *hinfo)
241 { 248 {
242 unsigned int h = tcf_hash(p->tcfc_inde 249 unsigned int h = tcf_hash(p->tcfc_index, hinfo->hmask);
243 250
244 write_lock_bh(hinfo->lock); 251 write_lock_bh(hinfo->lock);
245 p->tcfc_next = hinfo->htab[h]; 252 p->tcfc_next = hinfo->htab[h];
246 hinfo->htab[h] = p; 253 hinfo->htab[h] = p;
247 write_unlock_bh(hinfo->lock); 254 write_unlock_bh(hinfo->lock);
248 } 255 }
249 EXPORT_SYMBOL(tcf_hash_insert); 256 EXPORT_SYMBOL(tcf_hash_insert);
250 257
251 static struct tc_action_ops *act_base = NULL; 258 static struct tc_action_ops *act_base = NULL;
252 static DEFINE_RWLOCK(act_mod_lock); 259 static DEFINE_RWLOCK(act_mod_lock);
253 260
254 int tcf_register_action(struct tc_action_ops * 261 int tcf_register_action(struct tc_action_ops *act)
255 { 262 {
256 struct tc_action_ops *a, **ap; 263 struct tc_action_ops *a, **ap;
257 264
258 write_lock(&act_mod_lock); 265 write_lock(&act_mod_lock);
259 for (ap = &act_base; (a = *ap) != NULL 266 for (ap = &act_base; (a = *ap) != NULL; ap = &a->next) {
260 if (act->type == a->type || (s 267 if (act->type == a->type || (strcmp(act->kind, a->kind) == 0)) {
261 write_unlock(&act_mod_ 268 write_unlock(&act_mod_lock);
262 return -EEXIST; 269 return -EEXIST;
263 } 270 }
264 } 271 }
265 act->next = NULL; 272 act->next = NULL;
266 *ap = act; 273 *ap = act;
267 write_unlock(&act_mod_lock); 274 write_unlock(&act_mod_lock);
268 return 0; 275 return 0;
269 } 276 }
270 EXPORT_SYMBOL(tcf_register_action); 277 EXPORT_SYMBOL(tcf_register_action);
271 278
272 int tcf_unregister_action(struct tc_action_ops 279 int tcf_unregister_action(struct tc_action_ops *act)
273 { 280 {
274 struct tc_action_ops *a, **ap; 281 struct tc_action_ops *a, **ap;
275 int err = -ENOENT; 282 int err = -ENOENT;
276 283
277 write_lock(&act_mod_lock); 284 write_lock(&act_mod_lock);
278 for (ap = &act_base; (a = *ap) != NULL 285 for (ap = &act_base; (a = *ap) != NULL; ap = &a->next)
279 if (a == act) 286 if (a == act)
280 break; 287 break;
281 if (a) { 288 if (a) {
282 *ap = a->next; 289 *ap = a->next;
283 a->next = NULL; 290 a->next = NULL;
284 err = 0; 291 err = 0;
285 } 292 }
286 write_unlock(&act_mod_lock); 293 write_unlock(&act_mod_lock);
287 return err; 294 return err;
288 } 295 }
289 EXPORT_SYMBOL(tcf_unregister_action); 296 EXPORT_SYMBOL(tcf_unregister_action);
290 297
291 /* lookup by name */ 298 /* lookup by name */
292 static struct tc_action_ops *tc_lookup_action_ 299 static struct tc_action_ops *tc_lookup_action_n(char *kind)
293 { 300 {
294 struct tc_action_ops *a = NULL; 301 struct tc_action_ops *a = NULL;
295 302
296 if (kind) { 303 if (kind) {
297 read_lock(&act_mod_lock); 304 read_lock(&act_mod_lock);
298 for (a = act_base; a; a = a->n 305 for (a = act_base; a; a = a->next) {
299 if (strcmp(kind, a->ki 306 if (strcmp(kind, a->kind) == 0) {
300 if (!try_modul 307 if (!try_module_get(a->owner)) {
301 read_u 308 read_unlock(&act_mod_lock);
302 return 309 return NULL;
303 } 310 }
304 break; 311 break;
305 } 312 }
306 } 313 }
307 read_unlock(&act_mod_lock); 314 read_unlock(&act_mod_lock);
308 } 315 }
309 return a; 316 return a;
310 } 317 }
311 318
312 /* lookup by nlattr */ 319 /* lookup by nlattr */
313 static struct tc_action_ops *tc_lookup_action( 320 static struct tc_action_ops *tc_lookup_action(struct nlattr *kind)
314 { 321 {
315 struct tc_action_ops *a = NULL; 322 struct tc_action_ops *a = NULL;
316 323
317 if (kind) { 324 if (kind) {
318 read_lock(&act_mod_lock); 325 read_lock(&act_mod_lock);
319 for (a = act_base; a; a = a->n 326 for (a = act_base; a; a = a->next) {
320 if (nla_strcmp(kind, a 327 if (nla_strcmp(kind, a->kind) == 0) {
321 if (!try_modul 328 if (!try_module_get(a->owner)) {
322 read_u 329 read_unlock(&act_mod_lock);
323 return 330 return NULL;
324 } 331 }
325 break; 332 break;
326 } 333 }
327 } 334 }
328 read_unlock(&act_mod_lock); 335 read_unlock(&act_mod_lock);
329 } 336 }
330 return a; 337 return a;
331 } 338 }
332 339
333 #if 0 340 #if 0
334 /* lookup by id */ 341 /* lookup by id */
335 static struct tc_action_ops *tc_lookup_action_ 342 static struct tc_action_ops *tc_lookup_action_id(u32 type)
336 { 343 {
337 struct tc_action_ops *a = NULL; 344 struct tc_action_ops *a = NULL;
338 345
339 if (type) { 346 if (type) {
340 read_lock(&act_mod_lock); 347 read_lock(&act_mod_lock);
341 for (a = act_base; a; a = a->n 348 for (a = act_base; a; a = a->next) {
342 if (a->type == type) { 349 if (a->type == type) {
343 if (!try_modul 350 if (!try_module_get(a->owner)) {
344 read_u 351 read_unlock(&act_mod_lock);
345 return 352 return NULL;
346 } 353 }
347 break; 354 break;
348 } 355 }
349 } 356 }
350 read_unlock(&act_mod_lock); 357 read_unlock(&act_mod_lock);
351 } 358 }
352 return a; 359 return a;
353 } 360 }
354 #endif 361 #endif
355 362
356 int tcf_action_exec(struct sk_buff *skb, struc 363 int tcf_action_exec(struct sk_buff *skb, struct tc_action *act,
357 struct tcf_result *res) 364 struct tcf_result *res)
358 { 365 {
359 struct tc_action *a; 366 struct tc_action *a;
360 int ret = -1; 367 int ret = -1;
361 368
362 if (skb->tc_verd & TC_NCLS) { 369 if (skb->tc_verd & TC_NCLS) {
363 skb->tc_verd = CLR_TC_NCLS(skb 370 skb->tc_verd = CLR_TC_NCLS(skb->tc_verd);
364 ret = TC_ACT_OK; 371 ret = TC_ACT_OK;
365 goto exec_done; 372 goto exec_done;
366 } 373 }
367 while ((a = act) != NULL) { 374 while ((a = act) != NULL) {
368 repeat: 375 repeat:
369 if (a->ops && a->ops->act) { 376 if (a->ops && a->ops->act) {
370 ret = a->ops->act(skb, 377 ret = a->ops->act(skb, a, res);
371 if (TC_MUNGED & skb->t 378 if (TC_MUNGED & skb->tc_verd) {
372 /* copied alre 379 /* copied already, allow trampling */
373 skb->tc_verd = 380 skb->tc_verd = SET_TC_OK2MUNGE(skb->tc_verd);
374 skb->tc_verd = 381 skb->tc_verd = CLR_TC_MUNGED(skb->tc_verd);
375 } 382 }
376 if (ret == TC_ACT_REPE 383 if (ret == TC_ACT_REPEAT)
377 goto repeat; 384 goto repeat; /* we need a ttl - JHS */
378 if (ret != TC_ACT_PIPE 385 if (ret != TC_ACT_PIPE)
379 goto exec_done 386 goto exec_done;
380 } 387 }
381 act = a->next; 388 act = a->next;
382 } 389 }
383 exec_done: 390 exec_done:
384 return ret; 391 return ret;
385 } 392 }
386 EXPORT_SYMBOL(tcf_action_exec); 393 EXPORT_SYMBOL(tcf_action_exec);
387 394
388 void tcf_action_destroy(struct tc_action *act, 395 void tcf_action_destroy(struct tc_action *act, int bind)
389 { 396 {
390 struct tc_action *a; 397 struct tc_action *a;
391 398
392 for (a = act; a; a = act) { 399 for (a = act; a; a = act) {
393 if (a->ops && a->ops->cleanup) 400 if (a->ops && a->ops->cleanup) {
394 if (a->ops->cleanup(a, 401 if (a->ops->cleanup(a, bind) == ACT_P_DELETED)
395 module_put(a-> 402 module_put(a->ops->owner);
396 act = act->next; 403 act = act->next;
397 kfree(a); 404 kfree(a);
398 } else { /*FIXME: Remove later 405 } else { /*FIXME: Remove later - catch insertion bugs*/
399 printk("tcf_action_des 406 printk("tcf_action_destroy: BUG? destroying NULL ops\n");
400 act = act->next; 407 act = act->next;
401 kfree(a); 408 kfree(a);
402 } 409 }
403 } 410 }
404 } 411 }
405 412
406 int 413 int
407 tcf_action_dump_old(struct sk_buff *skb, struc 414 tcf_action_dump_old(struct sk_buff *skb, struct tc_action *a, int bind, int ref)
408 { 415 {
409 int err = -EINVAL; 416 int err = -EINVAL;
410 417
411 if (a->ops == NULL || a->ops->dump == 418 if (a->ops == NULL || a->ops->dump == NULL)
412 return err; 419 return err;
413 return a->ops->dump(skb, a, bind, ref) 420 return a->ops->dump(skb, a, bind, ref);
414 } 421 }
415 422
416 int 423 int
417 tcf_action_dump_1(struct sk_buff *skb, struct 424 tcf_action_dump_1(struct sk_buff *skb, struct tc_action *a, int bind, int ref)
418 { 425 {
419 int err = -EINVAL; 426 int err = -EINVAL;
420 unsigned char *b = skb_tail_pointer(sk 427 unsigned char *b = skb_tail_pointer(skb);
421 struct nlattr *nest; 428 struct nlattr *nest;
422 429
423 if (a->ops == NULL || a->ops->dump == 430 if (a->ops == NULL || a->ops->dump == NULL)
424 return err; 431 return err;
425 432
426 NLA_PUT_STRING(skb, TCA_KIND, a->ops-> 433 NLA_PUT_STRING(skb, TCA_KIND, a->ops->kind);
427 if (tcf_action_copy_stats(skb, a, 0)) 434 if (tcf_action_copy_stats(skb, a, 0))
428 goto nla_put_failure; 435 goto nla_put_failure;
429 nest = nla_nest_start(skb, TCA_OPTIONS 436 nest = nla_nest_start(skb, TCA_OPTIONS);
430 if (nest == NULL) 437 if (nest == NULL)
431 goto nla_put_failure; 438 goto nla_put_failure;
432 if ((err = tcf_action_dump_old(skb, a, 439 if ((err = tcf_action_dump_old(skb, a, bind, ref)) > 0) {
433 nla_nest_end(skb, nest); 440 nla_nest_end(skb, nest);
434 return err; 441 return err;
435 } 442 }
436 443
437 nla_put_failure: 444 nla_put_failure:
438 nlmsg_trim(skb, b); 445 nlmsg_trim(skb, b);
439 return -1; 446 return -1;
440 } 447 }
441 EXPORT_SYMBOL(tcf_action_dump_1); 448 EXPORT_SYMBOL(tcf_action_dump_1);
442 449
443 int 450 int
444 tcf_action_dump(struct sk_buff *skb, struct tc 451 tcf_action_dump(struct sk_buff *skb, struct tc_action *act, int bind, int ref)
445 { 452 {
446 struct tc_action *a; 453 struct tc_action *a;
447 int err = -EINVAL; 454 int err = -EINVAL;
448 struct nlattr *nest; 455 struct nlattr *nest;
449 456
450 while ((a = act) != NULL) { 457 while ((a = act) != NULL) {
451 act = a->next; 458 act = a->next;
452 nest = nla_nest_start(skb, a-> 459 nest = nla_nest_start(skb, a->order);
453 if (nest == NULL) 460 if (nest == NULL)
454 goto nla_put_failure; 461 goto nla_put_failure;
455 err = tcf_action_dump_1(skb, a 462 err = tcf_action_dump_1(skb, a, bind, ref);
456 if (err < 0) 463 if (err < 0)
457 goto errout; 464 goto errout;
458 nla_nest_end(skb, nest); 465 nla_nest_end(skb, nest);
459 } 466 }
460 467
461 return 0; 468 return 0;
462 469
463 nla_put_failure: 470 nla_put_failure:
464 err = -EINVAL; 471 err = -EINVAL;
465 errout: 472 errout:
466 nla_nest_cancel(skb, nest); 473 nla_nest_cancel(skb, nest);
467 return err; 474 return err;
468 } 475 }
469 476
470 struct tc_action *tcf_action_init_1(struct nla 477 struct tc_action *tcf_action_init_1(struct nlattr *nla, struct nlattr *est,
471 char *name 478 char *name, int ovr, int bind)
472 { 479 {
473 struct tc_action *a; 480 struct tc_action *a;
474 struct tc_action_ops *a_o; 481 struct tc_action_ops *a_o;
475 char act_name[IFNAMSIZ]; 482 char act_name[IFNAMSIZ];
476 struct nlattr *tb[TCA_ACT_MAX+1]; 483 struct nlattr *tb[TCA_ACT_MAX+1];
477 struct nlattr *kind; 484 struct nlattr *kind;
478 int err; 485 int err;
479 486
480 if (name == NULL) { 487 if (name == NULL) {
481 err = nla_parse_nested(tb, TCA 488 err = nla_parse_nested(tb, TCA_ACT_MAX, nla, NULL);
482 if (err < 0) 489 if (err < 0)
483 goto err_out; 490 goto err_out;
484 err = -EINVAL; 491 err = -EINVAL;
485 kind = tb[TCA_ACT_KIND]; 492 kind = tb[TCA_ACT_KIND];
486 if (kind == NULL) 493 if (kind == NULL)
487 goto err_out; 494 goto err_out;
488 if (nla_strlcpy(act_name, kind 495 if (nla_strlcpy(act_name, kind, IFNAMSIZ) >= IFNAMSIZ)
489 goto err_out; 496 goto err_out;
490 } else { 497 } else {
491 err = -EINVAL; 498 err = -EINVAL;
492 if (strlcpy(act_name, name, IF 499 if (strlcpy(act_name, name, IFNAMSIZ) >= IFNAMSIZ)
493 goto err_out; 500 goto err_out;
494 } 501 }
495 502
496 a_o = tc_lookup_action_n(act_name); 503 a_o = tc_lookup_action_n(act_name);
497 if (a_o == NULL) { 504 if (a_o == NULL) {
498 #ifdef CONFIG_KMOD !! 505 #ifdef CONFIG_MODULES
499 rtnl_unlock(); 506 rtnl_unlock();
500 request_module("act_%s", act_n 507 request_module("act_%s", act_name);
501 rtnl_lock(); 508 rtnl_lock();
502 509
503 a_o = tc_lookup_action_n(act_n 510 a_o = tc_lookup_action_n(act_name);
504 511
505 /* We dropped the RTNL semapho 512 /* We dropped the RTNL semaphore in order to
506 * perform the module load. S 513 * perform the module load. So, even if we
507 * succeeded in loading the mo 514 * succeeded in loading the module we have to
508 * tell the caller to replay t 515 * tell the caller to replay the request. We
509 * indicate this using -EAGAIN 516 * indicate this using -EAGAIN.
510 */ 517 */
511 if (a_o != NULL) { 518 if (a_o != NULL) {
512 err = -EAGAIN; 519 err = -EAGAIN;
513 goto err_mod; 520 goto err_mod;
514 } 521 }
515 #endif 522 #endif
516 err = -ENOENT; 523 err = -ENOENT;
517 goto err_out; 524 goto err_out;
518 } 525 }
519 526
520 err = -ENOMEM; 527 err = -ENOMEM;
521 a = kzalloc(sizeof(*a), GFP_KERNEL); 528 a = kzalloc(sizeof(*a), GFP_KERNEL);
522 if (a == NULL) 529 if (a == NULL)
523 goto err_mod; 530 goto err_mod;
524 531
525 /* backward compatibility for policer 532 /* backward compatibility for policer */
526 if (name == NULL) 533 if (name == NULL)
527 err = a_o->init(tb[TCA_ACT_OPT 534 err = a_o->init(tb[TCA_ACT_OPTIONS], est, a, ovr, bind);
528 else 535 else
529 err = a_o->init(nla, est, a, o 536 err = a_o->init(nla, est, a, ovr, bind);
530 if (err < 0) 537 if (err < 0)
531 goto err_free; 538 goto err_free;
532 539
533 /* module count goes up only when bran 540 /* module count goes up only when brand new policy is created
534 if it exists and is only bound to i 541 if it exists and is only bound to in a_o->init() then
535 ACT_P_CREATED is not returned (a ze 542 ACT_P_CREATED is not returned (a zero is).
536 */ 543 */
537 if (err != ACT_P_CREATED) 544 if (err != ACT_P_CREATED)
538 module_put(a_o->owner); 545 module_put(a_o->owner);
539 a->ops = a_o; 546 a->ops = a_o;
540 547
541 return a; 548 return a;
542 549
543 err_free: 550 err_free:
544 kfree(a); 551 kfree(a);
545 err_mod: 552 err_mod:
546 module_put(a_o->owner); 553 module_put(a_o->owner);
547 err_out: 554 err_out:
548 return ERR_PTR(err); 555 return ERR_PTR(err);
549 } 556 }
550 557
551 struct tc_action *tcf_action_init(struct nlatt 558 struct tc_action *tcf_action_init(struct nlattr *nla, struct nlattr *est,
552 char *name, 559 char *name, int ovr, int bind)
553 { 560 {
554 struct nlattr *tb[TCA_ACT_MAX_PRIO+1]; 561 struct nlattr *tb[TCA_ACT_MAX_PRIO+1];
555 struct tc_action *head = NULL, *act, * 562 struct tc_action *head = NULL, *act, *act_prev = NULL;
556 int err; 563 int err;
557 int i; 564 int i;
558 565
559 err = nla_parse_nested(tb, TCA_ACT_MAX 566 err = nla_parse_nested(tb, TCA_ACT_MAX_PRIO, nla, NULL);
560 if (err < 0) 567 if (err < 0)
561 return ERR_PTR(err); 568 return ERR_PTR(err);
562 569
563 for (i = 1; i <= TCA_ACT_MAX_PRIO && t 570 for (i = 1; i <= TCA_ACT_MAX_PRIO && tb[i]; i++) {
564 act = tcf_action_init_1(tb[i], 571 act = tcf_action_init_1(tb[i], est, name, ovr, bind);
565 if (IS_ERR(act)) 572 if (IS_ERR(act))
566 goto err; 573 goto err;
567 act->order = i; 574 act->order = i;
568 575
569 if (head == NULL) 576 if (head == NULL)
570 head = act; 577 head = act;
571 else 578 else
572 act_prev->next = act; 579 act_prev->next = act;
573 act_prev = act; 580 act_prev = act;
574 } 581 }
575 return head; 582 return head;
576 583
577 err: 584 err:
578 if (head != NULL) 585 if (head != NULL)
579 tcf_action_destroy(head, bind) 586 tcf_action_destroy(head, bind);
580 return act; 587 return act;
581 } 588 }
582 589
583 int tcf_action_copy_stats(struct sk_buff *skb, 590 int tcf_action_copy_stats(struct sk_buff *skb, struct tc_action *a,
584 int compat_mode) 591 int compat_mode)
585 { 592 {
586 int err = 0; 593 int err = 0;
587 struct gnet_dump d; 594 struct gnet_dump d;
588 struct tcf_act_hdr *h = a->priv; 595 struct tcf_act_hdr *h = a->priv;
589 596
590 if (h == NULL) 597 if (h == NULL)
591 goto errout; 598 goto errout;
592 599
593 /* compat_mode being true specifies a 600 /* compat_mode being true specifies a call that is supposed
594 * to add additional backward compatib 601 * to add additional backward compatiblity statistic TLVs.
595 */ 602 */
596 if (compat_mode) { 603 if (compat_mode) {
597 if (a->type == TCA_OLD_COMPAT) 604 if (a->type == TCA_OLD_COMPAT)
598 err = gnet_stats_start 605 err = gnet_stats_start_copy_compat(skb, 0,
599 TCA_STATS, TCA 606 TCA_STATS, TCA_XSTATS, &h->tcf_lock, &d);
600 else 607 else
601 return 0; 608 return 0;
602 } else 609 } else
603 err = gnet_stats_start_copy(sk 610 err = gnet_stats_start_copy(skb, TCA_ACT_STATS,
604 &h 611 &h->tcf_lock, &d);
605 612
606 if (err < 0) 613 if (err < 0)
607 goto errout; 614 goto errout;
608 615
609 if (a->ops != NULL && a->ops->get_stat 616 if (a->ops != NULL && a->ops->get_stats != NULL)
610 if (a->ops->get_stats(skb, a) 617 if (a->ops->get_stats(skb, a) < 0)
611 goto errout; 618 goto errout;
612 619
613 if (gnet_stats_copy_basic(&d, &h->tcf_ 620 if (gnet_stats_copy_basic(&d, &h->tcf_bstats) < 0 ||
614 gnet_stats_copy_rate_est(&d, &h->t 621 gnet_stats_copy_rate_est(&d, &h->tcf_rate_est) < 0 ||
615 gnet_stats_copy_queue(&d, &h->tcf_ 622 gnet_stats_copy_queue(&d, &h->tcf_qstats) < 0)
616 goto errout; 623 goto errout;
617 624
618 if (gnet_stats_finish_copy(&d) < 0) 625 if (gnet_stats_finish_copy(&d) < 0)
619 goto errout; 626 goto errout;
620 627
621 return 0; 628 return 0;
622 629
623 errout: 630 errout:
624 return -1; 631 return -1;
625 } 632 }
626 633
627 static int 634 static int
628 tca_get_fill(struct sk_buff *skb, struct tc_ac 635 tca_get_fill(struct sk_buff *skb, struct tc_action *a, u32 pid, u32 seq,
629 u16 flags, int event, int bind, i 636 u16 flags, int event, int bind, int ref)
630 { 637 {
631 struct tcamsg *t; 638 struct tcamsg *t;
632 struct nlmsghdr *nlh; 639 struct nlmsghdr *nlh;
633 unsigned char *b = skb_tail_pointer(sk 640 unsigned char *b = skb_tail_pointer(skb);
634 struct nlattr *nest; 641 struct nlattr *nest;
635 642
636 nlh = NLMSG_NEW(skb, pid, seq, event, 643 nlh = NLMSG_NEW(skb, pid, seq, event, sizeof(*t), flags);
637 644
638 t = NLMSG_DATA(nlh); 645 t = NLMSG_DATA(nlh);
639 t->tca_family = AF_UNSPEC; 646 t->tca_family = AF_UNSPEC;
640 t->tca__pad1 = 0; 647 t->tca__pad1 = 0;
641 t->tca__pad2 = 0; 648 t->tca__pad2 = 0;
642 649
643 nest = nla_nest_start(skb, TCA_ACT_TAB 650 nest = nla_nest_start(skb, TCA_ACT_TAB);
644 if (nest == NULL) 651 if (nest == NULL)
645 goto nla_put_failure; 652 goto nla_put_failure;
646 653
647 if (tcf_action_dump(skb, a, bind, ref) 654 if (tcf_action_dump(skb, a, bind, ref) < 0)
648 goto nla_put_failure; 655 goto nla_put_failure;
649 656
650 nla_nest_end(skb, nest); 657 nla_nest_end(skb, nest);
651 658
652 nlh->nlmsg_len = skb_tail_pointer(skb) 659 nlh->nlmsg_len = skb_tail_pointer(skb) - b;
653 return skb->len; 660 return skb->len;
654 661
655 nla_put_failure: 662 nla_put_failure:
656 nlmsg_failure: 663 nlmsg_failure:
657 nlmsg_trim(skb, b); 664 nlmsg_trim(skb, b);
658 return -1; 665 return -1;
659 } 666 }
660 667
661 static int 668 static int
662 act_get_notify(u32 pid, struct nlmsghdr *n, st 669 act_get_notify(u32 pid, struct nlmsghdr *n, struct tc_action *a, int event)
663 { 670 {
664 struct sk_buff *skb; 671 struct sk_buff *skb;
665 672
666 skb = alloc_skb(NLMSG_GOODSIZE, GFP_KE 673 skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
667 if (!skb) 674 if (!skb)
668 return -ENOBUFS; 675 return -ENOBUFS;
669 if (tca_get_fill(skb, a, pid, n->nlmsg 676 if (tca_get_fill(skb, a, pid, n->nlmsg_seq, 0, event, 0, 0) <= 0) {
670 kfree_skb(skb); 677 kfree_skb(skb);
671 return -EINVAL; 678 return -EINVAL;
672 } 679 }
673 680
674 return rtnl_unicast(skb, &init_net, pi 681 return rtnl_unicast(skb, &init_net, pid);
675 } 682 }
676 683
677 static struct tc_action * 684 static struct tc_action *
678 tcf_action_get_1(struct nlattr *nla, struct nl 685 tcf_action_get_1(struct nlattr *nla, struct nlmsghdr *n, u32 pid)
679 { 686 {
680 struct nlattr *tb[TCA_ACT_MAX+1]; 687 struct nlattr *tb[TCA_ACT_MAX+1];
681 struct tc_action *a; 688 struct tc_action *a;
682 int index; 689 int index;
683 int err; 690 int err;
684 691
685 err = nla_parse_nested(tb, TCA_ACT_MAX 692 err = nla_parse_nested(tb, TCA_ACT_MAX, nla, NULL);
686 if (err < 0) 693 if (err < 0)
687 goto err_out; 694 goto err_out;
688 695
689 err = -EINVAL; 696 err = -EINVAL;
690 if (tb[TCA_ACT_INDEX] == NULL || 697 if (tb[TCA_ACT_INDEX] == NULL ||
691 nla_len(tb[TCA_ACT_INDEX]) < sizeo 698 nla_len(tb[TCA_ACT_INDEX]) < sizeof(index))
692 goto err_out; 699 goto err_out;
693 index = nla_get_u32(tb[TCA_ACT_INDEX]) 700 index = nla_get_u32(tb[TCA_ACT_INDEX]);
694 701
695 err = -ENOMEM; 702 err = -ENOMEM;
696 a = kzalloc(sizeof(struct tc_action), 703 a = kzalloc(sizeof(struct tc_action), GFP_KERNEL);
697 if (a == NULL) 704 if (a == NULL)
698 goto err_out; 705 goto err_out;
699 706
700 err = -EINVAL; 707 err = -EINVAL;
701 a->ops = tc_lookup_action(tb[TCA_ACT_K 708 a->ops = tc_lookup_action(tb[TCA_ACT_KIND]);
702 if (a->ops == NULL) 709 if (a->ops == NULL)
703 goto err_free; 710 goto err_free;
704 if (a->ops->lookup == NULL) 711 if (a->ops->lookup == NULL)
705 goto err_mod; 712 goto err_mod;
706 err = -ENOENT; 713 err = -ENOENT;
707 if (a->ops->lookup(a, index) == 0) 714 if (a->ops->lookup(a, index) == 0)
708 goto err_mod; 715 goto err_mod;
709 716
710 module_put(a->ops->owner); 717 module_put(a->ops->owner);
711 return a; 718 return a;
712 719
713 err_mod: 720 err_mod:
714 module_put(a->ops->owner); 721 module_put(a->ops->owner);
715 err_free: 722 err_free:
716 kfree(a); 723 kfree(a);
717 err_out: 724 err_out:
718 return ERR_PTR(err); 725 return ERR_PTR(err);
719 } 726 }
720 727
721 static void cleanup_a(struct tc_action *act) 728 static void cleanup_a(struct tc_action *act)
722 { 729 {
723 struct tc_action *a; 730 struct tc_action *a;
724 731
725 for (a = act; a; a = act) { 732 for (a = act; a; a = act) {
726 act = a->next; 733 act = a->next;
727 kfree(a); 734 kfree(a);
728 } 735 }
729 } 736 }
730 737
731 static struct tc_action *create_a(int i) 738 static struct tc_action *create_a(int i)
732 { 739 {
733 struct tc_action *act; 740 struct tc_action *act;
734 741
735 act = kzalloc(sizeof(*act), GFP_KERNEL 742 act = kzalloc(sizeof(*act), GFP_KERNEL);
736 if (act == NULL) { 743 if (act == NULL) {
737 printk("create_a: failed to al 744 printk("create_a: failed to alloc!\n");
738 return NULL; 745 return NULL;
739 } 746 }
740 act->order = i; 747 act->order = i;
741 return act; 748 return act;
742 } 749 }
743 750
744 static int tca_action_flush(struct nlattr *nla 751 static int tca_action_flush(struct nlattr *nla, struct nlmsghdr *n, u32 pid)
745 { 752 {
746 struct sk_buff *skb; 753 struct sk_buff *skb;
747 unsigned char *b; 754 unsigned char *b;
748 struct nlmsghdr *nlh; 755 struct nlmsghdr *nlh;
749 struct tcamsg *t; 756 struct tcamsg *t;
750 struct netlink_callback dcb; 757 struct netlink_callback dcb;
751 struct nlattr *nest; 758 struct nlattr *nest;
752 struct nlattr *tb[TCA_ACT_MAX+1]; 759 struct nlattr *tb[TCA_ACT_MAX+1];
753 struct nlattr *kind; 760 struct nlattr *kind;
754 struct tc_action *a = create_a(0); 761 struct tc_action *a = create_a(0);
755 int err = -EINVAL; !! 762 int err = -ENOMEM;
756 763
757 if (a == NULL) { 764 if (a == NULL) {
758 printk("tca_action_flush: coul 765 printk("tca_action_flush: couldnt create tc_action\n");
759 return err; 766 return err;
760 } 767 }
761 768
762 skb = alloc_skb(NLMSG_GOODSIZE, GFP_KE 769 skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
763 if (!skb) { 770 if (!skb) {
764 printk("tca_action_flush: fail 771 printk("tca_action_flush: failed skb alloc\n");
765 kfree(a); 772 kfree(a);
766 return -ENOBUFS; !! 773 return err;
767 } 774 }
768 775
769 b = skb_tail_pointer(skb); 776 b = skb_tail_pointer(skb);
770 777
771 err = nla_parse_nested(tb, TCA_ACT_MAX 778 err = nla_parse_nested(tb, TCA_ACT_MAX, nla, NULL);
772 if (err < 0) 779 if (err < 0)
773 goto err_out; 780 goto err_out;
774 781
775 err = -EINVAL; 782 err = -EINVAL;
776 kind = tb[TCA_ACT_KIND]; 783 kind = tb[TCA_ACT_KIND];
777 a->ops = tc_lookup_action(kind); 784 a->ops = tc_lookup_action(kind);
778 if (a->ops == NULL) 785 if (a->ops == NULL)
779 goto err_out; 786 goto err_out;
780 787
781 nlh = NLMSG_PUT(skb, pid, n->nlmsg_seq 788 nlh = NLMSG_PUT(skb, pid, n->nlmsg_seq, RTM_DELACTION, sizeof(*t));
782 t = NLMSG_DATA(nlh); 789 t = NLMSG_DATA(nlh);
783 t->tca_family = AF_UNSPEC; 790 t->tca_family = AF_UNSPEC;
784 t->tca__pad1 = 0; 791 t->tca__pad1 = 0;
785 t->tca__pad2 = 0; 792 t->tca__pad2 = 0;
786 793
787 nest = nla_nest_start(skb, TCA_ACT_TAB 794 nest = nla_nest_start(skb, TCA_ACT_TAB);
788 if (nest == NULL) 795 if (nest == NULL)
789 goto nla_put_failure; 796 goto nla_put_failure;
790 797
791 err = a->ops->walk(skb, &dcb, RTM_DELA 798 err = a->ops->walk(skb, &dcb, RTM_DELACTION, a);
792 if (err < 0) 799 if (err < 0)
793 goto nla_put_failure; 800 goto nla_put_failure;
>> 801 if (err == 0)
>> 802 goto noflush_out;
794 803
795 nla_nest_end(skb, nest); 804 nla_nest_end(skb, nest);
796 805
797 nlh->nlmsg_len = skb_tail_pointer(skb) 806 nlh->nlmsg_len = skb_tail_pointer(skb) - b;
798 nlh->nlmsg_flags |= NLM_F_ROOT; 807 nlh->nlmsg_flags |= NLM_F_ROOT;
799 module_put(a->ops->owner); 808 module_put(a->ops->owner);
800 kfree(a); 809 kfree(a);
801 err = rtnetlink_send(skb, &init_net, p 810 err = rtnetlink_send(skb, &init_net, pid, RTNLGRP_TC, n->nlmsg_flags&NLM_F_ECHO);
802 if (err > 0) 811 if (err > 0)
803 return 0; 812 return 0;
804 813
805 return err; 814 return err;
806 815
807 nla_put_failure: 816 nla_put_failure:
808 nlmsg_failure: 817 nlmsg_failure:
809 module_put(a->ops->owner); 818 module_put(a->ops->owner);
810 err_out: 819 err_out:
>> 820 noflush_out:
811 kfree_skb(skb); 821 kfree_skb(skb);
812 kfree(a); 822 kfree(a);
813 return err; 823 return err;
814 } 824 }
815 825
816 static int 826 static int
817 tca_action_gd(struct nlattr *nla, struct nlmsg 827 tca_action_gd(struct nlattr *nla, struct nlmsghdr *n, u32 pid, int event)
818 { 828 {
819 int i, ret; 829 int i, ret;
820 struct nlattr *tb[TCA_ACT_MAX_PRIO+1]; 830 struct nlattr *tb[TCA_ACT_MAX_PRIO+1];
821 struct tc_action *head = NULL, *act, * 831 struct tc_action *head = NULL, *act, *act_prev = NULL;
822 832
823 ret = nla_parse_nested(tb, TCA_ACT_MAX 833 ret = nla_parse_nested(tb, TCA_ACT_MAX_PRIO, nla, NULL);
824 if (ret < 0) 834 if (ret < 0)
825 return ret; 835 return ret;
826 836
827 if (event == RTM_DELACTION && n->nlmsg 837 if (event == RTM_DELACTION && n->nlmsg_flags&NLM_F_ROOT) {
828 if (tb[0] != NULL && tb[1] == !! 838 if (tb[1] != NULL)
829 return tca_action_flus !! 839 return tca_action_flush(tb[1], n, pid);
>> 840 else
>> 841 return -EINVAL;
830 } 842 }
831 843
832 for (i = 1; i <= TCA_ACT_MAX_PRIO && t 844 for (i = 1; i <= TCA_ACT_MAX_PRIO && tb[i]; i++) {
833 act = tcf_action_get_1(tb[i], 845 act = tcf_action_get_1(tb[i], n, pid);
834 if (IS_ERR(act)) { 846 if (IS_ERR(act)) {
835 ret = PTR_ERR(act); 847 ret = PTR_ERR(act);
836 goto err; 848 goto err;
837 } 849 }
838 act->order = i; 850 act->order = i;
839 851
840 if (head == NULL) 852 if (head == NULL)
841 head = act; 853 head = act;
842 else 854 else
843 act_prev->next = act; 855 act_prev->next = act;
844 act_prev = act; 856 act_prev = act;
845 } 857 }
846 858
847 if (event == RTM_GETACTION) 859 if (event == RTM_GETACTION)
848 ret = act_get_notify(pid, n, h 860 ret = act_get_notify(pid, n, head, event);
849 else { /* delete */ 861 else { /* delete */
850 struct sk_buff *skb; 862 struct sk_buff *skb;
851 863
852 skb = alloc_skb(NLMSG_GOODSIZE 864 skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
853 if (!skb) { 865 if (!skb) {
854 ret = -ENOBUFS; 866 ret = -ENOBUFS;
855 goto err; 867 goto err;
856 } 868 }
857 869
858 if (tca_get_fill(skb, head, pi 870 if (tca_get_fill(skb, head, pid, n->nlmsg_seq, 0, event,
859 0, 1) <= 0) { 871 0, 1) <= 0) {
860 kfree_skb(skb); 872 kfree_skb(skb);
861 ret = -EINVAL; 873 ret = -EINVAL;
862 goto err; 874 goto err;
863 } 875 }
864 876
865 /* now do the delete */ 877 /* now do the delete */
866 tcf_action_destroy(head, 0); 878 tcf_action_destroy(head, 0);
867 ret = rtnetlink_send(skb, &ini 879 ret = rtnetlink_send(skb, &init_net, pid, RTNLGRP_TC,
868 n->nlmsg_ 880 n->nlmsg_flags&NLM_F_ECHO);
869 if (ret > 0) 881 if (ret > 0)
870 return 0; 882 return 0;
871 return ret; 883 return ret;
872 } 884 }
873 err: 885 err:
874 cleanup_a(head); 886 cleanup_a(head);
875 return ret; 887 return ret;
876 } 888 }
877 889
878 static int tcf_add_notify(struct tc_action *a, 890 static int tcf_add_notify(struct tc_action *a, u32 pid, u32 seq, int event,
879 u16 flags) 891 u16 flags)
880 { 892 {
881 struct tcamsg *t; 893 struct tcamsg *t;
882 struct nlmsghdr *nlh; 894 struct nlmsghdr *nlh;
883 struct sk_buff *skb; 895 struct sk_buff *skb;
884 struct nlattr *nest; 896 struct nlattr *nest;
885 unsigned char *b; 897 unsigned char *b;
886 int err = 0; 898 int err = 0;
887 899
888 skb = alloc_skb(NLMSG_GOODSIZE, GFP_KE 900 skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
889 if (!skb) 901 if (!skb)
890 return -ENOBUFS; 902 return -ENOBUFS;
891 903
892 b = skb_tail_pointer(skb); 904 b = skb_tail_pointer(skb);
893 905
894 nlh = NLMSG_NEW(skb, pid, seq, event, 906 nlh = NLMSG_NEW(skb, pid, seq, event, sizeof(*t), flags);
895 t = NLMSG_DATA(nlh); 907 t = NLMSG_DATA(nlh);
896 t->tca_family = AF_UNSPEC; 908 t->tca_family = AF_UNSPEC;
897 t->tca__pad1 = 0; 909 t->tca__pad1 = 0;
898 t->tca__pad2 = 0; 910 t->tca__pad2 = 0;
899 911
900 nest = nla_nest_start(skb, TCA_ACT_TAB 912 nest = nla_nest_start(skb, TCA_ACT_TAB);
901 if (nest == NULL) 913 if (nest == NULL)
902 goto nla_put_failure; 914 goto nla_put_failure;
903 915
904 if (tcf_action_dump(skb, a, 0, 0) < 0) 916 if (tcf_action_dump(skb, a, 0, 0) < 0)
905 goto nla_put_failure; 917 goto nla_put_failure;
906 918
907 nla_nest_end(skb, nest); 919 nla_nest_end(skb, nest);
908 920
909 nlh->nlmsg_len = skb_tail_pointer(skb) 921 nlh->nlmsg_len = skb_tail_pointer(skb) - b;
910 NETLINK_CB(skb).dst_group = RTNLGRP_TC 922 NETLINK_CB(skb).dst_group = RTNLGRP_TC;
911 923
912 err = rtnetlink_send(skb, &init_net, p 924 err = rtnetlink_send(skb, &init_net, pid, RTNLGRP_TC, flags&NLM_F_ECHO);
913 if (err > 0) 925 if (err > 0)
914 err = 0; 926 err = 0;
915 return err; 927 return err;
916 928
917 nla_put_failure: 929 nla_put_failure:
918 nlmsg_failure: 930 nlmsg_failure:
919 kfree_skb(skb); 931 kfree_skb(skb);
920 return -1; 932 return -1;
921 } 933 }
922 934
923 935
924 static int 936 static int
925 tcf_action_add(struct nlattr *nla, struct nlms 937 tcf_action_add(struct nlattr *nla, struct nlmsghdr *n, u32 pid, int ovr)
926 { 938 {
927 int ret = 0; 939 int ret = 0;
928 struct tc_action *act; 940 struct tc_action *act;
929 struct tc_action *a; 941 struct tc_action *a;
930 u32 seq = n->nlmsg_seq; 942 u32 seq = n->nlmsg_seq;
931 943
932 act = tcf_action_init(nla, NULL, NULL, 944 act = tcf_action_init(nla, NULL, NULL, ovr, 0);
933 if (act == NULL) 945 if (act == NULL)
934 goto done; 946 goto done;
935 if (IS_ERR(act)) { 947 if (IS_ERR(act)) {
936 ret = PTR_ERR(act); 948 ret = PTR_ERR(act);
937 goto done; 949 goto done;
938 } 950 }
939 951
940 /* dump then free all the actions afte 952 /* dump then free all the actions after update; inserted policy
941 * stays intact 953 * stays intact
942 * */ 954 * */
943 ret = tcf_add_notify(act, pid, seq, RT 955 ret = tcf_add_notify(act, pid, seq, RTM_NEWACTION, n->nlmsg_flags);
944 for (a = act; a; a = act) { 956 for (a = act; a; a = act) {
945 act = a->next; 957 act = a->next;
946 kfree(a); 958 kfree(a);
947 } 959 }
948 done: 960 done:
949 return ret; 961 return ret;
950 } 962 }
951 963
952 static int tc_ctl_action(struct sk_buff *skb, 964 static int tc_ctl_action(struct sk_buff *skb, struct nlmsghdr *n, void *arg)
953 { 965 {
954 struct net *net = skb->sk->sk_net; !! 966 struct net *net = sock_net(skb->sk);
955 struct nlattr *tca[TCA_ACT_MAX + 1]; 967 struct nlattr *tca[TCA_ACT_MAX + 1];
956 u32 pid = skb ? NETLINK_CB(skb).pid : 968 u32 pid = skb ? NETLINK_CB(skb).pid : 0;
957 int ret = 0, ovr = 0; 969 int ret = 0, ovr = 0;
958 970
959 if (net != &init_net) 971 if (net != &init_net)
960 return -EINVAL; 972 return -EINVAL;
961 973
962 ret = nlmsg_parse(n, sizeof(struct tca 974 ret = nlmsg_parse(n, sizeof(struct tcamsg), tca, TCA_ACT_MAX, NULL);
963 if (ret < 0) 975 if (ret < 0)
964 return ret; 976 return ret;
965 977
966 if (tca[TCA_ACT_TAB] == NULL) { 978 if (tca[TCA_ACT_TAB] == NULL) {
967 printk("tc_ctl_action: receive 979 printk("tc_ctl_action: received NO action attribs\n");
968 return -EINVAL; 980 return -EINVAL;
969 } 981 }
970 982
971 /* n->nlmsg_flags&NLM_F_CREATE 983 /* n->nlmsg_flags&NLM_F_CREATE
972 * */ 984 * */
973 switch (n->nlmsg_type) { 985 switch (n->nlmsg_type) {
974 case RTM_NEWACTION: 986 case RTM_NEWACTION:
975 /* we are going to assume all 987 /* we are going to assume all other flags
976 * imply create only if it doe 988 * imply create only if it doesnt exist
977 * Note that CREATE | EXCL imp 989 * Note that CREATE | EXCL implies that
978 * but since we want avoid amb 990 * but since we want avoid ambiguity (eg when flags
979 * is zero) then just set this 991 * is zero) then just set this
980 */ 992 */
981 if (n->nlmsg_flags&NLM_F_REPLA 993 if (n->nlmsg_flags&NLM_F_REPLACE)
982 ovr = 1; 994 ovr = 1;
983 replay: 995 replay:
984 ret = tcf_action_add(tca[TCA_A 996 ret = tcf_action_add(tca[TCA_ACT_TAB], n, pid, ovr);
985 if (ret == -EAGAIN) 997 if (ret == -EAGAIN)
986 goto replay; 998 goto replay;
987 break; 999 break;
988 case RTM_DELACTION: 1000 case RTM_DELACTION:
989 ret = tca_action_gd(tca[TCA_AC 1001 ret = tca_action_gd(tca[TCA_ACT_TAB], n, pid, RTM_DELACTION);
990 break; 1002 break;
991 case RTM_GETACTION: 1003 case RTM_GETACTION:
992 ret = tca_action_gd(tca[TCA_AC 1004 ret = tca_action_gd(tca[TCA_ACT_TAB], n, pid, RTM_GETACTION);
993 break; 1005 break;
994 default: 1006 default:
995 BUG(); 1007 BUG();
996 } 1008 }
997 1009
998 return ret; 1010 return ret;
999 } 1011 }
1000 1012
1001 static struct nlattr * 1013 static struct nlattr *
1002 find_dump_kind(struct nlmsghdr *n) 1014 find_dump_kind(struct nlmsghdr *n)
1003 { 1015 {
1004 struct nlattr *tb1, *tb2[TCA_ACT_MAX+ 1016 struct nlattr *tb1, *tb2[TCA_ACT_MAX+1];
1005 struct nlattr *tb[TCA_ACT_MAX_PRIO + 1017 struct nlattr *tb[TCA_ACT_MAX_PRIO + 1];
1006 struct nlattr *nla[TCAA_MAX + 1]; 1018 struct nlattr *nla[TCAA_MAX + 1];
1007 struct nlattr *kind; 1019 struct nlattr *kind;
1008 1020
1009 if (nlmsg_parse(n, sizeof(struct tcam 1021 if (nlmsg_parse(n, sizeof(struct tcamsg), nla, TCAA_MAX, NULL) < 0)
1010 return NULL; 1022 return NULL;
1011 tb1 = nla[TCA_ACT_TAB]; 1023 tb1 = nla[TCA_ACT_TAB];
1012 if (tb1 == NULL) 1024 if (tb1 == NULL)
1013 return NULL; 1025 return NULL;
1014 1026
1015 if (nla_parse(tb, TCA_ACT_MAX_PRIO, n 1027 if (nla_parse(tb, TCA_ACT_MAX_PRIO, nla_data(tb1),
1016 NLMSG_ALIGN(nla_len(tb1 1028 NLMSG_ALIGN(nla_len(tb1)), NULL) < 0)
1017 return NULL; 1029 return NULL;
1018 1030
1019 if (tb[1] == NULL) 1031 if (tb[1] == NULL)
1020 return NULL; 1032 return NULL;
1021 if (nla_parse(tb2, TCA_ACT_MAX, nla_d 1033 if (nla_parse(tb2, TCA_ACT_MAX, nla_data(tb[1]),
1022 nla_len(tb[1]), NULL) < 1034 nla_len(tb[1]), NULL) < 0)
1023 return NULL; 1035 return NULL;
1024 kind = tb2[TCA_ACT_KIND]; 1036 kind = tb2[TCA_ACT_KIND];
1025 1037
1026 return kind; 1038 return kind;
1027 } 1039 }
1028 1040
1029 static int 1041 static int
1030 tc_dump_action(struct sk_buff *skb, struct ne 1042 tc_dump_action(struct sk_buff *skb, struct netlink_callback *cb)
1031 { 1043 {
1032 struct net *net = skb->sk->sk_net; !! 1044 struct net *net = sock_net(skb->sk);
1033 struct nlmsghdr *nlh; 1045 struct nlmsghdr *nlh;
1034 unsigned char *b = skb_tail_pointer(s 1046 unsigned char *b = skb_tail_pointer(skb);
1035 struct nlattr *nest; 1047 struct nlattr *nest;
1036 struct tc_action_ops *a_o; 1048 struct tc_action_ops *a_o;
1037 struct tc_action a; 1049 struct tc_action a;
1038 int ret = 0; 1050 int ret = 0;
1039 struct tcamsg *t = (struct tcamsg *) 1051 struct tcamsg *t = (struct tcamsg *) NLMSG_DATA(cb->nlh);
1040 struct nlattr *kind = find_dump_kind( 1052 struct nlattr *kind = find_dump_kind(cb->nlh);
1041 1053
1042 if (net != &init_net) 1054 if (net != &init_net)
1043 return 0; 1055 return 0;
1044 1056
1045 if (kind == NULL) { 1057 if (kind == NULL) {
1046 printk("tc_dump_action: actio 1058 printk("tc_dump_action: action bad kind\n");
1047 return 0; 1059 return 0;
1048 } 1060 }
1049 1061
1050 a_o = tc_lookup_action(kind); 1062 a_o = tc_lookup_action(kind);
1051 if (a_o == NULL) { 1063 if (a_o == NULL) {
1052 return 0; 1064 return 0;
1053 } 1065 }
1054 1066
1055 memset(&a, 0, sizeof(struct tc_action 1067 memset(&a, 0, sizeof(struct tc_action));
1056 a.ops = a_o; 1068 a.ops = a_o;
1057 1069
1058 if (a_o->walk == NULL) { 1070 if (a_o->walk == NULL) {
1059 printk("tc_dump_action: %s !c 1071 printk("tc_dump_action: %s !capable of dumping table\n", a_o->kind);
1060 goto nla_put_failure; 1072 goto nla_put_failure;
1061 } 1073 }
1062 1074
1063 nlh = NLMSG_PUT(skb, NETLINK_CB(cb->s 1075 nlh = NLMSG_PUT(skb, NETLINK_CB(cb->skb).pid, cb->nlh->nlmsg_seq,
1064 cb->nlh->nlmsg_type, 1076 cb->nlh->nlmsg_type, sizeof(*t));
1065 t = NLMSG_DATA(nlh); 1077 t = NLMSG_DATA(nlh);
1066 t->tca_family = AF_UNSPEC; 1078 t->tca_family = AF_UNSPEC;
1067 t->tca__pad1 = 0; 1079 t->tca__pad1 = 0;
1068 t->tca__pad2 = 0; 1080 t->tca__pad2 = 0;
1069 1081
1070 nest = nla_nest_start(skb, TCA_ACT_TA 1082 nest = nla_nest_start(skb, TCA_ACT_TAB);
1071 if (nest == NULL) 1083 if (nest == NULL)
1072 goto nla_put_failure; 1084 goto nla_put_failure;
1073 1085
1074 ret = a_o->walk(skb, cb, RTM_GETACTIO 1086 ret = a_o->walk(skb, cb, RTM_GETACTION, &a);
1075 if (ret < 0) 1087 if (ret < 0)
1076 goto nla_put_failure; 1088 goto nla_put_failure;
1077 1089
1078 if (ret > 0) { 1090 if (ret > 0) {
1079 nla_nest_end(skb, nest); 1091 nla_nest_end(skb, nest);
1080 ret = skb->len; 1092 ret = skb->len;
1081 } else 1093 } else
1082 nla_nest_cancel(skb, nest); 1094 nla_nest_cancel(skb, nest);
1083 1095
1084 nlh->nlmsg_len = skb_tail_pointer(skb 1096 nlh->nlmsg_len = skb_tail_pointer(skb) - b;
1085 if (NETLINK_CB(cb->skb).pid && ret) 1097 if (NETLINK_CB(cb->skb).pid && ret)
1086 nlh->nlmsg_flags |= NLM_F_MUL 1098 nlh->nlmsg_flags |= NLM_F_MULTI;
1087 module_put(a_o->owner); 1099 module_put(a_o->owner);
1088 return skb->len; 1100 return skb->len;
1089 1101
1090 nla_put_failure: 1102 nla_put_failure:
1091 nlmsg_failure: 1103 nlmsg_failure:
1092 module_put(a_o->owner); 1104 module_put(a_o->owner);
1093 nlmsg_trim(skb, b); 1105 nlmsg_trim(skb, b);
1094 return skb->len; 1106 return skb->len;
1095 } 1107 }
1096 1108
1097 static int __init tc_action_init(void) 1109 static int __init tc_action_init(void)
1098 { 1110 {
1099 rtnl_register(PF_UNSPEC, RTM_NEWACTIO 1111 rtnl_register(PF_UNSPEC, RTM_NEWACTION, tc_ctl_action, NULL);
1100 rtnl_register(PF_UNSPEC, RTM_DELACTIO 1112 rtnl_register(PF_UNSPEC, RTM_DELACTION, tc_ctl_action, NULL);
1101 rtnl_register(PF_UNSPEC, RTM_GETACTIO 1113 rtnl_register(PF_UNSPEC, RTM_GETACTION, tc_ctl_action, tc_dump_action);
1102 1114
1103 return 0; 1115 return 0;
1104 } 1116 }
1105 1117
1106 subsys_initcall(tc_action_init); 1118 subsys_initcall(tc_action_init);
1107 1119
|
This page was automatically generated by the
LXR engine.
|