Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dist/pf/net PF from OpenBSD 3.5



details:   https://anonhg.NetBSD.org/src/rev/7d46ac7b0eb8
branches:  trunk
changeset: 567596:7d46ac7b0eb8
user:      itojun <itojun%NetBSD.org@localhost>
date:      Tue Jun 22 13:52:05 2004 +0000

description:
PF from OpenBSD 3.5

diffstat:

 sys/dist/pf/net/if_pflog.c  |   229 +
 sys/dist/pf/net/if_pflog.h  |    75 +
 sys/dist/pf/net/if_pfsync.c |  1243 +++++++++
 sys/dist/pf/net/if_pfsync.h |   280 ++
 sys/dist/pf/net/pf.c        |  5854 +++++++++++++++++++++++++++++++++++++++++++
 sys/dist/pf/net/pf_if.c     |   840 ++++++
 sys/dist/pf/net/pf_ioctl.c  |  2655 +++++++++++++++++++
 sys/dist/pf/net/pf_norm.c   |  1537 +++++++++++
 sys/dist/pf/net/pf_osfp.c   |   525 +++
 sys/dist/pf/net/pf_table.c  |  2112 +++++++++++++++
 sys/dist/pf/net/pfvar.h     |  1471 ++++++++++
 11 files changed, 16821 insertions(+), 0 deletions(-)

diffs (truncated from 16865 to 300 lines):

