xref: /titanic_52/usr/src/uts/common/io/ppp/sppp/sppp.h (revision 74e20cfe817b82802b16fac8690dadcda76f54f5)
1 /*
2  * sppp.h - Solaris STREAMS PPP multiplexing pseudo-driver definitions
3  *
4  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
5  * Use is subject to license terms.
6  *
7  * Permission to use, copy, modify, and distribute this software and its
8  * documentation is hereby granted, provided that the above copyright
9  * notice appears in all copies.
10  *
11  * SUN MAKES NO REPRESENTATION OR WARRANTIES ABOUT THE SUITABILITY OF
12  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
13  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
14  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT.  SUN SHALL NOT BE LIABLE FOR
15  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
16  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES
17  *
18  * Copyright (c) 1994 The Australian National University.
19  * All rights reserved.
20  *
21  * Permission to use, copy, modify, and distribute this software and its
22  * documentation is hereby granted, provided that the above copyright
23  * notice appears in all copies.  This software is provided without any
24  * warranty, express or implied. The Australian National University
25  * makes no representations about the suitability of this software for
26  * any purpose.
27  *
28  * IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY
29  * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
30  * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
31  * THE AUSTRALIAN NATIONAL UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY
32  * OF SUCH DAMAGE.
33  *
34  * THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
35  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
36  * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
37  * ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO
38  * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
39  * OR MODIFICATIONS.
40  *
41  * This driver is derived from the original SVR4 STREAMS PPP driver
42  * originally written by Paul Mackerras <paul.mackerras@cs.anu.edu.au>.
43  *
44  * Adi Masputra <adi.masputra@sun.com> rewrote and restructured the code
45  * for improved performance and scalability.
46  *
47  * $Id: sppp.h,v 1.0 2000/05/08 01:10:12 masputra Exp $
48  */
49 
50 #ifndef __SPPP_H
51 #define	__SPPP_H
52 
53 #pragma ident	"%Z%%M%	%I%	%E% SMI"
54 
55 #include <sys/dlpi.h>
56 #include <net/ppp_defs.h>
57 
58 #ifdef	__cplusplus
59 extern "C" {
60 #endif
61 
62 #if !defined(ETHERTYPE_IP)
63 #define	ETHERTYPE_IP	0x800
64 #endif
65 
66 #if !defined(ETHERTYPE_IPV6)
67 #define	ETHERTYPE_IPV6	0x86dd
68 #endif
69 
70 #if !defined(ETHERTYPE_PPP)
71 #define	ETHERTYPE_PPP	0x880b
72 #endif
73 
74 #if !defined(ETHERTYPE_ALLSAP)
75 #define	ETHERTYPE_ALLSAP	0
76 #endif
77 
78 #if !defined(PPP_ALLSAP)
79 #define	PPP_ALLSAP	PPP_ALLSTATIONS
80 #endif
81 
82 /*
83  * DLPI handler (function table item).
84  */
85 struct  sppp_dlpi_pinfo_t {
86 	int	pi_minlen;		/* minimum primitive length */
87 	uint_t	pi_state;		/* acceptable starting state */
88 	int	(*pi_funcp)();		/* function() to call */
89 };
90 
91 #ifndef DL_MAXPRIM
92 #define	DL_MAXPRIM DL_GET_STATISTICS_ACK
93 #endif
94 
95 /*
96  * Per-attachment kstats.
97  */
98 typedef struct sppp_kstats {
99 	kstat_named_t	allocbfail;
100 	kstat_named_t	rbytes;
101 	kstat_named_t	ierrors;
102 	kstat_named_t	ierrors_lower;
103 	kstat_named_t	ioctlsfwd;
104 	kstat_named_t	ioctlsfwdok;
105 	kstat_named_t	ioctlsfwderr;
106 	kstat_named_t	ipackets;
107 	kstat_named_t	ipackets_ctl;
108 	kstat_named_t	iqdropped;
109 	kstat_named_t	irunts;
110 	kstat_named_t	itoolongs;
111 	kstat_named_t	lsneedup;
112 	kstat_named_t	lsdown;
113 	kstat_named_t	mctlsfwd;
114 	kstat_named_t	mctlsfwderr;
115 	kstat_named_t	mctlsknown;
116 	kstat_named_t	mctlsunknown;
117 	kstat_named_t	obytes;
118 	kstat_named_t	oerrors;
119 	kstat_named_t	oerrors_lower;
120 	kstat_named_t	opackets;
121 	kstat_named_t	opackets_ctl;
122 	kstat_named_t	oqdropped;
123 	kstat_named_t	otoolongs;
124 	kstat_named_t	orunts;
125 
126 	/* 64 bit entries */
127 	kstat_named_t	ipackets64;
128 	kstat_named_t	opackets64;
129 	kstat_named_t	rbytes64;
130 	kstat_named_t	obytes64;
131 } sppp_kstats_t;
132 
133 /*
134  * Same order as above.  Note that for netstat -i to work, there needs
135  * to be "ipackets", "opackets", "ierrors", and "oerrors" kstat named
136  * variables.
137  */
138 #define	SPPP_KSTATS_NAMES	\
139 	"allocbfail", "rbytes", "ierrors", "ierrors_lower", "ioctlsfwd", \
140 	"ioctlsfwdok", "ioctlsfwderr", "ipackets", "ipkts_ctl", \
141 	"ipkts_qdropped", "ipkts_runts", "ipkts_toolong", "lsneedup", \
142 	"lsdown", "mctlsfwd", "mctlsfwderr", "mctlsknown", "mctlsunknown", \
143 	"obytes", "oerrors", "oerrors_lower", "opackets", "opkts_ctl", \
144 	"opkts_qdropped", "opkts_toolong", "opkts_runts"
145 
146 #define	SPPP_KSTATS64_NAMES	\
147 	"ipackets64", "opackets64", "rbytes64", "obytes64"
148 
149 /*
150  * dl_addr_length needs to be equal to the absolute value of dl_sap_length,
151  * in order for IP to derive a default setting for IFF_POINTOPOINT flag.
152  */
153 typedef t_uscalar_t	spppreqsap_t;
154 #define	SPPP_SAPL	sizeof (spppreqsap_t)
155 #define	SPPP_ADDRL	SPPP_SAPL
156 
157 /*
158  * Per-Stream instance state information.
159  *
160  * Each instance is dynamically allocated at open() and free'd at close().
161  * Each per-Stream instance points to at most one per-attachment structure
162  * using the sps_ppa field. All instances are threaded together into one
163  * list of active instances ordered on minor device number, using the
164  * sps_nextmn field.
165  */
166 typedef struct spppstr {
167 	/*
168 	 * Note that EX_st_nextmn field should never be referenced other
169 	 * than by the routines manipulating the global upper streams list,
170 	 * by first obtaining exclusive access at the outer perimeter.
171 	 */
172 	struct spppstr	*sps_nextmn;	/* next minor in global list */
173 	/*
174 	 * These fields are common to all upper streams. If this stream
175 	 * is attached to a ppa, then the sps_ppa field will point to the
176 	 * ppa structure associated with this particular upper stream.
177 	 */
178 	minor_t		sps_mn_id;	/* minor device number of this stream */
179 	queue_t		*sps_rq;	/* pointer to the read queue */
180 	uint32_t	sps_flags;	/* miscellaneous flags */
181 	uint32_t	sps_ioc_id;	/* last ioctl ID for this stream */
182 	struct sppa	*sps_ppa;	/* pointer to ppa structure */
183 	/*
184 	 * sps_nextsib is protected by the ppa's sibling lock (ppa_sib_lock),
185 	 * and access made to it should only be done by first ensuring that
186 	 * the sps_ppa field is valid, i.e., this stream has been attached.
187 	 */
188 	struct spppstr	*sps_nextsib;	/* next stream of same ppa (sibling) */
189 	/*
190 	 * These fields are common to all non-control streams, i.e., those
191 	 * in which a PPPIO_NEWPPA has not been issued on. Non-control
192 	 * streams are valid candidates for network streams, and they can
193 	 * only be considered network streams (ones which carry IP packets)
194 	 * if they are attached and bound. The only mandatory requirement
195 	 * for control stream is that its sps_npmode field should always
196 	 * be equal to NPMODE_PASS, as we obviously will never block the
197 	 * control stream from sending or receiving packets.
198 	 */
199 	t_scalar_t	sps_sap;	/* bound sap */
200 	spppreqsap_t	sps_req_sap;	/* requested sap */
201 	enum NPmode	sps_npmode;	/* network protocol mode */
202 	/*
203 	 * sps_dlstate is only valid for network streams in which DLPI
204 	 * is intended to be used to transfer network-layer data. It is set
205 	 * to DL_UNATTACHED for all other streams.
206 	 */
207 	t_uscalar_t	sps_dlstate;	/* current DLPI state */
208 	mblk_t		*sps_hangup;	/* preallocated M_HANGUP message */
209 } spppstr_t;
210 
211 /*
212  * Values for sps_flags, and their descriptions.
213  */
214 /*			0x00000001	unused */
215 #define	SPS_CONTROL	0x00000002	/* stream is a control stream */
216 #define	SPS_FASTPATH	0x00000004	/* stream uses IP fastpath */
217 #define	SPS_PROMISC	0x00000008	/* stream is promiscuous */
218 #define	SPS_RAWDATA	0x00000010	/* raw M_DATA, no DLPI header */
219 #define	SPS_PIOATTACH	0x00000020	/* attached using PPPIO_ATTACH */
220 #define	SPS_KDEBUG	0x00000040	/* stream has kdebug turned on */
221 #define	SPS_CACHED	0x00000080	/* network stream pointer is cached */
222 
223 #define	IS_SPS_CONTROL(x)	\
224 	((x)->sps_flags & SPS_CONTROL)
225 #define	IS_SPS_FASTPATH(x)	\
226 	((x)->sps_flags & SPS_FASTPATH)
227 #define	IS_SPS_PROMISC(x)	\
228 	((x)->sps_flags & SPS_PROMISC)
229 #define	IS_SPS_RAWDATA(x)	\
230 	((x)->sps_flags & SPS_RAWDATA)
231 #define	IS_SPS_PIOATTACH(x)	\
232 	((x)->sps_flags & SPS_PIOATTACH)
233 #define	IS_SPS_KDEBUG(x)	\
234 	((x)->sps_flags & SPS_KDEBUG)
235 #define	IS_SPS_CACHED(x)	\
236 	((x)->sps_flags & SPS_CACHED)
237 
238 /*
239  * Bit format (octal based) string for cmn_err, which represents the flags.
240  */
241 #define	SPS_FLAGS_STR	\
242 	"\020"		\
243 	"\1priv"	\
244 	"\2control"	\
245 	"\3fastpath"	\
246 	"\4promisc"	\
247 	"\5rawdata"	\
248 	"\6pioattach"	\
249 	"\7kdebug"	\
250 	"\10cached"
251 
252 /*
253  * Per-Attachment instance state information.
254  *
255  * Each instance is dynamically allocated on first attach (PPPIO_NEWPPA).
256  * Allocation of this structure is only done once per control stream. A ppa
257  * instance may be shared by two or more upper streams, and it is always
258  * linked to the upper stream marked as the control stream (SPS_CONTROL)
259  * via the ppa_ctl field.  Non-control streams are linked to ppa_streams.
260  */
261 typedef struct sppa {
262 	/*
263 	 * Note that EX_st_nextppa field should only be accessed (walked)
264 	 * by the ppa manipulation routines, i.e, those which affect
265 	 * the global ppa list, e.g: open, close, new_ppa, and XX_attach_upper.
266 	 */
267 	struct sppa	*ppa_nextppa;	/* next attachment instance */
268 	/*
269 	 * ppa_sib_lock guards the linkages between all upper streams related
270 	 * to this ppa. Walking the sps_nextsib of any upper streams should
271 	 * be done by first holding this lock.
272 	 */
273 	krwlock_t	ppa_sib_lock;	/* lock for sibling upper streams */
274 	uint32_t	ppa_flags;	/* miscellaneous flags */
275 	int32_t		ppa_refcnt;	/* upper stream reference count */
276 	uint32_t	ppa_ppa_id;	/* unique attachment id */
277 	spppstr_t	*ppa_streams;	/* list of all non-control streams */
278 	spppstr_t	*ppa_ctl;	/* back pointer to control stream */
279 	queue_t		*ppa_lower_wq;	/* pointer to lower write queue */
280 	uint16_t	ppa_mru;	/* link layer maximum receive unit */
281 	uint16_t	ppa_mtu;	/* link layer maximum transmit unit */
282 	hrtime_t	ppa_lasttx;	/* last transmit time for a packet */
283 	hrtime_t	ppa_lastrx;	/* last receive time for a packet */
284 	int32_t		ppa_promicnt;	/* promiscous stream count */
285 	/*
286 	 * ppa_sta_lock mutex guards the statistic fields of this ppa, since
287 	 * this structure is shared by upper streams of the same ppa.
288 	 */
289 	kmutex_t	ppa_sta_lock;	/* mutex to lock structure */
290 	struct ppp_stats64 ppa_stats;	/* legacy stats structure */
291 	uint32_t	ppa_allocbfail;	/* memory allocation failure count */
292 	uint32_t	ppa_ierr_low;	/* errors from below during receive */
293 	uint32_t	ppa_ioctlsfwd;	/* total ioctl forwarded down */
294 	uint32_t	ppa_ioctlsfwdok;  /* and the reply sent upward */
295 	uint32_t	ppa_ioctlsfwderr; /* or discarded replies */
296 	uint32_t	ppa_ipkt_ctl;	/* received control pkts */
297 	uint32_t	ppa_iqdropped;	/* msg dropped due to putq error */
298 	uint32_t	ppa_irunts;	/* packet rcvd is too short */
299 	uint32_t	ppa_itoolongs;	/* packet rcvd is larger than MRU */
300 	uint32_t	ppa_lsneedup;	/* total LINKSTAT_NEEDUP msg sent up */
301 	uint32_t	ppa_lsdown;	/* total LINKSTAT_DOWN msg sent up */
302 	uint32_t	ppa_mctlsfwd;	/* total M_{PC}PROTO forwarded down */
303 	uint32_t	ppa_mctlsfwderr; /*   and discarded count */
304 	uint32_t	ppa_mctlsknown;	/* total known M_CTL messages */
305 	uint32_t	ppa_mctlsunknown; /* total unknown M_CTL messages */
306 	uint32_t	ppa_oerr_low;	/* errors from below during transmit */
307 	uint32_t	ppa_opkt_ctl;	/* transmitted control pkts */
308 	uint32_t	ppa_oqdropped;	/* msg dropped due to putq error */
309 	uint32_t	ppa_orunts;	/* packet sent is too short */
310 	uint32_t	ppa_otoolongs;	/* packet sent is larger than MTU */
311 	kstat_t		*ppa_kstats;	/* pointer to kstats structure */
312 	/*
313 	 * We keep the following pointers for performance reasons. Instead
314 	 * of walking the list of attached upper streams to find the
315 	 * destination upper stream everytime we need to send a packet up,
316 	 * we keep them here for easy access.
317 	 */
318 	spppstr_t	*ppa_ip_cache;	/* ptr to PPP_IP upper stream */
319 	spppstr_t	*ppa_ip6_cache;	/* ptr to PPP_IPV6 upper stream */
320 
321 	kmutex_t	ppa_npmutex;	/* protects the 2 fields below */
322 	uint32_t 	ppa_npflag;	/* network protocols blocked */
323 	uint32_t 	ppa_holdpkts[3]; /* # of packets blocked per np */
324 } sppa_t;
325 
326 /* bit position (in ppa_npflag) for each ppp_protocol that can be blocked */
327 #define	NP_IP	1
328 #define	NP_IPV6	2
329 
330 /*
331  * Values for ppa_flags, and their descriptions.
332  */
333 #define	PPA_LASTMOD	0x00000001	/* last PPP entity on the stream */
334 #define	PPA_TIMESTAMP	0x00000002	/* time-stamp each packet */
335 
336 #define	IS_PPA_LASTMOD(x)	\
337 	((x)->ppa_flags & PPA_LASTMOD)
338 #define	IS_PPA_TIMESTAMP(x)	\
339 	((x)->ppa_flags & PPA_TIMESTAMP)
340 
341 /*
342  * Bit format (octal based) string for cmn_err, which represents the flags.
343  */
344 #define	PPA_FLAGS_STR	\
345 	"\020"		\
346 	"\1lastmod"	\
347 	"\2timestamp"
348 
349 /*
350  * General macros.
351  */
352 #define	SPDEBUG	printf
353 
354 /*
355  * Function declarations.
356  */
357 extern int	sppp_close(queue_t *);
358 extern mblk_t	*sppp_dladdud(spppstr_t *, mblk_t *, t_scalar_t, boolean_t);
359 extern void	sppp_dlpi_pinfoinit(void);
360 extern void	sppp_dlprsendup(spppstr_t *, mblk_t *, t_scalar_t, boolean_t);
361 extern int	sppp_lrput(queue_t *, mblk_t *);
362 extern int	sppp_lwsrv(queue_t *);
363 extern int	sppp_mproto(queue_t *, mblk_t *, spppstr_t *);
364 extern int	sppp_open(queue_t *, dev_t *, int, int, cred_t *);
365 extern int	sppp_uwput(queue_t *, mblk_t *);
366 extern int	sppp_uwsrv(queue_t *);
367 extern void	sppp_remove_ppa(spppstr_t *sps);
368 extern sppa_t	*sppp_find_ppa(uint32_t ppa_id);
369 extern sppa_t	*sppp_create_ppa(uint32_t ppa_id);
370 
371 #ifdef	__cplusplus
372 }
373 #endif
374 
375 #endif /* __SPPP_H */
376