Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2ff378b7 authored by Amir Vadai's avatar Amir Vadai Committed by David S. Miller
Browse files

net/dst: Utility functions to build dst_metadata without supplying an skb



Extract __ip_tun_set_dst() and __ipv6_tun_set_dst() out of
ip_tun_rx_dst() and ipv6_tun_rx_dst(), to be used without supplying an
skb.

Signed-off-by: default avatarAmir Vadai <amir@vadai.me>
Signed-off-by: default avatarHadar Hen Zion <hadarh@mellanox.com>
Acked-by: default avatarJiri Pirko <jiri@mellanox.com>
Reviewed-by: default avatarShmulik Ladkani <shmulik.ladkani@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent d817f432
Loading
Loading
Loading
Loading
+39 −13
Original line number Original line Diff line number Diff line
@@ -112,12 +112,13 @@ static inline struct ip_tunnel_info *skb_tunnel_info_unclone(struct sk_buff *skb
	return &dst->u.tun_info;
	return &dst->u.tun_info;
}
}


static inline struct metadata_dst *ip_tun_rx_dst(struct sk_buff *skb,
static inline struct metadata_dst *__ip_tun_set_dst(__be32 saddr,
						    __be32 daddr,
						    __u8 tos, __u8 ttl,
						    __be16 flags,
						    __be16 flags,
						    __be64 tunnel_id,
						    __be64 tunnel_id,
						    int md_size)
						    int md_size)
{
{
	const struct iphdr *iph = ip_hdr(skb);
	struct metadata_dst *tun_dst;
	struct metadata_dst *tun_dst;


	tun_dst = tun_rx_dst(md_size);
	tun_dst = tun_rx_dst(md_size);
@@ -125,17 +126,30 @@ static inline struct metadata_dst *ip_tun_rx_dst(struct sk_buff *skb,
		return NULL;
		return NULL;


	ip_tunnel_key_init(&tun_dst->u.tun_info.key,
	ip_tunnel_key_init(&tun_dst->u.tun_info.key,
			   iph->saddr, iph->daddr, iph->tos, iph->ttl,
			   saddr, daddr, tos, ttl,
			   0, 0, 0, tunnel_id, flags);
			   0, 0, 0, tunnel_id, flags);
	return tun_dst;
	return tun_dst;
}
}


static inline struct metadata_dst *ipv6_tun_rx_dst(struct sk_buff *skb,
static inline struct metadata_dst *ip_tun_rx_dst(struct sk_buff *skb,
						 __be16 flags,
						 __be64 tunnel_id,
						 int md_size)
{
	const struct iphdr *iph = ip_hdr(skb);

	return __ip_tun_set_dst(iph->saddr, iph->daddr, iph->tos, iph->ttl,
				flags, tunnel_id, md_size);
}

static inline struct metadata_dst *__ipv6_tun_set_dst(const struct in6_addr *saddr,
						      const struct in6_addr *daddr,
						      __u8 tos, __u8 ttl,
						      __be32 label,
						      __be16 flags,
						      __be16 flags,
						      __be64 tunnel_id,
						      __be64 tunnel_id,
						      int md_size)
						      int md_size)
{
{
	const struct ipv6hdr *ip6h = ipv6_hdr(skb);
	struct metadata_dst *tun_dst;
	struct metadata_dst *tun_dst;
	struct ip_tunnel_info *info;
	struct ip_tunnel_info *info;


@@ -150,14 +164,26 @@ static inline struct metadata_dst *ipv6_tun_rx_dst(struct sk_buff *skb,
	info->key.tp_src = 0;
	info->key.tp_src = 0;
	info->key.tp_dst = 0;
	info->key.tp_dst = 0;


	info->key.u.ipv6.src = ip6h->saddr;
	info->key.u.ipv6.src = *saddr;
	info->key.u.ipv6.dst = ip6h->daddr;
	info->key.u.ipv6.dst = *daddr;


	info->key.tos = ipv6_get_dsfield(ip6h);
	info->key.tos = tos;
	info->key.ttl = ip6h->hop_limit;
	info->key.ttl = ttl;
	info->key.label = ip6_flowlabel(ip6h);
	info->key.label = label;


	return tun_dst;
	return tun_dst;
}
}


static inline struct metadata_dst *ipv6_tun_rx_dst(struct sk_buff *skb,
						   __be16 flags,
						   __be64 tunnel_id,
						   int md_size)
{
	const struct ipv6hdr *ip6h = ipv6_hdr(skb);

	return __ipv6_tun_set_dst(&ip6h->saddr, &ip6h->daddr,
				  ipv6_get_dsfield(ip6h), ip6h->hop_limit,
				  ip6_flowlabel(ip6h), flags, tunnel_id,
				  md_size);
}
#endif /* __NET_DST_METADATA_H */
#endif /* __NET_DST_METADATA_H */