Home | History | Annotate | Line # | Download | only in common
      1 /*	$NetBSD: if_spppsubr50.c,v 1.5 2022/09/03 03:11:56 thorpej 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 (at) 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 (at) 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.5 2022/09/03 03:11:56 thorpej 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/if_types.h>
     75 #include <net/route.h>
     76 #include <net/ppp_defs.h>
     77 
     78 #include <netinet/in.h>
     79 #include <netinet/in_systm.h>
     80 #include <netinet/in_var.h>
     81 #ifdef INET
     82 #include <netinet/ip.h>
     83 #include <netinet/tcp.h>
     84 #endif
     85 #include <net/ethertypes.h>
     86 
     87 #ifdef INET6
     88 #include <netinet6/scope6_var.h>
     89 #endif
     90 
     91 #include <net/if_sppp.h>
     92 #include <net/if_spppvar.h>
     93 
     94 #include <compat/common/if_spppsubr50.h>
     95 
     96 #ifdef NET_MPSAFE
     97 #define SPPPSUBR_MPSAFE	1
     98 #endif
     99 
    100 #define SPPP_LOCK(_sp, _op)	rw_enter(&(_sp)->pp_lock, (_op))
    101 #define SPPP_UNLOCK(_sp)	rw_exit(&(_sp)->pp_lock)
    102 
    103 int sppp_compat50_params(struct sppp *, u_long, void *);
    104 
    105 int
    106 sppp_compat50_params(struct sppp *sp, u_long cmd, void *data)
    107 {
    108 	switch (cmd) {
    109 	case __SPPPGETIDLETO50:
    110 	    {
    111 	    	struct spppidletimeout50 *to = (struct spppidletimeout50 *)data;
    112 
    113 		SPPP_LOCK(sp, RW_READER);
    114 		to->idle_seconds = (uint32_t)sp->pp_idle_timeout;
    115 		SPPP_UNLOCK(sp);
    116 	    }
    117 	    break;
    118 	case __SPPPSETIDLETO50:
    119 	    {
    120 		struct spppidletimeout50 *to = (struct spppidletimeout50 *)data;
    121 
    122 		SPPP_LOCK(sp, RW_WRITER);
    123 		sp->pp_idle_timeout = (time_t)to->idle_seconds;
    124 		SPPP_UNLOCK(sp);
    125 	    }
    126 	    break;
    127 	case __SPPPGETKEEPALIVE50:
    128 	    {
    129 	    	struct spppkeepalivesettings50 *settings =
    130 		     (struct spppkeepalivesettings50*)data;
    131 
    132 		SPPP_LOCK(sp, RW_READER);
    133 		settings->maxalive = sp->pp_maxalive;
    134 		settings->max_noreceive = (uint32_t)sp->pp_max_noreceive;
    135 		SPPP_UNLOCK(sp);
    136 	    }
    137 	    break;
    138 	case __SPPPSETKEEPALIVE50:
    139 	    {
    140 	    	struct spppkeepalivesettings50 *settings =
    141 		     (struct spppkeepalivesettings50*)data;
    142 
    143 		SPPP_LOCK(sp, RW_WRITER);
    144 		sp->pp_maxalive = settings->maxalive;
    145 		sp->pp_max_noreceive = (time_t)settings->max_noreceive;
    146 		SPPP_UNLOCK(sp);
    147 	    }
    148 	    break;
    149 	default:
    150 	    return EINVAL;
    151 	}
    152 
    153 	return 0;
    154 }
    155 
    156 void
    157 if_spppsubr_50_init(void)
    158 {
    159 
    160 	MODULE_HOOK_SET(sppp_params_50_hook, sppp_compat50_params);
    161 }
    162 
    163 void
    164 if_spppsubr_50_fini(void)
    165 {
    166 
    167 	MODULE_HOOK_UNSET(sppp_params_50_hook);
    168 }
    169