act_pedit.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * net/sched/act_pedit.c Generic packet editor
  4. *
  5. * Authors: Jamal Hadi Salim (2002-4)
  6. */
  7. #include <linux/types.h>
  8. #include <linux/kernel.h>
  9. #include <linux/string.h>
  10. #include <linux/errno.h>
  11. #include <linux/skbuff.h>
  12. #include <linux/rtnetlink.h>
  13. #include <linux/module.h>
  14. #include <linux/init.h>
  15. #include <linux/ip.h>
  16. #include <linux/ipv6.h>
  17. #include <linux/slab.h>
  18. #include <net/ipv6.h>
  19. #include <net/netlink.h>
  20. #include <net/pkt_sched.h>
  21. #include <linux/tc_act/tc_pedit.h>
  22. #include <net/tc_act/tc_pedit.h>
  23. #include <uapi/linux/tc_act/tc_pedit.h>
  24. #include <net/pkt_cls.h>
  25. #include <net/tc_wrapper.h>
  26. static struct tc_action_ops act_pedit_ops;
  27. static const struct nla_policy pedit_policy[TCA_PEDIT_MAX + 1] = {
  28. [TCA_PEDIT_PARMS] = { .len = sizeof(struct tc_pedit) },
  29. [TCA_PEDIT_PARMS_EX] = { .len = sizeof(struct tc_pedit) },
  30. [TCA_PEDIT_KEYS_EX] = { .type = NLA_NESTED },
  31. };
  32. static const struct nla_policy pedit_key_ex_policy[TCA_PEDIT_KEY_EX_MAX + 1] = {
  33. [TCA_PEDIT_KEY_EX_HTYPE] =
  34. NLA_POLICY_MAX(NLA_U16, TCA_PEDIT_HDR_TYPE_MAX),
  35. [TCA_PEDIT_KEY_EX_CMD] = NLA_POLICY_MAX(NLA_U16, TCA_PEDIT_CMD_MAX),
  36. };
  37. static struct tcf_pedit_key_ex *tcf_pedit_keys_ex_parse(struct nlattr *nla,
  38. u8 n, struct netlink_ext_ack *extack)
  39. {
  40. struct tcf_pedit_key_ex *keys_ex;
  41. struct tcf_pedit_key_ex *k;
  42. const struct nlattr *ka;
  43. int err = -EINVAL;
  44. int rem;
  45. if (!nla)
  46. return NULL;
  47. keys_ex = kcalloc(n, sizeof(*k), GFP_KERNEL);
  48. if (!keys_ex)
  49. return ERR_PTR(-ENOMEM);
  50. k = keys_ex;
  51. nla_for_each_nested(ka, nla, rem) {
  52. struct nlattr *tb[TCA_PEDIT_KEY_EX_MAX + 1];
  53. if (!n) {
  54. NL_SET_ERR_MSG_MOD(extack, "Can't parse more extended keys than requested");
  55. err = -EINVAL;
  56. goto err_out;
  57. }
  58. n--;
  59. if (nla_type(ka) != TCA_PEDIT_KEY_EX) {
  60. NL_SET_ERR_MSG_ATTR(extack, ka, "Unknown attribute, expected extended key");
  61. err = -EINVAL;
  62. goto err_out;
  63. }
  64. err = nla_parse_nested_deprecated(tb, TCA_PEDIT_KEY_EX_MAX,
  65. ka, pedit_key_ex_policy,
  66. NULL);
  67. if (err)
  68. goto err_out;
  69. if (NL_REQ_ATTR_CHECK(extack, nla, tb, TCA_PEDIT_KEY_EX_HTYPE)) {
  70. NL_SET_ERR_MSG(extack, "Missing required attribute");
  71. err = -EINVAL;
  72. goto err_out;
  73. }
  74. if (NL_REQ_ATTR_CHECK(extack, nla, tb, TCA_PEDIT_KEY_EX_CMD)) {
  75. NL_SET_ERR_MSG(extack, "Missing required attribute");
  76. err = -EINVAL;
  77. goto err_out;
  78. }
  79. k->htype = nla_get_u16(tb[TCA_PEDIT_KEY_EX_HTYPE]);
  80. k->cmd = nla_get_u16(tb[TCA_PEDIT_KEY_EX_CMD]);
  81. k++;
  82. }
  83. if (n) {
  84. NL_SET_ERR_MSG_MOD(extack, "Not enough extended keys to parse");
  85. err = -EINVAL;
  86. goto err_out;
  87. }
  88. return keys_ex;
  89. err_out:
  90. kfree(keys_ex);
  91. return ERR_PTR(err);
  92. }
  93. static int tcf_pedit_key_ex_dump(struct sk_buff *skb,
  94. struct tcf_pedit_key_ex *keys_ex, int n)
  95. {
  96. struct nlattr *keys_start = nla_nest_start_noflag(skb,
  97. TCA_PEDIT_KEYS_EX);
  98. if (!keys_start)
  99. goto nla_failure;
  100. for (; n > 0; n--) {
  101. struct nlattr *key_start;
  102. key_start = nla_nest_start_noflag(skb, TCA_PEDIT_KEY_EX);
  103. if (!key_start)
  104. goto nla_failure;
  105. if (nla_put_u16(skb, TCA_PEDIT_KEY_EX_HTYPE, keys_ex->htype) ||
  106. nla_put_u16(skb, TCA_PEDIT_KEY_EX_CMD, keys_ex->cmd))
  107. goto nla_failure;
  108. nla_nest_end(skb, key_start);
  109. keys_ex++;
  110. }
  111. nla_nest_end(skb, keys_start);
  112. return 0;
  113. nla_failure:
  114. nla_nest_cancel(skb, keys_start);
  115. return -EINVAL;
  116. }
  117. static void tcf_pedit_cleanup_rcu(struct rcu_head *head)
  118. {
  119. struct tcf_pedit_parms *parms =
  120. container_of(head, struct tcf_pedit_parms, rcu);
  121. kfree(parms->tcfp_keys_ex);
  122. kfree(parms->tcfp_keys);
  123. kfree(parms);
  124. }
  125. static int tcf_pedit_init(struct net *net, struct nlattr *nla,
  126. struct nlattr *est, struct tc_action **a,
  127. struct tcf_proto *tp, u32 flags,
  128. struct netlink_ext_ack *extack)
  129. {
  130. struct tc_action_net *tn = net_generic(net, act_pedit_ops.net_id);
  131. bool bind = flags & TCA_ACT_FLAGS_BIND;
  132. struct tcf_chain *goto_ch = NULL;
  133. struct tcf_pedit_parms *oparms, *nparms;
  134. struct nlattr *tb[TCA_PEDIT_MAX + 1];
  135. struct tc_pedit *parm;
  136. struct nlattr *pattr;
  137. struct tcf_pedit *p;
  138. int ret = 0, err;
  139. int i, ksize;
  140. u32 index;
  141. if (!nla) {
  142. NL_SET_ERR_MSG_MOD(extack, "Pedit requires attributes to be passed");
  143. return -EINVAL;
  144. }
  145. err = nla_parse_nested_deprecated(tb, TCA_PEDIT_MAX, nla,
  146. pedit_policy, NULL);
  147. if (err < 0)
  148. return err;
  149. pattr = tb[TCA_PEDIT_PARMS];
  150. if (!pattr)
  151. pattr = tb[TCA_PEDIT_PARMS_EX];
  152. if (!pattr) {
  153. NL_SET_ERR_MSG_MOD(extack, "Missing required TCA_PEDIT_PARMS or TCA_PEDIT_PARMS_EX pedit attribute");
  154. return -EINVAL;
  155. }
  156. parm = nla_data(pattr);
  157. index = parm->index;
  158. err = tcf_idr_check_alloc(tn, &index, a, bind);
  159. if (!err) {
  160. ret = tcf_idr_create_from_flags(tn, index, est, a,
  161. &act_pedit_ops, bind, flags);
  162. if (ret) {
  163. tcf_idr_cleanup(tn, index);
  164. return ret;
  165. }
  166. ret = ACT_P_CREATED;
  167. } else if (err > 0) {
  168. if (bind)
  169. return ACT_P_BOUND;
  170. if (!(flags & TCA_ACT_FLAGS_REPLACE)) {
  171. ret = -EEXIST;
  172. goto out_release;
  173. }
  174. } else {
  175. return err;
  176. }
  177. if (!parm->nkeys) {
  178. NL_SET_ERR_MSG_MOD(extack, "Pedit requires keys to be passed");
  179. ret = -EINVAL;
  180. goto out_release;
  181. }
  182. ksize = parm->nkeys * sizeof(struct tc_pedit_key);
  183. if (nla_len(pattr) < sizeof(*parm) + ksize) {
  184. NL_SET_ERR_MSG_ATTR(extack, pattr, "Length of TCA_PEDIT_PARMS or TCA_PEDIT_PARMS_EX pedit attribute is invalid");
  185. ret = -EINVAL;
  186. goto out_release;
  187. }
  188. nparms = kzalloc(sizeof(*nparms), GFP_KERNEL);
  189. if (!nparms) {
  190. ret = -ENOMEM;
  191. goto out_release;
  192. }
  193. nparms->tcfp_keys_ex =
  194. tcf_pedit_keys_ex_parse(tb[TCA_PEDIT_KEYS_EX], parm->nkeys, extack);
  195. if (IS_ERR(nparms->tcfp_keys_ex)) {
  196. ret = PTR_ERR(nparms->tcfp_keys_ex);
  197. goto out_free;
  198. }
  199. err = tcf_action_check_ctrlact(parm->action, tp, &goto_ch, extack);
  200. if (err < 0) {
  201. ret = err;
  202. goto out_free_ex;
  203. }
  204. nparms->tcfp_off_max_hint = 0;
  205. nparms->tcfp_flags = parm->flags;
  206. nparms->tcfp_nkeys = parm->nkeys;
  207. nparms->tcfp_keys = kmemdup(parm->keys, ksize, GFP_KERNEL);
  208. if (!nparms->tcfp_keys) {
  209. ret = -ENOMEM;
  210. goto put_chain;
  211. }
  212. for (i = 0; i < nparms->tcfp_nkeys; ++i) {
  213. u32 offmask = nparms->tcfp_keys[i].offmask;
  214. u32 cur = nparms->tcfp_keys[i].off;
  215. /* The AT option can be added to static offsets in the datapath */
  216. if (!offmask && cur % 4) {
  217. NL_SET_ERR_MSG_MOD(extack, "Offsets must be on 32bit boundaries");
  218. ret = -EINVAL;
  219. goto out_free_keys;
  220. }
  221. /* sanitize the shift value for any later use */
  222. nparms->tcfp_keys[i].shift = min_t(size_t,
  223. BITS_PER_TYPE(int) - 1,
  224. nparms->tcfp_keys[i].shift);
  225. /* The AT option can read a single byte, we can bound the actual
  226. * value with uchar max.
  227. */
  228. cur += (0xff & offmask) >> nparms->tcfp_keys[i].shift;
  229. /* Each key touches 4 bytes starting from the computed offset */
  230. nparms->tcfp_off_max_hint =
  231. max(nparms->tcfp_off_max_hint, cur + 4);
  232. }
  233. p = to_pedit(*a);
  234. spin_lock_bh(&p->tcf_lock);
  235. goto_ch = tcf_action_set_ctrlact(*a, parm->action, goto_ch);
  236. oparms = rcu_replace_pointer(p->parms, nparms, 1);
  237. spin_unlock_bh(&p->tcf_lock);
  238. if (oparms)
  239. call_rcu(&oparms->rcu, tcf_pedit_cleanup_rcu);
  240. if (goto_ch)
  241. tcf_chain_put_by_act(goto_ch);
  242. return ret;
  243. out_free_keys:
  244. kfree(nparms->tcfp_keys);
  245. put_chain:
  246. if (goto_ch)
  247. tcf_chain_put_by_act(goto_ch);
  248. out_free_ex:
  249. kfree(nparms->tcfp_keys_ex);
  250. out_free:
  251. kfree(nparms);
  252. out_release:
  253. tcf_idr_release(*a, bind);
  254. return ret;
  255. }
  256. static void tcf_pedit_cleanup(struct tc_action *a)
  257. {
  258. struct tcf_pedit *p = to_pedit(a);
  259. struct tcf_pedit_parms *parms;
  260. parms = rcu_dereference_protected(p->parms, 1);
  261. if (parms)
  262. call_rcu(&parms->rcu, tcf_pedit_cleanup_rcu);
  263. }
  264. static bool offset_valid(struct sk_buff *skb, int offset)
  265. {
  266. if (offset > 0 && offset > skb->len)
  267. return false;
  268. if (offset < 0 && -offset > skb_headroom(skb))
  269. return false;
  270. return true;
  271. }
  272. static int pedit_l4_skb_offset(struct sk_buff *skb, int *hoffset, const int header_type)
  273. {
  274. const int noff = skb_network_offset(skb);
  275. int ret = -EINVAL;
  276. struct iphdr _iph;
  277. switch (skb->protocol) {
  278. case htons(ETH_P_IP): {
  279. const struct iphdr *iph = skb_header_pointer(skb, noff, sizeof(_iph), &_iph);
  280. if (!iph)
  281. goto out;
  282. *hoffset = noff + iph->ihl * 4;
  283. ret = 0;
  284. break;
  285. }
  286. case htons(ETH_P_IPV6):
  287. ret = ipv6_find_hdr(skb, hoffset, header_type, NULL, NULL) == header_type ? 0 : -EINVAL;
  288. break;
  289. }
  290. out:
  291. return ret;
  292. }
  293. static int pedit_skb_hdr_offset(struct sk_buff *skb,
  294. enum pedit_header_type htype, int *hoffset)
  295. {
  296. int ret = -EINVAL;
  297. /* 'htype' is validated in the netlink parsing */
  298. switch (htype) {
  299. case TCA_PEDIT_KEY_EX_HDR_TYPE_ETH:
  300. if (skb_mac_header_was_set(skb)) {
  301. *hoffset = skb_mac_offset(skb);
  302. ret = 0;
  303. }
  304. break;
  305. case TCA_PEDIT_KEY_EX_HDR_TYPE_NETWORK:
  306. case TCA_PEDIT_KEY_EX_HDR_TYPE_IP4:
  307. case TCA_PEDIT_KEY_EX_HDR_TYPE_IP6:
  308. *hoffset = skb_network_offset(skb);
  309. ret = 0;
  310. break;
  311. case TCA_PEDIT_KEY_EX_HDR_TYPE_TCP:
  312. ret = pedit_l4_skb_offset(skb, hoffset, IPPROTO_TCP);
  313. break;
  314. case TCA_PEDIT_KEY_EX_HDR_TYPE_UDP:
  315. ret = pedit_l4_skb_offset(skb, hoffset, IPPROTO_UDP);
  316. break;
  317. default:
  318. break;
  319. }
  320. return ret;
  321. }
  322. TC_INDIRECT_SCOPE int tcf_pedit_act(struct sk_buff *skb,
  323. const struct tc_action *a,
  324. struct tcf_result *res)
  325. {
  326. enum pedit_header_type htype = TCA_PEDIT_KEY_EX_HDR_TYPE_NETWORK;
  327. enum pedit_cmd cmd = TCA_PEDIT_KEY_EX_CMD_SET;
  328. struct tcf_pedit *p = to_pedit(a);
  329. struct tcf_pedit_key_ex *tkey_ex;
  330. struct tcf_pedit_parms *parms;
  331. struct tc_pedit_key *tkey;
  332. u32 max_offset;
  333. int i;
  334. parms = rcu_dereference_bh(p->parms);
  335. max_offset = (skb_transport_header_was_set(skb) ?
  336. skb_transport_offset(skb) :
  337. skb_network_offset(skb)) +
  338. parms->tcfp_off_max_hint;
  339. if (skb_ensure_writable(skb, min(skb->len, max_offset)))
  340. goto done;
  341. tcf_lastuse_update(&p->tcf_tm);
  342. tcf_action_update_bstats(&p->common, skb);
  343. tkey = parms->tcfp_keys;
  344. tkey_ex = parms->tcfp_keys_ex;
  345. for (i = parms->tcfp_nkeys; i > 0; i--, tkey++) {
  346. int offset = tkey->off;
  347. int hoffset = 0;
  348. u32 *ptr, hdata;
  349. u32 val;
  350. int rc;
  351. if (tkey_ex) {
  352. htype = tkey_ex->htype;
  353. cmd = tkey_ex->cmd;
  354. tkey_ex++;
  355. }
  356. rc = pedit_skb_hdr_offset(skb, htype, &hoffset);
  357. if (rc) {
  358. pr_info_ratelimited("tc action pedit unable to extract header offset for header type (0x%x)\n", htype);
  359. goto bad;
  360. }
  361. if (tkey->offmask) {
  362. u8 *d, _d;
  363. if (!offset_valid(skb, hoffset + tkey->at)) {
  364. pr_info_ratelimited("tc action pedit 'at' offset %d out of bounds\n",
  365. hoffset + tkey->at);
  366. goto bad;
  367. }
  368. d = skb_header_pointer(skb, hoffset + tkey->at,
  369. sizeof(_d), &_d);
  370. if (!d)
  371. goto bad;
  372. offset += (*d & tkey->offmask) >> tkey->shift;
  373. if (offset % 4) {
  374. pr_info_ratelimited("tc action pedit offset must be on 32 bit boundaries\n");
  375. goto bad;
  376. }
  377. }
  378. if (!offset_valid(skb, hoffset + offset)) {
  379. pr_info_ratelimited("tc action pedit offset %d out of bounds\n", hoffset + offset);
  380. goto bad;
  381. }
  382. ptr = skb_header_pointer(skb, hoffset + offset,
  383. sizeof(hdata), &hdata);
  384. if (!ptr)
  385. goto bad;
  386. /* just do it, baby */
  387. switch (cmd) {
  388. case TCA_PEDIT_KEY_EX_CMD_SET:
  389. val = tkey->val;
  390. break;
  391. case TCA_PEDIT_KEY_EX_CMD_ADD:
  392. val = (*ptr + tkey->val) & ~tkey->mask;
  393. break;
  394. default:
  395. pr_info_ratelimited("tc action pedit bad command (%d)\n", cmd);
  396. goto bad;
  397. }
  398. *ptr = ((*ptr & tkey->mask) ^ val);
  399. if (ptr == &hdata)
  400. skb_store_bits(skb, hoffset + offset, ptr, 4);
  401. }
  402. goto done;
  403. bad:
  404. tcf_action_inc_overlimit_qstats(&p->common);
  405. done:
  406. return p->tcf_action;
  407. }
  408. static void tcf_pedit_stats_update(struct tc_action *a, u64 bytes, u64 packets,
  409. u64 drops, u64 lastuse, bool hw)
  410. {
  411. struct tcf_pedit *d = to_pedit(a);
  412. struct tcf_t *tm = &d->tcf_tm;
  413. tcf_action_update_stats(a, bytes, packets, drops, hw);
  414. tm->lastuse = max_t(u64, tm->lastuse, lastuse);
  415. }
  416. static int tcf_pedit_dump(struct sk_buff *skb, struct tc_action *a,
  417. int bind, int ref)
  418. {
  419. unsigned char *b = skb_tail_pointer(skb);
  420. struct tcf_pedit *p = to_pedit(a);
  421. struct tcf_pedit_parms *parms;
  422. struct tc_pedit *opt;
  423. struct tcf_t t;
  424. int s;
  425. spin_lock_bh(&p->tcf_lock);
  426. parms = rcu_dereference_protected(p->parms, 1);
  427. s = struct_size(opt, keys, parms->tcfp_nkeys);
  428. opt = kzalloc(s, GFP_ATOMIC);
  429. if (unlikely(!opt)) {
  430. spin_unlock_bh(&p->tcf_lock);
  431. return -ENOBUFS;
  432. }
  433. opt->nkeys = parms->tcfp_nkeys;
  434. memcpy(opt->keys, parms->tcfp_keys,
  435. flex_array_size(opt, keys, parms->tcfp_nkeys));
  436. opt->index = p->tcf_index;
  437. opt->flags = parms->tcfp_flags;
  438. opt->action = p->tcf_action;
  439. opt->refcnt = refcount_read(&p->tcf_refcnt) - ref;
  440. opt->bindcnt = atomic_read(&p->tcf_bindcnt) - bind;
  441. if (parms->tcfp_keys_ex) {
  442. if (tcf_pedit_key_ex_dump(skb, parms->tcfp_keys_ex,
  443. parms->tcfp_nkeys))
  444. goto nla_put_failure;
  445. if (nla_put(skb, TCA_PEDIT_PARMS_EX, s, opt))
  446. goto nla_put_failure;
  447. } else {
  448. if (nla_put(skb, TCA_PEDIT_PARMS, s, opt))
  449. goto nla_put_failure;
  450. }
  451. tcf_tm_dump(&t, &p->tcf_tm);
  452. if (nla_put_64bit(skb, TCA_PEDIT_TM, sizeof(t), &t, TCA_PEDIT_PAD))
  453. goto nla_put_failure;
  454. spin_unlock_bh(&p->tcf_lock);
  455. kfree(opt);
  456. return skb->len;
  457. nla_put_failure:
  458. spin_unlock_bh(&p->tcf_lock);
  459. nlmsg_trim(skb, b);
  460. kfree(opt);
  461. return -1;
  462. }
  463. static int tcf_pedit_offload_act_setup(struct tc_action *act, void *entry_data,
  464. u32 *index_inc, bool bind,
  465. struct netlink_ext_ack *extack)
  466. {
  467. if (bind) {
  468. struct flow_action_entry *entry = entry_data;
  469. int k;
  470. for (k = 0; k < tcf_pedit_nkeys(act); k++) {
  471. switch (tcf_pedit_cmd(act, k)) {
  472. case TCA_PEDIT_KEY_EX_CMD_SET:
  473. entry->id = FLOW_ACTION_MANGLE;
  474. break;
  475. case TCA_PEDIT_KEY_EX_CMD_ADD:
  476. entry->id = FLOW_ACTION_ADD;
  477. break;
  478. default:
  479. NL_SET_ERR_MSG_MOD(extack, "Unsupported pedit command offload");
  480. return -EOPNOTSUPP;
  481. }
  482. entry->mangle.htype = tcf_pedit_htype(act, k);
  483. entry->mangle.mask = tcf_pedit_mask(act, k);
  484. entry->mangle.val = tcf_pedit_val(act, k);
  485. entry->mangle.offset = tcf_pedit_offset(act, k);
  486. entry->hw_stats = tc_act_hw_stats(act->hw_stats);
  487. entry++;
  488. }
  489. *index_inc = k;
  490. } else {
  491. struct flow_offload_action *fl_action = entry_data;
  492. u32 cmd = tcf_pedit_cmd(act, 0);
  493. int k;
  494. switch (cmd) {
  495. case TCA_PEDIT_KEY_EX_CMD_SET:
  496. fl_action->id = FLOW_ACTION_MANGLE;
  497. break;
  498. case TCA_PEDIT_KEY_EX_CMD_ADD:
  499. fl_action->id = FLOW_ACTION_ADD;
  500. break;
  501. default:
  502. NL_SET_ERR_MSG_MOD(extack, "Unsupported pedit command offload");
  503. return -EOPNOTSUPP;
  504. }
  505. for (k = 1; k < tcf_pedit_nkeys(act); k++) {
  506. if (cmd != tcf_pedit_cmd(act, k)) {
  507. NL_SET_ERR_MSG_MOD(extack, "Unsupported pedit command offload");
  508. return -EOPNOTSUPP;
  509. }
  510. }
  511. }
  512. return 0;
  513. }
  514. static struct tc_action_ops act_pedit_ops = {
  515. .kind = "pedit",
  516. .id = TCA_ID_PEDIT,
  517. .owner = THIS_MODULE,
  518. .act = tcf_pedit_act,
  519. .stats_update = tcf_pedit_stats_update,
  520. .dump = tcf_pedit_dump,
  521. .cleanup = tcf_pedit_cleanup,
  522. .init = tcf_pedit_init,
  523. .offload_act_setup = tcf_pedit_offload_act_setup,
  524. .size = sizeof(struct tcf_pedit),
  525. };
  526. MODULE_ALIAS_NET_ACT("pedit");
  527. static __net_init int pedit_init_net(struct net *net)
  528. {
  529. struct tc_action_net *tn = net_generic(net, act_pedit_ops.net_id);
  530. return tc_action_net_init(net, tn, &act_pedit_ops);
  531. }
  532. static void __net_exit pedit_exit_net(struct list_head *net_list)
  533. {
  534. tc_action_net_exit(net_list, act_pedit_ops.net_id);
  535. }
  536. static struct pernet_operations pedit_net_ops = {
  537. .init = pedit_init_net,
  538. .exit_batch = pedit_exit_net,
  539. .id = &act_pedit_ops.net_id,
  540. .size = sizeof(struct tc_action_net),
  541. };
  542. MODULE_AUTHOR("Jamal Hadi Salim(2002-4)");
  543. MODULE_DESCRIPTION("Generic Packet Editor actions");
  544. MODULE_LICENSE("GPL");
  545. static int __init pedit_init_module(void)
  546. {
  547. return tcf_register_action(&act_pedit_ops, &pedit_net_ops);
  548. }
  549. static void __exit pedit_cleanup_module(void)
  550. {
  551. tcf_unregister_action(&act_pedit_ops, &pedit_net_ops);
  552. }
  553. module_init(pedit_init_module);
  554. module_exit(pedit_cleanup_module);