From: Matthias Weisser <weisserm@arcor.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH RFC] sandbox: Add tap based networking
Date: Sat, 03 Dec 2011 16:06:58 +0100 [thread overview]
Message-ID: <4EDA3B12.9030705@arcor.de> (raw)
In-Reply-To: <201111291339.17625.vapier@gentoo.org>
Am 29.11.2011 19:39, schrieb Mike Frysinger:
>>>> +static int tap_set_hwaddr(struct eth_device *dev)
>>>> > >> +{
>>>> > >> + /* Nothing to be done here */
>>>> > >> + return 0;
>>>> > >> +}
>>> > >
>>> > > isn't there an ioctl that lets you control this ?
>> >
>> > Sure. But if I read the the docs correct it is an privileged operation
>> > and I don't think we wan't to run u-boot as super user all the time. How
>> > is the situation handled on real hardware when the MAC is programmed to
>> > an EEPROM on the NIC. Can the MAC be read from the NIC and set to
>> > u-boot? This would be the best solution as linux should take care about
>> > MAC address assignment.
> the tap_initialize() func should read the current MAC address assigned to the
> tap device and write that to dev->enetaddr
Done.
> then when tap_set_hwaddr() gets called, if the MAC is different, it will
> attempt to set the MAC to what the user requested. if they don't have
> permission, then the code can yell at them. but if they do, this should work
> imo. this gets us the best of all worlds i think.
I looked into that. It seems that you have to shut down the interface,
change the MAC and up the interface again. I tried now to do this using
some ioctls but didn't got it working as user or as root. So I give up
at this point. Should I submit the V2 patch without setting MAC function
anyway or will it not be applied then?
If someone has an idea: Here is the (simplified) code to set the MAC of
a tap interface.
void os_tap_set_hw_addr(int fd, unsigned char *hwaddr)
{
struct ifreq ifr;
memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name, "tap0", IFNAMSIZ);
/* Get the interface flags */
if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) {
perror("Could not get interface flags");
}
/* Shut down the interface */
ifr.ifr_flags &= ~(IFF_UP);
if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0) {
perror("Could not down the interface");
}
/* Set the new hw address */
ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER;
memcpy(&ifr.ifr_hwaddr.sa_data, hwaddr, ETH_ALEN);
if (ioctl(fd, SIOCSIFHWADDR, &ifr) < 0) {
perror("ioctl(SIOCSIFHWADDR)");
}
/* Get the interface flags */
if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) {
perror("Could not get interface flags");
}
/* Shut down the interface */
ifr.ifr_flags |= IFF_UP;
if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0) {
perror("Could not up the interface");
}
}
The SIOC{G,S}IFFLAGS ioctl calls fail with "Invalid argument" and the
SIOCSIFHWADDR fails with "Device or resource busy".
--
Matthias
next prev parent reply other threads:[~2011-12-03 15:06 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-29 14:09 [U-Boot] [PATCH RFC] sandbox: Add tap based networking Matthias Weisser
2011-11-29 15:24 ` Mike Frysinger
2011-11-29 18:21 ` Matthias Weisser
2011-11-29 18:39 ` Mike Frysinger
2011-12-03 15:06 ` Matthias Weisser [this message]
2011-12-03 17:02 ` Mike Frysinger
2011-12-04 17:57 ` [U-Boot] [PATCH] " Matthias Weisser
2011-12-13 23:54 ` Simon Glass
2011-12-14 3:35 ` Mike Frysinger
2011-12-15 15:46 ` Simon Glass
2011-12-17 22:47 ` Wolfgang Denk
2012-01-08 8:47 ` Mike Frysinger
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=4EDA3B12.9030705@arcor.de \
--to=weisserm@arcor.de \
--cc=u-boot@lists.denx.de \
/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