Skip to content

Commit dcab1bb

Browse files
cfraeqvinox
authored andcommitted
bgpd: conditional default-originate using route-map
Incorporate a patch by Svetozar Mihailov which implements default-originate route-maps to behave as expected, i.e. allowing the default route to be advertised conditionally, depending on a criterion given by the route-map. I am aware that the performance attributes of the following implementation are far from optimal. However, this affects only code paths belonging to a feature that is broken without this patch, therefore, it seems reasonable to me to have this in the mainline for now. Cc: Svetozar Mihailov <[email protected]> Reported-by: Sébastien Cramatte <[email protected]> Signed-off-by: Christian Franke <[email protected]> Signed-off-by: David Lamparter <[email protected]>
1 parent 86998bc commit dcab1bb

File tree

3 files changed

+49
-14
lines changed

3 files changed

+49
-14
lines changed

NEWS

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
Note: this file lists major user-visible changes only.
22

3+
- [bgpd] The semantics of default-originate route-map have changed.
4+
The route-map is now used to advertise the default route conditionally.
5+
The old behaviour which allowed to set attributes on the originated
6+
default route is no longer supported.
7+
38
* Changes in Quagga 0.99.21
49

510
- [bgpd] BGP multipath support has been merged

bgpd/bgp_nexthop.c

+10
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,16 @@ bgp_scan (afi_t afi, safi_t safi)
506506
else if (afi == AFI_IP6)
507507
zlog_debug ("scanning IPv6 Unicast routing tables");
508508
}
509+
510+
/* Reevaluate default-originate route-maps and announce/withdraw
511+
* default route if neccesary. */
512+
for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
513+
{
514+
if (peer->status == Established
515+
&& CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE)
516+
&& peer->default_rmap[afi][safi].name)
517+
bgp_default_originate (peer, afi, safi, 0);
518+
}
509519
}
510520

511521
/* BGP scan thread. This thread check nexthop reachability. */

bgpd/bgp_route.c

+34-14
Original file line numberDiff line numberDiff line change
@@ -2462,8 +2462,9 @@ bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
24622462
struct attr attr;
24632463
struct aspath *aspath;
24642464
struct prefix p;
2465-
struct bgp_info binfo;
24662465
struct peer *from;
2466+
struct bgp_node *rn;
2467+
struct bgp_info *ri;
24672468
int ret = RMAP_DENYMATCH;
24682469

24692470
if (!(afi == AFI_IP || afi == AFI_IP6))
@@ -2505,21 +2506,37 @@ bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
25052506

25062507
if (peer->default_rmap[afi][safi].name)
25072508
{
2508-
binfo.peer = bgp->peer_self;
2509-
binfo.attr = &attr;
2510-
25112509
SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
2512-
2513-
ret = route_map_apply (peer->default_rmap[afi][safi].map, &p,
2514-
RMAP_BGP, &binfo);
2515-
2510+
for (rn = bgp_table_top(bgp->rib[afi][safi]); rn; rn = bgp_route_next(rn))
2511+
{
2512+
for (ri = rn->info; ri; ri = ri->next)
2513+
{
2514+
struct attr dummy_attr;
2515+
struct attr_extra dummy_extra;
2516+
struct bgp_info info;
2517+
2518+
/* Provide dummy so the route-map can't modify the attributes */
2519+
dummy_attr.extra = &dummy_extra;
2520+
bgp_attr_dup(&dummy_attr, ri->attr);
2521+
info.peer = ri->peer;
2522+
info.attr = &dummy_attr;
2523+
2524+
ret = route_map_apply(peer->default_rmap[afi][safi].map, &rn->p,
2525+
RMAP_BGP, &info);
2526+
2527+
/* The route map might have set attributes. If we don't flush them
2528+
* here, they will be leaked. */
2529+
bgp_attr_flush(&dummy_attr);
2530+
if (ret != RMAP_DENYMATCH)
2531+
break;
2532+
}
2533+
if (ret != RMAP_DENYMATCH)
2534+
break;
2535+
}
25162536
bgp->peer_self->rmap_type = 0;
25172537

25182538
if (ret == RMAP_DENYMATCH)
2519-
{
2520-
bgp_attr_flush (&attr);
2521-
withdraw = 1;
2522-
}
2539+
withdraw = 1;
25232540
}
25242541

25252542
if (withdraw)
@@ -2530,8 +2547,11 @@ bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
25302547
}
25312548
else
25322549
{
2533-
SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2534-
bgp_default_update_send (peer, &attr, afi, safi, from);
2550+
if (! CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2551+
{
2552+
SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2553+
bgp_default_update_send (peer, &attr, afi, safi, from);
2554+
}
25352555
}
25362556

25372557
bgp_attr_extra_free (&attr);

0 commit comments

Comments
 (0)