2 * sppp.h - Solaris STREAMS PPP multiplexing pseudo-driver definitions
4 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
5 * Use is subject to license terms.
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.
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
18 * Copyright (c) 1994 The Australian National University.
19 * All rights reserved.
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
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
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,
41 * This driver is derived from the original SVR4 STREAMS PPP driver
42 * originally written by Paul Mackerras <paul.mackerras@cs.anu.edu.au>.
44 * Adi Masputra <adi.masputra@sun.com> rewrote and restructured the code
45 * for improved performance and scalability.
47 * $Id: sppp.h,v 1.0 2000/05/08 01:10:12 masputra Exp $
54 #include <net/ppp_defs.h>
60 #if !defined(ETHERTYPE_IP)
61 #define ETHERTYPE_IP 0x800
64 #if !defined(ETHERTYPE_IPV6)
65 #define ETHERTYPE_IPV6 0x86dd
68 #if !defined(ETHERTYPE_PPP)
69 #define ETHERTYPE_PPP 0x880b
72 #if !defined(ETHERTYPE_ALLSAP)
73 #define ETHERTYPE_ALLSAP 0
76 #if !defined(PPP_ALLSAP)
77 #define PPP_ALLSAP PPP_ALLSTATIONS
81 * DLPI handler (function table item).
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 */
90 #define DL_MAXPRIM DL_GET_STATISTICS_ACK
94 * Per-attachment kstats.
96 typedef struct sppp_kstats
{
97 kstat_named_t allocbfail
;
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
;
125 kstat_named_t ipackets64
;
126 kstat_named_t opackets64
;
127 kstat_named_t rbytes64
;
128 kstat_named_t obytes64
;
132 * Same order as above. Note that for netstat -i to work, there needs
133 * to be "ipackets", "opackets", "ierrors", and "oerrors" kstat named
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"
144 #define SPPP_KSTATS64_NAMES \
145 "ipackets64", "opackets64", "rbytes64", "obytes64"
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.
151 typedef t_uscalar_t spppreqsap_t
;
152 #define SPPP_SAPL sizeof (spppreqsap_t)
153 #define SPPP_ADDRL SPPP_SAPL
156 * Per-Stream instance state information.
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
164 typedef struct spppstr
{
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.
170 struct spppstr
*sps_nextmn
; /* next minor in global list */
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.
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 */
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.
186 struct spppstr
*sps_nextsib
; /* next stream of same ppa (sibling) */
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.
197 t_scalar_t sps_sap
; /* bound sap */
198 spppreqsap_t sps_req_sap
; /* requested sap */
199 enum NPmode sps_npmode
; /* network protocol mode */
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.
205 t_uscalar_t sps_dlstate
; /* current DLPI state */
206 mblk_t
*sps_hangup
; /* preallocated M_HANGUP message */
208 zoneid_t sps_zoneid
; /* zone in which we were opened */
212 * Values for sps_flags, and their descriptions.
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 */
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)
242 * Bit format (octal based) string for cmn_err, which represents the flags.
244 #define SPS_FLAGS_STR \
256 * Per-Attachment instance state information.
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.
264 typedef struct sppa
{
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.
270 struct sppa
*ppa_nextppa
; /* next attachment instance */
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.
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 */
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.
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 */
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.
321 spppstr_t
*ppa_ip_cache
; /* ptr to PPP_IP upper stream */
322 spppstr_t
*ppa_ip6_cache
; /* ptr to PPP_IPV6 upper stream */
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 */
328 zoneid_t ppa_zoneid
; /* zone where PPA is in use */
331 /* bit position (in ppa_npflag) for each ppp_protocol that can be blocked */
336 * Values for ppa_flags, and their descriptions.
338 #define PPA_LASTMOD 0x00000001 /* last PPP entity on the stream */
339 #define PPA_TIMESTAMP 0x00000002 /* time-stamp each packet */
341 #define IS_PPA_LASTMOD(x) \
342 ((x)->ppa_flags & PPA_LASTMOD)
343 #define IS_PPA_TIMESTAMP(x) \
344 ((x)->ppa_flags & PPA_TIMESTAMP)
347 * Bit format (octal based) string for cmn_err, which represents the flags.
349 #define PPA_FLAGS_STR \
357 #define SPDEBUG printf
360 * Function declarations.
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 void sppp_lrput(queue_t
*, mblk_t
*);
367 extern void sppp_lrsrv(queue_t
*);
368 extern void 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 void sppp_uwput(queue_t
*, mblk_t
*);
372 extern void 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
);
381 #endif /* __SPPP_H */