Skip to content

Commit

Permalink
Use new lwIP netif facility for tftp_rom
Browse files Browse the repository at this point in the history
LwIP can be used without libc or its plugin libraries.

Fix TUD-OS#36
  • Loading branch information
ehmry authored and nfeske committed Sep 3, 2018
1 parent 2a45dc1 commit 6dbbba4
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 19 deletions.
11 changes: 8 additions & 3 deletions run/tftp_rom.run
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ append config {
<service name="ROM"/>
<service name="SIGNAL"/>
</parent-provides>
<default caps="256"/>
<default-route>
<any-service> <parent/> <any-child/> </any-service>
</default-route>}
Expand All @@ -57,18 +58,21 @@ append config {
<start name="tftp_rom">
<resource name="RAM" quantum="32M"/>
<provides> <service name="ROM"/> </provides>
<config verbose="yes">
<config verbose="yes" dhcp="yes">
<libc stdout="/log" stderr="/log">
<vfs> <log/> </vfs>
</libc>
<policy label_prefix="init" ip="10.0.2.2" port="69"
<default-policy label_prefix="init" ip="10.0.2.2" port="69"
dir="/genode" timeout="10"/>
</config>
</start>
<start name="init">
<exit propagate="yes"/>
<resource name="RAM" quantum="6M"/>
<route>
<service name="ROM" unscoped_label="ld.lib.so">
<parent/> </service>
<service name="ROM" label_suffix="ld.lib.so">
<parent/> </service>
<any-service>
<child name="tftp_rom"/>
<parent/>
Expand All @@ -88,6 +92,7 @@ append config {
<default-route>
<any-service> <parent/> </any-service>
</default-route>
<default caps="256"/>
<start name="test-libc">
<resource name="RAM" quantum="4M"/>
<config>
Expand Down
44 changes: 29 additions & 15 deletions src/server/tftp_rom/component.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,18 @@
#include <base/attached_rom_dataspace.h>
#include <base/heap.h>
#include <root/component.h>
#include <libc/component.h>
#include <base/component.h>
#include <util/list.h>
#include <util/string.h>
#include <util/endian.h>

/* lwIP raw API */
#include <lwip/genode.h>
/* LwIP includes */
#include <lwip/api.h>
#include <lwip/inet.h>
#include <lwip/udp.h>
#include <lwip/init.h>
#include <lwip/genode_init.h>
#include <lwip/nic_netif.h>


namespace Tftp_rom {
Expand All @@ -48,11 +49,11 @@ namespace Tftp_rom {
}


extern "C" void rrq_cb(void *arg, udp_pcb *upcb, pbuf *pbuf,
ip_addr_t *addr, Genode::uint16_t port);
extern "C" void rrq_cb(void *arg, struct udp_pcb *pcb, struct pbuf *p,
const ip_addr_t *addr, u16_t port);

extern "C" void data_cb(void *arg, udp_pcb *upcb, pbuf *pbuf,
ip_addr_t *addr, Genode::uint16_t port);
extern "C" void data_cb(void *arg, struct udp_pcb *pcb, struct pbuf *p,
const ip_addr_t *addr, u16_t port);


class Tftp_rom::Session_component :
Expand Down Expand Up @@ -185,7 +186,7 @@ class Tftp_rom::Session_component :
udp_send(_pcb, ack);
}

void first_response(pbuf *data, ip_addr_t *addr, uint16_t port)
void first_response(pbuf *data, ip_addr_t const *addr, uint16_t port)
{
/*
* we now know the port the server will use,
Expand Down Expand Up @@ -325,8 +326,8 @@ class Tftp_rom::Session_component :
********************/


extern "C" void rrq_cb(void *arg, udp_pcb *upcb, pbuf *data,
ip_addr_t *addr, Genode::uint16_t port)
extern "C" void rrq_cb(void *arg, struct udp_pcb *pcb, struct pbuf *data,
const ip_addr_t *addr, u16_t port)
{
Tftp_rom::Session_component *session = (Tftp_rom::Session_component*)arg;

Expand All @@ -347,7 +348,7 @@ extern "C" void rrq_cb(void *arg, udp_pcb *upcb, pbuf *data,


extern "C" void data_cb(void *arg, udp_pcb *upcb, pbuf *data,
ip_addr_t *addr, Genode::uint16_t port)
ip_addr_t const *addr, Genode::uint16_t port)
{
Tftp_rom::Session_component *session = (Tftp_rom::Session_component*)arg;
if (session->add_block(data)) return;
Expand All @@ -365,6 +366,11 @@ class Tftp_rom::Root : public Genode::Root_component<Session_component>
Genode::Env &_env;
Genode::Attached_rom_dataspace _config_rom { _env, "config" };

/**
* LwIP connection to Nic service
*/
Lwip::Nic_netif _netif { _env, *md_alloc(), _config_rom.xml() };

class Timeout_dispatcher : Genode::Thread, Genode::Lock
{
private:
Expand Down Expand Up @@ -456,6 +462,9 @@ class Tftp_rom::Root : public Genode::Root_component<Session_component>

Session_component *_create_session(const char *args) override
{
while (!_netif.ready())
_env.ep().wait_and_dispatch_one_io_signal();

Session_component *session;

_config_rom.update();
Expand Down Expand Up @@ -531,9 +540,14 @@ class Tftp_rom::Root : public Genode::Root_component<Session_component>
};


void Libc::Component::construct(Libc::Env &env )
void Component::construct(Genode::Env &env)
{
static Genode::Sliced_heap sliced_heap(env.ram(), env.rm());
static Tftp_rom::Root root(env, sliced_heap);
}
env.exec_static_constructors();

static Genode::Heap heap(env.ram(), env.rm());
static Timer::Connection timer(env, "lwip");

Lwip::genode_init(heap, timer);

static Tftp_rom::Root root(env, heap);
}
2 changes: 1 addition & 1 deletion src/server/tftp_rom/target.mk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
TARGET = tftp_rom
SRC_CC = component.cc
LIBS = base lwip libc libc_lwip libc_lwip_nic_dhcp
LIBS = base lwip

CC_CXX_WARN_STRICT =

0 comments on commit 6dbbba4

Please sign in to comment.