@@ -7,11 +7,11 @@ import (
77 "context"
88 "errors"
99 "fmt"
10- "net"
1110 "net/netip"
1211 "syscall"
1312
1413 "github.com/containerd/log"
14+ "github.com/docker/docker/daemon/libnetwork/internal/hashable"
1515 "github.com/docker/docker/daemon/libnetwork/internal/setmatrix"
1616 "github.com/docker/docker/daemon/libnetwork/osl"
1717)
@@ -20,7 +20,7 @@ const ovPeerTable = "overlay_peer_table"
2020
2121type peerEntry struct {
2222 eid string
23- mac macAddr
23+ mac hashable. MACAddr
2424 vtep netip.Addr
2525}
2626
@@ -49,10 +49,10 @@ func (pm *peerMap) Get(peerIP netip.Prefix) (peerEntry, bool) {
4949 return c [0 ], true
5050}
5151
52- func (pm * peerMap ) Add (eid string , peerIP netip.Prefix , peerMac net. HardwareAddr , vtep netip.Addr ) (bool , int ) {
52+ func (pm * peerMap ) Add (eid string , peerIP netip.Prefix , peerMac hashable. MACAddr , vtep netip.Addr ) (bool , int ) {
5353 pEntry := peerEntry {
5454 eid : eid ,
55- mac : macAddrOf ( peerMac ) ,
55+ mac : peerMac ,
5656 vtep : vtep ,
5757 }
5858 b , i := pm .mp .Insert (peerIP , pEntry )
@@ -64,10 +64,10 @@ func (pm *peerMap) Add(eid string, peerIP netip.Prefix, peerMac net.HardwareAddr
6464 return b , i
6565}
6666
67- func (pm * peerMap ) Delete (eid string , peerIP netip.Prefix , peerMac net. HardwareAddr , vtep netip.Addr ) (bool , int ) {
67+ func (pm * peerMap ) Delete (eid string , peerIP netip.Prefix , peerMac hashable. MACAddr , vtep netip.Addr ) (bool , int ) {
6868 pEntry := peerEntry {
6969 eid : eid ,
70- mac : macAddrOf ( peerMac ) ,
70+ mac : peerMac ,
7171 vtep : vtep ,
7272 }
7373
@@ -94,7 +94,7 @@ func (n *network) initSandboxPeerDB() error {
9494 var errs []error
9595 n .peerdb .Walk (func (peerIP netip.Prefix , pEntry peerEntry ) {
9696 if ! pEntry .isLocal () {
97- if err := n .addNeighbor (peerIP , pEntry .mac . HardwareAddr () , pEntry .vtep ); err != nil {
97+ if err := n .addNeighbor (peerIP , pEntry .mac , pEntry .vtep ); err != nil {
9898 errs = append (errs , fmt .Errorf ("failed to add neighbor entries for %s: %w" , peerIP , err ))
9999 }
100100 }
@@ -105,7 +105,7 @@ func (n *network) initSandboxPeerDB() error {
105105// peerAdd adds a new entry to the peer database.
106106//
107107// Local peers are signified by an invalid vtep (i.e. netip.Addr{}).
108- func (n * network ) peerAdd (eid string , peerIP netip.Prefix , peerMac net. HardwareAddr , vtep netip.Addr ) error {
108+ func (n * network ) peerAdd (eid string , peerIP netip.Prefix , peerMac hashable. MACAddr , vtep netip.Addr ) error {
109109 if eid == "" {
110110 return errors .New ("invalid endpoint id" )
111111 }
@@ -130,7 +130,7 @@ func (n *network) peerAdd(eid string, peerIP netip.Prefix, peerMac net.HardwareA
130130}
131131
132132// addNeighbor programs the kernel so the given peer is reachable through the VXLAN tunnel.
133- func (n * network ) addNeighbor (peerIP netip.Prefix , peerMac net. HardwareAddr , vtep netip.Addr ) error {
133+ func (n * network ) addNeighbor (peerIP netip.Prefix , peerMac hashable. MACAddr , vtep netip.Addr ) error {
134134 if n .sbox == nil {
135135 // We are hitting this case for all the events that are arriving before that the sandbox
136136 // is being created. The peer got already added into the database and the sandbox init will
@@ -154,13 +154,13 @@ func (n *network) addNeighbor(peerIP netip.Prefix, peerMac net.HardwareAddr, vte
154154 }
155155
156156 // Add neighbor entry for the peer IP
157- if err := n .sbox .AddNeighbor (peerIP .Addr ().AsSlice (), peerMac , osl .WithLinkName (s .vxlanName )); err != nil {
157+ if err := n .sbox .AddNeighbor (peerIP .Addr ().AsSlice (), peerMac . AsSlice () , osl .WithLinkName (s .vxlanName )); err != nil {
158158 return fmt .Errorf ("could not add neighbor entry into the sandbox: %w" , err )
159159 }
160160
161161 // Add fdb entry to the bridge for the peer mac
162- if n .fdbCnt .Add (ipmacOf (vtep , peerMac ), 1 ) == 1 {
163- if err := n .sbox .AddNeighbor (vtep .AsSlice (), peerMac , osl .WithLinkName (s .vxlanName ), osl .WithFamily (syscall .AF_BRIDGE )); err != nil {
162+ if n .fdbCnt .Add (hashable . IPMACFrom (vtep , peerMac ), 1 ) == 1 {
163+ if err := n .sbox .AddNeighbor (vtep .AsSlice (), peerMac . AsSlice () , osl .WithLinkName (s .vxlanName ), osl .WithFamily (syscall .AF_BRIDGE )); err != nil {
164164 return fmt .Errorf ("could not add fdb entry into the sandbox: %w" , err )
165165 }
166166 }
@@ -171,7 +171,7 @@ func (n *network) addNeighbor(peerIP netip.Prefix, peerMac net.HardwareAddr, vte
171171// peerDelete removes an entry from the peer database.
172172//
173173// Local peers are signified by an invalid vtep (i.e. netip.Addr{}).
174- func (n * network ) peerDelete (eid string , peerIP netip.Prefix , peerMac net. HardwareAddr , vtep netip.Addr ) error {
174+ func (n * network ) peerDelete (eid string , peerIP netip.Prefix , peerMac hashable. MACAddr , vtep netip.Addr ) error {
175175 if eid == "" {
176176 return errors .New ("invalid endpoint id" )
177177 }
@@ -207,7 +207,7 @@ func (n *network) peerDelete(eid string, peerIP netip.Prefix, peerMac net.Hardwa
207207 if ! ok {
208208 return fmt .Errorf ("peerDelete: unable to restore a configuration: no entry for %v found in the database" , peerIP )
209209 }
210- err := n .addNeighbor (peerIP , peerEntry .mac . HardwareAddr () , peerEntry .vtep )
210+ err := n .addNeighbor (peerIP , peerEntry .mac , peerEntry .vtep )
211211 if err != nil {
212212 return fmt .Errorf ("peer delete operation failed: %w" , err )
213213 }
@@ -217,7 +217,7 @@ func (n *network) peerDelete(eid string, peerIP netip.Prefix, peerMac net.Hardwa
217217
218218// deleteNeighbor removes programming from the kernel for the given peer to be
219219// reachable through the VXLAN tunnel. It is the inverse of [driver.addNeighbor].
220- func (n * network ) deleteNeighbor (peerIP netip.Prefix , peerMac net. HardwareAddr , vtep netip.Addr ) error {
220+ func (n * network ) deleteNeighbor (peerIP netip.Prefix , peerMac hashable. MACAddr , vtep netip.Addr ) error {
221221 if n .sbox == nil {
222222 return nil
223223 }
@@ -233,14 +233,14 @@ func (n *network) deleteNeighbor(peerIP netip.Prefix, peerMac net.HardwareAddr,
233233 return fmt .Errorf ("could not find the subnet %q in network %q" , peerIP .String (), n .id )
234234 }
235235 // Remove fdb entry to the bridge for the peer mac
236- if n .fdbCnt .Add (ipmacOf (vtep , peerMac ), - 1 ) == 0 {
237- if err := n .sbox .DeleteNeighbor (vtep .AsSlice (), peerMac , osl .WithLinkName (s .vxlanName ), osl .WithFamily (syscall .AF_BRIDGE )); err != nil {
236+ if n .fdbCnt .Add (hashable . IPMACFrom (vtep , peerMac ), - 1 ) == 0 {
237+ if err := n .sbox .DeleteNeighbor (vtep .AsSlice (), peerMac . AsSlice () , osl .WithLinkName (s .vxlanName ), osl .WithFamily (syscall .AF_BRIDGE )); err != nil {
238238 return fmt .Errorf ("could not delete fdb entry in the sandbox: %w" , err )
239239 }
240240 }
241241
242242 // Delete neighbor entry for the peer IP
243- if err := n .sbox .DeleteNeighbor (peerIP .Addr ().AsSlice (), peerMac , osl .WithLinkName (s .vxlanName )); err != nil {
243+ if err := n .sbox .DeleteNeighbor (peerIP .Addr ().AsSlice (), peerMac . AsSlice () , osl .WithLinkName (s .vxlanName )); err != nil {
244244 return fmt .Errorf ("could not delete neighbor entry in the sandbox:%v" , err )
245245 }
246246
0 commit comments