📄 bgp_route.c
字号:
{ vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE); return CMD_WARNING; }#ifdef HAVE_IPV6 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6)) { vty_out (vty, "%% Malformed prefix (link-local address)%s", VTY_NEWLINE); return CMD_WARNING; }#endif /* HAVE_IPV6 */ apply_mask (&p); /* Set BGP static route configuration. */ rn = bgp_node_get (bgp->route[afi][safi], &p); if (rn->info) { /* Configuration change. */ bgp_static = rn->info; /* Check previous routes are installed into BGP. */ if (! bgp_static->backdoor && bgp_static->valid) need_update = 1; bgp_static->backdoor = backdoor; if (rmap) { if (bgp_static->rmap.name) free (bgp_static->rmap.name); bgp_static->rmap.name = strdup (rmap); bgp_static->rmap.map = route_map_lookup_by_name (rmap); } else { if (bgp_static->rmap.name) free (bgp_static->rmap.name); bgp_static->rmap.name = NULL; bgp_static->rmap.map = NULL; bgp_static->valid = 0; } bgp_unlock_node (rn); } else { /* New configuration. */ bgp_static = bgp_static_new (); bgp_static->backdoor = backdoor; bgp_static->valid = 0; bgp_static->igpmetric = 0; bgp_static->igpnexthop.s_addr = 0; if (rmap) { if (bgp_static->rmap.name) free (bgp_static->rmap.name); bgp_static->rmap.name = strdup (rmap); bgp_static->rmap.map = route_map_lookup_by_name (rmap); } rn->info = bgp_static; } /* If BGP scan is not enabled, we should install this route here. */ if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK)) { bgp_static->valid = 1; if (need_update) bgp_static_withdraw (bgp, &p, afi, safi); if (! bgp_static->backdoor) bgp_static_update (bgp, &p, bgp_static, afi, safi); } return CMD_SUCCESS;}/* Configure static BGP network. */intbgp_static_unset (struct vty *vty, struct bgp *bgp, char *ip_str, u_int16_t afi, u_char safi){ int ret; struct prefix p; struct bgp_static *bgp_static; struct bgp_node *rn; /* Convert IP prefix string to struct prefix. */ ret = str2prefix (ip_str, &p); if (! ret) { vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE); return CMD_WARNING; }#ifdef HAVE_IPV6 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6)) { vty_out (vty, "%% Malformed prefix (link-local address)%s", VTY_NEWLINE); return CMD_WARNING; }#endif /* HAVE_IPV6 */ apply_mask (&p); rn = bgp_node_lookup (bgp->route[afi][safi], &p); if (! rn) { vty_out (vty, "%% Can't find specified static route configuration.%s", VTY_NEWLINE); return CMD_WARNING; } bgp_static = rn->info; /* Update BGP RIB. */ if (! bgp_static->backdoor) bgp_static_withdraw (bgp, &p, afi, safi); /* Clear configuration. */ bgp_static_free (bgp_static); rn->info = NULL; bgp_unlock_node (rn); bgp_unlock_node (rn); return CMD_SUCCESS;}/* Called from bgp_delete(). Delete all static routes from the BGP instance. */voidbgp_static_delete (struct bgp *bgp){ afi_t afi; safi_t safi; struct bgp_node *rn; struct bgp_node *rm; struct bgp_table *table; struct bgp_static *bgp_static; for (afi = AFI_IP; afi < AFI_MAX; afi++) for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn)) if (rn->info != NULL) { if (safi == SAFI_MPLS_VPN) { table = rn->info; for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm)) { bgp_static = rn->info; bgp_static_withdraw_vpnv4 (bgp, &rm->p, AFI_IP, SAFI_MPLS_VPN, (struct prefix_rd *)&rn->p, bgp_static->tag); bgp_static_free (bgp_static); rn->info = NULL; bgp_unlock_node (rn); } } else { bgp_static = rn->info; bgp_static_withdraw (bgp, &rn->p, afi, safi); bgp_static_free (bgp_static); rn->info = NULL; bgp_unlock_node (rn); } }}intbgp_static_set_vpnv4 (struct vty *vty, char *ip_str, char *rd_str, char *tag_str){ int ret; struct prefix p; struct prefix_rd prd; struct bgp *bgp; struct bgp_node *prn; struct bgp_node *rn; struct bgp_table *table; struct bgp_static *bgp_static; u_char tag[3]; bgp = vty->index; ret = str2prefix (ip_str, &p); if (! ret) { vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE); return CMD_WARNING; } apply_mask (&p); ret = str2prefix_rd (rd_str, &prd); if (! ret) { vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE); return CMD_WARNING; } ret = str2tag (tag_str, tag); if (! ret) { vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE); return CMD_WARNING; } prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN], (struct prefix *)&prd); if (prn->info == NULL) prn->info = bgp_table_init (); else bgp_unlock_node (prn); table = prn->info; rn = bgp_node_get (table, &p); if (rn->info) { vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE); bgp_unlock_node (rn); } else { /* New configuration. */ bgp_static = bgp_static_new (); bgp_static->valid = 1; memcpy (bgp_static->tag, tag, 3); rn->info = bgp_static; bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag); } return CMD_SUCCESS;}/* Configure static BGP network. */intbgp_static_unset_vpnv4 (struct vty *vty, char *ip_str, char *rd_str, char *tag_str){ int ret; struct bgp *bgp; struct prefix p; struct prefix_rd prd; struct bgp_node *prn; struct bgp_node *rn; struct bgp_table *table; struct bgp_static *bgp_static; u_char tag[3]; bgp = vty->index; /* Convert IP prefix string to struct prefix. */ ret = str2prefix (ip_str, &p); if (! ret) { vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE); return CMD_WARNING; } apply_mask (&p); ret = str2prefix_rd (rd_str, &prd); if (! ret) { vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE); return CMD_WARNING; } ret = str2tag (tag_str, tag); if (! ret) { vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE); return CMD_WARNING; } prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN], (struct prefix *)&prd); if (prn->info == NULL) prn->info = bgp_table_init (); else bgp_unlock_node (prn); table = prn->info; rn = bgp_node_lookup (table, &p); if (rn) { bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag); bgp_static = rn->info; bgp_static_free (bgp_static); rn->info = NULL; bgp_unlock_node (rn); bgp_unlock_node (rn); } else vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE); return CMD_SUCCESS;}DEFUN (bgp_network, bgp_network_cmd, "network A.B.C.D/M", "Specify a network to announce via BGP\n" "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"){ return bgp_static_set (vty, vty->index, argv[0], AFI_IP, bgp_node_safi (vty), NULL, 0);}DEFUN (bgp_network_route_map, bgp_network_route_map_cmd, "network A.B.C.D/M route-map WORD", "Specify a network to announce via BGP\n" "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" "Route-map to modify the attributes\n" "Name of the route map\n"){ return bgp_static_set (vty, vty->index, argv[0], AFI_IP, bgp_node_safi (vty), argv[1], 0);}DEFUN (bgp_network_backdoor, bgp_network_backdoor_cmd, "network A.B.C.D/M backdoor", "Specify a network to announce via BGP\n" "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" "Specify a BGP backdoor route\n"){ return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);}DEFUN (bgp_network_mask, bgp_network_mask_cmd, "network A.B.C.D mask A.B.C.D", "Specify a network to announce via BGP\n" "Network number\n" "Network mask\n" "Network mask\n"){ int ret; char prefix_str[BUFSIZ]; ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str); if (! ret) { vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE); return CMD_WARNING; } return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, bgp_node_safi (vty), NULL, 0);}DEFUN (bgp_network_mask_route_map, bgp_network_mask_route_map_cmd, "network A.B.C.D mask A.B.C.D route-map WORD", "Specify a network to announce via BGP\n" "Network number\n" "Network mask\n" "Network mask\n" "Route-map to modify the attributes\n" "Name of the route map\n"){ int ret; char prefix_str[BUFSIZ]; ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str); if (! ret) { vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE); return CMD_WARNING; } return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, bgp_node_safi (vty), argv[2], 0);}DEFUN (bgp_network_mask_backdoor, bgp_network_mask_backdoor_cmd, "network A.B.C.D mask A.B.C.D backdoor", "Specify a network to announce via BGP\n" "Network number\n" "Network mask\n" "Network mask\n" "Specify a BGP backdoor route\n"){ int ret; char prefix_str[BUFSIZ]; ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str); if (! ret) { vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE); return CMD_WARNING; } return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST, NULL, 1);}DEFUN (bgp_network_mask_natural, bgp_network_mask_natural_cmd, "network A.B.C.D", "Specify a network to announce via BGP\n" "Network number\n"){ int ret; char prefix_str[BUFSIZ]; ret = netmask_str2prefix_str (argv[0], NULL, prefix_str); if (! ret) { vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE); return CMD_WARNING; } return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, bgp_node_safi (vty), NULL, 0);}DEFUN (bgp_network_mask_natural_route_map, bgp_network_mask_natural_route_map_cmd, "network A.B.C.D route-map WORD", "Specify a network to announce via BGP\n" "Network number\n" "Route-map to modify the attributes\n" "Name of the route map\n"){ int ret; char prefix_str[BUFSIZ]; ret = netmask_str2prefix_str (argv[0], NULL, prefix_str); if (! ret) { vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE); return CMD_WARNING; } return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, bgp_node_safi (vty), argv[1], 0);}DEFUN (bgp_network_mask_natural_backdoor, bgp_network_mask_natural_backdoor_cmd, "network A.B.C.D backdoor", "Specify a network to announce via BGP\n" "Network number\n" "Specify a BGP backdoor route\n"){ int ret; char prefix_str[BUFSIZ]; ret = netmask_str2prefix_str (argv[0], NULL, prefix_str); if (! ret) { vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE); return CMD_WARNING; } return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST, NULL, 1);}DEFUN (no_bgp_network, no_bgp_network_cmd, "no network A.B.C.D/M", NO_STR "Specify a network to announce via BGP\n" "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"){ return bgp_static_unset (vty, vty->index, argv[0], AFI_IP, bgp_node_safi (vty));}ALIAS (no_bgp_network, no_bgp_network_route_map_cmd, "no network A.B.C.D/M route-map WORD", NO_STR "Specify a network to announce via BGP\n" "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" "Route-map to modify the attributes\n" "Name of the route map\n");ALIAS (no_bgp_network, no_bgp_network_backdoor_cmd, "no network A.B.C.D/M backdoor", NO_STR "Specify a network to announce via BGP\n" "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" "Specify a BGP backdoor route\n");DEFUN (no_bgp_network_mask, no_bgp_network_mask_cmd, "no network A.B.C.D mask A.B.C.D", NO_STR "Specify a network to announce via BGP\n" "Network number\n"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -