Index: icmp6.c
===================================================================
RCS file: /cvsroot/src/sys/netinet6/icmp6.c,v
retrieving revision 1.244
diff -u -r1.244 icmp6.c
--- icmp6.c	9 Mar 2020 21:20:56 -0000	1.244
+++ icmp6.c	13 Apr 2020 12:39:56 -0000
@@ -806,6 +806,7 @@
 
 	case ND_ROUTER_ADVERT:
 		icmp6_ifstat_inc(rcvif, ifs6_in_routeradvert);
+		printf("_icmp6_input: ND_ROUTER_ADVERT\n");
 		if (code != 0)
 			goto badcode;
 		if (icmp6len < sizeof(struct nd_router_advert))
Index: nd6_rtr.c
===================================================================
RCS file: /cvsroot/src/sys/netinet6/nd6_rtr.c,v
retrieving revision 1.147
diff -u -r1.147 nd6_rtr.c
--- nd6_rtr.c	27 Dec 2019 10:17:56 -0000	1.147
+++ nd6_rtr.c	13 Apr 2020 12:39:57 -0000
@@ -236,11 +236,16 @@
 	struct psref psref;
 	char ip6buf[INET6_ADDRSTRLEN], ip6buf2[INET6_ADDRSTRLEN];
 
+	printf("nd6_ra_input: entered\n");
+
 	ifp = m_get_rcvif_psref(m, &psref);
 	if (ifp == NULL)
 		goto freeit;
 
 	ndi = ND_IFINFO(ifp);
+
+	printf("nd6_ra_input: src %s\n", IN6_PRINT(ip6buf, &saddr6));
+
 	/*
 	 * We only accept RAs when the system-wide variable allows the
 	 * acceptance, and the per-interface variable allows RAs on the
@@ -442,11 +447,13 @@
     }
 
  freeit:
+	printf("nd6_ra_input: freeit\n");
 	m_put_rcvif_psref(ifp, &psref);
 	m_freem(m);
 	return;
 
  bad:
+	printf("nd6_ra_input: bad\n");
 	ICMP6_STATINC(ICMP6_STAT_BADRA);
 	m_put_rcvif_psref(ifp, &psref);
 	m_freem(m);
@@ -484,8 +491,10 @@
 #endif
 	error = rtrequest_newmsg(RTM_ADD, &def.sa, &gate.sa, &mask.sa,
 	    RTF_GATEWAY);
+	printf("defrouter_addreq: error = %d\n", error);
 	if (error == 0) {
 		nd6_numroutes++;
+		printf("defrouter_addreq: nd6_numroutes = %d\n", nd6_numroutes);
 		newdr->installed = 1;
 	}
 #ifndef NET_MPSAFE
@@ -647,6 +656,9 @@
 {
 	struct nd_ifinfo *ndi;
 	struct nd_defrouter *dr, *selected_dr = NULL, *installed_dr = NULL;
+	char ip6buf[INET6_ADDRSTRLEN];
+
+	printf("nd6_defrouter_select: entered\n");
 
 	ND6_ASSERT_WLOCK();
 
@@ -674,14 +686,23 @@
 	 * We just pick up the first reachable one (if any), assuming that
 	 * the ordering rule of the list described in defrtrlist_update().
 	 */
+	printf("nd6_defrouter_select: search\n");
 	ND_DEFROUTER_LIST_FOREACH(dr) {
+		bool dr_if_accepts_rtadv;
+		bool dr_is_llinfo_probreach;
+
 		ndi = ND_IFINFO(dr->ifp);
-		if (nd6_accepts_rtadv(ndi))
-			continue;
+		dr_if_accepts_rtadv = nd6_accepts_rtadv(ndi);
 
-		if (selected_dr == NULL &&
-		    nd6_is_llinfo_probreach(dr))
-			selected_dr = dr;
+		dr_is_llinfo_probreach = nd6_is_llinfo_probreach(dr);
+
+		printf("nd6_defrouter_select: - %s (inst = %d / reach = %d) on %s (accept_rtadv = %d)\n",
+		    IN6_PRINT(ip6buf, &dr->rtaddr),
+		    dr->installed,
+		    dr_is_llinfo_probreach,
+		    if_name(dr->ifp),
+		    dr_if_accepts_rtadv
+		);
 
 		if (dr->installed && !installed_dr)
 			installed_dr = dr;
@@ -690,6 +711,18 @@
 			log(LOG_ERR, "nd6_defrouter_select: more than one router"
 			    " is installed\n");
 		}
