Skip to content

Commit 7c15b0f

Browse files
authored
Merge pull request #16 from douzzer/20220513-default_event-fallthrough_route
20220513-default_event-fallthrough_route
2 parents ae228d7 + 868751e commit 7c15b0f

29 files changed

+3833
-466
lines changed

ChangeLog.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,34 @@
1+
# wolfSentry Release 0.4.0 (May 27, 2022)
2+
3+
Preview Release 0.4.0 of the wolfSentry embedded firewall/IDPS has bug fixes and new features including:
4+
5+
## New Features
6+
7+
* User-defined key-value pairs in JSON configuration: allows user plugins to access custom config parameters in the wolfSentry config using the new wolfsentry_user_value_*() family of API functions. Binary configuration data can be supplied in the configuration using base64 encoding, and are decoded at parse time and directly available to user plugins in the original raw binary form. The key-value facility also supports a custom validator callback to enforce constraints on user-defined config params in the JSON.
8+
9+
* User-defined address families: allows user plugins for custom address families and formats, using new wolfsentry_addr_family_*() API routines. This allows idiomatic formats for non-Internet addresses in the JSON config, useful for various buses and device namespaces.
10+
11+
* Formalization of the concepts of default events and fallthrough rules in the route tables.
12+
13+
* A new subevent action list facility to support logging and notifications around the final decisions of the rule engine, alongside the existing subevents for rule insertions, matches, and deletions.
14+
15+
* The main plugin interface (wolfsentry_action_callback_t) now passes two separate routes, a "trigger_route" with full attributes of the instant traffic, and a "rule_route" that matches that traffic. In dynamic rule scenarios, plugins can manipulate the passed rule_route and set the WOLFSENTRY_ACTION_RES_INSERT bit in the to define a new rule that will match the traffic thereafter. All actions in the chain retain readonly access to the unmodified trigger route for informational purposes.
16+
17+
* The JSON DOM facility from CentiJSON is now included in the library by default (disabled by make NO_JSON_DOM=1), layered on the SAX facility used directly by the wolfSentry core to process the JSON config package. The DOM facility can be used as a helper in user plugins and applications, for convenient JSON parsing, random access, and production.
18+
19+
20+
## Noteworthy Changes
21+
22+
* In the JSON config, non-event-specific members of top level node "config-update" node have been moved to the new top level node "default-policies", which must appear after "event-insert". "default-policies" members are "default-policy-static", "default-policy-dynamic", "default-event-static", and "default-event-dynamic".
23+
24+
25+
## Bug Fixes
26+
27+
* In wolfsentry_config_json_init(), properly copy the load_flags from the caller into the _json_process_state.
28+
29+
* The JSON SAX API routines (wolfsentry/centijson_sax.h) are now properly exported.
30+
31+
132
# wolfSentry Release 0.3.0 (Dec 30, 2021)
233

334
Preview Release 0.3.0 of the wolfSentry embedded firewall/IDPS has bug fixes and new features including:

Makefile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ VISIBILITY_CFLAGS := -fvisibility=hidden -DHAVE_VISIBILITY=1
8484
DYNAMIC_CFLAGS := -fpic
8585
DYNAMIC_LDFLAGS := -shared
8686

87-
$(BUILD_TOP)/src/json/centijson_sax.o: CFLAGS+=-DWOLFSENTRY -Wno-conversion -Wno-sign-conversion -Wno-sign-compare
88-
$(BUILD_TOP)/src/json/centijson_sax.So: CFLAGS+=-DWOLFSENTRY -Wno-conversion -Wno-sign-conversion -Wno-sign-compare
87+
$(BUILD_TOP)/src/json/centijson_%.o: CFLAGS+=-DWOLFSENTRY -Wno-conversion -Wno-sign-conversion -Wno-sign-compare
88+
$(BUILD_TOP)/src/json/centijson_%.So: CFLAGS+=-DWOLFSENTRY -Wno-conversion -Wno-sign-conversion -Wno-sign-compare
8989

