Dr. Werner Fink 2014-02-26 15:16:45 +00:00 committed by Git OBS Bridge
parent 8e129fe3f6
commit 7853b47c16

View File

@ -66,140 +66,140 @@ NFS share is added as "After=" dependency to the <nfs-share-mount-point>.mount.
+ +
+_pure_ static unsigned int mask2prefix(const void* ipv6) +_pure_ static unsigned int mask2prefix(const void* ipv6)
+{ +{
+ unsigned int nippels = 0; + unsigned int nippels = 0;
+ unsigned int i; + unsigned int i;
+ +
+ assert(ipv6); + assert(ipv6);
+ +
+ for (i = 0; i < sizeof(struct in6_addr); i++) { + for (i = 0; i < sizeof(struct in6_addr); i++) {
+ uint8_t byte = ((const uint8_t*)ipv6)[i]; + uint8_t byte = ((const uint8_t*)ipv6)[i];
+ if (byte == 0xFF) { + if (byte == 0xFF) {
+ nippels += sizeof(uint8_t); + nippels += sizeof(uint8_t);
+ continue; + continue;
+ } + }
+ while (byte & 0x80) { + while (byte & 0x80) {
+ nippels++; + nippels++;
+ byte <<= 1; + byte <<= 1;
+ } + }
+ break; + break;
+ } + }
+ +
+ return nippels; + return nippels;
+} +}
+ +
+static void netmask(unsigned int prefix, const void* in6, void* out6) +static void netmask(unsigned int prefix, const void* in6, void* out6)
+{ +{
+ unsigned int nippels; + unsigned int nippels;
+ unsigned int i; + unsigned int i;
+ +
+ assert(in6); + assert(in6);
+ assert(out6); + assert(out6);
+ +
+ for (i = 0; i < sizeof(struct in6_addr); i++) { + for (i = 0; i < sizeof(struct in6_addr); i++) {
+ nippels = (prefix < sizeof(uint8_t)) ? prefix : sizeof(uint8_t); + nippels = (prefix < sizeof(uint8_t)) ? prefix : sizeof(uint8_t);
+ ((uint8_t*)out6)[i] = ((const uint8_t*)in6)[i] & (0xFF00>>nippels); + ((uint8_t*)out6)[i] = ((const uint8_t*)in6)[i] & (0xFF00>>nippels);
+ prefix -= nippels; + prefix -= nippels;
+ } + }
+} +}
+ +
+char *host2iface(const char *ip) +char *host2iface(const char *ip)
+{ +{
+ const struct ifaddrs *ifa; + const struct ifaddrs *ifa;
+ uint32_t ip4 = 0; + uint32_t ip4 = 0;
+ char *ret = NULL; + char *ret = NULL;
+ struct search { + struct search {
+ union { + union {
+ struct in_addr addr; + struct in_addr addr;
+ struct in6_addr addr6; + struct in6_addr addr6;
+ }; + };
+ int family; + int family;
+ } host; + } host;
+ int r; + int r;
+ +
+ if (!ifa_list && (getifaddrs(&ifa_list) < 0)) { + if (!ifa_list && (getifaddrs(&ifa_list) < 0)) {
+ log_oom(); + log_oom();
+ goto err; + goto err;
+ } + }
+ +
+ if (strchr(ip, ':')) { + if (strchr(ip, ':')) {
+ r = inet_pton(AF_INET6, ip, &host.addr6); + r = inet_pton(AF_INET6, ip, &host.addr6);
+ host.family = AF_INET6; + host.family = AF_INET6;
+ } else { + } else {
+ r = inet_pton(AF_INET, ip, &host.addr); + r = inet_pton(AF_INET, ip, &host.addr);
+ host.family = AF_INET; + host.family = AF_INET;
+ } + }
+ +
+ if (r < 0) { + if (r < 0) {
+ log_error("Failed to convert IP address %s from text to binary: %m", ip); + log_error("Failed to convert IP address %s from text to binary: %m", ip);
+ goto err; + goto err;
+ } + }
+ +
+ for (ifa = ifa_list; ifa != NULL; ifa = ifa->ifa_next) { + for (ifa = ifa_list; ifa != NULL; ifa = ifa->ifa_next) {
+ +
+ if (!ifa->ifa_addr) + if (!ifa->ifa_addr)
+ continue; + continue;
+ if (ifa->ifa_flags & IFF_POINTOPOINT) + if (ifa->ifa_flags & IFF_POINTOPOINT)
+ continue; + continue;
+ if (!ifa->ifa_addr) + if (!ifa->ifa_addr)
+ continue; + continue;
+ if (!ifa->ifa_netmask) + if (!ifa->ifa_netmask)
+ continue; + continue;
+ +
+ if (ifa->ifa_addr->sa_family == AF_INET) { + if (ifa->ifa_addr->sa_family == AF_INET) {
+ uint32_t addr, dest, mask; + uint32_t addr, dest, mask;
+ +
+ if (host.family != AF_INET) + if (host.family != AF_INET)
+ continue; + continue;
+ if (!ifa->ifa_broadaddr) + if (!ifa->ifa_broadaddr)
+ continue; + continue;
+ +
+ if (!ip4) + if (!ip4)
+ ip4 = (uint32_t)ntohl(host.addr.s_addr); + ip4 = (uint32_t)ntohl(host.addr.s_addr);
+ +
+ addr = (uint32_t)ntohl(((struct sockaddr_in*)ifa->ifa_addr)->sin_addr.s_addr); + addr = (uint32_t)ntohl(((struct sockaddr_in*)ifa->ifa_addr)->sin_addr.s_addr);
+ if ((addr & 0xFF000000) == 0x7F000000) /* IPV4 loopback */ + if ((addr & 0xFF000000) == 0x7F000000) /* IPV4 loopback */
+ continue; + continue;
+ +
+ mask = (uint32_t)ntohl(((struct sockaddr_in*)ifa->ifa_netmask)->sin_addr.s_addr); + mask = (uint32_t)ntohl(((struct sockaddr_in*)ifa->ifa_netmask)->sin_addr.s_addr);
+ dest = (uint32_t)ntohl(((struct sockaddr_in*)ifa->ifa_broadaddr)->sin_addr.s_addr); + dest = (uint32_t)ntohl(((struct sockaddr_in*)ifa->ifa_broadaddr)->sin_addr.s_addr);
+ if ((ip4 & mask) != (dest & mask)) + if ((ip4 & mask) != (dest & mask))
+ continue; + continue;
+ +
+ ret = ifa->ifa_name; + ret = ifa->ifa_name;
+ break; + break;
+ } else if (ifa->ifa_addr->sa_family == AF_INET6) { + } else if (ifa->ifa_addr->sa_family == AF_INET6) {
+ struct in6_addr *addr, *mask, dest, ip6; + struct in6_addr *addr, *mask, dest, ip6;
+ unsigned int prefix; + unsigned int prefix;
+ +
+ if (host.family != AF_INET6) + if (host.family != AF_INET6)
+ continue; + continue;
+ +
+ addr = &((struct sockaddr_in6*)ifa->ifa_addr)->sin6_addr; + addr = &((struct sockaddr_in6*)ifa->ifa_addr)->sin6_addr;
+ mask = &((struct sockaddr_in6*)ifa->ifa_netmask)->sin6_addr; + mask = &((struct sockaddr_in6*)ifa->ifa_netmask)->sin6_addr;
+ prefix = mask2prefix(mask); + prefix = mask2prefix(mask);
+ +
+ netmask(prefix, addr, &dest); + netmask(prefix, addr, &dest);
+ netmask(prefix, &host.addr6, &ip6); + netmask(prefix, &host.addr6, &ip6);
+ +
+ if (memcmp(&dest, &ip6, sizeof(struct in6_addr)) != 0) + if (memcmp(&dest, &ip6, sizeof(struct in6_addr)) != 0)
+ continue; + continue;
+ +
+ ret = ifa->ifa_name; + ret = ifa->ifa_name;
+ break; + break;
+ } + }
+ } + }
+err: +err:
+ return ret; + return ret;
+} +}
+ +
+void freeroutes(void) +void freeroutes(void)
+{ +{
+ if (ifa_list) + if (ifa_list)
+ freeifaddrs(ifa_list); + freeifaddrs(ifa_list);
+ ifa_list = NULL; + ifa_list = NULL;
+} +}
--- systemd-208/src/core/mount-iface.h --- systemd-208/src/core/mount-iface.h
+++ systemd-208/src/core/mount-iface.h 2014-02-26 11:08:19.797906189 +0100 +++ systemd-208/src/core/mount-iface.h 2014-02-26 11:08:19.797906189 +0100
@@ -0,0 +1,25 @@ @@ -0,0 +1,25 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+ +