Subject: [PATCH] rtnetlink & address family problem

From: Michal Ludvig <[email-masked]>
Date: Fri, 03 Dec 2004 18:43:16 +0100

Hi,

running 'ip -6 addr flush dev eth0' on a kernel without IPv6 support
flushes *all* addresses from the interface, even those IPv4 ones,
because the unsupported protocol is substituted by PF_UNSPEC.
IMHO it should better return with an error EAFNOSUPPORT.

Attached patch fixes it. Please apply.

BTW Credits to Jan Kara <[email-masked]> for discovering and analysing
this bug.

Michal Ludvig
-- 
SUSE Labs                    [email-masked]
(+420) 296.542.396        http://www.suse.cz
Personal homepage http://www.logix.cz/michal
# This is a BitKeeper generated diff -Nru style patch.
#
# ChangeSet
#   2004/12/03 18:06:31+01:00 [email-masked] 
#   Return EAFNOSUPPORT if requested operation on unsupported family.
#   
#   Signed-off-by: Michal Ludvig <[email-masked]>
# 
# net/core/rtnetlink.c
#   2004/12/03 18:05:49+01:00 [email-masked] +4 -2
#   Return EAFNOSUPPORT if requested operation on unsupported family.
# 
diff -Nru a/net/core/rtnetlink.c b/net/core/rtnetlink.c
--- a/net/core/rtnetlink.c	2004-12-03 18:30:33 +01:00
+++ b/net/core/rtnetlink.c	2004-12-03 18:30:33 +01:00
@@ -477,8 +477,10 @@
 	}
 
 	link_tab = rtnetlink_links[family];
-	if (link_tab == NULL)
-		link_tab = rtnetlink_links[PF_UNSPEC];
+	if (link_tab == NULL) {
+		*errp = -EAFNOSUPPORT;
+		return -1;
+	}
 	link = &link_tab[type];
 
 	sz_idx = type>>2;