2001-01-05 15:49:52 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1997, 2000 Hellmuth Michaelis. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
*---------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* i4b_ipr.c - isdn4bsd IP over raw HDLC ISDN network driver
|
|
|
|
* ---------------------------------------------------------
|
|
|
|
*
|
2010-04-05 11:19:28 +04:00
|
|
|
* $Id: i4b_ipr.c,v 1.35 2010/04/05 07:22:50 joerg Exp $
|
2001-01-05 15:49:52 +03:00
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*
|
|
|
|
* last edit-date: [Fri Jan 5 11:33:47 2001]
|
|
|
|
*
|
|
|
|
*---------------------------------------------------------------------------*
|
|
|
|
*
|
|
|
|
* statistics counter usage (interface lifetime):
|
|
|
|
* ----------------------------------------------
|
|
|
|
* sc->sc_if.if_ipackets # of received packets
|
|
|
|
* sc->sc_if.if_ierrors # of error packets not going to upper layers
|
|
|
|
* sc->sc_if.if_opackets # of transmitted packets
|
|
|
|
* sc->sc_if.if_oerrors # of error packets not being transmitted
|
|
|
|
* sc->sc_if.if_collisions # of invalid ip packets after VJ decompression
|
|
|
|
* sc->sc_if.if_ibytes # of bytes coming in from the line (before VJ)
|
|
|
|
* sc->sc_if.if_obytes # of bytes going out to the line (after VJ)
|
|
|
|
* sc->sc_if.if_imcasts (currently unused)
|
|
|
|
* sc->sc_if.if_omcasts # of frames sent out of the fastqueue
|
|
|
|
* sc->sc_if.if_iqdrops # of frames dropped on input because queue full
|
|
|
|
* sc->sc_if.if_noproto # of frames dropped on output because !AF_INET
|
|
|
|
*
|
|
|
|
* statistics counter usage (connection lifetime):
|
|
|
|
* -----------------------------------------------
|
|
|
|
* sc->sc_iinb # of ISDN incoming bytes from HSCX
|
|
|
|
* sc->sc_ioutb # of ISDN outgoing bytes from HSCX
|
|
|
|
* sc->sc_inb # of incoming bytes after decompression
|
|
|
|
* sc->sc_outb # of outgoing bytes before compression
|
|
|
|
*
|
2005-02-27 01:31:44 +03:00
|
|
|
*---------------------------------------------------------------------------*/
|
2001-01-05 15:49:52 +03:00
|
|
|
|
2001-11-13 03:56:55 +03:00
|
|
|
#include <sys/cdefs.h>
|
2010-04-05 11:19:28 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: i4b_ipr.c,v 1.35 2010/04/05 07:22:50 joerg Exp $");
|
2001-11-13 03:56:55 +03:00
|
|
|
|
2002-03-16 19:55:51 +03:00
|
|
|
#include "irip.h"
|
2003-04-11 18:45:27 +04:00
|
|
|
#include "opt_irip.h"
|
2001-01-05 15:49:52 +03:00
|
|
|
|
2002-03-16 19:55:51 +03:00
|
|
|
#if NIRIP > 0
|
2001-01-05 15:49:52 +03:00
|
|
|
|
|
|
|
#ifdef __FreeBSD__
|
|
|
|
#include "opt_i4b.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#if defined(__FreeBSD__) && __FreeBSD__ >= 3
|
|
|
|
#include <sys/ioccom.h>
|
|
|
|
#include <sys/sockio.h>
|
|
|
|
#ifdef IPR_VJ
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__NetBSD__) && __NetBSD_Version__ >= 104230000
|
|
|
|
#include <sys/callout.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/protosw.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_types.h>
|
|
|
|
#include <net/netisr.h>
|
|
|
|
#include <net/route.h>
|
|
|
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/in_var.h>
|
|
|
|
#include <netinet/ip.h>
|
|
|
|
|
2003-04-11 18:45:27 +04:00
|
|
|
#ifdef IRIP_VJ
|
2005-02-27 01:31:44 +03:00
|
|
|
#include <net/slcompress.h>
|
2001-01-05 15:49:52 +03:00
|
|
|
#define IPR_COMPRESS IFF_LINK0 /* compress TCP traffic */
|
|
|
|
#define IPR_AUTOCOMP IFF_LINK1 /* auto-enable TCP compression */
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------
|
|
|
|
* NOTICE: using NO separate buffer relies on the assumption, that the HSCX
|
|
|
|
* IRQ handler _always_ allocates a single, continuous mbuf cluster large
|
|
|
|
* enough to hold the maximum MTU size if the ipr interface !
|
|
|
|
*
|
|
|
|
* CAUTION: i have re-defined IPR_VJ_USEBUFFER because it makes problems
|
|
|
|
* with 2 i4b's back to back running cvs over ssh, cvs simply
|
|
|
|
* aborts because it gets bad data. Everything else (telnet/ftp?etc)
|
2005-02-27 01:31:44 +03:00
|
|
|
* functions fine.
|
2001-01-05 15:49:52 +03:00
|
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
#define IPR_VJ_USEBUFFER /* define to use an allocated separate buffer*/
|
|
|
|
/* undef to uncompress in the mbuf itself */
|
2003-04-11 18:45:27 +04:00
|
|
|
#endif /* IRIP_VJ */
|
2001-01-05 15:49:52 +03:00
|
|
|
|
|
|
|
#if defined(__FreeBSD_version) && __FreeBSD_version >= 400008
|
|
|
|
#include "bpf.h"
|
|
|
|
#else
|
2010-01-20 01:08:16 +03:00
|
|
|
#define NBPFILTER 1
|
2001-01-05 15:49:52 +03:00
|
|
|
#endif
|
|
|
|
#if NBPFILTER > 0 || NBPF > 0
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <net/bpf.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __FreeBSD__
|
|
|
|
#include <machine/i4b_ioctl.h>
|
|
|
|
#include <machine/i4b_debug.h>
|
|
|
|
#else
|
|
|
|
#include <netisdn/i4b_debug.h>
|
|
|
|
#include <netisdn/i4b_ioctl.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <netisdn/i4b_global.h>
|
|
|
|
#include <netisdn/i4b_mbuf.h>
|
|
|
|
#include <netisdn/i4b_l3l4.h>
|
|
|
|
|
|
|
|
#include <netisdn/i4b_l4.h>
|
|
|
|
|
|
|
|
#ifndef __FreeBSD__
|
2007-10-19 15:59:34 +04:00
|
|
|
#include <sys/cpu.h> /* For softnet */
|
2001-01-05 15:49:52 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __FreeBSD__
|
2002-03-16 19:55:51 +03:00
|
|
|
#define IPR_FMT "irip%d: "
|
2001-01-05 15:49:52 +03:00
|
|
|
#define IPR_ARG(sc) ((sc)->sc_if.if_unit)
|
|
|
|
#define PDEVSTATIC static
|
|
|
|
#elif defined(__bsdi__)
|
2002-03-16 19:55:51 +03:00
|
|
|
#define IPR_FMT "irip%d: "
|
2001-01-05 15:49:52 +03:00
|
|
|
#define IPR_ARG(sc) ((sc)->sc_if.if_unit)
|
|
|
|
#define PDEVSTATIC /* not static */
|
|
|
|
#else
|
|
|
|
#define IPR_FMT "%s: "
|
|
|
|
#define IPR_ARG(sc) ((sc)->sc_if.if_xname)
|
|
|
|
#define PDEVSTATIC /* not static */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define I4BIPRMTU 1500 /* regular MTU */
|
|
|
|
#define I4BIPRMAXMTU 2000 /* max MTU */
|
|
|
|
#define I4BIPRMINMTU 500 /* min MTU */
|
|
|
|
|
|
|
|
#define I4BIPRMAXQLEN 50 /* max queue length */
|
|
|
|
|
|
|
|
#define I4BIPRACCT 1 /* enable accounting messages */
|
|
|
|
#define I4BIPRACCTINTVL 2 /* accounting msg interval in secs */
|
|
|
|
#define I4BIPRADJFRXP 1 /* adjust 1st rxd packet */
|
|
|
|
|
|
|
|
|
|
|
|
struct ipr_softc {
|
|
|
|
struct ifnet sc_if; /* network-visible interface */
|
|
|
|
int sc_state; /* state of the interface */
|
|
|
|
|
|
|
|
call_desc_t *sc_cdp; /* ptr to call descriptor */
|
2002-03-17 23:54:04 +03:00
|
|
|
isdn_link_t *sc_ilt; /* ptr to B channel driver/state */
|
|
|
|
|
|
|
|
int sc_unit; /* which instance are we? */
|
2001-01-05 15:49:52 +03:00
|
|
|
int sc_updown; /* soft state of interface */
|
|
|
|
struct ifqueue sc_fastq; /* interactive traffic */
|
|
|
|
int sc_dialresp; /* dialresponse */
|
|
|
|
int sc_lastdialresp;/* last dialresponse */
|
2005-02-27 01:31:44 +03:00
|
|
|
|
2001-01-05 15:49:52 +03:00
|
|
|
#if I4BIPRACCT
|
|
|
|
int sc_iinb; /* isdn driver # of inbytes */
|
|
|
|
int sc_ioutb; /* isdn driver # of outbytes */
|
|
|
|
int sc_inb; /* # of bytes rx'd */
|
|
|
|
int sc_outb; /* # of bytes tx'd */
|
|
|
|
int sc_linb; /* last # of bytes rx'd */
|
|
|
|
int sc_loutb; /* last # of bytes tx'd */
|
|
|
|
int sc_fn; /* flag, first null acct */
|
2005-02-27 01:31:44 +03:00
|
|
|
#endif
|
2001-01-05 15:49:52 +03:00
|
|
|
|
|
|
|
#if defined(__NetBSD__) && __NetBSD_Version__ >= 104230000
|
|
|
|
struct callout sc_callout;
|
|
|
|
#endif
|
|
|
|
#if defined(__FreeBSD__)
|
|
|
|
struct callout_handle sc_callout;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef I4BIPRADJFRXP
|
|
|
|
int sc_first_pkt; /* flag, first rxd packet */
|
|
|
|
#endif
|
|
|
|
#if IPR_LOG
|
|
|
|
int sc_log_first; /* log first n packets */
|
|
|
|
#endif
|
|
|
|
|
2003-04-11 18:45:27 +04:00
|
|
|
#ifdef IRIP_VJ
|
2001-01-05 15:49:52 +03:00
|
|
|
struct slcompress sc_compr; /* tcp compression data */
|
|
|
|
#ifdef IPR_VJ_USEBUFFER
|
|
|
|
u_char *sc_cbuf; /* tcp decompression buffer */
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2002-03-16 19:55:51 +03:00
|
|
|
} ipr_softc[NIRIP];
|
2001-01-05 15:49:52 +03:00
|
|
|
|
|
|
|
enum ipr_states {
|
|
|
|
ST_IDLE, /* initialized, ready, idle */
|
|
|
|
ST_DIALING, /* dialling out to remote */
|
|
|
|
ST_CONNECTED_W, /* connected to remote */
|
|
|
|
ST_CONNECTED_A, /* connected to remote */
|
|
|
|
};
|
|
|
|
|
|
|
|
#if defined(__FreeBSD__) || defined(__bsdi__)
|
|
|
|
#define THE_UNIT sc->sc_if.if_unit
|
|
|
|
#else
|
|
|
|
#define THE_UNIT sc->sc_unit
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __FreeBSD__
|
|
|
|
#if defined(__FreeBSD_version) && __FreeBSD_version >= 300001
|
|
|
|
# define IOCTL_CMD_T u_long
|
|
|
|
#else
|
|
|
|
#ifdef __NetBSD__
|
|
|
|
# define IOCTL_CMD_T u_long
|
|
|
|
#else
|
|
|
|
# define IOCTL_CMD_T int
|
|
|
|
#endif
|
|
|
|
#endif
|
2002-03-16 19:55:51 +03:00
|
|
|
PDEVSTATIC void iripattach(void *);
|
|
|
|
PSEUDO_SET(iripattach, i4b_ipr);
|
2007-03-04 08:59:00 +03:00
|
|
|
static int irpioctl(struct ifnet *ifp, IOCTL_CMD_T cmd, void *data);
|
2001-01-05 15:49:52 +03:00
|
|
|
#else
|
2009-03-14 17:45:51 +03:00
|
|
|
PDEVSTATIC void iripattach(void);
|
2007-03-04 08:59:00 +03:00
|
|
|
static int iripioctl(struct ifnet *ifp, u_long cmd, void *data);
|
2001-01-05 15:49:52 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __bsdi__
|
|
|
|
static int iprwatchdog(int unit);
|
|
|
|
#else
|
|
|
|
static void iprwatchdog(struct ifnet *ifp);
|
|
|
|
#endif
|
2002-03-17 12:45:58 +03:00
|
|
|
static void ipr_tx_queue_empty(void *);
|
2007-02-20 10:43:28 +03:00
|
|
|
static int iripoutput(struct ifnet *ifp, struct mbuf *m, const struct sockaddr *dst, struct rtentry *rtp);
|
2002-03-16 19:55:51 +03:00
|
|
|
static void iripclearqueues(struct ipr_softc *sc);
|
2002-03-17 23:54:04 +03:00
|
|
|
static void ipr_set_linktab(void *softc, isdn_link_t *ilt);
|
|
|
|
static void ipr_activity(void *softc, int rxtx);
|
|
|
|
static void ipr_rx_data_rdy(void *softc);
|
|
|
|
static void ipr_disconnect(void *softc, void *cdp);
|
|
|
|
static void ipr_connect(void *softc, void *cdp);
|
|
|
|
static void ipr_dialresponse(void *softc, int status, cause_t cause);
|
|
|
|
static void ipr_updown(void *softc, int updown);
|
|
|
|
static void* ipr_get_softc(int unit);
|
|
|
|
|
|
|
|
static const struct isdn_l4_driver_functions
|
|
|
|
ipr_l4_functions = {
|
|
|
|
ipr_rx_data_rdy,
|
|
|
|
ipr_tx_queue_empty,
|
|
|
|
ipr_activity,
|
|
|
|
ipr_connect,
|
|
|
|
ipr_disconnect,
|
|
|
|
ipr_dialresponse,
|
|
|
|
ipr_updown,
|
|
|
|
ipr_get_softc,
|
|
|
|
ipr_set_linktab,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static int irip_driver_id = -1;
|
2001-01-05 15:49:52 +03:00
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* DEVICE DRIVER ROUTINES
|
|
|
|
*===========================================================================*/
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* interface attach routine at kernel boot time
|
|
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
PDEVSTATIC void
|
|
|
|
#ifdef __FreeBSD__
|
2002-03-16 19:55:51 +03:00
|
|
|
iripattach(void *dummy)
|
2001-01-05 15:49:52 +03:00
|
|
|
#else
|
2009-03-18 13:22:21 +03:00
|
|
|
iripattach(void)
|
2001-01-05 15:49:52 +03:00
|
|
|
#endif
|
|
|
|
{
|
|
|
|
struct ipr_softc *sc = ipr_softc;
|
|
|
|
int i;
|
2002-03-17 23:54:04 +03:00
|
|
|
|
|
|
|
irip_driver_id = isdn_l4_driver_attach("irip", NIRIP, &ipr_l4_functions);
|
2005-02-27 01:31:44 +03:00
|
|
|
|
2002-03-16 19:55:51 +03:00
|
|
|
for(i=0; i < NIRIP; sc++, i++)
|
2001-01-05 15:49:52 +03:00
|
|
|
{
|
|
|
|
NDBGL4(L4_DIALST, "setting dial state to ST_IDLE");
|
|
|
|
|
|
|
|
sc->sc_state = ST_IDLE;
|
2002-03-17 23:54:04 +03:00
|
|
|
sc->sc_unit = i;
|
2005-02-27 01:31:44 +03:00
|
|
|
|
|
|
|
#ifdef __FreeBSD__
|
2002-03-16 19:55:51 +03:00
|
|
|
sc->sc_if.if_name = "irip";
|
2001-01-05 15:49:52 +03:00
|
|
|
#if __FreeBSD__ < 3
|
|
|
|
sc->sc_if.if_next = NULL;
|
|
|
|
#endif
|
|
|
|
sc->sc_if.if_unit = i;
|
|
|
|
#elif defined(__bsdi__)
|
2002-03-16 19:55:51 +03:00
|
|
|
sc->sc_if.if_name = "irip";
|
2001-01-05 15:49:52 +03:00
|
|
|
sc->sc_if.if_unit = i;
|
|
|
|
#else
|
2004-04-21 22:40:37 +04:00
|
|
|
snprintf(sc->sc_if.if_xname, sizeof(sc->sc_if.if_xname),
|
|
|
|
"irip%d", i);
|
2001-01-05 15:49:52 +03:00
|
|
|
sc->sc_if.if_softc = sc;
|
|
|
|
#endif
|
|
|
|
|
2003-04-11 18:45:27 +04:00
|
|
|
#ifdef IRIP_VJ
|
2001-01-05 15:49:52 +03:00
|
|
|
sc->sc_if.if_flags = IFF_POINTOPOINT | IFF_SIMPLEX | IPR_AUTOCOMP;
|
|
|
|
#else
|
|
|
|
sc->sc_if.if_flags = IFF_POINTOPOINT | IFF_SIMPLEX;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__NetBSD__) && __NetBSD_Version__ >= 104230000
|
2007-07-10 00:51:58 +04:00
|
|
|
callout_init(&sc->sc_callout, 0);
|
2001-01-05 15:49:52 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
sc->sc_if.if_mtu = I4BIPRMTU;
|
|
|
|
sc->sc_if.if_type = IFT_ISDNBASIC;
|
2002-03-16 19:55:51 +03:00
|
|
|
sc->sc_if.if_ioctl = iripioctl;
|
|
|
|
sc->sc_if.if_output = iripoutput;
|
2001-01-05 15:49:52 +03:00
|
|
|
|
2001-02-03 21:43:45 +03:00
|
|
|
IFQ_SET_MAXLEN(&sc->sc_if.if_snd, I4BIPRMAXQLEN);
|
2001-01-05 15:49:52 +03:00
|
|
|
sc->sc_fastq.ifq_maxlen = I4BIPRMAXQLEN;
|
2001-02-03 21:43:45 +03:00
|
|
|
IFQ_SET_READY(&sc->sc_if.if_snd);
|
2005-02-27 01:31:44 +03:00
|
|
|
|
2001-01-05 15:49:52 +03:00
|
|
|
sc->sc_if.if_ipackets = 0;
|
|
|
|
sc->sc_if.if_ierrors = 0;
|
|
|
|
sc->sc_if.if_opackets = 0;
|
|
|
|
sc->sc_if.if_oerrors = 0;
|
|
|
|
sc->sc_if.if_collisions = 0;
|
|
|
|
sc->sc_if.if_ibytes = 0;
|
|
|
|
sc->sc_if.if_obytes = 0;
|
|
|
|
sc->sc_if.if_imcasts = 0;
|
|
|
|
sc->sc_if.if_omcasts = 0;
|
|
|
|
sc->sc_if.if_iqdrops = 0;
|
|
|
|
sc->sc_if.if_noproto = 0;
|
|
|
|
|
|
|
|
#if I4BIPRACCT
|
2005-02-27 01:31:44 +03:00
|
|
|
sc->sc_if.if_timer = 0;
|
|
|
|
sc->sc_if.if_watchdog = iprwatchdog;
|
2001-01-05 15:49:52 +03:00
|
|
|
sc->sc_iinb = 0;
|
|
|
|
sc->sc_ioutb = 0;
|
|
|
|
sc->sc_inb = 0;
|
|
|
|
sc->sc_outb = 0;
|
|
|
|
sc->sc_linb = 0;
|
|
|
|
sc->sc_loutb = 0;
|
|
|
|
sc->sc_fn = 1;
|
|
|
|
#endif
|
|
|
|
#if IPR_LOG
|
|
|
|
sc->sc_log_first = IPR_LOG;
|
|
|
|
#endif
|
|
|
|
|
2003-04-11 18:45:27 +04:00
|
|
|
#ifdef IRIP_VJ
|
2001-01-05 15:49:52 +03:00
|
|
|
#ifdef __FreeBSD__
|
|
|
|
sl_compress_init(&sc->sc_compr, -1);
|
|
|
|
#else
|
|
|
|
sl_compress_init(&sc->sc_compr);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef IPR_VJ_USEBUFFER
|
|
|
|
if(!((sc->sc_cbuf =
|
|
|
|
(u_char *)malloc(I4BIPRMAXMTU+128, M_DEVBUF, M_WAITOK))))
|
|
|
|
{
|
|
|
|
panic("if_ipr.c, ipr_attach: VJ malloc failed");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
sc->sc_updown = SOFT_ENA; /* soft enabled */
|
|
|
|
|
|
|
|
sc->sc_dialresp = DSTAT_NONE; /* no response */
|
|
|
|
sc->sc_lastdialresp = DSTAT_NONE;
|
2005-02-27 01:31:44 +03:00
|
|
|
|
2001-01-05 15:49:52 +03:00
|
|
|
#if defined(__FreeBSD_version) && ((__FreeBSD_version >= 500009) || (410000 <= __FreeBSD_version && __FreeBSD_version < 500000))
|
|
|
|
/* do not call bpfattach in ether_ifattach */
|
|
|
|
ether_ifattach(&sc->sc_if, 0);
|
|
|
|
#else
|
|
|
|
if_attach(&sc->sc_if);
|
2001-01-17 03:30:49 +03:00
|
|
|
if_alloc_sadl(&sc->sc_if);
|
2001-01-05 15:49:52 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if NBPFILTER > 0 || NBPF > 0
|
|
|
|
#ifdef __FreeBSD__
|
|
|
|
bpfattach(&sc->sc_if, DLT_NULL, sizeof(u_int));
|
|
|
|
#else
|
2010-04-05 11:19:28 +04:00
|
|
|
bpf_attach(&sc->sc_if, DLT_NULL, sizeof(u_int));
|
2001-01-05 15:49:52 +03:00
|
|
|
#endif
|
2005-02-27 01:31:44 +03:00
|
|
|
#endif
|
2001-01-05 15:49:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* output a packet to the ISDN B-channel
|
|
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
static int
|
2007-02-20 10:43:28 +03:00
|
|
|
iripoutput(struct ifnet *ifp, struct mbuf *m, const struct sockaddr *dst,
|
2006-11-16 04:32:37 +03:00
|
|
|
struct rtentry *rtp)
|
2001-01-05 15:49:52 +03:00
|
|
|
{
|
|
|
|
struct ipr_softc *sc;
|
|
|
|
int s, rv;
|
|
|
|
struct ifqueue *ifq = NULL;
|
|
|
|
struct ip *ip;
|
|
|
|
ALTQ_DECL(struct altq_pktattr pktattr;)
|
2005-02-27 01:31:44 +03:00
|
|
|
|
2001-01-19 15:44:44 +03:00
|
|
|
s = splnet();
|
2001-01-05 15:49:52 +03:00
|
|
|
|
|
|
|
#if defined(__FreeBSD__) || defined(__bsdi__)
|
|
|
|
unit = ifp->if_unit;
|
|
|
|
sc = &ipr_softc[unit];
|
|
|
|
#else
|
|
|
|
sc = ifp->if_softc;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* check for IP */
|
2005-02-27 01:31:44 +03:00
|
|
|
|
2001-01-05 15:49:52 +03:00
|
|
|
if(dst->sa_family != AF_INET)
|
|
|
|
{
|
|
|
|
printf(IPR_FMT "af%d not supported\n", IPR_ARG(sc), dst->sa_family);
|
|
|
|
m_freem(m);
|
|
|
|
splx(s);
|
|
|
|
sc->sc_if.if_noproto++;
|
|
|
|
sc->sc_if.if_oerrors++;
|
|
|
|
return(EAFNOSUPPORT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check interface state = UP */
|
2005-02-27 01:31:44 +03:00
|
|
|
|
2001-01-05 15:49:52 +03:00
|
|
|
if(!(ifp->if_flags & IFF_UP))
|
|
|
|
{
|
2002-03-17 23:54:04 +03:00
|
|
|
NDBGL4(L4_IPRDBG, "%s: interface is DOWN!", sc->sc_if.if_xname);
|
2001-01-05 15:49:52 +03:00
|
|
|
m_freem(m);
|
|
|
|
splx(s);
|
|
|
|
sc->sc_if.if_oerrors++;
|
|
|
|
return(ENETDOWN);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* dial if necessary */
|
2005-02-27 01:31:44 +03:00
|
|
|
|
2001-01-05 15:49:52 +03:00
|
|
|
if(sc->sc_state == ST_IDLE || sc->sc_state == ST_DIALING)
|
|
|
|
{
|
|
|
|
|
|
|
|
#ifdef NOTDEF
|
|
|
|
switch(sc->sc_dialresp)
|
|
|
|
{
|
|
|
|
case DSTAT_TFAIL: /* transient failure */
|
2002-03-17 23:54:04 +03:00
|
|
|
NDBGL4(L4_IPRDBG, "%s: transient dial failure!", sc->sc_if.if_xname);
|
2001-01-05 15:49:52 +03:00
|
|
|
m_freem(m);
|
2002-03-16 19:55:51 +03:00
|
|
|
iripclearqueues(sc);
|
2001-01-05 15:49:52 +03:00
|
|
|
sc->sc_dialresp = DSTAT_NONE;
|
|
|
|
splx(s);
|
|
|
|
sc->sc_if.if_oerrors++;
|
|
|
|
return(ENETUNREACH);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DSTAT_PFAIL: /* permanent failure */
|
2002-03-17 23:54:04 +03:00
|
|
|
NDBGL4(L4_IPRDBG, "%s: permanent dial failure!", sc->sc_if.if_xname);
|
2001-01-05 15:49:52 +03:00
|
|
|
m_freem(m);
|
2002-03-16 19:55:51 +03:00
|
|
|
iripclearqueues(sc);
|
2001-01-05 15:49:52 +03:00
|
|
|
sc->sc_dialresp = DSTAT_NONE;
|
|
|
|
splx(s);
|
|
|
|
sc->sc_if.if_oerrors++;
|
2005-02-27 01:31:44 +03:00
|
|
|
return(EHOSTUNREACH);
|
2001-01-05 15:49:52 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DSTAT_INONLY: /* no dialout allowed*/
|
2002-03-17 23:54:04 +03:00
|
|
|
NDBGL4(L4_IPRDBG, "%s: dialout not allowed failure!", sc->sc_if.if_xname);
|
2001-01-05 15:49:52 +03:00
|
|
|
m_freem(m);
|
2002-03-16 19:55:51 +03:00
|
|
|
iripclearqueues(sc);
|
2001-01-05 15:49:52 +03:00
|
|
|
sc->sc_dialresp = DSTAT_NONE;
|
|
|
|
splx(s);
|
|
|
|
sc->sc_if.if_oerrors++;
|
2005-02-27 01:31:44 +03:00
|
|
|
return(EHOSTUNREACH);
|
2001-01-05 15:49:52 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-03-17 23:54:04 +03:00
|
|
|
NDBGL4(L4_IPRDBG, "%s: send dial request message!", sc->sc_if.if_xname);
|
|
|
|
NDBGL4(L4_DIALST, "%s: setting dial state to ST_DIALING", sc->sc_if.if_xname);
|
2002-03-19 01:15:28 +03:00
|
|
|
i4b_l4_dialout(irip_driver_id, sc->sc_unit);
|
2001-01-05 15:49:52 +03:00
|
|
|
sc->sc_state = ST_DIALING;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if IPR_LOG
|
|
|
|
if(sc->sc_log_first > 0)
|
|
|
|
{
|
|
|
|
--(sc->sc_log_first);
|
2002-05-21 14:31:10 +04:00
|
|
|
i4b_l4_packet_ind(irip_driver_id, sc->sc_unit, 1, m );
|
2001-01-05 15:49:52 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* check, if type of service indicates interactive, i.e. telnet,
|
|
|
|
* traffic. in case it is interactive, put it into the fast queue,
|
|
|
|
* else (i.e. ftp traffic) put it into the "normal" queue
|
|
|
|
*/
|
|
|
|
|
|
|
|
IFQ_CLASSIFY(&ifp->if_snd, m, dst->sa_family, &pktattr);
|
|
|
|
|
|
|
|
ip = mtod(m, struct ip *); /* get ptr to ip header */
|
2005-02-27 01:31:44 +03:00
|
|
|
|
2001-01-05 15:49:52 +03:00
|
|
|
if(ip->ip_tos & IPTOS_LOWDELAY)
|
|
|
|
ifq = &sc->sc_fastq;
|
|
|
|
|
|
|
|
/* check for space in choosen send queue */
|
|
|
|
|
|
|
|
if ((ifq != NULL)
|
|
|
|
#ifdef ALTQ
|
|
|
|
&& ALTQ_IS_ENABLED(&sc->sc_if.if_snd) == 0
|
|
|
|
#endif
|
|
|
|
) {
|
|
|
|
if(IF_QFULL(ifq))
|
|
|
|
{
|
2002-03-19 01:15:28 +03:00
|
|
|
NDBGL4(L4_IPRDBG, "%s: send queue full!", sc->sc_if.if_xname);
|
2001-01-05 15:49:52 +03:00
|
|
|
IF_DROP(ifq);
|
|
|
|
m_freem(m);
|
|
|
|
sc->sc_if.if_oerrors++;
|
|
|
|
splx(s);
|
|
|
|
return(ENOBUFS);
|
|
|
|
}
|
2001-02-03 21:43:45 +03:00
|
|
|
IF_ENQUEUE(ifq, m);
|
2001-01-05 15:49:52 +03:00
|
|
|
} else {
|
|
|
|
IFQ_ENQUEUE(&sc->sc_if.if_snd, m, &pktattr, rv);
|
|
|
|
if (rv != 0) {
|
|
|
|
sc->sc_if.if_oerrors++;
|
|
|
|
splx(s);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
2005-02-27 01:31:44 +03:00
|
|
|
|
2002-03-19 01:15:28 +03:00
|
|
|
NDBGL4(L4_IPRDBG, "%s: added packet to send queue!", sc->sc_if.if_xname);
|
2001-01-05 15:49:52 +03:00
|
|
|
|
2002-03-17 12:45:58 +03:00
|
|
|
ipr_tx_queue_empty(sc);
|
2001-01-05 15:49:52 +03:00
|
|
|
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* process ioctl
|
|
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
static int
|
2007-03-04 08:59:00 +03:00
|
|
|
iripioctl(struct ifnet *ifp, u_long cmd, void *data)
|
2001-01-05 15:49:52 +03:00
|
|
|
{
|
|
|
|
struct ipr_softc *sc = ifp->if_softc;
|
|
|
|
|
|
|
|
struct ifreq *ifr = (struct ifreq *)data;
|
|
|
|
struct ifaddr *ifa = (struct ifaddr *)data;
|
|
|
|
int s;
|
|
|
|
int error = 0;
|
|
|
|
|
2001-01-19 15:44:44 +03:00
|
|
|
s = splnet();
|
2005-02-27 01:31:44 +03:00
|
|
|
|
2001-01-05 15:49:52 +03:00
|
|
|
switch (cmd)
|
|
|
|
{
|
|
|
|
case SIOCAIFADDR: /* add interface address */
|
*** Summary ***
When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.
Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)
Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.
Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.
Return consistent, appropriate error codes from network drivers.
Improve readability. KNF.
*** Details ***
In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.
In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.
Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.
In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.
Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:
switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}
Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,
switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}
unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).
In ipw(4), remove an if_set_sadl() call that is out of place.
In nfe(4), reuse the jumbo MTU logic in ether_ioctl().
Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.
Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.
Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.
Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.
In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.
Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.
In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.
Let ifioctl_common() handle SIOCGIFADDR.
Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.
In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.
bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.
2008-11-07 03:20:01 +03:00
|
|
|
case SIOCINITIFADDR: /* set interface address */
|
2001-01-05 15:49:52 +03:00
|
|
|
case SIOCSIFDSTADDR: /* set interface destination address */
|
|
|
|
if(ifa->ifa_addr->sa_family != AF_INET)
|
|
|
|
error = EAFNOSUPPORT;
|
|
|
|
else
|
|
|
|
sc->sc_if.if_flags |= IFF_UP;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCSIFFLAGS: /* set interface flags */
|
*** Summary ***
When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.
Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)
Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.
Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.
Return consistent, appropriate error codes from network drivers.
Improve readability. KNF.
*** Details ***
In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.
In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.
Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.
In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.
Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:
switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}
Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,
switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}
unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).
In ipw(4), remove an if_set_sadl() call that is out of place.
In nfe(4), reuse the jumbo MTU logic in ether_ioctl().
Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.
Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.
Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.
Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.
In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.
Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.
In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.
Let ifioctl_common() handle SIOCGIFADDR.
Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.
In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.
bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.
2008-11-07 03:20:01 +03:00
|
|
|
if ((error = ifioctl_common(ifp, cmd, data)) != 0)
|
|
|
|
break;
|
|
|
|
if ((ifr->ifr_flags & IFF_UP) == 0) {
|
|
|
|
if (sc->sc_if.if_flags & IFF_RUNNING) {
|
2001-01-05 15:49:52 +03:00
|
|
|
/* disconnect ISDN line */
|
2002-03-17 23:54:04 +03:00
|
|
|
i4b_l4_drvrdisc(sc->sc_cdp->cdid);
|
2001-01-05 15:49:52 +03:00
|
|
|
sc->sc_if.if_flags &= ~IFF_RUNNING;
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->sc_state = ST_IDLE;
|
|
|
|
|
|
|
|
/* empty queues */
|
|
|
|
|
2002-03-16 19:55:51 +03:00
|
|
|
iripclearqueues(sc);
|
2001-01-05 15:49:52 +03:00
|
|
|
}
|
|
|
|
|
2008-11-09 18:48:13 +03:00
|
|
|
#if 0
|
2001-01-05 15:49:52 +03:00
|
|
|
if(ifr->ifr_flags & IFF_DEBUG)
|
*** Summary ***
When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.
Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)
Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.
Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.
Return consistent, appropriate error codes from network drivers.
Improve readability. KNF.
*** Details ***
In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.
In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.
Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.
In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.
Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:
switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}
Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,
switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}
unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).
In ipw(4), remove an if_set_sadl() call that is out of place.
In nfe(4), reuse the jumbo MTU logic in ether_ioctl().
Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.
Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.
Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.
Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.
In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.
Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.
In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.
Let ifioctl_common() handle SIOCGIFADDR.
Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.
In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.
bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.
2008-11-07 03:20:01 +03:00
|
|
|
; /* enable debug messages */
|
2008-11-09 18:48:13 +03:00
|
|
|
#endif
|
2005-02-27 01:31:44 +03:00
|
|
|
|
2001-01-05 15:49:52 +03:00
|
|
|
break;
|
|
|
|
|
2005-02-27 01:31:44 +03:00
|
|
|
#if !defined(__OpenBSD__)
|
2001-01-05 15:49:52 +03:00
|
|
|
case SIOCSIFMTU: /* set interface MTU */
|
|
|
|
if(ifr->ifr_mtu > I4BIPRMAXMTU)
|
|
|
|
error = EINVAL;
|
|
|
|
else if(ifr->ifr_mtu < I4BIPRMINMTU)
|
|
|
|
error = EINVAL;
|
2008-02-07 04:21:52 +03:00
|
|
|
else if ((error = ifioctl_common(ifp, cmd, data)) == ENETRESET)
|
|
|
|
error = 0;
|
2001-01-05 15:49:52 +03:00
|
|
|
break;
|
|
|
|
#endif /* __OPENBSD__ */
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* not needed for FreeBSD, done in sl_compress_init() (-hm) */
|
2005-02-27 01:31:44 +03:00
|
|
|
|
2001-01-05 15:49:52 +03:00
|
|
|
/* need to add an ioctl: set VJ max slot ID
|
|
|
|
* #define IPRIOCSMAXCID _IOW('I', XXX, int)
|
|
|
|
*/
|
|
|
|
#ifdef IPR_VJ
|
|
|
|
case IPRIOCSMAXCID:
|
|
|
|
{
|
2006-07-24 02:06:03 +04:00
|
|
|
struct lwp *l = curlwp; /* XXX */
|
|
|
|
|
2006-10-26 03:44:42 +04:00
|
|
|
if((error = kauth_authorize_network(l->l_cred,
|
|
|
|
KAUTH_NETWORK_INTERFACE,
|
|
|
|
KAUTH_REQ_NETWORK_INTERFACE_SETPRIV, ifp,
|
|
|
|
(void *)cmd, NULL)) != 0)
|
2002-12-29 00:09:14 +03:00
|
|
|
break;
|
2001-01-05 15:49:52 +03:00
|
|
|
sl_compress_setup(sc->sc_compr, *(int *)data);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
default:
|
*** Summary ***
When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.
Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)
Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.
Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.
Return consistent, appropriate error codes from network drivers.
Improve readability. KNF.
*** Details ***
In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.
In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.
Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.
In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.
Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:
switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}
Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,
switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}
unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).
In ipw(4), remove an if_set_sadl() call that is out of place.
In nfe(4), reuse the jumbo MTU logic in ether_ioctl().
Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.
Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.
Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.
Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.
In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.
Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.
In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.
Let ifioctl_common() handle SIOCGIFADDR.
Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.
In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.
bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.
2008-11-07 03:20:01 +03:00
|
|
|
error = ifioctl_common(ifp, cmd, data);
|
|
|
|
if (error == ENETRESET)
|
|
|
|
error = 0;
|
2001-01-05 15:49:52 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* clear the interface's send queues
|
|
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
2002-03-16 19:55:51 +03:00
|
|
|
iripclearqueues(struct ipr_softc *sc)
|
2001-01-05 15:49:52 +03:00
|
|
|
{
|
|
|
|
int x;
|
|
|
|
struct mbuf *m;
|
2005-02-27 01:31:44 +03:00
|
|
|
|
2001-01-05 15:49:52 +03:00
|
|
|
for(;;)
|
|
|
|
{
|
2001-01-19 15:44:44 +03:00
|
|
|
x = splnet();
|
2001-01-05 15:49:52 +03:00
|
|
|
IF_DEQUEUE(&sc->sc_fastq, m);
|
|
|
|
splx(x);
|
|
|
|
|
|
|
|
if(m)
|
|
|
|
m_freem(m);
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(;;)
|
|
|
|
{
|
2001-01-19 15:44:44 +03:00
|
|
|
x = splnet();
|
2001-02-03 21:43:45 +03:00
|
|
|
IFQ_DEQUEUE(&sc->sc_if.if_snd, m);
|
2001-01-05 15:49:52 +03:00
|
|
|
splx(x);
|
|
|
|
|
|
|
|
if(m)
|
|
|
|
m_freem(m);
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2005-02-27 01:31:44 +03:00
|
|
|
|
2001-01-05 15:49:52 +03:00
|
|
|
#if I4BIPRACCT
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* watchdog routine
|
|
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
#ifdef __bsdi__
|
|
|
|
static int
|
|
|
|
iprwatchdog(int unit)
|
|
|
|
{
|
|
|
|
#else
|
|
|
|
static void
|
|
|
|
iprwatchdog(struct ifnet *ifp)
|
|
|
|
{
|
|
|
|
#endif
|
|
|
|
#ifdef __FreeBSD__
|
|
|
|
int unit = ifp->if_unit;
|
|
|
|
struct ipr_softc *sc = &ipr_softc[unit];
|
|
|
|
#elif defined(__bsdi__)
|
|
|
|
struct ipr_softc *sc = &ipr_softc[unit];
|
|
|
|
struct ifnet *ifp = &ipr_softc[unit].sc_if;
|
|
|
|
#else
|
|
|
|
struct ipr_softc *sc = ifp->if_softc;
|
|
|
|
#endif
|
|
|
|
bchan_statistics_t bs;
|
2005-02-27 01:31:44 +03:00
|
|
|
|
|
|
|
/* get # of bytes in and out from the HSCX driver */
|
|
|
|
|
2002-03-17 23:54:04 +03:00
|
|
|
(*sc->sc_ilt->bchannel_driver->bch_stat)
|
|
|
|
(sc->sc_ilt->l1token, sc->sc_ilt->channel, &bs);
|
2001-01-05 15:49:52 +03:00
|
|
|
|
|
|
|
sc->sc_ioutb += bs.outbytes;
|
|
|
|
sc->sc_iinb += bs.inbytes;
|
2005-02-27 01:31:44 +03:00
|
|
|
|
|
|
|
if((sc->sc_iinb != sc->sc_linb) || (sc->sc_ioutb != sc->sc_loutb) || sc->sc_fn)
|
2001-01-05 15:49:52 +03:00
|
|
|
{
|
|
|
|
int ri = (sc->sc_iinb - sc->sc_linb)/I4BIPRACCTINTVL;
|
|
|
|
int ro = (sc->sc_ioutb - sc->sc_loutb)/I4BIPRACCTINTVL;
|
|
|
|
|
|
|
|
if((sc->sc_iinb == sc->sc_linb) && (sc->sc_ioutb == sc->sc_loutb))
|
|
|
|
sc->sc_fn = 0;
|
|
|
|
else
|
|
|
|
sc->sc_fn = 1;
|
2005-02-27 01:31:44 +03:00
|
|
|
|
2001-01-05 15:49:52 +03:00
|
|
|
sc->sc_linb = sc->sc_iinb;
|
|
|
|
sc->sc_loutb = sc->sc_ioutb;
|
|
|
|
|
2002-03-17 14:08:31 +03:00
|
|
|
if (sc->sc_cdp)
|
|
|
|
i4b_l4_accounting(sc->sc_cdp->cdid, ACCT_DURING,
|
|
|
|
sc->sc_ioutb, sc->sc_iinb, ro, ri, sc->sc_outb, sc->sc_inb);
|
2001-01-05 15:49:52 +03:00
|
|
|
}
|
2005-02-27 01:31:44 +03:00
|
|
|
sc->sc_if.if_timer = I4BIPRACCTINTVL;
|
2001-01-05 15:49:52 +03:00
|
|
|
#ifdef __bsdi__
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif /* I4BIPRACCT */
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* ISDN INTERFACE ROUTINES
|
|
|
|
*===========================================================================*/
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* start transmitting after connect
|
|
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
|
|
|
i4bipr_connect_startio(struct ipr_softc *sc)
|
|
|
|
{
|
2001-01-19 15:44:44 +03:00
|
|
|
int s = splnet();
|
2005-02-27 01:31:44 +03:00
|
|
|
|
2001-01-05 15:49:52 +03:00
|
|
|
if(sc->sc_state == ST_CONNECTED_W)
|
|
|
|
{
|
|
|
|
sc->sc_state = ST_CONNECTED_A;
|
2002-03-17 12:45:58 +03:00
|
|
|
ipr_tx_queue_empty(sc);
|
2001-01-05 15:49:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
splx(s);
|
|
|
|
}
|
2005-02-27 01:31:44 +03:00
|
|
|
|
2001-01-05 15:49:52 +03:00
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* this routine is called from L4 handler at connect time
|
|
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
2002-03-17 12:45:58 +03:00
|
|
|
ipr_connect(void *softc, void *cdp)
|
2001-01-05 15:49:52 +03:00
|
|
|
{
|
2002-03-17 12:45:58 +03:00
|
|
|
struct ipr_softc *sc = softc;
|
2001-01-05 15:49:52 +03:00
|
|
|
int s;
|
|
|
|
|
|
|
|
sc->sc_cdp = (call_desc_t *)cdp;
|
|
|
|
|
2001-01-19 15:44:44 +03:00
|
|
|
s = splnet();
|
2001-01-05 15:49:52 +03:00
|
|
|
|
2002-03-17 12:45:58 +03:00
|
|
|
NDBGL4(L4_DIALST, "%s: setting dial state to ST_CONNECTED", sc->sc_if.if_xname);
|
2001-01-05 15:49:52 +03:00
|
|
|
|
|
|
|
sc->sc_if.if_flags |= IFF_RUNNING;
|
|
|
|
sc->sc_state = ST_CONNECTED_W;
|
|
|
|
|
|
|
|
sc->sc_dialresp = DSTAT_NONE;
|
2005-02-27 01:31:44 +03:00
|
|
|
sc->sc_lastdialresp = DSTAT_NONE;
|
|
|
|
|
2001-01-05 15:49:52 +03:00
|
|
|
#if I4BIPRACCT
|
|
|
|
sc->sc_iinb = 0;
|
|
|
|
sc->sc_ioutb = 0;
|
|
|
|
sc->sc_inb = 0;
|
|
|
|
sc->sc_outb = 0;
|
|
|
|
sc->sc_linb = 0;
|
|
|
|
sc->sc_loutb = 0;
|
|
|
|
sc->sc_if.if_timer = I4BIPRACCTINTVL;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef I4BIPRADJFRXP
|
|
|
|
sc->sc_first_pkt = 1;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Sometimes ISDN B-channels are switched thru asymmetic. This
|
|
|
|
* means that under such circumstances B-channel data (the first
|
|
|
|
* three packets of a TCP connection in my case) may get lost,
|
|
|
|
* causing a large delay until the connection is started.
|
|
|
|
* When the sending of the very first packet of a TCP connection
|
|
|
|
* is delayed for a to be empirically determined delay (close
|
|
|
|
* to a second in my case) those packets go thru and the TCP
|
|
|
|
* connection comes up "almost" immediately (-hm).
|
|
|
|
*/
|
|
|
|
|
|
|
|
if(sc->sc_cdp->isdntxdelay > 0)
|
|
|
|
{
|
2005-06-14 00:34:16 +04:00
|
|
|
int xdelay;
|
2001-01-05 15:49:52 +03:00
|
|
|
|
|
|
|
if (hz == 100) {
|
2005-06-14 00:34:16 +04:00
|
|
|
xdelay = sc->sc_cdp->isdntxdelay; /* avoid any rounding */
|
2001-01-05 15:49:52 +03:00
|
|
|
} else {
|
2005-06-14 00:34:16 +04:00
|
|
|
xdelay = sc->sc_cdp->isdntxdelay*hz;
|
|
|
|
xdelay /= 100;
|
2001-01-05 15:49:52 +03:00
|
|
|
}
|
|
|
|
|
2005-06-14 00:34:16 +04:00
|
|
|
START_TIMER(sc->sc_callout, (TIMEOUT_FUNC_T)i4bipr_connect_startio, (void *)sc, xdelay);
|
2001-01-05 15:49:52 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sc->sc_state = ST_CONNECTED_A;
|
2002-03-17 12:45:58 +03:00
|
|
|
ipr_tx_queue_empty(sc);
|
2001-01-05 15:49:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
/* we don't need any negotiation - pass event back right now */
|
|
|
|
i4b_l4_negcomplete(sc->sc_cdp);
|
|
|
|
}
|
2005-02-27 01:31:44 +03:00
|
|
|
|
2001-01-05 15:49:52 +03:00
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* this routine is called from L4 handler at disconnect time
|
|
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
2002-03-17 12:45:58 +03:00
|
|
|
ipr_disconnect(void *softc, void *cdp)
|
2001-01-05 15:49:52 +03:00
|
|
|
{
|
|
|
|
call_desc_t *cd = (call_desc_t *)cdp;
|
2002-03-17 12:45:58 +03:00
|
|
|
struct ipr_softc *sc = softc;
|
2001-01-05 15:49:52 +03:00
|
|
|
|
|
|
|
/* new stuff to check that the active channel is being closed */
|
|
|
|
|
|
|
|
if (cd != sc->sc_cdp)
|
|
|
|
{
|
2002-03-17 12:45:58 +03:00
|
|
|
NDBGL4(L4_IPRDBG, "%s: channel %d not active",
|
|
|
|
sc->sc_if.if_xname, cd->channelid);
|
2001-01-05 15:49:52 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if I4BIPRACCT
|
|
|
|
sc->sc_if.if_timer = 0;
|
|
|
|
#endif
|
|
|
|
#if IPR_LOG
|
|
|
|
/* show next IPR_LOG packets again */
|
|
|
|
sc->sc_log_first = IPR_LOG;
|
|
|
|
#endif
|
|
|
|
|
2002-03-17 14:08:31 +03:00
|
|
|
i4b_l4_accounting(cd->cdid, ACCT_FINAL,
|
2001-01-05 15:49:52 +03:00
|
|
|
sc->sc_ioutb, sc->sc_iinb, 0, 0, sc->sc_outb, sc->sc_inb);
|
2005-02-27 01:31:44 +03:00
|
|
|
|
2002-03-17 14:08:31 +03:00
|
|
|
sc->sc_cdp = NULL;
|
2001-01-05 15:49:52 +03:00
|
|
|
|
|
|
|
NDBGL4(L4_DIALST, "setting dial state to ST_IDLE");
|
|
|
|
|
|
|
|
sc->sc_dialresp = DSTAT_NONE;
|
2005-02-27 01:31:44 +03:00
|
|
|
sc->sc_lastdialresp = DSTAT_NONE;
|
2001-01-05 15:49:52 +03:00
|
|
|
|
|
|
|
sc->sc_if.if_flags &= ~IFF_RUNNING;
|
|
|
|
sc->sc_state = ST_IDLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* this routine is used to give a feedback from userland daemon
|
|
|
|
* in case of dial problems
|
|
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
2006-11-16 04:32:37 +03:00
|
|
|
ipr_dialresponse(void *softc, int status, cause_t cause)
|
2001-01-05 15:49:52 +03:00
|
|
|
{
|
2002-03-17 12:45:58 +03:00
|
|
|
struct ipr_softc *sc = softc;
|
2001-01-05 15:49:52 +03:00
|
|
|
sc->sc_dialresp = status;
|
|
|
|
|
2002-03-17 12:45:58 +03:00
|
|
|
NDBGL4(L4_IPRDBG, "%s: last=%d, this=%d",
|
|
|
|
sc->sc_if.if_xname, sc->sc_lastdialresp, sc->sc_dialresp);
|
2001-01-05 15:49:52 +03:00
|
|
|
|
|
|
|
if(status != DSTAT_NONE)
|
|
|
|
{
|
2002-03-17 12:45:58 +03:00
|
|
|
NDBGL4(L4_IPRDBG, "%s: clearing queues", sc->sc_if.if_xname);
|
2002-03-16 19:55:51 +03:00
|
|
|
iripclearqueues(sc);
|
2001-01-05 15:49:52 +03:00
|
|
|
}
|
|
|
|
}
|
2005-02-27 01:31:44 +03:00
|
|
|
|
2001-01-05 15:49:52 +03:00
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* interface soft up/down
|
|
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
2002-03-17 12:45:58 +03:00
|
|
|
ipr_updown(void *softc, int updown)
|
2001-01-05 15:49:52 +03:00
|
|
|
{
|
2002-03-17 12:45:58 +03:00
|
|
|
struct ipr_softc *sc = softc;
|
2001-01-05 15:49:52 +03:00
|
|
|
sc->sc_updown = updown;
|
|
|
|
}
|
2005-02-27 01:31:44 +03:00
|
|
|
|
2001-01-05 15:49:52 +03:00
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* this routine is called from the HSCX interrupt handler
|
|
|
|
* when a new frame (mbuf) has been received and was put on
|
|
|
|
* the rx queue. It is assumed that this routines runs at
|
2001-01-19 15:44:44 +03:00
|
|
|
* appropriate protection level! Keep it short !
|
2001-01-05 15:49:52 +03:00
|
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
2002-03-17 12:45:58 +03:00
|
|
|
ipr_rx_data_rdy(void *softc)
|
2001-01-05 15:49:52 +03:00
|
|
|
{
|
2002-03-17 12:45:58 +03:00
|
|
|
register struct ipr_softc *sc = softc;
|
2001-01-05 15:49:52 +03:00
|
|
|
register struct mbuf *m;
|
2003-04-11 18:45:27 +04:00
|
|
|
#ifdef IRIP_VJ
|
2001-01-05 15:49:52 +03:00
|
|
|
#ifdef IPR_VJ_USEBUFFER
|
|
|
|
u_char *cp = sc->sc_cbuf;
|
2005-02-27 01:31:44 +03:00
|
|
|
#endif
|
2001-01-05 15:49:52 +03:00
|
|
|
int len, c;
|
|
|
|
#endif
|
2005-02-27 01:31:44 +03:00
|
|
|
|
2002-03-17 23:54:04 +03:00
|
|
|
if((m = *sc->sc_ilt->rx_mbuf) == NULL)
|
2001-01-05 15:49:52 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
m->m_pkthdr.rcvif = &sc->sc_if;
|
|
|
|
|
|
|
|
m->m_pkthdr.len = m->m_len;
|
|
|
|
|
|
|
|
#ifdef I4BIPRADJFRXP
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The very first packet after the B channel is switched thru
|
|
|
|
* has very often several bytes of random data prepended. This
|
|
|
|
* routine looks where the IP header starts and removes the
|
|
|
|
* the bad data.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if(sc->sc_first_pkt)
|
|
|
|
{
|
|
|
|
unsigned char *mp = m->m_data;
|
|
|
|
int i;
|
2005-02-27 01:31:44 +03:00
|
|
|
|
2001-01-05 15:49:52 +03:00
|
|
|
sc->sc_first_pkt = 0;
|
|
|
|
|
|
|
|
for(i = 0; i < m->m_len; i++, mp++)
|
|
|
|
{
|
|
|
|
if( ((*mp & 0xf0) == 0x40) &&
|
|
|
|
((*mp & 0x0f) >= 0x05) )
|
|
|
|
{
|
|
|
|
m->m_data = mp;
|
2005-02-27 01:31:44 +03:00
|
|
|
m->m_pkthdr.len -= i;
|
2001-01-05 15:49:52 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2005-02-27 01:31:44 +03:00
|
|
|
|
2001-01-05 15:49:52 +03:00
|
|
|
sc->sc_if.if_ipackets++;
|
|
|
|
sc->sc_if.if_ibytes += m->m_pkthdr.len;
|
|
|
|
|
2003-04-11 18:45:27 +04:00
|
|
|
#ifdef IRIP_VJ
|
2001-01-05 15:49:52 +03:00
|
|
|
if((c = (*(mtod(m, u_char *)) & 0xf0)) != (IPVERSION << 4))
|
|
|
|
{
|
|
|
|
/* copy data to buffer */
|
|
|
|
|
|
|
|
len = m->m_len;
|
|
|
|
|
|
|
|
#ifdef IPR_VJ_USEBUFFER
|
|
|
|
/* XXX */ m_copydata(m, 0, len, cp);
|
|
|
|
#endif
|
2005-02-27 01:31:44 +03:00
|
|
|
|
2001-01-05 15:49:52 +03:00
|
|
|
if(c & 0x80)
|
|
|
|
{
|
|
|
|
c = TYPE_COMPRESSED_TCP;
|
|
|
|
}
|
|
|
|
else if(c == TYPE_UNCOMPRESSED_TCP)
|
|
|
|
{
|
|
|
|
#ifdef IPR_VJ_USEBUFFER
|
|
|
|
*cp &= 0x4f; /* XXX */
|
|
|
|
#else
|
2005-02-27 01:31:44 +03:00
|
|
|
*(mtod(m, u_char *)) &= 0x4f;
|
|
|
|
#endif
|
2001-01-05 15:49:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We've got something that's not an IP packet.
|
|
|
|
* If compression is enabled, try to decompress it.
|
|
|
|
* Otherwise, if `auto-enable' compression is on and
|
|
|
|
* it's a reasonable packet, decompress it and then
|
|
|
|
* enable compression. Otherwise, drop it.
|
|
|
|
*/
|
|
|
|
if(sc->sc_if.if_flags & IPR_COMPRESS)
|
|
|
|
{
|
|
|
|
#ifdef IPR_VJ_USEBUFFER
|
|
|
|
len = sl_uncompress_tcp(&cp,len,(u_int)c,&sc->sc_compr);
|
|
|
|
#else
|
|
|
|
len = sl_uncompress_tcp((u_char **)&m->m_data, len,
|
|
|
|
(u_int)c, &sc->sc_compr);
|
2005-02-27 01:31:44 +03:00
|
|
|
#endif
|
2001-01-05 15:49:52 +03:00
|
|
|
|
|
|
|
if(len <= 0)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_IPR_VJ
|
|
|
|
printf("i4b_ipr, ipr_rx_data_rdy: len <= 0 IPR_COMPRESS!\n");
|
|
|
|
#endif
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if((sc->sc_if.if_flags & IPR_AUTOCOMP) &&
|
|
|
|
(c == TYPE_UNCOMPRESSED_TCP) && (len >= 40))
|
|
|
|
{
|
|
|
|
#ifdef IPR_VJ_USEBUFFER
|
|
|
|
len = sl_uncompress_tcp(&cp,len,(u_int)c,&sc->sc_compr);
|
|
|
|
#else
|
|
|
|
len = sl_uncompress_tcp((u_char **)&m->m_data, len,
|
|
|
|
(u_int)c, &sc->sc_compr);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if(len <= 0)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_IPR_VJ
|
|
|
|
printf("i4b_ipr, ipr_rx_data_rdy: len <= 0 IPR_AUTOCOMP!\n");
|
|
|
|
#endif
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->sc_if.if_flags |= IPR_COMPRESS;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_IPR_VJ
|
|
|
|
printf("i4b_ipr, ipr_input: invalid ip packet!\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
error:
|
|
|
|
sc->sc_if.if_ierrors++;
|
|
|
|
sc->sc_if.if_collisions++;
|
|
|
|
m_freem(m);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#ifdef IPR_VJ_USEBUFFER
|
|
|
|
/* XXX */ m_copyback(m, 0, len, cp);
|
|
|
|
#else
|
|
|
|
m->m_len = m->m_pkthdr.len = len;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if I4BIPRACCT
|
|
|
|
/* NB. do the accounting after decompression! */
|
|
|
|
sc->sc_inb += m->m_pkthdr.len;
|
|
|
|
#endif
|
|
|
|
#if IPR_LOG
|
|
|
|
if(sc->sc_log_first > 0)
|
|
|
|
{
|
|
|
|
--(sc->sc_log_first);
|
2002-05-21 14:31:10 +04:00
|
|
|
i4b_l4_packet_ind(irip_driver_id, sc->sc_unit, 0, m );
|
2001-01-05 15:49:52 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if NBPFILTER > 0 || NBPF > 0
|
|
|
|
if(sc->sc_if.if_bpf)
|
|
|
|
{
|
2005-02-27 01:31:44 +03:00
|
|
|
/* prepend the address family as a four byte field */
|
2001-01-05 15:49:52 +03:00
|
|
|
struct mbuf mm;
|
|
|
|
u_int af = AF_INET;
|
|
|
|
mm.m_next = m;
|
|
|
|
mm.m_len = 4;
|
|
|
|
mm.m_data = (char *)⁡
|
|
|
|
|
|
|
|
bpf_mtap(&sc->sc_if, &mm);
|
|
|
|
}
|
|
|
|
#endif /* NBPFILTER > 0 || NBPF > 0 */
|
|
|
|
|
|
|
|
if(IF_QFULL(&ipintrq))
|
|
|
|
{
|
2002-03-17 12:45:58 +03:00
|
|
|
NDBGL4(L4_IPRDBG, "%s: ipintrq full!", sc->sc_if.if_xname);
|
2001-01-05 15:49:52 +03:00
|
|
|
|
|
|
|
IF_DROP(&ipintrq);
|
|
|
|
sc->sc_if.if_ierrors++;
|
2005-02-27 01:31:44 +03:00
|
|
|
sc->sc_if.if_iqdrops++;
|
2001-01-05 15:49:52 +03:00
|
|
|
m_freem(m);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
IF_ENQUEUE(&ipintrq, m);
|
|
|
|
schednetisr(NETISR_IP);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* this routine is called from the HSCX interrupt handler
|
|
|
|
* when the last frame has been sent out and there is no
|
|
|
|
* further frame (mbuf) in the tx queue.
|
|
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
2002-03-17 12:45:58 +03:00
|
|
|
ipr_tx_queue_empty(void *softc)
|
2001-01-05 15:49:52 +03:00
|
|
|
{
|
2002-03-17 12:45:58 +03:00
|
|
|
register struct ipr_softc *sc = softc;
|
2001-01-05 15:49:52 +03:00
|
|
|
register struct mbuf *m;
|
2005-02-27 01:31:44 +03:00
|
|
|
#ifdef IRIP_VJ
|
|
|
|
struct ip *ip;
|
2001-01-05 15:49:52 +03:00
|
|
|
#endif
|
|
|
|
int x = 0;
|
|
|
|
|
|
|
|
if(sc->sc_state != ST_CONNECTED_A)
|
|
|
|
return;
|
2005-02-27 01:31:44 +03:00
|
|
|
|
2001-01-05 15:49:52 +03:00
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
IF_DEQUEUE(&sc->sc_fastq, m);
|
|
|
|
if(m)
|
|
|
|
{
|
|
|
|
sc->sc_if.if_omcasts++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-02-03 21:43:45 +03:00
|
|
|
IFQ_DEQUEUE(&sc->sc_if.if_snd, m);
|
2001-01-05 15:49:52 +03:00
|
|
|
if(m == NULL)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if NBPFILTER > 0 || NBPF > 0
|
|
|
|
if(sc->sc_if.if_bpf)
|
|
|
|
{
|
|
|
|
/* prepend the address family as a four byte field */
|
2005-02-27 01:31:44 +03:00
|
|
|
|
2001-01-05 15:49:52 +03:00
|
|
|
struct mbuf mm;
|
|
|
|
u_int af = AF_INET;
|
|
|
|
mm.m_next = m;
|
|
|
|
mm.m_len = 4;
|
|
|
|
mm.m_data = (char *)⁡
|
2005-02-27 01:31:44 +03:00
|
|
|
|
2001-01-05 15:49:52 +03:00
|
|
|
bpf_mtap(&sc->sc_if, &mm);
|
|
|
|
}
|
|
|
|
#endif /* NBPFILTER */
|
2005-02-27 01:31:44 +03:00
|
|
|
|
2001-01-05 15:49:52 +03:00
|
|
|
#if I4BIPRACCT
|
|
|
|
sc->sc_outb += m->m_pkthdr.len; /* size before compression */
|
|
|
|
#endif
|
|
|
|
|
2005-02-27 01:31:44 +03:00
|
|
|
#ifdef IRIP_VJ
|
2001-01-05 15:49:52 +03:00
|
|
|
if((ip = mtod(m, struct ip *))->ip_p == IPPROTO_TCP)
|
|
|
|
{
|
|
|
|
if(sc->sc_if.if_flags & IPR_COMPRESS)
|
|
|
|
{
|
|
|
|
*mtod(m, u_char *) |= sl_compress_tcp(m, ip,
|
|
|
|
&sc->sc_compr, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
x = 1;
|
|
|
|
|
2002-03-17 23:54:04 +03:00
|
|
|
if(IF_QFULL(sc->sc_ilt->tx_queue))
|
2001-01-05 15:49:52 +03:00
|
|
|
{
|
2002-03-17 12:45:58 +03:00
|
|
|
NDBGL4(L4_IPRDBG, "%s: tx queue full!", sc->sc_if.if_xname);
|
2001-01-05 15:49:52 +03:00
|
|
|
m_freem(m);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-03-17 23:54:04 +03:00
|
|
|
IF_ENQUEUE(sc->sc_ilt->tx_queue, m);
|
2001-01-05 15:49:52 +03:00
|
|
|
|
|
|
|
sc->sc_if.if_obytes += m->m_pkthdr.len;
|
|
|
|
|
|
|
|
sc->sc_if.if_opackets++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(x)
|
2002-03-17 23:54:04 +03:00
|
|
|
(*sc->sc_ilt->bchannel_driver->bch_tx_start)(sc->sc_ilt->l1token, sc->sc_ilt->channel);
|
2001-01-05 15:49:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* this routine is called from the HSCX interrupt handler
|
|
|
|
* each time a packet is received or transmitted. It should
|
|
|
|
* be used to implement an activity timeout mechanism.
|
|
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
2006-11-16 04:32:37 +03:00
|
|
|
ipr_activity(void *softc, int rxtx)
|
2001-01-05 15:49:52 +03:00
|
|
|
{
|
2002-03-17 12:45:58 +03:00
|
|
|
struct ipr_softc *sc = softc;
|
|
|
|
sc->sc_cdp->last_active_time = SECOND;
|
2001-01-05 15:49:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* return this drivers linktab address
|
|
|
|
*---------------------------------------------------------------------------*/
|
2002-03-17 23:54:04 +03:00
|
|
|
static void*
|
|
|
|
ipr_get_softc(int unit)
|
2001-01-05 15:49:52 +03:00
|
|
|
{
|
2002-03-17 23:54:04 +03:00
|
|
|
return &ipr_softc[unit];
|
2001-01-05 15:49:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* setup the isdn_linktab for this driver
|
|
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
2002-03-17 23:54:04 +03:00
|
|
|
ipr_set_linktab(void *softc, isdn_link_t *ilt)
|
2001-01-05 15:49:52 +03:00
|
|
|
{
|
2002-03-17 23:54:04 +03:00
|
|
|
struct ipr_softc *sc = softc;
|
|
|
|
sc->sc_ilt = ilt;
|
2001-01-05 15:49:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2002-03-16 19:55:51 +03:00
|
|
|
#endif /* NIRIP > 0 */
|