提交 962924fa 编写于 作者: W wenxu 提交者: David S. Miller

ip_gre: Refactor collect metatdata mode tunnel xmit to ip_md_tunnel_xmit

Refactor collect metatdata mode tunnel xmit to the generic xmit function
ip_md_tunnel_xmit. It makes codes more generic and support more feture
such as pmtu_update through ip_md_tunnel_xmit
Signed-off-by: Nwenxu <wenxu@ucloud.cn>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 6e6b904a
...@@ -458,81 +458,14 @@ static int gre_handle_offloads(struct sk_buff *skb, bool csum) ...@@ -458,81 +458,14 @@ static int gre_handle_offloads(struct sk_buff *skb, bool csum)
return iptunnel_handle_offloads(skb, csum ? SKB_GSO_GRE_CSUM : SKB_GSO_GRE); return iptunnel_handle_offloads(skb, csum ? SKB_GSO_GRE_CSUM : SKB_GSO_GRE);
} }
static struct rtable *gre_get_rt(struct sk_buff *skb,
struct net_device *dev,
struct flowi4 *fl,
const struct ip_tunnel_key *key)
{
struct net *net = dev_net(dev);
memset(fl, 0, sizeof(*fl));
fl->daddr = key->u.ipv4.dst;
fl->saddr = key->u.ipv4.src;
fl->flowi4_tos = RT_TOS(key->tos);
fl->flowi4_mark = skb->mark;
fl->flowi4_proto = IPPROTO_GRE;
return ip_route_output_key(net, fl);
}
static struct rtable *prepare_fb_xmit(struct sk_buff *skb,
struct net_device *dev,
struct flowi4 *fl,
int tunnel_hlen)
{
struct ip_tunnel_info *tun_info;
const struct ip_tunnel_key *key;
struct rtable *rt = NULL;
int min_headroom;
bool use_cache;
int err;
tun_info = skb_tunnel_info(skb);
key = &tun_info->key;
use_cache = ip_tunnel_dst_cache_usable(skb, tun_info);
if (use_cache)
rt = dst_cache_get_ip4(&tun_info->dst_cache, &fl->saddr);
if (!rt) {
rt = gre_get_rt(skb, dev, fl, key);
if (IS_ERR(rt))
goto err_free_skb;
if (use_cache)
dst_cache_set_ip4(&tun_info->dst_cache, &rt->dst,
fl->saddr);
}
min_headroom = LL_RESERVED_SPACE(rt->dst.dev) + rt->dst.header_len
+ tunnel_hlen + sizeof(struct iphdr);
if (skb_headroom(skb) < min_headroom || skb_header_cloned(skb)) {
int head_delta = SKB_DATA_ALIGN(min_headroom -
skb_headroom(skb) +
16);
err = pskb_expand_head(skb, max_t(int, head_delta, 0),
0, GFP_ATOMIC);
if (unlikely(err))
goto err_free_rt;
}
return rt;
err_free_rt:
ip_rt_put(rt);
err_free_skb:
kfree_skb(skb);
dev->stats.tx_dropped++;
return NULL;
}
static void gre_fb_xmit(struct sk_buff *skb, struct net_device *dev, static void gre_fb_xmit(struct sk_buff *skb, struct net_device *dev,
__be16 proto) __be16 proto)
{ {
struct ip_tunnel *tunnel = netdev_priv(dev); struct ip_tunnel *tunnel = netdev_priv(dev);
struct ip_tunnel_info *tun_info; struct ip_tunnel_info *tun_info;
const struct ip_tunnel_key *key; const struct ip_tunnel_key *key;
struct rtable *rt = NULL;
struct flowi4 fl;
int tunnel_hlen; int tunnel_hlen;
__be16 df, flags; __be16 flags;
tun_info = skb_tunnel_info(skb); tun_info = skb_tunnel_info(skb);
if (unlikely(!tun_info || !(tun_info->mode & IP_TUNNEL_INFO_TX) || if (unlikely(!tun_info || !(tun_info->mode & IP_TUNNEL_INFO_TX) ||
...@@ -542,13 +475,12 @@ static void gre_fb_xmit(struct sk_buff *skb, struct net_device *dev, ...@@ -542,13 +475,12 @@ static void gre_fb_xmit(struct sk_buff *skb, struct net_device *dev,
key = &tun_info->key; key = &tun_info->key;
tunnel_hlen = gre_calc_hlen(key->tun_flags); tunnel_hlen = gre_calc_hlen(key->tun_flags);
rt = prepare_fb_xmit(skb, dev, &fl, tunnel_hlen); if (skb_cow_head(skb, dev->needed_headroom))
if (!rt) goto err_free_skb;
return;
/* Push Tunnel header. */ /* Push Tunnel header. */
if (gre_handle_offloads(skb, !!(tun_info->key.tun_flags & TUNNEL_CSUM))) if (gre_handle_offloads(skb, !!(tun_info->key.tun_flags & TUNNEL_CSUM)))
goto err_free_rt; goto err_free_skb;
flags = tun_info->key.tun_flags & flags = tun_info->key.tun_flags &
(TUNNEL_CSUM | TUNNEL_KEY | TUNNEL_SEQ); (TUNNEL_CSUM | TUNNEL_KEY | TUNNEL_SEQ);
...@@ -556,14 +488,10 @@ static void gre_fb_xmit(struct sk_buff *skb, struct net_device *dev, ...@@ -556,14 +488,10 @@ static void gre_fb_xmit(struct sk_buff *skb, struct net_device *dev,
tunnel_id_to_key32(tun_info->key.tun_id), tunnel_id_to_key32(tun_info->key.tun_id),
(flags & TUNNEL_SEQ) ? htonl(tunnel->o_seqno++) : 0); (flags & TUNNEL_SEQ) ? htonl(tunnel->o_seqno++) : 0);
df = key->tun_flags & TUNNEL_DONT_FRAGMENT ? htons(IP_DF) : 0; ip_md_tunnel_xmit(skb, dev, IPPROTO_GRE, tunnel_hlen);
iptunnel_xmit(skb->sk, rt, skb, fl.saddr, key->u.ipv4.dst, IPPROTO_GRE,
key->tos, key->ttl, df, false);
return; return;
err_free_rt:
ip_rt_put(rt);
err_free_skb: err_free_skb:
kfree_skb(skb); kfree_skb(skb);
dev->stats.tx_dropped++; dev->stats.tx_dropped++;
...@@ -575,10 +503,8 @@ static void erspan_fb_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -575,10 +503,8 @@ static void erspan_fb_xmit(struct sk_buff *skb, struct net_device *dev)
struct ip_tunnel_info *tun_info; struct ip_tunnel_info *tun_info;
const struct ip_tunnel_key *key; const struct ip_tunnel_key *key;
struct erspan_metadata *md; struct erspan_metadata *md;
struct rtable *rt = NULL;
bool truncate = false; bool truncate = false;
__be16 df, proto; __be16 proto;
struct flowi4 fl;
int tunnel_hlen; int tunnel_hlen;
int version; int version;
int nhoff; int nhoff;
...@@ -591,21 +517,20 @@ static void erspan_fb_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -591,21 +517,20 @@ static void erspan_fb_xmit(struct sk_buff *skb, struct net_device *dev)
key = &tun_info->key; key = &tun_info->key;
if (!(tun_info->key.tun_flags & TUNNEL_ERSPAN_OPT)) if (!(tun_info->key.tun_flags & TUNNEL_ERSPAN_OPT))
goto err_free_rt; goto err_free_skb;
md = ip_tunnel_info_opts(tun_info); md = ip_tunnel_info_opts(tun_info);
if (!md) if (!md)
goto err_free_rt; goto err_free_skb;
/* ERSPAN has fixed 8 byte GRE header */ /* ERSPAN has fixed 8 byte GRE header */
version = md->version; version = md->version;
tunnel_hlen = 8 + erspan_hdr_len(version); tunnel_hlen = 8 + erspan_hdr_len(version);
rt = prepare_fb_xmit(skb, dev, &fl, tunnel_hlen); if (skb_cow_head(skb, dev->needed_headroom))
if (!rt) goto err_free_skb;
return;
if (gre_handle_offloads(skb, false)) if (gre_handle_offloads(skb, false))
goto err_free_rt; goto err_free_skb;
if (skb->len > dev->mtu + dev->hard_header_len) { if (skb->len > dev->mtu + dev->hard_header_len) {
pskb_trim(skb, dev->mtu + dev->hard_header_len); pskb_trim(skb, dev->mtu + dev->hard_header_len);
...@@ -634,20 +559,16 @@ static void erspan_fb_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -634,20 +559,16 @@ static void erspan_fb_xmit(struct sk_buff *skb, struct net_device *dev)
truncate, true); truncate, true);
proto = htons(ETH_P_ERSPAN2); proto = htons(ETH_P_ERSPAN2);
} else { } else {
goto err_free_rt; goto err_free_skb;
} }
gre_build_header(skb, 8, TUNNEL_SEQ, gre_build_header(skb, 8, TUNNEL_SEQ,
proto, 0, htonl(tunnel->o_seqno++)); proto, 0, htonl(tunnel->o_seqno++));
df = key->tun_flags & TUNNEL_DONT_FRAGMENT ? htons(IP_DF) : 0; ip_md_tunnel_xmit(skb, dev, IPPROTO_GRE, tunnel_hlen);
iptunnel_xmit(skb->sk, rt, skb, fl.saddr, key->u.ipv4.dst, IPPROTO_GRE,
key->tos, key->ttl, df, false);
return; return;
err_free_rt:
ip_rt_put(rt);
err_free_skb: err_free_skb:
kfree_skb(skb); kfree_skb(skb);
dev->stats.tx_dropped++; dev->stats.tx_dropped++;
...@@ -656,13 +577,18 @@ static void erspan_fb_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -656,13 +577,18 @@ static void erspan_fb_xmit(struct sk_buff *skb, struct net_device *dev)
static int gre_fill_metadata_dst(struct net_device *dev, struct sk_buff *skb) static int gre_fill_metadata_dst(struct net_device *dev, struct sk_buff *skb)
{ {
struct ip_tunnel_info *info = skb_tunnel_info(skb); struct ip_tunnel_info *info = skb_tunnel_info(skb);
const struct ip_tunnel_key *key;
struct rtable *rt; struct rtable *rt;
struct flowi4 fl4; struct flowi4 fl4;
if (ip_tunnel_info_af(info) != AF_INET) if (ip_tunnel_info_af(info) != AF_INET)
return -EINVAL; return -EINVAL;
rt = gre_get_rt(skb, dev, &fl4, &info->key); key = &info->key;
ip_tunnel_init_flow(&fl4, IPPROTO_GRE, key->u.ipv4.dst, key->u.ipv4.src,
tunnel_id_to_key32(key->tun_id), key->tos, 0,
skb->mark);
rt = ip_route_output_key(dev_net(dev), &fl4);
if (IS_ERR(rt)) if (IS_ERR(rt))
return PTR_ERR(rt); return PTR_ERR(rt);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册