datapath: check for backported proto_ports_offset
[cascardo/ovs.git] / datapath / linux / compat / include / linux / in.h
1 #ifndef __LINUX_IN_WRAPPER_H
2 #define __LINUX_IN_WRAPPER_H 1
3
4 #include_next <linux/in.h>
5
6 #include <linux/module.h>
7 #ifndef HAVE_PROTO_PORTS_OFFSET
8 static inline int proto_ports_offset(int proto)
9 {
10         switch (proto) {
11         case IPPROTO_TCP:
12         case IPPROTO_UDP:
13         case IPPROTO_DCCP:
14         case IPPROTO_ESP:       /* SPI */
15         case IPPROTO_SCTP:
16         case IPPROTO_UDPLITE:
17                 return 0;
18         case IPPROTO_AH:        /* SPI */
19                 return 4;
20         default:
21                 return -EINVAL;
22         }
23 }
24 #endif
25
26 #ifndef HAVE_IPV4_IS_MULTICAST
27
28 static inline bool ipv4_is_loopback(__be32 addr)
29 {
30         return (addr & htonl(0xff000000)) == htonl(0x7f000000);
31 }
32
33 static inline bool ipv4_is_multicast(__be32 addr)
34 {
35         return (addr & htonl(0xf0000000)) == htonl(0xe0000000);
36 }
37
38 static inline bool ipv4_is_local_multicast(__be32 addr)
39 {
40         return (addr & htonl(0xffffff00)) == htonl(0xe0000000);
41 }
42
43 static inline bool ipv4_is_lbcast(__be32 addr)
44 {
45         /* limited broadcast */
46         return addr == htonl(INADDR_BROADCAST);
47 }
48
49 static inline bool ipv4_is_zeronet(__be32 addr)
50 {
51         return (addr & htonl(0xff000000)) == htonl(0x00000000);
52 }
53
54 #endif /* !HAVE_IPV4_IS_MULTICAST */
55
56 #endif