freebsd-ports/net/quagga/files/extra-patch-ospf-nexthop
Sergey Matveychuk 9c02d5316a - Add an optional patch to allow 'set ip next-hop' in route maps
for OSPF announces. This is useful for OSPF with CARP.

Submitted by:	glebius
Approved by:	maintainer
Feature safe:	yes
2012-11-02 13:06:15 +00:00

175 lines
5 KiB
Text

diff -Nur ./ospfd/ospf_asbr.c /tmp/quagga-0.99.20-patched/ospfd/ospf_asbr.c
--- ./ospfd/ospf_asbr.c 2011-09-29 16:59:32.000000000 +0400
+++ /tmp/quagga-0.99.20-patched/ospfd/ospf_asbr.c 2012-01-15 18:44:18.000000000 +0400
@@ -122,6 +122,7 @@
{
values->metric = -1;
values->metric_type = -1;
+ values->nexthop.s_addr = -1;
}
int
diff -Nur ./ospfd/ospf_asbr.h /tmp/quagga-0.99.20-patched/ospfd/ospf_asbr.h
--- ./ospfd/ospf_asbr.h 2011-09-29 16:59:32.000000000 +0400
+++ /tmp/quagga-0.99.20-patched/ospfd/ospf_asbr.h 2012-01-15 18:44:18.000000000 +0400
@@ -27,6 +27,7 @@
{
int32_t metric;
int32_t metric_type;
+ struct in_addr nexthop;
};
/* Redistributed external information. */
@@ -50,6 +51,7 @@
struct route_map_set_values route_map_set;
#define ROUTEMAP_METRIC(E) (E)->route_map_set.metric
#define ROUTEMAP_METRIC_TYPE(E) (E)->route_map_set.metric_type
+#define ROUTEMAP_NEXTHOP(E) (E)->route_map_set.nexthop
};
#define OSPF_ASBR_CHECK_DELAY 30
diff -Nur ./ospfd/ospf_lsa.c /tmp/quagga-0.99.20-patched/ospfd/ospf_lsa.c
--- ./ospfd/ospf_lsa.c 2011-09-29 16:59:32.000000000 +0400
+++ /tmp/quagga-0.99.20-patched/ospfd/ospf_lsa.c 2012-01-15 18:44:18.000000000 +0400
@@ -1614,7 +1614,8 @@
stream_put_ospf_metric (s, mvalue);
/* Get forwarding address to nexthop if on the Connection List, else 0. */
- fwd_addr = ospf_external_lsa_nexthop_get (ospf, ei->nexthop);
+ fwd_addr = (ei->route_map_set.nexthop.s_addr != -1) ?
+ ROUTEMAP_NEXTHOP (ei) : ospf_external_lsa_nexthop_get (ospf, ei->nexthop);
/* Put forwarding address. */
stream_put_ipv4 (s, fwd_addr.s_addr);
diff -Nur ./ospfd/ospf_routemap.c /tmp/quagga-0.99.20-patched/ospfd/ospf_routemap.c
--- ./ospfd/ospf_routemap.c 2011-09-29 16:59:32.000000000 +0400
+++ /tmp/quagga-0.99.20-patched/ospfd/ospf_routemap.c 2012-01-15 18:44:18.000000000 +0400
@@ -527,6 +527,62 @@
route_set_metric_type_free,
};
+/* `set ip next-hop IP_ADDRESS' */
+/* Set nexthop to object. */
+static route_map_result_t
+route_set_ip_nexthop (void *rule, struct prefix *prefix,
+ route_map_object_t type, void *object)
+{
+ struct in_addr *address;
+ struct external_info *ei;
+
+ if (type == RMAP_OSPF)
+ {
+ /* Fetch routemap's rule information. */
+ address = rule;
+ ei = object;
+
+ /* Set metric out value. */
+ ei->route_map_set.nexthop = *address;
+ }
+ return RMAP_OKAY;
+}
+
+/* set ip next-hop compilation. */
+static void *
+route_set_ip_nexthop_compile (const char *arg)
+{
+ struct in_addr *address = NULL;
+ int ret;
+
+ 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;
+}
+
+/* Free route map's compiled `set ip next-hop' value. */
+static void
+route_set_ip_nexthop_free (void *rule)
+{
+ XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
+}
+
+/* Set ip next-hop rule structure. */
+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,
+};
+
DEFUN (match_ip_nexthop,
match_ip_nexthop_cmd,
"match ip next-hop (<1-199>|<1300-2699>|WORD)",
@@ -781,6 +837,49 @@
"OSPF[6] external type 1 metric\n"
"OSPF[6] external type 2 metric\n")
+DEFUN (set_ip_nexthop,
+ set_ip_nexthop_cmd,
+ "set ip next-hop A.B.C.D",
+ SET_STR
+ IP_STR
+ "Next hop address\n"
+ "IP address of next hop\n")
+{
+ union sockunion su;
+ int ret;
+
+ ret = str2sockunion (argv[0], &su);
+ if (ret < 0)
+ {
+ vty_out (vty, "%% Malformed Next-hop address%s", VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ return ospf_route_set_add (vty, vty->index, "ip next-hop", argv[0]);
+}
+
+DEFUN (no_set_ip_nexthop,
+ no_set_ip_nexthop_cmd,
+ "no set ip next-hop",
+ NO_STR
+ SET_STR
+ "Next hop address\n")
+{
+ if (argc == 0)
+ return ospf_route_set_delete (vty, vty->index, "ip next-hop", NULL);
+
+ return ospf_route_set_delete (vty, vty->index, "ip next-hop", argv[0]);
+}
+
+ALIAS (no_set_ip_nexthop,
+ no_set_ip_nexthop_val_cmd,
+ "no set ip next-hop A.B.C.D",
+ NO_STR
+ SET_STR
+ IP_STR
+ "Next hop address\n"
+ "IP address of next hop\n")
+
/* Route-map init */
void
ospf_route_map_init (void)
@@ -800,6 +899,7 @@
route_map_install_set (&route_set_metric_cmd);
route_map_install_set (&route_set_metric_type_cmd);
+ route_map_install_set (&route_set_ip_nexthop_cmd);
install_element (RMAP_NODE, &match_ip_nexthop_cmd);
install_element (RMAP_NODE, &no_match_ip_nexthop_cmd);
@@ -823,4 +923,7 @@
install_element (RMAP_NODE, &set_metric_type_cmd);
install_element (RMAP_NODE, &no_set_metric_type_cmd);
install_element (RMAP_NODE, &no_set_metric_type_val_cmd);
+ install_element (RMAP_NODE, &set_ip_nexthop_cmd);
+ install_element (RMAP_NODE, &no_set_ip_nexthop_cmd);
+ install_element (RMAP_NODE, &no_set_ip_nexthop_val_cmd);
}