19952f691SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only 2ca9b0e27SAlexander Duyck /* 3ca9b0e27SAlexander Duyck * Copyright (c) 2008, Intel Corporation. 4ca9b0e27SAlexander Duyck * 5ca9b0e27SAlexander Duyck * Author: Alexander Duyck <alexander.h.duyck@intel.com> 6ca9b0e27SAlexander Duyck */ 7ca9b0e27SAlexander Duyck 8ca9b0e27SAlexander Duyck #include <linux/module.h> 9ca9b0e27SAlexander Duyck #include <linux/init.h> 10ca9b0e27SAlexander Duyck #include <linux/kernel.h> 11ca9b0e27SAlexander Duyck #include <linux/skbuff.h> 12ca9b0e27SAlexander Duyck #include <linux/rtnetlink.h> 13ca9b0e27SAlexander Duyck #include <net/netlink.h> 14ca9b0e27SAlexander Duyck #include <net/pkt_sched.h> 15e7e3728bSQiaobin Fu #include <net/ip.h> 16e7e3728bSQiaobin Fu #include <net/ipv6.h> 17e7e3728bSQiaobin Fu #include <net/dsfield.h> 18ec7727bbSDavide Caratti #include <net/pkt_cls.h> 19ca9b0e27SAlexander Duyck 20ca9b0e27SAlexander Duyck #include <linux/tc_act/tc_skbedit.h> 21ca9b0e27SAlexander Duyck #include <net/tc_act/tc_skbedit.h> 22ca9b0e27SAlexander Duyck 23c7d03a00SAlexey Dobriyan static unsigned int skbedit_net_id; 24a85a970aSWANG Cong static struct tc_action_ops act_skbedit_ops; 25ddf97ccdSWANG Cong 2645da1dacSJamal Hadi Salim static int tcf_skbedit_act(struct sk_buff *skb, const struct tc_action *a, 27ca9b0e27SAlexander Duyck struct tcf_result *res) 28ca9b0e27SAlexander Duyck { 29a85a970aSWANG Cong struct tcf_skbedit *d = to_skbedit(a); 30c749cddaSDavide Caratti struct tcf_skbedit_params *params; 31c749cddaSDavide Caratti int action; 32ca9b0e27SAlexander Duyck 339c4a4e48SJamal Hadi Salim tcf_lastuse_update(&d->tcf_tm); 346f3dfb0dSDavide Caratti bstats_cpu_update(this_cpu_ptr(d->common.cpu_bstats), skb); 35ca9b0e27SAlexander Duyck 367fd4b288SPaolo Abeni params = rcu_dereference_bh(d->params); 37c749cddaSDavide Caratti action = READ_ONCE(d->tcf_action); 38c749cddaSDavide Caratti 39c749cddaSDavide Caratti if (params->flags & SKBEDIT_F_PRIORITY) 40c749cddaSDavide Caratti skb->priority = params->priority; 41c749cddaSDavide Caratti if (params->flags & SKBEDIT_F_INHERITDSFIELD) { 42e7e3728bSQiaobin Fu int wlen = skb_network_offset(skb); 43e7e3728bSQiaobin Fu 44d7bf2ebeSToke Høiland-Jørgensen switch (skb_protocol(skb, true)) { 45e7e3728bSQiaobin Fu case htons(ETH_P_IP): 46e7e3728bSQiaobin Fu wlen += sizeof(struct iphdr); 47e7e3728bSQiaobin Fu if (!pskb_may_pull(skb, wlen)) 48e7e3728bSQiaobin Fu goto err; 49e7e3728bSQiaobin Fu skb->priority = ipv4_get_dsfield(ip_hdr(skb)) >> 2; 50e7e3728bSQiaobin Fu break; 51e7e3728bSQiaobin Fu 52e7e3728bSQiaobin Fu case htons(ETH_P_IPV6): 53e7e3728bSQiaobin Fu wlen += sizeof(struct ipv6hdr); 54e7e3728bSQiaobin Fu if (!pskb_may_pull(skb, wlen)) 55e7e3728bSQiaobin Fu goto err; 56e7e3728bSQiaobin Fu skb->priority = ipv6_get_dsfield(ipv6_hdr(skb)) >> 2; 57e7e3728bSQiaobin Fu break; 58e7e3728bSQiaobin Fu } 59e7e3728bSQiaobin Fu } 60c749cddaSDavide Caratti if (params->flags & SKBEDIT_F_QUEUE_MAPPING && 61c749cddaSDavide Caratti skb->dev->real_num_tx_queues > params->queue_mapping) 62c749cddaSDavide Caratti skb_set_queue_mapping(skb, params->queue_mapping); 63c749cddaSDavide Caratti if (params->flags & SKBEDIT_F_MARK) { 64c749cddaSDavide Caratti skb->mark &= ~params->mask; 65c749cddaSDavide Caratti skb->mark |= params->mark & params->mask; 664fe77d82SAntonio Quartulli } 67c749cddaSDavide Caratti if (params->flags & SKBEDIT_F_PTYPE) 68c749cddaSDavide Caratti skb->pkt_type = params->ptype; 69c749cddaSDavide Caratti return action; 707fd4b288SPaolo Abeni 71e7e3728bSQiaobin Fu err: 726f3dfb0dSDavide Caratti qstats_drop_inc(this_cpu_ptr(d->common.cpu_qstats)); 737fd4b288SPaolo Abeni return TC_ACT_SHOT; 74ca9b0e27SAlexander Duyck } 75ca9b0e27SAlexander Duyck 76837cb17dSPetr Machata static void tcf_skbedit_stats_update(struct tc_action *a, u64 bytes, 774b61d3e8SPo Liu u64 packets, u64 drops, 784b61d3e8SPo Liu u64 lastuse, bool hw) 79837cb17dSPetr Machata { 80837cb17dSPetr Machata struct tcf_skbedit *d = to_skbedit(a); 81837cb17dSPetr Machata struct tcf_t *tm = &d->tcf_tm; 82837cb17dSPetr Machata 834b61d3e8SPo Liu tcf_action_update_stats(a, bytes, packets, drops, hw); 84837cb17dSPetr Machata tm->lastuse = max_t(u64, tm->lastuse, lastuse); 85837cb17dSPetr Machata } 86837cb17dSPetr Machata 87ca9b0e27SAlexander Duyck static const struct nla_policy skbedit_policy[TCA_SKBEDIT_MAX + 1] = { 88ca9b0e27SAlexander Duyck [TCA_SKBEDIT_PARMS] = { .len = sizeof(struct tc_skbedit) }, 89ca9b0e27SAlexander Duyck [TCA_SKBEDIT_PRIORITY] = { .len = sizeof(u32) }, 90ca9b0e27SAlexander Duyck [TCA_SKBEDIT_QUEUE_MAPPING] = { .len = sizeof(u16) }, 911c55d62eSjamal [TCA_SKBEDIT_MARK] = { .len = sizeof(u32) }, 92ff202ee1SJamal Hadi Salim [TCA_SKBEDIT_PTYPE] = { .len = sizeof(u16) }, 934fe77d82SAntonio Quartulli [TCA_SKBEDIT_MASK] = { .len = sizeof(u32) }, 94e7e3728bSQiaobin Fu [TCA_SKBEDIT_FLAGS] = { .len = sizeof(u64) }, 95ca9b0e27SAlexander Duyck }; 96ca9b0e27SAlexander Duyck 97c1b52739SBenjamin LaHaise static int tcf_skbedit_init(struct net *net, struct nlattr *nla, 98a85a970aSWANG Cong struct nlattr *est, struct tc_action **a, 99abbb0d33SVlad Buslov struct tcf_proto *tp, u32 act_flags, 100789871bbSVlad Buslov struct netlink_ext_ack *extack) 101ca9b0e27SAlexander Duyck { 102ddf97ccdSWANG Cong struct tc_action_net *tn = net_generic(net, skbedit_net_id); 103*695176bfSCong Wang bool bind = act_flags & TCA_ACT_FLAGS_BIND; 1046d7a8df6SVlad Buslov struct tcf_skbedit_params *params_new; 105ca9b0e27SAlexander Duyck struct nlattr *tb[TCA_SKBEDIT_MAX + 1]; 106ec7727bbSDavide Caratti struct tcf_chain *goto_ch = NULL; 107ca9b0e27SAlexander Duyck struct tc_skbedit *parm; 108ca9b0e27SAlexander Duyck struct tcf_skbedit *d; 1094fe77d82SAntonio Quartulli u32 flags = 0, *priority = NULL, *mark = NULL, *mask = NULL; 110ff202ee1SJamal Hadi Salim u16 *queue_mapping = NULL, *ptype = NULL; 111b2313077SWANG Cong bool exists = false; 112b2313077SWANG Cong int ret = 0, err; 1137be8ef2cSDmytro Linkin u32 index; 114ca9b0e27SAlexander Duyck 115ca9b0e27SAlexander Duyck if (nla == NULL) 116ca9b0e27SAlexander Duyck return -EINVAL; 117ca9b0e27SAlexander Duyck 1188cb08174SJohannes Berg err = nla_parse_nested_deprecated(tb, TCA_SKBEDIT_MAX, nla, 1198cb08174SJohannes Berg skbedit_policy, NULL); 120ca9b0e27SAlexander Duyck if (err < 0) 121ca9b0e27SAlexander Duyck return err; 122ca9b0e27SAlexander Duyck 123ca9b0e27SAlexander Duyck if (tb[TCA_SKBEDIT_PARMS] == NULL) 124ca9b0e27SAlexander Duyck return -EINVAL; 125ca9b0e27SAlexander Duyck 126ca9b0e27SAlexander Duyck if (tb[TCA_SKBEDIT_PRIORITY] != NULL) { 127ca9b0e27SAlexander Duyck flags |= SKBEDIT_F_PRIORITY; 128ca9b0e27SAlexander Duyck priority = nla_data(tb[TCA_SKBEDIT_PRIORITY]); 129ca9b0e27SAlexander Duyck } 130ca9b0e27SAlexander Duyck 131ca9b0e27SAlexander Duyck if (tb[TCA_SKBEDIT_QUEUE_MAPPING] != NULL) { 132ca9b0e27SAlexander Duyck flags |= SKBEDIT_F_QUEUE_MAPPING; 133ca9b0e27SAlexander Duyck queue_mapping = nla_data(tb[TCA_SKBEDIT_QUEUE_MAPPING]); 134ca9b0e27SAlexander Duyck } 1351c55d62eSjamal 136ff202ee1SJamal Hadi Salim if (tb[TCA_SKBEDIT_PTYPE] != NULL) { 137ff202ee1SJamal Hadi Salim ptype = nla_data(tb[TCA_SKBEDIT_PTYPE]); 138ff202ee1SJamal Hadi Salim if (!skb_pkt_type_ok(*ptype)) 139ff202ee1SJamal Hadi Salim return -EINVAL; 140ff202ee1SJamal Hadi Salim flags |= SKBEDIT_F_PTYPE; 141ff202ee1SJamal Hadi Salim } 142ff202ee1SJamal Hadi Salim 1431c55d62eSjamal if (tb[TCA_SKBEDIT_MARK] != NULL) { 1441c55d62eSjamal flags |= SKBEDIT_F_MARK; 1451c55d62eSjamal mark = nla_data(tb[TCA_SKBEDIT_MARK]); 1461c55d62eSjamal } 1471c55d62eSjamal 1484fe77d82SAntonio Quartulli if (tb[TCA_SKBEDIT_MASK] != NULL) { 1494fe77d82SAntonio Quartulli flags |= SKBEDIT_F_MASK; 1504fe77d82SAntonio Quartulli mask = nla_data(tb[TCA_SKBEDIT_MASK]); 1514fe77d82SAntonio Quartulli } 1524fe77d82SAntonio Quartulli 153e7e3728bSQiaobin Fu if (tb[TCA_SKBEDIT_FLAGS] != NULL) { 154e7e3728bSQiaobin Fu u64 *pure_flags = nla_data(tb[TCA_SKBEDIT_FLAGS]); 155e7e3728bSQiaobin Fu 156e7e3728bSQiaobin Fu if (*pure_flags & SKBEDIT_F_INHERITDSFIELD) 157e7e3728bSQiaobin Fu flags |= SKBEDIT_F_INHERITDSFIELD; 158e7e3728bSQiaobin Fu } 159e7e3728bSQiaobin Fu 160ca9b0e27SAlexander Duyck parm = nla_data(tb[TCA_SKBEDIT_PARMS]); 1617be8ef2cSDmytro Linkin index = parm->index; 1627be8ef2cSDmytro Linkin err = tcf_idr_check_alloc(tn, &index, a, bind); 1630190c1d4SVlad Buslov if (err < 0) 1640190c1d4SVlad Buslov return err; 1650190c1d4SVlad Buslov exists = err; 1665e1567aeSJamal Hadi Salim if (exists && bind) 1675e1567aeSJamal Hadi Salim return 0; 1685e1567aeSJamal Hadi Salim 1695e1567aeSJamal Hadi Salim if (!flags) { 170af5d0184SRoman Mashak if (exists) 17165a206c0SChris Mi tcf_idr_release(*a, bind); 1720190c1d4SVlad Buslov else 1737be8ef2cSDmytro Linkin tcf_idr_cleanup(tn, index); 1745e1567aeSJamal Hadi Salim return -EINVAL; 1755e1567aeSJamal Hadi Salim } 1765e1567aeSJamal Hadi Salim 1775e1567aeSJamal Hadi Salim if (!exists) { 1787be8ef2cSDmytro Linkin ret = tcf_idr_create(tn, index, est, a, 179e3822678SVlad Buslov &act_skbedit_ops, bind, true, 0); 1800190c1d4SVlad Buslov if (ret) { 1817be8ef2cSDmytro Linkin tcf_idr_cleanup(tn, index); 18286062033SWANG Cong return ret; 1830190c1d4SVlad Buslov } 184ca9b0e27SAlexander Duyck 185a85a970aSWANG Cong d = to_skbedit(*a); 186ca9b0e27SAlexander Duyck ret = ACT_P_CREATED; 187ca9b0e27SAlexander Duyck } else { 188a85a970aSWANG Cong d = to_skbedit(*a); 189*695176bfSCong Wang if (!(act_flags & TCA_ACT_FLAGS_REPLACE)) { 19065a206c0SChris Mi tcf_idr_release(*a, bind); 191ca9b0e27SAlexander Duyck return -EEXIST; 192ca9b0e27SAlexander Duyck } 1934e8ddd7fSVlad Buslov } 194ec7727bbSDavide Caratti err = tcf_action_check_ctrlact(parm->action, tp, &goto_ch, extack); 195ec7727bbSDavide Caratti if (err < 0) 196ec7727bbSDavide Caratti goto release_idr; 197ca9b0e27SAlexander Duyck 198c749cddaSDavide Caratti params_new = kzalloc(sizeof(*params_new), GFP_KERNEL); 199c749cddaSDavide Caratti if (unlikely(!params_new)) { 200ec7727bbSDavide Caratti err = -ENOMEM; 201ec7727bbSDavide Caratti goto put_chain; 202c749cddaSDavide Caratti } 203c749cddaSDavide Caratti 204c749cddaSDavide Caratti params_new->flags = flags; 205ca9b0e27SAlexander Duyck if (flags & SKBEDIT_F_PRIORITY) 206c749cddaSDavide Caratti params_new->priority = *priority; 207ca9b0e27SAlexander Duyck if (flags & SKBEDIT_F_QUEUE_MAPPING) 208c749cddaSDavide Caratti params_new->queue_mapping = *queue_mapping; 2091c55d62eSjamal if (flags & SKBEDIT_F_MARK) 210c749cddaSDavide Caratti params_new->mark = *mark; 211ff202ee1SJamal Hadi Salim if (flags & SKBEDIT_F_PTYPE) 212c749cddaSDavide Caratti params_new->ptype = *ptype; 2134fe77d82SAntonio Quartulli /* default behaviour is to use all the bits */ 214c749cddaSDavide Caratti params_new->mask = 0xffffffff; 2154fe77d82SAntonio Quartulli if (flags & SKBEDIT_F_MASK) 216c749cddaSDavide Caratti params_new->mask = *mask; 2171c55d62eSjamal 2186d7a8df6SVlad Buslov spin_lock_bh(&d->tcf_lock); 219ec7727bbSDavide Caratti goto_ch = tcf_action_set_ctrlact(*a, parm->action, goto_ch); 220445d3749SPaul E. McKenney params_new = rcu_replace_pointer(d->params, params_new, 2216d7a8df6SVlad Buslov lockdep_is_held(&d->tcf_lock)); 2226d7a8df6SVlad Buslov spin_unlock_bh(&d->tcf_lock); 2236d7a8df6SVlad Buslov if (params_new) 2246d7a8df6SVlad Buslov kfree_rcu(params_new, rcu); 225ec7727bbSDavide Caratti if (goto_ch) 226ec7727bbSDavide Caratti tcf_chain_put_by_act(goto_ch); 227ca9b0e27SAlexander Duyck 228ca9b0e27SAlexander Duyck return ret; 229ec7727bbSDavide Caratti put_chain: 230ec7727bbSDavide Caratti if (goto_ch) 231ec7727bbSDavide Caratti tcf_chain_put_by_act(goto_ch); 232ec7727bbSDavide Caratti release_idr: 233ec7727bbSDavide Caratti tcf_idr_release(*a, bind); 234ec7727bbSDavide Caratti return err; 235ca9b0e27SAlexander Duyck } 236ca9b0e27SAlexander Duyck 237cc7ec456SEric Dumazet static int tcf_skbedit_dump(struct sk_buff *skb, struct tc_action *a, 238ca9b0e27SAlexander Duyck int bind, int ref) 239ca9b0e27SAlexander Duyck { 240ca9b0e27SAlexander Duyck unsigned char *b = skb_tail_pointer(skb); 241a85a970aSWANG Cong struct tcf_skbedit *d = to_skbedit(a); 242c749cddaSDavide Caratti struct tcf_skbedit_params *params; 2431c40be12SEric Dumazet struct tc_skbedit opt = { 2441c40be12SEric Dumazet .index = d->tcf_index, 245036bb443SVlad Buslov .refcnt = refcount_read(&d->tcf_refcnt) - ref, 246036bb443SVlad Buslov .bindcnt = atomic_read(&d->tcf_bindcnt) - bind, 2471c40be12SEric Dumazet }; 248e7e3728bSQiaobin Fu u64 pure_flags = 0; 249c749cddaSDavide Caratti struct tcf_t t; 250c749cddaSDavide Caratti 2516d7a8df6SVlad Buslov spin_lock_bh(&d->tcf_lock); 2526d7a8df6SVlad Buslov params = rcu_dereference_protected(d->params, 2536d7a8df6SVlad Buslov lockdep_is_held(&d->tcf_lock)); 2546d7a8df6SVlad Buslov opt.action = d->tcf_action; 255ca9b0e27SAlexander Duyck 2561b34ec43SDavid S. Miller if (nla_put(skb, TCA_SKBEDIT_PARMS, sizeof(opt), &opt)) 2571b34ec43SDavid S. Miller goto nla_put_failure; 258c749cddaSDavide Caratti if ((params->flags & SKBEDIT_F_PRIORITY) && 259c749cddaSDavide Caratti nla_put_u32(skb, TCA_SKBEDIT_PRIORITY, params->priority)) 2601b34ec43SDavid S. Miller goto nla_put_failure; 261c749cddaSDavide Caratti if ((params->flags & SKBEDIT_F_QUEUE_MAPPING) && 262c749cddaSDavide Caratti nla_put_u16(skb, TCA_SKBEDIT_QUEUE_MAPPING, params->queue_mapping)) 2631b34ec43SDavid S. Miller goto nla_put_failure; 264c749cddaSDavide Caratti if ((params->flags & SKBEDIT_F_MARK) && 265c749cddaSDavide Caratti nla_put_u32(skb, TCA_SKBEDIT_MARK, params->mark)) 2661b34ec43SDavid S. Miller goto nla_put_failure; 267c749cddaSDavide Caratti if ((params->flags & SKBEDIT_F_PTYPE) && 268c749cddaSDavide Caratti nla_put_u16(skb, TCA_SKBEDIT_PTYPE, params->ptype)) 269ff202ee1SJamal Hadi Salim goto nla_put_failure; 270c749cddaSDavide Caratti if ((params->flags & SKBEDIT_F_MASK) && 271c749cddaSDavide Caratti nla_put_u32(skb, TCA_SKBEDIT_MASK, params->mask)) 2724fe77d82SAntonio Quartulli goto nla_put_failure; 273c749cddaSDavide Caratti if (params->flags & SKBEDIT_F_INHERITDSFIELD) 274e7e3728bSQiaobin Fu pure_flags |= SKBEDIT_F_INHERITDSFIELD; 275e7e3728bSQiaobin Fu if (pure_flags != 0 && 276e7e3728bSQiaobin Fu nla_put(skb, TCA_SKBEDIT_FLAGS, sizeof(pure_flags), &pure_flags)) 277e7e3728bSQiaobin Fu goto nla_put_failure; 27848d8ee16SJamal Hadi Salim 27948d8ee16SJamal Hadi Salim tcf_tm_dump(&t, &d->tcf_tm); 2809854518eSNicolas Dichtel if (nla_put_64bit(skb, TCA_SKBEDIT_TM, sizeof(t), &t, TCA_SKBEDIT_PAD)) 2811b34ec43SDavid S. Miller goto nla_put_failure; 2826d7a8df6SVlad Buslov spin_unlock_bh(&d->tcf_lock); 2836d7a8df6SVlad Buslov 284ca9b0e27SAlexander Duyck return skb->len; 285ca9b0e27SAlexander Duyck 286ca9b0e27SAlexander Duyck nla_put_failure: 2876d7a8df6SVlad Buslov spin_unlock_bh(&d->tcf_lock); 288ca9b0e27SAlexander Duyck nlmsg_trim(skb, b); 289ca9b0e27SAlexander Duyck return -1; 290ca9b0e27SAlexander Duyck } 291ca9b0e27SAlexander Duyck 292c749cddaSDavide Caratti static void tcf_skbedit_cleanup(struct tc_action *a) 293c749cddaSDavide Caratti { 294c749cddaSDavide Caratti struct tcf_skbedit *d = to_skbedit(a); 295c749cddaSDavide Caratti struct tcf_skbedit_params *params; 296c749cddaSDavide Caratti 297c749cddaSDavide Caratti params = rcu_dereference_protected(d->params, 1); 298c749cddaSDavide Caratti if (params) 299c749cddaSDavide Caratti kfree_rcu(params, rcu); 300c749cddaSDavide Caratti } 301c749cddaSDavide Caratti 302ddf97ccdSWANG Cong static int tcf_skbedit_walker(struct net *net, struct sk_buff *skb, 303ddf97ccdSWANG Cong struct netlink_callback *cb, int type, 30441780105SAlexander Aring const struct tc_action_ops *ops, 30541780105SAlexander Aring struct netlink_ext_ack *extack) 306ddf97ccdSWANG Cong { 307ddf97ccdSWANG Cong struct tc_action_net *tn = net_generic(net, skbedit_net_id); 308ddf97ccdSWANG Cong 309b3620145SAlexander Aring return tcf_generic_walker(tn, skb, cb, type, ops, extack); 310ddf97ccdSWANG Cong } 311ddf97ccdSWANG Cong 312f061b48cSCong Wang static int tcf_skbedit_search(struct net *net, struct tc_action **a, u32 index) 313ddf97ccdSWANG Cong { 314ddf97ccdSWANG Cong struct tc_action_net *tn = net_generic(net, skbedit_net_id); 315ddf97ccdSWANG Cong 31665a206c0SChris Mi return tcf_idr_search(tn, a, index); 317ddf97ccdSWANG Cong } 318ddf97ccdSWANG Cong 319e1fea322SRoman Mashak static size_t tcf_skbedit_get_fill_size(const struct tc_action *act) 320e1fea322SRoman Mashak { 321e1fea322SRoman Mashak return nla_total_size(sizeof(struct tc_skbedit)) 322e1fea322SRoman Mashak + nla_total_size(sizeof(u32)) /* TCA_SKBEDIT_PRIORITY */ 323e1fea322SRoman Mashak + nla_total_size(sizeof(u16)) /* TCA_SKBEDIT_QUEUE_MAPPING */ 324e1fea322SRoman Mashak + nla_total_size(sizeof(u32)) /* TCA_SKBEDIT_MARK */ 325e1fea322SRoman Mashak + nla_total_size(sizeof(u16)) /* TCA_SKBEDIT_PTYPE */ 326e1fea322SRoman Mashak + nla_total_size(sizeof(u32)) /* TCA_SKBEDIT_MASK */ 327e1fea322SRoman Mashak + nla_total_size_64bit(sizeof(u64)); /* TCA_SKBEDIT_FLAGS */ 328e1fea322SRoman Mashak } 329e1fea322SRoman Mashak 330ca9b0e27SAlexander Duyck static struct tc_action_ops act_skbedit_ops = { 331ca9b0e27SAlexander Duyck .kind = "skbedit", 332eddd2cf1SEli Cohen .id = TCA_ID_SKBEDIT, 333ca9b0e27SAlexander Duyck .owner = THIS_MODULE, 33445da1dacSJamal Hadi Salim .act = tcf_skbedit_act, 335837cb17dSPetr Machata .stats_update = tcf_skbedit_stats_update, 336ca9b0e27SAlexander Duyck .dump = tcf_skbedit_dump, 337ca9b0e27SAlexander Duyck .init = tcf_skbedit_init, 338c749cddaSDavide Caratti .cleanup = tcf_skbedit_cleanup, 339ddf97ccdSWANG Cong .walk = tcf_skbedit_walker, 340e1fea322SRoman Mashak .get_fill_size = tcf_skbedit_get_fill_size, 341ddf97ccdSWANG Cong .lookup = tcf_skbedit_search, 342a85a970aSWANG Cong .size = sizeof(struct tcf_skbedit), 343ddf97ccdSWANG Cong }; 344ddf97ccdSWANG Cong 345ddf97ccdSWANG Cong static __net_init int skbedit_init_net(struct net *net) 346ddf97ccdSWANG Cong { 347ddf97ccdSWANG Cong struct tc_action_net *tn = net_generic(net, skbedit_net_id); 348ddf97ccdSWANG Cong 349981471bdSCong Wang return tc_action_net_init(net, tn, &act_skbedit_ops); 350ddf97ccdSWANG Cong } 351ddf97ccdSWANG Cong 352039af9c6SCong Wang static void __net_exit skbedit_exit_net(struct list_head *net_list) 353ddf97ccdSWANG Cong { 354039af9c6SCong Wang tc_action_net_exit(net_list, skbedit_net_id); 355ddf97ccdSWANG Cong } 356ddf97ccdSWANG Cong 357ddf97ccdSWANG Cong static struct pernet_operations skbedit_net_ops = { 358ddf97ccdSWANG Cong .init = skbedit_init_net, 359039af9c6SCong Wang .exit_batch = skbedit_exit_net, 360ddf97ccdSWANG Cong .id = &skbedit_net_id, 361ddf97ccdSWANG Cong .size = sizeof(struct tc_action_net), 362ca9b0e27SAlexander Duyck }; 363ca9b0e27SAlexander Duyck 364ca9b0e27SAlexander Duyck MODULE_AUTHOR("Alexander Duyck, <alexander.h.duyck@intel.com>"); 365ca9b0e27SAlexander Duyck MODULE_DESCRIPTION("SKB Editing"); 366ca9b0e27SAlexander Duyck MODULE_LICENSE("GPL"); 367ca9b0e27SAlexander Duyck 368ca9b0e27SAlexander Duyck static int __init skbedit_init_module(void) 369ca9b0e27SAlexander Duyck { 370ddf97ccdSWANG Cong return tcf_register_action(&act_skbedit_ops, &skbedit_net_ops); 371ca9b0e27SAlexander Duyck } 372ca9b0e27SAlexander Duyck 373ca9b0e27SAlexander Duyck static void __exit skbedit_cleanup_module(void) 374ca9b0e27SAlexander Duyck { 375ddf97ccdSWANG Cong tcf_unregister_action(&act_skbedit_ops, &skbedit_net_ops); 376ca9b0e27SAlexander Duyck } 377ca9b0e27SAlexander Duyck 378ca9b0e27SAlexander Duyck module_init(skbedit_init_module); 379ca9b0e27SAlexander Duyck module_exit(skbedit_cleanup_module); 380