1 /* $NetBSD: if_spppsubr50.c,v 1.4 2019/12/12 02:15:42 pgoyette Exp $ */ 2 3 /* 4 * Synchronous PPP/Cisco link level subroutines. 5 * Keepalive protocol implemented in both Cisco and PPP modes. 6 * 7 * Copyright (C) 1994-1996 Cronyx Engineering Ltd. 8 * Author: Serge Vakulenko, <vak@cronyx.ru> 9 * 10 * Heavily revamped to conform to RFC 1661. 11 * Copyright (C) 1997, Joerg Wunsch. 12 * 13 * RFC2472 IPv6CP support. 14 * Copyright (C) 2000, Jun-ichiro itojun Hagino <itojun@iijlab.net>. 15 * 16 * Redistribution and use in source and binary forms, with or without 17 * modification, are permitted provided that the following conditions are met: 18 * 1. Redistributions of source code must retain the above copyright notice, 19 * this list of conditions and the following disclaimer. 20 * 2. Redistributions in binary form must reproduce the above copyright notice, 21 * this list of conditions and the following disclaimer in the documentation 22 * and/or other materials provided with the distribution. 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE FREEBSD PROJECT ``AS IS'' AND ANY 25 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * ARE DISCLAIMED. IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE 28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 * POSSIBILITY OF SUCH DAMAGE. 35 * 36 * From: Version 2.4, Thu Apr 30 17:17:21 MSD 1997 37 * 38 * From: if_spppsubr.c,v 1.39 1998/04/04 13:26:03 phk Exp 39 * 40 * From: Id: if_spppsubr.c,v 1.23 1999/02/23 14:47:50 hm Exp 41 */ 42 43 #include <sys/cdefs.h> 44 __KERNEL_RCSID(0, "$NetBSD: if_spppsubr50.c,v 1.4 2019/12/12 02:15:42 pgoyette Exp $"); 45 46 #if defined(_KERNEL_OPT) 47 #include "opt_inet.h" 48 #include "opt_modular.h" 49 #include "opt_compat_netbsd.h" 50 #include "opt_net_mpsafe.h" 51 #endif 52 53 54 #include <sys/param.h> 55 #include <sys/proc.h> 56 #include <sys/systm.h> 57 #include <sys/kernel.h> 58 #include <sys/sockio.h> 59 #include <sys/socket.h> 60 #include <sys/syslog.h> 61 #include <sys/malloc.h> 62 #include <sys/mbuf.h> 63 #include <sys/callout.h> 64 #include <sys/md5.h> 65 #include <sys/inttypes.h> 66 #include <sys/kauth.h> 67 #include <sys/cprng.h> 68 #include <sys/module.h> 69 #include <sys/workqueue.h> 70 #include <sys/atomic.h> 71 #include <sys/compat_stub.h> 72 73 #include <net/if.h> 74 #include <net/netisr.h> 75 #include <net/if_types.h> 76 #include <net/route.h> 77 #include <net/ppp_defs.h> 78 79 #include <netinet/in.h> 80 #include <netinet/in_systm.h> 81 #include <netinet/in_var.h> 82 #ifdef INET 83 #include <netinet/ip.h> 84 #include <netinet/tcp.h> 85 #endif 86 #include <net/ethertypes.h> 87 88 #ifdef INET6 89 #include <netinet6/scope6_var.h> 90 #endif 91 92 #include <net/if_sppp.h> 93 #include <net/if_spppvar.h> 94 95 #include <compat/common/if_spppsubr50.h> 96 97 #ifdef NET_MPSAFE 98 #define SPPPSUBR_MPSAFE 1 99 #endif 100 101 #define SPPP_LOCK(_sp, _op) rw_enter(&(_sp)->pp_lock, (_op)) 102 #define SPPP_UNLOCK(_sp) rw_exit(&(_sp)->pp_lock) 103 104 int sppp_compat50_params(struct sppp *, u_long, void *); 105 106 int 107 sppp_compat50_params(struct sppp *sp, u_long cmd, void *data) 108 { 109 switch (cmd) { 110 case __SPPPGETIDLETO50: 111 { 112 struct spppidletimeout50 *to = (struct spppidletimeout50 *)data; 113 114 SPPP_LOCK(sp, RW_READER); 115 to->idle_seconds = (uint32_t)sp->pp_idle_timeout; 116 SPPP_UNLOCK(sp); 117 } 118 break; 119 case __SPPPSETIDLETO50: 120 { 121 struct spppidletimeout50 *to = (struct spppidletimeout50 *)data; 122 123 SPPP_LOCK(sp, RW_WRITER); 124 sp->pp_idle_timeout = (time_t)to->idle_seconds; 125 SPPP_UNLOCK(sp); 126 } 127 break; 128 case __SPPPGETKEEPALIVE50: 129 { 130 struct spppkeepalivesettings50 *settings = 131 (struct spppkeepalivesettings50*)data; 132 133 SPPP_LOCK(sp, RW_READER); 134 settings->maxalive = sp->pp_maxalive; 135 settings->max_noreceive = (uint32_t)sp->pp_max_noreceive; 136 SPPP_UNLOCK(sp); 137 } 138 break; 139 case __SPPPSETKEEPALIVE50: 140 { 141 struct spppkeepalivesettings50 *settings = 142 (struct spppkeepalivesettings50*)data; 143 144 SPPP_LOCK(sp, RW_WRITER); 145 sp->pp_maxalive = settings->maxalive; 146 sp->pp_max_noreceive = (time_t)settings->max_noreceive; 147 SPPP_UNLOCK(sp); 148 } 149 break; 150 default: 151 return EINVAL; 152 } 153 154 return 0; 155 } 156 157 void 158 if_spppsubr_50_init(void) 159 { 160 161 MODULE_HOOK_SET(sppp_params_50_hook, sppp_compat50_params); 162 } 163 164 void 165 if_spppsubr_50_fini(void) 166 { 167 168 MODULE_HOOK_UNSET(sppp_params_50_hook); 169 } 170