9090
ifeq "$(NO_STDIO)" "1"
9191
CFLAGS += -DWOLFSENTRY_NO_STDIO
@@ -96,6 +96,10 @@ ifeq "$(NO_JSON)" "1"
9696
CFLAGS += -DWOLFSENTRY_NO_JSON
9797
else
9898
SRCS += json/centijson_sax.c json/load_config.c
99+
ifneq "$(NO_JSON_DOM)" "1"
100+
CFLAGS += -DWOLFSENTRY_HAVE_JSON_DOM
101+
SRCS += json/centijson_dom.c json/centijson_value.c
102+
endif
99103
endif
100104

101105
ifdef USER_SETTINGS_FILE
@@ -124,7 +128,7 @@ LIB_NAME := libwolfsentry.a
124128

125129
INSTALL_LIBS := $(BUILD_TOP)/$(LIB_NAME)
126130

127-
INSTALL_HEADERS := wolfsentry/wolfsentry.h wolfsentry/wolfsentry_errcodes.h wolfsentry/wolfsentry_af.h wolfsentry/wolfsentry_util.h wolfsentry/wolfsentry_json.h wolfsentry/centijson_sax.h $(BUILD_TOP)/wolfsentry_options.h
131+
INSTALL_HEADERS := wolfsentry/wolfsentry.h wolfsentry/wolfsentry_errcodes.h wolfsentry/wolfsentry_af.h wolfsentry/wolfsentry_util.h wolfsentry/wolfsentry_json.h wolfsentry/centijson_sax.h wolfsentry/centijson_dom.h wolfsentry/centijson_value.h $(BUILD_TOP)/wolfsentry_options.h
128132

129133
all: $(BUILD_TOP)/$(LIB_NAME)
130134

Makefile.analyzers

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,13 @@ no-json-test:
194194
@$(MAKE) $(EXTRA_MAKE_FLAGS) $(QUIET_FLAG) -f $(THIS_MAKEFILE) VERY_QUIET=1 BUILD_TOP=NO_JSON-builds clean
195195
@echo "NO_JSON test passed."
196196

197+
.PHONY: no-json-dom-test
198+
no-json-dom-test:
199+
@$(MAKE) $(EXTRA_MAKE_FLAGS) $(QUIET_FLAG) -f $(THIS_MAKEFILE) VERY_QUIET=1 BUILD_TOP=NO_JSON_DOM-builds clean
200+
@$(MAKE) $(EXTRA_MAKE_FLAGS) $(QUIET_FLAG) -f $(THIS_MAKEFILE) VERY_QUIET=1 BUILD_TOP=NO_JSON_DOM-builds NO_JSON_DOM=1 test
201+
@$(MAKE) $(EXTRA_MAKE_FLAGS) $(QUIET_FLAG) -f $(THIS_MAKEFILE) VERY_QUIET=1 BUILD_TOP=NO_JSON_DOM-builds clean
202+
@echo "NO_JSON_DOM test passed."
203+
197204
.PHONY: no-error-strings-test
198205
no-error-strings-test:
199206
@$(MAKE) $(EXTRA_MAKE_FLAGS) $(QUIET_FLAG) -f $(THIS_MAKEFILE) VERY_QUIET=1 BUILD_TOP=no-error-strings-builds clean
@@ -238,7 +245,7 @@ dist-check:
238245
@echo $@ 'passed.'
239246

240247
.PHONY: check
241-
check: analyze-all dynamic-build-test c99-test m32-test singlethreaded-test no-json-test no-error-strings-test no-protocol-names-test no-stdio-test minimal-build-test dist-check
248+
check: analyze-all dynamic-build-test c99-test m32-test singlethreaded-test no-json-test no-json-dom-test no-error-strings-test no-protocol-names-test no-stdio-test minimal-build-test dist-check
242249
@echo "all checks passed."
243250

244251
# recipe to run the pre-push hook on the commit head, without actually pushing:

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
## Description
44

5-
wolfSentry is the wolfSSL IDPS (Intrusion Detection and Prevention System). It
6-
is mainly used as a library, but can also be used as part of a kernel module.
5+
wolfSentry is the wolfSSL IDPS (Intrusion Detection and Prevention System). It is mainly used as a library, but can also be used as part of a kernel module.
76

87
At a high level, wolfSentry is a dynamically configurable logic hub, arbitrarily associating user-defined events with user-defined actions, contextualized by connection attributes, tracking the evolution of the client-server relationship. At a low level, wolfSentry is an embedded firewall engine (both static and fully dynamic), with O(log n) lookup of known hosts/netblocks.
98

