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

     1  package ipvlan
     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  	ipvlanType          = "ipvlan" // driver type name
    19  	modeL2              = "l2"     // ipvlan mode l2 is the default
    20  	modeL3              = "l3"     // ipvlan L3 mode
    21  	parentOpt           = "parent" // parent interface -o parent
    22  	modeOpt             = "_mode"  // ipvlan mode ux opt suffix
    23  )
    24  
    25  var driverModeOpt = ipvlanType + modeOpt // mode -o ipvlan_mode
    26  
    27  type endpointTable map[string]*endpoint
    28  
    29  type networkTable map[string]*network
    30  
    31  type driver struct {
    32  	networks networkTable
    33  	sync.Once
    34  	sync.Mutex
    35  	store datastore.DataStore
    36  }
    37  
    38  type endpoint struct {
    39  	id       string
    40  	nid      string
    41  	mac      net.HardwareAddr
    42  	addr     *net.IPNet
    43  	addrv6   *net.IPNet
    44  	srcName  string
    45  	dbIndex  uint64
    46  	dbExists bool
    47  }
    48  
    49  type network struct {
    50  	id        string
    51  	sbox      osl.Sandbox
    52  	endpoints endpointTable
    53  	driver    *driver
    54  	config    *configuration
    55  	sync.Mutex
    56  }
    57  
    58  // Init initializes and registers the libnetwork ipvlan driver
    59  func Init(dc driverapi.DriverCallback, config map[string]interface{}) error {
    60  	c := driverapi.Capability{
    61  		DataScope: datastore.LocalScope,
    62  	}
    63  	d := &driver{
    64  		networks: networkTable{},
    65  	}
    66  	d.initStore(config)
    67  
    68  	return dc.RegisterDriver(ipvlanType, d, c)
    69  }
    70  
    71  func (d *driver) NetworkAllocate(id string, option map[string]string, ipV4Data, ipV6Data []driverapi.IPAMData) (map[string]string, error) {
    72  	return nil, types.NotImplementedErrorf("not implemented")
    73  }
    74  
    75  func (d *driver) NetworkFree(id string) error {
    76  	return types.NotImplementedErrorf("not implemented")
    77  }
    78  
    79  func (d *driver) EndpointOperInfo(nid, eid string) (map[string]interface{}, error) {
    80  	return make(map[string]interface{}, 0), nil
    81  }
    82  
    83  func (d *driver) Type() string {
    84  	return ipvlanType
    85  }
    86  
    87  func (d *driver) ProgramExternalConnectivity(nid, eid string, options map[string]interface{}) error {
    88  	return nil
    89  }
    90  
    91  func (d *driver) RevokeExternalConnectivity(nid, eid string) error {
    92  	return nil
    93  }
    94  
    95  // DiscoverNew is a notification for a new discovery event.
    96  func (d *driver) DiscoverNew(dType discoverapi.DiscoveryType, data interface{}) error {
    97  	return nil
    98  }
    99  
   100  // DiscoverDelete is a notification for a discovery delete event.
   101  func (d *driver) DiscoverDelete(dType discoverapi.DiscoveryType, data interface{}) error {
   102  	return nil
   103  }
   104  
   105  func (d *driver) EventNotify(etype driverapi.EventType, nid, tableName, key string, value []byte) {
   106  }