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_connmark.c  netfilter connmark retriever action
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * skb mark is over-written
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Copyright (c) 2011 Felix Fietkau <nbd@openwrt.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/module.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 <linux/pkt_cls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/ip.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/ipv6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <net/netlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <net/pkt_sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <net/act_api.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <net/pkt_cls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <uapi/linux/tc_act/tc_connmark.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <net/tc_act/tc_connmark.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <net/netfilter/nf_conntrack.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <net/netfilter/nf_conntrack_core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <net/netfilter/nf_conntrack_zones.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) static unsigned int connmark_net_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) static struct tc_action_ops act_connmark_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) static int tcf_connmark_act(struct sk_buff *skb, const struct tc_action *a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 			    struct tcf_result *res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	const struct nf_conntrack_tuple_hash *thash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	struct nf_conntrack_tuple tuple;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	enum ip_conntrack_info ctinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	struct tcf_connmark_info *ca = to_connmark(a);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	struct nf_conntrack_zone zone;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	struct nf_conn *c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	int proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	spin_lock(&ca->tcf_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	tcf_lastuse_update(&ca->tcf_tm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	bstats_update(&ca->tcf_bstats, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	switch (skb_protocol(skb, true)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	case htons(ETH_P_IP):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		if (skb->len < sizeof(struct iphdr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		proto = NFPROTO_IPV4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	case htons(ETH_P_IPV6):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		if (skb->len < sizeof(struct ipv6hdr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		proto = NFPROTO_IPV6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	c = nf_ct_get(skb, &ctinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	if (c) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		skb->mark = c->mark;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		/* using overlimits stats to count how many packets marked */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		ca->tcf_qstats.overlimits++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	if (!nf_ct_get_tuplepr(skb, skb_network_offset(skb),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 			       proto, ca->net, &tuple))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	zone.id = ca->zone;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	zone.dir = NF_CT_DEFAULT_ZONE_DIR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	thash = nf_conntrack_find_get(ca->net, &zone, &tuple);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	if (!thash)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	c = nf_ct_tuplehash_to_ctrack(thash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	/* using overlimits stats to count how many packets marked */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	ca->tcf_qstats.overlimits++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	skb->mark = c->mark;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	nf_ct_put(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	spin_unlock(&ca->tcf_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	return ca->tcf_action;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) static const struct nla_policy connmark_policy[TCA_CONNMARK_MAX + 1] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	[TCA_CONNMARK_PARMS] = { .len = sizeof(struct tc_connmark) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) static int tcf_connmark_init(struct net *net, struct nlattr *nla,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 			     struct nlattr *est, struct tc_action **a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 			     int ovr, int bind, bool rtnl_held,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 			     struct tcf_proto *tp, u32 flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 			     struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	struct tc_action_net *tn = net_generic(net, connmark_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	struct nlattr *tb[TCA_CONNMARK_MAX + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	struct tcf_chain *goto_ch = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	struct tcf_connmark_info *ci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	struct tc_connmark *parm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	int ret = 0, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	u32 index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	if (!nla)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	ret = nla_parse_nested_deprecated(tb, TCA_CONNMARK_MAX, nla,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 					  connmark_policy, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	if (!tb[TCA_CONNMARK_PARMS])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	parm = nla_data(tb[TCA_CONNMARK_PARMS]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	index = parm->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	ret = tcf_idr_check_alloc(tn, &index, a, bind);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	if (!ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		ret = tcf_idr_create(tn, index, est, a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 				     &act_connmark_ops, bind, false, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 			tcf_idr_cleanup(tn, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		ci = to_connmark(*a);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		err = tcf_action_check_ctrlact(parm->action, tp, &goto_ch,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 					       extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 			goto release_idr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		tcf_action_set_ctrlact(*a, parm->action, goto_ch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		ci->net = net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		ci->zone = parm->zone;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		ret = ACT_P_CREATED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	} else if (ret > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		ci = to_connmark(*a);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		if (bind)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		if (!ovr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 			tcf_idr_release(*a, bind);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 			return -EEXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		err = tcf_action_check_ctrlact(parm->action, tp, &goto_ch,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 					       extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 			goto release_idr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		/* replacing action and zone */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		spin_lock_bh(&ci->tcf_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		goto_ch = tcf_action_set_ctrlact(*a, parm->action, goto_ch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		ci->zone = parm->zone;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		spin_unlock_bh(&ci->tcf_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		if (goto_ch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 			tcf_chain_put_by_act(goto_ch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) release_idr:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	tcf_idr_release(*a, bind);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) static inline int tcf_connmark_dump(struct sk_buff *skb, struct tc_action *a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 				    int bind, int ref)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	unsigned char *b = skb_tail_pointer(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	struct tcf_connmark_info *ci = to_connmark(a);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	struct tc_connmark opt = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		.index   = ci->tcf_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		.refcnt  = refcount_read(&ci->tcf_refcnt) - ref,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		.bindcnt = atomic_read(&ci->tcf_bindcnt) - bind,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	struct tcf_t t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	spin_lock_bh(&ci->tcf_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	opt.action = ci->tcf_action;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	opt.zone = ci->zone;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	if (nla_put(skb, TCA_CONNMARK_PARMS, sizeof(opt), &opt))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	tcf_tm_dump(&t, &ci->tcf_tm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	if (nla_put_64bit(skb, TCA_CONNMARK_TM, sizeof(t), &t,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 			  TCA_CONNMARK_PAD))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	spin_unlock_bh(&ci->tcf_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	return skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) nla_put_failure:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	spin_unlock_bh(&ci->tcf_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	nlmsg_trim(skb, b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) static int tcf_connmark_walker(struct net *net, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 			       struct netlink_callback *cb, int type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 			       const struct tc_action_ops *ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 			       struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	struct tc_action_net *tn = net_generic(net, connmark_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	return tcf_generic_walker(tn, skb, cb, type, ops, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) static int tcf_connmark_search(struct net *net, struct tc_action **a, u32 index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	struct tc_action_net *tn = net_generic(net, connmark_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	return tcf_idr_search(tn, a, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) static struct tc_action_ops act_connmark_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	.kind		=	"connmark",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	.id		=	TCA_ID_CONNMARK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	.owner		=	THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	.act		=	tcf_connmark_act,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	.dump		=	tcf_connmark_dump,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	.init		=	tcf_connmark_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	.walk		=	tcf_connmark_walker,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	.lookup		=	tcf_connmark_search,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	.size		=	sizeof(struct tcf_connmark_info),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) static __net_init int connmark_init_net(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	struct tc_action_net *tn = net_generic(net, connmark_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	return tc_action_net_init(net, tn, &act_connmark_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) static void __net_exit connmark_exit_net(struct list_head *net_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	tc_action_net_exit(net_list, connmark_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) static struct pernet_operations connmark_net_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	.init = connmark_init_net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	.exit_batch = connmark_exit_net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	.id   = &connmark_net_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	.size = sizeof(struct tc_action_net),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) static int __init connmark_init_module(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	return tcf_register_action(&act_connmark_ops, &connmark_net_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) static void __exit connmark_cleanup_module(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	tcf_unregister_action(&act_connmark_ops, &connmark_net_ops);
^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) module_init(connmark_init_module);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) module_exit(connmark_cleanup_module);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) MODULE_AUTHOR("Felix Fietkau <nbd@openwrt.org>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) MODULE_DESCRIPTION("Connection tracking mark restoring");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) MODULE_LICENSE("GPL");