iface->self->dr.s_addr = dr->addr.s_addr; if (bdr) iface->self->bdr.s_addr = dr->addr.s_addr;
if_act_elect(struct iface *iface){	struct nbr	*nbr, *bdr = NULL, *dr = NULL;	int		 round = 0;	int		 changed = 0;	int		 old_state;	char		 b1[16], b2[16], b3[16], b4[16];	log_debug("if_act_elect: interface %s", iface->name);start:	/* elect backup designated router */	LIST_FOREACH(nbr, &iface->nbr_list, entry) {		if (nbr->priority == 0 || nbr == dr ||	/* not electable */		    nbr->state & NBR_STA_DOWN ||	/* not available */		    nbr->dr.s_addr == nbr->addr.s_addr)	/* don't elect DR */			continue;		if (bdr != NULL) {			if (nbr->bdr.s_addr == nbr->addr.s_addr) {				if (bdr->bdr.s_addr == bdr->addr.s_addr)					bdr = if_elect(bdr, nbr);				else					bdr = nbr;			} else if (bdr->bdr.s_addr != bdr->addr.s_addr)					bdr = if_elect(bdr, nbr);		} else			bdr = nbr;	}	log_debug("if_act_elect: bdr %s", bdr ?	    inet_ntop(AF_INET, &bdr->addr, b4, sizeof(b4)) : "none");	/* elect designated router */	LIST_FOREACH(nbr, &iface->nbr_list, entry) {		if (nbr->priority == 0 || nbr->state & NBR_STA_DOWN ||		    (nbr != dr && nbr->dr.s_addr != nbr->addr.s_addr))			/* only DR may be elected check priority too */			continue;		if (dr == NULL || bdr == NULL)			dr = nbr;		else			dr = if_elect(dr, nbr);	}	log_debug("if_act_elect: dr %s", dr ?	    inet_ntop(AF_INET, &dr->addr, b4, sizeof(b4)) : "none");	if (dr == NULL) {		/* no designate router found use backup DR */		dr = bdr;		bdr = NULL;	}	/*	 * if we are involved in the election (e.g. new DR or no	 * longer BDR) redo the election	 */	if (round == 0 &&	    ((iface->self == dr && iface->self != iface->dr) ||	    (iface->self != dr && iface->self == iface->dr) ||	    (iface->self == bdr && iface->self != iface->bdr) ||	    (iface->self != bdr && iface->self == iface->bdr))) {		log_debug("if_act_elect: round two");		round = 1;		goto start;	}	log_debug("if_act_elect: interface %s old dr %s new dr %s, "	    "old bdr %s new bdr %s", iface->name,	    iface->dr ? inet_ntop(AF_INET, &iface->dr->addr, b1, sizeof(b1)) :	    "none", dr ? inet_ntop(AF_INET, &dr->addr, b2, sizeof(b2)) : "none",	    iface->bdr ? inet_ntop(AF_INET, &iface->bdr->addr, b3, sizeof(b3)) :	    "none", bdr ? inet_ntop(AF_INET, &bdr->addr, b4, sizeof(b4)) :	    "none");	/*	 * After the second round still DR or BDR change state to DR or BDR,	 * etc.	 */	old_state = iface->state;	if (dr == iface->self)		iface->state = IF_STA_DR;	else if (bdr == iface->self)		iface->state = IF_STA_BACKUP;	else		iface->state = IF_STA_DROTHER;	/* TODO if iface is NBMA send all non eligible neighbors event Start */	/*	 * if DR or BDR changed issue a AdjOK? event for all neighbors > 2-Way	 */	if (iface->dr != dr || iface->bdr != bdr)		changed = 1;	iface->dr = dr;	iface->bdr = bdr;	if (changed) {		LIST_FOREACH(nbr, &iface->nbr_list, entry) {			if (nbr->state & NBR_STA_BIDIR)				nbr_fsm(nbr, NBR_EVT_ADJ_OK);		}		orig_rtr_lsa(iface->area);		if (iface->state & IF_STA_DR || old_state & IF_STA_DR)			orig_net_lsa(iface);	}	if (if_start_hello_timer(iface)) {		log_warnx("if_act_elect: cannot schedule hello_timer");		return (-1);	}	return (0);}