📄 ospf6_neighbor.c
字号:
/* * Copyright (C) 1999 Yasuhiro Ohara * * This file is part of GNU Zebra. * * GNU Zebra is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2, or (at your option) any * later version. * * GNU Zebra is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GNU Zebra; see the file COPYING. If not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */#include "ospf6d.h"#include <zebra.h>#include "log.h"#include "thread.h"#include "linklist.h"#include "vty.h"#include "command.h"#include "ospf6_lsa.h"#include "ospf6_message.h"#include "ospf6_neighbor.h"#include "ospf6_nsm.h"#include "ospf6_lsa.h"#include "ospf6_lsdb.h"char *ospf6_neighbor_state_string[] ={ "None", "Down", "Attempt", "Init", "Twoway", "ExStart", "ExChange", "Loading", "Full", NULL};intospf6_neighbor_last_dbdesc_release (struct thread *thread){ struct ospf6_neighbor *o6n; o6n = (struct ospf6_neighbor *) THREAD_ARG (thread); assert (o6n); memset (&o6n->last_dd, 0, sizeof (struct ospf6_dbdesc)); return 0;}voidospf6_neighbor_thread_cancel_all (struct ospf6_neighbor *o6n){ if (o6n->inactivity_timer) thread_cancel (o6n->inactivity_timer); o6n->inactivity_timer = (struct thread *) NULL; if (o6n->send_update) thread_cancel (o6n->send_update); o6n->send_update = (struct thread *) NULL; if (o6n->thread_send_dbdesc) thread_cancel (o6n->thread_send_dbdesc); o6n->thread_send_dbdesc = (struct thread *) NULL; if (o6n->thread_rxmt_dbdesc) thread_cancel (o6n->thread_rxmt_dbdesc); o6n->thread_rxmt_dbdesc = (struct thread *) NULL; if (o6n->thread_rxmt_lsreq) thread_cancel (o6n->thread_rxmt_lsreq); o6n->thread_rxmt_lsreq = (struct thread *) NULL;}voidospf6_neighbor_lslist_clear (struct ospf6_neighbor *nei){ ospf6_lsdb_remove_all (nei->summary_list); ospf6_lsdb_remove_all (nei->request_list); ospf6_lsdb_remove_all (nei->retrans_list); ospf6_lsdb_remove_all (nei->dbdesc_list);}voidospf6_neighbor_summary_add (struct ospf6_lsa *lsa, struct ospf6_neighbor *nei){ struct ospf6_lsa *summary; if (IS_OSPF6_DUMP_NEIGHBOR) { zlog_info ("Neighbor %s summary-list:", nei->str); zlog_info (" Add %s", lsa->str); } ospf6_lsa_age_current (lsa); summary = ospf6_lsa_summary_create (lsa->header); ospf6_lsdb_add (summary, nei->summary_list);}voidospf6_neighbor_summary_remove (struct ospf6_lsa *lsa, struct ospf6_neighbor *nei){ struct ospf6_lsa *summary; if (IS_OSPF6_DUMP_NEIGHBOR) { zlog_info ("Neighbor %s summary-list:", nei->str); zlog_info (" Remove %s", lsa->str); } summary = ospf6_lsdb_lookup_lsdb (lsa->header->type, lsa->header->id, lsa->header->adv_router, nei->summary_list); ospf6_lsdb_remove (summary, nei->summary_list);}voidospf6_neighbor_request_add (struct ospf6_lsa *lsa, struct ospf6_neighbor *nei){ struct ospf6_lsa *summary; if (IS_OSPF6_DUMP_NEIGHBOR) { zlog_info ("Neighbor %s request-list:", nei->str); zlog_info (" Add %s", lsa->str); } ospf6_lsa_age_current (lsa); summary = ospf6_lsa_summary_create (lsa->header); ospf6_lsdb_add (summary, nei->request_list);}voidospf6_neighbor_request_remove (struct ospf6_lsa *lsa, struct ospf6_neighbor *nei){ struct ospf6_lsa *summary; if (IS_OSPF6_DUMP_NEIGHBOR) { zlog_info ("Neighbor %s request-list:", nei->str); zlog_info (" Remove %s", lsa->str); } summary = ospf6_lsdb_lookup_lsdb (lsa->header->type, lsa->header->id, lsa->header->adv_router, nei->request_list); ospf6_lsdb_remove (summary, nei->request_list);}voidospf6_neighbor_retrans_add (struct ospf6_lsa *lsa, struct ospf6_neighbor *nei){ if (IS_OSPF6_DUMP_NEIGHBOR) { zlog_info ("Neighbor %s retrans-list:", nei->str); zlog_info (" Add %s", lsa->str); } ospf6_lsdb_add (lsa, nei->retrans_list);}voidospf6_neighbor_retrans_remove (struct ospf6_lsa *lsa, struct ospf6_neighbor *nei){ if (IS_OSPF6_DUMP_NEIGHBOR) { zlog_info ("Neighbor %s retrans-list:", nei->str); zlog_info (" Remove %s", lsa->str); } ospf6_lsdb_remove (lsa, nei->retrans_list); if (nei->retrans_list->count == 0) { if (nei->send_update) thread_cancel (nei->send_update); nei->send_update = NULL; }}voidospf6_neighbor_dbdesc_add (struct ospf6_lsa *lsa, struct ospf6_neighbor *nei){ if (IS_OSPF6_DUMP_NEIGHBOR) { zlog_info ("Neighbor %s dbdesc-list:", nei->str); zlog_info (" Add %s", lsa->str); } ospf6_lsdb_add (lsa, nei->dbdesc_list);}voidospf6_neighbor_dbdesc_remove (struct ospf6_lsa *lsa, struct ospf6_neighbor *nei){ if (IS_OSPF6_DUMP_NEIGHBOR) { zlog_info ("Neighbor %s dbdesc-list:", nei->str); zlog_info (" Remove %s", lsa->str); } ospf6_lsdb_remove (lsa, nei->dbdesc_list);}/* prepare summary-list of his neighbor structure */voidospf6_neighbor_dbex_init (struct ospf6_neighbor *nei){ struct ospf6_lsdb_node node; /* clear ls-list */ ospf6_neighbor_lslist_clear (nei); /* AS scope LSAs */ for (ospf6_lsdb_head (&node, nei->ospf6_interface->area->ospf6->lsdb); ! ospf6_lsdb_is_end (&node); ospf6_lsdb_next (&node)) { if (IS_LSA_MAXAGE (node.lsa)) ospf6_neighbor_retrans_add (node.lsa, nei); else ospf6_neighbor_summary_add (node.lsa, nei); } /* AREA scope LSAs */ for (ospf6_lsdb_head (&node, nei->ospf6_interface->area->lsdb); ! ospf6_lsdb_is_end (&node); ospf6_lsdb_next (&node)) { if (IS_LSA_MAXAGE (node.lsa)) ospf6_neighbor_retrans_add (node.lsa, nei); else ospf6_neighbor_summary_add (node.lsa, nei); } /* INTERFACE scope LSAs */ for (ospf6_lsdb_head (&node, nei->ospf6_interface->lsdb); ! ospf6_lsdb_is_end (&node); ospf6_lsdb_next (&node)) { if (IS_LSA_MAXAGE (node.lsa)) ospf6_neighbor_retrans_add (node.lsa, nei); else ospf6_neighbor_summary_add (node.lsa, nei); }}/* create ospf6_neighbor */struct ospf6_neighbor *ospf6_neighbor_create (u_int32_t router_id, struct ospf6_interface *o6i){ struct ospf6_neighbor *new; char buf[32]; new = (struct ospf6_neighbor *) XMALLOC (MTYPE_OSPF6_NEIGHBOR, sizeof (struct ospf6_neighbor)); if (new == NULL) { zlog_warn ("neighbor: malloc failed"); return NULL; } memset (new, 0, sizeof (struct ospf6_neighbor)); new->state = OSPF6_NEIGHBOR_STATE_DOWN; new->router_id = router_id; inet_ntop (AF_INET, &router_id, buf, sizeof (buf)); snprintf (new->str, sizeof (new->str), "%s%%%s", buf, o6i->interface->name); new->inactivity_timer = (struct thread *) NULL; new->summary_list = ospf6_lsdb_create (); new->request_list = ospf6_lsdb_create (); new->retrans_list = ospf6_lsdb_create (); new->dbdesc_list = ospf6_lsdb_create (); listnode_add (o6i->neighbor_list, new); new->ospf6_interface = o6i; CALL_ADD_HOOK (&neighbor_hook, new); return new;}voidospf6_neighbor_delete (struct ospf6_neighbor *o6n){ CALL_REMOVE_HOOK (&neighbor_hook, o6n); ospf6_neighbor_thread_cancel_all (o6n); ospf6_neighbor_lslist_clear (o6n);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -