Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/npf/npfctl Always print the rule id associated with...



details:   https://anonhg.NetBSD.org/src/rev/c01f4d0cba58
branches:  trunk
changeset: 821224:c01f4d0cba58
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Jan 29 00:18:15 2017 +0000

description:
Always print the rule id associated with a rule.

diffstat:

 usr.sbin/npf/npfctl/npf_show.c |  23 +++++++++++++----------
 1 files changed, 13 insertions(+), 10 deletions(-)

diffs (65 lines):

diff -r c1ea82375f55 -r c01f4d0cba58 usr.sbin/npf/npfctl/npf_show.c
--- a/usr.sbin/npf/npfctl/npf_show.c    Sun Jan 29 00:16:42 2017 +0000
+++ b/usr.sbin/npf/npfctl/npf_show.c    Sun Jan 29 00:18:15 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: npf_show.c,v 1.22 2016/12/29 20:48:50 rmind Exp $      */
+/*     $NetBSD: npf_show.c,v 1.23 2017/01/29 00:18:15 christos Exp $   */
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: npf_show.c,v 1.22 2016/12/29 20:48:50 rmind Exp $");
+__RCSID("$NetBSD: npf_show.c,v 1.23 2017/01/29 00:18:15 christos Exp $");
 
 #include <sys/socket.h>
 #define        __FAVOR_BSD
@@ -338,6 +338,13 @@
 }
 
 static void
+npfctl_print_id(npf_conf_info_t *ctx, nl_rule_t *rl)
+{
+       uint64_t id = id = npf_rule_getid(rl);
+       fprintf(ctx->fp, "# id=\"%" PRIu64 "\" ", id);
+}
+
+static void
 npfctl_print_filter(npf_conf_info_t *ctx, nl_rule_t *rl)
 {
        const void *marks;
@@ -399,8 +406,7 @@
 
        if ((attr & NPF_DYNAMIC_GROUP) == NPF_RULE_GROUP) {
                /* Group; done. */
-               fputs("\n", ctx->fp);
-               return;
+               goto out;
        }
 
        /* Print filter criteria. */
@@ -411,12 +417,8 @@
                fprintf(ctx->fp, "apply \"%s\" ", rproc);
        }
 
-       /* If dynamic rule - print its ID. */
-       if ((attr & NPF_DYNAMIC_GROUP) == NPF_RULE_DYNAMIC) {
-               uint64_t id = npf_rule_getid(rl);
-               fprintf(ctx->fp, "# id = \"%" PRIx64 "\" ", id);
-       }
-
+out:
+       npfctl_print_id(ctx, rl);
        fputs("\n", ctx->fp);
 }
 
@@ -465,6 +467,7 @@
            ifname, (flags & NPF_NAT_STATIC) ? "static" : "dynamic",
            seg1, arrow, seg2);
        npfctl_print_filter(ctx, rl);
+       npfctl_print_id(ctx, rl);
        fputs("\n", ctx->fp);
        free(seg);
 }



Home | Main Index | Thread Index | Old Index