📄 bgp_routemap.c
字号:
return (access_list_apply (alist, prefix) == FILTER_DENY ? RMAP_NOMATCH : RMAP_MATCH); } return RMAP_NOMATCH;}void *route_match_ipv6_address_compile (char *arg){ return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);}voidroute_match_ipv6_address_free (void *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};/* `match ipv6 next-hop IP_ADDRESS' */route_map_result_troute_match_ipv6_next_hop (void *rule, struct prefix *prefix, route_map_object_t type, void *object){ struct in6_addr *addr; struct bgp_info *bgp_info; if (type == RMAP_BGP) { addr = rule; bgp_info = object; if (IPV6_ADDR_SAME (&bgp_info->attr->mp_nexthop_global, rule)) return RMAP_MATCH; if (bgp_info->attr->mp_nexthop_len == 32 && IPV6_ADDR_SAME (&bgp_info->attr->mp_nexthop_local, rule)) return RMAP_MATCH; return RMAP_NOMATCH; } return RMAP_NOMATCH;}void *route_match_ipv6_next_hop_compile (char *arg){ struct in6_addr *address; int ret; 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; } return address;}voidroute_match_ipv6_next_hop_free (void *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};/* `match ipv6 address prefix-list PREFIX_LIST' */route_map_result_troute_match_ipv6_address_prefix_list (void *rule, struct prefix *prefix, route_map_object_t type, void *object){ struct prefix_list *plist; 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;}void *route_match_ipv6_address_prefix_list_compile (char *arg){ return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);}voidroute_match_ipv6_address_prefix_list_free (void *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};/* `set ipv6 nexthop global IP_ADDRESS' *//* Set nexthop to object. ojbect must be pointer to struct attr. */route_map_result_troute_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_info->attr->mp_nexthop_global = *address; /* Set nexthop length. */ if (bgp_info->attr->mp_nexthop_len == 0) bgp_info->attr->mp_nexthop_len = 16; } return RMAP_OKAY;}/* Route map `ip next-hop' compile function. Given string is converted to struct in_addr structure. */void *route_set_ipv6_nexthop_global_compile (char *arg){ int ret; struct in6_addr *address; address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in6_addr)); ret = inet_pton (AF_INET6, arg, address); if (ret == 0) { XFREE (MTYPE_ROUTE_MAP_COMPILED, address); return NULL; } return address;}/* Free route map's compiled `ip next-hop' value. */voidroute_set_ipv6_nexthop_global_free (void *rule){ XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);}/* Route map commands for ip nexthop set. */struct route_map_rule_cmd route_set_ipv6_nexthop_global_cmd ={ "ipv6 next-hop global", route_set_ipv6_nexthop_global, route_set_ipv6_nexthop_global_compile, route_set_ipv6_nexthop_global_free};/* `set ipv6 nexthop local IP_ADDRESS' *//* Set nexthop to object. ojbect must be pointer to struct attr. */route_map_result_troute_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_info->attr->mp_nexthop_local = *address; /* Set nexthop length. */ if (bgp_info->attr->mp_nexthop_len != 32) bgp_info->attr->mp_nexthop_len = 32; } return RMAP_OKAY;}/* Route map `ip nexthop' compile function. Given string is converted to struct in_addr structure. */void *route_set_ipv6_nexthop_local_compile (char *arg){ int ret; struct in6_addr *address; address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in6_addr)); ret = inet_pton (AF_INET6, arg, address); if (ret == 0) { XFREE (MTYPE_ROUTE_MAP_COMPILED, address); return NULL; } return address;}/* Free route map's compiled `ip nexthop' value. */voidroute_set_ipv6_nexthop_local_free (void *rule){ XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);}/* Route map commands for ip nexthop set. */struct route_map_rule_cmd route_set_ipv6_nexthop_local_cmd ={ "ipv6 next-hop local", route_set_ipv6_nexthop_local, route_set_ipv6_nexthop_local_compile, route_set_ipv6_nexthop_local_free};#endif /* HAVE_IPV6 *//* `set vpnv4 nexthop A.B.C.D' */route_map_result_troute_set_vpnv4_nexthop (void *rule, struct prefix *prefix, route_map_object_t type, void *object){ struct in_addr *address; struct bgp_info *bgp_info; if (type == RMAP_BGP) { /* Fetch routemap's rule information. */ address = rule; bgp_info = object; /* Set next hop value. */ bgp_info->attr->mp_nexthop_global_in = *address; } return RMAP_OKAY;}void *route_set_vpnv4_nexthop_compile (char *arg){ int ret; struct in_addr *address; address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in_addr)); ret = inet_aton (arg, address); if (ret == 0) { XFREE (MTYPE_ROUTE_MAP_COMPILED, address); return NULL; } return address;}voidroute_set_vpnv4_nexthop_free (void *rule){ XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);}/* Route map commands for ip nexthop set. */struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd ={ "vpnv4 next-hop", route_set_vpnv4_nexthop, route_set_vpnv4_nexthop_compile, route_set_vpnv4_nexthop_free};/* `set originator-id' *//* For origin set. */route_map_result_troute_set_originator_id (void *rule, struct prefix *prefix, route_map_object_t type, void *object){ struct in_addr *address; struct bgp_info *bgp_info; if (type == RMAP_BGP) { address = rule; bgp_info = object; bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID); bgp_info->attr->originator_id = *address; } return RMAP_OKAY;}/* Compile function for originator-id set. */void *route_set_originator_id_compile (char *arg){ int ret; struct in_addr *address; address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in_addr)); ret = inet_aton (arg, address); if (ret == 0) { XFREE (MTYPE_ROUTE_MAP_COMPILED, address); return NULL; } return address;}/* Compile function for originator_id set. */voidroute_set_originator_id_free (void *rule){ XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);}/* Set metric rule structure. */struct route_map_rule_cmd route_set_originator_id_cmd = { "originator-id", route_set_originator_id, route_set_originator_id_compile, route_set_originator_id_free,};/* Add bgp route map rule. */intbgp_route_match_add (struct vty *vty, struct route_map_index *index, char *command, char *arg){ int ret; ret = route_map_add_match (index, command, arg); if (ret) { switch (ret) { case RMAP_RULE_MISSING: vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE); return CMD_WARNING; break; case RMAP_COMPILE_ERROR: vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE); return CMD_WARNING; break; } } return CMD_SUCCESS;}/* Delete bgp route map rule. */intbgp_route_match_delete (struct vty *vty, struct route_map_index *index, char *command, char *arg){ int ret; ret = route_map_delete_match (index, command, arg); if (ret) { switch (ret) { case RMAP_RULE_MISSING: vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE); return CMD_WARNING; break; case RMAP_COMPILE_ERROR: vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE); return CMD_WARNING; break; } } return CMD_SUCCESS;}/* Add bgp route map rule. */intbgp_route_set_add (struct vty *vty, struct route_map_index *index, char *command, char *arg){ int ret; ret = route_map_add_set (index, command, arg); if (ret) { switch (ret) { case RMAP_RULE_MISSING: vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE); return CMD_WARNING; break; case RMAP_COMPILE_ERROR: vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE); return CMD_WARNING; break; } } return CMD_SUCCESS;}/* Delete bgp route map rule. */intbgp_route_set_delete (struct vty *vty, struct route_map_index *index, char *command, char *arg){ int ret; ret = route_map_delete_set (index, command, arg); if (ret) { switch (ret) { case RMAP_RULE_MISSING: vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE); return CMD_WARNING; break; case RMAP_COMPILE_ERROR: vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE); return CMD_WARNING; break; } } return CMD_SUCCESS;}/* Hook function for updating route_map assignment. */voidbgp_route_map_update (){ int i; afi_t afi; safi_t safi; int direct; struct listnode *nn, *nm; struct bgp *bgp; struct peer *peer; struct peer_group *group; struct bgp_filter *filter; struct bgp_node *bn; struct bgp_static *bgp_static; /* For neighbor route-map updates. */ LIST_LOOP (bm->bgp, bgp, nn) { LIST_LOOP (bgp->peer, peer, nm) { for (afi = AFI_IP; afi < AFI_MAX; afi++) for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) { filter = &peer->filter[afi][safi]; for (direct = FILTER_IN; direct < FILTER_MAX; direct++) { if (filter->map[direct].name) filter->map[direct].map = route_map_lookup_by_name (filter->map[direct].name); else filter->map[direct].map = NULL; } if (filter->usmap.name) filter->usmap.map = route_map_lookup_by_name (filter->usmap.name); else filter->usmap.map = NULL; } } LIST_LOOP (bgp->group, group, nm) { for (afi = AFI_IP; afi < AFI_MAX; afi++) for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) { filter = &group->conf->filter[afi][safi]; for (direct = FILTER_IN; direct < FILTER_MAX; direct++) { if (filter->map[direct].name) filter->map[direct].map = route_map_lookup_by_name (filter->map[direct].name); else filter->map[direct].map = NULL; } if (filter->usmap.name) filter->usmap.map = route_map_lookup_by_name (filter->usmap.name); else filter->usmap.map = NULL; } } } /* For default-originate route-map updates. */ LIST_LOOP (bm->bgp, bgp, nn) { LIST_LOOP (bgp->peer, peer, nm) { for (afi = AFI_IP; afi < AFI_MAX; afi++) for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) { if (peer->default_rmap[afi][safi].name) peer->default_rmap[afi][safi].map = route_map_lookup_by_name (peer->default_rmap[afi][safi].name); else peer->default_rmap[afi][safi].map = NULL; } } } /* For network route-map updates. */ LIST_LOOP (bm->bgp, bgp, nn) { for (afi = AFI_IP; afi < AFI_MAX; afi++) for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) for (bn = bgp_table_top (bgp->route[afi][safi]); bn; bn = bgp_route_next (bn))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -