diff options
author | Martin Willi <martin@revosec.ch> | 2012-10-18 11:23:30 +0200 |
---|---|---|
committer | Martin Willi <martin@revosec.ch> | 2012-10-24 13:25:08 +0200 |
commit | 1efd6c6f2a126094bf375c859eea5a5f04da8be0 (patch) | |
tree | 14aef5559d96b60ffa1d18cb7999c7daf14d93f7 /src | |
parent | fd6c0c8fb499a1d99b80cea30a2e6c00bc780f05 (diff) | |
download | strongswan-1efd6c6f2a126094bf375c859eea5a5f04da8be0.tar.bz2 strongswan-1efd6c6f2a126094bf375c859eea5a5f04da8be0.tar.xz |
Make use of new CIDR string ts constructor where appropriate
Diffstat (limited to 'src')
-rw-r--r-- | src/conftest/config.c | 12 | ||||
-rw-r--r-- | src/libcharon/plugins/medcli/medcli_config.c | 24 | ||||
-rw-r--r-- | src/libcharon/plugins/stroke/stroke_config.c | 37 | ||||
-rw-r--r-- | src/libcharon/plugins/uci/uci_config.c | 24 |
4 files changed, 23 insertions, 74 deletions
diff --git a/src/conftest/config.c b/src/conftest/config.c index 6adb545c0..98f3dc433 100644 --- a/src/conftest/config.c +++ b/src/conftest/config.c @@ -143,9 +143,7 @@ static child_cfg_t *load_child_config(private_config_t *this, proposal_t *proposal; traffic_selector_t *ts; ipsec_mode_t mode = MODE_TUNNEL; - host_t *net; char *token; - int bits; u_int32_t tfc; if (settings->get_bool(settings, "configs.%s.%s.transport", @@ -189,10 +187,9 @@ static child_cfg_t *load_child_config(private_config_t *this, enumerator = enumerator_create_token(token, ",", " "); while (enumerator->enumerate(enumerator, &token)) { - net = host_create_from_subnet(token, &bits); - if (net) + ts = traffic_selector_create_from_cidr(token, 0, 0); + if (ts) { - ts = traffic_selector_create_from_subnet(net, bits, 0, 0); child_cfg->add_traffic_selector(child_cfg, TRUE, ts); } else @@ -214,10 +211,9 @@ static child_cfg_t *load_child_config(private_config_t *this, enumerator = enumerator_create_token(token, ",", " "); while (enumerator->enumerate(enumerator, &token)) { - net = host_create_from_subnet(token, &bits); - if (net) + ts = traffic_selector_create_from_cidr(token, 0, 0); + if (ts) { - ts = traffic_selector_create_from_subnet(net, bits, 0, 0); child_cfg->add_traffic_selector(child_cfg, FALSE, ts); } else diff --git a/src/libcharon/plugins/medcli/medcli_config.c b/src/libcharon/plugins/medcli/medcli_config.c index 440d4dd4e..42c158231 100644 --- a/src/libcharon/plugins/medcli/medcli_config.c +++ b/src/libcharon/plugins/medcli/medcli_config.c @@ -61,28 +61,12 @@ static traffic_selector_t *ts_from_string(char *str) { if (str) { - int netbits = 32; - host_t *net; - char *pos; + traffic_selector_t *ts; - str = strdupa(str); - pos = strchr(str, '/'); - if (pos) + ts = traffic_selector_create_from_cidr(str, 0, 0); + if (ts) { - *pos++ = '\0'; - netbits = atoi(pos); - } - else - { - if (strchr(str, ':')) - { - netbits = 128; - } - } - net = host_create_from_string(str, 0); - if (net) - { - return traffic_selector_create_from_subnet(net, netbits, 0, 0); + return ts; } } return traffic_selector_create_dynamic(0, 0, 65535); diff --git a/src/libcharon/plugins/stroke/stroke_config.c b/src/libcharon/plugins/stroke/stroke_config.c index 0d3684d6d..de3f4472e 100644 --- a/src/libcharon/plugins/stroke/stroke_config.c +++ b/src/libcharon/plugins/stroke/stroke_config.c @@ -881,10 +881,10 @@ static void add_ts(private_stroke_config_t *this, } else { - host_t *net; - if (!end->subnets) { + host_t *net; + net = host_create_from_string(end->address, 0); if (net) { @@ -895,39 +895,24 @@ static void add_ts(private_stroke_config_t *this, } else { - char *del, *start, *bits; + enumerator_t *enumerator; + char *subnet; - start = end->subnets; - do + enumerator = enumerator_create_token(end->subnets, ",", " "); + while (enumerator->enumerate(enumerator, &subnet)) { - int intbits = 0; - - del = strchr(start, ','); - if (del) - { - *del = '\0'; - } - bits = strchr(start, '/'); - if (bits) - { - *bits = '\0'; - intbits = atoi(bits + 1); - } - - net = host_create_from_string(start, 0); - if (net) + ts = traffic_selector_create_from_cidr(subnet, + end->protocol, end->port); + if (ts) { - ts = traffic_selector_create_from_subnet(net, intbits, - end->protocol, end->port); child_cfg->add_traffic_selector(child_cfg, local, ts); } else { - DBG1(DBG_CFG, "invalid subnet: %s, skipped", start); + DBG1(DBG_CFG, "invalid subnet: %s, skipped", subnet); } - start = del + 1; } - while (del); + enumerator->destroy(enumerator); } } } diff --git a/src/libcharon/plugins/uci/uci_config.c b/src/libcharon/plugins/uci/uci_config.c index 82887303f..76dce125b 100644 --- a/src/libcharon/plugins/uci/uci_config.c +++ b/src/libcharon/plugins/uci/uci_config.c @@ -87,28 +87,12 @@ static traffic_selector_t *create_ts(char *string) { if (string) { - int netbits = 32; - host_t *net; - char *pos; + traffic_selector_t *ts; - string = strdupa(string); - pos = strchr(string, '/'); - if (pos) + ts = traffic_selector_create_from_cidr(string, 0, 0); + if (ts) { - *pos++ = '\0'; - netbits = atoi(pos); - } - else - { - if (strchr(string, ':')) - { - netbits = 128; - } - } - net = host_create_from_string(string, 0); - if (net) - { - return traffic_selector_create_from_subnet(net, netbits, 0, 0); + return ts; } } return traffic_selector_create_dynamic(0, 0, 65535); |