📄 ospfd.c
字号:
area->no_summary == 0 && area->default_cost == 1 && EXPORT_NAME (area) == NULL && IMPORT_NAME (area) == NULL && area->auth_type == OSPF_AUTH_NULL) { listnode_delete (ospf->areas, area); ospf_area_free (area); }}struct ospf_area *ospf_area_get (struct ospf *ospf, struct in_addr area_id, int format){ struct ospf_area *area; area = ospf_area_lookup_by_area_id (ospf, area_id); if (!area) { area = ospf_area_new (ospf, area_id); area->format = format; listnode_add_sort (ospf->areas, area); ospf_check_abr_status (ospf); } return area;}struct ospf_area *ospf_area_lookup_by_area_id (struct ospf *ospf, struct in_addr area_id){ struct ospf_area *area; listnode node; for (node = listhead (ospf->areas); node; nextnode (node)) { area = getdata (node); if (IPV4_ADDR_SAME (&area->area_id, &area_id)) return area; } return NULL;}voidospf_area_add_if (struct ospf_area *area, struct ospf_interface *oi){ listnode_add (area->oiflist, oi);}voidospf_area_del_if (struct ospf_area *area, struct ospf_interface *oi){ listnode_delete (area->oiflist, oi);}/* Config network statement related functions. */struct ospf_network *ospf_network_new (struct in_addr area_id, int format){ struct ospf_network *new; new = XCALLOC (MTYPE_OSPF_NETWORK, sizeof (struct ospf_network)); new->area_id = area_id; new->format = format; return new;}voidospf_network_free (struct ospf *ospf, struct ospf_network *network){ ospf_area_check_free (ospf, network->area_id); ospf_schedule_abr_task (ospf); XFREE (MTYPE_OSPF_NETWORK, network);}intospf_network_set (struct ospf *ospf, struct prefix_ipv4 *p, struct in_addr area_id){ struct ospf_network *network; struct ospf_area *area; struct route_node *rn; struct external_info *ei; int ret = OSPF_AREA_ID_FORMAT_ADDRESS; rn = route_node_get (ospf->networks, (struct prefix *)p); if (rn->info) { /* There is already same network statement. */ route_unlock_node (rn); return 0; } rn->info = network = ospf_network_new (area_id, ret); area = ospf_area_get (ospf, area_id, ret); /* Run network config now. */ ospf_network_run (ospf, (struct prefix *)p, area); /* Update connected redistribute. */ if (ospf_is_type_redistributed (ZEBRA_ROUTE_CONNECT)) if (EXTERNAL_INFO (ZEBRA_ROUTE_CONNECT)) for (rn = route_top (EXTERNAL_INFO (ZEBRA_ROUTE_CONNECT)); rn; rn = route_next (rn)) if ((ei = rn->info) != NULL) if (ospf_external_info_find_lsa (ospf, &ei->p)) if (!ospf_distribute_check_connected (ospf, ei)) ospf_external_lsa_flush (ospf, ei->type, &ei->p, ei->ifindex, ei->nexthop); ospf_area_check_free (ospf, area_id); return 1;}intospf_network_unset (struct ospf *ospf, struct prefix_ipv4 *p, struct in_addr area_id){ struct route_node *rn; struct ospf_network *network; struct external_info *ei; rn = route_node_lookup (ospf->networks, (struct prefix *)p); if (rn == NULL) return 0; network = rn->info; if (!IPV4_ADDR_SAME (&area_id, &network->area_id)) return 0; ospf_network_free (ospf, rn->info); rn->info = NULL; route_unlock_node (rn); ospf_if_update (ospf); /* Update connected redistribute. */ if (ospf_is_type_redistributed (ZEBRA_ROUTE_CONNECT)) if (EXTERNAL_INFO (ZEBRA_ROUTE_CONNECT)) for (rn = route_top (EXTERNAL_INFO (ZEBRA_ROUTE_CONNECT)); rn; rn = route_next (rn)) if ((ei = rn->info) != NULL) if (!ospf_external_info_find_lsa (ospf, &ei->p)) if (ospf_distribute_check_connected (ospf, ei)) ospf_external_lsa_originate (ospf, ei); return 1;}voidospf_network_run (struct ospf *ospf, struct prefix *p, struct ospf_area *area){ struct interface *ifp; listnode node; /* Schedule Router ID Update. */ if (ospf->router_id_static.s_addr == 0) if (ospf->t_router_id_update == NULL) { OSPF_TIMER_ON (ospf->t_router_id_update, ospf_router_id_update_timer, OSPF_ROUTER_ID_UPDATE_DELAY); } /* Get target interface. */ for (node = listhead (om->iflist); node; nextnode (node)) { listnode cn; if ((ifp = getdata (node)) == NULL) continue; if (memcmp (ifp->name, "VLINK", 5) == 0) continue; /* if interface prefix is match specified prefix, then create socket and join multicast group. */ for (cn = listhead (ifp->connected); cn; nextnode (cn)) { struct connected *co = getdata (cn); struct prefix *addr; if (if_is_pointopoint (ifp)) addr = co->destination; else addr = co->address; if (p->family == co->address->family && ! ospf_if_is_configured (ospf, &(addr->u.prefix4))) if ((if_is_pointopoint (ifp) && IPV4_ADDR_SAME (&(addr->u.prefix4), &(p->u.prefix4))) || prefix_match (p, addr)) { struct ospf_interface *oi; oi = ospf_if_new (ospf, ifp, co->address); oi->connected = co; oi->nbr_self->address = *oi->address; area->act_ints++; oi->area = area; oi->params = ospf_lookup_if_params (ifp, oi->address->u.prefix4); oi->output_cost = ospf_if_get_output_cost (oi); if (area->external_routing != OSPF_AREA_DEFAULT) UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_E); oi->nbr_self->priority = OSPF_IF_PARAM (oi, priority); /* Add pseudo neighbor. */ ospf_nbr_add_self (oi); /* Make sure pseudo neighbor's router_id. */ oi->nbr_self->router_id = ospf->router_id; oi->nbr_self->src = oi->address->u.prefix4; /* Relate ospf interface to ospf instance. */ oi->ospf = ospf; /* update network type as interface flag */ /* If network type is specified previously, skip network type setting. */ oi->type = IF_DEF_PARAMS (ifp)->type; /* Set area flag. */ switch (area->external_routing) { case OSPF_AREA_DEFAULT: SET_FLAG (oi->nbr_self->options, OSPF_OPTION_E); break; case OSPF_AREA_STUB: UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_E); break;#ifdef HAVE_NSSA case OSPF_AREA_NSSA: UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_E); SET_FLAG (oi->nbr_self->options, OSPF_OPTION_NP); break;#endif /* HAVE_NSSA */ } ospf_area_add_if (oi->area, oi); if (if_is_up (ifp)) ospf_if_up (oi); break; } } }}voidospf_ls_upd_queue_empty (struct ospf_interface *oi){ struct route_node *rn; listnode node; list lst; struct ospf_lsa *lsa; /* empty ls update queue */ for (rn = route_top (oi->ls_upd_queue); rn; rn = route_next (rn)) if ((lst = (list) rn->info)) { for (node = listhead (lst); node; nextnode (node)) if ((lsa = getdata (node))) ospf_lsa_unlock (lsa); list_free (lst); rn->info = NULL; } /* remove update event */ if (oi->t_ls_upd_event) { thread_cancel (oi->t_ls_upd_event); oi->t_ls_upd_event = NULL; }}voidospf_if_update (struct ospf *ospf){ struct route_node *rn; listnode node; listnode next; struct ospf_network *network; struct ospf_area *area; if (ospf != NULL) { /* Update Router ID scheduled. */ if (ospf->router_id_static.s_addr == 0) if (ospf->t_router_id_update == NULL) { OSPF_TIMER_ON (ospf->t_router_id_update, ospf_router_id_update_timer, OSPF_ROUTER_ID_UPDATE_DELAY); } /* Find interfaces that not configured already. */ for (node = listhead (ospf->oiflist); node; node = next) { int found = 0; struct ospf_interface *oi = getdata (node); struct connected *co = oi->connected; next = nextnode (node); if (oi->type == OSPF_IFTYPE_VIRTUALLINK) continue; for (rn = route_top (ospf->networks); rn; rn = route_next (rn)) { if (rn->info == NULL) continue; if ((oi->type == OSPF_IFTYPE_POINTOPOINT && IPV4_ADDR_SAME (&(co->destination->u.prefix4), &(rn->p.u.prefix4))) || prefix_match (&(rn->p), co->address)) { found = 1; route_unlock_node (rn); break; } } if (found == 0) ospf_if_free (oi); } /* Run each interface. */ for (rn = route_top (ospf->networks); rn; rn = route_next (rn)) if (rn->info != NULL) { network = (struct ospf_network *) rn->info; area = ospf_area_get (ospf, network->area_id, network->format); ospf_network_run (ospf, &rn->p, area); } }}voidospf_remove_vls_through_area (struct ospf *ospf, struct ospf_area *area){ listnode node, next; struct ospf_vl_data *vl_data; for (node = listhead (ospf->vlinks); node; node = next) { next = node->next; if ((vl_data = getdata (node)) != NULL) if (IPV4_ADDR_SAME (&vl_data->vl_area_id, &area->area_id)) ospf_vl_delete (ospf, vl_data); }}struct message ospf_area_type_msg[] ={ { OSPF_AREA_DEFAULT, "Default" }, { OSPF_AREA_STUB, "Stub" }, { OSPF_AREA_NSSA, "NSSA" },};int ospf_area_type_msg_max = OSPF_AREA_TYPE_MAX;voidospf_area_type_set (struct ospf_area *area, int type){ listnode node; struct ospf_interface *oi; if (area->external_routing == type) { if (IS_DEBUG_OSPF_EVENT) zlog_info ("Area[%s]: Types are the same, ignored.", inet_ntoa (area->area_id)); return; } area->external_routing = type; if (IS_DEBUG_OSPF_EVENT) zlog_info ("Area[%s]: Configured as %s", inet_ntoa (area->area_id), LOOKUP (ospf_area_type_msg, type)); switch (area->external_routing) { case OSPF_AREA_DEFAULT: for (node = listhead (area->oiflist); node; nextnode (node)) if ((oi = getdata (node)) != NULL) if (oi->nbr_self != NULL) SET_FLAG (oi->nbr_self->options, OSPF_OPTION_E); break; case OSPF_AREA_STUB: for (node = listhead (area->oiflist); node; nextnode (node)) if ((oi = getdata (node)) != NULL) if (oi->nbr_self != NULL) { if (IS_DEBUG_OSPF_EVENT) zlog_info ("setting options on %s accordingly", IF_NAME (oi)); UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_E); if (IS_DEBUG_OSPF_EVENT) zlog_info ("options set on %s: %x", IF_NAME (oi), OPTIONS (oi)); } break; case OSPF_AREA_NSSA:#ifdef HAVE_NSSA for (node = listhead (area->oiflist); node; nextnode (node)) if ((oi = getdata (node)) != NULL) if (oi->nbr_self != NULL) { zlog_info ("setting nssa options on %s accordingly", IF_NAME (oi)); UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_E); SET_FLAG (oi->nbr_self->options, OSPF_OPTION_NP); zlog_info ("options set on %s: %x", IF_NAME (oi), OPTIONS (oi)); }#endif /* HAVE_NSSA */ break; default: break; } ospf_router_lsa_timer_add (area); ospf_schedule_abr_task (area->ospf);}intospf_area_shortcut_set (struct ospf *ospf, struct ospf_area *area, int mode){ if (area->shortcut_configured == mode) return 0; area->shortcut_configured = mode; ospf_router_lsa_timer_add (area); ospf_schedule_abr_task (ospf); ospf_area_check_free (ospf, area->area_id); return 1;}intospf_area_shortcut_unset (struct ospf *ospf, struct ospf_area *area){ area->shortcut_configured = OSPF_SHORTCUT_DEFAULT; ospf_router_lsa_timer_add (area); ospf_area_check_free (ospf, area->area_id); ospf_schedule_abr_task (ospf); return 1;}intospf_area_vlink_count (struct ospf *ospf, struct ospf_area *area){ struct ospf_vl_data *vl; listnode node; int count = 0; for (node = listhead (ospf->vlinks); node; nextnode (node)) { vl = getdata (node); if (IPV4_ADDR_SAME (&vl->vl_area_id, &area->area_id)) count++; } return count;}intospf_area_stub_set (struct ospf *ospf, struct in_addr area_id){ struct ospf_area *area; int format = OSPF_AREA_ID_FORMAT_ADDRESS; area = ospf_area_get (ospf, area_id, format); if (ospf_area_vlink_count (ospf, area)) return 0; if (area->external_routing != OSPF_AREA_STUB) ospf_area_type_set (area, OSPF_AREA_STUB); return 1;}intospf_area_stub_unset (struct ospf *ospf, struct in_addr area_id){ struct ospf_area *area; area = ospf_area_lookup_by_area_id (ospf, area_id); if (area == NULL) return 1; if (area->external_routing == OSPF_AREA_STUB) ospf_area_type_set (area, OSPF_AREA_DEFAULT); ospf_area_check_free (ospf, area_id); return 1;}intospf_area_no_summary_set (struct ospf *ospf, struct in_addr area_id){ struct ospf_area *area; int format = OSPF_AREA_ID_FORMAT_ADDRESS; area = ospf_area_get (ospf, area_id, format); area->no_summary = 1; return 1;}intospf_area_no_summary_unset (struct ospf *ospf, struct in_addr area_id){ struct ospf_area *area; area = ospf_area_lookup_by_area_id (ospf, area_id); if (area == NULL) return 0; area->no_summary = 0; ospf_area_check_free (ospf, area_id); return 1;}intospf_area_nssa_set (struct ospf *ospf, struct in_addr area_id){ struct ospf_area *area; int format = OSPF_AREA_ID_FORMAT_ADDRESS; area = ospf_area_get (ospf, area_id, format); if (ospf_area_vlink_count (ospf, area)) return 0; if (area->external_routing != OSPF_AREA_NSSA) { ospf_area_type_set (area, OSPF_AREA_NSSA); ospf->anyNSSA++;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -