#include <netdb.h>
#include <errno.h>
+#include "sockaddr.h"
#include "misc.h"
#include "nfslib.h"
#include "exportfs.h"
return new;
}
-static _Bool
-addrs_match4(const struct sockaddr *sa1, const struct sockaddr *sa2)
-{
- const struct sockaddr_in *si1 = (const struct sockaddr_in *)sa1;
- const struct sockaddr_in *si2 = (const struct sockaddr_in *)sa2;
-
- return si1->sin_addr.s_addr == si2->sin_addr.s_addr;
-}
-
-static _Bool
-addrs_match(const struct sockaddr *sa1, const struct sockaddr *sa2)
-{
- if (sa1->sa_family == sa2->sa_family)
- switch (sa1->sa_family) {
- case AF_INET:
- return addrs_match4(sa1, sa2);
- }
-
- return false;
-}
-
/*
* Check each address listed in @ai against each address
* stored in @clp. Return 1 if a match is found, otherwise
for (; ai; ai = ai->ai_next)
for (i = 0; i < clp->m_naddr; i++)
- if (addrs_match(ai->ai_addr, get_addrlist(clp, i)))
+ if (nfs_compare_sockaddr(ai->ai_addr,
+ get_addrlist(clp, i)))
return 1;
return 0;
return 0;
}
+#ifdef IPV6_SUPPORTED
+static int
+check_subnet_v6(const struct sockaddr_in6 *address,
+ const struct sockaddr_in6 *mask, const struct addrinfo *ai)
+{
+ for (; ai; ai = ai->ai_next) {
+ struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)ai->ai_addr;
+
+ if (sin6->sin6_family != AF_INET6)
+ continue;
+
+ if (mask_match(address->sin6_addr.s6_addr32[0],
+ sin6->sin6_addr.s6_addr32[0],
+ mask->sin6_addr.s6_addr32[0]) &&
+ mask_match(address->sin6_addr.s6_addr32[1],
+ sin6->sin6_addr.s6_addr32[1],
+ mask->sin6_addr.s6_addr32[1]) &&
+ mask_match(address->sin6_addr.s6_addr32[2],
+ sin6->sin6_addr.s6_addr32[2],
+ mask->sin6_addr.s6_addr32[2]) &&
+ mask_match(address->sin6_addr.s6_addr32[3],
+ sin6->sin6_addr.s6_addr32[3],
+ mask->sin6_addr.s6_addr32[3]))
+ return 1;
+ }
+ return 0;
+}
+#else /* !IPV6_SUPPORTED */
+static int
+check_subnet_v6(const struct sockaddr_in6 *UNUSED(address),
+ const struct sockaddr_in6 *UNUSED(mask),
+ const struct addrinfo *UNUSED(ai))
+{
+ return 0;
+}
+#endif /* !IPV6_SUPPORTED */
+
/*
* Check each address listed in @ai against the subnetwork or
* host address stored in @clp. Return 1 if an address in @hp
case AF_INET:
return check_subnet_v4(get_addrlist_in(clp, 0),
get_addrlist_in(clp, 1), ai);
+ case AF_INET6:
+ return check_subnet_v6(get_addrlist_in6(clp, 0),
+ get_addrlist_in6(clp, 1), ai);
}
return 0;