Module Name:    src
Committed By:   ozaki-r
Date:           Mon Feb 27 08:26:53 UTC 2017

Modified Files:
        src/sys/netinet: ip_carp.c
        src/tests/net/carp: t_basic.sh

Log Message:
Make CARP on IPv6 work

It passes ATF tests but no more, no less.


To generate a diff of this commit:
cvs rdiff -u -r1.84 -r1.85 src/sys/netinet/ip_carp.c
cvs rdiff -u -r1.3 -r1.4 src/tests/net/carp/t_basic.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/netinet/ip_carp.c
diff -u src/sys/netinet/ip_carp.c:1.84 src/sys/netinet/ip_carp.c:1.85
--- src/sys/netinet/ip_carp.c:1.84	Thu Feb  2 02:52:10 2017
+++ src/sys/netinet/ip_carp.c	Mon Feb 27 08:26:53 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_carp.c,v 1.84 2017/02/02 02:52:10 ozaki-r Exp $	*/
+/*	$NetBSD: ip_carp.c,v 1.85 2017/02/27 08:26:53 ozaki-r Exp $	*/
 /*	$OpenBSD: ip_carp.c,v 1.113 2005/11/04 08:11:54 mcbride Exp $	*/
 
 /*
@@ -33,7 +33,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip_carp.c,v 1.84 2017/02/02 02:52:10 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_carp.c,v 1.85 2017/02/27 08:26:53 ozaki-r Exp $");
 
 /*
  * TODO:
@@ -252,6 +252,12 @@ carp_cksum(struct mbuf *m, int len)
 	return (in_cksum(m, len));
 }
 
+static __inline u_int16_t
+carp6_cksum(struct mbuf *m, uint32_t off, uint32_t len)
+{
+	return (in6_cksum(m, IPPROTO_CARP, off, len));
+}
+
 static void
 carp_hmac_prepare(struct carp_softc *sc)
 {
@@ -601,16 +607,13 @@ _carp6_proto_input(struct mbuf *m, int o
 		return;
 	}
 
-
 	/* verify the CARP checksum */
-	m->m_data += off;
-	if (carp_cksum(m, sizeof(*ch))) {
+	if (carp6_cksum(m, off, sizeof(*ch))) {
 		CARP_STATINC(CARP_STAT_BADSUM);
 		CARP_LOG(sc, ("checksum failed, on %s", rcvif->if_xname));
 		m_freem(m);
 		return;
 	}
-	m->m_data -= off;
 
 	carp_proto_input_c(m, ch, AF_INET6);
 	return;
@@ -1120,7 +1123,7 @@ carp_send_ad(void *v)
 		}
 	}
 #endif /* INET */
-#ifdef INET6_notyet
+#ifdef INET6
 	if (sc->sc_naddrs6) {
 		struct ip6_hdr *ip6;
 		struct ifaddr *ifa;
@@ -1161,7 +1164,7 @@ carp_send_ad(void *v)
 
 		ip6->ip6_dst.s6_addr16[0] = htons(0xff02);
 		ip6->ip6_dst.s6_addr8[15] = 0x12;
-		if (in6_setscope(&ip6->ip6_dst, sc->sc_carpdev, NULL) != 0) {
+		if (in6_setscope(&ip6->ip6_dst, &sc->sc_if, NULL) != 0) {
 			sc->sc_if.if_oerrors++;
 			m_freem(m);
 			CARP_LOG(sc, ("in6_setscope failed"));
@@ -1173,9 +1176,8 @@ carp_send_ad(void *v)
 		if (carp_prepare_ad(m, sc, ch_ptr))
 			goto retry_later;
 
-		m->m_data += sizeof(*ip6);
-		ch_ptr->carp_cksum = carp_cksum(m, len - sizeof(*ip6));
-		m->m_data -= sizeof(*ip6);
+		ch_ptr->carp_cksum = carp6_cksum(m, sizeof(*ip6),
+		    len - sizeof(*ip6));
 
 		nanotime(&sc->sc_if.if_lastchange);
 		sc->sc_if.if_opackets++;
@@ -1530,7 +1532,7 @@ carp_setrun(struct carp_softc *sc, sa_fa
 			callout_schedule(&sc->sc_md_tmo, tvtohz(&tv));
 			break;
 #endif /* INET */
-#ifdef INET6_notyet
+#ifdef INET6
 		case AF_INET6:
 			callout_schedule(&sc->sc_md6_tmo, tvtohz(&tv));
 			break;
@@ -1538,7 +1540,7 @@ carp_setrun(struct carp_softc *sc, sa_fa
 		default:
 			if (sc->sc_naddrs)
 				callout_schedule(&sc->sc_md_tmo, tvtohz(&tv));
-#ifdef INET6_notyet
+#ifdef INET6
 			if (sc->sc_naddrs6)
 				callout_schedule(&sc->sc_md6_tmo, tvtohz(&tv));
 #endif /* INET6 */

Index: src/tests/net/carp/t_basic.sh
diff -u src/tests/net/carp/t_basic.sh:1.3 src/tests/net/carp/t_basic.sh:1.4
--- src/tests/net/carp/t_basic.sh:1.3	Mon Feb 27 07:25:59 2017
+++ src/tests/net/carp/t_basic.sh	Mon Feb 27 08:26:53 2017
@@ -1,4 +1,4 @@
-#	$NetBSD: t_basic.sh,v 1.3 2017/02/27 07:25:59 ozaki-r Exp $
+#	$NetBSD: t_basic.sh,v 1.4 2017/02/27 08:26:53 ozaki-r Exp $
 #
 # Copyright (c) 2017 Internet Initiative Japan Inc.
 # All rights reserved.
@@ -273,8 +273,6 @@ test_carp6_handover()
 {
 	local op=$1
 
-	atf_expect_fail 'The implementation of CARP on IPv6 is incomplete yet.'
-
 	rump_server_start $SOCK_CLIENT netinet6
 	rump_server_start $SOCK_MASTER netinet6
 	rump_server_start $SOCK_BACKUP netinet6

Reply via email to