src: handle rule tracing as an monitor object
Pablo Neira Ayuso
maintainerPATCH 1/2 src: handle rule tracing as an monitor object
Traces are not an event type, they should be handled as an object.
Signed-off-by Pablo Neira Ayuso <[email protected]>
--- include/rule.h | 1 + src/evaluate.c | 31 ++++--------------------------- src/parser_bison.y | 2 ++ src/scanner.l | 1 + 4 files changed, 8 insertions(+), 27 deletions(-)
include/rule.h +1 -0
@@ -397,6 +397,7 @@ enum {CMD_MONITOR_OBJ_SETS ,CMD_MONITOR_OBJ_ELEMS ,CMD_MONITOR_OBJ_RULESET , +CMD_MONITOR_OBJ_TRACE , CMD_MONITOR_OBJ_MAX };
src/evaluate.c +4 -27
@@ -3218,7 +3218,6 @@ enum {CMD_MONITOR_EVENT_ANY ,CMD_MONITOR_EVENT_NEW ,CMD_MONITOR_EVENT_DEL , -CMD_MONITOR_EVENT_TRACE , CMD_MONITOR_EVENT_MAX };
@@ -3247,6 +3246,7 @@ static uint32_t monitor_flags[CMD_MONITOR_EVENT_MAX][CMD_MONITOR_OBJ_MAX] = { (1 <<NFT_MSG_DELSETELEM ) | (1 <<NFT_MSG_NEWOBJ ) | (1 << NFT_MSG_DELOBJ), + [CMD_MONITOR_OBJ_TRACE] = (1 << NFT_MSG_TRACE), }, [CMD_MONITOR_EVENT_NEW] = { [CMD_MONITOR_OBJ_ANY] = (1 << NFT_MSG_NEWTABLE) |
@@ -3264,7 +3264,8 @@ static uint32_t monitor_flags[CMD_MONITOR_EVENT_MAX][CMD_MONITOR_OBJ_MAX] = { (1 <<NFT_MSG_NEWRULE ) | (1 <<NFT_MSG_NEWSET ) | (1 <<NFT_MSG_NEWSETELEM ) | - (1 <<NFT_MSG_NEWOBJ ) + (1 << NFT_MSG_NEWOBJ), + [CMD_MONITOR_OBJ_TRACE] = 0, }, [CMD_MONITOR_EVENT_DEL] = { [CMD_MONITOR_OBJ_ANY] = (1 << NFT_MSG_DELTABLE) |
@@ -3283,29 +3284,7 @@ static uint32_t monitor_flags[CMD_MONITOR_EVENT_MAX][CMD_MONITOR_OBJ_MAX] = { (1 <<NFT_MSG_DELSET ) | (1 <<NFT_MSG_DELSETELEM ) | (1 << NFT_MSG_DELOBJ), - }, - [CMD_MONITOR_EVENT_TRACE] = { - [CMD_MONITOR_OBJ_ANY ] = (1 <<NFT_MSG_NEWTABLE ) | - (1 <<NFT_MSG_NEWCHAIN ) | - (1 <<NFT_MSG_NEWRULE ) | - (1 <<NFT_MSG_DELTABLE ) | - (1 <<NFT_MSG_DELCHAIN ) | - (1 <<NFT_MSG_DELRULE ) | - (1 << NFT_MSG_TRACE), - [CMD_MONITOR_OBJ_TABLES ] = (1 <<NFT_MSG_NEWTABLE ) | - (1 << NFT_MSG_DELTABLE), - [CMD_MONITOR_OBJ_CHAINS ] = (1 <<NFT_MSG_NEWCHAIN ) | - (1 << NFT_MSG_DELCHAIN), - [CMD_MONITOR_OBJ_RULES ] = (1 <<NFT_MSG_NEWRULE ) | - (1 << NFT_MSG_DELRULE), - [CMD_MONITOR_OBJ_RULESET ] = (1 <<NFT_MSG_NEWTABLE ) | - (1 <<NFT_MSG_NEWCHAIN ) | - (1 <<NFT_MSG_NEWRULE ) | - (1 <<NFT_MSG_NEWOBJ ) | - (1 <<NFT_MSG_DELTABLE ) | - (1 <<NFT_MSG_DELCHAIN ) | - (1 <<NFT_MSG_DELRULE ) | - (1 << NFT_MSG_DELOBJ), + [CMD_MONITOR_OBJ_TRACE] = 0, }, };
@@ -3324,8 +3303,6 @@ static int cmd_evaluate_monitor(struct eval_ctx *ctx, struct cmd *cmd) event =CMD_MONITOR_EVENT_NEW ; else if (strcmp(cmd->monitor->event, "destroy") == 0) event =CMD_MONITOR_EVENT_DEL ; - else if (strcmp(cmd->monitor->event, "trace") == 0) - event =CMD_MONITOR_EVENT_TRACE ; else {return monitor_error (ctx, cmd->monitor,"invalid event %s" , cmd->monitor->event);
src/parser_bison.y +2 -0
@@ -194,6 +194,7 @@ static void location_update(struct location *loc, struct location *rhs, int n) %token MAPS "maps" %token HANDLE "handle" %token RULESET "ruleset" +%token TRACE "trace" %token INET "inet" %token NETDEV "netdev"
@@ -1196,6 +1197,7 @@ monitor_object : /* empty */ { $$ = CMD_MONITOR_OBJ_ANY; } | RULES { $$ = CMD_MONITOR_OBJ_RULES; } | ELEMENTS { $$ = CMD_MONITOR_OBJ_ELEMS; } | RULESET { $$ = CMD_MONITOR_OBJ_RULESET; } + | TRACE { $$ = CMD_MONITOR_OBJ_TRACE; } ; monitor_format : /* empty */ { $$ = NFTNL_OUTPUT_DEFAULT; }
src/scanner.l +1 -0
@@ -250,6 +250,7 @@ addrstring ({macaddr}|{ip4addr}|{ip6addr}) "maps" { return MAPS; } "handle" { return HANDLE; } "ruleset" { return RULESET; } +"trace" { return TRACE; } "accept" { return ACCEPT; } "drop" { return DROP; }
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 2/2 src: netlink: Subscribe nft monitor and nft monitor trace to respective groups.
From: Varsha Rao <[email protected]>
Subscribe nft monitor to both NFNLGRP_NFTABLES and NFNLGRP_NFTRACE. nft monitor trace subscribes only to NFNLGRP_NFTRACE. Other event reporting options to only NFNLGRP_NFTABLES.
Joint work with Pablo Neira.
Signed-off-by Varsha Rao <[email protected]>
Signed-off-by Pablo Neira Ayuso <[email protected]>
--- src/netlink.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-)
src/netlink.c +20 -16
@@ -3080,22 +3080,26 @@ int netlink_monitor(struct netlink_mon_handler *monhandler, {int group; - group =NFNLGRP_NFTABLES ; -if (mnl_socket_setsockopt (nf_sock,NETLINK_ADD_MEMBERSHIP , &group, -sizeof (int )) <0 ) -return netlink_io_error (monhandler->ctx, monhandler->loc, -"Could not bind to netlink socket %s" , -strerror (errno)); - - group =NFNLGRP_NFTRACE ; -if (mnl_socket_setsockopt (nf_sock,NETLINK_ADD_MEMBERSHIP , &group, -sizeof (int )) <0 ) -return netlink_io_error (monhandler->ctx, monhandler->loc, -"Could not bind to netlink socket %s" , -strerror (errno)); - -return mnl_nft_event_listener (nf_sock, netlink_events_cb, - monhandler); +if (monhandler->monitor_flags & (1 <<NFT_MSG_TRACE )) { + group =NFNLGRP_NFTRACE ; +if (mnl_socket_setsockopt (nf_sock,NETLINK_ADD_MEMBERSHIP , + &group,sizeof (int )) <0 ) +return netlink_io_error (monhandler->ctx, + monhandler->loc, +"Could not bind to netlink socket %s" , +strerror (errno)); + } +if (monhandler->monitor_flags & ~(1 <<NFT_MSG_TRACE )) { + group =NFNLGRP_NFTABLES ; +if (mnl_socket_setsockopt (nf_sock,NETLINK_ADD_MEMBERSHIP , + &group,sizeof (int )) <0 ) +return netlink_io_error (monhandler->ctx, + monhandler->loc, +"Could not bind to netlink socket %s" , +strerror (errno)); + } + +return mnl_nft_event_listener (nf_sock, netlink_events_cb, monhandler); }bool netlink_batch_supported (struct mnl_socket *nf_sock)
Signature · 1 line
2.1.4