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

📄 bgp_routemap.c

📁 大名鼎鼎的路由器源码。程序分ZEBRA、OSPFRIP等3个包。程序框架采用一个路由协议一个进程的方式
💻 C
📖 第 1 页 / 共 5 页
字号:
  struct in6_addr *address;  struct bgp_info *bgp_info;  if (type == RMAP_BGP)    {      /* Fetch routemap's rule information. */      address = rule;      bgp_info = object;          /* Set next hop value. */       bgp_info->attr->mp_nexthop_local = *address;          /* Set nexthop length. */      if (bgp_info->attr->mp_nexthop_len != 32)	bgp_info->attr->mp_nexthop_len = 32;    }  return RMAP_OKAY;}/* Route map `ip nexthop' compile function.  Given string is converted   to struct in_addr structure. */void *route_set_ipv6_nexthop_local_compile (char *arg){  int ret;  struct in6_addr *address;  address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in6_addr));  ret = inet_pton (AF_INET6, arg, address);  if (ret == 0)    {      XFREE (MTYPE_ROUTE_MAP_COMPILED, address);      return NULL;    }  return address;}/* Free route map's compiled `ip nexthop' value. */voidroute_set_ipv6_nexthop_local_free (void *rule){  XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);}/* Route map commands for ip nexthop set. */struct route_map_rule_cmd route_set_ipv6_nexthop_local_cmd ={  "ipv6 next-hop local",  route_set_ipv6_nexthop_local,  route_set_ipv6_nexthop_local_compile,  route_set_ipv6_nexthop_local_free};#endif /* HAVE_IPV6 *//* `set vpnv4 nexthop A.B.C.D' */route_map_result_troute_set_vpnv4_nexthop (void *rule, struct prefix *prefix, 			 route_map_object_t type, void *object){  struct in_addr *address;  struct bgp_info *bgp_info;  if (type == RMAP_BGP)    {      /* Fetch routemap's rule information. */      address = rule;      bgp_info = object;          /* Set next hop value. */       bgp_info->attr->mp_nexthop_global_in = *address;    }  return RMAP_OKAY;}void *route_set_vpnv4_nexthop_compile (char *arg){  int ret;  struct in_addr *address;  address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in_addr));  ret = inet_aton (arg, address);  if (ret == 0)    {      XFREE (MTYPE_ROUTE_MAP_COMPILED, address);      return NULL;    }  return address;}voidroute_set_vpnv4_nexthop_free (void *rule){  XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);}/* Route map commands for ip nexthop set. */struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd ={  "vpnv4 next-hop",  route_set_vpnv4_nexthop,  route_set_vpnv4_nexthop_compile,  route_set_vpnv4_nexthop_free};/* `set originator-id' *//* For origin set. */route_map_result_troute_set_originator_id (void *rule, struct prefix *prefix, route_map_object_t type, void *object){  struct in_addr *address;  struct bgp_info *bgp_info;  if (type == RMAP_BGP)     {      address = rule;      bgp_info = object;          bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID);      bgp_info->attr->originator_id = *address;    }  return RMAP_OKAY;}/* Compile function for originator-id set. */void *route_set_originator_id_compile (char *arg){  int ret;  struct in_addr *address;  address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in_addr));  ret = inet_aton (arg, address);  if (ret == 0)    {      XFREE (MTYPE_ROUTE_MAP_COMPILED, address);      return NULL;    }  return address;}/* Compile function for originator_id set. */voidroute_set_originator_id_free (void *rule){  XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);}/* Set metric rule structure. */struct route_map_rule_cmd route_set_originator_id_cmd = {  "originator-id",  route_set_originator_id,  route_set_originator_id_compile,  route_set_originator_id_free,};/* Add bgp route map rule. */intbgp_route_match_add (struct vty *vty, struct route_map_index *index,		    char *command, char *arg){  int ret;  ret = route_map_add_match (index, command, arg);  if (ret)    {      switch (ret)	{	case RMAP_RULE_MISSING:	  vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);	  return CMD_WARNING;	  break;	case RMAP_COMPILE_ERROR:	  vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);	  return CMD_WARNING;	  break;	}    }  return CMD_SUCCESS;}/* Delete bgp route map rule. */intbgp_route_match_delete (struct vty *vty, struct route_map_index *index,			char *command, char *arg){  int ret;  ret = route_map_delete_match (index, command, arg);  if (ret)    {      switch (ret)	{	case RMAP_RULE_MISSING:	  vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);	  return CMD_WARNING;	  break;	case RMAP_COMPILE_ERROR:	  vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);	  return CMD_WARNING;	  break;	}    }  return CMD_SUCCESS;}/* Add bgp route map rule. */intbgp_route_set_add (struct vty *vty, struct route_map_index *index,		   char *command, char *arg){  int ret;  ret = route_map_add_set (index, command, arg);  if (ret)    {      switch (ret)	{	case RMAP_RULE_MISSING:	  vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);	  return CMD_WARNING;	  break;	case RMAP_COMPILE_ERROR:	  vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);	  return CMD_WARNING;	  break;	}    }  return CMD_SUCCESS;}/* Delete bgp route map rule. */intbgp_route_set_delete (struct vty *vty, struct route_map_index *index,		      char *command, char *arg){  int ret;  ret = route_map_delete_set (index, command, arg);  if (ret)    {      switch (ret)	{	case RMAP_RULE_MISSING:	  vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);	  return CMD_WARNING;	  break;	case RMAP_COMPILE_ERROR:	  vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);	  return CMD_WARNING;	  break;	}    }  return CMD_SUCCESS;}/* Hook function for updating route_map assignment. */voidbgp_route_map_update (){  int i;  afi_t afi;  safi_t safi;  int direct;  struct listnode *nn, *nm;  struct bgp *bgp;  struct peer *peer;  struct peer_group *group;  struct bgp_filter *filter;  struct bgp_node *bn;  struct bgp_static *bgp_static;  /* For neighbor route-map updates. */  LIST_LOOP (bm->bgp, bgp, nn)    {      LIST_LOOP (bgp->peer, peer, nm)	{	  for (afi = AFI_IP; afi < AFI_MAX; afi++)	    for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)	      {		filter = &peer->filter[afi][safi];	  		for (direct = FILTER_IN; direct < FILTER_MAX; direct++)		  {		    if (filter->map[direct].name)		      filter->map[direct].map = 			route_map_lookup_by_name (filter->map[direct].name);		    else		      filter->map[direct].map = NULL;		  }		if (filter->usmap.name)		  filter->usmap.map = route_map_lookup_by_name (filter->usmap.name);		else		  filter->usmap.map = NULL;	      }	}      LIST_LOOP (bgp->group, group, nm)	{	  for (afi = AFI_IP; afi < AFI_MAX; afi++)	    for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)	      {		filter = &group->conf->filter[afi][safi];	  		for (direct = FILTER_IN; direct < FILTER_MAX; direct++)		  {		    if (filter->map[direct].name)		      filter->map[direct].map = 			route_map_lookup_by_name (filter->map[direct].name);		    else		      filter->map[direct].map = NULL;		  }		if (filter->usmap.name)		  filter->usmap.map = route_map_lookup_by_name (filter->usmap.name);		else		  filter->usmap.map = NULL;	      }	}    }  /* For default-originate route-map updates. */  LIST_LOOP (bm->bgp, bgp, nn)    {      LIST_LOOP (bgp->peer, peer, nm)	{	  for (afi = AFI_IP; afi < AFI_MAX; afi++)	    for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)	      {		if (peer->default_rmap[afi][safi].name)		  peer->default_rmap[afi][safi].map =		    route_map_lookup_by_name (peer->default_rmap[afi][safi].name);		else		  peer->default_rmap[afi][safi].map = NULL;	      }	}    }  /* For network route-map updates. */  LIST_LOOP (bm->bgp, bgp, nn)    {      for (afi = AFI_IP; afi < AFI_MAX; afi++)	for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)	  for (bn = bgp_table_top (bgp->route[afi][safi]); bn;	       bn = bgp_route_next (bn))	    if ((bgp_static = bn->info) != NULL)	      {		if (bgp_static->rmap.name)		  bgp_static->rmap.map =			 route_map_lookup_by_name (bgp_static->rmap.name);		else		  bgp_static->rmap.map = NULL;	      }    }  /* For redistribute route-map updates. */  LIST_LOOP (bm->bgp, bgp, nn)    {      for (i = 0; i < ZEBRA_ROUTE_MAX; i++)	{	  if (bgp->rmap[ZEBRA_FAMILY_IPV4][i].name)	    bgp->rmap[ZEBRA_FAMILY_IPV4][i].map = 	      route_map_lookup_by_name (bgp->rmap[ZEBRA_FAMILY_IPV4][i].name);#ifdef HAVE_IPV6	  if (bgp->rmap[ZEBRA_FAMILY_IPV6][i].name)	    bgp->rmap[ZEBRA_FAMILY_IPV6][i].map =	      route_map_lookup_by_name (bgp->rmap[ZEBRA_FAMILY_IPV6][i].name);#endif /* HAVE_IPV6 */	}    }}DEFUN (match_ip_address,        match_ip_address_cmd,       "match ip address (<1-199>|<1300-2699>|WORD)",       MATCH_STR       IP_STR       "Match address of route\n"       "IP access-list number\n"       "IP access-list number (expanded range)\n"       "IP Access-list name\n"){  return bgp_route_match_add (vty, vty->index, "ip address", argv[0]);}DEFUN (no_match_ip_address,        no_match_ip_address_cmd,       "no match ip address",       NO_STR       MATCH_STR       IP_STR       "Match address of route\n"){  if (argc == 0)    return bgp_route_match_delete (vty, vty->index, "ip address", NULL);  return bgp_route_match_delete (vty, vty->index, "ip address", argv[0]);}ALIAS (no_match_ip_address,        no_match_ip_address_val_cmd,       "no match ip address (<1-199>|<1300-2699>|WORD)",       NO_STR       MATCH_STR       IP_STR       "Match address of route\n"       "IP access-list number\n"       "IP access-list number (expanded range)\n"       "IP Access-list name\n");DEFUN (match_ip_next_hop,        match_ip_next_hop_cmd,       "match ip next-hop (<1-199>|<1300-2699>|WORD)",       MATCH_STR       IP_STR       "Match next-hop address of route\n"       "IP access-list number\n"       "IP access-list number (expanded range)\n"       "IP Access-list name\n"){  return bgp_route_match_add (vty, vty->index, "ip next-hop", argv[0]);}DEFUN (no_match_ip_next_hop,       no_match_ip_next_hop_cmd,       "no match ip next-hop",       NO_STR       MATCH_STR       IP_STR       "Match next-hop address of route\n"){  if (argc == 0)    return bgp_route_match_delete (vty, vty->index, "ip next-hop", NULL);  return bgp_route_match_delete (vty, vty->index, "ip next-hop", argv[0]);}ALIAS (no_match_ip_next_hop,       no_match_ip_next_hop_val_cmd,       "no match ip next-hop (<1-199>|<1300-2699>|WORD)",       NO_STR       MATCH_STR       IP_STR       "Match next-hop address of route\n"       "IP access-list number\n"       "IP access-list number (expanded range)\n"       "IP Access-list name\n");DEFUN (match_ip_address_prefix_list,        match_ip_address_prefix_list_cmd,       "match ip address prefix-list WORD",       MATCH_STR       IP_STR       "Match address of route\n"       "Match entries of prefix-lists\n"       "IP prefix-list name\n"){  return bgp_route_match_add (vty, vty->index, "ip address prefix-list", argv[0]);}DEFUN (no_match_ip_address_prefix_list,       no_match_ip_address_prefix_list_cmd,       "no match ip address prefix-list",       NO_STR       MATCH_STR       IP_STR       "Match address of route\n"       "Match entries of prefix-lists\n"){  if (argc == 0)    return bgp_route_match_delete (vty, vty->index, "ip address prefix-list", NULL);  return bgp_route_match_delete (vty, vty->index, "ip address prefix-list", argv[0]);}ALIAS (no_match_ip_address_prefix_list,       no_match_ip_address_prefix_list_val_cmd,       "no match ip address prefix-list WORD",       NO_STR       MATCH_STR       IP_STR       "Match address of route\n"       "Match entries of prefix-lists\n"       "IP prefix-list name\n");DEFUN (match_ip_next_hop_prefix_list,        match_ip_next_hop_prefix_list_cmd,       "match ip next-hop prefix-list WORD",       MATCH_STR       IP_STR       "Match next-hop address of route\n"       "Match entries of prefix-lists\n"       "IP prefix-list name\n"){  return bgp_route_match_add (vty, vty->index, "ip next-hop prefix-list", argv[0]);}DEFUN (no_match_ip_next_hop_prefix_list,       no_match_ip_next_hop_prefix_list_cmd,       "no match ip next-hop prefix-list",       NO_STR       MATCH_STR       IP_STR       "Match next-hop address of route\n"       "Match entries of prefix-lists\n"){  if (argc == 0)    return bgp_route_match_delete (vty, vty->index, "ip next-hop prefix-list", NULL);  return bgp_route_match_delete (vty, vty->index, "ip next-hop prefix-list", argv[0]);}ALIAS (no_match_ip_next_hop_prefix_list,       no_match_ip_next_hop_prefix_list_val_cmd,       "no match ip next-hop prefix-list WORD",       NO_STR       MATCH_STR       IP_STR       "Match next-hop address of route\n"       "Match entries of prefix-lists\n"       "IP prefix-list name\n");DEFUN (match_metric,        match_metric_cmd,       "match metric <0-4294967295>",       MATCH_STR       "Match metric of route\n"       "Metric value\n"){  return bgp_route_match_add (vty, vty->index, "metric", argv[0]);}DEFUN (no_match_metric,       no_match_metric_cmd,       "no match metric",       NO_STR       MATCH_STR       "Match metric of route\n"){  if (argc == 0)    return bgp_route_match_delete (vty, vty->index, "metric", NULL);  return bgp_route_match_delete (vty, vty->index, "metric", argv[0]);}

⌨️ 快捷键说明

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