Source-Changes-HG archive

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

[src/trunk]: src/lib/libnpf Add _npf_config_setsubmit() function.



details:   https://anonhg.NetBSD.org/src/rev/832d0cf3d929
branches:  trunk
changeset: 771634:832d0cf3d929
user:      rmind <rmind%NetBSD.org@localhost>
date:      Sat Nov 26 23:11:19 2011 +0000

description:
Add _npf_config_setsubmit() function.

diffstat:

 lib/libnpf/npf.c |  28 ++++++++++++++++++++--------
 lib/libnpf/npf.h |   5 ++++-
 2 files changed, 24 insertions(+), 9 deletions(-)

diffs (97 lines):

diff -r 29f01d385b47 -r 832d0cf3d929 lib/libnpf/npf.c
--- a/lib/libnpf/npf.c  Sat Nov 26 22:49:37 2011 +0000
+++ b/lib/libnpf/npf.c  Sat Nov 26 23:11:19 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: npf.c,v 1.3 2011/11/04 01:00:28 zoltan Exp $   */
+/*     $NetBSD: npf.c,v 1.4 2011/11/26 23:11:19 rmind Exp $    */
 
 /*-
  * Copyright (c) 2010-2011 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: npf.c,v 1.3 2011/11/04 01:00:28 zoltan Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf.c,v 1.4 2011/11/26 23:11:19 rmind Exp $");
 
 #include <sys/types.h>
 #include <netinet/in_systm.h>
@@ -54,6 +54,8 @@
        /* Priority counters. */
        pri_t                   ncf_rule_pri;
        pri_t                   ncf_nat_pri;
+       /* Custom file to externalise property-list. */
+       const char *            ncf_plist;
 };
 
 struct nl_rule {
@@ -89,6 +91,8 @@
        ncf->ncf_rule_pri = 1;
        ncf->ncf_nat_pri = 1;
 
+       ncf->ncf_plist = NULL;
+
        return ncf;
 }
 
@@ -96,6 +100,7 @@
 npf_config_submit(nl_config_t *ncf, int fd)
 {
        prop_dictionary_t npf_dict;
+       const char *plist = ncf->ncf_plist;
        int error = 0;
 
        npf_dict = prop_dictionary_create();
@@ -107,13 +112,13 @@
        prop_dictionary_set(npf_dict, "tables", ncf->ncf_table_list);
        prop_dictionary_set(npf_dict, "translation", ncf->ncf_nat_list);
 
-#ifndef _NPF_TESTING
-       error = prop_dictionary_send_ioctl(npf_dict, fd, IOC_NPF_RELOAD);
-#else
-       if (!prop_dictionary_externalize_to_file(npf_dict, "./npf.plist")) {
-               error = errno;
+       if (plist) {
+               if (!prop_dictionary_externalize_to_file(npf_dict, plist)) {
+                       error = errno;
+               }
+       } else {
+               error = prop_dictionary_send_ioctl(npf_dict, fd, IOC_NPF_RELOAD);
        }
-#endif
        prop_object_release(npf_dict);
        return error;
 }
@@ -129,6 +134,13 @@
        free(ncf);
 }
 
+void
+_npf_config_setsubmit(nl_config_t *ncf, const char *plist_file)
+{
+
+       ncf->ncf_plist = plist_file;
+}
+
 static bool
 _npf_prop_array_lookup(prop_array_t array, const char *key, const char *name)
 {
diff -r 29f01d385b47 -r 832d0cf3d929 lib/libnpf/npf.h
--- a/lib/libnpf/npf.h  Sat Nov 26 22:49:37 2011 +0000
+++ b/lib/libnpf/npf.h  Sat Nov 26 23:11:19 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: npf.h,v 1.2 2011/11/04 01:00:28 zoltan Exp $   */
+/*     $NetBSD: npf.h,v 1.3 2011/11/26 23:11:19 rmind Exp $    */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -63,6 +63,9 @@
 nl_config_t *  npf_config_create(void);
 int            npf_config_submit(nl_config_t *, int);
 void           npf_config_destroy(nl_config_t *);
+#ifdef _NPF_PRIVATE
+void           _npf_config_setsubmit(nl_config_t *, const char *);
+#endif
 
 nl_rule_t *    npf_rule_create(const char *, uint32_t, u_int);
 int            npf_rule_setcode(nl_rule_t *, int, const void *, size_t);



Home | Main Index | Thread Index | Old Index