Skip to content

Commit c6a09c9

Browse files
committed
Initial import for internal reviews
0 parents  commit c6a09c9

36 files changed

+10394
-0
lines changed

.github/workflows/linux.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
Name: Linux interop tests
2+
3+
4+
on:
5+
push:
6+
branches: [ 'master', 'main', 'release/**' ]
7+
pull_request:
8+
branches: [ '*' ]
9+
10+
jobs:
11+
unit_test:
12+
runs-on: ubuntu-22.04
13+
14+
steps:
15+
- uses: actions/checkout@v2
16+
with:
17+
submodules: true
18+
19+
- name: Update repo
20+
run: |
21+
sudo apt-get update
22+
sudo modprobe tun
23+
24+
- name: Build linux tests
25+
run: |
26+
mkdir -p build/port
27+
make
28+
29+
# - name: Run interop tests
30+
# run: |
31+
# sudo build/test
32+
#
33+
#

.github/workflows/units.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
Name: Unit Tests
2+
3+
4+
on:
5+
push:
6+
branches: [ 'master', 'main', 'release/**' ]
7+
pull_request:
8+
branches: [ '*' ]
9+
10+
jobs:
11+
unit_test:
12+
runs-on: ubuntu-22.04
13+
14+
steps:
15+
- uses: actions/checkout@v2
16+
with:
17+
submodules: true
18+
19+
- name: Update repo
20+
run: |
21+
sudo apt-get update
22+
23+
- name: Install check
24+
run: |
25+
sudo apt-get -y install check
26+
27+
- name: Build unit tests
28+
run: |
29+
make unit
30+
31+
- name: Run unit tests
32+
run: |
33+
build/test/unit

