From: dean <dlug...@gmail.com> Two grammar rules were added that allow addition of source dependent routes in the configuration of the static protocol.
route <dst_prefix> from <src_prefix> via <ip> route <dst_prefix> from <src_prefix> via "<interface>" Added a function that returns an addr_data object initialized from a static_route object. static_install and static_remove functions use net_*2 functions to install/remove SADR routes if SADR is enabled. --- proto/static/config.Y | 26 ++++++++++++++++++++++++++ proto/static/static.c | 21 +++++++++++++++++++-- proto/static/static.h | 6 ++++++ 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/proto/static/config.Y b/proto/static/config.Y index 182721b..1ab35a4 100644 --- a/proto/static/config.Y +++ b/proto/static/config.Y @@ -91,12 +91,38 @@ stat_route: this_srt->via = $3; this_srt->via_if = $4; } + | stat_route0 FROM prefix VIA ipa ipa_scope { + this_srt->dest = RTD_ROUTER; + this_srt->via = $5; + this_srt->via_if = $6; + + #ifdef SADR_OSPF + this_srt->from = $3.addr; + this_srt->slen = $3.len; + #else + cf_error("\"from\" keyword only works when SADR is enabled."); + #endif + } | stat_route0 VIA TEXT { this_srt->dest = RTD_DEVICE; this_srt->if_name = $3; rem_node(&this_srt->n); add_tail(&STATIC_CFG->iface_routes, &this_srt->n); } + | stat_route0 FROM prefix VIA TEXT { + this_srt->dest = RTD_DEVICE; + + #ifdef SADR_OSPF + this_srt->from = $3.addr; + this_srt->slen = $3.len; + #else + cf_error("\"from\" keyword only works when SADR is enabled."); + #endif + + this_srt->if_name = $5; + rem_node(&this_srt->n); + add_tail(&STATIC_CFG->iface_routes, &this_srt->n); + } | stat_route0 MULTIPATH stat_multipath { this_srt->dest = RTD_MULTIPATH; } diff --git a/proto/static/static.c b/proto/static/static.c index d54302a..acf6c30 100644 --- a/proto/static/static.c +++ b/proto/static/static.c @@ -57,6 +57,21 @@ p_igp_table(struct proto *p) return cf->igp_table ? cf->igp_table->table : p->table; } +static addr_data +addr_data_static_init(struct static_route *r) { + addr_data addr = { + .prefix = &r->net, + .pxlen = r->masklen + }; + + #ifdef SADR_OSPF + addr.src_prefix = &r->from; + addr.src_pxlen = r->slen; + #endif + + return addr; +} + static void static_install(struct proto *p, struct static_route *r, struct iface *ifa) { @@ -109,7 +124,8 @@ static_install(struct proto *p, struct static_route *r, struct iface *ifa) /* We skip rta_lookup() here */ - n = net_get(p->table, r->net, r->masklen); + addr_data addr = addr_data_static_init(r); + n = net_get2(p->table, addr); e = rte_get_temp(&a); e->net = n; e->pflags = 0; @@ -133,7 +149,8 @@ static_remove(struct proto *p, struct static_route *r) return; DBG("Removing static route %I/%d via %I\n", r->net, r->masklen, r->via); - n = net_find(p->table, r->net, r->masklen); + addr_data addr = addr_data_static_init(r); + n = net_find2(p->table, addr); rte_update(p, n, NULL); r->installed = 0; } diff --git a/proto/static/static.h b/proto/static/static.h index 6b04723..9bf481b 100644 --- a/proto/static/static.h +++ b/proto/static/static.h @@ -30,6 +30,12 @@ struct static_route { int masklen; /* Mask length */ int dest; /* Destination type (RTD_*) */ ip_addr via; /* Destination router */ + + #ifdef SADR_OSPF + ip_addr from; /* Source address */ + int slen; /* Source address mask length */ + #endif + struct iface *via_if; /* Destination iface, for link-local vias */ struct neighbor *neigh; byte *if_name; /* Name for RTD_DEVICE routes */ -- 2.7.4