Skip to content

Commit 69e429d

Browse files
authored
Merge pull request #77 from danielinux/wolfip-support
Add support for wolfIP
2 parents 642b400 + ebb674e commit 69e429d

File tree

12 files changed

+1452
-1
lines changed

12 files changed

+1452
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ wolfsentry/wolfsentry_options.h
2525

2626
/examples/notification-demo/log_server/log_server
2727
/examples/notification-demo/udp_to_dbus/udp_to_dbus
28+
/examples/Linux-wolfIP/wolfip-wolfsentry-demo
2829

2930
/scripts/analyzer-config.sh
3031

Makefile

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,23 @@ ifdef LWIP
129129
SRCS += lwip/packet_filter_glue.c
130130
endif
131131

132+
ifdef WOLFIP
133+
ifndef WOLFIP_TOP
134+
WOLFIP_TOP := $(SRC_TOP)/../wolfip
135+
endif
136+
ifndef WOLFIP_CONFIG_DIR
137+
WOLFIP_CONFIG_DIR := $(WOLFIP_TOP)
138+
endif
139+
ifndef WOLFIP_ENABLE_IPFILTER
140+
WOLFIP_ENABLE_IPFILTER := 1
141+
endif
142+
WOLFIP_CFLAGS += -DWOLFSENTRY_WOLFIP -I$(WOLFIP_CONFIG_DIR) -I$(WOLFIP_TOP)
143+
ifeq ($(WOLFIP_ENABLE_IPFILTER),1)
144+
WOLFIP_CFLAGS += -DCONFIG_IPFILTER=1
145+
endif
146+
SRCS += wolfip/packet_filter_glue.c
147+
endif
148+
132149
ifdef NETXDUO
133150
ifndef NETXDUO_TOP
134151
NETXDUO_TOP=$(THREADX_TOP)
@@ -166,7 +183,7 @@ ifndef C_WARNFLAGS
166183
endif
167184
endif
168185

169-
CFLAGS := -I$(BUILD_TOP) -I$(SRC_TOP) $(OPTIM) $(DEBUG) $(C_WARNFLAGS) $(LWIP_CFLAGS) $(RUNTIME_CFLAGS) $(EXTRA_CFLAGS)
186+
CFLAGS := -I$(BUILD_TOP) -I$(SRC_TOP) $(OPTIM) $(DEBUG) $(C_WARNFLAGS) $(LWIP_CFLAGS) $(WOLFIP_CFLAGS) $(RUNTIME_CFLAGS) $(EXTRA_CFLAGS)
170187
LDFLAGS := $(EXTRA_LDFLAGS)
171188

172189
VISIBILITY_CFLAGS := -fvisibility=hidden -DHAVE_VISIBILITY=1

examples/Linux-wolfIP/Makefile

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
CC ?= gcc
2+
AR ?= ar
3+
4+
WOLFSENTRY_PATH ?= ../../../wolfsentry
5+
WOLFSENTRY_LIB ?= $(WOLFSENTRY_PATH)/libwolfsentry.a
6+
WOLFIP_PATH ?= ../../../wolfip
7+
8+
CFLAGS ?= -O2 -g
9+
CFLAGS += -D_GNU_SOURCE
10+
CFLAGS += -DCONFIG_IPFILTER=1
11+
CFLAGS += -Wall -Wextra -Wpedantic -std=c99
12+
CFLAGS += -std=c99
13+
CFLAGS += -I.
14+
CFLAGS += -I./wolfip
15+
CFLAGS += -I../../../wolfsentry/wolfsentry
16+
CFLAGS += -I../../../wolfsentry
17+
CFLAGS += -I$(WOLFIP_PATH)
18+
CFLAGS += -I$(WOLFIP_PATH)/src
19+
CFLAGS += -I$(WOLFIP_PATH)/src/port/posix
20+
CFLAGS += -pthread
21+
22+
LDFLAGS ?= -pthread
23+
24+
TARGET := wolfip-wolfsentry-demo
25+
26+
APP_SRCS := main.c
27+
APP_OBJS := $(APP_SRCS:.c=.o)
28+
29+
TAP_SRC := $(WOLFIP_PATH)/src/port/posix/tap_linux.c
30+
TAP_OBJ := tap_linux.o
31+
32+
WOLFIP_SRC := $(WOLFIP_PATH)/src/wolfip.c
33+
WOLFIP_LIB := libwolfip.a
34+
WOLFIP_OBJ := wolfip.o
35+
36+
.PHONY: all clean
37+
38+
all: $(TARGET)
39+
40+
$(TARGET): $(APP_OBJS) $(TAP_OBJ) $(WOLFIP_LIB) $(WOLFSENTRY_LIB)
41+
$(CC) $(CFLAGS) $^ $(LDFLAGS) -o $@
42+
43+
$(APP_OBJS): %.o : %.c
44+
$(CC) $(CFLAGS) -c $< -o $@
45+
46+
$(TAP_OBJ): $(TAP_SRC) wolfip/config.h
47+
$(CC) $(CFLAGS) -c $< -o $@
48+
49+
$(WOLFIP_OBJ): $(WOLFIP_SRC) wolfip/config.h
50+
$(CC) $(CFLAGS) -c $< -o $@
51+
52+
$(WOLFIP_LIB): $(WOLFIP_OBJ)
53+
$(AR) rcs $@ $<
54+
55+
$(WOLFSENTRY_LIB):
56+
$(MAKE) -C $(WOLFSENTRY_PATH) libwolfsentry.a \
57+
WOLFIP=1 \
58+
WOLFIP_TOP=$(abspath $(WOLFIP_PATH)) \
59+
WOLFIP_CONFIG_DIR=$(abspath $(CURDIR)/wolfip)
60+
61+
clean:
62+
$(RM) $(APP_OBJS) $(TAP_OBJ) $(WOLFIP_OBJ) $(WOLFIP_LIB) $(TARGET)

