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

📄 bgp_routemap.c

📁 linux 路由软件 可支持RIP OSPF BGP等
💻 C
📖 第 1 页 / 共 5 页
字号:
  int none;};/* For community set mechanism. */route_map_result_troute_set_community (void *rule, struct prefix *prefix,		     route_map_object_t type, void *object){  struct rmap_com_set *rcs;  struct bgp_info *binfo;  struct attr *attr;  struct community *new = NULL;  struct community *old;  struct community *merge;  if (type == RMAP_BGP)    {      rcs = rule;      binfo = object;      attr = binfo->attr;      old = attr->community;      /* "none" case.  */      if (rcs->none)	{	  attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES));	  attr->community = NULL;	  return RMAP_OKAY;	}      /* "additive" case.  */      if (rcs->additive && old)	{	  merge = community_merge (community_dup (old), rcs->com);	  new = community_uniq_sort (merge);	  community_free (merge);	}      else	new = community_dup (rcs->com);      attr->community = new;      attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES);    }  return RMAP_OKAY;}/* Compile function for set community. */void *route_set_community_compile (char *arg){  struct rmap_com_set *rcs;  struct community *com = NULL;  char *sp;  int additive = 0;  int none = 0;    if (strcmp (arg, "none") == 0)    none = 1;  else    {      sp = strstr (arg, "additive");      if (sp && sp > arg)  	{	  /* "additive" keyworkd is included.  */	  additive = 1;	  *(sp - 1) = '\0';	}      com = community_str2com (arg);      if (additive)	*(sp - 1) = ' ';      if (! com)	return NULL;    }    rcs = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct rmap_com_set));  memset (rcs, 0, sizeof (struct rmap_com_set));    rcs->com = com;  rcs->additive = additive;  rcs->none = none;    return rcs;}/* Free function for set community. */voidroute_set_community_free (void *rule){  struct rmap_com_set *rcs = rule;  if (rcs->com)    community_free (rcs->com);  XFREE (MTYPE_ROUTE_MAP_COMPILED, rcs);}/* Set community rule structure. */struct route_map_rule_cmd route_set_community_cmd = {  "community",  route_set_community,  route_set_community_compile,  route_set_community_free,};/* `set comm-list (<1-99>|<100-500>|WORD) delete' *//* For community set mechanism. */route_map_result_troute_set_community_delete (void *rule, struct prefix *prefix,			    route_map_object_t type, void *object){  struct community_list *list;  struct community *merge;  struct community *new;  struct community *old;  struct bgp_info *binfo;  if (type == RMAP_BGP)    {      if (! rule)	return RMAP_OKAY;      binfo = object;      list = community_list_lookup (bgp_clist, rule, COMMUNITY_LIST_MASTER);      old = binfo->attr->community;      if (list && old)	{	  merge = community_list_match_delete (old, list);	  new = community_uniq_sort (merge);	  community_free (merge);	  if (new->size == 0)	    {	      binfo->attr->community = NULL;	      binfo->attr->flag &= ~ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES);	      community_free (new);	    }	  else	    {	      binfo->attr->community = new;	      binfo->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES);	    }	}    }  return RMAP_OKAY;}/* Compile function for set community. */void *route_set_community_delete_compile (char *arg){  char *p;  char *str;  int len;  p = strchr (arg, ' ');  if (p)    {      len = p - arg;      str = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, len + 1);      memcpy (str, arg, len);    }  else    str = NULL;  return str;}/* Free function for set community. */voidroute_set_community_delete_free (void *rule){  XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);}/* Set community rule structure. */struct route_map_rule_cmd route_set_community_delete_cmd ={  "comm-list",  route_set_community_delete,  route_set_community_delete_compile,  route_set_community_delete_free,};/* `set extcommunity rt COMMUNITY' *//* For community set mechanism. */route_map_result_troute_set_ecommunity_rt (void *rule, struct prefix *prefix, 			 route_map_object_t type, void *object){  struct ecommunity *ecom;  struct ecommunity *new_ecom;  struct ecommunity *old_ecom;  struct bgp_info *bgp_info;  if (type == RMAP_BGP)    {      ecom = rule;      bgp_info = object;          if (! ecom)	return RMAP_OKAY;          /* We assume additive for Extended Community. */      old_ecom = bgp_info->attr->ecommunity;      if (old_ecom)	new_ecom = ecommunity_merge (ecommunity_dup (old_ecom), ecom);      else	new_ecom = ecommunity_dup (ecom);      bgp_info->attr->ecommunity = new_ecom;      if (old_ecom)	ecommunity_free (old_ecom);      bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_EXT_COMMUNITIES);    }  return RMAP_OKAY;}/* Compile function for set community. */void *route_set_ecommunity_rt_compile (char *arg){  struct ecommunity *ecom;  ecom = ecommunity_str2com (arg, ECOMMUNITY_TYPE_ROUTE_TARGET, 0);  if (! ecom)    return NULL;  return ecom;}/* Free function for set community. */voidroute_set_ecommunity_rt_free (void *rule){  struct ecommunity *ecom = rule;  ecommunity_free (ecom);}/* Set community rule structure. */struct route_map_rule_cmd route_set_ecommunity_rt_cmd = {  "extcommunity rt",  route_set_ecommunity_rt,  route_set_ecommunity_rt_compile,  route_set_ecommunity_rt_free,};/* `set extcommunity soo COMMUNITY' *//* For community set mechanism. */route_map_result_troute_set_ecommunity_soo (void *rule, struct prefix *prefix, 			 route_map_object_t type, void *object){  struct ecommunity *ecom;  struct ecommunity *new_ecom;  struct ecommunity *old_ecom;  struct bgp_info *bgp_info;  if (type == RMAP_BGP)    {      ecom = rule;      bgp_info = object;          if (! ecom)	return RMAP_OKAY;      /* We assume additive for Extended Community. */      old_ecom = bgp_info->attr->ecommunity;      if (old_ecom)        new_ecom = ecommunity_merge (ecommunity_dup (old_ecom), ecom);      else        new_ecom = ecommunity_dup (ecom);      bgp_info->attr->ecommunity = new_ecom;      if (old_ecom)	ecommunity_free (old_ecom);      bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_EXT_COMMUNITIES);    }  return RMAP_OKAY;}/* Compile function for set community. */void *route_set_ecommunity_soo_compile (char *arg){  struct ecommunity *ecom;  ecom = ecommunity_str2com (arg, ECOMMUNITY_TYPE_SITE_ORIGIN, 0);  if (! ecom)    return NULL;    return ecom;}/* Free function for set community. */voidroute_set_ecommunity_soo_free (void *rule){  struct ecommunity *ecom = rule;  ecommunity_free (ecom);}/* Set community rule structure. */struct route_map_rule_cmd route_set_ecommunity_soo_cmd = {  "extcommunity soo",  route_set_ecommunity_soo,  route_set_ecommunity_soo_compile,  route_set_ecommunity_soo_free,};/* `set extcommunity cost igp COMMUNITY' *//* For community set mechanism. */route_map_result_troute_set_ecommunity_cost_igp (void *rule, struct prefix *prefix, 			       route_map_object_t type, void *object){  struct ecommunity *ecom;  struct ecommunity *new_ecom;  struct ecommunity *old_ecom;  struct bgp_info *bgp_info;  if (type == RMAP_BGP)    {      ecom = rule;      bgp_info = object;          if (! ecom)	return RMAP_OKAY;          /* We assume additive for Extended Community. */      old_ecom = bgp_info->attr->ecommunity;      if (old_ecom)	new_ecom = ecommunity_merge (ecommunity_dup (old_ecom), ecom);      else	new_ecom = ecommunity_dup (ecom);      bgp_info->attr->ecommunity = new_ecom;      if (old_ecom)	ecommunity_free (old_ecom);      bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_EXT_COMMUNITIES);    }  return RMAP_OKAY;}/* Compile function for set community. */void *route_set_ecommunity_cost_igp_compile (char *arg){  struct ecommunity *ecom;  ecom = ecommunity_cost_str2com (arg, ECOMMUNITY_COST_POI_IGP);  if (! ecom)    return NULL;  return ecom;}/* Free function for set community. */voidroute_set_ecommunity_cost_igp_free (void *rule){  struct ecommunity *ecom = rule;  ecommunity_free (ecom);}/* Set community rule structure. */struct route_map_rule_cmd route_set_ecommunity_cost_igp_cmd = {  "extcommunity cost igp",  route_set_ecommunity_cost_igp,  route_set_ecommunity_cost_igp_compile,  route_set_ecommunity_cost_igp_free,};/* `set origin ORIGIN' *//* For origin set. */route_map_result_troute_set_origin (void *rule, struct prefix *prefix, route_map_object_t type, void *object){  u_char *origin;  struct bgp_info *bgp_info;  if (type == RMAP_BGP)    {      origin = rule;      bgp_info = object;          bgp_info->attr->origin = *origin;    }  return RMAP_OKAY;}/* Compile function for origin set. */void *route_set_origin_compile (char *arg){  u_char *origin;  origin = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_char));  if (strcmp (arg, "igp") == 0)    *origin = 0;  else if (strcmp (arg, "egp") == 0)    *origin = 1;  else    *origin = 2;  return origin;}/* Compile function for origin set. */voidroute_set_origin_free (void *rule){  XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);}/* Set metric rule structure. */struct route_map_rule_cmd route_set_origin_cmd = {  "origin",  route_set_origin,  route_set_origin_compile,  route_set_origin_free,};/* `set atomic-aggregate' *//* For atomic aggregate set. */route_map_result_troute_set_atomic_aggregate (void *rule, struct prefix *prefix,			    route_map_object_t type, void *object){  struct bgp_info *bgp_info;  if (type == RMAP_BGP)    {      bgp_info = object;      bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);    }  return RMAP_OKAY;}/* Compile function for atomic aggregate. */void *route_set_atomic_aggregate_compile (char *arg){  return (void *)1;}/* Compile function for atomic aggregate. */voidroute_set_atomic_aggregate_free (void *rule){  return;}/* Set atomic aggregate rule structure. */struct route_map_rule_cmd route_set_atomic_aggregate_cmd = {  "atomic-aggregate",  route_set_atomic_aggregate,  route_set_atomic_aggregate_compile,  route_set_atomic_aggregate_free,};/* `set aggregator as AS A.B.C.D' */struct aggregator{  as_t as;  struct in_addr address;};route_map_result_troute_set_aggregator_as (void *rule, struct prefix *prefix, 			 route_map_object_t type, void *object){  struct bgp_info *bgp_info;  struct aggregator *aggregator;  if (type == RMAP_BGP)    {      bgp_info = object;      aggregator = rule;          bgp_info->attr->aggregator_as = aggregator->as;      bgp_info->attr->aggregator_addr = aggregator->address;      bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR);    }  return RMAP_OKAY;}void *route_set_aggregator_as_compile (char *arg){  struct aggregator *aggregator;  char as[10];  char address[20];  aggregator = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct aggregator));  memset (aggregator, 0, sizeof (struct aggregator));  sscanf (arg, "%s %s", as, address);  aggregator->as = strtoul (as, NULL, 10);  inet_aton (address, &aggregator->address);  return aggregator;}voidroute_set_aggregator_as_free (void *rule){  XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);}struct route_map_rule_cmd route_set_aggregator_as_cmd = {  "aggregator as",  route_set_aggregator_as,  route_set_aggregator_as_compile,  route_set_aggregator_as_free,};#ifdef HAVE_IPV6/* `match ipv6 address IP_ACCESS_LIST' */route_map_result_troute_match_ipv6_address (void *rule, struct prefix *prefix, 			  route_map_object_t type, void *object){  struct access_list *alist;  if (type == RMAP_BGP)    {      alist = access_list_lookup (AFI_IP6, (char *) rule);      if (alist == NULL)	return RMAP_NOMATCH;

⌨️ 快捷键说明

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