github.com/rish1988/moby@v25.0.2+incompatible/libnetwork/drivers/windows/overlay/joinleave_windows.go (about) 1 package overlay 2 3 import ( 4 "context" 5 "fmt" 6 "net" 7 8 "github.com/containerd/log" 9 "github.com/docker/docker/libnetwork/driverapi" 10 "github.com/docker/docker/libnetwork/types" 11 "github.com/gogo/protobuf/proto" 12 ) 13 14 // Join method is invoked when a Sandbox is attached to an endpoint. 15 func (d *driver) Join(nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, options map[string]interface{}) error { 16 if err := validateID(nid, eid); err != nil { 17 return err 18 } 19 20 n := d.network(nid) 21 if n == nil { 22 return fmt.Errorf("could not find network with id %s", nid) 23 } 24 25 ep := n.endpoint(eid) 26 if ep == nil { 27 return fmt.Errorf("could not find endpoint with id %s", eid) 28 } 29 30 buf, err := proto.Marshal(&PeerRecord{ 31 EndpointIP: ep.addr.String(), 32 EndpointMAC: ep.mac.String(), 33 TunnelEndpointIP: n.providerAddress, 34 }) 35 if err != nil { 36 return err 37 } 38 39 if err := jinfo.AddTableEntry(ovPeerTable, eid, buf); err != nil { 40 log.G(context.TODO()).Errorf("overlay: Failed adding table entry to joininfo: %v", err) 41 } 42 43 if ep.disablegateway { 44 jinfo.DisableGatewayService() 45 } 46 47 return nil 48 } 49 50 func (d *driver) EventNotify(etype driverapi.EventType, nid, tableName, key string, value []byte) { 51 if tableName != ovPeerTable { 52 log.G(context.TODO()).Errorf("Unexpected table notification for table %s received", tableName) 53 return 54 } 55 56 eid := key 57 58 var peer PeerRecord 59 if err := proto.Unmarshal(value, &peer); err != nil { 60 log.G(context.TODO()).Errorf("Failed to unmarshal peer record: %v", err) 61 return 62 } 63 64 n := d.network(nid) 65 if n == nil { 66 return 67 } 68 69 // Ignore local peers. We already know about them and they 70 // should not be added to vxlan fdb. 71 if peer.TunnelEndpointIP == n.providerAddress { 72 return 73 } 74 75 addr, err := types.ParseCIDR(peer.EndpointIP) 76 if err != nil { 77 log.G(context.TODO()).Errorf("Invalid peer IP %s received in event notify", peer.EndpointIP) 78 return 79 } 80 81 mac, err := net.ParseMAC(peer.EndpointMAC) 82 if err != nil { 83 log.G(context.TODO()).Errorf("Invalid mac %s received in event notify", peer.EndpointMAC) 84 return 85 } 86 87 vtep := net.ParseIP(peer.TunnelEndpointIP) 88 if vtep == nil { 89 log.G(context.TODO()).Errorf("Invalid VTEP %s received in event notify", peer.TunnelEndpointIP) 90 return 91 } 92 93 if etype == driverapi.Delete { 94 d.peerDelete(nid, eid, addr.IP, addr.Mask, mac, vtep, true) 95 return 96 } 97 98 err = d.peerAdd(nid, eid, addr.IP, addr.Mask, mac, vtep, true) 99 if err != nil { 100 log.G(context.TODO()).Errorf("peerAdd failed (%v) for ip %s with mac %s", err, addr.IP.String(), mac.String()) 101 } 102 } 103 104 func (d *driver) DecodeTableEntry(tablename string, key string, value []byte) (string, map[string]string) { 105 return "", nil 106 } 107 108 // Leave method is invoked when a Sandbox detaches from an endpoint. 109 func (d *driver) Leave(nid, eid string) error { 110 if err := validateID(nid, eid); err != nil { 111 return err 112 } 113 114 return nil 115 }