github.com/jfrazelle/docker@v1.1.2-0.20210712172922-bf78e25fe508/libnetwork/drivers/ipvlan/ipvlan.go (about)

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