[Swan-dev] addconn: handle EOF from netlink as error

D. Hugh Redelmeier hugh at mimosa.com
Wed Oct 4 16:44:52 UTC 2017


| commit 440b6a739aa79cef76ac928fb962ca7f43a27b0a
| Author: Kim B. Heino <b at bbbs.net>
| Date:   Wed Oct 4 16:05:25 2017 +0300
| 
|     addconn: handle EOF from netlink as error

-			if (readlen < 0 || salen != sizeof(sa))
+			if (readlen <= 0 || salen != sizeof(sa))

>From <linux/netlink.h>:
#define NLMSG_OK(nlh,len) ((len) >= (int)sizeof(struct nlmsghdr) && \
	                   (nlh)->nlmsg_len >= sizeof(struct nlmsghdr) && \
                           (nlh)->nlmsg_len <= (len))

So NLMSG_OK(nlhdr, (size_t)readlen) [a few lines down] will fail, causing 
the same result.

Unless sa.nl_pid != 0.  In that case, the new code will give up and the 
old code will try again.

I think that the old code is more correct.  Or am I misunderstanding 
something?

PS: more whining about formatting:

		if (!NLMSG_OK(nlhdr, (size_t)readlen) ||
			nlhdr->nlmsg_type == NLMSG_ERROR)
			return -1;

is harder for me to read than

		if (!NLMSG_OK(nlhdr, (size_t)readlen) ||
		    nlhdr->nlmsg_type == NLMSG_ERROR)
			return -1;

Both are worse than

		if (!NLMSG_OK(nlhdr, (size_t)readlen)
		|| nlhdr->nlmsg_type == NLMSG_ERROR)
			return -1;



More information about the Swan-dev mailing list