@@ -57,8 +56,9 @@ Build and test libwolfsentry.a without support for multithreading:
5756

5857
`make -j SINGLETHREADED=1 test`
5958

60-
Other available make flags are `STATIC=1` and `STRIPPED=1`, and the defaults values
61-
for `DEBUG`, `OPTIM`, and `C_WARNFLAGS` can also be usefully overridden.
59+
Other available make flags are `STATIC=1`, `STRIPPED=1`, `NO_JSON=1`, and
60+
`NO_JSON_DOM=1`, and the defaults values for `DEBUG`, `OPTIM`, and `C_WARNFLAGS`
61+
can also be usefully overridden.
6262

6363
Build with a user-supplied makefile preamble to override defaults:
6464

examples/Linux-LWIP/echo-config.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
"wolfsentry-config-version" : 1,
33
"config-update" : {
44
"max-connection-count" : 5,
5-
"penalty-box-duration" : "1h",
6-
"default-policy-static" : "reject"
5+
"penalty-box-duration" : "1h"
76
},
87
"events-insert" : [
98
{
@@ -34,6 +33,10 @@
3433
"label" : "call-in-from-echo"
3534
}
3635
],
36+
"default-policies" : {
37+
"default-policy-static" : "reject",
38+
"default-event-static" : "static-route-parent"
39+
},
3740
"static-routes-insert" : [
3841
{
3942
"parent-event" : "static-route-parent",

examples/Linux-LWIP/sentry.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ static wolfsentry_errcode_t test_action(
2020
void *caller_arg,
2121
const struct wolfsentry_event *trigger_event,
2222
wolfsentry_action_type_t action_type,
23+
const struct wolfsentry_route *target_route,
2324
struct wolfsentry_route_table *route_table,
24-
const struct wolfsentry_route *route,
25+
const struct wolfsentry_route *rule_route,
2526
wolfsentry_action_res_t *action_results)
2627
{
27-
const struct wolfsentry_event *parent_event = wolfsentry_route_parent_event(route);
28+
const struct wolfsentry_event *parent_event = wolfsentry_route_parent_event(rule_route);
2829
(void)wolfsentry;
2930
(void)handler_arg;
3031
(void)route_table;

examples/STM32-LWIP-WOLFSSL/Src/sentry.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ static const char *wolfsentry_config_data = "{\n"
1414
" \"wolfsentry-config-version\" : 1,\n"
1515
" \"config-update\" : {\n"
1616
" \"max-connection-count\" : 0,\n"
17-
" \"penalty-box-duration\" : \"1h\",\n"
18-
" \"default-policy-static\" : \"reject\"\n"
17+
" \"penalty-box-duration\" : \"1h\"\n"
1918
" },\n"
2019
" \"events-insert\" : [\n"
2120
" {\n"
@@ -46,6 +45,10 @@ static const char *wolfsentry_config_data = "{\n"
4645
" \"label\" : \"call-in-from-echo\"\n"
4746
" }\n"
4847
" ],\n"
48+
" \"default-policies\" : {\n"
49+
" \"default-policy-static\" : \"reject\",\n"
50+
" \"default-event-static\" : \"static-route-parent\"\n"
51+
" },\n"
4952
" \"static-routes-insert\" : [\n"
5053
"{\n"
5154
" \"parent-event\" : \"static-route-parent\",\n"
@@ -107,11 +110,12 @@ static wolfsentry_errcode_t test_action(
107110
void *caller_arg,
108111
const struct wolfsentry_event *trigger_event,
109112
wolfsentry_action_type_t action_type,
113+
const struct wolfsentry_route *target_route,
110114
struct wolfsentry_route_table *route_table,
111-
const struct wolfsentry_route *route,
115+
const struct wolfsentry_route *rule_route,
112116
wolfsentry_action_res_t *action_results)
113117
{
114-
const struct wolfsentry_event *parent_event = wolfsentry_route_parent_event(route);
118+
const struct wolfsentry_event *parent_event = wolfsentry_route_parent_event(rule_route);
115119
(void)wolfsentry;
116120
(void)handler_arg;
117121
(void)route_table;

examples/STM32-LWIP/Src/sentry.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ static const char *wolfsentry_config_data = "{\n"
1414
" \"wolfsentry-config-version\" : 1,\n"
1515
" \"config-update\" : {\n"
1616
" \"max-connection-count\" : 5,\n"
17-
" \"penalty-box-duration\" : \"1h\",\n"
18-
" \"default-policy-static\" : \"reject\"\n"
17+
" \"penalty-box-duration\" : \"1h\"\n"
1918
" },\n"
2019
" \"events-insert\" : [\n"
2120
" {\n"
@@ -46,6 +45,10 @@ static const char *wolfsentry_config_data = "{\n"
4645
" \"label\" : \"call-in-from-echo\"\n"
4746
" }\n"
4847
" ],\n"
48+
" \"default-policies\" : {\n"
49+
" \"default-policy-static\" : \"reject\",\n"
50+
" \"default-event-static\" : \"static-route-parent\"\n"
51+
" },\n"
4952
" \"static-routes-insert\" : [\n"
5053
"{\n"
5154
" \"parent-event\" : \"static-route-parent\",\n"
@@ -107,11 +110,12 @@ static wolfsentry_errcode_t test_action(
107110
void *caller_arg,
108111
const struct wolfsentry_event *trigger_event,
109112
wolfsentry_action_type_t action_type,
113+
const struct wolfsentry_route *target_route,
110114
struct wolfsentry_route_table *route_table,
111-
const struct wolfsentry_route *route,
115+
const struct wolfsentry_route *rule_route,
112116
wolfsentry_action_res_t *action_results)
113117
{
114-
const struct wolfsentry_event *parent_event = wolfsentry_route_parent_event(route);
118+
const struct wolfsentry_event *parent_event = wolfsentry_route_parent_event(rule_route);
115119
(void)wolfsentry;
116120
(void)handler_arg;
117121
(void)route_table;

src/actions.c

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,14 @@ wolfsentry_errcode_t wolfsentry_action_insert(struct wolfsentry_context *wolfsen
121121

122122
if ((ret = wolfsentry_action_new_1(wolfsentry, label, label_len, flags, handler, handler_arg, &new)) < 0)
123123
return ret;
124-
if ((ret = wolfsentry_id_generate(wolfsentry, WOLFSENTRY_OBJECT_TYPE_ACTION, &new->header.id)) < 0) {
124+
if ((ret = wolfsentry_id_allocate(wolfsentry, &new->header)) < 0) {
125125
WOLFSENTRY_FREE(new); // GCOV_EXCL_LINE
126126
return ret; // GCOV_EXCL_LINE
127127
}
128128
if (id)
129129
*id = new->header.id;
130130
if ((ret = wolfsentry_table_ent_insert(wolfsentry, &new->header, &wolfsentry->actions->header, 1 /* unique_p */)) < 0) {
131+
wolfsentry_table_ent_delete_by_id_1(wolfsentry, &new->header);
131132
WOLFSENTRY_FREE(new);
132133
WOLFSENTRY_ERROR_RERETURN(ret);
133134
}
@@ -449,37 +450,41 @@ wolfsentry_errcode_t wolfsentry_action_list_dispatch(
449450
struct wolfsentry_event *action_event,
450451
struct wolfsentry_event *trigger_event,
451452
wolfsentry_action_type_t action_type,
453+
const struct wolfsentry_route *target_route,
452454
struct wolfsentry_route_table *route_table,
453-
struct wolfsentry_route *route,
455+
struct wolfsentry_route *rule_route,
454456
wolfsentry_action_res_t *action_results)
455457
{
456458
wolfsentry_errcode_t ret;
457459
struct wolfsentry_action_list_ent *i;
458460

461+
if (action_results == NULL)
462+
WOLFSENTRY_ERROR_RETURN(INVALID_ARG);
463+
459464
if (*action_results & WOLFSENTRY_ACTION_RES_STOP)
460465
WOLFSENTRY_ERROR_RETURN(ALREADY_STOPPED);
461466

462467
if (action_type == WOLFSENTRY_ACTION_TYPE_INSERT) {
463-
if (WOLFSENTRY_CHECK_BITS(route->flags, WOLFSENTRY_ROUTE_FLAG_INSERT_ACTIONS_CALLED))
468+
if (WOLFSENTRY_CHECK_BITS(rule_route->flags, WOLFSENTRY_ROUTE_FLAG_INSERT_ACTIONS_CALLED))
464469
WOLFSENTRY_ERROR_RETURN(ALREADY);
465470
else {
466471
wolfsentry_route_flags_t flags_before;
467472
wolfsentry_route_flags_t flags_after;
468473
WOLFSENTRY_ATOMIC_UPDATE(
469-
route->flags,
474+
rule_route->flags,
470475
(wolfsentry_route_flags_t)WOLFSENTRY_ROUTE_FLAG_INSERT_ACTIONS_CALLED,
471476
(wolfsentry_route_flags_t)WOLFSENTRY_ROUTE_FLAG_NONE,
472477
&flags_before,
473478
&flags_after);
474479
}
475480
} else if (action_type == WOLFSENTRY_ACTION_TYPE_DELETE) {
476-
if (WOLFSENTRY_CHECK_BITS(route->flags, WOLFSENTRY_ROUTE_FLAG_DELETE_ACTIONS_CALLED))
481+
if (WOLFSENTRY_CHECK_BITS(rule_route->flags, WOLFSENTRY_ROUTE_FLAG_DELETE_ACTIONS_CALLED))
477482
WOLFSENTRY_ERROR_RETURN(ALREADY);
478483
else {
479484
wolfsentry_route_flags_t flags_before;
480485
wolfsentry_route_flags_t flags_after;
481486
WOLFSENTRY_ATOMIC_UPDATE(
482-
route->flags,
487+
rule_route->flags,
483488
(wolfsentry_route_flags_t)WOLFSENTRY_ROUTE_FLAG_DELETE_ACTIONS_CALLED,
484489
(wolfsentry_route_flags_t)WOLFSENTRY_ROUTE_FLAG_NONE,
485490
&flags_before,
@@ -494,11 +499,11 @@ wolfsentry_errcode_t wolfsentry_action_list_dispatch(
494499
for (i = (struct wolfsentry_action_list_ent *)action_event->action_list.header.head;
495500
i;
496501
i = (struct wolfsentry_action_list_ent *)i->header.next) {
497-
if (! (route->flags & WOLFSENTRY_ROUTE_FLAG_DONT_COUNT_HITS))
502+
if (! (rule_route->flags & WOLFSENTRY_ROUTE_FLAG_DONT_COUNT_HITS))
498503
WOLFSENTRY_ATOMIC_INCREMENT(i->action->header.hitcount, 1);
499504
if (WOLFSENTRY_CHECK_BITS(i->action->flags, WOLFSENTRY_ACTION_FLAG_DISABLED))
500505
continue;
501-
if ((ret = i->action->handler(wolfsentry, i->action, i->action->handler_arg, caller_arg, trigger_event, action_type, route_table, route, action_results)) < 0)
506+
if ((ret = i->action->handler(wolfsentry, i->action, i->action->handler_arg, caller_arg, trigger_event, action_type, target_route, route_table, rule_route, action_results)) < 0)
502507
return ret;
503508
if (WOLFSENTRY_CHECK_BITS(*action_results, WOLFSENTRY_ACTION_RES_STOP))
504509
WOLFSENTRY_RETURN_OK;
@@ -515,3 +520,18 @@ wolfsentry_errcode_t wolfsentry_action_table_init(
515520
action_table->header.ent_type = WOLFSENTRY_OBJECT_TYPE_ACTION;
516521
WOLFSENTRY_RETURN_OK;
517522
}
523+
524+
wolfsentry_errcode_t wolfsentry_action_table_clone_header(
525+
struct wolfsentry_context *wolfsentry,
526+
struct wolfsentry_table_header *src_table,
527+
struct wolfsentry_context *dest_context,
528+
struct wolfsentry_table_header *dest_table,
529+
wolfsentry_clone_flags_t flags)
530+
{
531+
(void)wolfsentry;
532+
(void)src_table;
533+
(void)dest_context;
534+
(void)dest_table;
535+
(void)flags;
536+
WOLFSENTRY_RETURN_OK;
537+
}

0 commit comments

Comments
 (0)