examples/Linux-wolfIP/README.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Linux wolfIP + wolfSentry Demo
2+
3+
This example runs a single wolfIP instance on a TAP interface and forwards
4+
wolfIP packet-filter events into wolfSentry via the wolfIP glue layer. The
5+
installed wolfSentry actions log every inbound Ethernet frame and drop every
6+
seventh inbound ICMP echo request while logging the drop decision.
7+
8+
## Prerequisites
9+
10+
* Linux host with `/dev/net/tun` access (run the demo with `sudo`).
11+
* `libpcap` is **not** required.
12+
* Build `wolfsentry` with wolfIP support enabled so the packet-filter glue is
13+
present:
14+
15+
```sh
16+
cd ../../wolfsentry
17+
make WOLFIP=1 WOLFIP_CONFIG_DIR=examples/Linux-wolfIP/wolfip
18+
```
19+
20+
The example will then compile its own copy of wolfIP from `$(WOLFIP_PATH)`
21+
using the local configuration in `wolfip/config.h`, so you do not need to
22+
build wolfIP separately. Edit that file if you need different Ethernet/TAP
23+
settings, such as the wolfIP and host IP addresses or the TAP interface name.
24+
25+
## Build the demo
26+
27+
```sh
28+
cd wolfsentry/examples/Linux-wolfIP
29+
make # override WOLFIP_PATH=/path/to/wolfip if needed
30+
```
31+
32+
The Makefile first builds a local `libwolfip.a` from
33+
`$(WOLFIP_PATH)/src/wolfip.c`, picking up the Ethernet/TAP configuration in
34+
`wolfip/config.h`, and then links the demo against that static library plus
35+
`../../../wolfsentry/libwolfsentry.a`. Override `WOLFIP_PATH` if your source
36+
tree lives elsewhere. If `libwolfsentry.a` is missing or older than the
37+
example sources, the Makefile automatically runs
38+
`make WOLFIP=1 WOLFIP_CONFIG_DIR=examples/Linux-wolfIP/wolfip` inside
39+
`../../wolfsentry` so the packet-filter glue is rebuilt with the local config.
40+
41+
## Run the demo
42+
43+
```sh
44+
sudo ./wolfip-wolfsentry-demo
45+
```
46+
47+
The program:
48+
49+
1. Initializes wolfSentry, registers two actions (`log-event` and
50+
`icmp-mod7`), and loads `wolfip-config.json`.
51+
2. Installs wolfSentry as the wolfIP packet filter for Ethernet, IPv4 and
52+
ICMP events.
53+
3. Brings up wolfIP on a TAP interface (default host IP `10.10.10.1`,
54+
wolfIP address `10.10.10.2`) and enters the polling loop.
55+
56+
While it runs you can exercise it from the host by pinging
57+
`10.10.10.2`. The demo now starts a background
58+
`ping -I wolfip0 -c 100 10.10.10.2` process automatically so you immediately
59+
get traffic; it stops after 100 packets, and you can launch your own ping if
60+
you prefer. ICMP echo requests are accepted except when the running counter is
61+
a multiple of 7 – only those discarded packets are logged.
62+
63+
The demo links in wolfIP's POSIX TAP driver (`tap_linux.c`), so the call to
64+
`tap_init()` inside the sample automatically creates, configures, and brings up
65+
the TAP interface on the host (default name `wolfip0`). No manual `ip`
66+
commands are required beyond running the binary with sufficient privileges.
67+
68+
Stop the demo with `Ctrl+C`.
69+
70+
## Cleaning up
71+
72+
```sh
73+
make clean
74+
```
75+
76+
This removes the local binary and object files; it does not touch the
77+
wolfIP/wolfSentry build outputs.

0 commit comments

Comments
 (0)