From: David Miller <davem@davemloft.net>
To: pavlin@icir.org
Cc: linux-kernel@vger.kernel.org, roland@topspin.com
Subject: Re: Bug in the RTM_SETLINK kernel API for setting MAC address
Date: Mon, 07 Aug 2006 23:35:29 -0700 (PDT) [thread overview]
Message-ID: <20060807.233529.58454613.davem@davemloft.net> (raw)
In-Reply-To: <200608080531.k785VxYL077237@possum.icir.org>
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;
next prev parent reply other threads:[~2006-08-08 6:35 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-08-08 3:40 Pavlin Radoslavov
2006-08-08 3:48 ` David Miller
2006-08-08 5:31 ` Pavlin Radoslavov
2006-08-08 6:35 ` David Miller [this message]
2006-08-08 18:26 ` Pavlin Radoslavov
2006-08-08 23:47 ` David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20060807.233529.58454613.davem@davemloft.net \
--to=davem@davemloft.net \
--cc=linux-kernel@vger.kernel.org \
--cc=pavlin@icir.org \
--cc=roland@topspin.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®