From 7ab1fb2a8d5d83380d63400781370297f2502e9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20K=C4=99pie=C5=84?= Date: Mon, 3 Jun 2019 14:13:23 +0200 Subject: [PATCH 1/7] Fix on BSD systems Current versions of DragonFly BSD, FreeBSD, NetBSD, and OpenBSD all support the modern variants of functions converting values between host and big-endian/little-endian byte order while older ones might not. Ensure works properly in both cases. --- lib/isc/include/isc/endian.h | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/isc/include/isc/endian.h b/lib/isc/include/isc/endian.h index 35ea578b33..f713cec025 100644 --- a/lib/isc/include/isc/endian.h +++ b/lib/isc/include/isc/endian.h @@ -39,18 +39,24 @@ # define __LITTLE_ENDIAN LITTLE_ENDIAN # define __PDP_ENDIAN PDP_ENDIAN -#elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__) +#elif defined(__DragonFly__) || defined(__FreeBSD__) || \ + defined(__NetBSD__) || defined (__OpenBSD__) || defined(__bsdi__) # include -# define be16toh(x) betoh16(x) -# define le16toh(x) letoh16(x) - -# define be32toh(x) betoh32(x) -# define le32toh(x) letoh32(x) - -# define be64toh(x) betoh64(x) -# define le64toh(x) letoh64(x) +/* + * Recent BSDs should have [bl]e{16,32,64}toh() defined in . + * Older ones might not, but these should have the alternatively named + * [bl]etoh{16,32,64}() functions defined. + */ +# ifndef be16toh +# define be16toh(x) betoh16(x) +# define le16toh(x) letoh16(x) +# define be32toh(x) betoh32(x) +# define le32toh(x) letoh32(x) +# define be64toh(x) betoh64(x) +# define le64toh(x) letoh64(x) +# endif /* !be16toh */ #elif defined(_WIN32) /* Windows is always little endian */ From 85059c293771806910e57a017804aea80315bade Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Mon, 3 Jun 2019 14:13:23 +0200 Subject: [PATCH 2/7] Add fallback definitions to Since the hto[bl]e{16,32,64}() and [bl]e{16,32,64}toh() conversion functions are nonstandard, add fallback definitions of these functions to , so that their unavailability does not prevent compilation from succeeding. --- lib/isc/include/isc/endian.h | 88 +++++++++++++++++++++++++++++++++++- 1 file changed, 86 insertions(+), 2 deletions(-) diff --git a/lib/isc/include/isc/endian.h b/lib/isc/include/isc/endian.h index f713cec025..1e4433e4ac 100644 --- a/lib/isc/include/isc/endian.h +++ b/lib/isc/include/isc/endian.h @@ -85,6 +85,90 @@ #else -#error Platform not supported +#endif /* Specific platform support */ -#endif +/* + * Fallback definitions. + */ + +#include + +#ifndef bswap_16 +# define bswap_16(x) \ + ((uint16_t)((((uint16_t) (x) & 0xff00) >> 8) | \ + (((uint16_t) (x) & 0x00ff) << 8))) +#endif /* !bswap_16 */ + +#ifndef bswap_32 +# define bswap_32(x) \ + ((uint32_t)((((uint32_t) (x) & 0xff000000) >> 24) | \ + (((uint32_t) (x) & 0x00ff0000) >> 8) | \ + (((uint32_t) (x) & 0x0000ff00) << 8) | \ + (((uint32_t) (x) & 0x000000ff) << 24))) +#endif /* !bswap_32 */ + +#ifndef bswap_64 +# define bswap_64(x) \ + ((uint64_t)((((uint64_t) (x) & 0xff00000000000000ULL) >> 56) | \ + (((uint64_t) (x) & 0x00ff000000000000ULL) >> 40) | \ + (((uint64_t) (x) & 0x0000ff0000000000ULL) >> 24) | \ + (((uint64_t) (x) & 0x000000ff00000000ULL) >> 8) | \ + (((uint64_t) (x) & 0x00000000ff000000ULL) << 8) | \ + (((uint64_t) (x) & 0x0000000000ff0000ULL) << 24) | \ + (((uint64_t) (x) & 0x000000000000ff00ULL) << 40) | \ + (((uint64_t) (x) & 0x00000000000000ffULL) << 56))) +#endif /* !bswap_64 */ + +#ifndef htobe16 +# if WORDS_BIGENDIAN + +# define htobe16(x) (x) +# define htole16(x) bswap_16(x) +# define be16toh(x) (x) +# define le16toh(x) bswap_16(x) + +# else /* WORDS_BIGENDIAN */ + +# define htobe16(x) bswap_16(x) +# define htole16(x) (x) +# define be16toh(x) bswap_16(x) +# define le16toh(x) (x) + +# endif /* WORDS_BIGENDIAN */ +#endif /* !htobe16 */ + +#ifndef htobe32 +# if WORDS_BIGENDIAN + +# define htobe32(x) (x) +# define htole32(x) bswap_32(x) +# define be32toh(x) (x) +# define le32toh(x) bswap_32(x) + +# else /* WORDS_BIGENDIAN */ + +# define htobe32(x) bswap_32(x) +# define htole32(x) (x) +# define be32toh(x) bswap_32(x) +# define le32toh(x) (x) + +# endif /* WORDS_BIGENDIAN */ +#endif /* !htobe32 */ + +#ifndef htobe64 +# if WORDS_BIGENDIAN + +# define htobe64(x) (x) +# define htole64(x) bswap_64(x) +# define be64toh(x) (x) +# define le64toh(x) bswap_64(x) + +#else /* WORDS_BIGENDIAN */ + +# define htobe64(x) bswap_64(x) +# define htole64(x) (x) +# define be64toh(x) bswap_64(x) +# define le64toh(x) (x) + +# endif /* WORDS_BIGENDIAN */ +#endif /* !htobe64 */ From 387cc001210bfdb40ae131ad0974aeb5858c616d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Mon, 3 Jun 2019 14:13:23 +0200 Subject: [PATCH 3/7] Add Solaris support for While Solaris does not support the nonstandard hto[bl]e{16,32,64}() and [bl]e{16,32,64}toh() conversion functions, it does have some byte-swapping macros available in . Ensure these macros are used in the fallback definitions of the aforementioned nonstandard functions. --- lib/isc/include/isc/endian.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/isc/include/isc/endian.h b/lib/isc/include/isc/endian.h index 1e4433e4ac..98a26dafac 100644 --- a/lib/isc/include/isc/endian.h +++ b/lib/isc/include/isc/endian.h @@ -83,6 +83,19 @@ # define __LITTLE_ENDIAN LITTLE_ENDIAN # define __PDP_ENDIAN PDP_ENDIAN +#elif defined(sun) || defined(__sun) || defined(__SVR4) + +/* + * For Solaris, rely on the fallback definitions below, though use + * Solaris-specific versions of bswap_{16,32,64}(). + */ + +# include + +# define bswap_16(x) BSWAP_16(x) +# define bswap_32(x) BSWAP_32(x) +# define bswap_64(x) BSWAP_64(x) + #else #endif /* Specific platform support */ From 2e54b1be2901c5b687169ad4d6f0f9017ae9493d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Mon, 3 Jun 2019 14:13:23 +0200 Subject: [PATCH 4/7] Make detect GNU rather than Linux Instead of only supporting Linux, try making support other GNU platforms as well. Since some compilers define __GNUC__ on BSDs (e.g. Clang on FreeBSD), move the relevant section to the bottom of the platform-specific part of , so that it only gets evaluated when more specific platform determination criteria are not met. Also include so that any byte-swapping macros which may be defined in that file on older platforms are used in the fallback definitions of the nonstandard hto[bl]e{16,32,64}() and [bl]e{16,32,64}toh() conversion functions. --- lib/isc/include/isc/endian.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/isc/include/isc/endian.h b/lib/isc/include/isc/endian.h index 98a26dafac..30a8f1e076 100644 --- a/lib/isc/include/isc/endian.h +++ b/lib/isc/include/isc/endian.h @@ -11,11 +11,7 @@ #pragma once -#if defined(__linux__) || defined(__CYGWIN__) - -#include - -#elif defined __APPLE__ +#if defined __APPLE__ #include @@ -96,6 +92,12 @@ # define bswap_32(x) BSWAP_32(x) # define bswap_64(x) BSWAP_64(x) +#elif defined(__ANDROID__) || defined(__CYGWIN__) || \ + defined(__GNUC__) || defined(__GNU__) + +# include +# include + #else #endif /* Specific platform support */ From 7e05848870faa4a935e4023948921569f0350416 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Mon, 3 Jun 2019 14:13:23 +0200 Subject: [PATCH 5/7] Revise the macOS section of Move the macOS section of to a lower spot as it is believed not to be the most popular platform for running BIND. Add a comment and remove redundant definitions. --- lib/isc/include/isc/endian.h | 51 ++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/lib/isc/include/isc/endian.h b/lib/isc/include/isc/endian.h index 30a8f1e076..f0ceab6417 100644 --- a/lib/isc/include/isc/endian.h +++ b/lib/isc/include/isc/endian.h @@ -11,32 +11,8 @@ #pragma once -#if defined __APPLE__ - -#include - -# define htobe16(x) OSSwapHostToBigInt16(x) -# define htole16(x) OSSwapHostToLittleInt16(x) -# define be16toh(x) OSSwapBigToHostInt16(x) -# define le16toh(x) OSSwapLittleToHostInt16(x) - -# define htobe32(x) OSSwapHostToBigInt32(x) -# define htole32(x) OSSwapHostToLittleInt32(x) -# define be32toh(x) OSSwapBigToHostInt32(x) -# define le32toh(x) OSSwapLittleToHostInt32(x) - -# define htobe64(x) OSSwapHostToBigInt64(x) -# define htole64(x) OSSwapHostToLittleInt64(x) -# define be64toh(x) OSSwapBigToHostInt64(x) -# define le64toh(x) OSSwapLittleToHostInt64(x) - -# define __BYTE_ORDER BYTE_ORDER -# define __BIG_ENDIAN BIG_ENDIAN -# define __LITTLE_ENDIAN LITTLE_ENDIAN -# define __PDP_ENDIAN PDP_ENDIAN - -#elif defined(__DragonFly__) || defined(__FreeBSD__) || \ - defined(__NetBSD__) || defined (__OpenBSD__) || defined(__bsdi__) +#if defined(__DragonFly__) || defined(__FreeBSD__) || \ + defined(__NetBSD__) || defined (__OpenBSD__) || defined(__bsdi__) # include @@ -79,6 +55,29 @@ # define __LITTLE_ENDIAN LITTLE_ENDIAN # define __PDP_ENDIAN PDP_ENDIAN +#elif defined __APPLE__ + +/* + * macOS has its own byte-swapping routines, so use these. + */ + +# include + +# define htobe16(x) OSSwapHostToBigInt16(x) +# define htole16(x) OSSwapHostToLittleInt16(x) +# define be16toh(x) OSSwapBigToHostInt16(x) +# define le16toh(x) OSSwapLittleToHostInt16(x) + +# define htobe32(x) OSSwapHostToBigInt32(x) +# define htole32(x) OSSwapHostToLittleInt32(x) +# define be32toh(x) OSSwapBigToHostInt32(x) +# define le32toh(x) OSSwapLittleToHostInt32(x) + +# define htobe64(x) OSSwapHostToBigInt64(x) +# define htole64(x) OSSwapHostToLittleInt64(x) +# define be64toh(x) OSSwapBigToHostInt64(x) +# define le64toh(x) OSSwapLittleToHostInt64(x) + #elif defined(sun) || defined(__sun) || defined(__SVR4) /* From 14ecd7d79e49fdbd795a68246f898210cdb605b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Mon, 3 Jun 2019 14:13:23 +0200 Subject: [PATCH 6/7] Revise the Windows section of Add a comment and remove redundant definitions. --- lib/isc/include/isc/endian.h | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/isc/include/isc/endian.h b/lib/isc/include/isc/endian.h index f0ceab6417..54421d55d4 100644 --- a/lib/isc/include/isc/endian.h +++ b/lib/isc/include/isc/endian.h @@ -31,9 +31,13 @@ # endif /* !be16toh */ #elif defined(_WIN32) -/* Windows is always little endian */ -#include +/* + * Windows is always little-endian and has its own byte-swapping routines, so + * use these. + */ + +# include # define htobe16(x) _byteswap_ushort(x) # define htole16(x) (x) @@ -50,11 +54,6 @@ # define be64toh(x) _byteswap_uint64(x) # define le64toh(x) (x) -# define __BYTE_ORDER BYTE_ORDER -# define __BIG_ENDIAN BIG_ENDIAN -# define __LITTLE_ENDIAN LITTLE_ENDIAN -# define __PDP_ENDIAN PDP_ENDIAN - #elif defined __APPLE__ /* From c0e0643fc5c0b1329167e0afbcc05a3fa9d865d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20K=C4=99pie=C5=84?= Date: Mon, 3 Jun 2019 14:13:23 +0200 Subject: [PATCH 7/7] Make ifconfig.sh work on DragonFly BSD On DragonFly BSD, use the same commands for configuring network interfaces used during system tests as on NetBSD and OpenBSD. --- bin/tests/system/ifconfig.sh | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/bin/tests/system/ifconfig.sh b/bin/tests/system/ifconfig.sh index aab6eb534b..fe410ecd5a 100755 --- a/bin/tests/system/ifconfig.sh +++ b/bin/tests/system/ifconfig.sh @@ -92,13 +92,7 @@ case "$1" in [ "$ipv6" ] && ifconfig lo0 inet6 \ fd92:7065:b8e:${ipv6}ff::$ns alias ;; - *-unknown-netbsd*) - ifconfig lo0 10.53.$i.$ns alias \ - netmask 255.255.255.0 - [ "$ipv6" ] && ifconfig lo0 inet6 \ - fd92:7065:b8e:${ipv6}ff::$ns alias - ;; - *-unknown-openbsd*) + *-unknown-dragonfly*|*-unknown-netbsd*|*-unknown-openbsd*) ifconfig lo0 10.53.$i.$ns alias \ netmask 255.255.255.0 [ "$ipv6" ] && ifconfig lo0 inet6 \