Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
Jiri Pirko | 0c6965d | 2014-11-05 20:51:51 +0100 | [diff] [blame] | 3 | * net/sched/act_pedit.c Generic packet editor |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * Authors: Jamal Hadi Salim (2002-4) |
| 6 | */ |
| 7 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | #include <linux/types.h> |
| 9 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <linux/string.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/errno.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/skbuff.h> |
| 13 | #include <linux/rtnetlink.h> |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/init.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 16 | #include <linux/slab.h> |
Arnaldo Carvalho de Melo | dc5fc57 | 2007-03-25 23:06:12 -0700 | [diff] [blame] | 17 | #include <net/netlink.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <net/pkt_sched.h> |
| 19 | #include <linux/tc_act/tc_pedit.h> |
| 20 | #include <net/tc_act/tc_pedit.h> |
Amir Vadai | 71d0ed7 | 2017-02-07 09:56:07 +0200 | [diff] [blame] | 21 | #include <uapi/linux/tc_act/tc_pedit.h> |
Davide Caratti | 6ac86ca | 2019-03-20 15:00:07 +0100 | [diff] [blame] | 22 | #include <net/pkt_cls.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | |
Alexey Dobriyan | c7d03a0 | 2016-11-17 04:58:21 +0300 | [diff] [blame] | 24 | static unsigned int pedit_net_id; |
WANG Cong | a85a970 | 2016-07-25 16:09:41 -0700 | [diff] [blame] | 25 | static struct tc_action_ops act_pedit_ops; |
WANG Cong | ddf97cc | 2016-02-22 15:57:53 -0800 | [diff] [blame] | 26 | |
Patrick McHardy | 53b2bf3 | 2008-01-23 20:36:30 -0800 | [diff] [blame] | 27 | static const struct nla_policy pedit_policy[TCA_PEDIT_MAX + 1] = { |
jamal | 53f7e35 | 2009-10-11 04:21:38 +0000 | [diff] [blame] | 28 | [TCA_PEDIT_PARMS] = { .len = sizeof(struct tc_pedit) }, |
Amir Vadai | 71d0ed7 | 2017-02-07 09:56:07 +0200 | [diff] [blame] | 29 | [TCA_PEDIT_KEYS_EX] = { .type = NLA_NESTED }, |
Patrick McHardy | 53b2bf3 | 2008-01-23 20:36:30 -0800 | [diff] [blame] | 30 | }; |
| 31 | |
Amir Vadai | 71d0ed7 | 2017-02-07 09:56:07 +0200 | [diff] [blame] | 32 | static const struct nla_policy pedit_key_ex_policy[TCA_PEDIT_KEY_EX_MAX + 1] = { |
| 33 | [TCA_PEDIT_KEY_EX_HTYPE] = { .type = NLA_U16 }, |
Amir Vadai | 853a14b | 2017-02-07 09:56:08 +0200 | [diff] [blame] | 34 | [TCA_PEDIT_KEY_EX_CMD] = { .type = NLA_U16 }, |
Amir Vadai | 71d0ed7 | 2017-02-07 09:56:07 +0200 | [diff] [blame] | 35 | }; |
| 36 | |
| 37 | static struct tcf_pedit_key_ex *tcf_pedit_keys_ex_parse(struct nlattr *nla, |
| 38 | u8 n) |
| 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 | |
| 46 | if (!nla || !n) |
| 47 | return NULL; |
| 48 | |
| 49 | keys_ex = kcalloc(n, sizeof(*k), GFP_KERNEL); |
| 50 | if (!keys_ex) |
| 51 | return ERR_PTR(-ENOMEM); |
| 52 | |
| 53 | k = keys_ex; |
| 54 | |
| 55 | nla_for_each_nested(ka, nla, rem) { |
| 56 | struct nlattr *tb[TCA_PEDIT_KEY_EX_MAX + 1]; |
| 57 | |
| 58 | if (!n) { |
| 59 | err = -EINVAL; |
| 60 | goto err_out; |
| 61 | } |
| 62 | n--; |
| 63 | |
| 64 | if (nla_type(ka) != TCA_PEDIT_KEY_EX) { |
| 65 | err = -EINVAL; |
| 66 | goto err_out; |
| 67 | } |
| 68 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 69 | err = nla_parse_nested_deprecated(tb, TCA_PEDIT_KEY_EX_MAX, |
| 70 | ka, pedit_key_ex_policy, |
| 71 | NULL); |
Amir Vadai | 71d0ed7 | 2017-02-07 09:56:07 +0200 | [diff] [blame] | 72 | if (err) |
| 73 | goto err_out; |
| 74 | |
Amir Vadai | 853a14b | 2017-02-07 09:56:08 +0200 | [diff] [blame] | 75 | if (!tb[TCA_PEDIT_KEY_EX_HTYPE] || |
| 76 | !tb[TCA_PEDIT_KEY_EX_CMD]) { |
Amir Vadai | 71d0ed7 | 2017-02-07 09:56:07 +0200 | [diff] [blame] | 77 | err = -EINVAL; |
| 78 | goto err_out; |
| 79 | } |
| 80 | |
| 81 | k->htype = nla_get_u16(tb[TCA_PEDIT_KEY_EX_HTYPE]); |
Amir Vadai | 853a14b | 2017-02-07 09:56:08 +0200 | [diff] [blame] | 82 | k->cmd = nla_get_u16(tb[TCA_PEDIT_KEY_EX_CMD]); |
Amir Vadai | 71d0ed7 | 2017-02-07 09:56:07 +0200 | [diff] [blame] | 83 | |
Amir Vadai | 853a14b | 2017-02-07 09:56:08 +0200 | [diff] [blame] | 84 | if (k->htype > TCA_PEDIT_HDR_TYPE_MAX || |
| 85 | k->cmd > TCA_PEDIT_CMD_MAX) { |
Amir Vadai | 71d0ed7 | 2017-02-07 09:56:07 +0200 | [diff] [blame] | 86 | err = -EINVAL; |
| 87 | goto err_out; |
| 88 | } |
| 89 | |
| 90 | k++; |
| 91 | } |
| 92 | |
Dan Carpenter | c4f65b0 | 2017-06-14 13:29:31 +0300 | [diff] [blame] | 93 | if (n) { |
| 94 | err = -EINVAL; |
Amir Vadai | 71d0ed7 | 2017-02-07 09:56:07 +0200 | [diff] [blame] | 95 | goto err_out; |
Dan Carpenter | c4f65b0 | 2017-06-14 13:29:31 +0300 | [diff] [blame] | 96 | } |
Amir Vadai | 71d0ed7 | 2017-02-07 09:56:07 +0200 | [diff] [blame] | 97 | |
| 98 | return keys_ex; |
| 99 | |
| 100 | err_out: |
| 101 | kfree(keys_ex); |
| 102 | return ERR_PTR(err); |
| 103 | } |
| 104 | |
| 105 | static int tcf_pedit_key_ex_dump(struct sk_buff *skb, |
| 106 | struct tcf_pedit_key_ex *keys_ex, int n) |
| 107 | { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 108 | struct nlattr *keys_start = nla_nest_start_noflag(skb, |
| 109 | TCA_PEDIT_KEYS_EX); |
Amir Vadai | 71d0ed7 | 2017-02-07 09:56:07 +0200 | [diff] [blame] | 110 | |
Davide Caratti | 85eb9af | 2018-08-27 22:56:22 +0200 | [diff] [blame] | 111 | if (!keys_start) |
| 112 | goto nla_failure; |
Amir Vadai | 71d0ed7 | 2017-02-07 09:56:07 +0200 | [diff] [blame] | 113 | for (; n > 0; n--) { |
| 114 | struct nlattr *key_start; |
| 115 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 116 | key_start = nla_nest_start_noflag(skb, TCA_PEDIT_KEY_EX); |
Davide Caratti | 85eb9af | 2018-08-27 22:56:22 +0200 | [diff] [blame] | 117 | if (!key_start) |
| 118 | goto nla_failure; |
Amir Vadai | 71d0ed7 | 2017-02-07 09:56:07 +0200 | [diff] [blame] | 119 | |
Amir Vadai | 853a14b | 2017-02-07 09:56:08 +0200 | [diff] [blame] | 120 | if (nla_put_u16(skb, TCA_PEDIT_KEY_EX_HTYPE, keys_ex->htype) || |
Davide Caratti | 85eb9af | 2018-08-27 22:56:22 +0200 | [diff] [blame] | 121 | nla_put_u16(skb, TCA_PEDIT_KEY_EX_CMD, keys_ex->cmd)) |
| 122 | goto nla_failure; |
Amir Vadai | 71d0ed7 | 2017-02-07 09:56:07 +0200 | [diff] [blame] | 123 | |
| 124 | nla_nest_end(skb, key_start); |
| 125 | |
| 126 | keys_ex++; |
| 127 | } |
| 128 | |
| 129 | nla_nest_end(skb, keys_start); |
| 130 | |
| 131 | return 0; |
Davide Caratti | 85eb9af | 2018-08-27 22:56:22 +0200 | [diff] [blame] | 132 | nla_failure: |
| 133 | nla_nest_cancel(skb, keys_start); |
| 134 | return -EINVAL; |
Amir Vadai | 71d0ed7 | 2017-02-07 09:56:07 +0200 | [diff] [blame] | 135 | } |
| 136 | |
Benjamin LaHaise | c1b5273 | 2013-01-14 05:15:39 +0000 | [diff] [blame] | 137 | static int tcf_pedit_init(struct net *net, struct nlattr *nla, |
WANG Cong | a85a970 | 2016-07-25 16:09:41 -0700 | [diff] [blame] | 138 | struct nlattr *est, struct tc_action **a, |
Vlad Buslov | 789871b | 2018-07-05 17:24:25 +0300 | [diff] [blame] | 139 | int ovr, int bind, bool rtnl_held, |
Vlad Buslov | abbb0d3 | 2019-10-30 16:09:05 +0200 | [diff] [blame^] | 140 | struct tcf_proto *tp, u32 flags, |
| 141 | struct netlink_ext_ack *extack) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | { |
WANG Cong | ddf97cc | 2016-02-22 15:57:53 -0800 | [diff] [blame] | 143 | struct tc_action_net *tn = net_generic(net, pedit_net_id); |
Patrick McHardy | 7ba699c | 2008-01-22 22:11:50 -0800 | [diff] [blame] | 144 | struct nlattr *tb[TCA_PEDIT_MAX + 1]; |
Davide Caratti | 6ac86ca | 2019-03-20 15:00:07 +0100 | [diff] [blame] | 145 | struct tcf_chain *goto_ch = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | struct tc_pedit_key *keys = NULL; |
Amir Vadai | 71d0ed7 | 2017-02-07 09:56:07 +0200 | [diff] [blame] | 147 | struct tcf_pedit_key_ex *keys_ex; |
Roman Mashak | 80f0f57 | 2018-06-27 13:33:30 -0400 | [diff] [blame] | 148 | struct tc_pedit *parm; |
| 149 | struct nlattr *pattr; |
| 150 | struct tcf_pedit *p; |
| 151 | int ret = 0, err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | int ksize; |
Dmytro Linkin | 7be8ef2 | 2019-08-01 13:02:51 +0000 | [diff] [blame] | 153 | u32 index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | |
Roman Mashak | 9868c0b | 2018-07-02 00:02:02 -0400 | [diff] [blame] | 155 | if (!nla) { |
| 156 | NL_SET_ERR_MSG_MOD(extack, "Pedit requires attributes to be passed"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | return -EINVAL; |
Roman Mashak | 9868c0b | 2018-07-02 00:02:02 -0400 | [diff] [blame] | 158 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 160 | err = nla_parse_nested_deprecated(tb, TCA_PEDIT_MAX, nla, |
| 161 | pedit_policy, NULL); |
Patrick McHardy | cee6372 | 2008-01-23 20:33:32 -0800 | [diff] [blame] | 162 | if (err < 0) |
| 163 | return err; |
| 164 | |
Amir Vadai | 71d0ed7 | 2017-02-07 09:56:07 +0200 | [diff] [blame] | 165 | pattr = tb[TCA_PEDIT_PARMS]; |
| 166 | if (!pattr) |
| 167 | pattr = tb[TCA_PEDIT_PARMS_EX]; |
Roman Mashak | 9868c0b | 2018-07-02 00:02:02 -0400 | [diff] [blame] | 168 | if (!pattr) { |
| 169 | NL_SET_ERR_MSG_MOD(extack, "Missing required TCA_PEDIT_PARMS or TCA_PEDIT_PARMS_EX pedit attribute"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | return -EINVAL; |
Roman Mashak | 9868c0b | 2018-07-02 00:02:02 -0400 | [diff] [blame] | 171 | } |
Amir Vadai | 71d0ed7 | 2017-02-07 09:56:07 +0200 | [diff] [blame] | 172 | |
| 173 | parm = nla_data(pattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | ksize = parm->nkeys * sizeof(struct tc_pedit_key); |
Roman Mashak | 9868c0b | 2018-07-02 00:02:02 -0400 | [diff] [blame] | 175 | if (nla_len(pattr) < sizeof(*parm) + ksize) { |
| 176 | NL_SET_ERR_MSG_ATTR(extack, pattr, "Length of TCA_PEDIT_PARMS or TCA_PEDIT_PARMS_EX pedit attribute is invalid"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | return -EINVAL; |
Roman Mashak | 9868c0b | 2018-07-02 00:02:02 -0400 | [diff] [blame] | 178 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | |
Amir Vadai | 71d0ed7 | 2017-02-07 09:56:07 +0200 | [diff] [blame] | 180 | keys_ex = tcf_pedit_keys_ex_parse(tb[TCA_PEDIT_KEYS_EX], parm->nkeys); |
| 181 | if (IS_ERR(keys_ex)) |
| 182 | return PTR_ERR(keys_ex); |
| 183 | |
Dmytro Linkin | 7be8ef2 | 2019-08-01 13:02:51 +0000 | [diff] [blame] | 184 | index = parm->index; |
| 185 | err = tcf_idr_check_alloc(tn, &index, a, bind); |
Vlad Buslov | 0190c1d | 2018-07-05 17:24:32 +0300 | [diff] [blame] | 186 | if (!err) { |
Roman Mashak | 9868c0b | 2018-07-02 00:02:02 -0400 | [diff] [blame] | 187 | if (!parm->nkeys) { |
Dmytro Linkin | 7be8ef2 | 2019-08-01 13:02:51 +0000 | [diff] [blame] | 188 | tcf_idr_cleanup(tn, index); |
Roman Mashak | 9868c0b | 2018-07-02 00:02:02 -0400 | [diff] [blame] | 189 | NL_SET_ERR_MSG_MOD(extack, "Pedit requires keys to be passed"); |
Wei Yongjun | 30e99ed | 2018-07-03 13:45:12 +0000 | [diff] [blame] | 190 | ret = -EINVAL; |
| 191 | goto out_free; |
Roman Mashak | 9868c0b | 2018-07-02 00:02:02 -0400 | [diff] [blame] | 192 | } |
Dmytro Linkin | 7be8ef2 | 2019-08-01 13:02:51 +0000 | [diff] [blame] | 193 | ret = tcf_idr_create(tn, index, est, a, |
Chris Mi | 65a206c | 2017-08-30 02:31:59 -0400 | [diff] [blame] | 194 | &act_pedit_ops, bind, false); |
Vlad Buslov | 0190c1d | 2018-07-05 17:24:32 +0300 | [diff] [blame] | 195 | if (ret) { |
Dmytro Linkin | 7be8ef2 | 2019-08-01 13:02:51 +0000 | [diff] [blame] | 196 | tcf_idr_cleanup(tn, index); |
Wei Yongjun | 30e99ed | 2018-07-03 13:45:12 +0000 | [diff] [blame] | 197 | goto out_free; |
Vlad Buslov | 0190c1d | 2018-07-05 17:24:32 +0300 | [diff] [blame] | 198 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | ret = ACT_P_CREATED; |
Vlad Buslov | 0190c1d | 2018-07-05 17:24:32 +0300 | [diff] [blame] | 200 | } else if (err > 0) { |
Jamal Hadi Salim | 1a29321 | 2013-12-23 08:02:11 -0500 | [diff] [blame] | 201 | if (bind) |
Wei Yongjun | 30e99ed | 2018-07-03 13:45:12 +0000 | [diff] [blame] | 202 | goto out_free; |
Wei Yongjun | 30e99ed | 2018-07-03 13:45:12 +0000 | [diff] [blame] | 203 | if (!ovr) { |
| 204 | ret = -EEXIST; |
Vlad Buslov | 67b0c1a | 2018-08-10 20:51:46 +0300 | [diff] [blame] | 205 | goto out_release; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | } |
Vlad Buslov | 0190c1d | 2018-07-05 17:24:32 +0300 | [diff] [blame] | 207 | } else { |
Davide Caratti | 19ab691 | 2018-11-14 12:17:25 +0100 | [diff] [blame] | 208 | ret = err; |
| 209 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | } |
| 211 | |
Davide Caratti | 6ac86ca | 2019-03-20 15:00:07 +0100 | [diff] [blame] | 212 | err = tcf_action_check_ctrlact(parm->action, tp, &goto_ch, extack); |
| 213 | if (err < 0) { |
| 214 | ret = err; |
| 215 | goto out_release; |
| 216 | } |
Vlad Buslov | 67b0c1a | 2018-08-10 20:51:46 +0300 | [diff] [blame] | 217 | p = to_pedit(*a); |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 218 | spin_lock_bh(&p->tcf_lock); |
Vlad Buslov | 67b0c1a | 2018-08-10 20:51:46 +0300 | [diff] [blame] | 219 | |
| 220 | if (ret == ACT_P_CREATED || |
| 221 | (p->tcfp_nkeys && p->tcfp_nkeys != parm->nkeys)) { |
| 222 | keys = kmalloc(ksize, GFP_ATOMIC); |
| 223 | if (!keys) { |
| 224 | spin_unlock_bh(&p->tcf_lock); |
| 225 | ret = -ENOMEM; |
Davide Caratti | 6ac86ca | 2019-03-20 15:00:07 +0100 | [diff] [blame] | 226 | goto put_chain; |
Vlad Buslov | 67b0c1a | 2018-08-10 20:51:46 +0300 | [diff] [blame] | 227 | } |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 228 | kfree(p->tcfp_keys); |
| 229 | p->tcfp_keys = keys; |
| 230 | p->tcfp_nkeys = parm->nkeys; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | } |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 232 | memcpy(p->tcfp_keys, parm->keys, ksize); |
Amir Vadai | 71d0ed7 | 2017-02-07 09:56:07 +0200 | [diff] [blame] | 233 | |
Vlad Buslov | 67b0c1a | 2018-08-10 20:51:46 +0300 | [diff] [blame] | 234 | p->tcfp_flags = parm->flags; |
Davide Caratti | 6ac86ca | 2019-03-20 15:00:07 +0100 | [diff] [blame] | 235 | goto_ch = tcf_action_set_ctrlact(*a, parm->action, goto_ch); |
Vlad Buslov | 67b0c1a | 2018-08-10 20:51:46 +0300 | [diff] [blame] | 236 | |
Amir Vadai | 71d0ed7 | 2017-02-07 09:56:07 +0200 | [diff] [blame] | 237 | kfree(p->tcfp_keys_ex); |
| 238 | p->tcfp_keys_ex = keys_ex; |
| 239 | |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 240 | spin_unlock_bh(&p->tcf_lock); |
Davide Caratti | 6ac86ca | 2019-03-20 15:00:07 +0100 | [diff] [blame] | 241 | if (goto_ch) |
| 242 | tcf_chain_put_by_act(goto_ch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | if (ret == ACT_P_CREATED) |
Chris Mi | 65a206c | 2017-08-30 02:31:59 -0400 | [diff] [blame] | 244 | tcf_idr_insert(tn, *a); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | return ret; |
Vlad Buslov | 67b0c1a | 2018-08-10 20:51:46 +0300 | [diff] [blame] | 246 | |
Davide Caratti | 6ac86ca | 2019-03-20 15:00:07 +0100 | [diff] [blame] | 247 | put_chain: |
| 248 | if (goto_ch) |
| 249 | tcf_chain_put_by_act(goto_ch); |
Vlad Buslov | 67b0c1a | 2018-08-10 20:51:46 +0300 | [diff] [blame] | 250 | out_release: |
| 251 | tcf_idr_release(*a, bind); |
Wei Yongjun | 30e99ed | 2018-07-03 13:45:12 +0000 | [diff] [blame] | 252 | out_free: |
| 253 | kfree(keys_ex); |
| 254 | return ret; |
| 255 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | } |
| 257 | |
Cong Wang | 9a63b25 | 2017-12-05 12:53:07 -0800 | [diff] [blame] | 258 | static void tcf_pedit_cleanup(struct tc_action *a) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | { |
WANG Cong | a85a970 | 2016-07-25 16:09:41 -0700 | [diff] [blame] | 260 | struct tcf_pedit *p = to_pedit(a); |
WANG Cong | a5b5c95 | 2014-02-11 17:07:32 -0800 | [diff] [blame] | 261 | struct tc_pedit_key *keys = p->tcfp_keys; |
Roman Mashak | 80f0f57 | 2018-06-27 13:33:30 -0400 | [diff] [blame] | 262 | |
WANG Cong | a5b5c95 | 2014-02-11 17:07:32 -0800 | [diff] [blame] | 263 | kfree(keys); |
Amir Vadai | 71d0ed7 | 2017-02-07 09:56:07 +0200 | [diff] [blame] | 264 | kfree(p->tcfp_keys_ex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | } |
| 266 | |
Amir Vadai | 95c2027 | 2016-11-28 12:56:40 +0200 | [diff] [blame] | 267 | static bool offset_valid(struct sk_buff *skb, int offset) |
| 268 | { |
| 269 | if (offset > 0 && offset > skb->len) |
| 270 | return false; |
| 271 | |
| 272 | if (offset < 0 && -offset > skb_headroom(skb)) |
| 273 | return false; |
| 274 | |
| 275 | return true; |
| 276 | } |
| 277 | |
Amir Vadai | 71d0ed7 | 2017-02-07 09:56:07 +0200 | [diff] [blame] | 278 | static int pedit_skb_hdr_offset(struct sk_buff *skb, |
| 279 | enum pedit_header_type htype, int *hoffset) |
| 280 | { |
| 281 | int ret = -EINVAL; |
| 282 | |
| 283 | switch (htype) { |
| 284 | case TCA_PEDIT_KEY_EX_HDR_TYPE_ETH: |
| 285 | if (skb_mac_header_was_set(skb)) { |
| 286 | *hoffset = skb_mac_offset(skb); |
| 287 | ret = 0; |
| 288 | } |
| 289 | break; |
| 290 | case TCA_PEDIT_KEY_EX_HDR_TYPE_NETWORK: |
| 291 | case TCA_PEDIT_KEY_EX_HDR_TYPE_IP4: |
| 292 | case TCA_PEDIT_KEY_EX_HDR_TYPE_IP6: |
| 293 | *hoffset = skb_network_offset(skb); |
| 294 | ret = 0; |
| 295 | break; |
| 296 | case TCA_PEDIT_KEY_EX_HDR_TYPE_TCP: |
| 297 | case TCA_PEDIT_KEY_EX_HDR_TYPE_UDP: |
| 298 | if (skb_transport_header_was_set(skb)) { |
| 299 | *hoffset = skb_transport_offset(skb); |
| 300 | ret = 0; |
| 301 | } |
| 302 | break; |
| 303 | default: |
| 304 | ret = -EINVAL; |
| 305 | break; |
YueHaibing | 0a80848 | 2018-07-28 18:29:01 +0800 | [diff] [blame] | 306 | } |
Amir Vadai | 71d0ed7 | 2017-02-07 09:56:07 +0200 | [diff] [blame] | 307 | |
| 308 | return ret; |
| 309 | } |
| 310 | |
Jamal Hadi Salim | 6a2b401 | 2018-08-12 09:34:55 -0400 | [diff] [blame] | 311 | static int tcf_pedit_act(struct sk_buff *skb, const struct tc_action *a, |
| 312 | struct tcf_result *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | { |
WANG Cong | a85a970 | 2016-07-25 16:09:41 -0700 | [diff] [blame] | 314 | struct tcf_pedit *p = to_pedit(a); |
Florian Westphal | 4749c3ef | 2015-04-30 12:12:00 +0200 | [diff] [blame] | 315 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | |
Pravin B Shelar | 14bbd6a | 2013-02-14 09:44:49 +0000 | [diff] [blame] | 317 | if (skb_unclone(skb, GFP_ATOMIC)) |
Eric Dumazet | cc7ec45 | 2011-01-19 19:26:56 +0000 | [diff] [blame] | 318 | return p->tcf_action; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 320 | spin_lock(&p->tcf_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | |
Jamal Hadi Salim | 9c4a4e4 | 2016-06-06 06:32:53 -0400 | [diff] [blame] | 322 | tcf_lastuse_update(&p->tcf_tm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 324 | if (p->tcfp_nkeys > 0) { |
| 325 | struct tc_pedit_key *tkey = p->tcfp_keys; |
Amir Vadai | 71d0ed7 | 2017-02-07 09:56:07 +0200 | [diff] [blame] | 326 | struct tcf_pedit_key_ex *tkey_ex = p->tcfp_keys_ex; |
Roman Mashak | 80f0f57 | 2018-06-27 13:33:30 -0400 | [diff] [blame] | 327 | enum pedit_header_type htype = |
| 328 | TCA_PEDIT_KEY_EX_HDR_TYPE_NETWORK; |
Amir Vadai | 853a14b | 2017-02-07 09:56:08 +0200 | [diff] [blame] | 329 | enum pedit_cmd cmd = TCA_PEDIT_KEY_EX_CMD_SET; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 331 | for (i = p->tcfp_nkeys; i > 0; i--, tkey++) { |
Roman Mashak | 544377c | 2018-06-27 13:33:32 -0400 | [diff] [blame] | 332 | u32 *ptr, hdata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | int offset = tkey->off; |
Amir Vadai | 71d0ed7 | 2017-02-07 09:56:07 +0200 | [diff] [blame] | 334 | int hoffset; |
Amir Vadai | 853a14b | 2017-02-07 09:56:08 +0200 | [diff] [blame] | 335 | u32 val; |
Amir Vadai | 71d0ed7 | 2017-02-07 09:56:07 +0200 | [diff] [blame] | 336 | int rc; |
| 337 | |
| 338 | if (tkey_ex) { |
| 339 | htype = tkey_ex->htype; |
Amir Vadai | 853a14b | 2017-02-07 09:56:08 +0200 | [diff] [blame] | 340 | cmd = tkey_ex->cmd; |
| 341 | |
Amir Vadai | 71d0ed7 | 2017-02-07 09:56:07 +0200 | [diff] [blame] | 342 | tkey_ex++; |
| 343 | } |
| 344 | |
| 345 | rc = pedit_skb_hdr_offset(skb, htype, &hoffset); |
| 346 | if (rc) { |
Roman Mashak | 95b0d2d | 2018-06-27 13:33:34 -0400 | [diff] [blame] | 347 | pr_info("tc action pedit bad header type specified (0x%x)\n", |
Amir Vadai | 71d0ed7 | 2017-02-07 09:56:07 +0200 | [diff] [blame] | 348 | htype); |
| 349 | goto bad; |
| 350 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | |
| 352 | if (tkey->offmask) { |
Roman Mashak | 4305274 | 2018-06-27 13:33:35 -0400 | [diff] [blame] | 353 | u8 *d, _d; |
Changli Gao | db2c241 | 2010-06-02 04:55:02 +0000 | [diff] [blame] | 354 | |
Amir Vadai | 71d0ed7 | 2017-02-07 09:56:07 +0200 | [diff] [blame] | 355 | if (!offset_valid(skb, hoffset + tkey->at)) { |
Roman Mashak | 95b0d2d | 2018-06-27 13:33:34 -0400 | [diff] [blame] | 356 | pr_info("tc action pedit 'at' offset %d out of bounds\n", |
Amir Vadai | 71d0ed7 | 2017-02-07 09:56:07 +0200 | [diff] [blame] | 357 | hoffset + tkey->at); |
Amir Vadai | 95c2027 | 2016-11-28 12:56:40 +0200 | [diff] [blame] | 358 | goto bad; |
| 359 | } |
Roman Mashak | 80f0f57 | 2018-06-27 13:33:30 -0400 | [diff] [blame] | 360 | d = skb_header_pointer(skb, hoffset + tkey->at, |
Roman Mashak | 6ff7586 | 2018-06-27 13:33:33 -0400 | [diff] [blame] | 361 | sizeof(_d), &_d); |
Changli Gao | db2c241 | 2010-06-02 04:55:02 +0000 | [diff] [blame] | 362 | if (!d) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | goto bad; |
Changli Gao | db2c241 | 2010-06-02 04:55:02 +0000 | [diff] [blame] | 364 | offset += (*d & tkey->offmask) >> tkey->shift; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | if (offset % 4) { |
Roman Mashak | 95b0d2d | 2018-06-27 13:33:34 -0400 | [diff] [blame] | 368 | pr_info("tc action pedit offset must be on 32 bit boundaries\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | goto bad; |
| 370 | } |
Amir Vadai | 95c2027 | 2016-11-28 12:56:40 +0200 | [diff] [blame] | 371 | |
Amir Vadai | 71d0ed7 | 2017-02-07 09:56:07 +0200 | [diff] [blame] | 372 | if (!offset_valid(skb, hoffset + offset)) { |
Roman Mashak | 95b0d2d | 2018-06-27 13:33:34 -0400 | [diff] [blame] | 373 | pr_info("tc action pedit offset %d out of bounds\n", |
Amir Vadai | 71d0ed7 | 2017-02-07 09:56:07 +0200 | [diff] [blame] | 374 | hoffset + offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | goto bad; |
| 376 | } |
| 377 | |
Roman Mashak | 80f0f57 | 2018-06-27 13:33:30 -0400 | [diff] [blame] | 378 | ptr = skb_header_pointer(skb, hoffset + offset, |
Roman Mashak | 6ff7586 | 2018-06-27 13:33:33 -0400 | [diff] [blame] | 379 | sizeof(hdata), &hdata); |
Changli Gao | db2c241 | 2010-06-02 04:55:02 +0000 | [diff] [blame] | 380 | if (!ptr) |
| 381 | goto bad; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | /* just do it, baby */ |
Amir Vadai | 853a14b | 2017-02-07 09:56:08 +0200 | [diff] [blame] | 383 | switch (cmd) { |
| 384 | case TCA_PEDIT_KEY_EX_CMD_SET: |
| 385 | val = tkey->val; |
| 386 | break; |
| 387 | case TCA_PEDIT_KEY_EX_CMD_ADD: |
| 388 | val = (*ptr + tkey->val) & ~tkey->mask; |
| 389 | break; |
| 390 | default: |
Roman Mashak | 95b0d2d | 2018-06-27 13:33:34 -0400 | [diff] [blame] | 391 | pr_info("tc action pedit bad command (%d)\n", |
Amir Vadai | 853a14b | 2017-02-07 09:56:08 +0200 | [diff] [blame] | 392 | cmd); |
| 393 | goto bad; |
| 394 | } |
| 395 | |
| 396 | *ptr = ((*ptr & tkey->mask) ^ val); |
Roman Mashak | 544377c | 2018-06-27 13:33:32 -0400 | [diff] [blame] | 397 | if (ptr == &hdata) |
Amir Vadai | 71d0ed7 | 2017-02-07 09:56:07 +0200 | [diff] [blame] | 398 | skb_store_bits(skb, hoffset + offset, ptr, 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | } |
YOSHIFUJI Hideaki | 10297b9 | 2007-02-09 23:25:16 +0900 | [diff] [blame] | 400 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | goto done; |
Roman Mashak | 80f0f57 | 2018-06-27 13:33:30 -0400 | [diff] [blame] | 402 | } else { |
stephen hemminger | 6ff9c36 | 2010-05-12 06:37:05 +0000 | [diff] [blame] | 403 | WARN(1, "pedit BUG: index %d\n", p->tcf_index); |
Roman Mashak | 80f0f57 | 2018-06-27 13:33:30 -0400 | [diff] [blame] | 404 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | |
| 406 | bad: |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 407 | p->tcf_qstats.overlimits++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | done: |
Eric Dumazet | bfe0d02 | 2011-01-09 08:30:54 +0000 | [diff] [blame] | 409 | bstats_update(&p->tcf_bstats, skb); |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 410 | spin_unlock(&p->tcf_lock); |
| 411 | return p->tcf_action; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | } |
| 413 | |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 414 | static int tcf_pedit_dump(struct sk_buff *skb, struct tc_action *a, |
| 415 | int bind, int ref) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | { |
Arnaldo Carvalho de Melo | 27a884d | 2007-04-19 20:29:13 -0700 | [diff] [blame] | 417 | unsigned char *b = skb_tail_pointer(skb); |
WANG Cong | a85a970 | 2016-07-25 16:09:41 -0700 | [diff] [blame] | 418 | struct tcf_pedit *p = to_pedit(a); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | struct tc_pedit *opt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | struct tcf_t t; |
YOSHIFUJI Hideaki | 10297b9 | 2007-02-09 23:25:16 +0900 | [diff] [blame] | 421 | int s; |
| 422 | |
Gustavo A. R. Silva | 8fe5756 | 2019-02-07 19:02:52 -0600 | [diff] [blame] | 423 | s = struct_size(opt, keys, p->tcfp_nkeys); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | |
| 425 | /* netlink spinlocks held above us - must use ATOMIC */ |
Panagiotis Issaris | 0da974f | 2006-07-21 14:51:30 -0700 | [diff] [blame] | 426 | opt = kzalloc(s, GFP_ATOMIC); |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 427 | if (unlikely(!opt)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | return -ENOBUFS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | |
Vlad Buslov | 67b0c1a | 2018-08-10 20:51:46 +0300 | [diff] [blame] | 430 | spin_lock_bh(&p->tcf_lock); |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 431 | memcpy(opt->keys, p->tcfp_keys, |
| 432 | p->tcfp_nkeys * sizeof(struct tc_pedit_key)); |
| 433 | opt->index = p->tcf_index; |
| 434 | opt->nkeys = p->tcfp_nkeys; |
| 435 | opt->flags = p->tcfp_flags; |
| 436 | opt->action = p->tcf_action; |
Vlad Buslov | 036bb44 | 2018-07-05 17:24:24 +0300 | [diff] [blame] | 437 | opt->refcnt = refcount_read(&p->tcf_refcnt) - ref; |
| 438 | opt->bindcnt = atomic_read(&p->tcf_bindcnt) - bind; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | |
Amir Vadai | 71d0ed7 | 2017-02-07 09:56:07 +0200 | [diff] [blame] | 440 | if (p->tcfp_keys_ex) { |
Davide Caratti | 85eb9af | 2018-08-27 22:56:22 +0200 | [diff] [blame] | 441 | if (tcf_pedit_key_ex_dump(skb, |
| 442 | p->tcfp_keys_ex, |
| 443 | p->tcfp_nkeys)) |
| 444 | goto nla_put_failure; |
Amir Vadai | 71d0ed7 | 2017-02-07 09:56:07 +0200 | [diff] [blame] | 445 | |
| 446 | if (nla_put(skb, TCA_PEDIT_PARMS_EX, s, opt)) |
| 447 | goto nla_put_failure; |
| 448 | } else { |
| 449 | if (nla_put(skb, TCA_PEDIT_PARMS, s, opt)) |
| 450 | goto nla_put_failure; |
| 451 | } |
Jamal Hadi Salim | 48d8ee1 | 2016-06-06 06:32:55 -0400 | [diff] [blame] | 452 | |
| 453 | tcf_tm_dump(&t, &p->tcf_tm); |
Nicolas Dichtel | 9854518e | 2016-04-26 10:06:18 +0200 | [diff] [blame] | 454 | if (nla_put_64bit(skb, TCA_PEDIT_TM, sizeof(t), &t, TCA_PEDIT_PAD)) |
David S. Miller | 1b34ec4 | 2012-03-29 05:11:39 -0400 | [diff] [blame] | 455 | goto nla_put_failure; |
Vlad Buslov | 67b0c1a | 2018-08-10 20:51:46 +0300 | [diff] [blame] | 456 | spin_unlock_bh(&p->tcf_lock); |
Jamal Hadi Salim | 48d8ee1 | 2016-06-06 06:32:55 -0400 | [diff] [blame] | 457 | |
Patrick McHardy | 541673c8 | 2006-01-08 22:17:27 -0800 | [diff] [blame] | 458 | kfree(opt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | return skb->len; |
| 460 | |
Patrick McHardy | 7ba699c | 2008-01-22 22:11:50 -0800 | [diff] [blame] | 461 | nla_put_failure: |
Vlad Buslov | 67b0c1a | 2018-08-10 20:51:46 +0300 | [diff] [blame] | 462 | spin_unlock_bh(&p->tcf_lock); |
Arnaldo Carvalho de Melo | dc5fc57 | 2007-03-25 23:06:12 -0700 | [diff] [blame] | 463 | nlmsg_trim(skb, b); |
Patrick McHardy | 541673c8 | 2006-01-08 22:17:27 -0800 | [diff] [blame] | 464 | kfree(opt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | return -1; |
| 466 | } |
| 467 | |
WANG Cong | ddf97cc | 2016-02-22 15:57:53 -0800 | [diff] [blame] | 468 | static int tcf_pedit_walker(struct net *net, struct sk_buff *skb, |
| 469 | struct netlink_callback *cb, int type, |
Alexander Aring | 4178010 | 2018-02-15 10:54:58 -0500 | [diff] [blame] | 470 | const struct tc_action_ops *ops, |
| 471 | struct netlink_ext_ack *extack) |
WANG Cong | ddf97cc | 2016-02-22 15:57:53 -0800 | [diff] [blame] | 472 | { |
| 473 | struct tc_action_net *tn = net_generic(net, pedit_net_id); |
| 474 | |
Alexander Aring | b362014 | 2018-02-15 10:54:59 -0500 | [diff] [blame] | 475 | return tcf_generic_walker(tn, skb, cb, type, ops, extack); |
WANG Cong | ddf97cc | 2016-02-22 15:57:53 -0800 | [diff] [blame] | 476 | } |
| 477 | |
Cong Wang | f061b48 | 2018-08-29 10:15:35 -0700 | [diff] [blame] | 478 | static int tcf_pedit_search(struct net *net, struct tc_action **a, u32 index) |
WANG Cong | ddf97cc | 2016-02-22 15:57:53 -0800 | [diff] [blame] | 479 | { |
| 480 | struct tc_action_net *tn = net_generic(net, pedit_net_id); |
| 481 | |
Chris Mi | 65a206c | 2017-08-30 02:31:59 -0400 | [diff] [blame] | 482 | return tcf_idr_search(tn, a, index); |
WANG Cong | ddf97cc | 2016-02-22 15:57:53 -0800 | [diff] [blame] | 483 | } |
| 484 | |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 485 | static struct tc_action_ops act_pedit_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | .kind = "pedit", |
Eli Cohen | eddd2cf | 2019-02-10 14:25:00 +0200 | [diff] [blame] | 487 | .id = TCA_ID_PEDIT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | .owner = THIS_MODULE, |
Jamal Hadi Salim | 6a2b401 | 2018-08-12 09:34:55 -0400 | [diff] [blame] | 489 | .act = tcf_pedit_act, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | .dump = tcf_pedit_dump, |
| 491 | .cleanup = tcf_pedit_cleanup, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | .init = tcf_pedit_init, |
WANG Cong | ddf97cc | 2016-02-22 15:57:53 -0800 | [diff] [blame] | 493 | .walk = tcf_pedit_walker, |
| 494 | .lookup = tcf_pedit_search, |
WANG Cong | a85a970 | 2016-07-25 16:09:41 -0700 | [diff] [blame] | 495 | .size = sizeof(struct tcf_pedit), |
WANG Cong | ddf97cc | 2016-02-22 15:57:53 -0800 | [diff] [blame] | 496 | }; |
| 497 | |
| 498 | static __net_init int pedit_init_net(struct net *net) |
| 499 | { |
| 500 | struct tc_action_net *tn = net_generic(net, pedit_net_id); |
| 501 | |
Cong Wang | 981471b | 2019-08-25 10:01:32 -0700 | [diff] [blame] | 502 | return tc_action_net_init(net, tn, &act_pedit_ops); |
WANG Cong | ddf97cc | 2016-02-22 15:57:53 -0800 | [diff] [blame] | 503 | } |
| 504 | |
Cong Wang | 039af9c | 2017-12-11 15:35:03 -0800 | [diff] [blame] | 505 | static void __net_exit pedit_exit_net(struct list_head *net_list) |
WANG Cong | ddf97cc | 2016-02-22 15:57:53 -0800 | [diff] [blame] | 506 | { |
Cong Wang | 039af9c | 2017-12-11 15:35:03 -0800 | [diff] [blame] | 507 | tc_action_net_exit(net_list, pedit_net_id); |
WANG Cong | ddf97cc | 2016-02-22 15:57:53 -0800 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | static struct pernet_operations pedit_net_ops = { |
| 511 | .init = pedit_init_net, |
Cong Wang | 039af9c | 2017-12-11 15:35:03 -0800 | [diff] [blame] | 512 | .exit_batch = pedit_exit_net, |
WANG Cong | ddf97cc | 2016-02-22 15:57:53 -0800 | [diff] [blame] | 513 | .id = &pedit_net_id, |
| 514 | .size = sizeof(struct tc_action_net), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | }; |
| 516 | |
| 517 | MODULE_AUTHOR("Jamal Hadi Salim(2002-4)"); |
| 518 | MODULE_DESCRIPTION("Generic Packet Editor actions"); |
| 519 | MODULE_LICENSE("GPL"); |
| 520 | |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 521 | static int __init pedit_init_module(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | { |
WANG Cong | ddf97cc | 2016-02-22 15:57:53 -0800 | [diff] [blame] | 523 | return tcf_register_action(&act_pedit_ops, &pedit_net_ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | } |
| 525 | |
David S. Miller | e9ce1cd | 2006-08-21 23:54:55 -0700 | [diff] [blame] | 526 | static void __exit pedit_cleanup_module(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | { |
WANG Cong | ddf97cc | 2016-02-22 15:57:53 -0800 | [diff] [blame] | 528 | tcf_unregister_action(&act_pedit_ops, &pedit_net_ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | module_init(pedit_init_module); |
| 532 | module_exit(pedit_cleanup_module); |