Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Add NPF "rndblock" extension to randomly drop packets (using...
details: https://anonhg.NetBSD.org/src/rev/573b7bd91a74
branches: trunk
changeset: 783177:573b7bd91a74
user: rmind <rmind%NetBSD.org@localhost>
date: Mon Dec 10 00:32:23 2012 +0000
description:
Add NPF "rndblock" extension to randomly drop packets (using a random function
with a percentage or modulo operation). This is a demo module, although it can
be used for packet loss simulation. Example of a procedure in npf.conf:
procedure "somedrop" {
# Drop 1.9% of the traffic
rndblock: percentage 1.9
}
diffstat:
distrib/sets/lists/base/ad.mips64eb | 8 +-
distrib/sets/lists/base/ad.mips64el | 8 +-
distrib/sets/lists/base/md.amd64 | 5 +-
distrib/sets/lists/base/md.sparc64 | 5 +-
distrib/sets/lists/base/shl.mi | 5 +-
distrib/sets/lists/comp/shl.mi | 3 +-
distrib/sets/lists/modules/md.evbppc | 6 +-
distrib/sets/lists/modules/mi | 4 +-
lib/npf/Makefile | 4 +-
lib/npf/ext_rndblock/Makefile | 21 +++
lib/npf/ext_rndblock/npfext_rndblock.c | 97 ++++++++++++++++++
lib/npf/ext_rndblock/shlib_version | 4 +
sys/modules/Makefile | 3 +-
sys/modules/npf_ext_rndblock/Makefile | 11 ++
sys/net/npf/files.npf | 3 +-
sys/net/npf/npf_ext_rndblock.c | 174 +++++++++++++++++++++++++++++++++
16 files changed, 349 insertions(+), 12 deletions(-)
diffs (truncated from 551 to 300 lines):
diff -r 8f41f4485b3e -r 573b7bd91a74 distrib/sets/lists/base/ad.mips64eb
--- a/distrib/sets/lists/base/ad.mips64eb Sun Dec 09 23:53:39 2012 +0000
+++ b/distrib/sets/lists/base/ad.mips64eb Mon Dec 10 00:32:23 2012 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: ad.mips64eb,v 1.105 2012/12/09 22:06:21 spz Exp $
+# $NetBSD: ad.mips64eb,v 1.106 2012/12/10 00:32:24 rmind Exp $
./libexec/ld.elf_so-64 base-compat-shlib compat,pic
./libexec/ld.elf_so-o32 base-sysutil-bin compat,pic
./usr/lib/64 base-compat-lib
@@ -297,6 +297,9 @@
./usr/lib/64/npf/ext_normalise.so base-npf-shlib compat,pic
./usr/lib/64/npf/ext_normalise.so.0 base-npf-shlib compat,pic
./usr/lib/64/npf/ext_normalise.so.0.0 base-npf-shlib compat,pic
+./usr/lib/64/npf/ext_rndblock.so base-npf-shlib compat,pic
+./usr/lib/64/npf/ext_rndblock.so.0 base-npf-shlib compat,pic
+./usr/lib/64/npf/ext_rndblock.so.0.0 base-npf-shlib compat,pic
./usr/lib/64/security base-compat-shlib
./usr/lib/64/security/pam_afslog.so.3 base-compat-shlib compat,pic,kerberos,pam
./usr/lib/64/security/pam_chroot.so.3 base-compat-shlib compat,pic,pam
@@ -610,6 +613,9 @@
./usr/lib/o32/npf/ext_normalise.so base-npf-shlib compat,pic
./usr/lib/o32/npf/ext_normalise.so.0 base-npf-shlib compat,pic
./usr/lib/o32/npf/ext_normalise.so.0.0 base-npf-shlib compat,pic
+./usr/lib/o32/npf/ext_rndblock.so base-npf-shlib compat,pic
+./usr/lib/o32/npf/ext_rndblock.so.0 base-npf-shlib compat,pic
+./usr/lib/o32/npf/ext_rndblock.so.0.0 base-npf-shlib compat,pic
./usr/lib/o32/security base-compat-shlib
./usr/lib/o32/security/pam_afslog.so.3 base-compat-shlib compat,pic,kerberos,pam
./usr/lib/o32/security/pam_chroot.so.3 base-compat-shlib compat,pic,pam
diff -r 8f41f4485b3e -r 573b7bd91a74 distrib/sets/lists/base/ad.mips64el
--- a/distrib/sets/lists/base/ad.mips64el Sun Dec 09 23:53:39 2012 +0000
+++ b/distrib/sets/lists/base/ad.mips64el Mon Dec 10 00:32:23 2012 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: ad.mips64el,v 1.105 2012/12/09 22:06:21 spz Exp $
+# $NetBSD: ad.mips64el,v 1.106 2012/12/10 00:32:24 rmind Exp $
./libexec/ld.elf_so-64 base-compat-shlib compat,pic
./libexec/ld.elf_so-o32 base-sysutil-bin compat,pic
./usr/lib/64 base-compat-lib
@@ -297,6 +297,9 @@
./usr/lib/64/npf/ext_normalise.so base-npf-shlib compat,pic
./usr/lib/64/npf/ext_normalise.so.0 base-npf-shlib compat,pic
./usr/lib/64/npf/ext_normalise.so.0.0 base-npf-shlib compat,pic
+./usr/lib/64/npf/ext_rndblock.so base-npf-shlib compat,pic
+./usr/lib/64/npf/ext_rndblock.so.0 base-npf-shlib compat,pic
+./usr/lib/64/npf/ext_rndblock.so.0.0 base-npf-shlib compat,pic
./usr/lib/64/security base-compat-shlib
./usr/lib/64/security/pam_afslog.so.3 base-compat-shlib compat,pic,kerberos,pam
./usr/lib/64/security/pam_chroot.so.3 base-compat-shlib compat,pic,pam
@@ -610,6 +613,9 @@
./usr/lib/o32/npf/ext_normalise.so base-npf-shlib compat,pic
./usr/lib/o32/npf/ext_normalise.so.0 base-npf-shlib compat,pic
./usr/lib/o32/npf/ext_normalise.so.0.0 base-npf-shlib compat,pic
+./usr/lib/o32/npf/ext_rndblock.so base-npf-shlib compat,pic
+./usr/lib/o32/npf/ext_rndblock.so.0 base-npf-shlib compat,pic
+./usr/lib/o32/npf/ext_rndblock.so.0.0 base-npf-shlib compat,pic
./usr/lib/o32/security base-compat-shlib
./usr/lib/o32/security/pam_afslog.so.3 base-compat-shlib compat,pic,kerberos,pam
./usr/lib/o32/security/pam_chroot.so.3 base-compat-shlib compat,pic,pam
diff -r 8f41f4485b3e -r 573b7bd91a74 distrib/sets/lists/base/md.amd64
--- a/distrib/sets/lists/base/md.amd64 Sun Dec 09 23:53:39 2012 +0000
+++ b/distrib/sets/lists/base/md.amd64 Mon Dec 10 00:32:23 2012 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: md.amd64,v 1.181 2012/12/09 22:06:21 spz Exp $
+# $NetBSD: md.amd64,v 1.182 2012/12/10 00:32:24 rmind Exp $
./dev/lms0 base-obsolete obsolete
./dev/mms0 base-obsolete obsolete
./libexec/ld.elf_so-i386 base-sys-shlib compat,pic
@@ -300,6 +300,9 @@
./usr/lib/i386/npf/ext_normalise.so base-npf-shlib compat,pic
./usr/lib/i386/npf/ext_normalise.so.0 base-npf-shlib compat,pic
./usr/lib/i386/npf/ext_normalise.so.0.0 base-npf-shlib compat,pic
+./usr/lib/i386/npf/ext_rndblock.so base-npf-shlib compat,pic
+./usr/lib/i386/npf/ext_rndblock.so.0 base-npf-shlib compat,pic
+./usr/lib/i386/npf/ext_rndblock.so.0.0 base-npf-shlib compat,pic
./usr/lib/i386/security base-compat-shlib compat
./usr/lib/i386/security/pam_afslog.so.3 base-compat-shlib compat,pic,kerberos,pam
./usr/lib/i386/security/pam_chroot.so.3 base-compat-shlib compat,pic,pam
diff -r 8f41f4485b3e -r 573b7bd91a74 distrib/sets/lists/base/md.sparc64
--- a/distrib/sets/lists/base/md.sparc64 Sun Dec 09 23:53:39 2012 +0000
+++ b/distrib/sets/lists/base/md.sparc64 Mon Dec 10 00:32:23 2012 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: md.sparc64,v 1.170 2012/12/09 22:06:21 spz Exp $
+# $NetBSD: md.sparc64,v 1.171 2012/12/10 00:32:24 rmind Exp $
./libexec/ld.elf_so-sparc base-sysutil-bin compat,pic
./sbin/edlabel base-sysutil-root obsolete
./usr/bin/fdformat base-util-bin
@@ -298,6 +298,9 @@
./usr/lib/sparc/npf/ext_normalise.so base-npf-shlib compat,pic
./usr/lib/sparc/npf/ext_normalise.so.0 base-npf-shlib compat,pic
./usr/lib/sparc/npf/ext_normalise.so.0.0 base-npf-shlib compat,pic
+./usr/lib/sparc/npf/ext_rndblock.so base-npf-shlib compat,pic
+./usr/lib/sparc/npf/ext_rndblock.so.0 base-npf-shlib compat,pic
+./usr/lib/sparc/npf/ext_rndblock.so.0.0 base-npf-shlib compat,pic
./usr/lib/sparc/security base-compat-shlib compat
./usr/lib/sparc/security/pam_afslog.so.3 base-compat-shlib compat,pic,kerberos
./usr/lib/sparc/security/pam_chroot.so.3 base-compat-shlib compat,pic
diff -r 8f41f4485b3e -r 573b7bd91a74 distrib/sets/lists/base/shl.mi
--- a/distrib/sets/lists/base/shl.mi Sun Dec 09 23:53:39 2012 +0000
+++ b/distrib/sets/lists/base/shl.mi Mon Dec 10 00:32:23 2012 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: shl.mi,v 1.642 2012/12/04 23:38:58 spz Exp $
+# $NetBSD: shl.mi,v 1.643 2012/12/10 00:32:24 rmind Exp $
#
# Note: Don't delete entries from here - mark them as "obsolete" instead,
# unless otherwise stated below.
@@ -741,6 +741,9 @@
./usr/lib/npf/ext_normalise.so base-npf-shlib npf
./usr/lib/npf/ext_normalise.so.0 base-npf-shlib npf
./usr/lib/npf/ext_normalise.so.0.0 base-npf-shlib npf
+./usr/lib/npf/ext_rndblock.so base-npf-shlib npf
+./usr/lib/npf/ext_rndblock.so.0 base-npf-shlib npf
+./usr/lib/npf/ext_rndblock.so.0.0 base-npf-shlib npf
./usr/lib/nss_mdns.so.0 base-obsolete obsolete
./usr/lib/nss_mdnsd.so.0 base-mdns-shlib mdns
./usr/lib/nss_multicast_dns.so.0 base-mdns-shlib mdns
diff -r 8f41f4485b3e -r 573b7bd91a74 distrib/sets/lists/comp/shl.mi
--- a/distrib/sets/lists/comp/shl.mi Sun Dec 09 23:53:39 2012 +0000
+++ b/distrib/sets/lists/comp/shl.mi Mon Dec 10 00:32:23 2012 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: shl.mi,v 1.240 2012/12/07 18:36:24 njoly Exp $
+# $NetBSD: shl.mi,v 1.241 2012/12/10 00:32:24 rmind Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -460,3 +460,4 @@
./usr/libdata/debug/usr/lib/libzpool.so.0.0.debug comp-zfs-debug zfs,dynamicroot,debug
./usr/libdata/debug/usr/lib/npf/libext_log.so.0.0.debug comp-sys-debug debug,npf
./usr/libdata/debug/usr/lib/npf/libext_normalise.so.0.0.debug comp-sys-debug debug,npf
+./usr/libdata/debug/usr/lib/npf/libext_rndblock.so.0.0.debug comp-sys-debug debug,npf
diff -r 8f41f4485b3e -r 573b7bd91a74 distrib/sets/lists/modules/md.evbppc
--- a/distrib/sets/lists/modules/md.evbppc Sun Dec 09 23:53:39 2012 +0000
+++ b/distrib/sets/lists/modules/md.evbppc Mon Dec 10 00:32:23 2012 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: md.evbppc,v 1.28 2012/09/21 08:42:33 martin Exp $
+# $NetBSD: md.evbppc,v 1.29 2012/12/10 00:32:24 rmind Exp $
./stand/powerpc-4xx base-kernel-modules kmod,compatmodules
./stand/powerpc-4xx/@OSRELEASE@ base-kernel-modules kmod,compatmodules
./stand/powerpc-4xx/@OSRELEASE@/modules base-kernel-modules kmod,compatmodules
@@ -116,6 +116,8 @@
./stand/powerpc-4xx/@OSRELEASE@/modules/npf_ext_log/npf_ext_log.kmod base-kernel-modules kmod
./stand/powerpc-4xx/@OSRELEASE@/modules/npf_ext_normalise base-kernel-modules kmod
./stand/powerpc-4xx/@OSRELEASE@/modules/npf_ext_normalise/npf_ext_normalise.kmod base-kernel-modules kmod
+./stand/powerpc-4xx/@OSRELEASE@/modules/npf_ext_rndblock base-kernel-modules kmod
+./stand/powerpc-4xx/@OSRELEASE@/modules/npf_ext_rndblock/npf_ext_rndblock.kmod base-kernel-modules kmod
./stand/powerpc-4xx/@OSRELEASE@/modules/ntfs base-kernel-modules kmod,compatmodules
./stand/powerpc-4xx/@OSRELEASE@/modules/ntfs/ntfs.kmod base-kernel-modules kmod,compatmodules
./stand/powerpc-4xx/@OSRELEASE@/modules/null base-kernel-modules kmod,compatmodules
@@ -307,6 +309,8 @@
./stand/powerpc-booke/@OSRELEASE@/modules/npf_ext_log/npf_ext_log.kmod base-kernel-modules kmod
./stand/powerpc-booke/@OSRELEASE@/modules/npf_ext_normalise base-kernel-modules kmod
./stand/powerpc-booke/@OSRELEASE@/modules/npf_ext_normalise/npf_ext_normalise.kmod base-kernel-modules kmod
+./stand/powerpc-booke/@OSRELEASE@/modules/npf_ext_rndblock base-kernel-modules kmod
+./stand/powerpc-booke/@OSRELEASE@/modules/npf_ext_rndblock/npf_ext_rndblock.kmod base-kernel-modules kmod
./stand/powerpc-booke/@OSRELEASE@/modules/ntfs base-kernel-modules kmod,compatmodules
./stand/powerpc-booke/@OSRELEASE@/modules/ntfs/ntfs.kmod base-kernel-modules kmod,compatmodules
./stand/powerpc-booke/@OSRELEASE@/modules/null base-kernel-modules kmod,compatmodules
diff -r 8f41f4485b3e -r 573b7bd91a74 distrib/sets/lists/modules/mi
--- a/distrib/sets/lists/modules/mi Sun Dec 09 23:53:39 2012 +0000
+++ b/distrib/sets/lists/modules/mi Mon Dec 10 00:32:23 2012 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.48 2012/09/16 13:47:43 rmind Exp $
+# $NetBSD: mi,v 1.49 2012/12/10 00:32:24 rmind Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -119,6 +119,8 @@
./@MODULEDIR@/npf_ext_log/npf_ext_log.kmod base-kernel-modules kmod
./@MODULEDIR@/npf_ext_normalise base-kernel-modules kmod
./@MODULEDIR@/npf_ext_normalise/npf_ext_normalise.kmod base-kernel-modules kmod
+./@MODULEDIR@/npf_ext_rndblock base-kernel-modules kmod
+./@MODULEDIR@/npf_ext_rndblock/npf_ext_rndblock.kmod base-kernel-modules kmod
./@MODULEDIR@/ntfs base-kernel-modules kmod
./@MODULEDIR@/ntfs/ntfs.kmod base-kernel-modules kmod
./@MODULEDIR@/null base-kernel-modules kmod
diff -r 8f41f4485b3e -r 573b7bd91a74 lib/npf/Makefile
--- a/lib/npf/Makefile Sun Dec 09 23:53:39 2012 +0000
+++ b/lib/npf/Makefile Mon Dec 10 00:32:23 2012 +0000
@@ -1,10 +1,10 @@
-# $NetBSD: Makefile,v 1.1 2012/09/16 13:47:41 rmind Exp $
+# $NetBSD: Makefile,v 1.2 2012/12/10 00:32:24 rmind Exp $
.include <bsd.own.mk>
.if ${MKPIC} != "no"
-SUBDIR= ext_log ext_normalise
+SUBDIR= ext_log ext_normalise ext_rndblock
.endif
diff -r 8f41f4485b3e -r 573b7bd91a74 lib/npf/ext_rndblock/Makefile
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/npf/ext_rndblock/Makefile Mon Dec 10 00:32:23 2012 +0000
@@ -0,0 +1,21 @@
+# $NetBSD: Makefile,v 1.1 2012/12/10 00:32:24 rmind Exp $
+
+.include <bsd.own.mk>
+
+LIBISMODULE= yes
+.if defined(MLIBDIR)
+LIBDIR= /usr/lib/${MLIBDIR}/npf
+SHLIBDIR= /usr/lib/${MLIBDIR}/npf
+SHLIBINSTALLDIR=/usr/lib/${MLIBDIR}/npf
+.else
+LIBDIR= /usr/lib/npf
+SHLIBDIR= /usr/lib/npf
+SHLIBINSTALLDIR=/usr/lib/npf
+.endif
+
+LIB= ext_rndblock
+
+SRCS= npfext_rndblock.c
+WARNS= 5
+
+.include <bsd.lib.mk>
diff -r 8f41f4485b3e -r 573b7bd91a74 lib/npf/ext_rndblock/npfext_rndblock.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/npf/ext_rndblock/npfext_rndblock.c Mon Dec 10 00:32:23 2012 +0000
@@ -0,0 +1,97 @@
+/* $NetBSD: npfext_rndblock.c,v 1.1 2012/12/10 00:32:24 rmind Exp $ */
+
+/*-
+ * Copyright (c) 2012 The NetBSD Foundation, Inc.
+ * 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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: npfext_rndblock.c,v 1.1 2012/12/10 00:32:24 rmind Exp $");
+
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <errno.h>
+
+#include <npf.h>
+
+int npfext_rndblock_init(void);
+nl_ext_t * npfext_rndblock_construct(const char *);
+int npfext_rndblock_param(nl_ext_t *, const char *, const char *);
+
+int
+npfext_rndblock_init(void)
+{
+ /* Nothing to initialise. */
+ return 0;
+}
+
+nl_ext_t *
+npfext_rndblock_construct(const char *name)
+{
+ assert(strcmp(name, "rndblock") == 0);
+ return npf_ext_construct(name);
+}
+
+int
+npfext_rndblock_param(nl_ext_t *ext, const char *param, const char *val)
+{
+ enum ptype { PARAM_U32 };
+ static const struct param {
+ const char * name;
+ enum ptype type;
+ signed long min;
+ signed long max;
+ } params[] = {
+ { "mod", PARAM_U32, 1, LONG_MAX },
+ { "percentage", PARAM_U32, 1, 9999 },
+ };
+
+ if (val == NULL) {
+ return EINVAL;
+ }
+ for (unsigned i = 0; i < __arraycount(params); i++) {
+ const char *name = params[i].name;
+ long ival;
+
+ if (strcmp(name, param) != 0) {
+ continue;
+ }
+
Home |
Main Index |
Thread Index |
Old Index