annotate packages/net/ppp/current/src/if_ppp.c @ 1777:c16341b1bac6 default tip

* Added execute permissions to files missed in conversion from CVS
author alexs
date Mon, 12 Oct 2009 02:26:09 +0100
parents e0d88dc6a92f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1586
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1 //==========================================================================
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
2 //
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
3 // src/if_ppp.c
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
4 //
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
5 //==========================================================================
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
6 // This file is part of eCos, the Embedded Configurable Operating System.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
7 // Portions created by Nick Garnett are
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
8 // Copyright (C) 2003 eCosCentric Ltd.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
9 //####BSDCOPYRIGHTBEGIN####
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
10 //
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
11 // -------------------------------------------
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
12 //
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
13 // Portions of this software may have been derived from OpenBSD,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
14 // FreeBSD or other sources, and are covered by the appropriate
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
15 // copyright disclaimers included herein.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
16 //
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
17 // -------------------------------------------
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
18 //
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
19 //####BSDCOPYRIGHTEND####
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
20 //==========================================================================
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
21
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
22 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
23 * if_ppp.c - Point-to-Point Protocol (PPP) Asynchronous driver.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
24 *
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
25 * Copyright (c) 1989 Carnegie Mellon University.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
26 * All rights reserved.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
27 *
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
28 * Redistribution and use in source and binary forms are permitted
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
29 * provided that the above copyright notice and this paragraph are
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
30 * duplicated in all such forms and that any documentation,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
31 * advertising materials, and other materials related to such
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
32 * distribution and use acknowledge that the software was developed
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
33 * by Carnegie Mellon University. The name of the
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
34 * University may not be used to endorse or promote products derived
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
35 * from this software without specific prior written permission.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
36 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
37 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
38 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
39 *
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
40 * Drew D. Perkins
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
41 * Carnegie Mellon University
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
42 * 4910 Forbes Ave.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
43 * Pittsburgh, PA 15213
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
44 * (412) 268-8576
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
45 * ddp@andrew.cmu.edu
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
46 *
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
47 * Based on:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
48 * @(#)if_sl.c 7.6.1.2 (Berkeley) 2/15/89
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
49 *
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
50 * Copyright (c) 1987 Regents of the University of California.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
51 * All rights reserved.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
52 *
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
53 * Redistribution and use in source and binary forms are permitted
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
54 * provided that the above copyright notice and this paragraph are
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
55 * duplicated in all such forms and that any documentation,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
56 * and other materials related to such
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
57 * distribution and use acknowledge that the software was developed
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
58 * by the University of California, Berkeley. The name of the
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
59 * University may not be used to endorse or promote products derived
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
60 * from this software without specific prior written permission.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
61 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
62 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
63 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
64 *
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
65 * Serial Line interface
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
66 *
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
67 * Rick Adams
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
68 * Center for Seismic Studies
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
69 * 1300 N 17th Street, Suite 1450
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
70 * Arlington, Virginia 22209
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
71 * (703)276-7900
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
72 * rick@seismo.ARPA
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
73 * seismo!rick
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
74 *
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
75 * Pounded on heavily by Chris Torek (chris@mimsy.umd.edu, umcp-cs!chris).
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
76 * Converted to 4.3BSD Beta by Chris Torek.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
77 * Other changes made at Berkeley, based in part on code by Kirk Smith.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
78 *
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
79 * Converted to 4.3BSD+ 386BSD by Brad Parker (brad@cayman.com)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
80 * Added VJ tcp header compression; more unified ioctls
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
81 *
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
82 * Extensively modified by Paul Mackerras (paulus@cs.anu.edu.au).
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
83 * Cleaned up a lot of the mbuf-related code to fix bugs that
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
84 * caused system crashes and packet corruption. Changed pppstart
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
85 * so that it doesn't just give up with a collision if the whole
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
86 * packet doesn't fit in the output ring buffer.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
87 *
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
88 * Added priority queueing for interactive IP packets, following
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
89 * the model of if_sl.c, plus hooks for bpf.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
90 * Paul Mackerras (paulus@cs.anu.edu.au).
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
91 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
92
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
93 /* $FreeBSD: src/sys/net/if_ppp.c,v 1.67.2.1 2001/09/11 09:49:54 kris Exp $ */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
94 /* from if_sl.c,v 1.11 84/10/04 12:54:47 rick Exp */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
95 /* from NetBSD: if_ppp.c,v 1.15.2.2 1994/07/28 05:17:58 cgd Exp */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
96
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
97 #include <pkgconf/system.h>
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
98 #include <pkgconf/net.h>
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
99 #include <pkgconf/ppp.h>
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
100
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
101 //#include "ppp.h"
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
102 #define NPPP 1
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
103 #define _KERNEL
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
104
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
105 #if 0
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
106 #include "opt_inet.h"
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
107 #include "opt_ipx.h"
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
108 #include "opt_ppp.h"
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
109 #endif
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
110
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
111 #ifdef INET
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
112 #define VJC
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
113 #endif
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
114 #define PPP_COMPRESS
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
115
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
116 #include <sys/param.h>
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
117 //#include <sys/systm.h>
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
118 //#include <sys/proc.h>
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
119 #define suser(x) 0
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
120 #include <sys/mbuf.h>
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
121 #include <sys/socket.h>
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
122 //#include <sys/filio.h>
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
123 #include <sys/sockio.h>
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
124 //#include <sys/kernel.h>
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
125 #include <sys/time.h>
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
126 #include <sys/malloc.h>
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
127
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
128 #include <net/if.h>
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
129 #include <net/if_types.h>
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
130 #include <net/netisr.h>
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
131 //#include <net/bpf.h>
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
132
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
133 #if INET
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
134 #include <netinet/in.h>
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
135 #include <netinet/in_systm.h>
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
136 #include <netinet/in_var.h>
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
137 #include <netinet/ip.h>
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
138 #endif
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
139
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
140 #if 0 // IPX
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
141 #include <netipx/ipx.h>
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
142 #include <netipx/ipx_if.h>
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
143 #endif
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
144
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
145 #ifdef VJC
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
146 #include <cyg/ppp/slcompress.h>
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
147 #endif
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
148
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
149 #include <cyg/ppp/net/if_ppp.h>
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
150 #include <cyg/ppp/net/if_pppvar.h>
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
151
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
152 /* minimise diffs */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
153 #ifndef splsoftnet
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
154 #define splsoftnet splnet
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
155 #endif
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
156
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
157 #ifdef PPP_COMPRESS
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
158 #define PACKETPTR struct mbuf *
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
159 #include <cyg/ppp/net/ppp_comp.h>
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
160 #endif
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
161
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
162 struct ppp_softc ppp_softc[NPPP];
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
163
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
164 /* XXX layering violation */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
165 extern void pppasyncattach __P((void *));
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
166
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
167 //static void pppattach __P((void *));
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
168 void pppattach __P((void *));
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
169 PSEUDO_SET(pppattach, if_ppp);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
170
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
171 static int pppsioctl __P((struct ifnet *ifp, u_long cmd, caddr_t data));
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
172 static void pppintr __P((void));
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
173
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
174 static void ppp_requeue __P((struct ppp_softc *));
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
175 static void ppp_ccp __P((struct ppp_softc *, struct mbuf *m, int rcvd));
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
176 static void ppp_ccp_closed __P((struct ppp_softc *));
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
177 static void ppp_inproc __P((struct ppp_softc *, struct mbuf *));
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
178 //static void pppdumpm __P((struct mbuf *m0));
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
179
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
180 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
181 * Some useful mbuf macros not in mbuf.h.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
182 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
183 #define M_IS_CLUSTER(m) ((m)->m_flags & M_EXT)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
184
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
185 #define M_DATASTART(m) \
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
186 (M_IS_CLUSTER(m) ? (m)->m_ext.ext_buf : \
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
187 (m)->m_flags & M_PKTHDR ? (m)->m_pktdat : (m)->m_dat)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
188
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
189 #define M_DATASIZE(m) \
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
190 (M_IS_CLUSTER(m) ? (m)->m_ext.ext_size : \
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
191 (m)->m_flags & M_PKTHDR ? MHLEN: MLEN)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
192
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
193 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
194 * We steal two bits in the mbuf m_flags, to mark high-priority packets
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
195 * for output, and received packets following lost/corrupted packets.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
196 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
197 #define M_HIGHPRI 0x2000 /* output packet for sc_fastq */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
198 #define M_ERRMARK 0x4000 /* steal a bit in mbuf m_flags */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
199
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
200
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
201 #ifdef PPP_COMPRESS
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
202 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
203 * List of compressors we know about.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
204 * We leave some space so maybe we can modload compressors.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
205 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
206
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
207 extern struct compressor ppp_bsd_compress;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
208 extern struct compressor ppp_deflate, ppp_deflate_draft;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
209
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
210 static struct compressor *ppp_compressors[8] = {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
211 #if DO_BSD_COMPRESS && defined(PPP_BSDCOMP)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
212 &ppp_bsd_compress,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
213 #endif
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
214 #if DO_DEFLATE && defined(PPP_DEFLATE)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
215 &ppp_deflate,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
216 &ppp_deflate_draft,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
217 #endif
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
218 NULL
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
219 };
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
220 #endif /* PPP_COMPRESS */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
221
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
222 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
223 * Called from boot code to establish ppp interfaces.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
224 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
225 //static void
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
226 void
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
227 pppattach(dummy)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
228 void *dummy;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
229 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
230 register struct ppp_softc *sc;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
231 register int i = 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
232
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
233 for (sc = ppp_softc; i < NPPP; sc++) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
234 sc->sc_if.if_name = "ppp";
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
235 sc->sc_if.if_unit = i++;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
236 sc->sc_if.if_mtu = PPP_MTU;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
237 sc->sc_if.if_flags = IFF_POINTOPOINT | IFF_MULTICAST;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
238 sc->sc_if.if_type = IFT_PPP;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
239 sc->sc_if.if_hdrlen = PPP_HDRLEN;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
240 sc->sc_if.if_ioctl = pppsioctl;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
241 sc->sc_if.if_output = pppoutput;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
242 sc->sc_if.if_snd.ifq_maxlen = IFQ_MAXLEN;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
243 sc->sc_inq.ifq_maxlen = IFQ_MAXLEN;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
244 sc->sc_fastq.ifq_maxlen = IFQ_MAXLEN;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
245 sc->sc_rawq.ifq_maxlen = IFQ_MAXLEN;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
246 // sc->sc_fd = -1;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
247 if_attach(&sc->sc_if);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
248 #ifdef BPF
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
249 bpfattach(&sc->sc_if, DLT_PPP, PPP_HDRLEN);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
250 #endif
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
251 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
252 register_netisr(NETISR_PPP, pppintr);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
253 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
254 * XXX layering violation - if_ppp can work over any lower level
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
255 * transport that cares to attach to it.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
256 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
257 // pppasyncattach(dummy);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
258 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
259
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
260 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
261 * Allocate a ppp interface unit and initialize it.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
262 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
263 struct ppp_softc *
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
264 pppalloc(pid)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
265 pid_t pid;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
266 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
267 int nppp, i;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
268 struct ppp_softc *sc;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
269
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
270 #ifndef __ECOS
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
271 for (nppp = 0, sc = ppp_softc; nppp < NPPP; nppp++, sc++)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
272 if (sc->sc_xfer == pid) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
273 sc->sc_xfer = 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
274 return sc;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
275 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
276 #endif
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
277 for (nppp = 0, sc = ppp_softc; nppp < NPPP; nppp++, sc++)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
278 if (sc->sc_devp == NULL)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
279 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
280
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
281 if (nppp >= NPPP)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
282 return NULL;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
283
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
284 sc->sc_flags = 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
285 sc->sc_mru = PPP_MRU;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
286 sc->sc_relinq = NULL;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
287 bzero((char *)&sc->sc_stats, sizeof(sc->sc_stats));
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
288 #ifdef VJC
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
289 MALLOC(sc->sc_comp, struct slcompress *, sizeof(struct slcompress),
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
290 M_DEVBUF, M_NOWAIT);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
291 if (sc->sc_comp)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
292 sl_compress_init(sc->sc_comp, -1);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
293 #endif
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
294 #ifdef PPP_COMPRESS
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
295 sc->sc_xc_state = NULL;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
296 sc->sc_rc_state = NULL;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
297 #endif /* PPP_COMPRESS */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
298 for (i = 0; i < NUM_NP; ++i)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
299 sc->sc_npmode[i] = NPMODE_ERROR;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
300 sc->sc_npqueue = NULL;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
301 sc->sc_npqtail = &sc->sc_npqueue;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
302 sc->sc_last_sent = sc->sc_last_recv = time_second;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
303
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
304 return sc;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
305 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
306
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
307 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
308 * Deallocate a ppp unit. Must be called at splsoftnet or higher.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
309 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
310 void
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
311 pppdealloc(sc)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
312 struct ppp_softc *sc;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
313 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
314 struct mbuf *m;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
315
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
316 if_down(&sc->sc_if);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
317 sc->sc_if.if_flags &= ~(IFF_UP|IFF_RUNNING);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
318 getmicrotime(&sc->sc_if.if_lastchange);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
319 #if 1 //def __NEVER__
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
320 sc->sc_devp = NULL;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
321 #else
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
322 sc->sc_fd = -1;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
323 #endif
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
324 sc->sc_xfer = 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
325 for (;;) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
326 IF_DEQUEUE(&sc->sc_rawq, m);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
327 if (m == NULL)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
328 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
329 m_freem(m);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
330 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
331 for (;;) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
332 IF_DEQUEUE(&sc->sc_inq, m);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
333 if (m == NULL)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
334 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
335 m_freem(m);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
336 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
337 for (;;) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
338 IF_DEQUEUE(&sc->sc_fastq, m);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
339 if (m == NULL)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
340 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
341 m_freem(m);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
342 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
343 while ((m = sc->sc_npqueue) != NULL) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
344 sc->sc_npqueue = m->m_nextpkt;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
345 m_freem(m);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
346 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
347 #ifdef PPP_COMPRESS
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
348 ppp_ccp_closed(sc);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
349 sc->sc_xc_state = NULL;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
350 sc->sc_rc_state = NULL;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
351 #endif /* PPP_COMPRESS */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
352 #ifdef PPP_FILTER
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
353 if (sc->sc_pass_filt.bf_insns != 0) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
354 FREE(sc->sc_pass_filt.bf_insns, M_DEVBUF);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
355 sc->sc_pass_filt.bf_insns = 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
356 sc->sc_pass_filt.bf_len = 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
357 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
358 if (sc->sc_active_filt.bf_insns != 0) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
359 FREE(sc->sc_active_filt.bf_insns, M_DEVBUF);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
360 sc->sc_active_filt.bf_insns = 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
361 sc->sc_active_filt.bf_len = 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
362 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
363 #endif /* PPP_FILTER */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
364 #ifdef VJC
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
365 if (sc->sc_comp != 0) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
366 FREE(sc->sc_comp, M_DEVBUF);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
367 sc->sc_comp = 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
368 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
369 #endif
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
370 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
371
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
372 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
373 * Ioctl routine for generic ppp devices.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
374 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
375 int
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
376 pppioctl(sc, cmd, data, flag, p)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
377 struct ppp_softc *sc;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
378 u_long cmd;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
379 caddr_t data;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
380 int flag;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
381 struct proc *p;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
382 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
383 int s, error, flags, mru, npx;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
384 u_int nb;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
385 struct ppp_option_data *odp;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
386 struct compressor **cp;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
387 struct npioctl *npi;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
388 time_t t;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
389 #ifdef PPP_FILTER
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
390 struct bpf_program *bp, *nbp;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
391 struct bpf_insn *newcode, *oldcode;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
392 int newcodelen;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
393 #endif /* PPP_FILTER */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
394 #ifdef PPP_COMPRESS
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
395 u_char ccp_option[CCP_MAX_OPTION_LENGTH];
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
396 #endif
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
397
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
398 switch (cmd) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
399 case FIONREAD:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
400 *(int *)data = sc->sc_inq.ifq_len;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
401 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
402
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
403 case PPPIOCGUNIT:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
404 *(int *)data = sc->sc_if.if_unit;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
405 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
406
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
407 case PPPIOCGFLAGS:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
408 *(u_int *)data = sc->sc_flags;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
409 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
410
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
411 case PPPIOCSFLAGS:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
412 if ((error = suser(p)) != 0)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
413 return (error);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
414 flags = *(int *)data & SC_MASK;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
415 s = splsoftnet();
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
416 #ifdef PPP_COMPRESS
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
417 if (sc->sc_flags & SC_CCP_OPEN && !(flags & SC_CCP_OPEN))
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
418 ppp_ccp_closed(sc);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
419 #endif
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
420 splimp();
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
421 sc->sc_flags = (sc->sc_flags & ~SC_MASK) | flags;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
422 splx(s);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
423 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
424
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
425 case PPPIOCSMRU:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
426 if ((error = suser(p)) != 0)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
427 return (error);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
428 mru = *(int *)data;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
429 if (mru >= PPP_MRU && mru <= PPP_MAXMRU)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
430 sc->sc_mru = mru;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
431 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
432
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
433 case PPPIOCGMRU:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
434 *(int *)data = sc->sc_mru;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
435 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
436
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
437 #ifdef VJC
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
438 case PPPIOCSMAXCID:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
439 if ((error = suser(p)) != 0)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
440 return (error);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
441 if (sc->sc_comp) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
442 s = splsoftnet();
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
443 sl_compress_init(sc->sc_comp, *(int *)data);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
444 splx(s);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
445 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
446 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
447 #endif
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
448
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
449 case PPPIOCXFERUNIT:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
450 if ((error = suser(p)) != 0)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
451 return (error);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
452 // sc->sc_xfer = p->p_pid;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
453 sc->sc_xfer = 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
454 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
455
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
456 #ifdef PPP_COMPRESS
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
457 case PPPIOCSCOMPRESS:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
458 if ((error = suser(p)) != 0)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
459 return (error);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
460 odp = (struct ppp_option_data *) data;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
461 nb = odp->length;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
462 if (nb > sizeof(ccp_option))
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
463 nb = sizeof(ccp_option);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
464 if ((error = copyin(odp->ptr, ccp_option, nb)) != 0)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
465 return (error);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
466 if (ccp_option[1] < 2) /* preliminary check on the length byte */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
467 return (EINVAL);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
468 for (cp = ppp_compressors; *cp != NULL; ++cp)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
469 if ((*cp)->compress_proto == ccp_option[0]) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
470 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
471 * Found a handler for the protocol - try to allocate
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
472 * a compressor or decompressor.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
473 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
474 error = 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
475 if (odp->transmit) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
476 s = splsoftnet();
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
477 if (sc->sc_xc_state != NULL)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
478 (*sc->sc_xcomp->comp_free)(sc->sc_xc_state);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
479 sc->sc_xcomp = *cp;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
480 sc->sc_xc_state = (*cp)->comp_alloc(ccp_option, nb);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
481 if (sc->sc_xc_state == NULL) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
482 if (sc->sc_flags & SC_DEBUG)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
483 diag_printf("ppp%d: comp_alloc failed\n",
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
484 sc->sc_if.if_unit);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
485 error = ENOBUFS;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
486 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
487 splimp();
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
488 sc->sc_flags &= ~SC_COMP_RUN;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
489 splx(s);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
490 } else {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
491 s = splsoftnet();
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
492 if (sc->sc_rc_state != NULL)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
493 (*sc->sc_rcomp->decomp_free)(sc->sc_rc_state);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
494 sc->sc_rcomp = *cp;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
495 sc->sc_rc_state = (*cp)->decomp_alloc(ccp_option, nb);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
496 if (sc->sc_rc_state == NULL) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
497 if (sc->sc_flags & SC_DEBUG)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
498 diag_printf("ppp%d: decomp_alloc failed\n",
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
499 sc->sc_if.if_unit);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
500 error = ENOBUFS;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
501 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
502 splimp();
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
503 sc->sc_flags &= ~SC_DECOMP_RUN;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
504 splx(s);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
505 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
506 return (error);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
507 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
508 if (sc->sc_flags & SC_DEBUG)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
509 diag_printf("ppp%d: no compressor for [%x %x %x], %x\n",
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
510 sc->sc_if.if_unit, ccp_option[0], ccp_option[1],
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
511 ccp_option[2], nb);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
512 return (EINVAL); /* no handler found */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
513 #endif /* PPP_COMPRESS */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
514
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
515 case PPPIOCGNPMODE:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
516 case PPPIOCSNPMODE:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
517 npi = (struct npioctl *) data;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
518 switch (npi->protocol) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
519 case PPP_IP:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
520 npx = NP_IP;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
521 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
522 default:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
523 return EINVAL;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
524 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
525 if (cmd == PPPIOCGNPMODE) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
526 npi->mode = sc->sc_npmode[npx];
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
527 } else {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
528 if ((error = suser(p)) != 0)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
529 return (error);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
530 if (npi->mode != sc->sc_npmode[npx]) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
531 s = splsoftnet();
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
532 sc->sc_npmode[npx] = npi->mode;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
533 if (npi->mode != NPMODE_QUEUE) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
534 ppp_requeue(sc);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
535 (*sc->sc_start)(sc);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
536 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
537 splx(s);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
538 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
539 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
540 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
541
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
542 case PPPIOCGIDLE:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
543 s = splsoftnet();
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
544 t = time_second;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
545 ((struct ppp_idle *)data)->xmit_idle = t - sc->sc_last_sent;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
546 ((struct ppp_idle *)data)->recv_idle = t - sc->sc_last_recv;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
547 splx(s);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
548 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
549
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
550 #ifdef PPP_FILTER
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
551 case PPPIOCSPASS:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
552 case PPPIOCSACTIVE:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
553 nbp = (struct bpf_program *) data;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
554 if ((unsigned) nbp->bf_len > BPF_MAXINSNS)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
555 return EINVAL;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
556 newcodelen = nbp->bf_len * sizeof(struct bpf_insn);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
557 if (newcodelen != 0) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
558 MALLOC(newcode, struct bpf_insn *, newcodelen, M_DEVBUF, M_WAITOK);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
559 if (newcode == 0) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
560 return EINVAL; /* or sumpin */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
561 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
562 if ((error = copyin((caddr_t)nbp->bf_insns, (caddr_t)newcode,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
563 newcodelen)) != 0) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
564 FREE(newcode, M_DEVBUF);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
565 return error;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
566 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
567 if (!bpf_validate(newcode, nbp->bf_len)) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
568 FREE(newcode, M_DEVBUF);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
569 return EINVAL;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
570 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
571 } else
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
572 newcode = 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
573 bp = (cmd == PPPIOCSPASS)? &sc->sc_pass_filt: &sc->sc_active_filt;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
574 oldcode = bp->bf_insns;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
575 s = splimp();
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
576 bp->bf_len = nbp->bf_len;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
577 bp->bf_insns = newcode;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
578 splx(s);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
579 if (oldcode != 0)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
580 FREE(oldcode, M_DEVBUF);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
581 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
582 #endif
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
583
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
584 default:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
585 // return (ENOIOCTL);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
586 return ENOSYS;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
587 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
588 return (0);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
589 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
590
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
591 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
592 * Process an ioctl request to the ppp network interface.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
593 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
594 static int
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
595 pppsioctl(ifp, cmd, data)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
596 register struct ifnet *ifp;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
597 u_long cmd;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
598 caddr_t data;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
599 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
600 // struct proc *p = curproc; /* XXX */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
601 register struct ppp_softc *sc = &ppp_softc[ifp->if_unit];
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
602 register struct ifaddr *ifa = (struct ifaddr *)data;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
603 register struct ifreq *ifr = (struct ifreq *)data;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
604 struct ppp_stats *psp;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
605 #ifdef PPP_COMPRESS
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
606 struct ppp_comp_stats *pcp;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
607 #endif
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
608 int s = splimp(), error = 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
609
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
610 switch (cmd) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
611 case SIOCSIFFLAGS:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
612 if ((ifp->if_flags & IFF_RUNNING) == 0)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
613 ifp->if_flags &= ~IFF_UP;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
614 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
615
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
616 case SIOCSIFADDR:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
617 case SIOCAIFADDR:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
618 switch(ifa->ifa_addr->sa_family) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
619 #ifdef INET
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
620 case AF_INET:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
621 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
622 #endif
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
623 #ifdef IPX
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
624 case AF_IPX:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
625 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
626 #endif
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
627 default:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
628 error = EAFNOSUPPORT;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
629 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
630 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
631 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
632
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
633 case SIOCSIFDSTADDR:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
634 switch(ifa->ifa_addr->sa_family) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
635 #ifdef INET
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
636 case AF_INET:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
637 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
638 #endif
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
639 #ifdef IPX
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
640 case AF_IPX:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
641 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
642 #endif
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
643 default:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
644 error = EAFNOSUPPORT;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
645 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
646 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
647 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
648
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
649 case SIOCSIFMTU:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
650 if ((error = suser(p)) != 0)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
651 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
652 if (ifr->ifr_mtu > PPP_MAXMTU)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
653 error = EINVAL;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
654 else {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
655 sc->sc_if.if_mtu = ifr->ifr_mtu;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
656 if (sc->sc_setmtu)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
657 (*sc->sc_setmtu)(sc);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
658 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
659 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
660
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
661 case SIOCGIFMTU:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
662 ifr->ifr_mtu = sc->sc_if.if_mtu;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
663 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
664
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
665 case SIOCADDMULTI:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
666 case SIOCDELMULTI:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
667 if (ifr == 0) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
668 error = EAFNOSUPPORT;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
669 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
670 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
671 switch(ifr->ifr_addr.sa_family) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
672 #ifdef INET
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
673 case AF_INET:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
674 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
675 #endif
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
676 default:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
677 error = EAFNOSUPPORT;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
678 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
679 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
680 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
681
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
682 case SIOCGPPPSTATS:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
683 psp = &((struct ifpppstatsreq *) data)->stats;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
684 bzero(psp, sizeof(*psp));
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
685 psp->p = sc->sc_stats;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
686 #if defined(VJC) && !defined(SL_NO_STATS)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
687 if (sc->sc_comp) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
688 psp->vj.vjs_packets = sc->sc_comp->sls_packets;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
689 psp->vj.vjs_compressed = sc->sc_comp->sls_compressed;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
690 psp->vj.vjs_searches = sc->sc_comp->sls_searches;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
691 psp->vj.vjs_misses = sc->sc_comp->sls_misses;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
692 psp->vj.vjs_uncompressedin = sc->sc_comp->sls_uncompressedin;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
693 psp->vj.vjs_compressedin = sc->sc_comp->sls_compressedin;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
694 psp->vj.vjs_errorin = sc->sc_comp->sls_errorin;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
695 psp->vj.vjs_tossed = sc->sc_comp->sls_tossed;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
696 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
697 #endif /* VJC */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
698 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
699
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
700 #ifdef PPP_COMPRESS
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
701 case SIOCGPPPCSTATS:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
702 pcp = &((struct ifpppcstatsreq *) data)->stats;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
703 bzero(pcp, sizeof(*pcp));
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
704 if (sc->sc_xc_state != NULL)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
705 (*sc->sc_xcomp->comp_stat)(sc->sc_xc_state, &pcp->c);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
706 if (sc->sc_rc_state != NULL)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
707 (*sc->sc_rcomp->decomp_stat)(sc->sc_rc_state, &pcp->d);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
708 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
709 #endif /* PPP_COMPRESS */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
710
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
711 default:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
712 error = ENOTTY;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
713 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
714 splx(s);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
715 return (error);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
716 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
717
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
718 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
719 * Queue a packet. Start transmission if not active.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
720 * Packet is placed in Information field of PPP frame.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
721 * Called at splnet as the if->if_output handler.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
722 * Called at splnet from pppwrite().
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
723 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
724 int
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
725 pppoutput(ifp, m0, dst, rtp)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
726 struct ifnet *ifp;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
727 struct mbuf *m0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
728 struct sockaddr *dst;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
729 struct rtentry *rtp;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
730 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
731 register struct ppp_softc *sc = &ppp_softc[ifp->if_unit];
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
732 int protocol, address, control;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
733 u_char *cp;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
734 int s, error;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
735 struct ip *ip;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
736 struct ifqueue *ifq;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
737 enum NPmode mode;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
738 int len;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
739 struct mbuf *m;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
740
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
741 if (sc->sc_devp == NULL || (ifp->if_flags & IFF_RUNNING) == 0
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
742 || ((ifp->if_flags & IFF_UP) == 0 && dst->sa_family != AF_UNSPEC)) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
743 error = ENETDOWN; /* sort of */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
744 goto bad;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
745 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
746
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
747 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
748 * Compute PPP header.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
749 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
750 m0->m_flags &= ~M_HIGHPRI;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
751 switch (dst->sa_family) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
752 #ifdef INET
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
753 case AF_INET:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
754 address = PPP_ALLSTATIONS;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
755 control = PPP_UI;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
756 protocol = PPP_IP;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
757 mode = sc->sc_npmode[NP_IP];
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
758
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
759 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
760 * If this packet has the "low delay" bit set in the IP header,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
761 * put it on the fastq instead.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
762 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
763 ip = mtod(m0, struct ip *);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
764 if (ip->ip_tos & IPTOS_LOWDELAY)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
765 m0->m_flags |= M_HIGHPRI;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
766 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
767 #endif
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
768 #ifdef IPX
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
769 case AF_IPX:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
770 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
771 * This is pretty bogus.. We dont have an ipxcp module in pppd
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
772 * yet to configure the link parameters. Sigh. I guess a
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
773 * manual ifconfig would do.... -Peter
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
774 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
775 address = PPP_ALLSTATIONS;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
776 control = PPP_UI;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
777 protocol = PPP_IPX;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
778 mode = NPMODE_PASS;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
779 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
780 #endif
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
781 case AF_UNSPEC:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
782 address = PPP_ADDRESS(dst->sa_data);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
783 control = PPP_CONTROL(dst->sa_data);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
784 protocol = PPP_PROTOCOL(dst->sa_data);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
785 mode = NPMODE_PASS;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
786 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
787 default:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
788 diag_printf("ppp%d: af%d not supported\n", ifp->if_unit, dst->sa_family);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
789 error = EAFNOSUPPORT;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
790 goto bad;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
791 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
792
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
793 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
794 * Drop this packet, or return an error, if necessary.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
795 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
796 if (mode == NPMODE_ERROR) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
797 error = ENETDOWN;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
798 goto bad;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
799 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
800 if (mode == NPMODE_DROP) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
801 error = 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
802 goto bad;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
803 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
804
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
805 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
806 * Add PPP header. If no space in first mbuf, allocate another.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
807 * (This assumes M_LEADINGSPACE is always 0 for a cluster mbuf.)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
808 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
809 if (M_LEADINGSPACE(m0) < PPP_HDRLEN) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
810 m0 = m_prepend(m0, PPP_HDRLEN, M_DONTWAIT);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
811 if (m0 == 0) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
812 error = ENOBUFS;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
813 goto bad;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
814 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
815 m0->m_len = 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
816 } else
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
817 m0->m_data -= PPP_HDRLEN;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
818
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
819 cp = mtod(m0, u_char *);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
820 *cp++ = address;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
821 *cp++ = control;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
822 *cp++ = protocol >> 8;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
823 *cp++ = protocol & 0xff;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
824 m0->m_len += PPP_HDRLEN;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
825
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
826 len = 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
827 for (m = m0; m != 0; m = m->m_next)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
828 len += m->m_len;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
829
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
830 if (sc->sc_flags & SC_LOG_OUTPKT) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
831 diag_printf("ppp%d output: ", ifp->if_unit);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
832 // pppdumpm(m0);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
833 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
834
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
835 if ((protocol & 0x8000) == 0) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
836 #ifdef PPP_FILTER
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
837 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
838 * Apply the pass and active filters to the packet,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
839 * but only if it is a data packet.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
840 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
841 *mtod(m0, u_char *) = 1; /* indicates outbound */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
842 if (sc->sc_pass_filt.bf_insns != 0
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
843 && bpf_filter(sc->sc_pass_filt.bf_insns, (u_char *) m0,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
844 len, 0) == 0) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
845 error = 0; /* drop this packet */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
846 goto bad;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
847 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
848
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
849 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
850 * Update the time we sent the most recent packet.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
851 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
852 if (sc->sc_active_filt.bf_insns == 0
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
853 || bpf_filter(sc->sc_active_filt.bf_insns, (u_char *) m0, len, 0))
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
854 sc->sc_last_sent = time_second;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
855
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
856 *mtod(m0, u_char *) = address;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
857 #else
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
858 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
859 * Update the time we sent the most recent data packet.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
860 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
861 sc->sc_last_sent = time_second;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
862 #endif /* PPP_FILTER */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
863 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
864
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
865 #ifdef BPF
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
866 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
867 * See if bpf wants to look at the packet.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
868 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
869 if (ifp->if_bpf)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
870 bpf_mtap(ifp, m0);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
871 #endif
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
872
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
873 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
874 * Put the packet on the appropriate queue.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
875 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
876 s = splsoftnet(); /* redundant */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
877 if (mode == NPMODE_QUEUE) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
878 /* XXX we should limit the number of packets on this queue */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
879 *sc->sc_npqtail = m0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
880 m0->m_nextpkt = NULL;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
881 sc->sc_npqtail = &m0->m_nextpkt;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
882 } else {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
883 /* fastq and if_snd are emptied at spl[soft]net now */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
884 ifq = (m0->m_flags & M_HIGHPRI)? &sc->sc_fastq: &ifp->if_snd;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
885 if (IF_QFULL(ifq) && dst->sa_family != AF_UNSPEC) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
886 IF_DROP(ifq);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
887 splx(s);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
888 sc->sc_if.if_oerrors++;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
889 sc->sc_stats.ppp_oerrors++;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
890 error = ENOBUFS;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
891 goto bad;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
892 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
893 IF_ENQUEUE(ifq, m0);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
894 (*sc->sc_start)(sc);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
895 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
896 getmicrotime(&ifp->if_lastchange);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
897 ifp->if_opackets++;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
898 ifp->if_obytes += len;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
899
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
900 splx(s);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
901 return (0);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
902
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
903 bad:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
904 m_freem(m0);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
905 return (error);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
906 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
907
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
908 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
909 * After a change in the NPmode for some NP, move packets from the
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
910 * npqueue to the send queue or the fast queue as appropriate.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
911 * Should be called at spl[soft]net.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
912 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
913 static void
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
914 ppp_requeue(sc)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
915 struct ppp_softc *sc;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
916 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
917 struct mbuf *m, **mpp;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
918 struct ifqueue *ifq;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
919 enum NPmode mode;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
920
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
921 for (mpp = &sc->sc_npqueue; (m = *mpp) != NULL; ) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
922 switch (PPP_PROTOCOL(mtod(m, u_char *))) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
923 case PPP_IP:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
924 mode = sc->sc_npmode[NP_IP];
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
925 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
926 default:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
927 mode = NPMODE_PASS;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
928 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
929
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
930 switch (mode) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
931 case NPMODE_PASS:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
932 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
933 * This packet can now go on one of the queues to be sent.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
934 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
935 *mpp = m->m_nextpkt;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
936 m->m_nextpkt = NULL;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
937 ifq = (m->m_flags & M_HIGHPRI)? &sc->sc_fastq: &sc->sc_if.if_snd;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
938 if (IF_QFULL(ifq)) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
939 IF_DROP(ifq);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
940 sc->sc_if.if_oerrors++;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
941 sc->sc_stats.ppp_oerrors++;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
942 } else
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
943 IF_ENQUEUE(ifq, m);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
944 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
945
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
946 case NPMODE_DROP:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
947 case NPMODE_ERROR:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
948 *mpp = m->m_nextpkt;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
949 m_freem(m);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
950 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
951
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
952 case NPMODE_QUEUE:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
953 mpp = &m->m_nextpkt;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
954 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
955 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
956 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
957 sc->sc_npqtail = mpp;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
958 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
959
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
960 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
961 * Transmitter has finished outputting some stuff;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
962 * remember to call sc->sc_start later at splsoftnet.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
963 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
964 void
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
965 ppp_restart(sc)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
966 struct ppp_softc *sc;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
967 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
968 int s = splimp();
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
969
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
970 sc->sc_flags &= ~SC_TBUSY;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
971 schednetisr(NETISR_PPP);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
972 splx(s);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
973 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
974
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
975
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
976 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
977 * Get a packet to send. This procedure is intended to be called at
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
978 * splsoftnet, since it may involve time-consuming operations such as
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
979 * applying VJ compression, packet compression, address/control and/or
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
980 * protocol field compression to the packet.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
981 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
982 struct mbuf *
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
983 ppp_dequeue(sc)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
984 struct ppp_softc *sc;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
985 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
986 struct mbuf *m, *mp;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
987 u_char *cp;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
988 int address, control, protocol;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
989
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
990 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
991 * Grab a packet to send: first try the fast queue, then the
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
992 * normal queue.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
993 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
994 IF_DEQUEUE(&sc->sc_fastq, m);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
995 if (m == NULL)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
996 IF_DEQUEUE(&sc->sc_if.if_snd, m);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
997 if (m == NULL)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
998 return NULL;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
999
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1000 ++sc->sc_stats.ppp_opackets;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1001
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1002 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1003 * Extract the ppp header of the new packet.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1004 * The ppp header will be in one mbuf.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1005 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1006 cp = mtod(m, u_char *);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1007 address = PPP_ADDRESS(cp);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1008 control = PPP_CONTROL(cp);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1009 protocol = PPP_PROTOCOL(cp);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1010
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1011 switch (protocol) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1012 case PPP_IP:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1013 #ifdef VJC
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1014 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1015 * If the packet is a TCP/IP packet, see if we can compress it.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1016 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1017 if ((sc->sc_flags & SC_COMP_TCP) && sc->sc_comp != NULL) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1018 struct ip *ip;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1019 int type;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1020
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1021 mp = m;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1022 ip = (struct ip *) (cp + PPP_HDRLEN);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1023 if (mp->m_len <= PPP_HDRLEN) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1024 mp = mp->m_next;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1025 if (mp == NULL)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1026 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1027 ip = mtod(mp, struct ip *);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1028 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1029 /* this code assumes the IP/TCP header is in one non-shared mbuf */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1030 if (ip->ip_p == IPPROTO_TCP) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1031 type = sl_compress_tcp(mp, ip, sc->sc_comp,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1032 !(sc->sc_flags & SC_NO_TCP_CCID));
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1033 switch (type) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1034 case TYPE_UNCOMPRESSED_TCP:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1035 protocol = PPP_VJC_UNCOMP;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1036 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1037 case TYPE_COMPRESSED_TCP:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1038 protocol = PPP_VJC_COMP;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1039 cp = mtod(m, u_char *);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1040 cp[0] = address; /* header has moved */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1041 cp[1] = control;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1042 cp[2] = 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1043 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1044 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1045 cp[3] = protocol; /* update protocol in PPP header */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1046 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1047 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1048 #endif /* VJC */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1049 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1050
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1051 #ifdef PPP_COMPRESS
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1052 case PPP_CCP:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1053 ppp_ccp(sc, m, 0);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1054 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1055 #endif /* PPP_COMPRESS */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1056 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1057
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1058 #ifdef PPP_COMPRESS
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1059 if (protocol != PPP_LCP && protocol != PPP_CCP
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1060 && sc->sc_xc_state && (sc->sc_flags & SC_COMP_RUN)) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1061 struct mbuf *mcomp = NULL;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1062 int slen, clen;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1063
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1064 slen = 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1065 for (mp = m; mp != NULL; mp = mp->m_next)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1066 slen += mp->m_len;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1067 clen = (*sc->sc_xcomp->compress)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1068 (sc->sc_xc_state, &mcomp, m, slen, sc->sc_if.if_mtu + PPP_HDRLEN);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1069 if (mcomp != NULL) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1070 if (sc->sc_flags & SC_CCP_UP) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1071 /* Send the compressed packet instead of the original. */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1072 m_freem(m);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1073 m = mcomp;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1074 cp = mtod(m, u_char *);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1075 protocol = cp[3];
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1076 } else {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1077 /* Can't transmit compressed packets until CCP is up. */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1078 m_freem(mcomp);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1079 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1080 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1081 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1082 #endif /* PPP_COMPRESS */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1083
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1084 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1085 * Compress the address/control and protocol, if possible.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1086 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1087 if (sc->sc_flags & SC_COMP_AC && address == PPP_ALLSTATIONS &&
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1088 control == PPP_UI && protocol != PPP_ALLSTATIONS &&
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1089 protocol != PPP_LCP) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1090 /* can compress address/control */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1091 m->m_data += 2;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1092 m->m_len -= 2;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1093 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1094 if (sc->sc_flags & SC_COMP_PROT && protocol < 0xFF) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1095 /* can compress protocol */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1096 if (mtod(m, u_char *) == cp) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1097 cp[2] = cp[1]; /* move address/control up */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1098 cp[1] = cp[0];
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1099 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1100 ++m->m_data;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1101 --m->m_len;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1102 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1103
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1104 return m;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1105 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1106
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1107 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1108 * Software interrupt routine, called at spl[soft]net.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1109 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1110 static void
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1111 pppintr()
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1112 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1113 struct ppp_softc *sc;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1114 int i, s;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1115 struct mbuf *m;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1116
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1117 sc = ppp_softc;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1118 for (i = 0; i < NPPP; ++i, ++sc) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1119 s = splimp();
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1120 if (!(sc->sc_flags & SC_TBUSY)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1121 && (sc->sc_if.if_snd.ifq_head || sc->sc_fastq.ifq_head)) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1122 sc->sc_flags |= SC_TBUSY;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1123 splx(s);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1124 (*sc->sc_start)(sc);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1125 } else
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1126 splx(s);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1127 for (;;) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1128 s = splimp();
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1129 IF_DEQUEUE(&sc->sc_rawq, m);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1130 splx(s);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1131 if (m == NULL)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1132 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1133 ppp_inproc(sc, m);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1134 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1135 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1136 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1137
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1138 #ifdef PPP_COMPRESS
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1139 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1140 * Handle a CCP packet. `rcvd' is 1 if the packet was received,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1141 * 0 if it is about to be transmitted.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1142 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1143 static void
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1144 ppp_ccp(sc, m, rcvd)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1145 struct ppp_softc *sc;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1146 struct mbuf *m;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1147 int rcvd;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1148 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1149 u_char *dp, *ep;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1150 struct mbuf *mp;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1151 int slen, s;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1152
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1153 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1154 * Get a pointer to the data after the PPP header.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1155 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1156 if (m->m_len <= PPP_HDRLEN) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1157 mp = m->m_next;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1158 if (mp == NULL)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1159 return;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1160 dp = (mp != NULL)? mtod(mp, u_char *): NULL;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1161 } else {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1162 mp = m;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1163 dp = mtod(mp, u_char *) + PPP_HDRLEN;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1164 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1165
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1166 ep = mtod(mp, u_char *) + mp->m_len;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1167 if (dp + CCP_HDRLEN > ep)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1168 return;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1169 slen = CCP_LENGTH(dp);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1170 if (dp + slen > ep) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1171 if (sc->sc_flags & SC_DEBUG)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1172 diag_printf("if_ppp/ccp: not enough data in mbuf (%p+%x > %p+%x)\n",
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1173 dp, slen, mtod(mp, u_char *), mp->m_len);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1174 return;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1175 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1176
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1177 switch (CCP_CODE(dp)) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1178 case CCP_CONFREQ:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1179 case CCP_TERMREQ:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1180 case CCP_TERMACK:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1181 /* CCP must be going down - disable compression */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1182 if (sc->sc_flags & SC_CCP_UP) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1183 s = splimp();
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1184 sc->sc_flags &= ~(SC_CCP_UP | SC_COMP_RUN | SC_DECOMP_RUN);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1185 splx(s);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1186 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1187 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1188
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1189 case CCP_CONFACK:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1190 if (sc->sc_flags & SC_CCP_OPEN && !(sc->sc_flags & SC_CCP_UP)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1191 && slen >= CCP_HDRLEN + CCP_OPT_MINLEN
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1192 && slen >= CCP_OPT_LENGTH(dp + CCP_HDRLEN) + CCP_HDRLEN) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1193 if (!rcvd) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1194 /* we're agreeing to send compressed packets. */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1195 if (sc->sc_xc_state != NULL
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1196 && (*sc->sc_xcomp->comp_init)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1197 (sc->sc_xc_state, dp + CCP_HDRLEN, slen - CCP_HDRLEN,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1198 sc->sc_if.if_unit, 0, sc->sc_flags & SC_DEBUG)) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1199 s = splimp();
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1200 sc->sc_flags |= SC_COMP_RUN;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1201 splx(s);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1202 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1203 } else {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1204 /* peer is agreeing to send compressed packets. */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1205 if (sc->sc_rc_state != NULL
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1206 && (*sc->sc_rcomp->decomp_init)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1207 (sc->sc_rc_state, dp + CCP_HDRLEN, slen - CCP_HDRLEN,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1208 sc->sc_if.if_unit, 0, sc->sc_mru,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1209 sc->sc_flags & SC_DEBUG)) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1210 s = splimp();
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1211 sc->sc_flags |= SC_DECOMP_RUN;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1212 sc->sc_flags &= ~(SC_DC_ERROR | SC_DC_FERROR);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1213 splx(s);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1214 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1215 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1216 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1217 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1218
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1219 case CCP_RESETACK:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1220 if (sc->sc_flags & SC_CCP_UP) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1221 if (!rcvd) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1222 if (sc->sc_xc_state && (sc->sc_flags & SC_COMP_RUN))
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1223 (*sc->sc_xcomp->comp_reset)(sc->sc_xc_state);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1224 } else {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1225 if (sc->sc_rc_state && (sc->sc_flags & SC_DECOMP_RUN)) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1226 (*sc->sc_rcomp->decomp_reset)(sc->sc_rc_state);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1227 s = splimp();
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1228 sc->sc_flags &= ~SC_DC_ERROR;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1229 splx(s);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1230 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1231 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1232 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1233 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1234 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1235 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1236
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1237 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1238 * CCP is down; free (de)compressor state if necessary.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1239 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1240 static void
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1241 ppp_ccp_closed(sc)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1242 struct ppp_softc *sc;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1243 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1244 if (sc->sc_xc_state) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1245 (*sc->sc_xcomp->comp_free)(sc->sc_xc_state);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1246 sc->sc_xc_state = NULL;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1247 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1248 if (sc->sc_rc_state) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1249 (*sc->sc_rcomp->decomp_free)(sc->sc_rc_state);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1250 sc->sc_rc_state = NULL;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1251 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1252 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1253 #endif /* PPP_COMPRESS */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1254
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1255 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1256 * PPP packet input routine.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1257 * The caller has checked and removed the FCS and has inserted
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1258 * the address/control bytes and the protocol high byte if they
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1259 * were omitted.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1260 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1261 void
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1262 ppppktin(sc, m, lost)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1263 struct ppp_softc *sc;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1264 struct mbuf *m;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1265 int lost;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1266 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1267 int s = splimp();
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1268
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1269 if (lost)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1270 m->m_flags |= M_ERRMARK;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1271 IF_ENQUEUE(&sc->sc_rawq, m);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1272 schednetisr(NETISR_PPP);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1273 splx(s);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1274 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1275
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1276 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1277 * Process a received PPP packet, doing decompression as necessary.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1278 * Should be called at splsoftnet.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1279 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1280 #define COMPTYPE(proto) ((proto) == PPP_VJC_COMP? TYPE_COMPRESSED_TCP: \
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1281 TYPE_UNCOMPRESSED_TCP)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1282
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1283 static void
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1284 ppp_inproc(sc, m)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1285 struct ppp_softc *sc;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1286 struct mbuf *m;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1287 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1288 struct ifnet *ifp = &sc->sc_if;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1289 struct ifqueue *inq;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1290 int s, ilen = 0, xlen, proto, rv;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1291 u_char *cp, adrs, ctrl;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1292 struct mbuf *mp, *dmp = NULL;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1293 u_char *iphdr;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1294 u_int hlen;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1295
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1296 sc->sc_stats.ppp_ipackets++;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1297
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1298 if (sc->sc_flags & SC_LOG_INPKT) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1299 ilen = 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1300 for (mp = m; mp != NULL; mp = mp->m_next)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1301 ilen += mp->m_len;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1302 diag_printf("ppp%d: got %d bytes\n", ifp->if_unit, ilen);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1303 // pppdumpm(m);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1304 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1305
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1306 cp = mtod(m, u_char *);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1307 adrs = PPP_ADDRESS(cp);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1308 ctrl = PPP_CONTROL(cp);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1309 proto = PPP_PROTOCOL(cp);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1310
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1311 if (m->m_flags & M_ERRMARK) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1312 m->m_flags &= ~M_ERRMARK;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1313 s = splimp();
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1314 sc->sc_flags |= SC_VJ_RESET;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1315 splx(s);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1316 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1317
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1318 #ifdef PPP_COMPRESS
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1319 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1320 * Decompress this packet if necessary, update the receiver's
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1321 * dictionary, or take appropriate action on a CCP packet.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1322 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1323 if (proto == PPP_COMP && sc->sc_rc_state && (sc->sc_flags & SC_DECOMP_RUN)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1324 && !(sc->sc_flags & SC_DC_ERROR) && !(sc->sc_flags & SC_DC_FERROR)) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1325 /* decompress this packet */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1326 rv = (*sc->sc_rcomp->decompress)(sc->sc_rc_state, m, &dmp);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1327 if (rv == DECOMP_OK) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1328 m_freem(m);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1329 if (dmp == NULL) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1330 /* no error, but no decompressed packet produced */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1331 return;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1332 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1333 m = dmp;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1334 cp = mtod(m, u_char *);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1335 proto = PPP_PROTOCOL(cp);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1336
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1337 } else {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1338 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1339 * An error has occurred in decompression.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1340 * Pass the compressed packet up to pppd, which may take
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1341 * CCP down or issue a Reset-Req.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1342 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1343 if (sc->sc_flags & SC_DEBUG)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1344 diag_printf("ppp%d: decompress failed %d\n", ifp->if_unit, rv);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1345 s = splimp();
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1346 sc->sc_flags |= SC_VJ_RESET;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1347 if (rv == DECOMP_ERROR)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1348 sc->sc_flags |= SC_DC_ERROR;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1349 else
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1350 sc->sc_flags |= SC_DC_FERROR;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1351 splx(s);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1352 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1353
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1354 } else {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1355 if (sc->sc_rc_state && (sc->sc_flags & SC_DECOMP_RUN)) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1356 (*sc->sc_rcomp->incomp)(sc->sc_rc_state, m);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1357 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1358 if (proto == PPP_CCP) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1359 ppp_ccp(sc, m, 1);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1360 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1361 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1362 #endif
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1363
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1364 ilen = 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1365 for (mp = m; mp != NULL; mp = mp->m_next)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1366 ilen += mp->m_len;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1367
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1368 #ifdef VJC
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1369 if (sc->sc_flags & SC_VJ_RESET) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1370 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1371 * If we've missed a packet, we must toss subsequent compressed
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1372 * packets which don't have an explicit connection ID.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1373 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1374 if (sc->sc_comp)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1375 sl_uncompress_tcp(NULL, 0, TYPE_ERROR, sc->sc_comp);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1376 s = splimp();
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1377 sc->sc_flags &= ~SC_VJ_RESET;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1378 splx(s);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1379 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1380
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1381 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1382 * See if we have a VJ-compressed packet to uncompress.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1383 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1384 if (proto == PPP_VJC_COMP) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1385 if ((sc->sc_flags & SC_REJ_COMP_TCP) || sc->sc_comp == 0)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1386 goto bad;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1387
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1388 xlen = sl_uncompress_tcp_core(cp + PPP_HDRLEN, m->m_len - PPP_HDRLEN,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1389 ilen - PPP_HDRLEN, TYPE_COMPRESSED_TCP,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1390 sc->sc_comp, &iphdr, &hlen);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1391
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1392 if (xlen <= 0) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1393 if (sc->sc_flags & SC_DEBUG)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1394 diag_printf("ppp%d: VJ uncompress failed on type comp\n",
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1395 ifp->if_unit);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1396 goto bad;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1397 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1398
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1399 /* Copy the PPP and IP headers into a new mbuf. */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1400 MGETHDR(mp, M_DONTWAIT, MT_DATA);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1401 if (mp == NULL)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1402 goto bad;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1403 mp->m_len = 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1404 mp->m_next = NULL;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1405 if (hlen + PPP_HDRLEN > MHLEN) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1406 MCLGET(mp, M_DONTWAIT);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1407 if (M_TRAILINGSPACE(mp) < hlen + PPP_HDRLEN) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1408 m_freem(mp);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1409 goto bad; /* lose if big headers and no clusters */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1410 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1411 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1412 cp = mtod(mp, u_char *);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1413 cp[0] = adrs;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1414 cp[1] = ctrl;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1415 cp[2] = 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1416 cp[3] = PPP_IP;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1417 proto = PPP_IP;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1418 bcopy(iphdr, cp + PPP_HDRLEN, hlen);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1419 mp->m_len = hlen + PPP_HDRLEN;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1420
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1421 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1422 * Trim the PPP and VJ headers off the old mbuf
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1423 * and stick the new and old mbufs together.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1424 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1425 m->m_data += PPP_HDRLEN + xlen;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1426 m->m_len -= PPP_HDRLEN + xlen;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1427 if (m->m_len <= M_TRAILINGSPACE(mp)) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1428 bcopy(mtod(m, u_char *), mtod(mp, u_char *) + mp->m_len, m->m_len);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1429 mp->m_len += m->m_len;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1430 MFREE(m, mp->m_next);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1431 } else
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1432 mp->m_next = m;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1433 m = mp;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1434 ilen += hlen - xlen;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1435
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1436 } else if (proto == PPP_VJC_UNCOMP) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1437 if ((sc->sc_flags & SC_REJ_COMP_TCP) || sc->sc_comp == 0)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1438 goto bad;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1439
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1440 xlen = sl_uncompress_tcp_core(cp + PPP_HDRLEN, m->m_len - PPP_HDRLEN,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1441 ilen - PPP_HDRLEN, TYPE_UNCOMPRESSED_TCP,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1442 sc->sc_comp, &iphdr, &hlen);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1443
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1444 if (xlen < 0) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1445 if (sc->sc_flags & SC_DEBUG)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1446 diag_printf("ppp%d: VJ uncompress failed on type uncomp\n",
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1447 ifp->if_unit);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1448 goto bad;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1449 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1450
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1451 proto = PPP_IP;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1452 cp[3] = PPP_IP;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1453 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1454 #endif /* VJC */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1455
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1456 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1457 * If the packet will fit in a header mbuf, don't waste a
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1458 * whole cluster on it.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1459 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1460 if (ilen <= MHLEN && M_IS_CLUSTER(m)) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1461 MGETHDR(mp, M_DONTWAIT, MT_DATA);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1462 if (mp != NULL) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1463 m_copydata(m, 0, ilen, mtod(mp, caddr_t));
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1464 m_freem(m);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1465 m = mp;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1466 m->m_len = ilen;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1467 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1468 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1469 m->m_pkthdr.len = ilen;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1470 m->m_pkthdr.rcvif = ifp;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1471
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1472 if ((proto & 0x8000) == 0) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1473 #ifdef PPP_FILTER
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1474 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1475 * See whether we want to pass this packet, and
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1476 * if it counts as link activity.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1477 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1478 adrs = *mtod(m, u_char *); /* save address field */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1479 *mtod(m, u_char *) = 0; /* indicate inbound */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1480 if (sc->sc_pass_filt.bf_insns != 0
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1481 && bpf_filter(sc->sc_pass_filt.bf_insns, (u_char *) m,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1482 ilen, 0) == 0) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1483 /* drop this packet */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1484 m_freem(m);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1485 return;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1486 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1487 if (sc->sc_active_filt.bf_insns == 0
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1488 || bpf_filter(sc->sc_active_filt.bf_insns, (u_char *) m, ilen, 0))
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1489 sc->sc_last_recv = time_second;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1490
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1491 *mtod(m, u_char *) = adrs;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1492 #else
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1493 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1494 * Record the time that we received this packet.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1495 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1496 sc->sc_last_recv = time_second;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1497 #endif /* PPP_FILTER */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1498 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1499
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1500 #ifdef BPF
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1501 /* See if bpf wants to look at the packet. */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1502 if (sc->sc_if.if_bpf)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1503 bpf_mtap(&sc->sc_if, m);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1504 #endif
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1505
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1506 rv = 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1507 switch (proto) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1508 #ifdef INET
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1509 case PPP_IP:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1510 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1511 * IP packet - take off the ppp header and pass it up to IP.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1512 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1513 if ((ifp->if_flags & IFF_UP) == 0
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1514 || sc->sc_npmode[NP_IP] != NPMODE_PASS) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1515 /* interface is down - drop the packet. */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1516 m_freem(m);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1517 return;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1518 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1519 m->m_pkthdr.len -= PPP_HDRLEN;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1520 m->m_data += PPP_HDRLEN;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1521 m->m_len -= PPP_HDRLEN;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1522 if (ipflow_fastforward(m)) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1523 sc->sc_last_recv = time_second;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1524 return;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1525 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1526 schednetisr(NETISR_IP);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1527 inq = &ipintrq;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1528 sc->sc_last_recv = time_second; /* update time of last pkt rcvd */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1529 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1530 #endif
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1531 #ifdef IPX
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1532 case PPP_IPX:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1533 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1534 * IPX packet - take off the ppp header and pass it up to IPX.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1535 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1536 if ((sc->sc_if.if_flags & IFF_UP) == 0
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1537 /* XXX: || sc->sc_npmode[NP_IPX] != NPMODE_PASS*/) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1538 /* interface is down - drop the packet. */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1539 m_freem(m);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1540 return;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1541 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1542 m->m_pkthdr.len -= PPP_HDRLEN;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1543 m->m_data += PPP_HDRLEN;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1544 m->m_len -= PPP_HDRLEN;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1545 schednetisr(NETISR_IPX);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1546 inq = &ipxintrq;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1547 sc->sc_last_recv = time_second; /* update time of last pkt rcvd */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1548 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1549 #endif
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1550
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1551 default:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1552 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1553 * Some other protocol - place on input queue for read().
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1554 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1555 inq = &sc->sc_inq;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1556 rv = 1;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1557 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1558 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1559
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1560 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1561 * Put the packet on the appropriate input queue.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1562 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1563 s = splimp();
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1564 if (IF_QFULL(inq)) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1565 IF_DROP(inq);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1566 splx(s);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1567 if (sc->sc_flags & SC_DEBUG)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1568 diag_printf("ppp%d: input queue full\n", ifp->if_unit);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1569 ifp->if_iqdrops++;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1570 goto bad;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1571 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1572 IF_ENQUEUE(inq, m);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1573 splx(s);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1574 ifp->if_ipackets++;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1575 ifp->if_ibytes += ilen;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1576 getmicrotime(&ifp->if_lastchange);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1577
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1578 if (rv)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1579 (*sc->sc_ctlp)(sc);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1580
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1581 return;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1582
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1583 bad:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1584 m_freem(m);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1585 sc->sc_if.if_ierrors++;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1586 sc->sc_stats.ppp_ierrors++;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1587 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1588
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1589 #if 0
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1590
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1591 #define MAX_DUMP_BYTES 128
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1592
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1593 static void
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1594 pppdumpm(m0)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1595 struct mbuf *m0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1596 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1597 char buf[3*MAX_DUMP_BYTES+4];
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1598 char *bp = buf;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1599 struct mbuf *m;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1600
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1601 for (m = m0; m; m = m->m_next) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1602 int l = m->m_len;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1603 u_char *rptr = (u_char *)m->m_data;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1604
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1605 while (l--) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1606 if (bp > buf + sizeof(buf) - 4)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1607 goto done;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1608 *bp++ = hex2ascii(*rptr >> 4);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1609 *bp++ = hex2ascii(*rptr++ & 0xf);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1610 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1611
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1612 if (m->m_next) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1613 if (bp > buf + sizeof(buf) - 3)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1614 goto done;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1615 *bp++ = '|';
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1616 } else
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1617 *bp++ = ' ';
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1618 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1619 done:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1620 if (m)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1621 *bp++ = '>';
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1622 *bp = 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1623 diag_printf("%s\n", buf);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1624 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1625
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1626 #endif