X-Git-Url: http://git.onelab.eu/?p=distributedratelimiting.git;a=blobdiff_plain;f=drl%2Fulogd_DRL.c;h=cb32f3bba121d4fe816b95e0c8e85cb0d32e829e;hp=f7b027256901326322647c007087b9982b726cb8;hb=77e70ca3ac61f5a17ba5f0222ce205ff58c9a314;hpb=89df43dd6b8cb8df82cfbf395b923014d2826b5a diff --git a/drl/ulogd_DRL.c b/drl/ulogd_DRL.c index f7b0272..cb32f3b 100644 --- a/drl/ulogd_DRL.c +++ b/drl/ulogd_DRL.c @@ -124,8 +124,24 @@ * Add the config options for DRL. */ -static config_entry_t create_htb = { +static config_entry_t leaves = { .next = NULL, + .key = "leaves", + .type = CONFIG_TYPE_STRING, + .options = CONFIG_OPT_NONE, + .u = { .string = "PLANETLAB" }, +}; + +static config_entry_t bind_addr = { + .next = &leaves, + .key = "bind_addr", + .type = CONFIG_TYPE_STRING, + .options = CONFIG_OPT_NONE, + .u = { .string = "AUTO" }, +}; + +static config_entry_t create_htb = { + .next = &bind_addr, .key = "create_htb", .type = CONFIG_TYPE_INT, .options = CONFIG_OPT_NONE, @@ -223,7 +239,7 @@ static config_entry_t policy = { .key = "policy", .type = CONFIG_TYPE_STRING, .options = CONFIG_OPT_MANDATORY, - .u = { .string = "GRD" }, + .u = { .string = "FPS" }, }; /** The estimate interval, in milliseconds. */ @@ -232,7 +248,7 @@ static config_entry_t estintms = { .key = "estintms", .type = CONFIG_TYPE_INT, .options = CONFIG_OPT_MANDATORY, - .u = { .value = 100 }, + .u = { .value = 500 }, }; #define config_entries (&estintms) @@ -717,15 +733,29 @@ static int validate_htb_exists(int node, int parent) { FILE *pipe = popen("/sbin/tc class show dev eth0", "r"); char line[200]; - while (fgets(line, 200, pipe) != NULL) { - int n, p; - char ignore[200]; + if (parent != 0) { + while (fgets(line, 200, pipe) != NULL) { + int n, p; + char ignore[200]; - sscanf(line, "class htb 1:%x parent 1:%x prio %s", &n, &p, ignore); - if (n == node && p == parent) { - pclose(pipe); - return 0; + sscanf(line, "class htb 1:%x parent 1:%x prio %s", &n, &p, ignore); + if (n == node && p == parent) { + pclose(pipe); + return 0; + } + } + } else { + while (fgets(line, 200, pipe) != NULL) { + int n, p; + char ignore[200]; + + sscanf(line, "class htb 1:%x root prio %d %s", &n, &p, ignore); + if (n == node && strstr(line, "root") != NULL) { + pclose(pipe); + return 0; + } } + } pclose(pipe); @@ -1526,15 +1556,20 @@ static int init_drl(void) { pthread_rwlock_init(&limiter.limiter_lock,NULL); /* determine our local IP by iterating through interfaces */ - limiter.ip = get_local_ip(); - if (limiter.ip == NULL) { - printlog(LOG_CRITICAL, "ulogd_DRL unable to aquire local IP address, not registering.\n"); - return false; + if (strncmp(bind_addr.u.string, "AUTO", 4)) { + limiter.ip = bind_addr.u.string; + } else { + limiter.ip = get_local_ip(); + if (limiter.ip == NULL) { + printlog(LOG_CRITICAL, "ulogd_DRL unable to aquire local IP address, not registering.\n"); + return false; + } } limiter.localaddr = inet_addr(limiter.ip); limiter.port = htons(LIMITER_LISTEN_PORT); limiter.udp_socket = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); if (limiter.udp_socket < 0) { + perror("socket()"); printlog(LOG_CRITICAL, "Failed to create UDP socket().\n"); return false; } @@ -1545,6 +1580,7 @@ static int init_drl(void) { server_address.sin_port = limiter.port; if (bind(limiter.udp_socket, (struct sockaddr *) &server_address, sizeof(server_address)) < 0) { + perror("bind()"); printlog(LOG_CRITICAL, "Failed to bind UDP socket.\n"); return false; } @@ -1580,9 +1616,18 @@ static int init_drl(void) { return false; } - if (get_eligible_leaves(&limiter.stable_instance)) { - printlog(LOG_CRITICAL, "Failed to read eligigle leaves.\n"); - return false; + /* If no leaves are specified, assume we're on planetlab and read them out + * of /proc/virtual. Otherwise, read the specified line. */ + if (!strncmp(leaves.u.string, "PLANETLAB", 9)) { + if (get_eligible_leaves(&limiter.stable_instance)) { + printlog(LOG_CRITICAL, "Failed to read eligigle leaves.\n"); + return false; + } + } else { + if (parse_leaves(&limiter.stable_instance, leaves.u.string)) { + printlog(LOG_CRITICAL, "Failed to parse leaf string.\n"); + return false; + } } if (parse_drl_config(drl_configfile.u.string, &configs)) { @@ -1669,10 +1714,18 @@ static void reconfig() { return; } - if (get_eligible_leaves(&limiter.new_instance)) { - free_failed_config(configs, &limiter.new_instance); - printlog(LOG_CRITICAL, "Failed to read leaves during reconfig().\n"); - return; + if (!strncmp(leaves.u.string, "PLANETLAB", 9)) { + if (get_eligible_leaves(&limiter.new_instance)) { + free_failed_config(configs, &limiter.new_instance); + printlog(LOG_CRITICAL, "Failed to read eligigle leaves.\n"); + return false; + } + } else { + if (parse_leaves(&limiter.new_instance, leaves.u.string)) { + free_failed_config(configs, &limiter.new_instance); + printlog(LOG_CRITICAL, "Failed to parse leaf string.\n"); + return false; + } } if (parse_drl_config(drl_configfile.u.string, &configs)) {