Commit bc7ebc56 authored by Kuniyuki Iwashima's avatar Kuniyuki Iwashima Committed by Jakub Kicinski
Browse files

mpls: Use in6_dev_rcu() and dev_net_rcu() in mpls_forward() and mpls_xmit().



mpls_forward() and mpls_xmit() are called under RCU.

Let's use in6_dev_rcu() and dev_net_rcu() there to annotate
as such.

Now we pass net to mpls_stats_inc_outucastpkts() not to read
dev_net_rcu() twice.

Signed-off-by: default avatarKuniyuki Iwashima <kuniyu@google.com>
Reviewed-by: default avatarGuillaume Nault <gnault@redhat.com>
Link: https://patch.msgid.link/20251029173344.2934622-6-kuniyu@google.com


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent d8f9581e
Loading
Loading
Loading
Loading
+8 −7
Original line number Diff line number Diff line
@@ -129,7 +129,8 @@ bool mpls_pkt_too_big(const struct sk_buff *skb, unsigned int mtu)
}
EXPORT_SYMBOL_GPL(mpls_pkt_too_big);

void mpls_stats_inc_outucastpkts(struct net_device *dev,
void mpls_stats_inc_outucastpkts(struct net *net,
				 struct net_device *dev,
				 const struct sk_buff *skb)
{
	struct mpls_dev *mdev;
@@ -141,13 +142,13 @@ void mpls_stats_inc_outucastpkts(struct net_device *dev,
					   tx_packets,
					   tx_bytes);
	} else if (skb->protocol == htons(ETH_P_IP)) {
		IP_UPD_PO_STATS(dev_net(dev), IPSTATS_MIB_OUT, skb->len);
		IP_UPD_PO_STATS(net, IPSTATS_MIB_OUT, skb->len);
#if IS_ENABLED(CONFIG_IPV6)
	} else if (skb->protocol == htons(ETH_P_IPV6)) {
		struct inet6_dev *in6dev = __in6_dev_get(dev);
		struct inet6_dev *in6dev = in6_dev_rcu(dev);

		if (in6dev)
			IP6_UPD_PO_STATS(dev_net(dev), in6dev,
			IP6_UPD_PO_STATS(net, in6dev,
					 IPSTATS_MIB_OUT, skb->len);
#endif
	}
@@ -342,7 +343,7 @@ static bool mpls_egress(struct net *net, struct mpls_route *rt,
static int mpls_forward(struct sk_buff *skb, struct net_device *dev,
			struct packet_type *pt, struct net_device *orig_dev)
{
	struct net *net = dev_net(dev);
	struct net *net = dev_net_rcu(dev);
	struct mpls_shim_hdr *hdr;
	const struct mpls_nh *nh;
	struct mpls_route *rt;
@@ -434,7 +435,7 @@ static int mpls_forward(struct sk_buff *skb, struct net_device *dev,
	dec.ttl -= 1;
	if (unlikely(!new_header_size && dec.bos)) {
		/* Penultimate hop popping */
		if (!mpls_egress(dev_net(out_dev), rt, skb, dec))
		if (!mpls_egress(net, rt, skb, dec))
			goto err;
	} else {
		bool bos;
@@ -451,7 +452,7 @@ static int mpls_forward(struct sk_buff *skb, struct net_device *dev,
		}
	}

	mpls_stats_inc_outucastpkts(out_dev, skb);
	mpls_stats_inc_outucastpkts(net, out_dev, skb);

	/* If via wasn't specified then send out using device address */
	if (nh->nh_via_table == MPLS_NEIGH_TABLE_UNSPEC)
+2 −1
Original line number Diff line number Diff line
@@ -197,7 +197,8 @@ int nla_get_labels(const struct nlattr *nla, u8 max_labels, u8 *labels,
bool mpls_output_possible(const struct net_device *dev);
unsigned int mpls_dev_mtu(const struct net_device *dev);
bool mpls_pkt_too_big(const struct sk_buff *skb, unsigned int mtu);
void mpls_stats_inc_outucastpkts(struct net_device *dev,
void mpls_stats_inc_outucastpkts(struct net *net,
				 struct net_device *dev,
				 const struct sk_buff *skb);

#endif /* MPLS_INTERNAL_H */
+2 −2
Original line number Diff line number Diff line
@@ -53,7 +53,7 @@ static int mpls_xmit(struct sk_buff *skb)

	/* Find the output device */
	out_dev = dst->dev;
	net = dev_net(out_dev);
	net = dev_net_rcu(out_dev);

	if (!mpls_output_possible(out_dev) ||
	    !dst->lwtstate || skb_warn_if_lro(skb))
@@ -128,7 +128,7 @@ static int mpls_xmit(struct sk_buff *skb)
		bos = false;
	}

	mpls_stats_inc_outucastpkts(out_dev, skb);
	mpls_stats_inc_outucastpkts(net, out_dev, skb);

	if (rt) {
		if (rt->rt_gw_family == AF_INET6)