joinleave_windows.go 2.8 KB

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