tap support for freebsd
I have been attempting to use 1.6_beta6 and found that support for the tap device wasn't working on FreeBSD 5.1. I discovered it worked fine on FreeBSD 5.1 with 1.6_beta1.
I believe that it is necessary to conditionalise the write_tun and read_tun functions (tun.c) in the same way as has been done for openbsd so that the protocol uint32 is only prepended for tun devices.
At least, with that change, both tun and tap support work fine under FreeBSD 5.1 for me.
Thanks for a superb product!
Nathanael
Hi,
I submitted that patch. And will fix it. - If you not already did that.
Quoted 3 lines
I have been attempting to use 1.6_beta6 and found that support for the tap device wasn't working on FreeBSD 5.1. I discovered it worked fine on FreeBSD 5.1 with 1.6_beta1.
Ic.
Quoted 5 lines
I believe that it is necessary to conditionalise the
write_tunandread_tunfunctions (tun.c) in the same way as has been done for openbsd so that the protocol uint32 is only prepended for tun devices. At least, with that change, both tun and tap support work fine under FreeBSD 5.1 for me.
Could you please send me a patch for this.
Thomas
Quoted 1 line · Thomas Glanzmann <sithglan <at> stud.uni-erlangen.de> writes:
Could you please send me a patch for this.
Sure. I'm sorry I didn't include one in the initial post. Below is a patch against version 1.41 of tun.c. Apart from replacing openbsd with freebsd, it is just a straight copy of the corresponding functions (write_tun and read_tun) for OpenBSD from earlier in the file.
Nathanael
tun.c Sat Feb 21 16:47:55 2004 renamed from tun.c Sat Feb 21 16:40:01 2004 +36 -27
@@ -1308,38 +1308,47 @@ int write_tun (struct tuntap* tt, uint8_t *buf, int len) { - struct iovec iv[2]; - u_int32_t type; - struct ip *iph; - - iph = (struct ip *)buf; - - if(tt->ipv6 && iph->ip_v == 6) - type = htonl(AF_INET6); - else - type = htonl(AF_INET); - - iv[0].iov_base = &type; - iv[0].iov_len = sizeof (type); - iv[1].iov_base = buf; - iv[1].iov_len = len; - - return freebsd_modify_read_write_return (writev (tt->fd, iv, 2)); + if (tt->type == DEV_TYPE_TUN) + { + u_int32_t type; + struct iovec iv[2]; + struct ip *iph; + + iph = (struct ip *) buf; + + if (tt->ipv6 && iph->ip_v == 6) + type = htonl (AF_INET6); + else + type = htonl (AF_INET); + + iv[0].iov_base = &type; + iv[0].iov_len = sizeof (type); + iv[1].iov_base = buf; + iv[1].iov_len = len; + + return freebsd_modify_read_write_return (writev (tt->fd, iv, 2)); + } + else + return write (tt->fd, buf, len); } int read_tun (struct tuntap* tt, uint8_t *buf, int len) { - u_int32_t type; - struct iovec iv[2]; - - iv[0].iov_base = &type; - iv[0].iov_len = sizeof (type); - iv[1].iov_base = buf; - iv[1].iov_len = len; - - - return freebsd_modify_read_write_return (readv (tt->fd, iv, 2)); + if (tt->type == DEV_TYPE_TUN) + { + u_int32_t type; + struct iovec iv[2]; + + iv[0].iov_base = &type; + iv[0].iov_len = sizeof (type); + iv[1].iov_base = buf; + iv[1].iov_len = len; + + return freebsd_modify_read_write_return (readv (tt->fd, iv, 2)); + } + else + return read (tt->fd, buf, len); } #elif defined(WIN32)