Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,11 @@ TAP_PIE_OBJ:=$(patsubst src/%.c,build/pie/%.o,$(TAP_SRC))
ifeq ($(UNAME_S),Darwin)
BEGIN_GROUP:=
END_GROUP:=
OPEN_CMD?=open
else
BEGIN_GROUP:=-Wl,--start-group
END_GROUP:=-Wl,--end-group
OPEN_CMD?=xdg-open
endif

CHECK_PKG_CFLAGS:=$(shell pkg-config --cflags check 2>/dev/null)
Expand All @@ -76,6 +78,7 @@ CHECK_PKG_LIBS:=$(shell pkg-config --libs check 2>/dev/null)
ifneq ($(CHECK_PKG_CFLAGS),)
UNIT_CFLAGS+=$(CHECK_PKG_CFLAGS)
endif
UNIT_CFLAGS+=-Isrc/test/unit/mocks

CPPCHECK=cppcheck
CPPCHECK_FLAGS=--enable=warning,performance,portability,missingInclude \
Expand Down Expand Up @@ -271,17 +274,40 @@ unit: build/test/unit
build/test/unit:
@mkdir -p build/test/
@echo "[CC] unit.c"
@$(CC) $(CFLAGS) $(UNIT_CFLAGS) -c src/test/unit/unit.c -o build/test/unit.o
@$(CC) $(UNIT_CFLAGS) $(CFLAGS) -c src/test/unit/unit.c -o build/test/unit.o
@echo "[LD] $@"
@$(CC) build/test/unit.o -o build/test/unit $(UNIT_LDFLAGS) $(LDFLAGS)

COV_DIR:=build/coverage
COV_UNIT:=$(COV_DIR)/unit
COV_UNIT_O:=$(COV_DIR)/unit.o

$(COV_UNIT_O): src/test/unit/unit.c
@mkdir -p $(COV_DIR)
@echo "[CC] unit.c (coverage)"
@$(CC) $(UNIT_CFLAGS) $(CFLAGS) --coverage -c src/test/unit/unit.c -o $(COV_UNIT_O)

$(COV_UNIT): LDFLAGS+=--coverage $(UNIT_LIBS)
$(COV_UNIT): $(COV_UNIT_O)
@echo "[LD] $@"
@$(CC) $(COV_UNIT_O) -o $(COV_UNIT) $(UNIT_LDFLAGS) $(LDFLAGS)

