Skip to contentSkip to conversation

Bug#489340: iproute2: no error message when link up command fails.

PATCH Andreas Henriksson 6 participants 10 messages Jul 16, 2008 – Jul 17, 2008

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

Hi Stephen and co.!

Johannes Berg reported that iproute2 doesn't give any error message when "ip link set ... up" failed for him (as opposed to ifconfig):
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=489340

The ways he suggested didn't work for me to reproduce, but I found out simply using the wmaster0 device works as a testcase. (You'll need a wireless device, probably with a driver based on the new mac80211 stack).

I've debugged this into a place in the bundled rtnetlink library where if there's a netlink error - it is ignored if there's no errno, which seems weird. I don't really understand the code, but this "proof of concept" patch makes "ip link set dev wmaster0 up" spit out an error message atleast. Could you please have a look at what's going on here?

lib/libnetlink.c +1 -0
index 5ae64f7..afa58fb 100644
@@ -351,6 +351,7 @@ int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer,
 					if (errno == 0) {
 						if (answer)
 							memcpy(answer, h, h->nlmsg_len);
+						fprintf(stderr, "Unknown netlink error.\n");
 						return 0;
 					}
 					perror("RTNETLINK answers");

For the record, here's what ifconfig says:

$ sudo ifconfig wmaster0 up
SIOCSIFFLAGS: Operation not supported

--
Regards,
Andreas Henriksson

#1 lore raw

Re: iproute2: no error message when link up command fails.

Quoted 33 lines · On Thu, 17 Jul 2008 00:00:58 +0200 Andreas Henriksson <[email protected]> wrote:

Hi Stephen and co.!

Johannes Berg reported that iproute2 doesn't give any error message when "ip link set ... up" failed for him (as opposed to ifconfig):
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=489340

The ways he suggested didn't work for me to reproduce, but I found out simply using the wmaster0 device works as a testcase. (You'll need a wireless device, probably with a driver based on the new mac80211 stack).

I've debugged this into a place in the bundled rtnetlink library where if there's a netlink error - it is ignored if there's no errno, which seems weird. I don't really understand the code, but this "proof of concept" patch makes "ip link set dev wmaster0 up" spit out an error message atleast. Could you please have a look at what's going on here?

lib/libnetlink.c +1 -0
index 5ae64f7..afa58fb 100644
@@ -351,6 +351,7 @@ int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer,
 					if (errno == 0) {
 						if (answer)
 							memcpy(answer, h, h->nlmsg_len);
+						fprintf(stderr, "Unknown netlink error.\n");
 						return 0;
 					}
 					perror("RTNETLINK answers");
Quoted 4 lines

For the record, here's what ifconfig says:

$ sudo ifconfig wmaster0 up
SIOCSIFFLAGS: Operation not supported

libnetlink shouldn't print the error, it needs to be done by the caller.

#2 lore raw

Re: iproute2: no error message when link up command fails.

Quoted 2 lines · Stephen Hemminger

On Thu, 17 Jul 2008 00:00:58 +0200
Andreas Henriksson <[email protected]> wrote:

[...]

Quoted 2 lines
Quoted 2 lines
lib/libnetlink.c +1 -0
+						fprintf(stderr, "Unknown netlink error.\n");
 						return 0;

[..]

Quoted 1 line

libnetlink shouldn't print the error, it needs to be done by the caller.

... and iproute should exit with a proper error code. This isn't possible today, as there's no way for the caller to detect the error! I was just trying to be a bit helpful on where we end up in the code.

If anyone could help out with how to modify the code to solve all this, that would be nice. I don't understand the current code tries to do.

(By the way, most uses of rtnl_* seems to be if (rtnl_* < 0) exit(1); in iproute2 currently. The error messages are in libnetlink.)

Signature · 2 lines
Regards,
Andreas Henriksson
#3 lore raw

Re: iproute2: no error message when link up command fails.

Quoted 12 lines · On Thu, 17 Jul 2008 00:27:17 +0200 Andreas Henriksson <[email protected]> wrote:
Quoted 2 lines · Stephen Hemminger

On Thu, 17 Jul 2008 00:00:58 +0200
Andreas Henriksson <[email protected]> wrote:

[...]

