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 44e7e3728bSQiaobin Fu switch (tc_skb_protocol(skb)) { 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 76*837cb17dSPetr Machata static void tcf_skbedit_stats_update(struct tc_action *a, u64 bytes, 77*837cb17dSPetr Machata u32 packets, u64 lastuse, bool hw) 78*837cb17dSPetr Machata { 79*837cb17dSPetr Machata struct tcf_skbedit *d = to_skbedit(a); 80*837cb17dSPetr Machata struct tcf_t *tm = &d->tcf_tm; 81*837cb17dSPetr Machata 82*837cb17dSPetr Machata tcf_action_update_stats(a, bytes, packets, false, hw); 83*837cb17dSPetr Machata tm->lastuse = max_t(u64, tm->lastuse, lastuse); 84*837cb17dSPetr Machata } 85*837cb17dSPetr Machata 86ca9b0e27SAlexander Duyck static const struct nla_policy skbedit_policy[TCA_SKBEDIT_MAX + 1] = { 87ca9b0e27SAlexander Duyck [TCA_SKBEDIT_PARMS] = { .len = sizeof(struct tc_skbedit) }, 88ca9b0e27SAlexander Duyck [TCA_SKBEDIT_PRIORITY] = { .len = sizeof(u32) }, 89ca9b0e27SAlexander Duyck [TCA_SKBEDIT_QUEUE_MAPPING] = { .len = sizeof(u16) }, 901c55d62eSjamal [TCA_SKBEDIT_MARK] = { .len = sizeof(u32) }, 91ff202ee1SJamal Hadi Salim [TCA_SKBEDIT_PTYPE] = { .len = sizeof(u16) }, 924fe77d82SAntonio Quartulli [TCA_SKBEDIT_MASK] = { .len = sizeof(u32) }, 93e7e3728bSQiaobin Fu [TCA_SKBEDIT_FLAGS] = { .len = sizeof(u64) }, 94ca9b0e27SAlexander Duyck }; 95ca9b0e27SAlexander Duyck 96c1b52739SBenjamin LaHaise static int tcf_skbedit_init(struct net *net, struct nlattr *nla, 97a85a970aSWANG Cong struct nlattr *est, struct tc_action **a, 98789871bbSVlad Buslov int ovr, int bind, bool rtnl_held, 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); 1036d7a8df6SVlad Buslov struct tcf_skbedit_params *params_new; 104ca9b0e27SAlexander Duyck struct nlattr *tb[TCA_SKBEDIT_MAX + 1]; 105ec7727bbSDavide Caratti struct tcf_chain *goto_ch = NULL; 106ca9b0e27SAlexander Duyck struct tc_skbedit *parm; 107ca9b0e27SAlexander Duyck struct tcf_skbedit *d; 1084fe77d82SAntonio Quartulli u32 flags = 0, *priority = NULL, *mark = NULL, *mask = NULL; 109ff202ee1SJamal Hadi Salim u16 *queue_mapping = NULL, *ptype = NULL; 110b2313077SWANG Cong bool exists = false; 111b2313077SWANG Cong int ret = 0, err; 1127be8ef2cSDmytro Linkin u32 index; 113ca9b0e27SAlexander Duyck 114ca9b0e27SAlexander Duyck if (nla == NULL) 115ca9b0e27SAlexander Duyck return -EINVAL; 116ca9b0e27SAlexander Duyck 1178cb08174SJohannes Berg err = nla_parse_nested_deprecated(tb, TCA_SKBEDIT_MAX, nla, 1188cb08174SJohannes Berg skbedit_policy, NULL); 119ca9b0e27SAlexander Duyck if (err < 0) 120ca9b0e27SAlexander Duyck return err; 121ca9b0e27SAlexander Duyck 122ca9b0e27SAlexander Duyck if (tb[TCA_SKBEDIT_PARMS] == NULL) 123ca9b0e27SAlexander Duyck return -EINVAL; 124ca9b0e27SAlexander Duyck 125ca9b0e27SAlexander Duyck if (tb[TCA_SKBEDIT_PRIORITY] != NULL) { 126ca9b0e27SAlexander Duyck flags |= SKBEDIT_F_PRIORITY; 127ca9b0e27SAlexander Duyck priority = nla_data(tb[TCA_SKBEDIT_PRIORITY]); 128ca9b0e27SAlexander Duyck } 129ca9b0e27SAlexander Duyck 130ca9b0e27SAlexander Duyck if (tb[TCA_SKBEDIT_QUEUE_MAPPING] != NULL) { 131ca9b0e27SAlexander Duyck flags |= SKBEDIT_F_QUEUE_MAPPING; 132ca9b0e27SAlexander Duyck queue_mapping = nla_data(tb[TCA_SKBEDIT_QUEUE_MAPPING]); 133ca9b0e27SAlexander Duyck } 1341c55d62eSjamal 135ff202ee1SJamal Hadi Salim if (tb[TCA_SKBEDIT_PTYPE] != NULL) { 136ff202ee1SJamal Hadi Salim ptype = nla_data(tb[TCA_SKBEDIT_PTYPE]); 137ff202ee1SJamal Hadi Salim if (!skb_pkt_type_ok(*ptype)) 138ff202ee1SJamal Hadi Salim return -EINVAL; 139ff202ee1SJamal Hadi Salim flags |= SKBEDIT_F_PTYPE; 140ff202ee1SJamal Hadi Salim } 141ff202ee1SJamal Hadi Salim 1421c55d62eSjamal if (tb[TCA_SKBEDIT_MARK] != NULL) { 1431c55d62eSjamal flags |= SKBEDIT_F_MARK; 1441c55d62eSjamal mark = nla_data(tb[TCA_SKBEDIT_MARK]); 1451c55d62eSjamal } 1461c55d62eSjamal 1474fe77d82SAntonio Quartulli if (tb[TCA_SKBEDIT_MASK] != NULL) { 1484fe77d82SAntonio Quartulli flags |= SKBEDIT_F_MASK; 1494fe77d82SAntonio Quartulli mask = nla_data(tb[TCA_SKBEDIT_MASK]); 1504fe77d82SAntonio Quartulli } 1514fe77d82SAntonio Quartulli 152e7e3728bSQiaobin Fu if (tb[TCA_SKBEDIT_FLAGS] != NULL) { 153e7e3728bSQiaobin Fu u64 *pure_flags = nla_data(tb[TCA_SKBEDIT_FLAGS]); 154e7e3728bSQiaobin Fu 155e7e3728bSQiaobin Fu if (*pure_flags & SKBEDIT_F_INHERITDSFIELD) 156e7e3728bSQiaobin Fu flags |= SKBEDIT_F_INHERITDSFIELD; 157e7e3728bSQiaobin Fu } 158e7e3728bSQiaobin Fu 159ca9b0e27SAlexander Duyck parm = nla_data(tb[TCA_SKBEDIT_PARMS]); 1607be8ef2cSDmytro Linkin index = parm->index; 1617be8ef2cSDmytro Linkin err = tcf_idr_check_alloc(tn, &index, a, bind); 1620190c1d4SVlad Buslov if (err < 0) 1630190c1d4SVlad Buslov return err; 1640190c1d4SVlad Buslov exists = err; 1655e1567aeSJamal Hadi Salim if (exists && bind) 1665e1567aeSJamal Hadi Salim return 0; 1675e1567aeSJamal Hadi Salim 1685e1567aeSJamal Hadi Salim if (!flags) { 169af5d0184SRoman Mashak if (exists) 17065a206c0SChris Mi tcf_idr_release(*a, bind); 1710190c1d4SVlad Buslov else 1727be8ef2cSDmytro Linkin tcf_idr_cleanup(tn, index); 1735e1567aeSJamal Hadi Salim return -EINVAL; 1745e1567aeSJamal Hadi Salim } 1755e1567aeSJamal Hadi Salim 1765e1567aeSJamal Hadi Salim if (!exists) { 1777be8ef2cSDmytro Linkin ret = tcf_idr_create(tn, index, est, a, 178e3822678SVlad Buslov &act_skbedit_ops, bind, true, 0); 1790190c1d4SVlad Buslov if (ret) { 1807be8ef2cSDmytro Linkin tcf_idr_cleanup(tn, index); 18186062033SWANG Cong return ret; 1820190c1d4SVlad Buslov } 183ca9b0e27SAlexander Duyck 184a85a970aSWANG Cong d = to_skbedit(*a); 185ca9b0e27SAlexander Duyck ret = ACT_P_CREATED; 186ca9b0e27SAlexander Duyck } else { 187a85a970aSWANG Cong d = to_skbedit(*a); 1884e8ddd7fSVlad Buslov if (!ovr) { 18965a206c0SChris Mi tcf_idr_release(*a, bind); 190ca9b0e27SAlexander Duyck return -EEXIST; 191ca9b0e27SAlexander Duyck } 1924e8ddd7fSVlad Buslov } 193ec7727bbSDavide Caratti err = tcf_action_check_ctrlact(parm->action, tp, &goto_ch, extack); 194ec7727bbSDavide Caratti if (err < 0) 195ec7727bbSDavide Caratti goto release_idr; 196ca9b0e27SAlexander Duyck 197c749cddaSDavide Caratti params_new = kzalloc(sizeof(*params_new), GFP_KERNEL); 198c749cddaSDavide Caratti if (unlikely(!params_new)) { 199ec7727bbSDavide Caratti err = -ENOMEM; 200ec7727bbSDavide Caratti goto put_chain; 201c749cddaSDavide Caratti } 202c749cddaSDavide Caratti 203c749cddaSDavide Caratti params_new->flags = flags; 204ca9b0e27SAlexander Duyck if (flags & SKBEDIT_F_PRIORITY) 205c749cddaSDavide Caratti params_new->priority = *priority; 206ca9b0e27SAlexander Duyck if (flags & SKBEDIT_F_QUEUE_MAPPING) 207c749cddaSDavide Caratti params_new->queue_mapping = *queue_mapping; 2081c55d62eSjamal if (flags & SKBEDIT_F_MARK) 209c749cddaSDavide Caratti params_new->mark = *mark; 210ff202ee1SJamal Hadi Salim if (flags & SKBEDIT_F_PTYPE) 211c749cddaSDavide Caratti params_new->ptype = *ptype; 2124fe77d82SAntonio Quartulli /* default behaviour is to use all the bits */ 213c749cddaSDavide Caratti params_new->mask = 0xffffffff; 2144fe77d82SAntonio Quartulli if (flags & SKBEDIT_F_MASK) 215c749cddaSDavide Caratti params_new->mask = *mask; 2161c55d62eSjamal 2176d7a8df6SVlad Buslov spin_lock_bh(&d->tcf_lock); 218ec7727bbSDavide Caratti goto_ch = tcf_action_set_ctrlact(*a, parm->action, goto_ch); 219445d3749SPaul E. McKenney params_new = rcu_replace_pointer(d->params, params_new, 2206d7a8df6SVlad Buslov lockdep_is_held(&d->tcf_lock)); 2216d7a8df6SVlad Buslov spin_unlock_bh(&d->tcf_lock); 2226d7a8df6SVlad Buslov if (params_new) 2236d7a8df6SVlad Buslov kfree_rcu(params_new, rcu); 224ec7727bbSDavide Caratti if (goto_ch) 225ec7727bbSDavide Caratti tcf_chain_put_by_act(goto_ch); 226ca9b0e27SAlexander Duyck 227ca9b0e27SAlexander Duyck if (ret == ACT_P_CREATED) 22865a206c0SChris Mi tcf_idr_insert(tn, *a); 229ca9b0e27SAlexander Duyck return ret; 230ec7727bbSDavide Caratti put_chain: 231ec7727bbSDavide Caratti if (goto_ch) 232ec7727bbSDavide Caratti tcf_chain_put_by_act(goto_ch); 233ec7727bbSDavide Caratti release_idr: 234ec7727bbSDavide Caratti tcf_idr_release(*a, bind); 235ec7727bbSDavide Caratti return err; 236ca9b0e27SAlexander Duyck } 237ca9b0e27SAlexander Duyck 238cc7ec456SEric Dumazet static int tcf_skbedit_dump(struct sk_buff *skb, struct tc_action *a, 239ca9b0e27SAlexander Duyck int bind, int ref) 240ca9b0e27SAlexander Duyck { 241ca9b0e27SAlexander Duyck unsigned char *b = skb_tail_pointer(skb); 242a85a970aSWANG Cong struct tcf_skbedit *d = to_skbedit(a); 243c749cddaSDavide Caratti struct tcf_skbedit_params *params; 2441c40be12SEric Dumazet struct tc_skbedit opt = { 2451c40be12SEric Dumazet .index = d->tcf_index, 246036bb443SVlad Buslov .refcnt = refcount_read(&d->tcf_refcnt) - ref, 247036bb443SVlad Buslov .bindcnt = atomic_read(&d->tcf_bindcnt) - bind, 2481c40be12SEric Dumazet }; 249e7e3728bSQiaobin Fu u64 pure_flags = 0; 250c749cddaSDavide Caratti struct tcf_t t; 251c749cddaSDavide Caratti 2526d7a8df6SVlad Buslov spin_lock_bh(&d->tcf_lock); 2536d7a8df6SVlad Buslov params = rcu_dereference_protected(d->params, 2546d7a8df6SVlad Buslov lockdep_is_held(&d->tcf_lock)); 2556d7a8df6SVlad Buslov opt.action = d->tcf_action; 256ca9b0e27SAlexander Duyck 2571b34ec43SDavid S. Miller if (nla_put(skb, TCA_SKBEDIT_PARMS, sizeof(opt), &opt)) 2581b34ec43SDavid S. Miller goto nla_put_failure; 259c749cddaSDavide Caratti if ((params->flags & SKBEDIT_F_PRIORITY) && 260c749cddaSDavide Caratti nla_put_u32(skb, TCA_SKBEDIT_PRIORITY, params->priority)) 2611b34ec43SDavid S. Miller goto nla_put_failure; 262c749cddaSDavide Caratti if ((params->flags & SKBEDIT_F_QUEUE_MAPPING) && 263c749cddaSDavide Caratti nla_put_u16(skb, TCA_SKBEDIT_QUEUE_MAPPING, params->queue_mapping)) 2641b34ec43SDavid S. Miller goto nla_put_failure; 265c749cddaSDavide Caratti if ((params->flags & SKBEDIT_F_MARK) && 266c749cddaSDavide Caratti nla_put_u32(skb, TCA_SKBEDIT_MARK, params->mark)) 2671b34ec43SDavid S. Miller goto nla_put_failure; 268c749cddaSDavide Caratti if ((params->flags & SKBEDIT_F_PTYPE) && 269c749cddaSDavide Caratti nla_put_u16(skb, TCA_SKBEDIT_PTYPE, params->ptype)) 270ff202ee1SJamal Hadi Salim goto nla_put_failure; 271c749cddaSDavide Caratti if ((params->flags & SKBEDIT_F_MASK) && 272c749cddaSDavide Caratti nla_put_u32(skb, TCA_SKBEDIT_MASK, params->mask)) 2734fe77d82SAntonio Quartulli goto nla_put_failure; 274c749cddaSDavide Caratti if (params->flags & SKBEDIT_F_INHERITDSFIELD) 275e7e3728bSQiaobin Fu pure_flags |= SKBEDIT_F_INHERITDSFIELD; 276e7e3728bSQiaobin Fu if (pure_flags != 0 && 277e7e3728bSQiaobin Fu nla_put(skb, TCA_SKBEDIT_FLAGS, sizeof(pure_flags), &pure_flags)) 278e7e3728bSQiaobin Fu goto nla_put_failure; 27948d8ee16SJamal Hadi Salim 28048d8ee16SJamal Hadi Salim tcf_tm_dump(&t, &d->tcf_tm); 2819854518eSNicolas Dichtel if (nla_put_64bit(skb, TCA_SKBEDIT_TM, sizeof(t), &t, TCA_SKBEDIT_PAD)) 2821b34ec43SDavid S. Miller goto nla_put_failure; 2836d7a8df6SVlad Buslov spin_unlock_bh(&d->tcf_lock); 2846d7a8df6SVlad Buslov 285ca9b0e27SAlexander Duyck return skb->len; 286ca9b0e27SAlexander Duyck 287ca9b0e27SAlexander Duyck nla_put_failure: 2886d7a8df6SVlad Buslov spin_unlock_bh(&d->tcf_lock); 289ca9b0e27SAlexander Duyck nlmsg_trim(skb, b); 290ca9b0e27SAlexander Duyck return -1; 291ca9b0e27SAlexander Duyck } 292ca9b0e27SAlexander Duyck 293c749cddaSDavide Caratti static void tcf_skbedit_cleanup(struct tc_action *a) 294c749cddaSDavide Caratti { 295c749cddaSDavide Caratti struct tcf_skbedit *d = to_skbedit(a); 296c749cddaSDavide Caratti struct tcf_skbedit_params *params; 297c749cddaSDavide Caratti 298c749cddaSDavide Caratti params = rcu_dereference_protected(d->params, 1); 299c749cddaSDavide Caratti if (params) 300c749cddaSDavide Caratti kfree_rcu(params, rcu); 301c749cddaSDavide Caratti } 302c749cddaSDavide Caratti 303ddf97ccdSWANG Cong static int tcf_skbedit_walker(struct net *net, struct sk_buff *skb, 304ddf97ccdSWANG Cong struct netlink_callback *cb, int type, 30541780105SAlexander Aring const struct tc_action_ops *ops, 30641780105SAlexander Aring struct netlink_ext_ack *extack) 307ddf97ccdSWANG Cong { 308ddf97ccdSWANG Cong struct tc_action_net *tn = net_generic(net, skbedit_net_id); 309ddf97ccdSWANG Cong 310b3620145SAlexander Aring return tcf_generic_walker(tn, skb, cb, type, ops, extack); 311ddf97ccdSWANG Cong } 312ddf97ccdSWANG Cong 313f061b48cSCong Wang static int tcf_skbedit_search(struct net *net, struct tc_action **a, u32 index) 314ddf97ccdSWANG Cong { 315ddf97ccdSWANG Cong struct tc_action_net *tn = net_generic(net, skbedit_net_id); 316ddf97ccdSWANG Cong 31765a206c0SChris Mi return tcf_idr_search(tn, a, index); 318ddf97ccdSWANG Cong } 319ddf97ccdSWANG Cong 320e1fea322SRoman Mashak static size_t tcf_skbedit_get_fill_size(const struct tc_action *act) 321e1fea322SRoman Mashak { 322e1fea322SRoman Mashak return nla_total_size(sizeof(struct tc_skbedit)) 323e1fea322SRoman Mashak + nla_total_size(sizeof(u32)) /* TCA_SKBEDIT_PRIORITY */ 324e1fea322SRoman Mashak + nla_total_size(sizeof(u16)) /* TCA_SKBEDIT_QUEUE_MAPPING */ 325e1fea322SRoman Mashak + nla_total_size(sizeof(u32)) /* TCA_SKBEDIT_MARK */ 326e1fea322SRoman Mashak + nla_total_size(sizeof(u16)) /* TCA_SKBEDIT_PTYPE */ 327e1fea322SRoman Mashak + nla_total_size(sizeof(u32)) /* TCA_SKBEDIT_MASK */ 328e1fea322SRoman Mashak + nla_total_size_64bit(sizeof(u64)); /* TCA_SKBEDIT_FLAGS */ 329e1fea322SRoman Mashak } 330e1fea322SRoman Mashak 331ca9b0e27SAlexander Duyck static struct tc_action_ops act_skbedit_ops = { 332ca9b0e27SAlexander Duyck .kind = "skbedit", 333eddd2cf1SEli Cohen .id = TCA_ID_SKBEDIT, 334ca9b0e27SAlexander Duyck .owner = THIS_MODULE, 33545da1dacSJamal Hadi Salim .act = tcf_skbedit_act, 336*837cb17dSPetr Machata .stats_update = tcf_skbedit_stats_update, 337ca9b0e27SAlexander Duyck .dump = tcf_skbedit_dump, 338ca9b0e27SAlexander Duyck .init = tcf_skbedit_init, 339c749cddaSDavide Caratti .cleanup = tcf_skbedit_cleanup, 340ddf97ccdSWANG Cong .walk = tcf_skbedit_walker, 341e1fea322SRoman Mashak .get_fill_size = tcf_skbedit_get_fill_size, 342ddf97ccdSWANG Cong .lookup = tcf_skbedit_search, 343a85a970aSWANG Cong .size = sizeof(struct tcf_skbedit), 344ddf97ccdSWANG Cong }; 345ddf97ccdSWANG Cong 346ddf97ccdSWANG Cong static __net_init int skbedit_init_net(struct net *net) 347ddf97ccdSWANG Cong { 348ddf97ccdSWANG Cong struct tc_action_net *tn = net_generic(net, skbedit_net_id); 349ddf97ccdSWANG Cong 350981471bdSCong Wang return tc_action_net_init(net, tn, &act_skbedit_ops); 351ddf97ccdSWANG Cong } 352ddf97ccdSWANG Cong 353039af9c6SCong Wang static void __net_exit skbedit_exit_net(struct list_head *net_list) 354ddf97ccdSWANG Cong { 355039af9c6SCong Wang tc_action_net_exit(net_list, skbedit_net_id); 356ddf97ccdSWANG Cong } 357ddf97ccdSWANG Cong 358ddf97ccdSWANG Cong static struct pernet_operations skbedit_net_ops = { 359ddf97ccdSWANG Cong .init = skbedit_init_net, 360039af9c6SCong Wang .exit_batch = skbedit_exit_net, 361ddf97ccdSWANG Cong .id = &skbedit_net_id, 362ddf97ccdSWANG Cong .size = sizeof(struct tc_action_net), 363ca9b0e27SAlexander Duyck }; 364ca9b0e27SAlexander Duyck 365ca9b0e27SAlexander Duyck MODULE_AUTHOR("Alexander Duyck, <alexander.h.duyck@intel.com>"); 366ca9b0e27SAlexander Duyck MODULE_DESCRIPTION("SKB Editing"); 367ca9b0e27SAlexander Duyck MODULE_LICENSE("GPL"); 368ca9b0e27SAlexander Duyck 369ca9b0e27SAlexander Duyck static int __init skbedit_init_module(void) 370ca9b0e27SAlexander Duyck { 371ddf97ccdSWANG Cong return tcf_register_action(&act_skbedit_ops, &skbedit_net_ops); 372ca9b0e27SAlexander Duyck } 373ca9b0e27SAlexander Duyck 374ca9b0e27SAlexander Duyck static void __exit skbedit_cleanup_module(void) 375ca9b0e27SAlexander Duyck { 376ddf97ccdSWANG Cong tcf_unregister_action(&act_skbedit_ops, &skbedit_net_ops); 377ca9b0e27SAlexander Duyck } 378ca9b0e27SAlexander Duyck 379ca9b0e27SAlexander Duyck module_init(skbedit_init_module); 380ca9b0e27SAlexander Duyck module_exit(skbedit_cleanup_module); 381