FreeBSD/usr.sbin/rtsold/probe.c
/*
 * Probe if each router in the default router list is still alive.
 */
Probe if each router in the default router list is still alive.
Probe if each router in the default router list is still alive .
void
defrouter_probe(struct ifinfo *ifinfo)
{
	struct in6_defrouter *p, *ep;
	int ifindex, mib[4];
	char *buf, ntopbuf[INET6_ADDRSTRLEN];
	size_t l;
	ifindex = ifinfo->sdl->sdl_index;
	if (ifindex == 0)
		return;
	mib[0] = CTL_NET;
	mib[1] = PF_INET6;
	mib[2] = IPPROTO_ICMPV6;
	mib[3] = ICMPV6CTL_ND6_DRLIST;
	if (sysctl(mib, nitems(mib), NULL, &l, NULL, 0) < 0) {
		warnmsg(LOG_ERR, __func__, "sysctl(ICMPV6CTL_ND6_DRLIST): %s",
		    strerror(errno));
		return;
	}
	if (l == 0)
		return;
	buf = malloc(l);
	if (buf == NULL) {
		warnmsg(LOG_ERR, __func__, "malloc(): %s", strerror(errno));
		return;
	}
	if (sysctl(mib, nitems(mib), buf, &l, NULL, 0) < 0) {
		warnmsg(LOG_ERR, __func__, "sysctl(ICMPV6CTL_ND6_DRLIST): %s",
		    strerror(errno));
		free(buf);
		return;
	}
	ep = (struct in6_defrouter *)(void *)(buf + l);
	for (p = (struct in6_defrouter *)(void *)buf; p < ep; p++) {
		if (ifindex != p->if_index)
			continue;
		if (!IN6_IS_ADDR_LINKLOCAL(&p->rtaddr.sin6_addr)) {
			warnmsg(LOG_ERR, __func__,
			    "default router list contains a "
			    "non-link-local address(%s)",
			    inet_ntop(AF_INET6, &p->rtaddr.sin6_addr, ntopbuf,
			    INET6_ADDRSTRLEN));
			continue; 
		}
		sendprobe(&p->rtaddr.sin6_addr, ifinfo);
	}
	free(buf);
}
void defrouter_probe ( struct ifinfo * ifinfo ) { struct in6_defrouter * p , * ep ; int ifindex , mib [ 4 ] ; char * buf , ntopbuf [ INET6_ADDRSTRLEN ] ; size_t l ; ifindex = ifinfo -> sdl -> sdl_index ; if ( ifindex == 0 ) return ; mib [ 0 ] = CTL_NET ; mib [ 1 ] = PF_INET6 ; mib [ 2 ] = IPPROTO_ICMPV6 ; mib [ 3 ] = ICMPV6CTL_ND6_DRLIST ; if ( sysctl ( mib , nitems ( mib ) , NULL , & l , NULL , 0 ) < 0 ) { warnmsg ( LOG_ERR , __func__ , " " , strerror ( errno ) ) ; return ; } if ( l == 0 ) return ; buf = malloc ( l ) ; if ( buf == NULL ) { warnmsg ( LOG_ERR , __func__ , " " , strerror ( errno ) ) ; return ; } if ( sysctl ( mib , nitems ( mib ) , buf , & l , NULL , 0 ) < 0 ) { warnmsg ( LOG_ERR , __func__ , " " , strerror ( errno ) ) ; free ( buf ) ; return ; } ep = ( struct in6_defrouter * ) ( void * ) ( buf + l ) ; for ( p = ( struct in6_defrouter * ) ( void * ) buf ; p < ep ; p ++ ) { if ( ifindex != p -> if_index ) continue ; if ( ! IN6_IS_ADDR_LINKLOCAL ( & p -> rtaddr . sin6_addr ) ) { warnmsg ( LOG_ERR , __func__ , " " " " , inet_ntop ( AF_INET6 , & p -> rtaddr . sin6_addr , ntopbuf , INET6_ADDRSTRLEN ) ) ; continue ; } sendprobe ( & p -> rtaddr . sin6_addr , ifinfo ) ; } free ( buf ) ; }
Probe if each router in the default router list is still alive.
Probe if each router in the default router list is still alive .
/* ignore the address */