mirror of
https://github.com/genodelabs/genode.git
synced 2025-04-07 19:34:56 +00:00
net: get rid of static constructors
This commit is contained in:
parent
29685f48ef
commit
6edf9ccf5a
@ -49,8 +49,7 @@ class Net::Ethernet_frame
|
||||
ADDR_LEN = 6, /* MAC address length in bytes */
|
||||
};
|
||||
|
||||
|
||||
static const Mac_address BROADCAST; /* broadcast address */
|
||||
static Mac_address broadcast() { return Mac_address((Genode::uint8_t)0xff); }
|
||||
|
||||
private:
|
||||
|
||||
|
@ -85,8 +85,8 @@ class Net::Ipv4_packet
|
||||
ADDR_LEN = IPV4_ADDR_LEN, /* Ip address length in bytes */
|
||||
};
|
||||
|
||||
static const Ipv4_address CURRENT; /* current network */
|
||||
static const Ipv4_address BROADCAST; /* broadcast address */
|
||||
static Ipv4_address current() { return Ipv4_address((Genode::uint8_t)0x00); }
|
||||
static Ipv4_address broadcast() { return Ipv4_address((Genode::uint8_t)0xff); }
|
||||
|
||||
static Ipv4_address ip_from_string(const char *ip);
|
||||
|
||||
|
@ -43,9 +43,14 @@ namespace Net {
|
||||
|
||||
class Alloc_failed : Genode::Exception {};
|
||||
|
||||
|
||||
/* reference MAC address */
|
||||
static Mac_address mac_addr_base;
|
||||
/**
|
||||
* Reference MAC address
|
||||
*
|
||||
* We take the range 02:02:02:02:02:XX for our MAC address
|
||||
* allocator, it's likely, that we will have no clashes here.
|
||||
* (e.g. Linux uses 02:00... for its tap-devices.)
|
||||
*/
|
||||
Mac_address mac_addr_base { Mac_address(0x02) };
|
||||
|
||||
Mac_allocator() { Genode::memset(&_msbs, 0, sizeof(_msbs)); }
|
||||
|
||||
|
@ -181,7 +181,7 @@ void Main::_handle_eth(void *const eth_base,
|
||||
|
||||
/* drop packet if ETH does not target us */
|
||||
if (eth.dst() != _src_mac &&
|
||||
eth.dst() != Ethernet_frame::BROADCAST)
|
||||
eth.dst() != Ethernet_frame::broadcast())
|
||||
{
|
||||
if (_verbose) {
|
||||
log("bad ETH destination"); }
|
||||
@ -202,7 +202,7 @@ void Main::_handle_ip(Ethernet_frame ð,
|
||||
size_t const ip_size = eth_size - sizeof(Ethernet_frame);
|
||||
Ipv4_packet &ip = *eth.data<Ipv4_packet>(ip_size);
|
||||
if (ip.dst() != _src_ip &&
|
||||
ip.dst() != Ipv4_packet::BROADCAST)
|
||||
ip.dst() != Ipv4_packet::broadcast())
|
||||
{
|
||||
if (_verbose) {
|
||||
log("bad IP destination"); }
|
||||
@ -533,10 +533,4 @@ void Main::_send_ping(Duration)
|
||||
}
|
||||
|
||||
|
||||
void Component::construct(Env &env)
|
||||
{
|
||||
/* XXX execute constructors of global statics */
|
||||
env.exec_static_constructors();
|
||||
|
||||
static Main main(env);
|
||||
}
|
||||
void Component::construct(Env &env) { static Main main(env); }
|
||||
|
@ -17,8 +17,6 @@
|
||||
#include <net/ipv4.h>
|
||||
#include <base/output.h>
|
||||
|
||||
const Net::Mac_address Net::Ethernet_frame::BROADCAST(0xFF);
|
||||
|
||||
|
||||
void Net::Ethernet_frame::print(Genode::Output &output) const
|
||||
{
|
||||
|
@ -147,7 +147,3 @@ Genode::uint16_t Ipv4_packet::calculate_checksum(Ipv4_packet const &packet)
|
||||
+ host_to_big_endian(data[9]);
|
||||
return ~((0xFFFF & sum) + (sum >> 16));
|
||||
}
|
||||
|
||||
|
||||
const Ipv4_address Ipv4_packet::CURRENT((Genode::uint8_t)0x00);
|
||||
const Ipv4_address Ipv4_packet::BROADCAST((Genode::uint8_t)0xFF);
|
||||
|
@ -238,6 +238,8 @@ class Net::Root : public Genode::Root_component<Net::Session_component>
|
||||
Genode::Xml_node config)
|
||||
: Genode::Root_component<Session_component>(env.ep(), md_alloc),
|
||||
_env(env), _nic(nic), _config(config) { }
|
||||
|
||||
Mac_address &mac_addr_base() { return _mac_alloc.mac_addr_base; }
|
||||
};
|
||||
|
||||
#endif /* _COMPONENT_H_ */
|
||||
|
@ -1,22 +0,0 @@
|
||||
/*
|
||||
* \brief MAC-address allocator
|
||||
* \author Stefan Kalkowski
|
||||
* \date 2010-08-25
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2010-2017 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.
|
||||
*/
|
||||
|
||||
/* Genode includes */
|
||||
#include <nic_bridge/mac_allocator.h>
|
||||
|
||||
/**
|
||||
* We take the range 02:02:02:02:02:XX for our MAC address allocator,
|
||||
* it's likely, that we will have no clashes here.
|
||||
* (e.g. Linux uses 02:00... for its tap-devices.)
|
||||
*/
|
||||
Net::Mac_address Net::Mac_allocator::mac_addr_base(0x02);
|
@ -41,7 +41,7 @@ struct Main
|
||||
try {
|
||||
Nic::Mac_address mac;
|
||||
config.xml().attribute("mac").value(&mac);
|
||||
Genode::memcpy(&Net::Mac_allocator::mac_addr_base, &mac,
|
||||
Genode::memcpy(&root.mac_addr_base(), &mac,
|
||||
sizeof(Net::Mac_allocator::mac_addr_base));
|
||||
} catch(...) {}
|
||||
}
|
||||
@ -65,10 +65,4 @@ struct Main
|
||||
};
|
||||
|
||||
|
||||
void Component::construct(Genode::Env &env)
|
||||
{
|
||||
/* XXX execute constructors of global statics */
|
||||
env.exec_static_constructors();
|
||||
|
||||
static Main nic_bridge(env);
|
||||
}
|
||||
void Component::construct(Genode::Env &env) { static Main nic_bridge(env); }
|
||||
|
@ -62,7 +62,7 @@ void Packet_handler::_link_state()
|
||||
void Packet_handler::broadcast_to_clients(Ethernet_frame *eth, Genode::size_t size)
|
||||
{
|
||||
/* check whether it's really a broadcast packet */
|
||||
if (eth->dst() == Ethernet_frame::BROADCAST) {
|
||||
if (eth->dst() == Ethernet_frame::broadcast()) {
|
||||
/* iterate through the list of clients */
|
||||
Mac_address_node *node =
|
||||
_vlan.mac_list.first();
|
||||
|
@ -1,4 +1,4 @@
|
||||
TARGET = nic_bridge
|
||||
LIBS = base net
|
||||
SRC_CC = component.cc mac_allocator.cc main.cc nic.cc packet_handler.cc
|
||||
SRC_CC = component.cc main.cc nic.cc packet_handler.cc
|
||||
INC_DIR += $(PRG_DIR)
|
||||
|
@ -49,10 +49,4 @@ Main::Main(Env &env)
|
||||
}
|
||||
|
||||
|
||||
void Component::construct(Env &env)
|
||||
{
|
||||
/* XXX execute constructors of global statics */
|
||||
env.exec_static_constructors();
|
||||
|
||||
static Main main(env);
|
||||
}
|
||||
void Component::construct(Env &env) { static Main main(env); }
|
||||
|
@ -125,7 +125,7 @@ Net::Root::Root(Entrypoint &ep,
|
||||
_ep(ep), _router_mac(router_mac), _config(config), _buf_ram(buf_ram),
|
||||
_region_map(region_map), _interfaces(interfaces)
|
||||
{
|
||||
Mac_allocator::mac_addr_base = config.mac_first();
|
||||
_mac_alloc.mac_addr_base = config.mac_first();
|
||||
}
|
||||
|
||||
|
||||
|
@ -24,16 +24,12 @@
|
||||
using namespace Net;
|
||||
using namespace Genode;
|
||||
|
||||
static Cstring const _udp_name("UDP");
|
||||
static Cstring const _tcp_name("TCP");
|
||||
static Cstring const _icmp_name("ICMP");
|
||||
|
||||
Cstring const &Net::udp_name() { return _udp_name; }
|
||||
Cstring const &Net::tcp_name() { return _tcp_name; }
|
||||
Cstring const &Net::icmp_name() { return _icmp_name; }
|
||||
char const *Net::tcp_name() { return "TCP"; }
|
||||
char const *Net::udp_name() { return "UDP"; }
|
||||
char const *Net::icmp_name() { return "ICMP"; }
|
||||
|
||||
|
||||
Cstring const &Net::l3_protocol_name(L3_protocol protocol)
|
||||
char const *Net::l3_protocol_name(L3_protocol protocol)
|
||||
{
|
||||
switch (protocol) {
|
||||
case L3_protocol::TCP: return tcp_name();
|
||||
|
@ -24,10 +24,10 @@ namespace Net {
|
||||
|
||||
using L3_protocol = Ipv4_packet::Protocol;
|
||||
|
||||
Genode::Cstring const &tcp_name();
|
||||
Genode::Cstring const &udp_name();
|
||||
Genode::Cstring const &icmp_name();
|
||||
Genode::Cstring const &l3_protocol_name(L3_protocol protocol);
|
||||
char const *tcp_name();
|
||||
char const *udp_name();
|
||||
char const *icmp_name();
|
||||
char const *l3_protocol_name(L3_protocol protocol);
|
||||
}
|
||||
|
||||
#endif /* _L3_PROTOCOL_H_ */
|
||||
|
@ -1,17 +0,0 @@
|
||||
/*
|
||||
* \brief MAC-address allocator
|
||||
* \author Martin Stein
|
||||
* \date 2016-10-24
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2016-2017 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.
|
||||
*/
|
||||
|
||||
/* Genode includes */
|
||||
#include <nic_bridge/mac_allocator.h>
|
||||
|
||||
Net::Mac_address Net::Mac_allocator::mac_addr_base(0x02);
|
@ -104,9 +104,6 @@ void Net::Main::_handle_config()
|
||||
|
||||
void Component::construct(Env &env)
|
||||
{
|
||||
/* XXX execute constructors of global statics */
|
||||
env.exec_static_constructors();
|
||||
|
||||
try { static Net::Main main(env); }
|
||||
|
||||
catch (Net::Domain_tree::No_match) {
|
||||
|
@ -4,7 +4,7 @@ LIBS += base net
|
||||
|
||||
SRC_CC += arp_waiter.cc ip_rule.cc ipv4_address_prefix.cc
|
||||
SRC_CC += component.cc port_allocator.cc forward_rule.cc
|
||||
SRC_CC += nat_rule.cc mac_allocator.cc main.cc ipv4_config.cc
|
||||
SRC_CC += nat_rule.cc main.cc ipv4_config.cc
|
||||
SRC_CC += uplink.cc interface.cc arp_cache.cc configuration.cc
|
||||
SRC_CC += domain.cc l3_protocol.cc direct_rule.cc link.cc
|
||||
SRC_CC += transport_rule.cc leaf_rule.cc permit_rule.cc
|
||||
|
Loading…
x
Reference in New Issue
Block a user