github.com/adityamillind98/moby@v23.0.0-rc.4+incompatible/libnetwork/drivers/macvlan/macvlan.go (about)

     1  //go:build linux
     2  // +build linux
     3  
     4  package macvlan
     5  
     6  import (
     7  	"net"
     8  	"sync"
     9  
    10  	"github.com/docker/docker/libnetwork/datastore"
    11  	"github.com/docker/docker/libnetwork/discoverapi"
    12  	"github.com/docker/docker/libnetwork/driverapi"
    13  	"github.com/docker/docker/libnetwork/types"
    14  )
    15  
    16  const (
    17  	vethLen             = 7
    18  	containerVethPrefix = "eth"
    19  	vethPrefix          = "veth"
    20  	macvlanType         = "macvlan"  // driver type name
    21  	modePrivate         = "private"  // macvlan mode private
    22  	modeVepa            = "vepa"     // macvlan mode vepa
    23  	modeBridge          = "bridge"   // macvlan mode bridge
    24  	modePassthru        = "passthru" // macvlan mode passthrough
    25  	parentOpt           = "parent"   // parent interface -o parent
    26  	modeOpt             = "_mode"    // macvlan mode ux opt suffix
    27  )
    28  
    29  var driverModeOpt = macvlanType + modeOpt // mode --option macvlan_mode
    30  
    31  type endpointTable map[string]*endpoint
    32  
    33  type networkTable map[string]*network
    34  
    35  type driver struct {
    36  	networks networkTable
    37  	sync.Once
    38  	sync.Mutex
    39  	store datastore.DataStore
    40  }
    41  
    42  type endpoint struct {
    43  	id       string
    44  	nid      string
    45  	mac      net.HardwareAddr
    46  	addr     *net.IPNet
    47  	addrv6   *net.IPNet
    48  	srcName  string
    49  	dbIndex  uint64
    50  	dbExists bool
    51  }
    52  
    53  type network struct {
    54  	id        string
    55  	endpoints endpointTable
    56  	driver    *driver
    57  	config    *configuration
    58  	sync.Mutex
    59  }
    60  
    61  // Init initializes and registers the libnetwork macvlan driver
    62  func Init(dc driverapi.DriverCallback, config map[string]interface{}) error {
    63  	c := driverapi.Capability{
    64  		DataScope:         datastore.LocalScope,
    65  		ConnectivityScope: datastore.GlobalScope,
    66  	}
    67  	d := &driver{
    68  		networks: networkTable{},
    69  	}
    70  	if err := d.initStore(config); err != nil {
    71  		return err
    72  	}
    73  
    74  	return dc.RegisterDriver(macvlanType, d, c)
    75  }
    76  
    77  func (d *driver) NetworkAllocate(id string, option map[string]string, ipV4Data, ipV6Data []driverapi.IPAMData) (map[string]string, error) {
    78  	return nil, types.NotImplementedErrorf("not implemented")
    79  }
    80  
    81  func (d *driver) NetworkFree(id string) error {
    82  	return types.NotImplementedErrorf("not implemented")
    83  }
    84  
    85  func (d *driver) EndpointOperInfo(nid, eid string) (map[string]interface{}, error) {
    86  	return make(map[string]interface{}), nil
    87  }
    88  
    89  func (d *driver) Type() string {
    90  	return macvlanType
    91  }
    92  
    93  func (d *driver) IsBuiltIn() bool {
    94  	return true
    95  }
    96  
    97  func (d *driver) ProgramExternalConnectivity(nid, eid string, options map[string]interface{}) error {
    98  	return nil
    99  }
   100  
   101  func (d *driver) RevokeExternalConnectivity(nid, eid string) error {
   102  	return nil
   103  }
   104  
   105  // DiscoverNew is a notification for a new discovery event
   106  func (d *driver) DiscoverNew(dType discoverapi.DiscoveryType, data interface{}) error {
   107  	return nil
   108  }
   109  
   110  // DiscoverDelete is a notification for a discovery delete event
   111  func (d *driver) DiscoverDelete(dType discoverapi.DiscoveryType, data interface{}) error {
   112  	return nil
   113  }
   114  
   115  func (d *driver) EventNotify(etype driverapi.EventType, nid, tableName, key string, value []byte) {
   116  }
   117  
   118  func (d *driver) DecodeTableEntry(tablename string, key string, value []byte) (string, map[string]string) {
   119  	return "", nil
   120  }