[ovs-dev] sparse: Add guards to prevent FreeBSD-incompatible #include order.

Message ID 20171106224232.27296-1-blp@ovn.org
State New
Headers show
Series
  • [ovs-dev] sparse: Add guards to prevent FreeBSD-incompatible #include order.
Related show

Commit Message

Ben Pfaff Nov. 6, 2017, 10:42 p.m.
FreeBSD insists that <sys/types.h> be included before <netinet/in.h> and
that <netinet/in.h> be included before <arpa/inet.h>.  This adds guards to
the "sparse" headers to yield a warning if this order is violated.  This
commit also adjusts the order of many #includes to suit this requirement.

Signed-off-by: Ben Pfaff <blp@ovn.org>
---
 configure.ac                                | 1 +
 include/openvswitch/packets.h               | 1 +
 include/sparse/arpa/inet.h                  | 4 ++++
 include/sparse/automake.mk                  | 1 +
 include/sparse/netinet/in.h                 | 6 ++++++
 include/sparse/{arpa/inet.h => sys/types.h} | 5 +++--
 lib/bfd.c                                   | 1 +
 lib/bundle.c                                | 2 ++
 lib/bundle.h                                | 2 ++
 lib/byte-order.h                            | 3 ++-
 lib/classifier.c                            | 1 +
 lib/csum.c                                  | 1 +
 lib/dpctl.c                                 | 3 ++-
 lib/dpif-netdev.c                           | 1 +
 lib/learning-switch.c                       | 1 +
 lib/lldp/lldpd-structs.h                    | 4 +---
 lib/lldp/lldpd.c                            | 3 ++-
 lib/lldp/lldpd.h                            | 4 +---
 lib/multipath.c                             | 4 ++--
 lib/netdev-linux.c                          | 4 ++--
 lib/netdev-native-tnl.c                     | 1 +
 lib/netdev-vport.c                          | 1 +
 lib/netdev.c                                | 2 +-
 lib/netlink.h                               | 1 +
 lib/odp-execute.c                           | 3 ++-
 lib/odp-util.c                              | 3 ++-
 lib/ofp-actions.c                           | 2 ++
 lib/ofp-ed-props.c                          | 2 ++
 lib/ofp-parse.c                             | 1 +
 lib/ovs-lldp.c                              | 4 ++--
 lib/ovs-router.c                            | 3 ++-
 lib/ovs-router.h                            | 1 +
 lib/packets.c                               | 4 ++--
 lib/route-table.c                           | 2 ++
 lib/rstp-state-machines.c                   | 4 ++--
 lib/rstp.c                                  | 4 ++--
 lib/sflow_api.h                             | 6 +++---
 lib/smap.h                                  | 1 +
 lib/socket-util.c                           | 2 ++
 lib/stream.c                                | 1 +
 lib/tc.h                                    | 1 +
 lib/util.h                                  | 2 ++
 lib/vconn.c                                 | 1 +
 ofproto/in-band.c                           | 2 ++
 ofproto/in-band.h                           | 1 +
 ofproto/netflow.c                           | 2 ++
 ofproto/ofproto-dpif-xlate-cache.c          | 3 ++-
 ofproto/ofproto-dpif-xlate-cache.h          | 1 +
 ofproto/ofproto-dpif-xlate.c                | 3 ++-
 ovn/lib/ovn-l7.h                            | 1 +
 tests/test-csum.c                           | 1 +
 tests/test-sflow.c                          | 2 ++
 utilities/ovs-dpctl.c                       | 3 ++-
 53 files changed, 90 insertions(+), 33 deletions(-)
 copy include/sparse/{arpa/inet.h => sys/types.h} (85%)

Patch

