11ae349f5Scvs2svn /*- 21ae349f5Scvs2svn * Copyright (c) 1997 Brian Somers <brian@Awfulhak.org> 31ae349f5Scvs2svn * All rights reserved. 41ae349f5Scvs2svn * 51ae349f5Scvs2svn * Redistribution and use in source and binary forms, with or without 61ae349f5Scvs2svn * modification, are permitted provided that the following conditions 71ae349f5Scvs2svn * are met: 81ae349f5Scvs2svn * 1. Redistributions of source code must retain the above copyright 91ae349f5Scvs2svn * notice, this list of conditions and the following disclaimer. 101ae349f5Scvs2svn * 2. Redistributions in binary form must reproduce the above copyright 111ae349f5Scvs2svn * notice, this list of conditions and the following disclaimer in the 121ae349f5Scvs2svn * documentation and/or other materials provided with the distribution. 131ae349f5Scvs2svn * 141ae349f5Scvs2svn * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 151ae349f5Scvs2svn * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 161ae349f5Scvs2svn * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 171ae349f5Scvs2svn * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 181ae349f5Scvs2svn * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 191ae349f5Scvs2svn * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 201ae349f5Scvs2svn * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 211ae349f5Scvs2svn * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 221ae349f5Scvs2svn * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 231ae349f5Scvs2svn * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 241ae349f5Scvs2svn * SUCH DAMAGE. 251ae349f5Scvs2svn * 263b0f8d2eSBrian Somers * $Id: tun.c,v 1.6.4.9 1998/03/20 19:48:25 brian Exp $ 271ae349f5Scvs2svn */ 281ae349f5Scvs2svn 291ae349f5Scvs2svn #include <sys/param.h> 301ae349f5Scvs2svn #include <sys/time.h> 311ae349f5Scvs2svn #include <sys/socket.h> 321ae349f5Scvs2svn #include <netinet/in.h> 331ae349f5Scvs2svn #include <net/if.h> 34d2fd8d77SBrian Somers #include <sys/select.h> 351ae349f5Scvs2svn #include <net/if_tun.h> 36eaa4df37SBrian Somers #include <netinet/in_systm.h> 37eaa4df37SBrian Somers #include <netinet/ip.h> 381ae349f5Scvs2svn 391ae349f5Scvs2svn #include <stdio.h> 401ae349f5Scvs2svn #include <string.h> 411ae349f5Scvs2svn #include <sys/ioctl.h> 421ae349f5Scvs2svn #include <sys/errno.h> 431ae349f5Scvs2svn 441ae349f5Scvs2svn #include "command.h" 451ae349f5Scvs2svn #include "mbuf.h" 461ae349f5Scvs2svn #include "log.h" 4763258dccSBrian Somers #include "timer.h" 48879ed6faSBrian Somers #include "lqr.h" 491ae349f5Scvs2svn #include "hdlc.h" 501ae349f5Scvs2svn #include "defs.h" 511ae349f5Scvs2svn #include "loadalias.h" 521ae349f5Scvs2svn #include "vars.h" 536d666775SBrian Somers #include "fsm.h" 545828db6dSBrian Somers #include "throughput.h" 555828db6dSBrian Somers #include "iplist.h" 56eaa4df37SBrian Somers #include "slcompress.h" 575828db6dSBrian Somers #include "ipcp.h" 585ca5389aSBrian Somers #include "filter.h" 592f786681SBrian Somers #include "descriptor.h" 603b0f8d2eSBrian Somers #include "lcp.h" 613b0f8d2eSBrian Somers #include "ccp.h" 623b0f8d2eSBrian Somers #include "link.h" 633b0f8d2eSBrian Somers #include "mp.h" 647a6f8720SBrian Somers #include "bundle.h" 651ae349f5Scvs2svn #include "tun.h" 661ae349f5Scvs2svn 671ae349f5Scvs2svn void 687a6f8720SBrian Somers tun_configure(struct bundle *bundle, int mtu, int speed) 691ae349f5Scvs2svn { 701ae349f5Scvs2svn struct tuninfo info; 711ae349f5Scvs2svn 721ae349f5Scvs2svn info.type = 23; 731ae349f5Scvs2svn info.mtu = mtu; 741ae349f5Scvs2svn if (VarPrefMTU != 0 && VarPrefMTU < mtu) 751ae349f5Scvs2svn info.mtu = VarPrefMTU; 761ae349f5Scvs2svn info.baudrate = speed; 771ae349f5Scvs2svn #ifdef __OpenBSD__ 781ae349f5Scvs2svn info.flags = IFF_UP|IFF_POINTOPOINT; 791ae349f5Scvs2svn #endif 807a6f8720SBrian Somers if (ioctl(bundle->tun_fd, TUNSIFINFO, &info) < 0) 811ae349f5Scvs2svn LogPrintf(LogERROR, "tun_configure: ioctl(TUNSIFINFO): %s\n", 821ae349f5Scvs2svn strerror(errno)); 831ae349f5Scvs2svn } 84