Home | History | Annotate | Line # | Download | only in net
if_spppvar.h revision 1.23
      1 /*	$NetBSD: if_spppvar.h,v 1.23 2020/04/04 17:12:33 is Exp $	*/
      2 
      3 #ifndef _NET_IF_SPPPVAR_H_
      4 #define _NET_IF_SPPPVAR_H_
      5 
      6 /*
      7  * Defines for synchronous PPP/Cisco link level subroutines.
      8  *
      9  * Copyright (C) 1994 Cronyx Ltd.
     10  * Author: Serge Vakulenko, <vak (at) cronyx.ru>
     11  *
     12  * Heavily revamped to conform to RFC 1661.
     13  * Copyright (C) 1997, Joerg Wunsch.
     14  *
     15  * This software is distributed with NO WARRANTIES, not even the implied
     16  * warranties for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
     17  *
     18  * Authors grant any other persons or organizations permission to use
     19  * or modify this software as long as this message is kept with the software,
     20  * all derivative works or modified versions.
     21  *
     22  * From: Version 2.0, Fri Oct  6 20:39:21 MSK 1995
     23  *
     24  * From: if_sppp.h,v 1.8 1997/10/11 11:25:20 joerg Exp
     25  *
     26  * From: Id: if_sppp.h,v 1.7 1998/12/01 20:20:19 hm Exp
     27  */
     28 
     29 #include <sys/workqueue.h>
     30 #include <sys/pcq.h>
     31 
     32 #include <net/if_media.h>
     33 
     34 #define IDX_LCP 0		/* idx into state table */
     35 
     36 struct slcp {
     37 	u_long	opts;		/* LCP options to send (bitfield) */
     38 	u_long  magic;          /* local magic number */
     39 	u_long	mru;		/* our max receive unit */
     40 	u_long	their_mru;	/* their max receive unit */
     41 	u_long	protos;		/* bitmask of protos that are started */
     42 	u_char  echoid;         /* id of last keepalive echo request */
     43 	/* restart max values, see RFC 1661 */
     44 	int	timeout;
     45 	int	max_terminate;
     46 	int	max_configure;
     47 	int	max_failure;
     48 	/* multilink variables */
     49 	u_long	mrru;		/* our   max received reconstructed unit */
     50 	u_long	their_mrru;	/* their max receive dreconstructed unit */
     51 };
     52 
     53 #define IDX_IPCP 1		/* idx into state table */
     54 #define IDX_IPV6CP 2		/* idx into state table */
     55 
     56 struct sipcp {
     57 	u_long	opts;		/* IPCP options to send (bitfield) */
     58 	u_int	flags;
     59 #define IPCP_HISADDR_SEEN 1	/* have seen his address already */
     60 #define IPCP_MYADDR_SEEN  2	/* have a local address assigned already */
     61 #define IPCP_MYADDR_DYN   4	/* my address is dynamically assigned */
     62 #define	IPCP_HISADDR_DYN  8	/* his address is dynamically assigned */
     63 #ifdef notdef
     64 #define IPV6CP_MYIFID_DYN   2	/* my ifid is dynamically assigned */
     65 #endif
     66 #define IPV6CP_MYIFID_SEEN  4	/* have seen his ifid already */
     67 	uint32_t saved_hisaddr;/* if hisaddr (IPv4) is dynamic, save original one here, in network byte order */
     68 	uint32_t req_hisaddr;	/* remote address requested */
     69 	uint32_t req_myaddr;	/* local address requested */
     70 
     71 	struct workqueue *update_addrs_wq;
     72 	struct work update_addrs_wk;
     73 	u_int update_addrs_enqueued;
     74 	pcq_t *update_addrs_q;
     75 };
     76 
     77 struct sauth {
     78 	u_short	proto;			/* authentication protocol to use */
     79 	u_short	flags;
     80 	char	*name;			/* system identification name */
     81 	char	*secret;		/* secret password */
     82 	u_char	name_len;		/* no need to have a bigger size */
     83 	u_char	secret_len;		/* because proto gives size in a byte */
     84 	char	challenge[16];		/* random challenge [don't change size! it's really hardcoded!] */
     85 };
     86 
     87 #define IDX_PAP		3
     88 #define IDX_CHAP	4
     89 
     90 #define IDX_COUNT (IDX_CHAP + 1) /* bump this when adding cp's! */
     91 
     92 struct sppp {
     93 	/* NB: pp_if _must_ be first */
     94 	struct  ifnet pp_if;    /* network interface data */
     95 	struct	ifmedia pp_im;	/* interface media, to report link status */
     96 	struct  ifqueue pp_fastq; /* fast output queue */
     97 	struct	ifqueue pp_cpq;	/* PPP control protocol queue */
     98 	struct  sppp *pp_next;  /* next interface in keepalive list */
     99 	u_int   pp_flags;       /* use Cisco protocol instead of PPP */
    100 	u_int	pp_framebytes;	/* number of bytes added by (hardware) framing */
    101 	u_int   pp_alivecnt;    /* keepalive packets counter */
    102 	u_int   pp_loopcnt;     /* loopback detection counter */
    103 	u_int	pp_maxalive;	/* number or echo req. w/o reply */
    104 	u_long  pp_seq[IDX_COUNT];	/* local sequence number */
    105 	u_long  pp_rseq[IDX_COUNT];	/* remote sequence number */
    106 	uint64_t	pp_saved_mtu;	/* saved MTU value */
    107 	time_t	pp_last_receive;	/* peer's last "sign of life" */
    108 	time_t	pp_max_noreceive;	/* seconds since last receive before
    109 					   we start to worry and send echo
    110 					   requests */
    111 	time_t	pp_last_activity;	/* second of last payload data s/r */
    112 	time_t	pp_idle_timeout;	/* idle seconds before auto-disconnect,
    113 					 * 0 = disabled */
    114 	int	pp_auth_failures;	/* authorization failures */
    115 	int	pp_max_auth_fail;	/* max. allowed authorization failures */
    116 	int	pp_phase;	/* phase we're currently in */
    117 	krwlock_t	pp_lock;	/* lock for sppp structure */
    118 	int	query_dns;	/* 1 if we want to know the dns addresses */
    119 	uint32_t	dns_addrs[2];
    120 	int	state[IDX_COUNT];	/* state machine */
    121 	u_char  confid[IDX_COUNT];	/* id of last configuration request */
    122 	int	rst_counter[IDX_COUNT];	/* restart counter */
    123 	int	fail_counter[IDX_COUNT]; /* negotiation failure counter */
    124 #if defined(__NetBSD__)
    125 	struct	callout ch[IDX_COUNT];	/* per-proto and if callouts */
    126 	struct	callout pap_my_to_ch;	/* PAP needs one more... */
    127 #endif
    128 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
    129 	struct callout_handle ch[IDX_COUNT]; /* per-proto and if callouts */
    130 	struct callout_handle pap_my_to_ch; /* PAP needs one more... */
    131 #endif
    132 	struct slcp lcp;		/* LCP params */
    133 	struct sipcp ipcp;		/* IPCP params */
    134 	struct sipcp ipv6cp;		/* IPv6CP params */
    135 	struct sauth myauth;		/* auth params, i'm peer */
    136 	struct sauth hisauth;		/* auth params, i'm authenticator */
    137 	/*
    138 	 * These functions are filled in by sppp_attach(), and are
    139 	 * expected to be used by the lower layer (hardware) drivers
    140 	 * in order to communicate the (un)availability of the
    141 	 * communication link.  Lower layer drivers that are always
    142 	 * ready to communicate (like hardware HDLC) can shortcut
    143 	 * pp_up from pp_tls, and pp_down from pp_tlf.
    144 	 */
    145 	void	(*pp_up)(struct sppp *);
    146 	void	(*pp_down)(struct sppp *);
    147 	/*
    148 	 * These functions need to be filled in by the lower layer
    149 	 * (hardware) drivers if they request notification from the
    150 	 * PPP layer whether the link is actually required.  They
    151 	 * correspond to the tls and tlf actions.
    152 	 */
    153 	void	(*pp_tls)(struct sppp *);
    154 	void	(*pp_tlf)(struct sppp *);
    155 	/*
    156 	 * These (optional) functions may be filled by the hardware
    157 	 * driver if any notification of established connections
    158 	 * (currently: IPCP up) is desired (pp_con) or any internal
    159 	 * state change of the interface state machine should be
    160 	 * signaled for monitoring purposes (pp_chg).
    161 	 */
    162 	void	(*pp_con)(struct sppp *);
    163 	void	(*pp_chg)(struct sppp *, int);
    164 };
    165 
    166 #define PP_KEEPALIVE    0x01    /* use keepalive protocol */
    167 #define PP_CISCO        0x02    /* use Cisco protocol instead of PPP */
    168 				/* 0x04 was PP_TIMO */
    169 #define PP_CALLIN	0x08	/* we are being called */
    170 #define PP_NEEDAUTH	0x10	/* remote requested authentication */
    171 #define	PP_NOFRAMING	0x20	/* do not add/expect encapsulation
    172 				   around PPP frames (i.e. the serial
    173 				   HDLC like encapsulation, RFC1662) */
    174 
    175 
    176 #define PP_MTU          1500    /* default/minimal MRU */
    177 #define PP_MAX_MRU	2048	/* maximal MRU we want to negotiate */
    178 
    179 #ifdef _KERNEL
    180 void sppp_attach (struct ifnet *);
    181 void sppp_detach (struct ifnet *);
    182 void sppp_input (struct ifnet *, struct mbuf *);
    183 int sppp_ioctl(struct ifnet *, u_long, void *);
    184 struct mbuf *sppp_dequeue (struct ifnet *);
    185 int sppp_isempty (struct ifnet *);
    186 void sppp_flush (struct ifnet *);
    187 #endif
    188 
    189 /*
    190  * Locking notes:
    191  * + spppq is protected by spppq_lock (an adaptive mutex)
    192  *     spppq is a list of all struct sppps, and it is used for
    193  *     sending keepalive packets.
    194  * + struct sppp is protected by sppp->pp_lock (an rwlock)
    195  *     sppp holds configuration parameters for line,
    196  *     authentication and addresses. It also has pointers
    197  *     of functions to notify events to lower layer.
    198  *     When notify events, sppp->pp_lock must be released.
    199  *     Because the event handler implemented in a lower
    200  *     layer often call functions implemented in
    201  *     if_spppsubr.c.
    202  *
    203  * Locking order:
    204  *    - spppq_lock => struct sppp->pp_lock
    205  *
    206  * NOTICE
    207  * - Lower layers must not acquire sppp->pp_lock
    208  */
    209 #endif /* !_NET_IF_SPPPVAR_H_ */
    210