1 /* $NetBSD: if_ppp.c,v 1.128 2009/01/19 15:16:34 yamt Exp $ */
2 /* Id: if_ppp.c,v 1.6 1997/03/04 03:33:00 paulus Exp */
5 * if_ppp.c - Point-to-Point Protocol (PPP) Asynchronous driver.
7 * Copyright (c) 1984-2000 Carnegie Mellon University. All rights reserved.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
21 * 3. The name "Carnegie Mellon University" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For permission or any legal
24 * details, please contact
25 * Office of Technology Transfer
26 * Carnegie Mellon University
28 * Pittsburgh, PA 15213-3890
29 * (412) 268-4387, fax: (412) 268-7395
30 * tech-transfer@andrew.cmu.edu
32 * 4. Redistributions of any form whatsoever must retain the following
34 * "This product includes software developed by Computing Services
35 * at Carnegie Mellon University (http://www.cmu.edu/computing/)."
37 * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
38 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
39 * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
40 * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
41 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
42 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
43 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
46 * @(#)if_sl.c 7.6.1.2 (Berkeley) 2/15/89
48 * Copyright (c) 1987 Regents of the University of California.
49 * All rights reserved.
51 * Redistribution and use in source and binary forms are permitted
52 * provided that the above copyright notice and this paragraph are
53 * duplicated in all such forms and that any documentation,
54 * advertising materials, and other materials related to such
55 * distribution and use acknowledge that the software was developed
56 * by the University of California, Berkeley. The name of the
57 * University may not be used to endorse or promote products derived
58 * from this software without specific prior written permission.
59 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
60 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
61 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
63 * Serial Line interface
66 * Center for Seismic Studies
67 * 1300 N 17th Street, Suite 1450
68 * Arlington, Virginia 22209
73 * Pounded on heavily by Chris Torek (chris@mimsy.umd.edu, umcp-cs!chris).
74 * Converted to 4.3BSD Beta by Chris Torek.
75 * Other changes made at Berkeley, based in part on code by Kirk Smith.
77 * Converted to 4.3BSD+ 386BSD by Brad Parker (brad@cayman.com)
78 * Added VJ tcp header compression; more unified ioctls
80 * Extensively modified by Paul Mackerras (paulus@cs.anu.edu.au).
81 * Cleaned up a lot of the mbuf-related code to fix bugs that
82 * caused system crashes and packet corruption. Changed pppstart
83 * so that it doesn't just give up with a collision if the whole
84 * packet doesn't fit in the output ring buffer.
86 * Added priority queueing for interactive IP packets, following
87 * the model of if_sl.c, plus hooks for bpf.
88 * Paul Mackerras (paulus@cs.anu.edu.au).
91 /* from if_sl.c,v 1.11 84/10/04 12:54:47 rick Exp */
92 /* from NetBSD: if_ppp.c,v 1.15.2.2 1994/07/28 05:17:58 cgd Exp */
97 * This is an explanation of that comment. This code used to use
98 * splimp() to block both network and tty interrupts. However,
99 * that call is deprecated. So, we have replaced the uses of
100 * splimp() with splhigh() in order to applomplish what it needs
101 * to accomplish, and added that happy little comment.
104 #include <sys/cdefs.h>
105 __KERNEL_RCSID(0, "$NetBSD: if_ppp.c,v 1.128 2009/01/19 15:16:34 yamt Exp $");
109 #include "opt_inet.h"
110 #include "opt_gateway.h"
118 #include <sys/param.h>
119 #include <sys/proc.h>
120 #include <sys/mbuf.h>
121 #include <sys/socket.h>
122 #include <sys/ioctl.h>
123 #include <sys/kernel.h>
124 #include <sys/systm.h>
125 #include <sys/time.h>
126 #include <sys/malloc.h>
127 #include <sys/module.h>
128 #include <sys/mutex.h>
129 #include <sys/once.h>
130 #include <sys/conf.h>
131 #include <sys/kauth.h>
132 #include <sys/intr.h>
133 #include <sys/simplelock.h>
134 #include <sys/socketvar.h>
137 #include <net/if_types.h>
138 #include <net/netisr.h>
139 #include <net/route.h>
144 #include <netinet/in.h>
145 #include <netinet/in_systm.h>
146 #include <netinet/in_var.h>
148 #include <netinet/ip.h>
151 #include "bpfilter.h"
156 #if defined(PPP_FILTER) || NBPFILTER > 0
157 #include <net/slip.h>
161 #include <net/slcompress.h>
164 #include <net/ppp_defs.h>
165 #include <net/if_ppp.h>
166 #include <net/if_pppvar.h>
170 #define PACKETPTR struct mbuf *
171 #include <net/ppp-comp.h>
174 static int pppsioctl(struct ifnet
*, u_long
, void *);
175 static void ppp_requeue(struct ppp_softc
*);
176 static void ppp_ccp(struct ppp_softc
*, struct mbuf
*m
, int rcvd
);
177 static void ppp_ccp_closed(struct ppp_softc
*);
178 static void ppp_inproc(struct ppp_softc
*, struct mbuf
*);
179 static void pppdumpm(struct mbuf
*m0
);
181 static void ppp_ifstart(struct ifnet
*ifp
);
184 static void pppintr(void *);
187 * Some useful mbuf macros not in mbuf.h.
189 #define M_IS_CLUSTER(m) ((m)->m_flags & M_EXT)
191 #define M_DATASTART(m) \
192 (M_IS_CLUSTER(m) ? (m)->m_ext.ext_buf : \
193 (m)->m_flags & M_PKTHDR ? (m)->m_pktdat : (m)->m_dat)
195 #define M_DATASIZE(m) \
196 (M_IS_CLUSTER(m) ? (m)->m_ext.ext_size : \
197 (m)->m_flags & M_PKTHDR ? MHLEN: MLEN)
200 * We define two link layer specific mbuf flags, to mark high-priority
201 * packets for output, and received packets following lost/corrupted
204 #define M_HIGHPRI M_LINK0 /* output packet for sc_fastq */
205 #define M_ERRMARK M_LINK1 /* rx packet following lost/corrupted pkt */
207 static int ppp_clone_create(struct if_clone
*, int);
208 static int ppp_clone_destroy(struct ifnet
*);
210 static struct ppp_softc
*ppp_create(const char *, int);
212 static LIST_HEAD(, ppp_softc
) ppp_softc_list
;
214 struct if_clone ppp_cloner
=
215 IF_CLONE_INITIALIZER("ppp", ppp_clone_create
, ppp_clone_destroy
);
217 static struct simplelock ppp_list_mutex
= SIMPLELOCK_INITIALIZER
;
220 ONCE_DECL(ppp_compressor_mtx_init
);
221 static LIST_HEAD(, compressor
) ppp_compressors
= { NULL
};
222 static kmutex_t ppp_compressors_mtx
;
224 static int ppp_compressor_init(void);
225 static struct compressor
*ppp_get_compressor(uint8_t);
226 static void ppp_compressor_rele(struct compressor
*);
227 #endif /* PPP_COMPRESS */
231 * Called from boot code to establish ppp interfaces.
236 extern struct linesw ppp_disc
;
238 if (ttyldisc_attach(&ppp_disc
) != 0)
240 LIST_INIT(&ppp_softc_list
);
241 if_clone_attach(&ppp_cloner
);
242 RUN_ONCE(&ppp_compressor_mtx_init
, ppp_compressor_init
);
245 static struct ppp_softc
*
246 ppp_create(const char *name
, int unit
)
248 struct ppp_softc
*sc
, *sci
, *scl
= NULL
;
250 sc
= malloc(sizeof(*sc
), M_DEVBUF
, M_WAIT
|M_ZERO
);
252 simple_lock(&ppp_list_mutex
);
255 LIST_FOREACH(sci
, &ppp_softc_list
, sc_iflist
) {
257 if (i
< sci
->sc_unit
) {
262 KASSERT(i
== sci
->sc_unit
);
270 LIST_FOREACH(sci
, &ppp_softc_list
, sc_iflist
) {
272 if (unit
< sci
->sc_unit
)
274 else if (unit
== sci
->sc_unit
) {
282 LIST_INSERT_BEFORE(sci
, sc
, sc_iflist
);
283 else if (scl
!= NULL
)
284 LIST_INSERT_AFTER(scl
, sc
, sc_iflist
);
286 LIST_INSERT_HEAD(&ppp_softc_list
, sc
, sc_iflist
);
288 simple_unlock(&ppp_list_mutex
);
290 if_initname(&sc
->sc_if
, name
, sc
->sc_unit
= unit
);
291 callout_init(&sc
->sc_timo_ch
, 0);
292 sc
->sc_if
.if_softc
= sc
;
293 sc
->sc_if
.if_mtu
= PPP_MTU
;
294 sc
->sc_if
.if_flags
= IFF_POINTOPOINT
| IFF_MULTICAST
;
295 sc
->sc_if
.if_type
= IFT_PPP
;
296 sc
->sc_if
.if_hdrlen
= PPP_HDRLEN
;
297 sc
->sc_if
.if_dlt
= DLT_NULL
;
298 sc
->sc_if
.if_ioctl
= pppsioctl
;
299 sc
->sc_if
.if_output
= pppoutput
;
301 sc
->sc_if
.if_start
= ppp_ifstart
;
303 IFQ_SET_MAXLEN(&sc
->sc_if
.if_snd
, IFQ_MAXLEN
);
304 sc
->sc_inq
.ifq_maxlen
= IFQ_MAXLEN
;
305 sc
->sc_fastq
.ifq_maxlen
= IFQ_MAXLEN
;
306 sc
->sc_rawq
.ifq_maxlen
= IFQ_MAXLEN
;
307 /* Ratio of 1:2 packets between the regular and the fast queue */
309 IFQ_SET_READY(&sc
->sc_if
.if_snd
);
310 if_attach(&sc
->sc_if
);
311 if_alloc_sadl(&sc
->sc_if
);
313 bpfattach(&sc
->sc_if
, DLT_NULL
, 0);
319 ppp_clone_create(struct if_clone
*ifc
, int unit
)
321 return ppp_create(ifc
->ifc_name
, unit
) == NULL
? EEXIST
: 0;
325 ppp_clone_destroy(struct ifnet
*ifp
)
327 struct ppp_softc
*sc
= (struct ppp_softc
*)ifp
->if_softc
;
329 if (sc
->sc_devp
!= NULL
)
330 return EBUSY
; /* Not removing it */
332 simple_lock(&ppp_list_mutex
);
333 LIST_REMOVE(sc
, sc_iflist
);
334 simple_unlock(&ppp_list_mutex
);
346 * Allocate a ppp interface unit and initialize it.
351 struct ppp_softc
*sc
= NULL
, *scf
;
354 simple_lock(&ppp_list_mutex
);
355 for (scf
= LIST_FIRST(&ppp_softc_list
); scf
!= NULL
;
356 scf
= LIST_NEXT(scf
, sc_iflist
)) {
357 if (scf
->sc_xfer
== pid
) {
359 simple_unlock(&ppp_list_mutex
);
362 if (scf
->sc_devp
== NULL
&& sc
== NULL
)
365 simple_unlock(&ppp_list_mutex
);
368 sc
= ppp_create(ppp_cloner
.ifc_name
, -1);
370 sc
->sc_si
= softint_establish(SOFTINT_NET
, pppintr
, sc
);
371 if (sc
->sc_si
== NULL
) {
372 printf("%s: unable to establish softintr\n", sc
->sc_if
.if_xname
);
376 sc
->sc_mru
= PPP_MRU
;
377 sc
->sc_relinq
= NULL
;
378 (void)memset(&sc
->sc_stats
, 0, sizeof(sc
->sc_stats
));
380 sc
->sc_comp
= malloc(sizeof(struct slcompress
), M_DEVBUF
, M_NOWAIT
);
382 sl_compress_init(sc
->sc_comp
);
385 sc
->sc_xc_state
= NULL
;
386 sc
->sc_rc_state
= NULL
;
387 #endif /* PPP_COMPRESS */
388 for (i
= 0; i
< NUM_NP
; ++i
)
389 sc
->sc_npmode
[i
] = NPMODE_ERROR
;
390 sc
->sc_npqueue
= NULL
;
391 sc
->sc_npqtail
= &sc
->sc_npqueue
;
392 sc
->sc_last_sent
= sc
->sc_last_recv
= time_second
;
398 * Deallocate a ppp unit. Must be called at splsoftnet or higher.
401 pppdealloc(struct ppp_softc
*sc
)
405 softint_disestablish(sc
->sc_si
);
407 sc
->sc_if
.if_flags
&= ~(IFF_UP
|IFF_RUNNING
);
411 IF_DEQUEUE(&sc
->sc_rawq
, m
);
417 IF_DEQUEUE(&sc
->sc_inq
, m
);
423 IF_DEQUEUE(&sc
->sc_fastq
, m
);
428 while ((m
= sc
->sc_npqueue
) != NULL
) {
429 sc
->sc_npqueue
= m
->m_nextpkt
;
432 if (sc
->sc_togo
!= NULL
) {
433 m_freem(sc
->sc_togo
);
438 sc
->sc_xc_state
= NULL
;
439 sc
->sc_rc_state
= NULL
;
440 #endif /* PPP_COMPRESS */
442 if (sc
->sc_pass_filt_in
.bf_insns
!= 0) {
443 free(sc
->sc_pass_filt_in
.bf_insns
, M_DEVBUF
);
444 sc
->sc_pass_filt_in
.bf_insns
= 0;
445 sc
->sc_pass_filt_in
.bf_len
= 0;
447 if (sc
->sc_pass_filt_out
.bf_insns
!= 0) {
448 free(sc
->sc_pass_filt_out
.bf_insns
, M_DEVBUF
);
449 sc
->sc_pass_filt_out
.bf_insns
= 0;
450 sc
->sc_pass_filt_out
.bf_len
= 0;
452 if (sc
->sc_active_filt_in
.bf_insns
!= 0) {
453 free(sc
->sc_active_filt_in
.bf_insns
, M_DEVBUF
);
454 sc
->sc_active_filt_in
.bf_insns
= 0;
455 sc
->sc_active_filt_in
.bf_len
= 0;
457 if (sc
->sc_active_filt_out
.bf_insns
!= 0) {
458 free(sc
->sc_active_filt_out
.bf_insns
, M_DEVBUF
);
459 sc
->sc_active_filt_out
.bf_insns
= 0;
460 sc
->sc_active_filt_out
.bf_len
= 0;
462 #endif /* PPP_FILTER */
464 if (sc
->sc_comp
!= 0) {
465 free(sc
->sc_comp
, M_DEVBUF
);
469 (void)ppp_clone_destroy(&sc
->sc_if
);
473 * Ioctl routine for generic ppp devices.
476 pppioctl(struct ppp_softc
*sc
, u_long cmd
, void *data
, int flag
,
479 int s
, error
, flags
, mru
, npx
;
481 struct ppp_option_data
*odp
;
482 struct compressor
*cp
;
486 struct bpf_program
*bp
, *nbp
;
487 struct bpf_insn
*newcode
, *oldcode
;
489 #endif /* PPP_FILTER */
491 u_char ccp_option
[CCP_MAX_OPTION_LENGTH
];
498 case PPPIOCSCOMPRESS
:
500 if (kauth_authorize_network(l
->l_cred
, KAUTH_NETWORK_INTERFACE
,
501 KAUTH_REQ_NETWORK_INTERFACE_SETPRIV
, &sc
->sc_if
, KAUTH_ARG(cmd
),
506 /* XXX: Why is this privileged?! */
507 if (kauth_authorize_network(l
->l_cred
, KAUTH_NETWORK_INTERFACE
,
508 KAUTH_REQ_NETWORK_INTERFACE_GETPRIV
, &sc
->sc_if
, KAUTH_ARG(cmd
),
518 *(int *)data
= sc
->sc_inq
.ifq_len
;
522 *(int *)data
= sc
->sc_unit
;
526 *(u_int
*)data
= sc
->sc_flags
;
531 struct ppp_rawin
*rwin
= (struct ppp_rawin
*)data
;
534 for (c
= sc
->sc_rawin_start
; c
< sizeof(sc
->sc_rawin
.buf
);)
535 rwin
->buf
[q
++] = sc
->sc_rawin
.buf
[c
++];
537 for (c
= 0; c
< sc
->sc_rawin_start
;)
538 rwin
->buf
[q
++] = sc
->sc_rawin
.buf
[c
++];
540 rwin
->count
= sc
->sc_rawin
.count
;
545 flags
= *(int *)data
& SC_MASK
;
548 if (sc
->sc_flags
& SC_CCP_OPEN
&& !(flags
& SC_CCP_OPEN
))
551 splhigh(); /* XXX IMP ME HARDER */
552 sc
->sc_flags
= (sc
->sc_flags
& ~SC_MASK
) | flags
;
558 if (mru
>= PPP_MINMRU
&& mru
<= PPP_MAXMRU
)
563 *(int *)data
= sc
->sc_mru
;
570 sl_compress_setup(sc
->sc_comp
, *(int *)data
);
577 sc
->sc_xfer
= l
->l_proc
->p_pid
;
581 case PPPIOCSCOMPRESS
:
582 odp
= (struct ppp_option_data
*) data
;
584 if (nb
> sizeof(ccp_option
))
585 nb
= sizeof(ccp_option
);
586 if ((error
= copyin(odp
->ptr
, ccp_option
, nb
)) != 0)
588 if (ccp_option
[1] < 2) /* preliminary check on the length byte */
590 cp
= ppp_get_compressor(ccp_option
[0]);
592 if (sc
->sc_flags
& SC_DEBUG
)
593 printf("%s: no compressor for [%x %x %x], %x\n",
594 sc
->sc_if
.if_xname
, ccp_option
[0], ccp_option
[1],
596 return (EINVAL
); /* no handler found */
599 * Found a handler for the protocol - try to allocate
600 * a compressor or decompressor.
605 if (sc
->sc_xc_state
!= NULL
) {
606 (*sc
->sc_xcomp
->comp_free
)(sc
->sc_xc_state
);
607 ppp_compressor_rele(sc
->sc_xcomp
);
610 sc
->sc_xc_state
= cp
->comp_alloc(ccp_option
, nb
);
611 if (sc
->sc_xc_state
== NULL
) {
612 if (sc
->sc_flags
& SC_DEBUG
)
613 printf("%s: comp_alloc failed\n",
617 splhigh(); /* XXX IMP ME HARDER */
618 sc
->sc_flags
&= ~SC_COMP_RUN
;
622 if (sc
->sc_rc_state
!= NULL
) {
623 (*sc
->sc_rcomp
->decomp_free
)(sc
->sc_rc_state
);
624 ppp_compressor_rele(sc
->sc_rcomp
);
627 sc
->sc_rc_state
= cp
->decomp_alloc(ccp_option
, nb
);
628 if (sc
->sc_rc_state
== NULL
) {
629 if (sc
->sc_flags
& SC_DEBUG
)
630 printf("%s: decomp_alloc failed\n",
634 splhigh(); /* XXX IMP ME HARDER */
635 sc
->sc_flags
&= ~SC_DECOMP_RUN
;
639 #endif /* PPP_COMPRESS */
643 npi
= (struct npioctl
*) data
;
644 switch (npi
->protocol
) {
654 if (cmd
== PPPIOCGNPMODE
) {
655 npi
->mode
= sc
->sc_npmode
[npx
];
657 if (npi
->mode
!= sc
->sc_npmode
[npx
]) {
659 sc
->sc_npmode
[npx
] = npi
->mode
;
660 if (npi
->mode
!= NPMODE_QUEUE
) {
672 ((struct ppp_idle
*)data
)->xmit_idle
= t
- sc
->sc_last_sent
;
673 ((struct ppp_idle
*)data
)->recv_idle
= t
- sc
->sc_last_recv
;
680 /* These are no longer supported. */
687 nbp
= (struct bpf_program
*) data
;
688 if ((unsigned) nbp
->bf_len
> BPF_MAXINSNS
)
690 newcodelen
= nbp
->bf_len
* sizeof(struct bpf_insn
);
691 if (newcodelen
!= 0) {
692 newcode
= malloc(newcodelen
, M_DEVBUF
, M_WAITOK
);
693 /* WAITOK -- malloc() never fails. */
694 if ((error
= copyin((void *)nbp
->bf_insns
, (void *)newcode
,
696 free(newcode
, M_DEVBUF
);
699 if (!bpf_validate(newcode
, nbp
->bf_len
)) {
700 free(newcode
, M_DEVBUF
);
707 bp
= &sc
->sc_pass_filt_in
;
711 bp
= &sc
->sc_pass_filt_out
;
715 bp
= &sc
->sc_active_filt_in
;
719 bp
= &sc
->sc_active_filt_out
;
722 free(newcode
, M_DEVBUF
);
723 return (EPASSTHROUGH
);
725 oldcode
= bp
->bf_insns
;
727 bp
->bf_len
= nbp
->bf_len
;
728 bp
->bf_insns
= newcode
;
731 free(oldcode
, M_DEVBUF
);
733 #endif /* PPP_FILTER */
736 return (EPASSTHROUGH
);
742 * Process an ioctl request to the ppp network interface.
745 pppsioctl(struct ifnet
*ifp
, u_long cmd
, void *data
)
747 struct lwp
*l
= curlwp
; /* XXX */
748 struct ppp_softc
*sc
= ifp
->if_softc
;
749 struct ifaddr
*ifa
= (struct ifaddr
*)data
;
750 struct ifreq
*ifr
= (struct ifreq
*)data
;
751 struct ppp_stats
*psp
;
753 struct ppp_comp_stats
*pcp
;
755 int s
= splnet(), error
= 0;
759 if ((error
= ifioctl_common(ifp
, cmd
, data
)) != 0)
761 if ((ifp
->if_flags
& IFF_RUNNING
) == 0)
762 ifp
->if_flags
&= ~IFF_UP
;
766 switch (ifa
->ifa_addr
->sa_family
) {
776 error
= EAFNOSUPPORT
;
782 switch (ifa
->ifa_addr
->sa_family
) {
792 error
= EAFNOSUPPORT
;
800 error
= EAFNOSUPPORT
;
803 switch (ifreq_getaddr(cmd
, ifr
)->sa_family
) {
813 error
= EAFNOSUPPORT
;
819 psp
= &((struct ifpppstatsreq
*) data
)->stats
;
820 memset(psp
, 0, sizeof(*psp
));
821 psp
->p
= sc
->sc_stats
;
822 #if defined(VJC) && !defined(SL_NO_STATS)
824 psp
->vj
.vjs_packets
= sc
->sc_comp
->sls_packets
;
825 psp
->vj
.vjs_compressed
= sc
->sc_comp
->sls_compressed
;
826 psp
->vj
.vjs_searches
= sc
->sc_comp
->sls_searches
;
827 psp
->vj
.vjs_misses
= sc
->sc_comp
->sls_misses
;
828 psp
->vj
.vjs_uncompressedin
= sc
->sc_comp
->sls_uncompressedin
;
829 psp
->vj
.vjs_compressedin
= sc
->sc_comp
->sls_compressedin
;
830 psp
->vj
.vjs_errorin
= sc
->sc_comp
->sls_errorin
;
831 psp
->vj
.vjs_tossed
= sc
->sc_comp
->sls_tossed
;
838 pcp
= &((struct ifpppcstatsreq
*) data
)->stats
;
839 memset(pcp
, 0, sizeof(*pcp
));
840 if (sc
->sc_xc_state
!= NULL
)
841 (*sc
->sc_xcomp
->comp_stat
)(sc
->sc_xc_state
, &pcp
->c
);
842 if (sc
->sc_rc_state
!= NULL
)
843 (*sc
->sc_rcomp
->decomp_stat
)(sc
->sc_rc_state
, &pcp
->d
);
845 #endif /* PPP_COMPRESS */
848 if ((error
= kauth_authorize_network(l
->l_cred
,
849 KAUTH_NETWORK_INTERFACE
, KAUTH_REQ_NETWORK_INTERFACE_SETPRIV
,
850 ifp
, (void *)cmd
, NULL
) != 0))
854 if ((error
= ifioctl_common(&sc
->sc_if
, cmd
, data
)) == ENETRESET
)
863 * Queue a packet. Start transmission if not active.
864 * Packet is placed in Information field of PPP frame.
867 pppoutput(struct ifnet
*ifp
, struct mbuf
*m0
, const struct sockaddr
*dst
,
870 struct ppp_softc
*sc
= ifp
->if_softc
;
871 int protocol
, address
, control
;
880 ALTQ_DECL(struct altq_pktattr pktattr
;)
882 if (sc
->sc_devp
== NULL
|| (ifp
->if_flags
& IFF_RUNNING
) == 0
883 || ((ifp
->if_flags
& IFF_UP
) == 0 && dst
->sa_family
!= AF_UNSPEC
)) {
884 error
= ENETDOWN
; /* sort of */
888 IFQ_CLASSIFY(&ifp
->if_snd
, m0
, dst
->sa_family
, &pktattr
);
891 * Compute PPP header.
893 m0
->m_flags
&= ~M_HIGHPRI
;
894 switch (dst
->sa_family
) {
897 address
= PPP_ALLSTATIONS
;
900 mode
= sc
->sc_npmode
[NP_IP
];
903 * If this packet has the "low delay" bit set in the IP header,
904 * put it on the fastq instead.
906 ip
= mtod(m0
, struct ip
*);
907 if (ip
->ip_tos
& IPTOS_LOWDELAY
)
908 m0
->m_flags
|= M_HIGHPRI
;
913 address
= PPP_ALLSTATIONS
; /*XXX*/
914 control
= PPP_UI
; /*XXX*/
916 mode
= sc
->sc_npmode
[NP_IPV6
];
918 #if 0 /* XXX flowinfo/traffic class, maybe? */
920 * If this packet has the "low delay" bit set in the IP header,
921 * put it on the fastq instead.
923 ip
= mtod(m0
, struct ip
*);
924 if (ip
->ip_tos
& IPTOS_LOWDELAY
)
925 m0
->m_flags
|= M_HIGHPRI
;
930 address
= PPP_ADDRESS(dst
->sa_data
);
931 control
= PPP_CONTROL(dst
->sa_data
);
932 protocol
= PPP_PROTOCOL(dst
->sa_data
);
936 printf("%s: af%d not supported\n", ifp
->if_xname
, dst
->sa_family
);
937 error
= EAFNOSUPPORT
;
942 * Drop this packet, or return an error, if necessary.
944 if (mode
== NPMODE_ERROR
) {
948 if (mode
== NPMODE_DROP
) {
956 M_PREPEND(m0
, PPP_HDRLEN
, M_DONTWAIT
);
962 cp
= mtod(m0
, u_char
*);
965 *cp
++ = protocol
>> 8;
966 *cp
++ = protocol
& 0xff;
970 if (sc
->sc_flags
& SC_LOG_OUTPKT
) {
971 printf("%s output: ", ifp
->if_xname
);
975 if ((protocol
& 0x8000) == 0) {
978 * Apply the pass and active filters to the packet,
979 * but only if it is a data packet.
981 if (sc
->sc_pass_filt_out
.bf_insns
!= 0
982 && bpf_filter(sc
->sc_pass_filt_out
.bf_insns
, (u_char
*) m0
,
984 error
= 0; /* drop this packet */
989 * Update the time we sent the most recent packet.
991 if (sc
->sc_active_filt_out
.bf_insns
== 0
992 || bpf_filter(sc
->sc_active_filt_out
.bf_insns
, (u_char
*) m0
,
994 sc
->sc_last_sent
= time_second
;
997 * Update the time we sent the most recent packet.
999 sc
->sc_last_sent
= time_second
;
1000 #endif /* PPP_FILTER */
1005 * See if bpf wants to look at the packet.
1007 if (sc
->sc_if
.if_bpf
)
1008 bpf_mtap(sc
->sc_if
.if_bpf
, m0
);
1012 * Put the packet on the appropriate queue.
1015 if (mode
== NPMODE_QUEUE
) {
1016 /* XXX we should limit the number of packets on this queue */
1017 *sc
->sc_npqtail
= m0
;
1018 m0
->m_nextpkt
= NULL
;
1019 sc
->sc_npqtail
= &m0
->m_nextpkt
;
1021 ifq
= (m0
->m_flags
& M_HIGHPRI
) ? &sc
->sc_fastq
: NULL
;
1022 if ((error
= ifq_enqueue2(&sc
->sc_if
, ifq
, m0
1023 ALTQ_COMMA
ALTQ_DECL(&pktattr
))) != 0) {
1025 sc
->sc_if
.if_oerrors
++;
1026 sc
->sc_stats
.ppp_oerrors
++;
1032 ifp
->if_obytes
+= len
;
1043 * After a change in the NPmode for some NP, move packets from the
1044 * npqueue to the send queue or the fast queue as appropriate.
1045 * Should be called at splnet, since we muck with the queues.
1048 ppp_requeue(struct ppp_softc
*sc
)
1050 struct mbuf
*m
, **mpp
;
1051 struct ifqueue
*ifq
;
1055 for (mpp
= &sc
->sc_npqueue
; (m
= *mpp
) != NULL
; ) {
1056 switch (PPP_PROTOCOL(mtod(m
, u_char
*))) {
1058 mode
= sc
->sc_npmode
[NP_IP
];
1061 mode
= sc
->sc_npmode
[NP_IPV6
];
1070 * This packet can now go on one of the queues to be sent.
1072 *mpp
= m
->m_nextpkt
;
1073 m
->m_nextpkt
= NULL
;
1074 ifq
= (m
->m_flags
& M_HIGHPRI
) ? &sc
->sc_fastq
: NULL
;
1075 if ((error
= ifq_enqueue2(&sc
->sc_if
, ifq
, m ALTQ_COMMA
1076 ALTQ_DECL(NULL
))) != 0) {
1077 sc
->sc_if
.if_oerrors
++;
1078 sc
->sc_stats
.ppp_oerrors
++;
1084 *mpp
= m
->m_nextpkt
;
1089 mpp
= &m
->m_nextpkt
;
1093 sc
->sc_npqtail
= mpp
;
1097 * Transmitter has finished outputting some stuff;
1098 * remember to call sc->sc_start later at splsoftnet.
1101 ppp_restart(struct ppp_softc
*sc
)
1103 int s
= splhigh(); /* XXX IMP ME HARDER */
1105 sc
->sc_flags
&= ~SC_TBUSY
;
1106 softint_schedule(sc
->sc_si
);
1111 * Get a packet to send. This procedure is intended to be called at
1112 * splsoftnet, since it may involve time-consuming operations such as
1113 * applying VJ compression, packet compression, address/control and/or
1114 * protocol field compression to the packet.
1117 ppp_dequeue(struct ppp_softc
*sc
)
1119 struct mbuf
*m
, *mp
;
1121 int address
, control
, protocol
;
1125 * Grab a packet to send: first try the fast queue, then the
1129 if (sc
->sc_nfastq
< sc
->sc_maxfastq
) {
1130 IF_DEQUEUE(&sc
->sc_fastq
, m
);
1134 IFQ_DEQUEUE(&sc
->sc_if
.if_snd
, m
);
1137 IFQ_DEQUEUE(&sc
->sc_if
.if_snd
, m
);
1139 IF_DEQUEUE(&sc
->sc_fastq
, m
);
1149 ++sc
->sc_stats
.ppp_opackets
;
1152 * Extract the ppp header of the new packet.
1153 * The ppp header will be in one mbuf.
1155 cp
= mtod(m
, u_char
*);
1156 address
= PPP_ADDRESS(cp
);
1157 control
= PPP_CONTROL(cp
);
1158 protocol
= PPP_PROTOCOL(cp
);
1164 * If the packet is a TCP/IP packet, see if we can compress it.
1166 if ((sc
->sc_flags
& SC_COMP_TCP
) && sc
->sc_comp
!= NULL
) {
1171 ip
= (struct ip
*) (cp
+ PPP_HDRLEN
);
1172 if (mp
->m_len
<= PPP_HDRLEN
) {
1176 ip
= mtod(mp
, struct ip
*);
1178 /* this code assumes the IP/TCP header is in one non-shared mbuf */
1179 if (ip
->ip_p
== IPPROTO_TCP
) {
1180 type
= sl_compress_tcp(mp
, ip
, sc
->sc_comp
,
1181 !(sc
->sc_flags
& SC_NO_TCP_CCID
));
1183 case TYPE_UNCOMPRESSED_TCP
:
1184 protocol
= PPP_VJC_UNCOMP
;
1186 case TYPE_COMPRESSED_TCP
:
1187 protocol
= PPP_VJC_COMP
;
1188 cp
= mtod(m
, u_char
*);
1189 cp
[0] = address
; /* header has moved */
1194 cp
[3] = protocol
; /* update protocol in PPP header */
1204 #endif /* PPP_COMPRESS */
1208 if (protocol
!= PPP_LCP
&& protocol
!= PPP_CCP
1209 && sc
->sc_xc_state
&& (sc
->sc_flags
& SC_COMP_RUN
)) {
1210 struct mbuf
*mcomp
= NULL
;
1214 for (mp
= m
; mp
!= NULL
; mp
= mp
->m_next
)
1216 (*sc
->sc_xcomp
->compress
)
1217 (sc
->sc_xc_state
, &mcomp
, m
, slen
, sc
->sc_if
.if_mtu
+ PPP_HDRLEN
);
1218 if (mcomp
!= NULL
) {
1219 if (sc
->sc_flags
& SC_CCP_UP
) {
1220 /* Send the compressed packet instead of the original. */
1223 cp
= mtod(m
, u_char
*);
1226 /* Can't transmit compressed packets until CCP is up. */
1231 #endif /* PPP_COMPRESS */
1234 * Compress the address/control and protocol, if possible.
1236 if (sc
->sc_flags
& SC_COMP_AC
&& address
== PPP_ALLSTATIONS
&&
1237 control
== PPP_UI
&& protocol
!= PPP_ALLSTATIONS
&&
1238 protocol
!= PPP_LCP
) {
1239 /* can compress address/control */
1243 if (sc
->sc_flags
& SC_COMP_PROT
&& protocol
< 0xFF) {
1244 /* can compress protocol */
1245 if (mtod(m
, u_char
*) == cp
) {
1246 cp
[2] = cp
[1]; /* move address/control up */
1257 * Software interrupt routine, called at splsoftnet.
1262 struct ppp_softc
*sc
= arg
;
1266 mutex_enter(softnet_lock
);
1267 if (!(sc
->sc_flags
& SC_TBUSY
)
1268 && (IFQ_IS_EMPTY(&sc
->sc_if
.if_snd
) == 0 || sc
->sc_fastq
.ifq_head
1270 s
= splhigh(); /* XXX IMP ME HARDER */
1271 sc
->sc_flags
|= SC_TBUSY
;
1273 (*sc
->sc_start
)(sc
);
1277 IF_DEQUEUE(&sc
->sc_rawq
, m
);
1283 mutex_exit(softnet_lock
);
1288 * Handle a CCP packet. `rcvd' is 1 if the packet was received,
1289 * 0 if it is about to be transmitted.
1292 ppp_ccp(struct ppp_softc
*sc
, struct mbuf
*m
, int rcvd
)
1299 * Get a pointer to the data after the PPP header.
1301 if (m
->m_len
<= PPP_HDRLEN
) {
1305 dp
= (mp
!= NULL
)? mtod(mp
, u_char
*): NULL
;
1308 dp
= mtod(mp
, u_char
*) + PPP_HDRLEN
;
1311 ep
= mtod(mp
, u_char
*) + mp
->m_len
;
1312 if (dp
+ CCP_HDRLEN
> ep
)
1314 slen
= CCP_LENGTH(dp
);
1315 if (dp
+ slen
> ep
) {
1316 if (sc
->sc_flags
& SC_DEBUG
)
1317 printf("if_ppp/ccp: not enough data in mbuf (%p+%x > %p+%x)\n",
1318 dp
, slen
, mtod(mp
, u_char
*), mp
->m_len
);
1322 switch (CCP_CODE(dp
)) {
1326 /* CCP must be going down - disable compression */
1327 if (sc
->sc_flags
& SC_CCP_UP
) {
1328 s
= splhigh(); /* XXX IMP ME HARDER */
1329 sc
->sc_flags
&= ~(SC_CCP_UP
| SC_COMP_RUN
| SC_DECOMP_RUN
);
1335 if (sc
->sc_flags
& SC_CCP_OPEN
&& !(sc
->sc_flags
& SC_CCP_UP
)
1336 && slen
>= CCP_HDRLEN
+ CCP_OPT_MINLEN
1337 && slen
>= CCP_OPT_LENGTH(dp
+ CCP_HDRLEN
) + CCP_HDRLEN
) {
1339 /* we're agreeing to send compressed packets. */
1340 if (sc
->sc_xc_state
!= NULL
1341 && (*sc
->sc_xcomp
->comp_init
)
1342 (sc
->sc_xc_state
, dp
+ CCP_HDRLEN
, slen
- CCP_HDRLEN
,
1343 sc
->sc_unit
, 0, sc
->sc_flags
& SC_DEBUG
)) {
1344 s
= splhigh(); /* XXX IMP ME HARDER */
1345 sc
->sc_flags
|= SC_COMP_RUN
;
1349 /* peer is agreeing to send compressed packets. */
1350 if (sc
->sc_rc_state
!= NULL
1351 && (*sc
->sc_rcomp
->decomp_init
)
1352 (sc
->sc_rc_state
, dp
+ CCP_HDRLEN
, slen
- CCP_HDRLEN
,
1353 sc
->sc_unit
, 0, sc
->sc_mru
,
1354 sc
->sc_flags
& SC_DEBUG
)) {
1355 s
= splhigh(); /* XXX IMP ME HARDER */
1356 sc
->sc_flags
|= SC_DECOMP_RUN
;
1357 sc
->sc_flags
&= ~(SC_DC_ERROR
| SC_DC_FERROR
);
1365 if (sc
->sc_flags
& SC_CCP_UP
) {
1367 if (sc
->sc_xc_state
&& (sc
->sc_flags
& SC_COMP_RUN
))
1368 (*sc
->sc_xcomp
->comp_reset
)(sc
->sc_xc_state
);
1370 if (sc
->sc_rc_state
&& (sc
->sc_flags
& SC_DECOMP_RUN
)) {
1371 (*sc
->sc_rcomp
->decomp_reset
)(sc
->sc_rc_state
);
1372 s
= splhigh(); /* XXX IMP ME HARDER */
1373 sc
->sc_flags
&= ~SC_DC_ERROR
;
1383 * CCP is down; free (de)compressor state if necessary.
1386 ppp_ccp_closed(struct ppp_softc
*sc
)
1388 if (sc
->sc_xc_state
) {
1389 (*sc
->sc_xcomp
->comp_free
)(sc
->sc_xc_state
);
1390 ppp_compressor_rele(sc
->sc_xcomp
);
1391 sc
->sc_xc_state
= NULL
;
1393 if (sc
->sc_rc_state
) {
1394 (*sc
->sc_rcomp
->decomp_free
)(sc
->sc_rc_state
);
1395 ppp_compressor_rele(sc
->sc_rcomp
);
1396 sc
->sc_rc_state
= NULL
;
1399 #endif /* PPP_COMPRESS */
1402 * PPP packet input routine.
1403 * The caller has checked and removed the FCS and has inserted
1404 * the address/control bytes and the protocol high byte if they
1408 ppppktin(struct ppp_softc
*sc
, struct mbuf
*m
, int lost
)
1410 int s
= splhigh(); /* XXX IMP ME HARDER */
1413 m
->m_flags
|= M_ERRMARK
;
1414 IF_ENQUEUE(&sc
->sc_rawq
, m
);
1415 softint_schedule(sc
->sc_si
);
1420 * Process a received PPP packet, doing decompression as necessary.
1421 * Should be called at splsoftnet.
1423 #define COMPTYPE(proto) ((proto) == PPP_VJC_COMP? TYPE_COMPRESSED_TCP: \
1424 TYPE_UNCOMPRESSED_TCP)
1427 ppp_inproc(struct ppp_softc
*sc
, struct mbuf
*m
)
1429 struct ifnet
*ifp
= &sc
->sc_if
;
1430 struct ifqueue
*inq
;
1431 int s
, ilen
, proto
, rv
;
1432 u_char
*cp
, adrs
, ctrl
;
1433 struct mbuf
*mp
, *dmp
= NULL
;
1440 sc
->sc_stats
.ppp_ipackets
++;
1442 if (sc
->sc_flags
& SC_LOG_INPKT
) {
1444 for (mp
= m
; mp
!= NULL
; mp
= mp
->m_next
)
1446 printf("%s: got %d bytes\n", ifp
->if_xname
, ilen
);
1450 cp
= mtod(m
, u_char
*);
1451 adrs
= PPP_ADDRESS(cp
);
1452 ctrl
= PPP_CONTROL(cp
);
1453 proto
= PPP_PROTOCOL(cp
);
1455 if (m
->m_flags
& M_ERRMARK
) {
1456 m
->m_flags
&= ~M_ERRMARK
;
1457 s
= splhigh(); /* XXX IMP ME HARDER */
1458 sc
->sc_flags
|= SC_VJ_RESET
;
1464 * Decompress this packet if necessary, update the receiver's
1465 * dictionary, or take appropriate action on a CCP packet.
1467 if (proto
== PPP_COMP
&& sc
->sc_rc_state
&& (sc
->sc_flags
& SC_DECOMP_RUN
)
1468 && !(sc
->sc_flags
& SC_DC_ERROR
) && !(sc
->sc_flags
& SC_DC_FERROR
)) {
1469 /* decompress this packet */
1470 rv
= (*sc
->sc_rcomp
->decompress
)(sc
->sc_rc_state
, m
, &dmp
);
1471 if (rv
== DECOMP_OK
) {
1474 /* no error, but no decompressed packet produced */
1478 cp
= mtod(m
, u_char
*);
1479 proto
= PPP_PROTOCOL(cp
);
1483 * An error has occurred in decompression.
1484 * Pass the compressed packet up to pppd, which may take
1485 * CCP down or issue a Reset-Req.
1487 if (sc
->sc_flags
& SC_DEBUG
)
1488 printf("%s: decompress failed %d\n", ifp
->if_xname
, rv
);
1489 s
= splhigh(); /* XXX IMP ME HARDER */
1490 sc
->sc_flags
|= SC_VJ_RESET
;
1491 if (rv
== DECOMP_ERROR
)
1492 sc
->sc_flags
|= SC_DC_ERROR
;
1494 sc
->sc_flags
|= SC_DC_FERROR
;
1499 if (sc
->sc_rc_state
&& (sc
->sc_flags
& SC_DECOMP_RUN
)) {
1500 (*sc
->sc_rcomp
->incomp
)(sc
->sc_rc_state
, m
);
1502 if (proto
== PPP_CCP
) {
1509 for (mp
= m
; mp
!= NULL
; mp
= mp
->m_next
)
1513 if (sc
->sc_flags
& SC_VJ_RESET
) {
1515 * If we've missed a packet, we must toss subsequent compressed
1516 * packets which don't have an explicit connection ID.
1519 sl_uncompress_tcp(NULL
, 0, TYPE_ERROR
, sc
->sc_comp
);
1520 s
= splhigh(); /* XXX IMP ME HARDER */
1521 sc
->sc_flags
&= ~SC_VJ_RESET
;
1526 * See if we have a VJ-compressed packet to uncompress.
1528 if (proto
== PPP_VJC_COMP
) {
1529 if ((sc
->sc_flags
& SC_REJ_COMP_TCP
) || sc
->sc_comp
== 0)
1532 xlen
= sl_uncompress_tcp_core(cp
+ PPP_HDRLEN
, m
->m_len
- PPP_HDRLEN
,
1533 ilen
- PPP_HDRLEN
, TYPE_COMPRESSED_TCP
,
1534 sc
->sc_comp
, &iphdr
, &hlen
);
1537 if (sc
->sc_flags
& SC_DEBUG
)
1538 printf("%s: VJ uncompress failed on type comp\n",
1543 /* Copy the PPP and IP headers into a new mbuf. */
1544 MGETHDR(mp
, M_DONTWAIT
, MT_DATA
);
1549 if (hlen
+ PPP_HDRLEN
> MHLEN
) {
1550 MCLGET(mp
, M_DONTWAIT
);
1551 if (M_TRAILINGSPACE(mp
) < hlen
+ PPP_HDRLEN
) {
1553 goto bad
; /* lose if big headers and no clusters */
1556 cp
= mtod(mp
, u_char
*);
1562 bcopy(iphdr
, cp
+ PPP_HDRLEN
, hlen
);
1563 mp
->m_len
= hlen
+ PPP_HDRLEN
;
1566 * Trim the PPP and VJ headers off the old mbuf
1567 * and stick the new and old mbufs together.
1569 m
->m_data
+= PPP_HDRLEN
+ xlen
;
1570 m
->m_len
-= PPP_HDRLEN
+ xlen
;
1571 if (m
->m_len
<= M_TRAILINGSPACE(mp
)) {
1572 bcopy(mtod(m
, u_char
*), mtod(mp
, u_char
*) + mp
->m_len
, m
->m_len
);
1573 mp
->m_len
+= m
->m_len
;
1574 MFREE(m
, mp
->m_next
);
1578 ilen
+= hlen
- xlen
;
1580 } else if (proto
== PPP_VJC_UNCOMP
) {
1581 if ((sc
->sc_flags
& SC_REJ_COMP_TCP
) || sc
->sc_comp
== 0)
1584 xlen
= sl_uncompress_tcp_core(cp
+ PPP_HDRLEN
, m
->m_len
- PPP_HDRLEN
,
1585 ilen
- PPP_HDRLEN
, TYPE_UNCOMPRESSED_TCP
,
1586 sc
->sc_comp
, &iphdr
, &hlen
);
1589 if (sc
->sc_flags
& SC_DEBUG
)
1590 printf("%s: VJ uncompress failed on type uncomp\n",
1601 * If the packet will fit in a header mbuf, don't waste a
1602 * whole cluster on it.
1604 if (ilen
<= MHLEN
&& M_IS_CLUSTER(m
)) {
1605 MGETHDR(mp
, M_DONTWAIT
, MT_DATA
);
1607 m_copydata(m
, 0, ilen
, mtod(mp
, void *));
1613 m
->m_pkthdr
.len
= ilen
;
1614 m
->m_pkthdr
.rcvif
= ifp
;
1616 if ((proto
& 0x8000) == 0) {
1619 * See whether we want to pass this packet, and
1620 * if it counts as link activity.
1622 if (sc
->sc_pass_filt_in
.bf_insns
!= 0
1623 && bpf_filter(sc
->sc_pass_filt_in
.bf_insns
, (u_char
*) m
,
1625 /* drop this packet */
1629 if (sc
->sc_active_filt_in
.bf_insns
== 0
1630 || bpf_filter(sc
->sc_active_filt_in
.bf_insns
, (u_char
*) m
,
1632 sc
->sc_last_recv
= time_second
;
1635 * Record the time that we received this packet.
1637 sc
->sc_last_recv
= time_second
;
1638 #endif /* PPP_FILTER */
1642 /* See if bpf wants to look at the packet. */
1643 if (sc
->sc_if
.if_bpf
)
1644 bpf_mtap(sc
->sc_if
.if_bpf
, m
);
1652 * IP packet - take off the ppp header and pass it up to IP.
1654 if ((ifp
->if_flags
& IFF_UP
) == 0
1655 || sc
->sc_npmode
[NP_IP
] != NPMODE_PASS
) {
1656 /* interface is down - drop the packet. */
1660 m
->m_pkthdr
.len
-= PPP_HDRLEN
;
1661 m
->m_data
+= PPP_HDRLEN
;
1662 m
->m_len
-= PPP_HDRLEN
;
1664 if (ipflow_fastforward(m
))
1667 schednetisr(NETISR_IP
);
1675 * IPv6 packet - take off the ppp header and pass it up to IPv6.
1677 if ((ifp
->if_flags
& IFF_UP
) == 0
1678 || sc
->sc_npmode
[NP_IPV6
] != NPMODE_PASS
) {
1679 /* interface is down - drop the packet. */
1683 m
->m_pkthdr
.len
-= PPP_HDRLEN
;
1684 m
->m_data
+= PPP_HDRLEN
;
1685 m
->m_len
-= PPP_HDRLEN
;
1687 if (ip6flow_fastforward(m
))
1690 schednetisr(NETISR_IPV6
);
1697 * Some other protocol - place on input queue for read().
1705 * Put the packet on the appropriate input queue.
1708 if (IF_QFULL(inq
)) {
1711 if (sc
->sc_flags
& SC_DEBUG
)
1712 printf("%s: input queue full\n", ifp
->if_xname
);
1719 ifp
->if_ibytes
+= ilen
;
1728 sc
->sc_if
.if_ierrors
++;
1729 sc
->sc_stats
.ppp_ierrors
++;
1732 #define MAX_DUMP_BYTES 128
1735 pppdumpm(struct mbuf
*m0
)
1737 char buf
[3*MAX_DUMP_BYTES
+4];
1741 for (m
= m0
; m
; m
= m
->m_next
) {
1743 u_char
*rptr
= (u_char
*)m
->m_data
;
1746 if (bp
> buf
+ sizeof(buf
) - 4)
1748 *bp
++ = hexdigits
[*rptr
>> 4]; /* convert byte to ascii hex */
1749 *bp
++ = hexdigits
[*rptr
++ & 0xf];
1753 if (bp
> buf
+ sizeof(buf
) - 3)
1763 printf("%s\n", buf
);
1768 * a wrapper to transmit a packet from if_start since ALTQ uses
1769 * if_start to send a packet.
1772 ppp_ifstart(struct ifnet
*ifp
)
1774 struct ppp_softc
*sc
;
1777 (*sc
->sc_start
)(sc
);
1781 static const struct ppp_known_compressor
{
1784 } ppp_known_compressors
[] = {
1785 { CI_DEFLATE
, "ppp_deflate" },
1786 { CI_DEFLATE_DRAFT
, "ppp_deflate" },
1787 { CI_BSD_COMPRESS
, "ppp_bsdcomp" },
1788 { CI_MPPE
, "ppp_mppe" },
1793 ppp_compressor_init(void)
1796 mutex_init(&ppp_compressors_mtx
, MUTEX_DEFAULT
, IPL_NONE
);
1801 ppp_compressor_rele(struct compressor
*cp
)
1804 mutex_enter(&ppp_compressors_mtx
);
1806 mutex_exit(&ppp_compressors_mtx
);
1809 static struct compressor
*
1810 ppp_get_compressor_noload(uint8_t ci
, bool hold
)
1812 struct compressor
*cp
;
1814 KASSERT(mutex_owned(&ppp_compressors_mtx
));
1815 LIST_FOREACH(cp
, &ppp_compressors
, comp_list
) {
1816 if (cp
->compress_proto
== ci
) {
1826 static struct compressor
*
1827 ppp_get_compressor(uint8_t ci
)
1829 struct compressor
*cp
= NULL
;
1830 const struct ppp_known_compressor
*pkc
;
1832 mutex_enter(&ppp_compressors_mtx
);
1833 cp
= ppp_get_compressor_noload(ci
, true);
1834 mutex_exit(&ppp_compressors_mtx
);
1838 mutex_enter(&module_lock
);
1839 mutex_enter(&ppp_compressors_mtx
);
1840 cp
= ppp_get_compressor_noload(ci
, true);
1841 mutex_exit(&ppp_compressors_mtx
);
1843 /* Not found, so try to autoload a module */
1844 for (pkc
= ppp_known_compressors
; pkc
->module
!= NULL
; pkc
++) {
1845 if (pkc
->code
== ci
) {
1846 if (module_autoload(pkc
->module
,
1847 MODULE_CLASS_MISC
) != 0)
1849 mutex_enter(&ppp_compressors_mtx
);
1850 cp
= ppp_get_compressor_noload(ci
, true);
1851 mutex_exit(&ppp_compressors_mtx
);
1856 mutex_exit(&module_lock
);
1862 ppp_register_compressor(struct compressor
*pc
, size_t ncomp
)
1867 RUN_ONCE(&ppp_compressor_mtx_init
, ppp_compressor_init
);
1869 mutex_enter(&ppp_compressors_mtx
);
1870 for (i
= 0; i
< ncomp
; i
++) {
1871 if (ppp_get_compressor_noload(pc
[i
].compress_proto
,
1876 for (i
= 0; i
< ncomp
; i
++) {
1877 pc
[i
].comp_refcnt
= 0;
1878 LIST_INSERT_HEAD(&ppp_compressors
, &pc
[i
], comp_list
);
1881 mutex_exit(&ppp_compressors_mtx
);
1887 ppp_unregister_compressor(struct compressor
*pc
, size_t ncomp
)
1892 mutex_enter(&ppp_compressors_mtx
);
1893 for (i
= 0; i
< ncomp
; i
++) {
1894 if (ppp_get_compressor_noload(pc
[i
].compress_proto
,
1897 else if (pc
[i
].comp_refcnt
!= 0)
1901 for (i
= 0; i
< ncomp
; i
++) {
1902 LIST_REMOVE(&pc
[i
], comp_list
);
1905 mutex_exit(&ppp_compressors_mtx
);