Quoted 2 lines
Quoted 2 lines
lib/libnetlink.c +1 -0
+						fprintf(stderr, "Unknown netlink error.\n");
 						return 0;

[..]

Quoted 1 line

libnetlink shouldn't print the error, it needs to be done by the caller.

... and iproute should exit with a proper error code. This isn't possible today, as there's no way for the caller to detect the error! I was just trying to be a bit helpful on where we end up in the code.

Quoted 7 lines

If anyone could help out with how to modify the code to solve all this, that would be nice. I don't understand the current code tries to do.

(By the way, most uses of rtnl_* seems to be if (rtnl_* < 0) exit(1); in iproute2 currently. The error messages are in libnetlink.)

The problem is the driver is responding with an error packet but the errno is 0. This looks like a kernel bug, not an library bug.

#4 lore raw

Re: iproute2: no error message when link up command fails.

Quoted 6 lines
Quoted 3 lines

(By the way, most uses of rtnl_* seems to be if (rtnl_* < 0) exit(1); in iproute2 currently. The error messages are in libnetlink.)

The problem is the driver is responding with an error packet but the errno is 0. This looks like a kernel bug, not an library bug.

I don't think so, the recvmsg() call worked fine, but the message indicates that the netlink consumer had an error. Or am I missing something?

johannes

#5 lore raw

Re: iproute2: no error message when link up command fails.

Quoted 4 lines · On Thu, 17 Jul 2008 00:35:22 +0200 Johannes Berg <[email protected]>…
Quoted 3 lines
Quoted 3 lines

(By the way, most uses of rtnl_* seems to be if (rtnl_* < 0) exit(1); in iproute2 currently. The error messages are in libnetlink.)

Quoted 8 lines
Quoted 2 lines

The problem is the driver is responding with an error packet but the errno is 0. This looks like a kernel bug, not an library bug.

I don't think so, the recvmsg() call worked fine, but the message indicates that the netlink consumer had an error. Or am I missing something?

johannes

