Skip to content

Stronger types for BGP unnumbered peer addressing #9832

@jgallagher

Description

@jgallagher

(This is followup from review comments on #9570 that can be deferred to after R18, but I think we should consider it tech debt that we should pay down as soon as is reasonable. I believe addressing it is blocked by #9801.)

#9570 introduces support for BGP unnumbered peers, which have no address. This is mostly expressed by using an unspecified address (0.0.0.0 or ::, depending ipv4/ipv6) to mean "no address". In some spots we use an Option<IpAddr> instead, where None means "no address", but the inconsistency is unfortunate:

  • If the address isn't optional, any user of the address that needs to consider this now needs to check whether the address is unspecified. I'll propose that this seems easy to forget. b211fc9 is an example of the kind of thing I'm worried about; this adds a check to tread unspecified addresses specially, and it seems quite difficult to know (a) whether we've updated all sites that need to be updated and (b) that we'll have confidence that we continue to do so in the future.
  • If the address is optional, what does Some(addr) mean if addr is itself unspecified?
  • The datastore model types use Option<IpNetwork>, but then convert to an unspecified address as a sentinel value in the database, which has all the typical "sentinel value" issues (in particular: we have to correctly convert them at every insertion and query).

This is definitely not my area of expertise, but I'd tentatively propose something shaped sort of like this, with more clear names from someone who knows the domain better:

enum MaybeAddress {
    BgpUnnumbered,
    Address(SpecifiedIpAddr),
}

where SpecifiedIpAddr is a newtype around IpAddr similar to NonZeroU8 and friends (i.e., it validates that the IP address it wraps is not unspecified).

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions