⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ospf6d.c

📁 大名鼎鼎的路由器源码。程序分ZEBRA、OSPFRIP等3个包。程序框架采用一个路由协议一个进程的方式
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * 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 "ospf6_damp.h"/* global ospf6d variable */int  ospf6_sock;list nexthoplist = NULL;struct sockaddr_in6 allspfrouters6;struct sockaddr_in6 alldrouters6;char *recent_reason; /* set by ospf6_lsa_check_recent () */int proctitle_mode = 0;char ospf6_daemon_version[] = OSPF6_DAEMON_VERSION;#define TIMER_SEC_MICRO 1000000voidospf6_timeval_sub (const struct timeval *t1, const struct timeval *t2,                   struct timeval *result){  long usec, movedown = 0;  if (t1->tv_sec < t2->tv_sec ||      (t1->tv_sec == t2->tv_sec && t1->tv_usec < t2->tv_usec))    {      result->tv_sec = 0;      result->tv_usec = 0;      return;    }  if (t1->tv_usec < t2->tv_usec)    {      usec = t1->tv_usec + TIMER_SEC_MICRO;      movedown++;    }  else    usec = t1->tv_usec;  result->tv_usec = usec - t2->tv_usec;  result->tv_sec = t1->tv_sec - t2->tv_sec - movedown;}voidospf6_timeval_div (const struct timeval *t1, u_int by,                   struct timeval *result){  long movedown;  if (by == 0)    {      result->tv_sec = 0;      result->tv_usec = 0;      return;    }  movedown = t1->tv_sec % by;  result->tv_sec = t1->tv_sec / by;  result->tv_usec = (t1->tv_usec + movedown * TIMER_SEC_MICRO) / by;}voidospf6_timeval_decode (const struct timeval *t, long *dayp, long *hourp,                      long *minp, long *secp, long *msecp, long *usecp){  long day, hour, min, sec, msec, usec, left;  left = t->tv_sec;  day = left / 86400; left -= day * 86400;  hour = left / 3600; left -= hour * 3600;  min = left / 60; left -= min * 60;  sec = left;  left = t->tv_usec;  msec = left / 1000; left -= msec * 1000;  usec = left;  if (dayp) *dayp = day;  if (hourp) *hourp = hour;  if (minp) *minp = min;  if (secp) *secp = sec;  if (msecp) *msecp = msec;  if (usecp) *usecp = usec;}voidospf6_timeval_string (struct timeval *tv, char *buf, int size){  char days[16], hours[16], mins[16], secs[16], msecs[16], usecs[16];  long day, hour, min, sec, msec, usec;  ospf6_timeval_decode (tv, &day, &hour, &min, &sec, &msec, &usec);  snprintf (days, sizeof (days), "%ld days ", day);  snprintf (hours, sizeof (hours), "%ld hours ", hour);  snprintf (mins, sizeof (mins), "%ld mins ", min);  snprintf (secs, sizeof (secs), "%ld secs ", sec);  snprintf (msecs, sizeof (msecs), "%ld msecs ", msec);  snprintf (usecs, sizeof (usecs), "%ld usecs ", usec);  snprintf (buf, size, "%s%s%s%s%s%s",            (day ? days : ""), (hour ? hours : ""),            (min ? mins : ""), (sec ? secs : ""),            (msec ? msecs : ""), (usec ? usecs : ""));}voidospf6_timeval_string_summary (struct timeval *tv, char *buf, int size){  char days[16], hours[16], mins[16], secs[16], msecs[16], usecs[16];  long day, hour, min, sec, msec, usec;  ospf6_timeval_decode (tv, &day, &hour, &min, &sec, &msec, &usec);  snprintf (days, sizeof (days), "%02ldd", day);  snprintf (hours, sizeof (hours), "%ldh", hour);  snprintf (mins, sizeof (mins), "%ldm", min);  snprintf (secs, sizeof (secs), "%lds", sec);  snprintf (msecs, sizeof (msecs), "%ldms", msec);  snprintf (usecs, sizeof (usecs), "%ldus", usec);  snprintf (buf, size, "%s%02ld:%02ld:%02ld",            (day ? days : ""), hour, min, sec);}/* foreach function */voidospf6_count_state (void *arg, int val, void *obj){  int *count = (int *) arg;  u_char state = val;  struct ospf6_neighbor *nei = (struct ospf6_neighbor *) obj;  if (nei->state == state)    (*count)++;}/* VTY commands.  */DEFUN (reload,       reload_cmd,       "reload",       "Reloads\n"){  extern void _reload ();  _reload ();  return CMD_SUCCESS;}DEFUN (garbage_collection,       garbage_collection_cmd,       "ipv6 ospf6 garbage collect",       IPV6_STR       OSPF6_STR       "garbage collection by hand\n"       "Remove Maxages if possible and recalculate routes\n"){  ospf6_maxage_remover ();#if 0  ospf6_route_calculation_schedule ();#endif  return CMD_SUCCESS;}/* Show version. */DEFUN (show_version_ospf6,       show_version_ospf6_cmd,       "show version ospf6",       SHOW_STR       "Displays ospf6d version\n"){  vty_out (vty, "Zebra OSPF6d Version: %s%s",           ospf6_daemon_version, VTY_NEWLINE);  return CMD_SUCCESS;}/* start ospf6 */DEFUN (router_ospf6,       router_ospf6_cmd,       "router ospf6",       OSPF6_ROUTER_STR       OSPF6_STR){  if (ospf6 == NULL)    ospf6_start ();  /* set current ospf point. */  vty->node = OSPF6_NODE;  vty->index = ospf6;  return CMD_SUCCESS;}/* stop ospf6 */DEFUN (no_router_ospf6,       no_router_ospf6_cmd,       "no router ospf6",       NO_STR       OSPF6_ROUTER_STR){  if (!ospf6)    vty_out (vty, "OSPFv3 is not running%s", VTY_NEWLINE);  else    ospf6_stop ();  /* return to config node . */  vty->node = CONFIG_NODE;  vty->index = NULL;  return CMD_SUCCESS;}/* show top level structures */DEFUN (show_ipv6_ospf6,       show_ipv6_ospf6_cmd,       "show ipv6 ospf6",       SHOW_STR       IP6_STR       OSPF6_STR){  OSPF6_CMD_CHECK_RUNNING ();  ospf6_show (vty);  return CMD_SUCCESS;}DEFUN (show_ipv6_ospf6_nexthoplist,       show_ipv6_ospf6_nexthoplist_cmd,       "show ipv6 ospf6 nexthop-list",       SHOW_STR       IP6_STR       OSPF6_STR       "List of nexthop\n"){#if 0  listnode i;  struct ospf6_nexthop *nh;  char buf[128];  for (i = listhead (nexthoplist); i; nextnode (i))    {      nh = (struct ospf6_nexthop *) getdata (i);      nexthop_str (nh, buf, sizeof (buf));      vty_out (vty, "%s%s", buf,	       VTY_NEWLINE);    }#endif  return CMD_SUCCESS;}DEFUN (show_ipv6_ospf6_statistics,       show_ipv6_ospf6_statistics_cmd,       "show ipv6 ospf6 statistics",       SHOW_STR       IP6_STR       OSPF6_STR       "Statistics\n"){  OSPF6_CMD_CHECK_RUNNING ();  ospf6_statistics_show (vty, ospf6);  return CMD_SUCCESS;}/* change Router_ID commands. */DEFUN (ospf6_router_id,       ospf6_router_id_cmd,       "router-id ROUTER_ID",       "Configure ospf Router-ID.\n"       V4NOTATION_STR){  int ret;  u_int32_t router_id;  ret = inet_pton (AF_INET, argv[0], &router_id);  if (!ret)    {      vty_out (vty, "malformed ospf router identifier%s", VTY_NEWLINE);      vty_out (vty, "%s", VTY_NEWLINE);      return CMD_WARNING;    }  if (IS_OSPF6_DUMP_CONFIG)    zlog_info ("CONFIG: router-id %s", argv[0]);  ospf6->router_id = router_id;  return CMD_SUCCESS;}intospf6_interface_bind_area (struct vty *vty,                           char *if_name, char *area_name,                           char *plist_name, int passive){  struct interface *ifp;  struct ospf6_interface *o6i;  struct ospf6_area *o6a;  u_int32_t area_id;  /* find/create ospf6 interface */  ifp = if_get_by_name (if_name);  o6i = (struct ospf6_interface *) ifp->info;  if (! o6i)    o6i = ospf6_interface_create (ifp);  /* parse Area-ID */  if (inet_pton (AF_INET, area_name, &area_id) != 1)    {      vty_out (vty, "Invalid Area-ID: %s%s", area_name, VTY_NEWLINE);      return CMD_ERR_AMBIGUOUS;    }  /* find/create ospf6 area */  o6a = ospf6_area_lookup (area_id, ospf6);  if (!o6a)    {      o6a = ospf6_area_create (area_id);      o6a->ospf6 = ospf6;      listnode_add (ospf6->area_list, o6a);    }  if (o6i->area)    {      if (o6i->area != o6a)        {          vty_out (vty, "Aready attached to area %s%s",                   o6i->area->str, VTY_NEWLINE);          return CMD_ERR_NOTHING_TODO;        }    }  else    {      listnode_add (o6a->if_list, o6i);      o6i->area = o6a;    }  /* prefix-list name */  if (plist_name)    {      if (o6i->plist_name)        XFREE (MTYPE_PREFIX_LIST_STR, o6i->plist_name);      o6i->plist_name = XSTRDUP (MTYPE_PREFIX_LIST_STR, plist_name);    }  else    {      if (o6i->plist_name)        XFREE (MTYPE_PREFIX_LIST_STR, o6i->plist_name);      o6i->plist_name = NULL;    }  if (passive)    {      listnode node;      struct ospf6_neighbor *o6n;      SET_FLAG (o6i->flag, OSPF6_INTERFACE_FLAG_PASSIVE);      if (o6i->thread_send_hello)        {          thread_cancel (o6i->thread_send_hello);          o6i->thread_send_hello = (struct thread *) NULL;        }      for (node = listhead (o6i->neighbor_list); node; nextnode (node))        {          o6n = getdata (node);          if (o6n->inactivity_timer)            thread_cancel (o6n->inactivity_timer);          thread_execute (master, inactivity_timer, o6n, 0);        }    }  else    {      UNSET_FLAG (o6i->flag, OSPF6_INTERFACE_FLAG_PASSIVE);      if (o6i->thread_send_hello == NULL)        thread_add_event (master, ospf6_send_hello, o6i, 0);    }  /* enable I/F if it's not enabled still */  if (! ospf6_interface_is_enabled (o6i->interface->ifindex))    thread_add_event (master, interface_up, o6i, 0);  else    CALL_FOREACH_LSA_HOOK (hook_interface, hook_change, o6i);  CALL_CHANGE_HOOK (&interface_hook, o6i);  return CMD_SUCCESS;}DEFUN (ospf6_interface_area_plist,       ospf6_interface_area_plist_cmd,       "interface IFNAME area A.B.C.D prefix-list WORD",       "Enable routing on an IPv6 interface\n"       IFNAME_STR       "Set the OSPF6 area ID\n"       "OSPF6 area ID in IPv4 address notation\n"       OSPF6_PREFIX_LIST_STR       "IPv6 prefix-list name\n"

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -