Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * net/sched/act_simple.c	Simple example of an action
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Authors:	Jamal Hadi Salim (2005-8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/rtnetlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <net/netlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <net/pkt_sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <net/pkt_cls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/tc_act/tc_defact.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <net/tc_act/tc_defact.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) static unsigned int simp_net_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) static struct tc_action_ops act_simp_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #define SIMP_MAX_DATA	32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) static int tcf_simp_act(struct sk_buff *skb, const struct tc_action *a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 			struct tcf_result *res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	struct tcf_defact *d = to_defact(a);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	spin_lock(&d->tcf_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	tcf_lastuse_update(&d->tcf_tm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	bstats_update(&d->tcf_bstats, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	/* print policy string followed by _ then packet count
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	 * Example if this was the 3rd packet and the string was "hello"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	 * then it would look like "hello_3" (without quotes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	pr_info("simple: %s_%llu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	       (char *)d->tcfd_defdata, d->tcf_bstats.packets);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	spin_unlock(&d->tcf_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	return d->tcf_action;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) static void tcf_simp_release(struct tc_action *a)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	struct tcf_defact *d = to_defact(a);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	kfree(d->tcfd_defdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) static int alloc_defdata(struct tcf_defact *d, const struct nlattr *defdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	d->tcfd_defdata = kzalloc(SIMP_MAX_DATA, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	if (unlikely(!d->tcfd_defdata))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	nla_strlcpy(d->tcfd_defdata, defdata, SIMP_MAX_DATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) static int reset_policy(struct tc_action *a, const struct nlattr *defdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 			struct tc_defact *p, struct tcf_proto *tp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 			struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	struct tcf_chain *goto_ch = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	struct tcf_defact *d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	err = tcf_action_check_ctrlact(p->action, tp, &goto_ch, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	d = to_defact(a);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	spin_lock_bh(&d->tcf_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	goto_ch = tcf_action_set_ctrlact(a, p->action, goto_ch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	memset(d->tcfd_defdata, 0, SIMP_MAX_DATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	nla_strlcpy(d->tcfd_defdata, defdata, SIMP_MAX_DATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	spin_unlock_bh(&d->tcf_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	if (goto_ch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		tcf_chain_put_by_act(goto_ch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) static const struct nla_policy simple_policy[TCA_DEF_MAX + 1] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	[TCA_DEF_PARMS]	= { .len = sizeof(struct tc_defact) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	[TCA_DEF_DATA]	= { .type = NLA_STRING, .len = SIMP_MAX_DATA },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) static int tcf_simp_init(struct net *net, struct nlattr *nla,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 			 struct nlattr *est, struct tc_action **a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 			 int ovr, int bind, bool rtnl_held,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 			 struct tcf_proto *tp, u32 flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 			 struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	struct tc_action_net *tn = net_generic(net, simp_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	struct nlattr *tb[TCA_DEF_MAX + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	struct tcf_chain *goto_ch = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	struct tc_defact *parm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	struct tcf_defact *d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	bool exists = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	int ret = 0, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	u32 index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	if (nla == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	err = nla_parse_nested_deprecated(tb, TCA_DEF_MAX, nla, simple_policy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 					  NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	if (tb[TCA_DEF_PARMS] == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	parm = nla_data(tb[TCA_DEF_PARMS]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	index = parm->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	err = tcf_idr_check_alloc(tn, &index, a, bind);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	exists = err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	if (exists && bind)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	if (tb[TCA_DEF_DATA] == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		if (exists)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 			tcf_idr_release(*a, bind);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 			tcf_idr_cleanup(tn, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	if (!exists) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		ret = tcf_idr_create(tn, index, est, a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 				     &act_simp_ops, bind, false, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 			tcf_idr_cleanup(tn, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		d = to_defact(*a);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		err = tcf_action_check_ctrlact(parm->action, tp, &goto_ch,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 					       extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 			goto release_idr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		err = alloc_defdata(d, tb[TCA_DEF_DATA]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 			goto put_chain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		tcf_action_set_ctrlact(*a, parm->action, goto_ch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		ret = ACT_P_CREATED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		if (!ovr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 			err = -EEXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 			goto release_idr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		err = reset_policy(*a, tb[TCA_DEF_DATA], parm, tp, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 			goto release_idr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) put_chain:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	if (goto_ch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		tcf_chain_put_by_act(goto_ch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) release_idr:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	tcf_idr_release(*a, bind);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) static int tcf_simp_dump(struct sk_buff *skb, struct tc_action *a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 			 int bind, int ref)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	unsigned char *b = skb_tail_pointer(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	struct tcf_defact *d = to_defact(a);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	struct tc_defact opt = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		.index   = d->tcf_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		.refcnt  = refcount_read(&d->tcf_refcnt) - ref,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		.bindcnt = atomic_read(&d->tcf_bindcnt) - bind,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	struct tcf_t t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	spin_lock_bh(&d->tcf_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	opt.action = d->tcf_action;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	if (nla_put(skb, TCA_DEF_PARMS, sizeof(opt), &opt) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	    nla_put_string(skb, TCA_DEF_DATA, d->tcfd_defdata))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	tcf_tm_dump(&t, &d->tcf_tm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	if (nla_put_64bit(skb, TCA_DEF_TM, sizeof(t), &t, TCA_DEF_PAD))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	spin_unlock_bh(&d->tcf_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	return skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) nla_put_failure:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	spin_unlock_bh(&d->tcf_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	nlmsg_trim(skb, b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) static int tcf_simp_walker(struct net *net, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 			   struct netlink_callback *cb, int type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 			   const struct tc_action_ops *ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 			   struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	struct tc_action_net *tn = net_generic(net, simp_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	return tcf_generic_walker(tn, skb, cb, type, ops, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) static int tcf_simp_search(struct net *net, struct tc_action **a, u32 index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	struct tc_action_net *tn = net_generic(net, simp_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	return tcf_idr_search(tn, a, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) static struct tc_action_ops act_simp_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	.kind		=	"simple",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	.id		=	TCA_ID_SIMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	.owner		=	THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	.act		=	tcf_simp_act,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	.dump		=	tcf_simp_dump,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	.cleanup	=	tcf_simp_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	.init		=	tcf_simp_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	.walk		=	tcf_simp_walker,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	.lookup		=	tcf_simp_search,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	.size		=	sizeof(struct tcf_defact),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) static __net_init int simp_init_net(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	struct tc_action_net *tn = net_generic(net, simp_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	return tc_action_net_init(net, tn, &act_simp_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) static void __net_exit simp_exit_net(struct list_head *net_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	tc_action_net_exit(net_list, simp_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) static struct pernet_operations simp_net_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	.init = simp_init_net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	.exit_batch = simp_exit_net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	.id   = &simp_net_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	.size = sizeof(struct tc_action_net),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) MODULE_AUTHOR("Jamal Hadi Salim(2005)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) MODULE_DESCRIPTION("Simple example action");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) static int __init simp_init_module(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	int ret = tcf_register_action(&act_simp_ops, &simp_net_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		pr_info("Simple TC action Loaded\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) static void __exit simp_cleanup_module(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	tcf_unregister_action(&act_simp_ops, &simp_net_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) module_init(simp_init_module);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) module_exit(simp_cleanup_module);