Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e760702e authored by Changli Gao's avatar Changli Gao Committed by David S. Miller
Browse files

net: introduce proto_ports_offset()



Introduce proto_ports_offset() for getting the position of the ports or
SPI in the message of a protocol.

Signed-off-by: default avatarChangli Gao <xiaosuo@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent dbe5775b
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -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);