dnsmasq: backport latest patches
[openwrt/staging/mkresin.git] / package / network / services / dnsmasq / patches / 0048-Fix-cmsg-3-API-usage-on-OpenBSD.patch
1 From c6cc455dd191fbea56ee14a0ef88a7d655a6fe9a Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Courr=C3=A8ges-Anglas?= <jca@wxcvbn.org>
3 Date: Fri, 22 Mar 2019 10:56:13 +0100
4 Subject: [PATCH 48/57] Fix cmsg(3) API usage on OpenBSD
5
6 msg_controllen should be set using CMSG_SPACE() to account for padding.
7 RFC3542 provides more details:
8
9 While sending an application may or may not include padding at the end
10 of last ancillary data in msg_controllen and implementations must
11 accept both as valid.
12
13 At least OpenBSD rejects control messages if msg_controllen doesn't
14 account for padding, so use CMSG_SPACE() for maximal portability. This
15 is consistent with the example provided in the Linux cmsg(3) manpage.
16
17 Signed-off-by: Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>
18 ---
19 src/forward.c | 9 ++++++---
20 1 file changed, 6 insertions(+), 3 deletions(-)
21
22 --- a/src/forward.c
23 +++ b/src/forward.c
24 @@ -65,13 +65,15 @@ int send_from(int fd, int nowild, char *
25 struct in_pktinfo p;
26 p.ipi_ifindex = 0;
27 p.ipi_spec_dst = source->addr4;
28 + msg.msg_controllen = CMSG_SPACE(sizeof(struct in_pktinfo));
29 memcpy(CMSG_DATA(cmptr), &p, sizeof(p));
30 - msg.msg_controllen = cmptr->cmsg_len = CMSG_LEN(sizeof(struct in_pktinfo));
31 + cmptr->cmsg_len = CMSG_LEN(sizeof(struct in_pktinfo));
32 cmptr->cmsg_level = IPPROTO_IP;
33 cmptr->cmsg_type = IP_PKTINFO;
34 #elif defined(IP_SENDSRCADDR)
35 + msg.msg_controllen = CMSG_SPACE(sizeof(struct in_addr));
36 memcpy(CMSG_DATA(cmptr), &(source->addr4), sizeof(source->addr4));
37 - msg.msg_controllen = cmptr->cmsg_len = CMSG_LEN(sizeof(struct in_addr));
38 + cmptr->cmsg_len = CMSG_LEN(sizeof(struct in_addr));
39 cmptr->cmsg_level = IPPROTO_IP;
40 cmptr->cmsg_type = IP_SENDSRCADDR;
41 #endif
42 @@ -81,8 +83,9 @@ int send_from(int fd, int nowild, char *
43 struct in6_pktinfo p;
44 p.ipi6_ifindex = iface; /* Need iface for IPv6 to handle link-local addrs */
45 p.ipi6_addr = source->addr6;
46 + msg.msg_controllen = CMSG_SPACE(sizeof(struct in6_pktinfo));
47 memcpy(CMSG_DATA(cmptr), &p, sizeof(p));
48 - msg.msg_controllen = cmptr->cmsg_len = CMSG_LEN(sizeof(struct in6_pktinfo));
49 + cmptr->cmsg_len = CMSG_LEN(sizeof(struct in6_pktinfo));
50 cmptr->cmsg_type = daemon->v6pktinfo;
51 cmptr->cmsg_level = IPPROTO_IPV6;
52 }