Home | History | Annotate | Line # | Download | only in net
if_spppvar.h revision 1.29
      1 /*	$NetBSD: if_spppvar.h,v 1.29 2020/11/25 09:46:05 yamaguchi 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 struct sppp;
     32 
     33 struct sppp_work {
     34 	struct work	 work;
     35 	void		*arg;
     36 	void		(*func)(struct sppp *, void *);
     37 	unsigned int	 state;
     38 #define SPPP_WK_FREE	0
     39 #define SPPP_WK_BUSY	1
     40 #define SPPP_WK_UNAVAIL	2
     41 };
     42 
     43 #define IDX_LCP 0		/* idx into state table */
     44 
     45 struct slcp {
     46 	u_long	opts;		/* LCP options to send (bitfield) */
     47 	u_long  magic;          /* local magic number */
     48 	u_long	mru;		/* our max receive unit */
     49 	u_long	their_mru;	/* their max receive unit */
     50 	u_long	protos;		/* bitmask of protos that are started */
     51 	u_char  echoid;         /* id of last keepalive echo request */
     52 	/* restart max values, see RFC 1661 */
     53 	int	timeout;
     54 	int	max_terminate;
     55 	int	max_configure;
     56 	int	max_failure;
     57 	/* multilink variables */
     58 	u_long	mrru;		/* our   max received reconstructed unit */
     59 	u_long	their_mrru;	/* their max receive dreconstructed unit */
     60 	bool	reestablish;	/* reestablish after the next down event */
     61 };
     62 
     63 #define IDX_IPCP 1		/* idx into state table */
     64 #define IDX_IPV6CP 2		/* idx into state table */
     65 
     66 struct sipcp {
     67 	u_long	opts;		/* IPCP options to send (bitfield) */
     68 	u_int	flags;
     69 #define IPCP_HISADDR_SEEN 1	/* have seen his address already */
     70 #define IPCP_MYADDR_SEEN  2	/* have a local address assigned already */
     71 #define IPCP_MYADDR_DYN   4	/* my address is dynamically assigned */
     72 #define	IPCP_HISADDR_DYN  8	/* his address is dynamically assigned */
     73 #ifdef notdef
     74 #define IPV6CP_MYIFID_DYN   2	/* my ifid is dynamically assigned */
     75 #endif
     76 #define IPV6CP_MYIFID_SEEN  4	/* have seen his ifid already */
     77 	uint32_t saved_hisaddr;/* if hisaddr (IPv4) is dynamic, save original one here, in network byte order */
     78 	uint32_t req_hisaddr;	/* remote address requested */
     79 	uint32_t req_myaddr;	/* local address requested */
     80 
     81 	struct workqueue *update_addrs_wq;
     82 	struct work update_addrs_wk;
     83 	u_int update_addrs_enqueued;
     84 	pcq_t *update_addrs_q;
     85 };
     86 
     87 struct sauth {
     88 	u_short	proto;			/* authentication protocol to use */
     89 	u_short	flags;
     90 	char	*name;			/* system identification name */
     91 	char	*secret;		/* secret password */
     92 	u_char	name_len;		/* no need to have a bigger size */
     93 	u_char	secret_len;		/* because proto gives size in a byte */
     94 };
     95 
     96 struct schap {
     97 	char	 challenge[16];		/* random challenge
     98 					   [don't change size! it's really hardcoded!] */
     99 	char	 digest[16];
    100 	u_char	 digest_len;
    101 	bool	 rechallenging;		/* sent challenge after open */
    102 	bool	 response_rcvd;		/* receive response, stop sending challenge */
    103 
    104 	struct sppp_work	 work_challenge_rcvd;
    105 };
    106 
    107 #define IDX_PAP		3
    108 #define IDX_CHAP	4
    109 
    110 #define IDX_COUNT (IDX_CHAP + 1) /* bump this when adding cp's! */
    111 
    112 struct sppp_cp {
    113 	u_long		 seq;		/* local sequence number */
    114 	u_long		 rseq;		/* remote sequence number */
    115 	int		 state;		/* state machine */
    116 	u_char		 confid;	/* local id of last configuration request */
    117 	u_char		 rconfid;	/* remote id of last configuration request */
    118 	int		 rst_counter;	/* restart counter */
    119 	int		 fail_counter;	/* negotiation failure counter */
    120 	struct callout	 ch;		/* per-proto and if callouts */
    121 	u_char		 rcr_type;
    122 	void		*rcr_buf;
    123 	size_t		 rcr_blen;
    124 	int		 rcr_rlen;
    125 
    126 	struct sppp_work	 work_up;
    127 	struct sppp_work	 work_down;
    128 	struct sppp_work	 work_open;
    129 	struct sppp_work	 work_close;
    130 	struct sppp_work	 work_to;
    131 	struct sppp_work	 work_rcr;
    132 	struct sppp_work	 work_rca;
    133 	struct sppp_work	 work_rcn;
    134 	struct sppp_work	 work_rtr;
    135 	struct sppp_work	 work_rta;
    136 	struct sppp_work	 work_rxj;
    137 };
    138 
    139 struct sppp {
    140 	/* NB: pp_if _must_ be first */
    141 	struct  ifnet pp_if;    /* network interface data */
    142 	struct  ifqueue pp_fastq; /* fast output queue */
    143 	struct	ifqueue pp_cpq;	/* PPP control protocol queue */
    144 	struct  sppp *pp_next;  /* next interface in keepalive list */
    145 	u_int   pp_flags;       /* use Cisco protocol instead of PPP */
    146 	u_int	pp_framebytes;	/* number of bytes added by (hardware) framing */
    147 	u_int   pp_alivecnt;    /* keepalive packets counter */
    148 	u_int   pp_loopcnt;     /* loopback detection counter */
    149 	u_int	pp_maxalive;	/* number or echo req. w/o reply */
    150 	uint64_t	pp_saved_mtu;	/* saved MTU value */
    151 	time_t	pp_last_receive;	/* peer's last "sign of life" */
    152 	time_t	pp_max_noreceive;	/* seconds since last receive before
    153 					   we start to worry and send echo
    154 					   requests */
    155 	time_t	pp_last_activity;	/* second of last payload data s/r */
    156 	time_t	pp_idle_timeout;	/* idle seconds before auto-disconnect,
    157 					 * 0 = disabled */
    158 	int	pp_auth_failures;	/* authorization failures */
    159 	int	pp_max_auth_fail;	/* max. allowed authorization failures */
    160 	int	pp_phase;	/* phase we're currently in */
    161 	krwlock_t	pp_lock;	/* lock for sppp structure */
    162 	int	query_dns;	/* 1 if we want to know the dns addresses */
    163 	uint32_t	dns_addrs[2];
    164 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
    165 	struct callout_handle ch[IDX_COUNT]; /* per-proto and if callouts */
    166 	struct callout_handle pap_my_to_ch; /* PAP needs one more... */
    167 #endif
    168 	struct workqueue *wq_cp;
    169 	struct sppp_work work_ifdown;
    170 	struct sppp_cp scp[IDX_COUNT];
    171 	struct slcp lcp;		/* LCP params */
    172 	struct sipcp ipcp;		/* IPCP params */
    173 	struct sipcp ipv6cp;		/* IPv6CP params */
    174 	struct sauth myauth;		/* auth params, i'm peer */
    175 	struct sauth hisauth;		/* auth params, i'm authenticator */
    176 	struct schap chap;		/* CHAP params */
    177 	/*
    178 	 * These functions are filled in by sppp_attach(), and are
    179 	 * expected to be used by the lower layer (hardware) drivers
    180 	 * in order to communicate the (un)availability of the
    181 	 * communication link.  Lower layer drivers that are always
    182 	 * ready to communicate (like hardware HDLC) can shortcut
    183 	 * pp_up from pp_tls, and pp_down from pp_tlf.
    184 	 */
    185 	void	(*pp_up)(struct sppp *);
    186 	void	(*pp_down)(struct sppp *);
    187 	/*
    188 	 * These functions need to be filled in by the lower layer
    189 	 * (hardware) drivers if they request notification from the
    190 	 * PPP layer whether the link is actually required.  They
    191 	 * correspond to the tls and tlf actions.
    192 	 */
    193 	void	(*pp_tls)(struct sppp *);
    194 	void	(*pp_tlf)(struct sppp *);
    195 	/*
    196 	 * These (optional) functions may be filled by the hardware
    197 	 * driver if any notification of established connections
    198 	 * (currently: IPCP up) is desired (pp_con) or any internal
    199 	 * state change of the interface state machine should be
    200 	 * signaled for monitoring purposes (pp_chg).
    201 	 */
    202 	void	(*pp_con)(struct sppp *);
    203 	void	(*pp_chg)(struct sppp *, int);
    204 };
    205 
    206 #define PP_KEEPALIVE    0x01    /* use keepalive protocol */
    207 #define PP_CISCO        0x02    /* use Cisco protocol instead of PPP */
    208 				/* 0x04 was PP_TIMO */
    209 #define PP_CALLIN	0x08	/* we are being called */
    210 #define PP_NEEDAUTH	0x10	/* remote requested authentication */
    211 #define	PP_NOFRAMING	0x20	/* do not add/expect encapsulation
    212 				   around PPP frames (i.e. the serial
    213 				   HDLC like encapsulation, RFC1662) */
    214 
    215 
    216 #define PP_MTU          1500    /* default/minimal MRU */
    217 #define PP_MAX_MRU	2048	/* maximal MRU we want to negotiate */
    218 
    219 #ifdef _KERNEL
    220 void sppp_attach (struct ifnet *);
    221 void sppp_detach (struct ifnet *);
    222 void sppp_input (struct ifnet *, struct mbuf *);
    223 int sppp_ioctl(struct ifnet *, u_long, void *);
    224 struct mbuf *sppp_dequeue (struct ifnet *);
    225 int sppp_isempty (struct ifnet *);
    226 void sppp_flush (struct ifnet *);
    227 #endif
    228 
    229 /*
    230  * Locking notes:
    231  * + spppq is protected by spppq_lock (an adaptive mutex)
    232  *     spppq is a list of all struct sppps, and it is used for
    233  *     sending keepalive packets.
    234  * + struct sppp is protected by sppp->pp_lock (an rwlock)
    235  *     sppp holds configuration parameters for line,
    236  *     authentication and addresses. It also has pointers
    237  *     of functions to notify events to lower layer.
    238  *     When notify events, sppp->pp_lock must be released.
    239  *     Because the event handler implemented in a lower
    240  *     layer often call functions implemented in
    241  *     if_spppsubr.c.
    242  *
    243  * Locking order:
    244  *    - spppq_lock => struct sppp->pp_lock
    245  *
    246  * NOTICE
    247  * - Lower layers must not acquire sppp->pp_lock
    248  */
    249 #endif /* !_NET_IF_SPPPVAR_H_ */
    250