+
+		/* if (!nd6_accepts_rtadv(ndi)) */
+		if (!dr_if_accepts_rtadv)
+			continue;
+
+		if (selected_dr == NULL &&
+		    /* nd6_is_llinfo_probreach(dr) */
+		    dr_is_llinfo_probreach
+		    ) {
+			printf("nd6_defrouter_select:   selected\n");
+			selected_dr = dr;
+		}
 	}
 	/*
 	 * If none of the default routers was found to be reachable,
@@ -701,27 +734,48 @@
 	 */
 	if (selected_dr == NULL) {
 		if (installed_dr == NULL ||
-		    ND_DEFROUTER_LIST_NEXT(installed_dr) == NULL)
+		    ND_DEFROUTER_LIST_NEXT(installed_dr) == NULL) {
+			printf("nd6_defrouter_select: selecting first\n");
 			selected_dr = ND_DEFROUTER_LIST_FIRST();
-		else
+		} else {
+			printf("nd6_defrouter_select: selecting next after installed\n");
 			selected_dr = ND_DEFROUTER_LIST_NEXT(installed_dr);
+		}
 	} else if (installed_dr &&
 	    nd6_is_llinfo_probreach(installed_dr) &&
 	    rtpref(selected_dr) <= rtpref(installed_dr)) {
+		printf("nd6_defrouter_select: selecting installed\n");
 		selected_dr = installed_dr;
 	}
 
+	if (installed_dr)
+	    printf("nd6_defrouter_select: installed router is %s on %s\n",
+		IN6_PRINT(ip6buf, &installed_dr->rtaddr),
+		if_name(installed_dr->ifp)
+	    );
+	if (selected_dr)
+	    printf("nd6_defrouter_select: selected  router is %s on %s\n",
+		IN6_PRINT(ip6buf, &selected_dr->rtaddr),
+		if_name(selected_dr->ifp)
+	    );
+
 	/*
 	 * If the selected router is different than the installed one,
 	 * remove the installed router and install the selected one.
 	 * Note that the selected router is never NULL here.
 	 */
 	if (installed_dr != selected_dr) {
-		if (installed_dr)
+		if (installed_dr) {
+			printf("nd6_defrouter_select: delete\n");
 			defrouter_delreq(installed_dr);
+		}
+		printf("nd6_defrouter_select: install\n");
 		defrouter_addreq(selected_dr);
 	}
 
+	printf("nd6_defrouter_select: selected_dr->installed = %d\n",
+	    selected_dr->installed);
+
 	return;
 }
 
@@ -758,10 +812,13 @@
 	struct nd_defrouter *dr, *n, *ret = NULL;
 	struct in6_ifextra *ext = newdr->ifp->if_afdata[AF_INET6];
 
+	printf("defrtrlist_update: entered\n");
+
 	ND6_ASSERT_WLOCK();
 
 	if ((dr = nd6_defrouter_lookup(&newdr->rtaddr, newdr->ifp)) != NULL) {
 		/* entry exists */
+		printf("defrtrlist_update: entry exists\n");
 		if (newdr->rtlifetime == 0) {
 			nd6_defrtrlist_del(dr, ext);
 			dr = NULL;
@@ -778,6 +835,7 @@
 			 * to sort the entries.
 			 */
 			if (rtpref(newdr) == oldpref) {
+				printf("defrtrlist_update: newpref == oldpref\n");
 				ret = dr;
 				goto out;
 			}
@@ -825,6 +883,8 @@
 	 * sorted in the arriving time order.
 	 */
 
+	printf("defrtrlist_update: insert\n");
+
 	/* insert at the end of the group */
 	ND_DEFROUTER_LIST_FOREACH(dr) {
 		if (rtpref(n) > rtpref(dr))
@@ -841,6 +901,7 @@
 
 	ret = n;
 out:
+	printf("defrtrlist_update: out\n");
 	return ret;
 }