summaryrefslogtreecommitdiffstats
path: root/include/linux/etherdevice.h
diff options
context:
space:
mode:
authorAlexander Duyck <alexander.h.duyck@redhat.com>2015-05-04 14:33:48 -0700
committerDavid S. Miller <davem@davemloft.net>2015-05-05 19:24:42 -0400
commit2c7a88c252bf3381958cf716f31b6b2e0f2f3fa7 (patch)
tree8c242beda53e88b084af505aaa4039f1c1f3f2e6 /include/linux/etherdevice.h
parent784b58a327ad16967ab64bbfa558df81980d31e9 (diff)
downloadop-kernel-dev-2c7a88c252bf3381958cf716f31b6b2e0f2f3fa7.zip
op-kernel-dev-2c7a88c252bf3381958cf716f31b6b2e0f2f3fa7.tar.gz
etherdev: Fix sparse error, make test usable by other functions
This change does two things. First it fixes a sparse error for the fact that the __be16 degrades to an integer. Since that is actually what I am kind of doing I am simply working around that by forcing both sides of the comparison to u16. Also I realized on some compilers I was generating another instruction for big endian systems such as PowerPC since it was masking the value before doing the comparison. So to resolve that I have simply pulled the mask out and wrapped it in an #ifndef __BIG_ENDIAN. Lastly I pulled this all out into its own function. I notices there are similar checks in a number of other places so this function can be reused there to help reduce overhead in these paths as well. Signed-off-by: Alexander Duyck <alexander.h.duyck@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/linux/etherdevice.h')
-rw-r--r--include/linux/etherdevice.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/include/linux/etherdevice.h b/include/linux/etherdevice.h
index c4a10f9..9012f877 100644
--- a/include/linux/etherdevice.h
+++ b/include/linux/etherdevice.h
@@ -191,6 +191,24 @@ static inline bool is_valid_ether_addr(const u8 *addr)
}
/**
+ * eth_proto_is_802_3 - Determine if a given Ethertype/length is a protocol
+ * @proto: Ethertype/length value to be tested
+ *
+ * Check that the value from the Ethertype/length field is a valid Ethertype.
+ *
+ * Return true if the valid is an 802.3 supported Ethertype.
+ */
+static inline bool eth_proto_is_802_3(__be16 proto)
+{
+#ifndef __BIG_ENDIAN
+ /* if CPU is little endian mask off bits representing LSB */
+ proto &= htons(0xFF00);
+#endif
+ /* cast both to u16 and compare since LSB can be ignored */
+ return (__force u16)proto >= (__force u16)htons(ETH_P_802_3_MIN);
+}
+
+/**
* eth_random_addr - Generate software assigned random Ethernet address
* @addr: Pointer to a six-byte array containing the Ethernet address
*
OpenPOWER on IntegriCloud