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, |
2835 | 2835 | mesg.msg_name = &to->dest.addr.sa; |
2836 | 2836 | mesg.msg_namelen = sizeof (struct sockaddr_in); |
2837 | 2837 | mesg.msg_control = &opi; |
2838 | | mesg.msg_controllen = sizeof (struct openvpn_in4_pktinfo); |
2839 | 2838 | mesg.msg_flags = 0; |
| 2839 | #ifdef HAVE_IN_PKTINFO |
| 2840 | mesg.msg_controllen = sizeof (struct openvpn_in4_pktinfo); |
2840 | 2841 | cmsg = CMSG_FIRSTHDR (&mesg); |
2841 | 2842 | cmsg->cmsg_len = sizeof (struct openvpn_in4_pktinfo); |
2842 | | #ifdef HAVE_IN_PKTINFO |
2843 | 2843 | cmsg->cmsg_level = SOL_IP; |
2844 | 2844 | cmsg->cmsg_type = IP_PKTINFO; |
2845 | 2845 | { |
… |
… |
link_socket_write_udp_posix_sendmsg (struct link_socket *sock, |
2850 | 2850 | pkti->ipi_addr.s_addr = 0; |
2851 | 2851 | } |
2852 | 2852 | #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)); |
2853 | 2857 | cmsg->cmsg_level = IPPROTO_IP; |
2854 | 2858 | cmsg->cmsg_type = IP_RECVDSTADDR; |
2855 | 2859 | *(struct in_addr *) CMSG_DATA (cmsg) = to->pi.in4; |