From: Wolfgang Denk Date: Sat, 17 Dec 2011 23:47:26 +0100 Subject: [U-Boot] =?utf-8?q?=5BPATCH=5D_sandbox=3A_Add_tap_based_networkin?= =?utf-8?q?g?= In-Reply-To: <1323021425-7854-1-git-send-email-weisserm@arcor.de> References: <1322575743-21760-1-git-send-email-weisserm@arcor.de> <1323021425-7854-1-git-send-email-weisserm@arcor.de> Message-ID: <20111217224726.72000138EEA1@gemini.denx.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Dear Matthias Weisser, In message <1323021425-7854-1-git-send-email-weisserm@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 ... > +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