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

📄 ospf6_interface.c

📁 linux 路由软件 可支持RIP OSPF BGP等
💻 C
📖 第 1 页 / 共 3 页
字号:
      drouter = better_drouter (drouter, on);    }  best_drouter = drouter;  drouter = better_drouter (best_drouter, &myself);  if (drouter == NULL)    drouter = bdrouter;  /* the router itself is newly/no longer DR/BDR (4) */  if ((drouter == &myself && myself.drouter != myself.router_id) ||      (drouter != &myself && myself.drouter == myself.router_id) ||      (bdrouter == &myself && myself.bdrouter != myself.router_id) ||      (bdrouter != &myself && myself.bdrouter == myself.router_id))    {      myself.drouter = (drouter ? drouter->router_id : htonl (0));      myself.bdrouter = (bdrouter ? bdrouter->router_id : htonl (0));      /* compatible to Electing BDR (2) */      bdrouter = better_bdrouter (best_bdrouter, &myself);      /* compatible to Electing DR (3) */      drouter = better_drouter (best_drouter, &myself);      if (drouter == NULL)        drouter = bdrouter;    }  /* Set interface state accordingly (5) */  if (drouter && drouter == &myself)    next_state = OSPF6_INTERFACE_DR;  else if (bdrouter && bdrouter == &myself)    next_state = OSPF6_INTERFACE_BDR;  else    next_state = OSPF6_INTERFACE_DROTHER;  /* If NBMA, schedule Start for each neighbor having priority of 0 (6) */  /* XXX */  /* If DR or BDR change, invoke AdjOK? for each neighbor (7) */  /* RFC 2328 section 12.4. Originating LSAs (3) will be handled     accordingly after AdjOK */  if (oi->drouter != (drouter ? drouter->router_id : htonl (0)) ||      oi->bdrouter != (bdrouter ? bdrouter->router_id : htonl (0)))    {      if (IS_OSPF6_DEBUG_INTERFACE)        zlog_info ("DR Election on %s: DR: %s BDR: %s", oi->interface->name,                   (drouter ? drouter->name : "0.0.0.0"),                   (bdrouter ? bdrouter->name : "0.0.0.0"));      for (i = listhead (oi->neighbor_list); i; nextnode (i))        {          on = (struct ospf6_neighbor *) getdata (i);          if (on->state < OSPF6_NEIGHBOR_TWOWAY)            continue;          /* Schedule AdjOK. */          thread_add_event (master, adj_ok, on, 0);        }    }  oi->drouter = (drouter ? drouter->router_id : htonl (0));  oi->bdrouter = (bdrouter ? bdrouter->router_id : htonl (0));  return next_state;}/* Interface State Machine */intinterface_up (struct thread *thread){  struct ospf6_interface *oi;  oi = (struct ospf6_interface *) THREAD_ARG (thread);  assert (oi && oi->interface);  if (IS_OSPF6_DEBUG_INTERFACE)    zlog_info ("Interface Event %s: [InterfaceUp]",               oi->interface->name);  /* check physical interface is up */  if (! if_is_up (oi->interface))    {      if (IS_OSPF6_DEBUG_INTERFACE)        zlog_info ("Interface %s is down, can't execute [InterfaceUp]",                   oi->interface->name);      return 0;    }  /* if already enabled, do nothing */  if (oi->state > OSPF6_INTERFACE_DOWN)    {      if (IS_OSPF6_DEBUG_INTERFACE)        zlog_info ("Interface %s already enabled",                   oi->interface->name);      return 0;    }  /* Join AllSPFRouters */  ospf6_join_allspfrouters (oi->interface->ifindex);  /* Update interface route */  ospf6_interface_connected_route_update (oi->interface);  /* Schedule Hello */  if (! CHECK_FLAG (oi->flag, OSPF6_INTERFACE_PASSIVE))    thread_add_event (master, ospf6_hello_send, oi, 0);  /* decide next interface state */  if (if_is_pointopoint (oi->interface))    ospf6_interface_state_change (OSPF6_INTERFACE_POINTTOPOINT, oi);  else if (oi->priority == 0)    ospf6_interface_state_change (OSPF6_INTERFACE_DROTHER, oi);  else    {      ospf6_interface_state_change (OSPF6_INTERFACE_WAITING, oi);      thread_add_timer (master, wait_timer, oi, oi->dead_interval);    }  return 0;}intwait_timer (struct thread *thread){  struct ospf6_interface *oi;  oi = (struct ospf6_interface *) THREAD_ARG (thread);  assert (oi && oi->interface);  if (IS_OSPF6_DEBUG_INTERFACE)    zlog_info ("Interface Event %s: [WaitTimer]",               oi->interface->name);  if (oi->state == OSPF6_INTERFACE_WAITING)    ospf6_interface_state_change (dr_election (oi), oi);  return 0;}intbackup_seen (struct thread *thread){  struct ospf6_interface *oi;  oi = (struct ospf6_interface *) THREAD_ARG (thread);  assert (oi && oi->interface);  if (IS_OSPF6_DEBUG_INTERFACE)    zlog_info ("Interface Event %s: [BackupSeen]",               oi->interface->name);  if (oi->state == OSPF6_INTERFACE_WAITING)    ospf6_interface_state_change (dr_election (oi), oi);  return 0;}intneighbor_change (struct thread *thread){  struct ospf6_interface *oi;  oi = (struct ospf6_interface *) THREAD_ARG (thread);  assert (oi && oi->interface);  if (IS_OSPF6_DEBUG_INTERFACE)    zlog_info ("Interface Event %s: [NeighborChange]",               oi->interface->name);  if (oi->state == OSPF6_INTERFACE_DROTHER ||      oi->state == OSPF6_INTERFACE_BDR ||      oi->state == OSPF6_INTERFACE_DR)    ospf6_interface_state_change (dr_election (oi), oi);  return 0;}intloopind (struct thread *thread){  struct ospf6_interface *oi;  oi = (struct ospf6_interface *) THREAD_ARG (thread);  assert (oi && oi->interface);  if (IS_OSPF6_DEBUG_INTERFACE)    zlog_info ("Interface Event %s: [LoopInd]",               oi->interface->name);  /* XXX not yet */  return 0;}intinterface_down (struct thread *thread){  struct ospf6_interface *oi;  listnode n;  struct ospf6_neighbor *on;  oi = (struct ospf6_interface *) THREAD_ARG (thread);  assert (oi && oi->interface);  if (IS_OSPF6_DEBUG_INTERFACE)    zlog_info ("Interface Event %s: [InterfaceDown]",               oi->interface->name);  /* Leave AllSPFRouters */  if (oi->state > OSPF6_INTERFACE_DOWN)    ospf6_leave_allspfrouters (oi->interface->ifindex);  ospf6_interface_state_change (OSPF6_INTERFACE_DOWN, oi);  for (n = listhead (oi->neighbor_list); n; nextnode (n))    {      on = (struct ospf6_neighbor *) getdata (n);      ospf6_neighbor_delete (on);    }  list_delete_all_node (oi->neighbor_list);  return 0;}/* show specified interface structure */intospf6_interface_show (struct vty *vty, struct interface *ifp){  struct ospf6_interface *oi;  struct connected *c;  struct prefix *p;  listnode i;  char strbuf[64], drouter[32], bdrouter[32];  char *updown[3] = {"down", "up", NULL};  char *type;  struct timeval res, now;  char duration[32];  struct ospf6_lsa *lsa;  /* check physical interface type */  if (if_is_loopback (ifp))    type = "LOOPBACK";  else if (if_is_broadcast (ifp))    type = "BROADCAST";  else if (if_is_pointopoint (ifp))    type = "POINTOPOINT";  else    type = "UNKNOWN";  vty_out (vty, "%s is %s, type %s%s",           ifp->name, updown[if_is_up (ifp)], type,	   VNL);  vty_out (vty, "  Interface ID: %d%s", ifp->ifindex, VNL);  if (ifp->info == NULL)    {      vty_out (vty, "   OSPF not enabled on this interface%s", VNL);      return 0;    }  else    oi = (struct ospf6_interface *) ifp->info;  vty_out (vty, "  Internet Address:%s", VNL);  for (i = listhead (ifp->connected); i; nextnode (i))    {      c = (struct connected *)getdata (i);      p = c->address;      prefix2str (p, strbuf, sizeof (strbuf));      switch (p->family)        {        case AF_INET:          vty_out (vty, "    inet : %s%s", strbuf,		   VNL);          break;        case AF_INET6:          vty_out (vty, "    inet6: %s%s", strbuf,		   VNL);          break;        default:          vty_out (vty, "    ???  : %s%s", strbuf,		   VNL);          break;        }    }  if (oi->area)    {      vty_out (vty, "  Instance ID %d, Interface MTU %d (autodetect: %d)%s",	       oi->instance_id, oi->ifmtu, ifp->mtu, VNL);      inet_ntop (AF_INET, &oi->area->area_id,                 strbuf, sizeof (strbuf));      vty_out (vty, "  Area ID %s, Cost %hu%s", strbuf, oi->cost,	       VNL);    }  else    vty_out (vty, "  Not Attached to Area%s", VNL);  vty_out (vty, "  State %s, Transmit Delay %d sec, Priority %d%s",           ospf6_interface_state_str[oi->state],           oi->transdelay, oi->priority,	   VNL);  vty_out (vty, "  Timer intervals configured:%s", VNL);  vty_out (vty, "   Hello %d, Dead %d, Retransmit %d%s",           oi->hello_interval, oi->dead_interval, oi->rxmt_interval,	   VNL);  inet_ntop (AF_INET, &oi->drouter, drouter, sizeof (drouter));  inet_ntop (AF_INET, &oi->bdrouter, bdrouter, sizeof (bdrouter));  vty_out (vty, "  DR: %s BDR: %s%s", drouter, bdrouter, VNL);  vty_out (vty, "  Number of I/F scoped LSAs is %u%s",           oi->lsdb->count, VNL);  gettimeofday (&now, (struct timezone *) NULL);  timerclear (&res);  if (oi->thread_send_lsupdate)    timersub (&oi->thread_send_lsupdate->u.sands, &now, &res);  timerstring (&res, duration, sizeof (duration));  vty_out (vty, "    %d Pending LSAs for LSUpdate in Time %s [thread %s]%s",           oi->lsupdate_list->count, duration,           (oi->thread_send_lsupdate ? "on" : "off"),           VNL);  for (lsa = ospf6_lsdb_head (oi->lsupdate_list); lsa;       lsa = ospf6_lsdb_next (lsa))    vty_out (vty, "      %s%s", lsa->name, VNL);  timerclear (&res);  if (oi->thread_send_lsack)    timersub (&oi->thread_send_lsack->u.sands, &now, &res);  timerstring (&res, duration, sizeof (duration));  vty_out (vty, "    %d Pending LSAs for LSAck in Time %s [thread %s]%s",           oi->lsack_list->count, duration,           (oi->thread_send_lsack ? "on" : "off"),           VNL);  for (lsa = ospf6_lsdb_head (oi->lsack_list); lsa;       lsa = ospf6_lsdb_next (lsa))    vty_out (vty, "      %s%s", lsa->name, VNL);  return 0;}/* show interface */DEFUN (show_ipv6_ospf6_interface,       show_ipv6_ospf6_interface_ifname_cmd,       "show ipv6 ospf6 interface IFNAME",       SHOW_STR       IP6_STR       OSPF6_STR       INTERFACE_STR       IFNAME_STR       ){  struct interface *ifp;  listnode i;  if (argc)    {      ifp = if_lookup_by_name (argv[0]);      if (ifp == NULL)        {          vty_out (vty, "No such Interface: %s%s", argv[0],                   VNL);          return CMD_WARNING;        }      ospf6_interface_show (vty, ifp);    }  else    {      for (i = listhead (iflist); i; nextnode (i))        {          ifp = (struct interface *) getdata (i);          ospf6_interface_show (vty, ifp);        }    }  return CMD_SUCCESS;}ALIAS (show_ipv6_ospf6_interface,       show_ipv6_ospf6_interface_cmd,       "show ipv6 ospf6 interface",       SHOW_STR       IP6_STR       OSPF6_STR       INTERFACE_STR       );DEFUN (show_ipv6_ospf6_interface_ifname_prefix,       show_ipv6_ospf6_interface_ifname_prefix_cmd,       "show ipv6 ospf6 interface IFNAME prefix",       SHOW_STR       IP6_STR       OSPF6_STR       INTERFACE_STR       IFNAME_STR       "Display connected prefixes to advertise\n"       ){  struct interface *ifp;  struct ospf6_interface *oi;  ifp = if_lookup_by_name (argv[0]);  if (ifp == NULL)    {      vty_out (vty, "No such Interface: %s%s", argv[0], VNL);      return CMD_WARNING;    }  oi = ifp->info;  if (oi == NULL)    {      vty_out (vty, "OSPFv3 is not enabled on %s%s", argv[0], VNL);      return CMD_WARNING;    }  argc--;  argv++;  ospf6_route_table_show (vty, argc, argv, oi->route_connected);  return CMD_SUCCESS;}ALIAS (show_ipv6_ospf6_interface_ifname_prefix,       show_ipv6_ospf6_interface_ifname_prefix_detail_cmd,       "show ipv6 ospf6 interface IFNAME prefix (X:X::X:X|X:X::X:X/M|detail)",       SHOW_STR       IP6_STR       OSPF6_STR       INTERFACE_STR       IFNAME_STR       "Display connected prefixes to advertise\n"       OSPF6_ROUTE_ADDRESS_STR       OSPF6_ROUTE_PREFIX_STR       "Dispaly details of the prefixes\n"       );ALIAS (show_ipv6_ospf6_interface_ifname_prefix,       show_ipv6_ospf6_interface_ifname_prefix_match_cmd,       "show ipv6 ospf6 interface IFNAME prefix X:X::X:X/M (match|detail)",       SHOW_STR       IP6_STR       OSPF6_STR       INTERFACE_STR       IFNAME_STR       "Display connected prefixes to advertise\n"       OSPF6_ROUTE_PREFIX_STR       OSPF6_ROUTE_MATCH_STR       "Dispaly details of the prefixes\n"       );DEFUN (show_ipv6_ospf6_interface_prefix,       show_ipv6_ospf6_interface_prefix_cmd,       "show ipv6 ospf6 interface prefix",       SHOW_STR       IP6_STR       OSPF6_STR       INTERFACE_STR       "Display connected prefixes to advertise\n"       ){  listnode i;  struct ospf6_interface *oi;  struct interface *ifp;  for (i = listhead (iflist); i; nextnode (i))    {      ifp = (struct interface *) getdata (i);      oi = (struct ospf6_interface *) ifp->info;      if (oi == NULL)        continue;      ospf6_route_table_show (vty, argc, argv, oi->route_connected);    }  return CMD_SUCCESS;}ALIAS (show_ipv6_ospf6_interface_prefix,       show_ipv6_ospf6_interface_prefix_detail_cmd,       "show ipv6 ospf6 interface prefix (X:X::X:X|X:X::X:X/M|detail)",       SHOW_STR       IP6_STR       OSPF6_STR       INTERFACE_STR       "Display connected prefixes to advertise\n"       OSPF6_ROUTE_ADDRESS_STR       OSPF6_ROUTE_PREFIX_STR       "Dispaly details of the prefixes\n"       );ALIAS (show_ipv6_ospf6_interface_prefix,       show_ipv6_ospf6_interface_prefix_match_cmd,       "show ipv6 ospf6 interface prefix X:X::X:X/M (match|detail)",       SHOW_STR       IP6_STR       OSPF6_STR       INTERFACE_STR       "Display connected prefixes to advertise\n"       OSPF6_ROUTE_PREFIX_STR       OSPF6_ROUTE_MATCH_STR       "Dispaly details of the prefixes\n"       );/* interface variable set command */DEFUN (ipv6_ospf6_ifmtu,       ipv6_ospf6_ifmtu_cmd,       "ipv6 ospf6 ifmtu <1-65535>",       IP6_STR       OSPF6_STR       "Interface MTU\n"       "OSPFv3 Interface MTU\n"       ){  struct ospf6_interface *oi;  struct interface *ifp;  int ifmtu, iobuflen;  listnode node;  struct ospf6_neighbor *on;  ifp = (struct interface *) vty->index;  assert (ifp);  oi = (struct ospf6_interface *) ifp->info;  if (oi == NULL)    oi = ospf6_interface_create (ifp);  assert (oi);  ifmtu = strtol (argv[0], NULL, 10);  if (oi->ifmtu == ifmtu)    return CMD_SUCCESS;  if (ifp->mtu != 0 && ifp->mtu < ifmtu)    {      vty_out (vty, "%s's ospf6 ifmtu cannot go beyond physical mtu (%d)%s",               ifp->name, ifp->mtu, VNL);      return CMD_WARNING;    }  if (oi->ifmtu < ifmtu)    {      iobuflen = ospf6_iobuf_size (ifmtu);      if (iobuflen < ifmtu)        {          vty_out (vty, "%s's ifmtu is adjusted to I/O buffer size (%d).%s",

⌨️ 快捷键说明

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