|
| 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