libnetwork/osl: remove Sandbox.NeighborOptions() etc.

NeighborOptions() returned an NeighborOptionSetter interface, which
contained "methods" that returned functional options. Such a construct
could have made sense if the functional options returned would (e.g.)
be pre-propagated with information from the Sandbox (network namespace),
but none of that was the case.

There was only one implementation of NeighborOptionSetter (networkNamespace),
which happened to be the same as the only implementation of Sandbox, so
remove the interface as well, to help networkNamespace with its multi-personality
disorder.

This patch:

- removes Sandbox.LinkName() and makes it a regular function (WithLinkName)
- removes Sandbox.Family() and makes it a regular function (WithFamily)
- removes Sandbox.NeighborOptions().
- removes the NeighborOptionSetter interface

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2023-08-20 10:53:07 +02:00
parent a365fb0e9d
commit f3d29db6a2
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
4 changed files with 6 additions and 28 deletions

View file

@ -322,7 +322,7 @@ func (d *driver) peerAddOp(nid, eid string, peerIP net.IP, peerIPMask net.IPMask
}
// Add neighbor entry for the peer IP
if err := sbox.AddNeighbor(peerIP, peerMac, l3Miss, sbox.NeighborOptions().LinkName(s.vxlanName)); err != nil {
if err := sbox.AddNeighbor(peerIP, peerMac, l3Miss, osl.WithLinkName(s.vxlanName)); err != nil {
if _, ok := err.(osl.NeighborSearchError); ok && dbEntries > 1 {
// We are in the transient case so only the first configuration is programmed into the kernel
// Upon deletion if the active configuration is deleted the next one from the database will be restored
@ -333,8 +333,7 @@ func (d *driver) peerAddOp(nid, eid string, peerIP net.IP, peerIPMask net.IPMask
}
// Add fdb entry to the bridge for the peer mac
if err := sbox.AddNeighbor(vtep, peerMac, l2Miss, sbox.NeighborOptions().LinkName(s.vxlanName),
sbox.NeighborOptions().Family(syscall.AF_BRIDGE)); err != nil {
if err := sbox.AddNeighbor(vtep, peerMac, l2Miss, osl.WithLinkName(s.vxlanName), osl.WithFamily(syscall.AF_BRIDGE)); err != nil {
return fmt.Errorf("could not add fdb entry for nid:%s eid:%s into the sandbox:%v", nid, eid, err)
}

View file

@ -348,11 +348,6 @@ func (n *networkNamespace) InterfaceOptions() IfaceOptionSetter {
return n
}
// NeighborOptions returns an interface with methods to set neighbor options.
func (n *networkNamespace) NeighborOptions() NeighborOptionSetter {
return n
}
func (n *networkNamespace) loopbackUp() error {
iface, err := n.nlHandle.LinkByName("lo")
if err != nil {

View file

@ -10,17 +10,15 @@ func (nh *neigh) processNeighOptions(options ...NeighOption) {
}
}
// LinkName returns an option setter to set the srcName of the link that should
// be used in the neighbor entry
func (n *networkNamespace) LinkName(name string) NeighOption {
// WithLinkName sets the srcName of the link to use in the neighbor entry.
func WithLinkName(name string) NeighOption {
return func(nh *neigh) {
nh.linkName = name
}
}
// Family returns an option setter to set the address family for the neighbor
// entry. eg. AF_BRIDGE
func (n *networkNamespace) Family(family int) NeighOption {
// WithFamily sets the address-family for the neighbor entry. e.g. [syscall.AF_BRIDGE].
func WithFamily(family int) NeighOption {
return func(nh *neigh) {
nh.family = family
}

View file

@ -77,9 +77,6 @@ type Sandbox interface {
// DeleteNeighbor deletes neighbor entry from the sandbox.
DeleteNeighbor(dstIP net.IP, dstMac net.HardwareAddr, osDelete bool) error
// NeighborOptions returns an interface with methods to set neighbor options.
NeighborOptions() NeighborOptionSetter
// InterfaceOptions an interface with methods to set interface options.
InterfaceOptions() IfaceOptionSetter
@ -98,17 +95,6 @@ type Sandbox interface {
Info
}
// NeighborOptionSetter interface defines the option setter methods for interface options
type NeighborOptionSetter interface {
// LinkName returns an option setter to set the srcName of the link that should
// be used in the neighbor entry
LinkName(string) NeighOption
// Family returns an option setter to set the address family for the neighbor
// entry. eg. AF_BRIDGE
Family(int) NeighOption
}
// IfaceOptionSetter interface defines the option setter methods for interface options.
type IfaceOptionSetter interface {
// Bridge returns an option setter to set if the interface is a bridge.