FreeBSD/sys/netinet6/nd6.c
/*
 * Calculates new isRouter value based on provided parameters and
 * returns it.
 */
Calculates new isRouter value based on provided parameters and
returns it.
Calculates new isRouter value based on provided parameters and returns it .
static int
nd6_is_router(int type, int code, int is_new, int old_addr, int new_addr,
    int ln_router)
{
	switch (type & 0xff) {
	case ND_NEIGHBOR_SOLICIT:
		if (is_new)					
			ln_router = 0;
		break;
	case ND_REDIRECT:
		if (code == ND_REDIRECT_ROUTER)
			ln_router = 1;
		else {
			if (is_new)				
				ln_router = 0;
		}
		break;
	case ND_ROUTER_SOLICIT:
		ln_router = 0;
		break;
	case ND_ROUTER_ADVERT:
		if ((!is_new && (old_addr || new_addr)) ||	
		    (is_new && new_addr)) {			
			ln_router = 1;
		}
		break;
	}
	return (ln_router);
}
static int nd6_is_router ( int type , int code , int is_new , int old_addr , int new_addr , int ln_router ) { switch ( type & 0xff ) { case ND_NEIGHBOR_SOLICIT : if ( is_new ) ln_router = 0 ; break ; case ND_REDIRECT : if ( code == ND_REDIRECT_ROUTER ) ln_router = 1 ; else { if ( is_new ) ln_router = 0 ; } break ; case ND_ROUTER_SOLICIT : ln_router = 0 ; break ; case ND_ROUTER_ADVERT : if ( ( ! is_new && ( old_addr || new_addr ) ) || ( is_new && new_addr ) ) { ln_router = 1 ; } break ; } return ( ln_router ) ; }
Calculates new isRouter value based on provided parameters and
 returns it.
Calculates new isRouter value based on provided parameters and returns it .
/*
	 * ICMP6 type dependent behavior.
	 *
	 * NS: clear IsRouter if new entry
	 * RS: clear IsRouter
	 * RA: set IsRouter if there's lladdr
	 * redir: clear IsRouter if new entry
	 *
	 * RA case, (1):
	 * The spec says that we must set IsRouter in the following cases:
	 * - If lladdr exist, set IsRouter.  This means (1-5).
	 * - If it is old entry (!newentry), set IsRouter.  This means (7).
	 * So, based on the spec, in (1-5) and (7) cases we must set IsRouter.
	 * A quetion arises for (1) case.  (1) case has no lladdr in the
	 * neighbor cache, this is similar to (6).
	 * This case is rare but we figured that we MUST NOT set IsRouter.
	 *
	 *   is_new  old_addr new_addr 	    NS  RS  RA	redir
	 *							D R
	 *	0	n	n	(1)	c   ?     s
	 *	0	y	n	(2)	c   s     s
	 *	0	n	y	(3)	c   s     s
	 *	0	y	y	(4)	c   s     s
	 *	0	y	y	(5)	c   s     s
	 *	1	--	n	(6) c	c	c s
	 *	1	--	y	(7) c	c   s	c s
	 *
	 *					(c=clear s=set)
	 */ /*
		 * New entry must have is_router flag cleared.
		 */ /* (6-7) */ /*
		 * If the icmp is a redirect to a better router, always set the
		 * is_router flag.  Otherwise, if the entry is newly created,
		 * clear the flag.  [RFC 2461, sec 8.3]
		 */ /* (6-7) */ /*
		 * is_router flag must always be cleared.
		 */ /*
		 * Mark an entry with lladdr as a router.
		 */ /* (2-5) */ /* (7) */