test/ip_raw: add support for lwip

Add lwIP requiremnts to the ip_raw test.

issue 
This commit is contained in:
Sebastian Sumpf 2025-02-24 15:37:59 +01:00 committed by Norman Feske
parent 836caa299d
commit e46bc6159d
6 changed files with 95 additions and 11 deletions
repos
dde_linux/src/test/ip_raw
client
include
lwip
client
server
server
libports/run

@ -5,7 +5,7 @@
*/
/*
* Copyright (C) 2023-2024 Genode Labs GmbH
* Copyright (C) 2023-2025 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU Affero General Public License version 3.
@ -17,11 +17,10 @@
#include <net/ipv4.h>
#include <util/endian.h>
#include <genode_c_api/socket_types.h>
#include <genode_c_api/socket.h>
#include <data.h>
#include <socket_types.h>
namespace Test {
struct Client;
@ -58,10 +57,27 @@ struct Test::Client
Data data { };
char *recv_buf[Data::SIZE];
genode_socket_wakeup _wakeup;
void wakeup_remote_peer()
{
genode_socket_wakeup_remote();
}
static void _wakeup_remote(void *data)
{
Client *c = static_cast<Client *>(data);
c->wakeup_remote_peer();
}
Client(Env &env) : env(env)
{
genode_socket_init(genode_env_ptr(env), nullptr);
_wakeup.data = this;
_wakeup.callback = _wakeup_remote;
genode_socket_register_wakeup(&_wakeup);
genode_socket_config address_config = { .dhcp = true };
genode_socket_config_address(&address_config);
}
@ -178,6 +194,8 @@ struct Test::Client
ASSERT("send bytes...",
genode_socket_sendmsg(handle, msg.header(), &bytes_send) == GENODE_ENONE
&& bytes_send == MAX_UDP_LOAD);
genode_socket_wait_for_progress();
}
}
};

@ -0,0 +1,21 @@
/*
* \brief Definitions of standard socket API values used when no libc headers
* are present
* \author Sebastian Sumpf
* \date 2024-01-29
*/
/*
* Copyright (C) 2024 Genode Labs GmbH
*
* This file is distributed under the terms of the GNU General Public License
* version 2.
*/
enum {
/* sockaddr_in */
INADDR_ANY = 0ul,
/* shutdown */
SHUT_RDWR = 2,
};

@ -0,0 +1,11 @@
TARGET = test-lwip_client
LIBS = lwip base net
SRC_CC = main.cc
IP_DIR = $(REP_DIR)/src/test/ip_raw
INC_DIR += $(IP_DIR)/include
vpath %.cc $(IP_DIR)/client
CC_CXX_WARN_STRICT =

@ -0,0 +1,11 @@
TARGET = test-lwip_server
LIBS = lwip base net
SRC_CC = main.cc
IP_DIR = $(REP_DIR)/src/test/ip_raw
INC_DIR += $(IP_DIR)/include
vpath %.cc $(IP_DIR)/server
CC_CXX_WARN_STRICT =

@ -5,7 +5,7 @@
*/
/*
* Copyright (C) 2023-2024 Genode Labs GmbH
* Copyright (C) 2023-2025 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU Affero General Public License version 3.
@ -16,10 +16,10 @@
#include <net/ipv4.h>
#include <util/endian.h>
#include <genode_c_api/socket_types.h>
#include <genode_c_api/socket.h>
#include <data.h>
#include <socket_types.h>
namespace Test {
using namespace Net;
@ -66,10 +66,27 @@ struct Test::Server
enum { SIZE = Data::SIZE };
char buf[SIZE];
genode_socket_wakeup _wakeup;
void wakeup_remote_peer()
{
genode_socket_wakeup_remote();
}
static void _wakeup_remote(void *data)
{
Server *s = static_cast<Server *>(data);
s->wakeup_remote_peer();
}
Server(Env &env) : env(env)
{
genode_socket_init(genode_env_ptr(env), nullptr);
_wakeup.data = this;
_wakeup.callback = _wakeup_remote;
genode_socket_register_wakeup(&_wakeup);
genode_socket_config address_config = {
.dhcp = false,
.ip_addr = ip.string(),
@ -131,19 +148,22 @@ struct Test::Server
(handle_reuse = genode_socket(AF_INET, SOCK_STREAM, 0, &err)) != nullptr);
int opt = 1;
Errno reuse_err = genode_socket_setsockopt(handle, GENODE_SOL_SOCKET, GENODE_SO_REUSEPORT,
&opt, sizeof(opt));
ASSERT("setsockopt REUSEPORT handle...",
genode_socket_setsockopt(handle, GENODE_SOL_SOCKET, GENODE_SO_REUSEPORT,
&opt, sizeof(opt)) == GENODE_ENONE);
ASSERT("setsockopt REUSEPORT handle re-use...",
genode_socket_setsockopt(handle_reuse, GENODE_SOL_SOCKET, GENODE_SO_REUSEPORT,
&opt, sizeof(opt)) == GENODE_ENONE);
(reuse_err == GENODE_ENONE || reuse_err == GENODE_ENOPROTOOPT));
if (reuse_err == GENODE_ENONE)
ASSERT("setsockopt REUSEPORT handle re-use...",
genode_socket_setsockopt(handle_reuse, GENODE_SOL_SOCKET, GENODE_SO_REUSEPORT,
&opt, sizeof(opt)) == GENODE_ENONE);
genode_sockaddr addr;
addr.family = AF_INET;
addr.in.port = host_to_big_endian(port);
addr.in.addr = INADDR_ANY;
ASSERT("bind socket...", genode_socket_bind(handle, &addr) == GENODE_ENONE);
ASSERT("bind socket re-use...", genode_socket_bind(handle_reuse, &addr) == GENODE_ENONE);
if (reuse_err == GENODE_ENONE)
ASSERT("bind socket re-use...", genode_socket_bind(handle_reuse, &addr) == GENODE_ENONE);
ASSERT("listen...", genode_socket_listen(handle, 5) == GENODE_ENONE);

@ -0,0 +1,3 @@
proc ipstack { } { return lwip }
source ${genode_dir}/repos/dde_linux/run/ip_raw.inc