Skip to content

Commit

Permalink
Merge pull request #111 from rsa9000/cmsg-smooth-assigning
Browse files Browse the repository at this point in the history
Another one fix for control buf handling in udp_xmit
  • Loading branch information
shussain authored Jun 21, 2016
2 parents 551b92f + de345ff commit f71a5d1
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 f71a5d1

Please sign in to comment.