Skip to content

Commit

Permalink
sparse: Add guards to prevent FreeBSD-incompatible #include order.
Browse files Browse the repository at this point in the history
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>
Acked-by: Justin Pettit <jpettit@ovn.org>
  • Loading branch information
blp committed Dec 22, 2017
1 parent 9041097 commit b2befd5
Show file tree
Hide file tree
Showing 53 changed files with 109 additions and 31 deletions.
1 change: 1 addition & 0 deletions configure.ac
Expand Up @@ -105,6 +105,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])
Expand Down
1 change: 1 addition & 0 deletions include/openvswitch/packets.h
Expand Up @@ -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"

Expand Down
4 changes: 4 additions & 0 deletions include/sparse/arpa/inet.h
Expand Up @@ -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>
1 change: 1 addition & 0 deletions include/sparse/automake.mk
Expand Up @@ -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
6 changes: 6 additions & 0 deletions include/sparse/netinet/in.h
Expand Up @@ -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

Expand Down
22 changes: 22 additions & 0 deletions include/sparse/sys/types.h
@@ -0,0 +1,22 @@
/*
* 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.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef __CHECKER__
#error "Use this header only with sparse. It is not a correct implementation."
#endif

#define SYS_TYPES_H_INCLUDED 1
#include_next <sys/types.h>
1 change: 1 addition & 0 deletions lib/bfd.c
Expand Up @@ -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>
Expand Down
2 changes: 2 additions & 0 deletions lib/bundle.c
Expand Up @@ -17,6 +17,8 @@

#include "bundle.h"

#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <inttypes.h>

Expand Down
2 changes: 2 additions & 0 deletions lib/bundle.h
Expand Up @@ -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>
Expand Down
3 changes: 2 additions & 1 deletion lib/byte-order.h
Expand Up @@ -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"

Expand Down
1 change: 1 addition & 0 deletions lib/classifier.c
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions lib/csum.c
Expand Up @@ -17,6 +17,7 @@
#include <config.h>
#include "csum.h"
#include "unaligned.h"
#include <sys/types.h>
#include <netinet/in.h>

#ifndef __CHECKER__
Expand Down
3 changes: 2 additions & 1 deletion lib/dpctl.c
Expand Up @@ -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>
Expand Down
1 change: 1 addition & 0 deletions lib/dpif-netdev.c
Expand Up @@ -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>
Expand Down
1 change: 1 addition & 0 deletions lib/learning-switch.c
Expand Up @@ -19,6 +19,7 @@

#include <errno.h>
#include <inttypes.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <time.h>
Expand Down
4 changes: 1 addition & 3 deletions lib/lldp/lldpd-structs.h
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion lib/lldp/lldpd.c
Expand Up @@ -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>
Expand All @@ -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
Expand Down
4 changes: 1 addition & 3 deletions lib/lldp/lldpd.h
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions lib/multipath.c
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions lib/netdev-linux.c
Expand Up @@ -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>
Expand All @@ -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>
Expand All @@ -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>
Expand Down
1 change: 1 addition & 0 deletions lib/netdev-native-tnl.c
Expand Up @@ -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>
Expand Down
1 change: 1 addition & 0 deletions lib/netdev-vport.c
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion lib/netdev.c
Expand Up @@ -19,6 +19,7 @@

#include <errno.h>
#include <inttypes.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <string.h>
Expand All @@ -28,7 +29,6 @@
#include <ifaddrs.h>
#include <net/if.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#endif

#include "cmap.h"
Expand Down
1 change: 1 addition & 0 deletions lib/netlink.h
Expand Up @@ -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>
Expand Down
3 changes: 2 additions & 1 deletion lib/odp-execute.c
Expand Up @@ -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>
Expand Down
3 changes: 2 additions & 1 deletion lib/odp-util.c
Expand Up @@ -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>
Expand Down
2 changes: 2 additions & 0 deletions lib/ofp-actions.c
Expand Up @@ -15,6 +15,8 @@
*/

#include <config.h>

#include <sys/types.h>
#include <netinet/in.h>

#include "bundle.h"
Expand Down
2 changes: 2 additions & 0 deletions lib/ofp-ed-props.c
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions lib/ofp-parse.c
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions lib/ovs-lldp.c
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion lib/ovs-router.c
Expand Up @@ -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>
Expand Down
1 change: 1 addition & 0 deletions lib/ovs-router.h
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions lib/packets.c
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions lib/route-table.c
Expand Up @@ -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>
Expand Down

0 comments on commit b2befd5

Please sign in to comment.