Skip to content

Commit

Permalink
ospfd: Allow unnumbered and numbered addresses to co-exist better
Browse files Browse the repository at this point in the history
When forming a neighbor relationship on an interface, ospf is
currently evaluating unnumbered as highest priority, without
any consideration for if you have /32's and non /32's on the
interface.  Effectively if I have something like this:

int foo0
  ip address 192.168.119.1/24
!
router ospf
  network 0.0.0.0/0 area 0
!

ospf will form a neighbor on foo0 if it exists.  Now
suppose someone does this:

int foo0
  ip address 192.168.120.1/32

This will create the unnumbered interface on foo0 and
the peering will come down immediately.

The problem here is that the original designers of the unnumbered
code for ospf didn't envision end operators mixing and matching
addresses on an interface like this ( for perfectly legitimate
reasons I might add ).

So if ospf has both numbered and unnumbered let's match against
the numbered first and then unnumbered.  This solves the problem

Fixes: #6823
Signed-off-by: Donald Sharp <[email protected]>
(cherry picked from commit 5136e67)
  • Loading branch information
donaldsharp authored and mergify[bot] committed Nov 8, 2022
1 parent 9d2a8d5 commit fe5434e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions ospfd/ospf_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -461,13 +461,13 @@ struct ospf_interface *ospf_if_lookup_recv_if(struct ospf *ospf,
{
struct route_node *rn;
struct prefix_ipv4 addr;
struct ospf_interface *oi, *match;
struct ospf_interface *oi, *match, *unnumbered_match;

addr.family = AF_INET;
addr.prefix = src;
addr.prefixlen = IPV4_MAX_BITLEN;

match = NULL;
match = unnumbered_match = NULL;

for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
oi = rn->info;
Expand All @@ -482,7 +482,7 @@ struct ospf_interface *ospf_if_lookup_recv_if(struct ospf *ospf,
continue;

if (CHECK_FLAG(oi->connected->flags, ZEBRA_IFA_UNNUMBERED))
match = oi;
unnumbered_match = oi;
else if (prefix_match(CONNECTED_PREFIX(oi->connected),
(struct prefix *)&addr)) {
if ((match == NULL) || (match->address->prefixlen
Expand All @@ -491,7 +491,10 @@ struct ospf_interface *ospf_if_lookup_recv_if(struct ospf *ospf,
}
}

return match;
if (match)
return match;

return unnumbered_match;
}

void ospf_interface_fifo_flush(struct ospf_interface *oi)
Expand Down

0 comments on commit fe5434e

Please sign in to comment.