int olsr_string_to_prefix(int ipversion, struct olsr_ip_prefix *dst, const char *string) { static char buf[MAX(INET6_ADDRSTRLEN + 1 + 3, INET_ADDRSTRLEN + 1 + INET_ADDRSTRLEN)]; char *ptr; strscpy(buf, string, sizeof(buf)); dst->prefix_len = ipversion == AF_INET ? 32 : 128; ptr = strchr(buf, '/'); if (!ptr) { ptr = strchr(buf, ' '); } if (ptr) { *ptr++ = 0; if (olsr_cnf->ip_version == AF_INET && strchr(ptr, '.')) { uint8_t subnetbuf[4]; if (inet_pton(AF_INET, ptr, subnetbuf) != 1) { return -1; } dst->prefix_len = netmask_to_prefix(subnetbuf, sizeof(subnetbuf)); } else { dst->prefix_len = atoi(ptr); } } return inet_pton(ipversion, buf, &dst->prefix) == 1 ? 0 : -1; }
/* Calculate final configuration values needed for ipv4-mapped-ipv6 */ static void finalize_ipv4_mapped_ipv6_config(struct config *config) { set_ipv4_defaults(config); config->live_local_ip = ipv4_parse(config->live_local_ip_string); config->live_remote_ip = ipv4_parse(config->live_remote_ip_string); config->live_prefix_len = netmask_to_prefix(config->live_netmask_ip_string); config->live_gateway_ip = ipv4_parse(config->live_gateway_ip_string); config->live_bind_ip = ipv6_parse("::"); config->live_connect_ip = ipv6_map_from_ipv4(config->live_remote_ip); config->socket_domain = AF_INET6; config->wire_protocol = AF_INET; }
int process_param(char *key, char *value) { static union olsr_ip_addr curr_hna_net; static bool curr_hna_ok = false; if (!strcmp(key, "debug_level")) { int ival = atoi(value); if ((ival < 0) || (ival > 9)) return -1; olsr_cnf->debug_level = ival; return 1; } if (!strcmp(key, "tc_redundancy")) { int ival = atoi(value); if ((ival < 0) || (ival > 3)) return -1; olsr_cnf->tc_redundancy = ival; return 1; } if (!strcmp(key, "mpr_coverage")) { int ival = atoi(value); if (ival < 0) return -1; olsr_cnf->mpr_coverage = ival; return 1; } if (!strcmp(key, "willingness")) { int ival = atoi(value); if ((ival < 0) || (ival > 7)) return -1; olsr_cnf->willingness = ival; return 1; } if (!strcmp(key, "lq_level")) { int ival = atoi(value); if ((ival < 0) || (ival > 2)) return -1; olsr_cnf->lq_level = ival; return 1; } if (!strcmp(key, "lq_wsize")) { int ival = atoi(value); if ((ival < 0) || (ival > 10)) return -1; olsr_cnf->lq_wsize = ival; return 1; } if (!strcmp(key, "hyst_scaling")) { float fval = 1.1; sscanf(value, "%f", &fval); if ((fval < 0.0) || (fval > 1.0)) return -1; olsr_cnf->hysteresis_param.scaling = fval; return 1; } if (!strcmp(key, "hyst_scaling")) { float fval = 1.1; sscanf(value, "%f", &fval); if ((fval < 0.0) || (fval > 1.0)) return -1; olsr_cnf->hysteresis_param.scaling = fval; return 1; } if (!strcmp(key, "hyst_lower")) { float fval = 1.1; sscanf(value, "%f", &fval); if ((fval < 0.0) || (fval > 1.0)) return -1; olsr_cnf->hysteresis_param.thr_low = fval; return 1; } if (!strcmp(key, "hyst_upper")) { float fval = 1.1; sscanf(value, "%f", &fval); if ((fval < 0.0) || (fval > 1.0)) return -1; olsr_cnf->hysteresis_param.thr_high = fval; return 1; } if (!strcmp(key, "pollrate")) { float fval = 1.1; sscanf(value, "%f", &fval); if ((fval < 0.0) || (fval > 1.0)) return -1; olsr_cnf->pollrate = fval; return 1; } if (!strcmp(key, "hna_new_net")) { if (inet_pton(olsr_cnf->ipsize, value, &curr_hna_net.v4) == 0) { fprintf(stderr, "Failed converting new HNA net %s\n", value); return -1; } curr_hna_ok = true; return 1; } if (!strcmp(key, "hna_new_netmask")) { struct in_addr in; uint8_t prefixlen; if (!curr_hna_ok) return -1; curr_hna_ok = false; if (inet_aton(value, &in) == 0) { fprintf(stderr, "Failed converting new HNA netmask %s\n", value); return -1; } prefixlen = netmask_to_prefix((uint8_t *) & in, olsr_cnf->ipsize); if (prefixlen == UCHAR_MAX) { fprintf(stderr, "Failed converting new HNA netmask %s\n", value); return -1; } ip_prefix_list_add(&olsr_cnf->hna_entries, &curr_hna_net, prefixlen); return 1; } if (!strncmp(key, "del_hna", 7) && !strcmp(value, "on")) { struct in_addr net, mask; char ip_net[16], ip_mask[16]; int seperator = 0; uint8_t prefixlen; while (key[7 + seperator] != '*') { seperator++; } memcpy(ip_net, &key[7], seperator); ip_net[seperator] = 0; memcpy(ip_mask, &key[7 + seperator + 1], 16); olsr_printf(1, "Deleting HNA %s/%s\n", ip_net, ip_mask); if (inet_aton(ip_net, &net) == 0) { fprintf(stderr, "Failed converting HNA net %s for deletion\n", ip_net); return -1; } if (inet_aton(ip_mask, &mask) == 0) { fprintf(stderr, "Failed converting HNA netmask %s for deletion\n", ip_mask); return -1; } prefixlen = netmask_to_prefix((uint8_t *) & mask, olsr_cnf->ipsize); if (prefixlen == UCHAR_MAX) { fprintf(stderr, "Failed converting new HNA netmask %s\n", value); return -1; } ip_prefix_list_add(&olsr_cnf->hna_entries, &curr_hna_net, prefixlen); return 1; } return 0; #if 0 { 1, admin_basic_setting_string, "TOS:", "tos", 6, "TBD"} , #endif }