Skip to content

Commit add93b6

Browse files
kaberdavem330
authored andcommitted
[NET_SCHED]: Convert classifiers from rtnetlink to new netlink API
Signed-off-by: Patrick McHardy <kaber@trash.net> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 1e90474 commit add93b6

12 files changed

Lines changed: 290 additions & 282 deletions

File tree

‎include/net/pkt_cls.h‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ tcf_exts_exec(struct sk_buff *skb, struct tcf_exts *exts,
129129
return 0;
130130
}
131131

132-
extern int tcf_exts_validate(struct tcf_proto *tp, struct rtattr **tb,
133-
struct rtattr *rate_tlv, struct tcf_exts *exts,
132+
extern int tcf_exts_validate(struct tcf_proto *tp, struct nlattr **tb,
133+
struct nlattr *rate_tlv, struct tcf_exts *exts,
134134
struct tcf_ext_map *map);
135135
extern void tcf_exts_destroy(struct tcf_proto *tp, struct tcf_exts *exts);
136136
extern void tcf_exts_change(struct tcf_proto *tp, struct tcf_exts *dst,
@@ -247,7 +247,7 @@ struct tcf_ematch_ops
247247

248248
extern int tcf_em_register(struct tcf_ematch_ops *);
249249
extern int tcf_em_unregister(struct tcf_ematch_ops *);
250-
extern int tcf_em_tree_validate(struct tcf_proto *, struct rtattr *,
250+
extern int tcf_em_tree_validate(struct tcf_proto *, struct nlattr *,
251251
struct tcf_ematch_tree *);
252252
extern void tcf_em_tree_destroy(struct tcf_proto *, struct tcf_ematch_tree *);
253253
extern int tcf_em_tree_dump(struct sk_buff *, struct tcf_ematch_tree *, int);
@@ -338,9 +338,9 @@ static inline int tcf_valid_offset(const struct sk_buff *skb,
338338
#include <net/net_namespace.h>
339339

340340
static inline int
341-
tcf_change_indev(struct tcf_proto *tp, char *indev, struct rtattr *indev_tlv)
341+
tcf_change_indev(struct tcf_proto *tp, char *indev, struct nlattr *indev_tlv)
342342
{
343-
if (rtattr_strlcpy(indev, indev_tlv, IFNAMSIZ) >= IFNAMSIZ)
343+
if (nla_strlcpy(indev, indev_tlv, IFNAMSIZ) >= IFNAMSIZ)
344344
return -EINVAL;
345345
return 0;
346346
}

‎include/net/sch_generic.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ struct tcf_proto_ops
126126
unsigned long (*get)(struct tcf_proto*, u32 handle);
127127
void (*put)(struct tcf_proto*, unsigned long);
128128
int (*change)(struct tcf_proto*, unsigned long,
129-
u32 handle, struct rtattr **,
129+
u32 handle, struct nlattr **,
130130
unsigned long *);
131131
int (*delete)(struct tcf_proto*, unsigned long);
132132
void (*walk)(struct tcf_proto*, struct tcf_walker *arg);

‎net/sched/cls_api.c‎

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ static DEFINE_RWLOCK(cls_mod_lock);
3838

3939
/* Find classifier type by string name */
4040

41-
static struct tcf_proto_ops *tcf_proto_lookup_ops(struct rtattr *kind)
41+
static struct tcf_proto_ops *tcf_proto_lookup_ops(struct nlattr *kind)
4242
{
4343
struct tcf_proto_ops *t = NULL;
4444

4545
if (kind) {
4646
read_lock(&cls_mod_lock);
4747
for (t = tcf_proto_base; t; t = t->next) {
48-
if (rtattr_strcmp(kind, t->kind) == 0) {
48+
if (nla_strcmp(kind, t->kind) == 0) {
4949
if (!try_module_get(t->owner))
5050
t = NULL;
5151
break;
@@ -118,7 +118,7 @@ static inline u32 tcf_auto_prio(struct tcf_proto *tp)
118118
static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n, void *arg)
119119
{
120120
struct net *net = skb->sk->sk_net;
121-
struct rtattr **tca;
121+
struct nlattr *tca[TCA_MAX + 1];
122122
struct tcmsg *t;
123123
u32 protocol;
124124
u32 prio;
@@ -138,7 +138,6 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n, void *arg)
138138
return -EINVAL;
139139

140140
replay:
141-
tca = arg;
142141
t = NLMSG_DATA(n);
143142
protocol = TC_H_MIN(t->tcm_info);
144143
prio = TC_H_MAJ(t->tcm_info);
@@ -160,6 +159,10 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n, void *arg)
160159
if (dev == NULL)
161160
return -ENODEV;
162161

162+
err = nlmsg_parse(n, sizeof(*t), tca, TCA_MAX, NULL);
163+
if (err < 0)
164+
return err;
165+
163166
/* Find qdisc */
164167
if (!parent) {
165168
q = dev->qdisc_sleeping;
@@ -202,7 +205,7 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n, void *arg)
202205
if (tp == NULL) {
203206
/* Proto-tcf does not exist, create new one */
204207

205-
if (tca[TCA_KIND-1] == NULL || !protocol)
208+
if (tca[TCA_KIND] == NULL || !protocol)
206209
goto errout;
207210

208211
err = -ENOENT;
@@ -217,14 +220,14 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n, void *arg)
217220
if (tp == NULL)
218221
goto errout;
219222
err = -EINVAL;
220-
tp_ops = tcf_proto_lookup_ops(tca[TCA_KIND-1]);
223+
tp_ops = tcf_proto_lookup_ops(tca[TCA_KIND]);
221224
if (tp_ops == NULL) {
222225
#ifdef CONFIG_KMOD
223-
struct rtattr *kind = tca[TCA_KIND-1];
226+
struct nlattr *kind = tca[TCA_KIND];
224227
char name[IFNAMSIZ];
225228

226229
if (kind != NULL &&
227-
rtattr_strlcpy(name, kind, IFNAMSIZ) < IFNAMSIZ) {
230+
nla_strlcpy(name, kind, IFNAMSIZ) < IFNAMSIZ) {
228231
rtnl_unlock();
229232
request_module("cls_%s", name);
230233
rtnl_lock();
@@ -263,7 +266,7 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n, void *arg)
263266
*back = tp;
264267
qdisc_unlock_tree(dev);
265268

266-
} else if (tca[TCA_KIND-1] && rtattr_strcmp(tca[TCA_KIND-1], tp->ops->kind))
269+
} else if (tca[TCA_KIND] && nla_strcmp(tca[TCA_KIND], tp->ops->kind))
267270
goto errout;
268271

269272
fh = tp->ops->get(tp, t->tcm_handle);
@@ -333,18 +336,18 @@ static int tcf_fill_node(struct sk_buff *skb, struct tcf_proto *tp,
333336
tcm->tcm_ifindex = tp->q->dev->ifindex;
334337
tcm->tcm_parent = tp->classid;
335338
tcm->tcm_info = TC_H_MAKE(tp->prio, tp->protocol);
336-
RTA_PUT(skb, TCA_KIND, IFNAMSIZ, tp->ops->kind);
339+
NLA_PUT(skb, TCA_KIND, IFNAMSIZ, tp->ops->kind);
337340
tcm->tcm_handle = fh;
338341
if (RTM_DELTFILTER != event) {
339342
tcm->tcm_handle = 0;
340343
if (tp->ops->dump && tp->ops->dump(tp, fh, skb, tcm) < 0)
341-
goto rtattr_failure;
344+
goto nla_put_failure;
342345
}
343346
nlh->nlmsg_len = skb_tail_pointer(skb) - b;
344347
return skb->len;
345348

346349
nlmsg_failure:
347-
rtattr_failure:
350+
nla_put_failure:
348351
nlmsg_trim(skb, b);
349352
return -1;
350353
}
@@ -476,8 +479,8 @@ void tcf_exts_destroy(struct tcf_proto *tp, struct tcf_exts *exts)
476479
}
477480
EXPORT_SYMBOL(tcf_exts_destroy);
478481

479-
int tcf_exts_validate(struct tcf_proto *tp, struct rtattr **tb,
480-
struct rtattr *rate_tlv, struct tcf_exts *exts,
482+
int tcf_exts_validate(struct tcf_proto *tp, struct nlattr **tb,
483+
struct nlattr *rate_tlv, struct tcf_exts *exts,
481484
struct tcf_ext_map *map)
482485
{
483486
memset(exts, 0, sizeof(*exts));
@@ -487,17 +490,19 @@ int tcf_exts_validate(struct tcf_proto *tp, struct rtattr **tb,
487490
int err;
488491
struct tc_action *act;
489492

490-
if (map->police && tb[map->police-1]) {
491-
act = tcf_action_init_1(tb[map->police-1], rate_tlv,
493+
if (map->police && tb[map->police]) {
494+
act = tcf_action_init_1((struct rtattr *)tb[map->police],
495+
(struct rtattr *)rate_tlv,
492496
"police", TCA_ACT_NOREPLACE,
493497
TCA_ACT_BIND, &err);
494498
if (act == NULL)
495499
return err;
496500

497501
act->type = TCA_OLD_COMPAT;
498502
exts->action = act;
499-
} else if (map->action && tb[map->action-1]) {
500-
act = tcf_action_init(tb[map->action-1], rate_tlv, NULL,
503+
} else if (map->action && tb[map->action]) {
504+
act = tcf_action_init((struct rtattr *)tb[map->action],
505+
(struct rtattr *)rate_tlv, NULL,
501506
TCA_ACT_NOREPLACE, TCA_ACT_BIND, &err);
502507
if (act == NULL)
503508
return err;
@@ -506,8 +511,8 @@ int tcf_exts_validate(struct tcf_proto *tp, struct rtattr **tb,
506511
}
507512
}
508513
#else
509-
if ((map->action && tb[map->action-1]) ||
510-
(map->police && tb[map->police-1]))
514+
if ((map->action && tb[map->action]) ||
515+
(map->police && tb[map->police]))
511516
return -EOPNOTSUPP;
512517
#endif
513518

@@ -541,23 +546,23 @@ int tcf_exts_dump(struct sk_buff *skb, struct tcf_exts *exts,
541546
* to work with both old and new modes of entering
542547
* tc data even if iproute2 was newer - jhs
543548
*/
544-
struct rtattr *p_rta = (struct rtattr *)skb_tail_pointer(skb);
549+
struct nlattr *p_rta = (struct nlattr *)skb_tail_pointer(skb);
545550

546551
if (exts->action->type != TCA_OLD_COMPAT) {
547-
RTA_PUT(skb, map->action, 0, NULL);
552+
NLA_PUT(skb, map->action, 0, NULL);
548553
if (tcf_action_dump(skb, exts->action, 0, 0) < 0)
549-
goto rtattr_failure;
550-
p_rta->rta_len = skb_tail_pointer(skb) - (u8 *)p_rta;
554+
goto nla_put_failure;
555+
p_rta->nla_len = skb_tail_pointer(skb) - (u8 *)p_rta;
551556
} else if (map->police) {
552-
RTA_PUT(skb, map->police, 0, NULL);
557+
NLA_PUT(skb, map->police, 0, NULL);
553558
if (tcf_action_dump_old(skb, exts->action, 0, 0) < 0)
554-
goto rtattr_failure;
555-
p_rta->rta_len = skb_tail_pointer(skb) - (u8 *)p_rta;
559+
goto nla_put_failure;
560+
p_rta->nla_len = skb_tail_pointer(skb) - (u8 *)p_rta;
556561
}
557562
}
558563
#endif
559564
return 0;
560-
rtattr_failure: __attribute__ ((unused))
565+
nla_put_failure: __attribute__ ((unused))
561566
return -1;
562567
}
563568
EXPORT_SYMBOL(tcf_exts_dump);
@@ -569,10 +574,10 @@ int tcf_exts_dump_stats(struct sk_buff *skb, struct tcf_exts *exts,
569574
#ifdef CONFIG_NET_CLS_ACT
570575
if (exts->action)
571576
if (tcf_action_copy_stats(skb, exts->action, 1) < 0)
572-
goto rtattr_failure;
577+
goto nla_put_failure;
573578
#endif
574579
return 0;
575-
rtattr_failure: __attribute__ ((unused))
580+
nla_put_failure: __attribute__ ((unused))
576581
return -1;
577582
}
578583
EXPORT_SYMBOL(tcf_exts_dump_stats);

‎net/sched/cls_basic.c‎

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -130,27 +130,27 @@ static int basic_delete(struct tcf_proto *tp, unsigned long arg)
130130
}
131131

132132
static inline int basic_set_parms(struct tcf_proto *tp, struct basic_filter *f,
133-
unsigned long base, struct rtattr **tb,
134-
struct rtattr *est)
133+
unsigned long base, struct nlattr **tb,
134+
struct nlattr *est)
135135
{
136136
int err = -EINVAL;
137137
struct tcf_exts e;
138138
struct tcf_ematch_tree t;
139139

140-
if (tb[TCA_BASIC_CLASSID-1])
141-
if (RTA_PAYLOAD(tb[TCA_BASIC_CLASSID-1]) < sizeof(u32))
140+
if (tb[TCA_BASIC_CLASSID])
141+
if (nla_len(tb[TCA_BASIC_CLASSID]) < sizeof(u32))
142142
return err;
143143

144144
err = tcf_exts_validate(tp, tb, est, &e, &basic_ext_map);
145145
if (err < 0)
146146
return err;
147147

148-
err = tcf_em_tree_validate(tp, tb[TCA_BASIC_EMATCHES-1], &t);
148+
err = tcf_em_tree_validate(tp, tb[TCA_BASIC_EMATCHES], &t);
149149
if (err < 0)
150150
goto errout;
151151

152-
if (tb[TCA_BASIC_CLASSID-1]) {
153-
f->res.classid = *(u32*)RTA_DATA(tb[TCA_BASIC_CLASSID-1]);
152+
if (tb[TCA_BASIC_CLASSID]) {
153+
f->res.classid = *(u32*)nla_data(tb[TCA_BASIC_CLASSID]);
154154
tcf_bind_filter(tp, &f->res, base);
155155
}
156156

@@ -164,23 +164,23 @@ static inline int basic_set_parms(struct tcf_proto *tp, struct basic_filter *f,
164164
}
165165

166166
static int basic_change(struct tcf_proto *tp, unsigned long base, u32 handle,
167-
struct rtattr **tca, unsigned long *arg)
167+
struct nlattr **tca, unsigned long *arg)
168168
{
169169
int err = -EINVAL;
170170
struct basic_head *head = (struct basic_head *) tp->root;
171-
struct rtattr *tb[TCA_BASIC_MAX];
171+
struct nlattr *tb[TCA_BASIC_MAX + 1];
172172
struct basic_filter *f = (struct basic_filter *) *arg;
173173

174-
if (tca[TCA_OPTIONS-1] == NULL)
174+
if (tca[TCA_OPTIONS] == NULL)
175175
return -EINVAL;
176176

177-
if (rtattr_parse_nested(tb, TCA_BASIC_MAX, tca[TCA_OPTIONS-1]) < 0)
177+
if (nla_parse_nested(tb, TCA_BASIC_MAX, tca[TCA_OPTIONS], NULL) < 0)
178178
return -EINVAL;
179179

180180
if (f != NULL) {
181181
if (handle && f->handle != handle)
182182
return -EINVAL;
183-
return basic_set_parms(tp, f, base, tb, tca[TCA_RATE-1]);
183+
return basic_set_parms(tp, f, base, tb, tca[TCA_RATE]);
184184
}
185185

186186
err = -ENOBUFS;
@@ -206,7 +206,7 @@ static int basic_change(struct tcf_proto *tp, unsigned long base, u32 handle,
206206
f->handle = head->hgenerator;
207207
}
208208

209-
err = basic_set_parms(tp, f, base, tb, tca[TCA_RATE-1]);
209+
err = basic_set_parms(tp, f, base, tb, tca[TCA_RATE]);
210210
if (err < 0)
211211
goto errout;
212212

@@ -246,27 +246,27 @@ static int basic_dump(struct tcf_proto *tp, unsigned long fh,
246246
{
247247
struct basic_filter *f = (struct basic_filter *) fh;
248248
unsigned char *b = skb_tail_pointer(skb);
249-
struct rtattr *rta;
249+
struct nlattr *nla;
250250

251251
if (f == NULL)
252252
return skb->len;
253253

254254
t->tcm_handle = f->handle;
255255

256-
rta = (struct rtattr *) b;
257-
RTA_PUT(skb, TCA_OPTIONS, 0, NULL);
256+
nla = (struct nlattr *) b;
257+
NLA_PUT(skb, TCA_OPTIONS, 0, NULL);
258258

259259
if (f->res.classid)
260-
RTA_PUT(skb, TCA_BASIC_CLASSID, sizeof(u32), &f->res.classid);
260+
NLA_PUT(skb, TCA_BASIC_CLASSID, sizeof(u32), &f->res.classid);
261261

262262
if (tcf_exts_dump(skb, &f->exts, &basic_ext_map) < 0 ||
263263
tcf_em_tree_dump(skb, &f->ematches, TCA_BASIC_EMATCHES) < 0)
264-
goto rtattr_failure;
264+
goto nla_put_failure;
265265

266-
rta->rta_len = skb_tail_pointer(skb) - b;
266+
nla->nla_len = skb_tail_pointer(skb) - b;
267267
return skb->len;
268268

269-
rtattr_failure:
269+
nla_put_failure:
270270
nlmsg_trim(skb, b);
271271
return -1;
272272
}

0 commit comments

Comments
 (0)