[U-Boot] [PATCH] sandbox: Add tap based networking
Wolfgang Denk
wd at denx.de
Sat Dec 17 23:47:26 CET 2011
Dear Matthias Weisser,
In message <1323021425-7854-1-git-send-email-weisserm at arcor.de> you wrote:
> This patch adds support for networking to sandbox architecture using
> tap. A tap device "tap0" has to be created e.g. using openvpn
>
> $ openvpn --mktun --dev tap0
>
> u-boot should then be able to detect the network device on startup.
> To test the network related commands the following commands can be used
> to create an ethernet bridge to local network connection.
>
> $ brctl addbr br0
> $ ifconfig eth0 0.0.0.0 promisc
> $ ifconfig tap0 0.0.0.0
> $ brctl addif br0 eth0
> $ brctl addif br0 tap0
> $ ifconfig br0 up
> $ pump -i br0
>
> Signed-off-by: Matthias Weisser <weisserm at arcor.de>
...
> +int os_tap_set_hw_addr(int fd, unsigned char *hwaddr)
> +{
> + /*
> + * The following code should be able to change the MAC of a TAP
> + * interface but doesn't work on my box. So leave it disabled
> + * here as a reference if someone is going to pick that up in
> + * the future.
> + */
> +#if 0
> + 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");
> + return -1;
> + }
> + /* Shut down the interface */
> + ifr.ifr_flags &= ~(IFF_UP);
> + if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0) {
> + perror("Could not down the interface");
> + return -1;
> + }
> +
> + /* 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)");
> + return -1;
> + }
> +
> + /* Get the interface flags */
> + if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) {
> + perror("Could not get interface flags");
> + return -1;
> + }
> + /* Shut down the interface */
> + ifr.ifr_flags |= IFF_UP;
> + if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0) {
> + perror("Could not up the interface");
> + return -1;
> + }
> + return 0;
> +#endif
Please do not add dead code.
Best regards,
Wolfgang Denk
--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Even historians fail to learn from history -- they repeat the same
mistakes.
-- John Gill, "Patterns of Force", stardate 2534.7
More information about the U-Boot
mailing list