cls_bpf.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  1. /*
  2. * Berkeley Packet Filter based traffic classifier
  3. *
  4. * Might be used to classify traffic through flexible, user-defined and
  5. * possibly JIT-ed BPF filters for traffic control as an alternative to
  6. * ematches.
  7. *
  8. * (C) 2013 Daniel Borkmann <dborkman@redhat.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. */
  14. #include <linux/module.h>
  15. #include <linux/types.h>
  16. #include <linux/skbuff.h>
  17. #include <linux/filter.h>
  18. #include <linux/bpf.h>
  19. #include <net/rtnetlink.h>
  20. #include <net/pkt_cls.h>
  21. #include <net/sock.h>
  22. MODULE_LICENSE("GPL");
  23. MODULE_AUTHOR("Daniel Borkmann <dborkman@redhat.com>");
  24. MODULE_DESCRIPTION("TC BPF based classifier");
  25. #define CLS_BPF_NAME_LEN 256
  26. #define CLS_BPF_SUPPORTED_GEN_FLAGS \
  27. (TCA_CLS_FLAGS_SKIP_HW | TCA_CLS_FLAGS_SKIP_SW)
  28. struct cls_bpf_head {
  29. struct list_head plist;
  30. u32 hgen;
  31. struct rcu_head rcu;
  32. };
  33. struct cls_bpf_prog {
  34. struct bpf_prog *filter;
  35. struct list_head link;
  36. struct tcf_result res;
  37. bool exts_integrated;
  38. bool offloaded;
  39. u32 gen_flags;
  40. struct tcf_exts exts;
  41. u32 handle;
  42. u16 bpf_num_ops;
  43. struct sock_filter *bpf_ops;
  44. const char *bpf_name;
  45. struct tcf_proto *tp;
  46. struct rcu_head rcu;
  47. };
  48. static const struct nla_policy bpf_policy[TCA_BPF_MAX + 1] = {
  49. [TCA_BPF_CLASSID] = { .type = NLA_U32 },
  50. [TCA_BPF_FLAGS] = { .type = NLA_U32 },
  51. [TCA_BPF_FLAGS_GEN] = { .type = NLA_U32 },
  52. [TCA_BPF_FD] = { .type = NLA_U32 },
  53. [TCA_BPF_NAME] = { .type = NLA_NUL_STRING,
  54. .len = CLS_BPF_NAME_LEN },
  55. [TCA_BPF_OPS_LEN] = { .type = NLA_U16 },
  56. [TCA_BPF_OPS] = { .type = NLA_BINARY,
  57. .len = sizeof(struct sock_filter) * BPF_MAXINSNS },
  58. };
  59. static int cls_bpf_exec_opcode(int code)
  60. {
  61. switch (code) {
  62. case TC_ACT_OK:
  63. case TC_ACT_SHOT:
  64. case TC_ACT_STOLEN:
  65. case TC_ACT_TRAP:
  66. case TC_ACT_REDIRECT:
  67. case TC_ACT_UNSPEC:
  68. return code;
  69. default:
  70. return TC_ACT_UNSPEC;
  71. }
  72. }
  73. static int cls_bpf_classify(struct sk_buff *skb, const struct tcf_proto *tp,
  74. struct tcf_result *res)
  75. {
  76. struct cls_bpf_head *head = rcu_dereference_bh(tp->root);
  77. bool at_ingress = skb_at_tc_ingress(skb);
  78. struct cls_bpf_prog *prog;
  79. int ret = -1;
  80. /* Needed here for accessing maps. */
  81. rcu_read_lock();
  82. list_for_each_entry_rcu(prog, &head->plist, link) {
  83. int filter_res;
  84. qdisc_skb_cb(skb)->tc_classid = prog->res.classid;
  85. if (tc_skip_sw(prog->gen_flags)) {
  86. filter_res = prog->exts_integrated ? TC_ACT_UNSPEC : 0;
  87. } else if (at_ingress) {
  88. /* It is safe to push/pull even if skb_shared() */
  89. __skb_push(skb, skb->mac_len);
  90. bpf_compute_data_end(skb);
  91. filter_res = BPF_PROG_RUN(prog->filter, skb);
  92. __skb_pull(skb, skb->mac_len);
  93. } else {
  94. bpf_compute_data_end(skb);
  95. filter_res = BPF_PROG_RUN(prog->filter, skb);
  96. }
  97. if (prog->exts_integrated) {
  98. res->class = 0;
  99. res->classid = TC_H_MAJ(prog->res.classid) |
  100. qdisc_skb_cb(skb)->tc_classid;
  101. ret = cls_bpf_exec_opcode(filter_res);
  102. if (ret == TC_ACT_UNSPEC)
  103. continue;
  104. break;
  105. }
  106. if (filter_res == 0)
  107. continue;
  108. if (filter_res != -1) {
  109. res->class = 0;
  110. res->classid = filter_res;
  111. } else {
  112. *res = prog->res;
  113. }
  114. ret = tcf_exts_exec(skb, &prog->exts, res);
  115. if (ret < 0)
  116. continue;
  117. break;
  118. }
  119. rcu_read_unlock();
  120. return ret;
  121. }
  122. static bool cls_bpf_is_ebpf(const struct cls_bpf_prog *prog)
  123. {
  124. return !prog->bpf_ops;
  125. }
  126. static int cls_bpf_offload_cmd(struct tcf_proto *tp, struct cls_bpf_prog *prog,
  127. enum tc_clsbpf_command cmd)
  128. {
  129. struct net_device *dev = tp->q->dev_queue->dev;
  130. struct tc_cls_bpf_offload bpf_offload = {};
  131. struct tc_to_netdev offload;
  132. int err;
  133. offload.type = TC_SETUP_CLSBPF;
  134. offload.cls_bpf = &bpf_offload;
  135. bpf_offload.command = cmd;
  136. bpf_offload.exts = &prog->exts;
  137. bpf_offload.prog = prog->filter;
  138. bpf_offload.name = prog->bpf_name;
  139. bpf_offload.exts_integrated = prog->exts_integrated;
  140. bpf_offload.gen_flags = prog->gen_flags;
  141. err = dev->netdev_ops->ndo_setup_tc(dev, tp->q->handle,
  142. tp->chain->index,
  143. tp->protocol, &offload);
  144. if (!err && (cmd == TC_CLSBPF_ADD || cmd == TC_CLSBPF_REPLACE))
  145. prog->gen_flags |= TCA_CLS_FLAGS_IN_HW;
  146. return err;
  147. }
  148. static int cls_bpf_offload(struct tcf_proto *tp, struct cls_bpf_prog *prog,
  149. struct cls_bpf_prog *oldprog)
  150. {
  151. struct net_device *dev = tp->q->dev_queue->dev;
  152. struct cls_bpf_prog *obj = prog;
  153. enum tc_clsbpf_command cmd;
  154. bool skip_sw;
  155. int ret;
  156. skip_sw = tc_skip_sw(prog->gen_flags) ||
  157. (oldprog && tc_skip_sw(oldprog->gen_flags));
  158. if (oldprog && oldprog->offloaded) {
  159. if (tc_should_offload(dev, tp, prog->gen_flags)) {
  160. cmd = TC_CLSBPF_REPLACE;
  161. } else if (!tc_skip_sw(prog->gen_flags)) {
  162. obj = oldprog;
  163. cmd = TC_CLSBPF_DESTROY;
  164. } else {
  165. return -EINVAL;
  166. }
  167. } else {
  168. if (!tc_should_offload(dev, tp, prog->gen_flags))
  169. return skip_sw ? -EINVAL : 0;
  170. cmd = TC_CLSBPF_ADD;
  171. }
  172. ret = cls_bpf_offload_cmd(tp, obj, cmd);
  173. if (ret)
  174. return skip_sw ? ret : 0;
  175. obj->offloaded = true;
  176. if (oldprog)
  177. oldprog->offloaded = false;
  178. return 0;
  179. }
  180. static void cls_bpf_stop_offload(struct tcf_proto *tp,
  181. struct cls_bpf_prog *prog)
  182. {
  183. int err;
  184. if (!prog->offloaded)
  185. return;
  186. err = cls_bpf_offload_cmd(tp, prog, TC_CLSBPF_DESTROY);
  187. if (err) {
  188. pr_err("Stopping hardware offload failed: %d\n", err);
  189. return;
  190. }
  191. prog->offloaded = false;
  192. }
  193. static void cls_bpf_offload_update_stats(struct tcf_proto *tp,
  194. struct cls_bpf_prog *prog)
  195. {
  196. if (!prog->offloaded)
  197. return;
  198. cls_bpf_offload_cmd(tp, prog, TC_CLSBPF_STATS);
  199. }
  200. static int cls_bpf_init(struct tcf_proto *tp)
  201. {
  202. struct cls_bpf_head *head;
  203. head = kzalloc(sizeof(*head), GFP_KERNEL);
  204. if (head == NULL)
  205. return -ENOBUFS;
  206. INIT_LIST_HEAD_RCU(&head->plist);
  207. rcu_assign_pointer(tp->root, head);
  208. return 0;
  209. }
  210. static void __cls_bpf_delete_prog(struct cls_bpf_prog *prog)
  211. {
  212. tcf_exts_destroy(&prog->exts);
  213. if (cls_bpf_is_ebpf(prog))
  214. bpf_prog_put(prog->filter);
  215. else
  216. bpf_prog_destroy(prog->filter);
  217. kfree(prog->bpf_name);
  218. kfree(prog->bpf_ops);
  219. kfree(prog);
  220. }
  221. static void cls_bpf_delete_prog_rcu(struct rcu_head *rcu)
  222. {
  223. __cls_bpf_delete_prog(container_of(rcu, struct cls_bpf_prog, rcu));
  224. }
  225. static void __cls_bpf_delete(struct tcf_proto *tp, struct cls_bpf_prog *prog)
  226. {
  227. cls_bpf_stop_offload(tp, prog);
  228. list_del_rcu(&prog->link);
  229. tcf_unbind_filter(tp, &prog->res);
  230. call_rcu(&prog->rcu, cls_bpf_delete_prog_rcu);
  231. }
  232. static int cls_bpf_delete(struct tcf_proto *tp, unsigned long arg, bool *last)
  233. {
  234. struct cls_bpf_head *head = rtnl_dereference(tp->root);
  235. __cls_bpf_delete(tp, (struct cls_bpf_prog *) arg);
  236. *last = list_empty(&head->plist);
  237. return 0;
  238. }
  239. static void cls_bpf_destroy(struct tcf_proto *tp)
  240. {
  241. struct cls_bpf_head *head = rtnl_dereference(tp->root);
  242. struct cls_bpf_prog *prog, *tmp;
  243. list_for_each_entry_safe(prog, tmp, &head->plist, link)
  244. __cls_bpf_delete(tp, prog);
  245. kfree_rcu(head, rcu);
  246. }
  247. static unsigned long cls_bpf_get(struct tcf_proto *tp, u32 handle)
  248. {
  249. struct cls_bpf_head *head = rtnl_dereference(tp->root);
  250. struct cls_bpf_prog *prog;
  251. unsigned long ret = 0UL;
  252. list_for_each_entry(prog, &head->plist, link) {
  253. if (prog->handle == handle) {
  254. ret = (unsigned long) prog;
  255. break;
  256. }
  257. }
  258. return ret;
  259. }
  260. static int cls_bpf_prog_from_ops(struct nlattr **tb, struct cls_bpf_prog *prog)
  261. {
  262. struct sock_filter *bpf_ops;
  263. struct sock_fprog_kern fprog_tmp;
  264. struct bpf_prog *fp;
  265. u16 bpf_size, bpf_num_ops;
  266. int ret;
  267. bpf_num_ops = nla_get_u16(tb[TCA_BPF_OPS_LEN]);
  268. if (bpf_num_ops > BPF_MAXINSNS || bpf_num_ops == 0)
  269. return -EINVAL;
  270. bpf_size = bpf_num_ops * sizeof(*bpf_ops);
  271. if (bpf_size != nla_len(tb[TCA_BPF_OPS]))
  272. return -EINVAL;
  273. bpf_ops = kzalloc(bpf_size, GFP_KERNEL);
  274. if (bpf_ops == NULL)
  275. return -ENOMEM;
  276. memcpy(bpf_ops, nla_data(tb[TCA_BPF_OPS]), bpf_size);
  277. fprog_tmp.len = bpf_num_ops;
  278. fprog_tmp.filter = bpf_ops;
  279. ret = bpf_prog_create(&fp, &fprog_tmp);
  280. if (ret < 0) {
  281. kfree(bpf_ops);
  282. return ret;
  283. }
  284. prog->bpf_ops = bpf_ops;
  285. prog->bpf_num_ops = bpf_num_ops;
  286. prog->bpf_name = NULL;
  287. prog->filter = fp;
  288. return 0;
  289. }
  290. static int cls_bpf_prog_from_efd(struct nlattr **tb, struct cls_bpf_prog *prog,
  291. const struct tcf_proto *tp)
  292. {
  293. struct bpf_prog *fp;
  294. char *name = NULL;
  295. u32 bpf_fd;
  296. bpf_fd = nla_get_u32(tb[TCA_BPF_FD]);
  297. fp = bpf_prog_get_type(bpf_fd, BPF_PROG_TYPE_SCHED_CLS);
  298. if (IS_ERR(fp))
  299. return PTR_ERR(fp);
  300. if (tb[TCA_BPF_NAME]) {
  301. name = nla_memdup(tb[TCA_BPF_NAME], GFP_KERNEL);
  302. if (!name) {
  303. bpf_prog_put(fp);
  304. return -ENOMEM;
  305. }
  306. }
  307. prog->bpf_ops = NULL;
  308. prog->bpf_name = name;
  309. prog->filter = fp;
  310. if (fp->dst_needed && !(tp->q->flags & TCQ_F_INGRESS))
  311. netif_keep_dst(qdisc_dev(tp->q));
  312. return 0;
  313. }
  314. static int cls_bpf_modify_existing(struct net *net, struct tcf_proto *tp,
  315. struct cls_bpf_prog *prog,
  316. unsigned long base, struct nlattr **tb,
  317. struct nlattr *est, bool ovr)
  318. {
  319. bool is_bpf, is_ebpf, have_exts = false;
  320. struct tcf_exts exts;
  321. u32 gen_flags = 0;
  322. int ret;
  323. is_bpf = tb[TCA_BPF_OPS_LEN] && tb[TCA_BPF_OPS];
  324. is_ebpf = tb[TCA_BPF_FD];
  325. if ((!is_bpf && !is_ebpf) || (is_bpf && is_ebpf))
  326. return -EINVAL;
  327. ret = tcf_exts_init(&exts, TCA_BPF_ACT, TCA_BPF_POLICE);
  328. if (ret < 0)
  329. return ret;
  330. ret = tcf_exts_validate(net, tp, tb, est, &exts, ovr);
  331. if (ret < 0)
  332. goto errout;
  333. if (tb[TCA_BPF_FLAGS]) {
  334. u32 bpf_flags = nla_get_u32(tb[TCA_BPF_FLAGS]);
  335. if (bpf_flags & ~TCA_BPF_FLAG_ACT_DIRECT) {
  336. ret = -EINVAL;
  337. goto errout;
  338. }
  339. have_exts = bpf_flags & TCA_BPF_FLAG_ACT_DIRECT;
  340. }
  341. if (tb[TCA_BPF_FLAGS_GEN]) {
  342. gen_flags = nla_get_u32(tb[TCA_BPF_FLAGS_GEN]);
  343. if (gen_flags & ~CLS_BPF_SUPPORTED_GEN_FLAGS ||
  344. !tc_flags_valid(gen_flags)) {
  345. ret = -EINVAL;
  346. goto errout;
  347. }
  348. }
  349. prog->exts_integrated = have_exts;
  350. prog->gen_flags = gen_flags;
  351. ret = is_bpf ? cls_bpf_prog_from_ops(tb, prog) :
  352. cls_bpf_prog_from_efd(tb, prog, tp);
  353. if (ret < 0)
  354. goto errout;
  355. if (tb[TCA_BPF_CLASSID]) {
  356. prog->res.classid = nla_get_u32(tb[TCA_BPF_CLASSID]);
  357. tcf_bind_filter(tp, &prog->res, base);
  358. }
  359. tcf_exts_change(tp, &prog->exts, &exts);
  360. return 0;
  361. errout:
  362. tcf_exts_destroy(&exts);
  363. return ret;
  364. }
  365. static u32 cls_bpf_grab_new_handle(struct tcf_proto *tp,
  366. struct cls_bpf_head *head)
  367. {
  368. unsigned int i = 0x80000000;
  369. u32 handle;
  370. do {
  371. if (++head->hgen == 0x7FFFFFFF)
  372. head->hgen = 1;
  373. } while (--i > 0 && cls_bpf_get(tp, head->hgen));
  374. if (unlikely(i == 0)) {
  375. pr_err("Insufficient number of handles\n");
  376. handle = 0;
  377. } else {
  378. handle = head->hgen;
  379. }
  380. return handle;
  381. }
  382. static int cls_bpf_change(struct net *net, struct sk_buff *in_skb,
  383. struct tcf_proto *tp, unsigned long base,
  384. u32 handle, struct nlattr **tca,
  385. unsigned long *arg, bool ovr)
  386. {
  387. struct cls_bpf_head *head = rtnl_dereference(tp->root);
  388. struct cls_bpf_prog *oldprog = (struct cls_bpf_prog *) *arg;
  389. struct nlattr *tb[TCA_BPF_MAX + 1];
  390. struct cls_bpf_prog *prog;
  391. int ret;
  392. if (tca[TCA_OPTIONS] == NULL)
  393. return -EINVAL;
  394. ret = nla_parse_nested(tb, TCA_BPF_MAX, tca[TCA_OPTIONS], bpf_policy,
  395. NULL);
  396. if (ret < 0)
  397. return ret;
  398. prog = kzalloc(sizeof(*prog), GFP_KERNEL);
  399. if (!prog)
  400. return -ENOBUFS;
  401. ret = tcf_exts_init(&prog->exts, TCA_BPF_ACT, TCA_BPF_POLICE);
  402. if (ret < 0)
  403. goto errout;
  404. if (oldprog) {
  405. if (handle && oldprog->handle != handle) {
  406. ret = -EINVAL;
  407. goto errout;
  408. }
  409. }
  410. if (handle == 0)
  411. prog->handle = cls_bpf_grab_new_handle(tp, head);
  412. else
  413. prog->handle = handle;
  414. if (prog->handle == 0) {
  415. ret = -EINVAL;
  416. goto errout;
  417. }
  418. ret = cls_bpf_modify_existing(net, tp, prog, base, tb, tca[TCA_RATE],
  419. ovr);
  420. if (ret < 0)
  421. goto errout;
  422. ret = cls_bpf_offload(tp, prog, oldprog);
  423. if (ret) {
  424. __cls_bpf_delete_prog(prog);
  425. return ret;
  426. }
  427. if (!tc_in_hw(prog->gen_flags))
  428. prog->gen_flags |= TCA_CLS_FLAGS_NOT_IN_HW;
  429. if (oldprog) {
  430. list_replace_rcu(&oldprog->link, &prog->link);
  431. tcf_unbind_filter(tp, &oldprog->res);
  432. call_rcu(&oldprog->rcu, cls_bpf_delete_prog_rcu);
  433. } else {
  434. list_add_rcu(&prog->link, &head->plist);
  435. }
  436. *arg = (unsigned long) prog;
  437. return 0;
  438. errout:
  439. tcf_exts_destroy(&prog->exts);
  440. kfree(prog);
  441. return ret;
  442. }
  443. static int cls_bpf_dump_bpf_info(const struct cls_bpf_prog *prog,
  444. struct sk_buff *skb)
  445. {
  446. struct nlattr *nla;
  447. if (nla_put_u16(skb, TCA_BPF_OPS_LEN, prog->bpf_num_ops))
  448. return -EMSGSIZE;
  449. nla = nla_reserve(skb, TCA_BPF_OPS, prog->bpf_num_ops *
  450. sizeof(struct sock_filter));
  451. if (nla == NULL)
  452. return -EMSGSIZE;
  453. memcpy(nla_data(nla), prog->bpf_ops, nla_len(nla));
  454. return 0;
  455. }
  456. static int cls_bpf_dump_ebpf_info(const struct cls_bpf_prog *prog,
  457. struct sk_buff *skb)
  458. {
  459. struct nlattr *nla;
  460. if (prog->bpf_name &&
  461. nla_put_string(skb, TCA_BPF_NAME, prog->bpf_name))
  462. return -EMSGSIZE;
  463. if (nla_put_u32(skb, TCA_BPF_ID, prog->filter->aux->id))
  464. return -EMSGSIZE;
  465. nla = nla_reserve(skb, TCA_BPF_TAG, sizeof(prog->filter->tag));
  466. if (nla == NULL)
  467. return -EMSGSIZE;
  468. memcpy(nla_data(nla), prog->filter->tag, nla_len(nla));
  469. return 0;
  470. }
  471. static int cls_bpf_dump(struct net *net, struct tcf_proto *tp, unsigned long fh,
  472. struct sk_buff *skb, struct tcmsg *tm)
  473. {
  474. struct cls_bpf_prog *prog = (struct cls_bpf_prog *) fh;
  475. struct nlattr *nest;
  476. u32 bpf_flags = 0;
  477. int ret;
  478. if (prog == NULL)
  479. return skb->len;
  480. tm->tcm_handle = prog->handle;
  481. cls_bpf_offload_update_stats(tp, prog);
  482. nest = nla_nest_start(skb, TCA_OPTIONS);
  483. if (nest == NULL)
  484. goto nla_put_failure;
  485. if (prog->res.classid &&
  486. nla_put_u32(skb, TCA_BPF_CLASSID, prog->res.classid))
  487. goto nla_put_failure;
  488. if (cls_bpf_is_ebpf(prog))
  489. ret = cls_bpf_dump_ebpf_info(prog, skb);
  490. else
  491. ret = cls_bpf_dump_bpf_info(prog, skb);
  492. if (ret)
  493. goto nla_put_failure;
  494. if (tcf_exts_dump(skb, &prog->exts) < 0)
  495. goto nla_put_failure;
  496. if (prog->exts_integrated)
  497. bpf_flags |= TCA_BPF_FLAG_ACT_DIRECT;
  498. if (bpf_flags && nla_put_u32(skb, TCA_BPF_FLAGS, bpf_flags))
  499. goto nla_put_failure;
  500. if (prog->gen_flags &&
  501. nla_put_u32(skb, TCA_BPF_FLAGS_GEN, prog->gen_flags))
  502. goto nla_put_failure;
  503. nla_nest_end(skb, nest);
  504. if (tcf_exts_dump_stats(skb, &prog->exts) < 0)
  505. goto nla_put_failure;
  506. return skb->len;
  507. nla_put_failure:
  508. nla_nest_cancel(skb, nest);
  509. return -1;
  510. }
  511. static void cls_bpf_walk(struct tcf_proto *tp, struct tcf_walker *arg)
  512. {
  513. struct cls_bpf_head *head = rtnl_dereference(tp->root);
  514. struct cls_bpf_prog *prog;
  515. list_for_each_entry(prog, &head->plist, link) {
  516. if (arg->count < arg->skip)
  517. goto skip;
  518. if (arg->fn(tp, (unsigned long) prog, arg) < 0) {
  519. arg->stop = 1;
  520. break;
  521. }
  522. skip:
  523. arg->count++;
  524. }
  525. }
  526. static struct tcf_proto_ops cls_bpf_ops __read_mostly = {
  527. .kind = "bpf",
  528. .owner = THIS_MODULE,
  529. .classify = cls_bpf_classify,
  530. .init = cls_bpf_init,
  531. .destroy = cls_bpf_destroy,
  532. .get = cls_bpf_get,
  533. .change = cls_bpf_change,
  534. .delete = cls_bpf_delete,
  535. .walk = cls_bpf_walk,
  536. .dump = cls_bpf_dump,
  537. };
  538. static int __init cls_bpf_init_mod(void)
  539. {
  540. return register_tcf_proto_ops(&cls_bpf_ops);
  541. }
  542. static void __exit cls_bpf_exit_mod(void)
  543. {
  544. unregister_tcf_proto_ops(&cls_bpf_ops);
  545. }
  546. module_init(cls_bpf_init_mod);
  547. module_exit(cls_bpf_exit_mod);