From: Martin Schwenke Date: Thu, 7 Jun 2018 21:33:32 +0000 (+1000) Subject: ctdb-common: Drop function parse_ip_mask() and supporting functions X-Git-Tag: ldb-1.5.0~158 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=77242e7631514b80a84146b2f4f232dab28d978b;p=thirdparty%2Fsamba.git ctdb-common: Drop function parse_ip_mask() and supporting functions Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs --- diff --git a/ctdb/common/system_socket.c b/ctdb/common/system_socket.c index 843e5d74816..562b2bf1aaf 100644 --- a/ctdb/common/system_socket.c +++ b/ctdb/common/system_socket.c @@ -112,141 +112,6 @@ bool ctdb_sys_have_ip(ctdb_sock_addr *_addr) return ret == 0; } -static bool parse_ipv4(const char *s, unsigned port, struct sockaddr_in *sin) -{ - sin->sin_family = AF_INET; - sin->sin_port = htons(port); - - if (inet_pton(AF_INET, s, &sin->sin_addr) != 1) { - DBG_ERR("Failed to translate %s into sin_addr\n", s); - return false; - } - -#ifdef HAVE_SOCK_SIN_LEN - sin->sin_len = sizeof(*sin); -#endif - return true; -} - -static bool parse_ipv6(const char *s, - const char *ifaces, - unsigned port, - ctdb_sock_addr *saddr) -{ - saddr->ip6.sin6_family = AF_INET6; - saddr->ip6.sin6_port = htons(port); - saddr->ip6.sin6_flowinfo = 0; - saddr->ip6.sin6_scope_id = 0; - - if (inet_pton(AF_INET6, s, &saddr->ip6.sin6_addr) != 1) { - DBG_ERR("Failed to translate %s into sin6_addr\n", s); - return false; - } - - if (ifaces && IN6_IS_ADDR_LINKLOCAL(&saddr->ip6.sin6_addr)) { - if (strchr(ifaces, ',')) { - DBG_ERR("Link local address %s " - "is specified for multiple ifaces %s\n", - s, ifaces); - return false; - } - saddr->ip6.sin6_scope_id = if_nametoindex(ifaces); - } - -#ifdef HAVE_SOCK_SIN6_LEN - saddr->ip6.sin6_len = sizeof(*saddr); -#endif - return true; -} - -static bool parse_ip(const char *addr, - const char *ifaces, - unsigned port, - ctdb_sock_addr *saddr) -{ - char *p; - bool ret; - - ZERO_STRUCTP(saddr); /* valgrind :-) */ - - /* - * IPv4 or IPv6 address? - * - * Use rindex() because we need the right-most ':' below for - * IPv4-mapped IPv6 addresses anyway... - */ - p = rindex(addr, ':'); - if (p == NULL) { - ret = parse_ipv4(addr, port, &saddr->ip); - } else { - uint8_t ipv4_mapped_prefix[12] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff - }; - - ret = parse_ipv6(addr, ifaces, port, saddr); - if (! ret) { - return ret; - } - - /* - * Check for IPv4-mapped IPv6 address - * (e.g. ::ffff:192.0.2.128) - reparse as IPv4 if - * necessary - */ - if (memcmp(&saddr->ip6.sin6_addr.s6_addr[0], - ipv4_mapped_prefix, - sizeof(ipv4_mapped_prefix)) == 0) { - /* Reparse as IPv4 */ - ret = parse_ipv4(p+1, port, &saddr->ip); - } - } - - return ret; -} - -/* - * Parse an ip/mask pair - */ -bool parse_ip_mask(const char *str, - const char *ifaces, - ctdb_sock_addr *addr, - unsigned *mask) -{ - char *p; - char s[64]; /* Much longer than INET6_ADDRSTRLEN */ - char *endp = NULL; - ssize_t len; - bool ret; - - ZERO_STRUCT(*addr); - - len = strlcpy(s, str, sizeof(s)); - if (len >= sizeof(s)) { - DBG_ERR("Address %s is unreasonably long\n", str); - return false; - } - - p = rindex(s, '/'); - if (p == NULL) { - DBG_ERR("Address %s does not contain a mask\n", s); - return false; - } - - *mask = strtoul(p+1, &endp, 10); - if (endp == NULL || *endp != 0) { - /* trailing garbage */ - DBG_ERR("Trailing garbage after the mask in %s\n", s); - return false; - } - *p = 0; - - - /* now is this a ipv4 or ipv6 address ?*/ - ret = parse_ip(s, ifaces, 0, addr); - - return ret; -} - /* * simple TCP checksum - assumes data is multiple of 2 bytes long */ diff --git a/ctdb/common/system_socket.h b/ctdb/common/system_socket.h index eb2c6f7b6ae..065c53cb2a8 100644 --- a/ctdb/common/system_socket.h +++ b/ctdb/common/system_socket.h @@ -24,11 +24,6 @@ bool ctdb_sys_have_ip(ctdb_sock_addr *addr); -bool parse_ip_mask(const char *str, - const char *ifaces, - ctdb_sock_addr *addr, - unsigned *mask); - int ctdb_sys_send_arp(const ctdb_sock_addr *addr, const char *iface); int ctdb_sys_send_tcp(const ctdb_sock_addr *dest,