xref: /illumos-gate/usr/src/uts/common/io/ppp/sppp/sppp.h (revision 5328fc53d11d7151861fa272e4fb0248b8f0e145)
1 /*
2  * sppp.h - Solaris STREAMS PPP multiplexing pseudo-driver definitions
3  *
4  * Copyright 2009 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 	int	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 
208 	zoneid_t	sps_zoneid;	/* zone in which we were opened */
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 #define	SPS_IOCQ	0x00000100	/* queue ioctls */
223 
224 #define	IS_SPS_CONTROL(x)	\
225 	((x)->sps_flags & SPS_CONTROL)
226 #define	IS_SPS_FASTPATH(x)	\
227 	((x)->sps_flags & SPS_FASTPATH)
228 #define	IS_SPS_PROMISC(x)	\
229 	((x)->sps_flags & SPS_PROMISC)
230 #define	IS_SPS_RAWDATA(x)	\
231 	((x)->sps_flags & SPS_RAWDATA)
232 #define	IS_SPS_PIOATTACH(x)	\
233 	((x)->sps_flags & SPS_PIOATTACH)
234 #define	IS_SPS_KDEBUG(x)	\
235 	((x)->sps_flags & SPS_KDEBUG)
236 #define	IS_SPS_CACHED(x)	\
237 	((x)->sps_flags & SPS_CACHED)
238 #define	IS_SPS_IOCQ(x)		\
239 	((x)->sps_flags & SPS_IOCQ)
240 
241 /*
242  * Bit format (octal based) string for cmn_err, which represents the flags.
243  */
244 #define	SPS_FLAGS_STR	\
245 	"\020"		\
246 	"\1priv"	\
247 	"\2control"	\
248 	"\3fastpath"	\
249 	"\4promisc"	\
250 	"\5rawdata"	\
251 	"\6pioattach"	\
252 	"\7kdebug"	\
253 	"\10cached"
254 
255 /*
256  * Per-Attachment instance state information.
257  *
258  * Each instance is dynamically allocated on first attach (PPPIO_NEWPPA).
259  * Allocation of this structure is only done once per control stream. A ppa
260  * instance may be shared by two or more upper streams, and it is always
261  * linked to the upper stream marked as the control stream (SPS_CONTROL)
262  * via the ppa_ctl field.  Non-control streams are linked to ppa_streams.
263  */
264 typedef struct sppa {
265 	/*
266 	 * Note that EX_st_nextppa field should only be accessed (walked)
267 	 * by the ppa manipulation routines, i.e, those which affect
268 	 * the global ppa list, e.g: open, close, new_ppa, and XX_attach_upper.
269 	 */
270 	struct sppa	*ppa_nextppa;	/* next attachment instance */
271 	/*
272 	 * ppa_sib_lock guards the linkages between all upper streams related
273 	 * to this ppa. Walking the sps_nextsib of any upper streams should
274 	 * be done by first holding this lock.
275 	 */
276 	krwlock_t	ppa_sib_lock;	/* lock for sibling upper streams */
277 	uint32_t	ppa_flags;	/* miscellaneous flags */
278 	int32_t		ppa_refcnt;	/* upper stream reference count */
279 	uint32_t	ppa_ppa_id;	/* unique attachment id */
280 	spppstr_t	*ppa_streams;	/* list of all non-control streams */
281 	spppstr_t	*ppa_ctl;	/* back pointer to control stream */
282 	queue_t		*ppa_lower_wq;	/* pointer to lower write queue */
283 	uint16_t	ppa_mru;	/* link layer maximum receive unit */
284 	uint16_t	ppa_mtu;	/* link layer maximum transmit unit */
285 	hrtime_t	ppa_lasttx;	/* last transmit time for a packet */
286 	hrtime_t	ppa_lastrx;	/* last receive time for a packet */
287 	int32_t		ppa_promicnt;	/* promiscous stream count */
288 	/*
289 	 * ppa_sta_lock mutex guards the statistic fields of this ppa, since
290 	 * this structure is shared by upper streams of the same ppa.
291 	 */
292 	kmutex_t	ppa_sta_lock;	/* mutex to lock structure */
293 	struct ppp_stats64 ppa_stats;	/* legacy stats structure */
294 	uint32_t	ppa_allocbfail;	/* memory allocation failure count */
295 	uint32_t	ppa_ierr_low;	/* errors from below during receive */
296 	uint32_t	ppa_ioctlsfwd;	/* total ioctl forwarded down */
297 	uint32_t	ppa_ioctlsfwdok;  /* and the reply sent upward */
298 	uint32_t	ppa_ioctlsfwderr; /* or discarded replies */
299 	uint32_t	ppa_ipkt_ctl;	/* received control pkts */
300 	uint32_t	ppa_iqdropped;	/* msg dropped due to putq error */
301 	uint32_t	ppa_irunts;	/* packet rcvd is too short */
302 	uint32_t	ppa_itoolongs;	/* packet rcvd is larger than MRU */
303 	uint32_t	ppa_lsneedup;	/* total LINKSTAT_NEEDUP msg sent up */
304 	uint32_t	ppa_lsdown;	/* total LINKSTAT_DOWN msg sent up */
305 	uint32_t	ppa_mctlsfwd;	/* total M_{PC}PROTO forwarded down */
306 	uint32_t	ppa_mctlsfwderr; /*   and discarded count */
307 	uint32_t	ppa_mctlsknown;	/* total known M_CTL messages */
308 	uint32_t	ppa_mctlsunknown; /* total unknown M_CTL messages */
309 	uint32_t	ppa_oerr_low;	/* errors from below during transmit */
310 	uint32_t	ppa_opkt_ctl;	/* transmitted control pkts */
311 	uint32_t	ppa_oqdropped;	/* msg dropped due to putq error */
312 	uint32_t	ppa_orunts;	/* packet sent is too short */
313 	uint32_t	ppa_otoolongs;	/* packet sent is larger than MTU */
314 	kstat_t		*ppa_kstats;	/* pointer to kstats structure */
315 	/*
316 	 * We keep the following pointers for performance reasons. Instead
317 	 * of walking the list of attached upper streams to find the
318 	 * destination upper stream everytime we need to send a packet up,
319 	 * we keep them here for easy access.
320 	 */
321 	spppstr_t	*ppa_ip_cache;	/* ptr to PPP_IP upper stream */
322 	spppstr_t	*ppa_ip6_cache;	/* ptr to PPP_IPV6 upper stream */
323 
324 	kmutex_t	ppa_npmutex;	/* protects the 2 fields below */
325 	uint32_t	ppa_npflag;	/* network protocols blocked */
326 	uint32_t	ppa_holdpkts[3]; /* # of packets blocked per np */
327 
328 	zoneid_t	ppa_zoneid;	/* zone where PPA is in use */
329 } sppa_t;
330 
331 /* bit position (in ppa_npflag) for each ppp_protocol that can be blocked */
332 #define	NP_IP	1
333 #define	NP_IPV6	2
334 
335 /*
336  * Values for ppa_flags, and their descriptions.
337  */
338 #define	PPA_LASTMOD	0x00000001	/* last PPP entity on the stream */
339 #define	PPA_TIMESTAMP	0x00000002	/* time-stamp each packet */
340 
341 #define	IS_PPA_LASTMOD(x)	\
342 	((x)->ppa_flags & PPA_LASTMOD)
343 #define	IS_PPA_TIMESTAMP(x)	\
344 	((x)->ppa_flags & PPA_TIMESTAMP)
345 
346 /*
347  * Bit format (octal based) string for cmn_err, which represents the flags.
348  */
349 #define	PPA_FLAGS_STR	\
350 	"\020"		\
351 	"\1lastmod"	\
352 	"\2timestamp"
353 
354 /*
355  * General macros.
356  */
357 #define	SPDEBUG	printf
358 
359 /*
360  * Function declarations.
361  */
362 extern int	sppp_close(queue_t *, int, cred_t *);
363 extern mblk_t	*sppp_dladdud(spppstr_t *, mblk_t *, t_scalar_t, boolean_t);
364 extern void	sppp_dlpi_pinfoinit(void);
365 extern void	sppp_dlprsendup(spppstr_t *, mblk_t *, t_scalar_t, boolean_t);
366 extern int	sppp_lrput(queue_t *, mblk_t *);
367 extern int	sppp_lrsrv(queue_t *);
368 extern int	sppp_lwsrv(queue_t *);
369 extern int	sppp_mproto(queue_t *, mblk_t *, spppstr_t *);
370 extern int	sppp_open(queue_t *, dev_t *, int, int, cred_t *);
371 extern int	sppp_uwput(queue_t *, mblk_t *);
372 extern int	sppp_uwsrv(queue_t *);
373 extern void	sppp_remove_ppa(spppstr_t *sps);
374 extern sppa_t	*sppp_find_ppa(uint32_t ppa_id);
375 extern sppa_t	*sppp_create_ppa(uint32_t ppa_id, zoneid_t zoneid);
376 
377 #ifdef	__cplusplus
378 }
379 #endif
380 
381 #endif /* __SPPP_H */
382