1994-09-23 00:10:32 +00:00
|
|
|
/*
|
|
|
|
* if_ppp.c - Point-to-Point Protocol (PPP) Asynchronous driver.
|
|
|
|
*
|
|
|
|
* Copyright (c) 1989 Carnegie Mellon University.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms are permitted
|
|
|
|
* provided that the above copyright notice and this paragraph are
|
|
|
|
* duplicated in all such forms and that any documentation,
|
|
|
|
* advertising materials, and other materials related to such
|
|
|
|
* distribution and use acknowledge that the software was developed
|
|
|
|
* by Carnegie Mellon University. The name of the
|
|
|
|
* University may not be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
*
|
|
|
|
* Drew D. Perkins
|
|
|
|
* Carnegie Mellon University
|
|
|
|
* 4910 Forbes Ave.
|
|
|
|
* Pittsburgh, PA 15213
|
|
|
|
* (412) 268-8576
|
|
|
|
* ddp@andrew.cmu.edu
|
|
|
|
*
|
|
|
|
* Based on:
|
|
|
|
* @(#)if_sl.c 7.6.1.2 (Berkeley) 2/15/89
|
|
|
|
*
|
|
|
|
* Copyright (c) 1987 Regents of the University of California.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms are permitted
|
|
|
|
* provided that the above copyright notice and this paragraph are
|
|
|
|
* duplicated in all such forms and that any documentation,
|
|
|
|
* advertising materials, and other materials related to such
|
|
|
|
* distribution and use acknowledge that the software was developed
|
|
|
|
* by the University of California, Berkeley. The name of the
|
|
|
|
* University may not be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
*
|
|
|
|
* Serial Line interface
|
|
|
|
*
|
|
|
|
* Rick Adams
|
|
|
|
* Center for Seismic Studies
|
|
|
|
* 1300 N 17th Street, Suite 1450
|
|
|
|
* Arlington, Virginia 22209
|
|
|
|
* (703)276-7900
|
|
|
|
* rick@seismo.ARPA
|
|
|
|
* seismo!rick
|
|
|
|
*
|
|
|
|
* Pounded on heavily by Chris Torek (chris@mimsy.umd.edu, umcp-cs!chris).
|
|
|
|
* Converted to 4.3BSD Beta by Chris Torek.
|
|
|
|
* Other changes made at Berkeley, based in part on code by Kirk Smith.
|
|
|
|
*
|
|
|
|
* Converted to 4.3BSD+ 386BSD by Brad Parker (brad@cayman.com)
|
|
|
|
* Added VJ tcp header compression; more unified ioctls
|
|
|
|
*
|
|
|
|
* Extensively modified by Paul Mackerras (paulus@cs.anu.edu.au).
|
|
|
|
* Cleaned up a lot of the mbuf-related code to fix bugs that
|
|
|
|
* caused system crashes and packet corruption. Changed pppstart
|
|
|
|
* so that it doesn't just give up with a collision if the whole
|
|
|
|
* packet doesn't fit in the output ring buffer.
|
|
|
|
*
|
|
|
|
* Added priority queueing for interactive IP packets, following
|
|
|
|
* the model of if_sl.c, plus hooks for bpf.
|
|
|
|
* Paul Mackerras (paulus@cs.anu.edu.au).
|
|
|
|
*/
|
|
|
|
|
1999-08-28 01:08:13 +00:00
|
|
|
/* $FreeBSD$ */
|
1994-09-23 00:10:32 +00:00
|
|
|
/* from if_sl.c,v 1.11 84/10/04 12:54:47 rick Exp */
|
1997-08-19 14:10:50 +00:00
|
|
|
/* from NetBSD: if_ppp.c,v 1.15.2.2 1994/07/28 05:17:58 cgd Exp */
|
1994-09-23 00:10:32 +00:00
|
|
|
|
1998-01-08 23:42:31 +00:00
|
|
|
#include "opt_inet.h"
|
1997-12-15 20:31:25 +00:00
|
|
|
#include "opt_ipx.h"
|
2002-08-01 21:13:47 +00:00
|
|
|
#include "opt_mac.h"
|
1998-01-08 23:42:31 +00:00
|
|
|
#include "opt_ppp.h"
|
1997-08-19 17:05:26 +00:00
|
|
|
|
1998-01-08 23:42:31 +00:00
|
|
|
#ifdef INET
|
1994-09-23 00:10:32 +00:00
|
|
|
#define VJC
|
1998-01-08 23:42:31 +00:00
|
|
|
#endif
|
1997-10-10 11:57:43 +00:00
|
|
|
#define PPP_COMPRESS
|
1997-10-18 00:56:23 +00:00
|
|
|
|
1994-09-23 00:10:32 +00:00
|
|
|
#include <sys/param.h>
|
1994-09-23 00:13:22 +00:00
|
|
|
#include <sys/systm.h>
|
1994-09-23 00:10:32 +00:00
|
|
|
#include <sys/proc.h>
|
2002-08-15 19:02:17 +00:00
|
|
|
#include <sys/mac.h>
|
1994-09-23 00:10:32 +00:00
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/socket.h>
|
1997-03-24 11:52:29 +00:00
|
|
|
#include <sys/filio.h>
|
|
|
|
#include <sys/sockio.h>
|
1994-09-23 00:13:22 +00:00
|
|
|
#include <sys/kernel.h>
|
1997-08-19 14:10:50 +00:00
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/malloc.h>
|
2001-01-31 07:58:58 +00:00
|
|
|
#include <sys/module.h>
|
1994-09-23 00:10:32 +00:00
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_types.h>
|
|
|
|
#include <net/netisr.h>
|
1999-09-26 18:44:29 +00:00
|
|
|
#include <net/bpf.h>
|
1994-09-23 00:10:32 +00:00
|
|
|
|
|
|
|
#if INET
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/in_var.h>
|
|
|
|
#include <netinet/ip.h>
|
|
|
|
#endif
|
|
|
|
|
1995-11-13 22:09:39 +00:00
|
|
|
#if IPX
|
|
|
|
#include <netipx/ipx.h>
|
|
|
|
#include <netipx/ipx_if.h>
|
|
|
|
#endif
|
|
|
|
|
1994-09-23 00:10:32 +00:00
|
|
|
#ifdef VJC
|
1995-10-31 20:24:14 +00:00
|
|
|
#include <net/slcompress.h>
|
1994-09-23 00:10:32 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <net/if_ppp.h>
|
1995-10-31 20:24:14 +00:00
|
|
|
#include <net/if_pppvar.h>
|
1997-08-19 14:10:50 +00:00
|
|
|
|
|
|
|
/* minimise diffs */
|
1998-06-07 17:13:14 +00:00
|
|
|
#ifndef splsoftnet
|
1997-08-19 14:10:50 +00:00
|
|
|
#define splsoftnet splnet
|
1998-06-07 17:13:14 +00:00
|
|
|
#endif
|
1994-09-23 00:10:32 +00:00
|
|
|
|
1995-10-31 20:24:14 +00:00
|
|
|
#ifdef PPP_COMPRESS
|
|
|
|
#define PACKETPTR struct mbuf *
|
|
|
|
#include <net/ppp_comp.h>
|
|
|
|
#endif
|
|
|
|
|
2002-08-09 15:30:48 +00:00
|
|
|
#define PPPNAME "ppp"
|
|
|
|
static MALLOC_DEFINE(M_PPP, PPPNAME, "PPP interface");
|
|
|
|
static LIST_HEAD(, ppp_softc) ppp_softc_list;
|
1996-04-13 12:45:57 +00:00
|
|
|
|
1997-05-31 10:13:46 +00:00
|
|
|
/* XXX layering violation */
|
2002-03-19 21:54:18 +00:00
|
|
|
extern void pppasyncattach(void *);
|
2002-08-09 15:30:48 +00:00
|
|
|
extern void pppasyncdetach(void);
|
1997-05-31 10:13:46 +00:00
|
|
|
|
2002-03-19 21:54:18 +00:00
|
|
|
static int pppsioctl(struct ifnet *ifp, u_long cmd, caddr_t data);
|
|
|
|
static void pppintr(void);
|
1994-10-05 21:22:45 +00:00
|
|
|
|
2002-03-19 21:54:18 +00:00
|
|
|
static void ppp_requeue(struct ppp_softc *);
|
|
|
|
static void ppp_ccp(struct ppp_softc *, struct mbuf *m, int rcvd);
|
|
|
|
static void ppp_ccp_closed(struct ppp_softc *);
|
|
|
|
static void ppp_inproc(struct ppp_softc *, struct mbuf *);
|
|
|
|
static void pppdumpm(struct mbuf *m0);
|
2002-08-09 15:30:48 +00:00
|
|
|
static int ppp_clone_create(struct if_clone *, int);
|
|
|
|
static void ppp_clone_destroy(struct ifnet *);
|
|
|
|
|
|
|
|
static struct if_clone ppp_cloner = IF_CLONE_INITIALIZER(PPPNAME,
|
|
|
|
ppp_clone_create, ppp_clone_destroy, 0, IF_MAXUNIT);
|
1995-10-05 00:33:27 +00:00
|
|
|
|
1994-09-23 00:10:32 +00:00
|
|
|
/*
|
|
|
|
* Some useful mbuf macros not in mbuf.h.
|
|
|
|
*/
|
1995-10-31 20:24:14 +00:00
|
|
|
#define M_IS_CLUSTER(m) ((m)->m_flags & M_EXT)
|
|
|
|
|
1994-09-23 00:10:32 +00:00
|
|
|
#define M_DATASTART(m) \
|
1995-10-31 20:24:14 +00:00
|
|
|
(M_IS_CLUSTER(m) ? (m)->m_ext.ext_buf : \
|
1994-09-23 00:10:32 +00:00
|
|
|
(m)->m_flags & M_PKTHDR ? (m)->m_pktdat : (m)->m_dat)
|
|
|
|
|
|
|
|
#define M_DATASIZE(m) \
|
1995-10-31 20:24:14 +00:00
|
|
|
(M_IS_CLUSTER(m) ? (m)->m_ext.ext_size : \
|
1994-09-23 00:10:32 +00:00
|
|
|
(m)->m_flags & M_PKTHDR ? MHLEN: MLEN)
|
|
|
|
|
|
|
|
/*
|
1995-10-31 20:24:14 +00:00
|
|
|
* We steal two bits in the mbuf m_flags, to mark high-priority packets
|
|
|
|
* for output, and received packets following lost/corrupted packets.
|
1994-09-23 00:10:32 +00:00
|
|
|
*/
|
1995-10-31 20:24:14 +00:00
|
|
|
#define M_HIGHPRI 0x2000 /* output packet for sc_fastq */
|
|
|
|
#define M_ERRMARK 0x4000 /* steal a bit in mbuf m_flags */
|
|
|
|
|
1994-09-23 00:10:32 +00:00
|
|
|
|
1995-10-31 20:24:14 +00:00
|
|
|
#ifdef PPP_COMPRESS
|
1994-09-23 00:10:32 +00:00
|
|
|
/*
|
1995-10-31 20:24:14 +00:00
|
|
|
* List of compressors we know about.
|
|
|
|
* We leave some space so maybe we can modload compressors.
|
1994-09-23 00:10:32 +00:00
|
|
|
*/
|
1995-10-31 20:24:14 +00:00
|
|
|
|
|
|
|
extern struct compressor ppp_bsd_compress;
|
1998-06-20 16:28:04 +00:00
|
|
|
extern struct compressor ppp_deflate, ppp_deflate_draft;
|
1995-10-31 20:24:14 +00:00
|
|
|
|
1995-12-14 09:55:16 +00:00
|
|
|
static struct compressor *ppp_compressors[8] = {
|
1997-08-19 17:05:26 +00:00
|
|
|
#if DO_BSD_COMPRESS && defined(PPP_BSDCOMP)
|
1995-10-31 20:24:14 +00:00
|
|
|
&ppp_bsd_compress,
|
1997-08-19 14:10:50 +00:00
|
|
|
#endif
|
1997-08-19 17:05:26 +00:00
|
|
|
#if DO_DEFLATE && defined(PPP_DEFLATE)
|
1997-08-19 14:10:50 +00:00
|
|
|
&ppp_deflate,
|
1998-06-20 16:28:04 +00:00
|
|
|
&ppp_deflate_draft,
|
1995-10-31 20:24:14 +00:00
|
|
|
#endif
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
#endif /* PPP_COMPRESS */
|
1994-09-23 00:10:32 +00:00
|
|
|
|
2002-08-09 15:30:48 +00:00
|
|
|
static int
|
|
|
|
ppp_clone_create(struct if_clone *ifc, int unit)
|
1994-09-23 00:10:32 +00:00
|
|
|
{
|
2002-08-09 15:30:48 +00:00
|
|
|
struct ppp_softc *sc;
|
1994-09-23 00:10:32 +00:00
|
|
|
|
2003-02-19 05:47:46 +00:00
|
|
|
sc = malloc(sizeof(struct ppp_softc), M_PPP, M_WAITOK | M_ZERO);
|
2002-08-09 15:30:48 +00:00
|
|
|
sc->sc_if.if_softc = sc;
|
2003-10-31 18:32:15 +00:00
|
|
|
if_initname(&sc->sc_if, ifc->ifc_name, unit);
|
1994-09-23 00:10:32 +00:00
|
|
|
sc->sc_if.if_mtu = PPP_MTU;
|
1995-06-11 19:33:05 +00:00
|
|
|
sc->sc_if.if_flags = IFF_POINTOPOINT | IFF_MULTICAST;
|
1994-09-23 00:10:32 +00:00
|
|
|
sc->sc_if.if_type = IFT_PPP;
|
|
|
|
sc->sc_if.if_hdrlen = PPP_HDRLEN;
|
1995-10-31 20:24:14 +00:00
|
|
|
sc->sc_if.if_ioctl = pppsioctl;
|
1994-09-23 00:10:32 +00:00
|
|
|
sc->sc_if.if_output = pppoutput;
|
|
|
|
sc->sc_if.if_snd.ifq_maxlen = IFQ_MAXLEN;
|
|
|
|
sc->sc_inq.ifq_maxlen = IFQ_MAXLEN;
|
|
|
|
sc->sc_fastq.ifq_maxlen = IFQ_MAXLEN;
|
1995-10-31 20:24:14 +00:00
|
|
|
sc->sc_rawq.ifq_maxlen = IFQ_MAXLEN;
|
2002-08-09 15:30:48 +00:00
|
|
|
mtx_init(&sc->sc_inq.ifq_mtx, "ppp_inq", NULL, MTX_DEF);
|
|
|
|
mtx_init(&sc->sc_fastq.ifq_mtx, "ppp_fastq", NULL, MTX_DEF);
|
|
|
|
mtx_init(&sc->sc_rawq.ifq_mtx, "ppp_rawq", NULL, MTX_DEF);
|
1994-09-23 00:10:32 +00:00
|
|
|
if_attach(&sc->sc_if);
|
1996-02-06 18:51:28 +00:00
|
|
|
bpfattach(&sc->sc_if, DLT_PPP, PPP_HDRLEN);
|
2002-08-09 15:30:48 +00:00
|
|
|
LIST_INSERT_HEAD(&ppp_softc_list, sc, sc_list);
|
|
|
|
|
2002-08-19 19:22:41 +00:00
|
|
|
return (0);
|
2002-08-09 15:30:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ppp_clone_destroy(struct ifnet *ifp)
|
|
|
|
{
|
|
|
|
struct ppp_softc *sc;
|
|
|
|
|
|
|
|
sc = ifp->if_softc;
|
|
|
|
|
|
|
|
LIST_REMOVE(sc, sc_list);
|
|
|
|
bpfdetach(ifp);
|
|
|
|
if_detach(ifp);
|
|
|
|
mtx_destroy(&sc->sc_rawq.ifq_mtx);
|
|
|
|
mtx_destroy(&sc->sc_fastq.ifq_mtx);
|
|
|
|
mtx_destroy(&sc->sc_inq.ifq_mtx);
|
2004-01-21 18:05:38 +00:00
|
|
|
|
|
|
|
free(sc, M_PPP);
|
1994-09-23 00:10:32 +00:00
|
|
|
}
|
|
|
|
|
2001-01-31 07:58:58 +00:00
|
|
|
static int
|
|
|
|
ppp_modevent(module_t mod, int type, void *data)
|
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case MOD_LOAD:
|
2004-01-21 18:05:38 +00:00
|
|
|
LIST_INIT(&ppp_softc_list);
|
2002-08-09 15:30:48 +00:00
|
|
|
if_clone_attach(&ppp_cloner);
|
|
|
|
|
2003-11-08 22:28:40 +00:00
|
|
|
netisr_register(NETISR_PPP, (netisr_t *)pppintr, NULL, 0);
|
2002-08-09 15:30:48 +00:00
|
|
|
/*
|
|
|
|
* XXX layering violation - if_ppp can work over any lower
|
|
|
|
* level transport that cares to attach to it.
|
|
|
|
*/
|
|
|
|
pppasyncattach(NULL);
|
2001-01-31 07:58:58 +00:00
|
|
|
break;
|
|
|
|
case MOD_UNLOAD:
|
2002-08-09 15:30:48 +00:00
|
|
|
/* XXX: layering violation */
|
|
|
|
pppasyncdetach();
|
|
|
|
|
2003-03-04 23:19:55 +00:00
|
|
|
netisr_unregister(NETISR_PPP);
|
2002-08-09 15:30:48 +00:00
|
|
|
|
|
|
|
if_clone_detach(&ppp_cloner);
|
|
|
|
|
|
|
|
while (!LIST_EMPTY(&ppp_softc_list))
|
|
|
|
ppp_clone_destroy(
|
|
|
|
&LIST_FIRST(&ppp_softc_list)->sc_if);
|
2002-08-19 19:22:41 +00:00
|
|
|
break;
|
2001-01-31 07:58:58 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static moduledata_t ppp_mod = {
|
|
|
|
"if_ppp",
|
|
|
|
ppp_modevent,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
DECLARE_MODULE(if_ppp, ppp_mod, SI_SUB_PSEUDO, SI_ORDER_ANY);
|
|
|
|
|
1994-09-23 00:10:32 +00:00
|
|
|
/*
|
|
|
|
* Allocate a ppp interface unit and initialize it.
|
|
|
|
*/
|
|
|
|
struct ppp_softc *
|
|
|
|
pppalloc(pid)
|
|
|
|
pid_t pid;
|
|
|
|
{
|
2002-08-09 15:30:48 +00:00
|
|
|
int i;
|
|
|
|
char tmpname[IFNAMSIZ];
|
|
|
|
struct ifnet *ifp;
|
1994-09-23 00:10:32 +00:00
|
|
|
struct ppp_softc *sc;
|
|
|
|
|
2002-08-09 15:30:48 +00:00
|
|
|
LIST_FOREACH(sc, &ppp_softc_list, sc_list) {
|
1994-09-23 00:10:32 +00:00
|
|
|
if (sc->sc_xfer == pid) {
|
|
|
|
sc->sc_xfer = 0;
|
1995-10-31 20:24:14 +00:00
|
|
|
return sc;
|
1994-09-23 00:10:32 +00:00
|
|
|
}
|
2002-08-09 15:30:48 +00:00
|
|
|
}
|
|
|
|
LIST_FOREACH(sc, &ppp_softc_list, sc_list) {
|
1995-10-31 20:24:14 +00:00
|
|
|
if (sc->sc_devp == NULL)
|
|
|
|
break;
|
2002-08-09 15:30:48 +00:00
|
|
|
}
|
|
|
|
/* Try to clone an interface if we don't have a free one */
|
|
|
|
if (sc == NULL) {
|
|
|
|
strcpy(tmpname, PPPNAME);
|
|
|
|
if (if_clone_create(tmpname, sizeof(tmpname)) != 0)
|
|
|
|
return NULL;
|
|
|
|
ifp = ifunit(tmpname);
|
|
|
|
if (ifp == NULL)
|
|
|
|
return NULL;
|
|
|
|
sc = ifp->if_softc;
|
|
|
|
}
|
|
|
|
if (sc == NULL || sc->sc_devp != NULL)
|
1994-09-23 00:10:32 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
sc->sc_flags = 0;
|
|
|
|
sc->sc_mru = PPP_MRU;
|
1995-10-31 20:24:14 +00:00
|
|
|
sc->sc_relinq = NULL;
|
1997-08-19 14:10:50 +00:00
|
|
|
bzero((char *)&sc->sc_stats, sizeof(sc->sc_stats));
|
1994-09-23 00:10:32 +00:00
|
|
|
#ifdef VJC
|
1997-08-19 14:10:50 +00:00
|
|
|
MALLOC(sc->sc_comp, struct slcompress *, sizeof(struct slcompress),
|
|
|
|
M_DEVBUF, M_NOWAIT);
|
|
|
|
if (sc->sc_comp)
|
|
|
|
sl_compress_init(sc->sc_comp, -1);
|
1994-09-23 00:10:32 +00:00
|
|
|
#endif
|
1995-10-31 20:24:14 +00:00
|
|
|
#ifdef PPP_COMPRESS
|
|
|
|
sc->sc_xc_state = NULL;
|
|
|
|
sc->sc_rc_state = NULL;
|
|
|
|
#endif /* PPP_COMPRESS */
|
|
|
|
for (i = 0; i < NUM_NP; ++i)
|
|
|
|
sc->sc_npmode[i] = NPMODE_ERROR;
|
|
|
|
sc->sc_npqueue = NULL;
|
|
|
|
sc->sc_npqtail = &sc->sc_npqueue;
|
1998-03-30 09:56:58 +00:00
|
|
|
sc->sc_last_sent = sc->sc_last_recv = time_second;
|
1994-09-23 00:10:32 +00:00
|
|
|
|
|
|
|
return sc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1997-08-19 14:10:50 +00:00
|
|
|
* Deallocate a ppp unit. Must be called at splsoftnet or higher.
|
1994-09-23 00:10:32 +00:00
|
|
|
*/
|
1994-09-23 00:13:22 +00:00
|
|
|
void
|
1994-09-23 00:10:32 +00:00
|
|
|
pppdealloc(sc)
|
1995-10-31 20:24:14 +00:00
|
|
|
struct ppp_softc *sc;
|
1994-09-23 00:10:32 +00:00
|
|
|
{
|
|
|
|
struct mbuf *m;
|
|
|
|
|
|
|
|
if_down(&sc->sc_if);
|
1995-10-31 20:24:14 +00:00
|
|
|
sc->sc_if.if_flags &= ~(IFF_UP|IFF_RUNNING);
|
1998-04-06 11:43:12 +00:00
|
|
|
getmicrotime(&sc->sc_if.if_lastchange);
|
1994-09-23 00:10:32 +00:00
|
|
|
sc->sc_devp = NULL;
|
|
|
|
sc->sc_xfer = 0;
|
Lock down the network interface queues. The queue mutex must be obtained
before adding/removing packets from the queue. Also, the if_obytes and
if_omcasts fields should only be manipulated under protection of the mutex.
IF_ENQUEUE, IF_PREPEND, and IF_DEQUEUE perform all necessary locking on
the queue. An IF_LOCK macro is provided, as well as the old (mutex-less)
versions of the macros in the form _IF_ENQUEUE, _IF_QFULL, for code which
needs them, but their use is discouraged.
Two new macros are introduced: IF_DRAIN() to drain a queue, and IF_HANDOFF,
which takes care of locking/enqueue, and also statistics updating/start
if necessary.
2000-11-25 07:35:38 +00:00
|
|
|
IF_DRAIN(&sc->sc_rawq);
|
|
|
|
IF_DRAIN(&sc->sc_inq);
|
|
|
|
IF_DRAIN(&sc->sc_fastq);
|
1995-10-31 20:24:14 +00:00
|
|
|
while ((m = sc->sc_npqueue) != NULL) {
|
|
|
|
sc->sc_npqueue = m->m_nextpkt;
|
|
|
|
m_freem(m);
|
1994-09-23 00:10:32 +00:00
|
|
|
}
|
1995-10-31 20:24:14 +00:00
|
|
|
#ifdef PPP_COMPRESS
|
|
|
|
ppp_ccp_closed(sc);
|
|
|
|
sc->sc_xc_state = NULL;
|
|
|
|
sc->sc_rc_state = NULL;
|
|
|
|
#endif /* PPP_COMPRESS */
|
1997-10-18 00:46:10 +00:00
|
|
|
#ifdef PPP_FILTER
|
1997-08-19 14:10:50 +00:00
|
|
|
if (sc->sc_pass_filt.bf_insns != 0) {
|
2002-04-04 06:03:17 +00:00
|
|
|
free(sc->sc_pass_filt.bf_insns, M_DEVBUF);
|
1997-08-19 14:10:50 +00:00
|
|
|
sc->sc_pass_filt.bf_insns = 0;
|
|
|
|
sc->sc_pass_filt.bf_len = 0;
|
|
|
|
}
|
|
|
|
if (sc->sc_active_filt.bf_insns != 0) {
|
2002-04-04 06:03:17 +00:00
|
|
|
free(sc->sc_active_filt.bf_insns, M_DEVBUF);
|
1997-08-19 14:10:50 +00:00
|
|
|
sc->sc_active_filt.bf_insns = 0;
|
|
|
|
sc->sc_active_filt.bf_len = 0;
|
|
|
|
}
|
1997-10-18 00:46:10 +00:00
|
|
|
#endif /* PPP_FILTER */
|
1997-08-19 14:10:50 +00:00
|
|
|
#ifdef VJC
|
|
|
|
if (sc->sc_comp != 0) {
|
2002-04-04 06:03:17 +00:00
|
|
|
free(sc->sc_comp, M_DEVBUF);
|
1997-08-19 14:10:50 +00:00
|
|
|
sc->sc_comp = 0;
|
|
|
|
}
|
|
|
|
#endif
|
1994-09-23 00:10:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1995-10-31 20:24:14 +00:00
|
|
|
* Ioctl routine for generic ppp devices.
|
1994-09-23 00:10:32 +00:00
|
|
|
*/
|
|
|
|
int
|
2001-09-12 08:38:13 +00:00
|
|
|
pppioctl(sc, cmd, data, flag, td)
|
1995-10-31 20:24:14 +00:00
|
|
|
struct ppp_softc *sc;
|
1998-06-07 17:13:14 +00:00
|
|
|
u_long cmd;
|
1994-09-23 00:10:32 +00:00
|
|
|
caddr_t data;
|
1997-08-19 14:10:50 +00:00
|
|
|
int flag;
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *td;
|
1994-09-23 00:10:32 +00:00
|
|
|
{
|
2001-09-12 08:38:13 +00:00
|
|
|
struct proc *p = td->td_proc;
|
2001-09-10 11:28:07 +00:00
|
|
|
int s, flags, mru, npx;
|
|
|
|
u_int nb;
|
Lock down the network interface queues. The queue mutex must be obtained
before adding/removing packets from the queue. Also, the if_obytes and
if_omcasts fields should only be manipulated under protection of the mutex.
IF_ENQUEUE, IF_PREPEND, and IF_DEQUEUE perform all necessary locking on
the queue. An IF_LOCK macro is provided, as well as the old (mutex-less)
versions of the macros in the form _IF_ENQUEUE, _IF_QFULL, for code which
needs them, but their use is discouraged.
Two new macros are introduced: IF_DRAIN() to drain a queue, and IF_HANDOFF,
which takes care of locking/enqueue, and also statistics updating/start
if necessary.
2000-11-25 07:35:38 +00:00
|
|
|
int error = 0;
|
1995-10-31 20:24:14 +00:00
|
|
|
struct ppp_option_data *odp;
|
|
|
|
struct compressor **cp;
|
|
|
|
struct npioctl *npi;
|
|
|
|
time_t t;
|
1997-10-18 00:46:10 +00:00
|
|
|
#ifdef PPP_FILTER
|
1997-08-19 14:10:50 +00:00
|
|
|
struct bpf_program *bp, *nbp;
|
|
|
|
struct bpf_insn *newcode, *oldcode;
|
|
|
|
int newcodelen;
|
1997-10-18 00:46:10 +00:00
|
|
|
#endif /* PPP_FILTER */
|
1995-10-31 20:24:14 +00:00
|
|
|
#ifdef PPP_COMPRESS
|
|
|
|
u_char ccp_option[CCP_MAX_OPTION_LENGTH];
|
|
|
|
#endif
|
1994-09-23 00:10:32 +00:00
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case FIONREAD:
|
|
|
|
*(int *)data = sc->sc_inq.ifq_len;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PPPIOCGUNIT:
|
2003-10-31 18:32:15 +00:00
|
|
|
*(int *)data = sc->sc_if.if_dunit;
|
1994-09-23 00:10:32 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PPPIOCGFLAGS:
|
|
|
|
*(u_int *)data = sc->sc_flags;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PPPIOCSFLAGS:
|
2002-04-01 21:31:13 +00:00
|
|
|
if ((error = suser(td)) != 0)
|
Lock down the network interface queues. The queue mutex must be obtained
before adding/removing packets from the queue. Also, the if_obytes and
if_omcasts fields should only be manipulated under protection of the mutex.
IF_ENQUEUE, IF_PREPEND, and IF_DEQUEUE perform all necessary locking on
the queue. An IF_LOCK macro is provided, as well as the old (mutex-less)
versions of the macros in the form _IF_ENQUEUE, _IF_QFULL, for code which
needs them, but their use is discouraged.
Two new macros are introduced: IF_DRAIN() to drain a queue, and IF_HANDOFF,
which takes care of locking/enqueue, and also statistics updating/start
if necessary.
2000-11-25 07:35:38 +00:00
|
|
|
break;
|
1994-09-23 00:10:32 +00:00
|
|
|
flags = *(int *)data & SC_MASK;
|
1997-08-19 14:10:50 +00:00
|
|
|
s = splsoftnet();
|
1995-10-31 20:24:14 +00:00
|
|
|
#ifdef PPP_COMPRESS
|
|
|
|
if (sc->sc_flags & SC_CCP_OPEN && !(flags & SC_CCP_OPEN))
|
|
|
|
ppp_ccp_closed(sc);
|
|
|
|
#endif
|
|
|
|
splimp();
|
1994-09-23 00:10:32 +00:00
|
|
|
sc->sc_flags = (sc->sc_flags & ~SC_MASK) | flags;
|
|
|
|
splx(s);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PPPIOCSMRU:
|
2002-04-01 21:31:13 +00:00
|
|
|
if ((error = suser(td)) != 0)
|
1994-09-23 00:10:32 +00:00
|
|
|
return (error);
|
|
|
|
mru = *(int *)data;
|
1995-10-31 20:24:14 +00:00
|
|
|
if (mru >= PPP_MRU && mru <= PPP_MAXMRU)
|
1994-09-23 00:10:32 +00:00
|
|
|
sc->sc_mru = mru;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PPPIOCGMRU:
|
|
|
|
*(int *)data = sc->sc_mru;
|
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef VJC
|
|
|
|
case PPPIOCSMAXCID:
|
2002-04-01 21:31:13 +00:00
|
|
|
if ((error = suser(td)) != 0)
|
Lock down the network interface queues. The queue mutex must be obtained
before adding/removing packets from the queue. Also, the if_obytes and
if_omcasts fields should only be manipulated under protection of the mutex.
IF_ENQUEUE, IF_PREPEND, and IF_DEQUEUE perform all necessary locking on
the queue. An IF_LOCK macro is provided, as well as the old (mutex-less)
versions of the macros in the form _IF_ENQUEUE, _IF_QFULL, for code which
needs them, but their use is discouraged.
Two new macros are introduced: IF_DRAIN() to drain a queue, and IF_HANDOFF,
which takes care of locking/enqueue, and also statistics updating/start
if necessary.
2000-11-25 07:35:38 +00:00
|
|
|
break;
|
1997-08-19 14:10:50 +00:00
|
|
|
if (sc->sc_comp) {
|
|
|
|
s = splsoftnet();
|
|
|
|
sl_compress_init(sc->sc_comp, *(int *)data);
|
|
|
|
splx(s);
|
|
|
|
}
|
1994-09-23 00:10:32 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
case PPPIOCXFERUNIT:
|
2002-04-01 21:31:13 +00:00
|
|
|
if ((error = suser(td)) != 0)
|
Lock down the network interface queues. The queue mutex must be obtained
before adding/removing packets from the queue. Also, the if_obytes and
if_omcasts fields should only be manipulated under protection of the mutex.
IF_ENQUEUE, IF_PREPEND, and IF_DEQUEUE perform all necessary locking on
the queue. An IF_LOCK macro is provided, as well as the old (mutex-less)
versions of the macros in the form _IF_ENQUEUE, _IF_QFULL, for code which
needs them, but their use is discouraged.
Two new macros are introduced: IF_DRAIN() to drain a queue, and IF_HANDOFF,
which takes care of locking/enqueue, and also statistics updating/start
if necessary.
2000-11-25 07:35:38 +00:00
|
|
|
break;
|
1994-09-23 00:10:32 +00:00
|
|
|
sc->sc_xfer = p->p_pid;
|
|
|
|
break;
|
|
|
|
|
1995-10-31 20:24:14 +00:00
|
|
|
#ifdef PPP_COMPRESS
|
|
|
|
case PPPIOCSCOMPRESS:
|
2002-04-01 21:31:13 +00:00
|
|
|
if ((error = suser(td)) != 0)
|
Lock down the network interface queues. The queue mutex must be obtained
before adding/removing packets from the queue. Also, the if_obytes and
if_omcasts fields should only be manipulated under protection of the mutex.
IF_ENQUEUE, IF_PREPEND, and IF_DEQUEUE perform all necessary locking on
the queue. An IF_LOCK macro is provided, as well as the old (mutex-less)
versions of the macros in the form _IF_ENQUEUE, _IF_QFULL, for code which
needs them, but their use is discouraged.
Two new macros are introduced: IF_DRAIN() to drain a queue, and IF_HANDOFF,
which takes care of locking/enqueue, and also statistics updating/start
if necessary.
2000-11-25 07:35:38 +00:00
|
|
|
break;
|
1995-10-31 20:24:14 +00:00
|
|
|
odp = (struct ppp_option_data *) data;
|
|
|
|
nb = odp->length;
|
|
|
|
if (nb > sizeof(ccp_option))
|
|
|
|
nb = sizeof(ccp_option);
|
1997-08-19 14:10:50 +00:00
|
|
|
if ((error = copyin(odp->ptr, ccp_option, nb)) != 0)
|
Lock down the network interface queues. The queue mutex must be obtained
before adding/removing packets from the queue. Also, the if_obytes and
if_omcasts fields should only be manipulated under protection of the mutex.
IF_ENQUEUE, IF_PREPEND, and IF_DEQUEUE perform all necessary locking on
the queue. An IF_LOCK macro is provided, as well as the old (mutex-less)
versions of the macros in the form _IF_ENQUEUE, _IF_QFULL, for code which
needs them, but their use is discouraged.
Two new macros are introduced: IF_DRAIN() to drain a queue, and IF_HANDOFF,
which takes care of locking/enqueue, and also statistics updating/start
if necessary.
2000-11-25 07:35:38 +00:00
|
|
|
break;
|
|
|
|
if (ccp_option[1] < 2) { /* preliminary check on the length byte */
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
1995-10-31 20:24:14 +00:00
|
|
|
for (cp = ppp_compressors; *cp != NULL; ++cp)
|
|
|
|
if ((*cp)->compress_proto == ccp_option[0]) {
|
|
|
|
/*
|
|
|
|
* Found a handler for the protocol - try to allocate
|
|
|
|
* a compressor or decompressor.
|
|
|
|
*/
|
|
|
|
error = 0;
|
|
|
|
if (odp->transmit) {
|
1997-08-19 14:10:50 +00:00
|
|
|
s = splsoftnet();
|
1995-10-31 20:24:14 +00:00
|
|
|
if (sc->sc_xc_state != NULL)
|
|
|
|
(*sc->sc_xcomp->comp_free)(sc->sc_xc_state);
|
|
|
|
sc->sc_xcomp = *cp;
|
|
|
|
sc->sc_xc_state = (*cp)->comp_alloc(ccp_option, nb);
|
|
|
|
if (sc->sc_xc_state == NULL) {
|
|
|
|
if (sc->sc_flags & SC_DEBUG)
|
2002-09-24 17:37:32 +00:00
|
|
|
if_printf(&sc->sc_if, "comp_alloc failed\n");
|
1995-10-31 20:24:14 +00:00
|
|
|
error = ENOBUFS;
|
|
|
|
}
|
|
|
|
splimp();
|
|
|
|
sc->sc_flags &= ~SC_COMP_RUN;
|
|
|
|
splx(s);
|
|
|
|
} else {
|
1997-08-19 14:10:50 +00:00
|
|
|
s = splsoftnet();
|
1995-10-31 20:24:14 +00:00
|
|
|
if (sc->sc_rc_state != NULL)
|
|
|
|
(*sc->sc_rcomp->decomp_free)(sc->sc_rc_state);
|
|
|
|
sc->sc_rcomp = *cp;
|
|
|
|
sc->sc_rc_state = (*cp)->decomp_alloc(ccp_option, nb);
|
|
|
|
if (sc->sc_rc_state == NULL) {
|
|
|
|
if (sc->sc_flags & SC_DEBUG)
|
2002-09-24 17:37:32 +00:00
|
|
|
if_printf(&sc->sc_if, "decomp_alloc failed\n");
|
1995-10-31 20:24:14 +00:00
|
|
|
error = ENOBUFS;
|
|
|
|
}
|
|
|
|
splimp();
|
|
|
|
sc->sc_flags &= ~SC_DECOMP_RUN;
|
|
|
|
splx(s);
|
|
|
|
}
|
Lock down the network interface queues. The queue mutex must be obtained
before adding/removing packets from the queue. Also, the if_obytes and
if_omcasts fields should only be manipulated under protection of the mutex.
IF_ENQUEUE, IF_PREPEND, and IF_DEQUEUE perform all necessary locking on
the queue. An IF_LOCK macro is provided, as well as the old (mutex-less)
versions of the macros in the form _IF_ENQUEUE, _IF_QFULL, for code which
needs them, but their use is discouraged.
Two new macros are introduced: IF_DRAIN() to drain a queue, and IF_HANDOFF,
which takes care of locking/enqueue, and also statistics updating/start
if necessary.
2000-11-25 07:35:38 +00:00
|
|
|
break;
|
1995-10-31 20:24:14 +00:00
|
|
|
}
|
|
|
|
if (sc->sc_flags & SC_DEBUG)
|
2002-09-24 17:37:32 +00:00
|
|
|
if_printf(&sc->sc_if, "no compressor for [%x %x %x], %x\n",
|
|
|
|
ccp_option[0], ccp_option[1], ccp_option[2], nb);
|
Lock down the network interface queues. The queue mutex must be obtained
before adding/removing packets from the queue. Also, the if_obytes and
if_omcasts fields should only be manipulated under protection of the mutex.
IF_ENQUEUE, IF_PREPEND, and IF_DEQUEUE perform all necessary locking on
the queue. An IF_LOCK macro is provided, as well as the old (mutex-less)
versions of the macros in the form _IF_ENQUEUE, _IF_QFULL, for code which
needs them, but their use is discouraged.
Two new macros are introduced: IF_DRAIN() to drain a queue, and IF_HANDOFF,
which takes care of locking/enqueue, and also statistics updating/start
if necessary.
2000-11-25 07:35:38 +00:00
|
|
|
error = EINVAL; /* no handler found */
|
|
|
|
break;
|
1995-10-31 20:24:14 +00:00
|
|
|
#endif /* PPP_COMPRESS */
|
|
|
|
|
|
|
|
case PPPIOCGNPMODE:
|
|
|
|
case PPPIOCSNPMODE:
|
|
|
|
npi = (struct npioctl *) data;
|
2001-01-31 08:27:09 +00:00
|
|
|
npx = 0; /* XXX: quiet gcc */
|
1995-10-31 20:24:14 +00:00
|
|
|
switch (npi->protocol) {
|
|
|
|
case PPP_IP:
|
|
|
|
npx = NP_IP;
|
|
|
|
break;
|
|
|
|
default:
|
Lock down the network interface queues. The queue mutex must be obtained
before adding/removing packets from the queue. Also, the if_obytes and
if_omcasts fields should only be manipulated under protection of the mutex.
IF_ENQUEUE, IF_PREPEND, and IF_DEQUEUE perform all necessary locking on
the queue. An IF_LOCK macro is provided, as well as the old (mutex-less)
versions of the macros in the form _IF_ENQUEUE, _IF_QFULL, for code which
needs them, but their use is discouraged.
Two new macros are introduced: IF_DRAIN() to drain a queue, and IF_HANDOFF,
which takes care of locking/enqueue, and also statistics updating/start
if necessary.
2000-11-25 07:35:38 +00:00
|
|
|
error = EINVAL;
|
1995-10-31 20:24:14 +00:00
|
|
|
}
|
Lock down the network interface queues. The queue mutex must be obtained
before adding/removing packets from the queue. Also, the if_obytes and
if_omcasts fields should only be manipulated under protection of the mutex.
IF_ENQUEUE, IF_PREPEND, and IF_DEQUEUE perform all necessary locking on
the queue. An IF_LOCK macro is provided, as well as the old (mutex-less)
versions of the macros in the form _IF_ENQUEUE, _IF_QFULL, for code which
needs them, but their use is discouraged.
Two new macros are introduced: IF_DRAIN() to drain a queue, and IF_HANDOFF,
which takes care of locking/enqueue, and also statistics updating/start
if necessary.
2000-11-25 07:35:38 +00:00
|
|
|
if (error)
|
|
|
|
break;
|
1995-10-31 20:24:14 +00:00
|
|
|
if (cmd == PPPIOCGNPMODE) {
|
|
|
|
npi->mode = sc->sc_npmode[npx];
|
|
|
|
} else {
|
2002-04-01 21:31:13 +00:00
|
|
|
if ((error = suser(td)) != 0)
|
Lock down the network interface queues. The queue mutex must be obtained
before adding/removing packets from the queue. Also, the if_obytes and
if_omcasts fields should only be manipulated under protection of the mutex.
IF_ENQUEUE, IF_PREPEND, and IF_DEQUEUE perform all necessary locking on
the queue. An IF_LOCK macro is provided, as well as the old (mutex-less)
versions of the macros in the form _IF_ENQUEUE, _IF_QFULL, for code which
needs them, but their use is discouraged.
Two new macros are introduced: IF_DRAIN() to drain a queue, and IF_HANDOFF,
which takes care of locking/enqueue, and also statistics updating/start
if necessary.
2000-11-25 07:35:38 +00:00
|
|
|
break;
|
1995-10-31 20:24:14 +00:00
|
|
|
if (npi->mode != sc->sc_npmode[npx]) {
|
1997-08-19 14:10:50 +00:00
|
|
|
s = splsoftnet();
|
1995-10-31 20:24:14 +00:00
|
|
|
sc->sc_npmode[npx] = npi->mode;
|
|
|
|
if (npi->mode != NPMODE_QUEUE) {
|
|
|
|
ppp_requeue(sc);
|
|
|
|
(*sc->sc_start)(sc);
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PPPIOCGIDLE:
|
1997-08-19 14:10:50 +00:00
|
|
|
s = splsoftnet();
|
1998-03-30 09:56:58 +00:00
|
|
|
t = time_second;
|
1995-10-31 20:24:14 +00:00
|
|
|
((struct ppp_idle *)data)->xmit_idle = t - sc->sc_last_sent;
|
|
|
|
((struct ppp_idle *)data)->recv_idle = t - sc->sc_last_recv;
|
|
|
|
splx(s);
|
|
|
|
break;
|
|
|
|
|
1997-10-18 00:46:10 +00:00
|
|
|
#ifdef PPP_FILTER
|
1997-08-19 14:10:50 +00:00
|
|
|
case PPPIOCSPASS:
|
|
|
|
case PPPIOCSACTIVE:
|
|
|
|
nbp = (struct bpf_program *) data;
|
Lock down the network interface queues. The queue mutex must be obtained
before adding/removing packets from the queue. Also, the if_obytes and
if_omcasts fields should only be manipulated under protection of the mutex.
IF_ENQUEUE, IF_PREPEND, and IF_DEQUEUE perform all necessary locking on
the queue. An IF_LOCK macro is provided, as well as the old (mutex-less)
versions of the macros in the form _IF_ENQUEUE, _IF_QFULL, for code which
needs them, but their use is discouraged.
Two new macros are introduced: IF_DRAIN() to drain a queue, and IF_HANDOFF,
which takes care of locking/enqueue, and also statistics updating/start
if necessary.
2000-11-25 07:35:38 +00:00
|
|
|
if ((unsigned) nbp->bf_len > BPF_MAXINSNS) {
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
1997-08-19 14:10:50 +00:00
|
|
|
newcodelen = nbp->bf_len * sizeof(struct bpf_insn);
|
|
|
|
if (newcodelen != 0) {
|
2003-02-19 05:47:46 +00:00
|
|
|
MALLOC(newcode, struct bpf_insn *, newcodelen, M_DEVBUF, M_WAITOK);
|
1997-08-19 14:10:50 +00:00
|
|
|
if (newcode == 0) {
|
Lock down the network interface queues. The queue mutex must be obtained
before adding/removing packets from the queue. Also, the if_obytes and
if_omcasts fields should only be manipulated under protection of the mutex.
IF_ENQUEUE, IF_PREPEND, and IF_DEQUEUE perform all necessary locking on
the queue. An IF_LOCK macro is provided, as well as the old (mutex-less)
versions of the macros in the form _IF_ENQUEUE, _IF_QFULL, for code which
needs them, but their use is discouraged.
Two new macros are introduced: IF_DRAIN() to drain a queue, and IF_HANDOFF,
which takes care of locking/enqueue, and also statistics updating/start
if necessary.
2000-11-25 07:35:38 +00:00
|
|
|
error = EINVAL; /* or sumpin */
|
|
|
|
break;
|
1997-08-19 14:10:50 +00:00
|
|
|
}
|
|
|
|
if ((error = copyin((caddr_t)nbp->bf_insns, (caddr_t)newcode,
|
|
|
|
newcodelen)) != 0) {
|
2002-04-04 06:03:17 +00:00
|
|
|
free(newcode, M_DEVBUF);
|
Lock down the network interface queues. The queue mutex must be obtained
before adding/removing packets from the queue. Also, the if_obytes and
if_omcasts fields should only be manipulated under protection of the mutex.
IF_ENQUEUE, IF_PREPEND, and IF_DEQUEUE perform all necessary locking on
the queue. An IF_LOCK macro is provided, as well as the old (mutex-less)
versions of the macros in the form _IF_ENQUEUE, _IF_QFULL, for code which
needs them, but their use is discouraged.
Two new macros are introduced: IF_DRAIN() to drain a queue, and IF_HANDOFF,
which takes care of locking/enqueue, and also statistics updating/start
if necessary.
2000-11-25 07:35:38 +00:00
|
|
|
break;
|
1997-08-19 14:10:50 +00:00
|
|
|
}
|
|
|
|
if (!bpf_validate(newcode, nbp->bf_len)) {
|
2002-04-04 06:03:17 +00:00
|
|
|
free(newcode, M_DEVBUF);
|
Lock down the network interface queues. The queue mutex must be obtained
before adding/removing packets from the queue. Also, the if_obytes and
if_omcasts fields should only be manipulated under protection of the mutex.
IF_ENQUEUE, IF_PREPEND, and IF_DEQUEUE perform all necessary locking on
the queue. An IF_LOCK macro is provided, as well as the old (mutex-less)
versions of the macros in the form _IF_ENQUEUE, _IF_QFULL, for code which
needs them, but their use is discouraged.
Two new macros are introduced: IF_DRAIN() to drain a queue, and IF_HANDOFF,
which takes care of locking/enqueue, and also statistics updating/start
if necessary.
2000-11-25 07:35:38 +00:00
|
|
|
error = EINVAL;
|
|
|
|
break;
|
1997-08-19 14:10:50 +00:00
|
|
|
}
|
|
|
|
} else
|
|
|
|
newcode = 0;
|
|
|
|
bp = (cmd == PPPIOCSPASS)? &sc->sc_pass_filt: &sc->sc_active_filt;
|
|
|
|
oldcode = bp->bf_insns;
|
|
|
|
s = splimp();
|
|
|
|
bp->bf_len = nbp->bf_len;
|
|
|
|
bp->bf_insns = newcode;
|
|
|
|
splx(s);
|
|
|
|
if (oldcode != 0)
|
2002-04-04 06:03:17 +00:00
|
|
|
free(oldcode, M_DEVBUF);
|
1997-08-19 14:10:50 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
1994-09-23 00:10:32 +00:00
|
|
|
default:
|
Lock down the network interface queues. The queue mutex must be obtained
before adding/removing packets from the queue. Also, the if_obytes and
if_omcasts fields should only be manipulated under protection of the mutex.
IF_ENQUEUE, IF_PREPEND, and IF_DEQUEUE perform all necessary locking on
the queue. An IF_LOCK macro is provided, as well as the old (mutex-less)
versions of the macros in the form _IF_ENQUEUE, _IF_QFULL, for code which
needs them, but their use is discouraged.
Two new macros are introduced: IF_DRAIN() to drain a queue, and IF_HANDOFF,
which takes care of locking/enqueue, and also statistics updating/start
if necessary.
2000-11-25 07:35:38 +00:00
|
|
|
error = ENOIOCTL;
|
|
|
|
break;
|
1994-09-23 00:10:32 +00:00
|
|
|
}
|
Lock down the network interface queues. The queue mutex must be obtained
before adding/removing packets from the queue. Also, the if_obytes and
if_omcasts fields should only be manipulated under protection of the mutex.
IF_ENQUEUE, IF_PREPEND, and IF_DEQUEUE perform all necessary locking on
the queue. An IF_LOCK macro is provided, as well as the old (mutex-less)
versions of the macros in the form _IF_ENQUEUE, _IF_QFULL, for code which
needs them, but their use is discouraged.
Two new macros are introduced: IF_DRAIN() to drain a queue, and IF_HANDOFF,
which takes care of locking/enqueue, and also statistics updating/start
if necessary.
2000-11-25 07:35:38 +00:00
|
|
|
return (error);
|
1994-09-23 00:10:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1995-10-31 20:24:14 +00:00
|
|
|
* Process an ioctl request to the ppp network interface.
|
1994-09-23 00:10:32 +00:00
|
|
|
*/
|
1995-12-14 09:55:16 +00:00
|
|
|
static int
|
1995-10-31 20:24:14 +00:00
|
|
|
pppsioctl(ifp, cmd, data)
|
|
|
|
register struct ifnet *ifp;
|
1998-06-07 17:13:14 +00:00
|
|
|
u_long cmd;
|
1995-10-31 20:24:14 +00:00
|
|
|
caddr_t data;
|
1994-09-23 00:10:32 +00:00
|
|
|
{
|
2002-04-01 21:31:13 +00:00
|
|
|
struct thread *td = curthread; /* XXX */
|
2002-08-09 15:30:48 +00:00
|
|
|
register struct ppp_softc *sc = ifp->if_softc;
|
1995-10-31 20:24:14 +00:00
|
|
|
register struct ifaddr *ifa = (struct ifaddr *)data;
|
|
|
|
register struct ifreq *ifr = (struct ifreq *)data;
|
|
|
|
struct ppp_stats *psp;
|
|
|
|
#ifdef PPP_COMPRESS
|
|
|
|
struct ppp_comp_stats *pcp;
|
|
|
|
#endif
|
|
|
|
int s = splimp(), error = 0;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case SIOCSIFFLAGS:
|
|
|
|
if ((ifp->if_flags & IFF_RUNNING) == 0)
|
|
|
|
ifp->if_flags &= ~IFF_UP;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCSIFADDR:
|
1995-11-13 22:09:39 +00:00
|
|
|
case SIOCAIFADDR:
|
|
|
|
switch(ifa->ifa_addr->sa_family) {
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef IPX
|
|
|
|
case AF_IPX:
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
1995-10-31 20:24:14 +00:00
|
|
|
error = EAFNOSUPPORT;
|
1995-11-13 22:09:39 +00:00
|
|
|
break;
|
|
|
|
}
|
1995-10-31 20:24:14 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCSIFDSTADDR:
|
1995-11-13 22:09:39 +00:00
|
|
|
switch(ifa->ifa_addr->sa_family) {
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef IPX
|
|
|
|
case AF_IPX:
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
1995-10-31 20:24:14 +00:00
|
|
|
error = EAFNOSUPPORT;
|
1995-11-13 22:09:39 +00:00
|
|
|
break;
|
|
|
|
}
|
1995-10-31 20:24:14 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCSIFMTU:
|
2002-04-01 21:31:13 +00:00
|
|
|
if ((error = suser(td)) != 0)
|
1995-10-31 20:24:14 +00:00
|
|
|
break;
|
|
|
|
if (ifr->ifr_mtu > PPP_MAXMTU)
|
|
|
|
error = EINVAL;
|
|
|
|
else {
|
1999-08-06 16:46:29 +00:00
|
|
|
sc->sc_if.if_mtu = ifr->ifr_mtu;
|
|
|
|
if (sc->sc_setmtu)
|
1996-07-21 17:14:06 +00:00
|
|
|
(*sc->sc_setmtu)(sc);
|
1995-10-31 20:24:14 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCGIFMTU:
|
|
|
|
ifr->ifr_mtu = sc->sc_if.if_mtu;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCADDMULTI:
|
|
|
|
case SIOCDELMULTI:
|
1997-08-19 14:10:50 +00:00
|
|
|
if (ifr == 0) {
|
|
|
|
error = EAFNOSUPPORT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
switch(ifr->ifr_addr.sa_family) {
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
error = EAFNOSUPPORT;
|
|
|
|
break;
|
|
|
|
}
|
1995-10-31 20:24:14 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCGPPPSTATS:
|
|
|
|
psp = &((struct ifpppstatsreq *) data)->stats;
|
|
|
|
bzero(psp, sizeof(*psp));
|
1997-08-19 14:10:50 +00:00
|
|
|
psp->p = sc->sc_stats;
|
|
|
|
#if defined(VJC) && !defined(SL_NO_STATS)
|
|
|
|
if (sc->sc_comp) {
|
|
|
|
psp->vj.vjs_packets = sc->sc_comp->sls_packets;
|
|
|
|
psp->vj.vjs_compressed = sc->sc_comp->sls_compressed;
|
|
|
|
psp->vj.vjs_searches = sc->sc_comp->sls_searches;
|
|
|
|
psp->vj.vjs_misses = sc->sc_comp->sls_misses;
|
|
|
|
psp->vj.vjs_uncompressedin = sc->sc_comp->sls_uncompressedin;
|
|
|
|
psp->vj.vjs_compressedin = sc->sc_comp->sls_compressedin;
|
|
|
|
psp->vj.vjs_errorin = sc->sc_comp->sls_errorin;
|
|
|
|
psp->vj.vjs_tossed = sc->sc_comp->sls_tossed;
|
|
|
|
}
|
1995-10-31 20:24:14 +00:00
|
|
|
#endif /* VJC */
|
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef PPP_COMPRESS
|
|
|
|
case SIOCGPPPCSTATS:
|
|
|
|
pcp = &((struct ifpppcstatsreq *) data)->stats;
|
|
|
|
bzero(pcp, sizeof(*pcp));
|
|
|
|
if (sc->sc_xc_state != NULL)
|
|
|
|
(*sc->sc_xcomp->comp_stat)(sc->sc_xc_state, &pcp->c);
|
|
|
|
if (sc->sc_rc_state != NULL)
|
|
|
|
(*sc->sc_rcomp->decomp_stat)(sc->sc_rc_state, &pcp->d);
|
|
|
|
break;
|
|
|
|
#endif /* PPP_COMPRESS */
|
|
|
|
|
|
|
|
default:
|
|
|
|
error = ENOTTY;
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
return (error);
|
1994-09-23 00:10:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Queue a packet. Start transmission if not active.
|
|
|
|
* Packet is placed in Information field of PPP frame.
|
1995-10-31 20:24:14 +00:00
|
|
|
* Called at splnet as the if->if_output handler.
|
|
|
|
* Called at splnet from pppwrite().
|
1994-09-23 00:10:32 +00:00
|
|
|
*/
|
|
|
|
int
|
1995-10-31 20:24:14 +00:00
|
|
|
pppoutput(ifp, m0, dst, rtp)
|
|
|
|
struct ifnet *ifp;
|
|
|
|
struct mbuf *m0;
|
|
|
|
struct sockaddr *dst;
|
|
|
|
struct rtentry *rtp;
|
1994-09-23 00:10:32 +00:00
|
|
|
{
|
2002-08-09 15:30:48 +00:00
|
|
|
register struct ppp_softc *sc = ifp->if_softc;
|
1994-09-23 00:10:32 +00:00
|
|
|
int protocol, address, control;
|
|
|
|
u_char *cp;
|
|
|
|
int s, error;
|
|
|
|
struct ip *ip;
|
|
|
|
struct ifqueue *ifq;
|
1995-10-31 20:24:14 +00:00
|
|
|
enum NPmode mode;
|
1997-08-19 14:10:50 +00:00
|
|
|
int len;
|
1994-09-23 00:10:32 +00:00
|
|
|
|
2002-08-01 21:13:47 +00:00
|
|
|
#ifdef MAC
|
|
|
|
error = mac_check_ifnet_transmit(ifp, m0);
|
|
|
|
if (error)
|
|
|
|
goto bad;
|
|
|
|
#endif
|
|
|
|
|
1994-09-23 00:10:32 +00:00
|
|
|
if (sc->sc_devp == NULL || (ifp->if_flags & IFF_RUNNING) == 0
|
1997-08-19 14:10:50 +00:00
|
|
|
|| ((ifp->if_flags & IFF_UP) == 0 && dst->sa_family != AF_UNSPEC)) {
|
1994-09-23 00:10:32 +00:00
|
|
|
error = ENETDOWN; /* sort of */
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Compute PPP header.
|
|
|
|
*/
|
1995-10-31 20:24:14 +00:00
|
|
|
m0->m_flags &= ~M_HIGHPRI;
|
1994-09-23 00:10:32 +00:00
|
|
|
switch (dst->sa_family) {
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
1995-10-31 20:24:14 +00:00
|
|
|
address = PPP_ALLSTATIONS;
|
|
|
|
control = PPP_UI;
|
1994-09-23 00:10:32 +00:00
|
|
|
protocol = PPP_IP;
|
1995-10-31 20:24:14 +00:00
|
|
|
mode = sc->sc_npmode[NP_IP];
|
1995-05-30 08:16:23 +00:00
|
|
|
|
1994-09-23 00:10:32 +00:00
|
|
|
/*
|
1995-10-31 20:24:14 +00:00
|
|
|
* If this packet has the "low delay" bit set in the IP header,
|
|
|
|
* put it on the fastq instead.
|
1994-09-23 00:10:32 +00:00
|
|
|
*/
|
1995-10-31 20:24:14 +00:00
|
|
|
ip = mtod(m0, struct ip *);
|
|
|
|
if (ip->ip_tos & IPTOS_LOWDELAY)
|
|
|
|
m0->m_flags |= M_HIGHPRI;
|
1994-09-23 00:10:32 +00:00
|
|
|
break;
|
|
|
|
#endif
|
1995-10-26 20:31:59 +00:00
|
|
|
#ifdef IPX
|
|
|
|
case AF_IPX:
|
1995-11-03 08:42:21 +00:00
|
|
|
/*
|
|
|
|
* This is pretty bogus.. We dont have an ipxcp module in pppd
|
|
|
|
* yet to configure the link parameters. Sigh. I guess a
|
|
|
|
* manual ifconfig would do.... -Peter
|
|
|
|
*/
|
|
|
|
address = PPP_ALLSTATIONS;
|
|
|
|
control = PPP_UI;
|
1995-10-26 20:31:59 +00:00
|
|
|
protocol = PPP_IPX;
|
1995-11-03 08:42:21 +00:00
|
|
|
mode = NPMODE_PASS;
|
1995-10-26 20:31:59 +00:00
|
|
|
break;
|
1994-09-23 00:10:32 +00:00
|
|
|
#endif
|
|
|
|
case AF_UNSPEC:
|
1995-10-31 20:24:14 +00:00
|
|
|
address = PPP_ADDRESS(dst->sa_data);
|
|
|
|
control = PPP_CONTROL(dst->sa_data);
|
|
|
|
protocol = PPP_PROTOCOL(dst->sa_data);
|
|
|
|
mode = NPMODE_PASS;
|
1994-09-23 00:10:32 +00:00
|
|
|
break;
|
|
|
|
default:
|
2002-09-24 17:37:32 +00:00
|
|
|
if_printf(ifp, "af%d not supported\n", dst->sa_family);
|
1994-09-23 00:10:32 +00:00
|
|
|
error = EAFNOSUPPORT;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
1995-10-31 20:24:14 +00:00
|
|
|
/*
|
|
|
|
* Drop this packet, or return an error, if necessary.
|
|
|
|
*/
|
|
|
|
if (mode == NPMODE_ERROR) {
|
|
|
|
error = ENETDOWN;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
if (mode == NPMODE_DROP) {
|
|
|
|
error = 0;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
1994-09-23 00:10:32 +00:00
|
|
|
/*
|
|
|
|
* Add PPP header. If no space in first mbuf, allocate another.
|
|
|
|
* (This assumes M_LEADINGSPACE is always 0 for a cluster mbuf.)
|
|
|
|
*/
|
|
|
|
if (M_LEADINGSPACE(m0) < PPP_HDRLEN) {
|
2003-02-19 05:47:46 +00:00
|
|
|
m0 = m_prepend(m0, PPP_HDRLEN, M_DONTWAIT);
|
1994-09-23 00:10:32 +00:00
|
|
|
if (m0 == 0) {
|
|
|
|
error = ENOBUFS;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
m0->m_len = 0;
|
|
|
|
} else
|
|
|
|
m0->m_data -= PPP_HDRLEN;
|
|
|
|
|
|
|
|
cp = mtod(m0, u_char *);
|
|
|
|
*cp++ = address;
|
|
|
|
*cp++ = control;
|
|
|
|
*cp++ = protocol >> 8;
|
|
|
|
*cp++ = protocol & 0xff;
|
|
|
|
m0->m_len += PPP_HDRLEN;
|
|
|
|
|
2002-09-18 19:44:14 +00:00
|
|
|
len = m_length(m0, NULL);
|
1997-08-19 14:10:50 +00:00
|
|
|
|
1994-09-23 00:10:32 +00:00
|
|
|
if (sc->sc_flags & SC_LOG_OUTPKT) {
|
2003-10-31 18:32:15 +00:00
|
|
|
printf("%s output: ", ifp->if_xname);
|
1995-10-31 20:24:14 +00:00
|
|
|
pppdumpm(m0);
|
1994-09-23 00:10:32 +00:00
|
|
|
}
|
|
|
|
|
1997-08-19 14:10:50 +00:00
|
|
|
if ((protocol & 0x8000) == 0) {
|
1997-10-18 00:46:10 +00:00
|
|
|
#ifdef PPP_FILTER
|
1997-08-19 14:10:50 +00:00
|
|
|
/*
|
|
|
|
* Apply the pass and active filters to the packet,
|
|
|
|
* but only if it is a data packet.
|
|
|
|
*/
|
|
|
|
*mtod(m0, u_char *) = 1; /* indicates outbound */
|
|
|
|
if (sc->sc_pass_filt.bf_insns != 0
|
|
|
|
&& bpf_filter(sc->sc_pass_filt.bf_insns, (u_char *) m0,
|
|
|
|
len, 0) == 0) {
|
|
|
|
error = 0; /* drop this packet */
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update the time we sent the most recent packet.
|
|
|
|
*/
|
|
|
|
if (sc->sc_active_filt.bf_insns == 0
|
|
|
|
|| bpf_filter(sc->sc_active_filt.bf_insns, (u_char *) m0, len, 0))
|
1998-03-30 09:56:58 +00:00
|
|
|
sc->sc_last_sent = time_second;
|
1997-08-19 14:10:50 +00:00
|
|
|
|
|
|
|
*mtod(m0, u_char *) = address;
|
|
|
|
#else
|
|
|
|
/*
|
|
|
|
* Update the time we sent the most recent data packet.
|
|
|
|
*/
|
1998-03-30 09:56:58 +00:00
|
|
|
sc->sc_last_sent = time_second;
|
1997-10-18 00:46:10 +00:00
|
|
|
#endif /* PPP_FILTER */
|
1997-08-19 14:10:50 +00:00
|
|
|
}
|
|
|
|
|
1995-10-31 20:24:14 +00:00
|
|
|
/*
|
|
|
|
* See if bpf wants to look at the packet.
|
|
|
|
*/
|
2002-11-15 00:00:15 +00:00
|
|
|
BPF_MTAP(ifp, m0);
|
1994-09-23 00:10:32 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Put the packet on the appropriate queue.
|
|
|
|
*/
|
1997-08-19 14:10:50 +00:00
|
|
|
s = splsoftnet(); /* redundant */
|
1995-10-31 20:24:14 +00:00
|
|
|
if (mode == NPMODE_QUEUE) {
|
|
|
|
/* XXX we should limit the number of packets on this queue */
|
|
|
|
*sc->sc_npqtail = m0;
|
|
|
|
m0->m_nextpkt = NULL;
|
|
|
|
sc->sc_npqtail = &m0->m_nextpkt;
|
|
|
|
} else {
|
1997-08-19 14:10:50 +00:00
|
|
|
/* fastq and if_snd are emptied at spl[soft]net now */
|
1995-10-31 20:24:14 +00:00
|
|
|
ifq = (m0->m_flags & M_HIGHPRI)? &sc->sc_fastq: &ifp->if_snd;
|
Lock down the network interface queues. The queue mutex must be obtained
before adding/removing packets from the queue. Also, the if_obytes and
if_omcasts fields should only be manipulated under protection of the mutex.
IF_ENQUEUE, IF_PREPEND, and IF_DEQUEUE perform all necessary locking on
the queue. An IF_LOCK macro is provided, as well as the old (mutex-less)
versions of the macros in the form _IF_ENQUEUE, _IF_QFULL, for code which
needs them, but their use is discouraged.
Two new macros are introduced: IF_DRAIN() to drain a queue, and IF_HANDOFF,
which takes care of locking/enqueue, and also statistics updating/start
if necessary.
2000-11-25 07:35:38 +00:00
|
|
|
IF_LOCK(ifq);
|
|
|
|
if (_IF_QFULL(ifq) && dst->sa_family != AF_UNSPEC) {
|
|
|
|
_IF_DROP(ifq);
|
|
|
|
IF_UNLOCK(ifq);
|
1995-10-31 20:24:14 +00:00
|
|
|
sc->sc_if.if_oerrors++;
|
1997-08-19 14:10:50 +00:00
|
|
|
sc->sc_stats.ppp_oerrors++;
|
1995-10-31 20:24:14 +00:00
|
|
|
error = ENOBUFS;
|
|
|
|
goto bad;
|
|
|
|
}
|
Lock down the network interface queues. The queue mutex must be obtained
before adding/removing packets from the queue. Also, the if_obytes and
if_omcasts fields should only be manipulated under protection of the mutex.
IF_ENQUEUE, IF_PREPEND, and IF_DEQUEUE perform all necessary locking on
the queue. An IF_LOCK macro is provided, as well as the old (mutex-less)
versions of the macros in the form _IF_ENQUEUE, _IF_QFULL, for code which
needs them, but their use is discouraged.
Two new macros are introduced: IF_DRAIN() to drain a queue, and IF_HANDOFF,
which takes care of locking/enqueue, and also statistics updating/start
if necessary.
2000-11-25 07:35:38 +00:00
|
|
|
_IF_ENQUEUE(ifq, m0);
|
|
|
|
IF_UNLOCK(ifq);
|
1995-10-31 20:24:14 +00:00
|
|
|
(*sc->sc_start)(sc);
|
1994-09-23 00:10:32 +00:00
|
|
|
}
|
1998-03-30 09:56:58 +00:00
|
|
|
getmicrotime(&ifp->if_lastchange);
|
1997-08-19 14:10:50 +00:00
|
|
|
ifp->if_opackets++;
|
|
|
|
ifp->if_obytes += len;
|
1994-09-23 00:10:32 +00:00
|
|
|
|
|
|
|
splx(s);
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
bad:
|
|
|
|
m_freem(m0);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1995-10-31 20:24:14 +00:00
|
|
|
* After a change in the NPmode for some NP, move packets from the
|
|
|
|
* npqueue to the send queue or the fast queue as appropriate.
|
1997-08-19 14:10:50 +00:00
|
|
|
* Should be called at spl[soft]net.
|
1994-09-23 00:10:32 +00:00
|
|
|
*/
|
1995-10-31 20:24:14 +00:00
|
|
|
static void
|
|
|
|
ppp_requeue(sc)
|
1994-09-23 00:10:32 +00:00
|
|
|
struct ppp_softc *sc;
|
|
|
|
{
|
1995-10-31 20:24:14 +00:00
|
|
|
struct mbuf *m, **mpp;
|
|
|
|
struct ifqueue *ifq;
|
|
|
|
enum NPmode mode;
|
1994-09-23 00:10:32 +00:00
|
|
|
|
1995-10-31 20:24:14 +00:00
|
|
|
for (mpp = &sc->sc_npqueue; (m = *mpp) != NULL; ) {
|
|
|
|
switch (PPP_PROTOCOL(mtod(m, u_char *))) {
|
|
|
|
case PPP_IP:
|
|
|
|
mode = sc->sc_npmode[NP_IP];
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
mode = NPMODE_PASS;
|
|
|
|
}
|
1994-09-23 00:10:32 +00:00
|
|
|
|
1995-10-31 20:24:14 +00:00
|
|
|
switch (mode) {
|
|
|
|
case NPMODE_PASS:
|
|
|
|
/*
|
|
|
|
* This packet can now go on one of the queues to be sent.
|
|
|
|
*/
|
|
|
|
*mpp = m->m_nextpkt;
|
|
|
|
m->m_nextpkt = NULL;
|
|
|
|
ifq = (m->m_flags & M_HIGHPRI)? &sc->sc_fastq: &sc->sc_if.if_snd;
|
Lock down the network interface queues. The queue mutex must be obtained
before adding/removing packets from the queue. Also, the if_obytes and
if_omcasts fields should only be manipulated under protection of the mutex.
IF_ENQUEUE, IF_PREPEND, and IF_DEQUEUE perform all necessary locking on
the queue. An IF_LOCK macro is provided, as well as the old (mutex-less)
versions of the macros in the form _IF_ENQUEUE, _IF_QFULL, for code which
needs them, but their use is discouraged.
Two new macros are introduced: IF_DRAIN() to drain a queue, and IF_HANDOFF,
which takes care of locking/enqueue, and also statistics updating/start
if necessary.
2000-11-25 07:35:38 +00:00
|
|
|
if (! IF_HANDOFF(ifq, m, NULL)) {
|
1995-10-31 20:24:14 +00:00
|
|
|
sc->sc_if.if_oerrors++;
|
1997-08-19 14:10:50 +00:00
|
|
|
sc->sc_stats.ppp_oerrors++;
|
Lock down the network interface queues. The queue mutex must be obtained
before adding/removing packets from the queue. Also, the if_obytes and
if_omcasts fields should only be manipulated under protection of the mutex.
IF_ENQUEUE, IF_PREPEND, and IF_DEQUEUE perform all necessary locking on
the queue. An IF_LOCK macro is provided, as well as the old (mutex-less)
versions of the macros in the form _IF_ENQUEUE, _IF_QFULL, for code which
needs them, but their use is discouraged.
Two new macros are introduced: IF_DRAIN() to drain a queue, and IF_HANDOFF,
which takes care of locking/enqueue, and also statistics updating/start
if necessary.
2000-11-25 07:35:38 +00:00
|
|
|
}
|
1995-10-31 20:24:14 +00:00
|
|
|
break;
|
1994-09-23 00:10:32 +00:00
|
|
|
|
1995-10-31 20:24:14 +00:00
|
|
|
case NPMODE_DROP:
|
|
|
|
case NPMODE_ERROR:
|
|
|
|
*mpp = m->m_nextpkt;
|
|
|
|
m_freem(m);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NPMODE_QUEUE:
|
|
|
|
mpp = &m->m_nextpkt;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sc->sc_npqtail = mpp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1997-08-19 14:10:50 +00:00
|
|
|
* Transmitter has finished outputting some stuff;
|
|
|
|
* remember to call sc->sc_start later at splsoftnet.
|
1995-10-31 20:24:14 +00:00
|
|
|
*/
|
1997-08-19 14:10:50 +00:00
|
|
|
void
|
|
|
|
ppp_restart(sc)
|
1995-10-31 20:24:14 +00:00
|
|
|
struct ppp_softc *sc;
|
|
|
|
{
|
|
|
|
int s = splimp();
|
|
|
|
|
|
|
|
sc->sc_flags &= ~SC_TBUSY;
|
|
|
|
schednetisr(NETISR_PPP);
|
|
|
|
splx(s);
|
|
|
|
}
|
1994-09-23 00:10:32 +00:00
|
|
|
|
1995-10-31 20:24:14 +00:00
|
|
|
|
|
|
|
/*
|
1997-08-19 14:10:50 +00:00
|
|
|
* Get a packet to send. This procedure is intended to be called at
|
|
|
|
* splsoftnet, since it may involve time-consuming operations such as
|
|
|
|
* applying VJ compression, packet compression, address/control and/or
|
|
|
|
* protocol field compression to the packet.
|
1995-10-31 20:24:14 +00:00
|
|
|
*/
|
1997-08-19 14:10:50 +00:00
|
|
|
struct mbuf *
|
|
|
|
ppp_dequeue(sc)
|
1995-10-31 20:24:14 +00:00
|
|
|
struct ppp_softc *sc;
|
|
|
|
{
|
|
|
|
struct mbuf *m, *mp;
|
|
|
|
u_char *cp;
|
|
|
|
int address, control, protocol;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Grab a packet to send: first try the fast queue, then the
|
|
|
|
* normal queue.
|
|
|
|
*/
|
|
|
|
IF_DEQUEUE(&sc->sc_fastq, m);
|
|
|
|
if (m == NULL)
|
|
|
|
IF_DEQUEUE(&sc->sc_if.if_snd, m);
|
|
|
|
if (m == NULL)
|
1997-08-19 14:10:50 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
++sc->sc_stats.ppp_opackets;
|
1995-10-31 20:24:14 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Extract the ppp header of the new packet.
|
|
|
|
* The ppp header will be in one mbuf.
|
|
|
|
*/
|
|
|
|
cp = mtod(m, u_char *);
|
|
|
|
address = PPP_ADDRESS(cp);
|
|
|
|
control = PPP_CONTROL(cp);
|
|
|
|
protocol = PPP_PROTOCOL(cp);
|
|
|
|
|
|
|
|
switch (protocol) {
|
|
|
|
case PPP_IP:
|
|
|
|
#ifdef VJC
|
|
|
|
/*
|
|
|
|
* If the packet is a TCP/IP packet, see if we can compress it.
|
|
|
|
*/
|
1997-08-19 14:10:50 +00:00
|
|
|
if ((sc->sc_flags & SC_COMP_TCP) && sc->sc_comp != NULL) {
|
1995-10-31 20:24:14 +00:00
|
|
|
struct ip *ip;
|
|
|
|
int type;
|
|
|
|
|
|
|
|
mp = m;
|
|
|
|
ip = (struct ip *) (cp + PPP_HDRLEN);
|
|
|
|
if (mp->m_len <= PPP_HDRLEN) {
|
|
|
|
mp = mp->m_next;
|
|
|
|
if (mp == NULL)
|
|
|
|
break;
|
|
|
|
ip = mtod(mp, struct ip *);
|
|
|
|
}
|
|
|
|
/* this code assumes the IP/TCP header is in one non-shared mbuf */
|
|
|
|
if (ip->ip_p == IPPROTO_TCP) {
|
1997-08-19 14:10:50 +00:00
|
|
|
type = sl_compress_tcp(mp, ip, sc->sc_comp,
|
1995-10-31 20:24:14 +00:00
|
|
|
!(sc->sc_flags & SC_NO_TCP_CCID));
|
|
|
|
switch (type) {
|
|
|
|
case TYPE_UNCOMPRESSED_TCP:
|
|
|
|
protocol = PPP_VJC_UNCOMP;
|
|
|
|
break;
|
|
|
|
case TYPE_COMPRESSED_TCP:
|
|
|
|
protocol = PPP_VJC_COMP;
|
|
|
|
cp = mtod(m, u_char *);
|
|
|
|
cp[0] = address; /* header has moved */
|
|
|
|
cp[1] = control;
|
|
|
|
cp[2] = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
cp[3] = protocol; /* update protocol in PPP header */
|
|
|
|
}
|
|
|
|
}
|
1994-09-23 00:10:32 +00:00
|
|
|
#endif /* VJC */
|
1995-10-31 20:24:14 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef PPP_COMPRESS
|
|
|
|
case PPP_CCP:
|
|
|
|
ppp_ccp(sc, m, 0);
|
|
|
|
break;
|
|
|
|
#endif /* PPP_COMPRESS */
|
|
|
|
}
|
1994-09-23 00:10:32 +00:00
|
|
|
|
1995-10-31 20:24:14 +00:00
|
|
|
#ifdef PPP_COMPRESS
|
|
|
|
if (protocol != PPP_LCP && protocol != PPP_CCP
|
|
|
|
&& sc->sc_xc_state && (sc->sc_flags & SC_COMP_RUN)) {
|
|
|
|
struct mbuf *mcomp = NULL;
|
|
|
|
int slen, clen;
|
|
|
|
|
2002-09-18 19:44:14 +00:00
|
|
|
slen = m_length(m, NULL);
|
1995-10-31 20:24:14 +00:00
|
|
|
clen = (*sc->sc_xcomp->compress)
|
1997-08-19 14:10:50 +00:00
|
|
|
(sc->sc_xc_state, &mcomp, m, slen, sc->sc_if.if_mtu + PPP_HDRLEN);
|
1995-10-31 20:24:14 +00:00
|
|
|
if (mcomp != NULL) {
|
1997-08-19 14:10:50 +00:00
|
|
|
if (sc->sc_flags & SC_CCP_UP) {
|
|
|
|
/* Send the compressed packet instead of the original. */
|
|
|
|
m_freem(m);
|
|
|
|
m = mcomp;
|
|
|
|
cp = mtod(m, u_char *);
|
|
|
|
protocol = cp[3];
|
|
|
|
} else {
|
|
|
|
/* Can't transmit compressed packets until CCP is up. */
|
|
|
|
m_freem(mcomp);
|
|
|
|
}
|
1995-10-31 20:24:14 +00:00
|
|
|
}
|
1994-09-23 00:10:32 +00:00
|
|
|
}
|
1995-10-31 20:24:14 +00:00
|
|
|
#endif /* PPP_COMPRESS */
|
1994-09-23 00:10:32 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Compress the address/control and protocol, if possible.
|
|
|
|
*/
|
|
|
|
if (sc->sc_flags & SC_COMP_AC && address == PPP_ALLSTATIONS &&
|
|
|
|
control == PPP_UI && protocol != PPP_ALLSTATIONS &&
|
|
|
|
protocol != PPP_LCP) {
|
|
|
|
/* can compress address/control */
|
|
|
|
m->m_data += 2;
|
|
|
|
m->m_len -= 2;
|
|
|
|
}
|
|
|
|
if (sc->sc_flags & SC_COMP_PROT && protocol < 0xFF) {
|
|
|
|
/* can compress protocol */
|
|
|
|
if (mtod(m, u_char *) == cp) {
|
|
|
|
cp[2] = cp[1]; /* move address/control up */
|
|
|
|
cp[1] = cp[0];
|
|
|
|
}
|
|
|
|
++m->m_data;
|
|
|
|
--m->m_len;
|
|
|
|
}
|
|
|
|
|
1997-08-19 14:10:50 +00:00
|
|
|
return m;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Software interrupt routine, called at spl[soft]net.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
pppintr()
|
|
|
|
{
|
|
|
|
struct ppp_softc *sc;
|
2002-08-09 15:30:48 +00:00
|
|
|
int s;
|
1997-08-19 14:10:50 +00:00
|
|
|
struct mbuf *m;
|
|
|
|
|
2003-11-08 22:28:40 +00:00
|
|
|
GIANT_REQUIRED;
|
|
|
|
|
2002-08-09 15:30:48 +00:00
|
|
|
LIST_FOREACH(sc, &ppp_softc_list, sc_list) {
|
1997-08-19 14:10:50 +00:00
|
|
|
s = splimp();
|
|
|
|
if (!(sc->sc_flags & SC_TBUSY)
|
|
|
|
&& (sc->sc_if.if_snd.ifq_head || sc->sc_fastq.ifq_head)) {
|
|
|
|
sc->sc_flags |= SC_TBUSY;
|
|
|
|
splx(s);
|
|
|
|
(*sc->sc_start)(sc);
|
|
|
|
} else
|
|
|
|
splx(s);
|
|
|
|
for (;;) {
|
|
|
|
s = splimp();
|
|
|
|
IF_DEQUEUE(&sc->sc_rawq, m);
|
|
|
|
splx(s);
|
|
|
|
if (m == NULL)
|
|
|
|
break;
|
2002-08-01 21:13:47 +00:00
|
|
|
#ifdef MAC
|
|
|
|
mac_create_mbuf_from_ifnet(&sc->sc_if, m);
|
|
|
|
#endif
|
1997-08-19 14:10:50 +00:00
|
|
|
ppp_inproc(sc, m);
|
|
|
|
}
|
|
|
|
}
|
1994-09-23 00:10:32 +00:00
|
|
|
}
|
|
|
|
|
1995-10-31 20:24:14 +00:00
|
|
|
#ifdef PPP_COMPRESS
|
1994-09-23 00:10:32 +00:00
|
|
|
/*
|
1995-10-31 20:24:14 +00:00
|
|
|
* Handle a CCP packet. `rcvd' is 1 if the packet was received,
|
|
|
|
* 0 if it is about to be transmitted.
|
1994-09-23 00:10:32 +00:00
|
|
|
*/
|
1995-10-31 20:24:14 +00:00
|
|
|
static void
|
|
|
|
ppp_ccp(sc, m, rcvd)
|
|
|
|
struct ppp_softc *sc;
|
|
|
|
struct mbuf *m;
|
|
|
|
int rcvd;
|
1994-09-23 00:10:32 +00:00
|
|
|
{
|
1995-10-31 20:24:14 +00:00
|
|
|
u_char *dp, *ep;
|
|
|
|
struct mbuf *mp;
|
|
|
|
int slen, s;
|
1994-09-23 00:10:32 +00:00
|
|
|
|
1995-10-31 20:24:14 +00:00
|
|
|
/*
|
|
|
|
* Get a pointer to the data after the PPP header.
|
|
|
|
*/
|
|
|
|
if (m->m_len <= PPP_HDRLEN) {
|
|
|
|
mp = m->m_next;
|
|
|
|
if (mp == NULL)
|
|
|
|
return;
|
|
|
|
dp = (mp != NULL)? mtod(mp, u_char *): NULL;
|
|
|
|
} else {
|
|
|
|
mp = m;
|
|
|
|
dp = mtod(mp, u_char *) + PPP_HDRLEN;
|
1994-09-23 00:10:32 +00:00
|
|
|
}
|
|
|
|
|
1995-10-31 20:24:14 +00:00
|
|
|
ep = mtod(mp, u_char *) + mp->m_len;
|
|
|
|
if (dp + CCP_HDRLEN > ep)
|
|
|
|
return;
|
|
|
|
slen = CCP_LENGTH(dp);
|
|
|
|
if (dp + slen > ep) {
|
|
|
|
if (sc->sc_flags & SC_DEBUG)
|
1997-08-19 14:10:50 +00:00
|
|
|
printf("if_ppp/ccp: not enough data in mbuf (%p+%x > %p+%x)\n",
|
1995-10-31 20:24:14 +00:00
|
|
|
dp, slen, mtod(mp, u_char *), mp->m_len);
|
|
|
|
return;
|
|
|
|
}
|
1994-09-23 00:10:32 +00:00
|
|
|
|
1995-10-31 20:24:14 +00:00
|
|
|
switch (CCP_CODE(dp)) {
|
|
|
|
case CCP_CONFREQ:
|
|
|
|
case CCP_TERMREQ:
|
|
|
|
case CCP_TERMACK:
|
|
|
|
/* CCP must be going down - disable compression */
|
|
|
|
if (sc->sc_flags & SC_CCP_UP) {
|
|
|
|
s = splimp();
|
|
|
|
sc->sc_flags &= ~(SC_CCP_UP | SC_COMP_RUN | SC_DECOMP_RUN);
|
|
|
|
splx(s);
|
1994-09-23 00:10:32 +00:00
|
|
|
}
|
1995-10-31 20:24:14 +00:00
|
|
|
break;
|
1994-09-23 00:10:32 +00:00
|
|
|
|
1995-10-31 20:24:14 +00:00
|
|
|
case CCP_CONFACK:
|
|
|
|
if (sc->sc_flags & SC_CCP_OPEN && !(sc->sc_flags & SC_CCP_UP)
|
|
|
|
&& slen >= CCP_HDRLEN + CCP_OPT_MINLEN
|
|
|
|
&& slen >= CCP_OPT_LENGTH(dp + CCP_HDRLEN) + CCP_HDRLEN) {
|
|
|
|
if (!rcvd) {
|
|
|
|
/* we're agreeing to send compressed packets. */
|
|
|
|
if (sc->sc_xc_state != NULL
|
|
|
|
&& (*sc->sc_xcomp->comp_init)
|
|
|
|
(sc->sc_xc_state, dp + CCP_HDRLEN, slen - CCP_HDRLEN,
|
2003-10-31 18:32:15 +00:00
|
|
|
sc->sc_if.if_dunit, 0, sc->sc_flags & SC_DEBUG)) {
|
1995-10-31 20:24:14 +00:00
|
|
|
s = splimp();
|
|
|
|
sc->sc_flags |= SC_COMP_RUN;
|
|
|
|
splx(s);
|
1994-09-23 00:10:32 +00:00
|
|
|
}
|
1995-10-31 20:24:14 +00:00
|
|
|
} else {
|
|
|
|
/* peer is agreeing to send compressed packets. */
|
|
|
|
if (sc->sc_rc_state != NULL
|
|
|
|
&& (*sc->sc_rcomp->decomp_init)
|
|
|
|
(sc->sc_rc_state, dp + CCP_HDRLEN, slen - CCP_HDRLEN,
|
2003-10-31 18:32:15 +00:00
|
|
|
sc->sc_if.if_dunit, 0, sc->sc_mru,
|
1995-10-31 20:24:14 +00:00
|
|
|
sc->sc_flags & SC_DEBUG)) {
|
|
|
|
s = splimp();
|
|
|
|
sc->sc_flags |= SC_DECOMP_RUN;
|
|
|
|
sc->sc_flags &= ~(SC_DC_ERROR | SC_DC_FERROR);
|
|
|
|
splx(s);
|
1994-09-23 00:10:32 +00:00
|
|
|
}
|
|
|
|
}
|
1995-10-31 20:24:14 +00:00
|
|
|
}
|
|
|
|
break;
|
1994-09-23 00:10:32 +00:00
|
|
|
|
1995-10-31 20:24:14 +00:00
|
|
|
case CCP_RESETACK:
|
|
|
|
if (sc->sc_flags & SC_CCP_UP) {
|
|
|
|
if (!rcvd) {
|
|
|
|
if (sc->sc_xc_state && (sc->sc_flags & SC_COMP_RUN))
|
|
|
|
(*sc->sc_xcomp->comp_reset)(sc->sc_xc_state);
|
|
|
|
} else {
|
|
|
|
if (sc->sc_rc_state && (sc->sc_flags & SC_DECOMP_RUN)) {
|
|
|
|
(*sc->sc_rcomp->decomp_reset)(sc->sc_rc_state);
|
|
|
|
s = splimp();
|
|
|
|
sc->sc_flags &= ~SC_DC_ERROR;
|
|
|
|
splx(s);
|
|
|
|
}
|
1994-09-23 00:10:32 +00:00
|
|
|
}
|
|
|
|
}
|
1995-10-31 20:24:14 +00:00
|
|
|
break;
|
1994-09-23 00:10:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1995-10-31 20:24:14 +00:00
|
|
|
* CCP is down; free (de)compressor state if necessary.
|
1994-09-23 00:10:32 +00:00
|
|
|
*/
|
1995-10-31 20:24:14 +00:00
|
|
|
static void
|
|
|
|
ppp_ccp_closed(sc)
|
|
|
|
struct ppp_softc *sc;
|
1994-09-23 00:10:32 +00:00
|
|
|
{
|
1995-10-31 20:24:14 +00:00
|
|
|
if (sc->sc_xc_state) {
|
|
|
|
(*sc->sc_xcomp->comp_free)(sc->sc_xc_state);
|
|
|
|
sc->sc_xc_state = NULL;
|
|
|
|
}
|
|
|
|
if (sc->sc_rc_state) {
|
|
|
|
(*sc->sc_rcomp->decomp_free)(sc->sc_rc_state);
|
|
|
|
sc->sc_rc_state = NULL;
|
1994-09-23 00:10:32 +00:00
|
|
|
}
|
|
|
|
}
|
1995-10-31 20:24:14 +00:00
|
|
|
#endif /* PPP_COMPRESS */
|
1994-09-23 00:10:32 +00:00
|
|
|
|
|
|
|
/*
|
1995-10-31 20:24:14 +00:00
|
|
|
* PPP packet input routine.
|
|
|
|
* The caller has checked and removed the FCS and has inserted
|
|
|
|
* the address/control bytes and the protocol high byte if they
|
|
|
|
* were omitted.
|
1994-09-23 00:10:32 +00:00
|
|
|
*/
|
1995-10-31 20:24:14 +00:00
|
|
|
void
|
|
|
|
ppppktin(sc, m, lost)
|
1994-09-23 00:10:32 +00:00
|
|
|
struct ppp_softc *sc;
|
1995-10-31 20:24:14 +00:00
|
|
|
struct mbuf *m;
|
|
|
|
int lost;
|
1994-09-23 00:10:32 +00:00
|
|
|
{
|
1995-10-31 20:24:14 +00:00
|
|
|
int s = splimp();
|
1994-09-23 00:10:32 +00:00
|
|
|
|
1995-10-31 20:24:14 +00:00
|
|
|
if (lost)
|
|
|
|
m->m_flags |= M_ERRMARK;
|
|
|
|
IF_ENQUEUE(&sc->sc_rawq, m);
|
|
|
|
schednetisr(NETISR_PPP);
|
|
|
|
splx(s);
|
1994-09-23 00:10:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1995-10-31 20:24:14 +00:00
|
|
|
* Process a received PPP packet, doing decompression as necessary.
|
1997-08-19 14:10:50 +00:00
|
|
|
* Should be called at splsoftnet.
|
1994-09-23 00:10:32 +00:00
|
|
|
*/
|
|
|
|
#define COMPTYPE(proto) ((proto) == PPP_VJC_COMP? TYPE_COMPRESSED_TCP: \
|
|
|
|
TYPE_UNCOMPRESSED_TCP)
|
|
|
|
|
1995-10-31 20:24:14 +00:00
|
|
|
static void
|
|
|
|
ppp_inproc(sc, m)
|
1994-09-23 00:10:32 +00:00
|
|
|
struct ppp_softc *sc;
|
|
|
|
struct mbuf *m;
|
|
|
|
{
|
1997-08-19 14:10:50 +00:00
|
|
|
struct ifnet *ifp = &sc->sc_if;
|
2003-03-04 23:19:55 +00:00
|
|
|
int isr;
|
1995-10-31 20:24:14 +00:00
|
|
|
int s, ilen = 0, xlen, proto, rv;
|
|
|
|
u_char *cp, adrs, ctrl;
|
|
|
|
struct mbuf *mp, *dmp = NULL;
|
|
|
|
u_char *iphdr;
|
|
|
|
u_int hlen;
|
1994-09-23 00:10:32 +00:00
|
|
|
|
1997-08-19 14:10:50 +00:00
|
|
|
sc->sc_stats.ppp_ipackets++;
|
1995-10-31 20:24:14 +00:00
|
|
|
|
|
|
|
if (sc->sc_flags & SC_LOG_INPKT) {
|
2002-09-18 19:44:14 +00:00
|
|
|
ilen = m_length(m, NULL);
|
2002-09-24 17:37:32 +00:00
|
|
|
if_printf(ifp, "got %d bytes\n", ilen);
|
1995-10-31 20:24:14 +00:00
|
|
|
pppdumpm(m);
|
|
|
|
}
|
|
|
|
|
|
|
|
cp = mtod(m, u_char *);
|
|
|
|
adrs = PPP_ADDRESS(cp);
|
|
|
|
ctrl = PPP_CONTROL(cp);
|
|
|
|
proto = PPP_PROTOCOL(cp);
|
|
|
|
|
|
|
|
if (m->m_flags & M_ERRMARK) {
|
|
|
|
m->m_flags &= ~M_ERRMARK;
|
|
|
|
s = splimp();
|
|
|
|
sc->sc_flags |= SC_VJ_RESET;
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef PPP_COMPRESS
|
|
|
|
/*
|
|
|
|
* Decompress this packet if necessary, update the receiver's
|
|
|
|
* dictionary, or take appropriate action on a CCP packet.
|
|
|
|
*/
|
|
|
|
if (proto == PPP_COMP && sc->sc_rc_state && (sc->sc_flags & SC_DECOMP_RUN)
|
|
|
|
&& !(sc->sc_flags & SC_DC_ERROR) && !(sc->sc_flags & SC_DC_FERROR)) {
|
|
|
|
/* decompress this packet */
|
|
|
|
rv = (*sc->sc_rcomp->decompress)(sc->sc_rc_state, m, &dmp);
|
|
|
|
if (rv == DECOMP_OK) {
|
|
|
|
m_freem(m);
|
|
|
|
if (dmp == NULL) {
|
|
|
|
/* no error, but no decompressed packet produced */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m = dmp;
|
|
|
|
cp = mtod(m, u_char *);
|
|
|
|
proto = PPP_PROTOCOL(cp);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* An error has occurred in decompression.
|
|
|
|
* Pass the compressed packet up to pppd, which may take
|
|
|
|
* CCP down or issue a Reset-Req.
|
|
|
|
*/
|
|
|
|
if (sc->sc_flags & SC_DEBUG)
|
2002-09-24 17:37:32 +00:00
|
|
|
if_printf(ifp, "decompress failed %d\n", rv);
|
1995-10-31 20:24:14 +00:00
|
|
|
s = splimp();
|
|
|
|
sc->sc_flags |= SC_VJ_RESET;
|
|
|
|
if (rv == DECOMP_ERROR)
|
|
|
|
sc->sc_flags |= SC_DC_ERROR;
|
|
|
|
else
|
|
|
|
sc->sc_flags |= SC_DC_FERROR;
|
|
|
|
splx(s);
|
|
|
|
}
|
1994-09-23 00:10:32 +00:00
|
|
|
|
1995-10-31 20:24:14 +00:00
|
|
|
} else {
|
|
|
|
if (sc->sc_rc_state && (sc->sc_flags & SC_DECOMP_RUN)) {
|
|
|
|
(*sc->sc_rcomp->incomp)(sc->sc_rc_state, m);
|
|
|
|
}
|
|
|
|
if (proto == PPP_CCP) {
|
|
|
|
ppp_ccp(sc, m, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-09-18 19:44:14 +00:00
|
|
|
ilen = m_length(m, NULL);
|
1994-09-23 00:10:32 +00:00
|
|
|
|
|
|
|
#ifdef VJC
|
1995-10-31 20:24:14 +00:00
|
|
|
if (sc->sc_flags & SC_VJ_RESET) {
|
|
|
|
/*
|
|
|
|
* If we've missed a packet, we must toss subsequent compressed
|
|
|
|
* packets which don't have an explicit connection ID.
|
|
|
|
*/
|
1997-08-19 14:10:50 +00:00
|
|
|
if (sc->sc_comp)
|
|
|
|
sl_uncompress_tcp(NULL, 0, TYPE_ERROR, sc->sc_comp);
|
1995-10-31 20:24:14 +00:00
|
|
|
s = splimp();
|
|
|
|
sc->sc_flags &= ~SC_VJ_RESET;
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
1994-09-23 00:10:32 +00:00
|
|
|
/*
|
|
|
|
* See if we have a VJ-compressed packet to uncompress.
|
|
|
|
*/
|
1995-10-31 20:24:14 +00:00
|
|
|
if (proto == PPP_VJC_COMP) {
|
1997-08-19 14:10:50 +00:00
|
|
|
if ((sc->sc_flags & SC_REJ_COMP_TCP) || sc->sc_comp == 0)
|
1995-10-31 20:24:14 +00:00
|
|
|
goto bad;
|
|
|
|
|
|
|
|
xlen = sl_uncompress_tcp_core(cp + PPP_HDRLEN, m->m_len - PPP_HDRLEN,
|
|
|
|
ilen - PPP_HDRLEN, TYPE_COMPRESSED_TCP,
|
1997-08-19 14:10:50 +00:00
|
|
|
sc->sc_comp, &iphdr, &hlen);
|
1994-09-23 00:10:32 +00:00
|
|
|
|
1995-10-31 20:24:14 +00:00
|
|
|
if (xlen <= 0) {
|
1994-09-23 00:10:32 +00:00
|
|
|
if (sc->sc_flags & SC_DEBUG)
|
2002-09-24 17:37:32 +00:00
|
|
|
if_printf(ifp, "VJ uncompress failed on type comp\n");
|
1995-10-31 20:24:14 +00:00
|
|
|
goto bad;
|
1994-09-23 00:10:32 +00:00
|
|
|
}
|
|
|
|
|
1995-10-31 20:24:14 +00:00
|
|
|
/* Copy the PPP and IP headers into a new mbuf. */
|
2003-02-19 05:47:46 +00:00
|
|
|
MGETHDR(mp, M_DONTWAIT, MT_DATA);
|
1995-10-31 20:24:14 +00:00
|
|
|
if (mp == NULL)
|
|
|
|
goto bad;
|
|
|
|
mp->m_len = 0;
|
|
|
|
mp->m_next = NULL;
|
|
|
|
if (hlen + PPP_HDRLEN > MHLEN) {
|
2003-02-19 05:47:46 +00:00
|
|
|
MCLGET(mp, M_DONTWAIT);
|
1995-10-31 20:24:14 +00:00
|
|
|
if (M_TRAILINGSPACE(mp) < hlen + PPP_HDRLEN) {
|
|
|
|
m_freem(mp);
|
|
|
|
goto bad; /* lose if big headers and no clusters */
|
|
|
|
}
|
|
|
|
}
|
2002-08-01 21:13:47 +00:00
|
|
|
#ifdef MAC
|
|
|
|
mac_create_mbuf_from_mbuf(m, mp);
|
|
|
|
#endif
|
1995-10-31 20:24:14 +00:00
|
|
|
cp = mtod(mp, u_char *);
|
|
|
|
cp[0] = adrs;
|
|
|
|
cp[1] = ctrl;
|
|
|
|
cp[2] = 0;
|
|
|
|
cp[3] = PPP_IP;
|
|
|
|
proto = PPP_IP;
|
|
|
|
bcopy(iphdr, cp + PPP_HDRLEN, hlen);
|
|
|
|
mp->m_len = hlen + PPP_HDRLEN;
|
1994-09-23 00:10:32 +00:00
|
|
|
|
1995-10-31 20:24:14 +00:00
|
|
|
/*
|
|
|
|
* Trim the PPP and VJ headers off the old mbuf
|
|
|
|
* and stick the new and old mbufs together.
|
|
|
|
*/
|
|
|
|
m->m_data += PPP_HDRLEN + xlen;
|
|
|
|
m->m_len -= PPP_HDRLEN + xlen;
|
|
|
|
if (m->m_len <= M_TRAILINGSPACE(mp)) {
|
|
|
|
bcopy(mtod(m, u_char *), mtod(mp, u_char *) + mp->m_len, m->m_len);
|
|
|
|
mp->m_len += m->m_len;
|
2002-02-05 02:00:56 +00:00
|
|
|
mp->m_next = m_free(m);
|
|
|
|
} else {
|
1995-10-31 20:24:14 +00:00
|
|
|
mp->m_next = m;
|
2002-02-05 02:00:56 +00:00
|
|
|
}
|
1995-10-31 20:24:14 +00:00
|
|
|
m = mp;
|
|
|
|
ilen += hlen - xlen;
|
|
|
|
|
|
|
|
} else if (proto == PPP_VJC_UNCOMP) {
|
1997-08-19 14:10:50 +00:00
|
|
|
if ((sc->sc_flags & SC_REJ_COMP_TCP) || sc->sc_comp == 0)
|
1995-10-31 20:24:14 +00:00
|
|
|
goto bad;
|
|
|
|
|
|
|
|
xlen = sl_uncompress_tcp_core(cp + PPP_HDRLEN, m->m_len - PPP_HDRLEN,
|
|
|
|
ilen - PPP_HDRLEN, TYPE_UNCOMPRESSED_TCP,
|
1997-08-19 14:10:50 +00:00
|
|
|
sc->sc_comp, &iphdr, &hlen);
|
1995-10-31 20:24:14 +00:00
|
|
|
|
|
|
|
if (xlen < 0) {
|
1994-09-23 00:10:32 +00:00
|
|
|
if (sc->sc_flags & SC_DEBUG)
|
2002-09-24 17:37:32 +00:00
|
|
|
if_printf(ifp, "VJ uncompress failed on type uncomp\n");
|
1995-10-31 20:24:14 +00:00
|
|
|
goto bad;
|
1994-09-23 00:10:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
proto = PPP_IP;
|
1995-10-31 20:24:14 +00:00
|
|
|
cp[3] = PPP_IP;
|
1994-09-23 00:10:32 +00:00
|
|
|
}
|
|
|
|
#endif /* VJC */
|
|
|
|
|
1995-10-31 20:24:14 +00:00
|
|
|
/*
|
|
|
|
* If the packet will fit in a header mbuf, don't waste a
|
|
|
|
* whole cluster on it.
|
|
|
|
*/
|
|
|
|
if (ilen <= MHLEN && M_IS_CLUSTER(m)) {
|
2003-02-19 05:47:46 +00:00
|
|
|
MGETHDR(mp, M_DONTWAIT, MT_DATA);
|
1995-10-31 20:24:14 +00:00
|
|
|
if (mp != NULL) {
|
2002-08-01 21:13:47 +00:00
|
|
|
#ifdef MAC
|
|
|
|
mac_create_mbuf_from_mbuf(m, mp);
|
|
|
|
#endif
|
1995-10-31 20:24:14 +00:00
|
|
|
m_copydata(m, 0, ilen, mtod(mp, caddr_t));
|
|
|
|
m_freem(m);
|
|
|
|
m = mp;
|
|
|
|
m->m_len = ilen;
|
|
|
|
}
|
1994-09-23 00:10:32 +00:00
|
|
|
}
|
|
|
|
m->m_pkthdr.len = ilen;
|
1997-08-19 14:10:50 +00:00
|
|
|
m->m_pkthdr.rcvif = ifp;
|
|
|
|
|
|
|
|
if ((proto & 0x8000) == 0) {
|
1997-10-18 00:46:10 +00:00
|
|
|
#ifdef PPP_FILTER
|
1997-08-19 14:10:50 +00:00
|
|
|
/*
|
|
|
|
* See whether we want to pass this packet, and
|
|
|
|
* if it counts as link activity.
|
|
|
|
*/
|
|
|
|
adrs = *mtod(m, u_char *); /* save address field */
|
|
|
|
*mtod(m, u_char *) = 0; /* indicate inbound */
|
|
|
|
if (sc->sc_pass_filt.bf_insns != 0
|
|
|
|
&& bpf_filter(sc->sc_pass_filt.bf_insns, (u_char *) m,
|
|
|
|
ilen, 0) == 0) {
|
|
|
|
/* drop this packet */
|
|
|
|
m_freem(m);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (sc->sc_active_filt.bf_insns == 0
|
|
|
|
|| bpf_filter(sc->sc_active_filt.bf_insns, (u_char *) m, ilen, 0))
|
1998-03-30 09:56:58 +00:00
|
|
|
sc->sc_last_recv = time_second;
|
1997-08-19 14:10:50 +00:00
|
|
|
|
|
|
|
*mtod(m, u_char *) = adrs;
|
|
|
|
#else
|
|
|
|
/*
|
|
|
|
* Record the time that we received this packet.
|
|
|
|
*/
|
1998-03-30 09:56:58 +00:00
|
|
|
sc->sc_last_recv = time_second;
|
1997-10-18 00:46:10 +00:00
|
|
|
#endif /* PPP_FILTER */
|
1997-08-19 14:10:50 +00:00
|
|
|
}
|
1994-09-23 00:10:32 +00:00
|
|
|
|
|
|
|
/* See if bpf wants to look at the packet. */
|
2002-11-15 00:00:15 +00:00
|
|
|
BPF_MTAP(&sc->sc_if, m);
|
1994-09-23 00:10:32 +00:00
|
|
|
|
2003-03-04 23:19:55 +00:00
|
|
|
isr = -1;
|
1994-09-23 00:10:32 +00:00
|
|
|
switch (proto) {
|
|
|
|
#ifdef INET
|
|
|
|
case PPP_IP:
|
|
|
|
/*
|
|
|
|
* IP packet - take off the ppp header and pass it up to IP.
|
|
|
|
*/
|
1997-08-19 14:10:50 +00:00
|
|
|
if ((ifp->if_flags & IFF_UP) == 0
|
1995-10-31 20:24:14 +00:00
|
|
|
|| sc->sc_npmode[NP_IP] != NPMODE_PASS) {
|
1994-09-23 00:10:32 +00:00
|
|
|
/* interface is down - drop the packet. */
|
|
|
|
m_freem(m);
|
1995-10-31 20:24:14 +00:00
|
|
|
return;
|
1994-09-23 00:10:32 +00:00
|
|
|
}
|
|
|
|
m->m_pkthdr.len -= PPP_HDRLEN;
|
|
|
|
m->m_data += PPP_HDRLEN;
|
|
|
|
m->m_len -= PPP_HDRLEN;
|
2003-11-14 21:02:22 +00:00
|
|
|
if (ip_fastforward(m))
|
1998-05-19 14:04:36 +00:00
|
|
|
return;
|
2003-03-04 23:19:55 +00:00
|
|
|
isr = NETISR_IP;
|
1994-09-23 00:10:32 +00:00
|
|
|
break;
|
|
|
|
#endif
|
1995-11-13 22:09:39 +00:00
|
|
|
#ifdef IPX
|
|
|
|
case PPP_IPX:
|
|
|
|
/*
|
|
|
|
* IPX packet - take off the ppp header and pass it up to IPX.
|
|
|
|
*/
|
|
|
|
if ((sc->sc_if.if_flags & IFF_UP) == 0
|
|
|
|
/* XXX: || sc->sc_npmode[NP_IPX] != NPMODE_PASS*/) {
|
|
|
|
/* interface is down - drop the packet. */
|
|
|
|
m_freem(m);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m->m_pkthdr.len -= PPP_HDRLEN;
|
|
|
|
m->m_data += PPP_HDRLEN;
|
|
|
|
m->m_len -= PPP_HDRLEN;
|
2003-03-04 23:19:55 +00:00
|
|
|
isr = NETISR_IPX;
|
1998-03-30 09:56:58 +00:00
|
|
|
sc->sc_last_recv = time_second; /* update time of last pkt rcvd */
|
1995-11-13 22:09:39 +00:00
|
|
|
break;
|
|
|
|
#endif
|
1994-09-23 00:10:32 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
/*
|
|
|
|
* Some other protocol - place on input queue for read().
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-03-04 23:19:55 +00:00
|
|
|
if (isr == -1)
|
|
|
|
rv = IF_HANDOFF(&sc->sc_inq, m, NULL);
|
|
|
|
else
|
|
|
|
rv = netisr_queue(isr, m);
|
2003-03-27 12:52:57 +00:00
|
|
|
if (!rv) {
|
1994-09-23 00:10:32 +00:00
|
|
|
if (sc->sc_flags & SC_DEBUG)
|
2002-09-24 17:37:32 +00:00
|
|
|
if_printf(ifp, "input queue full\n");
|
1997-08-19 14:10:50 +00:00
|
|
|
ifp->if_iqdrops++;
|
2004-04-15 19:11:34 +00:00
|
|
|
m = NULL;
|
1995-10-31 20:24:14 +00:00
|
|
|
goto bad;
|
1994-09-23 00:10:32 +00:00
|
|
|
}
|
1997-08-19 14:10:50 +00:00
|
|
|
ifp->if_ipackets++;
|
|
|
|
ifp->if_ibytes += ilen;
|
1998-03-30 09:56:58 +00:00
|
|
|
getmicrotime(&ifp->if_lastchange);
|
1994-11-27 15:29:57 +00:00
|
|
|
|
2003-03-04 23:19:55 +00:00
|
|
|
if (isr == -1)
|
1995-10-31 20:24:14 +00:00
|
|
|
(*sc->sc_ctlp)(sc);
|
1994-09-23 00:10:32 +00:00
|
|
|
|
1995-10-31 20:24:14 +00:00
|
|
|
return;
|
1994-09-23 00:10:32 +00:00
|
|
|
|
1995-10-31 20:24:14 +00:00
|
|
|
bad:
|
Lock down the network interface queues. The queue mutex must be obtained
before adding/removing packets from the queue. Also, the if_obytes and
if_omcasts fields should only be manipulated under protection of the mutex.
IF_ENQUEUE, IF_PREPEND, and IF_DEQUEUE perform all necessary locking on
the queue. An IF_LOCK macro is provided, as well as the old (mutex-less)
versions of the macros in the form _IF_ENQUEUE, _IF_QFULL, for code which
needs them, but their use is discouraged.
Two new macros are introduced: IF_DRAIN() to drain a queue, and IF_HANDOFF,
which takes care of locking/enqueue, and also statistics updating/start
if necessary.
2000-11-25 07:35:38 +00:00
|
|
|
if (m)
|
|
|
|
m_freem(m);
|
1995-10-31 20:24:14 +00:00
|
|
|
sc->sc_if.if_ierrors++;
|
1997-08-19 14:10:50 +00:00
|
|
|
sc->sc_stats.ppp_ierrors++;
|
1994-09-23 00:10:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define MAX_DUMP_BYTES 128
|
|
|
|
|
|
|
|
static void
|
1995-10-31 20:24:14 +00:00
|
|
|
pppdumpm(m0)
|
1994-09-23 00:10:32 +00:00
|
|
|
struct mbuf *m0;
|
|
|
|
{
|
|
|
|
char buf[3*MAX_DUMP_BYTES+4];
|
|
|
|
char *bp = buf;
|
|
|
|
struct mbuf *m;
|
|
|
|
|
1995-10-31 20:24:14 +00:00
|
|
|
for (m = m0; m; m = m->m_next) {
|
1994-09-23 00:10:32 +00:00
|
|
|
int l = m->m_len;
|
|
|
|
u_char *rptr = (u_char *)m->m_data;
|
|
|
|
|
|
|
|
while (l--) {
|
2003-02-02 18:15:28 +00:00
|
|
|
if (bp > buf + (sizeof(buf) - 4))
|
1994-09-23 00:10:32 +00:00
|
|
|
goto done;
|
1996-01-24 21:12:23 +00:00
|
|
|
*bp++ = hex2ascii(*rptr >> 4);
|
|
|
|
*bp++ = hex2ascii(*rptr++ & 0xf);
|
1994-09-23 00:10:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (m->m_next) {
|
2003-02-02 18:15:28 +00:00
|
|
|
if (bp > buf + (sizeof(buf) - 3))
|
1994-09-23 00:10:32 +00:00
|
|
|
goto done;
|
|
|
|
*bp++ = '|';
|
|
|
|
} else
|
|
|
|
*bp++ = ' ';
|
|
|
|
}
|
|
|
|
done:
|
1995-10-31 20:24:14 +00:00
|
|
|
if (m)
|
1994-09-23 00:10:32 +00:00
|
|
|
*bp++ = '>';
|
|
|
|
*bp = 0;
|
|
|
|
printf("%s\n", buf);
|
|
|
|
}
|