Skip to content

Commit

Permalink
Another one fix for control buf handling in udp_xmit
Browse files Browse the repository at this point in the history
To be able to put data to control buffer, it should be allocated and
assigned to message header. Do that unconditionally before message
build. Clear the control buffer fields just before message sending if
control buffer empty.

This change should finally fix 4830a20
(use address from the last received UDP packet in UDP messages response)
and bug introduced in 90368df (Fix
control buffer handling in udp_xmit)
  • Loading branch information
rsa9000 committed Jun 21, 2016
1 parent 551b92f commit de345ff
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions network.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@ void udp_xmit (struct buffer *buf, struct tunnel *t)
* OKAY, now send a packet with the right SAref values.
*/
memset(&msgh, 0, sizeof(struct msghdr));
msgh.msg_control = cbuf;
msgh.msg_controllen = sizeof(cbuf);

if (gconfig.ipsecsaref && t->refhim != IPSEC_SAREF_NULL) {
cmsg = CMSG_FIRSTHDR(&msgh);
Expand All @@ -303,9 +305,6 @@ void udp_xmit (struct buffer *buf, struct tunnel *t)
}

#ifdef LINUX
msgh.msg_control = cbuf;
msgh.msg_controllen = sizeof(cbuf);

if (t->my_addr.ipi_addr.s_addr){
struct in_pktinfo *pktinfo;

Expand All @@ -325,20 +324,17 @@ void udp_xmit (struct buffer *buf, struct tunnel *t)

finallen += cmsg->cmsg_len;
}

msgh.msg_controllen = finallen;
#endif

/*
* Some OS don't like assigned buffer with zero length (e.g. OpenBSD),
* some OS don't like empty buffer with non-zero length (e.g. Linux).
* So make them all happy by assigning control buffer only if we really
* have something there.
* have something there and zero both fields otherwise.
*/
if (finallen) {
msgh.msg_control = cbuf;
msgh.msg_controllen = finallen;
}
msgh.msg_controllen = finallen;
if (!finallen)
msgh.msg_control = NULL;

iov.iov_base = buf->start;
iov.iov_len = buf->len;
Expand Down

0 comments on commit de345ff

Please sign in to comment.