Skip to content

Commit 2fa8827

Browse files
committed
Updates to wolfSentry for supporting NetX Duo.
1 parent 3739734 commit 2fa8827

File tree

10 files changed

+1192
-33
lines changed

10 files changed

+1192
-33
lines changed

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ ifdef NETXDUO
136136
LWIP_CFLAGS += -DWOLFSENTRY_NETXDUO -I$(NETXDUO_TOP) -D_NETINET_IN_H -DWOLFSENTRY_NO_GETPROTOBY
137137
endif
138138

139-
CC_V := $(shell $(CC) -v 2>&1 | sed "s/'/'\\\\''/g; s/\`/'\\\\''/g;")
139+
CC_V := $(shell $(CC) -v 2>&1 | sed "s/[\`']/'\\\\''/g")
140140

141141
CC_IS_GCC := $(shell if [[ '$(CC_V)' =~ 'gcc version' ]]; then echo 1; else echo 0; fi)
142142

@@ -152,9 +152,9 @@ ifndef CLANG
152152
CLANG := clang
153153
endif
154154

155-
AS_VERSION := $(shell $(AS) --version 2>&1 | sed "s/'/'\\\\''/g; s/\`/'\\\\''/g;")
156-
LD_VERSION := $(shell $(LD) --version 2>&1 | sed "s/'/'\\\\''/g; s/\`/'\\\\''/g;")
157-
AR_VERSION := $(shell $(AR) --version 2>&1 | sed "s/'/'\\\\''/g; s/\`/'\\\\''/g;")
155+
AS_VERSION := $(shell $(AS) --version 2>&1 | sed "s/[\`']/'\\\\''/g")
156+
LD_VERSION := $(shell $(LD) --version 2>&1 | sed "s/[\`']/'\\\\''/g")
157+
AR_VERSION := $(shell $(AR) --version 2>&1 | sed "s/[\`']/'\\\\''/g")
158158

159159
AR_IS_GNU_AR := $(shell if [[ '$(AR_VERSION)' =~ 'GNU' ]]; then echo 1; else echo 0; fi)
160160

build.bat

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/json/load_config.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@
3434
#ifdef WOLFSENTRY_LWIP
3535
#include "lwip/sockets.h"
3636
#elif defined(WOLFSENTRY_NETXDUO)
37-
#include "nxd_bsd.h"
38-
/* undef OK this conflicts with the _OK macros in wolfsentry_errcodes.h */
39-
#undef OK
37+
#include "wolfsentry/wolfsentry_netxduo.h"
4038
#else
4139
#include <arpa/inet.h>
4240
#include <sys/socket.h>

src/netxduo/README.md

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# WolfSentry NetX Duo Integration
2+
3+
This directory contains the NetX Duo integration layer for WolfSentry, providing packet filtering and security policy enforcement for embedded systems using the NetX Duo TCP/IP stack.
4+
5+
## Overview
6+
7+
The NetX Duo integration enables WolfSentry to intercept and evaluate network packets at the IP layer, allowing for real-time security policy enforcement. This implementation provides:
8+
9+
- **Packet Filtering**: Intercepts all IP packets (TCP, UDP, ICMP) for security evaluation
10+
- **Address Conversion**: Implements `inet_ntop` and `inet_pton` functions compatible with NetX Duo
11+
- **Protocol Support**: Supports IPv4 addresses with extensible architecture for IPv6
12+
- **Fail-Open Policy**: Accepts packets by default if WolfSentry is not initialized or encounters errors
13+
14+
## Files
15+
16+
- `packet_filter_glue.c` - Main implementation file containing packet filtering logic and address conversion functions
17+
18+
## NetX Duo IP Callback Mechanism
19+
20+
### Overview
21+
22+
The integration uses NetX Duo's raw packet filtering mechanism to intercept all IP packets before they are processed by the TCP/IP stack. This allows WolfSentry to evaluate each packet against configured security policies.
23+
24+
### Callback Function
25+
26+
The main callback function is `wolfsentry_netx_packet_filter()`, which is registered with NetX Duo using `nx_ip_raw_packet_filter_set()`. This function:
27+
28+
1. **Parses IP Headers**: Extracts source/destination addresses, ports, and protocol information
29+
2. **Builds WolfSentry Structures**: Converts NetX packet data to WolfSentry sockaddr structures
30+
3. **Evaluates Security Policy**: Calls WolfSentry's route event dispatch to check against configured rules
31+
4. **Returns Decision**: Accepts or rejects the packet based on WolfSentry's evaluation
32+
33+
### Packet Processing Flow
34+
35+
```
36+
NetX Duo IP Stack
37+
38+
Raw Packet Filter Callback
39+
40+
Parse IP/TCP/UDP Headers
41+
42+
Build WolfSentry sockaddr
43+
44+
Call WolfSentry Route Event Dispatch
45+
46+
Return Accept/Reject Decision
47+
48+
NetX Duo Continues/Blocks Packet
49+
```
50+
51+
### Installation
52+
53+
To install the packet filter callbacks:
54+
55+
```c
56+
#include <wolfsentry/wolfsentry_netxduo.h>
57+
58+
// Initialize WolfSentry context
59+
struct wolfsentry_context *ctx = /* your wolfSentry context */;
60+
61+
// Set the context for NetX Duo integration
62+
wolfsentry_set_netx_context(ctx);
63+
64+
// Install the packet filter callbacks
65+
int result = wolfsentry_install_netx_filter_callbacks(ip_ptr);
66+
if (result != 0) {
67+
// Handle installation error
68+
}
69+
```
70+
71+
## Address Conversion Functions
72+
73+
The implementation provides custom `inet_ntop` and `inet_pton` functions that are compatible with NetX Duo's data structures:
74+
75+
### wolfsentry_inet_ntop()
76+
77+
Converts binary network addresses to string representation:
78+
79+
```c
80+
const char *wolfsentry_inet_ntop(int af, const void *src, char *dst, size_t size);
81+
```
82+
83+
- Supports IPv4 (AF_INET) addresses
84+
- Handles IPv4-mapped IPv6 addresses
85+
- Returns NULL on error, pointer to dst on success
86+
87+
### wolfsentry_inet_pton()
88+
89+
Converts string network addresses to binary format:
90+
91+
```c
92+
int wolfsentry_inet_pton(int af, const char* src, void* dst);
93+
```
94+
95+
- Supports IPv4 (AF_INET) addresses
96+
- Handles IPv4-mapped IPv6 addresses (::ffff:w.x.y.z format)
97+
- Returns 1 on success, 0 on invalid format, -1 on error
98+
99+
## Security Features
100+
101+
### Default Policy
102+
103+
The implementation follows a **fail-open** security policy:
104+
- If WolfSentry is not initialized, all packets are accepted
105+
- If packet parsing fails, packets are accepted by default
106+
- If WolfSentry evaluation fails, packets are accepted
107+
108+
### Action Results
109+
110+
WolfSentry can return the following actions:
111+
- `WOLFSENTRY_ACTION_RES_ACCEPT`: Packet is allowed through
112+
- `WOLFSENTRY_ACTION_RES_REJECT`: Packet is blocked
113+
- `WOLFSENTRY_ACTION_RES_NONE`: No explicit action (defaults to accept)

0 commit comments

Comments
 (0)