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

📄 ospf6_abr.c

📁 linux 路由软件 可支持RIP OSPF BGP等
💻 C
📖 第 1 页 / 共 2 页
字号:
      OSPF6_ABR_SUMMARY_METRIC_SET (router_lsa, route->path.cost);      router_lsa->router_id = ADV_ROUTER_IN_PREFIX (&route->prefix);      type = htons (OSPF6_LSTYPE_INTER_ROUTER);    }  else    {      prefix_lsa = (struct ospf6_inter_prefix_lsa *)        ((caddr_t) lsa_header + sizeof (struct ospf6_lsa_header));      p = (caddr_t) prefix_lsa + sizeof (struct ospf6_inter_prefix_lsa);      /* Fill Inter-Area-Prefix-LSA */      OSPF6_ABR_SUMMARY_METRIC_SET (prefix_lsa, route->path.cost);      prefix_lsa->prefix.prefix_length = route->prefix.prefixlen;      prefix_lsa->prefix.prefix_options = route->path.prefix_options;      /* set Prefix */      memcpy (p, &route->prefix.u.prefix6,              OSPF6_PREFIX_SPACE (route->prefix.prefixlen));      ospf6_prefix_apply_mask (&prefix_lsa->prefix);      p += OSPF6_PREFIX_SPACE (route->prefix.prefixlen);      type = htons (OSPF6_LSTYPE_INTER_PREFIX);    }  /* Fill LSA Header */  lsa_header->age = 0;  lsa_header->type = type;  lsa_header->id = summary->path.origin.id;  lsa_header->adv_router = area->ospf6->router_id;  lsa_header->seqnum =    ospf6_new_ls_seqnum (lsa_header->type, lsa_header->id,                         lsa_header->adv_router, area->lsdb);  lsa_header->length = htons ((caddr_t) p - (caddr_t) lsa_header);  /* LSA checksum */  ospf6_lsa_checksum (lsa_header);  /* create LSA */  lsa = ospf6_lsa_create (lsa_header);  /* Originate */  ospf6_lsa_originate_area (lsa, area);}voidospf6_abr_range_update (struct ospf6_route *range){  u_int32_t cost = 0;  struct ospf6_route *ro;  assert (range->type == OSPF6_DEST_TYPE_RANGE);  /* update range's cost and active flag */  for (ro = ospf6_route_match_head (&range->prefix, ospf6->route_table);       ro; ro = ospf6_route_match_next (&range->prefix, ro))    {      if (ro->path.area_id == range->path.area_id &&          ! CHECK_FLAG (ro->flag, OSPF6_ROUTE_REMOVE))        cost = MAX (cost, ro->path.cost);    }  if (range->path.cost != cost)    {      range->path.cost = cost;      if (range->path.cost)        SET_FLAG (range->flag, OSPF6_ROUTE_ACTIVE_SUMMARY);      else        UNSET_FLAG (range->flag, OSPF6_ROUTE_ACTIVE_SUMMARY);      ospf6_abr_originate_summary (range);    }}voidospf6_abr_originate_summary (struct ospf6_route *route){  listnode node;  struct ospf6_area *oa;  struct ospf6_route *range = NULL;  if (route->type == OSPF6_DEST_TYPE_NETWORK)    {      oa = ospf6_area_lookup (route->path.area_id, ospf6);      range = ospf6_route_lookup_bestmatch (&route->prefix, oa->range_table);      if (range)        ospf6_abr_range_update (range);    }  for (node = listhead (ospf6->area_list); node; nextnode (node))    {      oa = (struct ospf6_area *) getdata (node);      ospf6_abr_originate_summary_to_area (route, oa);    }}/* RFC 2328 16.2. Calculating the inter-area routes */voidospf6_abr_examin_summary (struct ospf6_lsa *lsa, struct ospf6_area *oa){  struct prefix prefix, abr_prefix;  struct ospf6_route_table *table = NULL;  struct ospf6_route *range, *route, *old = NULL;  struct ospf6_route *abr_entry;  u_char type = 0;  char options[3] = {0, 0, 0};  u_int8_t prefix_options = 0;  u_int32_t cost = 0;  u_char router_bits = 0;  int i;  char buf[64];  int is_debug = 0;  if (lsa->header->type == htons (OSPF6_LSTYPE_INTER_PREFIX))    {      struct ospf6_inter_prefix_lsa *prefix_lsa;      if (IS_OSPF6_DEBUG_EXAMIN (INTER_PREFIX))        {          is_debug++;          zlog_info ("Examin %s in area %s", lsa->name, oa->name);        }      prefix_lsa = (struct ospf6_inter_prefix_lsa *)        OSPF6_LSA_HEADER_END (lsa->header);      prefix.family = AF_INET6;      prefix.prefixlen = prefix_lsa->prefix.prefix_length;      ospf6_prefix_in6_addr (&prefix.u.prefix6, &prefix_lsa->prefix);      prefix2str (&prefix, buf, sizeof (buf));      table = oa->ospf6->route_table;      type = OSPF6_DEST_TYPE_NETWORK;      prefix_options = prefix_lsa->prefix.prefix_options;      cost = OSPF6_ABR_SUMMARY_METRIC (prefix_lsa);    }  else if (lsa->header->type == htons (OSPF6_LSTYPE_INTER_ROUTER))    {      struct ospf6_inter_router_lsa *router_lsa;      if (IS_OSPF6_DEBUG_EXAMIN (INTER_ROUTER))        {          is_debug++;          zlog_info ("Examin %s in area %s", lsa->name, oa->name);        }      router_lsa = (struct ospf6_inter_router_lsa *)        OSPF6_LSA_HEADER_END (lsa->header);      ospf6_linkstate_prefix (router_lsa->router_id, htonl (0), &prefix);      inet_ntop (AF_INET, &router_lsa->router_id, buf, sizeof (buf));      table = oa->ospf6->brouter_table;      type = OSPF6_DEST_TYPE_ROUTER;      options[0] = router_lsa->options[0];      options[1] = router_lsa->options[1];      options[2] = router_lsa->options[2];      cost = OSPF6_ABR_SUMMARY_METRIC (router_lsa);      SET_FLAG (router_bits, OSPF6_ROUTER_BIT_E);    }  else    assert (0);  /* Find existing route */  route = ospf6_route_lookup (&prefix, table);  if (route)    ospf6_route_lock (route);  while (route && ospf6_route_is_prefix (&prefix, route))    {      if (route->path.area_id == oa->area_id &&          route->path.origin.type == lsa->header->type &&          route->path.origin.id == lsa->header->id &&          route->path.origin.adv_router == lsa->header->adv_router)        old = route;      route = ospf6_route_next (route);    }  /* (1) if cost == LSInfinity or if the LSA is MaxAge */  if (cost == LS_INFINITY)    {      if (is_debug)        zlog_info ("cost is LS_INFINITY, ignore");      if (old)        ospf6_route_remove (old, table);      return;    }  if (OSPF6_LSA_IS_MAXAGE (lsa))    {      if (is_debug)        zlog_info ("LSA is MaxAge, ignore");      if (old)        ospf6_route_remove (old, table);      return;    }  /* (2) if the LSA is self-originated, ignore */  if (lsa->header->adv_router == oa->ospf6->router_id)    {      if (is_debug)        zlog_info ("LSA is self-originated, ignore");      if (old)        ospf6_route_remove (old, table);      return;    }  /* (3) if the prefix is equal to an active configured address range */  if (lsa->header->type == htons (OSPF6_LSTYPE_INTER_PREFIX))    {      range = ospf6_route_lookup (&prefix, oa->range_table);      if (range)        {          if (is_debug)            zlog_info ("Prefix is equal to address range, ignore");          if (old)            ospf6_route_remove (old, table);          return;        }    }  /* (4) if the routing table entry for the ABR does not exist */  ospf6_linkstate_prefix (lsa->header->adv_router, htonl (0), &abr_prefix);  abr_entry = ospf6_route_lookup (&abr_prefix, oa->ospf6->brouter_table);  if (abr_entry == NULL || abr_entry->path.area_id != oa->area_id ||      CHECK_FLAG (abr_entry->flag, OSPF6_ROUTE_REMOVE) ||      ! CHECK_FLAG (abr_entry->path.router_bits, OSPF6_ROUTER_BIT_B))    {      if (is_debug)        zlog_info ("ABR router entry does not exist, ignore");      if (old)        ospf6_route_remove (old, table);      return;    }  /* (5),(6),(7) the path preference is handled by the sorting     in the routing table. Always install the path by substituting     old route (if any). */  if (old)    route = ospf6_route_copy (old);  else    route = ospf6_route_create ();  route->type = type;  route->prefix = prefix;  route->path.origin.type = lsa->header->type;  route->path.origin.id = lsa->header->id;  route->path.origin.adv_router = lsa->header->adv_router;  route->path.router_bits = router_bits;  route->path.options[0] = options[0];  route->path.options[1] = options[1];  route->path.options[2] = options[2];  route->path.prefix_options = prefix_options;  route->path.area_id = oa->area_id;  route->path.type = OSPF6_PATH_TYPE_INTER;  route->path.cost = abr_entry->path.cost + cost;  for (i = 0; i < OSPF6_MULTI_PATH_LIMIT; i++)    route->nexthop[i] = abr_entry->nexthop[i];  if (is_debug)    zlog_info ("Install route: %s", buf);  ospf6_route_add (route, table);}voidospf6_abr_examin_brouter (u_int32_t router_id){  struct ospf6_lsa *lsa;  struct ospf6_area *oa;  listnode node;  u_int16_t type;  type = htons (OSPF6_LSTYPE_INTER_ROUTER);  for (node = listhead (ospf6->area_list); node; nextnode (node))    {      oa = OSPF6_AREA (getdata (node));      for (lsa = ospf6_lsdb_type_router_head (type, router_id, oa->lsdb); lsa;           lsa = ospf6_lsdb_type_router_next (type, router_id, lsa))        ospf6_abr_examin_summary (lsa, oa);    }  type = htons (OSPF6_LSTYPE_INTER_PREFIX);  for (node = listhead (ospf6->area_list); node; nextnode (node))    {      oa = OSPF6_AREA (getdata (node));      for (lsa = ospf6_lsdb_type_router_head (type, router_id, oa->lsdb); lsa;           lsa = ospf6_lsdb_type_router_next (type, router_id, lsa))        ospf6_abr_examin_summary (lsa, oa);    }}/* Display functions */intospf6_inter_area_prefix_lsa_show (struct vty *vty, struct ospf6_lsa *lsa){  struct ospf6_inter_prefix_lsa *prefix_lsa;  struct in6_addr in6;  char buf[64];  prefix_lsa = (struct ospf6_inter_prefix_lsa *)    OSPF6_LSA_HEADER_END (lsa->header);  vty_out (vty, "     Metric: %lu%s",           (u_long) OSPF6_ABR_SUMMARY_METRIC (prefix_lsa), VNL);  ospf6_prefix_options_printbuf (prefix_lsa->prefix.prefix_options,                                 buf, sizeof (buf));  vty_out (vty, "     Prefix Options: %s%s", buf, VNL);  ospf6_prefix_in6_addr (&in6, &prefix_lsa->prefix);  inet_ntop (AF_INET6, &in6, buf, sizeof (buf));  vty_out (vty, "     Prefix: %s/%d%s", buf,           prefix_lsa->prefix.prefix_length, VNL);  return 0;}intospf6_inter_area_router_lsa_show (struct vty *vty, struct ospf6_lsa *lsa){  struct ospf6_inter_router_lsa *router_lsa;  char buf[64];  router_lsa = (struct ospf6_inter_router_lsa *)    OSPF6_LSA_HEADER_END (lsa->header);  ospf6_options_printbuf (router_lsa->options, buf, sizeof (buf));  vty_out (vty, "     Options: %s%s", buf, VNL);  vty_out (vty, "     Metric: %lu%s",           (u_long) OSPF6_ABR_SUMMARY_METRIC (router_lsa), VNL);  inet_ntop (AF_INET, &router_lsa->router_id, buf, sizeof (buf));  vty_out (vty, "     Destination Router ID: %s%s", buf, VNL);  return 0;}/* Debug commands */DEFUN (debug_ospf6_abr,       debug_ospf6_abr_cmd,       "debug ospf6 abr",       DEBUG_STR       OSPF6_STR       "Debug OSPFv3 ABR function\n"      ){  OSPF6_DEBUG_ABR_ON ();  return CMD_SUCCESS;}DEFUN (no_debug_ospf6_abr,       no_debug_ospf6_abr_cmd,       "no debug ospf6 abr",       NO_STR       DEBUG_STR       OSPF6_STR       "Debug OSPFv3 ABR function\n"      ){  OSPF6_DEBUG_ABR_OFF ();  return CMD_SUCCESS;}intconfig_write_ospf6_debug_abr (struct vty *vty){  if (IS_OSPF6_DEBUG_ABR)    vty_out (vty, "debug ospf6 abr%s", VNL);  return 0;}voidinstall_element_ospf6_debug_abr (){  install_element (ENABLE_NODE, &debug_ospf6_abr_cmd);  install_element (ENABLE_NODE, &no_debug_ospf6_abr_cmd);  install_element (CONFIG_NODE, &debug_ospf6_abr_cmd);  install_element (CONFIG_NODE, &no_debug_ospf6_abr_cmd);}struct ospf6_lsa_handler inter_prefix_handler ={  OSPF6_LSTYPE_INTER_PREFIX,  "Inter-Prefix",  ospf6_inter_area_prefix_lsa_show};struct ospf6_lsa_handler inter_router_handler ={  OSPF6_LSTYPE_INTER_ROUTER,  "Inter-Router",  ospf6_inter_area_router_lsa_show};voidospf6_abr_init (){  ospf6_install_lsa_handler (&inter_prefix_handler);  ospf6_install_lsa_handler (&inter_router_handler);}

⌨️ 快捷键说明

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