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-only OR BSD-2-Clause)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /* Copyright (C) 2019 Netronome Systems, Inc. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) #include <linux/if_arp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/mpls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/rtnetlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/tc_act/tc_mpls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <net/mpls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <net/netlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <net/pkt_sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <net/pkt_cls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <net/tc_act/tc_mpls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) static unsigned int mpls_net_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) static struct tc_action_ops act_mpls_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #define ACT_MPLS_TTL_DEFAULT	255
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) static __be32 tcf_mpls_get_lse(struct mpls_shim_hdr *lse,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 			       struct tcf_mpls_params *p, bool set_bos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	u32 new_lse = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	if (lse)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 		new_lse = be32_to_cpu(lse->label_stack_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	if (p->tcfm_label != ACT_MPLS_LABEL_NOT_SET) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 		new_lse &= ~MPLS_LS_LABEL_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 		new_lse |= p->tcfm_label << MPLS_LS_LABEL_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	if (p->tcfm_ttl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 		new_lse &= ~MPLS_LS_TTL_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 		new_lse |= p->tcfm_ttl << MPLS_LS_TTL_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	if (p->tcfm_tc != ACT_MPLS_TC_NOT_SET) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 		new_lse &= ~MPLS_LS_TC_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 		new_lse |= p->tcfm_tc << MPLS_LS_TC_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	if (p->tcfm_bos != ACT_MPLS_BOS_NOT_SET) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		new_lse &= ~MPLS_LS_S_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		new_lse |= p->tcfm_bos << MPLS_LS_S_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	} else if (set_bos) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		new_lse |= 1 << MPLS_LS_S_SHIFT;
^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) 	return cpu_to_be32(new_lse);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) static int tcf_mpls_act(struct sk_buff *skb, const struct tc_action *a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 			struct tcf_result *res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	struct tcf_mpls *m = to_mpls(a);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	struct tcf_mpls_params *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	__be32 new_lse;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	int ret, mac_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	tcf_lastuse_update(&m->tcf_tm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	bstats_cpu_update(this_cpu_ptr(m->common.cpu_bstats), skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	/* Ensure 'data' points at mac_header prior calling mpls manipulating
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	 * functions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	if (skb_at_tc_ingress(skb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		skb_push_rcsum(skb, skb->mac_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		mac_len = skb->mac_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		mac_len = skb_network_header(skb) - skb_mac_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	ret = READ_ONCE(m->tcf_action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	p = rcu_dereference_bh(m->mpls_p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	switch (p->tcfm_action) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	case TCA_MPLS_ACT_POP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		if (skb_mpls_pop(skb, p->tcfm_proto, mac_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 				 skb->dev && skb->dev->type == ARPHRD_ETHER))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 			goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	case TCA_MPLS_ACT_PUSH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		new_lse = tcf_mpls_get_lse(NULL, p, !eth_p_mpls(skb_protocol(skb, true)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		if (skb_mpls_push(skb, new_lse, p->tcfm_proto, mac_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 				  skb->dev && skb->dev->type == ARPHRD_ETHER))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 			goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	case TCA_MPLS_ACT_MAC_PUSH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		if (skb_vlan_tag_present(skb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 			if (__vlan_insert_inner_tag(skb, skb->vlan_proto,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 						    skb_vlan_tag_get(skb),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 						    ETH_HLEN) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 				goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 			skb->protocol = skb->vlan_proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 			__vlan_hwaccel_clear_tag(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		new_lse = tcf_mpls_get_lse(NULL, p, mac_len ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 					   !eth_p_mpls(skb->protocol));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		if (skb_mpls_push(skb, new_lse, p->tcfm_proto, 0, false))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 			goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	case TCA_MPLS_ACT_MODIFY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		if (!pskb_may_pull(skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 				   skb_network_offset(skb) + MPLS_HLEN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 			goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		new_lse = tcf_mpls_get_lse(mpls_hdr(skb), p, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		if (skb_mpls_update_lse(skb, new_lse))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 			goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	case TCA_MPLS_ACT_DEC_TTL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		if (skb_mpls_dec_ttl(skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 			goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	if (skb_at_tc_ingress(skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		skb_pull_rcsum(skb, skb->mac_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) drop:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	qstats_drop_inc(this_cpu_ptr(m->common.cpu_qstats));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	return TC_ACT_SHOT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) static int valid_label(const struct nlattr *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		       struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	const u32 *label = nla_data(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	if (*label & ~MPLS_LABEL_MASK || *label == MPLS_LABEL_IMPLNULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		NL_SET_ERR_MSG_MOD(extack, "MPLS label out of range");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) static const struct nla_policy mpls_policy[TCA_MPLS_MAX + 1] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	[TCA_MPLS_PARMS]	= NLA_POLICY_EXACT_LEN(sizeof(struct tc_mpls)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	[TCA_MPLS_PROTO]	= { .type = NLA_U16 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	[TCA_MPLS_LABEL]	= NLA_POLICY_VALIDATE_FN(NLA_U32, valid_label),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	[TCA_MPLS_TC]		= NLA_POLICY_RANGE(NLA_U8, 0, 7),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	[TCA_MPLS_TTL]		= NLA_POLICY_MIN(NLA_U8, 1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	[TCA_MPLS_BOS]		= NLA_POLICY_RANGE(NLA_U8, 0, 1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) static int tcf_mpls_init(struct net *net, struct nlattr *nla,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 			 struct nlattr *est, struct tc_action **a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 			 int ovr, int bind, bool rtnl_held,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 			 struct tcf_proto *tp, u32 flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 			 struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	struct tc_action_net *tn = net_generic(net, mpls_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	struct nlattr *tb[TCA_MPLS_MAX + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	struct tcf_chain *goto_ch = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	struct tcf_mpls_params *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	struct tc_mpls *parm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	bool exists = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	struct tcf_mpls *m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	int ret = 0, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	u8 mpls_ttl = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	u32 index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	if (!nla) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		NL_SET_ERR_MSG_MOD(extack, "Missing netlink attributes");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	err = nla_parse_nested(tb, TCA_MPLS_MAX, nla, mpls_policy, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	if (!tb[TCA_MPLS_PARMS]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		NL_SET_ERR_MSG_MOD(extack, "No MPLS params");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	parm = nla_data(tb[TCA_MPLS_PARMS]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	index = parm->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	/* Verify parameters against action type. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	switch (parm->m_action) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	case TCA_MPLS_ACT_POP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		if (!tb[TCA_MPLS_PROTO]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 			NL_SET_ERR_MSG_MOD(extack, "Protocol must be set for MPLS pop");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		if (!eth_proto_is_802_3(nla_get_be16(tb[TCA_MPLS_PROTO]))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 			NL_SET_ERR_MSG_MOD(extack, "Invalid protocol type for MPLS pop");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		if (tb[TCA_MPLS_LABEL] || tb[TCA_MPLS_TTL] || tb[TCA_MPLS_TC] ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		    tb[TCA_MPLS_BOS]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 			NL_SET_ERR_MSG_MOD(extack, "Label, TTL, TC or BOS cannot be used with MPLS pop");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	case TCA_MPLS_ACT_DEC_TTL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		if (tb[TCA_MPLS_PROTO] || tb[TCA_MPLS_LABEL] ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		    tb[TCA_MPLS_TTL] || tb[TCA_MPLS_TC] || tb[TCA_MPLS_BOS]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 			NL_SET_ERR_MSG_MOD(extack, "Label, TTL, TC, BOS or protocol cannot be used with MPLS dec_ttl");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	case TCA_MPLS_ACT_PUSH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	case TCA_MPLS_ACT_MAC_PUSH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		if (!tb[TCA_MPLS_LABEL]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 			NL_SET_ERR_MSG_MOD(extack, "Label is required for MPLS push");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		if (tb[TCA_MPLS_PROTO] &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		    !eth_p_mpls(nla_get_be16(tb[TCA_MPLS_PROTO]))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 			NL_SET_ERR_MSG_MOD(extack, "Protocol must be an MPLS type for MPLS push");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 			return -EPROTONOSUPPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		/* Push needs a TTL - if not specified, set a default value. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		if (!tb[TCA_MPLS_TTL]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) #if IS_ENABLED(CONFIG_MPLS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 			mpls_ttl = net->mpls.default_ttl ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 				   net->mpls.default_ttl : ACT_MPLS_TTL_DEFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 			mpls_ttl = ACT_MPLS_TTL_DEFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	case TCA_MPLS_ACT_MODIFY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		if (tb[TCA_MPLS_PROTO]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 			NL_SET_ERR_MSG_MOD(extack, "Protocol cannot be used with MPLS modify");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		NL_SET_ERR_MSG_MOD(extack, "Unknown MPLS action");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		return -EINVAL;
^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) 	err = tcf_idr_check_alloc(tn, &index, a, bind);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	exists = err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	if (exists && bind)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	if (!exists) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		ret = tcf_idr_create(tn, index, est, a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 				     &act_mpls_ops, bind, true, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 			tcf_idr_cleanup(tn, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		ret = ACT_P_CREATED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	} else if (!ovr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		tcf_idr_release(*a, bind);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		return -EEXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	err = tcf_action_check_ctrlact(parm->action, tp, &goto_ch, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		goto release_idr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	m = to_mpls(*a);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	p = kzalloc(sizeof(*p), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	if (!p) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		goto put_chain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	p->tcfm_action = parm->m_action;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	p->tcfm_label = tb[TCA_MPLS_LABEL] ? nla_get_u32(tb[TCA_MPLS_LABEL]) :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 					     ACT_MPLS_LABEL_NOT_SET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	p->tcfm_tc = tb[TCA_MPLS_TC] ? nla_get_u8(tb[TCA_MPLS_TC]) :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 				       ACT_MPLS_TC_NOT_SET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	p->tcfm_ttl = tb[TCA_MPLS_TTL] ? nla_get_u8(tb[TCA_MPLS_TTL]) :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 					 mpls_ttl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	p->tcfm_bos = tb[TCA_MPLS_BOS] ? nla_get_u8(tb[TCA_MPLS_BOS]) :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 					 ACT_MPLS_BOS_NOT_SET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	p->tcfm_proto = tb[TCA_MPLS_PROTO] ? nla_get_be16(tb[TCA_MPLS_PROTO]) :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 					     htons(ETH_P_MPLS_UC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	spin_lock_bh(&m->tcf_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	goto_ch = tcf_action_set_ctrlact(*a, parm->action, goto_ch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	p = rcu_replace_pointer(m->mpls_p, p, lockdep_is_held(&m->tcf_lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	spin_unlock_bh(&m->tcf_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	if (goto_ch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 		tcf_chain_put_by_act(goto_ch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	if (p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		kfree_rcu(p, rcu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) put_chain:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	if (goto_ch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 		tcf_chain_put_by_act(goto_ch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) release_idr:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	tcf_idr_release(*a, bind);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) static void tcf_mpls_cleanup(struct tc_action *a)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	struct tcf_mpls *m = to_mpls(a);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	struct tcf_mpls_params *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	p = rcu_dereference_protected(m->mpls_p, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	if (p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		kfree_rcu(p, rcu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) static int tcf_mpls_dump(struct sk_buff *skb, struct tc_action *a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 			 int bind, int ref)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	unsigned char *b = skb_tail_pointer(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	struct tcf_mpls *m = to_mpls(a);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	struct tcf_mpls_params *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	struct tc_mpls opt = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		.index    = m->tcf_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		.refcnt   = refcount_read(&m->tcf_refcnt) - ref,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 		.bindcnt  = atomic_read(&m->tcf_bindcnt) - bind,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	struct tcf_t t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	spin_lock_bh(&m->tcf_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	opt.action = m->tcf_action;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	p = rcu_dereference_protected(m->mpls_p, lockdep_is_held(&m->tcf_lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	opt.m_action = p->tcfm_action;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	if (nla_put(skb, TCA_MPLS_PARMS, sizeof(opt), &opt))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	if (p->tcfm_label != ACT_MPLS_LABEL_NOT_SET &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	    nla_put_u32(skb, TCA_MPLS_LABEL, p->tcfm_label))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	if (p->tcfm_tc != ACT_MPLS_TC_NOT_SET &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	    nla_put_u8(skb, TCA_MPLS_TC, p->tcfm_tc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	if (p->tcfm_ttl && nla_put_u8(skb, TCA_MPLS_TTL, p->tcfm_ttl))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	if (p->tcfm_bos != ACT_MPLS_BOS_NOT_SET &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	    nla_put_u8(skb, TCA_MPLS_BOS, p->tcfm_bos))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	if (nla_put_be16(skb, TCA_MPLS_PROTO, p->tcfm_proto))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	tcf_tm_dump(&t, &m->tcf_tm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	if (nla_put_64bit(skb, TCA_MPLS_TM, sizeof(t), &t, TCA_MPLS_PAD))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	spin_unlock_bh(&m->tcf_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	return skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) nla_put_failure:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	spin_unlock_bh(&m->tcf_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	nlmsg_trim(skb, b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) static int tcf_mpls_walker(struct net *net, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 			   struct netlink_callback *cb, int type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 			   const struct tc_action_ops *ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 			   struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	struct tc_action_net *tn = net_generic(net, mpls_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	return tcf_generic_walker(tn, skb, cb, type, ops, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) static int tcf_mpls_search(struct net *net, struct tc_action **a, u32 index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	struct tc_action_net *tn = net_generic(net, mpls_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	return tcf_idr_search(tn, a, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) static struct tc_action_ops act_mpls_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	.kind		=	"mpls",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	.id		=	TCA_ID_MPLS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	.owner		=	THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	.act		=	tcf_mpls_act,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	.dump		=	tcf_mpls_dump,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	.init		=	tcf_mpls_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	.cleanup	=	tcf_mpls_cleanup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	.walk		=	tcf_mpls_walker,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	.lookup		=	tcf_mpls_search,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	.size		=	sizeof(struct tcf_mpls),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) static __net_init int mpls_init_net(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	struct tc_action_net *tn = net_generic(net, mpls_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	return tc_action_net_init(net, tn, &act_mpls_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) static void __net_exit mpls_exit_net(struct list_head *net_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	tc_action_net_exit(net_list, mpls_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) static struct pernet_operations mpls_net_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	.init = mpls_init_net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	.exit_batch = mpls_exit_net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	.id   = &mpls_net_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	.size = sizeof(struct tc_action_net),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) static int __init mpls_init_module(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	return tcf_register_action(&act_mpls_ops, &mpls_net_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) static void __exit mpls_cleanup_module(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	tcf_unregister_action(&act_mpls_ops, &mpls_net_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) module_init(mpls_init_module);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) module_exit(mpls_cleanup_module);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) MODULE_SOFTDEP("post: mpls_gso");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) MODULE_AUTHOR("Netronome Systems <oss-drivers@netronome.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) MODULE_DESCRIPTION("MPLS manipulation actions");