[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1464043706-2843932-2-git-send-email-tom@herbertland.com>
Date: Mon, 23 May 2016 15:48:20 -0700
From: Tom Herbert <tom@...bertland.com>
To: <davem@...emloft.net>, <netdev@...r.kernel.org>
CC: <kernel-team@...com>
Subject: [RFC PATCH 1/7] fou: Get net from sock_net if dev_net unavailable
With the implementation of Transports over UDP fou and gue build header
may be called before skb->dev is set. This patch checks skb->dev and
if it is not set then tries to get net from sock_net.
Signed-off-by: Tom Herbert <tom@...bertland.com>
---
net/ipv4/fou.c | 22 ++++++++++++++++++----
1 file changed, 18 insertions(+), 4 deletions(-)
diff --git a/net/ipv4/fou.c b/net/ipv4/fou.c
index 5f9207c..96260c6 100644
--- a/net/ipv4/fou.c
+++ b/net/ipv4/fou.c
@@ -807,13 +807,20 @@ int __fou_build_header(struct sk_buff *skb, struct ip_tunnel_encap *e,
u8 *protocol, __be16 *sport, int type)
{
int err;
+ struct net *net;
err = iptunnel_handle_offloads(skb, type);
if (err)
return err;
- *sport = e->sport ? : udp_flow_src_port(dev_net(skb->dev),
- skb, 0, 0, false);
+ if (skb->dev)
+ net = dev_net(skb->dev);
+ else if (skb->sk)
+ net = sock_net(skb->sk);
+ else
+ return -EINVAL;
+
+ *sport = e->sport ? : udp_flow_src_port(net, skb, 0, 0, false);
return 0;
}
@@ -845,6 +852,14 @@ int __gue_build_header(struct sk_buff *skb, struct ip_tunnel_encap *e,
void *data;
bool need_priv = false;
int err;
+ struct net *net;
+
+ if (skb->dev)
+ net = dev_net(skb->dev);
+ else if (skb->sk)
+ net = sock_net(skb->sk);
+ else
+ return -EINVAL;
if ((e->flags & TUNNEL_ENCAP_FLAG_REMCSUM) &&
skb->ip_summed == CHECKSUM_PARTIAL) {
@@ -860,8 +875,7 @@ int __gue_build_header(struct sk_buff *skb, struct ip_tunnel_encap *e,
return err;
/* Get source port (based on flow hash) before skb_push */
- *sport = e->sport ? : udp_flow_src_port(dev_net(skb->dev),
- skb, 0, 0, false);
+ *sport = e->sport ? : udp_flow_src_port(net, skb, 0, 0, false);
hdrlen = sizeof(struct guehdr) + optlen;
--
2.8.0.rc2
Powered by blists - more mailing lists