diff --git a/repos/libports/run/nic_bridge.run b/repos/libports/run/nic_bridge.run index 611f8336c2..582b5b2ab4 100644 --- a/repos/libports/run/nic_bridge.run +++ b/repos/libports/run/nic_bridge.run @@ -59,7 +59,7 @@ append config { - + diff --git a/repos/os/src/server/nic_bridge/README b/repos/os/src/server/nic_bridge/README index c7eb0b90a6..ac78a1586a 100644 --- a/repos/os/src/server/nic_bridge/README +++ b/repos/os/src/server/nic_bridge/README @@ -23,6 +23,7 @@ running as Genode processes without real network connectivity. The static IP can be configured per client of the NIC bridge using a '' node of the configuration. For example, the following policy assigns a static address to a client with the session label "lighttpd". + ! ! ... ! @@ -34,6 +35,7 @@ Of course, the client needs to configure its TCP/IP stack to use the assigned IP address. This can be done via configuration arguments examined by the 'lwip_nic_dhcp' libc plugin. For the given example, the configuration for the lighttpd process would look as follows. + ! ! ! ! ! + +The verbosity mode of the NIC bridge can be toggled with the verbose attribute +(default value shown): + +! + +If enabled, the NIC bridge logs sent and received packets as well as the +lifetime of interfaces connected to the bridge. diff --git a/repos/os/src/server/nic_bridge/component.cc b/repos/os/src/server/nic_bridge/component.cc index 6eb114381e..6a7cda7ff0 100644 --- a/repos/os/src/server/nic_bridge/component.cc +++ b/repos/os/src/server/nic_bridge/component.cc @@ -108,22 +108,24 @@ void Session_component::set_ipv4_address(Ipv4_address ip_addr) } -Session_component::Session_component(Genode::Ram_session &ram, - Genode::Region_map &rm, - Genode::Entrypoint &ep, - Genode::size_t amount, - Genode::size_t tx_buf_size, - Genode::size_t rx_buf_size, - Mac_address vmac, - Net::Nic &nic, - char *ip_addr) +Session_component::Session_component(Genode::Ram_session &ram, + Genode::Region_map &rm, + Genode::Entrypoint &ep, + Genode::size_t amount, + Genode::size_t tx_buf_size, + Genode::size_t rx_buf_size, + Mac_address vmac, + Net::Nic &nic, + bool const &verbose, + Genode::Session_label const &label, + char *ip_addr) : Stream_allocator(ram, rm, amount), Stream_dataspaces(ram, tx_buf_size, rx_buf_size), Session_rpc_object(rm, Stream_dataspaces::tx_ds, Stream_dataspaces::rx_ds, Stream_allocator::range_allocator(), ep.rpc_ep()), - Packet_handler(ep, nic.vlan()), + Packet_handler(ep, nic.vlan(), label, verbose), _mac_node(*this, vmac), _ipv4_node(*this), _nic(nic) @@ -157,11 +159,16 @@ Session_component::~Session_component() { } -Net::Root::Root(Genode::Env &env, Net::Nic &nic, Genode::Allocator &md_alloc, - Genode::Xml_node config) +Net::Root::Root(Genode::Env &env, + Net::Nic &nic, + Genode::Allocator &md_alloc, + bool const &verbose, + Genode::Xml_node config) : Genode::Root_component(env.ep(), md_alloc), _mac_alloc(Mac_address(config.attribute_value("mac", Mac_address(DEFAULT_MAC)))), _env(env), _nic(nic), - _config(config) { } + _config(config), + _verbose(verbose) +{ } diff --git a/repos/os/src/server/nic_bridge/component.h b/repos/os/src/server/nic_bridge/component.h index 0f717dcd81..2e46275910 100644 --- a/repos/os/src/server/nic_bridge/component.h +++ b/repos/os/src/server/nic_bridge/component.h @@ -123,15 +123,17 @@ class Net::Session_component : private Net::Stream_allocator, * \param rx_buf_size buffer size for rx channel * \param vmac virtual mac address */ - Session_component(Genode::Ram_session &ram, - Genode::Region_map &rm, - Genode::Entrypoint &ep, - Genode::size_t amount, - Genode::size_t tx_buf_size, - Genode::size_t rx_buf_size, - Mac_address vmac, - Net::Nic &nic, - char *ip_addr = 0); + Session_component(Genode::Ram_session &ram, + Genode::Region_map &rm, + Genode::Entrypoint &ep, + Genode::size_t amount, + Genode::size_t tx_buf_size, + Genode::size_t rx_buf_size, + Mac_address vmac, + Net::Nic &nic, + bool const &verbose, + Genode::Session_label const &label, + char *ip_addr = 0); ~Session_component(); @@ -196,6 +198,7 @@ class Net::Root : public Genode::Root_component Genode::Env &_env; Net::Nic &_nic; Genode::Xml_node _config; + bool const &_verbose; protected: @@ -207,8 +210,9 @@ class Net::Root : public Genode::Root_component char ip_addr[MAX_IP_ADDR_LENGTH]; memset(ip_addr, 0, MAX_IP_ADDR_LENGTH); + Session_label label; try { - Session_label const label = label_from_args(args); + label = label_from_args(args); Session_policy policy(label, _config); policy.attribute("ip_addr").value(ip_addr, sizeof(ip_addr)); } catch (Xml_node::Nonexistent_attribute) { @@ -226,7 +230,8 @@ class Net::Root : public Genode::Root_component return new (md_alloc()) Session_component(_env.ram(), _env.rm(), _env.ep(), ram_quota, tx_buf_size, rx_buf_size, - _mac_alloc.alloc(), _nic, ip_addr); + _mac_alloc.alloc(), _nic, _verbose, + label, ip_addr); } catch (Mac_allocator::Alloc_failed) { Genode::warning("Mac address allocation failed!"); @@ -244,8 +249,11 @@ class Net::Root : public Genode::Root_component public: - Root(Genode::Env &env, Net::Nic &nic, Genode::Allocator &md_alloc, - Genode::Xml_node config); + Root(Genode::Env &env, + Net::Nic &nic, + Genode::Allocator &md_alloc, + bool const &verbose, + Genode::Xml_node config); }; #endif /* _COMPONENT_H_ */ diff --git a/repos/os/src/server/nic_bridge/config.xsd b/repos/os/src/server/nic_bridge/config.xsd new file mode 100644 index 0000000000..9c9bf057a6 --- /dev/null +++ b/repos/os/src/server/nic_bridge/config.xsd @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/repos/os/src/server/nic_bridge/main.cc b/repos/os/src/server/nic_bridge/main.cc index 5f9fc9155d..c2d8f5b6c3 100644 --- a/repos/os/src/server/nic_bridge/main.cc +++ b/repos/os/src/server/nic_bridge/main.cc @@ -28,12 +28,16 @@ struct Main { Genode::Env &env; - Genode::Entrypoint &ep { env.ep() }; - Genode::Heap heap { env.ram(), env.rm() }; - Genode::Attached_rom_dataspace config { env, "config" }; - Net::Vlan vlan { }; - Net::Nic nic { env, heap, vlan }; - Net::Root root { env, nic, heap, config.xml() }; + Genode::Entrypoint &ep { env.ep() }; + Genode::Heap heap { env.ram(), env.rm() }; + Genode::Attached_rom_dataspace config { env, "config" }; + Net::Vlan vlan { }; + Genode::Session_label const nic_label { "uplink" }; + bool const verbose { config.xml().attribute_value("verbose", false) }; + Net::Nic nic { env, heap, vlan, verbose, + nic_label }; + Net::Root root { env, nic, heap, verbose, + config.xml() }; Main(Genode::Env &e) : env(e) { diff --git a/repos/os/src/server/nic_bridge/nic.cc b/repos/os/src/server/nic_bridge/nic.cc index ca5eb681a5..8e3ddac5a1 100644 --- a/repos/os/src/server/nic_bridge/nic.cc +++ b/repos/os/src/server/nic_bridge/nic.cc @@ -122,8 +122,12 @@ bool Net::Nic::handle_ip(Ethernet_frame ð, } -Net::Nic::Nic(Genode::Env &env, Genode::Heap &heap, Net::Vlan &vlan) -: Packet_handler(env.ep(), vlan), +Net::Nic::Nic(Genode::Env &env, + Genode::Heap &heap, + Net::Vlan &vlan, + bool const &verbose, + Session_label const &label) +: Packet_handler(env.ep(), vlan, label, verbose), _tx_block_alloc(&heap), _nic(env, &_tx_block_alloc, BUF_SIZE, BUF_SIZE), _mac(_nic.mac_address().addr) diff --git a/repos/os/src/server/nic_bridge/nic.h b/repos/os/src/server/nic_bridge/nic.h index 90998f8bfa..77d0293065 100644 --- a/repos/os/src/server/nic_bridge/nic.h +++ b/repos/os/src/server/nic_bridge/nic.h @@ -37,7 +37,11 @@ class Net::Nic : public Net::Packet_handler public: - Nic(Genode::Env&, Genode::Heap&, Vlan&); + Nic(Genode::Env&, + Genode::Heap&, + Vlan&, + bool const &verbose, + Genode::Session_label const &label); ::Nic::Connection *nic() { return &_nic; } Mac_address mac() { return _mac; } diff --git a/repos/os/src/server/nic_bridge/packet_handler.cc b/repos/os/src/server/nic_bridge/packet_handler.cc index bb9cf2bb43..9db4eea216 100644 --- a/repos/os/src/server/nic_bridge/packet_handler.cc +++ b/repos/os/src/server/nic_bridge/packet_handler.cc @@ -81,6 +81,8 @@ void Packet_handler::handle_ethernet(void* src, Genode::size_t size) /* parse ethernet frame header */ Size_guard size_guard(size); Ethernet_frame ð = Ethernet_frame::cast_from(src, size_guard); + if (_verbose) { + Genode::log("[", _label, "] rcv ", eth); } switch (eth.type()) { case Ethernet_frame::Type::ARP: if (!handle_arp(eth, size_guard)) return; @@ -101,6 +103,8 @@ void Packet_handler::handle_ethernet(void* src, Genode::size_t size) void Packet_handler::send(Ethernet_frame *eth, Genode::size_t size) { + if (_verbose) { + Genode::log("[", _label, "] snd ", *eth); } try { /* copy and submit packet */ Packet_descriptor packet = source()->alloc_packet(size); @@ -113,11 +117,19 @@ void Packet_handler::send(Ethernet_frame *eth, Genode::size_t size) } -Packet_handler::Packet_handler(Genode::Entrypoint &ep, Vlan &vlan) +Packet_handler::Packet_handler(Genode::Entrypoint &ep, + Vlan &vlan, + Genode::Session_label const &label, + bool const &verbose) : _vlan(vlan), + _label(label), + _verbose(verbose), _sink_ack(ep, *this, &Packet_handler::_ack_avail), _sink_submit(ep, *this, &Packet_handler::_ready_to_submit), _source_ack(ep, *this, &Packet_handler::_ready_to_ack), _source_submit(ep, *this, &Packet_handler::_packet_avail), _client_link_state(ep, *this, &Packet_handler::_link_state) -{ } +{ + if (_verbose) { + Genode::log("[", _label, "] interface initialized"); } +} diff --git a/repos/os/src/server/nic_bridge/packet_handler.h b/repos/os/src/server/nic_bridge/packet_handler.h index a9eaaa3069..ee08b43fe0 100644 --- a/repos/os/src/server/nic_bridge/packet_handler.h +++ b/repos/os/src/server/nic_bridge/packet_handler.h @@ -39,8 +39,10 @@ class Net::Packet_handler { private: - Packet_descriptor _packet { }; - Net::Vlan &_vlan; + Packet_descriptor _packet { }; + Net::Vlan &_vlan; + Genode::Session_label _label; + bool const &_verbose; /** * submit queue not empty anymore @@ -83,7 +85,10 @@ class Net::Packet_handler public: - Packet_handler(Genode::Entrypoint&, Vlan&); + Packet_handler(Genode::Entrypoint&, + Vlan&, + Genode::Session_label const &label, + bool const &verbose); virtual ~Packet_handler() { } diff --git a/repos/os/src/server/nic_bridge/target.mk b/repos/os/src/server/nic_bridge/target.mk index 56dea24ce7..b2e5172a30 100644 --- a/repos/os/src/server/nic_bridge/target.mk +++ b/repos/os/src/server/nic_bridge/target.mk @@ -1,4 +1,5 @@ -TARGET = nic_bridge -LIBS = base net -SRC_CC = component.cc main.cc nic.cc packet_handler.cc -INC_DIR += $(PRG_DIR) +TARGET = nic_bridge +LIBS = base net +SRC_CC = component.cc main.cc nic.cc packet_handler.cc +CONFIG_XSD = config.xsd +INC_DIR += $(PRG_DIR)