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

📄 ospf6_asbr.c

📁 linux 路由软件 可支持RIP OSPF BGP等
💻 C
📖 第 1 页 / 共 3 页
字号:
void *ospf6_routemap_rule_set_metric_type_compile (char *arg){  if (strcmp (arg, "type-2") && strcmp (arg, "type-1"))    return NULL;  return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);}voidospf6_routemap_rule_set_metric_type_free (void *rule){  XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);}struct route_map_rule_cmdospf6_routemap_rule_set_metric_type_cmd ={  "metric-type",  ospf6_routemap_rule_set_metric_type,  ospf6_routemap_rule_set_metric_type_compile,  ospf6_routemap_rule_set_metric_type_free,};route_map_result_tospf6_routemap_rule_set_metric (void *rule, struct prefix *prefix,                                route_map_object_t type, void *object){  char *metric = rule;  struct ospf6_route *route = object;  if (type != RMAP_OSPF6)    return RMAP_OKAY;  route->path.cost = atoi (metric);  return RMAP_OKAY;}void *ospf6_routemap_rule_set_metric_compile (char *arg){  u_int32_t metric;  char *endp;  metric = strtoul (arg, &endp, 0);  if (metric > LS_INFINITY || *endp != '\0')    return NULL;  return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);}voidospf6_routemap_rule_set_metric_free (void *rule){  XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);}struct route_map_rule_cmdospf6_routemap_rule_set_metric_cmd ={  "metric",  ospf6_routemap_rule_set_metric,  ospf6_routemap_rule_set_metric_compile,  ospf6_routemap_rule_set_metric_free,};route_map_result_tospf6_routemap_rule_set_forwarding (void *rule, struct prefix *prefix,                                    route_map_object_t type, void *object){  char *forwarding = rule;  struct ospf6_route *route = object;  struct ospf6_external_info *info = route->route_option;  if (type != RMAP_OSPF6)    return RMAP_OKAY;  if (inet_pton (AF_INET6, forwarding, &info->forwarding) != 1)    {      memset (&info->forwarding, 0, sizeof (struct in6_addr));      return RMAP_ERROR;    }  return RMAP_OKAY;}void *ospf6_routemap_rule_set_forwarding_compile (char *arg){  struct in6_addr a;  if (inet_pton (AF_INET6, arg, &a) != 1)    return NULL;  return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);}voidospf6_routemap_rule_set_forwarding_free (void *rule){  XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);}struct route_map_rule_cmdospf6_routemap_rule_set_forwarding_cmd ={  "forwarding-address",  ospf6_routemap_rule_set_forwarding,  ospf6_routemap_rule_set_forwarding_compile,  ospf6_routemap_rule_set_forwarding_free,};introute_map_command_status (struct vty *vty, int ret){  if (! ret)    return CMD_SUCCESS;  switch (ret)    {    case RMAP_RULE_MISSING:      vty_out (vty, "Can't find rule.%s", VNL);      break;    case RMAP_COMPILE_ERROR:      vty_out (vty, "Argument is malformed.%s", VNL);      break;    default:      vty_out (vty, "route-map add set failed.%s", VNL);      break;    }  return CMD_WARNING;}/* add "match address" */DEFUN (ospf6_routemap_match_address_prefixlist,       ospf6_routemap_match_address_prefixlist_cmd,       "match ipv6 address prefix-list WORD",       "Match values\n"       IPV6_STR       "Match address of route\n"       "Match entries of prefix-lists\n"       "IPv6 prefix-list name\n"){  int ret = route_map_add_match ((struct route_map_index *) vty->index,                                 "ipv6 address prefix-list", argv[0]);  return route_map_command_status (vty, ret);}/* delete "match address" */DEFUN (ospf6_routemap_no_match_address_prefixlist,       ospf6_routemap_no_match_address_prefixlist_cmd,       "no match ipv6 address prefix-list WORD",       NO_STR       "Match values\n"       IPV6_STR       "Match address of route\n"       "Match entries of prefix-lists\n"       "IPv6 prefix-list name\n"){  int ret = route_map_delete_match ((struct route_map_index *) vty->index,                                    "ipv6 address prefix-list", argv[0]);  return route_map_command_status (vty, ret);}/* add "set metric-type" */DEFUN (ospf6_routemap_set_metric_type,       ospf6_routemap_set_metric_type_cmd,       "set metric-type (type-1|type-2)",       "Set value\n"       "Type of metric\n"       "OSPF6 external type 1 metric\n"       "OSPF6 external type 2 metric\n"){  int ret = route_map_add_set ((struct route_map_index *) vty->index,                               "metric-type", argv[0]);  return route_map_command_status (vty, ret);}/* delete "set metric-type" */DEFUN (ospf6_routemap_no_set_metric_type,       ospf6_routemap_no_set_metric_type_cmd,       "no set metric-type (type-1|type-2)",       NO_STR       "Set value\n"       "Type of metric\n"       "OSPF6 external type 1 metric\n"       "OSPF6 external type 2 metric\n"){  int ret = route_map_delete_set ((struct route_map_index *) vty->index,                                  "metric-type", argv[0]);  return route_map_command_status (vty, ret);}/* add "set metric" */DEFUN (set_metric,       set_metric_cmd,       "set metric <0-4294967295>",       "Set value\n"       "Metric value\n"       "Metric value\n"){  int ret = route_map_add_set ((struct route_map_index *) vty->index,                               "metric", argv[0]);  return route_map_command_status (vty, ret);}/* delete "set metric" */DEFUN (no_set_metric,       no_set_metric_cmd,       "no set metric <0-4294967295>",       NO_STR       "Set value\n"       "Metric\n"       "METRIC value\n"){  int ret = route_map_delete_set ((struct route_map_index *) vty->index,                                  "metric", argv[0]);  return route_map_command_status (vty, ret);}/* add "set forwarding-address" */DEFUN (ospf6_routemap_set_forwarding,       ospf6_routemap_set_forwarding_cmd,       "set forwarding-address X:X::X:X",       "Set value\n"       "Forwarding Address\n"       "IPv6 Address\n"){  int ret = route_map_add_set ((struct route_map_index *) vty->index,                               "forwarding-address", argv[0]);  return route_map_command_status (vty, ret);}/* delete "set forwarding-address" */DEFUN (ospf6_routemap_no_set_forwarding,       ospf6_routemap_no_set_forwarding_cmd,       "no set forwarding-address X:X::X:X",       NO_STR       "Set value\n"       "Forwarding Address\n"       "IPv6 Address\n"){  int ret = route_map_delete_set ((struct route_map_index *) vty->index,                                  "forwarding-address", argv[0]);  return route_map_command_status (vty, ret);}voidospf6_routemap_init (){  route_map_init ();  route_map_init_vty ();  route_map_add_hook (ospf6_asbr_routemap_update);  route_map_delete_hook (ospf6_asbr_routemap_update);  route_map_install_match (&ospf6_routemap_rule_match_address_prefixlist_cmd);  route_map_install_set (&ospf6_routemap_rule_set_metric_type_cmd);  route_map_install_set (&ospf6_routemap_rule_set_metric_cmd);  route_map_install_set (&ospf6_routemap_rule_set_forwarding_cmd);  /* Match address prefix-list */  install_element (RMAP_NODE, &ospf6_routemap_match_address_prefixlist_cmd);  install_element (RMAP_NODE, &ospf6_routemap_no_match_address_prefixlist_cmd);  /* ASE Metric Type (e.g. Type-1/Type-2) */  install_element (RMAP_NODE, &ospf6_routemap_set_metric_type_cmd);  install_element (RMAP_NODE, &ospf6_routemap_no_set_metric_type_cmd);  /* ASE Metric */  install_element (RMAP_NODE, &set_metric_cmd);  install_element (RMAP_NODE, &no_set_metric_cmd);  /* ASE Metric */  install_element (RMAP_NODE, &ospf6_routemap_set_forwarding_cmd);  install_element (RMAP_NODE, &ospf6_routemap_no_set_forwarding_cmd);}/* Display functions */intospf6_as_external_lsa_show (struct vty *vty, struct ospf6_lsa *lsa){  struct ospf6_as_external_lsa *external;  char buf[64];  struct in6_addr in6, *forwarding;  assert (lsa->header);  external = (struct ospf6_as_external_lsa *)    OSPF6_LSA_HEADER_END (lsa->header);    /* bits */  snprintf (buf, sizeof (buf), "%c%c%c",    (CHECK_FLAG (external->bits_metric, OSPF6_ASBR_BIT_E) ? 'E' : '-'),    (CHECK_FLAG (external->bits_metric, OSPF6_ASBR_BIT_F) ? 'F' : '-'),    (CHECK_FLAG (external->bits_metric, OSPF6_ASBR_BIT_T) ? 'T' : '-'));  vty_out (vty, "     Bits: %s%s", buf, VNL);  vty_out (vty, "     Metric: %5lu%s", (u_long) OSPF6_ASBR_METRIC (external),           VNL);  ospf6_prefix_options_printbuf (external->prefix.prefix_options,                                 buf, sizeof (buf));  vty_out (vty, "     Prefix Options: %s%s", buf,           VNL);  vty_out (vty, "     Referenced LSType: %d%s",           ntohs (external->prefix.prefix_refer_lstype),           VNL);  ospf6_prefix_in6_addr (&in6, &external->prefix);  inet_ntop (AF_INET6, &in6, buf, sizeof (buf));  vty_out (vty, "     Prefix: %s/%d%s", buf,           external->prefix.prefix_length, VNL);  /* Forwarding-Address */  if (CHECK_FLAG (external->bits_metric, OSPF6_ASBR_BIT_F))    {      forwarding = (struct in6_addr *)        ((caddr_t) external + sizeof (struct ospf6_as_external_lsa) +         OSPF6_PREFIX_SPACE (external->prefix.prefix_length));      inet_ntop (AF_INET6, forwarding, buf, sizeof (buf));      vty_out (vty, "     Forwarding-Address: %s%s", buf, VNL);    }  return 0;}voidospf6_asbr_external_route_show (struct vty *vty, struct ospf6_route *route){  struct ospf6_external_info *info = route->route_option;  char prefix[64], id[16], forwarding[64];  u_int32_t tmp_id;  prefix2str (&route->prefix, prefix, sizeof (prefix));  tmp_id = ntohl (info->id);  inet_ntop (AF_INET, &tmp_id, id, sizeof (id));  if (! IN6_IS_ADDR_UNSPECIFIED (&info->forwarding))    inet_ntop (AF_INET6, &info->forwarding, forwarding, sizeof (forwarding));  else    snprintf (forwarding, sizeof (forwarding), ":: (ifindex %d)",              route->nexthop[0].ifindex);  vty_out (vty, "%s %-32s %-15s type-%d %5lu %s%s",           ZROUTE_ABNAME (info->type),           prefix, id, route->path.metric_type,           (u_long) (route->path.metric_type == 2 ?                     route->path.cost_e2 : route->path.cost),           forwarding, VNL);}DEFUN (show_ipv6_ospf6_redistribute,       show_ipv6_ospf6_redistribute_cmd,       "show ipv6 ospf6 redistribute",       SHOW_STR       IP6_STR       OSPF6_STR       "redistributing External information\n"       ){  struct ospf6_route *route;  ospf6_redistribute_show_config (vty);  for (route = ospf6_route_head (ospf6->external_table); route;       route = ospf6_route_next (route))    ospf6_asbr_external_route_show (vty, route);  return CMD_SUCCESS;}struct ospf6_lsa_handler as_external_handler ={  OSPF6_LSTYPE_AS_EXTERNAL,  "AS-External",  ospf6_as_external_lsa_show};voidospf6_asbr_init (){  ospf6_routemap_init ();  ospf6_install_lsa_handler (&as_external_handler);  install_element (VIEW_NODE, &show_ipv6_ospf6_redistribute_cmd);  install_element (ENABLE_NODE, &show_ipv6_ospf6_redistribute_cmd);  install_element (OSPF6_NODE, &ospf6_redistribute_cmd);  install_element (OSPF6_NODE, &ospf6_redistribute_routemap_cmd);  install_element (OSPF6_NODE, &no_ospf6_redistribute_cmd);}DEFUN (debug_ospf6_asbr,       debug_ospf6_asbr_cmd,       "debug ospf6 asbr",       DEBUG_STR       OSPF6_STR       "Debug OSPFv3 ASBR function\n"      ){  OSPF6_DEBUG_ASBR_ON ();  return CMD_SUCCESS;}DEFUN (no_debug_ospf6_asbr,       no_debug_ospf6_asbr_cmd,       "no debug ospf6 asbr",       NO_STR       DEBUG_STR       OSPF6_STR       "Debug OSPFv3 ASBR function\n"      ){  OSPF6_DEBUG_ASBR_OFF ();  return CMD_SUCCESS;}intconfig_write_ospf6_debug_asbr (struct vty *vty){  if (IS_OSPF6_DEBUG_ASBR)    vty_out (vty, "debug ospf6 asbr%s", VNL);  return 0;}voidinstall_element_ospf6_debug_asbr (){  install_element (ENABLE_NODE, &debug_ospf6_asbr_cmd);  install_element (ENABLE_NODE, &no_debug_ospf6_asbr_cmd);  install_element (CONFIG_NODE, &debug_ospf6_asbr_cmd);  install_element (CONFIG_NODE, &no_debug_ospf6_asbr_cmd);}

⌨️ 快捷键说明

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