summaryrefslogtreecommitdiffstats
path: root/bgpd/bgp_routemap.c
diff options
context:
space:
mode:
authorDonald Sharp <sharpd@cumulusnetworks.com>2019-09-13 22:43:16 +0200
committerDonald Sharp <sharpd@cumulusnetworks.com>2019-09-13 22:43:16 +0200
commit7b7d48e586b00d75caf79f361432d361e44f37a9 (patch)
treeae9ef3f4d8922acbdd3c218367ee6c477d0c84fd /bgpd/bgp_routemap.c
parentMerge pull request #4969 from ton31337/feature/rewrite_bgp_aggregate-address_... (diff)
downloadfrr-7b7d48e586b00d75caf79f361432d361e44f37a9.tar.xz
frr-7b7d48e586b00d75caf79f361432d361e44f37a9.zip
bgpd: Create `set distance XXX` command for routemaps
Allow bgp to set a local Administrative distance to use for installing routes into the rib. Example: ! router bgp 9323 bgp router-id 1.2.3.4 neighbor enp0s8 interface remote-as external ! address-family ipv4 unicast neighbor enp0s8 route-map DISTANCE in exit-address-family ! route-map DISTANCE permit 10 set distance 153 ! line vty ! end eva# show ip route Codes: K - kernel route, C - connected, S - static, R - RIP, O - OSPF, I - IS-IS, B - BGP, E - EIGRP, N - NHRP, T - Table, v - VNC, V - VNC-Direct, A - Babel, D - SHARP, F - PBR, f - OpenFabric, > - selected route, * - FIB route, q - queued route, r - rejected route B 0.0.0.0/0 [153/0] via fe80::a00:27ff:fe84:c2d6, enp0s8, 00:00:06 K>* 0.0.0.0/0 [0/100] via 10.0.2.2, enp0s3, 00:06:31 B>* 1.1.1.1/32 [153/0] via fe80::a00:27ff:fe84:c2d6, enp0s8, 00:00:06 B>* 1.1.1.2/32 [153/0] via fe80::a00:27ff:fe84:c2d6, enp0s8, 00:00:06 B>* 1.1.1.3/32 [153/0] via fe80::a00:27ff:fe84:c2d6, enp0s8, 00:00:06 C>* 10.0.2.0/24 is directly connected, enp0s3, 00:06:31 K>* 169.254.0.0/16 [0/1000] is directly connected, enp0s3, 00:06:31 eva# Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
Diffstat (limited to '')
-rw-r--r--bgpd/bgp_routemap.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/bgpd/bgp_routemap.c b/bgpd/bgp_routemap.c
index da702ec85..55b6e670b 100644
--- a/bgpd/bgp_routemap.c
+++ b/bgpd/bgp_routemap.c
@@ -1683,6 +1683,30 @@ struct route_map_rule_cmd route_set_weight_cmd = {
"weight", route_set_weight, route_value_compile, route_value_free,
};
+/* `set distance DISTANCE */
+static enum route_map_cmd_result_t
+route_set_distance(void *rule, const struct prefix *prefix,
+ route_map_object_t type, void *object)
+{
+ struct bgp_path_info *path = object;
+ struct rmap_value *rv = rule;
+
+ if (type != RMAP_BGP)
+ return RMAP_OKAY;
+
+ path->attr->distance = rv->value;
+
+ return RMAP_OKAY;
+}
+
+/* set distance rule structure */
+struct route_map_rule_cmd route_set_distance_cmd = {
+ "distance",
+ route_set_distance,
+ route_value_compile,
+ route_value_free,
+};
+
/* `set metric METRIC' */
/* Set metric to attribute. */
@@ -4064,6 +4088,29 @@ DEFUN (set_ip_nexthop_unchanged,
"unchanged");
}
+DEFUN (set_distance,
+ set_distance_cmd,
+ "set distance (0-255)",
+ SET_STR
+ "BGP Administrative Distance to use\n"
+ "Distance value\n")
+{
+ int idx_number = 2;
+
+ return generic_set_add(vty, VTY_GET_CONTEXT(route_map_index),
+ "distance", argv[idx_number]->arg);
+}
+
+DEFUN (no_set_distance,
+ no_set_distance_cmd,
+ "no set distance [(0-255)]",
+ NO_STR SET_STR
+ "BGP Administrative Distance to use\n"
+ "Distance value\n")
+{
+ return generic_set_delete(vty, VTY_GET_CONTEXT(route_map_index),
+ "distance", NULL);
+}
DEFUN (set_local_pref,
set_local_pref_cmd,
@@ -5119,6 +5166,7 @@ void bgp_route_map_init(void)
route_map_install_set(&route_set_weight_cmd);
route_map_install_set(&route_set_label_index_cmd);
route_map_install_set(&route_set_metric_cmd);
+ route_map_install_set(&route_set_distance_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);
@@ -5172,6 +5220,8 @@ void bgp_route_map_init(void)
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, &set_distance_cmd);
+ install_element(RMAP_NODE, &no_set_distance_cmd);
install_element(RMAP_NODE, &no_set_local_pref_cmd);
install_element(RMAP_NODE, &set_weight_cmd);
install_element(RMAP_NODE, &set_label_index_cmd);