blob: 8b3e593884803370ea27ef5fe770fa5ae829a888 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Jiri Pirko0c6965d2014-11-05 20:51:51 +01002 * net/sched/act_mirred.c packet mirroring and redirect actions
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
8 *
9 * Authors: Jamal Hadi Salim (2002-4)
10 *
11 * TODO: Add ingress support (and socket redirect support)
12 *
13 */
14
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/types.h>
16#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/string.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <linux/errno.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <linux/skbuff.h>
20#include <linux/rtnetlink.h>
21#include <linux/module.h>
22#include <linux/init.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090023#include <linux/gfp.h>
Daniel Borkmannc4916802016-11-26 01:28:06 +010024#include <linux/if_arp.h>
Eric W. Biederman881d9662007-09-17 11:56:21 -070025#include <net/net_namespace.h>
Arnaldo Carvalho de Melodc5fc572007-03-25 23:06:12 -070026#include <net/netlink.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <net/pkt_sched.h>
28#include <linux/tc_act/tc_mirred.h>
29#include <net/tc_act/tc_mirred.h>
30
stephen hemminger3b879562010-07-22 18:45:04 +000031static LIST_HEAD(mirred_list);
WANG Cong6bd00b82015-10-01 11:37:42 -070032static DEFINE_SPINLOCK(mirred_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
Shmulik Ladkani53592b32016-10-13 09:06:44 +030034static bool tcf_mirred_is_act_redirect(int action)
35{
36 return action == TCA_EGRESS_REDIR || action == TCA_INGRESS_REDIR;
37}
38
Willem de Bruijn8dc07fd2017-01-07 17:06:37 -050039static bool tcf_mirred_act_wants_ingress(int action)
Shmulik Ladkani53592b32016-10-13 09:06:44 +030040{
41 switch (action) {
42 case TCA_EGRESS_REDIR:
43 case TCA_EGRESS_MIRROR:
Willem de Bruijn8dc07fd2017-01-07 17:06:37 -050044 return false;
Shmulik Ladkani53592b32016-10-13 09:06:44 +030045 case TCA_INGRESS_REDIR:
46 case TCA_INGRESS_MIRROR:
Willem de Bruijn8dc07fd2017-01-07 17:06:37 -050047 return true;
Shmulik Ladkani53592b32016-10-13 09:06:44 +030048 default:
49 BUG();
50 }
51}
52
WANG Conga5b5c952014-02-11 17:07:32 -080053static void tcf_mirred_release(struct tc_action *a, int bind)
Linus Torvalds1da177e2005-04-16 15:20:36 -070054{
WANG Cong86062032014-02-11 17:07:31 -080055 struct tcf_mirred *m = to_mirred(a);
WANG Congdc327f82016-05-16 15:11:18 -070056 struct net_device *dev;
Eric Dumazet2ee22a92015-07-06 05:18:09 -070057
WANG Cong6bd00b82015-10-01 11:37:42 -070058 /* We could be called either in a RCU callback or with RTNL lock held. */
59 spin_lock_bh(&mirred_list_lock);
WANG Conga5b5c952014-02-11 17:07:32 -080060 list_del(&m->tcfm_list);
WANG Congdc327f82016-05-16 15:11:18 -070061 dev = rcu_dereference_protected(m->tcfm_dev, 1);
Eric Dumazet2ee22a92015-07-06 05:18:09 -070062 if (dev)
63 dev_put(dev);
WANG Congdc327f82016-05-16 15:11:18 -070064 spin_unlock_bh(&mirred_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070065}
66
Patrick McHardy53b2bf32008-01-23 20:36:30 -080067static const struct nla_policy mirred_policy[TCA_MIRRED_MAX + 1] = {
68 [TCA_MIRRED_PARMS] = { .len = sizeof(struct tc_mirred) },
69};
70
Alexey Dobriyanc7d03a02016-11-17 04:58:21 +030071static unsigned int mirred_net_id;
WANG Conga85a9702016-07-25 16:09:41 -070072static struct tc_action_ops act_mirred_ops;
WANG Congddf97cc2016-02-22 15:57:53 -080073
Benjamin LaHaisec1b52732013-01-14 05:15:39 +000074static int tcf_mirred_init(struct net *net, struct nlattr *nla,
WANG Conga85a9702016-07-25 16:09:41 -070075 struct nlattr *est, struct tc_action **a, int ovr,
Benjamin LaHaisec1b52732013-01-14 05:15:39 +000076 int bind)
Linus Torvalds1da177e2005-04-16 15:20:36 -070077{
WANG Congddf97cc2016-02-22 15:57:53 -080078 struct tc_action_net *tn = net_generic(net, mirred_net_id);
Patrick McHardy7ba699c2008-01-22 22:11:50 -080079 struct nlattr *tb[TCA_MIRRED_MAX + 1];
Shmulik Ladkani16577922016-10-13 09:06:41 +030080 bool mac_header_xmit = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 struct tc_mirred *parm;
David S. Millere9ce1cd2006-08-21 23:54:55 -070082 struct tcf_mirred *m;
Changli Gaob76965e2009-11-17 04:15:16 -080083 struct net_device *dev;
WANG Congb2313072016-06-13 13:46:28 -070084 bool exists = false;
Shmulik Ladkani16577922016-10-13 09:06:41 +030085 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
Patrick McHardycee63722008-01-23 20:33:32 -080087 if (nla == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 return -EINVAL;
Johannes Bergfceb6432017-04-12 14:34:07 +020089 ret = nla_parse_nested(tb, TCA_MIRRED_MAX, nla, mirred_policy, NULL);
Changli Gaob76965e2009-11-17 04:15:16 -080090 if (ret < 0)
91 return ret;
Patrick McHardy53b2bf32008-01-23 20:36:30 -080092 if (tb[TCA_MIRRED_PARMS] == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 return -EINVAL;
Patrick McHardy7ba699c2008-01-22 22:11:50 -080094 parm = nla_data(tb[TCA_MIRRED_PARMS]);
Jamal Hadi Salim87dfbdc2016-05-10 16:49:28 -040095
Chris Mi65a206c2017-08-30 02:31:59 -040096 exists = tcf_idr_check(tn, parm->index, a, bind);
Jamal Hadi Salim87dfbdc2016-05-10 16:49:28 -040097 if (exists && bind)
98 return 0;
99
Changli Gaob76965e2009-11-17 04:15:16 -0800100 switch (parm->eaction) {
101 case TCA_EGRESS_MIRROR:
102 case TCA_EGRESS_REDIR:
Shmulik Ladkani53592b32016-10-13 09:06:44 +0300103 case TCA_INGRESS_REDIR:
104 case TCA_INGRESS_MIRROR:
Changli Gaob76965e2009-11-17 04:15:16 -0800105 break;
106 default:
Jamal Hadi Salim87dfbdc2016-05-10 16:49:28 -0400107 if (exists)
Chris Mi65a206c2017-08-30 02:31:59 -0400108 tcf_idr_release(*a, bind);
Changli Gaob76965e2009-11-17 04:15:16 -0800109 return -EINVAL;
110 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 if (parm->ifindex) {
Benjamin LaHaisec1b52732013-01-14 05:15:39 +0000112 dev = __dev_get_by_index(net, parm->ifindex);
Jamal Hadi Salim87dfbdc2016-05-10 16:49:28 -0400113 if (dev == NULL) {
114 if (exists)
Chris Mi65a206c2017-08-30 02:31:59 -0400115 tcf_idr_release(*a, bind);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 return -ENODEV;
Jamal Hadi Salim87dfbdc2016-05-10 16:49:28 -0400117 }
Shmulik Ladkanidcf80032016-10-13 09:06:42 +0300118 mac_header_xmit = dev_is_mac_header_xmit(dev);
Changli Gaob76965e2009-11-17 04:15:16 -0800119 } else {
120 dev = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 }
122
Jamal Hadi Salim87dfbdc2016-05-10 16:49:28 -0400123 if (!exists) {
Changli Gaob76965e2009-11-17 04:15:16 -0800124 if (dev == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 return -EINVAL;
Chris Mi65a206c2017-08-30 02:31:59 -0400126 ret = tcf_idr_create(tn, parm->index, est, a,
127 &act_mirred_ops, bind, true);
WANG Cong86062032014-02-11 17:07:31 -0800128 if (ret)
129 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 ret = ACT_P_CREATED;
131 } else {
Chris Mi65a206c2017-08-30 02:31:59 -0400132 tcf_idr_release(*a, bind);
WANG Cong215c90a2015-10-01 11:37:43 -0700133 if (!ovr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 return -EEXIST;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 }
WANG Conga85a9702016-07-25 16:09:41 -0700136 m = to_mirred(*a);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137
Eric Dumazet2ee22a92015-07-06 05:18:09 -0700138 ASSERT_RTNL();
David S. Millere9ce1cd2006-08-21 23:54:55 -0700139 m->tcf_action = parm->action;
140 m->tcfm_eaction = parm->eaction;
Changli Gaob76965e2009-11-17 04:15:16 -0800141 if (dev != NULL) {
David S. Millere9ce1cd2006-08-21 23:54:55 -0700142 m->tcfm_ifindex = parm->ifindex;
Jiri Pirko843e79d2017-10-11 09:41:07 +0200143 m->net = net;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 if (ret != ACT_P_CREATED)
Eric Dumazet2ee22a92015-07-06 05:18:09 -0700145 dev_put(rcu_dereference_protected(m->tcfm_dev, 1));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 dev_hold(dev);
Eric Dumazet2ee22a92015-07-06 05:18:09 -0700147 rcu_assign_pointer(m->tcfm_dev, dev);
Shmulik Ladkani16577922016-10-13 09:06:41 +0300148 m->tcfm_mac_header_xmit = mac_header_xmit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 }
Eric Dumazet2ee22a92015-07-06 05:18:09 -0700150
stephen hemminger3b879562010-07-22 18:45:04 +0000151 if (ret == ACT_P_CREATED) {
WANG Cong6bd00b82015-10-01 11:37:42 -0700152 spin_lock_bh(&mirred_list_lock);
stephen hemminger3b879562010-07-22 18:45:04 +0000153 list_add(&m->tcfm_list, &mirred_list);
WANG Cong6bd00b82015-10-01 11:37:42 -0700154 spin_unlock_bh(&mirred_list_lock);
Chris Mi65a206c2017-08-30 02:31:59 -0400155 tcf_idr_insert(tn, *a);
stephen hemminger3b879562010-07-22 18:45:04 +0000156 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 return ret;
159}
160
Eric Dumazetdc7f9f62011-07-05 23:25:42 +0000161static int tcf_mirred(struct sk_buff *skb, const struct tc_action *a,
David S. Millere9ce1cd2006-08-21 23:54:55 -0700162 struct tcf_result *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163{
WANG Conga85a9702016-07-25 16:09:41 -0700164 struct tcf_mirred *m = to_mirred(a);
Shmulik Ladkani53592b32016-10-13 09:06:44 +0300165 bool m_mac_header_xmit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 struct net_device *dev;
Changli Gaofeed1f12009-11-17 04:14:00 -0800167 struct sk_buff *skb2;
Shmulik Ladkani53592b32016-10-13 09:06:44 +0300168 int retval, err = 0;
169 int m_eaction;
170 int mac_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
Eric Dumazet2ee22a92015-07-06 05:18:09 -0700172 tcf_lastuse_update(&m->tcf_tm);
Eric Dumazet2ee22a92015-07-06 05:18:09 -0700173 bstats_cpu_update(this_cpu_ptr(m->common.cpu_bstats), skb);
174
175 rcu_read_lock();
Shmulik Ladkani53592b32016-10-13 09:06:44 +0300176 m_mac_header_xmit = READ_ONCE(m->tcfm_mac_header_xmit);
177 m_eaction = READ_ONCE(m->tcfm_eaction);
Eric Dumazet2ee22a92015-07-06 05:18:09 -0700178 retval = READ_ONCE(m->tcf_action);
179 dev = rcu_dereference(m->tcfm_dev);
180 if (unlikely(!dev)) {
181 pr_notice_once("tc mirred: target device is gone\n");
stephen hemminger3b879562010-07-22 18:45:04 +0000182 goto out;
183 }
184
Eric Dumazet2ee22a92015-07-06 05:18:09 -0700185 if (unlikely(!(dev->flags & IFF_UP))) {
Joe Perchese87cc472012-05-13 21:56:26 +0000186 net_notice_ratelimited("tc mirred to Houston: device %s is down\n",
187 dev->name);
Changli Gaofeed1f12009-11-17 04:14:00 -0800188 goto out;
189 }
190
Florian Westphale578d9c2015-05-11 19:50:41 +0200191 skb2 = skb_clone(skb, GFP_ATOMIC);
Eric Dumazet2ee22a92015-07-06 05:18:09 -0700192 if (!skb2)
Changli Gaofeed1f12009-11-17 04:14:00 -0800193 goto out;
194
Shmulik Ladkani53592b32016-10-13 09:06:44 +0300195 /* If action's target direction differs than filter's direction,
196 * and devices expect a mac header on xmit, then mac push/pull is
197 * needed.
198 */
Willem de Bruijn8dc07fd2017-01-07 17:06:37 -0500199 if (skb_at_tc_ingress(skb) != tcf_mirred_act_wants_ingress(m_eaction) &&
Willem de Bruijna5135bc2017-01-07 17:06:36 -0500200 m_mac_header_xmit) {
201 if (!skb_at_tc_ingress(skb)) {
Shmulik Ladkani53592b32016-10-13 09:06:44 +0300202 /* caught at egress, act ingress: pull mac */
203 mac_len = skb_network_header(skb) - skb_mac_header(skb);
204 skb_pull_rcsum(skb2, mac_len);
205 } else {
206 /* caught at ingress, act egress: push mac */
WANG Cong82a31b92016-06-30 10:15:22 -0700207 skb_push_rcsum(skb2, skb->mac_len);
Shmulik Ladkani53592b32016-10-13 09:06:44 +0300208 }
Changli Gaofeed1f12009-11-17 04:14:00 -0800209 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
211 /* mirror is always swallowed */
Willem de Bruijnbc31c902017-01-07 17:06:38 -0500212 if (tcf_mirred_is_act_redirect(m_eaction)) {
213 skb2->tc_redirected = 1;
214 skb2->tc_from_ingress = skb2->tc_at_ingress;
215 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
Eric Dumazet8964be42009-11-20 15:35:04 -0800217 skb2->skb_iif = skb->dev->ifindex;
Changli Gao210d6de2010-06-24 16:25:12 +0000218 skb2->dev = dev;
Willem de Bruijn8dc07fd2017-01-07 17:06:37 -0500219 if (!tcf_mirred_act_wants_ingress(m_eaction))
Shmulik Ladkani53592b32016-10-13 09:06:44 +0300220 err = dev_queue_xmit(skb2);
221 else
222 err = netif_receive_skb(skb2);
Changli Gaofeed1f12009-11-17 04:14:00 -0800223
Changli Gaofeed1f12009-11-17 04:14:00 -0800224 if (err) {
Eric Dumazet2ee22a92015-07-06 05:18:09 -0700225out:
226 qstats_overlimit_inc(this_cpu_ptr(m->common.cpu_qstats));
Shmulik Ladkani53592b32016-10-13 09:06:44 +0300227 if (tcf_mirred_is_act_redirect(m_eaction))
Jason Wang16c0b162012-08-15 20:44:27 +0000228 retval = TC_ACT_SHOT;
Eric Dumazet2ee22a92015-07-06 05:18:09 -0700229 }
230 rcu_read_unlock();
Changli Gaofeed1f12009-11-17 04:14:00 -0800231
232 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233}
234
Jakub Kicinski9798e6f2016-09-21 11:44:05 +0100235static void tcf_stats_update(struct tc_action *a, u64 bytes, u32 packets,
236 u64 lastuse)
237{
Paul Blakey5712bf92016-10-19 17:42:39 +0300238 struct tcf_mirred *m = to_mirred(a);
239 struct tcf_t *tm = &m->tcf_tm;
240
Jakub Kicinski9798e6f2016-09-21 11:44:05 +0100241 _bstats_cpu_update(this_cpu_ptr(a->cpu_bstats), bytes, packets);
Paul Blakey5712bf92016-10-19 17:42:39 +0300242 tm->lastuse = lastuse;
Jakub Kicinski9798e6f2016-09-21 11:44:05 +0100243}
244
Jamal Hadi Salim5a7a5552016-09-18 08:45:33 -0400245static int tcf_mirred_dump(struct sk_buff *skb, struct tc_action *a, int bind,
246 int ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247{
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -0700248 unsigned char *b = skb_tail_pointer(skb);
WANG Conga85a9702016-07-25 16:09:41 -0700249 struct tcf_mirred *m = to_mirred(a);
Eric Dumazet1c40be12010-08-16 20:04:22 +0000250 struct tc_mirred opt = {
251 .index = m->tcf_index,
252 .action = m->tcf_action,
253 .refcnt = m->tcf_refcnt - ref,
254 .bindcnt = m->tcf_bindcnt - bind,
255 .eaction = m->tcfm_eaction,
256 .ifindex = m->tcfm_ifindex,
257 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 struct tcf_t t;
259
David S. Miller1b34ec42012-03-29 05:11:39 -0400260 if (nla_put(skb, TCA_MIRRED_PARMS, sizeof(opt), &opt))
261 goto nla_put_failure;
Jamal Hadi Salim48d8ee12016-06-06 06:32:55 -0400262
263 tcf_tm_dump(&t, &m->tcf_tm);
Nicolas Dichtel9854518e2016-04-26 10:06:18 +0200264 if (nla_put_64bit(skb, TCA_MIRRED_TM, sizeof(t), &t, TCA_MIRRED_PAD))
David S. Miller1b34ec42012-03-29 05:11:39 -0400265 goto nla_put_failure;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 return skb->len;
267
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800268nla_put_failure:
Arnaldo Carvalho de Melodc5fc572007-03-25 23:06:12 -0700269 nlmsg_trim(skb, b);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 return -1;
271}
272
WANG Congddf97cc2016-02-22 15:57:53 -0800273static int tcf_mirred_walker(struct net *net, struct sk_buff *skb,
274 struct netlink_callback *cb, int type,
WANG Conga85a9702016-07-25 16:09:41 -0700275 const struct tc_action_ops *ops)
WANG Congddf97cc2016-02-22 15:57:53 -0800276{
277 struct tc_action_net *tn = net_generic(net, mirred_net_id);
278
WANG Conga85a9702016-07-25 16:09:41 -0700279 return tcf_generic_walker(tn, skb, cb, type, ops);
WANG Congddf97cc2016-02-22 15:57:53 -0800280}
281
WANG Conga85a9702016-07-25 16:09:41 -0700282static int tcf_mirred_search(struct net *net, struct tc_action **a, u32 index)
WANG Congddf97cc2016-02-22 15:57:53 -0800283{
284 struct tc_action_net *tn = net_generic(net, mirred_net_id);
285
Chris Mi65a206c2017-08-30 02:31:59 -0400286 return tcf_idr_search(tn, a, index);
WANG Congddf97cc2016-02-22 15:57:53 -0800287}
288
stephen hemminger3b879562010-07-22 18:45:04 +0000289static int mirred_device_event(struct notifier_block *unused,
290 unsigned long event, void *ptr)
291{
Jiri Pirko351638e2013-05-28 01:30:21 +0000292 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
stephen hemminger3b879562010-07-22 18:45:04 +0000293 struct tcf_mirred *m;
294
Eric Dumazet2ee22a92015-07-06 05:18:09 -0700295 ASSERT_RTNL();
WANG Cong6bd00b82015-10-01 11:37:42 -0700296 if (event == NETDEV_UNREGISTER) {
297 spin_lock_bh(&mirred_list_lock);
stephen hemminger3b879562010-07-22 18:45:04 +0000298 list_for_each_entry(m, &mirred_list, tcfm_list) {
Eric Dumazet2ee22a92015-07-06 05:18:09 -0700299 if (rcu_access_pointer(m->tcfm_dev) == dev) {
stephen hemminger3b879562010-07-22 18:45:04 +0000300 dev_put(dev);
Eric Dumazet2ee22a92015-07-06 05:18:09 -0700301 /* Note : no rcu grace period necessary, as
302 * net_device are already rcu protected.
303 */
304 RCU_INIT_POINTER(m->tcfm_dev, NULL);
stephen hemminger3b879562010-07-22 18:45:04 +0000305 }
306 }
WANG Cong6bd00b82015-10-01 11:37:42 -0700307 spin_unlock_bh(&mirred_list_lock);
308 }
stephen hemminger3b879562010-07-22 18:45:04 +0000309
310 return NOTIFY_DONE;
311}
312
313static struct notifier_block mirred_device_notifier = {
314 .notifier_call = mirred_device_event,
315};
316
Jiri Pirko843e79d2017-10-11 09:41:07 +0200317static struct net_device *tcf_mirred_get_dev(const struct tc_action *a)
Hadar Hen Zion255cb302016-12-01 14:06:36 +0200318{
Jiri Pirko843e79d2017-10-11 09:41:07 +0200319 struct tcf_mirred *m = to_mirred(a);
Hadar Hen Zion255cb302016-12-01 14:06:36 +0200320
Jiri Pirko843e79d2017-10-11 09:41:07 +0200321 return __dev_get_by_index(m->net, m->tcfm_ifindex);
Hadar Hen Zion255cb302016-12-01 14:06:36 +0200322}
323
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324static struct tc_action_ops act_mirred_ops = {
325 .kind = "mirred",
326 .type = TCA_ACT_MIRRED,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 .owner = THIS_MODULE,
328 .act = tcf_mirred,
Jakub Kicinski9798e6f2016-09-21 11:44:05 +0100329 .stats_update = tcf_stats_update,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 .dump = tcf_mirred_dump,
WANG Cong86062032014-02-11 17:07:31 -0800331 .cleanup = tcf_mirred_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 .init = tcf_mirred_init,
WANG Congddf97cc2016-02-22 15:57:53 -0800333 .walk = tcf_mirred_walker,
334 .lookup = tcf_mirred_search,
WANG Conga85a9702016-07-25 16:09:41 -0700335 .size = sizeof(struct tcf_mirred),
Jiri Pirko843e79d2017-10-11 09:41:07 +0200336 .get_dev = tcf_mirred_get_dev,
WANG Congddf97cc2016-02-22 15:57:53 -0800337};
338
339static __net_init int mirred_init_net(struct net *net)
340{
341 struct tc_action_net *tn = net_generic(net, mirred_net_id);
342
Cong Wangc7e460c2017-11-06 13:47:18 -0800343 return tc_action_net_init(tn, &act_mirred_ops);
WANG Congddf97cc2016-02-22 15:57:53 -0800344}
345
346static void __net_exit mirred_exit_net(struct net *net)
347{
348 struct tc_action_net *tn = net_generic(net, mirred_net_id);
349
350 tc_action_net_exit(tn);
351}
352
353static struct pernet_operations mirred_net_ops = {
354 .init = mirred_init_net,
355 .exit = mirred_exit_net,
356 .id = &mirred_net_id,
357 .size = sizeof(struct tc_action_net),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358};
359
360MODULE_AUTHOR("Jamal Hadi Salim(2002)");
361MODULE_DESCRIPTION("Device Mirror/redirect actions");
362MODULE_LICENSE("GPL");
363
David S. Millere9ce1cd2006-08-21 23:54:55 -0700364static int __init mirred_init_module(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365{
stephen hemminger3b879562010-07-22 18:45:04 +0000366 int err = register_netdevice_notifier(&mirred_device_notifier);
367 if (err)
368 return err;
369
stephen hemminger6ff9c362010-05-12 06:37:05 +0000370 pr_info("Mirror/redirect action on\n");
WANG Congddf97cc2016-02-22 15:57:53 -0800371 return tcf_register_action(&act_mirred_ops, &mirred_net_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372}
373
David S. Millere9ce1cd2006-08-21 23:54:55 -0700374static void __exit mirred_cleanup_module(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375{
WANG Congddf97cc2016-02-22 15:57:53 -0800376 tcf_unregister_action(&act_mirred_ops, &mirred_net_ops);
WANG Cong568a1532013-12-20 00:08:51 -0800377 unregister_netdevice_notifier(&mirred_device_notifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378}
379
380module_init(mirred_init_module);
381module_exit(mirred_cleanup_module);