From: Pavlin Radoslavov <pavlin@icir.org>
To: linux-kernel@vger.kernel.org
Cc: roland@topspin.com, pavlin@icir.org
Subject: Bug in the RTM_SETLINK kernel API for setting MAC address
Date: Mon, 07 Aug 2006 20:40:24 -0700 [thread overview]
Message-ID: <200608080340.k783eOfH076445@possum.icir.org> (raw)
It appears there is a bug in the RTM_SETLINK kernel API for setting
the MAC address on an interface.
E.g., below is the relevant sample code for setting the Ethernet MAC
address payload that works on 2.6.17.
/* Add the MAC address as an attribute */
struct sockaddr_storage ss_mac;
struct sockaddr* sa_mac_p = (struct sockaddr *)&ss_mac;
size_t sa_mac_len = 0;
memset(&ss_mac, 0, sizeof(ss_mac));
sa_mac_p->sa_family = ARPHRD_ETHER;
sa_mac_len = sizeof(sa_mac_p->sa_family) + ETH_ALEN;
memcpy(sa_mac_p->sa_data, ðer_addr, ETH_ALEN);
rta_len = RTA_LENGTH(sa_mac_len);
rtattr = IFLA_RTA(ifinfomsg);
rtattr->rta_type = IFLA_ADDRESS;
/*
* XXX
* rtattr->rta_len = rta_len;
*/
rtattr->rta_len = RTA_LENGTH(ETH_ALEN);
memcpy(RTA_DATA(rtattr), sa_mac_p, sa_mac_len);
nlh->nlmsg_len = NLMSG_ALIGN(nlh->nlmsg_len) + rta_len;
if (ns.sendto(buffer, nlh->nlmsg_len, 0, (struct sockaddr *)&snl,
sizeof(snl)) != (ssize_t)nlh->nlmsg_len) {
/* ERROR */
}
Note that the payload with the MAC address has to be
"struct sockaddr" (or equivalent) and the length of that payload is
the equivalent of "sizeof(sa_family) + mac_address_size".
However, the rta_len of the corresponding message MUST be set to
"mac_address_size" rather than the real payload size which is
"sizeof(sa_family) + mac_address_size".
I believe this is incorrect, and rta_len is suppose to be set to the
real payload size.
The particular problematic code in the kernel that checks for the
payload size is inside net/core/rtnetlink.c, do_setlink():
...
if (ida[IFLA_ADDRESS - 1]) {
...
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]));
...
Where dev->set_mac_address() (typically/always?) expects to see a
second argument of type "struct sockaddr".
Thanks,
Pavlin
P.S. Please CC to me in your replies, because I am not subscribed to
the list.
next reply other threads:[~2006-08-08 3:40 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-08-08 3:40 Pavlin Radoslavov [this message]
2006-08-08 3:48 ` David Miller
2006-08-08 5:31 ` Pavlin Radoslavov
2006-08-08 6:35 ` David Miller
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=200608080340.k783eOfH076445@possum.icir.org \
--to=pavlin@icir.org \
--cc=linux-kernel@vger.kernel.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®