act_gate.c 16 KB

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