xref: /openbsd-src/sys/net/if_pppvar.h (revision f6aab3d83b51b91c24247ad2c2573574de475a82)
1 /*	$OpenBSD: if_pppvar.h,v 1.20 2020/05/20 06:44:30 mpi Exp $	*/
2 /*	$NetBSD: if_pppvar.h,v 1.5 1997/01/03 07:23:29 mikel Exp $	*/
3 /*
4  * if_pppvar.h - private structures and declarations for PPP.
5  *
6  * Copyright (c) 1989-2002 Paul Mackerras. All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in
17  *    the documentation and/or other materials provided with the
18  *    distribution.
19  *
20  * 3. The name(s) of the authors of this software must not be used to
21  *    endorse or promote products derived from this software without
22  *    prior written permission.
23  *
24  * 4. Redistributions of any form whatsoever must retain the following
25  *    acknowledgment:
26  *    "This product includes software developed by Paul Mackerras
27  *     <paulus@samba.org>".
28  *
29  * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
30  * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
31  * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
32  * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
33  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
34  * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
35  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
36  *
37  * Copyright (c) 1984-2000 Carnegie Mellon University. All rights reserved.
38  *
39  * Redistribution and use in source and binary forms, with or without
40  * modification, are permitted provided that the following conditions
41  * are met:
42  *
43  * 1. Redistributions of source code must retain the above copyright
44  *    notice, this list of conditions and the following disclaimer.
45  *
46  * 2. Redistributions in binary form must reproduce the above copyright
47  *    notice, this list of conditions and the following disclaimer in
48  *    the documentation and/or other materials provided with the
49  *    distribution.
50  *
51  * 3. The name "Carnegie Mellon University" must not be used to
52  *    endorse or promote products derived from this software without
53  *    prior written permission. For permission or any legal
54  *    details, please contact
55  *      Office of Technology Transfer
56  *      Carnegie Mellon University
57  *      5000 Forbes Avenue
58  *      Pittsburgh, PA  15213-3890
59  *      (412) 268-4387, fax: (412) 268-7395
60  *      tech-transfer@andrew.cmu.edu
61  *
62  * 4. Redistributions of any form whatsoever must retain the following
63  *    acknowledgment:
64  *    "This product includes software developed by Computing Services
65  *     at Carnegie Mellon University (http://www.cmu.edu/computing/)."
66  *
67  * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
68  * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
69  * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
70  * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
71  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
72  * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
73  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
74  */
75 
76 #ifndef _NET_IF_PPPVAR_H_
77 #define _NET_IF_PPPVAR_H_
78 
79 /*
80  * Supported network protocols.  These values are used for
81  * indexing sc_npmode.
82  */
83 #define NP_IP	0		/* Internet Protocol */
84 #define NUM_NP	1		/* Number of NPs. */
85 
86 struct ppp_pkt;
87 
88 struct ppp_pkt_list {
89 	struct mutex	 pl_mtx;
90 	struct ppp_pkt	*pl_head;
91 	struct ppp_pkt	*pl_tail;
92 	u_int		 pl_count;
93 	u_int		 pl_limit;
94 };
95 
96 /*
97  * Structure describing each ppp unit.
98  */
99 struct ppp_softc {
100 	struct	ifnet sc_if;		/* network-visible interface */
101 	struct	timeout sc_timo;	/* timeout control (for ptys) */
102 	int	sc_unit;		/* XXX unit number */
103 	u_int	sc_flags;		/* control/status bits; see if_ppp.h */
104 	void	*sc_devp;		/* pointer to device-dep structure */
105 	void	(*sc_start)(struct ppp_softc *); /* start output proc */
106 	void	(*sc_ctlp)(struct ppp_softc *); /* rcvd control pkt */
107 	void	(*sc_relinq)(struct ppp_softc *); /* relinquish ifunit */
108 	u_int16_t sc_mru;		/* max receive unit */
109 	pid_t	sc_xfer;		/* used in transferring unit */
110 	struct	ppp_pkt_list sc_rawq;	/* received packets */
111 	struct	mbuf_queue sc_inq;	/* queue of input packets for daemon */
112 	struct	ifqueue sc_fastq;	/* interactive output packet q */
113 	struct	mbuf *sc_togo;		/* output packet ready to go */
114 	struct	mbuf_list sc_npqueue;	/* output packets not to be sent yet */
115 	struct	pppstat sc_stats;	/* count of bytes/pkts sent/rcvd */
116 	enum	NPmode sc_npmode[NUM_NP]; /* what to do with each NP */
117 	struct	compressor *sc_xcomp;	/* transmit compressor */
118 	void	*sc_xc_state;		/* transmit compressor state */
119 	struct	compressor *sc_rcomp;	/* receive decompressor */
120 	void	*sc_rc_state;		/* receive decompressor state */
121 	time_t	sc_last_sent;		/* time (secs) last NP pkt sent */
122 	time_t	sc_last_recv;		/* time (secs) last NP pkt rcvd */
123 	struct	bpf_program sc_pass_filt; /* filter for packets to pass */
124 	struct	bpf_program sc_active_filt; /* filter for "non-idle" packets */
125 #ifdef	VJC
126 	struct	slcompress *sc_comp;	/* vjc control buffer */
127 #endif
128 
129 	/* Device-dependent part for async lines. */
130 	ext_accm sc_asyncmap;		/* async control character map */
131 	u_int32_t sc_rasyncmap;		/* receive async control char map */
132 	struct	mbuf *sc_outm;		/* mbuf chain currently being output */
133 	struct	ppp_pkt *sc_pkt;	/* pointer to input pkt chain */
134 	struct	ppp_pkt *sc_pktc;	/* pointer to current input pkt */
135 	uint8_t	*sc_pktp;		/* ptr to next char in input pkt */
136 	u_int16_t sc_ilen;		/* length of input packet so far */
137 	u_int16_t sc_fcs;		/* FCS so far (input) */
138 	u_int16_t sc_outfcs;		/* FCS so far for output packet */
139 	u_char	sc_rawin[16];		/* chars as received */
140 	int	sc_rawin_count;		/* # in sc_rawin */
141 	LIST_ENTRY(ppp_softc) sc_list;	/* all ppp interfaces */
142 };
143 
144 #ifdef _KERNEL
145 
146 struct ppp_pkt_hdr {
147 	struct ppp_pkt		*ph_next; /* next in pkt chain */
148 	struct ppp_pkt		*ph_pkt;  /* prev in chain or next in list */
149 	uint16_t		ph_len;
150 	uint16_t		ph_errmark;
151 };
152 
153 struct ppp_pkt {
154 	struct ppp_pkt_hdr	p_hdr;
155 	uint8_t			p_buf[MCLBYTES - sizeof(struct ppp_pkt_hdr)];
156 };
157 
158 void	ppp_pkt_free(struct ppp_pkt *);
159 
160 #define PKT_NEXT(_p)		((_p)->p_hdr.ph_next)
161 #define PKT_PREV(_p)		((_p)->p_hdr.ph_pkt)
162 #define PKT_NEXTPKT(_p)		((_p)->p_hdr.ph_pkt)
163 #define PKT_LEN(_p)		((_p)->p_hdr.ph_len)
164 
165 extern	struct ppp_softc ppp_softc[];
166 
167 struct	ppp_softc *pppalloc(pid_t pid);
168 void	pppdealloc(struct ppp_softc *sc);
169 int	pppioctl(struct ppp_softc *sc, u_long cmd, caddr_t data,
170 		      int flag, struct proc *p);
171 void	ppppktin(struct ppp_softc *sc, struct ppp_pkt *pkt, int lost);
172 struct	mbuf *ppp_dequeue(struct ppp_softc *sc);
173 void	ppp_restart(struct ppp_softc *sc);
174 int	pppoutput(struct ifnet *, struct mbuf *,
175 		       struct sockaddr *, struct rtentry *);
176 #endif /* _KERNEL */
177 #endif /* _NET_IF_PPPVAR_H_ */
178