Browse code

Fix IP_PKTINFO related compilation failure on NetBSD 7.0

NetBSD has introduced IP_PKTINFO and struct in_pktinfo, but does not
have the "ipi_spec_dst" structure element, causing compilation errors.

Introduce a check for that (AC_CHECK_MEMBER) in configure.ac, and
change all "#ifdef HAVE_IN_PKTINFO" to also check "HAVE_IPI_SPEC_DST".

Patch inspired by NetBSD pkgsrc patch set.

(Note: with that patch, OpenVPN --multihome is still broken for IPv4
on NetBSD 7.0.1 / amd64, but that's a different issue)

Signed-off-by: Gert Doering <gert@greenie.muc.de>
Acked-by: Arne Schwabe <arne@rfc2549.org>
Message-Id: <20160916190242.44897-1-gert@greenie.muc.de>
URL: http://www.mail-archive.com/search?l=mid&q=20160916190242.44897-1-gert@greenie.muc.de
Signed-off-by: Gert Doering <gert@greenie.muc.de>

Gert Doering authored on 2016/09/17 04:02:42
Showing 4 changed files
... ...
@@ -455,6 +455,9 @@ SOCKET_INCLUDES="
455 455
 #ifdef HAVE_SYS_SOCKET_H
456 456
 #include <sys/socket.h>
457 457
 #endif
458
+#ifdef HAVE_NET_IF_H
459
+#include <net/if.h>
460
+#endif
458 461
 #ifdef HAVE_NETINET_IN_H
459 462
 #include <netinet/in.h>
460 463
 #endif
... ...
@@ -524,6 +527,12 @@ AC_CHECK_TYPE(
524 524
         ,
525 525
         [[${SOCKET_INCLUDES}]]
526 526
 )
527
+AC_CHECK_MEMBER(
528
+	[struct in_pktinfo.ipi_spec_dst],
529
+	[AC_DEFINE([HAVE_IPI_SPEC_DST], [1], [struct in_pktinfo.ipi_spec_dst needed for IP_PKTINFO support])],
530
+	,
531
+	[[${SOCKET_INCLUDES}]]
532
+)
527 533
 AC_CHECK_TYPE(
528 534
 	[struct sockaddr_in6],
529 535
 	,
... ...
@@ -1299,7 +1299,7 @@ initialization_sequence_completed (struct context *c, const unsigned int flags)
1299 1299
           switch (local.addr.sa.sa_family)
1300 1300
             {
1301 1301
             case AF_INET:
1302
-#ifdef IP_PKTINFO
1302
+#if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST)
1303 1303
               local.addr.in4.sin_addr = actual->pi.in4.ipi_spec_dst;
1304 1304
 #else
1305 1305
               local.addr.in4.sin_addr = actual->pi.in4;
... ...
@@ -790,7 +790,7 @@ create_socket_udp (struct addrinfo* addrinfo, const unsigned int flags)
790 790
       int pad = 1;
791 791
       if(addrinfo->ai_family == AF_INET)
792 792
         {
793
-#ifdef IP_PKTINFO
793
+#if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST)
794 794
           if (setsockopt (sd, SOL_IP, IP_PKTINFO,
795 795
                           (void*)&pad, sizeof(pad)) < 0)
796 796
             msg(M_ERR, "UDP: failed setsockopt for IP_PKTINFO");
... ...
@@ -2465,7 +2465,7 @@ print_link_socket_actual_ex (const struct link_socket_actual *act,
2465 2465
 		  struct openvpn_sockaddr sa;
2466 2466
 		  CLEAR (sa);
2467 2467
 		  sa.addr.in4.sin_family = AF_INET;
2468
-#ifdef IP_PKTINFO
2468
+#if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST)
2469 2469
 		  sa.addr.in4.sin_addr = act->pi.in4.ipi_spec_dst;
2470 2470
 		  if_indextoname(act->pi.in4.ipi_ifindex, ifname);
2471 2471
 #elif defined(IP_RECVDSTADDR)
... ...
@@ -2867,7 +2867,7 @@ link_socket_read_tcp (struct link_socket *sock,
2867 2867
 struct openvpn_in4_pktinfo
2868 2868
 {
2869 2869
   struct cmsghdr cmsghdr;
2870
-#ifdef HAVE_IN_PKTINFO
2870
+#if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST)
2871 2871
   struct in_pktinfo pi4;
2872 2872
 #elif defined(IP_RECVDSTADDR)
2873 2873
   struct in_addr pi4;
... ...
@@ -2911,7 +2911,7 @@ link_socket_read_udp_posix_recvmsg (struct link_socket *sock,
2911 2911
       cmsg = CMSG_FIRSTHDR (&mesg);
2912 2912
       if (cmsg != NULL
2913 2913
 	  && CMSG_NXTHDR (&mesg, cmsg) == NULL
2914
-#ifdef IP_PKTINFO
2914
+#if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST)
2915 2915
 	  && cmsg->cmsg_level == SOL_IP 
2916 2916
 	  && cmsg->cmsg_type == IP_PKTINFO
2917 2917
 #elif defined(IP_RECVDSTADDR)
... ...
@@ -2922,7 +2922,7 @@ link_socket_read_udp_posix_recvmsg (struct link_socket *sock,
2922 2922
 #endif
2923 2923
 	  && cmsg->cmsg_len >= sizeof (struct openvpn_in4_pktinfo))
2924 2924
 	{
2925
-#ifdef IP_PKTINFO
2925
+#if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST)
2926 2926
 	  struct in_pktinfo *pkti = (struct in_pktinfo *) CMSG_DATA (cmsg);
2927 2927
 	  from->pi.in4.ipi_ifindex = pkti->ipi_ifindex;
2928 2928
 	  from->pi.in4.ipi_spec_dst = pkti->ipi_spec_dst;
... ...
@@ -3021,7 +3021,7 @@ link_socket_write_udp_posix_sendmsg (struct link_socket *sock,
3021 3021
         mesg.msg_namelen = sizeof (struct sockaddr_in);
3022 3022
         mesg.msg_control = &opi;
3023 3023
         mesg.msg_flags = 0;
3024
-#ifdef HAVE_IN_PKTINFO
3024
+#if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST)
3025 3025
         mesg.msg_controllen = sizeof (struct openvpn_in4_pktinfo);
3026 3026
         cmsg = CMSG_FIRSTHDR (&mesg);
3027 3027
         cmsg->cmsg_len = sizeof (struct openvpn_in4_pktinfo);
... ...
@@ -90,7 +90,7 @@ struct link_socket_actual
90 90
   struct openvpn_sockaddr dest;
91 91
 #if ENABLE_IP_PKTINFO
92 92
   union {
93
-#ifdef HAVE_IN_PKTINFO
93
+#if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST)
94 94
     struct in_pktinfo in4;
95 95
 #elif defined(IP_RECVDSTADDR)
96 96
     struct in_addr in4;
... ...
@@ -626,7 +626,7 @@ addr_defined_ipi (const struct link_socket_actual *lsa)
626 626
 #if ENABLE_IP_PKTINFO
627 627
   if (!lsa) return 0;
628 628
   switch (lsa->dest.addr.sa.sa_family) {
629
-#ifdef HAVE_IN_PKTINFO
629
+#if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST)
630 630
     case AF_INET: return lsa->pi.in4.ipi_spec_dst.s_addr != 0;
631 631
 #elif defined(IP_RECVDSTADDR)
632 632
     case AF_INET: return lsa->pi.in4.s_addr != 0;