From abf7c1c540f8330fead5d50730d92606dcbe7a7e Mon Sep 17 00:00:00 2001 From: Robert Shearman Date: Mon, 3 Aug 2015 17:39:20 +0100 Subject: lwtunnel: set skb protocol and dev In the locally-generated packet path skb->protocol may not be set and this is required for the lwtunnel encap in order to get the lwtstate. This would otherwise have been set by ip_output or ip6_output so set skb->protocol prior to calling the lwtunnel encap function. Additionally set skb->dev in case it is needed further down the transmit path. Signed-off-by: Robert Shearman Signed-off-by: David S. Miller --- net/core/lwtunnel.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/net/core/lwtunnel.c b/net/core/lwtunnel.c index c240c895b319..5d6d8e3d450a 100644 --- a/net/core/lwtunnel.c +++ b/net/core/lwtunnel.c @@ -215,8 +215,12 @@ int lwtunnel_output6(struct sock *sk, struct sk_buff *skb) struct rt6_info *rt = (struct rt6_info *)skb_dst(skb); struct lwtunnel_state *lwtstate = NULL; - if (rt) + if (rt) { lwtstate = rt->rt6i_lwtstate; + skb->dev = rt->dst.dev; + } + + skb->protocol = htons(ETH_P_IPV6); return __lwtunnel_output(sk, skb, lwtstate); } @@ -227,8 +231,12 @@ int lwtunnel_output(struct sock *sk, struct sk_buff *skb) struct rtable *rt = (struct rtable *)skb_dst(skb); struct lwtunnel_state *lwtstate = NULL; - if (rt) + if (rt) { lwtstate = rt->rt_lwtstate; + skb->dev = rt->dst.dev; + } + + skb->protocol = htons(ETH_P_IP); return __lwtunnel_output(sk, skb, lwtstate); } -- cgit v1.2.3 From 0335f5b500adcc28bc3fd5d8a1e4482c348cff4a Mon Sep 17 00:00:00 2001 From: Robert Shearman Date: Mon, 3 Aug 2015 17:39:21 +0100 Subject: ipv4: apply lwtunnel encap for locally-generated packets lwtunnel encap is applied for forwarded packets, but not for locally-generated packets. This is because the output function is not overridden in __mkroute_output, unlike it is in __mkroute_input. The lwtunnel state is correctly set on the rth through the call to rt_set_nexthop, so all that needs to be done is to override the dst output function to be lwtunnel_output if there is lwtunnel state present and it requires output redirection. Signed-off-by: Robert Shearman Signed-off-by: David S. Miller --- net/ipv4/route.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/ipv4/route.c b/net/ipv4/route.c index 908f7ef2f12a..18fd7c9095c7 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c @@ -2022,6 +2022,8 @@ add: } rt_set_nexthop(rth, fl4->daddr, res, fnhe, fi, type, 0); + if (lwtunnel_output_redirect(rth->rt_lwtstate)) + rth->dst.output = lwtunnel_output; return rth; } -- cgit v1.2.3