The netlink message in question is marked as type ERROR but the errno encoded in the message is zero.

		if (h->nlmsg_type == NLMSG_ERROR) {
			struct nlmsgerr *err = (struct nlmsgerr*)NLMSG_DATA(h);
			if (l < sizeof(struct nlmsgerr)) {
				fprintf(stderr, "ERROR truncated\n");
			} else {
				errno = -err->error;
				if (errno == 0) {
					if (answer)
						memcpy(answer, h, h->nlmsg_len);
					return 0;
				}
				perror("RTNETLINK answers");
			}

So the netlink library just treats as a successful return. To me it looks like the problem is in the kernel sending back a NLMSG_ERROR with errno of zero. Some code path isn't setting it up properly.

#6 lore raw

Re: iproute2: no error message when link up command fails.

Quoted 17 lines · Stephen Hemminger

The netlink message in question is marked as type ERROR but the errno encoded in the message is zero.

		if (h->nlmsg_type == NLMSG_ERROR) {
			struct nlmsgerr *err = (struct nlmsgerr*)NLMSG_DATA(h);
			if (l < sizeof(struct nlmsgerr)) {
				fprintf(stderr, "ERROR truncated\n");
			} else {
				errno = -err->error;
				if (errno == 0) {
					if (answer)
						memcpy(answer, h, h->nlmsg_len);
					return 0;
				}
				perror("RTNETLINK answers");
			}
Quoted 1 line

So the netlink library just treats as a successful return.

Why? This seems like a really bad idea to me, and none of the callers in iproute benefits from this as far as I can see.

Just ripping out the errno == 0 special casing looks like and option to me, unless anyone can find a reason for it.
(It'll give an error message and an error exit code! The message will be strange, but lets blame the kernel for that cosmetic issue. Atleast the user got some kind of notification.)

Moving the "return 0;" inside the "if (answer)" would be another (atleast for iproutes callers of the library functions)...

Quoted 3 lines

To me it looks like the problem is in the kernel sending back a NLMSG_ERROR with errno of zero. Some code path isn't setting it up properly.

None the less, it would be be good if the application wouldn't poop it's pants when it can be avoided - broken kernel or not.

lib/libnetlink.c +1 -6
index 5ae64f7..4413165 100644
@@ -348,12 +348,7 @@ int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer,
 					fprintf(stderr, "ERROR truncated\n");
 				} else {
 					errno = -err->error;
-					if (errno == 0) {
-						if (answer)
-							memcpy(answer, h, h->nlmsg_len);
-						return 0;
-					}
-					perror("RTNETLINK answers");
+					perror("RTNETLINK error");
 				}
 				return -1;
 			}
Signature · 2 lines
Regards,
Andreas Henriksson
#7 lore raw

Re: iproute2: no error message when link up command fails.

Quoted 18 lines · Andreas Henriksson
Quoted 17 lines · Stephen Hemminger

The netlink message in question is marked as type ERROR but the errno encoded in the message is zero.

		if (h->nlmsg_type == NLMSG_ERROR) {
			struct nlmsgerr *err = (struct nlmsgerr*)NLMSG_DATA(h);
			if (l < sizeof(struct nlmsgerr)) {
				fprintf(stderr, "ERROR truncated\n");
			} else {
				errno = -err->error;
				if (errno == 0) {
					if (answer)
						memcpy(answer, h, h->nlmsg_len);
					return 0;
				}
				perror("RTNETLINK answers");
			}
Quoted 6 lines
Quoted 1 line

So the netlink library just treats as a successful return.

Why? This seems like a really bad idea to me, and none of the callers in iproute benefits from this as far as I can see.

Just ripping out the errno == 0 special casing looks like and option to me, unless anyone can find a reason for it.

NLMSG_ERROR with errno == 0 is a netlink ACK message.

Quoted 7 lines

(It'll give an error message and an error exit code! The message will be strange, but lets blame the kernel for that cosmetic issue. Atleast the user got some kind of notification.)

Moving the "return 0;" inside the "if (answer)" would be another (atleast for iproutes callers of the library functions)...

Quoted 6 lines
Quoted 3 lines

To me it looks like the problem is in the kernel sending back a NLMSG_ERROR with errno of zero. Some code path isn't setting it up properly.

None the less, it would be be good if the application wouldn't poop it's pants when it can be avoided - broken kernel or not.

The fix in this case is to propagate the return value from dev_change_flags().

rtnetlink: propagate error from dev_change_flags in do_setlink()

Andreas Henriksson <[email protected]> reported that unlike ifconfig, iproute doesn't report an error when setting an interface up fails.

Propagate the return value from dev_change_flags() to fix this.

net/core/rtnetlink.c +3 -1
index a9a7721..ffde766 100644
@@ -867,7 +867,9 @@ static int do_setlink(struct net_device *dev, struct ifinfomsg *ifm,
 		if (ifm->ifi_change)
 			flags = (flags & ifm->ifi_change) |
 				(dev->flags & ~ifm->ifi_change);
-		dev_change_flags(dev, flags);
+		err = dev_change_flags(dev, flags);
+		if (err < 0)
+			goto errout;
 	}
 
 	if (tb[IFLA_TXQLEN])
#8 lore raw

Re: iproute2: no error message when link up command fails.

On 17-07-2008 11:26, Patrick McHardy wrote:
...

Quoted 3 lines

rtnetlink: propagate error from dev_change_flags in do_setlink()

Andreas Henriksson <[email protected]> reported that

+ Johannes Berg reported that

Quoted 6 lines

unlike ifconfig,
iproute doesn't report an error when setting an interface up fails.

Propagate the return value from dev_change_flags() to fix this.

Jarek P.

#9 lore raw

Re: iproute2: no error message when link up command fails.

In reply to Andreas Henriksson
Quoted 1 line · Andreas Henriksson

Why?

Thats just how it rolls.

Quoted 2 lines

This seems like a really bad idea to me, and none of the callers in iproute benefits from this as far as I can see.

The receiver(kernel in this case, but it could be some other user space user) returning a zero means success. Essentially zero is an (Positive) ACK.
The receiver returning a non-zero implies a failure. Essentially a N(egative) ACK.

In the case of a NACK, the kernel must return you the original message header you sent (similar to the way some icmp messages behave). The returned error code is a standard errno - if you sent a bad config you may get an EINVAL back. The sender combines the errno + the header to figure out what went wrong.

Does that make sense? So the kernel fix is required (as Stephen noted).

cheers,
jamal