]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
proto: add debugging for protocol context updates
authorPatrick McHardy <kaber@trash.net>
Wed, 8 Jan 2014 13:02:16 +0000 (13:02 +0000)
committerPatrick McHardy <kaber@trash.net>
Wed, 8 Jan 2014 13:02:16 +0000 (13:02 +0000)
Add a new debugging level to debug updates to the protocol context.

Sample output:

<cmdline>:1:15-23: Evaluate
filter output tcp dport ssh
              ^^^^^^^^^
tcp

update transport layer protocol context:
 link layer          : none
 network layer       : ip
 transport layer     : tcp <-

Signed-off-by: Patrick McHardy <kaber@trash.net>
include/nftables.h
src/main.c
src/proto.c

index 12f3c49232a924a82721603e395407338f0ca7c9..801000e1f92e236328de96124e2abb23be65503c 100644 (file)
@@ -17,6 +17,7 @@ enum debug_level {
        DEBUG_PARSER            = 0x2,
        DEBUG_EVALUATION        = 0x4,
        DEBUG_NETLINK           = 0x8,
+       DEBUG_PROTO_CTX         = 0x10,
 };
 
 #define INCLUDE_PATHS_MAX      16
index 0c97120b2345e3aa6770a5e7fc202b8d16ea946d..859ddaacf032a9d5a391ef867e94df7893339f46 100644 (file)
@@ -111,7 +111,7 @@ static void show_help(const char *name)
 "  -a/--handle                 Output rule handle.\n"
 "  -I/--includepath <directory>        Add <directory> to the paths searched for include files.\n"
 #ifdef DEBUG
-"  --debug <level [,level...]> Specify debugging level (scanner, parser, eval, netlink, all)\n"
+"  --debug <level [,level...]> Specify debugging level (scanner, parser, eval, netlink, proto-ctx, all)\n"
 #endif
 "\n",
        name);
@@ -138,6 +138,10 @@ static const struct {
                .name           = "netlink",
                .level          = DEBUG_NETLINK,
        },
+       {
+               .name           = "proto-ctx",
+               .level          = DEBUG_PROTO_CTX,
+       },
        {
                .name           = "all",
                .level          = ~0,
index f611c97b5ba778702d60a8ce83a77448e25e74fc..c3fb7bf2968405813c0cccc972ee2d4b2ba452da 100644 (file)
@@ -128,6 +128,26 @@ const struct hook_proto_desc hook_proto_desc[] = {
        [NFPROTO_ARP]           = HOOK_PROTO_DESC(PROTO_BASE_NETWORK_HDR, &proto_arp),
 };
 
+static void proto_ctx_debug(const struct proto_ctx *ctx, enum proto_bases base)
+{
+#ifdef DEBUG
+       unsigned int i;
+
+       if (!(debug_level & DEBUG_PROTO_CTX))
+               return;
+
+       pr_debug("update %s protocol context:\n", proto_base_names[base]);
+       for (i = PROTO_BASE_LL_HDR; i <= PROTO_BASE_MAX; i++) {
+               pr_debug(" %-20s: %s%s\n",
+                        proto_base_names[i],
+                        ctx->protocol[i].desc ? ctx->protocol[i].desc->name :
+                                                "none",
+                        i == base ? " <-" : "");
+       }
+       pr_debug("\n");
+#endif
+}
+
 /**
  * proto_ctx_init - initialize protocol context for a given hook family
  *
@@ -141,6 +161,8 @@ void proto_ctx_init(struct proto_ctx *ctx, unsigned int family)
        memset(ctx, 0, sizeof(*ctx));
        ctx->family = family;
        ctx->protocol[h->base].desc = h->desc;
+
+       proto_ctx_debug(ctx, h->base);
 }
 
 /**
@@ -157,6 +179,8 @@ void proto_ctx_update(struct proto_ctx *ctx, enum proto_bases base,
 {
        ctx->protocol[base].location    = *loc;
        ctx->protocol[base].desc        = desc;
+
+       proto_ctx_debug(ctx, base);
 }
 
 #define HDR_TEMPLATE(__name, __dtype, __type, __member)                        \