2007-07-03 12:16:07 +00:00
|
|
|
/* $OpenBSD: if_pflog.c,v 1.22 2006/12/15 09:31:20 otto Exp $ */
|
2004-02-26 02:04:28 +00:00
|
|
|
/*
|
|
|
|
* The authors of this code are John Ioannidis (ji@tla.org),
|
|
|
|
* Angelos D. Keromytis (kermit@csd.uch.gr) and
|
|
|
|
* Niels Provos (provos@physnet.uni-hamburg.de).
|
|
|
|
*
|
|
|
|
* This code was written by John Ioannidis for BSD/OS in Athens, Greece,
|
|
|
|
* in November 1995.
|
|
|
|
*
|
|
|
|
* Ported to OpenBSD and NetBSD, with additional transforms, in December 1996,
|
|
|
|
* by Angelos D. Keromytis.
|
|
|
|
*
|
|
|
|
* Additional transforms and features in 1997 and 1998 by Angelos D. Keromytis
|
|
|
|
* and Niels Provos.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1995, 1996, 1997, 1998 by John Ioannidis, Angelos D. Keromytis
|
|
|
|
* and Niels Provos.
|
|
|
|
* Copyright (c) 2001, Angelos D. Keromytis, Niels Provos.
|
|
|
|
*
|
|
|
|
* Permission to use, copy, and modify this software with or without fee
|
|
|
|
* is hereby granted, provided that this entire notice is included in
|
|
|
|
* all copies of any software which is or includes a copy or
|
|
|
|
* modification of this software.
|
|
|
|
* You may use this code under the GNU public license if you so wish. Please
|
|
|
|
* contribute changes back to the authors under this freer than GPL license
|
|
|
|
* so that we may further the use of strong encryption without limitations to
|
|
|
|
* all.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY
|
|
|
|
* REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE
|
|
|
|
* MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR
|
|
|
|
* PURPOSE.
|
|
|
|
*/
|
|
|
|
|
2004-03-17 21:11:02 +00:00
|
|
|
#ifdef __FreeBSD__
|
2004-02-26 02:34:12 +00:00
|
|
|
#include "opt_inet.h"
|
|
|
|
#include "opt_inet6.h"
|
|
|
|
#include "opt_bpf.h"
|
|
|
|
#include "opt_pf.h"
|
2005-12-05 11:58:35 +00:00
|
|
|
|
2007-07-03 12:16:07 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2005-12-05 11:58:35 +00:00
|
|
|
#ifdef DEV_BPF
|
2004-03-17 21:11:02 +00:00
|
|
|
#define NBPFILTER DEV_BPF
|
2005-12-05 11:58:35 +00:00
|
|
|
#else
|
|
|
|
#define NBPFILTER 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef DEV_PFLOG
|
2004-03-17 21:11:02 +00:00
|
|
|
#define NPFLOG DEV_PFLOG
|
2005-12-05 11:58:35 +00:00
|
|
|
#else
|
|
|
|
#define NPFLOG 0
|
|
|
|
#endif
|
|
|
|
|
2007-07-03 12:16:07 +00:00
|
|
|
#else /* ! __FreeBSD__ */
|
|
|
|
#include "bpfilter.h"
|
|
|
|
#include "pflog.h"
|
|
|
|
#endif /* __FreeBSD__ */
|
2004-02-26 02:04:28 +00:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/mbuf.h>
|
2007-07-03 12:16:07 +00:00
|
|
|
#include <sys/proc.h>
|
2004-02-26 02:04:28 +00:00
|
|
|
#include <sys/socket.h>
|
2004-03-17 21:11:02 +00:00
|
|
|
#ifdef __FreeBSD__
|
2004-02-26 02:34:12 +00:00
|
|
|
#include <sys/kernel.h>
|
2007-07-03 12:16:07 +00:00
|
|
|
#include <sys/limits.h>
|
2004-02-26 02:34:12 +00:00
|
|
|
#include <sys/malloc.h>
|
2004-05-31 22:48:19 +00:00
|
|
|
#include <sys/module.h>
|
2004-02-26 02:34:12 +00:00
|
|
|
#include <sys/sockio.h>
|
|
|
|
#else
|
2004-02-26 02:04:28 +00:00
|
|
|
#include <sys/ioctl.h>
|
2004-02-26 02:34:12 +00:00
|
|
|
#endif
|
2004-02-26 02:04:28 +00:00
|
|
|
|
|
|
|
#include <net/if.h>
|
2007-07-03 12:16:07 +00:00
|
|
|
#ifdef __FreeBSD__
|
Major overhaul of pseudo-interface cloning. Highlights include:
- Split the code out into if_clone.[ch].
- Locked struct if_clone. [1]
- Add a per-cloner match function rather then simply matching names of
the form <name><unit> and <name>.
- Use the match function to allow creation of <interface>.<tag>
vlan interfaces. The old way is preserved unchanged!
- Also the match function to allow creation of stf(4) interfaces named
stf0, stf, or 6to4. This is the only major user visible change in
that "ifconfig stf" creates the interface stf rather then stf0 and
does not print "stf0" to stdout.
- Allow destroy functions to fail so they can refuse to delete
interfaces. Currently, we forbid the deletion of interfaces which
were created in the init function, particularly lo0, pflog0, and
pfsync0. In the case of lo0 this was a panic implementation so it
does not count as a user visiable change. :-)
- Since most interfaces do not need the new functionality, an family of
wrapper functions, ifc_simple_*(), were created to wrap old style
cloner functions.
- The IF_CLONE_INITIALIZER macro is replaced with a new incompatible
IFC_CLONE_INITIALIZER and ifc_simple consumers use IFC_SIMPLE_DECLARE
instead.
Submitted by: Maurycy Pawlowski-Wieronski <maurycy at fouk.org> [1]
Reviewed by: andre, mlaier
Discussed on: net
2004-06-22 20:13:25 +00:00
|
|
|
#include <net/if_clone.h>
|
|
|
|
#endif
|
2004-02-26 02:04:28 +00:00
|
|
|
#include <net/if_types.h>
|
|
|
|
#include <net/route.h>
|
|
|
|
#include <net/bpf.h>
|
|
|
|
|
|
|
|
#ifdef INET
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/in_var.h>
|
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/ip.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef INET6
|
|
|
|
#ifndef INET
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#endif
|
|
|
|
#include <netinet6/nd6.h>
|
|
|
|
#endif /* INET6 */
|
|
|
|
|
|
|
|
#include <net/pfvar.h>
|
|
|
|
#include <net/if_pflog.h>
|
|
|
|
|
2004-03-17 21:11:02 +00:00
|
|
|
#ifdef __FreeBSD__
|
2007-07-03 12:16:07 +00:00
|
|
|
#include <machine/in_cksum.h>
|
2004-02-26 02:34:12 +00:00
|
|
|
#endif
|
|
|
|
|
2004-02-26 02:04:28 +00:00
|
|
|
#define PFLOGMTU (32768 + MHLEN + MLEN)
|
|
|
|
|
|
|
|
#ifdef PFLOGDEBUG
|
|
|
|
#define DPRINTF(x) do { if (pflogdebug) printf x ; } while (0)
|
|
|
|
#else
|
|
|
|
#define DPRINTF(x)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void pflogattach(int);
|
|
|
|
int pflogoutput(struct ifnet *, struct mbuf *, struct sockaddr *,
|
|
|
|
struct rtentry *);
|
|
|
|
int pflogioctl(struct ifnet *, u_long, caddr_t);
|
|
|
|
void pflogstart(struct ifnet *);
|
2007-07-03 12:16:07 +00:00
|
|
|
#ifdef __FreeBSD__
|
|
|
|
static int pflog_clone_create(struct if_clone *, int, caddr_t);
|
|
|
|
static void pflog_clone_destroy(struct ifnet *);
|
|
|
|
#else
|
|
|
|
int pflog_clone_create(struct if_clone *, int);
|
|
|
|
int pflog_clone_destroy(struct ifnet *);
|
2004-02-26 02:34:12 +00:00
|
|
|
#endif
|
|
|
|
|
2007-07-03 12:16:07 +00:00
|
|
|
LIST_HEAD(, pflog_softc) pflogif_list;
|
2004-03-17 21:11:02 +00:00
|
|
|
#ifdef __FreeBSD__
|
2007-07-03 12:16:07 +00:00
|
|
|
IFC_SIMPLE_DECLARE(pflog, 1);
|
|
|
|
#else
|
|
|
|
struct if_clone pflog_cloner =
|
|
|
|
IF_CLONE_INITIALIZER("pflog", pflog_clone_create, pflog_clone_destroy);
|
|
|
|
#endif
|
2004-02-26 02:34:12 +00:00
|
|
|
|
2007-07-03 12:16:07 +00:00
|
|
|
struct ifnet *pflogifs[PFLOGIFS_MAX]; /* for fast access */
|
2004-02-26 02:34:12 +00:00
|
|
|
|
2007-07-03 12:16:07 +00:00
|
|
|
#ifndef __FreeBSD__
|
|
|
|
extern int ifqmaxlen;
|
|
|
|
#endif
|
2004-02-26 02:34:12 +00:00
|
|
|
|
2007-07-03 12:16:07 +00:00
|
|
|
void
|
|
|
|
pflogattach(int npflog)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
LIST_INIT(&pflogif_list);
|
|
|
|
for (i = 0; i < PFLOGIFS_MAX; i++)
|
|
|
|
pflogifs[i] = NULL;
|
|
|
|
#ifndef __FreeBSD__
|
|
|
|
(void) pflog_clone_create(&pflog_cloner, 0);
|
|
|
|
#endif
|
|
|
|
if_clone_attach(&pflog_cloner);
|
2004-02-26 02:34:12 +00:00
|
|
|
}
|
|
|
|
|
2006-07-09 06:04:01 +00:00
|
|
|
#ifdef __FreeBSD__
|
2007-07-03 12:16:07 +00:00
|
|
|
static int
|
|
|
|
pflog_clone_create(struct if_clone *ifc, int unit, caddr_t param)
|
2006-07-09 06:04:01 +00:00
|
|
|
#else
|
2007-07-03 12:16:07 +00:00
|
|
|
int
|
2004-02-26 02:34:12 +00:00
|
|
|
pflog_clone_create(struct if_clone *ifc, int unit)
|
2006-07-09 06:04:01 +00:00
|
|
|
#endif
|
2004-02-26 02:34:12 +00:00
|
|
|
{
|
2005-02-09 19:29:13 +00:00
|
|
|
struct ifnet *ifp;
|
2007-07-03 12:16:07 +00:00
|
|
|
struct pflog_softc *pflogif;
|
|
|
|
int s;
|
2004-02-26 02:34:12 +00:00
|
|
|
|
2007-07-03 12:16:07 +00:00
|
|
|
if (unit >= PFLOGIFS_MAX)
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
if ((pflogif = malloc(sizeof(*pflogif), M_DEVBUF, M_NOWAIT)) == NULL)
|
|
|
|
return (ENOMEM);
|
|
|
|
bzero(pflogif, sizeof(*pflogif));
|
|
|
|
|
|
|
|
pflogif->sc_unit = unit;
|
|
|
|
#ifdef __FreeBSD__
|
|
|
|
ifp = pflogif->sc_ifp = if_alloc(IFT_PFLOG);
|
2005-06-10 16:49:24 +00:00
|
|
|
if (ifp == NULL) {
|
2007-07-03 12:16:07 +00:00
|
|
|
free(pflogif, M_DEVBUF);
|
2005-06-10 16:49:24 +00:00
|
|
|
return (ENOSPC);
|
|
|
|
}
|
2005-02-09 19:29:13 +00:00
|
|
|
if_initname(ifp, ifc->ifc_name, unit);
|
2007-07-03 12:16:07 +00:00
|
|
|
#else
|
|
|
|
ifp = &pflogif->sc_if;
|
|
|
|
snprintf(ifp->if_xname, sizeof ifp->if_xname, "pflog%d", unit);
|
|
|
|
#endif
|
|
|
|
ifp->if_softc = pflogif;
|
2005-02-09 19:29:13 +00:00
|
|
|
ifp->if_mtu = PFLOGMTU;
|
|
|
|
ifp->if_ioctl = pflogioctl;
|
|
|
|
ifp->if_output = pflogoutput;
|
|
|
|
ifp->if_start = pflogstart;
|
2007-07-03 12:16:07 +00:00
|
|
|
#ifndef __FreeBSD__
|
|
|
|
ifp->if_type = IFT_PFLOG;
|
|
|
|
#endif
|
2005-02-09 19:29:13 +00:00
|
|
|
ifp->if_snd.ifq_maxlen = ifqmaxlen;
|
|
|
|
ifp->if_hdrlen = PFLOG_HDRLEN;
|
|
|
|
if_attach(ifp);
|
2007-07-03 12:16:07 +00:00
|
|
|
#ifndef __FreeBSD__
|
|
|
|
if_alloc_sadl(ifp);
|
|
|
|
#endif
|
2005-02-09 19:29:13 +00:00
|
|
|
|
2004-02-26 02:34:12 +00:00
|
|
|
#if NBPFILTER > 0
|
2007-07-03 12:16:07 +00:00
|
|
|
#ifdef __FreeBSD__
|
2005-02-09 19:29:13 +00:00
|
|
|
bpfattach(ifp, DLT_PFLOG, PFLOG_HDRLEN);
|
2007-07-03 12:16:07 +00:00
|
|
|
#else
|
|
|
|
bpfattach(&pflogif->sc_if.if_bpf, ifp, DLT_PFLOG, PFLOG_HDRLEN);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
s = splnet();
|
|
|
|
#ifdef __FreeBSD__
|
|
|
|
PF_LOCK();
|
|
|
|
#endif
|
|
|
|
LIST_INSERT_HEAD(&pflogif_list, pflogif, sc_list);
|
|
|
|
pflogifs[unit] = ifp;
|
|
|
|
#ifdef __FreeBSD__
|
|
|
|
PF_UNLOCK();
|
2004-02-26 02:34:12 +00:00
|
|
|
#endif
|
2007-07-03 12:16:07 +00:00
|
|
|
splx(s);
|
2004-02-26 02:04:28 +00:00
|
|
|
|
2005-02-09 19:29:13 +00:00
|
|
|
return (0);
|
2004-02-26 02:34:12 +00:00
|
|
|
}
|
2007-07-03 12:16:07 +00:00
|
|
|
|
|
|
|
#ifdef __FreeBSD__
|
|
|
|
static void
|
|
|
|
pflog_clone_destroy(struct ifnet *ifp)
|
|
|
|
#else
|
|
|
|
int
|
|
|
|
pflog_clone_destroy(struct ifnet *ifp)
|
|
|
|
#endif
|
2004-02-26 02:04:28 +00:00
|
|
|
{
|
2007-07-03 12:16:07 +00:00
|
|
|
struct pflog_softc *pflogif = ifp->if_softc;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splnet();
|
|
|
|
#ifdef __FreeBSD__
|
|
|
|
PF_LOCK();
|
|
|
|
#endif
|
|
|
|
pflogifs[pflogif->sc_unit] = NULL;
|
|
|
|
LIST_REMOVE(pflogif, sc_list);
|
|
|
|
#ifdef __FreeBSD__
|
|
|
|
PF_UNLOCK();
|
|
|
|
#endif
|
|
|
|
splx(s);
|
2004-02-26 02:04:28 +00:00
|
|
|
|
|
|
|
#if NBPFILTER > 0
|
2007-07-03 12:16:07 +00:00
|
|
|
bpfdetach(ifp);
|
|
|
|
#endif
|
|
|
|
if_detach(ifp);
|
|
|
|
#ifdef __FreeBSD__
|
|
|
|
if_free(ifp);
|
|
|
|
#endif
|
|
|
|
free(pflogif, M_DEVBUF);
|
|
|
|
#ifndef __FreeBSD__
|
|
|
|
return (0);
|
2004-02-26 02:04:28 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Start output on the pflog interface.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
pflogstart(struct ifnet *ifp)
|
|
|
|
{
|
|
|
|
struct mbuf *m;
|
2004-06-16 23:24:02 +00:00
|
|
|
#ifndef __FreeBSD__
|
2004-02-26 02:04:28 +00:00
|
|
|
int s;
|
2004-06-16 23:24:02 +00:00
|
|
|
#endif
|
2004-02-26 02:04:28 +00:00
|
|
|
|
|
|
|
for (;;) {
|
2004-03-17 21:11:02 +00:00
|
|
|
#ifdef __FreeBSD__
|
2004-06-14 16:13:05 +00:00
|
|
|
IF_LOCK(&ifp->if_snd);
|
|
|
|
_IF_DROP(&ifp->if_snd);
|
|
|
|
_IF_DEQUEUE(&ifp->if_snd, m);
|
2007-07-03 12:16:07 +00:00
|
|
|
IF_UNLOCK(&ifp->if_snd);
|
2004-02-26 02:34:12 +00:00
|
|
|
#else
|
2007-07-03 12:16:07 +00:00
|
|
|
s = splnet();
|
2004-02-26 02:04:28 +00:00
|
|
|
IF_DROP(&ifp->if_snd);
|
|
|
|
IF_DEQUEUE(&ifp->if_snd, m);
|
|
|
|
splx(s);
|
2007-07-03 12:16:07 +00:00
|
|
|
#endif
|
|
|
|
|
2004-02-26 02:04:28 +00:00
|
|
|
if (m == NULL)
|
|
|
|
return;
|
|
|
|
else
|
|
|
|
m_freem(m);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
pflogoutput(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst,
|
|
|
|
struct rtentry *rt)
|
|
|
|
{
|
|
|
|
m_freem(m);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
|
|
|
int
|
|
|
|
pflogioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
|
|
|
|
{
|
|
|
|
switch (cmd) {
|
|
|
|
case SIOCSIFADDR:
|
|
|
|
case SIOCAIFADDR:
|
|
|
|
case SIOCSIFDSTADDR:
|
|
|
|
case SIOCSIFFLAGS:
|
2005-08-09 11:59:02 +00:00
|
|
|
#ifdef __FreeBSD__
|
2004-02-26 02:04:28 +00:00
|
|
|
if (ifp->if_flags & IFF_UP)
|
2005-08-09 10:20:02 +00:00
|
|
|
ifp->if_drv_flags |= IFF_DRV_RUNNING;
|
2004-02-26 02:04:28 +00:00
|
|
|
else
|
2005-08-09 10:20:02 +00:00
|
|
|
ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
|
2005-08-09 11:59:02 +00:00
|
|
|
#else
|
|
|
|
if (ifp->if_flags & IFF_UP)
|
|
|
|
ifp->if_flags |= IFF_RUNNING;
|
|
|
|
else
|
|
|
|
ifp->if_flags &= ~IFF_RUNNING;
|
|
|
|
#endif
|
2004-02-26 02:04:28 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2004-06-16 23:24:02 +00:00
|
|
|
pflog_packet(struct pfi_kif *kif, struct mbuf *m, sa_family_t af, u_int8_t dir,
|
2004-02-26 02:04:28 +00:00
|
|
|
u_int8_t reason, struct pf_rule *rm, struct pf_rule *am,
|
2007-07-03 12:16:07 +00:00
|
|
|
struct pf_ruleset *ruleset, struct pf_pdesc *pd)
|
2004-02-26 02:04:28 +00:00
|
|
|
{
|
|
|
|
#if NBPFILTER > 0
|
|
|
|
struct ifnet *ifn;
|
|
|
|
struct pfloghdr hdr;
|
|
|
|
|
2007-07-03 12:16:07 +00:00
|
|
|
if (kif == NULL || m == NULL || rm == NULL || pd == NULL)
|
2004-02-26 02:04:28 +00:00
|
|
|
return (-1);
|
|
|
|
|
2007-07-03 12:16:07 +00:00
|
|
|
if ((ifn = pflogifs[rm->logif]) == NULL || !ifn->if_bpf)
|
|
|
|
return (0);
|
|
|
|
|
2004-06-16 23:24:02 +00:00
|
|
|
bzero(&hdr, sizeof(hdr));
|
2004-02-26 02:04:28 +00:00
|
|
|
hdr.length = PFLOG_REAL_HDRLEN;
|
|
|
|
hdr.af = af;
|
|
|
|
hdr.action = rm->action;
|
|
|
|
hdr.reason = reason;
|
2004-06-16 23:24:02 +00:00
|
|
|
memcpy(hdr.ifname, kif->pfik_name, sizeof(hdr.ifname));
|
2004-02-26 02:04:28 +00:00
|
|
|
|
|
|
|
if (am == NULL) {
|
|
|
|
hdr.rulenr = htonl(rm->nr);
|
|
|
|
hdr.subrulenr = -1;
|
|
|
|
} else {
|
|
|
|
hdr.rulenr = htonl(am->nr);
|
|
|
|
hdr.subrulenr = htonl(rm->nr);
|
2005-05-03 16:43:32 +00:00
|
|
|
if (ruleset != NULL && ruleset->anchor != NULL)
|
|
|
|
strlcpy(hdr.ruleset, ruleset->anchor->name,
|
2004-02-26 02:04:28 +00:00
|
|
|
sizeof(hdr.ruleset));
|
|
|
|
}
|
2007-07-03 12:16:07 +00:00
|
|
|
if (rm->log & PF_LOG_SOCKET_LOOKUP && !pd->lookup.done)
|
|
|
|
#ifdef __FreeBSD__
|
|
|
|
/*
|
|
|
|
* XXX: This should not happen as we force an early lookup
|
|
|
|
* via debug.pfugidhack
|
|
|
|
*/
|
|
|
|
; /* empty */
|
|
|
|
#else
|
|
|
|
pd->lookup.done = pf_socket_lookup(dir, pd);
|
|
|
|
#endif
|
|
|
|
if (pd->lookup.done > 0) {
|
|
|
|
hdr.uid = pd->lookup.uid;
|
|
|
|
hdr.pid = pd->lookup.pid;
|
|
|
|
} else {
|
|
|
|
hdr.uid = UID_MAX;
|
|
|
|
hdr.pid = NO_PID;
|
|
|
|
}
|
|
|
|
hdr.rule_uid = rm->cuid;
|
|
|
|
hdr.rule_pid = rm->cpid;
|
2004-02-26 02:04:28 +00:00
|
|
|
hdr.dir = dir;
|
|
|
|
|
|
|
|
#ifdef INET
|
|
|
|
if (af == AF_INET && dir == PF_OUT) {
|
|
|
|
struct ip *ip;
|
|
|
|
|
|
|
|
ip = mtod(m, struct ip *);
|
|
|
|
ip->ip_sum = 0;
|
|
|
|
ip->ip_sum = in_cksum(m, ip->ip_hl << 2);
|
|
|
|
}
|
|
|
|
#endif /* INET */
|
|
|
|
|
2007-07-03 12:16:07 +00:00
|
|
|
ifn->if_opackets++;
|
|
|
|
ifn->if_obytes += m->m_pkthdr.len;
|
2004-03-17 21:11:02 +00:00
|
|
|
#ifdef __FreeBSD__
|
2007-07-03 12:16:07 +00:00
|
|
|
BPF_MTAP2(ifn, &hdr, PFLOG_HDRLEN, m);
|
2004-02-26 02:34:12 +00:00
|
|
|
#else
|
2007-07-03 12:16:07 +00:00
|
|
|
bpf_mtap_hdr(ifn->if_bpf, (char *)&hdr, PFLOG_HDRLEN, m,
|
|
|
|
BPF_DIRECTION_OUT);
|
2004-06-16 23:24:02 +00:00
|
|
|
#endif
|
2004-02-26 02:04:28 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
2004-02-26 02:34:12 +00:00
|
|
|
|
2004-03-17 21:11:02 +00:00
|
|
|
#ifdef __FreeBSD__
|
2004-02-26 02:34:12 +00:00
|
|
|
static int
|
|
|
|
pflog_modevent(module_t mod, int type, void *data)
|
|
|
|
{
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case MOD_LOAD:
|
2007-07-03 12:16:07 +00:00
|
|
|
pflogattach(1);
|
2006-02-05 17:17:32 +00:00
|
|
|
PF_LOCK();
|
|
|
|
pflog_packet_ptr = pflog_packet;
|
|
|
|
PF_UNLOCK();
|
2004-02-26 02:34:12 +00:00
|
|
|
break;
|
|
|
|
case MOD_UNLOAD:
|
2006-02-05 17:17:32 +00:00
|
|
|
PF_LOCK();
|
|
|
|
pflog_packet_ptr = NULL;
|
|
|
|
PF_UNLOCK();
|
2004-02-26 02:34:12 +00:00
|
|
|
if_clone_detach(&pflog_cloner);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2007-07-03 12:16:07 +00:00
|
|
|
static moduledata_t pflog_mod = { "pflog", pflog_modevent, 0 };
|
2004-02-26 02:34:12 +00:00
|
|
|
|
|
|
|
#define PFLOG_MODVER 1
|
|
|
|
|
2004-09-14 03:12:01 +00:00
|
|
|
DECLARE_MODULE(pflog, pflog_mod, SI_SUB_PROTO_IFATTACHDOMAIN, SI_ORDER_ANY);
|
2004-02-26 02:34:12 +00:00
|
|
|
MODULE_VERSION(pflog, PFLOG_MODVER);
|
2006-02-05 17:17:32 +00:00
|
|
|
MODULE_DEPEND(pflog, pf, PF_MODVER, PF_MODVER, PF_MODVER);
|
2004-02-26 02:34:12 +00:00
|
|
|
#endif /* __FreeBSD__ */
|