lkml.org 
[lkml]   [2006]   [Aug]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
SubjectRe: Bug in the RTM_SETLINK kernel API for setting MAC address
From
From: Pavlin Radoslavov <pavlin@icir.org>
Date: Mon, 07 Aug 2006 22:31:59 -0700

> The real mismatch is that ida[IFLA_ADDRESS - 1] is (as you say)
> suppose to be a MAC address, but the set_mac_address() functions
> for each device assume that the RTA_DATA(ida[IFLA_ADDRESS - 1])
> payload is a sockaddr.

That's because ->set_mac_address() is usually invoked via
dev_set_mac_address() which in turn is invoked from places
SIOCSIFHWADDR ioctl() processing which does want the sockaddr
wrapped around the MAC address.

So the netlink code is definitely doing the wrong thing if
it wants merely the MAC address in the attribute.

Since changing all the drivers is a pain, what we probably
should do is have the netlink code allocate a sockaddr,
place the MAC address attribute in to that allocated sockaddr,
and pass it into ->set_mac_address().

This patch should do the trick, can you test it out?

Thanks.

diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index 20e5bb7..30cc1ba 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -394,6 +394,9 @@ static int do_setlink(struct sk_buff *sk
}

if (ida[IFLA_ADDRESS - 1]) {
+ struct sockaddr *sa;
+ int len;
+
if (!dev->set_mac_address) {
err = -EOPNOTSUPP;
goto out;
@@ -405,7 +408,17 @@ static int do_setlink(struct sk_buff *sk
if (ida[IFLA_ADDRESS - 1]->rta_len != RTA_LENGTH(dev->addr_len))
goto out;

- err = dev->set_mac_address(dev, RTA_DATA(ida[IFLA_ADDRESS - 1]));
+ len = sizeof(sa_family_t) + dev->addr_len;
+ sa = kmalloc(len, GFP_KERNEL);
+ if (!sa) {
+ err = -ENOMEM;
+ goto out;
+ }
+ sa->sa_family = dev->type;
+ memcpy(sa->sa_data, RTA_DATA(ida[IFLA_ADDRESS - 1]),
+ dev->addr_len);
+ err = dev->set_mac_address(dev, sa);
+ kfree(sa);
if (err)
goto out;
send_addr_notify = 1;
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
\
 
 \ /
  Last update: 2006-08-08 08:37    [W:0.051 / U:0.396 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site