All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net] net: Allow flow dissector to handle non 4-byte aligned headers
@ 2016-01-31 21:37 Tom Herbert
  2016-01-31 21:47 ` kbuild test robot
                   ` (4 more replies)
  0 siblings, 5 replies; 18+ messages in thread
From: Tom Herbert @ 2016-01-31 21:37 UTC (permalink / raw)
  To: davem, netdev; +Cc: sowmini.varadhan, kernel-team

Call get_unaligned_be32 when we access 32-bit fields in
__skb_flow_dissect. At the beginning check for unlikely case of
1-byte aligned packet.

Note that flow_dissector may be asked to parse packet unaligned
fields in two instances:

1) Packet from a driver which is aligned to Ethernet header
   (2-byte alignment)
2) Parsing inner headers of a received GRE-TEB packet

Testing: Ran super_netperf tests did not see a regression. This was on
x86 which does not have problems with unaligned data.

Signed-off-by: Tom Herbert <tom@herbertland.com>
---
 net/core/flow_dissector.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/net/core/flow_dissector.c b/net/core/flow_dissector.c
index d79699c..1c64a1a 100644
--- a/net/core/flow_dissector.c
+++ b/net/core/flow_dissector.c
@@ -95,7 +95,7 @@ __be32 __skb_flow_get_ports(const struct sk_buff *skb, int thoff, u8 ip_proto,
 		ports = __skb_header_pointer(skb, thoff + poff,
 					     sizeof(_ports), data, hlen, &_ports);
 		if (ports)
-			return *ports;
+			return get_unaligned_be32(ports);
 	}
 
 	return 0;
@@ -116,6 +116,10 @@ EXPORT_SYMBOL(__skb_flow_get_ports);
  * by flow_dissector from either the skbuff or a raw buffer specified by the
  * rest parameters.
  *
+ * This function does not assume 4-byte alignment, but it does assume 2-byte
+ * alignment (false is returned for 1-byte alignment). get_unaligned_be32
+ * is called to get thirty-two values out of the packet.
+ *
  * Caller must take care of zeroing target container memory.
  */
 bool __skb_flow_dissect(const struct sk_buff *skb,
@@ -140,6 +144,11 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
 		hlen = skb_headlen(skb);
 	}
 
+#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
+	if (WARN_ON(((u64)data & 0x1)))
+		return false;
+#endif
+
 	/* It is ensured by skb_flow_dissector_init() that control key will
 	 * be always present.
 	 */
@@ -230,7 +239,7 @@ ipv6:
 			key_control->addr_type = FLOW_DISSECTOR_KEY_IPV6_ADDRS;
 		}
 
-		flow_label = ip6_flowlabel(iph);
+		flow_label = get_unaligned_be32(iph) & IPV6_FLOWLABEL_MASK;
 		if (flow_label) {
 			if (dissector_uses_key(flow_dissector,
 					       FLOW_DISSECTOR_KEY_FLOW_LABEL)) {
@@ -303,7 +312,7 @@ ipv6:
 			key_addrs = skb_flow_dissector_target(flow_dissector,
 							      FLOW_DISSECTOR_KEY_TIPC_ADDRS,
 							      target_container);
-			key_addrs->tipcaddrs.srcnode = hdr->srcnode;
+			key_addrs->tipcaddrs.srcnode = get_unaligned_be32(&hdr->srcnode);
 			key_control->addr_type = FLOW_DISSECTOR_KEY_TIPC_ADDRS;
 		}
 		goto out_good;
@@ -325,7 +334,7 @@ mpls:
 				key_keyid = skb_flow_dissector_target(flow_dissector,
 								      FLOW_DISSECTOR_KEY_MPLS_ENTROPY,
 								      target_container);
-				key_keyid->keyid = hdr[1].entry &
+				key_keyid->keyid = get_unaligned_be32(&hdr[1].entry) &
 					htonl(MPLS_LS_LABEL_MASK);
 			}
 
@@ -379,7 +388,7 @@ ip_proto_again:
 				key_keyid = skb_flow_dissector_target(flow_dissector,
 								      FLOW_DISSECTOR_KEY_GRE_KEYID,
 								      target_container);
-				key_keyid->keyid = *keyid;
+				key_keyid->keyid = get_unaligned_be32(keyid);
 			}
 			nhoff += 4;
 		}
-- 
2.4.6

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

end of thread, other threads:[~2016-02-03 18:00 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-31 21:37 [PATCH net] net: Allow flow dissector to handle non 4-byte aligned headers Tom Herbert
2016-01-31 21:47 ` kbuild test robot
2016-01-31 22:06 ` Florian Westphal
2016-02-01  0:24 ` Eric Dumazet
2016-02-01  0:39   ` Florian Fainelli
2016-02-01 15:20     ` Nicolas Dichtel
2016-02-01 16:01       ` Sowmini Varadhan
2016-02-01  0:43   ` Sowmini Varadhan
2016-02-01 12:32 ` Sergei Shtylyov
2016-02-02  0:31 ` Sowmini Varadhan
2016-02-02  0:46   ` Tom Herbert
2016-02-02  3:56   ` Alexander Duyck
2016-02-02 13:41     ` Hannes Frederic Sowa
2016-02-02 18:35     ` Sowmini Varadhan
2016-02-03 17:07   ` Tom Herbert
2016-02-03 17:31     ` Sowmini Varadhan
2016-02-03 17:51       ` Tom Herbert
2016-02-03 17:59         ` Sowmini Varadhan

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.