Ticket #327: 0001-Repair-multihome-on-FreeBSD-for-IPv4-sockets.patch

File 0001-Repair-multihome-on-FreeBSD-for-IPv4-sockets.patch, 1.9 KB (added by Gert Döring, 8 years ago)
  • src/openvpn/socket.c

    From 4e35fbc2b0a13fd2bc4ed50356ccd6be772950e2 Mon Sep 17 00:00:00 2001
    From: Gert Doering <gert@greenie.muc.de>
    Date: Sun, 19 Jan 2014 20:04:11 +0100
    Subject: [PATCH] Repair --multihome on FreeBSD for IPv4 sockets.
    
    The code in link_socket_write_udp_posix_sendmsg() for the IP_RECVDESTADDR
    case was sending a too-large control message (sizeof openvpn_pktinfo,
    which is a union for IPv4+IPv6) instead of just openvpn_in4_pktinfo,
    leading to sendmsg() refusing to send the packet.
    
    Use RFC 2292 macros for alignment + size calculation.
    
    Fix trac#327
    
    Signed-off-by: Gert Doering <gert@greenie.muc.de>
    ---
     src/openvpn/socket.c | 8 ++++++--
     1 file changed, 6 insertions(+), 2 deletions(-)
    
    diff --git a/src/openvpn/socket.c b/src/openvpn/socket.c
    index 100eedd..525b864 100644
    a b link_socket_write_udp_posix_sendmsg (struct link_socket *sock, 
    28352835        mesg.msg_name = &to->dest.addr.sa;
    28362836        mesg.msg_namelen = sizeof (struct sockaddr_in);
    28372837        mesg.msg_control = &opi;
    2838         mesg.msg_controllen = sizeof (struct openvpn_in4_pktinfo);
    28392838        mesg.msg_flags = 0;
     2839#ifdef HAVE_IN_PKTINFO
     2840        mesg.msg_controllen = sizeof (struct openvpn_in4_pktinfo);
    28402841        cmsg = CMSG_FIRSTHDR (&mesg);
    28412842        cmsg->cmsg_len = sizeof (struct openvpn_in4_pktinfo);
    2842 #ifdef HAVE_IN_PKTINFO
    28432843        cmsg->cmsg_level = SOL_IP;
    28442844        cmsg->cmsg_type = IP_PKTINFO;
    28452845        {
    link_socket_write_udp_posix_sendmsg (struct link_socket *sock, 
    28502850        pkti->ipi_addr.s_addr = 0;
    28512851        }
    28522852#elif defined(IP_RECVDSTADDR)
     2853        ASSERT( CMSG_SPACE(sizeof (struct in_addr)) <= sizeof(opi) );
     2854        mesg.msg_controllen = CMSG_SPACE(sizeof (struct in_addr));
     2855        cmsg = CMSG_FIRSTHDR (&mesg);
     2856        cmsg->cmsg_len = CMSG_LEN(sizeof(struct in_addr));
    28532857        cmsg->cmsg_level = IPPROTO_IP;
    28542858        cmsg->cmsg_type = IP_RECVDSTADDR;
    28552859        *(struct in_addr *) CMSG_DATA (cmsg) = to->pi.in4;