cls_bpf.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  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. union {
  43. u32 bpf_fd;
  44. u16 bpf_num_ops;
  45. };
  46. struct sock_filter *bpf_ops;
  47. const char *bpf_name;
  48. struct tcf_proto *tp;
  49. struct rcu_head rcu;
  50. };
  51. static const struct nla_policy bpf_policy[TCA_BPF_MAX + 1] = {
  52. [TCA_BPF_CLASSID] = { .type = NLA_U32 },
  53. [TCA_BPF_FLAGS] = { .type = NLA_U32 },
  54. [TCA_BPF_FLAGS_GEN] = { .type = NLA_U32 },
  55. [TCA_BPF_FD] = { .type = NLA_U32 },
  56. [TCA_BPF_NAME] = { .type = NLA_NUL_STRING,
  57. .len = CLS_BPF_NAME_LEN },
  58. [TCA_BPF_OPS_LEN] = { .type = NLA_U16 },
  59. [TCA_BPF_OPS] = { .type = NLA_BINARY,
  60. .len = sizeof(struct sock_filter) * BPF_MAXINSNS },
  61. };
  62. static int cls_bpf_exec_opcode(int code)
  63. {
  64. switch (code) {
  65. case TC_ACT_OK:
  66. case TC_ACT_SHOT:
  67. case TC_ACT_STOLEN:
  68. case TC_ACT_REDIRECT:
  69. case TC_ACT_UNSPEC:
  70. return code;
  71. default:
  72. return TC_ACT_UNSPEC;
  73. }
  74. }
  75. static int cls_bpf_classify(struct sk_buff *skb, const struct tcf_proto *tp,
  76. struct tcf_result *res)
  77. {
  78. struct cls_bpf_head *head = rcu_dereference_bh(tp->root);
  79. bool at_ingress = skb_at_tc_ingress(skb);
  80. struct cls_bpf_prog *prog;
  81. int ret = -1;
  82. /* Needed here for accessing maps. */
  83. rcu_read_lock();
  84. list_for_each_entry_rcu(prog, &head->plist, link) {
  85. int filter_res;
  86. qdisc_skb_cb(skb)->tc_classid = prog->res.classid;
  87. if (tc_skip_sw(prog->gen_flags)) {
  88. filter_res = prog->exts_integrated ? TC_ACT_UNSPEC : 0;
  89. } else if (at_ingress) {
  90. /* It is safe to push/pull even if skb_shared() */
  91. __skb_push(skb, skb->mac_len);
  92. bpf_compute_data_end(skb);
  93. filter_res = BPF_PROG_RUN(prog->filter, skb);
  94. __skb_pull(skb, skb->mac_len);
  95. } else {
  96. bpf_compute_data_end(skb);
  97. filter_res = BPF_PROG_RUN(prog->filter, skb);
  98. }
  99. if (prog->exts_integrated) {
  100. res->class = 0;
  101. res->classid = TC_H_MAJ(prog->res.classid) |
  102. qdisc_skb_cb(skb)->tc_classid;
  103. ret = cls_bpf_exec_opcode(filter_res);
  104. if (ret == TC_ACT_UNSPEC)
  105. continue;
  106. break;
  107. }
  108. if (filter_res == 0)
  109. continue;
  110. if (filter_res != -1) {
  111. res->class = 0;
  112. res->classid = filter_res;
  113. } else {
  114. *res = prog->res;
  115. }
  116. ret = tcf_exts_exec(skb, &prog->exts, res);
  117. if (ret < 0)
  118. continue;
  119. break;
  120. }
  121. rcu_read_unlock();
  122. return ret;
  123. }
  124. static bool cls_bpf_is_ebpf(const struct cls_bpf_prog *prog)
  125. {
  126. return !prog->bpf_ops;
  127. }
  128. static int cls_bpf_offload_cmd(struct tcf_proto *tp, struct cls_bpf_prog *prog,
  129. enum tc_clsbpf_command cmd)
  130. {
  131. struct net_device *dev = tp->q->dev_queue->dev;
  132. struct tc_cls_bpf_offload bpf_offload = {};
  133. struct tc_to_netdev offload;
  134. offload.type = TC_SETUP_CLSBPF;
  135. offload.cls_bpf = &bpf_offload;
  136. bpf_offload.command = cmd;
  137. bpf_offload.exts = &prog->exts;
  138. bpf_offload.prog = prog->filter;
  139. bpf_offload.name = prog->bpf_name;
  140. bpf_offload.exts_integrated = prog->exts_integrated;
  141. bpf_offload.gen_flags = prog->gen_flags;
  142. return dev->netdev_ops->ndo_setup_tc(dev, tp->q->handle,
  143. tp->protocol, &offload);
  144. }
  145. static int cls_bpf_offload(struct tcf_proto *tp, struct cls_bpf_prog *prog,
  146. struct cls_bpf_prog *oldprog)
  147. {
  148. struct net_device *dev = tp->q->dev_queue->dev;
  149. struct cls_bpf_prog *obj = prog;
  150. enum tc_clsbpf_command cmd;
  151. bool skip_sw;
  152. int ret;
  153. skip_sw = tc_skip_sw(prog->gen_flags) ||
  154. (oldprog && tc_skip_sw(oldprog->gen_flags));
  155. if (oldprog && oldprog->offloaded) {
  156. if (tc_should_offload(dev, tp, prog->gen_flags)) {
  157. cmd = TC_CLSBPF_REPLACE;
  158. } else if (!tc_skip_sw(prog->gen_flags)) {
  159. obj = oldprog;
  160. cmd = TC_CLSBPF_DESTROY;
  161. } else {
  162. return -EINVAL;
  163. }
  164. } else {
  165. if (!tc_should_offload(dev, tp, prog->gen_flags))
  166. return skip_sw ? -EINVAL : 0;
  167. cmd = TC_CLSBPF_ADD;
  168. }
  169. ret = cls_bpf_offload_cmd(tp, obj, cmd);
  170. if (ret)
  171. return skip_sw ? ret : 0;
  172. obj->offloaded = true;
  173. if (oldprog)
  174. oldprog->offloaded = false;
  175. return 0;
  176. }
  177. static void cls_bpf_stop_offload(struct tcf_proto *tp,
  178. struct cls_bpf_prog *prog)
  179. {
  180. int err;
  181. if (!prog->offloaded)
  182. return;
  183. err = cls_bpf_offload_cmd(tp, prog, TC_CLSBPF_DESTROY);
  184. if (err) {
  185. pr_err("Stopping hardware offload failed: %d\n", err);
  186. return;
  187. }
  188. prog->offloaded = false;
  189. }
  190. static void cls_bpf_offload_update_stats(struct tcf_proto *tp,
  191. struct cls_bpf_prog *prog)
  192. {
  193. if (!prog->offloaded)
  194. return;
  195. cls_bpf_offload_cmd(tp, prog, TC_CLSBPF_STATS);
  196. }
  197. static int cls_bpf_init(struct tcf_proto *tp)
  198. {
  199. struct cls_bpf_head *head;
  200. head = kzalloc(sizeof(*head), GFP_KERNEL);
  201. if (head == NULL)
  202. return -ENOBUFS;
  203. INIT_LIST_HEAD_RCU(&head->plist);
  204. rcu_assign_pointer(tp->root, head);
  205. return 0;
  206. }
  207. static void cls_bpf_delete_prog(struct tcf_proto *tp, struct cls_bpf_prog *prog)
  208. {
  209. tcf_exts_destroy(&prog->exts);
  210. if (cls_bpf_is_ebpf(prog))
  211. bpf_prog_put(prog->filter);
  212. else
  213. bpf_prog_destroy(prog->filter);
  214. kfree(prog->bpf_name);
  215. kfree(prog->bpf_ops);
  216. kfree(prog);
  217. }
  218. static void __cls_bpf_delete_prog(struct rcu_head *rcu)
  219. {
  220. struct cls_bpf_prog *prog = container_of(rcu, struct cls_bpf_prog, rcu);
  221. cls_bpf_delete_prog(prog->tp, prog);
  222. }
  223. static int cls_bpf_delete(struct tcf_proto *tp, unsigned long arg)
  224. {
  225. struct cls_bpf_prog *prog = (struct cls_bpf_prog *) arg;
  226. cls_bpf_stop_offload(tp, prog);
  227. list_del_rcu(&prog->link);
  228. tcf_unbind_filter(tp, &prog->res);
  229. call_rcu(&prog->rcu, __cls_bpf_delete_prog);
  230. return 0;
  231. }
  232. static bool cls_bpf_destroy(struct tcf_proto *tp, bool force)
  233. {
  234. struct cls_bpf_head *head = rtnl_dereference(tp->root);
  235. struct cls_bpf_prog *prog, *tmp;
  236. if (!force && !list_empty(&head->plist))
  237. return false;
  238. list_for_each_entry_safe(prog, tmp, &head->plist, link) {
  239. cls_bpf_stop_offload(tp, prog);
  240. list_del_rcu(&prog->link);
  241. tcf_unbind_filter(tp, &prog->res);
  242. call_rcu(&prog->rcu, __cls_bpf_delete_prog);
  243. }
  244. kfree_rcu(head, rcu);
  245. return true;
  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 = kmemdup(nla_data(tb[TCA_BPF_NAME]),
  302. nla_len(tb[TCA_BPF_NAME]),
  303. GFP_KERNEL);
  304. if (!name) {
  305. bpf_prog_put(fp);
  306. return -ENOMEM;
  307. }
  308. }
  309. prog->bpf_ops = NULL;
  310. prog->bpf_fd = bpf_fd;
  311. prog->bpf_name = name;
  312. prog->filter = fp;
  313. if (fp->dst_needed && !(tp->q->flags & TCQ_F_INGRESS))
  314. netif_keep_dst(qdisc_dev(tp->q));
  315. return 0;
  316. }
  317. static int cls_bpf_modify_existing(struct net *net, struct tcf_proto *tp,
  318. struct cls_bpf_prog *prog,
  319. unsigned long base, struct nlattr **tb,
  320. struct nlattr *est, bool ovr)
  321. {
  322. bool is_bpf, is_ebpf, have_exts = false;
  323. struct tcf_exts exts;
  324. u32 gen_flags = 0;
  325. int ret;
  326. is_bpf = tb[TCA_BPF_OPS_LEN] && tb[TCA_BPF_OPS];
  327. is_ebpf = tb[TCA_BPF_FD];
  328. if ((!is_bpf && !is_ebpf) || (is_bpf && is_ebpf))
  329. return -EINVAL;
  330. ret = tcf_exts_init(&exts, TCA_BPF_ACT, TCA_BPF_POLICE);
  331. if (ret < 0)
  332. return ret;
  333. ret = tcf_exts_validate(net, tp, tb, est, &exts, ovr);
  334. if (ret < 0)
  335. goto errout;
  336. if (tb[TCA_BPF_FLAGS]) {
  337. u32 bpf_flags = nla_get_u32(tb[TCA_BPF_FLAGS]);
  338. if (bpf_flags & ~TCA_BPF_FLAG_ACT_DIRECT) {
  339. ret = -EINVAL;
  340. goto errout;
  341. }
  342. have_exts = bpf_flags & TCA_BPF_FLAG_ACT_DIRECT;
  343. }
  344. if (tb[TCA_BPF_FLAGS_GEN]) {
  345. gen_flags = nla_get_u32(tb[TCA_BPF_FLAGS_GEN]);
  346. if (gen_flags & ~CLS_BPF_SUPPORTED_GEN_FLAGS ||
  347. !tc_flags_valid(gen_flags)) {
  348. ret = -EINVAL;
  349. goto errout;
  350. }
  351. }
  352. prog->exts_integrated = have_exts;
  353. prog->gen_flags = gen_flags;
  354. ret = is_bpf ? cls_bpf_prog_from_ops(tb, prog) :
  355. cls_bpf_prog_from_efd(tb, prog, tp);
  356. if (ret < 0)
  357. goto errout;
  358. if (tb[TCA_BPF_CLASSID]) {
  359. prog->res.classid = nla_get_u32(tb[TCA_BPF_CLASSID]);
  360. tcf_bind_filter(tp, &prog->res, base);
  361. }
  362. tcf_exts_change(tp, &prog->exts, &exts);
  363. return 0;
  364. errout:
  365. tcf_exts_destroy(&exts);
  366. return ret;
  367. }
  368. static u32 cls_bpf_grab_new_handle(struct tcf_proto *tp,
  369. struct cls_bpf_head *head)
  370. {
  371. unsigned int i = 0x80000000;
  372. u32 handle;
  373. do {
  374. if (++head->hgen == 0x7FFFFFFF)
  375. head->hgen = 1;
  376. } while (--i > 0 && cls_bpf_get(tp, head->hgen));
  377. if (unlikely(i == 0)) {
  378. pr_err("Insufficient number of handles\n");
  379. handle = 0;
  380. } else {
  381. handle = head->hgen;
  382. }
  383. return handle;
  384. }
  385. static int cls_bpf_change(struct net *net, struct sk_buff *in_skb,
  386. struct tcf_proto *tp, unsigned long base,
  387. u32 handle, struct nlattr **tca,
  388. unsigned long *arg, bool ovr)
  389. {
  390. struct cls_bpf_head *head = rtnl_dereference(tp->root);
  391. struct cls_bpf_prog *oldprog = (struct cls_bpf_prog *) *arg;
  392. struct nlattr *tb[TCA_BPF_MAX + 1];
  393. struct cls_bpf_prog *prog;
  394. int ret;
  395. if (tca[TCA_OPTIONS] == NULL)
  396. return -EINVAL;
  397. ret = nla_parse_nested(tb, TCA_BPF_MAX, tca[TCA_OPTIONS], bpf_policy);
  398. if (ret < 0)
  399. return ret;
  400. prog = kzalloc(sizeof(*prog), GFP_KERNEL);
  401. if (!prog)
  402. return -ENOBUFS;
  403. ret = tcf_exts_init(&prog->exts, TCA_BPF_ACT, TCA_BPF_POLICE);
  404. if (ret < 0)
  405. goto errout;
  406. if (oldprog) {
  407. if (handle && oldprog->handle != handle) {
  408. ret = -EINVAL;
  409. goto errout;
  410. }
  411. }
  412. if (handle == 0)
  413. prog->handle = cls_bpf_grab_new_handle(tp, head);
  414. else
  415. prog->handle = handle;
  416. if (prog->handle == 0) {
  417. ret = -EINVAL;
  418. goto errout;
  419. }
  420. ret = cls_bpf_modify_existing(net, tp, prog, base, tb, tca[TCA_RATE],
  421. ovr);
  422. if (ret < 0)
  423. goto errout;
  424. ret = cls_bpf_offload(tp, prog, oldprog);
  425. if (ret) {
  426. cls_bpf_delete_prog(tp, prog);
  427. return ret;
  428. }
  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);
  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. if (nla_put_u32(skb, TCA_BPF_FD, prog->bpf_fd))
  460. return -EMSGSIZE;
  461. if (prog->bpf_name &&
  462. nla_put_string(skb, TCA_BPF_NAME, prog->bpf_name))
  463. return -EMSGSIZE;
  464. return 0;
  465. }
  466. static int cls_bpf_dump(struct net *net, struct tcf_proto *tp, unsigned long fh,
  467. struct sk_buff *skb, struct tcmsg *tm)
  468. {
  469. struct cls_bpf_prog *prog = (struct cls_bpf_prog *) fh;
  470. struct nlattr *nest;
  471. u32 bpf_flags = 0;
  472. int ret;
  473. if (prog == NULL)
  474. return skb->len;
  475. tm->tcm_handle = prog->handle;
  476. cls_bpf_offload_update_stats(tp, prog);
  477. nest = nla_nest_start(skb, TCA_OPTIONS);
  478. if (nest == NULL)
  479. goto nla_put_failure;
  480. if (prog->res.classid &&
  481. nla_put_u32(skb, TCA_BPF_CLASSID, prog->res.classid))
  482. goto nla_put_failure;
  483. if (cls_bpf_is_ebpf(prog))
  484. ret = cls_bpf_dump_ebpf_info(prog, skb);
  485. else
  486. ret = cls_bpf_dump_bpf_info(prog, skb);
  487. if (ret)
  488. goto nla_put_failure;
  489. if (tcf_exts_dump(skb, &prog->exts) < 0)
  490. goto nla_put_failure;
  491. if (prog->exts_integrated)
  492. bpf_flags |= TCA_BPF_FLAG_ACT_DIRECT;
  493. if (bpf_flags && nla_put_u32(skb, TCA_BPF_FLAGS, bpf_flags))
  494. goto nla_put_failure;
  495. if (prog->gen_flags &&
  496. nla_put_u32(skb, TCA_BPF_FLAGS_GEN, prog->gen_flags))
  497. goto nla_put_failure;
  498. nla_nest_end(skb, nest);
  499. if (tcf_exts_dump_stats(skb, &prog->exts) < 0)
  500. goto nla_put_failure;
  501. return skb->len;
  502. nla_put_failure:
  503. nla_nest_cancel(skb, nest);
  504. return -1;
  505. }
  506. static void cls_bpf_walk(struct tcf_proto *tp, struct tcf_walker *arg)
  507. {
  508. struct cls_bpf_head *head = rtnl_dereference(tp->root);
  509. struct cls_bpf_prog *prog;
  510. list_for_each_entry(prog, &head->plist, link) {
  511. if (arg->count < arg->skip)
  512. goto skip;
  513. if (arg->fn(tp, (unsigned long) prog, arg) < 0) {
  514. arg->stop = 1;
  515. break;
  516. }
  517. skip:
  518. arg->count++;
  519. }
  520. }
  521. static struct tcf_proto_ops cls_bpf_ops __read_mostly = {
  522. .kind = "bpf",
  523. .owner = THIS_MODULE,
  524. .classify = cls_bpf_classify,
  525. .init = cls_bpf_init,
  526. .destroy = cls_bpf_destroy,
  527. .get = cls_bpf_get,
  528. .change = cls_bpf_change,
  529. .delete = cls_bpf_delete,
  530. .walk = cls_bpf_walk,
  531. .dump = cls_bpf_dump,
  532. };
  533. static int __init cls_bpf_init_mod(void)
  534. {
  535. return register_tcf_proto_ops(&cls_bpf_ops);
  536. }
  537. static void __exit cls_bpf_exit_mod(void)
  538. {
  539. unregister_tcf_proto_ops(&cls_bpf_ops);
  540. }
  541. module_init(cls_bpf_init_mod);
  542. module_exit(cls_bpf_exit_mod);