lxip: support configuration of libc plugin

Added support for the 'ip_addr', 'gateway', and 'netmask' configuration
parameter.

Issue #984
This commit is contained in:
Sebastian Sumpf 2014-01-07 15:22:24 +01:00 committed by Norman Feske
parent 12f560dc0e
commit 880930cb4f
6 changed files with 77 additions and 15 deletions

View File

@ -31,7 +31,15 @@ namespace Lxip {
class Socketcall; class Socketcall;
Socketcall & init(); /**
* Init backend
*
* \param address_config for dynamic configuration use "dhcp", for static
* configuration use "<ip>::<gw-ip>:<netmask>:::off"
*
* \return Reference to Socketcall object
*/
Socketcall & init(char *address_config);
typedef Genode::uint8_t uint8_t; typedef Genode::uint8_t uint8_t;
typedef Genode::uint16_t uint16_t; typedef Genode::uint16_t uint16_t;

View File

@ -14,11 +14,65 @@
*/ */
#include <base/printf.h> #include <base/printf.h>
#include <base/snprintf.h>
#include <os/config.h>
#include <util/string.h>
extern void create_lxip_plugin(); extern void create_lxip_plugin(char *address_config);
void __attribute__((constructor)) init_libc_lxip(void) void __attribute__((constructor)) init_libc_lxip(void)
{ {
PDBG("init_libc_lxip()\n"); char ip_addr_str[16] = {0};
create_lxip_plugin(); char netmask_str[16] = {0};
char gateway_str[16] = {0};
char address_buf[128];
char *address_config;
try {
Genode::Xml_node libc_node = Genode::config()->xml_node().sub_node("libc");
try {
libc_node.attribute("ip_addr").value(ip_addr_str, sizeof(ip_addr_str));
} catch(...) { }
try {
libc_node.attribute("netmask").value(netmask_str, sizeof(netmask_str));
} catch(...) { }
try {
libc_node.attribute("gateway").value(gateway_str, sizeof(gateway_str));
} catch(...) { }
/* either none or all 3 interface attributes must exist */
if ((Genode::strlen(ip_addr_str) != 0) ||
(Genode::strlen(netmask_str) != 0) ||
(Genode::strlen(gateway_str) != 0)) {
if (Genode::strlen(ip_addr_str) == 0) {
PERR("Missing \"ip_addr\" attribute. Ignoring network interface config.");
throw Genode::Xml_node::Nonexistent_attribute();
} else if (Genode::strlen(netmask_str) == 0) {
PERR("Missing \"netmask\" attribute. Ignoring network interface config.");
throw Genode::Xml_node::Nonexistent_attribute();
} else if (Genode::strlen(gateway_str) == 0) {
PERR("Missing \"gateway\" attribute. Ignoring network interface config.");
throw Genode::Xml_node::Nonexistent_attribute();
}
} else
throw -1;
PDBG("static network interface: ip_addr=%s netmask=%s gateway=%s ",
ip_addr_str, netmask_str, 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 (...) {
PINF("Using DHCP for interface configuration.");
address_config = "dhcp";
}
PDBG("init_libc_lxip() address config=%s\n", address_config);
create_lxip_plugin(address_config);
} }

View File

@ -81,7 +81,7 @@ struct Plugin : Libc::Plugin
/** /**
* Constructor * Constructor
*/ */
Plugin(); Plugin(char *address_config);
bool supports_select(int nfds, bool supports_select(int nfds,
fd_set *readfds, fd_set *readfds,
@ -138,7 +138,7 @@ struct Plugin : Libc::Plugin
}; };
Plugin::Plugin() : socketcall(Lxip::init()) Plugin::Plugin(char *address_config) : socketcall(Lxip::init(address_config))
{ {
PDBG("using the lxip libc plugin"); PDBG("using the lxip libc plugin");
} }
@ -649,7 +649,7 @@ int Plugin::translate_ops_linux(int optname)
} /* unnamed namespace */ } /* unnamed namespace */
void create_lxip_plugin() void create_lxip_plugin(char *address_config)
{ {
static Plugin lxip_plugin; static Plugin lxip_plugin(address_config);
} }

View File

@ -16,6 +16,7 @@
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"
#endif #endif
int lxip_init(void);
int lxip_init(char *address_config);
#endif #endif

View File

@ -39,17 +39,16 @@ unsigned long nr_free_buffer_pages(void)
/** /**
* Initialize sub-systems * Initialize sub-systems
*/ */
int lxip_init() int lxip_init(char *address_config)
{ {
/* init data */ /* init data */
INIT_LIST_HEAD(&init_net.dev_base_head); INIT_LIST_HEAD(&init_net.dev_base_head);
/*start jiffies */ /*start jiffies */
dde_kit_timer_init(0, 0); dde_kit_timer_init(0, 0);
/* call __setup stuff */ /* call __setup stuff */
__ip_auto_config_setup("dhcp"); __ip_auto_config_setup(address_config);
core_sock_init(); core_sock_init();
core_netlink_proto_init(); core_netlink_proto_init();
@ -70,7 +69,7 @@ int lxip_init()
/* late */ /* late */
late_tcp_congestion_default(); late_tcp_congestion_default();
/* dhcp */ /* dhcp or static configuration */
late_ip_auto_config(); late_ip_auto_config();
return 1; return 1;

View File

@ -621,9 +621,9 @@ class Net::Socketcall : public Genode::Signal_dispatcher_base,
}; };
Lxip::Socketcall & Lxip::init() Lxip::Socketcall & Lxip::init(char *address_config)
{ {
static int init = lxip_init(); static int init = lxip_init(address_config);
static Net::Socketcall socketcall; static Net::Socketcall socketcall;
return socketcall; return socketcall;