Skip to content

Commit

Permalink
bgpd: Refactor bgp_static_set/bgp_static_set_safi
Browse files Browse the repository at this point in the history
Those two functions are very similar, let's get a single one.

Signed-off-by: Donatas Abraitis <[email protected]>
  • Loading branch information
ton31337 committed Aug 10, 2023
1 parent b886422 commit e06e5ce
Show file tree
Hide file tree
Showing 4 changed files with 163 additions and 268 deletions.
23 changes: 12 additions & 11 deletions bgpd/bgp_evpn_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -2081,12 +2081,12 @@ DEFUN(evpnrt5_network,
int idx_ethtag = 5;
int idx_routermac = 13;

return bgp_static_set_safi(
AFI_L2VPN, SAFI_EVPN, vty, argv[idx_ipv4_prefixlen]->arg,
argv[idx_route_distinguisher]->arg, argv[idx_label]->arg, NULL,
BGP_EVPN_IP_PREFIX_ROUTE, argv[idx_esi]->arg,
argv[idx_gwip]->arg, argv[idx_ethtag]->arg,
argv[idx_routermac]->arg);
return bgp_static_set(vty, false, argv[idx_ipv4_prefixlen]->arg,
argv[idx_route_distinguisher]->arg,
argv[idx_label]->arg, AFI_L2VPN, SAFI_EVPN, NULL,
0, 0, BGP_EVPN_IP_PREFIX_ROUTE,
argv[idx_esi]->arg, argv[idx_gwip]->arg,
argv[idx_ethtag]->arg, argv[idx_routermac]->arg);
}

/* For testing purpose, static route of EVPN RT-5. */
Expand All @@ -2113,11 +2113,12 @@ DEFUN(no_evpnrt5_network,
int idx_ethtag = 6;
int idx_esi = 10;
int idx_gwip = 12;
return bgp_static_unset_safi(
AFI_L2VPN, SAFI_EVPN, vty, argv[idx_ipv4_prefixlen]->arg,
argv[idx_ext_community]->arg, argv[idx_label]->arg,
BGP_EVPN_IP_PREFIX_ROUTE, argv[idx_esi]->arg,
argv[idx_gwip]->arg, argv[idx_ethtag]->arg);

return bgp_static_set(vty, true, argv[idx_ipv4_prefixlen]->arg,
argv[idx_ext_community]->arg,
argv[idx_label]->arg, AFI_L2VPN, SAFI_EVPN, NULL,
0, 0, BGP_EVPN_IP_PREFIX_ROUTE, argv[idx_esi]->arg,
argv[idx_gwip]->arg, argv[idx_ethtag]->arg, NULL);
}

static void evpn_import_rt_delete_auto(struct bgp *bgp, struct bgpevpn *vpn)
Expand Down
59 changes: 33 additions & 26 deletions bgpd/bgp_mplsvpn.c
Original file line number Diff line number Diff line change
Expand Up @@ -3011,10 +3011,11 @@ DEFUN (vpnv4_network,
int idx_ipv4_prefixlen = 1;
int idx_ext_community = 3;
int idx_label = 5;
return bgp_static_set_safi(
AFI_IP, SAFI_MPLS_VPN, vty, argv[idx_ipv4_prefixlen]->arg,
argv[idx_ext_community]->arg, argv[idx_label]->arg, NULL, 0,
NULL, NULL, NULL, NULL);

return bgp_static_set(vty, false, argv[idx_ipv4_prefixlen]->arg,
argv[idx_ext_community]->arg,
argv[idx_label]->arg, AFI_IP, SAFI_MPLS_VPN, NULL,
0, 0, 0, NULL, NULL, NULL, NULL);
}