.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
*.o
2+
*.a
3+
*.pcap
4+
*.so
5+
*.dis
6+
*.uf2
7+
*.bin
8+
CMakeCache.txt
9+
CMakeFiles
10+
CMakeScripts
11+
CMakeTmp
12+
build/*
13+
test/unit/unit
14+
tags

LICENSE

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

Makefile

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
CC?=gcc
2+
CFLAGS:=-Wall -Werror -Wextra -I.
3+
CFLAGS+=-g -ggdb
4+
LDFLAGS+=-pthread
5+
6+
OBJ=build/wolftcp.o \
7+
build/port/posix/linux_tap.o
8+
9+
EXE=build/tcpecho build/tcp_netcat_poll build/tcp_netcat_select \
10+
build/test-evloop build/test-dns
11+
LIB=libwolftcp.so
12+
13+
PREFIX=/usr/local
14+
15+
16+
all: $(EXE) $(LIB)
17+
18+
#Static library
19+
static: CFLAGS+=-static
20+
static: libtcpip.a
21+
22+
23+
24+
libtcpip.a: $(OBJ)
25+
@ar rcs $@ $^
26+
27+
libwolftcp.so:CFLAGS+=-fPIC
28+
libwolftcp.so: build/pie/port/posix/bsd_socket.o build/pie/wolftcp.o \
29+
build/pie/port/posix/linux_tap.o
30+
@mkdir -p `dirname $@` || true
31+
@echo "[LD] $@"
32+
@$(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ -Wl,--start-group $(^) -Wl,--end-group
33+
34+
35+
clean:
36+
@rm -rf build
37+
@rm -f *.so
38+
39+
asan: $(EXE) $(LIB)
40+
asan:CFLAGS+=-fsanitize=address
41+
asan:LDFLAGS+=-static-libasan
42+
43+
44+
# Test
45+
46+
unit:LDFLAGS+=-lcheck -lm -lpthread -lrt -ldl -lsubunit
47+
build/test-evloop: $(OBJ) build/test/test_linux_eventloop.o
48+
@echo "[LD] $@"
49+
@$(CC) $(CFLAGS) $(LDFLAGS) -o $@ -Wl,--start-group $(^) -Wl,--end-group
50+
51+
build/test-dns: $(OBJ) build/test/test_linux_dhcp_dns.o
52+
@echo "[LD] $@"
53+
@$(CC) $(CFLAGS) $(LDFLAGS) -o $@ -Wl,--start-group $(^) -Wl,--end-group
54+
55+
build/tcpecho: $(OBJ) build/port/posix/bsd_socket.o build/test/tcp_echo.o
56+
@echo "[LD] $@"
57+
@$(CC) $(CFLAGS) $(LDFLAGS) -o $@ -Wl,--start-group $(^) -Wl,--end-group
58+
59+
build/tcp_netcat_poll: $(OBJ) build/port/posix/bsd_socket.o build/test/tcp_netcat_poll.o
60+
@echo "[LD] $@"
61+
@$(CC) $(CFLAGS) $(LDFLAGS) -o $@ -Wl,--start-group $(^) -Wl,--end-group
62+
63+
build/tcp_netcat_select: $(OBJ) build/port/posix/bsd_socket.o build/test/tcp_netcat_select.o
64+
@echo "[LD] $@"
65+
@$(CC) $(CFLAGS) $(LDFLAGS) -o $@ -Wl,--start-group $(^) -Wl,--end-group
66+
67+
68+
build/test-wolfssl:CFLAGS+=-Wno-cpp -DWOLFSSL_DEBUG -DWOLFSSL_WOLFTCP
69+
build/test-httpd:CFLAGS+=-Wno-cpp -DWOLFSSL_DEBUG -DWOLFSSL_WOLFTCP -Isrc/http
70+
71+
72+
build/test-wolfssl: $(OBJ) build/test/test_native_wolfssl.o build/port/wolfssl_io.o build/certs/server_key.o build/certs/ca_cert.o build/certs/server_cert.o
73+
@echo "[LD] $@"
74+
@$(CC) $(CFLAGS) $(LDFLAGS) -o $@ -Wl,--start-group $(^) -lwolfssl -Wl,--end-group
75+
76+
build/test-httpd: $(OBJ) build/test/test_httpd.o build/port/wolfssl_io.o build/certs/server_key.o build/certs/server_cert.o build/http/httpd.o
77+
@echo "[LD] $@"
78+
@$(CC) $(CFLAGS) $(LDFLAGS) -o $@ -Wl,--start-group $(^) -lwolfssl -Wl,--end-group
79+
80+
build/%.o: src/%.c
81+
@mkdir -p `dirname $@` || true
82+
@echo "[CC] $<"
83+
@$(CC) $(CFLAGS) -c $< -o $@
84+
85+
build/pie/%.o: src/%.c
86+
@mkdir -p `dirname $@` || true
87+
@echo "[CC] $<"
88+
@$(CC) $(CFLAGS) -c $< -o $@
89+
90+
build/certs/%.o: build/certs/%.c
91+
@mkdir -p `dirname $@` || true
92+
@echo "[CC] $<"
93+
@$(CC) $(CFLAGS) -c $< -o $@
94+
95+
build/http/%.o: build/http/%.c
96+
@mkdir -p `dirname $@` || true
97+
@echo "[CC] $<"
98+
@$(CC) $(CFLAGS) -c $< -o $@
99+
100+
build/certs/ca_cert.c:
101+
@echo "[MKCERTS] `dirname $@`"
102+
@tools/certs/mkcerts.sh
103+
104+
build/certs/server_key.c:
105+
@echo "[MKCERTS] `dirname $@`"
106+
@tools/certs/mkcerts.sh
107+
108+
build/certs/server_cert.c:
109+
@echo "[MKCERTS] `dirname $@`"
110+
@tools/certs/mkcerts.sh
111+
112+
build/certs/server_key.o: build/certs/server_key.c
113+
@mkdir -p `dirname $@` || true
114+
@echo "[CC] $<"
115+
@$(CC) $(CFLAGS) -c $< -o $@
116+
117+
unit: build/test/unit
118+
119+
build/test/unit:
120+
@mkdir -p build/test/
121+
@echo "[CC] unit.c"
122+
@$(CC) $(CFLAGS) -c src/test/unit/unit.c -o build/test/unit.o
123+
@echo "[LD] $@"
124+
@$(CC) -o build/test/unit build/test/unit.o $(LDFLAGS)
125+
126+
# Install dynamic library to re-link linux applications
127+
#
128+
install:
129+
install libwolftcp.so $(PREFIX)/lib
130+
ldconfig
131+
132+
.PHONY: clean all static

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# wolfTCP
2+
3+
The smallest TCP/IP stack on the planet
4+
5+
## Description and project goals
6+
7+
wolfTCP is a TCP/IP stack with no dynamic memory allocations, designed to be
8+
used in resource-constrained embedded systems.
9+
10+
Endpoint only mode is supported, which means that wolftcp can be used to
11+
establish network connections but it does not route traffic between different
12+
network interfaces.
13+
14+
A single network interface can be associated with the device.
15+
16+
## Features supported
17+
18+
- ARP (RFC 826)
19+
- IPv4 (RFC 791)
20+
- ICMP (RFC 792): only ping replies
21+
- DHCP (RFC 2131): client only
22+
- DNS (RFC 1035): client only
23+
- UDP (RFC 768): unicast only
24+
- TCP (RFC 793)
25+
- TCP options supported: Timestamps, Maximum Segment Size
26+
- BSD-like, non blocking socket API, with custom callbacks
27+
- No dynamic memory allocation
28+
- Fixed number of concurrent sockets
29+
- Pre-allocated buffers for packet processing in static memory
30+
31+
32+
## Copyright and License
33+
34+
wolfTCP is licensed under the GPLv3 license. See the LICENSE file for details.
35+
Copyright (c) 2025 wolfSSL Inc.
36+

config.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef WOLF_CONFIG_H
2+
#define WOLF_CONFIG_H
3+
4+
#define ETHERNET
5+
#define LINK_MTU 1536
6+
7+
#define MAX_TCPSOCKETS 20
8+
#define MAX_UDPSOCKETS 2
9+
#define RXBUF_SIZE LINK_MTU * 4
10+
#define TXBUF_SIZE LINK_MTU * 16
11+
12+
#define MAX_NEIGHBORS 16
13+
14+
/* Linux test configuration */
15+
#define WOLFTCP_IP "10.10.10.2"
16+
#define LINUX_IP "10.10.10.1"
17+
18+
#endif

