static int ripng_if_down (struct interface *ifp) { struct route_node *rp; struct ripng_info *rinfo; struct ripng_interface *ri; struct list *list = NULL; struct listnode *listnode = NULL, *nextnode = NULL; if (ripng) for (rp = route_top (ripng->table); rp; rp = route_next (rp)) if ((list = rp->info) != NULL) for (ALL_LIST_ELEMENTS (list, listnode, nextnode, rinfo)) if (rinfo->ifindex == ifp->ifindex) ripng_ecmp_delete (rinfo); ri = ifp->info; if (ri->running) { if (IS_RIPNG_DEBUG_EVENT) zlog_debug ("turn off %s", ifp->name); /* Leave from multicast group. */ ripng_multicast_leave (ifp); ri->running = 0; } return 0; }
struct ospf_area_range * ospf_area_range_lookup_next (struct ospf_area *area, struct in_addr *range_net, int first) { struct route_node *rn; struct prefix_ipv4 p; struct ospf_area_range *find; p.family = AF_INET; p.prefixlen = IPV4_MAX_BITLEN; p.prefix = *range_net; if (first) rn = route_top (area->ranges); else { rn = route_node_get (area->ranges, (struct prefix *) &p); rn = route_next (rn); } for (; rn; rn = route_next (rn)) if (rn->info) break; if (rn && rn->info) { find = rn->info; *range_net = rn->p.u.prefix4; route_unlock_node (rn); return find; } return NULL; }
void ospf_abr_prepare_aggregates (struct ospf *ospf) { listnode node; struct route_node *rn; struct ospf_area_range *range; if (IS_DEBUG_OSPF_EVENT) zlog_info ("ospf_abr_prepare_aggregates(): Start"); for (node = listhead (ospf->areas); node; nextnode (node)) { struct ospf_area *area = getdata (node); for (rn = route_top (area->ranges); rn; rn = route_next (rn)) if ((range = rn->info) != NULL) { range->cost = 0; range->specifics = 0; } } if (IS_DEBUG_OSPF_EVENT) zlog_info ("ospf_abr_prepare_aggregates(): Stop"); }
int zebra_cleanup_rnh_client (vrf_id_t vrfid, int family, struct zserv *client) { struct route_table *ntable; struct route_node *nrn; struct rnh *rnh; ntable = lookup_rnh_table(vrfid, family); if (!ntable) { zlog_debug("cleanup_rnh_client: rnh table not found\n"); return -1; } for (nrn = route_top (ntable); nrn; nrn = route_next (nrn)) { if (!nrn->info) continue; rnh = nrn->info; if (IS_ZEBRA_DEBUG_NHT) { char bufn[INET6_ADDRSTRLEN]; prefix2str(&nrn->p, bufn, INET6_ADDRSTRLEN); zlog_debug("rnh %s - cleaning state for client %s", bufn, zebra_route_string(client->proto)); } zebra_remove_rnh_client(rnh, client); } return 1; }
int zebra_dispatch_rnh_table (vrf_id_t vrfid, int family, struct zserv *client) { struct route_table *ntable; struct route_node *nrn; struct rnh *rnh; ntable = lookup_rnh_table(vrfid, family); if (!ntable) { zlog_debug("dispatch_rnh_table: rnh table not found\n"); return -1; } for (nrn = route_top (ntable); nrn; nrn = route_next (nrn)) { if (!nrn->info) continue; rnh = nrn->info; if (IS_ZEBRA_DEBUG_NHT) { char bufn[INET6_ADDRSTRLEN]; prefix2str(&nrn->p, bufn, INET6_ADDRSTRLEN); zlog_debug("rnh %s - sending nexthop %s event to client %s", bufn, rnh->state ? "reachable" : "unreachable", zebra_route_string(client->proto)); } send_client(rnh, client, vrfid); } return 1; }
static int ospf_interface_delete (int command, struct zclient *zclient, zebra_size_t length) { struct interface *ifp; struct stream *s; struct route_node *rn; s = zclient->ibuf; /* zebra_interface_state_read() updates interface structure in iflist */ ifp = zebra_interface_state_read (s); if (ifp == NULL) return 0; if (if_is_up (ifp)) zlog_warn ("Zebra: got delete of %s, but interface is still up", ifp->name); if (IS_DEBUG_OSPF (zebra, ZEBRA_INTERFACE)) zlog_debug ("Zebra: interface delete %s index %d flags %llx metric %d mtu %d", ifp->name, ifp->ifindex, (unsigned long long)ifp->flags, ifp->metric, ifp->mtu); #ifdef HAVE_SNMP ospf_snmp_if_delete (ifp); #endif /* HAVE_SNMP */ for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn)) if (rn->info) ospf_if_free ((struct ospf_interface *) rn->info); ifp->ifindex = IFINDEX_INTERNAL; return 0; }
static int ospf_interface_state_down (int command, struct zclient *zclient, zebra_size_t length) { struct interface *ifp; struct ospf_interface *oi; struct route_node *node; ifp = zebra_interface_state_read (zclient->ibuf); if (ifp == NULL) return 0; if (IS_DEBUG_OSPF (zebra, ZEBRA_INTERFACE)) zlog_debug ("Zebra: Interface[%s] state change to down.", ifp->name); for (node = route_top (IF_OIFS (ifp)); node; node = route_next (node)) { if ((oi = node->info) == NULL) continue; ospf_if_down (oi); } return 0; }
/* Runs under child process. */ void bgp_dump_routes_func (int afi) { struct stream *obuf; struct route_node *rn; struct bgp_info *info; struct bgp *bgp; struct route_table *table; unsigned int seq = 0; obuf = bgp_dump_obuf; bgp = bgp_get_default (); if (!bgp) return; if (bgp_dump_routes.fp == NULL) return; /* Walk down each BGP route. */ table = bgp->rib[afi][SAFI_UNICAST]; for (rn = route_top (table); rn; rn = route_next (rn)) for (info = rn->info; info; info = info->next) bgp_dump_routes_entry (&rn->p, info, afi, MSG_TABLE_DUMP, seq++); }
void ospf_renegotiate_optional_capabilities(struct ospf *top) { struct listnode *node; struct ospf_interface *oi; struct route_table *nbrs; struct route_node *rn; struct ospf_neighbor *nbr; /* At first, flush self-originated LSAs from routing domain. */ ospf_flush_self_originated_lsas_now(top); /* Revert all neighbor status to ExStart. */ for (ALL_LIST_ELEMENTS_RO(top->oiflist, node, oi)) { if ((nbrs = oi->nbrs) == NULL) continue; for (rn = route_top(nbrs); rn; rn = route_next(rn)) { if ((nbr = rn->info) == NULL || nbr == oi->nbr_self) continue; if (nbr->state < NSM_ExStart) continue; if (IS_DEBUG_OSPF_EVENT) zlog_debug ("Renegotiate optional capabilities with neighbor(%s)", inet_ntoa(nbr->router_id)); OSPF_NSM_EVENT_SCHEDULE(nbr, NSM_SeqNumberMismatch); } } return; }
/* Restore an interface to its pre UP state Used from ism_interface_down only */ void ospf_if_cleanup (struct ospf_interface *oi) { struct route_node *rn; struct listnode *node, *nnode; struct ospf_neighbor *nbr; struct ospf_nbr_nbma *nbr_nbma; struct ospf_lsa *lsa; /* oi->nbrs and oi->nbr_nbma should be deleted on InterfaceDown event */ /* delete all static neighbors attached to this interface */ for (ALL_LIST_ELEMENTS (oi->nbr_nbma, node, nnode, nbr_nbma)) { OSPF_POLL_TIMER_OFF (nbr_nbma->t_poll); if (nbr_nbma->nbr) { nbr_nbma->nbr->nbr_nbma = NULL; nbr_nbma->nbr = NULL; } nbr_nbma->oi = NULL; listnode_delete (oi->nbr_nbma, nbr_nbma); } /* send Neighbor event KillNbr to all associated neighbors. */ for (rn = route_top (oi->nbrs); rn; rn = route_next (rn)) if ((nbr = rn->info) != NULL) if (nbr != oi->nbr_self) OSPF_NSM_EVENT_EXECUTE (nbr, NSM_KillNbr); /* Cleanup Link State Acknowlegdment list. */ for (ALL_LIST_ELEMENTS (oi->ls_ack, node, nnode, lsa)) ospf_lsa_unlock (&lsa); /* oi->ls_ack */ list_delete_all_node (oi->ls_ack); oi->crypt_seqnum = 0; /* Empty link state update queue */ ospf_ls_upd_queue_empty (oi); /* Reset pseudo neighbor. */ ospf_nbr_delete (oi->nbr_self); oi->nbr_self = ospf_nbr_new (oi); ospf_nbr_add_self (oi); ospf_lsa_unlock (&oi->network_lsa_self); oi->network_lsa_self = NULL; OSPF_TIMER_OFF (oi->t_network_lsa_self); #ifdef HAVE_GRACEFUL_RESTART THREAD_TIMER_OFF(oi->t_opaque_lsa_refresh); oi->v_opaque_lsa_count = 0 ; #endif }
static void isis_redist_set(struct isis_area *area, int level, int family, int type, uint32_t metric, const char *routemap, int originate_type) { int protocol = redist_protocol(family); struct isis_redist *redist = get_redist_settings(area, family, type, level); int i; struct route_table *ei_table; struct route_node *rn; struct isis_ext_info *info; redist->redist = (type == DEFAULT_ROUTE) ? originate_type : 1; redist->metric = metric; isis_redist_routemap_set(redist, routemap); if (!area->ext_reach[protocol][level-1]) { area->ext_reach[protocol][level-1] = route_table_init_with_delegate(&isis_redist_rt_delegate); } for (i = 0; i < REDIST_PROTOCOL_COUNT; i++) if (!area->isis->ext_info[i]) { area->isis->ext_info[i] = route_table_init_with_delegate(&isis_redist_rt_delegate); } isis_redist_update_zebra_subscriptions(area->isis); if (type == DEFAULT_ROUTE && originate_type == DEFAULT_ORIGINATE_ALWAYS) isis_redist_ensure_default(area->isis, family); ei_table = get_ext_info(area->isis, family); for (rn = route_top(ei_table); rn; rn = route_next(rn)) { if (!rn->info) continue; info = rn->info; if (type == DEFAULT_ROUTE) { if (!is_default(&rn->p)) continue; } else { if (info->origin != type) continue; } isis_redist_update_ext_reach(area, level, redist, &rn->p, info); } }
static int ripng_if_down (struct interface *ifp) { struct route_node *rp; struct ripng_info *rinfo; struct ripng_interface *ri; if (ripng) { for (rp = route_top (ripng->table); rp; rp = route_next (rp)) if ((rinfo = rp->info) != NULL) { /* Routes got through this interface. */ if (rinfo->ifindex == ifp->ifindex && rinfo->type == ZEBRA_ROUTE_RIPNG && rinfo->sub_type == RIPNG_ROUTE_RTE) { ripng_zebra_ipv6_delete ((struct prefix_ipv6 *) &rp->p, &rinfo->nexthop, rinfo->ifindex); ripng_redistribute_delete (rinfo->type, rinfo->sub_type, (struct prefix_ipv6 *)&rp->p, rinfo->ifindex); } else { /* All redistributed routes got through this interface, * but the static and system ones are kept. */ if ((rinfo->ifindex == ifp->ifindex) && (rinfo->type != ZEBRA_ROUTE_STATIC) && (rinfo->type != ZEBRA_ROUTE_SYSTEM)) ripng_redistribute_delete (rinfo->type, rinfo->sub_type, (struct prefix_ipv6 *) &rp->p, rinfo->ifindex); } } } ri = ifp->info; if (ri->running) { if (IS_RIPNG_DEBUG_EVENT) zlog_debug ("turn off %s", ifp->name); /* Leave from multicast group. */ ripng_multicast_leave (ifp); ri->running = 0; } return 0; }
/* Return the iterator of the first VRF. */ vrf_iter_t vrf_first (void) { struct route_node *rn; for (rn = route_top (vrf_table); rn; rn = route_next (rn)) if (rn->info) { route_unlock_node (rn); /* top/next */ return (vrf_iter_t)rn; } return VRF_ITER_INVALID; }
void route_table_unlock(struct route_table *t) { struct route_node *node; for (node = route_top(t); node != NULL; node = route_next(node)) { if (node == NULL) { break; } if (node->lock > 0) node->lock--; } }
/* Simulate down/up on the interface. This is needed, for example, when the MTU changes. */ void ospf_if_reset(struct interface *ifp) { struct route_node *rn; for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { struct ospf_interface *oi; if ((oi = rn->info) == NULL) continue; ospf_if_down(oi); ospf_if_up(oi); } }
void ospf_if_update_params(struct interface *ifp, struct in_addr addr) { struct route_node *rn; struct ospf_interface *oi; for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { if ((oi = rn->info) == NULL) continue; if (IPV4_ADDR_SAME(&oi->address->u.prefix4, &addr)) oi->params = ospf_lookup_if_params(ifp, oi->address->u.prefix4); } }
struct ospf_neighbor *ospf_nbr_lookup_by_routerid(struct route_table *nbrs, struct in_addr *id) { struct route_node *rn; struct ospf_neighbor *nbr; for (rn = route_top(nbrs); rn; rn = route_next(rn)) if ((nbr = rn->info) != NULL) if (IPV4_ADDR_SAME(&nbr->router_id, id)) { route_unlock_node(rn); return nbr; } return NULL; }
/* Get neighbor count by status. Specify status = 0, get all neighbor other than myself. */ int ospf_nbr_count(struct ospf_interface *oi, int state) { struct ospf_neighbor *nbr; struct route_node *rn; int count = 0; for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) if ((nbr = rn->info)) if (!IPV4_ADDR_SAME (&nbr->router_id, &oi->ospf->router_id)) if (state == 0 || nbr->state == state) count++; return count; }
/* Generate AdjOK? NSM event. */ static void ospf_dr_change (struct ospf *ospf, struct route_table *nbrs) { struct route_node *rn; struct ospf_neighbor *nbr; for (rn = route_top (nbrs); rn; rn = route_next (rn)) if ((nbr = rn->info) != NULL) /* Ignore 0.0.0.0 node*/ if (nbr->router_id.s_addr != 0) /* Is neighbor upper 2-Way? */ if (nbr->state >= NSM_TwoWay) /* Ignore myself. */ if (!IPV4_ADDR_SAME (&nbr->router_id, &ospf->router_id)) OSPF_NSM_EVENT_SCHEDULE (nbr, NSM_AdjOK); }
static void ospf_dr_eligible_routers (struct route_table *nbrs, struct list *el_list) { struct route_node *rn; struct ospf_neighbor *nbr; for (rn = route_top (nbrs); rn; rn = route_next (rn)) if ((nbr = rn->info) != NULL) /* Ignore 0.0.0.0 node*/ if (nbr->router_id.s_addr != 0) /* Is neighbor eligible? */ if (nbr->priority > 0) /* Is neighbor upper 2-Way? */ if (nbr->state >= NSM_TwoWay) listnode_add (el_list, nbr); }
int ospf_nbr_count_opaque_capable (struct ospf_interface *oi) { struct ospf_neighbor *nbr; struct route_node *rn; int count = 0; for (rn = route_top (oi->nbrs); rn; rn = route_next (rn)) if ((nbr = rn->info)) if (!IPV4_ADDR_SAME (&nbr->router_id, &oi->ospf->router_id)) if (nbr->state == NSM_Full) if (CHECK_FLAG (nbr->options, OSPF_OPTION_O)) count++; return count; }
/* Request routes at all interfaces. */ static void rip_request_neighbor_all (void) { struct route_node *rp; if (! rip) return; if (IS_RIP_DEBUG_EVENT) zlog_debug ("request to the all neighbor"); /* Send request to all neighbor. */ for (rp = route_top (rip->neighbor); rp; rp = route_next (rp)) if (rp->info) rip_request_neighbor (rp->p.u.prefix4); }
void ospf_db_summary_clear (struct ospf_neighbor *nbr) { struct ospf_lsdb *lsdb; int i; lsdb = &nbr->db_sum; for (i = OSPF_MIN_LSA; i < OSPF_MAX_LSA; i++) { struct route_table *table = lsdb->type[i].db; struct route_node *rn; for (rn = route_top (table); rn; rn = route_next (rn)) if (rn->info) ospf_lsdb_delete (&nbr->db_sum, rn->info); } }
u_char * ipCidrNumber (struct variable *v, oid objid[], size_t *objid_len, int exact, size_t *val_len, WriteMethod **write_method) { static int result; struct route_node *np; if (smux_header_generic(v, objid, objid_len, exact, val_len, write_method) == MATCH_FAILED) return NULL; /* Return number of routing entries. */ result = 0; for (np = route_top (rib_table_ipv4); np; np = route_next (np)) result++; return (u_char *)&result; }
void zebra_print_rnh_table (vrf_id_t vrfid, int af, struct vty *vty) { struct route_table *table; struct route_node *rn; table = lookup_rnh_table(vrfid, af); if (!table) { zlog_debug("print_rnhs: rnh table not found\n"); return; } for (rn = route_top(table); rn; rn = route_next(rn)) if (rn->info) print_rnh(rn, vty); }
static void isis_redist_unset(struct isis_area *area, int level, int family, int type) { struct isis_redist *redist = get_redist_settings(area, family, type, level); struct route_table *er_table = get_ext_reach(area, family, level); struct route_node *rn; struct isis_ext_info *info; if (!redist->redist) return; redist->redist = 0; if (!er_table) { zlog_warn("%s: External reachability table uninitialized.", __func__); return; } for (rn = route_top(er_table); rn; rn = route_next(rn)) { if (!rn->info) continue; info = rn->info; if (type == DEFAULT_ROUTE) { if (!is_default(&rn->p)) continue; } else { if (info->origin != type) continue; } XFREE(MTYPE_ISIS, rn->info); route_unlock_node(rn); } lsp_regenerate_schedule(area, level, 0); isis_redist_update_zebra_subscriptions(area->isis); }
/* Get neighbor count by status. Specify status = 0, get all neighbor other than myself. */ int ospf_nbr_count (struct route_table *nbrs, int status) { struct route_node *rn; struct ospf_neighbor *nbr; int count = 0; /* Sanity check. */ if (nbrs == NULL) return 0; for (rn = route_top (nbrs); rn; rn = route_next (rn)) if ((nbr = rn->info) != NULL) /* Ignore myself. */ if (!IPV4_ADDR_SAME (&nbr->router_id, &ospf_top->router_id)) if (status == 0 || nbr->status == status) count++; return count; }
/* Iteration function */ struct ospf6_lsa * ospf6_lsdb_head (struct ospf6_lsdb *lsdb) { struct route_node *node; node = route_top (lsdb->table); if (node == NULL) return NULL; /* skip to the existing lsdb entry */ while (node && node->info == NULL) node = route_next (node); if (node == NULL) return NULL; route_unlock_node (node); if (node->info) ospf6_lsa_lock ((struct ospf6_lsa *) node->info); return (struct ospf6_lsa *) node->info; }
static int ospf_if_delete_hook (struct interface *ifp) { int rc = 0; struct route_node *rn; rc = ospf_opaque_del_if (ifp); route_table_finish (IF_OIFS (ifp)); for (rn = route_top (IF_OIFS_PARAMS (ifp)); rn; rn = route_next (rn)) if (rn->info) ospf_del_if_params (rn->info); route_table_finish (IF_OIFS_PARAMS (ifp)); ospf_del_if_params ((struct ospf_if_params *) IF_DEF_PARAMS (ifp)); XFREE (MTYPE_OSPF_IF_INFO, ifp->info); ifp->info = NULL; return rc; }
void ospf_if_recalculate_output_cost(struct interface *ifp) { u_int32_t newcost; struct route_node *rn; for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { struct ospf_interface *oi; if ((oi = rn->info) == NULL) continue; newcost = ospf_if_get_output_cost(oi); /* Is actual output cost changed? */ if (oi->output_cost != newcost) { oi->output_cost = newcost; ospf_router_lsa_update_area(oi->area); } } }