From: Florian Schmidt Date: Wed, 5 Jun 2019 12:43:30 +0000 (+0200) Subject: support for loading click configs X-Git-Tag: RELEASE-0.4~4 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=8876e52f2f74f10ab5c78d8e054f79cd8dd1f1e3;p=unikraft%2Flibs%2Fclick.git support for loading click configs The expected way is to provide a (plain-text) config file as initrd. If no initrd is provided, click will fall back to a static, compiled-in config that replies to pings. Signed-off-by: Florian Schmidt Reviewed-by: Felipe Huici --- diff --git a/click.cc b/click.cc index a3bfba8..85a938b 100644 --- a/click.cc +++ b/click.cc @@ -52,11 +52,14 @@ extern "C"{ #include #include +#include + #include #include +#include +#include int click_nthreads = 1; - void *__dso_handle = NULL; #define NLOG(fmt, ...) @@ -119,6 +122,32 @@ read_config(u_int rid = 0) static ErrorHandler *errh; static Master master(1); +static String * +get_config() +{ + String *cfg; + struct ukplat_memregion_desc img; + char *cstr; + size_t cstr_len; + + /* First, try initrd */ + if (ukplat_memregion_find_initrd0(&img) >= 0) { + cstr = (char *)img.base; + cstr_len = img.len; + } else { + /* If we can't find a config: use a fallback one statically + * compiled in. + */ + uk_pr_warn("Could not find a config, using standard config!\n"); + cstr = CONFIGSTRING; + cstr_len = strlen(CONFIGSTRING); + } + cfg = new String(cstr, cstr_len); + printf("Received config (length %d):\n", cfg->length()); + printf("%s\n", cfg->c_str()); + return cfg; +} + struct router_instance { Router *r; u_int f_stop; @@ -127,9 +156,8 @@ struct router_instance { void router_thread(void *thread_data) { - u_int *rid = (u_int*) thread_data; - String *config = new String; //read_config(*rid); - struct router_instance *ri = &router_list[*rid]; + struct router_instance *ri = &router_list[(unsigned long)thread_data]; + String *config = get_config(); ri->r = click_read_router(*config, true, errh, false, &master); if (ri->r->initialize(errh) < 0) { @@ -150,7 +178,6 @@ router_thread(void *thread_data) LOG("Master/driver stopped, closing router_thread"); free(config); - free(rid); } void diff --git a/include/static_config.h b/include/static_config.h new file mode 100644 index 0000000..85c5d12 --- /dev/null +++ b/include/static_config.h @@ -0,0 +1,22 @@ +static char CONFIGSTRING[] = " define($IP 10.0.10.123);\n\ + define($MAC0 11:22:33:44:55:66);\n\ +\n\ + source :: FromDevice;\n\ + sink :: ToDevice;\n\ + // classifies packets \n\ + c :: Classifier(\n\ + 12/0806 20/0001, // ARP Requests goes to output 0\n\ + 12/0806 20/0002, // ARP Replies to output 1\n\ + 12/0800 14/45 34/08, // ICMP Requests to output 2\n\ + -); // without a match to output 3\n\ +\n\ + arpq :: ARPQuerier($IP, $MAC0);\n\ + arpr :: ARPResponder($IP $MAC0);\n\ +\n\ + source -> c;\n\ + c[0] -> CheckARPHeader(14) -> ARPPrint -> arpr -> ARPPrint -> sink;\n\ + c[1] -> [1]arpq;\n\ + Idle -> [0]arpq;\n\ + arpq -> sink;\n\ + c[2] -> CheckIPHeader(14) -> IPPrint -> ICMPPingResponder() -> EtherMirror() -> IPPrint -> sink;\n\ + c[3] -> Discard;";