struct ospf_neighbor * ospf_elect_bdr (struct ospf_interface *oi, struct list *el_list) { struct list *bdr_list, *no_dr_list; struct listnode *node; struct ospf_neighbor *nbr, *bdr = NULL; bdr_list = list_new (); no_dr_list = list_new (); /* Add neighbors to the list. */ for (node = listhead (el_list); node; nextnode (node)) { nbr = getdata (node); /* neighbor declared to be DR. */ if (NBR_IS_DR (nbr)) continue; /* neighbor declared to be BDR. */ if (NBR_IS_BDR (nbr)) listnode_add (bdr_list, nbr); listnode_add (no_dr_list, nbr); } /* Elect Backup Designated Router. */ if (listcount (bdr_list) > 0) bdr = ospf_dr_election_sub (bdr_list); else bdr = ospf_dr_election_sub (no_dr_list); /* Set BDR to interface. */ if (bdr) { BDR (oi) = bdr->address.u.prefix4; bdr->bd_router = bdr->address.u.prefix4; } else BDR (oi).s_addr = 0; list_delete (bdr_list); list_delete (no_dr_list); return bdr; }
struct ospf_neighbor * ospf_elect_dr (struct ospf_interface *oi, struct list *el_list) { struct list *dr_list; struct listnode *node; struct ospf_neighbor *nbr, *dr = NULL, *bdr = NULL; dr_list = list_new (); /* Add neighbors to the list. */ for (node = listhead (el_list); node; nextnode (node)) { nbr = getdata (node); /* neighbor declared to be DR. */ if (NBR_IS_DR (nbr)) listnode_add (dr_list, nbr); /* Preserve neighbor BDR. */ if (IPV4_ADDR_SAME (&BDR (oi), &nbr->address.u.prefix4)) bdr = nbr; } /* Elect Designated Router. */ if (listcount (dr_list) > 0) dr = ospf_dr_election_sub (dr_list); else dr = bdr; /* Set DR to interface. */ if (dr) { DR (oi) = dr->address.u.prefix4; dr->d_router = dr->address.u.prefix4; } else DR (oi).s_addr = 0; list_delete (dr_list); return dr; }
/* Do the LSA acking specified in table 19, Section 13.5, row 2 * This get called from ospf_flood_out_interface. Declared inline * for speed. */ static void ospf_flood_delayed_lsa_ack (struct ospf_neighbor *inbr, struct ospf_lsa *lsa) { /* LSA is more recent than database copy, but was not flooded back out receiving interface. Delayed acknowledgment sent. If interface is in Backup state delayed acknowledgment sent only if advertisement received from Designated Router, otherwise do nothing See RFC 2328 Section 13.5 */ /* Whether LSA is more recent or not, and whether this is in response to the LSA being sent out recieving interface has been worked out previously */ /* Deal with router as BDR */ if (inbr->oi->state == ISM_Backup && ! NBR_IS_DR (inbr)) return; /* Schedule a delayed LSA Ack to be sent */ listnode_add (inbr->oi->ls_ack, ospf_lsa_lock (lsa)); /* delayed LSA Ack */ }