]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: introduce parse_ip_port (#4825)
authorSusant Sahani <ssahani@users.noreply.github.com>
Tue, 6 Dec 2016 11:21:45 +0000 (16:51 +0530)
committerLennart Poettering <lennart@poettering.net>
Tue, 6 Dec 2016 11:21:45 +0000 (12:21 +0100)
1. Listed in TODO.
2. Tree wide replace safe_atou16 with parse_ip_port incase
   it's used for ports.

TODO
src/basic/parse-util.c
src/basic/parse-util.h
src/network/netdev/vxlan.c
src/nspawn/nspawn-expose-ports.c
src/resolve/resolve-tool.c

diff --git a/TODO b/TODO
index 93f050068030ca8fa34f60375e51d5dd2de591d7..74183b5f47ee6b68cf80bda81ae0bb2f07696922 100644 (file)
--- a/TODO
+++ b/TODO
@@ -32,8 +32,6 @@ Features:
 * replace all canonicalize_file_name() invocations by chase_symlinks(), in
   particulr those where a rootdir is relevant.
 
-* add parse_ip_port() or so, that is like safe_atou16() but checks for != 0
-
 * drop nss-myhostname in favour of nss-resolve?
 
 * drop internal dlopen() based nss-dns fallback in nss-resolve, and rely on the
index c98815b9bc70f4b4a3a424ebc68af0e8b0a8a397..6e58ced6f5291758ae7acab9f9c5d0531aad73ee 100644 (file)
@@ -574,3 +574,19 @@ int parse_nice(const char *p, int *ret) {
         *ret = n;
         return 0;
 }
+
+int parse_ip_port(const char *s, uint16_t *ret) {
+        uint16_t l;
+        int r;
+
+        r = safe_atou16(s, &l);
+        if (r < 0)
+                return r;
+
+        if (l == 0)
+                return -EINVAL;
+
+        *ret = (uint16_t) l;
+
+        return 0;
+}
index 461e1cd4d8e8a34fae44c6224d65e44559bd83fd..4d132f0de5a265429f631a6eae366d1b731159d1 100644 (file)
@@ -110,3 +110,5 @@ int parse_percent_unbounded(const char *p);
 int parse_percent(const char *p);
 
 int parse_nice(const char *p, int *ret);
+
+int parse_ip_port(const char *s, uint16_t *ret);
index 10c892b0440319f788710ab5652485148becd628..231f5cb442b1563a1fe5c852721a0ef171347507 100644 (file)
@@ -252,8 +252,8 @@ int config_parse_destination_port(const char *unit,
         assert(rvalue);
         assert(data);
 
-        r = safe_atou16(rvalue, &port);
-        if (r < 0 || port <= 0) {
+        r = parse_ip_port(rvalue, &port);
+        if (r < 0) {
                 log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse VXLAN destination port '%s'.", rvalue);
                 return 0;
         }
index 86124b8779948c784a24125de3786f93831102f9..bcaf0aaeaaf8f992e5fe453c29dbbf260092766c 100644 (file)
@@ -58,17 +58,17 @@ int expose_port_parse(ExposePort **l, const char *s) {
                 memcpy(v, e, split - e);
                 v[split - e] = 0;
 
-                r = safe_atou16(v, &host_port);
-                if (r < 0 || host_port <= 0)
+                r = parse_ip_port(v, &host_port);
+                if (r < 0)
                         return -EINVAL;
 
-                r = safe_atou16(split + 1, &container_port);
+                r = parse_ip_port(split + 1, &container_port);
         } else {
-                r = safe_atou16(e, &container_port);
+                r = parse_ip_port(e, &container_port);
                 host_port = container_port;
         }
 
-        if (r < 0 || container_port <= 0)
+        if (r < 0)
                 return -EINVAL;
 
         LIST_FOREACH(ports, p, *l)
index 9d4d04220cb73075176edb2b9d6c97759e067c0f..07d9582ccb243c5742835e47aff3c420d4719fc6 100644 (file)
@@ -881,8 +881,8 @@ static int resolve_tlsa(sd_bus *bus, const char *address) {
 
         port = strrchr(address, ':');
         if (port) {
-                r = safe_atou16(port + 1, &port_num);
-                if (r < 0 || port_num == 0)
+                r = parse_ip_port(port + 1, &port_num);
+                if (r < 0)
                         return log_error_errno(r, "Invalid port \"%s\".", port + 1);
 
                 address = strndupa(address, port - address);