All of lore.kernel.org
 help / color / mirror / Atom feed
* [net-next] ipv6: sr: Extract the right key values for "seg6_make_flowlabel"
@ 2018-04-26 14:11 Ahmed Abdelsalam
  2018-04-27 17:59 ` David Miller
  0 siblings, 1 reply; 3+ messages in thread
From: Ahmed Abdelsalam @ 2018-04-26 14:11 UTC (permalink / raw)
  To: davem, dav.lebrun, netdev, linux-kernel; +Cc: Ahmed Abdelsalam

The seg6_make_flowlabel() is used by seg6_do_srh_encap() to compute the
flowlabel from a given skb. It relies on skb_get_hash() which eventually
calls __skb_flow_dissect() to extract the flow_keys struct values from
the skb.

In case of IPv4 traffic, calling seg6_make_flowlabel() after skb_push(),
skb_reset_network_header(), and skb_mac_header_rebuild() will results in
flow_keys struct of all key values set to zero.

This patch calls seg6_make_flowlabel() before resetting the headers of skb
to get the right key values.

Extracted Key values are based on the type inner packet as follows:
1) IPv6 traffic: src_IP, dst_IP, L4 proto, and flowlabel of inner packet.
2) IPv4 traffic: src_IP, dst_IP, L4 proto, src_port, and dst_port
3) L2 traffic: depends on what kind of traffic carried into the L2
frame. IPv6 and IPv4 traffic works as discussed 1) and 2)

Signed-off-by: Ahmed Abdelsalam <amsalam20@gmail.com>
---
 net/ipv6/seg6_iptunnel.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/net/ipv6/seg6_iptunnel.c b/net/ipv6/seg6_iptunnel.c
index 9898926..0df83c0 100644
--- a/net/ipv6/seg6_iptunnel.c
+++ b/net/ipv6/seg6_iptunnel.c
@@ -119,6 +119,9 @@ int seg6_do_srh_encap(struct sk_buff *skb, struct ipv6_sr_hdr *osrh, int proto)
 	int hdrlen, tot_len, err;
 	__be32 flowlabel;
 
+	inner_hdr = ipv6_hdr(skb);
+	flowlabel = seg6_make_flowlabel(net, skb, inner_hdr);
+
 	hdrlen = (osrh->hdrlen + 1) << 3;
 	tot_len = hdrlen + sizeof(*hdr);
 
@@ -126,8 +129,6 @@ int seg6_do_srh_encap(struct sk_buff *skb, struct ipv6_sr_hdr *osrh, int proto)
 	if (unlikely(err))
 		return err;
 
-	inner_hdr = ipv6_hdr(skb);
-
 	skb_push(skb, tot_len);
 	skb_reset_network_header(skb);
 	skb_mac_header_rebuild(skb);
@@ -138,7 +139,6 @@ int seg6_do_srh_encap(struct sk_buff *skb, struct ipv6_sr_hdr *osrh, int proto)
 	 * decapsulation will overwrite inner hlim with outer hlim
 	 */
 
-	flowlabel = seg6_make_flowlabel(net, skb, inner_hdr);
 	if (skb->protocol == htons(ETH_P_IPV6)) {
 		ip6_flow_hdr(hdr, ip6_tclass(ip6_flowinfo(inner_hdr)),
 			     flowlabel);
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [net-next] ipv6: sr: Extract the right key values for "seg6_make_flowlabel"
  2018-04-26 14:11 [net-next] ipv6: sr: Extract the right key values for "seg6_make_flowlabel" Ahmed Abdelsalam
@ 2018-04-27 17:59 ` David Miller
  2018-04-28 10:20   ` Ahmed Abdelsalam
  0 siblings, 1 reply; 3+ messages in thread
From: David Miller @ 2018-04-27 17:59 UTC (permalink / raw)
  To: amsalam20; +Cc: dav.lebrun, netdev, linux-kernel

From: Ahmed Abdelsalam <amsalam20@gmail.com>
Date: Thu, 26 Apr 2018 16:11:11 +0200

> @@ -119,6 +119,9 @@ int seg6_do_srh_encap(struct sk_buff *skb, struct ipv6_sr_hdr *osrh, int proto)
>  	int hdrlen, tot_len, err;
>  	__be32 flowlabel;
>  
> +	inner_hdr = ipv6_hdr(skb);

You have to make this assignment after, not before, the skb_cow_header()
call.  Otherwise this point can be pointing to freed up memory.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [net-next] ipv6: sr: Extract the right key values for "seg6_make_flowlabel"
  2018-04-27 17:59 ` David Miller
@ 2018-04-28 10:20   ` Ahmed Abdelsalam
  0 siblings, 0 replies; 3+ messages in thread
From: Ahmed Abdelsalam @ 2018-04-28 10:20 UTC (permalink / raw)
  To: David Miller; +Cc: dav.lebrun, netdev, linux-kernel

On Fri, 27 Apr 2018 13:59:07 -0400 (EDT)
David Miller <davem@davemloft.net> wrote:

> From: Ahmed Abdelsalam <amsalam20@gmail.com>
> Date: Thu, 26 Apr 2018 16:11:11 +0200
> 
> > @@ -119,6 +119,9 @@ int seg6_do_srh_encap(struct sk_buff *skb, struct ipv6_sr_hdr *osrh, int proto)
> >  	int hdrlen, tot_len, err;
> >  	__be32 flowlabel;
> >  
> > +	inner_hdr = ipv6_hdr(skb);
> 
> You have to make this assignment after, not before, the skb_cow_header()
> call.  Otherwise this point can be pointing to freed up memory.

Ok! 
I fixed and sent you a v2 of the patch. 

-- 
Ahmed Abdelsalam <amsalam20@gmail.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-04-28 10:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-26 14:11 [net-next] ipv6: sr: Extract the right key values for "seg6_make_flowlabel" Ahmed Abdelsalam
2018-04-27 17:59 ` David Miller
2018-04-28 10:20   ` Ahmed Abdelsalam

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.