OSPF & BGP Default Route

I’m having trouble with default routes on ASBR’s. Here is a somewhat simplified diagram of how I’m set up:

(gw1) — [r1] — — — [r4] — (gw2)

  1. gw1 is on a DSL circuit to one ISP, with an OSPF adjacency with r1
  2. r1 has OSPF adjacencies with gw1 and r2
  3. r2 has OSPF adjacency with r1, and BGP session with r3
  4. r3 has BGP session with r2, and OSPF adjacency with r4
  5. r4 has OSPF adjacencies with r3 and gw2
  6. gw2 is on a DSL circuit to another ISP, with OSPF adjacency with r4

I have filters on both r2 and r3 that set the distance to 200 on the default route learned from BGP, so both sides prefer the path through their respective gateways.

I have the “distribute-default” OSPF parameter enabled on gw1 (if-installed-as-type-1), r2 (if-installed-as-type-2), gw2 (if-installed-as-type-1), and r3 (if-installed-as-type-2).

When this is first set up, everything works well – all the routers have two defaults, with the OSPF default route being active. If, for example, the link fails between gw1 and r1, the OSPF default (learned from gw1) will drop out of the table and the BGP default (learned from r3) will become active.

The problem is when the link is restored between gw1 and r1. r1 gets the default from gw1, but r2 does not. On r2, only the BGP default from r3 is in the table. If I look at “/rouing ospf lsa print” on r2, I’ll see that there is an entry in there for 0.0.0.0, but it is from r2 itself. I have to set distribute-default=never on r2 to get back the default route from gw1.