solaris.c revision 40cdc2e8babc6bb3ab847f6a129fc9eb76c5f4d5
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz/*
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz * Copyright (C) 1993-2001, 2003 by Darren Reed.
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz *
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz * See the IPFILTER.LICENCE file for details on licencing.
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz *
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz * Use is subject to license terms.
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz */
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#include <sys/systm.h>
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#include <sys/types.h>
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#include <sys/param.h>
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#include <sys/errno.h>
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#include <sys/uio.h>
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#include <sys/buf.h>
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#include <sys/modctl.h>
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#include <sys/open.h>
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#include <sys/kmem.h>
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#include <sys/conf.h>
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#include <sys/cmn_err.h>
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#include <sys/stat.h>
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#include <sys/cred.h>
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#include <sys/dditypes.h>
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#include <sys/poll.h>
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#include <sys/autoconf.h>
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#include <sys/byteorder.h>
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#include <sys/socket.h>
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#include <sys/dlpi.h>
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#include <sys/stropts.h>
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#include <sys/kstat.h>
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#include <sys/sockio.h>
381a2a9a387f449fab7d0c7e97c4184c26963abfdr#include <sys/neti.h>
381a2a9a387f449fab7d0c7e97c4184c26963abfdr#include <sys/hook.h>
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#include <net/if.h>
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#if SOLARIS2 >= 6
193974072f41a843678abf5f61979c748687e66bSherry Moore#include <net/if_types.h>
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#endif
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#include <net/af.h>
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#include <net/route.h>
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#include <netinet/in.h>
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#include <netinet/in_systm.h>
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#include <netinet/if_ether.h>
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#include <netinet/ip.h>
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#include <netinet/ip_var.h>
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#include <netinet/tcp.h>
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#include <netinet/udp.h>
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#include <netinet/tcpip.h>
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#include <netinet/ip_icmp.h>
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#include <sys/ddi.h>
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#include <sys/sunddi.h>
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#include "netinet/ip_compat.h"
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#include "netinet/ipl.h"
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#include "netinet/ip_fil.h"
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#include "netinet/ip_nat.h"
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#include "netinet/ip_frag.h"
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#include "netinet/ip_auth.h"
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#include "netinet/ip_state.h"
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh#include "netinet/ipf_stack.h"
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yzextern int iplwrite __P((dev_t, struct uio *, cred_t *));
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yzstatic int ipf_getinfo __P((dev_info_t *, ddi_info_cmd_t,
193974072f41a843678abf5f61979c748687e66bSherry Moore void *, void **));
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#if SOLARIS2 < 10
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yzstatic int ipf_identify __P((dev_info_t *));
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#endif
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yzstatic int ipf_attach __P((dev_info_t *, ddi_attach_cmd_t));
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yzstatic int ipf_detach __P((dev_info_t *, ddi_detach_cmd_t));
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reedstatic void *ipf_stack_create __P((const netid_t));
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reedstatic void ipf_stack_destroy __P((const netid_t, void *));
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dhstatic int ipf_property_g_update __P((dev_info_t *));
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yzstatic char *ipf_devfiles[] = { IPL_NAME, IPNAT_NAME, IPSTATE_NAME,
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz IPAUTH_NAME, IPSYNC_NAME, IPSCAN_NAME,
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz IPLOOKUP_NAME, NULL };
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yzstatic struct cb_ops ipf_cb_ops = {
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz iplopen,
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz iplclose,
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz nodev, /* strategy */
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz nodev, /* print */
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz nodev, /* dump */
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz iplread,
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz iplwrite, /* write */
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz iplioctl, /* ioctl */
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz nodev, /* devmap */
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz nodev, /* mmap */
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz nodev, /* segmap */
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz nochpoll, /* poll */
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz ddi_prop_op,
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz NULL,
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz D_MTSAFE,
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#if SOLARIS2 > 4
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz CB_REV,
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz nodev, /* aread */
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz nodev, /* awrite */
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#endif
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz};
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yzstatic struct dev_ops ipf_ops = {
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz DEVO_REV,
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz 0,
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz ipf_getinfo,
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#if SOLARIS2 >= 10
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz nulldev,
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#else
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz ipf_identify,
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#endif
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz nulldev,
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz ipf_attach,
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz ipf_detach,
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz nodev, /* reset */
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz &ipf_cb_ops,
193974072f41a843678abf5f61979c748687e66bSherry Moore (struct bus_ops *)0,
193974072f41a843678abf5f61979c748687e66bSherry Moore NULL,
193974072f41a843678abf5f61979c748687e66bSherry Moore ddi_quiesce_not_needed, /* quiesce */
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz};
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reedstatic net_instance_t *ipfncb = NULL;
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reedstatic ipf_stack_t *ipf_stacks = NULL;
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reedstatic kmutex_t ipf_stack_lock;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yzextern struct mod_ops mod_driverops;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yzstatic struct modldrv iplmod = {
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz &mod_driverops, IPL_VERSION, &ipf_ops };
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yzstatic struct modlinkage modlink1 = { MODREV_1, &iplmod, NULL };
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#if SOLARIS2 >= 6
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yzstatic size_t hdrsizes[57][2] = {
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { 0, 0 },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { IFT_OTHER, 0 },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { IFT_1822, 0 },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { IFT_HDH1822, 0 },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { IFT_X25DDN, 0 },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { IFT_X25, 0 },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { IFT_ETHER, 14 },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { IFT_ISO88023, 0 },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { IFT_ISO88024, 0 },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { IFT_ISO88025, 0 },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { IFT_ISO88026, 0 },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { IFT_STARLAN, 0 },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { IFT_P10, 0 },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { IFT_P80, 0 },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { IFT_HY, 0 },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { IFT_FDDI, 24 },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { IFT_LAPB, 0 },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { IFT_SDLC, 0 },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { IFT_T1, 0 },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { IFT_CEPT, 0 },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { IFT_ISDNBASIC, 0 },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { IFT_ISDNPRIMARY, 0 },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { IFT_PTPSERIAL, 0 },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { IFT_PPP, 0 },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { IFT_LOOP, 0 },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { IFT_EON, 0 },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { IFT_XETHER, 0 },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { IFT_NSIP, 0 },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { IFT_SLIP, 0 },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { IFT_ULTRA, 0 },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { IFT_DS3, 0 },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { IFT_SIP, 0 },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { IFT_FRELAY, 0 },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { IFT_RS232, 0 },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { IFT_PARA, 0 },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { IFT_ARCNET, 0 },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { IFT_ARCNETPLUS, 0 },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { IFT_ATM, 0 },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { IFT_MIOX25, 0 },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { IFT_SONET, 0 },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { IFT_X25PLE, 0 },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { IFT_ISO88022LLC, 0 },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { IFT_LOCALTALK, 0 },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { IFT_SMDSDXI, 0 },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { IFT_FRELAYDCE, 0 },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { IFT_V35, 0 },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { IFT_HSSI, 0 },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { IFT_HIPPI, 0 },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { IFT_MODEM, 0 },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { IFT_AAL5, 0 },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { IFT_SONETPATH, 0 },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { IFT_SONETVT, 0 },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { IFT_SMDSICIP, 0 },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { IFT_PROPVIRTUAL, 0 },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { IFT_PROPMUX, 0 },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz};
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#endif /* SOLARIS2 >= 6 */
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dhdev_info_t *ipf_dev_info = NULL;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yzstatic const filter_kstats_t ipf_kstat_tmp = {
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { "pass", KSTAT_DATA_ULONG },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { "block", KSTAT_DATA_ULONG },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { "nomatch", KSTAT_DATA_ULONG },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { "short", KSTAT_DATA_ULONG },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { "pass, logged", KSTAT_DATA_ULONG },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { "block, logged", KSTAT_DATA_ULONG },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { "nomatch, logged", KSTAT_DATA_ULONG },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { "logged", KSTAT_DATA_ULONG },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { "skip", KSTAT_DATA_ULONG },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { "return sent", KSTAT_DATA_ULONG },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { "acct", KSTAT_DATA_ULONG },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { "bad frag state alloc", KSTAT_DATA_ULONG },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { "new frag state kept", KSTAT_DATA_ULONG },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { "new frag state compl. pkt", KSTAT_DATA_ULONG },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { "bad pkt state alloc", KSTAT_DATA_ULONG },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { "new pkt kept state", KSTAT_DATA_ULONG },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { "cachehit", KSTAT_DATA_ULONG },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { "tcp cksum bad", KSTAT_DATA_ULONG },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz {{ "pullup ok", KSTAT_DATA_ULONG },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { "pullup nok", KSTAT_DATA_ULONG }},
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { "src != route", KSTAT_DATA_ULONG },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { "ttl invalid", KSTAT_DATA_ULONG },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { "bad ip pkt", KSTAT_DATA_ULONG },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { "ipv6 pkt", KSTAT_DATA_ULONG },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { "dropped:pps ceiling", KSTAT_DATA_ULONG },
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz { "ip upd. fail", KSTAT_DATA_ULONG }
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz};
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz
381a2a9a387f449fab7d0c7e97c4184c26963abfdr
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yzstatic int ipf_kstat_update(kstat_t *ksp, int rwflag);
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yzstatic void
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reedipf_kstat_init(ipf_stack_t *ifs)
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz{
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed ifs->ifs_kstatp[0] = net_kstat_create(ifs->ifs_netid, "ipf", 0,
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed "inbound", "net", KSTAT_TYPE_NAMED,
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed sizeof (filter_kstats_t) / sizeof (kstat_named_t), 0);
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed if (ifs->ifs_kstatp[0] != NULL) {
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed bcopy(&ipf_kstat_tmp, ifs->ifs_kstatp[0]->ks_data,
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed sizeof (filter_kstats_t));
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed ifs->ifs_kstatp[0]->ks_update = ipf_kstat_update;
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed ifs->ifs_kstatp[0]->ks_private = &ifs->ifs_frstats[0];
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed kstat_install(ifs->ifs_kstatp[0]);
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed }
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed ifs->ifs_kstatp[1] = net_kstat_create(ifs->ifs_netid, "ipf", 0,
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed "outbound", "net", KSTAT_TYPE_NAMED,
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed sizeof (filter_kstats_t) / sizeof (kstat_named_t), 0);
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed if (ifs->ifs_kstatp[1] != NULL) {
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed bcopy(&ipf_kstat_tmp, ifs->ifs_kstatp[1]->ks_data,
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed sizeof (filter_kstats_t));
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed ifs->ifs_kstatp[1]->ks_update = ipf_kstat_update;
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed ifs->ifs_kstatp[1]->ks_private = &ifs->ifs_frstats[1];
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed kstat_install(ifs->ifs_kstatp[1]);
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz }
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#ifdef IPFDEBUG
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed cmn_err(CE_NOTE, "IP Filter: ipf_kstat_init(%p) installed %p, %p",
193974072f41a843678abf5f61979c748687e66bSherry Moore ifs, ifs->ifs_kstatp[0], ifs->ifs_kstatp[1]);
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#endif
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz}
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yzstatic void
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reedipf_kstat_fini(ipf_stack_t *ifs)
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz{
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz int i;
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz for (i = 0; i < 2; i++) {
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh if (ifs->ifs_kstatp[i] != NULL) {
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed net_kstat_delete(ifs->ifs_netid, ifs->ifs_kstatp[i]);
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh ifs->ifs_kstatp[i] = NULL;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz }
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz }
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz}
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yzstatic int
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yzipf_kstat_update(kstat_t *ksp, int rwflag)
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz{
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz filter_kstats_t *fkp;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz filterstats_t *fsp;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh if (ksp == NULL || ksp->ks_data == NULL)
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh return (EIO);
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz if (rwflag == KSTAT_WRITE)
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz return (EACCES);
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz fkp = ksp->ks_data;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz fsp = ksp->ks_private;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz fkp->fks_pass.value.ul = fsp->fr_pass;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz fkp->fks_block.value.ul = fsp->fr_block;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz fkp->fks_nom.value.ul = fsp->fr_nom;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz fkp->fks_short.value.ul = fsp->fr_short;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz fkp->fks_ppkl.value.ul = fsp->fr_ppkl;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz fkp->fks_bpkl.value.ul = fsp->fr_bpkl;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz fkp->fks_npkl.value.ul = fsp->fr_npkl;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz fkp->fks_pkl.value.ul = fsp->fr_pkl;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz fkp->fks_skip.value.ul = fsp->fr_skip;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz fkp->fks_ret.value.ul = fsp->fr_ret;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz fkp->fks_acct.value.ul = fsp->fr_acct;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz fkp->fks_bnfr.value.ul = fsp->fr_bnfr;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz fkp->fks_nfr.value.ul = fsp->fr_nfr;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz fkp->fks_cfr.value.ul = fsp->fr_cfr;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz fkp->fks_bads.value.ul = fsp->fr_bads;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz fkp->fks_ads.value.ul = fsp->fr_ads;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz fkp->fks_chit.value.ul = fsp->fr_chit;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz fkp->fks_tcpbad.value.ul = fsp->fr_tcpbad;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz fkp->fks_pull[0].value.ul = fsp->fr_pull[0];
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz fkp->fks_pull[1].value.ul = fsp->fr_pull[1];
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz fkp->fks_badsrc.value.ul = fsp->fr_badsrc;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz fkp->fks_badttl.value.ul = fsp->fr_badttl;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz fkp->fks_bad.value.ul = fsp->fr_bad;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz fkp->fks_ipv6.value.ul = fsp->fr_ipv6;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz fkp->fks_ppshit.value.ul = fsp->fr_ppshit;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz fkp->fks_ipud.value.ul = fsp->fr_ipud;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz return (0);
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz}
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz
193974072f41a843678abf5f61979c748687e66bSherry Mooreint
193974072f41a843678abf5f61979c748687e66bSherry Moore_init()
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz{
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz int ipfinst;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz ipfinst = mod_install(&modlink1);
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#ifdef IPFDEBUG
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz cmn_err(CE_NOTE, "IP Filter: _init() = %d", ipfinst);
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#endif
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed mutex_init(&ipf_stack_lock, NULL, MUTEX_DRIVER, NULL);
193974072f41a843678abf5f61979c748687e66bSherry Moore return (ipfinst);
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz}
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz
193974072f41a843678abf5f61979c748687e66bSherry Mooreint
193974072f41a843678abf5f61979c748687e66bSherry Moore_fini(void)
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz{
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz int ipfinst;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz ipfinst = mod_remove(&modlink1);
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#ifdef IPFDEBUG
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz cmn_err(CE_NOTE, "IP Filter: _fini() = %d", ipfinst);
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#endif
193974072f41a843678abf5f61979c748687e66bSherry Moore return (ipfinst);
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz}
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz
193974072f41a843678abf5f61979c748687e66bSherry Mooreint
193974072f41a843678abf5f61979c748687e66bSherry Moore_info(modinfop)
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yzstruct modinfo *modinfop;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz{
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz int ipfinst;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz ipfinst = mod_info(&modlink1, modinfop);
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#ifdef IPFDEBUG
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed cmn_err(CE_NOTE, "IP Filter: _info(%p) = %d", modinfop, ipfinst);
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#endif
193974072f41a843678abf5f61979c748687e66bSherry Moore return (ipfinst);
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz}
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#if SOLARIS2 < 10
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yzstatic int ipf_identify(dip)
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yzdev_info_t *dip;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz{
193974072f41a843678abf5f61979c748687e66bSherry Moore#ifdef IPFDEBUG
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed cmn_err(CE_NOTE, "IP Filter: ipf_identify(%p)", dip);
193974072f41a843678abf5f61979c748687e66bSherry Moore#endif
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz if (strcmp(ddi_get_name(dip), "ipf") == 0)
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz return (DDI_IDENTIFIED);
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz return (DDI_NOT_IDENTIFIED);
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz}
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#endif
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh/*
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * Initialize things for IPF for each stack instance
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh */
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dhstatic void *
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reedipf_stack_create(const netid_t id)
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh{
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh ipf_stack_t *ifs;
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed#ifdef IPFDEBUG
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed cmn_err(CE_NOTE, "IP Filter:stack_create id=%d", id);
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh#endif
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed ifs = (ipf_stack_t *)kmem_alloc(sizeof (*ifs), KM_SLEEP);
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh bzero(ifs, sizeof (*ifs));
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh ifs->ifs_hook4_physical_in = B_FALSE;
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh ifs->ifs_hook4_physical_out = B_FALSE;
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh ifs->ifs_hook4_nic_events = B_FALSE;
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh ifs->ifs_hook4_loopback_in = B_FALSE;
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh ifs->ifs_hook4_loopback_out = B_FALSE;
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh ifs->ifs_hook6_physical_in = B_FALSE;
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh ifs->ifs_hook6_physical_out = B_FALSE;
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh ifs->ifs_hook6_nic_events = B_FALSE;
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh ifs->ifs_hook6_loopback_in = B_FALSE;
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh ifs->ifs_hook6_loopback_out = B_FALSE;
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh /*
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * Initialize mutex's
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh */
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh RWLOCK_INIT(&ifs->ifs_ipf_global, "ipf filter load/unload mutex");
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh RWLOCK_INIT(&ifs->ifs_ipf_mutex, "ipf filter rwlock");
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed ifs->ifs_netid = id;
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed ifs->ifs_zone = net_getzoneidbynetid(id);
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed ipf_kstat_init(ifs);
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed#ifdef IPFDEBUG
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed cmn_err(CE_CONT, "IP Filter:stack_create zone=%d", ifs->ifs_zone);
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh#endif
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh /*
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * Lock people out while we set things up.
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh */
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh WRITE_ENTER(&ifs->ifs_ipf_global);
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh ipftuneable_alloc(ifs);
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh RWLOCK_EXIT(&ifs->ifs_ipf_global);
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh
23f4867fdff96a11dd674de6259a5a0d0a13251cnordmark /* Limit to global stack */
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed if (ifs->ifs_zone == GLOBAL_ZONEID)
23f4867fdff96a11dd674de6259a5a0d0a13251cnordmark cmn_err(CE_CONT, "!%s, running.\n", ipfilter_version);
23f4867fdff96a11dd674de6259a5a0d0a13251cnordmark
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed mutex_enter(&ipf_stack_lock);
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed if (ipf_stacks != NULL)
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed ipf_stacks->ifs_pnext = &ifs->ifs_next;
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed ifs->ifs_next = ipf_stacks;
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed ifs->ifs_pnext = &ipf_stacks;
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed ipf_stacks = ifs;
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed mutex_exit(&ipf_stack_lock);
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh return (ifs);
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh}
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed/*
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed * This function should only ever be used to find the pointer to the
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed * ipfilter stack structure for the zone that is currently being
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed * executed... so if you're running in the context of zone 1, you
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed * should not attempt to find the ipf_stack_t for zone 0 or 2 or
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed * anything else but 1. In that way, the returned pointer is safe
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed * as it will only be nuked when the instance is destroyed as part
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed * of the final shutdown of a zone.
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed */
193974072f41a843678abf5f61979c748687e66bSherry Mooreipf_stack_t *
193974072f41a843678abf5f61979c748687e66bSherry Mooreipf_find_stack(const zoneid_t zone)
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed{
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed ipf_stack_t *ifs;
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed mutex_enter(&ipf_stack_lock);
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed for (ifs = ipf_stacks; ifs != NULL; ifs = ifs->ifs_next) {
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed if (ifs->ifs_zone == zone)
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed break;
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed }
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed mutex_exit(&ipf_stack_lock);
193974072f41a843678abf5f61979c748687e66bSherry Moore return (ifs);
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed}
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dhstatic int ipf_detach_check_zone(ipf_stack_t *ifs)
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh{
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh /*
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * Make sure we're the only one's modifying things. With
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * this lock others should just fall out of the loop.
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh */
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh READ_ENTER(&ifs->ifs_ipf_global);
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh if (ifs->ifs_fr_running == 1) {
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh RWLOCK_EXIT(&ifs->ifs_ipf_global);
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh return (-1);
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh }
193974072f41a843678abf5f61979c748687e66bSherry Moore
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh /*
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * Make sure there is no active filter rule.
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh */
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh if (ifs->ifs_ipfilter[0][ifs->ifs_fr_active] ||
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh ifs->ifs_ipfilter[1][ifs->ifs_fr_active] ||
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh ifs->ifs_ipfilter6[0][ifs->ifs_fr_active] ||
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh ifs->ifs_ipfilter6[1][ifs->ifs_fr_active]) {
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh RWLOCK_EXIT(&ifs->ifs_ipf_global);
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh return (-1);
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh }
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh RWLOCK_EXIT(&ifs->ifs_ipf_global);
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh return (0);
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh}
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dhstatic int ipf_detach_check_all()
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh{
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed ipf_stack_t *ifs;
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed mutex_enter(&ipf_stack_lock);
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed for (ifs = ipf_stacks; ifs != NULL; ifs = ifs->ifs_next)
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed if (ipf_detach_check_zone(ifs) != 0)
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed break;
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed mutex_exit(&ipf_stack_lock);
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed return ((ifs == NULL) ? 0 : -1);
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh}
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh/*
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * Destroy things for ipf for one stack.
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh */
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh/* ARGSUSED */
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dhstatic void
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reedipf_stack_destroy(const netid_t id, void *arg)
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh{
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh ipf_stack_t *ifs = (ipf_stack_t *)arg;
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed timeout_id_t tid;
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed#ifdef IPFDEBUG
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed (void) printf("ipf_stack_destroy(%p)\n", (void *)ifs);
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh#endif
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh /*
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * Make sure we're the only one's modifying things. With
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * this lock others should just fall out of the loop.
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh */
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh WRITE_ENTER(&ifs->ifs_ipf_global);
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh if (ifs->ifs_fr_running == -2) {
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh RWLOCK_EXIT(&ifs->ifs_ipf_global);
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh return;
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh }
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh ifs->ifs_fr_running = -2;
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed tid = ifs->ifs_fr_timer_id;
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed ifs->ifs_fr_timer_id = NULL;
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh RWLOCK_EXIT(&ifs->ifs_ipf_global);
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed mutex_enter(&ipf_stack_lock);
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed if (ifs->ifs_next != NULL)
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed ifs->ifs_next->ifs_pnext = ifs->ifs_pnext;
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed *ifs->ifs_pnext = ifs->ifs_next;
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed mutex_exit(&ipf_stack_lock);
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed ipf_kstat_fini(ifs);
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed if (tid != NULL)
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed (void) untimeout(tid);
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh WRITE_ENTER(&ifs->ifs_ipf_global);
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh if (ipldetach(ifs) != 0) {
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed printf("ipf_stack_destroy: ipldetach failed\n");
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh }
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh ipftuneable_free(ifs);
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh RWLOCK_EXIT(&ifs->ifs_ipf_global);
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh RW_DESTROY(&ifs->ifs_ipf_mutex);
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh RW_DESTROY(&ifs->ifs_ipf_global);
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh KFREE(ifs);
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh}
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yzstatic int ipf_attach(dip, cmd)
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yzdev_info_t *dip;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yzddi_attach_cmd_t cmd;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz{
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz char *s;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz int i;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz int instance;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#ifdef IPFDEBUG
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed cmn_err(CE_NOTE, "IP Filter: ipf_attach(%p,%x)", dip, cmd);
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#endif
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz switch (cmd)
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz {
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz case DDI_ATTACH:
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz instance = ddi_get_instance(dip);
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz /* Only one instance of ipf (instance 0) can be attached. */
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz if (instance > 0)
193974072f41a843678abf5f61979c748687e66bSherry Moore return (DDI_FAILURE);
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#ifdef IPFDEBUG
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed cmn_err(CE_CONT, "IP Filter: attach ipf instance %d", instance);
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#endif
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh (void) ipf_property_g_update(dip);
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz for (i = 0; ((s = ipf_devfiles[i]) != NULL); i++) {
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz s = strrchr(s, '/');
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz if (s == NULL)
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz continue;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz s++;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz if (ddi_create_minor_node(dip, s, S_IFCHR, i,
193974072f41a843678abf5f61979c748687e66bSherry Moore DDI_PSEUDO, 0) ==
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz DDI_FAILURE) {
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz ddi_remove_minor_node(dip, NULL);
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz goto attach_failed;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz }
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz }
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz ipf_dev_info = dip;
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed ipfncb = net_instance_alloc(NETINFO_VERSION);
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed ipfncb->nin_name = "ipf";
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed ipfncb->nin_create = ipf_stack_create;
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed ipfncb->nin_destroy = ipf_stack_destroy;
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed ipfncb->nin_shutdown = NULL;
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed i = net_instance_register(ipfncb);
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed#ifdef IPFDEBUG
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed cmn_err(CE_CONT, "IP Filter:stack_create callback_reg=%d", i);
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed#endif
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed
193974072f41a843678abf5f61979c748687e66bSherry Moore return (DDI_SUCCESS);
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz /* NOTREACHED */
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz default:
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz break;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz }
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yzattach_failed:
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh ddi_prop_remove_all(dip);
193974072f41a843678abf5f61979c748687e66bSherry Moore return (DDI_FAILURE);
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz}
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yzstatic int ipf_detach(dip, cmd)
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yzdev_info_t *dip;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yzddi_detach_cmd_t cmd;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz{
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz int i;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#ifdef IPFDEBUG
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed cmn_err(CE_NOTE, "IP Filter: ipf_detach(%p,%x)", dip, cmd);
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#endif
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz switch (cmd) {
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz case DDI_DETACH:
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh if (ipf_detach_check_all() != 0)
193974072f41a843678abf5f61979c748687e66bSherry Moore return (DDI_FAILURE);
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz
193974072f41a843678abf5f61979c748687e66bSherry Moore /*
193974072f41a843678abf5f61979c748687e66bSherry Moore * Undo what we did in ipf_attach, freeing resources
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz * and removing things we installed. The system
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz * framework guarantees we are not active with this devinfo
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz * node in any other entry points at this time.
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz */
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz ddi_prop_remove_all(dip);
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz i = ddi_get_instance(dip);
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz ddi_remove_minor_node(dip, NULL);
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz if (i > 0) {
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz cmn_err(CE_CONT, "IP Filter: still attached (%d)\n", i);
193974072f41a843678abf5f61979c748687e66bSherry Moore return (DDI_FAILURE);
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz }
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed (void) net_instance_unregister(ipfncb);
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed net_instance_free(ipfncb);
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed
193974072f41a843678abf5f61979c748687e66bSherry Moore return (DDI_SUCCESS);
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh /* NOTREACHED */
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz default:
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz break;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz }
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz cmn_err(CE_NOTE, "IP Filter: failed to detach\n");
193974072f41a843678abf5f61979c748687e66bSherry Moore return (DDI_FAILURE);
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz}
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz/*ARGSUSED*/
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yzstatic int ipf_getinfo(dip, infocmd, arg, result)
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yzdev_info_t *dip;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yzddi_info_cmd_t infocmd;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yzvoid *arg, **result;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz{
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz int error;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz error = DDI_FAILURE;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#ifdef IPFDEBUG
7ddc9b1afd18f260b9fb78ec7732facd91769131Darren Reed cmn_err(CE_NOTE, "IP Filter: ipf_getinfo(%p,%x,%p)", dip, infocmd, arg);
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#endif
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz switch (infocmd) {
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz case DDI_INFO_DEVT2DEVINFO:
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz *result = ipf_dev_info;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz error = DDI_SUCCESS;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz break;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz case DDI_INFO_DEVT2INSTANCE:
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz *result = (void *)0;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz error = DDI_SUCCESS;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz break;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz default:
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz break;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz }
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz return (error);
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz}
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz/*
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz * Fetch configuration file values that have been entered into the ipf.conf
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz * driver file.
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz */
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dhstatic int ipf_property_g_update(dip)
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yzdev_info_t *dip;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz{
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#ifdef DDI_NO_AUTODETACH
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz if (ddi_prop_update_int(DDI_DEV_T_NONE, dip,
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz DDI_NO_AUTODETACH, 1) != DDI_PROP_SUCCESS) {
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz cmn_err(CE_WARN, "!updating DDI_NO_AUTODETACH failed");
193974072f41a843678abf5f61979c748687e66bSherry Moore return (DDI_FAILURE);
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz }
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#else
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz if (ddi_prop_update_int(DDI_DEV_T_NONE, dip,
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz "ddi-no-autodetach", 1) != DDI_PROP_SUCCESS) {
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz cmn_err(CE_WARN, "!updating ddi-no-autodetach failed");
193974072f41a843678abf5f61979c748687e66bSherry Moore return (DDI_FAILURE);
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz }
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#endif
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz
193974072f41a843678abf5f61979c748687e66bSherry Moore return (DDI_SUCCESS);
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh}
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh
193974072f41a843678abf5f61979c748687e66bSherry Mooreint
193974072f41a843678abf5f61979c748687e66bSherry Mooreipf_property_update(dip, ifs)
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dhdev_info_t *dip;
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dhipf_stack_t *ifs;
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh{
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh ipftuneable_t *ipft;
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh char *name;
193974072f41a843678abf5f61979c748687e66bSherry Moore uint_t one;
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh int *i32p;
40cdc2e8babc6bb3ab847f6a129fc9eb76c5f4d5Alexandr Nedvedicky int err, rv = 0;
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh
40cdc2e8babc6bb3ab847f6a129fc9eb76c5f4d5Alexandr Nedvedicky for (ipft = ifs->ifs_ipf_tuneables;
40cdc2e8babc6bb3ab847f6a129fc9eb76c5f4d5Alexandr Nedvedicky (name = ipft->ipft_name) != NULL; ipft++) {
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz one = 1;
40cdc2e8babc6bb3ab847f6a129fc9eb76c5f4d5Alexandr Nedvedicky i32p = NULL;
40cdc2e8babc6bb3ab847f6a129fc9eb76c5f4d5Alexandr Nedvedicky err = ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip,
40cdc2e8babc6bb3ab847f6a129fc9eb76c5f4d5Alexandr Nedvedicky 0, name, &i32p, &one);
40cdc2e8babc6bb3ab847f6a129fc9eb76c5f4d5Alexandr Nedvedicky if (err == DDI_PROP_NOT_FOUND)
40cdc2e8babc6bb3ab847f6a129fc9eb76c5f4d5Alexandr Nedvedicky continue;
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#ifdef IPFDEBUG
40cdc2e8babc6bb3ab847f6a129fc9eb76c5f4d5Alexandr Nedvedicky cmn_err(CE_CONT, "IP Filter: lookup_int(%s) = %d\n",
40cdc2e8babc6bb3ab847f6a129fc9eb76c5f4d5Alexandr Nedvedicky name, err);
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz#endif
40cdc2e8babc6bb3ab847f6a129fc9eb76c5f4d5Alexandr Nedvedicky if (err != DDI_PROP_SUCCESS) {
40cdc2e8babc6bb3ab847f6a129fc9eb76c5f4d5Alexandr Nedvedicky rv = err;
40cdc2e8babc6bb3ab847f6a129fc9eb76c5f4d5Alexandr Nedvedicky continue;
40cdc2e8babc6bb3ab847f6a129fc9eb76c5f4d5Alexandr Nedvedicky }
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz
40cdc2e8babc6bb3ab847f6a129fc9eb76c5f4d5Alexandr Nedvedicky if (*i32p >= ipft->ipft_min &&
40cdc2e8babc6bb3ab847f6a129fc9eb76c5f4d5Alexandr Nedvedicky *i32p <= ipft->ipft_max) {
40cdc2e8babc6bb3ab847f6a129fc9eb76c5f4d5Alexandr Nedvedicky if (ipft->ipft_sz == sizeof (uint32_t)) {
40cdc2e8babc6bb3ab847f6a129fc9eb76c5f4d5Alexandr Nedvedicky *ipft->ipft_pint = *i32p;
40cdc2e8babc6bb3ab847f6a129fc9eb76c5f4d5Alexandr Nedvedicky } else if (ipft->ipft_sz == sizeof (uint64_t)) {
40cdc2e8babc6bb3ab847f6a129fc9eb76c5f4d5Alexandr Nedvedicky *ipft->ipft_plong = *i32p;
40cdc2e8babc6bb3ab847f6a129fc9eb76c5f4d5Alexandr Nedvedicky }
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz }
40cdc2e8babc6bb3ab847f6a129fc9eb76c5f4d5Alexandr Nedvedicky
40cdc2e8babc6bb3ab847f6a129fc9eb76c5f4d5Alexandr Nedvedicky ddi_prop_free(i32p);
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz }
40cdc2e8babc6bb3ab847f6a129fc9eb76c5f4d5Alexandr Nedvedicky
40cdc2e8babc6bb3ab847f6a129fc9eb76c5f4d5Alexandr Nedvedicky return (rv);
ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4yz}