lxip: network reconfiguration support

This commit is contained in:
Christian Prochaska 2017-02-07 20:52:34 +01:00 committed by Norman Feske
parent aa602032dd
commit a1453d83ff
5 changed files with 42 additions and 25 deletions

View File

@ -34,12 +34,18 @@ namespace Lxip {
/**
* Init backend
*
* \param address_config for dynamic configuration use "dhcp", for static
* configuration use "<ip>::<gw-ip>:<netmask>:::off"
* \param ip_addr_str IP address
* \param netmask_str Netmask
* \param gateway_str Gateway
* \param nameserver_str Nameserver
*
* \return Reference to Socketcall object
*/
Socketcall & init(Genode::Env &env, char const *address_config);
Socketcall & init(Genode::Env &env,
char const *ip_addr_str,
char const *netmask_str,
char const *gateway_str,
char const *nameserver_str);
typedef Genode::uint8_t uint8_t;
typedef Genode::uint16_t uint16_t;

View File

@ -83,8 +83,13 @@ struct Plugin : Libc::Plugin
Genode::Heap heap;
Lxip::Socketcall &socketcall;
Socketcall(Genode::Env &env, char const *address_config)
: heap(env.ram(), env.rm()), socketcall(Lxip::init(env, address_config))
Socketcall(Genode::Env &env,
char const *ip_addr_str,
char const *netmask_str,
char const *gateway_str)
: heap(env.ram(), env.rm()),
socketcall(Lxip::init(env, ip_addr_str, netmask_str,
gateway_str, gateway_str))
{ }
};
@ -174,7 +179,6 @@ void Plugin::init(Genode::Env &env)
char netmask_str[16] = {0};
char gateway_str[16] = {0};
char address_buf[128];
char const *address_config;
Genode::Attached_rom_dataspace config { env, "config"} ;
@ -214,18 +218,12 @@ void Plugin::init(Genode::Env &env)
"ip_addr=", Genode::Cstring(ip_addr_str), " "
"netmask=", Genode::Cstring(netmask_str), " "
"gateway=", Genode::Cstring(gateway_str));
Genode::snprintf(address_buf, sizeof(address_buf), "%s::%s:%s:::off",
ip_addr_str, gateway_str, netmask_str);
address_config = address_buf;
}
catch (...) {
Genode::log("Using DHCP for interface configuration.");
address_config = "dhcp";
}
Genode::log("Plugin::init() address config=", address_config);
socketconstruct.construct(env, address_config);
socketconstruct.construct(env, ip_addr_str, netmask_str, gateway_str);
};
/* TODO shameful copied from lwip... generalize this */

View File

@ -40,7 +40,12 @@ namespace Lx {
void lxcc_emul_init(Lx_kit::Env &env);
}
extern "C" int lxip_init(char const *address_config);
extern "C" void lxip_init();
extern "C" void lxip_configure_static(char const *addr,
char const *netmask,
char const *gateway,
char const *nameserver);
extern "C" void lxip_configure_dhcp();
#endif /* _LX_H_ */

View File

@ -480,14 +480,11 @@ void late_tcp_congestion_default(void);
/**
* Initialize sub-systems
*/
int lxip_init(char const *address_config)
void lxip_init()
{
/* init data */
INIT_LIST_HEAD(&init_net.dev_base_head);
/* call __setup stuff */
__ip_auto_config_setup((char *)address_config);
core_sock_init();
core_netlink_proto_init();
@ -506,14 +503,13 @@ int lxip_init(char const *address_config)
/* late */
late_tcp_congestion_default();
/* dhcp or static configuration */
late_ip_auto_config();
return 0;
}
/*
* Network configuration
*/
static void lxip_configure(char const *address_config)
{
__ip_auto_config_setup((char *)address_config);

View File

@ -617,7 +617,11 @@ class Net::Socketcall : public Lxip::Socketcall,
static void ticker() { }
Lxip::Socketcall & Lxip::init(Genode::Env &env, char const *address_config)
Lxip::Socketcall & Lxip::init(Genode::Env &env,
char const *ip_addr_str,
char const *netmask_str,
char const *gateway_str,
char const *nameserver_str)
{
Lx_kit::Env &lx_env = Lx_kit::construct_env(env);
@ -628,7 +632,15 @@ Lxip::Socketcall & Lxip::init(Genode::Env &env, char const *address_config)
Lx::nic_client_init(env, socketcall, lx_env.heap(), ticker);
Lx::lxcc_emul_init(lx_env);
lxip_init(address_config);
lxip_init();
if ((!ip_addr_str || (ip_addr_str[0] == 0)) ||
(!netmask_str || (netmask_str[0] == 0)) ||
(!gateway_str || (gateway_str[0] == 0)) ||
(!nameserver_str || (nameserver_str[0] == 0)))
lxip_configure_dhcp();
else
lxip_configure_static(ip_addr_str, netmask_str, gateway_str, nameserver_str);
return socketcall;
}