Source-Changes-HG archive

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

[src/tls-maxphys]: src Implement dynamic NPF extensions interface. An extens...



details:   https://anonhg.NetBSD.org/src/rev/b5352b27b37c
branches:  tls-maxphys
changeset: 852914:b5352b27b37c
user:      rmind <rmind%NetBSD.org@localhost>
date:      Sun Sep 16 13:47:42 2012 +0000

description:
Implement dynamic NPF extensions interface.  An extension consists of
dynamically loaded module (.so) supplementing npfctl(8) and a kernel
module.  Move normalisation and logging functionality into their own
extensions.  More improvements to come.

diffstat:

 lib/npf/Makefile                         |   11 +++
 lib/npf/Makefile.inc                     |    8 ++
 lib/npf/ext_log/Makefile                 |   13 ++++
 lib/npf/ext_log/npfext_log.c             |   75 +++++++++++++++++++++++
 lib/npf/ext_log/shlib_version            |    4 +
 lib/npf/ext_normalise/Makefile           |   13 ++++
 lib/npf/ext_normalise/npfext_normalise.c |  100 +++++++++++++++++++++++++++++++
 lib/npf/ext_normalise/shlib_version      |    4 +
 sys/modules/npf_ext_log/Makefile         |   11 +++
 sys/modules/npf_ext_normalise/Makefile   |   11 +++
 10 files changed, 250 insertions(+), 0 deletions(-)

diffs (290 lines):

