X-Git-Url: https://www.tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=src%2Fnet.c;h=3da023c3aa9c88caef1129efd0ef0bbea15b4206;hp=85255a4bbe8bd838f990e96df6cc986e7a876c13;hb=db21f015161aac244ec5600c4d0ff685549892c2;hpb=f25868fd2b58bc0b350a5cfaf342480f28f804cf diff --git a/src/net.c b/src/net.c index 85255a4b..3da023c3 100644 --- a/src/net.c +++ b/src/net.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: net.c,v 1.35.4.47 2000/10/28 21:05:17 guus Exp $ + $Id: net.c,v 1.35.4.49 2000/10/28 21:52:22 guus Exp $ */ #include "config.h" @@ -52,11 +52,13 @@ #include "netutl.h" #include "protocol.h" #include "meta.h" +#include "connlist.h" +#include "subnet.h" #include "system.h" int tap_fd = -1; -int taptype = 0; +int taptype = TAP_TYPE_ETHERTAP; int total_tap_in = 0; int total_tap_out = 0; int total_socket_in = 0; @@ -67,6 +69,8 @@ static int seconds_till_retry; char *unknown = NULL; +subnet_t mymac; + /* strip off the MAC adresses of an ethernet frame */ @@ -145,14 +149,24 @@ cp outlen = outpkt.len+2; memcpy(&outpkt, inpkt, outlen); - /* FIXME sometime - add_mac_addresses(&outpkt); - */ - - if(write(tap_fd, outpkt.data, outpkt.len) < 0) - syslog(LOG_ERR, _("Can't write to tap device: %m")); - else - total_tap_out += outpkt.len; + /* Fix mac address */ + + memcpy(outpkt.data, mymac.net.mac.address.x, 6); + + if(taptype == TAP_TYPE_TUNTAP) + { + if(write(tap_fd, outpkt.data, outpkt.len) < 0) + syslog(LOG_ERR, _("Can't write to tun/tap device: %m")); + else + total_tap_out += outpkt.len; + } + else /* ethertap */ + { + if(write(tap_fd, outpkt.data - 2, outpkt.len + 2) < 0) + syslog(LOG_ERR, _("Can't write to ethertap device: %m")); + else + total_tap_out += outpkt.len + 2; + } cp return 0; } @@ -371,7 +385,16 @@ cp cp tap_fd = nfd; - taptype = 0; + /* Set default MAC address for ethertap devices */ + + taptype = TAP_TYPE_ETHERTAP; + mymac.type = SUBNET_MAC; + mymac.net.mac.address.x[0] = 0xfe; + mymac.net.mac.address.x[1] = 0xfd; + mymac.net.mac.address.x[2] = 0x00; + mymac.net.mac.address.x[3] = 0x00; + mymac.net.mac.address.x[4] = 0x00; + mymac.net.mac.address.x[5] = 0x00; #ifdef HAVE_TUNTAP /* Ok now check if this is an old ethertap or a new tun/tap thingie */ @@ -384,12 +407,7 @@ cp if (!ioctl(tap_fd, TUNSETIFF, (void *) &ifr)) { syslog(LOG_INFO, _("%s is a new style tun/tap device"), tapfname); - taptype = 1; - - if((cfg = get_config_val(config, tapsubnet)) == NULL) - syslog(LOG_INFO, _("tun/tap device will be left unconfigured")); - else - /* Setup inetaddr/netmask etc */; + taptype = TAP_TYPE_TUNTAP; } #endif @@ -1225,7 +1243,7 @@ void handle_tap_input(void) ipv4_t dest; int lenin; cp - if(taptype = 1) + if(taptype == TAP_TYPE_TUNTAP) { if((lenin = read(tap_fd, vp.data, MTU)) <= 0) { @@ -1234,14 +1252,14 @@ cp } vp.len = lenin; } - else + else /* ethertap */ { - if((lenin = read(tap_fd, &vp.len, MTU)) <= 0) + if((lenin = read(tap_fd, vp.data - 2, MTU)) <= 0) { syslog(LOG_ERR, _("Error while reading from ethertap device: %m")); return; } -// vp.len = lenin - 2; + vp.len = lenin - 2; } total_tap_in += lenin;