Commit 05d6d492 authored by Eric Dumazet's avatar Eric Dumazet Committed by Jakub Kicinski
Browse files

inet: introduce dst_rtable() helper



I added dst_rt6_info() in commit
e8dfd42c ("ipv6: introduce dst_rt6_info() helper")

This patch does a similar change for IPv4.

Instead of (struct rtable *)dst casts, we can use :

 #define dst_rtable(_ptr) \
             container_of_const(_ptr, struct rtable, dst)

Patch is smaller than IPv6 one, because IPv4 has skb_rtable() helper.

Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Reviewed-by: default avatarDavid Ahern <dsahern@kernel.org>
Reviewed-by: default avatarSabrina Dubroca <sd@queasysnail.net>
Link: https://lore.kernel.org/r/20240429133009.1227754-1-edumazet@google.com


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent b4517670
Loading
Loading
Loading
Loading
+3 −9
Original line number Diff line number Diff line
@@ -348,16 +348,10 @@ static int dst_fetch_ha(const struct dst_entry *dst,

static bool has_gateway(const struct dst_entry *dst, sa_family_t family)
{
	const struct rtable *rt;
	const struct rt6_info *rt6;
	if (family == AF_INET)
		return dst_rtable(dst)->rt_uses_gateway;

	if (family == AF_INET) {
		rt = container_of(dst, struct rtable, dst);
		return rt->rt_uses_gateway;
	}

	rt6 = dst_rt6_info(dst);
	return rt6->rt6i_flags & RTF_GATEWAY;
	return dst_rt6_info(dst)->rt6i_flags & RTF_GATEWAY;
}

static int fetch_ha(const struct dst_entry *dst, struct rdma_dev_addr *dev_addr,
+1 −1
Original line number Diff line number Diff line
@@ -860,7 +860,7 @@ static int vrf_rt6_create(struct net_device *dev)
static int vrf_finish_output(struct net *net, struct sock *sk, struct sk_buff *skb)
{
	struct dst_entry *dst = skb_dst(skb);
	struct rtable *rt = (struct rtable *)dst;
	struct rtable *rt = dst_rtable(dst);
	struct net_device *dev = dst->dev;
	unsigned int hh_len = LL_RESERVED_SPACE(dev);
	struct neighbour *neigh;
+2 −3
Original line number Diff line number Diff line
@@ -970,9 +970,8 @@ static inline struct dst_entry *qeth_dst_check_rcu(struct sk_buff *skb,
static inline __be32 qeth_next_hop_v4_rcu(struct sk_buff *skb,
					  struct dst_entry *dst)
{
	struct rtable *rt = (struct rtable *) dst;

	return (rt) ? rt_nexthop(rt, ip_hdr(skb)->daddr) : ip_hdr(skb)->daddr;
	return (dst) ? rt_nexthop(dst_rtable(dst), ip_hdr(skb)->daddr) :
		       ip_hdr(skb)->daddr;
}

static inline struct in6_addr *qeth_next_hop_v6_rcu(struct sk_buff *skb,
+0 −9
Original line number Diff line number Diff line
@@ -1180,15 +1180,6 @@ static inline bool skb_dst_is_noref(const struct sk_buff *skb)
	return (skb->_skb_refdst & SKB_DST_NOREF) && skb_dst(skb);
}

/**
 * skb_rtable - Returns the skb &rtable
 * @skb: buffer
 */
static inline struct rtable *skb_rtable(const struct sk_buff *skb)
{
	return (struct rtable *)skb_dst(skb);
}

/* For mangling skb->pkt_type from user space side from applications
 * such as nft, tc, etc, we only allow a conservative subset of
 * possible pkt_types to be set.
+2 −2
Original line number Diff line number Diff line
@@ -423,7 +423,7 @@ int ip_decrease_ttl(struct iphdr *iph)

static inline int ip_mtu_locked(const struct dst_entry *dst)
{
	const struct rtable *rt = (const struct rtable *)dst;
	const struct rtable *rt = dst_rtable(dst);

	return rt->rt_mtu_locked || dst_metric_locked(dst, RTAX_MTU);
}
@@ -461,7 +461,7 @@ static inline bool ip_sk_ignore_df(const struct sock *sk)
static inline unsigned int ip_dst_mtu_maybe_forward(const struct dst_entry *dst,
						    bool forwarding)
{
	const struct rtable *rt = container_of(dst, struct rtable, dst);
	const struct rtable *rt = dst_rtable(dst);
	struct net *net = dev_net(dst->dev);
	unsigned int mtu;

Loading