diff options
| author | whitespace / reindent <invalid@invalid.invalid> | 2017-08-09 11:49:42 +0200 |
|---|---|---|
| committer | whitespace / reindent <invalid@invalid.invalid> | 2017-08-09 12:03:17 +0200 |
| commit | ac4d0be5874fafd14212d6007fff7495edc9b152 (patch) | |
| tree | 5e2f0d3189de928c849f9983406389ade3b098cb /bgpd/bgp_routemap.c | |
| parent | 76a86854181c27819e5cf71b12ae1fa5ccd9e02a (diff) | |
*: reindentreindent-3.0-after
indent.py `git ls-files | pcregrep '\.[ch]$' | pcregrep -v '^(ldpd|babeld|nhrpd)/'`
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to 'bgpd/bgp_routemap.c')
| -rw-r--r-- | bgpd/bgp_routemap.c | 5601 |
1 files changed, 2685 insertions, 2916 deletions
diff --git a/bgpd/bgp_routemap.c b/bgpd/bgp_routemap.c index 9b3a6a513a..822ddd6438 100644 --- a/bgpd/bgp_routemap.c +++ b/bgpd/bgp_routemap.c @@ -29,9 +29,9 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA #include "memory.h" #include "log.h" #ifdef HAVE_LIBPCREPOSIX -# include <pcreposix.h> +#include <pcreposix.h> #else -# include <regex.h> +#include <regex.h> #endif /* HAVE_LIBPCREPOSIX */ #include "buffer.h" #include "sockunion.h" @@ -56,7 +56,7 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA #include "bgpd/bgp_debug.h" #if ENABLE_BGP_VNC -# include "bgpd/rfapi/bgp_rfapi_cfg.h" +#include "bgpd/rfapi/bgp_rfapi_cfg.h" #endif /* Memo of route-map commands. @@ -111,2913 +111,2669 @@ o Local extensions */ - /* generic value manipulation to be shared in multiple rules */ +/* generic value manipulation to be shared in multiple rules */ #define RMAP_VALUE_SET 0 #define RMAP_VALUE_ADD 1 #define RMAP_VALUE_SUB 2 -struct rmap_value -{ - u_int8_t action; - u_int8_t variable; - u_int32_t value; +struct rmap_value { + u_int8_t action; + u_int8_t variable; + u_int32_t value; }; -static int -route_value_match (struct rmap_value *rv, u_int32_t value) -{ - if (rv->variable == 0 && value == rv->value) - return RMAP_MATCH; +static int route_value_match(struct rmap_value *rv, u_int32_t value) +{ + if (rv->variable == 0 && value == rv->value) + return RMAP_MATCH; - return RMAP_NOMATCH; + return RMAP_NOMATCH; } -static u_int32_t -route_value_adjust (struct rmap_value *rv, u_int32_t current, struct peer *peer) +static u_int32_t route_value_adjust(struct rmap_value *rv, u_int32_t current, + struct peer *peer) { - u_int32_t value; + u_int32_t value; - switch (rv->variable) - { - case 1: - value = peer->rtt; - break; - default: - value = rv->value; - break; - } + switch (rv->variable) { + case 1: + value = peer->rtt; + break; + default: + value = rv->value; + break; + } - switch (rv->action) - { - case RMAP_VALUE_ADD: - if (current > UINT32_MAX-value) - return UINT32_MAX; - return current + value; - case RMAP_VALUE_SUB: - if (current <= value) - return 0; - return current - value; - default: - return value; - } + switch (rv->action) { + case RMAP_VALUE_ADD: + if (current > UINT32_MAX - value) + return UINT32_MAX; + return current + value; + case RMAP_VALUE_SUB: + if (current <= value) + return 0; + return current - value; + default: + return value; + } } -static void * -route_value_compile (const char *arg) +static void *route_value_compile(const char *arg) { - u_int8_t action = RMAP_VALUE_SET, var = 0; - unsigned long larg = 0; - char *endptr = NULL; - struct rmap_value *rv; + u_int8_t action = RMAP_VALUE_SET, var = 0; + unsigned long larg = 0; + char *endptr = NULL; + struct rmap_value *rv; - if (arg[0] == '+') - { - action = RMAP_VALUE_ADD; - arg++; - } - else if (arg[0] == '-') - { - action = RMAP_VALUE_SUB; - arg++; - } + if (arg[0] == '+') { + action = RMAP_VALUE_ADD; + arg++; + } else if (arg[0] == '-') { + action = RMAP_VALUE_SUB; + arg++; + } - if (all_digit(arg)) - { - errno = 0; - larg = strtoul (arg, &endptr, 10); - if (*arg == 0 || *endptr != 0 || errno || larg > UINT32_MAX) - return NULL; - } - else - { - if (strcmp(arg, "rtt") == 0) - var = 1; - else - return NULL; - } + if (all_digit(arg)) { + errno = 0; + larg = strtoul(arg, &endptr, 10); + if (*arg == 0 || *endptr != 0 || errno || larg > UINT32_MAX) + return NULL; + } else { + if (strcmp(arg, "rtt") == 0) + var = 1; + else + return NULL; + } - rv = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof(struct rmap_value)); - if (!rv) - return NULL; + rv = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(struct rmap_value)); + if (!rv) + return NULL; - rv->action = action; - rv->variable = var; - rv->value = larg; - return rv; + rv->action = action; + rv->variable = var; + rv->value = larg; + return rv; } -static void -route_value_free (void *rule) +static void route_value_free(void *rule) { - XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); + XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); } - /* generic as path object to be shared in multiple rules */ +/* generic as path object to be shared in multiple rules */ -static void * -route_aspath_compile (const char *arg) +static void *route_aspath_compile(const char *arg) { - struct aspath *aspath; + struct aspath *aspath; - aspath = aspath_str2aspath (arg); - if (! aspath) - return NULL; - return aspath; + aspath = aspath_str2aspath(arg); + if (!aspath) + return NULL; + return aspath; } -static void -route_aspath_free (void *rule) +static void route_aspath_free(void *rule) { - struct aspath *aspath = rule; - aspath_free (aspath); + struct aspath *aspath = rule; + aspath_free(aspath); } - /* 'match peer (A.B.C.D|X:X::X:X)' */ +/* 'match peer (A.B.C.D|X:X::X:X)' */ /* Compares the peer specified in the 'match peer' clause with the peer received in bgp_info->peer. If it is the same, or if the peer structure received is a peer_group containing it, returns RMAP_MATCH. */ -static route_map_result_t -route_match_peer (void *rule, struct prefix *prefix, route_map_object_t type, - void *object) -{ - union sockunion *su; - union sockunion su_def = { .sin = { .sin_family = AF_INET, - .sin_addr.s_addr = INADDR_ANY } }; - struct peer_group *group; - struct peer *peer; - struct listnode *node, *nnode; - - if (type == RMAP_BGP) - { - su = rule; - peer = ((struct bgp_info *) object)->peer; - - if ( ! CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT) && - ! CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_EXPORT) ) - return RMAP_NOMATCH; - - /* If su='0.0.0.0' (command 'match peer local'), and it's a NETWORK, - REDISTRIBUTE or DEFAULT_GENERATED route => return RMAP_MATCH */ - if (sockunion_same (su, &su_def)) - { - int ret; - if ( CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_NETWORK) || - CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE) || - CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_DEFAULT)) - ret = RMAP_MATCH; - else - ret = RMAP_NOMATCH; - return ret; - } - - if (! CHECK_FLAG (peer->sflags, PEER_STATUS_GROUP)) - { - if (sockunion_same (su, &peer->su)) - return RMAP_MATCH; - - return RMAP_NOMATCH; - } - else - { - group = peer->group; - for (ALL_LIST_ELEMENTS (group->peer, node, nnode, peer)) - { - if (sockunion_same (su, &peer->su)) - return RMAP_MATCH; - } - return RMAP_NOMATCH; - } - } - return RMAP_NOMATCH; -} - -static void * -route_match_peer_compile (const char *arg) -{ - union sockunion *su; - int ret; - - su = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (union sockunion)); - - ret = str2sockunion (strcmp(arg, "local") ? arg : "0.0.0.0", su); - if (ret < 0) { - XFREE (MTYPE_ROUTE_MAP_COMPILED, su); - return NULL; - } - - return su; +static route_map_result_t route_match_peer(void *rule, struct prefix *prefix, + route_map_object_t type, + void *object) +{ + union sockunion *su; + union sockunion su_def = { + .sin = {.sin_family = AF_INET, .sin_addr.s_addr = INADDR_ANY}}; + struct peer_group *group; + struct peer *peer; + struct listnode *node, *nnode; + + if (type == RMAP_BGP) { + su = rule; + peer = ((struct bgp_info *)object)->peer; + + if (!CHECK_FLAG(peer->rmap_type, PEER_RMAP_TYPE_IMPORT) + && !CHECK_FLAG(peer->rmap_type, PEER_RMAP_TYPE_EXPORT)) + return RMAP_NOMATCH; + + /* If su='0.0.0.0' (command 'match peer local'), and it's a + NETWORK, + REDISTRIBUTE or DEFAULT_GENERATED route => return RMAP_MATCH + */ + if (sockunion_same(su, &su_def)) { + int ret; + if (CHECK_FLAG(peer->rmap_type, PEER_RMAP_TYPE_NETWORK) + || CHECK_FLAG(peer->rmap_type, + PEER_RMAP_TYPE_REDISTRIBUTE) + || CHECK_FLAG(peer->rmap_type, + PEER_RMAP_TYPE_DEFAULT)) + ret = RMAP_MATCH; + else + ret = RMAP_NOMATCH; + return ret; + } + + if (!CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) { + if (sockunion_same(su, &peer->su)) + return RMAP_MATCH; + + return RMAP_NOMATCH; + } else { + group = peer->group; + for (ALL_LIST_ELEMENTS(group->peer, node, nnode, + peer)) { + if (sockunion_same(su, &peer->su)) + return RMAP_MATCH; + } + return RMAP_NOMATCH; + } + } + return RMAP_NOMATCH; +} + +static void *route_match_peer_compile(const char *arg) +{ + union sockunion *su; + int ret; + + su = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(union sockunion)); + + ret = str2sockunion(strcmp(arg, "local") ? arg : "0.0.0.0", su); + if (ret < 0) { + XFREE(MTYPE_ROUTE_MAP_COMPILED, su); + return NULL; + } + + return su; } /* Free route map's compiled `ip address' value. */ -static void -route_match_peer_free (void *rule) +static void route_match_peer_free(void *rule) { - XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); + XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); } /* Route map commands for ip address matching. */ -struct route_map_rule_cmd route_match_peer_cmd = -{ - "peer", - route_match_peer, - route_match_peer_compile, - route_match_peer_free -}; +struct route_map_rule_cmd route_match_peer_cmd = {"peer", route_match_peer, + route_match_peer_compile, + route_match_peer_free}; /* `match ip address IP_ACCESS_LIST' */ /* Match function should return 1 if match is success else return zero. */ -static route_map_result_t -route_match_ip_address (void *rule, struct prefix *prefix, - route_map_object_t type, void *object) -{ - struct access_list *alist; - /* struct prefix_ipv4 match; */ - - if (type == RMAP_BGP) - { - alist = access_list_lookup (AFI_IP, (char *) rule); - if (alist == NULL) +static route_map_result_t route_match_ip_address(void *rule, + struct prefix *prefix, + route_map_object_t type, + void *object) +{ + struct access_list *alist; + /* struct prefix_ipv4 match; */ + + if (type == RMAP_BGP) { + alist = access_list_lookup(AFI_IP, (char *)rule); + if (alist == NULL) + return RMAP_NOMATCH; + + return (access_list_apply(alist, prefix) == FILTER_DENY + ? RMAP_NOMATCH + : RMAP_MATCH); + } return RMAP_NOMATCH; - - return (access_list_apply (alist, prefix) == FILTER_DENY ? - RMAP_NOMATCH : RMAP_MATCH); - } - return RMAP_NOMATCH; } /* Route map `ip address' match statement. `arg' should be access-list name. */ -static void * -route_match_ip_address_compile (const char *arg) +static void *route_match_ip_address_compile(const char *arg) { - return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg); + return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg); } /* Free route map's compiled `ip address' value. */ -static void -route_match_ip_address_free (void *rule) +static void route_match_ip_address_free(void *rule) { - XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); + XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); } /* Route map commands for ip address matching. */ -struct route_map_rule_cmd route_match_ip_address_cmd = -{ - "ip address", - route_match_ip_address, - route_match_ip_address_compile, - route_match_ip_address_free -}; +struct route_map_rule_cmd route_match_ip_address_cmd = { + "ip address", route_match_ip_address, route_match_ip_address_compile, + route_match_ip_address_free}; /* `match ip next-hop IP_ADDRESS' */ /* Match function return 1 if match is success else return zero. */ -static route_map_result_t -route_match_ip_next_hop (void *rule, struct prefix *prefix, - route_map_object_t type, void *object) -{ - struct access_list *alist; - struct bgp_info *bgp_info; - struct prefix_ipv4 p; - - if (type == RMAP_BGP) - { - bgp_info = object; - p.family = AF_INET; - p.prefix = bgp_info->attr->nexthop; - p.prefixlen = IPV4_MAX_BITLEN; - - alist = access_list_lookup (AFI_IP, (char *) rule); - if (alist == NULL) +static route_map_result_t route_match_ip_next_hop(void *rule, + struct prefix *prefix, + route_map_object_t type, + void *object) +{ + struct access_list *alist; + struct bgp_info *bgp_info; + struct prefix_ipv4 p; + + if (type == RMAP_BGP) { + bgp_info = object; + p.family = AF_INET; + p.prefix = bgp_info->attr->nexthop; + p.prefixlen = IPV4_MAX_BITLEN; + + alist = access_list_lookup(AFI_IP, (char *)rule); + if (alist == NULL) + return RMAP_NOMATCH; + + return (access_list_apply(alist, &p) == FILTER_DENY + ? RMAP_NOMATCH + : RMAP_MATCH); + } return RMAP_NOMATCH; - - return (access_list_apply (alist, &p) == FILTER_DENY ? - RMAP_NOMATCH : RMAP_MATCH); - } - return RMAP_NOMATCH; } /* Route map `ip next-hop' match statement. `arg' is access-list name. */ -static void * -route_match_ip_next_hop_compile (const char *arg) +static void *route_match_ip_next_hop_compile(const char *arg) { - return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg); + return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg); } /* Free route map's compiled `ip address' value. */ -static void -route_match_ip_next_hop_free (void *rule) +static void route_match_ip_next_hop_free(void *rule) { - XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); + XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); } /* Route map commands for ip next-hop matching. */ -struct route_map_rule_cmd route_match_ip_next_hop_cmd = -{ - "ip next-hop", - route_match_ip_next_hop, - route_match_ip_next_hop_compile, - route_match_ip_next_hop_free -}; +struct route_map_rule_cmd route_match_ip_next_hop_cmd = { + "ip next-hop", route_match_ip_next_hop, route_match_ip_next_hop_compile, + route_match_ip_next_hop_free}; /* `match ip route-source ACCESS-LIST' */ /* Match function return 1 if match is success else return zero. */ -static route_map_result_t -route_match_ip_route_source (void *rule, struct prefix *prefix, - route_map_object_t type, void *object) -{ - struct access_list *alist; - struct bgp_info *bgp_info; - struct peer *peer; - struct prefix_ipv4 p; - - if (type == RMAP_BGP) - { - bgp_info = object; - peer = bgp_info->peer; - - if (! peer || sockunion_family (&peer->su) != AF_INET) - return RMAP_NOMATCH; - - p.family = AF_INET; - p.prefix = peer->su.sin.sin_addr; - p.prefixlen = IPV4_MAX_BITLEN; - - alist = access_list_lookup (AFI_IP, (char *) rule); - if (alist == NULL) +static route_map_result_t route_match_ip_route_source(void *rule, + struct prefix *prefix, + route_map_object_t type, + void *object) +{ + struct access_list *alist; + struct bgp_info *bgp_info; + struct peer *peer; + struct prefix_ipv4 p; + + if (type == RMAP_BGP) { + bgp_info = object; + peer = bgp_info->peer; + + if (!peer || sockunion_family(&peer->su) != AF_INET) + return RMAP_NOMATCH; + + p.family = AF_INET; + p.prefix = peer->su.sin.sin_addr; + p.prefixlen = IPV4_MAX_BITLEN; + + alist = access_list_lookup(AFI_IP, (char *)rule); + if (alist == NULL) + return RMAP_NOMATCH; + + return (access_list_apply(alist, &p) == FILTER_DENY + ? RMAP_NOMATCH + : RMAP_MATCH); + } return RMAP_NOMATCH; - - return (access_list_apply (alist, &p) == FILTER_DENY ? - RMAP_NOMATCH : RMAP_MATCH); - } - return RMAP_NOMATCH; } /* Route map `ip route-source' match statement. `arg' is access-list name. */ -static void * -route_match_ip_route_source_compile (const char *arg) +static void *route_match_ip_route_source_compile(const char *arg) { - return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg); + return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg); } /* Free route map's compiled `ip address' value. */ -static void -route_match_ip_route_source_free (void *rule) +static void route_match_ip_route_source_free(void *rule) { - XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); + XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); } /* Route map commands for ip route-source matching. */ -struct route_map_rule_cmd route_match_ip_route_source_cmd = -{ - "ip route-source", - route_match_ip_route_source, - route_match_ip_route_source_compile, - route_match_ip_route_source_free -}; +struct route_map_rule_cmd route_match_ip_route_source_cmd = { + "ip route-source", route_match_ip_route_source, + route_match_ip_route_source_compile, route_match_ip_route_source_free}; /* `match ip address prefix-list PREFIX_LIST' */ static route_map_result_t -route_match_ip_address_prefix_list (void *rule, struct prefix *prefix, - route_map_object_t type, void *object) +route_match_ip_address_prefix_list(void *rule, struct prefix *prefix, + route_map_object_t type, void *object) { - struct prefix_list *plist; + struct prefix_list *plist; - if (type == RMAP_BGP) - { - plist = prefix_list_lookup (AFI_IP, (char *) rule); - if (plist == NULL) - return RMAP_NOMATCH; + if (type == RMAP_BGP) { + plist = prefix_list_lookup(AFI_IP, (char *)rule); + if (plist == NULL) + return RMAP_NOMATCH; - return (prefix_list_apply (plist, prefix) == PREFIX_DENY ? - RMAP_NOMATCH : RMAP_MATCH); - } - return RMAP_NOMATCH; + return (prefix_list_apply(plist, prefix) == PREFIX_DENY + ? RMAP_NOMATCH + : RMAP_MATCH); + } + return RMAP_NOMATCH; } -static void * -route_match_ip_address_prefix_list_compile (const char *arg) +static void *route_match_ip_address_prefix_list_compile(const char *arg) { - return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg); + return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg); } -static void -route_match_ip_address_prefix_list_free (void *rule) +static void route_match_ip_address_prefix_list_free(void *rule) { - XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); + XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); } -struct route_map_rule_cmd route_match_ip_address_prefix_list_cmd = -{ - "ip address prefix-list", - route_match_ip_address_prefix_list, - route_match_ip_address_prefix_list_compile, - route_match_ip_address_prefix_list_free -}; +struct route_map_rule_cmd route_match_ip_address_prefix_list_cmd = { + "ip address prefix-list", route_match_ip_address_prefix_list, + route_match_ip_address_prefix_list_compile, + route_match_ip_address_prefix_list_free}; /* `match ip next-hop prefix-list PREFIX_LIST' */ static route_map_result_t -route_match_ip_next_hop_prefix_list (void *rule, struct prefix *prefix, - route_map_object_t type, void *object) +route_match_ip_next_hop_prefix_list(void *rule, struct prefix *prefix, + route_map_object_t type, void *object) { - struct prefix_list *plist; - struct bgp_info *bgp_info; - struct prefix_ipv4 p; + struct prefix_list *plist; + struct bgp_info *bgp_info; + struct prefix_ipv4 p; - if (type == RMAP_BGP) - { - bgp_info = object; - p.family = AF_INET; - p.prefix = bgp_info->attr->nexthop; - p.prefixlen = IPV4_MAX_BITLEN; + if (type == RMAP_BGP) { + bgp_info = object; + p.family = AF_INET; + p.prefix = bgp_info->attr->nexthop; + p.prefixlen = IPV4_MAX_BITLEN; - plist = prefix_list_lookup (AFI_IP, (char *) rule); - if (plist == NULL) - return RMAP_NOMATCH; + plist = prefix_list_lookup(AFI_IP, (char *)rule); + if (plist == NULL) + return RMAP_NOMATCH; - return (prefix_list_apply (plist, &p) == PREFIX_DENY ? - RMAP_NOMATCH : RMAP_MATCH); - } - return RMAP_NOMATCH; + return (prefix_list_apply(plist, &p) == PREFIX_DENY + ? RMAP_NOMATCH + : RMAP_MATCH); + } + return RMAP_NOMATCH; } -static void * -route_match_ip_next_hop_prefix_list_compile (const char *arg) +static void *route_match_ip_next_hop_prefix_list_compile(const char *arg) { - return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg); + return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg); } -static void -route_match_ip_next_hop_prefix_list_free (void *rule) +static void route_match_ip_next_hop_prefix_list_free(void *rule) { - XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); + XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); } -struct route_map_rule_cmd route_match_ip_next_hop_prefix_list_cmd = -{ - "ip next-hop prefix-list", - route_match_ip_next_hop_prefix_list, - route_match_ip_next_hop_prefix_list_compile, - route_match_ip_next_hop_prefix_list_free -}; +struct route_map_rule_cmd route_match_ip_next_hop_prefix_list_cmd = { + "ip next-hop prefix-list", route_match_ip_next_hop_prefix_list, + route_match_ip_next_hop_prefix_list_compile, + route_match_ip_next_hop_prefix_list_free}; /* `match ip route-source prefix-list PREFIX_LIST' */ static route_map_result_t -route_match_ip_route_source_prefix_list (void *rule, struct prefix *prefix, - route_map_object_t type, void *object) +route_match_ip_route_source_prefix_list(void *rule, struct prefix *prefix, + route_map_object_t type, void *object) { - struct prefix_list *plist; - struct bgp_info *bgp_info; - struct peer *peer; - struct prefix_ipv4 p; + struct prefix_list *plist; + struct bgp_info *bgp_info; + struct peer *peer; + struct prefix_ipv4 p; - if (type == RMAP_BGP) - { - bgp_info = object; - peer = bgp_info->peer; + if (type == RMAP_BGP) { + bgp_info = object; + peer = bgp_info->peer; - if (! peer || sockunion_family (&peer->su) != AF_INET) - return RMAP_NOMATCH; + if (!peer || sockunion_family(&peer->su) != AF_INET) + return RMAP_NOMATCH; - p.family = AF_INET; - p.prefix = peer->su.sin.sin_addr; - p.prefixlen = IPV4_MAX_BITLEN; + p.family = AF_INET; + p.prefix = peer->su.sin.sin_addr; + p.prefixlen = IPV4_MAX_BITLEN; - plist = prefix_list_lookup (AFI_IP, (char *) rule); - if (plist == NULL) - return RMAP_NOMATCH; + plist = prefix_list_lookup(AFI_IP, (char *)rule); + if (plist == NULL) + return RMAP_NOMATCH; - return (prefix_list_apply (plist, &p) == PREFIX_DENY ? - RMAP_NOMATCH : RMAP_MATCH); - } - return RMAP_NOMATCH; + return (prefix_list_apply(plist, &p) == PREFIX_DENY + ? RMAP_NOMATCH + : RMAP_MATCH); + } + return RMAP_NOMATCH; } -static void * -route_match_ip_route_source_prefix_list_compile (const char *arg) +static void *route_match_ip_route_source_prefix_list_compile(const char *arg) { - return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg); + return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg); } -static void -route_match_ip_route_source_prefix_list_free (void *rule) +static void route_match_ip_route_source_prefix_list_free(void *rule) { - XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); + XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); } -struct route_map_rule_cmd route_match_ip_route_source_prefix_list_cmd = -{ - "ip route-source prefix-list", - route_match_ip_route_source_prefix_list, - route_match_ip_route_source_prefix_list_compile, - route_match_ip_route_source_prefix_list_free -}; +struct route_map_rule_cmd route_match_ip_route_source_prefix_list_cmd = { + "ip route-source prefix-list", route_match_ip_route_source_prefix_list, + route_match_ip_route_source_prefix_list_compile, + route_match_ip_route_source_prefix_list_free}; /* `match local-preference LOCAL-PREF' */ /* Match function return 1 if match is success else return zero. */ -static route_map_result_t -route_match_local_pref (void *rule, struct prefix *prefix, - route_map_object_t type, void *object) -{ - u_int32_t *local_pref; - struct bgp_info *bgp_info; - - if (type == RMAP_BGP) - { - local_pref = rule; - bgp_info = object; - - if (bgp_info->attr->local_pref == *local_pref) - return RMAP_MATCH; - else +static route_map_result_t route_match_local_pref(void *rule, + struct prefix *prefix, + route_map_object_t type, + void *object) +{ + u_int32_t *local_pref; + struct bgp_info *bgp_info; + + if (type == RMAP_BGP) { + local_pref = rule; + bgp_info = object; + + if (bgp_info->attr->local_pref == *local_pref) + return RMAP_MATCH; + else + return RMAP_NOMATCH; + } return RMAP_NOMATCH; - } - return RMAP_NOMATCH; } /* Route map `match local-preference' match statement. `arg' is local-pref value */ -static void * -route_match_local_pref_compile (const char *arg) +static void *route_match_local_pref_compile(const char *arg) { - u_int32_t *local_pref; - char *endptr = NULL; - unsigned long tmpval; + u_int32_t *local_pref; + char *endptr = NULL; + unsigned long tmpval; - /* Locpref value shoud be integer. */ - if (! all_digit (arg)) - return NULL; + /* Locpref value shoud be integer. */ + if (!all_digit(arg)) + return NULL; - errno = 0; - tmpval = strtoul (arg, &endptr, 10); - if (*endptr != '\0' || errno || tmpval > UINT32_MAX) - return NULL; + errno = 0; + tmpval = strtoul(arg, &endptr, 10); + if (*endptr != '\0' || errno || tmpval > UINT32_MAX) + return NULL; - local_pref = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t)); + local_pref = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(u_int32_t)); - if (!local_pref) - return local_pref; + if (!local_pref) + return local_pref; - *local_pref = tmpval; - return local_pref; + *local_pref = tmpval; + return local_pref; } /* Free route map's compiled `match local-preference' value. */ -static void -route_match_local_pref_free (void *rule) +static void route_match_local_pref_free(void *rule) { - XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); + XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); } /* Route map commands for metric matching. */ -struct route_map_rule_cmd route_match_local_pref_cmd = -{ - "local-preference", - route_match_local_pref, - route_match_local_pref_compile, - route_match_local_pref_free -}; +struct route_map_rule_cmd route_match_local_pref_cmd = { + "local-preference", route_match_local_pref, + route_match_local_pref_compile, route_match_local_pref_free}; /* `match metric METRIC' */ /* Match function return 1 if match is success else return zero. */ -static route_map_result_t -route_match_metric (void *rule, struct prefix *prefix, - route_map_object_t type, void *object) +static route_map_result_t route_match_metric(void *rule, struct prefix *prefix, + route_map_object_t type, + void *object) { - struct rmap_value *rv; - struct bgp_info *bgp_info; + struct rmap_value *rv; + struct bgp_info *bgp_info; - if (type == RMAP_BGP) - { - rv = rule; - bgp_info = object; - return route_value_match(rv, bgp_info->attr->med); - } - return RMAP_NOMATCH; + if (type == RMAP_BGP) { + rv = rule; + bgp_info = object; + return route_value_match(rv, bgp_info->attr->med); + } + return RMAP_NOMATCH; } /* Route map commands for metric matching. */ -struct route_map_rule_cmd route_match_metric_cmd = -{ - "metric", - route_match_metric, - route_value_compile, - route_value_free, +struct route_map_rule_cmd route_match_metric_cmd = { + "metric", route_match_metric, route_value_compile, route_value_free, }; /* `match as-path ASPATH' */ /* Match function for as-path match. I assume given object is */ -static route_map_result_t -route_match_aspath (void *rule, struct prefix *prefix, - route_map_object_t type, void *object) +static route_map_result_t route_match_aspath(void *rule, struct prefix *prefix, + route_map_object_t type, + void *object) { - struct as_list *as_list; - struct bgp_info *bgp_info; + struct as_list *as_list; + struct bgp_info *bgp_info; - if (type == RMAP_BGP) - { - as_list = as_list_lookup ((char *) rule); - if (as_list == NULL) - return RMAP_NOMATCH; + if (type == RMAP_BGP) { + as_list = as_list_lookup((char *)rule); + if (as_list == NULL) + return RMAP_NOMATCH; - bgp_info = object; + bgp_info = object; - /* Perform match. */ - return ((as_list_apply (as_list, bgp_info->attr->aspath) == AS_FILTER_DENY) ? RMAP_NOMATCH : RMAP_MATCH); - } - return RMAP_NOMATCH; + /* Perform match. */ + return ((as_list_apply(as_list, bgp_info->attr->aspath) + == AS_FILTER_DENY) + ? RMAP_NOMATCH + : RMAP_MATCH); + } + return RMAP_NOMATCH; } /* Compile function for as-path match. */ -static void * -route_match_aspath_compile (const char *arg) +static void *route_match_aspath_compile(const char *arg) { - return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg); + return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg); } /* Compile function for as-path match. */ -static void -route_match_aspath_free (void *rule) +static void route_match_aspath_free(void *rule) { - XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); + XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); } /* Route map commands for aspath matching. */ -struct route_map_rule_cmd route_match_aspath_cmd = -{ - "as-path", - route_match_aspath, - route_match_aspath_compile, - route_match_aspath_free -}; +struct route_map_rule_cmd route_match_aspath_cmd = { + "as-path", route_match_aspath, route_match_aspath_compile, + route_match_aspath_free}; /* `match community COMMUNIY' */ -struct rmap_community -{ - char *name; - int exact; +struct rmap_community { + char *name; + int exact; }; /* Match function for community match. */ -static route_map_result_t -route_match_community (void *rule, struct prefix *prefix, - route_map_object_t type, void *object) -{ - struct community_list *list; - struct bgp_info *bgp_info; - struct rmap_community *rcom; - - if (type == RMAP_BGP) - { - bgp_info = object; - rcom = rule; - - list = community_list_lookup (bgp_clist, rcom->name, COMMUNITY_LIST_MASTER); - if (! list) - return RMAP_NOMATCH; - - if (rcom->exact) - { - if (community_list_exact_match (bgp_info->attr->community, list)) - return RMAP_MATCH; - } - else - { - if (community_list_match (bgp_info->attr->community, list)) - return RMAP_MATCH; +static route_map_result_t route_match_community(void *rule, + struct prefix *prefix, + route_map_object_t type, + void *object) +{ + struct community_list *list; + struct bgp_info *bgp_info; + struct rmap_community *rcom; + + if (type == RMAP_BGP) { + bgp_info = object; + rcom = rule; + + list = community_list_lookup(bgp_clist, rcom->name, + COMMUNITY_LIST_MASTER); + if (!list) + return RMAP_NOMATCH; + + if (rcom->exact) { + if (community_list_exact_match( + bgp_info->attr->community, list)) + return RMAP_MATCH; + } else { + if (community_list_match(bgp_info->attr->community, + list)) + return RMAP_MATCH; + } } - } - return RMAP_NOMATCH; + return RMAP_NOMATCH; } /* Compile function for community match. */ -static void * -route_match_community_compile (const char *arg) -{ - struct rmap_community *rcom; - int len; - char *p; - - rcom = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct rmap_community)); - - p = strchr (arg, ' '); - if (p) - { - len = p - arg; - rcom->name = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, len + 1); - memcpy (rcom->name, arg, len); - rcom->exact = 1; - } - else - { - rcom->name = XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg); - rcom->exact = 0; - } - return rcom; +static void *route_match_community_compile(const char *arg) +{ + struct rmap_community *rcom; + int len; + char *p; + + rcom = XCALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(struct rmap_community)); + + p = strchr(arg, ' '); + if (p) { + len = p - arg; + rcom->name = XCALLOC(MTYPE_ROUTE_MAP_COMPILED, len + 1); + memcpy(rcom->name, arg, len); + rcom->exact = 1; + } else { + rcom->name = XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg); + rcom->exact = 0; + } + return rcom; } /* Compile function for community match. */ -static void -route_match_community_free (void *rule) +static void route_match_community_free(void *rule) { - struct rmap_community *rcom = rule; + struct rmap_community *rcom = rule; - XFREE (MTYPE_ROUTE_MAP_COMPILED, rcom->name); - XFREE (MTYPE_ROUTE_MAP_COMPILED, rcom); + XFREE(MTYPE_ROUTE_MAP_COMPILED, rcom->name); + XFREE(MTYPE_ROUTE_MAP_COMPILED, rcom); } /* Route map commands for community matching. */ -struct route_map_rule_cmd route_match_community_cmd = -{ - "community", - route_match_community, - route_match_community_compile, - route_match_community_free -}; +struct route_map_rule_cmd route_match_community_cmd = { + "community", route_match_community, route_match_community_compile, + route_match_community_free}; /* Match function for lcommunity match. */ -static route_map_result_t -route_match_lcommunity (void *rule, struct prefix *prefix, - route_map_object_t type, void *object) -{ - struct community_list *list; - struct bgp_info *bgp_info; - struct rmap_community *rcom; - - if (type == RMAP_BGP) - { - bgp_info = object; - rcom = rule; - - list = community_list_lookup (bgp_clist, rcom->name, - LARGE_COMMUNITY_LIST_MASTER); - if (! list) - return RMAP_NOMATCH; - - if (bgp_info->attr->extra && - lcommunity_list_match (bgp_info->attr->extra->lcommunity, list)) - return RMAP_MATCH; - - } - return RMAP_NOMATCH; +static route_map_result_t route_match_lcommunity(void *rule, + struct prefix *prefix, + route_map_object_t type, + void *object) +{ + struct community_list *list; + struct bgp_info *bgp_info; + struct rmap_community *rcom; + + if (type == RMAP_BGP) { + bgp_info = object; + rcom = rule; + + list = community_list_lookup(bgp_clist, rcom->name, + LARGE_COMMUNITY_LIST_MASTER); + if (!list) + return RMAP_NOMATCH; + + if (bgp_info->attr->extra + && lcommunity_list_match(bgp_info->attr->extra->lcommunity, + list)) + return RMAP_MATCH; + } + return RMAP_NOMATCH; } /* Compile function for community match. */ -static void * -route_match_lcommunity_compile (const char *arg) -{ - struct rmap_community *rcom; - int len; - char *p; - - rcom = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct rmap_community)); - - p = strchr (arg, ' '); - if (p) - { - len = p - arg; - rcom->name = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, len + 1); - memcpy (rcom->name, arg, len); - } - else - { - rcom->name = XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg); - rcom->exact = 0; - } - return rcom; +static void *route_match_lcommunity_compile(const char *arg) +{ + struct rmap_community *rcom; + int len; + char *p; + + rcom = XCALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(struct rmap_community)); + + p = strchr(arg, ' '); + if (p) { + len = p - arg; + rcom->name = XCALLOC(MTYPE_ROUTE_MAP_COMPILED, len + 1); + memcpy(rcom->name, arg, len); + } else { + rcom->name = XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg); + rcom->exact = 0; + } + return rcom; } /* Compile function for community match. */ -static void -route_match_lcommunity_free (void *rule) +static void route_match_lcommunity_free(void *rule) { - struct rmap_community *rcom = rule; + struct rmap_community *rcom = rule; - XFREE (MTYPE_ROUTE_MAP_COMPILED, rcom->name); - XFREE (MTYPE_ROUTE_MAP_COMPILED, rcom); + XFREE(MTYPE_ROUTE_MAP_COMPILED, rcom->name); + XFREE(MTYPE_ROUTE_MAP_COMPILED, rcom); } /* Route map commands for community matching. */ -struct route_map_rule_cmd route_match_lcommunity_cmd = -{ - "large-community", - route_match_lcommunity, - route_match_lcommunity_compile, - route_match_lcommunity_free -}; +struct route_map_rule_cmd route_match_lcommunity_cmd = { + "large-community", route_match_lcommunity, + route_match_lcommunity_compile, route_match_lcommunity_free}; /* Match function for extcommunity match. */ -static route_map_result_t -route_match_ecommunity (void *rule, struct prefix *prefix, - route_map_object_t type, void *object) +static route_map_result_t route_match_ecommunity(void *rule, + struct prefix *prefix, + route_map_object_t type, + void *object) { - struct community_list *list; - struct bgp_info *bgp_info; + struct community_list *list; + struct bgp_info *bgp_info; - if (type == RMAP_BGP) - { - bgp_info = object; + if (type == RMAP_BGP) { + bgp_info = object; - if (!bgp_info->attr->extra) - return RMAP_NOMATCH; + if (!bgp_info->attr->extra) + return RMAP_NOMATCH; - list = community_list_lookup (bgp_clist, (char *) rule, - EXTCOMMUNITY_LIST_MASTER); - if (! list) - return RMAP_NOMATCH; + list = community_list_lookup(bgp_clist, (char *)rule, + EXTCOMMUNITY_LIST_MASTER); + if (!list) + return RMAP_NOMATCH; - if (ecommunity_list_match (bgp_info->attr->extra->ecommunity, list)) - return RMAP_MATCH; - } - return RMAP_NOMATCH; + if (ecommunity_list_match(bgp_info->attr->extra->ecommunity, + list)) + return RMAP_MATCH; + } + return RMAP_NOMATCH; } /* Compile function for extcommunity match. */ -static void * -route_match_ecommunity_compile (const char *arg) +static void *route_match_ecommunity_compile(const char *arg) { - return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg); + return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg); } /* Compile function for extcommunity match. */ -static void -route_match_ecommunity_free (void *rule) +static void route_match_ecommunity_free(void *rule) { - XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); + XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); } /* Route map commands for community matching. */ -struct route_map_rule_cmd route_match_ecommunity_cmd = -{ - "extcommunity", - route_match_ecommunity, - route_match_ecommunity_compile, - route_match_ecommunity_free -}; +struct route_map_rule_cmd route_match_ecommunity_cmd = { + "extcommunity", route_match_ecommunity, route_match_ecommunity_compile, + route_match_ecommunity_free}; /* `match nlri` and `set nlri` are replaced by `address-family ipv4` and `address-family vpnv4'. */ /* `match origin' */ -static route_map_result_t -route_match_origin (void *rule, struct prefix *prefix, - route_map_object_t type, void *object) +static route_map_result_t route_match_origin(void *rule, struct prefix *prefix, + route_map_object_t type, + void *object) { - u_char *origin; - struct bgp_info *bgp_info; + u_char *origin; + struct bgp_info *bgp_info; - if (type == RMAP_BGP) - { - origin = rule; - bgp_info = object; + if (type == RMAP_BGP) { + origin = rule; + bgp_info = object; - if (bgp_info->attr->origin == *origin) - return RMAP_MATCH; - } + if (bgp_info->attr->origin == *origin) + return RMAP_MATCH; + } - return RMAP_NOMATCH; + return RMAP_NOMATCH; } -static void * -route_match_origin_compile (const char *arg) +static void *route_match_origin_compile(const char *arg) { - u_char *origin; + u_char *origin; - origin = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_char)); + 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; + if (strcmp(arg, "igp") == 0) + *origin = 0; + else if (strcmp(arg, "egp") == 0) + *origin = 1; + else + *origin = 2; - return origin; + return origin; } /* Free route map's compiled `ip address' value. */ -static void -route_match_origin_free (void *rule) +static void route_match_origin_free(void *rule) { - XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); + XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); } /* Route map commands for origin matching. */ -struct route_map_rule_cmd route_match_origin_cmd = -{ - "origin", - route_match_origin, - route_match_origin_compile, - route_match_origin_free -}; +struct route_map_rule_cmd route_match_origin_cmd = { + "origin", route_match_origin, route_match_origin_compile, + 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 = random(); - - switch (*(long *) rule) - { - case 0: break; - case RAND_MAX: return RMAP_MATCH; - default: - if (r < *(long *) rule) - { - return RMAP_MATCH; - } - } +static route_map_result_t route_match_probability(void *rule, + struct prefix *prefix, + route_map_object_t type, + void *object) +{ + long r = random(); + + switch (*(long *)rule) { + case 0: + break; + case RAND_MAX: + return RMAP_MATCH; + default: + if (r < *(long *)rule) { + return RMAP_MATCH; + } + } - return RMAP_NOMATCH; + return RMAP_NOMATCH; } -static void * -route_match_probability_compile (const char *arg) +static void *route_match_probability_compile(const char *arg) { - long *lobule; - unsigned perc; + long *lobule; + unsigned perc; - perc = atoi (arg); - lobule = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (long)); + perc = atoi(arg); + lobule = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(long)); - switch (perc) - { - case 0: *lobule = 0; break; - case 100: *lobule = RAND_MAX; break; - default: *lobule = RAND_MAX / 100 * perc; - } + switch (perc) { + case 0: + *lobule = 0; + break; + case 100: + *lobule = RAND_MAX; + break; + default: + *lobule = RAND_MAX / 100 * perc; + } - return lobule; + return lobule; } -static void -route_match_probability_free (void *rule) +static void route_match_probability_free(void *rule) { - XFREE (MTYPE_ROUTE_MAP_COMPILED, 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 -}; +struct route_map_rule_cmd route_match_probability_cmd = { + "probability", route_match_probability, route_match_probability_compile, + route_match_probability_free}; /* `match interface IFNAME' */ /* Match function should return 1 if match is success else return zero. */ -static route_map_result_t -route_match_interface (void *rule, struct prefix *prefix, - route_map_object_t type, void *object) +static route_map_result_t route_match_interface(void *rule, + struct prefix *prefix, + route_map_object_t type, + void *object) { - struct interface *ifp; - struct bgp_info *info; + struct interface *ifp; + struct bgp_info *info; - if (type == RMAP_BGP) - { - info = object; + if (type == RMAP_BGP) { + info = object; - if (!info || !info->attr) - return RMAP_NOMATCH; + if (!info || !info->attr) + return RMAP_NOMATCH; - ifp = if_lookup_by_name_all_vrf ((char *)rule); + ifp = if_lookup_by_name_all_vrf((char *)rule); - if (ifp == NULL || ifp->ifindex != info->attr->nh_ifindex) - return RMAP_NOMATCH; + if (ifp == NULL || ifp->ifindex != info->attr->nh_ifindex) + return RMAP_NOMATCH; - return RMAP_MATCH; - } - return RMAP_NOMATCH; + return RMAP_MATCH; + } + return RMAP_NOMATCH; } /* Route map `interface' match statement. `arg' should be interface name. */ -static void * -route_match_interface_compile (const char *arg) +static void *route_match_interface_compile(const char *arg) { - return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg); + return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg); } /* Free route map's compiled `interface' value. */ -static void -route_match_interface_free (void *rule) +static void route_match_interface_free(void *rule) { - XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); + XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); } /* Route map commands for ip address matching. */ -struct route_map_rule_cmd route_match_interface_cmd = -{ - "interface", - route_match_interface, - route_match_interface_compile, - route_match_interface_free -}; +struct route_map_rule_cmd route_match_interface_cmd = { + "interface", route_match_interface, route_match_interface_compile, + route_match_interface_free}; /* } */ /* `set ip next-hop IP_ADDRESS' */ /* Match function return 1 if match is success else return zero. */ -static route_map_result_t -route_match_tag (void *rule, struct prefix *prefix, - route_map_object_t type, void *object) +static route_map_result_t route_match_tag(void *rule, struct prefix *prefix, + route_map_object_t type, void *object) { - route_tag_t *tag; - struct bgp_info *bgp_info; + route_tag_t *tag; + struct bgp_info *bgp_info; - if (type == RMAP_BGP) - { - tag = rule; - bgp_info = object; + if (type == RMAP_BGP) { + tag = rule; + bgp_info = object; - if (!bgp_info->attr->extra) - return RMAP_NOMATCH; + if (!bgp_info->attr->extra) + return RMAP_NOMATCH; - return ((bgp_info->attr->extra->tag == *tag)? RMAP_MATCH : RMAP_NOMATCH); - } + return ((bgp_info->attr->extra->tag == *tag) ? RMAP_MATCH + : RMAP_NOMATCH); + } - return RMAP_NOMATCH; + return RMAP_NOMATCH; } /* Route map commands for tag matching. */ -static struct route_map_rule_cmd route_match_tag_cmd = -{ - "tag", - route_match_tag, - route_map_rule_tag_compile, - route_map_rule_tag_free, +static struct route_map_rule_cmd route_match_tag_cmd = { + "tag", route_match_tag, route_map_rule_tag_compile, + route_map_rule_tag_free, }; /* Set nexthop to object. ojbect must be pointer to struct attr. */ -struct rmap_ip_nexthop_set -{ - struct in_addr *address; - int peer_address; - int unchanged; +struct rmap_ip_nexthop_set { + struct in_addr *address; + int peer_address; + int unchanged; }; -static route_map_result_t -route_set_ip_nexthop (void *rule, struct prefix *prefix, - route_map_object_t type, void *object) -{ - struct rmap_ip_nexthop_set *rins = rule; - struct bgp_info *bgp_info; - struct peer *peer; - - if (type == RMAP_BGP) - { - bgp_info = object; - peer = bgp_info->peer; - - if (rins->unchanged) - { - SET_FLAG(bgp_info->attr->rmap_change_flags, - BATTR_RMAP_NEXTHOP_UNCHANGED); - } - else if (rins->peer_address) - { - if ((CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN) || - CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT)) - && peer->su_remote - && sockunion_family (peer->su_remote) == AF_INET) - { - bgp_info->attr->nexthop.s_addr = sockunion2ip (peer->su_remote); - bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP); - } - else if (CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT)) - { - /* The next hop value will be set as part of packet rewrite. - * Set the flags here to indicate that rewrite needs to be done. - * Also, clear the value. - */ - SET_FLAG(bgp_info->attr->rmap_change_flags, - BATTR_RMAP_NEXTHOP_PEER_ADDRESS); - bgp_info->attr->nexthop.s_addr = 0; - } - } - else - { - /* Set next hop value. */ - bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP); - bgp_info->attr->nexthop = *rins->address; - SET_FLAG(bgp_info->attr->rmap_change_flags, - BATTR_RMAP_IPV4_NHOP_CHANGED); +static route_map_result_t route_set_ip_nexthop(void *rule, + struct prefix *prefix, + route_map_object_t type, + void *object) +{ + struct rmap_ip_nexthop_set *rins = rule; + struct bgp_info *bgp_info; + struct peer *peer; + + if (type == RMAP_BGP) { + bgp_info = object; + peer = bgp_info->peer; + + if (rins->unchanged) { + SET_FLAG(bgp_info->attr->rmap_change_flags, + BATTR_RMAP_NEXTHOP_UNCHANGED); + } else if (rins->peer_address) { + if ((CHECK_FLAG(peer->rmap_type, PEER_RMAP_TYPE_IN) + || CHECK_FLAG(peer->rmap_type, + PEER_RMAP_TYPE_IMPORT)) + && peer->su_remote + && sockunion_family(peer->su_remote) == AF_INET) { + bgp_info->attr->nexthop.s_addr = + sockunion2ip(peer->su_remote); + bgp_info->attr->flag |= + ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP); + } else if (CHECK_FLAG(peer->rmap_type, + PEER_RMAP_TYPE_OUT)) { + /* The next hop value will be set as part of + * packet rewrite. + * Set the flags here to indicate that rewrite + * needs to be done. + * Also, clear the value. + */ + SET_FLAG(bgp_info->attr->rmap_change_flags, + BATTR_RMAP_NEXTHOP_PEER_ADDRESS); + bgp_info->attr->nexthop.s_addr = 0; + } + } else { + /* Set next hop value. */ + bgp_info->attr->flag |= + ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP); + bgp_info->attr->nexthop = *rins->address; + SET_FLAG(bgp_info->attr->rmap_change_flags, + BATTR_RMAP_IPV4_NHOP_CHANGED); + } } - } - return RMAP_OKAY; + return RMAP_OKAY; } /* Route map `ip nexthop' compile function. Given string is converted to struct in_addr structure. */ -static void * -route_set_ip_nexthop_compile (const char *arg) -{ - struct rmap_ip_nexthop_set *rins; - struct in_addr *address = NULL; - int peer_address = 0; - int unchanged = 0; - int ret; - - if (strcmp (arg, "peer-address") == 0) - peer_address = 1; - else if (strcmp (arg, "unchanged") == 0) - unchanged = 1; - else - { - 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; +static void *route_set_ip_nexthop_compile(const char *arg) +{ + struct rmap_ip_nexthop_set *rins; + struct in_addr *address = NULL; + int peer_address = 0; + int unchanged = 0; + int ret; + + if (strcmp(arg, "peer-address") == 0) + peer_address = 1; + else if (strcmp(arg, "unchanged") == 0) + unchanged = 1; + else { + 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; + } } - } - rins = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct rmap_ip_nexthop_set)); + rins = XCALLOC(MTYPE_ROUTE_MAP_COMPILED, + sizeof(struct rmap_ip_nexthop_set)); - rins->address = address; - rins->peer_address = peer_address; - rins->unchanged = unchanged; + rins->address = address; + rins->peer_address = peer_address; + rins->unchanged = unchanged; - return rins; + return rins; } /* Free route map's compiled `ip nexthop' value. */ -static void -route_set_ip_nexthop_free (void *rule) +static void route_set_ip_nexthop_free(void *rule) { - struct rmap_ip_nexthop_set *rins = rule; + struct rmap_ip_nexthop_set *rins = rule; - if (rins->address) - XFREE (MTYPE_ROUTE_MAP_COMPILED, rins->address); + if (rins->address) + XFREE(MTYPE_ROUTE_MAP_COMPILED, rins->address); - XFREE (MTYPE_ROUTE_MAP_COMPILED, rins); + XFREE(MTYPE_ROUTE_MAP_COMPILED, rins); } /* Route map commands for ip nexthop set. */ -struct route_map_rule_cmd route_set_ip_nexthop_cmd = -{ - "ip next-hop", - route_set_ip_nexthop, - route_set_ip_nexthop_compile, - route_set_ip_nexthop_free -}; +struct route_map_rule_cmd route_set_ip_nexthop_cmd = { + "ip next-hop", route_set_ip_nexthop, route_set_ip_nexthop_compile, + route_set_ip_nexthop_free}; /* `set local-preference LOCAL_PREF' */ /* Set local preference. */ -static route_map_result_t -route_set_local_pref (void *rule, struct prefix *prefix, - route_map_object_t type, void *object) -{ - struct rmap_value *rv; - struct bgp_info *bgp_info; - u_int32_t locpref = 0; - - if (type == RMAP_BGP) - { - /* Fetch routemap's rule information. */ - rv = rule; - bgp_info = object; - - /* Set local preference value. */ - if (bgp_info->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF)) - locpref = bgp_info->attr->local_pref; - - bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF); - bgp_info->attr->local_pref = route_value_adjust(rv, locpref, bgp_info->peer); - } +static route_map_result_t route_set_local_pref(void *rule, + struct prefix *prefix, + route_map_object_t type, + void *object) +{ + struct rmap_value *rv; + struct bgp_info *bgp_info; + u_int32_t locpref = 0; + + if (type == RMAP_BGP) { + /* Fetch routemap's rule information. */ + rv = rule; + bgp_info = object; + + /* Set local preference value. */ + if (bgp_info->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF)) + locpref = bgp_info->attr->local_pref; + + bgp_info->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF); + bgp_info->attr->local_pref = + route_value_adjust(rv, locpref, bgp_info->peer); + } - return RMAP_OKAY; + return RMAP_OKAY; } /* Set local preference rule structure. */ -struct route_map_rule_cmd route_set_local_pref_cmd = -{ - "local-preference", - route_set_local_pref, - route_value_compile, - route_value_free, +struct route_map_rule_cmd route_set_local_pref_cmd = { + "local-preference", route_set_local_pref, route_value_compile, + route_value_free, }; /* `set weight WEIGHT' */ /* Set weight. */ -static route_map_result_t -route_set_weight (void *rule, struct prefix *prefix, route_map_object_t type, - void *object) -{ - struct rmap_value *rv; - struct bgp_info *bgp_info; - u_int32_t weight; - - if (type == RMAP_BGP) - { - /* Fetch routemap's rule information. */ - rv = rule; - bgp_info = object; - - /* Set weight value. */ - weight = route_value_adjust(rv, 0, bgp_info->peer); - if (weight) - (bgp_attr_extra_get (bgp_info->attr))->weight = weight; - else if (bgp_info->attr->extra) - bgp_info->attr->extra->weight = 0; - } +static route_map_result_t route_set_weight(void *rule, struct prefix *prefix, + route_map_object_t type, + void *object) +{ + struct rmap_value *rv; + struct bgp_info *bgp_info; + u_int32_t weight; + + if (type == RMAP_BGP) { + /* Fetch routemap's rule information. */ + rv = rule; + bgp_info = object; + + /* Set weight value. */ + weight = route_value_adjust(rv, 0, bgp_info->peer); + if (weight) + (bgp_attr_extra_get(bgp_info->attr))->weight = weight; + else if (bgp_info->attr->extra) + bgp_info->attr->extra->weight = 0; + } - return RMAP_OKAY; + return RMAP_OKAY; } /* Set local preference rule structure. */ -struct route_map_rule_cmd route_set_weight_cmd = -{ - "weight", - route_set_weight, - route_value_compile, - route_value_free, +struct route_map_rule_cmd route_set_weight_cmd = { + "weight", route_set_weight, route_value_compile, route_value_free, }; /* `set metric METRIC' */ /* Set metric to attribute. */ -static route_map_result_t -route_set_metric (void *rule, struct prefix *prefix, - route_map_object_t type, void *object) -{ - struct rmap_value *rv; - struct bgp_info *bgp_info; - u_int32_t med = 0; - - if (type == RMAP_BGP) - { - /* Fetch routemap's rule information. */ - rv = rule; - bgp_info = object; - - if (bgp_info->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC)) - med = bgp_info->attr->med; - - bgp_info->attr->med = route_value_adjust(rv, med, bgp_info->peer); - bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC); - } - return RMAP_OKAY; +static route_map_result_t route_set_metric(void *rule, struct prefix *prefix, + route_map_object_t type, + void *object) +{ + struct rmap_value *rv; + struct bgp_info *bgp_info; + u_int32_t med = 0; + + if (type == RMAP_BGP) { + /* Fetch routemap's rule information. */ + rv = rule; + bgp_info = object; + + if (bgp_info->attr->flag + & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC)) + med = bgp_info->attr->med; + + bgp_info->attr->med = + route_value_adjust(rv, med, bgp_info->peer); + bgp_info->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC); + } + return RMAP_OKAY; } /* Set metric rule structure. */ -struct route_map_rule_cmd route_set_metric_cmd = -{ - "metric", - route_set_metric, - route_value_compile, - route_value_free, +struct route_map_rule_cmd route_set_metric_cmd = { + "metric", route_set_metric, route_value_compile, route_value_free, }; /* `set as-path prepend ASPATH' */ /* For AS path prepend mechanism. */ -static route_map_result_t -route_set_aspath_prepend (void *rule, struct prefix *prefix, route_map_object_t type, void *object) -{ - struct aspath *aspath; - struct aspath *new; - struct bgp_info *binfo; - - if (type == RMAP_BGP) - { - binfo = object; - - if (binfo->attr->aspath->refcnt) - new = aspath_dup (binfo->attr->aspath); - else - new = binfo->attr->aspath; - - if ((uintptr_t)rule > 10) - { - aspath = rule; - aspath_prepend (aspath, new); - } - else - { - as_t as = aspath_leftmost(new); - if (!as) as = binfo->peer->as; - new = aspath_add_seq_n (new, as, (uintptr_t) rule); - } +static route_map_result_t route_set_aspath_prepend(void *rule, + struct prefix *prefix, + route_map_object_t type, + void *object) +{ + struct aspath *aspath; + struct aspath *new; + struct bgp_info *binfo; + + if (type == RMAP_BGP) { + binfo = object; + + if (binfo->attr->aspath->refcnt) + new = aspath_dup(binfo->attr->aspath); + else + new = binfo->attr->aspath; + + if ((uintptr_t)rule > 10) { + aspath = rule; + aspath_prepend(aspath, new); + } else { + as_t as = aspath_leftmost(new); + if (!as) + as = binfo->peer->as; + new = aspath_add_seq_n(new, as, (uintptr_t)rule); + } - binfo->attr->aspath = new; - } + binfo->attr->aspath = new; + } - return RMAP_OKAY; + return RMAP_OKAY; } -static void * -route_set_aspath_prepend_compile (const char *arg) +static void *route_set_aspath_prepend_compile(const char *arg) { - unsigned int num; + unsigned int num; - if (sscanf(arg, "last-as %u", &num) == 1 && num > 0 && num <= 10) - return (void*)(uintptr_t)num; + if (sscanf(arg, "last-as %u", &num) == 1 && num > 0 && num <= 10) + return (void *)(uintptr_t)num; - return route_aspath_compile(arg); + return route_aspath_compile(arg); } -static void -route_set_aspath_prepend_free (void *rule) +static void route_set_aspath_prepend_free(void *rule) { - if ((uintptr_t)rule > 10) - route_aspath_free(rule); + if ((uintptr_t)rule > 10) + route_aspath_free(rule); } /* Set as-path prepend rule structure. */ -struct route_map_rule_cmd route_set_aspath_prepend_cmd = -{ - "as-path prepend", - route_set_aspath_prepend, - route_set_aspath_prepend_compile, - route_set_aspath_prepend_free, +struct route_map_rule_cmd route_set_aspath_prepend_cmd = { + "as-path prepend", route_set_aspath_prepend, + route_set_aspath_prepend_compile, route_set_aspath_prepend_free, }; /* `set as-path exclude ASn' */ /* For ASN exclude mechanism. - * Iterate over ASns requested and filter them from the given AS_PATH one by one. + * Iterate over ASns requested and filter them from the given AS_PATH one by + * one. * Make a deep copy of existing AS_PATH, but for the first ASn only. */ -static route_map_result_t -route_set_aspath_exclude (void *rule, struct prefix *dummy, route_map_object_t type, void *object) -{ - struct aspath * new_path, * exclude_path; - struct bgp_info *binfo; - - if (type == RMAP_BGP) - { - exclude_path = rule; - binfo = object; - if (binfo->attr->aspath->refcnt) - new_path = aspath_dup (binfo->attr->aspath); - else - new_path = binfo->attr->aspath; - binfo->attr->aspath = aspath_filter_exclude (new_path, exclude_path); - } - return RMAP_OKAY; +static route_map_result_t route_set_aspath_exclude(void *rule, + struct prefix *dummy, + route_map_object_t type, + void *object) +{ + struct aspath *new_path, *exclude_path; + struct bgp_info *binfo; + + if (type == RMAP_BGP) { + exclude_path = rule; + binfo = object; + if (binfo->attr->aspath->refcnt) + new_path = aspath_dup(binfo->attr->aspath); + else + new_path = binfo->attr->aspath; + binfo->attr->aspath = + aspath_filter_exclude(new_path, exclude_path); + } + return RMAP_OKAY; } /* Set ASn exlude rule structure. */ -struct route_map_rule_cmd route_set_aspath_exclude_cmd = -{ - "as-path exclude", - route_set_aspath_exclude, - route_aspath_compile, - route_aspath_free, +struct route_map_rule_cmd route_set_aspath_exclude_cmd = { + "as-path exclude", route_set_aspath_exclude, route_aspath_compile, + route_aspath_free, }; /* `set community COMMUNITY' */ -struct rmap_com_set -{ - struct community *com; - int additive; - int none; +struct rmap_com_set { + struct community *com; + int additive; + int none; }; /* For community set mechanism. */ -static route_map_result_t -route_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; - /* See the longer comment down below. */ - if (old && old->refcnt == 0) - community_free(old); - return RMAP_OKAY; - } +static route_map_result_t route_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; + /* See the longer comment down below. */ + if (old && old->refcnt == 0) + community_free(old); + return RMAP_OKAY; + } - /* "additive" case. */ - if (rcs->additive && old) - { - merge = community_merge (community_dup (old), rcs->com); - - /* HACK: if the old community is not intern'd, - * we should free it here, or all reference to it may be lost. - * Really need to cleanup attribute caching sometime. - */ - if (old->refcnt == 0) - community_free (old); - new = community_uniq_sort (merge); - community_free (merge); + /* "additive" case. */ + if (rcs->additive && old) { + merge = community_merge(community_dup(old), rcs->com); + + /* HACK: if the old community is not intern'd, + * we should free it here, or all reference to it may be + * lost. + * Really need to cleanup attribute caching sometime. + */ + if (old->refcnt == 0) + community_free(old); + new = community_uniq_sort(merge); + community_free(merge); + } else + new = community_dup(rcs->com); + + /* will be interned by caller if required */ + attr->community = new; + + attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES); } - else - new = community_dup (rcs->com); - /* will be interned by caller if required */ - attr->community = new; - - attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES); - } - - return RMAP_OKAY; + return RMAP_OKAY; } /* Compile function for set community. */ -static void * -route_set_community_compile (const 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'; - } +static void *route_set_community_compile(const 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); + com = community_str2com(arg); - if (additive) - *(sp - 1) = ' '; + if (additive) + *(sp - 1) = ' '; - if (! com) - return NULL; - } + if (!com) + return NULL; + } - rcs = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct rmap_com_set)); - rcs->com = com; - rcs->additive = additive; - rcs->none = none; + rcs = XCALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(struct rmap_com_set)); + rcs->com = com; + rcs->additive = additive; + rcs->none = none; - return rcs; + return rcs; } /* Free function for set community. */ -static void -route_set_community_free (void *rule) +static void route_set_community_free(void *rule) { - struct rmap_com_set *rcs = rule; + struct rmap_com_set *rcs = rule; - if (rcs->com) - community_free (rcs->com); - XFREE (MTYPE_ROUTE_MAP_COMPILED, rcs); + 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, +struct route_map_rule_cmd route_set_community_cmd = { + "community", route_set_community, route_set_community_compile, + route_set_community_free, }; /* `set community COMMUNITY' */ -struct rmap_lcom_set -{ - struct lcommunity *lcom; - int additive; - int none; +struct rmap_lcom_set { + struct lcommunity *lcom; + int additive; + int none; }; /* For lcommunity set mechanism. */ -static route_map_result_t -route_set_lcommunity (void *rule, struct prefix *prefix, - route_map_object_t type, void *object) -{ - struct rmap_lcom_set *rcs; - struct bgp_info *binfo; - struct attr *attr; - struct lcommunity *new = NULL; - struct lcommunity *old; - struct lcommunity *merge; - - if (type == RMAP_BGP) - { - rcs = rule; - binfo = object; - attr = binfo->attr; - old = (attr->extra) ? attr->extra->lcommunity : NULL; - - /* "none" case. */ - if (rcs->none) - { - attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_LARGE_COMMUNITIES)); - if (attr->extra) - attr->extra->lcommunity = NULL; - - /* See the longer comment down below. */ - if (old && old->refcnt == 0) - lcommunity_free(&old); - return RMAP_OKAY; - } - - if (rcs->additive && old) - { - merge = lcommunity_merge (lcommunity_dup (old), rcs->lcom); - - /* HACK: if the old large-community is not intern'd, - * we should free it here, or all reference to it may be lost. - * Really need to cleanup attribute caching sometime. - */ - if (old->refcnt == 0) - lcommunity_free (&old); - new = lcommunity_uniq_sort (merge); - lcommunity_free (&merge); - } - else - new = lcommunity_dup (rcs->lcom); - - /* will be intern()'d or attr_flush()'d by bgp_update_main() */ - (bgp_attr_extra_get (attr))->lcommunity = new; - - attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LARGE_COMMUNITIES); - } - - return RMAP_OKAY; -} +static route_map_result_t route_set_lcommunity(void *rule, + struct prefix *prefix, + route_map_object_t type, + void *object) +{ + struct rmap_lcom_set *rcs; + struct bgp_info *binfo; + struct attr *attr; + struct lcommunity *new = NULL; + struct lcommunity *old; + struct lcommunity *merge; + + if (type == RMAP_BGP) { + rcs = rule; + binfo = object; + attr = binfo->attr; + old = (attr->extra) ? attr->extra->lcommunity : NULL; + + /* "none" case. */ + if (rcs->none) { + attr->flag &= + ~(ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES)); + if (attr->extra) + attr->extra->lcommunity = NULL; + + /* See the longer comment down below. */ + if (old && old->refcnt == 0) + lcommunity_free(&old); + return RMAP_OKAY; + } -/* Compile function for set community. */ -static void * -route_set_lcommunity_compile (const char *arg) -{ - struct rmap_lcom_set *rcs; - struct lcommunity *lcom = NULL; - char *sp; - int additive = 0; - int none = 0; + if (rcs->additive && old) { + merge = lcommunity_merge(lcommunity_dup(old), + rcs->lcom); + + /* HACK: if the old large-community is not intern'd, + * we should free it here, or all reference to it may be + * lost. + * Really need to cleanup attribute caching sometime. + */ + if (old->refcnt == 0) + lcommunity_free(&old); + new = lcommunity_uniq_sort(merge); + lcommunity_free(&merge); + } else + new = lcommunity_dup(rcs->lcom); + + /* will be intern()'d or attr_flush()'d by bgp_update_main() */ + (bgp_attr_extra_get(attr))->lcommunity = new; + + attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES); + } - if (strcmp (arg, "none") == 0) - none = 1; - else - { - sp = strstr (arg, "additive"); + return RMAP_OKAY; +} - if (sp && sp > arg) - { - /* "additive" keyworkd is included. */ - additive = 1; - *(sp - 1) = '\0'; - } +/* Compile function for set community. */ +static void *route_set_lcommunity_compile(const char *arg) +{ + struct rmap_lcom_set *rcs; + struct lcommunity *lcom = 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'; + } - lcom = lcommunity_str2com (arg); + lcom = lcommunity_str2com(arg); - if (additive) - *(sp - 1) = ' '; + if (additive) + *(sp - 1) = ' '; - if (! lcom) - return NULL; - } + if (!lcom) + return NULL; + } - rcs = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct rmap_com_set)); - rcs->lcom = lcom; - rcs->additive = additive; - rcs->none = none; + rcs = XCALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(struct rmap_com_set)); + rcs->lcom = lcom; + rcs->additive = additive; + rcs->none = none; - return rcs; + return rcs; } /* Free function for set lcommunity. */ -static void -route_set_lcommunity_free (void *rule) +static void route_set_lcommunity_free(void *rule) { - struct rmap_lcom_set *rcs = rule; + struct rmap_lcom_set *rcs = rule; - if (rcs->lcom) { - lcommunity_free (&rcs->lcom); - } - XFREE (MTYPE_ROUTE_MAP_COMPILED, rcs); + if (rcs->lcom) { + lcommunity_free(&rcs->lcom); + } + XFREE(MTYPE_ROUTE_MAP_COMPILED, rcs); } /* Set community rule structure. */ -struct route_map_rule_cmd route_set_lcommunity_cmd = -{ - "large-community", - route_set_lcommunity, - route_set_lcommunity_compile, - route_set_lcommunity_free, +struct route_map_rule_cmd route_set_lcommunity_cmd = { + "large-community", route_set_lcommunity, route_set_lcommunity_compile, + route_set_lcommunity_free, }; /* `set large-comm-list (<1-99>|<100-500>|WORD) delete' */ /* For large community set mechanism. */ -static route_map_result_t -route_set_lcommunity_delete (void *rule, struct prefix *prefix, - route_map_object_t type, void *object) -{ - struct community_list *list; - struct lcommunity *merge; - struct lcommunity *new; - struct lcommunity *old; - struct bgp_info *binfo; - - if (type == RMAP_BGP) - { - if (! rule) - return RMAP_OKAY; - - binfo = object; - list = community_list_lookup (bgp_clist, rule, - LARGE_COMMUNITY_LIST_MASTER); - old = ((binfo->attr->extra) ? binfo->attr->extra->lcommunity : NULL); - - if (list && old) - { - merge = lcommunity_list_match_delete (lcommunity_dup (old), list); - new = lcommunity_uniq_sort (merge); - lcommunity_free (&merge); - - /* HACK: if the old community is not intern'd, - * we should free it here, or all reference to it may be lost. - * Really need to cleanup attribute caching sometime. - */ - if (old->refcnt == 0) - lcommunity_free (&old); - - if (new->size == 0) - { - binfo->attr->extra->lcommunity = NULL; - binfo->attr->flag &= ~ATTR_FLAG_BIT (BGP_ATTR_LARGE_COMMUNITIES); - lcommunity_free (&new); - } - else - { - binfo->attr->extra->lcommunity = new; - binfo->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LARGE_COMMUNITIES); - } - } - } - - return RMAP_OKAY; +static route_map_result_t route_set_lcommunity_delete(void *rule, + struct prefix *prefix, + route_map_object_t type, + void *object) +{ + struct community_list *list; + struct lcommunity *merge; + struct lcommunity *new; + struct lcommunity *old; + struct bgp_info *binfo; + + if (type == RMAP_BGP) { + if (!rule) + return RMAP_OKAY; + + binfo = object; + list = community_list_lookup(bgp_clist, rule, + LARGE_COMMUNITY_LIST_MASTER); + old = ((binfo->attr->extra) ? binfo->attr->extra->lcommunity + : NULL); + + if (list && old) { + merge = lcommunity_list_match_delete( + lcommunity_dup(old), list); + new = lcommunity_uniq_sort(merge); + lcommunity_free(&merge); + + /* HACK: if the old community is not intern'd, + * we should free it here, or all reference to it may be + * lost. + * Really need to cleanup attribute caching sometime. + */ + if (old->refcnt == 0) + lcommunity_free(&old); + + if (new->size == 0) { + binfo->attr->extra->lcommunity = NULL; + binfo->attr->flag &= ~ATTR_FLAG_BIT( + BGP_ATTR_LARGE_COMMUNITIES); + lcommunity_free(&new); + } else { + binfo->attr->extra->lcommunity = new; + binfo->attr->flag |= ATTR_FLAG_BIT( + BGP_ATTR_LARGE_COMMUNITIES); + } + } + } + + return RMAP_OKAY; } /* Compile function for set lcommunity. */ -static void * -route_set_lcommunity_delete_compile (const char *arg) +static void *route_set_lcommunity_delete_compile(const char *arg) { - char *p; - char *str; - int len; + 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; + 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; + return str; } /* Free function for set lcommunity. */ -static void -route_set_lcommunity_delete_free (void *rule) +static void route_set_lcommunity_delete_free(void *rule) { - XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); + XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); } /* Set lcommunity rule structure. */ -struct route_map_rule_cmd route_set_lcommunity_delete_cmd = -{ - "large-comm-list", - route_set_lcommunity_delete, - route_set_lcommunity_delete_compile, - route_set_lcommunity_delete_free, +struct route_map_rule_cmd route_set_lcommunity_delete_cmd = { + "large-comm-list", route_set_lcommunity_delete, + route_set_lcommunity_delete_compile, route_set_lcommunity_delete_free, }; /* `set comm-list (<1-99>|<100-500>|WORD) delete' */ /* For community set mechanism. */ -static route_map_result_t -route_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 (community_dup (old), list); - new = community_uniq_sort (merge); - community_free (merge); - - /* HACK: if the old community is not intern'd, - * we should free it here, or all reference to it may be lost. - * Really need to cleanup attribute caching sometime. - */ - if (old->refcnt == 0) - community_free (old); - - 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); - } +static route_map_result_t route_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(community_dup(old), + list); + new = community_uniq_sort(merge); + community_free(merge); + + /* HACK: if the old community is not intern'd, + * we should free it here, or all reference to it may be + * lost. + * Really need to cleanup attribute caching sometime. + */ + if (old->refcnt == 0) + community_free(old); + + 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; + return RMAP_OKAY; } /* Compile function for set community. */ -static void * -route_set_community_delete_compile (const char *arg) +static void *route_set_community_delete_compile(const char *arg) { - char *p; - char *str; - int len; + 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; + 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; + return str; } /* Free function for set community. */ -static void -route_set_community_delete_free (void *rule) +static void route_set_community_delete_free(void *rule) { - XFREE (MTYPE_ROUTE_MAP_COMPILED, 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, +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. Used by _rt and _soo. */ -static route_map_result_t -route_set_ecommunity (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_attr_extra_get (bgp_info->attr))->ecommunity; - - if (old_ecom) - { - new_ecom = ecommunity_merge (ecommunity_dup (old_ecom), ecom); - - /* old_ecom->refcnt = 1 => owned elsewhere, e.g. bgp_update_receive() - * ->refcnt = 0 => set by a previous route-map statement */ - if (!old_ecom->refcnt) - ecommunity_free (&old_ecom); +static route_map_result_t route_set_ecommunity(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_attr_extra_get(bgp_info->attr))->ecommunity; + + if (old_ecom) { + new_ecom = ecommunity_merge(ecommunity_dup(old_ecom), + ecom); + + /* old_ecom->refcnt = 1 => owned elsewhere, e.g. + * bgp_update_receive() + * ->refcnt = 0 => set by a previous route-map + * statement */ + if (!old_ecom->refcnt) + ecommunity_free(&old_ecom); + } else + new_ecom = ecommunity_dup(ecom); + + /* will be intern()'d or attr_flush()'d by bgp_update_main() */ + bgp_info->attr->extra->ecommunity = new_ecom; + + bgp_info->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES); } - else - new_ecom = ecommunity_dup (ecom); - - /* will be intern()'d or attr_flush()'d by bgp_update_main() */ - bgp_info->attr->extra->ecommunity = new_ecom; - - bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_EXT_COMMUNITIES); - } - return RMAP_OKAY; + return RMAP_OKAY; } /* Compile function for set community. */ -static void * -route_set_ecommunity_rt_compile (const char *arg) +static void *route_set_ecommunity_rt_compile(const char *arg) { - struct ecommunity *ecom; + struct ecommunity *ecom; - ecom = ecommunity_str2com (arg, ECOMMUNITY_ROUTE_TARGET, 0); - if (! ecom) - return NULL; - return ecommunity_intern (ecom); + ecom = ecommunity_str2com(arg, ECOMMUNITY_ROUTE_TARGET, 0); + if (!ecom) + return NULL; + return ecommunity_intern(ecom); } /* Free function for set community. Used by _rt and _soo */ -static void -route_set_ecommunity_free (void *rule) +static void route_set_ecommunity_free(void *rule) { - struct ecommunity *ecom = rule; - ecommunity_unintern (&ecom); + struct ecommunity *ecom = rule; + ecommunity_unintern(&ecom); } /* Set community rule structure. */ -struct route_map_rule_cmd route_set_ecommunity_rt_cmd = -{ - "extcommunity rt", - route_set_ecommunity, - route_set_ecommunity_rt_compile, - route_set_ecommunity_free, +struct route_map_rule_cmd route_set_ecommunity_rt_cmd = { + "extcommunity rt", route_set_ecommunity, + route_set_ecommunity_rt_compile, route_set_ecommunity_free, }; /* `set extcommunity soo COMMUNITY' */ /* Compile function for set community. */ -static void * -route_set_ecommunity_soo_compile (const char *arg) +static void *route_set_ecommunity_soo_compile(const char *arg) { - struct ecommunity *ecom; + struct ecommunity *ecom; - ecom = ecommunity_str2com (arg, ECOMMUNITY_SITE_ORIGIN, 0); - if (! ecom) - return NULL; + ecom = ecommunity_str2com(arg, ECOMMUNITY_SITE_ORIGIN, 0); + if (!ecom) + return NULL; - return ecommunity_intern (ecom); + return ecommunity_intern(ecom); } /* Set community rule structure. */ -struct route_map_rule_cmd route_set_ecommunity_soo_cmd = -{ - "extcommunity soo", - route_set_ecommunity, - route_set_ecommunity_soo_compile, - route_set_ecommunity_free, +struct route_map_rule_cmd route_set_ecommunity_soo_cmd = { + "extcommunity soo", route_set_ecommunity, + route_set_ecommunity_soo_compile, route_set_ecommunity_free, }; /* `set origin ORIGIN' */ /* For origin set. */ -static route_map_result_t -route_set_origin (void *rule, struct prefix *prefix, route_map_object_t type, void *object) +static route_map_result_t route_set_origin(void *rule, struct prefix *prefix, + route_map_object_t type, + void *object) { - u_char *origin; - struct bgp_info *bgp_info; + u_char *origin; + struct bgp_info *bgp_info; - if (type == RMAP_BGP) - { - origin = rule; - bgp_info = object; + if (type == RMAP_BGP) { + origin = rule; + bgp_info = object; - bgp_info->attr->origin = *origin; - } + bgp_info->attr->origin = *origin; + } - return RMAP_OKAY; + return RMAP_OKAY; } /* Compile function for origin set. */ -static void * -route_set_origin_compile (const char *arg) +static void *route_set_origin_compile(const char *arg) { - u_char *origin; + u_char *origin; - origin = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_char)); + 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; + if (strcmp(arg, "igp") == 0) + *origin = 0; + else if (strcmp(arg, "egp") == 0) + *origin = 1; + else + *origin = 2; - return origin; + return origin; } /* Compile function for origin set. */ -static void -route_set_origin_free (void *rule) +static void route_set_origin_free(void *rule) { - XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); + XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); } /* Set origin rule structure. */ -struct route_map_rule_cmd route_set_origin_cmd = -{ - "origin", - route_set_origin, - route_set_origin_compile, - route_set_origin_free, +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. */ -static route_map_result_t -route_set_atomic_aggregate (void *rule, struct prefix *prefix, - route_map_object_t type, void *object) +static route_map_result_t route_set_atomic_aggregate(void *rule, + struct prefix *prefix, + route_map_object_t type, + void *object) { - struct bgp_info *bgp_info; + struct bgp_info *bgp_info; - if (type == RMAP_BGP) - { - bgp_info = object; - bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE); - } + if (type == RMAP_BGP) { + bgp_info = object; + bgp_info->attr->flag |= + ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE); + } - return RMAP_OKAY; + return RMAP_OKAY; } /* Compile function for atomic aggregate. */ -static void * -route_set_atomic_aggregate_compile (const char *arg) +static void *route_set_atomic_aggregate_compile(const char *arg) { - return (void *)1; + return (void *)1; } /* Compile function for atomic aggregate. */ -static void -route_set_atomic_aggregate_free (void *rule) +static void route_set_atomic_aggregate_free(void *rule) { - return; + 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, +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; +struct aggregator { + as_t as; + struct in_addr address; }; -static route_map_result_t -route_set_aggregator_as (void *rule, struct prefix *prefix, - route_map_object_t type, void *object) +static route_map_result_t route_set_aggregator_as(void *rule, + struct prefix *prefix, + route_map_object_t type, + void *object) { - struct bgp_info *bgp_info; - struct aggregator *aggregator; - struct attr_extra *ae; + struct bgp_info *bgp_info; + struct aggregator *aggregator; + struct attr_extra *ae; - if (type == RMAP_BGP) - { - bgp_info = object; - aggregator = rule; - ae = bgp_attr_extra_get (bgp_info->attr); + if (type == RMAP_BGP) { + bgp_info = object; + aggregator = rule; + ae = bgp_attr_extra_get(bgp_info->attr); - ae->aggregator_as = aggregator->as; - ae->aggregator_addr = aggregator->address; - bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR); - } + ae->aggregator_as = aggregator->as; + ae->aggregator_addr = aggregator->address; + bgp_info->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR); + } - return RMAP_OKAY; + return RMAP_OKAY; } -static void * -route_set_aggregator_as_compile (const char *arg) +static void *route_set_aggregator_as_compile(const char *arg) { - struct aggregator *aggregator; - char as[10]; - char address[20]; + struct aggregator *aggregator; + char as[10]; + char address[20]; - aggregator = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct aggregator)); - sscanf (arg, "%s %s", as, address); + aggregator = + XCALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(struct aggregator)); + sscanf(arg, "%s %s", as, address); - aggregator->as = strtoul (as, NULL, 10); - inet_aton (address, &aggregator->address); + aggregator->as = strtoul(as, NULL, 10); + inet_aton(address, &aggregator->address); - return aggregator; + return aggregator; } -static void -route_set_aggregator_as_free (void *rule) +static void route_set_aggregator_as_free(void *rule) { - XFREE (MTYPE_ROUTE_MAP_COMPILED, 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, +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, }; /* Set tag to object. object must be pointer to struct bgp_info */ -static route_map_result_t -route_set_tag (void *rule, struct prefix *prefix, - route_map_object_t type, void *object) +static route_map_result_t route_set_tag(void *rule, struct prefix *prefix, + route_map_object_t type, void *object) { - route_tag_t *tag; - struct bgp_info *bgp_info; - struct attr_extra *ae; - - if (type == RMAP_BGP) - { - tag = rule; - bgp_info = object; - ae = bgp_attr_extra_get (bgp_info->attr); + route_tag_t *tag; + struct bgp_info *bgp_info; + struct attr_extra *ae; - /* Set tag value */ - ae->tag=*tag; + if (type == RMAP_BGP) { + tag = rule; + bgp_info = object; + ae = bgp_attr_extra_get(bgp_info->attr); - } + /* Set tag value */ + ae->tag = *tag; + } - return RMAP_OKAY; + return RMAP_OKAY; } /* Route map commands for tag set. */ -static struct route_map_rule_cmd route_set_tag_cmd = -{ - "tag", - route_set_tag, - route_map_rule_tag_compile, - route_map_rule_tag_free, +static struct route_map_rule_cmd route_set_tag_cmd = { + "tag", route_set_tag, route_map_rule_tag_compile, + route_map_rule_tag_free, }; /* `match ipv6 address IP_ACCESS_LIST' */ -static route_map_result_t -route_match_ipv6_address (void *rule, struct prefix *prefix, - route_map_object_t type, void *object) +static route_map_result_t route_match_ipv6_address(void *rule, + struct prefix *prefix, + route_map_object_t type, + void *object) { - struct access_list *alist; + struct access_list *alist; - if (type == RMAP_BGP) - { - alist = access_list_lookup (AFI_IP6, (char *) rule); - if (alist == NULL) - return RMAP_NOMATCH; + if (type == RMAP_BGP) { + alist = access_list_lookup(AFI_IP6, (char *)rule); + if (alist == NULL) + return RMAP_NOMATCH; - return (access_list_apply (alist, prefix) == FILTER_DENY ? - RMAP_NOMATCH : RMAP_MATCH); - } - return RMAP_NOMATCH; + return (access_list_apply(alist, prefix) == FILTER_DENY + ? RMAP_NOMATCH + : RMAP_MATCH); + } + return RMAP_NOMATCH; } -static void * -route_match_ipv6_address_compile (const char *arg) +static void *route_match_ipv6_address_compile(const char *arg) { - return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg); + return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg); } -static void -route_match_ipv6_address_free (void *rule) +static void route_match_ipv6_address_free(void *rule) { - XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); + XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); } /* Route map commands for ip address matching. */ -struct route_map_rule_cmd route_match_ipv6_address_cmd = -{ - "ipv6 address", - route_match_ipv6_address, - route_match_ipv6_address_compile, - route_match_ipv6_address_free -}; +struct route_map_rule_cmd route_match_ipv6_address_cmd = { + "ipv6 address", route_match_ipv6_address, + route_match_ipv6_address_compile, route_match_ipv6_address_free}; /* `match ipv6 next-hop IP_ADDRESS' */ -static route_map_result_t -route_match_ipv6_next_hop (void *rule, struct prefix *prefix, - route_map_object_t type, void *object) +static route_map_result_t route_match_ipv6_next_hop(void *rule, + struct prefix *prefix, + route_map_object_t type, + void *object) { - struct in6_addr *addr = rule; - struct bgp_info *bgp_info; + struct in6_addr *addr = rule; + struct bgp_info *bgp_info; - if (type == RMAP_BGP) - { - bgp_info = object; + if (type == RMAP_BGP) { + bgp_info = object; - if (!bgp_info->attr->extra) - return RMAP_NOMATCH; + if (!bgp_info->attr->extra) + return RMAP_NOMATCH; - if (IPV6_ADDR_SAME (&bgp_info->attr->extra->mp_nexthop_global, addr)) - return RMAP_MATCH; + if (IPV6_ADDR_SAME(&bgp_info->attr->extra->mp_nexthop_global, + addr)) + return RMAP_MATCH; - if (bgp_info->attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL && - IPV6_ADDR_SAME (&bgp_info->attr->extra->mp_nexthop_local, rule)) - return RMAP_MATCH; + if (bgp_info->attr->extra->mp_nexthop_len + == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL + && IPV6_ADDR_SAME(&bgp_info->attr->extra->mp_nexthop_local, + rule)) + return RMAP_MATCH; - return RMAP_NOMATCH; - } + return RMAP_NOMATCH; + } - return RMAP_NOMATCH; + return RMAP_NOMATCH; } -static void * -route_match_ipv6_next_hop_compile (const char *arg) +static void *route_match_ipv6_next_hop_compile(const char *arg) { - struct in6_addr *address; - int ret; + struct in6_addr *address; + int ret; - address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in6_addr)); + address = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(struct in6_addr)); - ret = inet_pton (AF_INET6, arg, address); - if (!ret) - { - XFREE (MTYPE_ROUTE_MAP_COMPILED, address); - return NULL; - } + ret = inet_pton(AF_INET6, arg, address); + if (!ret) { + XFREE(MTYPE_ROUTE_MAP_COMPILED, address); + return NULL; + } - return address; + return address; } -static void -route_match_ipv6_next_hop_free (void *rule) +static void route_match_ipv6_next_hop_free(void *rule) { - XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); + XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); } -struct route_map_rule_cmd route_match_ipv6_next_hop_cmd = -{ - "ipv6 next-hop", - route_match_ipv6_next_hop, - route_match_ipv6_next_hop_compile, - route_match_ipv6_next_hop_free -}; +struct route_map_rule_cmd route_match_ipv6_next_hop_cmd = { + "ipv6 next-hop", route_match_ipv6_next_hop, + route_match_ipv6_next_hop_compile, route_match_ipv6_next_hop_free}; /* `match ipv6 address prefix-list PREFIX_LIST' */ static route_map_result_t -route_match_ipv6_address_prefix_list (void *rule, struct prefix *prefix, - route_map_object_t type, void *object) +route_match_ipv6_address_prefix_list(void *rule, struct prefix *prefix, + route_map_object_t type, void *object) { - struct prefix_list *plist; + struct prefix_list *plist; - if (type == RMAP_BGP) - { - plist = prefix_list_lookup (AFI_IP6, (char *) rule); - if (plist == NULL) - return RMAP_NOMATCH; + if (type == RMAP_BGP) { + plist = prefix_list_lookup(AFI_IP6, (char *)rule); + if (plist == NULL) + return RMAP_NOMATCH; - return (prefix_list_apply (plist, prefix) == PREFIX_DENY ? - RMAP_NOMATCH : RMAP_MATCH); - } - return RMAP_NOMATCH; + return (prefix_list_apply(plist, prefix) == PREFIX_DENY + ? RMAP_NOMATCH + : RMAP_MATCH); + } + return RMAP_NOMATCH; } -static void * -route_match_ipv6_address_prefix_list_compile (const char *arg) +static void *route_match_ipv6_address_prefix_list_compile(const char *arg) { - return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg); + return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg); } -static void -route_match_ipv6_address_prefix_list_free (void *rule) +static void route_match_ipv6_address_prefix_list_free(void *rule) { - XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); + XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); } -struct route_map_rule_cmd route_match_ipv6_address_prefix_list_cmd = -{ - "ipv6 address prefix-list", - route_match_ipv6_address_prefix_list, - route_match_ipv6_address_prefix_list_compile, - route_match_ipv6_address_prefix_list_free -}; +struct route_map_rule_cmd route_match_ipv6_address_prefix_list_cmd = { + "ipv6 address prefix-list", route_match_ipv6_address_prefix_list, + route_match_ipv6_address_prefix_list_compile, + route_match_ipv6_address_prefix_list_free}; /* `set ipv6 nexthop global IP_ADDRESS' */ /* Set nexthop to object. ojbect must be pointer to struct attr. */ -static route_map_result_t -route_set_ipv6_nexthop_global (void *rule, struct prefix *prefix, - route_map_object_t type, void *object) -{ - 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_attr_extra_get (bgp_info->attr))->mp_nexthop_global = *address; - - /* Set nexthop length. */ - if (bgp_info->attr->extra->mp_nexthop_len == 0) - bgp_info->attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL; - - SET_FLAG(bgp_info->attr->rmap_change_flags, - BATTR_RMAP_IPV6_GLOBAL_NHOP_CHANGED); - } +static route_map_result_t route_set_ipv6_nexthop_global(void *rule, + struct prefix *prefix, + route_map_object_t type, + void *object) +{ + 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_attr_extra_get(bgp_info->attr))->mp_nexthop_global = + *address; + + /* Set nexthop length. */ + if (bgp_info->attr->extra->mp_nexthop_len == 0) + bgp_info->attr->extra->mp_nexthop_len = + BGP_ATTR_NHLEN_IPV6_GLOBAL; + + SET_FLAG(bgp_info->attr->rmap_change_flags, + BATTR_RMAP_IPV6_GLOBAL_NHOP_CHANGED); + } - return RMAP_OKAY; + return RMAP_OKAY; } /* Route map `ip next-hop' compile function. Given string is converted to struct in_addr structure. */ -static void * -route_set_ipv6_nexthop_global_compile (const char *arg) +static void *route_set_ipv6_nexthop_global_compile(const char *arg) { - int ret; - struct in6_addr *address; + int ret; + struct in6_addr *address; - address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in6_addr)); + address = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(struct in6_addr)); - ret = inet_pton (AF_INET6, arg, address); + ret = inet_pton(AF_INET6, arg, address); - if (ret == 0) - { - XFREE (MTYPE_ROUTE_MAP_COMPILED, address); - return NULL; - } + if (ret == 0) { + XFREE(MTYPE_ROUTE_MAP_COMPILED, address); + return NULL; + } - return address; + return address; } /* Free route map's compiled `ip next-hop' value. */ -static void -route_set_ipv6_nexthop_global_free (void *rule) +static void route_set_ipv6_nexthop_global_free(void *rule) { - XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); + XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); } /* Route map commands for ip nexthop set. */ -struct route_map_rule_cmd route_set_ipv6_nexthop_global_cmd = -{ - "ipv6 next-hop global", - route_set_ipv6_nexthop_global, - route_set_ipv6_nexthop_global_compile, - route_set_ipv6_nexthop_global_free -}; +struct route_map_rule_cmd route_set_ipv6_nexthop_global_cmd = { + "ipv6 next-hop global", route_set_ipv6_nexthop_global, + route_set_ipv6_nexthop_global_compile, + route_set_ipv6_nexthop_global_free}; /* Set next-hop preference value. */ static route_map_result_t -route_set_ipv6_nexthop_prefer_global (void *rule, struct prefix *prefix, - route_map_object_t type, void *object) -{ - struct bgp_info *bgp_info; - struct peer *peer; - - if (type == RMAP_BGP) - { - /* Fetch routemap's rule information. */ - bgp_info = object; - peer = bgp_info->peer; - - if ((CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN) || - CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT)) - && peer->su_remote - && sockunion_family (peer->su_remote) == AF_INET6) - { - /* Set next hop preference to global */ - bgp_info->attr->extra->mp_nexthop_prefer_global = TRUE; - SET_FLAG(bgp_info->attr->rmap_change_flags, - BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED); +route_set_ipv6_nexthop_prefer_global(void *rule, struct prefix *prefix, + route_map_object_t type, void *object) +{ + struct bgp_info *bgp_info; + struct peer *peer; + + if (type == RMAP_BGP) { + /* Fetch routemap's rule information. */ + bgp_info = object; + peer = bgp_info->peer; + + if ((CHECK_FLAG(peer->rmap_type, PEER_RMAP_TYPE_IN) + || CHECK_FLAG(peer->rmap_type, PEER_RMAP_TYPE_IMPORT)) + && peer->su_remote + && sockunion_family(peer->su_remote) == AF_INET6) { + /* Set next hop preference to global */ + bgp_info->attr->extra->mp_nexthop_prefer_global = TRUE; + SET_FLAG(bgp_info->attr->rmap_change_flags, + BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED); + } else { + bgp_info->attr->extra->mp_nexthop_prefer_global = FALSE; + SET_FLAG(bgp_info->attr->rmap_change_flags, + BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED); + } } - else - { - bgp_info->attr->extra->mp_nexthop_prefer_global = FALSE; - SET_FLAG(bgp_info->attr->rmap_change_flags, - BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED); - } - } - return RMAP_OKAY; + return RMAP_OKAY; } -static void * -route_set_ipv6_nexthop_prefer_global_compile (const char *arg) +static void *route_set_ipv6_nexthop_prefer_global_compile(const char *arg) { - int *rins = NULL; + int *rins = NULL; - rins = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (int)); - *rins = 1; + rins = XCALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(int)); + *rins = 1; - return rins; + return rins; } /* Free route map's compiled `ip next-hop' value. */ -static void -route_set_ipv6_nexthop_prefer_global_free (void *rule) +static void route_set_ipv6_nexthop_prefer_global_free(void *rule) { - XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); + XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); } /* Route map commands for ip nexthop set preferred. */ -struct route_map_rule_cmd route_set_ipv6_nexthop_prefer_global_cmd = -{ - "ipv6 next-hop prefer-global", - route_set_ipv6_nexthop_prefer_global, - route_set_ipv6_nexthop_prefer_global_compile, - route_set_ipv6_nexthop_prefer_global_free -}; +struct route_map_rule_cmd route_set_ipv6_nexthop_prefer_global_cmd = { + "ipv6 next-hop prefer-global", route_set_ipv6_nexthop_prefer_global, + route_set_ipv6_nexthop_prefer_global_compile, + route_set_ipv6_nexthop_prefer_global_free}; /* `set ipv6 nexthop local IP_ADDRESS' */ /* Set nexthop to object. ojbect must be pointer to struct attr. */ -static route_map_result_t -route_set_ipv6_nexthop_local (void *rule, struct prefix *prefix, - route_map_object_t type, void *object) -{ - 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_attr_extra_get (bgp_info->attr))->mp_nexthop_local = *address; - - /* Set nexthop length. */ - if (bgp_info->attr->extra->mp_nexthop_len != BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL) - bgp_info->attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL; - - SET_FLAG(bgp_info->attr->rmap_change_flags, - BATTR_RMAP_IPV6_LL_NHOP_CHANGED); - } +static route_map_result_t route_set_ipv6_nexthop_local(void *rule, + struct prefix *prefix, + route_map_object_t type, + void *object) +{ + 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_attr_extra_get(bgp_info->attr))->mp_nexthop_local = + *address; + + /* Set nexthop length. */ + if (bgp_info->attr->extra->mp_nexthop_len + != BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL) + bgp_info->attr->extra->mp_nexthop_len = + BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL; + + SET_FLAG(bgp_info->attr->rmap_change_flags, + BATTR_RMAP_IPV6_LL_NHOP_CHANGED); + } - return RMAP_OKAY; + return RMAP_OKAY; } /* Route map `ip nexthop' compile function. Given string is converted to struct in_addr structure. */ -static void * -route_set_ipv6_nexthop_local_compile (const char *arg) +static void *route_set_ipv6_nexthop_local_compile(const char *arg) { - int ret; - struct in6_addr *address; + int ret; + struct in6_addr *address; - address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in6_addr)); + address = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(struct in6_addr)); - ret = inet_pton (AF_INET6, arg, address); + ret = inet_pton(AF_INET6, arg, address); - if (ret == 0) - { - XFREE (MTYPE_ROUTE_MAP_COMPILED, address); - return NULL; - } + if (ret == 0) { + XFREE(MTYPE_ROUTE_MAP_COMPILED, address); + return NULL; + } - return address; + return address; } /* Free route map's compiled `ip nexthop' value. */ -static void -route_set_ipv6_nexthop_local_free (void *rule) +static void route_set_ipv6_nexthop_local_free(void *rule) { - XFREE (MTYPE_ROUTE_MAP_COMPILED, 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 -}; +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}; /* `set ipv6 nexthop peer-address' */ /* Set nexthop to object. ojbect must be pointer to struct attr. */ -static route_map_result_t -route_set_ipv6_nexthop_peer (void *rule, struct prefix *prefix, - route_map_object_t type, void *object) -{ - struct in6_addr peer_address; - struct bgp_info *bgp_info; - struct peer *peer; - - if (type == RMAP_BGP) - { - /* Fetch routemap's rule information. */ - bgp_info = object; - peer = bgp_info->peer; - - if ((CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN) || - CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT)) - && peer->su_remote - && sockunion_family (peer->su_remote) == AF_INET6) - { - peer_address = peer->su_remote->sin6.sin6_addr; - /* Set next hop value and length in attribute. */ - if (IN6_IS_ADDR_LINKLOCAL(&peer_address)) - { - (bgp_attr_extra_get (bgp_info->attr))->mp_nexthop_local = peer_address; - if (bgp_info->attr->extra->mp_nexthop_len != 32) - bgp_info->attr->extra->mp_nexthop_len = 32; - } - else - { - (bgp_attr_extra_get (bgp_info->attr))->mp_nexthop_global = peer_address; - if (bgp_info->attr->extra->mp_nexthop_len == 0) - bgp_info->attr->extra->mp_nexthop_len = 16; - } - - } - else if (CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT)) - { - /* The next hop value will be set as part of packet rewrite. - * Set the flags here to indicate that rewrite needs to be done. - * Also, clear the value - we clear both global and link-local - * nexthops, whether we send one or both is determined elsewhere. - */ - SET_FLAG(bgp_info->attr->rmap_change_flags, - BATTR_RMAP_NEXTHOP_PEER_ADDRESS); - /* clear next hop value. */ - memset (&((bgp_attr_extra_get (bgp_info->attr))->mp_nexthop_global), - 0, sizeof (struct in6_addr)); - memset (&((bgp_attr_extra_get (bgp_info->attr))->mp_nexthop_local), - 0, sizeof (struct in6_addr)); +static route_map_result_t route_set_ipv6_nexthop_peer(void *rule, + struct prefix *prefix, + route_map_object_t type, + void *object) +{ + struct in6_addr peer_address; + struct bgp_info *bgp_info; + struct peer *peer; + + if (type == RMAP_BGP) { + /* Fetch routemap's rule information. */ + bgp_info = object; + peer = bgp_info->peer; + + if ((CHECK_FLAG(peer->rmap_type, PEER_RMAP_TYPE_IN) + || CHECK_FLAG(peer->rmap_type, PEER_RMAP_TYPE_IMPORT)) + && peer->su_remote + && sockunion_family(peer->su_remote) == AF_INET6) { + peer_address = peer->su_remote->sin6.sin6_addr; + /* Set next hop value and length in attribute. */ + if (IN6_IS_ADDR_LINKLOCAL(&peer_address)) { + (bgp_attr_extra_get(bgp_info->attr)) + ->mp_nexthop_local = peer_address; + if (bgp_info->attr->extra->mp_nexthop_len != 32) + bgp_info->attr->extra->mp_nexthop_len = + 32; + } else { + (bgp_attr_extra_get(bgp_info->attr)) + ->mp_nexthop_global = peer_address; + if (bgp_info->attr->extra->mp_nexthop_len == 0) + bgp_info->attr->extra->mp_nexthop_len = + 16; + } + + } else if (CHECK_FLAG(peer->rmap_type, PEER_RMAP_TYPE_OUT)) { + /* The next hop value will be set as part of packet + * rewrite. + * Set the flags here to indicate that rewrite needs to + * be done. + * Also, clear the value - we clear both global and + * link-local + * nexthops, whether we send one or both is determined + * elsewhere. + */ + SET_FLAG(bgp_info->attr->rmap_change_flags, + BATTR_RMAP_NEXTHOP_PEER_ADDRESS); + /* clear next hop value. */ + memset(&((bgp_attr_extra_get(bgp_info->attr)) + ->mp_nexthop_global), + 0, sizeof(struct in6_addr)); + memset(&((bgp_attr_extra_get(bgp_info->attr)) + ->mp_nexthop_local), + 0, sizeof(struct in6_addr)); + } } - } - return RMAP_OKAY; + return RMAP_OKAY; } /* Route map `ip next-hop' compile function. Given string is converted to struct in_addr structure. */ -static void * -route_set_ipv6_nexthop_peer_compile (const char *arg) +static void *route_set_ipv6_nexthop_peer_compile(const char *arg) { - int *rins = NULL; + int *rins = NULL; - rins = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (int)); - *rins = 1; + rins = XCALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(int)); + *rins = 1; - return rins; + return rins; } /* Free route map's compiled `ip next-hop' value. */ -static void -route_set_ipv6_nexthop_peer_free (void *rule) +static void route_set_ipv6_nexthop_peer_free(void *rule) { - XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); + XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); } /* Route map commands for ip nexthop set. */ -struct route_map_rule_cmd route_set_ipv6_nexthop_peer_cmd = -{ - "ipv6 next-hop peer-address", - route_set_ipv6_nexthop_peer, - route_set_ipv6_nexthop_peer_compile, - route_set_ipv6_nexthop_peer_free -}; +struct route_map_rule_cmd route_set_ipv6_nexthop_peer_cmd = { + "ipv6 next-hop peer-address", route_set_ipv6_nexthop_peer, + route_set_ipv6_nexthop_peer_compile, route_set_ipv6_nexthop_peer_free}; /* `set ip vpn nexthop A.B.C.D' */ -static route_map_result_t -route_set_vpnv4_nexthop (void *rule, struct prefix *prefix, - route_map_object_t type, void *object) +static route_map_result_t route_set_vpnv4_nexthop(void *rule, + struct prefix *prefix, + route_map_object_t type, + void *object) { - struct in_addr *address; - struct bgp_info *bgp_info; + struct in_addr *address; + struct bgp_info *bgp_info; - if (type == RMAP_BGP) - { - /* Fetch routemap's rule information. */ - address = rule; - bgp_info = object; + if (type == RMAP_BGP) { + /* Fetch routemap's rule information. */ + address = rule; + bgp_info = object; - /* Set next hop value. */ - (bgp_attr_extra_get (bgp_info->attr))->mp_nexthop_global_in = *address; - (bgp_attr_extra_get (bgp_info->attr))->mp_nexthop_len = 4; - } + /* Set next hop value. */ + (bgp_attr_extra_get(bgp_info->attr))->mp_nexthop_global_in = + *address; + (bgp_attr_extra_get(bgp_info->attr))->mp_nexthop_len = 4; + } - return RMAP_OKAY; + return RMAP_OKAY; } -static void * -route_set_vpnv4_nexthop_compile (const char *arg) +static void *route_set_vpnv4_nexthop_compile(const char *arg) { - int ret; - struct in_addr *address; + int ret; + struct in_addr *address; - address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in_addr)); + address = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(struct in_addr)); - ret = inet_aton (arg, address); + ret = inet_aton(arg, address); - if (ret == 0) - { - XFREE (MTYPE_ROUTE_MAP_COMPILED, address); - return NULL; - } + if (ret == 0) { + XFREE(MTYPE_ROUTE_MAP_COMPILED, address); + return NULL; + } - return address; + return address; } /* `set ipv6 vpn nexthop A.B.C.D' */ -static route_map_result_t -route_set_vpnv6_nexthop (void *rule, struct prefix *prefix, - route_map_object_t type, void *object) +static route_map_result_t route_set_vpnv6_nexthop(void *rule, + struct prefix *prefix, + route_map_object_t type, + void *object) { - struct in6_addr *address; - struct bgp_info *bgp_info; + struct in6_addr *address; + struct bgp_info *bgp_info; - if (type == RMAP_BGP) - { - /* Fetch routemap's rule information. */ - address = rule; - bgp_info = object; + if (type == RMAP_BGP) { + /* Fetch routemap's rule information. */ + address = rule; + bgp_info = object; - /* Set next hop value. */ - memcpy (&(bgp_attr_extra_get (bgp_info->attr))->mp_nexthop_global, address, sizeof(struct in6_addr)); - (bgp_attr_extra_get (bgp_info->attr))->mp_nexthop_len = BGP_ATTR_NHLEN_VPNV6_GLOBAL; - } + /* Set next hop value. */ + memcpy(&(bgp_attr_extra_get(bgp_info->attr))->mp_nexthop_global, + address, sizeof(struct in6_addr)); + (bgp_attr_extra_get(bgp_info->attr))->mp_nexthop_len = + BGP_ATTR_NHLEN_VPNV6_GLOBAL; + } - return RMAP_OKAY; + return RMAP_OKAY; } -static void * -route_set_vpnv6_nexthop_compile (const char *arg) +static void *route_set_vpnv6_nexthop_compile(const char *arg) { - int ret; - struct in6_addr *address; + int ret; + struct in6_addr *address; - address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in6_addr)); - ret = inet_pton (AF_INET6, arg, 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; - } + if (ret == 0) { + XFREE(MTYPE_ROUTE_MAP_COMPILED, address); + return NULL; + } - return address; + return address; } -static void -route_set_vpn_nexthop_free (void *rule) +static void route_set_vpn_nexthop_free(void *rule) { - XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); + XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); } /* Route map commands for ip nexthop set. */ -struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd = -{ - "ip vpn next-hop", - route_set_vpnv4_nexthop, - route_set_vpnv4_nexthop_compile, - route_set_vpn_nexthop_free -}; +struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd = { + "ip vpn next-hop", route_set_vpnv4_nexthop, + route_set_vpnv4_nexthop_compile, route_set_vpn_nexthop_free}; /* Route map commands for ip nexthop set. */ -struct route_map_rule_cmd route_set_vpnv6_nexthop_cmd = -{ - "ipv6 vpn next-hop", - route_set_vpnv6_nexthop, - route_set_vpnv6_nexthop_compile, - route_set_vpn_nexthop_free -}; +struct route_map_rule_cmd route_set_vpnv6_nexthop_cmd = { + "ipv6 vpn next-hop", route_set_vpnv6_nexthop, + route_set_vpnv6_nexthop_compile, route_set_vpn_nexthop_free}; /* `set originator-id' */ /* For origin set. */ -static route_map_result_t -route_set_originator_id (void *rule, struct prefix *prefix, route_map_object_t type, void *object) +static route_map_result_t route_set_originator_id(void *rule, + struct prefix *prefix, + route_map_object_t type, + void *object) { - struct in_addr *address; - struct bgp_info *bgp_info; + struct in_addr *address; + struct bgp_info *bgp_info; - if (type == RMAP_BGP) - { - address = rule; - bgp_info = object; + if (type == RMAP_BGP) { + address = rule; + bgp_info = object; - bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID); - (bgp_attr_extra_get (bgp_info->attr))->originator_id = *address; - } + bgp_info->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID); + (bgp_attr_extra_get(bgp_info->attr))->originator_id = *address; + } - return RMAP_OKAY; + return RMAP_OKAY; } /* Compile function for originator-id set. */ -static void * -route_set_originator_id_compile (const char *arg) +static void *route_set_originator_id_compile(const char *arg) { - int ret; - struct in_addr *address; + int ret; + struct in_addr *address; - address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in_addr)); + address = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(struct in_addr)); - ret = inet_aton (arg, address); + ret = inet_aton(arg, address); - if (ret == 0) - { - XFREE (MTYPE_ROUTE_MAP_COMPILED, address); - return NULL; - } + if (ret == 0) { + XFREE(MTYPE_ROUTE_MAP_COMPILED, address); + return NULL; + } - return address; + return address; } /* Compile function for originator_id set. */ -static void -route_set_originator_id_free (void *rule) +static void route_set_originator_id_free(void *rule) { - XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); + XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); } /* Set originator-id 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, +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. */ -static int -bgp_route_match_add (struct vty *vty, - const char *command, const char *arg, - route_map_event_t type) -{ - VTY_DECLVAR_CONTEXT(route_map_index, index); - int ret; - - ret = route_map_add_match (index, command, arg); - if (ret) - { - switch (ret) - { - case RMAP_RULE_MISSING: - vty_out (vty, "%% BGP Can't find rule.%s", VTY_NEWLINE); - return CMD_WARNING; - case RMAP_COMPILE_ERROR: - vty_out (vty, "%% BGP Argument is malformed.%s", VTY_NEWLINE); - return CMD_WARNING; +static int bgp_route_match_add(struct vty *vty, const char *command, + const char *arg, route_map_event_t type) +{ + VTY_DECLVAR_CONTEXT(route_map_index, index); + int ret; + + ret = route_map_add_match(index, command, arg); + if (ret) { + switch (ret) { + case RMAP_RULE_MISSING: + vty_out(vty, "%% BGP Can't find rule.%s", VTY_NEWLINE); + return CMD_WARNING; + case RMAP_COMPILE_ERROR: + vty_out(vty, "%% BGP Argument is malformed.%s", + VTY_NEWLINE); + return CMD_WARNING; + } } - } - if (type != RMAP_EVENT_MATCH_ADDED) - { - route_map_upd8_dependency (type, arg, index->map->name); - } + if (type != RMAP_EVENT_MATCH_ADDED) { + route_map_upd8_dependency(type, arg, index->map->name); + } - return CMD_SUCCESS; + return CMD_SUCCESS; } /* Delete bgp route map rule. */ -static int -bgp_route_match_delete (struct vty *vty, - const char *command, const char *arg, - route_map_event_t type) -{ - VTY_DECLVAR_CONTEXT(route_map_index, index); - int ret; - char *dep_name = NULL; - const char *tmpstr; - char *rmap_name = NULL; - - if (type != RMAP_EVENT_MATCH_DELETED) - { - /* ignore the mundane, the types without any dependency */ - if (arg == NULL) - { - if ((tmpstr = route_map_get_match_arg(index, command)) != NULL) - dep_name = XSTRDUP(MTYPE_ROUTE_MAP_RULE, tmpstr); - } - else - { - dep_name = XSTRDUP(MTYPE_ROUTE_MAP_RULE, arg); +static int bgp_route_match_delete(struct vty *vty, const char *command, + const char *arg, route_map_event_t type) +{ + VTY_DECLVAR_CONTEXT(route_map_index, index); + int ret; + char *dep_name = NULL; + const char *tmpstr; + char *rmap_name = NULL; + + if (type != RMAP_EVENT_MATCH_DELETED) { + /* ignore the mundane, the types without any dependency */ + if (arg == NULL) { + if ((tmpstr = route_map_get_match_arg(index, command)) + != NULL) + dep_name = + XSTRDUP(MTYPE_ROUTE_MAP_RULE, tmpstr); + } else { + dep_name = XSTRDUP(MTYPE_ROUTE_MAP_RULE, arg); + } + rmap_name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, index->map->name); } - rmap_name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, index->map->name); - } - - ret = route_map_delete_match (index, command, dep_name); - if (ret) - { - switch (ret) - { - case RMAP_RULE_MISSING: - vty_out (vty, "%% BGP Can't find rule.%s", VTY_NEWLINE); - break; - case RMAP_COMPILE_ERROR: - vty_out (vty, "%% BGP Argument is malformed.%s", VTY_NEWLINE); - break; + + ret = route_map_delete_match(index, command, dep_name); + if (ret) { + switch (ret) { + case RMAP_RULE_MISSING: + vty_out(vty, "%% BGP Can't find rule.%s", VTY_NEWLINE); + break; + case RMAP_COMPILE_ERROR: + vty_out(vty, "%% BGP Argument is malformed.%s", + VTY_NEWLINE); + break; + } + if (dep_name) + XFREE(MTYPE_ROUTE_MAP_RULE, dep_name); + if (rmap_name) + XFREE(MTYPE_ROUTE_MAP_NAME, rmap_name); + return CMD_WARNING; } - if (dep_name) - XFREE(MTYPE_ROUTE_MAP_RULE, dep_name); - if (rmap_name) - XFREE(MTYPE_ROUTE_MAP_NAME, rmap_name); - return CMD_WARNING; - } - if (type != RMAP_EVENT_MATCH_DELETED && dep_name) - route_map_upd8_dependency(type, dep_name, rmap_name); + if (type != RMAP_EVENT_MATCH_DELETED && dep_name) + route_map_upd8_dependency(type, dep_name, rmap_name); - if (dep_name) - XFREE(MTYPE_ROUTE_MAP_RULE, dep_name); - if (rmap_name) - XFREE(MTYPE_ROUTE_MAP_NAME, rmap_name); + if (dep_name) + XFREE(MTYPE_ROUTE_MAP_RULE, dep_name); + if (rmap_name) + XFREE(MTYPE_ROUTE_MAP_NAME, rmap_name); - return CMD_SUCCESS; + return CMD_SUCCESS; } /* * This is the workhorse routine for processing in/out routemap * modifications. */ -static void -bgp_route_map_process_peer (const char *rmap_name, struct route_map *map, - struct peer *peer, int afi, int safi, - int route_update) -{ - - int update; - struct bgp_filter *filter; - - if (!peer || !rmap_name) - return; - - filter = &peer->filter[afi][safi]; - /* - * in is for non-route-server clients, - * out is for all peers - */ - if (!CHECK_FLAG(peer->flags, PEER_FLAG_RSERVER_CLIENT)) - { - if (filter->map[RMAP_IN].name && - (strcmp(rmap_name, filter->map[RMAP_IN].name) == 0)) - { - filter->map[RMAP_IN].map = map; - - if (route_update && peer->status == Established) - { - if (CHECK_FLAG (peer->af_flags[afi][safi], - PEER_FLAG_SOFT_RECONFIG)) - { - if (bgp_debug_update(peer, NULL, NULL, 1)) - zlog_debug("Processing route_map %s update on " - "peer %s (inbound, soft-reconfig)", - rmap_name, peer->host); - - bgp_soft_reconfig_in (peer, afi, safi); - } - else if (CHECK_FLAG (peer->cap, PEER_CAP_REFRESH_OLD_RCV) - || CHECK_FLAG (peer->cap, PEER_CAP_REFRESH_NEW_RCV)) - { - - if (bgp_debug_update(peer, NULL, NULL, 1)) - zlog_debug("Processing route_map %s update on " - "peer %s (inbound, route-refresh)", - rmap_name, peer->host); - bgp_route_refresh_send (peer, afi, safi, 0, 0, 0); +static void bgp_route_map_process_peer(const char *rmap_name, + struct route_map *map, struct peer *peer, + int afi, int safi, int route_update) +{ + + int update; + struct bgp_filter *filter; + + if (!peer || !rmap_name) + return; + + filter = &peer->filter[afi][safi]; + /* + * in is for non-route-server clients, + * out is for all peers + */ + if (!CHECK_FLAG(peer->flags, PEER_FLAG_RSERVER_CLIENT)) { + if (filter->map[RMAP_IN].name + && (strcmp(rmap_name, filter->map[RMAP_IN].name) == 0)) { + filter->map[RMAP_IN].map = map; + + if (route_update && peer->status == Established) { + if (CHECK_FLAG(peer->af_flags[afi][safi], + PEER_FLAG_SOFT_RECONFIG)) { + if (bgp_debug_update(peer, NULL, NULL, + 1)) + zlog_debug( + "Processing route_map %s update on " + "peer %s (inbound, soft-reconfig)", + rmap_name, peer->host); + + bgp_soft_reconfig_in(peer, afi, safi); + } else if ( + CHECK_FLAG(peer->cap, + PEER_CAP_REFRESH_OLD_RCV) + || CHECK_FLAG( + peer->cap, + PEER_CAP_REFRESH_NEW_RCV)) { + + if (bgp_debug_update(peer, NULL, NULL, + 1)) + zlog_debug( + "Processing route_map %s update on " + "peer %s (inbound, route-refresh)", + rmap_name, peer->host); + bgp_route_refresh_send(peer, afi, safi, + 0, 0, 0); + } + } } - } } - } - - if (CHECK_FLAG(peer->flags, PEER_FLAG_RSERVER_CLIENT)) - { - update = 0; - - if (update && route_update && peer->status == Established) - { - if (CHECK_FLAG (peer->af_flags[afi][safi], - PEER_FLAG_SOFT_RECONFIG)) - { - if (bgp_debug_update(peer, NULL, NULL, 1)) - zlog_debug("Processing route_map %s update on " - "peer %s (import, soft-reconfig)", - rmap_name, peer->host); - - bgp_soft_reconfig_in (peer, afi, safi); - } - else if (CHECK_FLAG (peer->cap, PEER_CAP_REFRESH_OLD_RCV) - || CHECK_FLAG (peer->cap, PEER_CAP_REFRESH_NEW_RCV)) - { - if (bgp_debug_update(peer, NULL, NULL, 1)) - zlog_debug("Processing route_map %s update on " - "peer %s (import, route-refresh)", - rmap_name, peer->host); - bgp_route_refresh_send (peer, afi, safi, 0, 0, 0); - } - /* DD: Else, what else do we do ? Reset peer ? */ - } - } - - /* - * For outbound, unsuppress and default-originate map change (content or - * map created), merely update the "config" here, the actual route - * announcement happens at the group level. - */ - if (filter->map[RMAP_OUT].name && - (strcmp(rmap_name, filter->map[RMAP_OUT].name) == 0)) - filter->map[RMAP_OUT].map = map; - - if (filter->usmap.name && - (strcmp(rmap_name, filter->usmap.name) == 0)) - filter->usmap.map = map; - - if (peer->default_rmap[afi][safi].name && - (strcmp (rmap_name, peer->default_rmap[afi][safi].name) == 0)) - peer->default_rmap[afi][safi].map = map; -} - -static void -bgp_route_map_update_peer_group(const char *rmap_name, struct route_map *map, - struct bgp *bgp) -{ - struct peer_group *group; - struct listnode *node, *nnode; - struct bgp_filter *filter; - int afi, safi; - int direct; - - if (!bgp) - return; - - /* All the peers have been updated correctly already. This is - * just updating the placeholder data. No real update required. - */ - for (ALL_LIST_ELEMENTS (bgp->group, node, nnode, group)) - for (afi = AFI_IP; afi < AFI_MAX; afi++) - for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) - { - filter = &group->conf->filter[afi][safi]; - - for (direct = RMAP_IN; direct < RMAP_MAX; direct++) - { - if ((filter->map[direct].name) && - (strcmp(rmap_name, filter->map[direct].name) == 0)) - filter->map[direct].map = map; - } - - if (filter->usmap.name && - (strcmp(rmap_name, filter->usmap.name) == 0)) - filter->usmap.map = map; + + if (CHECK_FLAG(peer->flags, PEER_FLAG_RSERVER_CLIENT)) { + update = 0; + + if (update && route_update && peer->status == Established) { + if (CHECK_FLAG(peer->af_flags[afi][safi], + PEER_FLAG_SOFT_RECONFIG)) { + if (bgp_debug_update(peer, NULL, NULL, 1)) + zlog_debug( + "Processing route_map %s update on " + "peer %s (import, soft-reconfig)", + rmap_name, peer->host); + + bgp_soft_reconfig_in(peer, afi, safi); + } else if (CHECK_FLAG(peer->cap, + PEER_CAP_REFRESH_OLD_RCV) + || CHECK_FLAG(peer->cap, + PEER_CAP_REFRESH_NEW_RCV)) { + if (bgp_debug_update(peer, NULL, NULL, 1)) + zlog_debug( + "Processing route_map %s update on " + "peer %s (import, route-refresh)", + rmap_name, peer->host); + bgp_route_refresh_send(peer, afi, safi, 0, 0, + 0); + } + /* DD: Else, what else do we do ? Reset peer ? */ + } } + + /* + * For outbound, unsuppress and default-originate map change (content or + * map created), merely update the "config" here, the actual route + * announcement happens at the group level. + */ + if (filter->map[RMAP_OUT].name + && (strcmp(rmap_name, filter->map[RMAP_OUT].name) == 0)) + filter->map[RMAP_OUT].map = map; + + if (filter->usmap.name && (strcmp(rmap_name, filter->usmap.name) == 0)) + filter->usmap.map = map; + + if (peer->default_rmap[afi][safi].name + && (strcmp(rmap_name, peer->default_rmap[afi][safi].name) == 0)) + peer->default_rmap[afi][safi].map = map; +} + +static void bgp_route_map_update_peer_group(const char *rmap_name, + struct route_map *map, + struct bgp *bgp) +{ + struct peer_group *group; + struct listnode *node, *nnode; + struct bgp_filter *filter; + int afi, safi; + int direct; + + if (!bgp) + return; + + /* All the peers have been updated correctly already. This is + * just updating the placeholder data. No real update required. + */ + for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) + for (afi = AFI_IP; afi < AFI_MAX; afi++) + for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) { + filter = &group->conf->filter[afi][safi]; + + for (direct = RMAP_IN; direct < RMAP_MAX; + direct++) { + if ((filter->map[direct].name) + && (strcmp(rmap_name, + filter->map[direct].name) + == 0)) + filter->map[direct].map = map; + } + + if (filter->usmap.name + && (strcmp(rmap_name, filter->usmap.name) + == 0)) + filter->usmap.map = map; + } } /* @@ -3027,200 +2783,210 @@ bgp_route_map_update_peer_group(const char *rmap_name, struct route_map *map, * called for each route-map and within this function we walk the list of peers, * network statements, etc looking to see if they use this route-map. */ -static void -bgp_route_map_process_update (struct bgp *bgp, const char *rmap_name, int route_update) -{ - int i; - afi_t afi; - safi_t safi; - struct peer *peer; - struct bgp_node *bn; - struct bgp_static *bgp_static; - struct listnode *node, *nnode; - struct route_map *map; - char buf[INET6_ADDRSTRLEN]; - - map = route_map_lookup_by_name (rmap_name); - - for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer)) - { - - /* Ignore dummy peer-group structure */ - if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) - continue; - - for (afi = AFI_IP; afi < AFI_MAX; afi++) - for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) - { - /* Ignore inactive AFI/SAFI */ - if (! peer->afc[afi][safi]) - continue; - - /* process in/out/import/export/default-orig route-maps */ - bgp_route_map_process_peer(rmap_name, map, peer, afi, safi, route_update); - } - } - - /* for outbound/default-orig route-maps, process for groups */ - update_group_policy_update(bgp, BGP_POLICY_ROUTE_MAP, rmap_name, - route_update, 0); - - /* update peer-group config (template) */ - bgp_route_map_update_peer_group(rmap_name, map, bgp); - - for (afi = AFI_IP; afi < AFI_MAX; afi++) - for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) - { - /* For table route-map updates. */ - if (bgp->table_map[afi][safi].name && - (strcmp(rmap_name, bgp->table_map[afi][safi].name) == 0)) - { - bgp->table_map[afi][safi].map = map; - - if (BGP_DEBUG (zebra, ZEBRA)) - zlog_debug("Processing route_map %s update on " - "table map", rmap_name); - if (route_update) - bgp_zebra_announce_table(bgp, afi, safi); - } - - /* For network route-map updates. */ - 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 && - (strcmp(rmap_name, bgp_static->rmap.name) == 0)) - { - bgp_static->rmap.map = map; - - if (route_update) - if (!bgp_static->backdoor) - { - if (bgp_debug_zebra(&bn->p)) - zlog_debug("Processing route_map %s update on " - "static route %s", rmap_name, - inet_ntop (bn->p.family, &bn->p.u.prefix, - buf, INET6_ADDRSTRLEN)); - bgp_static_update (bgp, &bn->p, bgp_static, afi, safi); - } - } - } - } - - /* For redistribute route-map updates. */ - for (afi = AFI_IP; afi < AFI_MAX; afi++) - for (i = 0; i < ZEBRA_ROUTE_MAX; i++) - { - struct list *red_list; - struct listnode *node; - struct bgp_redist *red; - - red_list = bgp->redist[afi][i]; - if (!red_list) - continue; - - for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) - { - if (red->rmap.name && - (strcmp(rmap_name, red->rmap.name) == 0)) - { - red->rmap.map = map; - - if (route_update) - { - if (BGP_DEBUG (zebra, ZEBRA)) - zlog_debug("Processing route_map %s update on " - "redistributed routes", rmap_name); - - bgp_redistribute_resend (bgp, afi, i, red->instance); - } - } - } - } -} - -static int -bgp_route_map_process_update_cb (char *rmap_name) -{ - struct listnode *node, *nnode; - struct bgp *bgp; - - for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp)) - bgp_route_map_process_update(bgp, rmap_name, 1); +static void bgp_route_map_process_update(struct bgp *bgp, const char *rmap_name, + int route_update) +{ + int i; + afi_t afi; + safi_t safi; + struct peer *peer; + struct bgp_node *bn; + struct bgp_static *bgp_static; + struct listnode *node, *nnode; + struct route_map *map; + char buf[INET6_ADDRSTRLEN]; + + map = route_map_lookup_by_name(rmap_name); + + for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) { + + /* Ignore dummy peer-group structure */ + if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) + continue; + + for (afi = AFI_IP; afi < AFI_MAX; afi++) + for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) { + /* Ignore inactive AFI/SAFI */ + if (!peer->afc[afi][safi]) + continue; + + /* process in/out/import/export/default-orig + * route-maps */ + bgp_route_map_process_peer(rmap_name, map, peer, + afi, safi, + route_update); + } + } + + /* for outbound/default-orig route-maps, process for groups */ + update_group_policy_update(bgp, BGP_POLICY_ROUTE_MAP, rmap_name, + route_update, 0); + + /* update peer-group config (template) */ + bgp_route_map_update_peer_group(rmap_name, map, bgp); + + for (afi = AFI_IP; afi < AFI_MAX; afi++) + for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) { + /* For table route-map updates. */ + if (bgp->table_map[afi][safi].name + && (strcmp(rmap_name, + bgp->table_map[afi][safi].name) + == 0)) { + bgp->table_map[afi][safi].map = map; + + if (BGP_DEBUG(zebra, ZEBRA)) + zlog_debug( + "Processing route_map %s update on " + "table map", + rmap_name); + if (route_update) + bgp_zebra_announce_table(bgp, afi, + safi); + } + + /* For network route-map updates. */ + 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 + && (strcmp(rmap_name, + bgp_static->rmap.name) + == 0)) { + bgp_static->rmap.map = map; + + if (route_update) + if (!bgp_static + ->backdoor) { + if (bgp_debug_zebra( + &bn->p)) + zlog_debug( + "Processing route_map %s update on " + "static route %s", + rmap_name, + inet_ntop( + bn->p.family, + &bn->p.u.prefix, + buf, + INET6_ADDRSTRLEN)); + bgp_static_update( + bgp, + &bn->p, + bgp_static, + afi, + safi); + } + } + } + } + + /* For redistribute route-map updates. */ + for (afi = AFI_IP; afi < AFI_MAX; afi++) + for (i = 0; i < ZEBRA_ROUTE_MAX; i++) { + struct list *red_list; + struct listnode *node; + struct bgp_redist *red; + + red_list = bgp->redist[afi][i]; + if (!red_list) + continue; + + for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) { + if (red->rmap.name + && (strcmp(rmap_name, red->rmap.name) + == 0)) { + red->rmap.map = map; + + if (route_update) { + if (BGP_DEBUG(zebra, ZEBRA)) + zlog_debug( + "Processing route_map %s update on " + "redistributed routes", + rmap_name); + + bgp_redistribute_resend( + bgp, afi, i, + red->instance); + } + } + } + } +} + +static int bgp_route_map_process_update_cb(char *rmap_name) +{ + struct listnode *node, *nnode; + struct bgp *bgp; + + for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) + bgp_route_map_process_update(bgp, rmap_name, 1); #if ENABLE_BGP_VNC - zlog_debug("%s: calling vnc_routemap_update", __func__); - vnc_routemap_update(bgp, __func__); + zlog_debug("%s: calling vnc_routemap_update", __func__); + vnc_routemap_update(bgp, __func__); #endif - return 0; + return 0; } -int -bgp_route_map_update_timer(struct thread *thread) +int bgp_route_map_update_timer(struct thread *thread) { - bm->t_rmap_update = NULL; + bm->t_rmap_update = NULL; - route_map_walk_update_list(bgp_route_map_process_update_cb); + route_map_walk_update_list(bgp_route_map_process_update_cb); - return (0); + return (0); } -static void -bgp_route_map_mark_update (const char *rmap_name) +static void bgp_route_map_mark_update(const char *rmap_name) { - if (bm->t_rmap_update == NULL) - { - struct listnode *node, *nnode; - struct bgp *bgp; + if (bm->t_rmap_update == NULL) { + struct listnode *node, *nnode; + struct bgp *bgp; - /* rmap_update_timer of 0 means don't do route updates */ - if (bm->rmap_update_timer) - { - bm->t_rmap_update = - thread_add_timer(bm->master, bgp_route_map_update_timer, NULL, - bm->rmap_update_timer); + /* rmap_update_timer of 0 means don't do route updates */ + if (bm->rmap_update_timer) { + bm->t_rmap_update = thread_add_timer( + bm->master, bgp_route_map_update_timer, NULL, + bm->rmap_update_timer); - /* Signal the groups that a route-map update event has started */ - for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp)) - update_group_policy_update(bgp, BGP_POLICY_ROUTE_MAP, rmap_name, 1, 1); - } - else - { - for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp)) - bgp_route_map_process_update(bgp, rmap_name, 0); - #if ENABLE_BGP_VNC - zlog_debug("%s: calling vnc_routemap_update", __func__); - vnc_routemap_update(bgp, __func__); + /* Signal the groups that a route-map update event has + * started */ + for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) + update_group_policy_update(bgp, + BGP_POLICY_ROUTE_MAP, + rmap_name, 1, 1); + } else { + for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) + bgp_route_map_process_update(bgp, rmap_name, 0); +#if ENABLE_BGP_VNC + zlog_debug("%s: calling vnc_routemap_update", __func__); + vnc_routemap_update(bgp, __func__); #endif - } - } + } + } } -static void -bgp_route_map_add (const char *rmap_name) +static void bgp_route_map_add(const char *rmap_name) { - if (route_map_mark_updated(rmap_name, 0) == 0) - bgp_route_map_mark_update(rmap_name); + if (route_map_mark_updated(rmap_name, 0) == 0) + bgp_route_map_mark_update(rmap_name); - route_map_notify_dependencies(rmap_name, RMAP_EVENT_MATCH_ADDED); + route_map_notify_dependencies(rmap_name, RMAP_EVENT_MATCH_ADDED); } -static void -bgp_route_map_delete (const char *rmap_name) +static void bgp_route_map_delete(const char *rmap_name) { - if (route_map_mark_updated(rmap_name, 1) == 0) - bgp_route_map_mark_update(rmap_name); + if (route_map_mark_updated(rmap_name, 1) == 0) + bgp_route_map_mark_update(rmap_name); - route_map_notify_dependencies(rmap_name, RMAP_EVENT_MATCH_DELETED); + route_map_notify_dependencies(rmap_name, RMAP_EVENT_MATCH_DELETED); } -static void -bgp_route_map_event (route_map_event_t event, const char *rmap_name) +static void bgp_route_map_event(route_map_event_t event, const char *rmap_name) { - if (route_map_mark_updated(rmap_name, 0) == 0) - bgp_route_map_mark_update(rmap_name); + if (route_map_mark_updated(rmap_name, 0) == 0) + bgp_route_map_mark_update(rmap_name); - route_map_notify_dependencies(rmap_name, RMAP_EVENT_MATCH_ADDED); + route_map_notify_dependencies(rmap_name, RMAP_EVENT_MATCH_ADDED); } @@ -3232,9 +2998,9 @@ DEFUN (match_peer, "IP address of peer\n" "IPv6 address of peer\n") { - int idx_ip = 2; - return bgp_route_match_add (vty, "peer", argv[idx_ip]->arg, - RMAP_EVENT_MATCH_ADDED); + int idx_ip = 2; + return bgp_route_match_add(vty, "peer", argv[idx_ip]->arg, + RMAP_EVENT_MATCH_ADDED); } DEFUN (match_peer_local, @@ -3244,8 +3010,8 @@ DEFUN (match_peer_local, "Match peer address\n" "Static or Redistributed routes\n") { - return bgp_route_match_add (vty, "peer", "local", - RMAP_EVENT_MATCH_DELETED); + return bgp_route_match_add(vty, "peer", "local", + RMAP_EVENT_MATCH_DELETED); } DEFUN (no_match_peer, @@ -3258,13 +3024,13 @@ DEFUN (no_match_peer, "IP address of peer\n" "IPv6 address of peer\n") { - int idx_peer = 3; + int idx_peer = 3; - if (argc <= idx_peer) - return bgp_route_match_delete (vty, "peer", NULL, - RMAP_EVENT_MATCH_DELETED); - return bgp_route_match_delete (vty, "peer", argv[idx_peer]->arg, - RMAP_EVENT_MATCH_DELETED); + if (argc <= idx_peer) + return bgp_route_match_delete(vty, "peer", NULL, + RMAP_EVENT_MATCH_DELETED); + return bgp_route_match_delete(vty, "peer", argv[idx_peer]->arg, + RMAP_EVENT_MATCH_DELETED); } @@ -3276,9 +3042,9 @@ DEFUN (match_probability, "Match portion of routes defined by percentage value\n" "Percentage of routes\n") { - int idx_number = 2; - return bgp_route_match_add (vty, "probability", argv[idx_number]->arg, - RMAP_EVENT_MATCH_ADDED); + int idx_number = 2; + return bgp_route_match_add(vty, "probability", argv[idx_number]->arg, + RMAP_EVENT_MATCH_ADDED); } @@ -3290,12 +3056,12 @@ DEFUN (no_match_probability, "Match portion of routes defined by percentage value\n" "Percentage of routes\n") { - int idx_number = 3; - if (argc <= idx_number) - return bgp_route_match_delete (vty, "probability", NULL, - RMAP_EVENT_MATCH_DELETED); - return bgp_route_match_delete (vty, "probability", argv[idx_number]->arg, - RMAP_EVENT_MATCH_DELETED); + int idx_number = 3; + if (argc <= idx_number) + return bgp_route_match_delete(vty, "probability", NULL, + RMAP_EVENT_MATCH_DELETED); + return bgp_route_match_delete(vty, "probability", argv[idx_number]->arg, + RMAP_EVENT_MATCH_DELETED); } @@ -3309,9 +3075,9 @@ DEFUN (match_ip_route_source, "IP access-list number (expanded range)\n" "IP standard access-list name\n") { - int idx_acl = 3; - return bgp_route_match_add (vty, "ip route-source", argv[idx_acl]->arg, - RMAP_EVENT_FILTER_ADDED); + int idx_acl = 3; + return bgp_route_match_add(vty, "ip route-source", argv[idx_acl]->arg, + RMAP_EVENT_FILTER_ADDED); } @@ -3326,12 +3092,13 @@ DEFUN (no_match_ip_route_source, "IP access-list number (expanded range)\n" "IP standard access-list name\n") { - int idx_number = 4; - if (argc <= idx_number) - return bgp_route_match_delete (vty, "ip route-source", - NULL, RMAP_EVENT_FILTER_DELETED); - return bgp_route_match_delete (vty, "ip route-source", - argv[idx_number]->arg, RMAP_EVENT_FILTER_DELETED); + int idx_number = 4; + if (argc <= idx_number) + return bgp_route_match_delete(vty, "ip route-source", NULL, + RMAP_EVENT_FILTER_DELETED); + return bgp_route_match_delete(vty, "ip route-source", + argv[idx_number]->arg, + RMAP_EVENT_FILTER_DELETED); } @@ -3344,9 +3111,9 @@ DEFUN (match_ip_route_source_prefix_list, "Match entries of prefix-lists\n" "IP prefix-list name\n") { - int idx_word = 4; - return bgp_route_match_add (vty, "ip route-source prefix-list", - argv[idx_word]->arg, RMAP_EVENT_PLIST_ADDED); + int idx_word = 4; + return bgp_route_match_add(vty, "ip route-source prefix-list", + argv[idx_word]->arg, RMAP_EVENT_PLIST_ADDED); } @@ -3360,12 +3127,14 @@ DEFUN (no_match_ip_route_source_prefix_list, "Match entries of prefix-lists\n" "IP prefix-list name\n") { - int idx_word = 5; - if (argc <= idx_word) - return bgp_route_match_delete (vty, "ip route-source prefix-list", - NULL, RMAP_EVENT_PLIST_DELETED); - return bgp_route_match_delete (vty, "ip route-source prefix-list", - argv[idx_word]->arg, RMAP_EVENT_PLIST_DELETED); + int idx_word = 5; + if (argc <= idx_word) + return bgp_route_match_delete(vty, + "ip route-source prefix-list", + NULL, RMAP_EVENT_PLIST_DELETED); + return bgp_route_match_delete(vty, "ip route-source prefix-list", + argv[idx_word]->arg, + RMAP_EVENT_PLIST_DELETED); } @@ -3376,9 +3145,10 @@ DEFUN (match_local_pref, "Match local-preference of route\n" "Metric value\n") { - int idx_number = 2; - return bgp_route_match_add (vty, "local-preference", argv[idx_number]->arg, - RMAP_EVENT_MATCH_ADDED); + int idx_number = 2; + return bgp_route_match_add(vty, "local-preference", + argv[idx_number]->arg, + RMAP_EVENT_MATCH_ADDED); } @@ -3390,13 +3160,13 @@ DEFUN (no_match_local_pref, "Match local preference of route\n" "Local preference value\n") { - int idx_localpref = 3; - if (argc <= idx_localpref) - return bgp_route_match_delete (vty, "local-preference", - NULL, RMAP_EVENT_MATCH_DELETED); - return bgp_route_match_delete (vty, "local-preference", - argv[idx_localpref]->arg, - RMAP_EVENT_MATCH_DELETED); + int idx_localpref = 3; + if (argc <= idx_localpref) + return bgp_route_match_delete(vty, "local-preference", NULL, + RMAP_EVENT_MATCH_DELETED); + return bgp_route_match_delete(vty, "local-preference", + argv[idx_localpref]->arg, + RMAP_EVENT_MATCH_DELETED); } @@ -3410,28 +3180,26 @@ DEFUN (match_community, "Community-list name\n" "Do exact matching of communities\n") { - int idx_comm_list = 2; - int ret; - char *argstr; + int idx_comm_list = 2; + int ret; + char *argstr; - if (argc == 4) - { - argstr = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, - strlen (argv[idx_comm_list]->arg) + - strlen ("exact-match") + 2); + if (argc == 4) { + argstr = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, + strlen(argv[idx_comm_list]->arg) + + strlen("exact-match") + 2); - sprintf (argstr, "%s exact-match", argv[idx_comm_list]->arg); - } - else - argstr = argv[idx_comm_list]->arg; + sprintf(argstr, "%s exact-match", argv[idx_comm_list]->arg); + } else + argstr = argv[idx_comm_list]->arg; - ret = bgp_route_match_add (vty, "community", argstr, - RMAP_EVENT_CLIST_ADDED); + ret = bgp_route_match_add(vty, "community", argstr, + RMAP_EVENT_CLIST_ADDED); - if (argstr != argv[idx_comm_list]->arg) - XFREE (MTYPE_ROUTE_MAP_COMPILED, argstr); + if (argstr != argv[idx_comm_list]->arg) + XFREE(MTYPE_ROUTE_MAP_COMPILED, argstr); - return ret; + return ret; } DEFUN (no_match_community, @@ -3445,8 +3213,8 @@ DEFUN (no_match_community, "Community-list name\n" "Do exact matching of communities\n") { - return bgp_route_match_delete (vty, "community", NULL, - RMAP_EVENT_CLIST_DELETED); + return bgp_route_match_delete(vty, "community", NULL, + RMAP_EVENT_CLIST_DELETED); } DEFUN (match_lcommunity, @@ -3458,8 +3226,8 @@ DEFUN (match_lcommunity, "Large Community-list number (expanded)\n" "Large Community-list name\n") { - return bgp_route_match_add (vty, "large-community", argv[2]->arg, - RMAP_EVENT_LLIST_ADDED); + return bgp_route_match_add(vty, "large-community", argv[2]->arg, + RMAP_EVENT_LLIST_ADDED); } DEFUN (no_match_lcommunity, @@ -3472,8 +3240,8 @@ DEFUN (no_match_lcommunity, "Large Community-list number (expanded)\n" "Large Community-list name\n") { - return bgp_route_match_delete (vty, "large-community", NULL, - RMAP_EVENT_LLIST_DELETED); + return bgp_route_match_delete(vty, "large-community", NULL, + RMAP_EVENT_LLIST_DELETED); } DEFUN (match_ecommunity, @@ -3485,9 +3253,10 @@ DEFUN (match_ecommunity, "Extended community-list number (expanded)\n" "Extended community-list name\n") { - int idx_comm_list = 2; - return bgp_route_match_add (vty, "extcommunity", argv[idx_comm_list]->arg, - RMAP_EVENT_ECLIST_ADDED); + int idx_comm_list = 2; + return bgp_route_match_add(vty, "extcommunity", + argv[idx_comm_list]->arg, + RMAP_EVENT_ECLIST_ADDED); } @@ -3501,8 +3270,8 @@ DEFUN (no_match_ecommunity, "Extended community-list number (expanded)\n" "Extended community-list name\n") { - return bgp_route_match_delete (vty, "extcommunity", NULL, - RMAP_EVENT_ECLIST_DELETED); + return bgp_route_match_delete(vty, "extcommunity", NULL, + RMAP_EVENT_ECLIST_DELETED); } @@ -3513,9 +3282,9 @@ DEFUN (match_aspath, "Match BGP AS path list\n" "AS path access-list name\n") { - int idx_word = 2; - return bgp_route_match_add (vty, "as-path", argv[idx_word]->arg, - RMAP_EVENT_ASLIST_ADDED); + int idx_word = 2; + return bgp_route_match_add(vty, "as-path", argv[idx_word]->arg, + RMAP_EVENT_ASLIST_ADDED); } @@ -3527,8 +3296,8 @@ DEFUN (no_match_aspath, "Match BGP AS path list\n" "AS path access-list name\n") { - return bgp_route_match_delete (vty, "as-path", NULL, - RMAP_EVENT_ASLIST_DELETED); + return bgp_route_match_delete(vty, "as-path", NULL, + RMAP_EVENT_ASLIST_DELETED); } @@ -3541,18 +3310,18 @@ DEFUN (match_origin, "local IGP\n" "unknown heritage\n") { - int idx_origin = 2; - if (strncmp (argv[idx_origin]->arg, "igp", 2) == 0) - return bgp_route_match_add (vty, "origin", "igp", - RMAP_EVENT_MATCH_ADDED); - if (strncmp (argv[idx_origin]->arg, "egp", 1) == 0) - return bgp_route_match_add (vty, "origin", "egp", - RMAP_EVENT_MATCH_ADDED); - if (strncmp (argv[idx_origin]->arg, "incomplete", 2) == 0) - return bgp_route_match_add (vty, "origin", "incomplete", - RMAP_EVENT_MATCH_ADDED); + int idx_origin = 2; + if (strncmp(argv[idx_origin]->arg, "igp", 2) == 0) + return bgp_route_match_add(vty, "origin", "igp", + RMAP_EVENT_MATCH_ADDED); + if (strncmp(argv[idx_origin]->arg, "egp", 1) == 0) + return bgp_route_match_add(vty, "origin", "egp", + RMAP_EVENT_MATCH_ADDED); + if (strncmp(argv[idx_origin]->arg, "incomplete", 2) == 0) + return bgp_route_match_add(vty, "origin", "incomplete", + RMAP_EVENT_MATCH_ADDED); - return CMD_WARNING; + return CMD_WARNING; } @@ -3566,8 +3335,8 @@ DEFUN (no_match_origin, "local IGP\n" "unknown heritage\n") { - return bgp_route_match_delete (vty, "origin", NULL, - RMAP_EVENT_MATCH_DELETED); + return bgp_route_match_delete(vty, "origin", NULL, + RMAP_EVENT_MATCH_DELETED); } DEFUN (set_ip_nexthop_peer, @@ -3578,8 +3347,8 @@ DEFUN (set_ip_nexthop_peer, "Next hop address\n" "Use peer address (for BGP only)\n") { - return generic_set_add (vty, VTY_GET_CONTEXT(route_map_index), - "ip next-hop", "peer-address"); + return generic_set_add(vty, VTY_GET_CONTEXT(route_map_index), + "ip next-hop", "peer-address"); } DEFUN (set_ip_nexthop_unchanged, @@ -3590,8 +3359,8 @@ DEFUN (set_ip_nexthop_unchanged, "Next hop address\n" "Don't modify existing Next hop address\n") { - return generic_set_add (vty, VTY_GET_CONTEXT(route_map_index), - "ip next-hop", "unchanged"); + return generic_set_add(vty, VTY_GET_CONTEXT(route_map_index), + "ip next-hop", "unchanged"); } @@ -3602,9 +3371,9 @@ DEFUN (set_local_pref, "BGP local preference path attribute\n" "Preference value\n") { - int idx_number = 2; - return generic_set_add (vty, VTY_GET_CONTEXT(route_map_index), - "local-preference", argv[idx_number]->arg); + int idx_number = 2; + return generic_set_add(vty, VTY_GET_CONTEXT(route_map_index), + "local-preference", argv[idx_number]->arg); } @@ -3616,12 +3385,12 @@ DEFUN (no_set_local_pref, "BGP local preference path attribute\n" "Preference value\n") { - int idx_localpref = 3; - if (argc <= idx_localpref) - return generic_set_delete (vty, VTY_GET_CONTEXT(route_map_index), - "local-preference", NULL); - return generic_set_delete (vty, VTY_GET_CONTEXT(route_map_index), - "local-preference", argv[idx_localpref]->arg); + int idx_localpref = 3; + if (argc <= idx_localpref) + return generic_set_delete(vty, VTY_GET_CONTEXT(route_map_index), + "local-preference", NULL); + return generic_set_delete(vty, VTY_GET_CONTEXT(route_map_index), + "local-preference", argv[idx_localpref]->arg); } @@ -3632,9 +3401,9 @@ DEFUN (set_weight, "BGP weight for routing table\n" "Weight value\n") { - int idx_number = 2; - return generic_set_add (vty, VTY_GET_CONTEXT(route_map_index), "weight", - argv[idx_number]->arg); + int idx_number = 2; + return generic_set_add(vty, VTY_GET_CONTEXT(route_map_index), "weight", + argv[idx_number]->arg); } @@ -3646,12 +3415,12 @@ DEFUN (no_set_weight, "BGP weight for routing table\n" "Weight value\n") { - int idx_weight = 3; - if (argc <= idx_weight) - return generic_set_delete (vty, VTY_GET_CONTEXT(route_map_index), - "weight", NULL); - return generic_set_delete (vty, VTY_GET_CONTEXT(route_map_index), "weight", - argv[idx_weight]->arg); + int idx_weight = 3; + if (argc <= idx_weight) + return generic_set_delete(vty, VTY_GET_CONTEXT(route_map_index), + "weight", NULL); + return generic_set_delete(vty, VTY_GET_CONTEXT(route_map_index), + "weight", argv[idx_weight]->arg); } @@ -3663,16 +3432,16 @@ DEFUN (set_aspath_prepend_asn, "Prepend to the as-path\n" "AS number\n") { - int idx_asn = 3; - int ret; - char *str; + int idx_asn = 3; + int ret; + char *str; - str = argv_concat (argv, argc, idx_asn); - ret = generic_set_add (vty, VTY_GET_CONTEXT(route_map_index), - "as-path prepend", str); - XFREE (MTYPE_TMP, str); + str = argv_concat(argv, argc, idx_asn); + ret = generic_set_add(vty, VTY_GET_CONTEXT(route_map_index), + "as-path prepend", str); + XFREE(MTYPE_TMP, str); - return ret; + return ret; } DEFUN (set_aspath_prepend_lastas, @@ -3684,7 +3453,7 @@ DEFUN (set_aspath_prepend_lastas, "Use the peer's AS-number\n" "Number of times to insert\n") { - return set_aspath_prepend_asn (self, vty, argc, argv); + return set_aspath_prepend_asn(self, vty, argc, argv); } DEFUN (no_set_aspath_prepend, @@ -3696,15 +3465,15 @@ DEFUN (no_set_aspath_prepend, "Prepend to the as-path\n" "AS number\n") { - int idx_asn = 4; - int ret; - char *str; + int idx_asn = 4; + int ret; + char *str; - str = argv_concat (argv, argc, idx_asn); - ret = generic_set_delete (vty, VTY_GET_CONTEXT(route_map_index), - "as-path prepend", str); - XFREE (MTYPE_TMP, str); - return ret; + str = argv_concat(argv, argc, idx_asn); + ret = generic_set_delete(vty, VTY_GET_CONTEXT(route_map_index), + "as-path prepend", str); + XFREE(MTYPE_TMP, str); + return ret; } @@ -3716,15 +3485,15 @@ DEFUN (set_aspath_exclude, "Exclude from the as-path\n" "AS number\n") { - int idx_asn = 3; - int ret; - char *str; + int idx_asn = 3; + int ret; + char *str; - str = argv_concat (argv, argc, idx_asn); - ret = generic_set_add (vty, VTY_GET_CONTEXT(route_map_index), - "as-path exclude", str); - XFREE (MTYPE_TMP, str); - return ret; + str = argv_concat(argv, argc, idx_asn); + ret = generic_set_add(vty, VTY_GET_CONTEXT(route_map_index), + "as-path exclude", str); + XFREE(MTYPE_TMP, str); + return ret; } DEFUN (no_set_aspath_exclude, @@ -3736,15 +3505,15 @@ DEFUN (no_set_aspath_exclude, "Exclude from the as-path\n" "AS number\n") { - int idx_asn = 4; - int ret; - char *str; + int idx_asn = 4; + int ret; + char *str; - str = argv_concat (argv, argc, idx_asn); - ret = generic_set_delete (vty, VTY_GET_CONTEXT(route_map_index), - "as-path exclude", str); - XFREE (MTYPE_TMP, str); - return ret; + str = argv_concat(argv, argc, idx_asn); + ret = generic_set_delete(vty, VTY_GET_CONTEXT(route_map_index), + "as-path exclude", str); + XFREE(MTYPE_TMP, str); + return ret; } @@ -3755,93 +3524,91 @@ DEFUN (set_community, "BGP community attribute\n" COMMUNITY_VAL_STR) { - int idx_aa_nn = 2; - int i; - int first = 0; - int additive = 0; - struct buffer *b; - struct community *com = NULL; - char *str; - char *argstr; - int ret; - - b = buffer_new (1024); - - for (i = idx_aa_nn; i < argc; i++) - { - if (strncmp (argv[i]->arg, "additive", strlen (argv[i]->arg)) == 0) - { - additive = 1; - continue; - } - - if (first) - buffer_putc (b, ' '); - else - first = 1; - - if (strncmp (argv[i]->arg, "internet", strlen (argv[i]->arg)) == 0) - { - buffer_putstr (b, "internet"); - continue; - } - if (strncmp (argv[i]->arg, "local-AS", strlen (argv[i]->arg)) == 0) - { - buffer_putstr (b, "local-AS"); - continue; - } - if (strncmp (argv[i]->arg, "no-a", strlen ("no-a")) == 0 - && strncmp (argv[i]->arg, "no-advertise", strlen (argv[i]->arg)) == 0) - { - buffer_putstr (b, "no-advertise"); - continue; - } - if (strncmp (argv[i]->arg, "no-e", strlen ("no-e"))== 0 - && strncmp (argv[i]->arg, "no-export", strlen (argv[i]->arg)) == 0) - { - buffer_putstr (b, "no-export"); - continue; - } - buffer_putstr (b, argv[i]->arg); - } - buffer_putc (b, '\0'); - - /* Fetch result string then compile it to communities attribute. */ - str = buffer_getstr (b); - buffer_free (b); - - if (str) - { - com = community_str2com (str); - XFREE (MTYPE_TMP, str); - } - - /* Can't compile user input into communities attribute. */ - if (! com) - { - vty_out (vty, "%% Malformed communities attribute%s", VTY_NEWLINE); - return CMD_WARNING; - } - - /* Set communites attribute string. */ - str = community_str (com); - - if (additive) - { - argstr = XCALLOC (MTYPE_TMP, strlen (str) + strlen (" additive") + 1); - strcpy (argstr, str); - strcpy (argstr + strlen (str), " additive"); - ret = generic_set_add (vty, VTY_GET_CONTEXT(route_map_index), - "community", argstr); - XFREE (MTYPE_TMP, argstr); - } - else - ret = generic_set_add (vty, VTY_GET_CONTEXT(route_map_index), - "community", str); - - community_free (com); - - return ret; + int idx_aa_nn = 2; + int i; + int first = 0; + int additive = 0; + struct buffer *b; + struct community *com = NULL; + char *str; + char *argstr; + int ret; + + b = buffer_new(1024); + + for (i = idx_aa_nn; i < argc; i++) { + if (strncmp(argv[i]->arg, "additive", strlen(argv[i]->arg)) + == 0) { + additive = 1; + continue; + } + + if (first) + buffer_putc(b, ' '); + else + first = 1; + + if (strncmp(argv[i]->arg, "internet", strlen(argv[i]->arg)) + == 0) { + buffer_putstr(b, "internet"); + continue; + } + if (strncmp(argv[i]->arg, "local-AS", strlen(argv[i]->arg)) + == 0) { + buffer_putstr(b, "local-AS"); + continue; + } + if (strncmp(argv[i]->arg, "no-a", strlen("no-a")) == 0 + && strncmp(argv[i]->arg, "no-advertise", + strlen(argv[i]->arg)) + == 0) { + buffer_putstr(b, "no-advertise"); + continue; + } + if (strncmp(argv[i]->arg, "no-e", strlen("no-e")) == 0 + && strncmp(argv[i]->arg, "no-export", strlen(argv[i]->arg)) + == 0) { + buffer_putstr(b, "no-export"); + continue; + } + buffer_putstr(b, argv[i]->arg); + } + buffer_putc(b, '\0'); + + /* Fetch result string then compile it to communities attribute. */ + str = buffer_getstr(b); + buffer_free(b); + + if (str) { + com = community_str2com(str); + XFREE(MTYPE_TMP, str); + } + + /* Can't compile user input into communities attribute. */ + if (!com) { + vty_out(vty, "%% Malformed communities attribute%s", + VTY_NEWLINE); + return CMD_WARNING; + } + + /* Set communites attribute string. */ + str = community_str(com); + + if (additive) { + argstr = XCALLOC(MTYPE_TMP, + strlen(str) + strlen(" additive") + 1); + strcpy(argstr, str); + strcpy(argstr + strlen(str), " additive"); + ret = generic_set_add(vty, VTY_GET_CONTEXT(route_map_index), + "community", argstr); + XFREE(MTYPE_TMP, argstr); + } else + ret = generic_set_add(vty, VTY_GET_CONTEXT(route_map_index), + "community", str); + + community_free(com); + + return ret; } DEFUN (set_community_none, @@ -3851,8 +3618,8 @@ DEFUN (set_community_none, "BGP community attribute\n" "No community attribute\n") { - return generic_set_add (vty, VTY_GET_CONTEXT(route_map_index), "community", - "none"); + return generic_set_add(vty, VTY_GET_CONTEXT(route_map_index), + "community", "none"); } DEFUN (no_set_community, @@ -3863,12 +3630,11 @@ DEFUN (no_set_community, "BGP community attribute\n" COMMUNITY_VAL_STR) { - return generic_set_delete (vty, VTY_GET_CONTEXT(route_map_index), - "community", NULL); + return generic_set_delete(vty, VTY_GET_CONTEXT(route_map_index), + "community", NULL); } - DEFUN (set_community_delete, set_community_delete_cmd, "set comm-list <(1-99)|(100-500)|WORD> delete", @@ -3879,17 +3645,19 @@ DEFUN (set_community_delete, "Community-list name\n" "Delete matching communities\n") { - int idx_comm_list = 2; - char *str; + int idx_comm_list = 2; + char *str; - str = XCALLOC (MTYPE_TMP, strlen (argv[idx_comm_list]->arg) + strlen (" delete") + 1); - strcpy (str, argv[idx_comm_list]->arg); - strcpy (str + strlen (argv[idx_comm_list]->arg), " delete"); + str = XCALLOC(MTYPE_TMP, + strlen(argv[idx_comm_list]->arg) + strlen(" delete") + 1); + strcpy(str, argv[idx_comm_list]->arg); + strcpy(str + strlen(argv[idx_comm_list]->arg), " delete"); - generic_set_add (vty, VTY_GET_CONTEXT(route_map_index), "comm-list", str); + generic_set_add(vty, VTY_GET_CONTEXT(route_map_index), "comm-list", + str); - XFREE (MTYPE_TMP, str); - return CMD_SUCCESS; + XFREE(MTYPE_TMP, str); + return CMD_SUCCESS; } DEFUN (no_set_community_delete, @@ -3903,8 +3671,8 @@ DEFUN (no_set_community_delete, "Community-list name\n" "Delete matching communities\n") { - return generic_set_delete (vty, VTY_GET_CONTEXT(route_map_index), - "comm-list", NULL); + return generic_set_delete(vty, VTY_GET_CONTEXT(route_map_index), + "comm-list", NULL); } DEFUN (set_lcommunity, @@ -3914,14 +3682,15 @@ DEFUN (set_lcommunity, "BGP large community attribute\n" "Large Community number in aa:bb:cc format or additive\n") { - int ret; - char *str; + int ret; + char *str; - str = argv_concat (argv, argc, 2); - ret = generic_set_add (vty, VTY_GET_CONTEXT(route_map_index), "large-community", str); - XFREE (MTYPE_TMP, str); + str = argv_concat(argv, argc, 2); + ret = generic_set_add(vty, VTY_GET_CONTEXT(route_map_index), + "large-community", str); + XFREE(MTYPE_TMP, str); - return ret; + return ret; } DEFUN (set_lcommunity_none, @@ -3931,8 +3700,8 @@ DEFUN (set_lcommunity_none, "BGP large community attribute\n" "No large community attribute\n") { - return generic_set_add (vty, VTY_GET_CONTEXT(route_map_index), - "large-community", "none"); + return generic_set_add(vty, VTY_GET_CONTEXT(route_map_index), + "large-community", "none"); } DEFUN (no_set_lcommunity, @@ -3943,8 +3712,8 @@ DEFUN (no_set_lcommunity, "BGP large community attribute\n" "No community attribute\n") { - return generic_set_delete (vty, VTY_GET_CONTEXT(route_map_index), - "large-community", NULL); + return generic_set_delete(vty, VTY_GET_CONTEXT(route_map_index), + "large-community", NULL); } DEFUN (no_set_lcommunity1, @@ -3955,8 +3724,8 @@ DEFUN (no_set_lcommunity1, "BGP large community attribute\n" "Large community in AA:BB:CC... format or additive\n") { - return generic_set_delete (vty, VTY_GET_CONTEXT(route_map_index), - "large-community", NULL); + return generic_set_delete(vty, VTY_GET_CONTEXT(route_map_index), + "large-community", NULL); } DEFUN (set_lcommunity_delete, @@ -3969,17 +3738,17 @@ DEFUN (set_lcommunity_delete, "Large Community-list name\n" "Delete matching large communities\n") { - char *str; + char *str; - str = XCALLOC (MTYPE_TMP, strlen (argv[2]->arg) + strlen (" delete") + 1); - strcpy (str, argv[2]->arg); - strcpy (str + strlen (argv[2]->arg), " delete"); + str = XCALLOC(MTYPE_TMP, strlen(argv[2]->arg) + strlen(" delete") + 1); + strcpy(str, argv[2]->arg); + strcpy(str + strlen(argv[2]->arg), " delete"); - generic_set_add (vty, VTY_GET_CONTEXT(route_map_index), - "large-comm-list", str); + generic_set_add(vty, VTY_GET_CONTEXT(route_map_index), + "large-comm-list", str); - XFREE (MTYPE_TMP, str); - return CMD_SUCCESS; + XFREE(MTYPE_TMP, str); + return CMD_SUCCESS; } DEFUN (no_set_lcommunity_delete, @@ -3993,8 +3762,8 @@ DEFUN (no_set_lcommunity_delete, "Large Community-list name\n" "Delete matching large communities\n") { - return generic_set_delete (vty, VTY_GET_CONTEXT(route_map_index), - "large-comm-list", NULL); + return generic_set_delete(vty, VTY_GET_CONTEXT(route_map_index), + "large-comm-list", NULL); } DEFUN (set_ecommunity_rt, @@ -4005,16 +3774,16 @@ DEFUN (set_ecommunity_rt, "Route Target extended community\n" "VPN extended community\n") { - int idx_asn_nn = 3; - int ret; - char *str; + int idx_asn_nn = 3; + int ret; + char *str; - str = argv_concat (argv, argc, idx_asn_nn); - ret = generic_set_add (vty, VTY_GET_CONTEXT(route_map_index), - "extcommunity rt", str); - XFREE (MTYPE_TMP, str); + str = argv_concat(argv, argc, idx_asn_nn); + ret = generic_set_add(vty, VTY_GET_CONTEXT(route_map_index), + "extcommunity rt", str); + XFREE(MTYPE_TMP, str); - return ret; + return ret; } DEFUN (no_set_ecommunity_rt, @@ -4026,8 +3795,8 @@ DEFUN (no_set_ecommunity_rt, "Route Target extended community\n" "VPN extended community\n") { - return generic_set_delete (vty, VTY_GET_CONTEXT(route_map_index), - "extcommunity rt", NULL); + return generic_set_delete(vty, VTY_GET_CONTEXT(route_map_index), + "extcommunity rt", NULL); } @@ -4039,15 +3808,15 @@ DEFUN (set_ecommunity_soo, "Site-of-Origin extended community\n" "VPN extended community\n") { - int idx_asn_nn = 3; - int ret; - char *str; + int idx_asn_nn = 3; + int ret; + char *str; - str = argv_concat (argv, argc, idx_asn_nn); - ret = generic_set_add (vty, VTY_GET_CONTEXT(route_map_index), - "extcommunity soo", str); - XFREE (MTYPE_TMP, str); - return ret; + str = argv_concat(argv, argc, idx_asn_nn); + ret = generic_set_add(vty, VTY_GET_CONTEXT(route_map_index), + "extcommunity soo", str); + XFREE(MTYPE_TMP, str); + return ret; } @@ -4060,8 +3829,8 @@ DEFUN (no_set_ecommunity_soo, "Site-of-Origin extended community\n" "VPN extended community\n") { - return generic_set_delete (vty, VTY_GET_CONTEXT(route_map_index), - "extcommunity soo", NULL); + return generic_set_delete(vty, VTY_GET_CONTEXT(route_map_index), + "extcommunity soo", NULL); } @@ -4074,18 +3843,18 @@ DEFUN (set_origin, "local IGP\n" "unknown heritage\n") { - int idx_origin = 2; - if (strncmp (argv[idx_origin]->arg, "igp", 2) == 0) - return generic_set_add (vty, VTY_GET_CONTEXT(route_map_index), "origin", - "igp"); - if (strncmp (argv[idx_origin]->arg, "egp", 1) == 0) - return generic_set_add (vty, VTY_GET_CONTEXT(route_map_index), "origin", - "egp"); - if (strncmp (argv[idx_origin]->arg, "incomplete", 2) == 0) - return generic_set_add (vty, VTY_GET_CONTEXT(route_map_index), "origin", - "incomplete"); + int idx_origin = 2; + if (strncmp(argv[idx_origin]->arg, "igp", 2) == 0) + return generic_set_add(vty, VTY_GET_CONTEXT(route_map_index), + "origin", "igp"); + if (strncmp(argv[idx_origin]->arg, "egp", 1) == 0) + return generic_set_add(vty, VTY_GET_CONTEXT(route_map_index), + "origin", "egp"); + if (strncmp(argv[idx_origin]->arg, "incomplete", 2) == 0) + return generic_set_add(vty, VTY_GET_CONTEXT(route_map_index), + "origin", "incomplete"); - return CMD_WARNING; + return CMD_WARNING; } @@ -4099,8 +3868,8 @@ DEFUN (no_set_origin, "local IGP\n" "unknown heritage\n") { - return generic_set_delete (vty, VTY_GET_CONTEXT(route_map_index), "origin", - NULL); + return generic_set_delete(vty, VTY_GET_CONTEXT(route_map_index), + "origin", NULL); } @@ -4110,8 +3879,8 @@ DEFUN (set_atomic_aggregate, SET_STR "BGP atomic aggregate attribute\n" ) { - return generic_set_add (vty, VTY_GET_CONTEXT(route_map_index), - "atomic-aggregate", NULL); + return generic_set_add(vty, VTY_GET_CONTEXT(route_map_index), + "atomic-aggregate", NULL); } DEFUN (no_set_atomic_aggregate, @@ -4121,8 +3890,8 @@ DEFUN (no_set_atomic_aggregate, SET_STR "BGP atomic aggregate attribute\n" ) { - return generic_set_delete (vty, VTY_GET_CONTEXT(route_map_index), - "atomic-aggregate", NULL); + return generic_set_delete(vty, VTY_GET_CONTEXT(route_map_index), + "atomic-aggregate", NULL); } DEFUN (set_aggregator_as, @@ -4134,30 +3903,30 @@ DEFUN (set_aggregator_as, "AS number\n" "IP address of aggregator\n") { - int idx_number = 3; - int idx_ipv4 = 4; - int ret; - struct in_addr address; - char *argstr; + int idx_number = 3; + int idx_ipv4 = 4; + int ret; + struct in_addr address; + char *argstr; - ret = inet_aton (argv[idx_ipv4]->arg, &address); - if (ret == 0) - { - vty_out (vty, "Aggregator IP address is invalid%s", VTY_NEWLINE); - return CMD_WARNING; - } + ret = inet_aton(argv[idx_ipv4]->arg, &address); + if (ret == 0) { + vty_out(vty, "Aggregator IP address is invalid%s", VTY_NEWLINE); + return CMD_WARNING; + } - argstr = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, - strlen (argv[idx_number]->arg) + strlen (argv[idx_ipv4]->arg) + 2); + argstr = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, + strlen(argv[idx_number]->arg) + + strlen(argv[idx_ipv4]->arg) + 2); - sprintf (argstr, "%s %s", argv[idx_number]->arg, argv[idx_ipv4]->arg); + sprintf(argstr, "%s %s", argv[idx_number]->arg, argv[idx_ipv4]->arg); - ret = generic_set_add (vty, VTY_GET_CONTEXT(route_map_index), - "aggregator as", argstr); + ret = generic_set_add(vty, VTY_GET_CONTEXT(route_map_index), + "aggregator as", argstr); - XFREE (MTYPE_ROUTE_MAP_COMPILED, argstr); + XFREE(MTYPE_ROUTE_MAP_COMPILED, argstr); - return ret; + return ret; } @@ -4171,34 +3940,34 @@ DEFUN (no_set_aggregator_as, "AS number\n" "IP address of aggregator\n") { - int idx_asn = 4; - int idx_ip = 5; - int ret; - struct in_addr address; - char *argstr; + int idx_asn = 4; + int idx_ip = 5; + int ret; + struct in_addr address; + char *argstr; - if (argc <= idx_asn) - return generic_set_delete (vty, VTY_GET_CONTEXT(route_map_index), - "aggregator as", NULL); + if (argc <= idx_asn) + return generic_set_delete(vty, VTY_GET_CONTEXT(route_map_index), + "aggregator as", NULL); - ret = inet_aton (argv[idx_ip]->arg, &address); - if (ret == 0) - { - vty_out (vty, "Aggregator IP address is invalid%s", VTY_NEWLINE); - return CMD_WARNING; - } + ret = inet_aton(argv[idx_ip]->arg, &address); + if (ret == 0) { + vty_out(vty, "Aggregator IP address is invalid%s", VTY_NEWLINE); + return CMD_WARNING; + } - argstr = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, - strlen (argv[idx_asn]->arg) + strlen (argv[idx_ip]->arg) + 2); + argstr = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, + strlen(argv[idx_asn]->arg) + strlen(argv[idx_ip]->arg) + + 2); - sprintf (argstr, "%s %s", argv[idx_asn]->arg, argv[idx_ip]->arg); + sprintf(argstr, "%s %s", argv[idx_asn]->arg, argv[idx_ip]->arg); - ret = generic_set_delete (vty, VTY_GET_CONTEXT(route_map_index), - "aggregator as", argstr); + ret = generic_set_delete(vty, VTY_GET_CONTEXT(route_map_index), + "aggregator as", argstr); - XFREE (MTYPE_ROUTE_MAP_COMPILED, argstr); + XFREE(MTYPE_ROUTE_MAP_COMPILED, argstr); - return ret; + return ret; } DEFUN (match_ipv6_next_hop, @@ -4209,9 +3978,9 @@ DEFUN (match_ipv6_next_hop, "Match IPv6 next-hop address of route\n" "IPv6 address of next hop\n") { - int idx_ipv6 = 3; - return bgp_route_match_add (vty, "ipv6 next-hop", argv[idx_ipv6]->arg, - RMAP_EVENT_MATCH_ADDED); + int idx_ipv6 = 3; + return bgp_route_match_add(vty, "ipv6 next-hop", argv[idx_ipv6]->arg, + RMAP_EVENT_MATCH_ADDED); } DEFUN (no_match_ipv6_next_hop, @@ -4223,9 +3992,9 @@ DEFUN (no_match_ipv6_next_hop, "Match IPv6 next-hop address of route\n" "IPv6 address of next hop\n") { - int idx_ipv6 = 4; - return bgp_route_match_delete (vty, "ipv6 next-hop", argv[idx_ipv6]->arg, - RMAP_EVENT_MATCH_DELETED); + int idx_ipv6 = 4; + return bgp_route_match_delete(vty, "ipv6 next-hop", argv[idx_ipv6]->arg, + RMAP_EVENT_MATCH_DELETED); } @@ -4237,8 +4006,8 @@ DEFUN (set_ipv6_nexthop_peer, "Next hop address\n" "Use peer address (for BGP only)\n") { - return generic_set_add (vty, VTY_GET_CONTEXT(route_map_index), - "ipv6 next-hop peer-address", NULL); + return generic_set_add(vty, VTY_GET_CONTEXT(route_map_index), + "ipv6 next-hop peer-address", NULL); } DEFUN (no_set_ipv6_nexthop_peer, @@ -4250,8 +4019,8 @@ DEFUN (no_set_ipv6_nexthop_peer, "IPv6 next-hop address\n" "Use peer address (for BGP only)\n") { - return generic_set_delete (vty, VTY_GET_CONTEXT(route_map_index), - "ipv6 next-hop peer-address", NULL); + return generic_set_delete(vty, VTY_GET_CONTEXT(route_map_index), + "ipv6 next-hop peer-address", NULL); } DEFUN (set_ipv6_nexthop_prefer_global, @@ -4262,8 +4031,9 @@ DEFUN (set_ipv6_nexthop_prefer_global, "IPv6 next-hop address\n" "Prefer global over link-local if both exist\n") { - return generic_set_add (vty, VTY_GET_CONTEXT(route_map_index), - "ipv6 next-hop prefer-global", NULL);; + return generic_set_add(vty, VTY_GET_CONTEXT(route_map_index), + "ipv6 next-hop prefer-global", NULL); + ; } DEFUN (no_set_ipv6_nexthop_prefer_global, @@ -4275,8 +4045,8 @@ DEFUN (no_set_ipv6_nexthop_prefer_global, "IPv6 next-hop address\n" "Prefer global over link-local if both exist\n") { - return generic_set_delete (vty, VTY_GET_CONTEXT(route_map_index), - "ipv6 next-hop prefer-global", NULL); + return generic_set_delete(vty, VTY_GET_CONTEXT(route_map_index), + "ipv6 next-hop prefer-global", NULL); } DEFUN (set_ipv6_nexthop_global, @@ -4288,27 +4058,24 @@ DEFUN (set_ipv6_nexthop_global, "IPv6 global address\n" "IPv6 address of next hop\n") { - int idx_ipv6 = 4; - struct in6_addr addr; - int ret; + int idx_ipv6 = 4; + struct in6_addr addr; + int ret; - ret = inet_pton (AF_INET6, argv[idx_ipv6]->arg, &addr); - if (!ret) - { - vty_out (vty, "%% Malformed nexthop address%s", VTY_NEWLINE); - return CMD_WARNING; - } - if (IN6_IS_ADDR_UNSPECIFIED(&addr) || - IN6_IS_ADDR_LOOPBACK(&addr) || - IN6_IS_ADDR_MULTICAST(&addr) || - IN6_IS_ADDR_LINKLOCAL(&addr)) - { - vty_out (vty, "%% Invalid global nexthop address%s", VTY_NEWLINE); - return CMD_WARNING; - } + ret = inet_pton(AF_INET6, argv[idx_ipv6]->arg, &addr); + if (!ret) { + vty_out(vty, "%% Malformed nexthop address%s", VTY_NEWLINE); + return CMD_WARNING; + } + if (IN6_IS_ADDR_UNSPECIFIED(&addr) || IN6_IS_ADDR_LOOPBACK(&addr) + || IN6_IS_ADDR_MULTICAST(&addr) || IN6_IS_ADDR_LINKLOCAL(&addr)) { + vty_out(vty, "%% Invalid global nexthop address%s", + VTY_NEWLINE); + return CMD_WARNING; + } - return generic_set_add (vty, VTY_GET_CONTEXT(route_map_index), - "ipv6 next-hop global", argv[idx_ipv6]->arg); + return generic_set_add(vty, VTY_GET_CONTEXT(route_map_index), + "ipv6 next-hop global", argv[idx_ipv6]->arg); } @@ -4322,12 +4089,12 @@ DEFUN (no_set_ipv6_nexthop_global, "IPv6 global address\n" "IPv6 address of next hop\n") { - int idx_ipv6 = 5; - if (argc <= idx_ipv6) - return generic_set_delete (vty, VTY_GET_CONTEXT(route_map_index), - "ipv6 next-hop global", NULL); - return generic_set_delete (vty, VTY_GET_CONTEXT(route_map_index), - "ipv6 next-hop global", argv[idx_ipv6]->arg); + int idx_ipv6 = 5; + if (argc <= idx_ipv6) + return generic_set_delete(vty, VTY_GET_CONTEXT(route_map_index), + "ipv6 next-hop global", NULL); + return generic_set_delete(vty, VTY_GET_CONTEXT(route_map_index), + "ipv6 next-hop global", argv[idx_ipv6]->arg); } #ifdef KEEP_OLD_VPN_COMMANDS @@ -4341,20 +4108,21 @@ DEFUN (set_vpn_nexthop, "IP address of next hop\n" "IPv6 address of next hop\n") { - int idx_ip = 3; - afi_t afi; - int idx = 0; - - if (argv_find_and_parse_vpnvx (argv, argc, &idx, &afi)) - { - if (afi == AFI_IP) - return generic_set_add (vty, VTY_GET_CONTEXT(route_map_index), - "ip vpn next-hop", argv[idx_ip]->arg); - else - return generic_set_add (vty, VTY_GET_CONTEXT(route_map_index), - "ipv6 vpn next-hop", argv[idx_ip]->arg); - } - return CMD_SUCCESS; + int idx_ip = 3; + afi_t afi; + int idx = 0; + + if (argv_find_and_parse_vpnvx(argv, argc, &idx, &afi)) { + if (afi == AFI_IP) + return generic_set_add( + vty, VTY_GET_CONTEXT(route_map_index), + "ip vpn next-hop", argv[idx_ip]->arg); + else + return generic_set_add( + vty, VTY_GET_CONTEXT(route_map_index), + "ipv6 vpn next-hop", argv[idx_ip]->arg); + } + return CMD_SUCCESS; } DEFUN (no_set_vpn_nexthop, @@ -4367,25 +4135,26 @@ DEFUN (no_set_vpn_nexthop, "IP address of next hop\n" "IPv6 address of next hop\n") { - int idx_ip = 4; - char *arg; - afi_t afi; - int idx = 0; - - if (argc <= idx_ip) - arg = NULL; - else - arg = argv[idx_ip]->arg; - if (argv_find_and_parse_vpnvx (argv, argc, &idx, &afi)) - { - if (afi == AFI_IP) - return generic_set_delete (vty, VTY_GET_CONTEXT(route_map_index), - "ip vpn next-hop", arg); - else - return generic_set_delete (vty, VTY_GET_CONTEXT(route_map_index), - "ipv6 vpn next-hop", argv[idx_ip]->arg); - } - return CMD_SUCCESS; + int idx_ip = 4; + char *arg; + afi_t afi; + int idx = 0; + + if (argc <= idx_ip) + arg = NULL; + else + arg = argv[idx_ip]->arg; + if (argv_find_and_parse_vpnvx(argv, argc, &idx, &afi)) { + if (afi == AFI_IP) + return generic_set_delete( + vty, VTY_GET_CONTEXT(route_map_index), + "ip vpn next-hop", arg); + else + return generic_set_delete( + vty, VTY_GET_CONTEXT(route_map_index), + "ipv6 vpn next-hop", argv[idx_ip]->arg); + } + return CMD_SUCCESS; } #endif /* KEEP_OLD_VPN_COMMANDS */ @@ -4400,20 +4169,21 @@ DEFUN (set_ipx_vpn_nexthop, "IP address of next hop\n" "IPv6 address of next hop\n") { - int idx_ip = 4; - afi_t afi; - int idx = 0; - - if (argv_find_and_parse_afi (argv, argc, &idx, &afi)) - { - if (afi == AFI_IP) - return generic_set_add (vty, VTY_GET_CONTEXT(route_map_index), - "ip vpn next-hop", argv[idx_ip]->arg); - else - return generic_set_add (vty, VTY_GET_CONTEXT(route_map_index), - "ipv6 vpn next-hop", argv[idx_ip]->arg); - } - return CMD_SUCCESS; + int idx_ip = 4; + afi_t afi; + int idx = 0; + + if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) { + if (afi == AFI_IP) + return generic_set_add( + vty, VTY_GET_CONTEXT(route_map_index), + "ip vpn next-hop", argv[idx_ip]->arg); + else + return generic_set_add( + vty, VTY_GET_CONTEXT(route_map_index), + "ipv6 vpn next-hop", argv[idx_ip]->arg); + } + return CMD_SUCCESS; } DEFUN (no_set_ipx_vpn_nexthop, @@ -4428,25 +4198,26 @@ DEFUN (no_set_ipx_vpn_nexthop, "IP address of next hop\n" "IPv6 address of next hop\n") { - int idx_ip = 5; - char *arg; - afi_t afi; - int idx = 0; - - if (argc <= idx_ip) - arg = NULL; - else - arg = argv[idx_ip]->arg; - if (argv_find_and_parse_afi (argv, argc, &idx, &afi)) - { - if (afi == AFI_IP) - return generic_set_delete (vty, VTY_GET_CONTEXT(route_map_index), - "ip vpn next-hop", arg); - else - return generic_set_delete (vty, VTY_GET_CONTEXT(route_map_index), - "ipv6 vpn next-hop", arg); - } - return CMD_SUCCESS; + int idx_ip = 5; + char *arg; + afi_t afi; + int idx = 0; + + if (argc <= idx_ip) + arg = NULL; + else + arg = argv[idx_ip]->arg; + if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) { + if (afi == AFI_IP) + return generic_set_delete( + vty, VTY_GET_CONTEXT(route_map_index), + "ip vpn next-hop", arg); + else + return generic_set_delete( + vty, VTY_GET_CONTEXT(route_map_index), + "ipv6 vpn next-hop", arg); + } + return CMD_SUCCESS; } DEFUN (set_originator_id, @@ -4456,9 +4227,9 @@ DEFUN (set_originator_id, "BGP originator ID attribute\n" "IP address of originator\n") { - int idx_ipv4 = 2; - return generic_set_add (vty, VTY_GET_CONTEXT(route_map_index), - "originator-id", argv[idx_ipv4]->arg); + int idx_ipv4 = 2; + return generic_set_add(vty, VTY_GET_CONTEXT(route_map_index), + "originator-id", argv[idx_ipv4]->arg); } @@ -4470,192 +4241,190 @@ DEFUN (no_set_originator_id, "BGP originator ID attribute\n" "IP address of originator\n") { - int idx = 0; - char *arg = argv_find (argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL; + int idx = 0; + char *arg = + argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL; - return generic_set_delete (vty, VTY_GET_CONTEXT(route_map_index), - "originator-id", arg); + return generic_set_delete(vty, VTY_GET_CONTEXT(route_map_index), + "originator-id", arg); } /* Initialization of route map. */ -void -bgp_route_map_init (void) -{ - route_map_init (); - - route_map_add_hook (bgp_route_map_add); - route_map_delete_hook (bgp_route_map_delete); - route_map_event_hook (bgp_route_map_event); - - route_map_match_interface_hook (generic_match_add); - route_map_no_match_interface_hook (generic_match_delete); - - route_map_match_ip_address_hook (generic_match_add); - route_map_no_match_ip_address_hook (generic_match_delete); - - route_map_match_ip_address_prefix_list_hook (generic_match_add); - route_map_no_match_ip_address_prefix_list_hook (generic_match_delete); - - route_map_match_ip_next_hop_hook (generic_match_add); - route_map_no_match_ip_next_hop_hook (generic_match_delete); - - route_map_match_ip_next_hop_prefix_list_hook (generic_match_add); - route_map_no_match_ip_next_hop_prefix_list_hook (generic_match_delete); - - route_map_match_ipv6_address_hook (generic_match_add); - route_map_no_match_ipv6_address_hook (generic_match_delete); - - route_map_match_ipv6_address_prefix_list_hook (generic_match_add); - route_map_no_match_ipv6_address_prefix_list_hook (generic_match_delete); - - route_map_match_metric_hook (generic_match_add); - route_map_no_match_metric_hook (generic_match_delete); - - route_map_match_tag_hook (generic_match_add); - route_map_no_match_tag_hook (generic_match_delete); - - route_map_set_ip_nexthop_hook (generic_set_add); - route_map_no_set_ip_nexthop_hook (generic_set_delete); - - route_map_set_ipv6_nexthop_local_hook (generic_set_add); - route_map_no_set_ipv6_nexthop_local_hook (generic_set_delete); - - route_map_set_metric_hook (generic_set_add); - route_map_no_set_metric_hook (generic_set_delete); - - route_map_set_tag_hook (generic_set_add); - route_map_no_set_tag_hook (generic_set_delete); - - route_map_install_match (&route_match_peer_cmd); - route_map_install_match (&route_match_local_pref_cmd); - route_map_install_match (&route_match_ip_address_cmd); - route_map_install_match (&route_match_ip_next_hop_cmd); - route_map_install_match (&route_match_ip_route_source_cmd); - route_map_install_match (&route_match_ip_address_prefix_list_cmd); - route_map_install_match (&route_match_ip_next_hop_prefix_list_cmd); - route_map_install_match (&route_match_ip_route_source_prefix_list_cmd); - route_map_install_match (&route_match_aspath_cmd); - route_map_install_match (&route_match_community_cmd); - route_map_install_match (&route_match_lcommunity_cmd); - route_map_install_match (&route_match_ecommunity_cmd); - route_map_install_match (&route_match_local_pref_cmd); - route_map_install_match (&route_match_metric_cmd); - route_map_install_match (&route_match_origin_cmd); - route_map_install_match (&route_match_probability_cmd); - route_map_install_match (&route_match_interface_cmd); - route_map_install_match (&route_match_tag_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_weight_cmd); - route_map_install_set (&route_set_metric_cmd); - route_map_install_set (&route_set_aspath_prepend_cmd); - route_map_install_set (&route_set_aspath_exclude_cmd); - route_map_install_set (&route_set_origin_cmd); - route_map_install_set (&route_set_atomic_aggregate_cmd); - route_map_install_set (&route_set_aggregator_as_cmd); - route_map_install_set (&route_set_community_cmd); - route_map_install_set (&route_set_community_delete_cmd); - route_map_install_set (&route_set_lcommunity_cmd); - route_map_install_set (&route_set_lcommunity_delete_cmd); - route_map_install_set (&route_set_vpnv4_nexthop_cmd); - route_map_install_set (&route_set_vpnv6_nexthop_cmd); - route_map_install_set (&route_set_originator_id_cmd); - route_map_install_set (&route_set_ecommunity_rt_cmd); - route_map_install_set (&route_set_ecommunity_soo_cmd); - route_map_install_set (&route_set_tag_cmd); - - install_element (RMAP_NODE, &match_peer_cmd); - install_element (RMAP_NODE, &match_peer_local_cmd); - install_element (RMAP_NODE, &no_match_peer_cmd); - install_element (RMAP_NODE, &match_ip_route_source_cmd); - install_element (RMAP_NODE, &no_match_ip_route_source_cmd); - install_element (RMAP_NODE, &match_ip_route_source_prefix_list_cmd); - install_element (RMAP_NODE, &no_match_ip_route_source_prefix_list_cmd); - - install_element (RMAP_NODE, &match_aspath_cmd); - install_element (RMAP_NODE, &no_match_aspath_cmd); - install_element (RMAP_NODE, &match_local_pref_cmd); - install_element (RMAP_NODE, &no_match_local_pref_cmd); - install_element (RMAP_NODE, &match_community_cmd); - install_element (RMAP_NODE, &no_match_community_cmd); - install_element (RMAP_NODE, &match_lcommunity_cmd); - install_element (RMAP_NODE, &no_match_lcommunity_cmd); - install_element (RMAP_NODE, &match_ecommunity_cmd); - install_element (RMAP_NODE, &no_match_ecommunity_cmd); - install_element (RMAP_NODE, &match_origin_cmd); - install_element (RMAP_NODE, &no_match_origin_cmd); - install_element (RMAP_NODE, &match_probability_cmd); - install_element (RMAP_NODE, &no_match_probability_cmd); - - install_element (RMAP_NODE, &set_ip_nexthop_peer_cmd); - install_element (RMAP_NODE, &set_ip_nexthop_unchanged_cmd); - install_element (RMAP_NODE, &set_local_pref_cmd); - install_element (RMAP_NODE, &no_set_local_pref_cmd); - install_element (RMAP_NODE, &set_weight_cmd); - install_element (RMAP_NODE, &no_set_weight_cmd); - install_element (RMAP_NODE, &set_aspath_prepend_asn_cmd); - install_element (RMAP_NODE, &set_aspath_prepend_lastas_cmd); - install_element (RMAP_NODE, &set_aspath_exclude_cmd); - install_element (RMAP_NODE, &no_set_aspath_prepend_cmd); - install_element (RMAP_NODE, &no_set_aspath_exclude_cmd); - install_element (RMAP_NODE, &set_origin_cmd); - install_element (RMAP_NODE, &no_set_origin_cmd); - install_element (RMAP_NODE, &set_atomic_aggregate_cmd); - install_element (RMAP_NODE, &no_set_atomic_aggregate_cmd); - install_element (RMAP_NODE, &set_aggregator_as_cmd); - install_element (RMAP_NODE, &no_set_aggregator_as_cmd); - install_element (RMAP_NODE, &set_community_cmd); - install_element (RMAP_NODE, &set_community_none_cmd); - install_element (RMAP_NODE, &no_set_community_cmd); - install_element (RMAP_NODE, &set_community_delete_cmd); - install_element (RMAP_NODE, &no_set_community_delete_cmd); - install_element (RMAP_NODE, &set_lcommunity_cmd); - install_element (RMAP_NODE, &set_lcommunity_none_cmd); - install_element (RMAP_NODE, &no_set_lcommunity_cmd); - install_element (RMAP_NODE, &no_set_lcommunity1_cmd); - install_element (RMAP_NODE, &set_lcommunity_delete_cmd); - install_element (RMAP_NODE, &no_set_lcommunity_delete_cmd); - install_element (RMAP_NODE, &set_ecommunity_rt_cmd); - install_element (RMAP_NODE, &no_set_ecommunity_rt_cmd); - install_element (RMAP_NODE, &set_ecommunity_soo_cmd); - install_element (RMAP_NODE, &no_set_ecommunity_soo_cmd); +void bgp_route_map_init(void) +{ + route_map_init(); + + route_map_add_hook(bgp_route_map_add); + route_map_delete_hook(bgp_route_map_delete); + route_map_event_hook(bgp_route_map_event); + + route_map_match_interface_hook(generic_match_add); + route_map_no_match_interface_hook(generic_match_delete); + + route_map_match_ip_address_hook(generic_match_add); + route_map_no_match_ip_address_hook(generic_match_delete); + + route_map_match_ip_address_prefix_list_hook(generic_match_add); + route_map_no_match_ip_address_prefix_list_hook(generic_match_delete); + + route_map_match_ip_next_hop_hook(generic_match_add); + route_map_no_match_ip_next_hop_hook(generic_match_delete); + + route_map_match_ip_next_hop_prefix_list_hook(generic_match_add); + route_map_no_match_ip_next_hop_prefix_list_hook(generic_match_delete); + + route_map_match_ipv6_address_hook(generic_match_add); + route_map_no_match_ipv6_address_hook(generic_match_delete); + + route_map_match_ipv6_address_prefix_list_hook(generic_match_add); + route_map_no_match_ipv6_address_prefix_list_hook(generic_match_delete); + + route_map_match_metric_hook(generic_match_add); + route_map_no_match_metric_hook(generic_match_delete); + + route_map_match_tag_hook(generic_match_add); + route_map_no_match_tag_hook(generic_match_delete); + + route_map_set_ip_nexthop_hook(generic_set_add); + route_map_no_set_ip_nexthop_hook(generic_set_delete); + + route_map_set_ipv6_nexthop_local_hook(generic_set_add); + route_map_no_set_ipv6_nexthop_local_hook(generic_set_delete); + + route_map_set_metric_hook(generic_set_add); + route_map_no_set_metric_hook(generic_set_delete); + + route_map_set_tag_hook(generic_set_add); + route_map_no_set_tag_hook(generic_set_delete); + + route_map_install_match(&route_match_peer_cmd); + route_map_install_match(&route_match_local_pref_cmd); + route_map_install_match(&route_match_ip_address_cmd); + route_map_install_match(&route_match_ip_next_hop_cmd); + route_map_install_match(&route_match_ip_route_source_cmd); + route_map_install_match(&route_match_ip_address_prefix_list_cmd); + route_map_install_match(&route_match_ip_next_hop_prefix_list_cmd); + route_map_install_match(&route_match_ip_route_source_prefix_list_cmd); + route_map_install_match(&route_match_aspath_cmd); + route_map_install_match(&route_match_community_cmd); + route_map_install_match(&route_match_lcommunity_cmd); + route_map_install_match(&route_match_ecommunity_cmd); + route_map_install_match(&route_match_local_pref_cmd); + route_map_install_match(&route_match_metric_cmd); + route_map_install_match(&route_match_origin_cmd); + route_map_install_match(&route_match_probability_cmd); + route_map_install_match(&route_match_interface_cmd); + route_map_install_match(&route_match_tag_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_weight_cmd); + route_map_install_set(&route_set_metric_cmd); + route_map_install_set(&route_set_aspath_prepend_cmd); + route_map_install_set(&route_set_aspath_exclude_cmd); + route_map_install_set(&route_set_origin_cmd); + route_map_install_set(&route_set_atomic_aggregate_cmd); + route_map_install_set(&route_set_aggregator_as_cmd); + route_map_install_set(&route_set_community_cmd); + route_map_install_set(&route_set_community_delete_cmd); + route_map_install_set(&route_set_lcommunity_cmd); + route_map_install_set(&route_set_lcommunity_delete_cmd); + route_map_install_set(&route_set_vpnv4_nexthop_cmd); + route_map_install_set(&route_set_vpnv6_nexthop_cmd); + route_map_install_set(&route_set_originator_id_cmd); + route_map_install_set(&route_set_ecommunity_rt_cmd); + route_map_install_set(&route_set_ecommunity_soo_cmd); + route_map_install_set(&route_set_tag_cmd); + + install_element(RMAP_NODE, &match_peer_cmd); + install_element(RMAP_NODE, &match_peer_local_cmd); + install_element(RMAP_NODE, &no_match_peer_cmd); + install_element(RMAP_NODE, &match_ip_route_source_cmd); + install_element(RMAP_NODE, &no_match_ip_route_source_cmd); + install_element(RMAP_NODE, &match_ip_route_source_prefix_list_cmd); + install_element(RMAP_NODE, &no_match_ip_route_source_prefix_list_cmd); + + install_element(RMAP_NODE, &match_aspath_cmd); + install_element(RMAP_NODE, &no_match_aspath_cmd); + install_element(RMAP_NODE, &match_local_pref_cmd); + install_element(RMAP_NODE, &no_match_local_pref_cmd); + install_element(RMAP_NODE, &match_community_cmd); + install_element(RMAP_NODE, &no_match_community_cmd); + install_element(RMAP_NODE, &match_lcommunity_cmd); + install_element(RMAP_NODE, &no_match_lcommunity_cmd); + install_element(RMAP_NODE, &match_ecommunity_cmd); + install_element(RMAP_NODE, &no_match_ecommunity_cmd); + install_element(RMAP_NODE, &match_origin_cmd); + install_element(RMAP_NODE, &no_match_origin_cmd); + install_element(RMAP_NODE, &match_probability_cmd); + install_element(RMAP_NODE, &no_match_probability_cmd); + + install_element(RMAP_NODE, &set_ip_nexthop_peer_cmd); + install_element(RMAP_NODE, &set_ip_nexthop_unchanged_cmd); + install_element(RMAP_NODE, &set_local_pref_cmd); + install_element(RMAP_NODE, &no_set_local_pref_cmd); + install_element(RMAP_NODE, &set_weight_cmd); + install_element(RMAP_NODE, &no_set_weight_cmd); + install_element(RMAP_NODE, &set_aspath_prepend_asn_cmd); + install_element(RMAP_NODE, &set_aspath_prepend_lastas_cmd); + install_element(RMAP_NODE, &set_aspath_exclude_cmd); + install_element(RMAP_NODE, &no_set_aspath_prepend_cmd); + install_element(RMAP_NODE, &no_set_aspath_exclude_cmd); + install_element(RMAP_NODE, &set_origin_cmd); + install_element(RMAP_NODE, &no_set_origin_cmd); + install_element(RMAP_NODE, &set_atomic_aggregate_cmd); + install_element(RMAP_NODE, &no_set_atomic_aggregate_cmd); + install_element(RMAP_NODE, &set_aggregator_as_cmd); + install_element(RMAP_NODE, &no_set_aggregator_as_cmd); + install_element(RMAP_NODE, &set_community_cmd); + install_element(RMAP_NODE, &set_community_none_cmd); + install_element(RMAP_NODE, &no_set_community_cmd); + install_element(RMAP_NODE, &set_community_delete_cmd); + install_element(RMAP_NODE, &no_set_community_delete_cmd); + install_element(RMAP_NODE, &set_lcommunity_cmd); + install_element(RMAP_NODE, &set_lcommunity_none_cmd); + install_element(RMAP_NODE, &no_set_lcommunity_cmd); + install_element(RMAP_NODE, &no_set_lcommunity1_cmd); + install_element(RMAP_NODE, &set_lcommunity_delete_cmd); + install_element(RMAP_NODE, &no_set_lcommunity_delete_cmd); + install_element(RMAP_NODE, &set_ecommunity_rt_cmd); + install_element(RMAP_NODE, &no_set_ecommunity_rt_cmd); + install_element(RMAP_NODE, &set_ecommunity_soo_cmd); + install_element(RMAP_NODE, &no_set_ecommunity_soo_cmd); #ifdef KEEP_OLD_VPN_COMMANDS - install_element (RMAP_NODE, &set_vpn_nexthop_cmd); - install_element (RMAP_NODE, &no_set_vpn_nexthop_cmd); + install_element(RMAP_NODE, &set_vpn_nexthop_cmd); + install_element(RMAP_NODE, &no_set_vpn_nexthop_cmd); #endif /* KEEP_OLD_VPN_COMMANDS */ - install_element (RMAP_NODE, &set_ipx_vpn_nexthop_cmd); - install_element (RMAP_NODE, &no_set_ipx_vpn_nexthop_cmd); - install_element (RMAP_NODE, &set_originator_id_cmd); - install_element (RMAP_NODE, &no_set_originator_id_cmd); - - route_map_install_match (&route_match_ipv6_address_cmd); - route_map_install_match (&route_match_ipv6_next_hop_cmd); - route_map_install_match (&route_match_ipv6_address_prefix_list_cmd); - route_map_install_set (&route_set_ipv6_nexthop_global_cmd); - route_map_install_set (&route_set_ipv6_nexthop_prefer_global_cmd); - route_map_install_set (&route_set_ipv6_nexthop_local_cmd); - route_map_install_set (&route_set_ipv6_nexthop_peer_cmd); - - install_element (RMAP_NODE, &match_ipv6_next_hop_cmd); - install_element (RMAP_NODE, &no_match_ipv6_next_hop_cmd); - install_element (RMAP_NODE, &set_ipv6_nexthop_global_cmd); - install_element (RMAP_NODE, &no_set_ipv6_nexthop_global_cmd); - install_element (RMAP_NODE, &set_ipv6_nexthop_prefer_global_cmd); - install_element (RMAP_NODE, &no_set_ipv6_nexthop_prefer_global_cmd); - install_element (RMAP_NODE, &set_ipv6_nexthop_peer_cmd); - install_element (RMAP_NODE, &no_set_ipv6_nexthop_peer_cmd); -} - -void -bgp_route_map_terminate (void) -{ - /* ToDo: Cleanup all the used memory */ - - route_map_add_hook (NULL); - route_map_delete_hook (NULL); - route_map_event_hook (NULL); - route_map_finish(); - + install_element(RMAP_NODE, &set_ipx_vpn_nexthop_cmd); + install_element(RMAP_NODE, &no_set_ipx_vpn_nexthop_cmd); + install_element(RMAP_NODE, &set_originator_id_cmd); + install_element(RMAP_NODE, &no_set_originator_id_cmd); + + route_map_install_match(&route_match_ipv6_address_cmd); + route_map_install_match(&route_match_ipv6_next_hop_cmd); + route_map_install_match(&route_match_ipv6_address_prefix_list_cmd); + route_map_install_set(&route_set_ipv6_nexthop_global_cmd); + route_map_install_set(&route_set_ipv6_nexthop_prefer_global_cmd); + route_map_install_set(&route_set_ipv6_nexthop_local_cmd); + route_map_install_set(&route_set_ipv6_nexthop_peer_cmd); + + install_element(RMAP_NODE, &match_ipv6_next_hop_cmd); + install_element(RMAP_NODE, &no_match_ipv6_next_hop_cmd); + install_element(RMAP_NODE, &set_ipv6_nexthop_global_cmd); + install_element(RMAP_NODE, &no_set_ipv6_nexthop_global_cmd); + install_element(RMAP_NODE, &set_ipv6_nexthop_prefer_global_cmd); + install_element(RMAP_NODE, &no_set_ipv6_nexthop_prefer_global_cmd); + install_element(RMAP_NODE, &set_ipv6_nexthop_peer_cmd); + install_element(RMAP_NODE, &no_set_ipv6_nexthop_peer_cmd); +} + +void bgp_route_map_terminate(void) +{ + /* ToDo: Cleanup all the used memory */ + + route_map_add_hook(NULL); + route_map_delete_hook(NULL); + route_map_event_hook(NULL); + route_map_finish(); } |
