net: introduce proto_ports_offset()
authorChangli Gao <xiaosuo@gmail.com>
Tue, 17 Aug 2010 19:03:44 +0000 (19:03 +0000)
committerDavid S. Miller <davem@davemloft.net>
Fri, 20 Aug 2010 00:16:23 +0000 (17:16 -0700)
Introduce proto_ports_offset() for getting the position of the ports or
SPI in the message of a protocol.

Signed-off-by: Changli Gao <xiaosuo@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/linux/in.h

index 41d88a4689af0a77a000cfc88437a70d8abdc1fb..beeb6dee2b49d416cc3f74537e920ca2ae93dd17 100644 (file)
@@ -250,6 +250,25 @@ struct sockaddr_in {
 
 #ifdef __KERNEL__
 
+#include <linux/errno.h>
+
+static inline int proto_ports_offset(int proto)
+{
+       switch (proto) {
+       case IPPROTO_TCP:
+       case IPPROTO_UDP:
+       case IPPROTO_DCCP:
+       case IPPROTO_ESP:       /* SPI */
+       case IPPROTO_SCTP:
+       case IPPROTO_UDPLITE:
+               return 0;
+       case IPPROTO_AH:        /* SPI */
+               return 4;
+       default:
+               return -EINVAL;
+       }
+}
+
 static inline bool ipv4_is_loopback(__be32 addr)
 {
        return (addr & htonl(0xff000000)) == htonl(0x7f000000);