version 1.1, 2012/02/21 17:26:11
|
version 1.1.1.3, 2013/07/21 23:54:38
|
Line 111 route_match_peer (void *rule, struct prefix *prefix, r
|
Line 111 route_match_peer (void *rule, struct prefix *prefix, r
|
void *object) |
void *object) |
{ |
{ |
union sockunion *su; |
union sockunion *su; |
union sockunion *su2; | union sockunion su_def = { .sa.sa_family = AF_INET, |
| .sin.sin_addr.s_addr = INADDR_ANY }; |
struct peer_group *group; |
struct peer_group *group; |
struct peer *peer; |
struct peer *peer; |
struct listnode *node, *nnode; |
struct listnode *node, *nnode; |
Line 127 route_match_peer (void *rule, struct prefix *prefix, r
|
Line 128 route_match_peer (void *rule, struct prefix *prefix, r
|
|
|
/* If su='0.0.0.0' (command 'match peer local'), and it's a NETWORK, |
/* If su='0.0.0.0' (command 'match peer local'), and it's a NETWORK, |
REDISTRIBUTE or DEFAULT_GENERATED route => return RMAP_MATCH */ |
REDISTRIBUTE or DEFAULT_GENERATED route => return RMAP_MATCH */ |
su2 = sockunion_str2su ("0.0.0.0"); | if (sockunion_same (su, &su_def)) |
if ( sockunion_same (su, su2) ) | |
{ |
{ |
int ret; |
int ret; |
if ( CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_NETWORK) || |
if ( CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_NETWORK) || |
Line 137 route_match_peer (void *rule, struct prefix *prefix, r
|
Line 137 route_match_peer (void *rule, struct prefix *prefix, r
|
ret = RMAP_MATCH; |
ret = RMAP_MATCH; |
else |
else |
ret = RMAP_NOMATCH; |
ret = RMAP_NOMATCH; |
|
|
sockunion_free (su2); |
|
return ret; |
return ret; |
} |
} |
sockunion_free (su2); | |
| |
if (! CHECK_FLAG (peer->sflags, PEER_STATUS_GROUP)) |
if (! CHECK_FLAG (peer->sflags, PEER_STATUS_GROUP)) |
{ |
{ |
if (sockunion_same (su, &peer->su)) |
if (sockunion_same (su, &peer->su)) |
Line 172 route_match_peer_compile (const char *arg)
|
Line 169 route_match_peer_compile (const char *arg)
|
|
|
su = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (union sockunion)); |
su = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (union sockunion)); |
|
|
ret = str2sockunion ( (arg)? arg : "0.0.0.0", su); | ret = str2sockunion (strcmp(arg, "local") ? arg : "0.0.0.0", su); |
if (ret < 0) { |
if (ret < 0) { |
XFREE (MTYPE_ROUTE_MAP_COMPILED, su); |
XFREE (MTYPE_ROUTE_MAP_COMPILED, su); |
return NULL; |
return NULL; |
Line 525 route_match_metric_compile (const char *arg)
|
Line 522 route_match_metric_compile (const char *arg)
|
char *endptr = NULL; |
char *endptr = NULL; |
unsigned long tmpval; |
unsigned long tmpval; |
|
|
|
/* Metric value shoud be integer. */ |
|
if (! all_digit (arg)) |
|
return NULL; |
|
|
|
errno = 0; |
tmpval = strtoul (arg, &endptr, 10); |
tmpval = strtoul (arg, &endptr, 10); |
if (*endptr != '\0' || tmpval == ULONG_MAX || tmpval > UINT32_MAX) | if (*endptr != '\0' || errno || tmpval > UINT32_MAX) |
return NULL; |
return NULL; |
|
|
med = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t)); |
med = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t)); |
Line 790 struct route_map_rule_cmd route_match_origin_cmd =
|
Line 792 struct route_map_rule_cmd route_match_origin_cmd =
|
route_match_origin_compile, |
route_match_origin_compile, |
route_match_origin_free |
route_match_origin_free |
}; |
}; |
|
|
|
/* match probability { */ |
|
|
|
static route_map_result_t |
|
route_match_probability (void *rule, struct prefix *prefix, |
|
route_map_object_t type, void *object) |
|
{ |
|
long r; |
|
#if _SVID_SOURCE || _BSD_SOURCE || _XOPEN_SOURCE >= 500 |
|
r = random(); |
|
#else |
|
r = (long) rand(); |
|
#endif |
|
|
|
switch (*(unsigned *) rule) |
|
{ |
|
case 0: break; |
|
case RAND_MAX: return RMAP_MATCH; |
|
default: |
|
if (r < *(unsigned *) rule) |
|
{ |
|
return RMAP_MATCH; |
|
} |
|
} |
|
|
|
return RMAP_NOMATCH; |
|
} |
|
|
|
static void * |
|
route_match_probability_compile (const char *arg) |
|
{ |
|
unsigned *lobule; |
|
unsigned perc; |
|
|
|
#if _SVID_SOURCE || _BSD_SOURCE || _XOPEN_SOURCE >= 500 |
|
srandom (time (NULL)); |
|
#else |
|
srand (time (NULL)); |
|
#endif |
|
|
|
perc = atoi (arg); |
|
lobule = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (unsigned)); |
|
|
|
switch (perc) |
|
{ |
|
case 0: *lobule = 0; break; |
|
case 100: *lobule = RAND_MAX; break; |
|
default: *lobule = RAND_MAX / 100 * perc; |
|
} |
|
|
|
return lobule; |
|
} |
|
|
|
static void |
|
route_match_probability_free (void *rule) |
|
{ |
|
XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); |
|
} |
|
|
|
struct route_map_rule_cmd route_match_probability_cmd = |
|
{ |
|
"probability", |
|
route_match_probability, |
|
route_match_probability_compile, |
|
route_match_probability_free |
|
}; |
|
|
|
/* } */ |
|
|
/* `set ip next-hop IP_ADDRESS' */ |
/* `set ip next-hop IP_ADDRESS' */ |
|
|
/* Set nexthop to object. ojbect must be pointer to struct attr. */ |
/* Set nexthop to object. ojbect must be pointer to struct attr. */ |
Line 804 route_set_ip_nexthop (void *rule, struct prefix *prefi
|
Line 875 route_set_ip_nexthop (void *rule, struct prefix *prefi
|
route_map_object_t type, void *object) |
route_map_object_t type, void *object) |
{ |
{ |
struct rmap_ip_nexthop_set *rins = rule; |
struct rmap_ip_nexthop_set *rins = rule; |
struct in_addr peer_address; |
|
struct bgp_info *bgp_info; |
struct bgp_info *bgp_info; |
struct peer *peer; |
struct peer *peer; |
|
|
Line 820 route_set_ip_nexthop (void *rule, struct prefix *prefi
|
Line 890 route_set_ip_nexthop (void *rule, struct prefix *prefi
|
&& peer->su_remote |
&& peer->su_remote |
&& sockunion_family (peer->su_remote) == AF_INET) |
&& sockunion_family (peer->su_remote) == AF_INET) |
{ |
{ |
inet_aton (sockunion_su2str (peer->su_remote), &peer_address); | bgp_info->attr->nexthop.s_addr = sockunion2ip (peer->su_remote); |
bgp_info->attr->nexthop = peer_address; | |
bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP); |
bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP); |
} |
} |
else if (CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT) |
else if (CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT) |
&& peer->su_local |
&& peer->su_local |
&& sockunion_family (peer->su_local) == AF_INET) |
&& sockunion_family (peer->su_local) == AF_INET) |
{ |
{ |
inet_aton (sockunion_su2str (peer->su_local), &peer_address); | bgp_info->attr->nexthop.s_addr = sockunion2ip (peer->su_local); |
bgp_info->attr->nexthop = peer_address; | |
bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP); |
bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP); |
} |
} |
} |
} |
Line 933 route_set_local_pref_compile (const char *arg)
|
Line 1001 route_set_local_pref_compile (const char *arg)
|
if (! all_digit (arg)) |
if (! all_digit (arg)) |
return NULL; |
return NULL; |
|
|
|
errno = 0; |
tmp = strtoul (arg, &endptr, 10); |
tmp = strtoul (arg, &endptr, 10); |
if (*endptr != '\0' || tmp == ULONG_MAX || tmp > UINT32_MAX) | if (*endptr != '\0' || errno || tmp > UINT32_MAX) |
return NULL; |
return NULL; |
|
|
local_pref = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t)); |
local_pref = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t)); |
Line 1001 route_set_weight_compile (const char *arg)
|
Line 1070 route_set_weight_compile (const char *arg)
|
if (! all_digit (arg)) |
if (! all_digit (arg)) |
return NULL; |
return NULL; |
|
|
| errno = 0; |
tmp = strtoul (arg, &endptr, 10); |
tmp = strtoul (arg, &endptr, 10); |
if (*endptr != '\0' || tmp == ULONG_MAX || tmp > UINT32_MAX) | if (*endptr != '\0' || errno || tmp > UINT32_MAX) |
return NULL; |
return NULL; |
|
|
weight = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t)); |
weight = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t)); |
Line 1092 route_set_metric_compile (const char *arg)
|
Line 1161 route_set_metric_compile (const char *arg)
|
if (all_digit (arg)) |
if (all_digit (arg)) |
{ |
{ |
/* set metric value check*/ |
/* set metric value check*/ |
|
errno = 0; |
larg = strtoul (arg, &endptr, 10); |
larg = strtoul (arg, &endptr, 10); |
if (*endptr != '\0' || larg == ULONG_MAX || larg > UINT32_MAX) | if (*endptr != '\0' || errno || larg > UINT32_MAX) |
return NULL; |
return NULL; |
metric = larg; |
metric = larg; |
} |
} |
Line 1105 route_set_metric_compile (const char *arg)
|
Line 1175 route_set_metric_compile (const char *arg)
|
|| (! all_digit (arg+1))) |
|| (! all_digit (arg+1))) |
return NULL; |
return NULL; |
|
|
|
errno = 0; |
larg = strtoul (arg+1, &endptr, 10); |
larg = strtoul (arg+1, &endptr, 10); |
if (*endptr != '\0' || larg == ULONG_MAX || larg > UINT32_MAX) | if (*endptr != '\0' || errno || larg > UINT32_MAX) |
return NULL; |
return NULL; |
metric = larg; |
metric = larg; |
} |
} |
Line 1276 route_set_community (void *rule, struct prefix *prefix
|
Line 1347 route_set_community (void *rule, struct prefix *prefix
|
{ |
{ |
attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES)); |
attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES)); |
attr->community = NULL; |
attr->community = NULL; |
|
/* See the longer comment down below. */ |
|
if (old && old->refcnt == 0) |
|
community_free(old); |
return RMAP_OKAY; |
return RMAP_OKAY; |
} |
} |
|
|
Line 2353 DEFUN (match_peer_local,
|
Line 2427 DEFUN (match_peer_local,
|
"Match peer address\n" |
"Match peer address\n" |
"Static or Redistributed routes\n") |
"Static or Redistributed routes\n") |
{ |
{ |
return bgp_route_match_add (vty, vty->index, "peer", NULL); | return bgp_route_match_add (vty, vty->index, "peer", "local"); |
} |
} |
|
|
DEFUN (no_match_peer, |
DEFUN (no_match_peer, |
Line 2462 ALIAS (no_match_ip_next_hop,
|
Line 2536 ALIAS (no_match_ip_next_hop,
|
"IP access-list number (expanded range)\n" |
"IP access-list number (expanded range)\n" |
"IP Access-list name\n") |
"IP Access-list name\n") |
|
|
|
/* match probability { */ |
|
|
|
DEFUN (match_probability, |
|
match_probability_cmd, |
|
"match probability <0-100>", |
|
MATCH_STR |
|
"Match portion of routes defined by percentage value\n" |
|
"Percentage of routes\n") |
|
{ |
|
return bgp_route_match_add (vty, vty->index, "probability", argv[0]); |
|
} |
|
|
|
DEFUN (no_match_probability, |
|
no_match_probability_cmd, |
|
"no match probability", |
|
NO_STR |
|
MATCH_STR |
|
"Match portion of routes defined by percentage value\n") |
|
{ |
|
return bgp_route_match_delete (vty, vty->index, "probability", argc ? argv[0] : NULL); |
|
} |
|
|
|
ALIAS (no_match_probability, |
|
no_match_probability_val_cmd, |
|
"no match probability <1-99>", |
|
NO_STR |
|
MATCH_STR |
|
"Match portion of routes defined by percentage value\n" |
|
"Percentage of routes\n") |
|
|
|
/* } */ |
|
|
DEFUN (match_ip_route_source, |
DEFUN (match_ip_route_source, |
match_ip_route_source_cmd, |
match_ip_route_source_cmd, |
"match ip route-source (<1-199>|<1300-2699>|WORD)", |
"match ip route-source (<1-199>|<1300-2699>|WORD)", |
Line 3749 bgp_route_map_init (void)
|
Line 3855 bgp_route_map_init (void)
|
route_map_install_match (&route_match_ecommunity_cmd); |
route_map_install_match (&route_match_ecommunity_cmd); |
route_map_install_match (&route_match_metric_cmd); |
route_map_install_match (&route_match_metric_cmd); |
route_map_install_match (&route_match_origin_cmd); |
route_map_install_match (&route_match_origin_cmd); |
|
route_map_install_match (&route_match_probability_cmd); |
|
|
route_map_install_set (&route_set_ip_nexthop_cmd); |
route_map_install_set (&route_set_ip_nexthop_cmd); |
route_map_install_set (&route_set_local_pref_cmd); |
route_map_install_set (&route_set_local_pref_cmd); |
Line 3780 bgp_route_map_init (void)
|
Line 3887 bgp_route_map_init (void)
|
install_element (RMAP_NODE, &match_ip_route_source_cmd); |
install_element (RMAP_NODE, &match_ip_route_source_cmd); |
install_element (RMAP_NODE, &no_match_ip_route_source_cmd); |
install_element (RMAP_NODE, &no_match_ip_route_source_cmd); |
install_element (RMAP_NODE, &no_match_ip_route_source_val_cmd); |
install_element (RMAP_NODE, &no_match_ip_route_source_val_cmd); |
|
|
install_element (RMAP_NODE, &match_ip_address_prefix_list_cmd); |
install_element (RMAP_NODE, &match_ip_address_prefix_list_cmd); |
install_element (RMAP_NODE, &no_match_ip_address_prefix_list_cmd); |
install_element (RMAP_NODE, &no_match_ip_address_prefix_list_cmd); |
install_element (RMAP_NODE, &no_match_ip_address_prefix_list_val_cmd); |
install_element (RMAP_NODE, &no_match_ip_address_prefix_list_val_cmd); |
Line 3808 bgp_route_map_init (void)
|
Line 3914 bgp_route_map_init (void)
|
install_element (RMAP_NODE, &match_origin_cmd); |
install_element (RMAP_NODE, &match_origin_cmd); |
install_element (RMAP_NODE, &no_match_origin_cmd); |
install_element (RMAP_NODE, &no_match_origin_cmd); |
install_element (RMAP_NODE, &no_match_origin_val_cmd); |
install_element (RMAP_NODE, &no_match_origin_val_cmd); |
|
install_element (RMAP_NODE, &match_probability_cmd); |
|
install_element (RMAP_NODE, &no_match_probability_cmd); |
|
install_element (RMAP_NODE, &no_match_probability_val_cmd); |
|
|
install_element (RMAP_NODE, &set_ip_nexthop_cmd); |
install_element (RMAP_NODE, &set_ip_nexthop_cmd); |
install_element (RMAP_NODE, &set_ip_nexthop_peer_cmd); |
install_element (RMAP_NODE, &set_ip_nexthop_peer_cmd); |