DEFUN (vpnv4_network_route_map,
Expand All @@ -3033,11 +3034,12 @@ DEFUN (vpnv4_network_route_map,
int idx_ipv4_prefixlen = 1;
int idx_ext_community = 3;
int idx_label = 5;
int idx_word_2 = 7;
return bgp_static_set_safi(
AFI_IP, SAFI_MPLS_VPN, vty, argv[idx_ipv4_prefixlen]->arg,
argv[idx_ext_community]->arg, argv[idx_label]->arg,
argv[idx_word_2]->arg, 0, NULL, NULL, NULL, NULL);
int idx_rmap = 7;

return bgp_static_set(vty, false, argv[idx_ipv4_prefixlen]->arg,
argv[idx_ext_community]->arg, argv[idx_label]->arg,
AFI_IP, SAFI_MPLS_VPN, argv[idx_rmap]->arg, 0, 0,
0, NULL, NULL, NULL, NULL);
}

/* For testing purpose, static route of MPLS-VPN. */
Expand All @@ -3056,10 +3058,11 @@ DEFUN (no_vpnv4_network,
int idx_ipv4_prefixlen = 2;
int idx_ext_community = 4;
int idx_label = 6;
return bgp_static_unset_safi(AFI_IP, SAFI_MPLS_VPN, vty,
argv[idx_ipv4_prefixlen]->arg,
argv[idx_ext_community]->arg,
argv[idx_label]->arg, 0, NULL, NULL, NULL);

return bgp_static_set(vty, true, argv[idx_ipv4_prefixlen]->arg,
argv[idx_ext_community]->arg,
argv[idx_label]->arg, AFI_IP, SAFI_MPLS_VPN, NULL,
0, 0, 0, NULL, NULL, NULL, NULL);
}

DEFUN (vpnv6_network,
Expand All @@ -3078,17 +3081,20 @@ DEFUN (vpnv6_network,
int idx_ipv6_prefix = 1;
int idx_ext_community = 3;
int idx_label = 5;
int idx_word_2 = 7;
int idx_rmap = 7;

if (argc == 8)
return bgp_static_set_safi(
AFI_IP6, SAFI_MPLS_VPN, vty, argv[idx_ipv6_prefix]->arg,
argv[idx_ext_community]->arg, argv[idx_label]->arg,
argv[idx_word_2]->arg, 0, NULL, NULL, NULL, NULL);
return bgp_static_set(vty, false, argv[idx_ipv6_prefix]->arg,
argv[idx_ext_community]->arg,
argv[idx_label]->arg, AFI_IP6,
SAFI_MPLS_VPN, argv[idx_rmap]->arg, 0, 0,
0, NULL, NULL, NULL, NULL);
else
return bgp_static_set_safi(
AFI_IP6, SAFI_MPLS_VPN, vty, argv[idx_ipv6_prefix]->arg,
argv[idx_ext_community]->arg, argv[idx_label]->arg,
NULL, 0, NULL, NULL, NULL, NULL);
return bgp_static_set(vty, false, argv[idx_ipv6_prefix]->arg,
argv[idx_ext_community]->arg,
argv[idx_label]->arg, AFI_IP6,
SAFI_MPLS_VPN, NULL, 0, 0, 0, NULL, NULL,
NULL, NULL);
}

/* For testing purpose, static route of MPLS-VPN. */
Expand All @@ -3107,10 +3113,11 @@ DEFUN (no_vpnv6_network,
int idx_ipv6_prefix = 2;
int idx_ext_community = 4;
int idx_label = 6;
return bgp_static_unset_safi(AFI_IP6, SAFI_MPLS_VPN, vty,
argv[idx_ipv6_prefix]->arg,
argv[idx_ext_community]->arg,
argv[idx_label]->arg, 0, NULL, NULL, NULL);

return bgp_static_set(vty, true, argv[idx_ipv6_prefix]->arg,
argv[idx_ext_community]->arg,
argv[idx_label]->arg, AFI_IP6, SAFI_MPLS_VPN,
NULL, 0, 0, 0, NULL, NULL, NULL, NULL);
}

int bgp_show_mpls_vpn(struct vty *vty, afi_t afi, struct prefix_rd *prd,
Expand Down
Loading

0 comments on commit e06e5ce

Please sign in to comment.