1997-02-09 22:50:16 +00:00
|
|
|
/*
|
2002-03-19 11:45:20 +00:00
|
|
|
* Copyright (C) 1993-2002 by Darren Reed.
|
1997-02-09 22:50:16 +00:00
|
|
|
*
|
2001-07-28 11:59:33 +00:00
|
|
|
* See the IPFILTER.LICENCE file for details on licencing.
|
1997-02-09 22:50:16 +00:00
|
|
|
*/
|
|
|
|
/* #pragma ident "@(#)solaris.c 1.12 6/5/96 (C) 1995 Darren Reed"*/
|
2002-04-25 03:34:26 +00:00
|
|
|
#pragma ident "@(#)$Id: solaris.c,v 2.15.2.30 2002/04/23 14:57:51 darrenr Exp $"
|
1997-02-09 22:50:16 +00:00
|
|
|
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/uio.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/modctl.h>
|
|
|
|
#include <sys/open.h>
|
|
|
|
#include <sys/kmem.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/cmn_err.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/cred.h>
|
|
|
|
#include <sys/dditypes.h>
|
|
|
|
#include <sys/stream.h>
|
|
|
|
#include <sys/poll.h>
|
|
|
|
#include <sys/autoconf.h>
|
|
|
|
#include <sys/byteorder.h>
|
|
|
|
#include <sys/socket.h>
|
1999-11-08 20:51:23 +00:00
|
|
|
#include <sys/dlpi.h>
|
|
|
|
#include <sys/stropts.h>
|
|
|
|
#include <sys/sockio.h>
|
1997-02-09 22:50:16 +00:00
|
|
|
#include <net/if.h>
|
2000-01-13 18:30:37 +00:00
|
|
|
#if SOLARIS2 >= 6
|
|
|
|
# include <net/if_types.h>
|
|
|
|
#endif
|
1997-02-09 22:50:16 +00:00
|
|
|
#include <net/af.h>
|
|
|
|
#include <net/route.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/if_ether.h>
|
|
|
|
#include <netinet/ip.h>
|
|
|
|
#include <netinet/ip_var.h>
|
|
|
|
#include <netinet/tcp.h>
|
|
|
|
#include <netinet/udp.h>
|
|
|
|
#include <netinet/tcpip.h>
|
|
|
|
#include <netinet/ip_icmp.h>
|
|
|
|
#include <sys/ddi.h>
|
|
|
|
#include <sys/sunddi.h>
|
1997-04-03 10:22:02 +00:00
|
|
|
#include "ip_compat.h"
|
|
|
|
#include "ipl.h"
|
|
|
|
#include "ip_fil.h"
|
1997-11-16 04:52:19 +00:00
|
|
|
#include "ip_nat.h"
|
2000-08-13 04:58:02 +00:00
|
|
|
#include "ip_state.h"
|
1997-02-09 22:50:16 +00:00
|
|
|
|
1999-11-08 20:51:23 +00:00
|
|
|
|
1997-02-09 22:50:16 +00:00
|
|
|
char _depends_on[] = "drv/ip";
|
|
|
|
|
|
|
|
|
1997-11-16 04:52:19 +00:00
|
|
|
void solipdrvattach __P((void));
|
|
|
|
int solipdrvdetach __P((void));
|
|
|
|
|
|
|
|
void solattach __P((void));
|
1997-04-03 10:22:02 +00:00
|
|
|
int soldetach __P((void));
|
1997-02-09 22:50:16 +00:00
|
|
|
|
|
|
|
extern struct filterstats frstats[];
|
1999-11-08 20:51:23 +00:00
|
|
|
extern KRWLOCK_T ipf_mutex, ipfs_mutex, ipf_nat, ipf_solaris;
|
|
|
|
extern kmutex_t ipf_rw;
|
|
|
|
extern int fr_running;
|
1997-02-09 22:50:16 +00:00
|
|
|
extern int fr_flags;
|
|
|
|
|
1997-11-16 04:52:19 +00:00
|
|
|
extern ipnat_t *nat_list;
|
|
|
|
|
1997-02-09 22:50:16 +00:00
|
|
|
static qif_t *qif_head = NULL;
|
1997-11-16 04:52:19 +00:00
|
|
|
static int ipf_getinfo __P((dev_info_t *, ddi_info_cmd_t,
|
1997-04-03 10:22:02 +00:00
|
|
|
void *, void **));
|
1997-11-16 04:52:19 +00:00
|
|
|
static int ipf_probe __P((dev_info_t *));
|
|
|
|
static int ipf_identify __P((dev_info_t *));
|
|
|
|
static int ipf_attach __P((dev_info_t *, ddi_attach_cmd_t));
|
|
|
|
static int ipf_detach __P((dev_info_t *, ddi_detach_cmd_t));
|
1997-04-03 10:22:02 +00:00
|
|
|
static qif_t *qif_from_queue __P((queue_t *));
|
|
|
|
static void fr_donotip __P((int, qif_t *, queue_t *, mblk_t *,
|
1999-11-08 20:51:23 +00:00
|
|
|
mblk_t *, ip_t *, size_t));
|
1997-11-16 04:52:19 +00:00
|
|
|
static char *ipf_devfiles[] = { IPL_NAME, IPL_NAT, IPL_STATE, IPL_AUTH,
|
|
|
|
NULL };
|
1999-11-08 20:51:23 +00:00
|
|
|
static int (*ipf_ip_inp) __P((queue_t *, mblk_t *)) = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
#if SOLARIS2 >= 7
|
|
|
|
extern void ipfr_slowtimer __P((void *));
|
|
|
|
timeout_id_t ipfr_timer_id;
|
|
|
|
static timeout_id_t synctimeoutid = 0;
|
|
|
|
#else
|
|
|
|
extern void ipfr_slowtimer __P((void));
|
|
|
|
int ipfr_timer_id;
|
|
|
|
static int synctimeoutid = 0;
|
|
|
|
#endif
|
2002-03-19 11:45:20 +00:00
|
|
|
int ipf_debug = 0;
|
|
|
|
int ipf_debug_verbose = 0;
|
1999-11-08 20:51:23 +00:00
|
|
|
|
2002-03-19 11:45:20 +00:00
|
|
|
/* #undef IPFDEBUG 1 */
|
|
|
|
/* #undef IPFDEBUG_VERBOSE 1 */
|
1997-11-16 04:52:19 +00:00
|
|
|
#ifdef IPFDEBUG
|
1997-04-03 10:22:02 +00:00
|
|
|
void printire __P((ire_t *));
|
1997-11-16 04:52:19 +00:00
|
|
|
#endif
|
2002-03-19 11:45:20 +00:00
|
|
|
#define isdigit(x) ((x) >= '0' && (x) <= '9')
|
|
|
|
|
1997-11-16 04:52:19 +00:00
|
|
|
static int fr_precheck __P((mblk_t **, queue_t *, qif_t *, int));
|
1997-04-03 10:22:02 +00:00
|
|
|
|
1997-02-09 22:50:16 +00:00
|
|
|
|
1997-11-16 04:52:19 +00:00
|
|
|
static struct cb_ops ipf_cb_ops = {
|
1997-02-09 22:50:16 +00:00
|
|
|
iplopen,
|
|
|
|
iplclose,
|
1997-11-16 04:52:19 +00:00
|
|
|
nodev, /* strategy */
|
|
|
|
nodev, /* print */
|
1997-02-09 22:50:16 +00:00
|
|
|
nodev, /* dump */
|
|
|
|
iplread,
|
|
|
|
nodev, /* write */
|
|
|
|
iplioctl, /* ioctl */
|
|
|
|
nodev, /* devmap */
|
|
|
|
nodev, /* mmap */
|
|
|
|
nodev, /* segmap */
|
|
|
|
nochpoll, /* poll */
|
|
|
|
ddi_prop_op,
|
|
|
|
NULL,
|
1997-11-16 04:52:19 +00:00
|
|
|
D_MTSAFE,
|
|
|
|
#if SOLARIS2 > 4
|
|
|
|
CB_REV,
|
|
|
|
nodev, /* aread */
|
|
|
|
nodev, /* awrite */
|
|
|
|
#endif
|
1997-02-09 22:50:16 +00:00
|
|
|
};
|
|
|
|
|
1997-11-16 04:52:19 +00:00
|
|
|
static struct dev_ops ipf_ops = {
|
1997-02-09 22:50:16 +00:00
|
|
|
DEVO_REV,
|
|
|
|
0,
|
1997-11-16 04:52:19 +00:00
|
|
|
ipf_getinfo,
|
|
|
|
ipf_identify,
|
|
|
|
ipf_probe,
|
|
|
|
ipf_attach,
|
|
|
|
ipf_detach,
|
1997-02-09 22:50:16 +00:00
|
|
|
nodev, /* reset */
|
1997-11-16 04:52:19 +00:00
|
|
|
&ipf_cb_ops,
|
1997-02-09 22:50:16 +00:00
|
|
|
(struct bus_ops *)0
|
|
|
|
};
|
|
|
|
|
|
|
|
extern struct mod_ops mod_driverops;
|
|
|
|
static struct modldrv iplmod = {
|
1997-11-16 04:52:19 +00:00
|
|
|
&mod_driverops, IPL_VERSION, &ipf_ops };
|
|
|
|
static struct modlinkage modlink1 = { MODREV_1, &iplmod, NULL };
|
1997-02-09 22:50:16 +00:00
|
|
|
|
2000-01-13 18:30:37 +00:00
|
|
|
#if SOLARIS2 >= 6
|
|
|
|
static size_t hdrsizes[57][2] = {
|
|
|
|
{ 0, 0 },
|
|
|
|
{ IFT_OTHER, 0 },
|
2001-07-28 11:59:33 +00:00
|
|
|
{ IFT_1822, 14 }, /* 14 for ire0 ?? */
|
2000-01-13 18:30:37 +00:00
|
|
|
{ IFT_HDH1822, 0 },
|
|
|
|
{ IFT_X25DDN, 0 },
|
|
|
|
{ IFT_X25, 0 },
|
|
|
|
{ IFT_ETHER, 14 },
|
2002-03-19 11:45:20 +00:00
|
|
|
{ IFT_ISO88023, 14 },
|
2000-01-13 18:30:37 +00:00
|
|
|
{ IFT_ISO88024, 0 },
|
|
|
|
{ IFT_ISO88025, 0 },
|
|
|
|
{ IFT_ISO88026, 0 },
|
|
|
|
{ IFT_STARLAN, 0 },
|
|
|
|
{ IFT_P10, 0 },
|
|
|
|
{ IFT_P80, 0 },
|
|
|
|
{ IFT_HY, 0 },
|
|
|
|
{ IFT_FDDI, 24 },
|
|
|
|
{ IFT_LAPB, 0 },
|
|
|
|
{ IFT_SDLC, 0 },
|
|
|
|
{ IFT_T1, 0 },
|
|
|
|
{ IFT_CEPT, 0 },
|
|
|
|
{ IFT_ISDNBASIC, 0 },
|
|
|
|
{ IFT_ISDNPRIMARY, 0 },
|
|
|
|
{ IFT_PTPSERIAL, 0 },
|
|
|
|
{ IFT_PPP, 0 },
|
|
|
|
{ IFT_LOOP, 0 },
|
|
|
|
{ IFT_EON, 0 },
|
|
|
|
{ IFT_XETHER, 0 },
|
|
|
|
{ IFT_NSIP, 0 },
|
|
|
|
{ IFT_SLIP, 0 },
|
|
|
|
{ IFT_ULTRA, 0 },
|
|
|
|
{ IFT_DS3, 0 },
|
|
|
|
{ IFT_SIP, 0 },
|
|
|
|
{ IFT_FRELAY, 0 },
|
|
|
|
{ IFT_RS232, 0 },
|
|
|
|
{ IFT_PARA, 0 },
|
|
|
|
{ IFT_ARCNET, 0 },
|
|
|
|
{ IFT_ARCNETPLUS, 0 },
|
|
|
|
{ IFT_ATM, 0 },
|
|
|
|
{ IFT_MIOX25, 0 },
|
|
|
|
{ IFT_SONET, 0 },
|
|
|
|
{ IFT_X25PLE, 0 },
|
|
|
|
{ IFT_ISO88022LLC, 0 },
|
|
|
|
{ IFT_LOCALTALK, 0 },
|
|
|
|
{ IFT_SMDSDXI, 0 },
|
|
|
|
{ IFT_FRELAYDCE, 0 },
|
|
|
|
{ IFT_V35, 0 },
|
|
|
|
{ IFT_HSSI, 0 },
|
|
|
|
{ IFT_HIPPI, 0 },
|
|
|
|
{ IFT_MODEM, 0 },
|
|
|
|
{ IFT_AAL5, 0 },
|
|
|
|
{ IFT_SONETPATH, 0 },
|
|
|
|
{ IFT_SONETVT, 0 },
|
|
|
|
{ IFT_SMDSICIP, 0 },
|
|
|
|
{ IFT_PROPVIRTUAL, 0 },
|
|
|
|
{ IFT_PROPMUX, 0 },
|
|
|
|
};
|
|
|
|
#endif /* SOLARIS2 >= 6 */
|
1997-02-09 22:50:16 +00:00
|
|
|
|
|
|
|
static dev_info_t *ipf_dev_info = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
int _init()
|
|
|
|
{
|
1999-11-08 20:51:23 +00:00
|
|
|
int ipfinst;
|
1997-11-16 04:52:19 +00:00
|
|
|
|
1999-11-08 20:51:23 +00:00
|
|
|
ipfinst = mod_install(&modlink1);
|
|
|
|
#ifdef IPFDEBUG
|
2002-03-19 11:45:20 +00:00
|
|
|
if (ipf_debug)
|
|
|
|
cmn_err(CE_NOTE, "IP Filter: _init() = %d", ipfinst);
|
1997-11-16 04:52:19 +00:00
|
|
|
#endif
|
1999-11-08 20:51:23 +00:00
|
|
|
return ipfinst;
|
1997-02-09 22:50:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int _fini(void)
|
|
|
|
{
|
1999-11-08 20:51:23 +00:00
|
|
|
int ipfinst;
|
1997-11-16 04:52:19 +00:00
|
|
|
|
1999-11-08 20:51:23 +00:00
|
|
|
ipfinst = mod_remove(&modlink1);
|
|
|
|
#ifdef IPFDEBUG
|
2002-03-19 11:45:20 +00:00
|
|
|
if (ipf_debug)
|
|
|
|
cmn_err(CE_NOTE, "IP Filter: _fini() = %d", ipfinst);
|
1997-11-16 04:52:19 +00:00
|
|
|
#endif
|
1999-11-08 20:51:23 +00:00
|
|
|
return ipfinst;
|
1997-02-09 22:50:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-11-16 04:52:19 +00:00
|
|
|
int _info(modinfop)
|
|
|
|
struct modinfo *modinfop;
|
1997-02-09 22:50:16 +00:00
|
|
|
{
|
1999-11-08 20:51:23 +00:00
|
|
|
int ipfinst;
|
|
|
|
|
|
|
|
ipfinst = mod_info(&modlink1, modinfop);
|
1997-02-09 22:50:16 +00:00
|
|
|
#ifdef IPFDEBUG
|
2002-03-19 11:45:20 +00:00
|
|
|
if (ipf_debug)
|
|
|
|
cmn_err(CE_NOTE, "IP Filter: _info(%x) = %x",
|
|
|
|
modinfop, ipfinst);
|
1997-11-16 04:52:19 +00:00
|
|
|
#endif
|
1999-11-08 20:51:23 +00:00
|
|
|
if (fr_running > 0)
|
|
|
|
ipfsync();
|
|
|
|
return ipfinst;
|
1997-02-09 22:50:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-11-16 04:52:19 +00:00
|
|
|
static int ipf_probe(dip)
|
|
|
|
dev_info_t *dip;
|
1997-02-09 22:50:16 +00:00
|
|
|
{
|
1999-11-08 20:51:23 +00:00
|
|
|
if (fr_running < 0)
|
|
|
|
return DDI_PROBE_FAILURE;
|
1997-02-09 22:50:16 +00:00
|
|
|
#ifdef IPFDEBUG
|
2002-03-19 11:45:20 +00:00
|
|
|
if (ipf_debug)
|
|
|
|
cmn_err(CE_NOTE, "IP Filter: ipf_probe(%x)", dip);
|
1997-02-09 22:50:16 +00:00
|
|
|
#endif
|
|
|
|
return DDI_PROBE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-11-16 04:52:19 +00:00
|
|
|
static int ipf_identify(dip)
|
|
|
|
dev_info_t *dip;
|
1997-02-09 22:50:16 +00:00
|
|
|
{
|
|
|
|
#ifdef IPFDEBUG
|
2002-03-19 11:45:20 +00:00
|
|
|
if (ipf_debug)
|
|
|
|
cmn_err(CE_NOTE, "IP Filter: ipf_identify(%x)", dip);
|
1997-02-09 22:50:16 +00:00
|
|
|
#endif
|
|
|
|
if (strcmp(ddi_get_name(dip), "ipf") == 0)
|
|
|
|
return (DDI_IDENTIFIED);
|
|
|
|
return (DDI_NOT_IDENTIFIED);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-28 11:59:33 +00:00
|
|
|
static void ipf_ire_walk(ire, arg)
|
|
|
|
ire_t *ire;
|
|
|
|
void *arg;
|
|
|
|
{
|
|
|
|
qif_t *qif = arg;
|
|
|
|
|
|
|
|
if ((ire->ire_type == IRE_CACHE) &&
|
|
|
|
#if SOLARIS2 >= 6
|
|
|
|
(ire->ire_ipif != NULL) &&
|
|
|
|
(ire->ire_ipif->ipif_ill == qif->qf_ill)
|
|
|
|
#else
|
|
|
|
(ire_to_ill(ire) == qif->qf_ill)
|
|
|
|
#endif
|
|
|
|
) {
|
|
|
|
#if SOLARIS2 >= 8
|
|
|
|
mblk_t *m = ire->ire_fp_mp;
|
|
|
|
#else
|
|
|
|
mblk_t *m = ire->ire_ll_hdr_mp;
|
|
|
|
#endif
|
|
|
|
if (m != NULL)
|
|
|
|
qif->qf_hl = m->b_wptr - m->b_rptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-11-16 04:52:19 +00:00
|
|
|
static int ipf_attach(dip, cmd)
|
1997-04-03 10:22:02 +00:00
|
|
|
dev_info_t *dip;
|
|
|
|
ddi_attach_cmd_t cmd;
|
1997-02-09 22:50:16 +00:00
|
|
|
{
|
1998-06-20 18:29:38 +00:00
|
|
|
#ifdef IPFDEBUG
|
1997-02-09 22:50:16 +00:00
|
|
|
int instance;
|
|
|
|
|
2002-03-19 11:45:20 +00:00
|
|
|
if (ipf_debug)
|
|
|
|
cmn_err(CE_NOTE, "IP Filter: ipf_attach(%x,%x)", dip, cmd);
|
1997-02-09 22:50:16 +00:00
|
|
|
#endif
|
|
|
|
switch (cmd) {
|
|
|
|
case DDI_ATTACH:
|
1999-11-08 20:51:23 +00:00
|
|
|
if (fr_running < 0)
|
|
|
|
break;
|
1997-02-09 22:50:16 +00:00
|
|
|
#ifdef IPFDEBUG
|
1998-06-20 18:29:38 +00:00
|
|
|
instance = ddi_get_instance(dip);
|
|
|
|
|
2002-03-19 11:45:20 +00:00
|
|
|
if (ipf_debug)
|
1997-11-16 04:52:19 +00:00
|
|
|
cmn_err(CE_NOTE, "IP Filter: attach ipf instance %d", instance);
|
1997-02-09 22:50:16 +00:00
|
|
|
#endif
|
1997-05-25 15:45:04 +00:00
|
|
|
if (ddi_create_minor_node(dip, "ipf", S_IFCHR, IPL_LOGIPF,
|
1997-02-09 22:50:16 +00:00
|
|
|
DDI_PSEUDO, 0) == DDI_FAILURE) {
|
|
|
|
ddi_remove_minor_node(dip, NULL);
|
|
|
|
goto attach_failed;
|
|
|
|
}
|
1997-05-25 15:45:04 +00:00
|
|
|
if (ddi_create_minor_node(dip, "ipnat", S_IFCHR, IPL_LOGNAT,
|
|
|
|
DDI_PSEUDO, 0) == DDI_FAILURE) {
|
1997-04-03 10:22:02 +00:00
|
|
|
ddi_remove_minor_node(dip, NULL);
|
|
|
|
goto attach_failed;
|
|
|
|
}
|
1997-05-25 15:45:04 +00:00
|
|
|
if (ddi_create_minor_node(dip, "ipstate", S_IFCHR,IPL_LOGSTATE,
|
|
|
|
DDI_PSEUDO, 0) == DDI_FAILURE) {
|
1997-04-03 10:22:02 +00:00
|
|
|
ddi_remove_minor_node(dip, NULL);
|
|
|
|
goto attach_failed;
|
|
|
|
}
|
1997-11-16 04:52:19 +00:00
|
|
|
if (ddi_create_minor_node(dip, "ipauth", S_IFCHR, IPL_LOGAUTH,
|
|
|
|
DDI_PSEUDO, 0) == DDI_FAILURE) {
|
|
|
|
ddi_remove_minor_node(dip, NULL);
|
|
|
|
goto attach_failed;
|
|
|
|
}
|
1997-02-09 22:50:16 +00:00
|
|
|
ipf_dev_info = dip;
|
|
|
|
sync();
|
|
|
|
/*
|
|
|
|
* Initialize mutex's
|
|
|
|
*/
|
1999-11-08 20:51:23 +00:00
|
|
|
if (iplattach() == -1)
|
|
|
|
goto attach_failed;
|
|
|
|
/*
|
|
|
|
* Lock people out while we set things up.
|
|
|
|
*/
|
|
|
|
WRITE_ENTER(&ipf_solaris);
|
1997-02-09 22:50:16 +00:00
|
|
|
solattach();
|
1997-11-16 04:52:19 +00:00
|
|
|
solipdrvattach();
|
1999-11-08 20:51:23 +00:00
|
|
|
RWLOCK_EXIT(&ipf_solaris);
|
2002-03-19 11:45:20 +00:00
|
|
|
cmn_err(CE_CONT, "%s, attaching complete.\n",
|
|
|
|
ipfilter_version);
|
1999-11-08 20:51:23 +00:00
|
|
|
sync();
|
|
|
|
if (fr_running == 0)
|
|
|
|
fr_running = 1;
|
|
|
|
if (ipfr_timer_id == 0)
|
|
|
|
ipfr_timer_id = timeout(ipfr_slowtimer, NULL,
|
|
|
|
drv_usectohz(500000));
|
|
|
|
if (fr_running == 1)
|
|
|
|
return DDI_SUCCESS;
|
2001-07-28 11:59:33 +00:00
|
|
|
#if SOLARIS2 >= 8
|
|
|
|
case DDI_RESUME :
|
|
|
|
case DDI_PM_RESUME :
|
|
|
|
if (ipfr_timer_id == 0)
|
|
|
|
ipfr_timer_id = timeout(ipfr_slowtimer, NULL,
|
|
|
|
drv_usectohz(500000));
|
|
|
|
return DDI_SUCCESS;
|
|
|
|
#endif
|
1997-02-09 22:50:16 +00:00
|
|
|
default:
|
1999-11-08 20:51:23 +00:00
|
|
|
return DDI_FAILURE;
|
1997-02-09 22:50:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
attach_failed:
|
1997-11-16 04:52:19 +00:00
|
|
|
cmn_err(CE_NOTE, "IP Filter: failed to attach\n");
|
1997-02-09 22:50:16 +00:00
|
|
|
/*
|
|
|
|
* Use our own detach routine to toss
|
|
|
|
* away any stuff we allocated above.
|
|
|
|
*/
|
1997-11-16 04:52:19 +00:00
|
|
|
(void) ipf_detach(dip, DDI_DETACH);
|
1999-11-08 20:51:23 +00:00
|
|
|
return DDI_FAILURE;
|
1997-02-09 22:50:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-11-16 04:52:19 +00:00
|
|
|
static int ipf_detach(dip, cmd)
|
1997-02-09 22:50:16 +00:00
|
|
|
dev_info_t *dip;
|
|
|
|
ddi_detach_cmd_t cmd;
|
|
|
|
{
|
1999-11-08 20:51:23 +00:00
|
|
|
int i;
|
1997-02-09 22:50:16 +00:00
|
|
|
|
|
|
|
#ifdef IPFDEBUG
|
2002-03-19 11:45:20 +00:00
|
|
|
if (ipf_debug)
|
|
|
|
cmn_err(CE_NOTE, "IP Filter: ipf_detach(%x,%x)", dip, cmd);
|
1997-02-09 22:50:16 +00:00
|
|
|
#endif
|
|
|
|
switch (cmd) {
|
|
|
|
case DDI_DETACH:
|
1999-11-08 20:51:23 +00:00
|
|
|
if (fr_running <= 0)
|
|
|
|
break;
|
|
|
|
/*
|
|
|
|
* Make sure we're the only one's modifying things. With
|
|
|
|
* this lock others should just fall out of the loop.
|
|
|
|
*/
|
|
|
|
mutex_enter(&ipf_rw);
|
|
|
|
if (ipfr_timer_id != 0) {
|
|
|
|
untimeout(ipfr_timer_id);
|
|
|
|
ipfr_timer_id = 0;
|
|
|
|
}
|
|
|
|
mutex_exit(&ipf_rw);
|
|
|
|
WRITE_ENTER(&ipf_solaris);
|
|
|
|
mutex_enter(&ipf_rw);
|
|
|
|
if (fr_running <= 0) {
|
|
|
|
mutex_exit(&ipf_rw);
|
|
|
|
return DDI_FAILURE;
|
|
|
|
}
|
|
|
|
fr_running = -1;
|
|
|
|
mutex_exit(&ipf_rw);
|
|
|
|
/* NOTE: ipf_solaris rwlock is released in ipldetach */
|
|
|
|
|
1997-02-09 22:50:16 +00:00
|
|
|
/*
|
1997-11-16 04:52:19 +00:00
|
|
|
* Undo what we did in ipf_attach, freeing resources
|
1997-02-09 22:50:16 +00:00
|
|
|
* and removing things we installed. The system
|
|
|
|
* framework guarantees we are not active with this devinfo
|
|
|
|
* node in any other entry points at this time.
|
|
|
|
*/
|
|
|
|
ddi_prop_remove_all(dip);
|
1999-11-08 20:51:23 +00:00
|
|
|
i = ddi_get_instance(dip);
|
1997-02-09 22:50:16 +00:00
|
|
|
ddi_remove_minor_node(dip, NULL);
|
|
|
|
sync();
|
1999-11-08 20:51:23 +00:00
|
|
|
i = solipdrvdetach();
|
|
|
|
if (i > 0) {
|
|
|
|
cmn_err(CE_CONT, "IP Filter: still attached (%d)\n", i);
|
|
|
|
return DDI_FAILURE;
|
|
|
|
}
|
1997-02-09 22:50:16 +00:00
|
|
|
if (!soldetach()) {
|
2000-05-24 02:14:22 +00:00
|
|
|
cmn_err(CE_CONT, "%s detached\n", ipfilter_version);
|
1997-02-09 22:50:16 +00:00
|
|
|
return (DDI_SUCCESS);
|
|
|
|
}
|
2001-07-28 11:59:33 +00:00
|
|
|
#if SOLARIS2 >= 8
|
|
|
|
case DDI_SUSPEND :
|
|
|
|
case DDI_PM_SUSPEND :
|
|
|
|
if (ipfr_timer_id != 0) {
|
|
|
|
untimeout(ipfr_timer_id);
|
|
|
|
ipfr_timer_id = 0;
|
|
|
|
}
|
|
|
|
if (synctimeoutid) {
|
|
|
|
untimeout(synctimeoutid);
|
|
|
|
synctimeoutid = 0;
|
|
|
|
}
|
|
|
|
return DDI_SUCCESS;
|
|
|
|
#endif
|
1997-02-09 22:50:16 +00:00
|
|
|
default:
|
|
|
|
return (DDI_FAILURE);
|
|
|
|
}
|
1999-11-08 20:51:23 +00:00
|
|
|
return DDI_FAILURE;
|
1997-02-09 22:50:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-11-16 04:52:19 +00:00
|
|
|
static int ipf_getinfo(dip, infocmd, arg, result)
|
1997-02-09 22:50:16 +00:00
|
|
|
dev_info_t *dip;
|
|
|
|
ddi_info_cmd_t infocmd;
|
|
|
|
void *arg, **result;
|
|
|
|
{
|
1999-11-08 20:51:23 +00:00
|
|
|
int error;
|
1997-02-09 22:50:16 +00:00
|
|
|
|
1999-11-08 20:51:23 +00:00
|
|
|
if (fr_running <= 0)
|
|
|
|
return DDI_FAILURE;
|
|
|
|
error = DDI_FAILURE;
|
1997-02-09 22:50:16 +00:00
|
|
|
#ifdef IPFDEBUG
|
2002-03-19 11:45:20 +00:00
|
|
|
if (ipf_debug)
|
|
|
|
cmn_err(CE_NOTE, "IP Filter: ipf_getinfo(%x,%x,%x)",
|
|
|
|
dip, infocmd, arg);
|
1997-02-09 22:50:16 +00:00
|
|
|
#endif
|
|
|
|
switch (infocmd) {
|
|
|
|
case DDI_INFO_DEVT2DEVINFO:
|
|
|
|
*result = ipf_dev_info;
|
|
|
|
error = DDI_SUCCESS;
|
|
|
|
break;
|
|
|
|
case DDI_INFO_DEVT2INSTANCE:
|
|
|
|
*result = (void *)getminor((dev_t) arg);
|
|
|
|
error = DDI_SUCCESS;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* find the filter structure setup for this queue
|
|
|
|
*/
|
1997-04-03 10:22:02 +00:00
|
|
|
static qif_t *qif_from_queue(q)
|
1997-02-09 22:50:16 +00:00
|
|
|
queue_t *q;
|
|
|
|
{
|
|
|
|
qif_t *qif;
|
|
|
|
|
|
|
|
for (qif = qif_head; qif; qif = qif->qf_next)
|
|
|
|
if ((qif->qf_iptr == q->q_ptr) || (qif->qf_optr == q->q_ptr))
|
|
|
|
break;
|
|
|
|
return qif;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* OK, this is pretty scrappy code, but then it's essentially just here for
|
|
|
|
* debug purposes and that's it. Packets should not normally come through
|
|
|
|
* here, and if they do, well, we would like to see as much information as
|
|
|
|
* possible about them and what they claim to hold.
|
|
|
|
*/
|
|
|
|
void fr_donotip(out, qif, q, m, mt, ip, off)
|
|
|
|
int out;
|
|
|
|
qif_t *qif;
|
|
|
|
queue_t *q;
|
|
|
|
mblk_t *m, *mt;
|
|
|
|
ip_t *ip;
|
1999-11-08 20:51:23 +00:00
|
|
|
size_t off;
|
1997-02-09 22:50:16 +00:00
|
|
|
{
|
|
|
|
u_char *s, outb[256], *t;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
outb[0] = '\0';
|
|
|
|
outb[1] = '\0';
|
|
|
|
outb[2] = '\0';
|
|
|
|
outb[3] = '\0';
|
|
|
|
s = ip ? (u_char *)ip : outb;
|
|
|
|
if (!ip && (m == mt) && m->b_cont && (MTYPE(m) != M_DATA))
|
|
|
|
m = m->b_cont;
|
|
|
|
|
2000-01-13 18:30:37 +00:00
|
|
|
cmn_err(CE_CONT, " !IP %s:%d %d %p %p %p %d %p/%d %p/%d %p %d %d %p\n",
|
2001-07-28 11:59:33 +00:00
|
|
|
qif ? qif->qf_name : "?", out, qif ? qif->qf_hl : -1, q,
|
1999-11-08 20:51:23 +00:00
|
|
|
q ? q->q_ptr : NULL, q ? q->q_qinfo : NULL,
|
|
|
|
mt->b_wptr - mt->b_rptr, m, MTYPE(m), mt, MTYPE(mt), m->b_rptr,
|
|
|
|
m->b_wptr - m->b_rptr, off, ip);
|
2000-01-13 18:30:37 +00:00
|
|
|
cmn_err(CE_CONT, "%02x%02x%02x%02x\n", *s, *(s+1), *(s+2), *(s+3));
|
1999-11-08 20:51:23 +00:00
|
|
|
while (m != mt) {
|
1997-02-09 22:50:16 +00:00
|
|
|
i = 0;
|
|
|
|
t = outb;
|
|
|
|
s = mt->b_rptr;
|
1999-11-08 20:51:23 +00:00
|
|
|
sprintf((char *)t, "%d:", MTYPE(mt));
|
|
|
|
t += strlen((char *)t);
|
1997-02-09 22:50:16 +00:00
|
|
|
for (; (i < 100) && (s < mt->b_wptr); i++) {
|
1999-11-08 20:51:23 +00:00
|
|
|
sprintf((char *)t, "%02x%s", *s++,
|
|
|
|
((i & 3) == 3) ? " " : "");
|
1997-02-09 22:50:16 +00:00
|
|
|
t += ((i & 3) == 3) ? 3 : 2;
|
|
|
|
}
|
|
|
|
*t++ = '\n';
|
|
|
|
*t = '\0';
|
2000-01-13 18:30:37 +00:00
|
|
|
cmn_err(CE_CONT, "%s", outb);
|
1999-11-08 20:51:23 +00:00
|
|
|
mt = mt->b_cont;
|
1997-02-09 22:50:16 +00:00
|
|
|
}
|
|
|
|
i = 0;
|
|
|
|
t = outb;
|
|
|
|
s = m->b_rptr;
|
1999-11-08 20:51:23 +00:00
|
|
|
sprintf((char *)t, "%d:", MTYPE(m));
|
|
|
|
t += strlen((char *)t);
|
1997-02-09 22:50:16 +00:00
|
|
|
for (; (i < 100) && (s < m->b_wptr); i++) {
|
1999-11-08 20:51:23 +00:00
|
|
|
sprintf((char *)t, "%02x%s", *s++, ((i & 3) == 3) ? " " : "");
|
1997-02-09 22:50:16 +00:00
|
|
|
t += ((i & 3) == 3) ? 3 : 2;
|
|
|
|
}
|
|
|
|
*t++ = '\n';
|
|
|
|
*t = '\0';
|
2000-01-13 18:30:37 +00:00
|
|
|
cmn_err(CE_CONT, "%s", outb);
|
1997-02-09 22:50:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* find the first data mblk, if present, in the chain we're processing. Also
|
|
|
|
* make a few sanity checks to try prevent the filter from causing a panic -
|
|
|
|
* none of the nice IP sanity checks (including checksumming) should have been
|
1999-11-08 20:51:23 +00:00
|
|
|
* done yet (for incoming packets) - dangerous!
|
1997-02-09 22:50:16 +00:00
|
|
|
*/
|
1997-11-16 04:52:19 +00:00
|
|
|
static int fr_precheck(mp, q, qif, out)
|
1997-02-09 22:50:16 +00:00
|
|
|
mblk_t **mp;
|
1997-11-16 04:52:19 +00:00
|
|
|
queue_t *q;
|
1997-02-09 22:50:16 +00:00
|
|
|
qif_t *qif;
|
|
|
|
int out;
|
|
|
|
{
|
1999-11-08 20:51:23 +00:00
|
|
|
register mblk_t *m, *mt = *mp;
|
1997-02-09 22:50:16 +00:00
|
|
|
register ip_t *ip;
|
2001-07-28 11:59:33 +00:00
|
|
|
size_t hlen, len, off, off2, mlen, iphlen, plen, woff;
|
|
|
|
int err, synced = 0, sap, p, realigned = 0, multi = 0;
|
1999-11-08 20:51:23 +00:00
|
|
|
u_char *bp;
|
2000-05-24 02:14:22 +00:00
|
|
|
#if SOLARIS2 >= 8
|
|
|
|
ip6_t *ip6;
|
|
|
|
#endif
|
1997-02-09 22:50:16 +00:00
|
|
|
#ifndef sparc
|
2000-05-24 02:14:22 +00:00
|
|
|
u_short __ipoff;
|
1997-02-09 22:50:16 +00:00
|
|
|
#endif
|
|
|
|
tryagain:
|
2000-05-24 02:14:22 +00:00
|
|
|
ip = NULL;
|
|
|
|
m = NULL;
|
1997-02-09 22:50:16 +00:00
|
|
|
/*
|
|
|
|
* If there is only M_DATA for a packet going out, then any header
|
|
|
|
* information (which would otherwise appear in an M_PROTO mblk before
|
|
|
|
* the M_DATA) is prepended before the IP header. We need to set the
|
|
|
|
* offset to account for this. - see MMM
|
|
|
|
*/
|
|
|
|
off = (out) ? qif->qf_hl : 0;
|
|
|
|
|
1999-11-08 20:51:23 +00:00
|
|
|
/*
|
|
|
|
* If the message protocol block indicates that there isn't a data
|
|
|
|
* block following it, just return back.
|
|
|
|
*/
|
|
|
|
bp = (u_char *)ALIGN32(mt->b_rptr);
|
|
|
|
if (MTYPE(mt) == M_PROTO || MTYPE(mt) == M_PCPROTO) {
|
|
|
|
dl_unitdata_ind_t *dl = (dl_unitdata_ind_t *)bp;
|
2001-07-28 11:59:33 +00:00
|
|
|
if (dl->dl_primitive == DL_UNITDATA_IND) {
|
|
|
|
multi = dl->dl_group_address;
|
|
|
|
m = mt->b_cont;
|
|
|
|
/*
|
|
|
|
* This is a complete kludge to try and work around
|
|
|
|
* some bizarre packets which drop through into
|
|
|
|
* fr_donotip.
|
|
|
|
*/
|
|
|
|
if (m && multi && ((*((u_char *)m->b_rptr) == 0x0) &&
|
|
|
|
((*((u_char *)m->b_rptr + 2) == 0x45)))) {
|
|
|
|
ip = (ip_t *)(m->b_rptr + 2);
|
|
|
|
off = 2;
|
|
|
|
} else
|
|
|
|
off = 0;
|
|
|
|
} else if (dl->dl_primitive != DL_UNITDATA_REQ) {
|
2000-05-24 02:14:22 +00:00
|
|
|
ip = (ip_t *)dl;
|
|
|
|
if ((ip->ip_v == IPVERSION) &&
|
|
|
|
(ip->ip_hl == (sizeof(*ip) >> 2)) &&
|
|
|
|
(ntohs(ip->ip_len) == mt->b_wptr - mt->b_rptr)) {
|
|
|
|
off = 0;
|
|
|
|
m = mt;
|
|
|
|
} else {
|
|
|
|
frstats[out].fr_notdata++;
|
|
|
|
return 0;
|
|
|
|
}
|
1999-11-08 20:51:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-02-09 22:50:16 +00:00
|
|
|
/*
|
|
|
|
* Find the first data block, count the data blocks in this chain and
|
|
|
|
* the total amount of data.
|
|
|
|
*/
|
2000-05-24 02:14:22 +00:00
|
|
|
if (ip == NULL)
|
|
|
|
for (m = mt; m && (MTYPE(m) != M_DATA); m = m->b_cont)
|
|
|
|
off = 0; /* Any non-M_DATA cancels the offset */
|
1997-02-09 22:50:16 +00:00
|
|
|
|
1999-11-08 20:51:23 +00:00
|
|
|
if (!m) {
|
|
|
|
frstats[out].fr_nodata++;
|
1997-02-09 22:50:16 +00:00
|
|
|
return 0; /* No data blocks */
|
1999-11-08 20:51:23 +00:00
|
|
|
}
|
|
|
|
|
1997-02-09 22:50:16 +00:00
|
|
|
ip = (ip_t *)(m->b_rptr + off); /* MMM */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We might have a 1st data block which is really M_PROTO, i.e. it is
|
|
|
|
* only big enough for the link layer header
|
|
|
|
*/
|
|
|
|
while ((u_char *)ip >= m->b_wptr) {
|
|
|
|
len = (u_char *)ip - m->b_wptr;
|
1999-11-08 20:51:23 +00:00
|
|
|
m = m->b_cont;
|
|
|
|
if (m == NULL)
|
1997-02-09 22:50:16 +00:00
|
|
|
return 0; /* not enough data for IP */
|
|
|
|
ip = (ip_t *)(m->b_rptr + len);
|
|
|
|
}
|
1999-11-08 20:51:23 +00:00
|
|
|
off = (u_char *)ip - m->b_rptr;
|
|
|
|
if (off != 0)
|
1997-02-09 22:50:16 +00:00
|
|
|
m->b_rptr = (u_char *)ip;
|
|
|
|
|
1999-11-08 20:51:23 +00:00
|
|
|
len = m->b_wptr - m->b_rptr;
|
|
|
|
if (m->b_wptr < m->b_rptr) {
|
2000-01-13 18:30:37 +00:00
|
|
|
cmn_err(CE_NOTE, "!IP Filter: Bad packet: wptr %p < rptr %p",
|
1999-11-08 20:51:23 +00:00
|
|
|
m->b_wptr, m->b_rptr);
|
|
|
|
frstats[out].fr_bad++;
|
|
|
|
return -1;
|
|
|
|
}
|
2000-05-24 02:14:22 +00:00
|
|
|
|
|
|
|
mlen = msgdsize(m);
|
|
|
|
sap = qif->qf_ill->ill_sap;
|
|
|
|
|
|
|
|
if (sap == 0x800) {
|
2000-07-19 13:52:47 +00:00
|
|
|
u_short tlen;
|
|
|
|
|
2000-05-24 02:14:22 +00:00
|
|
|
hlen = sizeof(*ip);
|
2000-07-19 13:52:47 +00:00
|
|
|
|
|
|
|
/* XXX - might not be aligned (from ppp?) */
|
|
|
|
((char *)&tlen)[0] = ((char *)&ip->ip_len)[0];
|
|
|
|
((char *)&tlen)[1] = ((char *)&ip->ip_len)[1];
|
|
|
|
|
|
|
|
plen = ntohs(tlen);
|
|
|
|
|
2000-05-24 02:14:22 +00:00
|
|
|
sap = 0;
|
|
|
|
}
|
|
|
|
#if SOLARIS2 >= 8
|
|
|
|
else if (sap == IP6_DL_SAP) {
|
2000-07-19 13:52:47 +00:00
|
|
|
u_short tlen;
|
|
|
|
|
2000-05-24 02:14:22 +00:00
|
|
|
hlen = sizeof(ip6_t);
|
|
|
|
ip6 = (ip6_t *)ip;
|
2000-07-19 13:52:47 +00:00
|
|
|
/* XXX - might not be aligned (from ppp?) */
|
2001-02-04 14:25:38 +00:00
|
|
|
((char *)&tlen)[0] = ((char *)&ip6->ip6_plen)[0];
|
|
|
|
((char *)&tlen)[1] = ((char *)&ip6->ip6_plen)[1];
|
2000-07-19 13:52:47 +00:00
|
|
|
plen = ntohs(tlen);
|
2001-07-28 11:59:33 +00:00
|
|
|
if (!plen)
|
|
|
|
return -1; /* Jumbo gram */
|
|
|
|
plen += sizeof(*ip6);
|
2000-05-24 02:14:22 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
else {
|
2001-07-28 11:59:33 +00:00
|
|
|
plen = 0;
|
2000-05-24 02:14:22 +00:00
|
|
|
hlen = 0;
|
|
|
|
sap = -1;
|
|
|
|
}
|
|
|
|
|
1997-02-09 22:50:16 +00:00
|
|
|
/*
|
1999-11-08 20:51:23 +00:00
|
|
|
* Ok, the IP header isn't on a 32bit aligned address so junk it.
|
1997-02-09 22:50:16 +00:00
|
|
|
*/
|
2001-07-28 11:59:33 +00:00
|
|
|
if (((u_long)ip & 0x3) || (plen > mlen) || (len < hlen) ||
|
|
|
|
(sap == -1)) {
|
|
|
|
mblk_t *m1, *m2;
|
|
|
|
u_char *s, c;
|
|
|
|
int v;
|
2000-05-24 02:14:22 +00:00
|
|
|
|
1999-11-08 20:51:23 +00:00
|
|
|
/*
|
2000-05-24 02:14:22 +00:00
|
|
|
* Junk using pullupmsg - it's next to useless.
|
1999-11-08 20:51:23 +00:00
|
|
|
*/
|
|
|
|
fixalign:
|
2001-07-28 11:59:33 +00:00
|
|
|
if (off)
|
|
|
|
m->b_rptr -= off;
|
|
|
|
c = *(u_char *)ip;
|
|
|
|
c >>= 4;
|
|
|
|
if (c != 4
|
|
|
|
#if SOLARIS2 >= 8
|
|
|
|
&& c != 6
|
|
|
|
#endif
|
|
|
|
) {
|
|
|
|
frstats[out].fr_notip++;
|
|
|
|
return (fr_flags & FF_BLOCKNONIP) ? -1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (realigned)
|
|
|
|
return -1;
|
|
|
|
realigned = 1;
|
|
|
|
off2 = (size_t)((u_long)ip & 0x3);
|
|
|
|
if (off2)
|
|
|
|
off2 = 4 - off2;
|
2000-05-24 02:14:22 +00:00
|
|
|
len = msgdsize(m);
|
2001-07-28 11:59:33 +00:00
|
|
|
m2 = allocb(len + off2, BPRI_HI);
|
2000-05-24 02:14:22 +00:00
|
|
|
if (m2 == NULL) {
|
1999-11-08 20:51:23 +00:00
|
|
|
frstats[out].fr_pull[1]++;
|
|
|
|
return -1;
|
|
|
|
}
|
2000-05-24 02:14:22 +00:00
|
|
|
|
2001-07-28 11:59:33 +00:00
|
|
|
MTYPE(m2) = M_DATA;
|
|
|
|
if (m->b_rptr != (u_char *)ip)
|
|
|
|
m2->b_rptr += off2;
|
2000-05-24 02:14:22 +00:00
|
|
|
m2->b_wptr = m2->b_rptr + len;
|
2001-07-28 11:59:33 +00:00
|
|
|
m1 = m;
|
|
|
|
s = (u_char *)m->b_rptr;
|
|
|
|
for (bp = m2->b_rptr; m1 && (bp < m2->b_wptr); bp += len) {
|
|
|
|
len = MIN(m1->b_wptr - s, m2->b_wptr - bp);
|
|
|
|
bcopy(s, bp, len);
|
|
|
|
m1 = m1->b_cont;
|
|
|
|
if (m1)
|
|
|
|
s = m1->b_rptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mt != m && mt->b_cont == m && !off) {
|
|
|
|
/*
|
|
|
|
* check if the buffer we're changing is chained in-
|
|
|
|
* between other buffers and unlink/relink as required.
|
|
|
|
*/
|
|
|
|
(void) unlinkb(mt); /* should return 'm' */
|
|
|
|
m1 = unlinkb(m);
|
|
|
|
if (m1)
|
|
|
|
linkb(m2, m1);
|
|
|
|
freemsg(m);
|
|
|
|
linkb(mt, m2);
|
|
|
|
} else {
|
|
|
|
if (m == mt) {
|
|
|
|
m1 = unlinkb(mt);
|
|
|
|
if (m1)
|
|
|
|
linkb(m2, m1);
|
|
|
|
}
|
|
|
|
freemsg(mt);
|
|
|
|
*mp = m2;
|
|
|
|
mt = m2;
|
2000-05-24 02:14:22 +00:00
|
|
|
}
|
|
|
|
|
1997-02-09 22:50:16 +00:00
|
|
|
frstats[out].fr_pull[0]++;
|
1999-11-08 20:51:23 +00:00
|
|
|
synced = 1;
|
|
|
|
off = 0;
|
|
|
|
goto tryagain;
|
|
|
|
}
|
2000-05-24 02:14:22 +00:00
|
|
|
|
|
|
|
if (((sap == 0) && (ip->ip_v != IP_VERSION))
|
|
|
|
#if SOLARIS2 >= 8
|
|
|
|
|| ((sap == IP6_DL_SAP) && ((ip6->ip6_vfc >> 4) != 6))
|
|
|
|
#endif
|
|
|
|
) {
|
1997-02-09 22:50:16 +00:00
|
|
|
m->b_rptr -= off;
|
2002-03-19 11:45:20 +00:00
|
|
|
return -2;
|
1997-02-09 22:50:16 +00:00
|
|
|
}
|
|
|
|
|
1999-11-08 20:51:23 +00:00
|
|
|
#ifndef sparc
|
2000-05-24 02:14:22 +00:00
|
|
|
# if SOLARIS2 >= 8
|
|
|
|
if (sap == IP6_DL_SAP) {
|
2001-07-28 11:59:33 +00:00
|
|
|
ip6->ip6_plen = plen - sizeof(*ip6);
|
2000-05-24 02:14:22 +00:00
|
|
|
} else {
|
|
|
|
# endif
|
|
|
|
__ipoff = (u_short)ip->ip_off;
|
1999-11-08 20:51:23 +00:00
|
|
|
|
2000-05-24 02:14:22 +00:00
|
|
|
ip->ip_len = plen;
|
|
|
|
ip->ip_off = ntohs(__ipoff);
|
|
|
|
# if SOLARIS2 >= 8
|
|
|
|
}
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
if (sap == 0)
|
|
|
|
iphlen = ip->ip_hl << 2;
|
|
|
|
#if SOLARIS2 >= 8
|
|
|
|
else if (sap == IP6_DL_SAP)
|
|
|
|
iphlen = sizeof(ip6_t);
|
1999-11-08 20:51:23 +00:00
|
|
|
#endif
|
|
|
|
|
2000-05-24 02:14:22 +00:00
|
|
|
if ((
|
|
|
|
#if SOLARIS2 >= 8
|
2001-07-28 11:59:33 +00:00
|
|
|
(sap == IP6_DL_SAP) && (mlen < plen)) ||
|
2000-05-24 02:14:22 +00:00
|
|
|
((sap == 0) &&
|
|
|
|
#endif
|
|
|
|
((iphlen < hlen) || (iphlen > plen) || (mlen < plen)))) {
|
1999-11-08 20:51:23 +00:00
|
|
|
/*
|
|
|
|
* Bad IP packet or not enough data/data length mismatches
|
|
|
|
*/
|
|
|
|
#ifndef sparc
|
2000-05-24 02:14:22 +00:00
|
|
|
# if SOLARIS2 >= 8
|
|
|
|
if (sap == IP6_DL_SAP) {
|
2001-07-28 11:59:33 +00:00
|
|
|
ip6->ip6_plen = htons(plen - sizeof(*ip6));
|
2000-05-24 02:14:22 +00:00
|
|
|
} else {
|
|
|
|
# endif
|
|
|
|
__ipoff = (u_short)ip->ip_off;
|
1999-11-08 20:51:23 +00:00
|
|
|
|
2000-05-24 02:14:22 +00:00
|
|
|
ip->ip_len = htons(plen);
|
|
|
|
ip->ip_off = htons(__ipoff);
|
|
|
|
# if SOLARIS2 >= 8
|
|
|
|
}
|
|
|
|
# endif
|
1999-11-08 20:51:23 +00:00
|
|
|
#endif
|
|
|
|
m->b_rptr -= off;
|
|
|
|
frstats[out].fr_bad++;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
1997-02-09 22:50:16 +00:00
|
|
|
/*
|
|
|
|
* Make hlen the total size of the IP header plus TCP/UDP/ICMP header
|
|
|
|
* (if it is one of these three).
|
|
|
|
*/
|
2000-05-24 02:14:22 +00:00
|
|
|
if (sap == 0)
|
|
|
|
p = ip->ip_p;
|
|
|
|
#if SOLARIS2 >= 8
|
|
|
|
else if (sap == IP6_DL_SAP)
|
|
|
|
p = ip6->ip6_nxt;
|
|
|
|
|
|
|
|
if ((sap == IP6_DL_SAP) || ((ip->ip_off & IP_OFFMASK) == 0))
|
|
|
|
#else
|
1999-11-08 20:51:23 +00:00
|
|
|
if ((ip->ip_off & IP_OFFMASK) == 0)
|
2000-05-24 02:14:22 +00:00
|
|
|
#endif
|
|
|
|
switch (p)
|
1997-02-09 22:50:16 +00:00
|
|
|
{
|
|
|
|
case IPPROTO_TCP :
|
|
|
|
hlen += sizeof(tcphdr_t);
|
|
|
|
break;
|
|
|
|
case IPPROTO_UDP :
|
|
|
|
hlen += sizeof(udphdr_t);
|
|
|
|
break;
|
|
|
|
case IPPROTO_ICMP :
|
1997-11-16 04:52:19 +00:00
|
|
|
/* 76 bytes is enough for a complete ICMP error. */
|
|
|
|
hlen += 76 + sizeof(icmphdr_t);
|
1997-02-09 22:50:16 +00:00
|
|
|
break;
|
|
|
|
default :
|
|
|
|
break;
|
|
|
|
}
|
1999-11-08 20:51:23 +00:00
|
|
|
|
2001-07-28 11:59:33 +00:00
|
|
|
woff = 0;
|
2000-05-24 02:14:22 +00:00
|
|
|
if (hlen > mlen) {
|
1999-11-08 20:51:23 +00:00
|
|
|
hlen = mlen;
|
2001-07-28 11:59:33 +00:00
|
|
|
} else if (m->b_wptr - m->b_rptr > plen) {
|
|
|
|
woff = m->b_wptr - m->b_rptr - plen;
|
|
|
|
m->b_wptr -= woff;
|
|
|
|
}
|
1999-11-08 20:51:23 +00:00
|
|
|
|
1997-02-09 22:50:16 +00:00
|
|
|
/*
|
|
|
|
* If we don't have enough data in the mblk or we haven't yet copied
|
|
|
|
* enough (above), then copy some more.
|
|
|
|
*/
|
|
|
|
if ((hlen > len)) {
|
1999-11-08 20:51:23 +00:00
|
|
|
if (!pullupmsg(m, (int)hlen)) {
|
2001-07-28 11:59:33 +00:00
|
|
|
cmn_err(CE_NOTE, "pullupmsg failed");
|
1999-11-08 20:51:23 +00:00
|
|
|
frstats[out].fr_pull[1]++;
|
|
|
|
return -1;
|
|
|
|
}
|
1997-02-09 22:50:16 +00:00
|
|
|
frstats[out].fr_pull[0]++;
|
1999-11-08 20:51:23 +00:00
|
|
|
ip = (ip_t *)ALIGN32(m->b_rptr);
|
1997-02-09 22:50:16 +00:00
|
|
|
}
|
|
|
|
qif->qf_m = m;
|
1997-11-16 04:52:19 +00:00
|
|
|
qif->qf_q = q;
|
|
|
|
qif->qf_off = off;
|
1997-02-09 22:50:16 +00:00
|
|
|
qif->qf_len = len;
|
1997-11-16 04:52:19 +00:00
|
|
|
err = fr_check(ip, iphlen, qif->qf_ill, out, qif, mp);
|
2001-07-28 11:59:33 +00:00
|
|
|
if (err == 2) {
|
1999-11-08 20:51:23 +00:00
|
|
|
goto fixalign;
|
2001-07-28 11:59:33 +00:00
|
|
|
}
|
1997-02-09 22:50:16 +00:00
|
|
|
/*
|
|
|
|
* Copy back the ip header data if it was changed, we haven't yet
|
|
|
|
* freed the message and we aren't going to drop the packet.
|
1999-11-08 20:51:23 +00:00
|
|
|
* BUT only do this if there were no changes to the buffer, else
|
|
|
|
* we can't be sure that the ip pointer is still correct!
|
1997-02-09 22:50:16 +00:00
|
|
|
*/
|
1999-11-08 20:51:23 +00:00
|
|
|
if (*mp != NULL) {
|
|
|
|
if (*mp == mt) {
|
2001-07-28 11:59:33 +00:00
|
|
|
m->b_wptr += woff;
|
1999-11-08 20:51:23 +00:00
|
|
|
m->b_rptr -= off;
|
1997-02-09 22:50:16 +00:00
|
|
|
#ifndef sparc
|
2000-05-24 02:14:22 +00:00
|
|
|
# if SOLARIS2 >= 8
|
|
|
|
if (sap == IP6_DL_SAP) {
|
2001-07-28 11:59:33 +00:00
|
|
|
ip6->ip6_plen = htons(plen - sizeof(*ip6));
|
2000-05-24 02:14:22 +00:00
|
|
|
} else {
|
|
|
|
# endif
|
|
|
|
__ipoff = (u_short)ip->ip_off;
|
|
|
|
/*
|
|
|
|
* plen is useless because of NAT.
|
|
|
|
*/
|
|
|
|
ip->ip_len = htons(ip->ip_len);
|
|
|
|
ip->ip_off = htons(__ipoff);
|
|
|
|
# if SOLARIS2 >= 8
|
|
|
|
}
|
|
|
|
# endif
|
1997-02-09 22:50:16 +00:00
|
|
|
#endif
|
1999-11-08 20:51:23 +00:00
|
|
|
} else
|
|
|
|
cmn_err(CE_NOTE,
|
2001-07-28 11:59:33 +00:00
|
|
|
"!IP Filter: *mp %p mt %p %s", *mp, mt,
|
1999-11-08 20:51:23 +00:00
|
|
|
"mblk changed, cannot revert ip_len, ip_off");
|
1997-02-09 22:50:16 +00:00
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-28 11:59:33 +00:00
|
|
|
/*
|
|
|
|
* Only called for M_IOCACK messages
|
|
|
|
*/
|
|
|
|
void fr_qif_update(qif, mp)
|
|
|
|
qif_t *qif;
|
|
|
|
mblk_t *mp;
|
|
|
|
{
|
|
|
|
struct iocblk *iocp;
|
|
|
|
|
|
|
|
if (!qif || !mp)
|
|
|
|
return;
|
|
|
|
iocp = (struct iocblk *)mp->b_rptr;
|
|
|
|
if (mp->b_cont && (iocp->ioc_cmd == DL_IOC_HDR_INFO)) {
|
|
|
|
mp = mp->b_cont;
|
|
|
|
if (MTYPE(mp) == M_PROTO && mp->b_cont) {
|
|
|
|
mp = mp->b_cont;
|
|
|
|
if (MTYPE(mp) == M_DATA) {
|
|
|
|
qif->qf_hl = mp->b_wptr - mp->b_rptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-11-16 04:52:19 +00:00
|
|
|
int fr_qin(q, mb)
|
1997-02-09 22:50:16 +00:00
|
|
|
queue_t *q;
|
|
|
|
mblk_t *mb;
|
|
|
|
{
|
1999-11-08 20:51:23 +00:00
|
|
|
int (*pnext) __P((queue_t *, mblk_t *)), type, synced = 0, err = 0;
|
|
|
|
qif_t qf, *qif;
|
1997-02-09 22:50:16 +00:00
|
|
|
|
2002-03-19 11:45:20 +00:00
|
|
|
#ifdef IPFDEBUG_VERBOSE
|
|
|
|
if (ipf_debug_verbose)
|
|
|
|
cmn_err(CE_CONT,
|
|
|
|
"fr_qin(%lx,%lx) ptr %lx type 0x%x ref %d len %d\n",
|
|
|
|
q, q->q_ptr, mb, MTYPE(mb), mb->b_datap->db_ref,
|
|
|
|
msgdsize(mb));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* IPFilter is still in the packet path but not enabled. Drop whatever
|
|
|
|
* it is that has come through.
|
|
|
|
*/
|
1999-11-08 20:51:23 +00:00
|
|
|
if (fr_running <= 0) {
|
|
|
|
mb->b_prev = NULL;
|
|
|
|
freemsg(mb);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-03-19 11:45:20 +00:00
|
|
|
type = MTYPE(mb);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If a mblk has more than one reference, make a copy, filter that and
|
|
|
|
* free a reference to the original.
|
|
|
|
*/
|
2000-05-24 02:14:22 +00:00
|
|
|
if (mb->b_datap->db_ref > 1) {
|
|
|
|
mblk_t *m1;
|
|
|
|
|
|
|
|
m1 = copymsg(mb);
|
2001-07-28 11:59:33 +00:00
|
|
|
if (!m1) {
|
|
|
|
frstats[0].fr_drop++;
|
|
|
|
mb->b_prev = NULL;
|
|
|
|
freemsg(mb);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
mb->b_prev = NULL;
|
2000-05-24 02:14:22 +00:00
|
|
|
freemsg(mb);
|
|
|
|
mb = m1;
|
|
|
|
frstats[0].fr_copy++;
|
|
|
|
}
|
|
|
|
|
1999-11-08 20:51:23 +00:00
|
|
|
READ_ENTER(&ipf_solaris);
|
1997-02-09 22:50:16 +00:00
|
|
|
again:
|
1999-11-08 20:51:23 +00:00
|
|
|
if (fr_running <= 0) {
|
|
|
|
mb->b_prev = NULL;
|
|
|
|
freemsg(mb);
|
2002-03-19 11:45:20 +00:00
|
|
|
RWLOCK_EXIT(&ipf_solaris);
|
1999-11-08 20:51:23 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
READ_ENTER(&ipfs_mutex);
|
|
|
|
if (!(qif = qif_from_queue(q))) {
|
1997-02-09 22:50:16 +00:00
|
|
|
for (qif = qif_head; qif; qif = qif->qf_next)
|
1997-11-16 04:52:19 +00:00
|
|
|
if (&qif->qf_rqinit == q->q_qinfo && qif->qf_rqinfo &&
|
|
|
|
qif->qf_rqinfo->qi_putp) {
|
|
|
|
pnext = qif->qf_rqinfo->qi_putp;
|
1997-02-09 22:50:16 +00:00
|
|
|
frstats[0].fr_notip++;
|
1999-11-08 20:51:23 +00:00
|
|
|
RWLOCK_EXIT(&ipfs_mutex);
|
1997-02-09 22:50:16 +00:00
|
|
|
if (!synced) {
|
|
|
|
ipfsync();
|
|
|
|
synced = 1;
|
|
|
|
goto again;
|
|
|
|
}
|
1999-11-08 20:51:23 +00:00
|
|
|
RWLOCK_EXIT(&ipf_solaris);
|
1997-02-09 22:50:16 +00:00
|
|
|
/* fr_donotip(0, NULL, q, mb, mb, NULL, 0); */
|
|
|
|
return (*pnext)(q, mb);
|
|
|
|
}
|
1999-11-08 20:51:23 +00:00
|
|
|
RWLOCK_EXIT(&ipfs_mutex);
|
1997-02-09 22:50:16 +00:00
|
|
|
if (!synced) {
|
|
|
|
ipfsync();
|
|
|
|
synced = 1;
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
cmn_err(CE_WARN,
|
2000-01-13 18:30:37 +00:00
|
|
|
"!IP Filter: dropped: fr_qin(%x,%x): type %x qif %x",
|
2002-03-19 11:45:20 +00:00
|
|
|
q, mb, type, qif);
|
1997-11-16 04:52:19 +00:00
|
|
|
cmn_err(CE_CONT,
|
2000-01-13 18:30:37 +00:00
|
|
|
"!IP Filter: info %x next %x ptr %x fsrv %x bsrv %x\n",
|
1997-02-09 22:50:16 +00:00
|
|
|
q->q_qinfo, q->q_next, q->q_ptr, q->q_nfsrv,
|
|
|
|
q->q_nbsrv);
|
2000-01-13 18:30:37 +00:00
|
|
|
cmn_err(CE_CONT, "!IP Filter: info: putp %x srvp %x info %x\n",
|
1997-02-09 22:50:16 +00:00
|
|
|
q->q_qinfo->qi_putp, q->q_qinfo->qi_srvp,
|
1997-11-16 04:52:19 +00:00
|
|
|
#if SOLARIS > 3
|
|
|
|
q->q_qinfo->qi_infop
|
|
|
|
#else
|
|
|
|
0
|
|
|
|
#endif
|
|
|
|
);
|
1997-02-09 22:50:16 +00:00
|
|
|
frstats[0].fr_drop++;
|
1999-11-08 20:51:23 +00:00
|
|
|
mb->b_prev = NULL;
|
1997-02-09 22:50:16 +00:00
|
|
|
freemsg(mb);
|
2002-03-19 11:45:20 +00:00
|
|
|
RWLOCK_EXIT(&ipf_solaris);
|
1997-02-09 22:50:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-03-19 11:45:20 +00:00
|
|
|
qif->qf_incnt++;
|
1999-11-08 20:51:23 +00:00
|
|
|
pnext = qif->qf_rqinfo->qi_putp;
|
2001-07-28 11:59:33 +00:00
|
|
|
if (type == M_IOCACK)
|
|
|
|
fr_qif_update(qif, mb);
|
2002-03-19 11:45:20 +00:00
|
|
|
bcopy((char *)qif, (char *)&qf, sizeof(qf));
|
|
|
|
if (datamsg(type) || (type == M_BREAK))
|
|
|
|
err = fr_precheck(&mb, q, &qf, 0);
|
1999-11-08 20:51:23 +00:00
|
|
|
|
|
|
|
RWLOCK_EXIT(&ipfs_mutex);
|
|
|
|
|
|
|
|
if ((err == 0) && (mb != NULL)) {
|
2002-03-19 11:45:20 +00:00
|
|
|
if (pnext) {
|
|
|
|
RWLOCK_EXIT(&ipf_solaris);
|
1997-02-09 22:50:16 +00:00
|
|
|
return (*pnext)(q, mb);
|
2002-03-19 11:45:20 +00:00
|
|
|
}
|
1997-02-09 22:50:16 +00:00
|
|
|
|
2001-07-28 11:59:33 +00:00
|
|
|
cmn_err(CE_WARN,
|
|
|
|
"!IP Filter: inp NULL: qif %x %s q %x info %x",
|
2002-03-19 11:45:20 +00:00
|
|
|
qif, qf.qf_name, q, q->q_qinfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (err == -2) {
|
|
|
|
if (synced == 0) {
|
|
|
|
ipfsync();
|
|
|
|
synced = 1;
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
frstats[0].fr_notip++;
|
|
|
|
if (!(fr_flags & FF_BLOCKNONIP) && (pnext != NULL)) {
|
|
|
|
RWLOCK_EXIT(&ipf_solaris);
|
|
|
|
return (*pnext)(q, mb);
|
|
|
|
}
|
1999-11-08 20:51:23 +00:00
|
|
|
}
|
2002-03-19 11:45:20 +00:00
|
|
|
|
|
|
|
|
1999-11-08 20:51:23 +00:00
|
|
|
if (mb) {
|
|
|
|
mb->b_prev = NULL;
|
1997-02-09 22:50:16 +00:00
|
|
|
freemsg(mb);
|
|
|
|
}
|
2002-03-19 11:45:20 +00:00
|
|
|
RWLOCK_EXIT(&ipf_solaris);
|
2002-04-25 03:34:26 +00:00
|
|
|
return 1;
|
1997-02-09 22:50:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-11-16 04:52:19 +00:00
|
|
|
int fr_qout(q, mb)
|
1997-02-09 22:50:16 +00:00
|
|
|
queue_t *q;
|
|
|
|
mblk_t *mb;
|
|
|
|
{
|
1999-11-08 20:51:23 +00:00
|
|
|
int (*pnext) __P((queue_t *, mblk_t *)), type, synced = 0, err = 0;
|
|
|
|
qif_t qf, *qif;
|
1997-02-09 22:50:16 +00:00
|
|
|
|
2002-03-19 11:45:20 +00:00
|
|
|
#ifdef IPFDEBUG_VERBOSE
|
|
|
|
if (ipf_debug_verbose)
|
|
|
|
cmn_err(CE_CONT,
|
|
|
|
"fr_qout(%lx,%lx) ptr %lx type 0x%x ref %d len %d\n",
|
|
|
|
q, q->q_ptr, mb, MTYPE(mb), mb->b_datap->db_ref,
|
|
|
|
msgdsize(mb));
|
|
|
|
#endif
|
|
|
|
|
1999-11-08 20:51:23 +00:00
|
|
|
if (fr_running <= 0) {
|
|
|
|
mb->b_prev = NULL;
|
|
|
|
freemsg(mb);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-03-19 11:45:20 +00:00
|
|
|
type = MTYPE(mb);
|
|
|
|
|
2001-07-28 11:59:33 +00:00
|
|
|
#if SOLARIS2 >= 6
|
|
|
|
if ((!dohwcksum || mb->b_ick_flag != ICK_VALID) &&
|
|
|
|
(mb->b_datap->db_ref > 1))
|
|
|
|
#else
|
|
|
|
if (mb->b_datap->db_ref > 1)
|
|
|
|
#endif
|
|
|
|
{
|
2000-05-24 02:14:22 +00:00
|
|
|
mblk_t *m1;
|
|
|
|
|
|
|
|
m1 = copymsg(mb);
|
2001-07-28 11:59:33 +00:00
|
|
|
if (!m1) {
|
|
|
|
frstats[1].fr_drop++;
|
|
|
|
mb->b_prev = NULL;
|
|
|
|
freemsg(mb);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
mb->b_prev = NULL;
|
2000-05-24 02:14:22 +00:00
|
|
|
freemsg(mb);
|
|
|
|
mb = m1;
|
|
|
|
frstats[1].fr_copy++;
|
|
|
|
}
|
|
|
|
|
1999-11-08 20:51:23 +00:00
|
|
|
READ_ENTER(&ipf_solaris);
|
1997-02-09 22:50:16 +00:00
|
|
|
again:
|
1999-11-08 20:51:23 +00:00
|
|
|
if (fr_running <= 0) {
|
|
|
|
mb->b_prev = NULL;
|
|
|
|
freemsg(mb);
|
2002-03-19 11:45:20 +00:00
|
|
|
RWLOCK_EXIT(&ipf_solaris);
|
1999-11-08 20:51:23 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
READ_ENTER(&ipfs_mutex);
|
1997-02-09 22:50:16 +00:00
|
|
|
if (!(qif = qif_from_queue(q))) {
|
|
|
|
for (qif = qif_head; qif; qif = qif->qf_next)
|
1997-11-16 04:52:19 +00:00
|
|
|
if (&qif->qf_wqinit == q->q_qinfo && qif->qf_wqinfo &&
|
|
|
|
qif->qf_wqinfo->qi_putp) {
|
|
|
|
pnext = qif->qf_wqinfo->qi_putp;
|
1999-11-08 20:51:23 +00:00
|
|
|
RWLOCK_EXIT(&ipfs_mutex);
|
1997-02-09 22:50:16 +00:00
|
|
|
frstats[1].fr_notip++;
|
|
|
|
if (!synced) {
|
|
|
|
ipfsync();
|
|
|
|
synced = 1;
|
|
|
|
goto again;
|
|
|
|
}
|
2001-07-28 11:59:33 +00:00
|
|
|
/* fr_donotip(1, NULL, q, mb, mb, NULL, 0); */
|
1999-11-08 20:51:23 +00:00
|
|
|
RWLOCK_EXIT(&ipf_solaris);
|
1997-02-09 22:50:16 +00:00
|
|
|
return (*pnext)(q, mb);
|
|
|
|
}
|
1999-11-08 20:51:23 +00:00
|
|
|
RWLOCK_EXIT(&ipfs_mutex);
|
1997-02-09 22:50:16 +00:00
|
|
|
if (!synced) {
|
|
|
|
ipfsync();
|
|
|
|
synced = 1;
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
cmn_err(CE_WARN,
|
2000-01-13 18:30:37 +00:00
|
|
|
"!IP Filter: dropped: fr_qout(%x,%x): type %x: qif %x",
|
2002-03-19 11:45:20 +00:00
|
|
|
q, mb, type, qif);
|
1997-11-16 04:52:19 +00:00
|
|
|
cmn_err(CE_CONT,
|
2000-01-13 18:30:37 +00:00
|
|
|
"!IP Filter: info %x next %x ptr %x fsrv %x bsrv %x\n",
|
1997-02-09 22:50:16 +00:00
|
|
|
q->q_qinfo, q->q_next, q->q_ptr, q->q_nfsrv,
|
|
|
|
q->q_nbsrv);
|
2000-01-13 18:30:37 +00:00
|
|
|
cmn_err(CE_CONT, "!IP Filter: info: putp %x srvp %x info %x\n",
|
1997-02-09 22:50:16 +00:00
|
|
|
q->q_qinfo->qi_putp, q->q_qinfo->qi_srvp,
|
1997-11-16 04:52:19 +00:00
|
|
|
#if SOLARIS > 3
|
|
|
|
q->q_qinfo->qi_infop
|
|
|
|
#else
|
|
|
|
0
|
|
|
|
#endif
|
|
|
|
);
|
1997-02-09 22:50:16 +00:00
|
|
|
if (q->q_nfsrv)
|
1997-11-16 04:52:19 +00:00
|
|
|
cmn_err(CE_CONT,
|
2000-01-13 18:30:37 +00:00
|
|
|
"!IP Filter: nfsrv: info %x next %x ptr %x\n",
|
1997-02-09 22:50:16 +00:00
|
|
|
q->q_nfsrv->q_qinfo, q->q_nfsrv->q_next,
|
|
|
|
q->q_nfsrv->q_ptr);
|
|
|
|
if (q->q_nbsrv)
|
1997-11-16 04:52:19 +00:00
|
|
|
cmn_err(CE_CONT,
|
2000-01-13 18:30:37 +00:00
|
|
|
"!IP Filter: nbsrv: info %x next %x ptr %x\n",
|
1997-02-09 22:50:16 +00:00
|
|
|
q->q_nbsrv->q_qinfo, q->q_nbsrv->q_next,
|
|
|
|
q->q_nbsrv->q_ptr);
|
|
|
|
frstats[1].fr_drop++;
|
1999-11-08 20:51:23 +00:00
|
|
|
mb->b_prev = NULL;
|
1997-02-09 22:50:16 +00:00
|
|
|
freemsg(mb);
|
2002-03-19 11:45:20 +00:00
|
|
|
RWLOCK_EXIT(&ipf_solaris);
|
1997-02-09 22:50:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-03-19 11:45:20 +00:00
|
|
|
qif->qf_outcnt++;
|
1999-11-08 20:51:23 +00:00
|
|
|
pnext = qif->qf_wqinfo->qi_putp;
|
2001-07-28 11:59:33 +00:00
|
|
|
if (type == M_IOCACK)
|
|
|
|
fr_qif_update(qif, mb);
|
2002-03-19 11:45:20 +00:00
|
|
|
bcopy((char *)qif, (char *)&qf, sizeof(qf));
|
|
|
|
if (datamsg(type) || (type == M_BREAK))
|
|
|
|
err = fr_precheck(&mb, q, &qf, 1);
|
1999-11-08 20:51:23 +00:00
|
|
|
|
|
|
|
RWLOCK_EXIT(&ipfs_mutex);
|
|
|
|
|
|
|
|
if ((err == 0) && (mb != NULL)) {
|
2002-03-19 11:45:20 +00:00
|
|
|
if (pnext) {
|
|
|
|
RWLOCK_EXIT(&ipf_solaris);
|
1997-02-09 22:50:16 +00:00
|
|
|
return (*pnext)(q, mb);
|
2002-03-19 11:45:20 +00:00
|
|
|
}
|
1997-02-09 22:50:16 +00:00
|
|
|
|
2000-01-13 18:30:37 +00:00
|
|
|
cmn_err(CE_WARN,
|
|
|
|
"!IP Filter: outp NULL: qif %x %s q %x info %x",
|
2002-03-19 11:45:20 +00:00
|
|
|
qif, qf.qf_name, q, q->q_qinfo);
|
1999-11-08 20:51:23 +00:00
|
|
|
}
|
2002-03-19 11:45:20 +00:00
|
|
|
|
|
|
|
if (err == -2) {
|
|
|
|
if (synced == 0) {
|
|
|
|
ipfsync();
|
|
|
|
synced = 1;
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
frstats[1].fr_notip++;
|
|
|
|
if (!(fr_flags & FF_BLOCKNONIP) && (pnext != NULL)) {
|
|
|
|
RWLOCK_EXIT(&ipf_solaris);
|
|
|
|
return (*pnext)(q, mb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-11-08 20:51:23 +00:00
|
|
|
if (mb) {
|
|
|
|
mb->b_prev = NULL;
|
1997-02-09 22:50:16 +00:00
|
|
|
freemsg(mb);
|
|
|
|
}
|
2002-03-19 11:45:20 +00:00
|
|
|
RWLOCK_EXIT(&ipf_solaris);
|
2002-04-25 03:34:26 +00:00
|
|
|
return 1;
|
1997-02-09 22:50:16 +00:00
|
|
|
}
|
|
|
|
|
1997-11-16 04:52:19 +00:00
|
|
|
|
|
|
|
void ipf_synctimeout(arg)
|
1999-11-08 20:51:23 +00:00
|
|
|
void *arg;
|
1997-11-16 04:52:19 +00:00
|
|
|
{
|
2000-02-09 20:46:45 +00:00
|
|
|
if (fr_running < 0)
|
|
|
|
return;
|
1999-11-08 20:51:23 +00:00
|
|
|
READ_ENTER(&ipf_solaris);
|
1997-11-16 04:52:19 +00:00
|
|
|
ipfsync();
|
1999-11-08 20:51:23 +00:00
|
|
|
WRITE_ENTER(&ipfs_mutex);
|
1997-11-16 04:52:19 +00:00
|
|
|
synctimeoutid = 0;
|
1999-11-08 20:51:23 +00:00
|
|
|
RWLOCK_EXIT(&ipfs_mutex);
|
|
|
|
RWLOCK_EXIT(&ipf_solaris);
|
1997-11-16 04:52:19 +00:00
|
|
|
}
|
|
|
|
|
2001-07-28 11:59:33 +00:00
|
|
|
|
1999-11-08 20:51:23 +00:00
|
|
|
static int ipf_ip_qin(q, mb)
|
1997-11-16 04:52:19 +00:00
|
|
|
queue_t *q;
|
1999-11-08 20:51:23 +00:00
|
|
|
mblk_t *mb;
|
1997-11-16 04:52:19 +00:00
|
|
|
{
|
|
|
|
struct iocblk *ioc;
|
|
|
|
int ret;
|
1999-11-08 20:51:23 +00:00
|
|
|
|
|
|
|
if (fr_running <= 0) {
|
|
|
|
mb->b_prev = NULL;
|
|
|
|
freemsg(mb);
|
|
|
|
return 0;
|
|
|
|
}
|
2000-05-24 02:14:22 +00:00
|
|
|
|
1999-11-08 20:51:23 +00:00
|
|
|
if (MTYPE(mb) != M_IOCTL)
|
|
|
|
return (*ipf_ip_inp)(q, mb);
|
1997-11-16 04:52:19 +00:00
|
|
|
|
1999-11-08 20:51:23 +00:00
|
|
|
READ_ENTER(&ipf_solaris);
|
|
|
|
if (fr_running <= 0) {
|
|
|
|
RWLOCK_EXIT(&ipf_solaris);
|
|
|
|
mb->b_prev = NULL;
|
|
|
|
freemsg(mb);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
ioc = (struct iocblk *)mb->b_rptr;
|
1997-11-16 04:52:19 +00:00
|
|
|
|
2001-07-28 11:59:33 +00:00
|
|
|
switch (ioc->ioc_cmd)
|
|
|
|
{
|
|
|
|
case DL_IOC_HDR_INFO:
|
|
|
|
fr_qif_update(qif_from_queue(q), mb);
|
|
|
|
break;
|
1997-11-16 04:52:19 +00:00
|
|
|
case I_LINK:
|
|
|
|
case I_UNLINK:
|
|
|
|
case SIOCSIFADDR:
|
|
|
|
case SIOCSIFFLAGS:
|
|
|
|
#ifdef IPFDEBUG
|
2002-03-19 11:45:20 +00:00
|
|
|
if (ipf_debug)
|
|
|
|
cmn_err(CE_NOTE,
|
|
|
|
"IP Filter: ipf_ip_qin() M_IOCTL type=0x%x",
|
|
|
|
ioc->ioc_cmd);
|
1997-11-16 04:52:19 +00:00
|
|
|
#endif
|
1999-11-08 20:51:23 +00:00
|
|
|
WRITE_ENTER(&ipfs_mutex);
|
1997-11-16 04:52:19 +00:00
|
|
|
if (synctimeoutid == 0) {
|
1999-11-08 20:51:23 +00:00
|
|
|
synctimeoutid = timeout(ipf_synctimeout,
|
1997-11-16 04:52:19 +00:00
|
|
|
NULL,
|
|
|
|
drv_usectohz(1000000) /*1 sec*/
|
|
|
|
);
|
1999-11-08 20:51:23 +00:00
|
|
|
}
|
|
|
|
RWLOCK_EXIT(&ipfs_mutex);
|
|
|
|
break;
|
1997-11-16 04:52:19 +00:00
|
|
|
default:
|
2000-01-13 18:30:37 +00:00
|
|
|
break;
|
1997-11-16 04:52:19 +00:00
|
|
|
}
|
1999-11-08 20:51:23 +00:00
|
|
|
RWLOCK_EXIT(&ipf_solaris);
|
2000-01-13 18:30:37 +00:00
|
|
|
return (*ipf_ip_inp)(q, mb);
|
1997-11-16 04:52:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int ipdrvattcnt = 0;
|
|
|
|
extern struct streamtab ipinfo;
|
|
|
|
|
|
|
|
void solipdrvattach()
|
|
|
|
{
|
|
|
|
#ifdef IPFDEBUG
|
2002-03-19 11:45:20 +00:00
|
|
|
if (ipf_debug)
|
|
|
|
cmn_err(CE_NOTE, "IP Filter: solipdrvattach() %d ipinfo=0x%lx",
|
|
|
|
ipdrvattcnt, &ipinfo);
|
1997-11-16 04:52:19 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (++ipdrvattcnt == 1) {
|
|
|
|
if (ipf_ip_inp == NULL) {
|
|
|
|
ipf_ip_inp = ipinfo.st_wrinit->qi_putp;
|
|
|
|
ipinfo.st_wrinit->qi_putp = ipf_ip_qin;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int solipdrvdetach()
|
|
|
|
{
|
|
|
|
#ifdef IPFDEBUG
|
2002-03-19 11:45:20 +00:00
|
|
|
if (ipf_debug)
|
|
|
|
cmn_err(CE_NOTE, "IP Filter: solipdrvdetach() %d ipinfo=0x%lx",
|
|
|
|
ipdrvattcnt, &ipinfo);
|
1997-11-16 04:52:19 +00:00
|
|
|
#endif
|
|
|
|
|
1999-11-08 20:51:23 +00:00
|
|
|
WRITE_ENTER(&ipfs_mutex);
|
1997-11-16 04:52:19 +00:00
|
|
|
if (--ipdrvattcnt <= 0) {
|
|
|
|
if (ipf_ip_inp && (ipinfo.st_wrinit->qi_putp == ipf_ip_qin)) {
|
|
|
|
ipinfo.st_wrinit->qi_putp = ipf_ip_inp;
|
|
|
|
ipf_ip_inp = NULL;
|
|
|
|
}
|
|
|
|
if (synctimeoutid) {
|
|
|
|
untimeout(synctimeoutid);
|
1999-11-08 20:51:23 +00:00
|
|
|
synctimeoutid = 0;
|
|
|
|
}
|
1997-11-16 04:52:19 +00:00
|
|
|
}
|
1999-11-08 20:51:23 +00:00
|
|
|
RWLOCK_EXIT(&ipfs_mutex);
|
|
|
|
return ipdrvattcnt;
|
1997-11-16 04:52:19 +00:00
|
|
|
}
|
1997-02-09 22:50:16 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* attach the packet filter to each interface that is defined as having an
|
|
|
|
* IP address associated with it and save some of the info. for that struct
|
1999-11-08 20:51:23 +00:00
|
|
|
* so we're not out of date as soon as the ill disappears - but we must sync
|
1997-02-09 22:50:16 +00:00
|
|
|
* to be correct!
|
|
|
|
*/
|
1997-11-16 04:52:19 +00:00
|
|
|
void solattach()
|
1997-02-09 22:50:16 +00:00
|
|
|
{
|
|
|
|
queue_t *in, *out;
|
1997-11-16 04:52:19 +00:00
|
|
|
struct frentry *f;
|
1999-11-08 20:51:23 +00:00
|
|
|
qif_t *qif, *qf2;
|
1997-11-16 04:52:19 +00:00
|
|
|
ipnat_t *np;
|
1999-11-08 20:51:23 +00:00
|
|
|
size_t len;
|
|
|
|
ill_t *il;
|
1997-02-09 22:50:16 +00:00
|
|
|
|
|
|
|
for (il = ill_g_head; il; il = il->ill_next) {
|
|
|
|
in = il->ill_rq;
|
|
|
|
if (!in || !il->ill_wq)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
out = il->ill_wq->q_next;
|
|
|
|
|
1999-11-08 20:51:23 +00:00
|
|
|
WRITE_ENTER(&ipfs_mutex);
|
1997-02-09 22:50:16 +00:00
|
|
|
/*
|
|
|
|
* Look for entry already setup for this device
|
|
|
|
*/
|
|
|
|
for (qif = qif_head; qif; qif = qif->qf_next)
|
|
|
|
if (qif->qf_iptr == in->q_ptr &&
|
|
|
|
qif->qf_optr == out->q_ptr)
|
|
|
|
break;
|
|
|
|
if (qif) {
|
1999-11-08 20:51:23 +00:00
|
|
|
RWLOCK_EXIT(&ipfs_mutex);
|
1997-02-09 22:50:16 +00:00
|
|
|
continue;
|
|
|
|
}
|
2002-03-19 11:45:20 +00:00
|
|
|
#ifdef IPFDEBUGX
|
|
|
|
if (ipf_debug)
|
1997-02-09 22:50:16 +00:00
|
|
|
cmn_err(CE_NOTE,
|
|
|
|
"IP Filter: il %x ipt %x opt %x ipu %x opu %x i %x/%x",
|
|
|
|
il, in->q_ptr, out->q_ptr, in->q_qinfo->qi_putp,
|
|
|
|
out->q_qinfo->qi_putp, out->q_qinfo, in->q_qinfo);
|
|
|
|
#endif
|
1999-11-08 20:51:23 +00:00
|
|
|
KMALLOC(qif, qif_t *);
|
1997-11-16 04:52:19 +00:00
|
|
|
if (!qif) {
|
2000-01-13 18:30:37 +00:00
|
|
|
cmn_err(CE_WARN,
|
2001-07-28 11:59:33 +00:00
|
|
|
"IP Filter: malloc(%d) for qif_t failed",
|
1997-11-16 04:52:19 +00:00
|
|
|
sizeof(qif_t));
|
1999-11-08 20:51:23 +00:00
|
|
|
RWLOCK_EXIT(&ipfs_mutex);
|
1997-11-16 04:52:19 +00:00
|
|
|
continue;
|
|
|
|
}
|
1997-02-09 22:50:16 +00:00
|
|
|
|
|
|
|
if (in->q_qinfo->qi_putp == fr_qin) {
|
|
|
|
for (qf2 = qif_head; qf2; qf2 = qf2->qf_next)
|
1997-11-16 04:52:19 +00:00
|
|
|
if (&qf2->qf_rqinit == in->q_qinfo) {
|
|
|
|
qif->qf_rqinfo = qf2->qf_rqinfo;
|
1997-02-09 22:50:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!qf2) {
|
2002-03-19 11:45:20 +00:00
|
|
|
#ifdef IPFDEBUGX
|
|
|
|
if (ipf_debug)
|
1997-02-09 22:50:16 +00:00
|
|
|
cmn_err(CE_WARN,
|
|
|
|
"IP Filter: rq:%s put %x qi %x",
|
|
|
|
il->ill_name, in->q_qinfo->qi_putp,
|
|
|
|
in->q_qinfo);
|
|
|
|
#endif
|
1999-11-08 20:51:23 +00:00
|
|
|
RWLOCK_EXIT(&ipfs_mutex);
|
1997-02-09 22:50:16 +00:00
|
|
|
KFREE(qif);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else
|
1997-11-16 04:52:19 +00:00
|
|
|
qif->qf_rqinfo = in->q_qinfo;
|
1997-02-09 22:50:16 +00:00
|
|
|
|
|
|
|
if (out->q_qinfo->qi_putp == fr_qout) {
|
|
|
|
for (qf2 = qif_head; qf2; qf2 = qf2->qf_next)
|
1997-11-16 04:52:19 +00:00
|
|
|
if (&qf2->qf_wqinit == out->q_qinfo) {
|
|
|
|
qif->qf_wqinfo = qf2->qf_wqinfo;
|
1997-02-09 22:50:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!qf2) {
|
2002-03-19 11:45:20 +00:00
|
|
|
#ifdef IPFDEBUGX
|
|
|
|
if (ipf_debug)
|
1997-02-09 22:50:16 +00:00
|
|
|
cmn_err(CE_WARN,
|
|
|
|
"IP Filter: wq:%s put %x qi %x",
|
|
|
|
il->ill_name, out->q_qinfo->qi_putp,
|
|
|
|
out->q_qinfo);
|
|
|
|
#endif
|
1999-11-08 20:51:23 +00:00
|
|
|
RWLOCK_EXIT(&ipfs_mutex);
|
1997-02-09 22:50:16 +00:00
|
|
|
KFREE(qif);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else
|
1997-11-16 04:52:19 +00:00
|
|
|
qif->qf_wqinfo = out->q_qinfo;
|
1997-02-09 22:50:16 +00:00
|
|
|
|
|
|
|
qif->qf_ill = il;
|
1999-11-08 20:51:23 +00:00
|
|
|
qif->qf_in = in;
|
|
|
|
qif->qf_out = out;
|
1997-02-09 22:50:16 +00:00
|
|
|
qif->qf_iptr = in->q_ptr;
|
|
|
|
qif->qf_optr = out->q_ptr;
|
2000-01-13 18:30:37 +00:00
|
|
|
#if SOLARIS2 < 8
|
1997-02-09 22:50:16 +00:00
|
|
|
qif->qf_hl = il->ill_hdr_length;
|
2000-01-13 18:30:37 +00:00
|
|
|
#else
|
|
|
|
{
|
|
|
|
ire_t *ire;
|
|
|
|
mblk_t *m;
|
|
|
|
|
|
|
|
qif->qf_hl = 0;
|
2000-05-24 02:14:22 +00:00
|
|
|
qif->qf_sap = il->ill_sap;
|
2000-01-13 18:30:37 +00:00
|
|
|
# if 0
|
|
|
|
/*
|
|
|
|
* Can't seem to lookup a route for the IP address on the
|
|
|
|
* interface itself.
|
|
|
|
*/
|
|
|
|
ire = ire_route_lookup(il->ill_ipif->ipif_lcl_addr, 0xffffffff,
|
|
|
|
0, 0, NULL, NULL, NULL,
|
|
|
|
MATCH_IRE_DSTONLY|MATCH_IRE_RECURSIVE);
|
|
|
|
if ((ire != NULL) && (m = ire->ire_fp_mp))
|
|
|
|
qif->qf_hl = m->b_wptr - m->b_rptr;
|
|
|
|
# endif
|
|
|
|
if ((qif->qf_hl == 0) && (il->ill_type > 0) &&
|
|
|
|
(il->ill_type < 0x37) &&
|
|
|
|
(hdrsizes[il->ill_type][0] == il->ill_type))
|
|
|
|
qif->qf_hl = hdrsizes[il->ill_type][1];
|
|
|
|
|
2002-03-19 11:45:20 +00:00
|
|
|
/* DREADFUL VLAN HACK - JUST HERE TO CHECK IT WORKS */
|
|
|
|
if (il->ill_type == IFT_ETHER &&
|
|
|
|
il->ill_name[0] == 'c' && il->ill_name[1] == 'e' &&
|
|
|
|
isdigit(il->ill_name[2]) && il->ill_name_length >= 6) {
|
|
|
|
cmn_err(CE_NOTE, "VLAN HACK ENABLED");
|
|
|
|
qif->qf_hl += 4;
|
|
|
|
}
|
|
|
|
/* DREADFUL VLAN HACK - JUST HERE TO CHECK IT WORKS */
|
|
|
|
|
2001-07-28 11:59:33 +00:00
|
|
|
if (qif->qf_hl == 0 && il->ill_type != IFT_OTHER)
|
2000-01-13 18:30:37 +00:00
|
|
|
cmn_err(CE_WARN,
|
2001-07-28 11:59:33 +00:00
|
|
|
"Unknown layer 2 header size for %s type %d",
|
|
|
|
il->ill_name, il->ill_type);
|
2000-01-13 18:30:37 +00:00
|
|
|
}
|
2001-07-28 11:59:33 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX Awful hack for PPP; fix when PPP/snoop fixed.
|
|
|
|
*/
|
|
|
|
if (il->ill_type == IFT_ETHER && !il->ill_bcast_addr_length)
|
|
|
|
qif->qf_hl = 0;
|
2000-01-13 18:30:37 +00:00
|
|
|
#endif
|
1997-02-09 22:50:16 +00:00
|
|
|
strncpy(qif->qf_name, il->ill_name, sizeof(qif->qf_name));
|
|
|
|
qif->qf_name[sizeof(qif->qf_name) - 1] = '\0';
|
|
|
|
|
|
|
|
qif->qf_next = qif_head;
|
|
|
|
qif_head = qif;
|
1997-11-16 04:52:19 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Activate any rules directly associated with this interface
|
|
|
|
*/
|
1999-11-08 20:51:23 +00:00
|
|
|
WRITE_ENTER(&ipf_mutex);
|
1998-06-20 18:29:38 +00:00
|
|
|
for (f = ipfilter[0][fr_active]; f; f = f->fr_next) {
|
1997-11-16 04:52:19 +00:00
|
|
|
if ((f->fr_ifa == (struct ifnet *)-1)) {
|
1999-11-08 20:51:23 +00:00
|
|
|
len = strlen(f->fr_ifname) + 1;
|
|
|
|
if ((len != 0) &&
|
|
|
|
(len == (size_t)il->ill_name_length) &&
|
1997-11-16 04:52:19 +00:00
|
|
|
!strncmp(il->ill_name, f->fr_ifname, len))
|
|
|
|
f->fr_ifa = il;
|
|
|
|
}
|
|
|
|
}
|
1998-06-20 18:29:38 +00:00
|
|
|
for (f = ipfilter[1][fr_active]; f; f = f->fr_next) {
|
1997-11-16 04:52:19 +00:00
|
|
|
if ((f->fr_ifa == (struct ifnet *)-1)) {
|
1999-11-08 20:51:23 +00:00
|
|
|
len = strlen(f->fr_ifname) + 1;
|
|
|
|
if ((len != 0) &&
|
|
|
|
(len == (size_t)il->ill_name_length) &&
|
1997-11-16 04:52:19 +00:00
|
|
|
!strncmp(il->ill_name, f->fr_ifname, len))
|
|
|
|
f->fr_ifa = il;
|
|
|
|
}
|
|
|
|
}
|
2000-05-24 02:14:22 +00:00
|
|
|
#if SOLARIS2 >= 8
|
|
|
|
for (f = ipfilter6[0][fr_active]; f; f = f->fr_next) {
|
|
|
|
if ((f->fr_ifa == (struct ifnet *)-1)) {
|
|
|
|
len = strlen(f->fr_ifname) + 1;
|
|
|
|
if ((len != 0) &&
|
|
|
|
(len == (size_t)il->ill_name_length) &&
|
|
|
|
!strncmp(il->ill_name, f->fr_ifname, len))
|
|
|
|
f->fr_ifa = il;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (f = ipfilter6[1][fr_active]; f; f = f->fr_next) {
|
|
|
|
if ((f->fr_ifa == (struct ifnet *)-1)) {
|
|
|
|
len = strlen(f->fr_ifname) + 1;
|
|
|
|
if ((len != 0) &&
|
|
|
|
(len == (size_t)il->ill_name_length) &&
|
|
|
|
!strncmp(il->ill_name, f->fr_ifname, len))
|
|
|
|
f->fr_ifa = il;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
1999-11-08 20:51:23 +00:00
|
|
|
RWLOCK_EXIT(&ipf_mutex);
|
|
|
|
WRITE_ENTER(&ipf_nat);
|
1997-11-16 04:52:19 +00:00
|
|
|
for (np = nat_list; np; np = np->in_next) {
|
|
|
|
if ((np->in_ifp == (struct ifnet *)-1)) {
|
1999-11-08 20:51:23 +00:00
|
|
|
len = strlen(np->in_ifname) + 1;
|
|
|
|
if ((len != 0) &&
|
|
|
|
(len == (size_t)il->ill_name_length) &&
|
1997-11-16 04:52:19 +00:00
|
|
|
!strncmp(il->ill_name, np->in_ifname, len))
|
|
|
|
np->in_ifp = il;
|
|
|
|
}
|
|
|
|
}
|
1999-11-08 20:51:23 +00:00
|
|
|
RWLOCK_EXIT(&ipf_nat);
|
1997-11-16 04:52:19 +00:00
|
|
|
|
|
|
|
bcopy((caddr_t)qif->qf_rqinfo, (caddr_t)&qif->qf_rqinit,
|
|
|
|
sizeof(struct qinit));
|
|
|
|
qif->qf_rqinit.qi_putp = fr_qin;
|
|
|
|
#ifdef IPFDEBUG
|
2002-03-19 11:45:20 +00:00
|
|
|
if (ipf_debug)
|
|
|
|
cmn_err(CE_NOTE,
|
|
|
|
"IP Filter: solattach: in queue(%lx)->q_qinfo FROM %lx TO %lx",
|
|
|
|
in, in->q_qinfo, &qif->qf_rqinit);
|
1997-11-16 04:52:19 +00:00
|
|
|
#endif
|
|
|
|
in->q_qinfo = &qif->qf_rqinit;
|
|
|
|
|
|
|
|
bcopy((caddr_t)qif->qf_wqinfo, (caddr_t)&qif->qf_wqinit,
|
|
|
|
sizeof(struct qinit));
|
|
|
|
qif->qf_wqinit.qi_putp = fr_qout;
|
|
|
|
#ifdef IPFDEBUG
|
2002-03-19 11:45:20 +00:00
|
|
|
if (ipf_debug)
|
|
|
|
cmn_err(CE_NOTE,
|
|
|
|
"IP Filter: solattach: out queue(%lx)->q_qinfo FROM %lx TO %lx",
|
|
|
|
out, out->q_qinfo, &qif->qf_wqinit);
|
1997-11-16 04:52:19 +00:00
|
|
|
#endif
|
|
|
|
out->q_qinfo = &qif->qf_wqinit;
|
|
|
|
|
2001-07-28 11:59:33 +00:00
|
|
|
ire_walk(ipf_ire_walk, (char *)qif);
|
1999-11-08 20:51:23 +00:00
|
|
|
RWLOCK_EXIT(&ipfs_mutex);
|
2000-05-24 02:14:22 +00:00
|
|
|
cmn_err(CE_CONT, "IP Filter: attach to [%s,%d] - %s\n",
|
|
|
|
qif->qf_name, il->ill_ppa,
|
|
|
|
#if SOLARIS2 >= 8
|
|
|
|
il->ill_isv6 ? "IPv6" : "IPv4"
|
|
|
|
#else
|
|
|
|
"IPv4"
|
|
|
|
#endif
|
|
|
|
);
|
1997-02-09 22:50:16 +00:00
|
|
|
}
|
1997-11-16 04:52:19 +00:00
|
|
|
if (!qif_head)
|
1997-02-09 22:50:16 +00:00
|
|
|
cmn_err(CE_CONT, "IP Filter: not attached to any interfaces\n");
|
1997-11-16 04:52:19 +00:00
|
|
|
return;
|
1997-02-09 22:50:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* look for bad consistancies between the list of interfaces the filter knows
|
|
|
|
* about and those which are currently configured.
|
|
|
|
*/
|
|
|
|
int ipfsync()
|
|
|
|
{
|
1997-11-16 04:52:19 +00:00
|
|
|
register struct frentry *f;
|
|
|
|
register ipnat_t *np;
|
1997-02-09 22:50:16 +00:00
|
|
|
register qif_t *qif, **qp;
|
|
|
|
register ill_t *il;
|
1997-11-16 04:52:19 +00:00
|
|
|
queue_t *in, *out;
|
1997-02-09 22:50:16 +00:00
|
|
|
|
1999-11-08 20:51:23 +00:00
|
|
|
WRITE_ENTER(&ipfs_mutex);
|
1997-02-09 22:50:16 +00:00
|
|
|
for (qp = &qif_head; (qif = *qp); ) {
|
|
|
|
for (il = ill_g_head; il; il = il->ill_next)
|
|
|
|
if ((qif->qf_ill == il) &&
|
|
|
|
!strcmp(qif->qf_name, il->ill_name)) {
|
2000-01-13 18:30:37 +00:00
|
|
|
#if SOLARIS2 < 8
|
1997-02-09 22:50:16 +00:00
|
|
|
mblk_t *m = il->ill_hdr_mp;
|
|
|
|
|
|
|
|
qif->qf_hl = il->ill_hdr_length;
|
|
|
|
if (m && qif->qf_hl != (m->b_wptr - m->b_rptr))
|
1997-11-16 04:52:19 +00:00
|
|
|
cmn_err(CE_NOTE,
|
|
|
|
"IP Filter: ILL Header Length Mismatch\n");
|
2000-01-13 18:30:37 +00:00
|
|
|
#endif
|
1997-02-09 22:50:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (il) {
|
|
|
|
qp = &qif->qf_next;
|
|
|
|
continue;
|
|
|
|
}
|
2000-05-24 02:14:22 +00:00
|
|
|
cmn_err(CE_CONT, "IP Filter: detaching [%s] - %s\n",
|
|
|
|
qif->qf_name,
|
|
|
|
#if SOLARIS2 >= 8
|
|
|
|
(qif->qf_sap == IP6_DL_SAP) ? "IPv6" : "IPv4"
|
|
|
|
#else
|
|
|
|
"IPv4"
|
|
|
|
#endif
|
|
|
|
);
|
1997-02-09 22:50:16 +00:00
|
|
|
*qp = qif->qf_next;
|
|
|
|
|
|
|
|
/*
|
1997-11-16 04:52:19 +00:00
|
|
|
* Disable any rules directly associated with this interface
|
1997-02-09 22:50:16 +00:00
|
|
|
*/
|
1999-11-08 20:51:23 +00:00
|
|
|
WRITE_ENTER(&ipf_nat);
|
1997-11-16 04:52:19 +00:00
|
|
|
for (np = nat_list; np; np = np->in_next)
|
|
|
|
if (np->in_ifp == (void *)qif->qf_ill)
|
|
|
|
np->in_ifp = (struct ifnet *)-1;
|
1999-11-08 20:51:23 +00:00
|
|
|
RWLOCK_EXIT(&ipf_nat);
|
|
|
|
WRITE_ENTER(&ipf_mutex);
|
1998-06-20 18:29:38 +00:00
|
|
|
for (f = ipfilter[0][fr_active]; f; f = f->fr_next)
|
1997-11-16 04:52:19 +00:00
|
|
|
if (f->fr_ifa == (void *)qif->qf_ill)
|
|
|
|
f->fr_ifa = (struct ifnet *)-1;
|
1998-06-20 18:29:38 +00:00
|
|
|
for (f = ipfilter[1][fr_active]; f; f = f->fr_next)
|
1997-11-16 04:52:19 +00:00
|
|
|
if (f->fr_ifa == (void *)qif->qf_ill)
|
|
|
|
f->fr_ifa = (struct ifnet *)-1;
|
2000-05-24 02:14:22 +00:00
|
|
|
#if SOLARIS2 >= 8
|
|
|
|
for (f = ipfilter6[0][fr_active]; f; f = f->fr_next)
|
|
|
|
if (f->fr_ifa == (void *)qif->qf_ill)
|
|
|
|
f->fr_ifa = (struct ifnet *)-1;
|
|
|
|
for (f = ipfilter6[1][fr_active]; f; f = f->fr_next)
|
|
|
|
if (f->fr_ifa == (void *)qif->qf_ill)
|
|
|
|
f->fr_ifa = (struct ifnet *)-1;
|
|
|
|
#endif
|
1997-11-16 04:52:19 +00:00
|
|
|
|
1999-11-08 20:51:23 +00:00
|
|
|
#if 0 /* XXX */
|
|
|
|
/*
|
|
|
|
* As well as the ill disappearing when a device is unplumb'd,
|
|
|
|
* it also appears that the associated queue structures also
|
|
|
|
* disappear - at least in the case of ppp, which is the most
|
|
|
|
* volatile here. Thanks to Greg for finding this problem.
|
|
|
|
*/
|
1997-11-16 04:52:19 +00:00
|
|
|
/*
|
|
|
|
* Restore q_qinfo pointers in interface queues
|
|
|
|
*/
|
1999-11-08 20:51:23 +00:00
|
|
|
out = qif->qf_out;
|
|
|
|
in = qif->qf_in;
|
1997-11-16 04:52:19 +00:00
|
|
|
if (in) {
|
1999-11-08 20:51:23 +00:00
|
|
|
# ifdef IPFDEBUG
|
2002-03-19 11:45:20 +00:00
|
|
|
if (ipf_debug)
|
|
|
|
cmn_err(CE_NOTE,
|
|
|
|
"IP Filter: ipfsync: in queue(%lx)->q_qinfo FROM %lx TO %lx",
|
|
|
|
in, in->q_qinfo, qif->qf_rqinfo);
|
1999-11-08 20:51:23 +00:00
|
|
|
# endif
|
1997-11-16 04:52:19 +00:00
|
|
|
in->q_qinfo = qif->qf_rqinfo;
|
|
|
|
}
|
|
|
|
if (out) {
|
1999-11-08 20:51:23 +00:00
|
|
|
# ifdef IPFDEBUG
|
2002-03-19 11:45:20 +00:00
|
|
|
if (ipf_debug)
|
|
|
|
cmn_err(CE_NOTE,
|
|
|
|
"IP Filter: ipfsync: out queue(%lx)->q_qinfo FROM %lx TO %lx",
|
|
|
|
out, out->q_qinfo, qif->qf_wqinfo);
|
1999-11-08 20:51:23 +00:00
|
|
|
# endif
|
1997-11-16 04:52:19 +00:00
|
|
|
out->q_qinfo = qif->qf_wqinfo;
|
|
|
|
}
|
1999-11-08 20:51:23 +00:00
|
|
|
#endif /* XXX */
|
|
|
|
RWLOCK_EXIT(&ipf_mutex);
|
1997-02-09 22:50:16 +00:00
|
|
|
KFREE(qif);
|
|
|
|
qif = *qp;
|
|
|
|
}
|
1999-11-08 20:51:23 +00:00
|
|
|
RWLOCK_EXIT(&ipfs_mutex);
|
1997-11-16 04:52:19 +00:00
|
|
|
solattach();
|
|
|
|
|
2000-01-13 18:30:37 +00:00
|
|
|
frsync();
|
1997-11-16 04:52:19 +00:00
|
|
|
/*
|
|
|
|
* Resync. any NAT `connections' using this interface and its IP #.
|
|
|
|
*/
|
2000-02-09 20:46:45 +00:00
|
|
|
for (il = ill_g_head; il; il = il->ill_next) {
|
1997-11-16 04:52:19 +00:00
|
|
|
ip_natsync((void *)il);
|
2000-02-09 20:46:45 +00:00
|
|
|
ip_statesync((void *)il);
|
|
|
|
}
|
1997-11-16 04:52:19 +00:00
|
|
|
return 0;
|
1997-02-09 22:50:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* unhook the IP filter from all defined interfaces with IP addresses
|
|
|
|
*/
|
|
|
|
int soldetach()
|
|
|
|
{
|
|
|
|
queue_t *in, *out;
|
1999-11-08 20:51:23 +00:00
|
|
|
qif_t *qif, **qp;
|
1997-02-09 22:50:16 +00:00
|
|
|
ill_t *il;
|
|
|
|
|
1999-11-08 20:51:23 +00:00
|
|
|
WRITE_ENTER(&ipfs_mutex);
|
1997-02-09 22:50:16 +00:00
|
|
|
/*
|
|
|
|
* Make two passes, first get rid of all the unknown devices, next
|
|
|
|
* unlink known devices.
|
|
|
|
*/
|
|
|
|
for (qp = &qif_head; (qif = *qp); ) {
|
|
|
|
for (il = ill_g_head; il; il = il->ill_next)
|
|
|
|
if (qif->qf_ill == il)
|
|
|
|
break;
|
|
|
|
if (il) {
|
|
|
|
qp = &qif->qf_next;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
cmn_err(CE_CONT, "IP Filter: removing [%s]\n", qif->qf_name);
|
|
|
|
*qp = qif->qf_next;
|
|
|
|
KFREE(qif);
|
|
|
|
}
|
|
|
|
|
|
|
|
while ((qif = qif_head)) {
|
|
|
|
qif_head = qif->qf_next;
|
|
|
|
for (il = ill_g_head; il; il = il->ill_next)
|
|
|
|
if (qif->qf_ill == il)
|
|
|
|
break;
|
|
|
|
if (il) {
|
1999-11-08 20:51:23 +00:00
|
|
|
in = qif->qf_in;
|
|
|
|
out = qif->qf_out;
|
2000-05-24 02:14:22 +00:00
|
|
|
cmn_err(CE_CONT, "IP Filter: detaching [%s,%d] - %s\n",
|
|
|
|
qif->qf_name, il->ill_ppa,
|
|
|
|
#if SOLARIS2 >= 8
|
|
|
|
(qif->qf_sap == IP6_DL_SAP) ? "IPv6" : "IPv4"
|
|
|
|
#else
|
|
|
|
"IPv4"
|
|
|
|
#endif
|
|
|
|
);
|
1997-11-16 04:52:19 +00:00
|
|
|
|
|
|
|
#ifdef IPFDEBUG
|
2002-03-19 11:45:20 +00:00
|
|
|
if (ipf_debug)
|
|
|
|
cmn_err(CE_NOTE,
|
|
|
|
"IP Filter: soldetach: in queue(%lx)->q_qinfo FROM %lx TO %lx",
|
|
|
|
in, in->q_qinfo, qif->qf_rqinfo);
|
1997-11-16 04:52:19 +00:00
|
|
|
#endif
|
|
|
|
in->q_qinfo = qif->qf_rqinfo;
|
|
|
|
|
1997-02-09 22:50:16 +00:00
|
|
|
/*
|
|
|
|
* and the write queue...
|
|
|
|
*/
|
1997-11-16 04:52:19 +00:00
|
|
|
#ifdef IPFDEBUG
|
2002-03-19 11:45:20 +00:00
|
|
|
if (ipf_debug)
|
|
|
|
cmn_err(CE_NOTE,
|
|
|
|
"IP Filter: soldetach: out queue(%lx)->q_qinfo FROM %lx TO %lx",
|
|
|
|
out, out->q_qinfo, qif->qf_wqinfo);
|
1997-11-16 04:52:19 +00:00
|
|
|
#endif
|
|
|
|
out->q_qinfo = qif->qf_wqinfo;
|
1997-02-09 22:50:16 +00:00
|
|
|
}
|
|
|
|
KFREE(qif);
|
|
|
|
}
|
1999-11-08 20:51:23 +00:00
|
|
|
RWLOCK_EXIT(&ipfs_mutex);
|
1997-02-09 22:50:16 +00:00
|
|
|
return ipldetach();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-11-16 04:52:19 +00:00
|
|
|
#ifdef IPFDEBUG
|
1997-04-03 10:22:02 +00:00
|
|
|
void printire(ire)
|
1997-02-09 22:50:16 +00:00
|
|
|
ire_t *ire;
|
|
|
|
{
|
2002-03-19 11:45:20 +00:00
|
|
|
if (!ipf_debug)
|
|
|
|
return;
|
1997-11-16 04:52:19 +00:00
|
|
|
printf("ire: ll_hdr_mp %p rfq %p stq %p src_addr %x max_frag %d\n",
|
2000-05-24 02:14:22 +00:00
|
|
|
# if SOLARIS2 >= 8
|
|
|
|
NULL,
|
|
|
|
# else
|
|
|
|
ire->ire_ll_hdr_mp,
|
|
|
|
# endif
|
|
|
|
ire->ire_rfq, ire->ire_stq,
|
1997-02-09 22:50:16 +00:00
|
|
|
ire->ire_src_addr, ire->ire_max_frag);
|
|
|
|
printf("ire: mask %x addr %x gateway_addr %x type %d\n",
|
|
|
|
ire->ire_mask, ire->ire_addr, ire->ire_gateway_addr,
|
|
|
|
ire->ire_type);
|
1997-11-16 04:52:19 +00:00
|
|
|
printf("ire: ll_hdr_length %d ll_hdr_saved_mp %p\n",
|
2000-05-24 02:14:22 +00:00
|
|
|
ire->ire_ll_hdr_length,
|
|
|
|
# if SOLARIS2 >= 8
|
|
|
|
NULL
|
|
|
|
# else
|
|
|
|
ire->ire_ll_hdr_saved_mp
|
|
|
|
# endif
|
|
|
|
);
|
1997-02-09 22:50:16 +00:00
|
|
|
}
|
1997-11-16 04:52:19 +00:00
|
|
|
#endif
|
1997-02-09 22:50:16 +00:00
|
|
|
|
|
|
|
|
2000-07-19 13:52:47 +00:00
|
|
|
int ipfr_fastroute(ip, mb, mpp, fin, fdp)
|
1997-02-09 22:50:16 +00:00
|
|
|
ip_t *ip;
|
|
|
|
mblk_t *mb, **mpp;
|
|
|
|
fr_info_t *fin;
|
|
|
|
frdest_t *fdp;
|
|
|
|
{
|
2000-05-24 02:14:22 +00:00
|
|
|
#ifdef USE_INET6
|
|
|
|
ip6_t *ip6 = (ip6_t *)ip;
|
|
|
|
#endif
|
1999-11-08 20:51:23 +00:00
|
|
|
ire_t *ir, *dir, *gw;
|
1997-02-09 22:50:16 +00:00
|
|
|
struct in_addr dst;
|
|
|
|
queue_t *q = NULL;
|
1999-11-08 20:51:23 +00:00
|
|
|
mblk_t *mp = NULL;
|
|
|
|
size_t hlen = 0;
|
|
|
|
frentry_t *fr;
|
2000-05-24 02:14:22 +00:00
|
|
|
frdest_t fd;
|
2000-01-13 18:30:37 +00:00
|
|
|
ill_t *ifp;
|
1999-11-08 20:51:23 +00:00
|
|
|
u_char *s;
|
2000-07-19 13:52:47 +00:00
|
|
|
qif_t *qf;
|
2000-05-24 02:14:22 +00:00
|
|
|
int p;
|
1997-02-09 22:50:16 +00:00
|
|
|
|
|
|
|
#ifndef sparc
|
|
|
|
u_short __iplen, __ipoff;
|
1999-11-08 20:51:23 +00:00
|
|
|
#endif
|
2000-07-19 13:52:47 +00:00
|
|
|
qf = fin->fin_qif;
|
|
|
|
|
1997-02-09 22:50:16 +00:00
|
|
|
/*
|
|
|
|
* If this is a duplicate mblk then we want ip to point at that
|
|
|
|
* data, not the original, if and only if it is already pointing at
|
|
|
|
* the current mblk data.
|
|
|
|
*/
|
2001-07-28 11:59:33 +00:00
|
|
|
if ((ip == (ip_t *)qf->qf_m->b_rptr) && (qf->qf_m != mb))
|
1997-02-09 22:50:16 +00:00
|
|
|
ip = (ip_t *)mb->b_rptr;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If there is another M_PROTO, we don't want it
|
|
|
|
*/
|
|
|
|
if (*mpp != mb) {
|
2000-02-09 20:46:45 +00:00
|
|
|
mp = *mpp;
|
|
|
|
(void) unlinkb(mp);
|
|
|
|
mp = (*mpp)->b_cont;
|
1997-02-09 22:50:16 +00:00
|
|
|
(*mpp)->b_cont = NULL;
|
1999-11-08 20:51:23 +00:00
|
|
|
(*mpp)->b_prev = NULL;
|
1997-02-09 22:50:16 +00:00
|
|
|
freemsg(*mpp);
|
2000-02-09 20:46:45 +00:00
|
|
|
*mpp = mp;
|
1997-02-09 22:50:16 +00:00
|
|
|
}
|
|
|
|
|
2000-05-24 02:14:22 +00:00
|
|
|
if (!fdp) {
|
|
|
|
ipif_t *ipif;
|
|
|
|
|
|
|
|
ifp = fin->fin_ifp;
|
|
|
|
ipif = ifp->ill_ipif;
|
|
|
|
if (!ipif)
|
|
|
|
goto bad_fastroute;
|
|
|
|
#if SOLARIS2 > 5
|
|
|
|
ir = ire_ctable_lookup(ipif->ipif_local_addr, 0, IRE_LOCAL,
|
|
|
|
NULL, NULL, MATCH_IRE_TYPE);
|
|
|
|
#else
|
|
|
|
ir = ire_lookup_myaddr(ipif->ipif_local_addr);
|
|
|
|
#endif
|
|
|
|
if (!ir)
|
|
|
|
ir = (ire_t *)-1;
|
|
|
|
|
2001-07-28 11:59:33 +00:00
|
|
|
fd.fd_ifp = (struct ifnet *)ir;
|
2000-05-24 02:14:22 +00:00
|
|
|
fd.fd_ip = ip->ip_dst;
|
|
|
|
fdp = &fd;
|
|
|
|
}
|
|
|
|
|
1997-02-09 22:50:16 +00:00
|
|
|
ir = (ire_t *)fdp->fd_ifp;
|
|
|
|
|
|
|
|
if (fdp->fd_ip.s_addr)
|
|
|
|
dst = fdp->fd_ip;
|
|
|
|
else
|
2000-05-24 02:14:22 +00:00
|
|
|
dst.s_addr = fin->fin_fi.fi_daddr;
|
1997-02-09 22:50:16 +00:00
|
|
|
|
2000-01-13 18:30:37 +00:00
|
|
|
#if SOLARIS2 >= 6
|
1999-11-08 20:51:23 +00:00
|
|
|
gw = NULL;
|
2000-05-24 02:14:22 +00:00
|
|
|
if (fin->fin_v == 4) {
|
|
|
|
p = ip->ip_p;
|
|
|
|
dir = ire_route_lookup(dst.s_addr, 0xffffffff, 0, 0, NULL,
|
|
|
|
&gw, NULL, MATCH_IRE_DSTONLY|
|
|
|
|
MATCH_IRE_DEFAULT|MATCH_IRE_RECURSIVE);
|
|
|
|
}
|
|
|
|
# ifdef USE_INET6
|
|
|
|
else if (fin->fin_v == 6) {
|
|
|
|
p = ip6->ip6_nxt;
|
2001-02-04 14:25:38 +00:00
|
|
|
dir = ire_route_lookup_v6(&ip6->ip6_dst, NULL, 0, 0,
|
2000-05-24 02:14:22 +00:00
|
|
|
NULL, &gw, NULL, MATCH_IRE_DSTONLY|
|
|
|
|
MATCH_IRE_DEFAULT|MATCH_IRE_RECURSIVE);
|
|
|
|
}
|
|
|
|
# endif
|
1997-05-25 15:45:04 +00:00
|
|
|
#else
|
1997-11-16 04:52:19 +00:00
|
|
|
dir = ire_lookup(dst.s_addr);
|
1997-05-25 15:45:04 +00:00
|
|
|
#endif
|
2000-01-13 18:30:37 +00:00
|
|
|
#if SOLARIS2 < 8
|
1997-11-16 04:52:19 +00:00
|
|
|
if (dir)
|
1997-02-09 22:50:16 +00:00
|
|
|
if (!dir->ire_ll_hdr_mp || !dir->ire_ll_hdr_length)
|
|
|
|
dir = NULL;
|
2000-01-13 18:30:37 +00:00
|
|
|
#else
|
|
|
|
if (dir)
|
|
|
|
if (!dir->ire_fp_mp || !dir->ire_dlureq_mp)
|
|
|
|
dir = NULL;
|
|
|
|
#endif
|
1997-02-09 22:50:16 +00:00
|
|
|
|
|
|
|
if (!ir)
|
|
|
|
ir = dir;
|
|
|
|
|
|
|
|
if (ir && dir) {
|
1999-11-08 20:51:23 +00:00
|
|
|
ifp = ire_to_ill(ir);
|
2000-01-13 18:30:37 +00:00
|
|
|
if (ifp == NULL)
|
|
|
|
goto bad_fastroute;
|
1999-11-08 20:51:23 +00:00
|
|
|
fr = fin->fin_fr;
|
2001-07-28 11:59:33 +00:00
|
|
|
|
1999-11-08 20:51:23 +00:00
|
|
|
/*
|
|
|
|
* In case we're here due to "to <if>" being used with
|
|
|
|
* "keep state", check that we're going in the correct
|
|
|
|
* direction.
|
|
|
|
*/
|
|
|
|
if ((fr != NULL) && (fdp->fd_ifp != NULL) &&
|
|
|
|
(fin->fin_rev != 0) && (fdp == &fr->fr_tif))
|
2001-07-28 11:59:33 +00:00
|
|
|
return 1;
|
1999-11-08 20:51:23 +00:00
|
|
|
|
2000-01-13 18:30:37 +00:00
|
|
|
fin->fin_ifp = ifp;
|
1999-11-08 20:51:23 +00:00
|
|
|
if (fin->fin_out == 0) {
|
|
|
|
fin->fin_fr = ipacct[1][fr_active];
|
|
|
|
if ((fin->fin_fr != NULL) &&
|
|
|
|
(fr_scanlist(FR_NOMATCH, ip, fin, mb)&FR_ACCOUNT)){
|
2000-05-24 02:14:22 +00:00
|
|
|
ATOMIC_INCL(frstats[1].fr_acct);
|
1999-11-08 20:51:23 +00:00
|
|
|
}
|
|
|
|
fin->fin_fr = NULL;
|
2000-07-19 13:52:47 +00:00
|
|
|
if (!fr || !(fr->fr_flags & FR_RETMASK))
|
2000-05-24 02:14:22 +00:00
|
|
|
(void) fr_checkstate(ip, fin);
|
2000-07-19 13:52:47 +00:00
|
|
|
(void) ip_natout(ip, fin);
|
2000-05-24 02:14:22 +00:00
|
|
|
}
|
1999-11-08 20:51:23 +00:00
|
|
|
#ifndef sparc
|
2000-05-24 02:14:22 +00:00
|
|
|
if (fin->fin_v == 4) {
|
|
|
|
__iplen = (u_short)ip->ip_len,
|
|
|
|
__ipoff = (u_short)ip->ip_off;
|
1999-11-08 20:51:23 +00:00
|
|
|
|
2000-05-24 02:14:22 +00:00
|
|
|
ip->ip_len = htons(__iplen);
|
|
|
|
ip->ip_off = htons(__ipoff);
|
|
|
|
}
|
1999-11-08 20:51:23 +00:00
|
|
|
#endif
|
|
|
|
|
2000-01-13 18:30:37 +00:00
|
|
|
#if SOLARIS2 < 8
|
|
|
|
mp = dir->ire_ll_hdr_mp;
|
|
|
|
hlen = dir->ire_ll_hdr_length;
|
|
|
|
#else
|
|
|
|
mp = dir->ire_fp_mp;
|
|
|
|
hlen = mp ? mp->b_wptr - mp->b_rptr : 0;
|
|
|
|
mp = dir->ire_dlureq_mp;
|
|
|
|
#endif
|
|
|
|
if (mp != NULL) {
|
1997-02-09 22:50:16 +00:00
|
|
|
s = mb->b_rptr;
|
2000-01-13 18:30:37 +00:00
|
|
|
if (
|
|
|
|
#if SOLARIS2 >= 6
|
|
|
|
(dohwcksum &&
|
|
|
|
ifp->ill_ick.ick_magic == ICK_M_CTL_MAGIC) ||
|
|
|
|
#endif
|
|
|
|
(hlen && (s - mb->b_datap->db_base) >= hlen)) {
|
1997-02-09 22:50:16 +00:00
|
|
|
s -= hlen;
|
|
|
|
mb->b_rptr = (u_char *)s;
|
|
|
|
bcopy((char *)mp->b_rptr, (char *)s, hlen);
|
|
|
|
} else {
|
|
|
|
mblk_t *mp2;
|
|
|
|
|
|
|
|
mp2 = copyb(mp);
|
|
|
|
if (!mp2)
|
|
|
|
goto bad_fastroute;
|
2000-05-24 02:14:22 +00:00
|
|
|
linkb(mp2, mb);
|
1997-02-09 22:50:16 +00:00
|
|
|
mb = mp2;
|
|
|
|
}
|
|
|
|
}
|
2000-02-09 20:46:45 +00:00
|
|
|
*mpp = mb;
|
1997-02-09 22:50:16 +00:00
|
|
|
|
|
|
|
if (ir->ire_stq)
|
|
|
|
q = ir->ire_stq;
|
|
|
|
else if (ir->ire_rfq)
|
|
|
|
q = WR(ir->ire_rfq);
|
|
|
|
if (q) {
|
1999-11-08 20:51:23 +00:00
|
|
|
mb->b_prev = NULL;
|
2000-02-09 20:46:45 +00:00
|
|
|
mb->b_queue = q;
|
1999-11-08 20:51:23 +00:00
|
|
|
RWLOCK_EXIT(&ipfs_mutex);
|
|
|
|
RWLOCK_EXIT(&ipf_solaris);
|
2000-01-13 18:30:37 +00:00
|
|
|
#if SOLARIS2 >= 6
|
2000-05-24 02:14:22 +00:00
|
|
|
if ((p == IPPROTO_TCP) && dohwcksum &&
|
2000-01-13 18:30:37 +00:00
|
|
|
(ifp->ill_ick.ick_magic == ICK_M_CTL_MAGIC)) {
|
|
|
|
tcphdr_t *tcp;
|
|
|
|
u_32_t t;
|
|
|
|
|
|
|
|
tcp = (tcphdr_t *)((char *)ip + fin->fin_hlen);
|
|
|
|
t = ip->ip_src.s_addr;
|
|
|
|
t += ip->ip_dst.s_addr;
|
|
|
|
t += 30;
|
|
|
|
t = (t & 0xffff) + (t >> 16);
|
|
|
|
tcp->th_sum = t & 0xffff;
|
|
|
|
}
|
|
|
|
#endif
|
1997-02-09 22:50:16 +00:00
|
|
|
putnext(q, mb);
|
1999-11-08 20:51:23 +00:00
|
|
|
READ_ENTER(&ipf_solaris);
|
|
|
|
READ_ENTER(&ipfs_mutex);
|
1997-11-16 04:52:19 +00:00
|
|
|
ipl_frouteok[0]++;
|
2001-07-28 11:59:33 +00:00
|
|
|
*mpp = NULL;
|
1997-02-09 22:50:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bad_fastroute:
|
1999-11-08 20:51:23 +00:00
|
|
|
mb->b_prev = NULL;
|
|
|
|
freemsg(mb);
|
|
|
|
ipl_frouteok[1]++;
|
2001-07-28 11:59:33 +00:00
|
|
|
*mpp = NULL;
|
1997-02-09 22:50:16 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-11-16 04:52:19 +00:00
|
|
|
void copyout_mblk(m, off, len, buf)
|
1997-02-09 22:50:16 +00:00
|
|
|
mblk_t *m;
|
1999-11-08 20:51:23 +00:00
|
|
|
size_t off, len;
|
1997-02-09 22:50:16 +00:00
|
|
|
char *buf;
|
|
|
|
{
|
1999-11-08 20:51:23 +00:00
|
|
|
u_char *s, *bp = (u_char *)buf;
|
|
|
|
size_t mlen, olen, clen;
|
1997-02-09 22:50:16 +00:00
|
|
|
|
|
|
|
for (; m && len; m = m->b_cont) {
|
|
|
|
if (MTYPE(m) != M_DATA)
|
|
|
|
continue;
|
|
|
|
s = m->b_rptr;
|
1999-11-08 20:51:23 +00:00
|
|
|
mlen = m->b_wptr - s;
|
1997-02-09 22:50:16 +00:00
|
|
|
olen = MIN(off, mlen);
|
|
|
|
if ((olen == mlen) || (olen < off)) {
|
|
|
|
off -= olen;
|
|
|
|
continue;
|
|
|
|
} else if (olen) {
|
|
|
|
off -= olen;
|
|
|
|
s += olen;
|
|
|
|
mlen -= olen;
|
|
|
|
}
|
|
|
|
clen = MIN(mlen, len);
|
|
|
|
bcopy(s, bp, clen);
|
|
|
|
len -= clen;
|
|
|
|
bp += clen;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-11-16 04:52:19 +00:00
|
|
|
void copyin_mblk(m, off, len, buf)
|
1997-02-09 22:50:16 +00:00
|
|
|
mblk_t *m;
|
1999-11-08 20:51:23 +00:00
|
|
|
size_t off, len;
|
1997-02-09 22:50:16 +00:00
|
|
|
char *buf;
|
|
|
|
{
|
1999-11-08 20:51:23 +00:00
|
|
|
u_char *s, *bp = (u_char *)buf;
|
|
|
|
size_t mlen, olen, clen;
|
1997-02-09 22:50:16 +00:00
|
|
|
|
|
|
|
for (; m && len; m = m->b_cont) {
|
|
|
|
if (MTYPE(m) != M_DATA)
|
|
|
|
continue;
|
|
|
|
s = m->b_rptr;
|
1999-11-08 20:51:23 +00:00
|
|
|
mlen = m->b_wptr - s;
|
1997-02-09 22:50:16 +00:00
|
|
|
olen = MIN(off, mlen);
|
|
|
|
if ((olen == mlen) || (olen < off)) {
|
|
|
|
off -= olen;
|
|
|
|
continue;
|
|
|
|
} else if (olen) {
|
|
|
|
off -= olen;
|
|
|
|
s += olen;
|
|
|
|
mlen -= olen;
|
|
|
|
}
|
|
|
|
clen = MIN(mlen, len);
|
|
|
|
bcopy(bp, s, clen);
|
|
|
|
len -= clen;
|
|
|
|
bp += clen;
|
|
|
|
}
|
|
|
|
}
|
2000-05-24 02:14:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
int fr_verifysrc(ipa, ifp)
|
|
|
|
struct in_addr ipa;
|
|
|
|
void *ifp;
|
|
|
|
{
|
|
|
|
ire_t *ir, *dir, *gw;
|
|
|
|
|
|
|
|
#if SOLARIS2 >= 6
|
|
|
|
dir = ire_route_lookup(ipa.s_addr, 0xffffffff, 0, 0, NULL, &gw, NULL,
|
|
|
|
MATCH_IRE_DSTONLY|MATCH_IRE_DEFAULT|
|
|
|
|
MATCH_IRE_RECURSIVE);
|
|
|
|
#else
|
|
|
|
dir = ire_lookup(ipa.s_addr);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!dir)
|
|
|
|
return 0;
|
|
|
|
return (ire_to_ill(dir) == ifp);
|
|
|
|
}
|