xref: /freebsd/usr.sbin/ppp/tun.c (revision eaa4df37f41891389081dc62e17cc172b36b8736)
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  *
26eaa4df37SBrian Somers  *	$Id: tun.c,v 1.6.4.7 1998/03/16 22:52:52 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"
597a6f8720SBrian Somers #include "bundle.h"
601ae349f5Scvs2svn #include "tun.h"
611ae349f5Scvs2svn 
621ae349f5Scvs2svn void
637a6f8720SBrian Somers tun_configure(struct bundle *bundle, int mtu, int speed)
641ae349f5Scvs2svn {
651ae349f5Scvs2svn   struct tuninfo info;
661ae349f5Scvs2svn 
671ae349f5Scvs2svn   info.type = 23;
681ae349f5Scvs2svn   info.mtu = mtu;
691ae349f5Scvs2svn   if (VarPrefMTU != 0 && VarPrefMTU < mtu)
701ae349f5Scvs2svn     info.mtu = VarPrefMTU;
711ae349f5Scvs2svn   info.baudrate = speed;
721ae349f5Scvs2svn #ifdef __OpenBSD__
731ae349f5Scvs2svn   info.flags = IFF_UP|IFF_POINTOPOINT;
741ae349f5Scvs2svn #endif
757a6f8720SBrian Somers   if (ioctl(bundle->tun_fd, TUNSIFINFO, &info) < 0)
761ae349f5Scvs2svn     LogPrintf(LogERROR, "tun_configure: ioctl(TUNSIFINFO): %s\n",
771ae349f5Scvs2svn 	      strerror(errno));
781ae349f5Scvs2svn }
79