Source-Changes-HG archive

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

[src/trunk]: src/sys/net/npf provide a copy function used for logging that do...



details:   https://anonhg.NetBSD.org/src/rev/78d91565d3c9
branches:  trunk
changeset: 821839:78d91565d3c9
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Feb 18 23:27:32 2017 +0000

description:
provide a copy function used for logging that does not lock, but can return
trash.

diffstat:

 sys/net/npf/npf_ext_log.c |  15 +++++----------
 sys/net/npf/npf_if.c      |  18 ++++++++++++++++--
 2 files changed, 21 insertions(+), 12 deletions(-)

diffs (76 lines):

diff -r 0f6b44ff33cc -r 78d91565d3c9 sys/net/npf/npf_ext_log.c
--- a/sys/net/npf/npf_ext_log.c Sat Feb 18 22:39:00 2017 +0000
+++ b/sys/net/npf/npf_ext_log.c Sat Feb 18 23:27:32 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: npf_ext_log.c,v 1.12 2017/02/18 18:08:16 mlelstv Exp $ */
+/*     $NetBSD: npf_ext_log.c,v 1.13 2017/02/18 23:27:32 christos Exp $        */
 
 /*-
  * Copyright (c) 2010-2012 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #ifdef _KERNEL
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: npf_ext_log.c,v 1.12 2017/02/18 18:08:16 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf_ext_log.c,v 1.13 2017/02/18 23:27:32 christos Exp $");
 
 #include <sys/types.h>
 #include <sys/module.h>
@@ -104,15 +104,10 @@
        hdr.action = *decision == NPF_DECISION_PASS ?
            0 /* pass */ : 1 /* block */;
        hdr.reason = 0; /* match */
-#if 0
+
        struct nbuf *nb = npc->npc_nbuf;
-       const char *ifname = nb && nb->nb_ifid ? 
-           npf_ifmap_getname(npc->npc_ctx, nb->nb_ifid) : "???";
-#else
-       const char *ifname = "???";
-#endif
-
-       strlcpy(hdr.ifname, ifname, sizeof(hdr.ifname));
+       npf_ifmap_copyname(npc->npc_ctx, nb ? nb->nb_ifid : 0,
+           hdr.ifname, sizeof(hdr.ifname));
 
        hdr.rulenr = htonl((uint32_t)mi->mi_rid);
        hdr.subrulenr = htonl((uint32_t)(mi->mi_rid >> 32));
diff -r 0f6b44ff33cc -r 78d91565d3c9 sys/net/npf/npf_if.c
--- a/sys/net/npf/npf_if.c      Sat Feb 18 22:39:00 2017 +0000
+++ b/sys/net/npf/npf_if.c      Sat Feb 18 23:27:32 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: npf_if.c,v 1.7 2016/12/26 23:05:06 christos Exp $      */
+/*     $NetBSD: npf_if.c,v 1.8 2017/02/18 23:27:32 christos Exp $      */
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -46,7 +46,7 @@
 
 #ifdef _KERNEL
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: npf_if.c,v 1.7 2016/12/26 23:05:06 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf_if.c,v 1.8 2017/02/18 23:27:32 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -155,6 +155,20 @@
        return i;
 }
 
+/*
+ * This function is toxic; it can return garbage since we don't
+ * lock, but it is only used temporarily and only for logging.
+ */
+void
+npf_ifmap_copyname(npf_t *npf, u_int id, char *buf, size_t len)
+{
+       if (id > 0 && id < npf->ifmap_cnt)
+               strlcpy(buf, npf->ifmap[id - 1].n_ifname,
+                   MIN(len, sizeof(npf->ifmap[id - 1].n_ifname)));
+       else
+               strlcpy(buf, "???", len);
+}
+
 const char *
 npf_ifmap_getname(npf_t *npf, const u_int id)
 {



Home | Main Index | Thread Index | Old Index