diff -r f9eda8024491 -r b5352b27b37c lib/npf/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/npf/Makefile  Sun Sep 16 13:47:42 2012 +0000
@@ -0,0 +1,11 @@
+# $NetBSD: Makefile,v 1.1.6.2 2012/09/16 13:47:42 rmind Exp $
+
+.include <bsd.own.mk>
+
+.if ${MKPIC} != "no"
+
+SUBDIR=                ext_log ext_normalise
+
+.endif
+
+.include <bsd.subdir.mk>
diff -r f9eda8024491 -r b5352b27b37c lib/npf/Makefile.inc
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/npf/Makefile.inc      Sun Sep 16 13:47:42 2012 +0000
@@ -0,0 +1,8 @@
+# $NetBSD: Makefile.inc,v 1.1.6.2 2012/09/16 13:47:43 rmind Exp $
+
+WARNS=         5
+MKLINT=                no
+
+.if exists(${.CURDIR}/../../Makefile.inc)
+.include "${.CURDIR}/../../Makefile.inc"
+.endif
diff -r f9eda8024491 -r b5352b27b37c lib/npf/ext_log/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/npf/ext_log/Makefile  Sun Sep 16 13:47:42 2012 +0000
@@ -0,0 +1,13 @@
+# $NetBSD: Makefile,v 1.1.6.2 2012/09/16 13:47:43 rmind Exp $
+
+.include <bsd.own.mk>
+
+LIBISMODULE= yes
+LIBDIR=        /usr/lib/npf
+
+LIB=   ext_log
+
+SRCS=  npfext_log.c
+WARNS= 5
+
+.include <bsd.lib.mk>
diff -r f9eda8024491 -r b5352b27b37c lib/npf/ext_log/npfext_log.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/npf/ext_log/npfext_log.c      Sun Sep 16 13:47:42 2012 +0000
@@ -0,0 +1,75 @@
+/*     $NetBSD: npfext_log.c,v 1.1.6.2 2012/09/16 13:47:43 rmind Exp $ */
+
+/*-
+ * Copyright (c) 2012 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Mindaugas Rasiukevicius.
+ *
+ * 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_log.c,v 1.1.6.2 2012/09/16 13:47:43 rmind Exp $");
+
+#include <sys/types.h>
+#include <net/if.h>
+
+#include <string.h>
+#include <assert.h>
+#include <errno.h>
+
+#include <npf.h>
+
+int            npfext_log_init(void);
+nl_ext_t *     npfext_log_construct(const char *);
+int            npfext_log_param(nl_ext_t *, const char *, const char *);
+
+int
+npfext_log_init(void)
+{
+       /* Nothing to initialise. */
+       return 0;
+}
+
+nl_ext_t *
+npfext_log_construct(const char *name)
+{
+       assert(strcmp(name, "log") == 0);
+       return npf_ext_construct(name);
+}
+
+int
+npfext_log_param(nl_ext_t *ext, const char *param, const char *val __unused)
+{
+       unsigned long if_idx;
+
+       assert(param != NULL);
+
+       if_idx = if_nametoindex(param);
+       if (if_idx == 0) {
+               return EINVAL;
+       }
+       npf_ext_param_u32(ext, "log-interface", if_idx);
+       return 0;
+}
diff -r f9eda8024491 -r b5352b27b37c lib/npf/ext_log/shlib_version
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/npf/ext_log/shlib_version     Sun Sep 16 13:47:42 2012 +0000
@@ -0,0 +1,4 @@
+# $NetBSD: shlib_version,v 1.1.6.2 2012/09/16 13:47:43 rmind Exp $
+
+major=0
+minor=0
diff -r f9eda8024491 -r b5352b27b37c lib/npf/ext_normalise/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/npf/ext_normalise/Makefile    Sun Sep 16 13:47:42 2012 +0000
@@ -0,0 +1,13 @@
+# $NetBSD: Makefile,v 1.1.6.2 2012/09/16 13:47:43 rmind Exp $
+
+.include <bsd.own.mk>
+
+LIBISMODULE= yes
+LIBDIR=        /usr/lib/npf
+
+LIB=   ext_normalise
+
+SRCS=  npfext_normalise.c
+WARNS= 5
+
+.include <bsd.lib.mk>
diff -r f9eda8024491 -r b5352b27b37c lib/npf/ext_normalise/npfext_normalise.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/npf/ext_normalise/npfext_normalise.c  Sun Sep 16 13:47:42 2012 +0000
@@ -0,0 +1,100 @@
+/*     $NetBSD: npfext_normalise.c,v 1.1.6.2 2012/09/16 13:47:43 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_normalise.c,v 1.1.6.2 2012/09/16 13:47:43 rmind Exp $");
+
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <errno.h>
+
+#include <npf.h>
+
+int            npfext_normalise_init(void);
+nl_ext_t *     npfext_normalise_construct(const char *);
+int            npfext_normalise_param(nl_ext_t *, const char *, const char *);
+
+int
+npfext_normalise_init(void)
+{
+       /* Nothing to initialise. */
+       return 0;
+}
+
+nl_ext_t *
+npfext_normalise_construct(const char *name)
+{
+       assert(strcmp(name, "normalise") == 0);
+       return npf_ext_construct(name);
+}
+
+int
+npfext_normalise_param(nl_ext_t *ext, const char *param, const char *val)
+{
+       enum ptype {
+               PARAM_BOOL,
+               PARAM_U32
+       };
+       static const struct param {
+               const char *    name;
+               enum ptype      type;
+               bool            reqval;
+       } params[] = {
+               { "random-id",  PARAM_BOOL,     false   },
+               { "no-df",      PARAM_BOOL,     false   },
+               { "min-ttl",    PARAM_U32,      true    },
+               { "max-mss",    PARAM_U32,      true    },
+       };
+
+       for (unsigned i = 0; i < __arraycount(params); i++) {
+               const char *name = params[i].name;
+
+               if (strcmp(name, param) != 0) {
+                       continue;
+               }
+               if (val == NULL && params[i].reqval) {
+                       return EINVAL;
+               }
+
+               switch (params[i].type) {
+               case PARAM_BOOL:
+                       npf_ext_param_bool(ext, name, true);
+                       break;
+               case PARAM_U32:
+                       npf_ext_param_u32(ext, name, atol(val));
+                       break;
+               default:
+                       assert(false);
+               }
+               return 0;
+       }
+
+       /* Invalid parameter, if not found. */
+       return EINVAL;
+}
diff -r f9eda8024491 -r b5352b27b37c lib/npf/ext_normalise/shlib_version
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/npf/ext_normalise/shlib_version       Sun Sep 16 13:47:42 2012 +0000
@@ -0,0 +1,4 @@
+# $NetBSD: shlib_version,v 1.1.6.2 2012/09/16 13:47:43 rmind Exp $
+
+major=0
+minor=0
diff -r f9eda8024491 -r b5352b27b37c sys/modules/npf_ext_log/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/modules/npf_ext_log/Makefile  Sun Sep 16 13:47:42 2012 +0000
@@ -0,0 +1,11 @@
+# $NetBSD: Makefile,v 1.1.6.2 2012/09/16 13:47:43 rmind Exp $
+
+.include "../Makefile.inc"
+
+.PATH:         ${S}/net/npf
+
+KMOD=          npf_ext_log
+
+SRCS=          npf_ext_log.c
+
+.include <bsd.kmodule.mk>
diff -r f9eda8024491 -r b5352b27b37c sys/modules/npf_ext_normalise/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/modules/npf_ext_normalise/Makefile    Sun Sep 16 13:47:42 2012 +0000
@@ -0,0 +1,11 @@
+# $NetBSD: Makefile,v 1.1.6.2 2012/09/16 13:47:44 rmind Exp $
+
+.include "../Makefile.inc"
+
+.PATH:         ${S}/net/npf
+
+KMOD=          npf_ext_normalise
+
+SRCS=          npf_ext_normalise.c
+
+.include <bsd.kmodule.mk>



Home | Main Index | Thread Index | Old Index