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