diff options
author | Tobias Brunner <tobias@strongswan.org> | 2012-05-15 16:20:15 +0200 |
---|---|---|
committer | Tobias Brunner <tobias@strongswan.org> | 2012-06-11 17:33:31 +0200 |
commit | 29906e0eabdcc3302b345c7f2e5c0c950f9c617e (patch) | |
tree | 5c05f93642b01c4e0992646ab8ba8b00f4004044 /src | |
parent | eca839b0a7646839f00a7a8ad1531b288e98788b (diff) | |
download | strongswan-29906e0eabdcc3302b345c7f2e5c0c950f9c617e.tar.bz2 strongswan-29906e0eabdcc3302b345c7f2e5c0c950f9c617e.tar.xz |
starter: Parse left|rightprotoport directly in confread.c.
Diffstat (limited to 'src')
-rw-r--r-- | src/starter/cmp.c | 1 | ||||
-rw-r--r-- | src/starter/confread.c | 57 | ||||
-rw-r--r-- | src/starter/confread.h | 1 |
3 files changed, 53 insertions, 6 deletions
diff --git a/src/starter/cmp.c b/src/starter/cmp.c index 68890b18a..9a1d29504 100644 --- a/src/starter/cmp.c +++ b/src/starter/cmp.c @@ -35,7 +35,6 @@ starter_cmp_end(starter_end_t *c1, starter_end_t *c2) return FALSE; VARCMP(ikeport); - VARCMP(has_port_wildcard); VARCMP(has_natip); VARCMP(modecfg); VARCMP(port); diff --git a/src/starter/confread.c b/src/starter/confread.c index b401aa744..8a4e38a55 100644 --- a/src/starter/confread.c +++ b/src/starter/confread.c @@ -19,6 +19,7 @@ #include <stdlib.h> #include <string.h> #include <assert.h> +#include <netdb.h> #include <library.h> #include <debug.h> @@ -159,9 +160,7 @@ static void load_setup(starter_config_t *cfg, config_parsed_t *cfgp) static void kw_end(starter_conn_t *conn, starter_end_t *end, kw_token_t token, kw_list_t *kw, char *conn_name, starter_config_t *cfg) { - err_t ugh = NULL; bool assigned = FALSE; - bool has_port_wildcard; /* set if port is %any */ char *name = kw->entry->name; char *value = kw->value; @@ -262,9 +261,59 @@ static void kw_end(starter_conn_t *conn, starter_end_t *end, kw_token_t token, switch (token) { case KW_PROTOPORT: - ugh = ttoprotoport(value, 0, &end->protocol, &end->port, &has_port_wildcard); - end->has_port_wildcard = has_port_wildcard; + { + struct protoent *proto; + struct servent *svc; + char *pos, *port = ""; + long int p; + + pos = strchr(value, '/'); + if (pos) + { /* protocol/port */ + *pos = '\0'; + port = pos + 1; + } + + proto = getprotobyname(value); + if (proto) + { + end->protocol = proto->p_proto; + } + else + { + p = strtol(value, &pos, 0); + if ((*value && *pos) || p < 0 || p > 0xff) + { + DBG1(DBG_APP, "# bad protocol: %s=%s", name, value); + goto err; + } + end->protocol = (u_int8_t)p; + } + + if (streq(port, "%any")) + { + end->port = 0; + } + else + { + svc = getservbyname(port, NULL); + if (svc) + { + end->port = ntohs(svc->s_port); + } + else + { + p = strtol(port, &pos, 0); + if ((*port && *pos) || p < 0 || p > 0xffff) + { + DBG1(DBG_APP, "# bad port: %s=%s", name, value); + goto err; + } + end->port = (u_int16_t)p; + } + } break; + } case KW_NATIP: { host_t *host; diff --git a/src/starter/confread.h b/src/starter/confread.h index 04a8e36bb..2d8534ea9 100644 --- a/src/starter/confread.h +++ b/src/starter/confread.h @@ -73,7 +73,6 @@ struct starter_end { char *host; u_int ikeport; char *subnet; - bool has_port_wildcard; bool has_natip; bool modecfg; certpolicy_t sendcert; |