Patchwork iproute2: ip route flush bugfix

login
register
mail settings
Submitter Sven Anders
Date Nov. 9, 2009, 7:39 p.m.
Message ID <4AF86FE3.4090005@anduras.de>
Download mbox | patch
Permalink /patch/38021/
State Accepted
Delegated to: stephen hemminger
Headers show

Comments

Sven Anders - Nov. 9, 2009, 7:39 p.m.
Hello!

I experienced an error, if I try to perform a

  ip route flush proto 4

with many routes in a complex environment, it
gave me the following error:

  Failed to send flush request: Success
  Flush terminated

I'm using version 2.6.29.
I check GIT, but there was only the "MSG_PEEK" fix.

I tracked it down to the rtnl_send_check() function
in lib/libnetlink.c.

In this function there is the following for loop:

        for (h = (struct nlmsghdr *)resp; NLMSG_OK(h, status);
             h = NLMSG_NEXT(h, status)) {
                if (h->nlmsg_type == NLMSG_ERROR) {
                        struct nlmsgerr *err = (struct nlmsgerr*)NLMSG_DATA(h);
                        if (h->nlmsg_len < NLMSG_LENGTH(sizeof(struct nlmsgerr)))
                                fprintf(stderr, "ERROR truncated\n");
                        else
                                errno = -err->error;
		}
                return -1;
        }

I think the "return -1;" should be inside the if statement.

I attached a patch for this. The first part of the patch is taken from
one of the late git commits.

Please note me, if the fix is wrong...


Regards
 Sven

PS: This is a repost, because I neither received a confirmation nor a remark, that
    the fix is wrong. Moreover the fix didn't make it in the GIT repository yet...
Eric Dumazet - Nov. 9, 2009, 8:24 p.m.
Sven Anders a écrit :
> Hello!
> 
> I experienced an error, if I try to perform a
> 
>   ip route flush proto 4
> 
> with many routes in a complex environment, it
> gave me the following error:
> 
>   Failed to send flush request: Success
>   Flush terminated
> 
> I'm using version 2.6.29.
> I check GIT, but there was only the "MSG_PEEK" fix.
> 
> I tracked it down to the rtnl_send_check() function
> in lib/libnetlink.c.
> 
> In this function there is the following for loop:
> 
>         for (h = (struct nlmsghdr *)resp; NLMSG_OK(h, status);
>              h = NLMSG_NEXT(h, status)) {
>                 if (h->nlmsg_type == NLMSG_ERROR) {
>                         struct nlmsgerr *err = (struct nlmsgerr*)NLMSG_DATA(h);
>                         if (h->nlmsg_len < NLMSG_LENGTH(sizeof(struct nlmsgerr)))
>                                 fprintf(stderr, "ERROR truncated\n");
>                         else
>                                 errno = -err->error;
> 		}
>                 return -1;
>         }
> 
> I think the "return -1;" should be inside the if statement.
> 
> I attached a patch for this. The first part of the patch is taken from
> one of the late git commits.
> 
> Please note me, if the fix is wrong...
> 
> 
> Regards
>  Sven
> 
> PS: This is a repost, because I neither received a confirmation nor a remark, that
>     the fix is wrong. Moreover the fix didn't make it in the GIT repository yet...
> 


Yes, I posted a similar patch yesterday :)

http://article.gmane.org/gmane.linux.network/142908

Still waiting an ACK from Stephen

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

--- iproute2-2.6.29/lib/libnetlink.c.orig	2009-09-23 14:47:03.000000000 +0200
+++ iproute2-2.6.29/lib/libnetlink.c	2009-09-23 14:48:09.000000000 +0200
@@ -122,7 +122,7 @@  int rtnl_send_check(struct rtnl_handle *
 		return status;
 
 	/* Check for errors */
-	status = recv(rth->fd, resp, sizeof(resp), MSG_DONTWAIT);
+	status = recv(rth->fd, resp, sizeof(resp), MSG_DONTWAIT|MSG_PEEK);
 	if (status < 0) {
 		if (errno == EAGAIN)
 			return 0;
@@ -137,8 +137,8 @@  int rtnl_send_check(struct rtnl_handle *
 				fprintf(stderr, "ERROR truncated\n");
 			else 
 				errno = -err->error;
-		}
 		return -1;
+		}
 	}
 
 	return 0;