[lib] re-enable conversion of v6mapped INET6 sockunions to regular INET
* lib/sockunion.c: Re-enable conversion of v6mapped INET6 sockunions to
regular INET sockunions, which was disabled in 0df7c9, as it leads to
failures in sockunion_cmp.
(sockunion_normalise_mapped) consolidate here
(sockunion_accept) remove conversion code altogether here - no sockunion
is created
(sockunion_get{sockname,peername}) normalise newly created sockunion.
diff --git a/lib/sockunion.c b/lib/sockunion.c
index cfd3bf9..8fbe345 100644
--- a/lib/sockunion.c
+++ b/lib/sockunion.c
@@ -227,6 +227,24 @@
return XSTRDUP (MTYPE_TMP, str);
}
+/* Convert IPv4 compatible IPv6 address to IPv4 address. */
+static void
+sockunion_normalise_mapped (union sockunion *su)
+{
+ struct sockaddr_in sin;
+
+#ifdef HAVE_IPV6
+ if (su->sa.sa_family == AF_INET6
+ && IN6_IS_ADDR_V4MAPPED (&su->sin6.sin6_addr))
+ {
+ memset (&sin, 0, sizeof (struct sockaddr_in));
+ sin.sin_family = AF_INET;
+ memcpy (&sin.sin_addr, ((char *)&su->sin6.sin6_addr) + 12, 4);
+ memcpy (su, &sin, sizeof (struct sockaddr_in));
+ }
+#endif /* HAVE_IPV6 */
+}
+
/* Return socket of sockunion. */
int
sockunion_socket (union sockunion *su)
@@ -253,23 +271,6 @@
len = sizeof (union sockunion);
client_sock = accept (sock, (struct sockaddr *) su, &len);
- /* Convert IPv4 compatible IPv6 address to IPv4 address. */
-#if 0
-#ifdef HAVE_IPV6
- if (su->sa.sa_family == AF_INET6)
- {
- if (IN6_IS_ADDR_V4MAPPED (&su->sin6.sin6_addr))
- {
- struct sockaddr_in sin;
-
- memset (&sin, 0, sizeof (struct sockaddr_in));
- sin.sin_family = AF_INET;
- memcpy (&sin.sin_addr, ((char *)&su->sin6.sin6_addr) + 12, 4);
- memcpy (su, &sin, sizeof (struct sockaddr_in));
- }
- }
-#endif /* HAVE_IPV6 */
-#endif
return client_sock;
}
@@ -592,18 +593,7 @@
{
su = XCALLOC (MTYPE_SOCKUNION, sizeof (union sockunion));
memcpy (su, &name, sizeof (struct sockaddr_in6));
-
-#if 0
- if (IN6_IS_ADDR_V4MAPPED (&su->sin6.sin6_addr))
- {
- struct sockaddr_in sin;
-
- sin.sin_family = AF_INET;
- memcpy (&sin.sin_addr, ((char *)&su->sin6.sin6_addr) + 12, 4);
- sin.sin_port = su->sin6.sin6_port;
- memcpy (su, &sin, sizeof (struct sockaddr_in));
- }
-#endif
+ sockunion_normalise_mapped (su);
return su;
}
#endif /* HAVE_IPV6 */
@@ -648,17 +638,7 @@
{
su = XCALLOC (MTYPE_SOCKUNION, sizeof (union sockunion));
memcpy (su, &name, sizeof (struct sockaddr_in6));
-#if 0
- if (IN6_IS_ADDR_V4MAPPED (&su->sin6.sin6_addr))
- {
- struct sockaddr_in sin;
-
- sin.sin_family = AF_INET;
- memcpy (&sin.sin_addr, ((char *)&su->sin6.sin6_addr) + 12, 4);
- sin.sin_port = su->sin6.sin6_port;
- memcpy (su, &sin, sizeof (struct sockaddr_in));
- }
-#endif
+ sockunion_normalise_mapped (su);
return su;
}
#endif /* HAVE_IPV6 */