Skip to content

Commit 1cf2a04

Browse files
authored
Merge pull request #77 from danielinux/iface-mtu
Add selection of MTU value per-interface
2 parents 60444d8 + f0af5ee commit 1cf2a04

5 files changed

Lines changed: 619 additions & 75 deletions

File tree

config.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77

88
#define ETHERNET
99
#define LINK_MTU 1536
10+
#ifndef LINK_MTU_MIN
11+
#define LINK_MTU_MIN 64U
12+
#endif
13+
#if LINK_MTU < LINK_MTU_MIN
14+
#error "LINK_MTU must be greater than or equal to LINK_MTU_MIN"
15+
#endif
1016

1117
#define MAX_TCPSOCKETS 4
1218
#define MAX_UDPSOCKETS 2

docs/API.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@ struct wolfIP_ll_dev {
2727
uint8_t mac[6]; // Device MAC address
2828
char ifname[16]; // Interface name
2929
uint8_t non_ethernet; // L3-only link (no Ethernet header/ARP when set)
30+
uint32_t mtu; // Optional internal frame budget, defaults to LINK_MTU
3031
int (*poll)(struct wolfIP_ll_dev *ll, void *buf, uint32_t len); // Receive function
3132
int (*send)(struct wolfIP_ll_dev *ll, void *buf, uint32_t len); // Transmit function
3233
};
3334
```
3435
wolfIP maintains an array of these descriptors sized by `WOLFIP_MAX_INTERFACES` (default `1`). Call `wolfIP_getdev_ex()` to access a specific slot; the legacy `wolfIP_getdev()` helper targets the first hardware slot (index `0` normally, or `1` when the optional loopback interface is enabled).
3536

3637
When `non_ethernet` is set, the interface is treated as L3-only point-to-point: the stack skips ARP/neighbor resolution, omits Ethernet headers on transmit, and expects receive buffers to begin at the IP header.
38+
The `mtu` field still describes wolfIP's internal frame budget including Ethernet headroom, so on non-Ethernet links the payload passed to `ll->send()` is effectively capped at `mtu - ETH_HEADER_LEN` on Ethernet-enabled builds.
3739

3840
### IP Configuration
3941
```c
@@ -203,8 +205,13 @@ Per-interface versions of the IP configuration helpers. The legacy functions tar
203205
```c
204206
struct wolfIP_ll_dev *wolfIP_getdev(struct wolfIP *s);
205207
struct wolfIP_ll_dev *wolfIP_getdev_ex(struct wolfIP *s, unsigned int if_idx);
208+
int wolfIP_mtu_set(struct wolfIP *s, unsigned int if_idx, uint32_t mtu);
209+
int wolfIP_mtu_get(struct wolfIP *s, unsigned int if_idx, uint32_t *mtu);
206210
```
207211
Access the link-layer descriptor(s) that should be wired to hardware drivers. `_ex` returns `NULL` if `if_idx` exceeds `WOLFIP_MAX_INTERFACES`.
212+
`wolfIP_mtu_set()` updates the effective per-interface MTU, treating `0` as the default `LINK_MTU` and clamping to `[LINK_MTU_MIN, LINK_MTU]`. `wolfIP_mtu_get()` returns the effective MTU currently used by the stack.
213+
For `non_ethernet` devices this value remains the internal frame budget; the maximum IP bytes handed to the driver are reduced by `ETH_HEADER_LEN` when Ethernet support is compiled in.
214+
- Returns: `wolfIP_getdev()`/`wolfIP_getdev_ex()` return a pointer to the link-layer descriptor or `NULL` on invalid interface index; `wolfIP_mtu_set()` returns `0` on success or a negative error code on failure; `wolfIP_mtu_get()` returns `0` on success or a negative error code on failure and stores the effective MTU in `*mtu`.
208215
209216
## DHCP Client Functions
210217

0 commit comments

Comments
 (0)