diff -r 26e8a3e45b6d -r 7d46ac7b0eb8 sys/dist/pf/net/if_pflog.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dist/pf/net/if_pflog.c        Tue Jun 22 13:52:05 2004 +0000
@@ -0,0 +1,229 @@
+/*     $OpenBSD: if_pflog.c,v 1.11 2003/12/31 11:18:25 cedric Exp $    */
+/*
+ * The authors of this code are John Ioannidis (ji%tla.org@localhost),
+ * Angelos D. Keromytis (kermit%csd.uch.gr@localhost) and 
+ * Niels Provos (provos%physnet.uni-hamburg.de@localhost).
+ *
+ * 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.
+ */
+
+#include "bpfilter.h"
+#include "pflog.h"
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/mbuf.h>
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+
+#include <net/if.h>
+#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>
+
+#define PFLOGMTU       (32768 + MHLEN + MLEN)
+
+#ifdef PFLOGDEBUG
+#define DPRINTF(x)    do { if (pflogdebug) printf x ; } while (0)
+#else
+#define DPRINTF(x)
+#endif
+
+struct pflog_softc pflogif[NPFLOG];
+
+void   pflogattach(int);
+int    pflogoutput(struct ifnet *, struct mbuf *, struct sockaddr *,
+                      struct rtentry *);
+int    pflogioctl(struct ifnet *, u_long, caddr_t);
+void   pflogrtrequest(int, struct rtentry *, struct sockaddr *);
+void   pflogstart(struct ifnet *);
+
+extern int ifqmaxlen;
+
+void
+pflogattach(int npflog)
+{
+       struct ifnet *ifp;
+       int i;
+
+       bzero(pflogif, sizeof(pflogif));
+
+       for (i = 0; i < NPFLOG; i++) {
+               ifp = &pflogif[i].sc_if;
+               snprintf(ifp->if_xname, sizeof ifp->if_xname, "pflog%d", i);
+               ifp->if_softc = &pflogif[i];
+               ifp->if_mtu = PFLOGMTU;
+               ifp->if_ioctl = pflogioctl;
+               ifp->if_output = pflogoutput;
+               ifp->if_start = pflogstart;
+               ifp->if_type = IFT_PFLOG;
+               ifp->if_snd.ifq_maxlen = ifqmaxlen;
+               ifp->if_hdrlen = PFLOG_HDRLEN;
+               if_attach(ifp);
+               if_alloc_sadl(ifp);
+
+#if NBPFILTER > 0
+               bpfattach(&pflogif[i].sc_if.if_bpf, ifp, DLT_PFLOG,
+                         PFLOG_HDRLEN);
+#endif
+       }
+}
+
+/*
+ * Start output on the pflog interface.
+ */
+void
+pflogstart(struct ifnet *ifp)
+{
+       struct mbuf *m;
+       int s;
+
+       for (;;) {
+               s = splimp();
+               IF_DROP(&ifp->if_snd);
+               IF_DEQUEUE(&ifp->if_snd, m);
+               splx(s);
+
+               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 */
+void
+pflogrtrequest(int cmd, struct rtentry *rt, struct sockaddr *sa)
+{
+       if (rt)
+               rt->rt_rmx.rmx_mtu = PFLOGMTU;
+}
+
+/* ARGSUSED */
+int
+pflogioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
+{
+       switch (cmd) {
+       case SIOCSIFADDR:
+       case SIOCAIFADDR:
+       case SIOCSIFDSTADDR:
+       case SIOCSIFFLAGS:
+               if (ifp->if_flags & IFF_UP)
+                       ifp->if_flags |= IFF_RUNNING;
+               else
+                       ifp->if_flags &= ~IFF_RUNNING;
+               break;
+       default:
+               return (EINVAL);
+       }
+
+       return (0);
+}
+
+int
+pflog_packet(struct pfi_kif *kif, struct mbuf *m, sa_family_t af, u_int8_t dir,
+    u_int8_t reason, struct pf_rule *rm, struct pf_rule *am,
+    struct pf_ruleset *ruleset)
+{
+#if NBPFILTER > 0
+       struct ifnet *ifn;
+       struct pfloghdr hdr;
+       struct mbuf m1;
+
+       if (kif == NULL || m == NULL || rm == NULL)
+               return (-1);
+
+       bzero(&hdr, sizeof(hdr));
+       hdr.length = PFLOG_REAL_HDRLEN;
+       hdr.af = af;
+       hdr.action = rm->action;
+       hdr.reason = reason;
+       memcpy(hdr.ifname, kif->pfik_name, sizeof(hdr.ifname));
+
+       if (am == NULL) {
+               hdr.rulenr = htonl(rm->nr);
+               hdr.subrulenr = -1;
+       } else {
+               hdr.rulenr = htonl(am->nr);
+               hdr.subrulenr = htonl(rm->nr);
+               if (ruleset != NULL)
+                       memcpy(hdr.ruleset, ruleset->name,
+                           sizeof(hdr.ruleset));
+
+                       
+       }
+       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 */
+
+       m1.m_next = m;
+       m1.m_len = PFLOG_HDRLEN;
+       m1.m_data = (char *) &hdr;
+
+       ifn = &(pflogif[0].sc_if);
+
+       if (ifn->if_bpf)
+               bpf_mtap(ifn->if_bpf, &m1);
+#endif
+
+       return (0);
+}
diff -r 26e8a3e45b6d -r 7d46ac7b0eb8 sys/dist/pf/net/if_pflog.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dist/pf/net/if_pflog.h        Tue Jun 22 13:52:05 2004 +0000
@@ -0,0 +1,75 @@
+/* $OpenBSD: if_pflog.h,v 1.10 2004/03/19 04:52:04 frantzen Exp $ */
+/*
+ * Copyright 2001 Niels Provos <provos%citi.umich.edu@localhost>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _NET_IF_PFLOG_H_
+#define _NET_IF_PFLOG_H_
+
+struct pflog_softc {
+       struct ifnet    sc_if;  /* the interface */
+};
+
+/* XXX keep in sync with pfvar.h */
+#ifndef PF_RULESET_NAME_SIZE
+#define PF_RULESET_NAME_SIZE    16
+#endif
+
+struct pfloghdr {
+       u_int8_t        length;
+       sa_family_t     af;
+       u_int8_t        action;
+       u_int8_t        reason;
+       char            ifname[IFNAMSIZ];
+       char            ruleset[PF_RULESET_NAME_SIZE];
+       u_int32_t       rulenr;
+       u_int32_t       subrulenr;
+       u_int8_t        dir;
+       u_int8_t        pad[3];
+};
+
+#define PFLOG_HDRLEN           sizeof(struct pfloghdr)
+/* minus pad, also used as a signature */
+#define PFLOG_REAL_HDRLEN      offsetof(struct pfloghdr, pad)
+
+/* XXX remove later when old format logs are no longer needed */
+struct old_pfloghdr {
+       u_int32_t af;
+       char ifname[IFNAMSIZ];
+       short rnr;
+       u_short reason;
+       u_short action;
+       u_short dir;



Home | Main Index | Thread Index | Old Index