cov: unit $(COV_UNIT)
@echo "[RUN] unit (coverage)"
@rm -f $(COV_DIR)/*.gcda
@$(COV_UNIT)
@echo "[COV] gcovr html"
@mkdir -p build/coverage
@gcovr -r . --exclude "src/test/unit/unit.c" --html-details -o build/coverage/index.html
@$(OPEN_CMD) build/coverage/index.html

# Install dynamic library to re-link linux applications
#
install:
install libwolfip.so $(PREFIX)/lib
ldconfig

.PHONY: clean all static cppcheck
.PHONY: clean all static cppcheck cov

cppcheck:
$(CPPCHECK) $(CPPCHECK_FLAGS) src/ 2>cppcheck_results.xml
35 changes: 27 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,38 @@ A single network interface can be associated with the device.

## Features supported

- ARP (RFC 826)
- IPv4 (RFC 791)
- ICMP (RFC 792): only ping replies
- DHCP (RFC 2131): client only
- DNS (RFC 1035): client only
- UDP (RFC 768): unicast only
- TCP (RFC 793)
- TCP options supported: Timestamps, Maximum Segment Size
- BSD-like, non blocking socket API, with custom callbacks
- No dynamic memory allocation
- Fixed number of concurrent sockets
- Pre-allocated buffers for packet processing in static memory

## Protocols and RFCs

| Layer | Protocol | Features | RFC(s) |
|-------|----------|----------|--------|
| **Data Link** | Ethernet II | Frame encapsulation | [IEEE 802.3](https://standards.ieee.org/ieee/802.3/10422/) |
| **Data Link** | ARP | Address resolution, request/reply | [RFC 826](https://datatracker.ietf.org/doc/html/rfc826) |
| **Network** | IPv4 | Datagram delivery, TTL handling | [RFC 791](https://datatracker.ietf.org/doc/html/rfc791) |
| **Network** | IPv4 Forwarding | Multi-interface routing (optional) | [RFC 1812](https://datatracker.ietf.org/doc/html/rfc1812) |
| **Network** | ICMP | Echo request/reply, TTL exceeded | [RFC 792](https://datatracker.ietf.org/doc/html/rfc792) |
| **Transport** | UDP | Unicast datagrams, checksum | [RFC 768](https://datatracker.ietf.org/doc/html/rfc768) |
| **Transport** | TCP | Connection management, reliable delivery | [RFC 793](https://datatracker.ietf.org/doc/html/rfc793), [RFC 9293](https://datatracker.ietf.org/doc/html/rfc9293) |
| **Transport** | TCP Options: MSS | Maximum Segment Size negotiation | [RFC 793](https://datatracker.ietf.org/doc/html/rfc793) |
| **Transport** | TCP Options: Timestamps | RTT measurement, PAWS | [RFC 7323](https://datatracker.ietf.org/doc/html/rfc7323) |
| **Transport** | TCP Congestion Control | Slow start, congestion avoidance | [RFC 5681](https://datatracker.ietf.org/doc/html/rfc5681) |
| **Transport** | TCP Fast Retransmit | Triple duplicate ACK detection | [RFC 5681](https://datatracker.ietf.org/doc/html/rfc5681) |
| **Application** | DHCP | Client only (DORA) | [RFC 2131](https://datatracker.ietf.org/doc/html/rfc2131) |
| **Application** | DNS | A and PTR record queries (client) | [RFC 1035](https://datatracker.ietf.org/doc/html/rfc1035) |
| **Application** | HTTP/HTTPS | Server with wolfSSL TLS support | [RFC 9110](https://datatracker.ietf.org/doc/html/rfc9110) |

### Notes

- **TCP Congestion Control**: Implements slow start and congestion avoidance with `cwnd`, `ssthresh` tracking.
- **TCP Fast Retransmit**: Detects triple duplicate ACKs and retransmits lost segments.
- **ICMP**: Responds to ping requests; sends TTL exceeded messages when forwarding is enabled.
- **DHCP**: Full DORA (Discover, Offer, Request, Acknowledge) state machine with retry logic.
- **DNS**: Supports A record (forward) and PTR record (reverse) lookups.


## Functional tests with `LD_PRELOAD`

Expand Down
1 change: 0 additions & 1 deletion src/port/wolfssl_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include <wolfssl/ssl.h>
#include <wolfssl/wolfcrypt/memory.h>


#ifndef MAX_WOLFIP_CTX
#define MAX_WOLFIP_CTX 8 /* Default value */
#endif
Expand Down
39 changes: 39 additions & 0 deletions src/test/unit/mocks/wolfssl/ssl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* Mock wolfssl/ssl.h for unit tests.
* Only includes pieces needed by src/port/wolfssl_io.c tests.
*/
#ifndef WOLFSSL_SSL_H
#define WOLFSSL_SSL_H

#ifdef __cplusplus
extern "C" {
#endif

typedef struct WOLFSSL_CTX {
int id;
} WOLFSSL_CTX;

typedef struct WOLFSSL {
WOLFSSL_CTX *ctx;
void *rctx;
void *wctx;
} WOLFSSL;

typedef int (*CallbackIORecv)(WOLFSSL *ssl, char *buf, int sz, void *ctx);
typedef int (*CallbackIOSend)(WOLFSSL *ssl, char *buf, int sz, void *ctx);

#define WOLFSSL_CBIO_ERR_GENERAL (-1)
#define WOLFSSL_CBIO_ERR_WANT_READ (-2)
#define WOLFSSL_CBIO_ERR_WANT_WRITE (-2)
#define WOLFSSL_CBIO_ERR_CONN_CLOSE (-5)

int wolfSSL_SetIORecv(WOLFSSL_CTX *ctx, CallbackIORecv cb);
int wolfSSL_SetIOSend(WOLFSSL_CTX *ctx, CallbackIOSend cb);
int wolfSSL_SetIOReadCtx(WOLFSSL *ssl, void *ctx);
int wolfSSL_SetIOWriteCtx(WOLFSSL *ssl, void *ctx);
WOLFSSL_CTX *wolfSSL_get_SSL_CTX(WOLFSSL *ssl);

#ifdef __cplusplus
}
#endif

#endif /* WOLFSSL_SSL_H */
5 changes: 5 additions & 0 deletions src/test/unit/mocks/wolfssl/wolfcrypt/memory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* Mock wolfssl/wolfcrypt/memory.h for unit tests. */
#ifndef WOLFSSL_WOLFCRYPT_MEMORY_H
#define WOLFSSL_WOLFCRYPT_MEMORY_H

#endif /* WOLFSSL_WOLFCRYPT_MEMORY_H */
5 changes: 5 additions & 0 deletions src/test/unit/mocks/wolfssl/wolfcrypt/settings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* Mock wolfssl/wolfcrypt/settings.h for unit tests. */
#ifndef WOLFSSL_WOLFCRYPT_SETTINGS_H
#define WOLFSSL_WOLFCRYPT_SETTINGS_H

#endif /* WOLFSSL_WOLFCRYPT_SETTINGS_H */
Loading