19
19
#include <linux/kernel.h>
20
20
#include <linux/string.h>
21
21
#include <linux/errno.h>
22
+ #include <linux/err.h>
22
23
#include <linux/skbuff.h>
23
24
#include <linux/init.h>
24
25
#include <linux/kmod.h>
@@ -38,14 +39,14 @@ static DEFINE_RWLOCK(cls_mod_lock);
38
39
39
40
/* Find classifier type by string name */
40
41
41
- static const struct tcf_proto_ops * tcf_proto_lookup_ops (struct nlattr * kind )
42
+ static const struct tcf_proto_ops * tcf_proto_lookup_ops (const char * kind )
42
43
{
43
44
const struct tcf_proto_ops * t , * res = NULL ;
44
45
45
46
if (kind ) {
46
47
read_lock (& cls_mod_lock );
47
48
list_for_each_entry (t , & tcf_proto_base , head ) {
48
- if (nla_strcmp (kind , t -> kind ) == 0 ) {
49
+ if (strcmp (kind , t -> kind ) == 0 ) {
49
50
if (try_module_get (t -> owner ))
50
51
res = t ;
51
52
break ;
@@ -127,6 +128,56 @@ static inline u32 tcf_auto_prio(struct tcf_proto *tp)
127
128
return first ;
128
129
}
129
130
131
+ static struct tcf_proto * tcf_proto_create (const char * kind , u32 protocol ,
132
+ u32 prio , u32 parent , struct Qdisc * q )
133
+ {
134
+ struct tcf_proto * tp ;
135
+ int err ;
136
+
137
+ tp = kzalloc (sizeof (* tp ), GFP_KERNEL );
138
+ if (!tp )
139
+ return ERR_PTR (- ENOBUFS );
140
+
141
+ err = - ENOENT ;
142
+ tp -> ops = tcf_proto_lookup_ops (kind );
143
+ if (!tp -> ops ) {
144
+ #ifdef CONFIG_MODULES
145
+ rtnl_unlock ();
146
+ request_module ("cls_%s" , kind );
147
+ rtnl_lock ();
148
+ tp -> ops = tcf_proto_lookup_ops (kind );
149
+ /* We dropped the RTNL semaphore in order to perform
150
+ * the module load. So, even if we succeeded in loading
151
+ * the module we have to replay the request. We indicate
152
+ * this using -EAGAIN.
153
+ */
154
+ if (tp -> ops ) {
155
+ module_put (tp -> ops -> owner );
156
+ err = - EAGAIN ;
157
+ } else {
158
+ err = - ENOENT ;
159
+ }
160
+ goto errout ;
161
+ #endif
162
+ }
163
+ tp -> classify = tp -> ops -> classify ;
164
+ tp -> protocol = protocol ;
165
+ tp -> prio = prio ;
166
+ tp -> classid = parent ;
167
+ tp -> q = q ;
168
+
169
+ err = tp -> ops -> init (tp );
170
+ if (err ) {
171
+ module_put (tp -> ops -> owner );
172
+ goto errout ;
173
+ }
174
+ return tp ;
175
+
176
+ errout :
177
+ kfree (tp );
178
+ return ERR_PTR (err );
179
+ }
180
+
130
181
static bool tcf_proto_destroy (struct tcf_proto * tp , bool force )
131
182
{
132
183
if (tp -> ops -> destroy (tp , force )) {
@@ -164,7 +215,6 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n)
164
215
struct tcf_proto __rcu * * back ;
165
216
struct tcf_proto __rcu * * chain ;
166
217
struct tcf_proto * tp ;
167
- const struct tcf_proto_ops * tp_ops ;
168
218
const struct Qdisc_class_ops * cops ;
169
219
unsigned long cl ;
170
220
unsigned long fh ;
@@ -279,58 +329,16 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n)
279
329
!(n -> nlmsg_flags & NLM_F_CREATE ))
280
330
goto errout ;
281
331
332
+ if (!nprio )
333
+ nprio = TC_H_MAJ (tcf_auto_prio (rtnl_dereference (* back )));
282
334
283
- /* Create new proto tcf */
284
-
285
- err = - ENOBUFS ;
286
- tp = kzalloc (sizeof (* tp ), GFP_KERNEL );
287
- if (tp == NULL )
288
- goto errout ;
289
- err = - ENOENT ;
290
- tp_ops = tcf_proto_lookup_ops (tca [TCA_KIND ]);
291
- if (tp_ops == NULL ) {
292
- #ifdef CONFIG_MODULES
293
- struct nlattr * kind = tca [TCA_KIND ];
294
- char name [IFNAMSIZ ];
295
-
296
- if (kind != NULL &&
297
- nla_strlcpy (name , kind , IFNAMSIZ ) < IFNAMSIZ ) {
298
- rtnl_unlock ();
299
- request_module ("cls_%s" , name );
300
- rtnl_lock ();
301
- tp_ops = tcf_proto_lookup_ops (kind );
302
- /* We dropped the RTNL semaphore in order to
303
- * perform the module load. So, even if we
304
- * succeeded in loading the module we have to
305
- * replay the request. We indicate this using
306
- * -EAGAIN.
307
- */
308
- if (tp_ops != NULL ) {
309
- module_put (tp_ops -> owner );
310
- err = - EAGAIN ;
311
- }
312
- }
313
- #endif
314
- kfree (tp );
335
+ tp = tcf_proto_create (nla_data (tca [TCA_KIND ]),
336
+ protocol , nprio , parent , q );
337
+ if (IS_ERR (tp )) {
338
+ err = PTR_ERR (tp );
315
339
goto errout ;
316
340
}
317
- tp -> ops = tp_ops ;
318
- tp -> protocol = protocol ;
319
- tp -> prio = nprio ? :
320
- TC_H_MAJ (tcf_auto_prio (rtnl_dereference (* back )));
321
- tp -> q = q ;
322
- tp -> classify = tp_ops -> classify ;
323
- tp -> classid = parent ;
324
-
325
- err = tp_ops -> init (tp );
326
- if (err != 0 ) {
327
- module_put (tp_ops -> owner );
328
- kfree (tp );
329
- goto errout ;
330
- }
331
-
332
341
tp_created = 1 ;
333
-
334
342
} else if (tca [TCA_KIND ] && nla_strcmp (tca [TCA_KIND ], tp -> ops -> kind ))
335
343
goto errout ;
336
344
0 commit comments