core.md

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# wolfTCP
2+
3+
## Stack architecture
4+
5+
- No dynamic allocation (pre-allocated sockets and buffers)
6+
- Four-steps main loop function
7+
- Callback-based socket interface (allows implementing blocking BSD calls)
8+
9+
10+
11+
## Data structures
12+
13+
* Two types of circular buffers (fixed size):
14+
15+
- "fifo" : contains entire frames, including a descriptor.
16+
- "queue" : contains pure data, indexed by byte. Used for TCP receive buffer
17+
only.
18+
19+
* One binary heap for timers
20+
21+
22+
23+
### wolfTCP fifo
24+
25+
```
26+
+---------------------------------------------------------------------------------------------------------------------------+
27+
| +-----+---+----+-----+------------------+-----+---+----+-----+------------------+ |
28+
| | De | E | IP | TCP | Payload | De | E | IP | TCP | Payload | |
29+
| | sc | T | | | | sc | T | | | | |
30+
|* FREE SPACE * | ri | H | | | | ri | H | | | | * FREE SPACE* |
31+
| | pt | | | | | pt | | | | | |
32+
| | or | | | | | or | | | | | |
33+
| +-----+---+----+-----+------------------+-----+---+----+-----+------------------+ |
34+
+---------------------------------------------------------------------------------------------------------------------------+
35+
^ ^
36+
| |
37+
| |
38+
| |
39+
|Tail Head|
40+
41+
```
42+
43+
44+
45+
### wolfTCP queue
46+
47+
```
48+
+--------------+--------------------------------------------+---------------------------------------------------------------+
49+
| |*------------------------------------------*| |
50+
| || || |
51+
| || || |
52+
|* FREE SPACE *|| DATA PAYLOAD || * FREE SPACE * |
53+
| || || |
54+
| || || |
55+
| |*------------------------------------------*| |
56+
+--------------+--------------------------------------------+---------------------------------------------------------------+
57+
^ ^
58+
| |
59+
| |
60+
| |
61+
|Tail Head|
62+
```
63+
64+
65+
66+
## Sockets
67+
68+
### TCP socket
69+
70+
```
71+
+-------------+
72+
|Main loop TX |
73+
+-------------+
74+
^
75+
+----------------------------------+ |
76+
| | +------+
77+
| TCP Socket | |
78+
| | |
79+
| | |
80+
| | |
81+
| +-----------------------+
82+
| +---------------+ | |
83+
>DATA OUT==>>|socket send() |-->| TX buffer (fifo) |
84+
| +---------------+ | |
85+
| +-----------------------+
86+
| |
87+
| |
88+
| |
89+
| +-----------------------+
90+
| +-------------+ | |
91+
<DATA IN<<====|socket recv()|<---| RX buffer (queue) |
92+
| +-------------+ | |
93+
| +-----------------------+
94+
+----------------------------------+ ^
95+
|
96+
|
97+
|
98+
+--------------+
99+
| tcp_recv() |
100+
+--------------+
101+
```
102+
103+
104+
105+
106+
107+

0 commit comments

Comments
 (0)