xref: /freebsd/usr.sbin/ppp/tun.c (revision 972a1bcf5db5ee4c5520a1d29d3c81e81bdec84f)
1c39934eaSBrian Somers /*-
2c39934eaSBrian Somers  * Copyright (c) 1997 Brian Somers <brian@Awfulhak.org>
3c39934eaSBrian Somers  * All rights reserved.
4c39934eaSBrian Somers  *
5c39934eaSBrian Somers  * Redistribution and use in source and binary forms, with or without
6c39934eaSBrian Somers  * modification, are permitted provided that the following conditions
7c39934eaSBrian Somers  * are met:
8c39934eaSBrian Somers  * 1. Redistributions of source code must retain the above copyright
9c39934eaSBrian Somers  *    notice, this list of conditions and the following disclaimer.
10c39934eaSBrian Somers  * 2. Redistributions in binary form must reproduce the above copyright
11c39934eaSBrian Somers  *    notice, this list of conditions and the following disclaimer in the
12c39934eaSBrian Somers  *    documentation and/or other materials provided with the distribution.
13c39934eaSBrian Somers  *
14c39934eaSBrian Somers  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15c39934eaSBrian Somers  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16c39934eaSBrian Somers  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17c39934eaSBrian Somers  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18c39934eaSBrian Somers  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19c39934eaSBrian Somers  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20c39934eaSBrian Somers  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21c39934eaSBrian Somers  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22c39934eaSBrian Somers  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23c39934eaSBrian Somers  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24c39934eaSBrian Somers  * SUCH DAMAGE.
25c39934eaSBrian Somers  *
26972a1bcfSBrian Somers  *	$Id: tun.c,v 1.10 1998/10/22 02:32:50 brian Exp $
27c7d4711fSBrian Somers  */
28c7d4711fSBrian Somers 
29972a1bcfSBrian Somers #include <sys/param.h>
3010a9be1eSBrian Somers #include <sys/socket.h>		/* For IFF_ defines */
3110a9be1eSBrian Somers #include <net/if.h>		/* For IFF_ defines */
321ae349f5Scvs2svn #include <netinet/in.h>
3344cae95dSBrian Somers #include <net/if_types.h>
346a6b4bbbSBrian Somers #include <net/if_tun.h>
35eaa4df37SBrian Somers #include <netinet/in_systm.h>
36eaa4df37SBrian Somers #include <netinet/ip.h>
371fa665f5SBrian Somers #include <sys/un.h>
386a6b4bbbSBrian Somers 
396a6b4bbbSBrian Somers #include <string.h>
406a6b4bbbSBrian Somers #include <sys/ioctl.h>
416a6b4bbbSBrian Somers #include <sys/errno.h>
426a6b4bbbSBrian Somers 
43b6e82f33SBrian Somers #include "mbuf.h"
44b6e82f33SBrian Somers #include "log.h"
4563258dccSBrian Somers #include "timer.h"
46879ed6faSBrian Somers #include "lqr.h"
476a6b4bbbSBrian Somers #include "hdlc.h"
486a6b4bbbSBrian Somers #include "defs.h"
496d666775SBrian Somers #include "fsm.h"
505828db6dSBrian Somers #include "throughput.h"
515828db6dSBrian Somers #include "iplist.h"
52eaa4df37SBrian Somers #include "slcompress.h"
535828db6dSBrian Somers #include "ipcp.h"
545ca5389aSBrian Somers #include "filter.h"
552f786681SBrian Somers #include "descriptor.h"
563b0f8d2eSBrian Somers #include "lcp.h"
573b0f8d2eSBrian Somers #include "ccp.h"
583b0f8d2eSBrian Somers #include "link.h"
593b0f8d2eSBrian Somers #include "mp.h"
60972a1bcfSBrian Somers #ifndef NORADIUS
61972a1bcfSBrian Somers #include "radius.h"
62972a1bcfSBrian Somers #endif
637a6f8720SBrian Somers #include "bundle.h"
646a6b4bbbSBrian Somers #include "tun.h"
656a6b4bbbSBrian Somers 
666a6b4bbbSBrian Somers void
67faefde08SBrian Somers tun_configure(struct bundle *bundle, int mtu)
686a6b4bbbSBrian Somers {
696a6b4bbbSBrian Somers   struct tuninfo info;
706a6b4bbbSBrian Somers 
718fa6ebe4SBrian Somers   memset(&info, '\0', sizeof info);
7244cae95dSBrian Somers   info.type = IFT_PPP;
73972a1bcfSBrian Somers #ifndef NORADIUS
74972a1bcfSBrian Somers   if (bundle->radius.valid && bundle->radius.mtu && bundle->radius.mtu < mtu) {
75972a1bcfSBrian Somers     log_Printf(LogLCP, "Reducing MTU to radius value %lu\n",
76972a1bcfSBrian Somers                bundle->radius.mtu);
77972a1bcfSBrian Somers     info.mtu = bundle->radius.mtu;
78972a1bcfSBrian Somers   } else
79972a1bcfSBrian Somers #endif
806a6b4bbbSBrian Somers     info.mtu = mtu;
81972a1bcfSBrian Somers 
828fa6ebe4SBrian Somers   info.baudrate = bundle->ifSpeed;
836a6b4bbbSBrian Somers #ifdef __OpenBSD__
846a6b4bbbSBrian Somers   info.flags = IFF_UP|IFF_POINTOPOINT;
856a6b4bbbSBrian Somers #endif
86faefde08SBrian Somers   if (ioctl(bundle->dev.fd, TUNSIFINFO, &info) < 0)
87dd7e2610SBrian Somers     log_Printf(LogERROR, "tun_configure: ioctl(TUNSIFINFO): %s\n",
886a6b4bbbSBrian Somers 	      strerror(errno));
896a6b4bbbSBrian Somers }
90