Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Amir Vadai and committed by
David S. Miller
2ff378b7 d817f432

+39 -13
+39 -13
include/net/dst_metadata.h
··· 112 112 return &dst->u.tun_info; 113 113 } 114 114 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) 119 121 { 120 - const struct iphdr *iph = ip_hdr(skb); 121 122 struct metadata_dst *tun_dst; 122 123 123 124 tun_dst = tun_rx_dst(md_size); ··· 126 125 return NULL; 127 126 128 127 ip_tunnel_key_init(&tun_dst->u.tun_info.key, 129 - iph->saddr, iph->daddr, iph->tos, iph->ttl, 128 + saddr, daddr, tos, ttl, 130 129 0, 0, 0, tunnel_id, flags); 131 130 return tun_dst; 132 131 } 133 132 134 - static inline struct metadata_dst *ipv6_tun_rx_dst(struct sk_buff *skb, 133 + static inline struct metadata_dst *ip_tun_rx_dst(struct sk_buff *skb, 135 134 __be16 flags, 136 135 __be64 tunnel_id, 137 136 int md_size) 138 137 { 139 - const struct ipv6hdr *ip6h = ipv6_hdr(skb); 138 + const struct iphdr *iph = ip_hdr(skb); 139 + 140 + return __ip_tun_set_dst(iph->saddr, iph->daddr, iph->tos, iph->ttl, 141 + flags, tunnel_id, md_size); 142 + } 143 + 144 + static inline struct metadata_dst *__ipv6_tun_set_dst(const struct in6_addr *saddr, 145 + const struct in6_addr *daddr, 146 + __u8 tos, __u8 ttl, 147 + __be32 label, 148 + __be16 flags, 149 + __be64 tunnel_id, 150 + int md_size) 151 + { 140 152 struct metadata_dst *tun_dst; 141 153 struct ip_tunnel_info *info; 142 154 ··· 164 150 info->key.tp_src = 0; 165 151 info->key.tp_dst = 0; 166 152 167 - info->key.u.ipv6.src = ip6h->saddr; 168 - info->key.u.ipv6.dst = ip6h->daddr; 153 + info->key.u.ipv6.src = *saddr; 154 + info->key.u.ipv6.dst = *daddr; 169 155 170 - info->key.tos = ipv6_get_dsfield(ip6h); 171 - info->key.ttl = ip6h->hop_limit; 172 - info->key.label = ip6_flowlabel(ip6h); 156 + info->key.tos = tos; 157 + info->key.ttl = ttl; 158 + info->key.label = label; 173 159 174 160 return tun_dst; 175 161 } 176 162 163 + static inline struct metadata_dst *ipv6_tun_rx_dst(struct sk_buff *skb, 164 + __be16 flags, 165 + __be64 tunnel_id, 166 + int md_size) 167 + { 168 + const struct ipv6hdr *ip6h = ipv6_hdr(skb); 169 + 170 + return __ipv6_tun_set_dst(&ip6h->saddr, &ip6h->daddr, 171 + ipv6_get_dsfield(ip6h), ip6h->hop_limit, 172 + ip6_flowlabel(ip6h), flags, tunnel_id, 173 + md_size); 174 + } 177 175 #endif /* __NET_DST_METADATA_H */