131921Sbrian/*- 231921Sbrian * Copyright (c) 1997 Brian Somers <brian@Awfulhak.org> 331921Sbrian * All rights reserved. 431921Sbrian * 531921Sbrian * Redistribution and use in source and binary forms, with or without 631921Sbrian * modification, are permitted provided that the following conditions 731921Sbrian * are met: 831921Sbrian * 1. Redistributions of source code must retain the above copyright 931921Sbrian * notice, this list of conditions and the following disclaimer. 1031921Sbrian * 2. Redistributions in binary form must reproduce the above copyright 1131921Sbrian * notice, this list of conditions and the following disclaimer in the 1231921Sbrian * documentation and/or other materials provided with the distribution. 1331921Sbrian * 1431921Sbrian * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1531921Sbrian * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1631921Sbrian * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1731921Sbrian * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1831921Sbrian * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1931921Sbrian * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2031921Sbrian * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2131921Sbrian * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2231921Sbrian * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2331921Sbrian * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2431921Sbrian * SUCH DAMAGE. 2531921Sbrian * 2650479Speter * $FreeBSD$ 2731196Sbrian */ 2831196Sbrian 2943313Sbrian#include <sys/param.h> 3078410Sbrian 3178410Sbrian#include <sys/socket.h> /* For IFF_ defines */ 3251447Sbrian#ifndef __FreeBSD__ 3337192Sbrian#include <net/if.h> /* For IFF_ defines */ 3449434Sbrian#endif 3578410Sbrian#include <net/route.h> 3631195Sbrian#include <netinet/in.h> 3738201Sbrian#include <net/if_types.h> 3831195Sbrian#include <net/if_tun.h> 3936285Sbrian#include <netinet/in_systm.h> 4036285Sbrian#include <netinet/ip.h> 4136285Sbrian#include <sys/un.h> 4231195Sbrian 4346085Sbrian#include <errno.h> 4431195Sbrian#include <string.h> 4549472Sbrian#if defined(__OpenBSD__) || defined(__NetBSD__) 4631195Sbrian#include <sys/ioctl.h> 4749472Sbrian#endif 4873988Sbrian#include <stdio.h> 4946686Sbrian#include <termios.h> 5046086Sbrian#ifdef __NetBSD__ 5146086Sbrian#include <unistd.h> 5246086Sbrian#endif 5331195Sbrian 5446686Sbrian#include "layer.h" 5531343Sbrian#include "mbuf.h" 5631343Sbrian#include "log.h" 5773988Sbrian#include "id.h" 5836285Sbrian#include "timer.h" 5936285Sbrian#include "lqr.h" 6031195Sbrian#include "hdlc.h" 6131195Sbrian#include "defs.h" 6236285Sbrian#include "fsm.h" 6336285Sbrian#include "throughput.h" 6436285Sbrian#include "iplist.h" 6536285Sbrian#include "slcompress.h" 6681634Sbrian#include "ncpaddr.h" 6736285Sbrian#include "ipcp.h" 6836285Sbrian#include "filter.h" 6936285Sbrian#include "descriptor.h" 7036285Sbrian#include "lcp.h" 7136285Sbrian#include "ccp.h" 7236285Sbrian#include "link.h" 7336285Sbrian#include "mp.h" 7478410Sbrian#include "iface.h" 7543313Sbrian#ifndef NORADIUS 7643313Sbrian#include "radius.h" 7743313Sbrian#endif 7881634Sbrian#include "ipv6cp.h" 7981634Sbrian#include "ncp.h" 8036285Sbrian#include "bundle.h" 8131195Sbrian#include "tun.h" 8231195Sbrian 8331195Sbrianvoid 8469303Sbriantun_configure(struct bundle *bundle) 8531195Sbrian{ 8646086Sbrian#ifdef __NetBSD__ 8746086Sbrian struct ifreq ifr; 8846086Sbrian int s; 8998243Sbrian 9089422Sbrian s = socket(PF_INET, SOCK_DGRAM, 0); 9198243Sbrian 9246086Sbrian if (s < 0) { 9346086Sbrian log_Printf(LogERROR, "tun_configure: socket(): %s\n", strerror(errno)); 9446086Sbrian return; 9546086Sbrian } 9646086Sbrian 9746086Sbrian sprintf(ifr.ifr_name, "tun%d", bundle->unit); 9878410Sbrian ifr.ifr_mtu = bundle->iface->mtu; 9946086Sbrian if (ioctl(s, SIOCSIFMTU, &ifr) < 0) 10046086Sbrian log_Printf(LogERROR, "tun_configure: ioctl(SIOCSIFMTU): %s\n", 10146086Sbrian strerror(errno)); 10246086Sbrian 10346086Sbrian close(s); 10446086Sbrian#else 10531195Sbrian struct tuninfo info; 10631195Sbrian 10740561Sbrian memset(&info, '\0', sizeof info); 10838201Sbrian info.type = IFT_PPP; 10978410Sbrian info.mtu = bundle->iface->mtu; 11098243Sbrian 11149434Sbrian info.baudrate = bundle->bandwidth; 11249434Sbrian#ifdef __OpenBSD__ 11382048Sbrian info.flags = IFF_UP|IFF_POINTOPOINT|IFF_MULTICAST; 11431195Sbrian#endif 11573988Sbrian if (ID0ioctl(bundle->dev.fd, TUNSIFINFO, &info) < 0) 11636285Sbrian log_Printf(LogERROR, "tun_configure: ioctl(TUNSIFINFO): %s\n", 11731195Sbrian strerror(errno)); 11846086Sbrian#endif 11931195Sbrian} 120