act_gate.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /* Copyright 2020 NXP */
  3. #include <linux/module.h>
  4. #include <linux/types.h>
  5. #include <linux/kernel.h>
  6. #include <linux/string.h>
  7. #include <linux/errno.h>
  8. #include <linux/skbuff.h>
  9. #include <linux/rtnetlink.h>
  10. #include <linux/init.h>
  11. #include <linux/slab.h>
  12. #include <net/act_api.h>
  13. #include <net/netlink.h>
  14. #include <net/pkt_cls.h>
  15. #include <net/tc_act/tc_gate.h>
  16. #include <net/tc_wrapper.h>
  17. static struct tc_action_ops act_gate_ops;
  18. static ktime_t gate_get_time(struct tcf_gate *gact)
  19. {
  20. ktime_t mono = ktime_get();
  21. switch (gact->tk_offset) {
  22. case TK_OFFS_MAX:
  23. return mono;
  24. default:
  25. return ktime_mono_to_any(mono, gact->tk_offset);
  26. }
  27. return KTIME_MAX;
  28. }
  29. static void gate_get_start_time(struct tcf_gate *gact, ktime_t *start)
  30. {
  31. struct tcf_gate_params *param = &gact->param;
  32. ktime_t now, base, cycle;
  33. u64 n;
  34. base = ns_to_ktime(param->tcfg_basetime);
  35. now = gate_get_time(gact);
  36. if (ktime_after(base, now)) {
  37. *start = base;
  38. return;
  39. }
  40. cycle = param->tcfg_cycletime;
  41. n = div64_u64(ktime_sub_ns(now, base), cycle);
  42. *start = ktime_add_ns(base, (n + 1) * cycle);
  43. }
  44. static void gate_start_timer(struct tcf_gate *gact, ktime_t start)
  45. {
  46. ktime_t expires;
  47. expires = hrtimer_get_expires(&gact->hitimer);
  48. if (expires == 0)
  49. expires = KTIME_MAX;
  50. start = min_t(ktime_t, start, expires);
  51. hrtimer_start(&gact->hitimer, start, HRTIMER_MODE_ABS_SOFT);
  52. }
  53. static enum hrtimer_restart gate_timer_func(struct hrtimer *timer)
  54. {
  55. struct tcf_gate *gact = container_of(timer, struct tcf_gate,
  56. hitimer);
  57. struct tcf_gate_params *p = &gact->param;
  58. struct tcfg_gate_entry *next;
  59. ktime_t close_time, now;
  60. spin_lock(&gact->tcf_lock);
  61. next = gact->next_entry;
  62. /* cycle start, clear pending bit, clear total octets */
  63. gact->current_gate_status = next->gate_state ? GATE_ACT_GATE_OPEN : 0;
  64. gact->current_entry_octets = 0;
  65. gact->current_max_octets = next->maxoctets;
  66. gact->current_close_time = ktime_add_ns(gact->current_close_time,
  67. next->interval);
  68. close_time = gact->current_close_time;
  69. if (list_is_last(&next->list, &p->entries))
  70. next = list_first_entry(&p->entries,
  71. struct tcfg_gate_entry, list);
  72. else
  73. next = list_next_entry(next, list);
  74. now = gate_get_time(gact);
  75. if (ktime_after(now, close_time)) {
  76. ktime_t cycle, base;
  77. u64 n;
  78. cycle = p->tcfg_cycletime;
  79. base = ns_to_ktime(p->tcfg_basetime);
  80. n = div64_u64(ktime_sub_ns(now, base), cycle);
  81. close_time = ktime_add_ns(base, (n + 1) * cycle);
  82. }
  83. gact->next_entry = next;
  84. hrtimer_set_expires(&gact->hitimer, close_time);
  85. spin_unlock(&gact->tcf_lock);
  86. return HRTIMER_RESTART;
  87. }
  88. TC_INDIRECT_SCOPE int tcf_gate_act(struct sk_buff *skb,
  89. const struct tc_action *a,
  90. struct tcf_result *res)
  91. {
  92. struct tcf_gate *gact = to_gate(a);
  93. int action = READ_ONCE(gact->tcf_action);
  94. tcf_lastuse_update(&gact->tcf_tm);
  95. tcf_action_update_bstats(&gact->common, skb);
  96. spin_lock(&gact->tcf_lock);
  97. if (unlikely(gact->current_gate_status & GATE_ACT_PENDING)) {
  98. spin_unlock(&gact->tcf_lock);
  99. return action;
  100. }
  101. if (!(gact->current_gate_status & GATE_ACT_GATE_OPEN)) {
  102. spin_unlock(&gact->tcf_lock);
  103. goto drop;
  104. }
  105. if (gact->current_max_octets >= 0) {
  106. gact->current_entry_octets += qdisc_pkt_len(skb);
  107. if (gact->current_entry_octets > gact->current_max_octets) {
  108. spin_unlock(&gact->tcf_lock);
  109. goto overlimit;
  110. }
  111. }
  112. spin_unlock(&gact->tcf_lock);
  113. return action;
  114. overlimit:
  115. tcf_action_inc_overlimit_qstats(&gact->common);
  116. drop:
  117. tcf_action_inc_drop_qstats(&gact->common);
  118. return TC_ACT_SHOT;
  119. }
  120. static const struct nla_policy entry_policy[TCA_GATE_ENTRY_MAX + 1] = {
  121. [TCA_GATE_ENTRY_INDEX] = { .type = NLA_U32 },
  122. [TCA_GATE_ENTRY_GATE] = { .type = NLA_FLAG },
  123. [TCA_GATE_ENTRY_INTERVAL] = { .type = NLA_U32 },
  124. [TCA_GATE_ENTRY_IPV] = { .type = NLA_S32 },
  125. [TCA_GATE_ENTRY_MAX_OCTETS] = { .type = NLA_S32 },
  126. };
  127. static const struct nla_policy gate_policy[TCA_GATE_MAX + 1] = {
  128. [TCA_GATE_PARMS] =
  129. NLA_POLICY_EXACT_LEN(sizeof(struct tc_gate)),
  130. [TCA_GATE_PRIORITY] = { .type = NLA_S32 },
  131. [TCA_GATE_ENTRY_LIST] = { .type = NLA_NESTED },
  132. [TCA_GATE_BASE_TIME] = { .type = NLA_U64 },
  133. [TCA_GATE_CYCLE_TIME] = { .type = NLA_U64 },
  134. [TCA_GATE_CYCLE_TIME_EXT] = { .type = NLA_U64 },
  135. [TCA_GATE_FLAGS] = { .type = NLA_U32 },
  136. [TCA_GATE_CLOCKID] = { .type = NLA_S32 },
  137. };
  138. static int fill_gate_entry(struct nlattr **tb, struct tcfg_gate_entry *entry,
  139. struct netlink_ext_ack *extack)
  140. {
  141. u32 interval = 0;
  142. entry->gate_state = nla_get_flag(tb[TCA_GATE_ENTRY_GATE]);
  143. if (tb[TCA_GATE_ENTRY_INTERVAL])
  144. interval = nla_get_u32(tb[TCA_GATE_ENTRY_INTERVAL]);
  145. if (interval == 0) {
  146. NL_SET_ERR_MSG(extack, "Invalid interval for schedule entry");
  147. return -EINVAL;
  148. }
  149. entry->interval = interval;
  150. if (tb[TCA_GATE_ENTRY_IPV])
  151. entry->ipv = nla_get_s32(tb[TCA_GATE_ENTRY_IPV]);
  152. else
  153. entry->ipv = -1;
  154. if (tb[TCA_GATE_ENTRY_MAX_OCTETS])
  155. entry->maxoctets = nla_get_s32(tb[TCA_GATE_ENTRY_MAX_OCTETS]);
  156. else
  157. entry->maxoctets = -1;
  158. return 0;
  159. }
  160. static int parse_gate_entry(struct nlattr *n, struct tcfg_gate_entry *entry,
  161. int index, struct netlink_ext_ack *extack)
  162. {
  163. struct nlattr *tb[TCA_GATE_ENTRY_MAX + 1] = { };
  164. int err;
  165. err = nla_parse_nested(tb, TCA_GATE_ENTRY_MAX, n, entry_policy, extack);
  166. if (err < 0) {
  167. NL_SET_ERR_MSG(extack, "Could not parse nested entry");
  168. return -EINVAL;
  169. }
  170. entry->index = index;
  171. return fill_gate_entry(tb, entry, extack);
  172. }
  173. static void release_entry_list(struct list_head *entries)
  174. {
  175. struct tcfg_gate_entry *entry, *e;
  176. list_for_each_entry_safe(entry, e, entries, list) {
  177. list_del(&entry->list);
  178. kfree(entry);
  179. }
  180. }
  181. static int parse_gate_list(struct nlattr *list_attr,
  182. struct tcf_gate_params *sched,
  183. struct netlink_ext_ack *extack)
  184. {
  185. struct tcfg_gate_entry *entry;
  186. struct nlattr *n;
  187. int err, rem;
  188. int i = 0;
  189. if (!list_attr)
  190. return -EINVAL;
  191. nla_for_each_nested(n, list_attr, rem) {
  192. if (nla_type(n) != TCA_GATE_ONE_ENTRY) {
  193. NL_SET_ERR_MSG(extack, "Attribute isn't type 'entry'");
  194. continue;
  195. }
  196. entry = kzalloc(sizeof(*entry), GFP_ATOMIC);
  197. if (!entry) {
  198. NL_SET_ERR_MSG(extack, "Not enough memory for entry");
  199. err = -ENOMEM;
  200. goto release_list;
  201. }
  202. err = parse_gate_entry(n, entry, i, extack);
  203. if (err < 0) {
  204. kfree(entry);
  205. goto release_list;
  206. }
  207. list_add_tail(&entry->list, &sched->entries);
  208. i++;
  209. }
  210. sched->num_entries = i;
  211. return i;
  212. release_list:
  213. release_entry_list(&sched->entries);
  214. return err;
  215. }
  216. static void gate_setup_timer(struct tcf_gate *gact, u64 basetime,
  217. enum tk_offsets tko, s32 clockid,
  218. bool do_init)
  219. {
  220. if (!do_init) {
  221. if (basetime == gact->param.tcfg_basetime &&
  222. tko == gact->tk_offset &&
  223. clockid == gact->param.tcfg_clockid)
  224. return;
  225. spin_unlock_bh(&gact->tcf_lock);
  226. hrtimer_cancel(&gact->hitimer);
  227. spin_lock_bh(&gact->tcf_lock);
  228. }
  229. gact->param.tcfg_basetime = basetime;
  230. gact->param.tcfg_clockid = clockid;
  231. gact->tk_offset = tko;
  232. hrtimer_init(&gact->hitimer, clockid, HRTIMER_MODE_ABS_SOFT);
  233. gact->hitimer.function = gate_timer_func;
  234. }
  235. static int tcf_gate_init(struct net *net, struct nlattr *nla,
  236. struct nlattr *est, struct tc_action **a,
  237. struct tcf_proto *tp, u32 flags,
  238. struct netlink_ext_ack *extack)
  239. {
  240. struct tc_action_net *tn = net_generic(net, act_gate_ops.net_id);
  241. enum tk_offsets tk_offset = TK_OFFS_TAI;
  242. bool bind = flags & TCA_ACT_FLAGS_BIND;
  243. struct nlattr *tb[TCA_GATE_MAX + 1];
  244. struct tcf_chain *goto_ch = NULL;
  245. u64 cycletime = 0, basetime = 0;
  246. struct tcf_gate_params *p;
  247. s32 clockid = CLOCK_TAI;
  248. struct tcf_gate *gact;
  249. struct tc_gate *parm;
  250. int ret = 0, err;
  251. u32 gflags = 0;
  252. s32 prio = -1;
  253. ktime_t start;
  254. u32 index;
  255. if (!nla)
  256. return -EINVAL;
  257. err = nla_parse_nested(tb, TCA_GATE_MAX, nla, gate_policy, extack);
  258. if (err < 0)
  259. return err;
  260. if (!tb[TCA_GATE_PARMS])
  261. return -EINVAL;
  262. if (tb[TCA_GATE_CLOCKID]) {
  263. clockid = nla_get_s32(tb[TCA_GATE_CLOCKID]);
  264. switch (clockid) {
  265. case CLOCK_REALTIME:
  266. tk_offset = TK_OFFS_REAL;
  267. break;
  268. case CLOCK_MONOTONIC:
  269. tk_offset = TK_OFFS_MAX;
  270. break;
  271. case CLOCK_BOOTTIME:
  272. tk_offset = TK_OFFS_BOOT;
  273. break;
  274. case CLOCK_TAI:
  275. tk_offset = TK_OFFS_TAI;
  276. break;
  277. default:
  278. NL_SET_ERR_MSG(extack, "Invalid 'clockid'");
  279. return -EINVAL;
  280. }
  281. }
  282. parm = nla_data(tb[TCA_GATE_PARMS]);
  283. index = parm->index;
  284. err = tcf_idr_check_alloc(tn, &index, a, bind);
  285. if (err < 0)
  286. return err;
  287. if (err && bind)
  288. return ACT_P_BOUND;
  289. if (!err) {
  290. ret = tcf_idr_create_from_flags(tn, index, est, a,
  291. &act_gate_ops, bind, flags);
  292. if (ret) {
  293. tcf_idr_cleanup(tn, index);
  294. return ret;
  295. }
  296. ret = ACT_P_CREATED;
  297. } else if (!(flags & TCA_ACT_FLAGS_REPLACE)) {
  298. tcf_idr_release(*a, bind);
  299. return -EEXIST;
  300. }
  301. if (tb[TCA_GATE_PRIORITY])
  302. prio = nla_get_s32(tb[TCA_GATE_PRIORITY]);
  303. if (tb[TCA_GATE_BASE_TIME])
  304. basetime = nla_get_u64(tb[TCA_GATE_BASE_TIME]);
  305. if (tb[TCA_GATE_FLAGS])
  306. gflags = nla_get_u32(tb[TCA_GATE_FLAGS]);
  307. gact = to_gate(*a);
  308. if (ret == ACT_P_CREATED)
  309. INIT_LIST_HEAD(&gact->param.entries);
  310. err = tcf_action_check_ctrlact(parm->action, tp, &goto_ch, extack);
  311. if (err < 0)
  312. goto release_idr;
  313. spin_lock_bh(&gact->tcf_lock);
  314. p = &gact->param;
  315. if (tb[TCA_GATE_CYCLE_TIME])
  316. cycletime = nla_get_u64(tb[TCA_GATE_CYCLE_TIME]);
  317. if (tb[TCA_GATE_ENTRY_LIST]) {
  318. err = parse_gate_list(tb[TCA_GATE_ENTRY_LIST], p, extack);
  319. if (err < 0)
  320. goto chain_put;
  321. }
  322. if (!cycletime) {
  323. struct tcfg_gate_entry *entry;
  324. ktime_t cycle = 0;
  325. list_for_each_entry(entry, &p->entries, list)
  326. cycle = ktime_add_ns(cycle, entry->interval);
  327. cycletime = cycle;
  328. if (!cycletime) {
  329. err = -EINVAL;
  330. goto chain_put;
  331. }
  332. }
  333. p->tcfg_cycletime = cycletime;
  334. if (tb[TCA_GATE_CYCLE_TIME_EXT])
  335. p->tcfg_cycletime_ext =
  336. nla_get_u64(tb[TCA_GATE_CYCLE_TIME_EXT]);
  337. gate_setup_timer(gact, basetime, tk_offset, clockid,
  338. ret == ACT_P_CREATED);
  339. p->tcfg_priority = prio;
  340. p->tcfg_flags = gflags;
  341. gate_get_start_time(gact, &start);
  342. gact->current_close_time = start;
  343. gact->current_gate_status = GATE_ACT_GATE_OPEN | GATE_ACT_PENDING;
  344. gact->next_entry = list_first_entry(&p->entries,
  345. struct tcfg_gate_entry, list);
  346. goto_ch = tcf_action_set_ctrlact(*a, parm->action, goto_ch);
  347. gate_start_timer(gact, start);
  348. spin_unlock_bh(&gact->tcf_lock);
  349. if (goto_ch)
  350. tcf_chain_put_by_act(goto_ch);
  351. return ret;
  352. chain_put:
  353. spin_unlock_bh(&gact->tcf_lock);
  354. if (goto_ch)
  355. tcf_chain_put_by_act(goto_ch);
  356. release_idr:
  357. /* action is not inserted in any list: it's safe to init hitimer
  358. * without taking tcf_lock.
  359. */
  360. if (ret == ACT_P_CREATED)
  361. gate_setup_timer(gact, gact->param.tcfg_basetime,
  362. gact->tk_offset, gact->param.tcfg_clockid,
  363. true);
  364. tcf_idr_release(*a, bind);
  365. return err;
  366. }
  367. static void tcf_gate_cleanup(struct tc_action *a)
  368. {
  369. struct tcf_gate *gact = to_gate(a);
  370. struct tcf_gate_params *p;
  371. p = &gact->param;
  372. hrtimer_cancel(&gact->hitimer);
  373. release_entry_list(&p->entries);
  374. }
  375. static int dumping_entry(struct sk_buff *skb,
  376. struct tcfg_gate_entry *entry)
  377. {
  378. struct nlattr *item;
  379. item = nla_nest_start_noflag(skb, TCA_GATE_ONE_ENTRY);
  380. if (!item)
  381. return -ENOSPC;
  382. if (nla_put_u32(skb, TCA_GATE_ENTRY_INDEX, entry->index))
  383. goto nla_put_failure;
  384. if (entry->gate_state && nla_put_flag(skb, TCA_GATE_ENTRY_GATE))
  385. goto nla_put_failure;
  386. if (nla_put_u32(skb, TCA_GATE_ENTRY_INTERVAL, entry->interval))
  387. goto nla_put_failure;
  388. if (nla_put_s32(skb, TCA_GATE_ENTRY_MAX_OCTETS, entry->maxoctets))
  389. goto nla_put_failure;
  390. if (nla_put_s32(skb, TCA_GATE_ENTRY_IPV, entry->ipv))
  391. goto nla_put_failure;
  392. return nla_nest_end(skb, item);
  393. nla_put_failure:
  394. nla_nest_cancel(skb, item);
  395. return -1;
  396. }
  397. static int tcf_gate_dump(struct sk_buff *skb, struct tc_action *a,
  398. int bind, int ref)
  399. {
  400. unsigned char *b = skb_tail_pointer(skb);
  401. struct tcf_gate *gact = to_gate(a);
  402. struct tc_gate opt = {
  403. .index = gact->tcf_index,
  404. .refcnt = refcount_read(&gact->tcf_refcnt) - ref,
  405. .bindcnt = atomic_read(&gact->tcf_bindcnt) - bind,
  406. };
  407. struct tcfg_gate_entry *entry;
  408. struct tcf_gate_params *p;
  409. struct nlattr *entry_list;
  410. struct tcf_t t;
  411. spin_lock_bh(&gact->tcf_lock);
  412. opt.action = gact->tcf_action;
  413. p = &gact->param;
  414. if (nla_put(skb, TCA_GATE_PARMS, sizeof(opt), &opt))
  415. goto nla_put_failure;
  416. if (nla_put_u64_64bit(skb, TCA_GATE_BASE_TIME,
  417. p->tcfg_basetime, TCA_GATE_PAD))
  418. goto nla_put_failure;
  419. if (nla_put_u64_64bit(skb, TCA_GATE_CYCLE_TIME,
  420. p->tcfg_cycletime, TCA_GATE_PAD))
  421. goto nla_put_failure;
  422. if (nla_put_u64_64bit(skb, TCA_GATE_CYCLE_TIME_EXT,
  423. p->tcfg_cycletime_ext, TCA_GATE_PAD))
  424. goto nla_put_failure;
  425. if (nla_put_s32(skb, TCA_GATE_CLOCKID, p->tcfg_clockid))
  426. goto nla_put_failure;
  427. if (nla_put_u32(skb, TCA_GATE_FLAGS, p->tcfg_flags))
  428. goto nla_put_failure;
  429. if (nla_put_s32(skb, TCA_GATE_PRIORITY, p->tcfg_priority))
  430. goto nla_put_failure;
  431. entry_list = nla_nest_start_noflag(skb, TCA_GATE_ENTRY_LIST);
  432. if (!entry_list)
  433. goto nla_put_failure;
  434. list_for_each_entry(entry, &p->entries, list) {
  435. if (dumping_entry(skb, entry) < 0)
  436. goto nla_put_failure;
  437. }
  438. nla_nest_end(skb, entry_list);
  439. tcf_tm_dump(&t, &gact->tcf_tm);
  440. if (nla_put_64bit(skb, TCA_GATE_TM, sizeof(t), &t, TCA_GATE_PAD))
  441. goto nla_put_failure;
  442. spin_unlock_bh(&gact->tcf_lock);
  443. return skb->len;
  444. nla_put_failure:
  445. spin_unlock_bh(&gact->tcf_lock);
  446. nlmsg_trim(skb, b);
  447. return -1;
  448. }
  449. static void tcf_gate_stats_update(struct tc_action *a, u64 bytes, u64 packets,
  450. u64 drops, u64 lastuse, bool hw)
  451. {
  452. struct tcf_gate *gact = to_gate(a);
  453. struct tcf_t *tm = &gact->tcf_tm;
  454. tcf_action_update_stats(a, bytes, packets, drops, hw);
  455. tm->lastuse = max_t(u64, tm->lastuse, lastuse);
  456. }
  457. static size_t tcf_gate_get_fill_size(const struct tc_action *act)
  458. {
  459. return nla_total_size(sizeof(struct tc_gate));
  460. }
  461. static void tcf_gate_entry_destructor(void *priv)
  462. {
  463. struct action_gate_entry *oe = priv;
  464. kfree(oe);
  465. }
  466. static int tcf_gate_get_entries(struct flow_action_entry *entry,
  467. const struct tc_action *act)
  468. {
  469. entry->gate.entries = tcf_gate_get_list(act);
  470. if (!entry->gate.entries)
  471. return -EINVAL;
  472. entry->destructor = tcf_gate_entry_destructor;
  473. entry->destructor_priv = entry->gate.entries;
  474. return 0;
  475. }
  476. static int tcf_gate_offload_act_setup(struct tc_action *act, void *entry_data,
  477. u32 *index_inc, bool bind,
  478. struct netlink_ext_ack *extack)
  479. {
  480. int err;
  481. if (bind) {
  482. struct flow_action_entry *entry = entry_data;
  483. entry->id = FLOW_ACTION_GATE;
  484. entry->gate.prio = tcf_gate_prio(act);
  485. entry->gate.basetime = tcf_gate_basetime(act);
  486. entry->gate.cycletime = tcf_gate_cycletime(act);
  487. entry->gate.cycletimeext = tcf_gate_cycletimeext(act);
  488. entry->gate.num_entries = tcf_gate_num_entries(act);
  489. err = tcf_gate_get_entries(entry, act);
  490. if (err)
  491. return err;
  492. *index_inc = 1;
  493. } else {
  494. struct flow_offload_action *fl_action = entry_data;
  495. fl_action->id = FLOW_ACTION_GATE;
  496. }
  497. return 0;
  498. }
  499. static struct tc_action_ops act_gate_ops = {
  500. .kind = "gate",
  501. .id = TCA_ID_GATE,
  502. .owner = THIS_MODULE,
  503. .act = tcf_gate_act,
  504. .dump = tcf_gate_dump,
  505. .init = tcf_gate_init,
  506. .cleanup = tcf_gate_cleanup,
  507. .stats_update = tcf_gate_stats_update,
  508. .get_fill_size = tcf_gate_get_fill_size,
  509. .offload_act_setup = tcf_gate_offload_act_setup,
  510. .size = sizeof(struct tcf_gate),
  511. };
  512. MODULE_ALIAS_NET_ACT("gate");
  513. static __net_init int gate_init_net(struct net *net)
  514. {
  515. struct tc_action_net *tn = net_generic(net, act_gate_ops.net_id);
  516. return tc_action_net_init(net, tn, &act_gate_ops);
  517. }
  518. static void __net_exit gate_exit_net(struct list_head *net_list)
  519. {
  520. tc_action_net_exit(net_list, act_gate_ops.net_id);
  521. }
  522. static struct pernet_operations gate_net_ops = {
  523. .init = gate_init_net,
  524. .exit_batch = gate_exit_net,
  525. .id = &act_gate_ops.net_id,
  526. .size = sizeof(struct tc_action_net),
  527. };
  528. static int __init gate_init_module(void)
  529. {
  530. return tcf_register_action(&act_gate_ops, &gate_net_ops);
  531. }
  532. static void __exit gate_cleanup_module(void)
  533. {
  534. tcf_unregister_action(&act_gate_ops, &gate_net_ops);
  535. }
  536. module_init(gate_init_module);
  537. module_exit(gate_cleanup_module);
  538. MODULE_DESCRIPTION("TC gate action");
  539. MODULE_LICENSE("GPL v2");