Skip to content

Commit 2ff378b

Browse files
amirvdavem330
authored andcommitted
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: Amir Vadai <amir@vadai.me> Signed-off-by: Hadar Hen Zion <hadarh@mellanox.com> Acked-by: Jiri Pirko <jiri@mellanox.com> Reviewed-by: Shmulik Ladkani <shmulik.ladkani@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent d817f43 commit 2ff378b

File tree

1 file changed

+39
-13
lines changed

1 file changed

+39
-13
lines changed

include/net/dst_metadata.h

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -112,30 +112,44 @@ static inline struct ip_tunnel_info *skb_tunnel_info_unclone(struct sk_buff *skb
112112
return &dst->u.tun_info;
113113
}
114114

115-
static inline struct metadata_dst *ip_tun_rx_dst(struct sk_buff *skb,
116-
__be16 flags,
117-
__be64 tunnel_id,
118-
int md_size)
115+
static inline struct metadata_dst *__ip_tun_set_dst(__be32 saddr,
116+
__be32 daddr,
117+
__u8 tos, __u8 ttl,
118+
__be16 flags,
119+
__be64 tunnel_id,
120+
int md_size)
119121
{
120-
const struct iphdr *iph = ip_hdr(skb);
121122
struct metadata_dst *tun_dst;
122123

123124
tun_dst = tun_rx_dst(md_size);
124125
if (!tun_dst)
125126
return NULL;
126127

127128
ip_tunnel_key_init(&tun_dst->u.tun_info.key,
128-
iph->saddr, iph->daddr, iph->tos, iph->ttl,
129+
saddr, daddr, tos, ttl,
129130
0, 0, 0, tunnel_id, flags);
130131
return tun_dst;
131132
}
132133

133-
static inline struct metadata_dst *ipv6_tun_rx_dst(struct sk_buff *skb,
134+
static inline struct metadata_dst *ip_tun_rx_dst(struct sk_buff *skb,
134135
__be16 flags,
135136
__be64 tunnel_id,
136137
int md_size)
137138
{
138-
const struct ipv6hdr *ip6h = ipv6_hdr(skb);
139+
const struct iphdr *iph = ip_hdr(skb);
140+
141+
return __ip_tun_set_dst(iph->saddr, iph->daddr, iph->tos, iph->ttl,
142+
flags, tunnel_id, md_size);
143+
}
144+
145+
static inline struct metadata_dst *__ipv6_tun_set_dst(const struct in6_addr *saddr,
146+
const struct in6_addr *daddr,
147+
__u8 tos, __u8 ttl,
148+
__be32 label,
149+
__be16 flags,
150+
__be64 tunnel_id,
151+
int md_size)
152+
{
139153
struct metadata_dst *tun_dst;
140154
struct ip_tunnel_info *info;
141155

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

153-
info->key.u.ipv6.src = ip6h->saddr;
154-
info->key.u.ipv6.dst = ip6h->daddr;
167+
info->key.u.ipv6.src = *saddr;
168+
info->key.u.ipv6.dst = *daddr;
155169

156-
info->key.tos = ipv6_get_dsfield(ip6h);
157-
info->key.ttl = ip6h->hop_limit;
158-
info->key.label = ip6_flowlabel(ip6h);
170+
info->key.tos = tos;
171+
info->key.ttl = ttl;
172+
info->key.label = label;
159173

160174
return tun_dst;
161175
}
162176

177+
static inline struct metadata_dst *ipv6_tun_rx_dst(struct sk_buff *skb,
178+
__be16 flags,
179+
__be64 tunnel_id,
180+
int md_size)
181+
{
182+
const struct ipv6hdr *ip6h = ipv6_hdr(skb);
183+
184+
return __ipv6_tun_set_dst(&ip6h->saddr, &ip6h->daddr,
185+
ipv6_get_dsfield(ip6h), ip6h->hop_limit,
186+
ip6_flowlabel(ip6h), flags, tunnel_id,
187+
md_size);
188+
}
163189
#endif /* __NET_DST_METADATA_H */

0 commit comments

Comments
 (0)