github.com/zhuohuang-hust/src-cbuild@v0.0.0-20230105071821-c7aab3e7c840/mergeCode/libnetwork/drivers/macvlan/macvlan.go (about)

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