diff --git a/configure.ac b/configure.ac
index 9e00818327a9..cddae6dc15d2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -111,6 +111,7 @@  AC_CHECK_MEMBERS([struct ifreq.ifr_flagshigh], [], [], [[#include <net/if.h>]])
 AC_CHECK_MEMBERS([struct mmsghdr.msg_len], [], [], [[#include <sys/socket.h>]])
 AC_CHECK_MEMBERS([struct sockaddr_in6.sin6_scope_id], [], [],
   [[#include <sys/socket.h>
+#include <sys/types.h>
 #include <netinet/in.h>]])
 AC_CHECK_FUNCS([mlockall strnlen getloadavg statvfs getmntent_r sendmmsg clock_gettime])
 AC_CHECK_HEADERS([mntent.h sys/statvfs.h linux/types.h linux/if_ether.h stdatomic.h])
diff --git a/include/openvswitch/packets.h b/include/openvswitch/packets.h
index be91e02daa60..51b1aa3468a2 100644
--- a/include/openvswitch/packets.h
+++ b/include/openvswitch/packets.h
@@ -17,6 +17,7 @@ 
 #ifndef OPENVSWITCH_PACKETS_H
 #define OPENVSWITCH_PACKETS_H 1
 
+#include <sys/types.h>
 #include <netinet/in.h>
 #include "openvswitch/tun-metadata.h"
 
diff --git a/include/sparse/arpa/inet.h b/include/sparse/arpa/inet.h
index dd64e61764e8..3634b230c8bb 100644
--- a/include/sparse/arpa/inet.h
+++ b/include/sparse/arpa/inet.h
@@ -18,4 +18,8 @@ 
 #error "Use this header only with sparse.  It is not a correct implementation."
 #endif
 
+#ifndef NETINET_IN_H_INCLUDED
+#error "Must include <netinet/in.h> before <arpa/inet.h> for FreeBSD support"
+#endif
+
 #include <netinet/in.h>
diff --git a/include/sparse/automake.mk b/include/sparse/automake.mk
index f3282c260414..e9b42f52ccb7 100644
--- a/include/sparse/automake.mk
+++ b/include/sparse/automake.mk
@@ -13,4 +13,5 @@  noinst_HEADERS += \
         include/sparse/rte_memcpy.h \
         include/sparse/rte_vect.h \
         include/sparse/sys/socket.h \
+        include/sparse/sys/types.h \
         include/sparse/sys/wait.h
diff --git a/include/sparse/netinet/in.h b/include/sparse/netinet/in.h
index c28158ca02f5..6abdb2331e23 100644
--- a/include/sparse/netinet/in.h
+++ b/include/sparse/netinet/in.h
@@ -18,6 +18,12 @@ 
 #error "Use this header only with sparse.  It is not a correct implementation."
 #endif
 
+#define NETINET_IN_H_INCLUDED 1
+
+#ifndef SYS_TYPES_H_INCLUDED
+#error "Must include <sys/types.h> before <netinet/in.h> for FreeBSD support"
+#endif
+
 #ifndef _NETINET_IN_H
 #define _NETINET_IN_H 1
 
diff --git a/include/sparse/arpa/inet.h b/include/sparse/sys/types.h
similarity index 85%
copy from include/sparse/arpa/inet.h
copy to include/sparse/sys/types.h
index dd64e61764e8..9bae5ae73924 100644
--- a/include/sparse/arpa/inet.h
+++ b/include/sparse/sys/types.h
@@ -1,5 +1,5 @@ 
 /*
- * Copyright (c) 2011 Nicira, Inc.
+ * Copyright (c) 2011, 2013, 2014, 2015, 2017 Nicira, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -18,4 +18,5 @@ 
 #error "Use this header only with sparse.  It is not a correct implementation."
 #endif
 
-#include <netinet/in.h>
+#define SYS_TYPES_H_INCLUDED 1
+#include_next <sys/types.h>
diff --git a/lib/bfd.c b/lib/bfd.c
index 40cd0beb9f12..482e779ea697 100644
--- a/lib/bfd.c
+++ b/lib/bfd.c
@@ -16,6 +16,7 @@ 
 #include "bfd.h"
 
 #include <sys/types.h>
+#include <netinet/in.h>
 #include <arpa/inet.h>
 #include <netinet/in_systm.h>
 #include <netinet/ip.h>
diff --git a/lib/bundle.c b/lib/bundle.c
index e6705a085999..a58d8d247270 100644
--- a/lib/bundle.c
+++ b/lib/bundle.c
@@ -17,6 +17,8 @@ 
 
 #include "bundle.h"
 
+#include <sys/types.h>
+#include <netinet/in.h>
 #include <arpa/inet.h>
 #include <inttypes.h>
 
diff --git a/lib/bundle.h b/lib/bundle.h
index 21f353f67f09..85a2e861d367 100644
--- a/lib/bundle.h
+++ b/lib/bundle.h
@@ -16,6 +16,8 @@ 
 #ifndef BUNDLE_H
 #define BUNDLE_H 1
 
+#include <sys/types.h>
+#include <netinet/in.h>
 #include <arpa/inet.h>
 #include <stdbool.h>
 #include <stddef.h>
diff --git a/lib/byte-order.h b/lib/byte-order.h
index b2a9082bbada..66d29a2b37da 100644
--- a/lib/byte-order.h
+++ b/lib/byte-order.h
@@ -16,8 +16,9 @@ 
 #ifndef BYTE_ORDER_H
 #define BYTE_ORDER_H 1
 
-#include <arpa/inet.h>
 #include <sys/types.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
 #include <inttypes.h>
 #include "openvswitch/types.h"
 
diff --git a/lib/classifier.c b/lib/classifier.c
index ca0650afb423..16c451da1b30 100644
--- a/lib/classifier.c
+++ b/lib/classifier.c
@@ -18,6 +18,7 @@ 
 #include "classifier.h"
 #include "classifier-private.h"
 #include <errno.h>
+#include <sys/types.h>
 #include <netinet/in.h>
 #include "byte-order.h"
 #include "openvswitch/dynamic-string.h"
diff --git a/lib/csum.c b/lib/csum.c
index 6419043aa519..eaa05ad98c03 100644
--- a/lib/csum.c
+++ b/lib/csum.c
@@ -17,6 +17,7 @@ 
 #include <config.h>
 #include "csum.h"
 #include "unaligned.h"
+#include <sys/types.h>
 #include <netinet/in.h>
 
 #ifndef __CHECKER__
diff --git a/lib/dpctl.c b/lib/dpctl.c
index 8055cdb56202..437316012fd4 100644
--- a/lib/dpctl.c
+++ b/lib/dpctl.c
@@ -15,12 +15,13 @@ 
  */
 
 #include <config.h>
+#include <sys/types.h>
+#include <netinet/in.h>
 #include <arpa/inet.h>
 #include <errno.h>
 #include <inttypes.h>
 #include <sys/socket.h>
 #include <net/if.h>
-#include <netinet/in.h>
 #include <stdarg.h>
 #include <stdlib.h>
 #include <string.h>
diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c
index 599308d257a8..3c6c46204298 100644
--- a/lib/dpif-netdev.c
+++ b/lib/dpif-netdev.c
@@ -22,6 +22,7 @@ 
 #include <fcntl.h>
 #include <inttypes.h>
 #include <net/if.h>
+#include <sys/types.h>
 #include <netinet/in.h>
 #include <stdint.h>
 #include <stdlib.h>
diff --git a/lib/learning-switch.c b/lib/learning-switch.c
index 6b02e93892a9..5b014e5f3757 100644
--- a/lib/learning-switch.c
+++ b/lib/learning-switch.c
@@ -19,6 +19,7 @@ 
 
 #include <errno.h>
 #include <inttypes.h>
+#include <sys/types.h>
 #include <netinet/in.h>
 #include <stdlib.h>
 #include <time.h>
diff --git a/lib/lldp/lldpd-structs.h b/lib/lldp/lldpd-structs.h
index 15e5ce8fa75d..6a3ffb8d33f0 100644
--- a/lib/lldp/lldpd-structs.h
+++ b/lib/lldp/lldpd-structs.h
@@ -20,11 +20,9 @@ 
 #define _LLDPD_STRUCTS_H
 
 #include <net/if.h>
-#ifndef _WIN32
+#include <sys/types.h>
 #include <netinet/in.h>
-#endif
 #include <sys/socket.h>
-#include <sys/types.h>
 #include "aa-structs.h"
 #include "lldp-const.h"
 #include "packets.h"
diff --git a/lib/lldp/lldpd.c b/lib/lldp/lldpd.c
index e9d1cf18e036..ff5e62846275 100644
--- a/lib/lldp/lldpd.c
+++ b/lib/lldp/lldpd.c
@@ -18,6 +18,8 @@ 
 
 #include <config.h>
 #include "lldpd.h"
+#include <sys/types.h>
+#include <netinet/in.h>
 #include <arpa/inet.h>
 #include <errno.h>
 #include <fcntl.h>
@@ -28,7 +30,6 @@ 
 #include <sys/socket.h>
 #include <sys/stat.h>
 #include <sys/time.h>
-#include <sys/types.h>
 #include <sys/wait.h>
 #include <unistd.h>
 #ifndef _WIN32
diff --git a/lib/lldp/lldpd.h b/lib/lldp/lldpd.h
index f77c6d52312e..5267c112af5e 100644
--- a/lib/lldp/lldpd.h
+++ b/lib/lldp/lldpd.h
@@ -19,13 +19,11 @@ 
 #ifndef _LLDPD_H
 #define _LLDPD_H
 
-#ifndef _WIN32
+#include <sys/types.h>
 #include <netinet/in.h>
-#endif
 #include <stdlib.h>
 #include <stddef.h>
 #include <string.h>
-#include <sys/types.h>
 #include "dp-packet.h"
 #include "openvswitch/list.h"
 #include "lldpd-structs.h"
diff --git a/lib/multipath.c b/lib/multipath.c
index 19e3d33e790d..fdbf94ea6947 100644
--- a/lib/multipath.c
+++ b/lib/multipath.c
@@ -17,10 +17,10 @@ 
 #include <config.h>
 
 #include "multipath.h"
-#include <arpa/inet.h>
-#include <inttypes.h>
 #include <sys/types.h>
 #include <netinet/in.h>
+#include <arpa/inet.h>
+#include <inttypes.h>
 #include "colors.h"
 #include "nx-match.h"
 #include "openflow/nicira-ext.h"
diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c
index fbbbb7205e67..d5f881225495 100644
--- a/lib/netdev-linux.c
+++ b/lib/netdev-linux.c
@@ -20,6 +20,8 @@ 
 
 #include <errno.h>
 #include <fcntl.h>
+#include <sys/types.h>
+#include <netinet/in.h>
 #include <arpa/inet.h>
 #include <inttypes.h>
 #include <linux/filter.h>
@@ -31,7 +33,6 @@ 
 #include <linux/mii.h>
 #include <linux/rtnetlink.h>
 #include <linux/sockios.h>
-#include <sys/types.h>
 #include <sys/ioctl.h>
 #include <sys/socket.h>
 #include <sys/utsname.h>
@@ -40,7 +41,6 @@ 
 #include <net/if_arp.h>
 #include <net/if_packet.h>
 #include <net/route.h>
-#include <netinet/in.h>
 #include <poll.h>
 #include <stdlib.h>
 #include <string.h>
diff --git a/lib/netdev-native-tnl.c b/lib/netdev-native-tnl.c
index 3264810f39c9..9ce856798414 100644
--- a/lib/netdev-native-tnl.c
+++ b/lib/netdev-native-tnl.c
@@ -23,6 +23,7 @@ 
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <net/if.h>
+#include <sys/types.h>
 #include <netinet/in.h>
 #include <netinet/ip.h>
 #include <netinet/ip6.h>
diff --git a/lib/netdev-vport.c b/lib/netdev-vport.c
index 518058a1f114..f72025e5b1a8 100644
--- a/lib/netdev-vport.c
+++ b/lib/netdev-vport.c
@@ -23,6 +23,7 @@ 
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <net/if.h>
+#include <sys/types.h>
 #include <netinet/in.h>
 #include <netinet/ip6.h>
 #include <sys/ioctl.h>
diff --git a/lib/netdev.c b/lib/netdev.c
index 704b38f7368e..cfe6a152d09d 100644
--- a/lib/netdev.c
+++ b/lib/netdev.c
@@ -19,6 +19,7 @@ 
 
 #include <errno.h>
 #include <inttypes.h>
+#include <sys/types.h>
 #include <netinet/in.h>
 #include <stdlib.h>
 #include <string.h>
@@ -28,7 +29,6 @@ 
 #include <ifaddrs.h>
 #include <net/if.h>
 #include <sys/ioctl.h>
-#include <sys/types.h>
 #endif
 
 #include "cmap.h"
diff --git a/lib/netlink.h b/lib/netlink.h
index 6dfac27c9d4b..638d166b331e 100644
--- a/lib/netlink.h
+++ b/lib/netlink.h
@@ -31,6 +31,7 @@ 
  * Linux-specific definitions for Netlink sockets, see netlink-socket.h.
  */
 
+#include <sys/types.h>
 #include <netinet/in.h>
 #include <stdbool.h>
 #include <stddef.h>
diff --git a/lib/odp-execute.c b/lib/odp-execute.c
index 3109f39bc8c6..3ba5b89e9259 100644
--- a/lib/odp-execute.c
+++ b/lib/odp-execute.c
@@ -17,8 +17,9 @@ 
 
 #include <config.h>
 #include "odp-execute.h"
-#include <arpa/inet.h>
+#include <sys/types.h>
 #include <netinet/in.h>
+#include <arpa/inet.h>
 #include <netinet/icmp6.h>
 #include <netinet/ip6.h>
 #include <stdlib.h>
diff --git a/lib/odp-util.c b/lib/odp-util.c
index 6304b3dd299a..3e54f935d9d7 100644
--- a/lib/odp-util.c
+++ b/lib/odp-util.c
@@ -15,12 +15,13 @@ 
  */
 
 #include <config.h>
+#include <sys/types.h>
+#include <netinet/in.h>
 #include <arpa/inet.h>
 #include "odp-util.h"
 #include <errno.h>
 #include <inttypes.h>
 #include <math.h>
-#include <netinet/in.h>
 #include <netinet/icmp6.h>
 #include <netinet/ip6.h>
 #include <stdlib.h>
diff --git a/lib/ofp-actions.c b/lib/ofp-actions.c
index e5d03e155543..a59962fc3153 100644
--- a/lib/ofp-actions.c
+++ b/lib/ofp-actions.c
@@ -15,6 +15,8 @@ 
  */
 
 #include <config.h>
+
+#include <sys/types.h>
 #include <netinet/in.h>
 
 #include "bundle.h"
diff --git a/lib/ofp-ed-props.c b/lib/ofp-ed-props.c
index eb168fee3903..d7bb72f35dbd 100644
--- a/lib/ofp-ed-props.c
+++ b/lib/ofp-ed-props.c
@@ -15,6 +15,8 @@ 
  */
 
 #include <config.h>
+#include <sys/types.h>
+#include <netinet/in.h>
 #include <arpa/inet.h>
 #include "openvswitch/ofp-ed-props.h"
 #include "openvswitch/ofp-util.h"
diff --git a/lib/ofp-parse.c b/lib/ofp-parse.c
index 0c68495bfd3e..bacbaa63886e 100644
--- a/lib/ofp-parse.c
+++ b/lib/ofp-parse.c
@@ -19,6 +19,7 @@ 
 #include <ctype.h>
 #include <errno.h>
 #include <stdlib.h>
+#include <sys/types.h>
 #include <netinet/in.h>
 
 #include "byte-order.h"
diff --git a/lib/ovs-lldp.c b/lib/ovs-lldp.c
index 43dd06d6f249..a866b77a160f 100644
--- a/lib/ovs-lldp.c
+++ b/lib/ovs-lldp.c
@@ -28,12 +28,12 @@ 
 
 #include <config.h>
 #include "ovs-lldp.h"
+#include <sys/types.h>
+#include <netinet/in.h>
 #include <arpa/inet.h>
 #include <inttypes.h>
-#include <netinet/in.h>
 #include <stdbool.h>
 #include <stdlib.h>
-#include <sys/types.h>
 #include "openvswitch/dynamic-string.h"
 #include "flow.h"
 #include "openvswitch/list.h"
diff --git a/lib/ovs-router.c b/lib/ovs-router.c
index ce2f80b387a7..cd2ab15fb003 100644
--- a/lib/ovs-router.c
+++ b/lib/ovs-router.c
@@ -18,12 +18,13 @@ 
 
 #include "ovs-router.h"
 
+#include <sys/types.h>
+#include <netinet/in.h>
 #include <arpa/inet.h>
 #include <errno.h>
 #include <inttypes.h>
 #include <sys/socket.h>
 #include <net/if.h>
-#include <netinet/in.h>
 #include <stdarg.h>
 #include <stdlib.h>
 #include <string.h>
diff --git a/lib/ovs-router.h b/lib/ovs-router.h
index 29c7c5fe18d5..b55b1a50b146 100644
--- a/lib/ovs-router.h
+++ b/lib/ovs-router.h
@@ -17,6 +17,7 @@ 
 #ifndef OVS_TNL_ROUTER_H
 #define OVS_TNL_ROUTER_H 1
 
+#include <sys/types.h>
 #include <netinet/in.h>
 
 #include "util.h"
diff --git a/lib/packets.c b/lib/packets.c
index 51044df4c786..b9905f8d9711 100644
--- a/lib/packets.c
+++ b/lib/packets.c
@@ -16,13 +16,13 @@ 
 
 #include <config.h>
 #include "packets.h"
+#include <sys/types.h>
+#include <netinet/in.h>
 #include <arpa/inet.h>
 #include <sys/socket.h>
-#include <netinet/in.h>
 #include <netinet/ip6.h>
 #include <netinet/icmp6.h>
 #include <stdlib.h>
-#include <sys/types.h>
 #include <netdb.h>
 #include "byte-order.h"
 #include "csum.h"
diff --git a/lib/route-table.c b/lib/route-table.c
index 4e40c37b424f..97a0be5c573a 100644
--- a/lib/route-table.c
+++ b/lib/route-table.c
@@ -19,6 +19,8 @@ 
 #include "route-table.h"
 
 #include <errno.h>
+#include <sys/types.h>
+#include <netinet/in.h>
 #include <arpa/inet.h>
 #include <sys/socket.h>
 #include <linux/rtnetlink.h>
diff --git a/lib/rstp-state-machines.c b/lib/rstp-state-machines.c
index 8fdaec953916..7d677d7a2401 100644
--- a/lib/rstp-state-machines.c
+++ b/lib/rstp-state-machines.c
@@ -31,11 +31,11 @@ 
 #include <config.h>
 #include "rstp.h"
 #include "rstp-state-machines.h"
+#include <sys/types.h>
+#include <netinet/in.h>
 #include <arpa/inet.h>
 #include <inttypes.h>
-#include <netinet/in.h>
 #include <stdlib.h>
-#include <sys/types.h>
 #include "byte-order.h"
 #include "connectivity.h"
 #include "openvswitch/ofpbuf.h"
diff --git a/lib/rstp.c b/lib/rstp.c
index 5d71a437412e..7a61b24d7b36 100644
--- a/lib/rstp.c
+++ b/lib/rstp.c
@@ -32,11 +32,11 @@ 
 #include "rstp.h"
 #include "rstp-common.h"
 #include "rstp-state-machines.h"
+#include <sys/types.h>
+#include <netinet/in.h>
 #include <arpa/inet.h>
 #include <inttypes.h>
-#include <netinet/in.h>
 #include <stdlib.h>
-#include <sys/types.h>
 #include "byte-order.h"
 #include "connectivity.h"
 #include "openvswitch/ofpbuf.h"
diff --git a/lib/sflow_api.h b/lib/sflow_api.h
index 2730a4cf4a27..7264fc1c588d 100644
--- a/lib/sflow_api.h
+++ b/lib/sflow_api.h
@@ -13,18 +13,18 @@ 
    callback in sfl_agent_init.*/
 /* #define SFLOW_DO_SOCKET */
 
+#include <sys/types.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <errno.h>
 #include <string.h>
-#include <sys/types.h>
-#include <arpa/inet.h> /* for htonl */
 
 #ifdef SFLOW_DO_SOCKET
 #include <sys/socket.h>
 #include <netinet/in_systm.h>
-#include <netinet/in.h>
 #include <netinet/ip.h>
 #endif
 
diff --git a/lib/smap.h b/lib/smap.h
index edf591cf156d..82e4ce13d7c8 100644
--- a/lib/smap.h
+++ b/lib/smap.h
@@ -15,6 +15,7 @@ 
 #ifndef SMAP_H
 #define SMAP_H 1
 
+#include <sys/types.h>
 #include <netinet/in.h>
 #include "hash.h"
 #include "openvswitch/hmap.h"
diff --git a/lib/socket-util.c b/lib/socket-util.c
index 055593d3572e..7fbcdf19feac 100644
--- a/lib/socket-util.c
+++ b/lib/socket-util.c
@@ -16,6 +16,8 @@ 
 
 #include <config.h>
 #include "socket-util.h"
+#include <sys/types.h>
+#include <netinet/in.h>
 #include <arpa/inet.h>
 #include <ctype.h>
 #include <errno.h>
diff --git a/lib/stream.c b/lib/stream.c
index 9cef18e843c7..083e2fb93f77 100644
--- a/lib/stream.c
+++ b/lib/stream.c
@@ -18,6 +18,7 @@ 
 #include "stream-provider.h"
 #include <errno.h>
 #include <inttypes.h>
+#include <sys/types.h>
 #include <netinet/in.h>
 #include <poll.h>
 #include <stdlib.h>
diff --git a/lib/tc.h b/lib/tc.h
index 6c69b7905599..5d54b41c3d0f 100644
--- a/lib/tc.h
+++ b/lib/tc.h
@@ -18,6 +18,7 @@ 
 #ifndef TC_H
 #define TC_H 1
 
+#include <sys/types.h>
 #include <netinet/in.h> /* Must happen before linux/pkt_cls.h - Glibc #20215 */
 #include <linux/pkt_cls.h>
 #include <linux/pkt_sched.h>
diff --git a/lib/util.h b/lib/util.h
index 3c43c2c355e2..70d479533984 100644
--- a/lib/util.h
+++ b/lib/util.h
@@ -17,6 +17,8 @@ 
 #ifndef UTIL_H
 #define UTIL_H 1
 
+#include <sys/types.h>
+#include <netinet/in.h>
 #include <arpa/inet.h>
 #include <inttypes.h>
 #include <limits.h>
diff --git a/lib/vconn.c b/lib/vconn.c
index 13623d87a7d9..bb56be2d2901 100644
--- a/lib/vconn.c
+++ b/lib/vconn.c
@@ -18,6 +18,7 @@ 
 #include "vconn-provider.h"
 #include <errno.h>
 #include <inttypes.h>
+#include <sys/types.h>
 #include <netinet/in.h>
 #include <poll.h>
 #include <stdlib.h>
diff --git a/ofproto/in-band.c b/ofproto/in-band.c
index 343dcfa1714e..849b1cedaff0 100644
--- a/ofproto/in-band.c
+++ b/ofproto/in-band.c
@@ -15,6 +15,8 @@ 
  */
 
 #include <config.h>
+#include <sys/types.h>
+#include <netinet/in.h>
 #include <arpa/inet.h>
 #include <errno.h>
 #include <inttypes.h>
diff --git a/ofproto/in-band.h b/ofproto/in-band.h
index 6e0585ad3c4e..3debd01284dd 100644
--- a/ofproto/in-band.h
+++ b/ofproto/in-band.h
@@ -20,6 +20,7 @@ 
 #include <stdbool.h>
 #include <stddef.h>
 #include <sys/socket.h>
+#include <sys/types.h>
 #include <netinet/in.h>
 #include "flow.h"
 
diff --git a/ofproto/netflow.c b/ofproto/netflow.c
index 783b9c94552b..b6baeb8268ab 100644
--- a/ofproto/netflow.c
+++ b/ofproto/netflow.c
@@ -16,6 +16,8 @@ 
 
 #include <config.h>
 #include "netflow.h"
+#include <sys/types.h>
+#include <netinet/in.h>
 #include <arpa/inet.h>
 #include <errno.h>
 #include <stdlib.h>
diff --git a/ofproto/ofproto-dpif-xlate-cache.c b/ofproto/ofproto-dpif-xlate-cache.c
index d319d287eadb..cdceb26f80c0 100644
--- a/ofproto/ofproto-dpif-xlate-cache.c
+++ b/ofproto/ofproto-dpif-xlate-cache.c
@@ -16,10 +16,11 @@ 
 
 #include "ofproto/ofproto-dpif-xlate-cache.h"
 
+#include <sys/types.h>
+#include <netinet/in.h>
 #include <arpa/inet.h>
 #include <errno.h>
 #include <net/if.h>
-#include <netinet/in.h>
 #include <sys/socket.h>
 
 #include "bfd.h"
diff --git a/ofproto/ofproto-dpif-xlate-cache.h b/ofproto/ofproto-dpif-xlate-cache.h
index e62719740cb2..19c1ef7b95ad 100644
--- a/ofproto/ofproto-dpif-xlate-cache.h
+++ b/ofproto/ofproto-dpif-xlate-cache.h
@@ -17,6 +17,7 @@ 
 
 #include <net/if.h>
 #include <sys/socket.h>
+#include <sys/types.h>
 #include <netinet/in.h>
 
 #include "openvswitch/types.h"
diff --git a/ofproto/ofproto-dpif-xlate.c b/ofproto/ofproto-dpif-xlate.c
index 468cd160c60e..18684040e729 100644
--- a/ofproto/ofproto-dpif-xlate.c
+++ b/ofproto/ofproto-dpif-xlate.c
@@ -17,10 +17,11 @@ 
 #include "ofproto/ofproto-dpif-xlate.h"
 
 #include <errno.h>
+#include <sys/types.h>
+#include <netinet/in.h>
 #include <arpa/inet.h>
 #include <net/if.h>
 #include <sys/socket.h>
-#include <netinet/in.h>
 
 #include "bfd.h"
 #include "bitmap.h"
diff --git a/ovn/lib/ovn-l7.h b/ovn/lib/ovn-l7.h
index 41cdacdfc30f..b8d6683bcdf4 100644
--- a/ovn/lib/ovn-l7.h
+++ b/ovn/lib/ovn-l7.h
@@ -17,6 +17,7 @@ 
 #ifndef OVN_DHCP_H
 #define OVN_DHCP_H 1
 
+#include <sys/types.h>
 #include <netinet/in.h>
 #include <netinet/icmp6.h>
 #include "openvswitch/hmap.h"
diff --git a/tests/test-csum.c b/tests/test-csum.c
index 97638b91605d..b94bd6481cdf 100644
--- a/tests/test-csum.c
+++ b/tests/test-csum.c
@@ -19,6 +19,7 @@ 
 #include "csum.h"
 #include <assert.h>
 #include <inttypes.h>
+#include <sys/types.h>
 #include <netinet/in.h>
 #include <netinet/ip.h>
 #include <stdio.h>
diff --git a/tests/test-sflow.c b/tests/test-sflow.c
index b70336b457bd..82e950273c4b 100644
--- a/tests/test-sflow.c
+++ b/tests/test-sflow.c
@@ -18,6 +18,8 @@ 
 #include <config.h>
 #undef NDEBUG
 #include "netflow.h"
+#include <sys/types.h>
+#include <netinet/in.h>
 #include <arpa/inet.h>
 #include <errno.h>
 #include <getopt.h>
diff --git a/utilities/ovs-dpctl.c b/utilities/ovs-dpctl.c
index 7b005ace3f4e..6b1f542c720f 100644
--- a/utilities/ovs-dpctl.c
+++ b/utilities/ovs-dpctl.c
@@ -15,13 +15,14 @@ 
  */
 
 #include <config.h>
+#include <sys/types.h>
+#include <netinet/in.h>
 #include <arpa/inet.h>
 #include <errno.h>
 #include <getopt.h>
 #include <inttypes.h>
 #include <sys/socket.h>
 #include <net/if.h>
-#include <netinet/in.h>
 #include <signal.h>
 #include <stdarg.h>
 #include <stdlib.h>