Skip to content

Added support for L3, non-ethernet interfaces#70

Open
danielinux wants to merge 3 commits intowolfSSL:masterfrom
danielinux:l3_dev
Open

Added support for L3, non-ethernet interfaces#70
danielinux wants to merge 3 commits intowolfSSL:masterfrom
danielinux:l3_dev

Conversation

@danielinux
Copy link
Member

Added the possibility to bind new network interfaces with non_ethernet=1 extra field, that skip L2 addressing and communicate solely via IP packets.

Added new posix port interface linux_tun.c, equivalent to tap, but point-to-point. Added functional test (evloop) using the tun device to demonstrate L3 interfaces.

Added unit tests (case: forwarding between interfaces of mixed types).

Copilot AI review requested due to automatic review settings March 5, 2026 17:06
@gasbytes gasbytes mentioned this pull request Mar 5, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copilot AI review requested due to automatic review settings March 5, 2026 23:51
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

int err;
struct sockaddr_in remote_sock = {
.sin_family = AF_INET,
.sin_port = ntohs(8), /* Echo */
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sin_port must be set in network byte order using htons(), not ntohs(). Using ntohs(8) will bind/connect to the wrong port on little-endian hosts (commonly 2048 instead of 8). Apply the same fix to the server-side socket address initialization in this file as well.

Suggested change
.sin_port = ntohs(8), /* Echo */
.sin_port = htons(8), /* Echo */

Copilot uses AI. Check for mistakes.
uint8_t local_buf[BUFFER_SIZE];
struct sockaddr_in local_sock = {
.sin_family = AF_INET,
.sin_port = ntohs(8), /* Echo */
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue as the client: sin_port must use htons(8) (network byte order). With ntohs(8) the server may listen on the wrong port depending on endianness.

Suggested change
.sin_port = ntohs(8), /* Echo */
.sin_port = htons(8), /* Echo */

Copilot uses AI. Check for mistakes.
Comment on lines +166 to +169
printf("test client: pattern mismatch\n");
printf("at position %u\n", i);
buf[i + 16] = 0;
printf("%s\n", &buf[i]);
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

buf[i + 16] = 0; writes out of bounds when i is the last chunk (e.g., i == sizeof(buf) - 16, then i + 16 == sizeof(buf)). Use a bounded print strategy (e.g., print a fixed-length slice) or null-terminate via a separate temporary buffer sized sizeof(test_pattern)+1.

Suggested change
printf("test client: pattern mismatch\n");
printf("at position %u\n", i);
buf[i + 16] = 0;
printf("%s\n", &buf[i]);
char tmp[sizeof(test_pattern) + 1];
printf("test client: pattern mismatch\n");
printf("at position %u\n", i);
memcpy(tmp, buf + i, sizeof(test_pattern));
tmp[sizeof(test_pattern)] = '\0';
printf("%s\n", tmp);

Copilot uses AI. Check for mistakes.
Comment on lines +323 to +329
for (i = 0; i < sizeof(local_buf); i += sizeof(test_pattern)) {
if (memcmp(local_buf + i, test_pattern, sizeof(test_pattern))) {
printf("test client: pattern mismatch\n");
printf("at position %u\n", i);
local_buf[i + 16] = 0;
printf("%s\n", &local_buf[i]);
return (void *)-1;
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same out-of-bounds write pattern as in client_cb: local_buf[i + 16] = 0; can write one byte past the end of the buffer for the last iteration. Prefer printing with an explicit length or copying into a small temporary, null-terminated buffer.

Copilot uses AI. Check for mistakes.
Comment on lines +148 to +152
if (ioctl(sock_fd, SIOCSIFADDR, &ifr) < 0) {
perror("ioctl SIOCSIFADDR");
close(sock_fd);
return -1;
}
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On these error paths, tun_fd is left open (and tun_fd is not reset), leaking the TUN device file descriptor. The same pattern repeats for later ioctl() failures (DSTADDR/NETMASK). Close tun_fd and set it back to -1 before returning to keep resource handling consistent with earlier failure handling.

Copilot uses AI. Check for mistakes.
Comment on lines +71 to +85
static int tun_add_host_route(const char *ifname, uint32_t peer_ip)
{
char peer_str[INET_ADDRSTRLEN];
char cmd[256];
struct in_addr peer = { .s_addr = peer_ip };
if (!inet_ntop(AF_INET, &peer, peer_str, sizeof(peer_str)))
return -1;
snprintf(cmd, sizeof(cmd), "ip route replace %s/32 dev %s >/dev/null 2>&1",
peer_str, ifname);
if (system(cmd) == 0)
return 0;
snprintf(cmd, sizeof(cmd), "route add -host %s dev %s >/dev/null 2>&1",
peer_str, ifname);
return (system(cmd) == 0) ? 0 : -1;
}
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Building shell commands with system() is vulnerable to command injection if ifname is not strictly controlled, and it also depends on external binaries and shell behavior. Prefer configuring routes via netlink (recommended on Linux) or a non-shell execution path (e.g., execve with fixed argv), and at minimum validate ifname against a strict allowlist of interface-name characters before composing commands.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants