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

📄 ospf6_route.c

📁 zebra测试源代码用于 SOCKET 通信
💻 C
📖 第 1 页 / 共 3 页
字号:
       ospf6_route_next (&request))    ospf6_route_remove (&request, table);}struct ospf6_route_table *ospf6_route_table_create (char *name){  int i;  struct ospf6_route_table *new;  new = XCALLOC (MTYPE_OSPF6_ROUTE, sizeof (struct ospf6_route_table));  snprintf (new->name, sizeof (new->name), "%s", name);  new->table = route_table_init ();  for (i = 0; i < 3; i++)    new->hook_list[i] = linklist_create ();  return new;}voidospf6_route_table_delete (struct ospf6_route_table *table){  int i;  ospf6_route_remove_all (table);  route_table_finish (table->table);  for (i = 0; i < 3; i++)    linklist_delete (table->hook_list[i]);  XFREE (MTYPE_OSPF6_ROUTE, table);}voidospf6_route_table_freeze (struct ospf6_route_table *route_table){  if (IS_OSPF6_DUMP_ROUTE)    zlog_info ("ROUTE: Table freeze: %s", route_table->name);  assert (route_table->freeze == 0);  route_table->freeze = 1;}voidospf6_route_table_thaw (struct ospf6_route_table *route_table){  struct route_node *node;  struct linklist_node pnode;  struct linklist_node nnode;  struct ospf6_route_node   *rn;  struct ospf6_path_node    *pn;  struct ospf6_nexthop_node *nn;  struct ospf6_route_req request;  if (IS_OSPF6_DUMP_ROUTE)    zlog_info ("ROUTE: Table thaw: %s", route_table->name);  assert (route_table->freeze == 1);  route_table->freeze = 0;  for (node = route_top (route_table->table); node;       node = route_next (node))    {      rn = node->info;      if (! rn)        continue;      for (linklist_head (rn->path_list, &pnode);           ! linklist_end (&pnode);           linklist_next (&pnode))        {          pn = pnode.data;          for (linklist_head (pn->nexthop_list, &nnode);               ! linklist_end (&nnode);               linklist_next (&nnode))            {              nn = nnode.data;              /* if the add and remove flag set without change flag,                 do nothing with this route */              if (! CHECK_FLAG (nn->flag, OSPF6_ROUTE_FLAG_CHANGE) &&                  CHECK_FLAG (nn->flag, OSPF6_ROUTE_FLAG_ADD) &&                  CHECK_FLAG (nn->flag, OSPF6_ROUTE_FLAG_REMOVE))                {                  nn->flag = 0;                  continue;                }              memset (&request, 0, sizeof (request));              memcpy (&request.route, &rn->route, sizeof (rn->route));              memcpy (&request.path, &pn->path, sizeof (pn->path));              memcpy (&request.nexthop, &nn->nexthop, sizeof (nn->nexthop));              if (CHECK_FLAG (nn->flag, OSPF6_ROUTE_FLAG_ADD) ||                  CHECK_FLAG (nn->flag, OSPF6_ROUTE_FLAG_CHANGE))                ospf6_route_add (&request, route_table);              else if (CHECK_FLAG (nn->flag, OSPF6_ROUTE_FLAG_REMOVE))                ospf6_route_remove (&request, route_table);            }        }    }}/* VTY commands */voidospf6_route_show (struct vty *vty, struct ospf6_route_node *rn){  struct linklist_node pnode;  struct linklist_node nnode;  struct ospf6_path_node    *pn;  struct ospf6_nexthop_node *nn;  struct timeval now, res;  char duration[16];  u_int pc = 0;  u_int nc = 0;#define HEAD (pc == 0 && nc == 0)  char prefix[64], nexthop[64], ifname[IFNAMSIZ];  gettimeofday (&now, (struct timezone *) NULL);  /* destination */  if (rn->route.prefix.family == AF_INET ||      rn->route.prefix.family == AF_INET6)    prefix2str (&rn->route.prefix, prefix, sizeof (prefix));  else    prefix_ls2str (&rn->route.prefix, prefix, sizeof (prefix));  for (linklist_head (rn->path_list, &pnode); ! linklist_end (&pnode);       linklist_next (&pnode))    {      pn = pnode.data;      for (linklist_head (pn->nexthop_list, &nnode); ! linklist_end (&nnode);           linklist_next (&nnode))        {          nn = nnode.data;          inet_ntop (AF_INET6, &nn->nexthop.address, nexthop,                     sizeof (nexthop));          if (! if_indextoname (nn->nexthop.ifindex, ifname))            snprintf (ifname, sizeof (ifname), "%d", nn->nexthop.ifindex);          ospf6_timeval_sub (&now, &nn->installed, &res);          ospf6_timeval_string_summary (&res, duration, sizeof (duration));          vty_out (vty, "%c%1s %2s %-30s %-25s %6s %s%s",                   (HEAD ? '*' : ' '),                   DTYPE_ABNAME (rn->route.type),                   PTYPE_ABNAME (pn->path.type),                   prefix, nexthop, ifname, duration, VTY_NEWLINE);          nc++;        }      pc++;    }}voidospf6_route_show_detail (struct vty *vty, struct ospf6_route_node *rn){  struct linklist_node pnode;  struct linklist_node nnode;  struct ospf6_path_node    *pn;  struct ospf6_nexthop_node *nn;  u_int pc = 0;  u_int nc = 0;  char prefix[64], nexthop[64], ifname[IFNAMSIZ];  char area_id[16], type[16], id[16], adv[16];  char capa[64];  /* destination */  if (rn->route.prefix.family == AF_INET ||      rn->route.prefix.family == AF_INET6)    prefix2str (&rn->route.prefix, prefix, sizeof (prefix));  else    prefix_ls2str (&rn->route.prefix, prefix, sizeof (prefix));  vty_out (vty, "%s%s%s", VTY_NEWLINE, prefix, VTY_NEWLINE);  vty_out (vty, "    Destination Type: %s%s",           DTYPE_NAME (rn->route.type), VTY_NEWLINE);  for (linklist_head (rn->path_list, &pnode); ! linklist_end (&pnode);       linklist_next (&pnode))    {      pn = pnode.data;      inet_ntop (AF_INET, &pn->path.area_id, area_id, sizeof (area_id));      ospf6_lsa_type_string (pn->path.origin.type, type, sizeof (type));      inet_ntop (AF_INET, &pn->path.origin.id, id, sizeof (id));      inet_ntop (AF_INET, &pn->path.origin.adv_router, adv, sizeof (adv));      ospf6_options_string (pn->path.capability, capa, sizeof (capa));      vty_out (vty, "  Path:%s", VTY_NEWLINE);      vty_out (vty, "    Associated Area: %s%s", area_id, VTY_NEWLINE);      vty_out (vty, "    LS Origin: %s ID: %s Adv: %s%s",               type, id, adv, VTY_NEWLINE);      vty_out (vty, "    Path Type: %s%s",               PTYPE_NAME (pn->path.type), VTY_NEWLINE);      vty_out (vty, "    Metric Type: %d%s",               pn->path.metric_type, VTY_NEWLINE);      vty_out (vty, "    Cost: Type-1: %lu Type-2: %lu%s",               (u_long) pn->path.cost, (u_long) pn->path.cost_e2,               VTY_NEWLINE);      vty_out (vty, "    Router Bits: %s|%s|%s|%s%s",               (CHECK_FLAG (pn->path.router_bits, OSPF6_ROUTER_LSA_BIT_W) ?                "W" : "-"),               (CHECK_FLAG (pn->path.router_bits, OSPF6_ROUTER_LSA_BIT_V) ?                "V" : "-"),               (CHECK_FLAG (pn->path.router_bits, OSPF6_ROUTER_LSA_BIT_E) ?                "E" : "-"),               (CHECK_FLAG (pn->path.router_bits, OSPF6_ROUTER_LSA_BIT_B) ?                "B" : "-"), VTY_NEWLINE);      vty_out (vty, "    Optional Capabilities: %s%s", capa, VTY_NEWLINE);      vty_out (vty, "    Prefix Options: %s%s", "xxx", VTY_NEWLINE);      vty_out (vty, "    Next Hops:%s", VTY_NEWLINE);      for (linklist_head (pn->nexthop_list, &nnode); ! linklist_end (&nnode);           linklist_next (&nnode))        {          nn = nnode.data;          inet_ntop (AF_INET6, &nn->nexthop.address, nexthop,                     sizeof (nexthop));          if (! if_indextoname (nn->nexthop.ifindex, ifname))            snprintf (ifname, sizeof (ifname), "%d", nn->nexthop.ifindex);          vty_out (vty, "       %c%s%%%s%s",                   (HEAD ? '*' : ' '), nexthop, ifname, VTY_NEWLINE);          nc++;        }      pc++;    }  vty_out (vty, "%s", VTY_NEWLINE);}intospf6_route_table_show (struct vty *vty, int argc, char **argv,                        struct ospf6_route_table *table){  int i, ret;  unsigned long ret_ul;  char *endptr;  struct prefix prefix;  int detail = 0;  int arg_ipv6  = 0;  int arg_ipv4  = 0;  int arg_digit = 0;  struct prefix_ipv6 *p6 = (struct prefix_ipv6 *) &prefix;  struct prefix_ls   *pl = (struct prefix_ls *) &prefix;  struct route_node *node;  u_int route_count = 0;  u_int path_count = 0;  u_int route_redundant = 0;  memset (&prefix, 0, sizeof (struct prefix));  for (i = 0; i < argc; i++)    {      if (! strcmp (argv[i], "detail"))        {          detail++;          break;        }      if (! arg_ipv6 && ! arg_ipv4 && ! arg_digit)        {          if ((ret = inet_pton (AF_INET6, argv[i], &p6->prefix)) == 1)            {              p6->family = AF_INET6;              p6->prefixlen = 128;              arg_ipv6++;              continue;            }          else if ((ret = inet_pton (AF_INET, argv[i], &pl->adv_router)) == 1)            {              pl->family = AF_UNSPEC;              pl->prefixlen = 64; /* xxx */              arg_ipv4++;              continue;            }          else            {              ret_ul = strtoul (argv[i], &endptr, 10);              if (*endptr == '\0')                {                  pl->adv_router.s_addr = htonl (ret_ul);                  pl->family = AF_UNSPEC;                  pl->prefixlen = 64; /* xxx */                  arg_digit++;                  continue;                }              else                {                  vty_out (vty, "Malformed argument: %s%s",                           argv[i], VTY_NEWLINE);                  return CMD_SUCCESS;                }            }        }      if (arg_ipv4 || arg_digit)        {          if ((ret = inet_pton (AF_INET, argv[i], &pl->id)) == 1)            {              arg_ipv4++;            }          else            {              ret_ul = strtoul (argv[i], &endptr, 10);              if (*endptr == '\0')                {                  pl->id.s_addr = htonl (ret_ul);                  arg_digit++;                }              else                {                  vty_out (vty, "Malformed argument: %s%s",                           argv[i], VTY_NEWLINE);                  return CMD_SUCCESS;                }            }        }    }  if (arg_ipv4 || arg_ipv6 || arg_digit)    {      node = route_node_match (table->table, &prefix);      if (node && node->info)        ospf6_route_show_detail (vty, node->info);      return CMD_SUCCESS;    }  if (! detail)    {      vty_out (vty, "%s%c%1s %2s %-30s %-25s %6s%s", VTY_NEWLINE,               ' ', " ", " ", "Destination", "Gateway", "I/F", VTY_NEWLINE);      vty_out (vty, "---------------------------%s", VTY_NEWLINE);    }  for (node = route_top (table->table); node; node = route_next (node))    {      struct ospf6_route_node *route = node->info;      if (! route)        continue;      if (detail)        ospf6_route_show_detail (vty, route);      else        ospf6_route_show (vty, route);      route_count++;      path_count += route->path_list->count;      if (route->path_list->count > 1)        route_redundant++;    }  vty_out (vty, "===========%s", VTY_NEWLINE);  vty_out (vty, "Route: %d Path: %d Redundant: %d%s",           route_count, path_count, route_redundant, VTY_NEWLINE);  return CMD_SUCCESS;}

⌨️ 快捷键说明

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