github.com/pwn-term/docker@v0.0.0-20210616085119-6e977cce2565/libnetwork/drivers/windows/overlay/joinleave_windows.go (about)

     1  package overlay
     2  
     3  import (
     4  	"fmt"
     5  	"net"
     6  
     7  	"github.com/docker/libnetwork/driverapi"
     8  	"github.com/docker/libnetwork/types"
     9  	"github.com/gogo/protobuf/proto"
    10  	"github.com/sirupsen/logrus"
    11  )
    12  
    13  // Join method is invoked when a Sandbox is attached to an endpoint.
    14  func (d *driver) Join(nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, options map[string]interface{}) error {
    15  	if err := validateID(nid, eid); err != nil {
    16  		return err
    17  	}
    18  
    19  	n := d.network(nid)
    20  	if n == nil {
    21  		return fmt.Errorf("could not find network with id %s", nid)
    22  	}
    23  
    24  	ep := n.endpoint(eid)
    25  	if ep == nil {
    26  		return fmt.Errorf("could not find endpoint with id %s", eid)
    27  	}
    28  
    29  	buf, err := proto.Marshal(&PeerRecord{
    30  		EndpointIP:       ep.addr.String(),
    31  		EndpointMAC:      ep.mac.String(),
    32  		TunnelEndpointIP: n.providerAddress,
    33  	})
    34  
    35  	if err != nil {
    36  		return err
    37  	}
    38  
    39  	if err := jinfo.AddTableEntry(ovPeerTable, eid, buf); err != nil {
    40  		logrus.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  		logrus.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  		logrus.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  		logrus.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  		logrus.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  		logrus.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  		logrus.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  }