1package ipvlan
2
3import (
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
14const (
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
25var driverModeOpt = ipvlanType + modeOpt // mode -o ipvlan_mode
26
27type endpointTable map[string]*endpoint
28
29type networkTable map[string]*network
30
31type driver struct {
32	networks networkTable
33	sync.Once
34	sync.Mutex
35	store datastore.DataStore
36}
37
38type 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
49type 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
59func 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	d.initStore(config)
68
69	return dc.RegisterDriver(ipvlanType, d, c)
70}
71
72func (d *driver) NetworkAllocate(id string, option map[string]string, ipV4Data, ipV6Data []driverapi.IPAMData) (map[string]string, error) {
73	return nil, types.NotImplementedErrorf("not implemented")
74}
75
76func (d *driver) NetworkFree(id string) error {
77	return types.NotImplementedErrorf("not implemented")
78}
79
80func (d *driver) EndpointOperInfo(nid, eid string) (map[string]interface{}, error) {
81	return make(map[string]interface{}, 0), nil
82}
83
84func (d *driver) Type() string {
85	return ipvlanType
86}
87
88func (d *driver) IsBuiltIn() bool {
89	return true
90}
91
92func (d *driver) ProgramExternalConnectivity(nid, eid string, options map[string]interface{}) error {
93	return nil
94}
95
96func (d *driver) RevokeExternalConnectivity(nid, eid string) error {
97	return nil
98}
99
100// DiscoverNew is a notification for a new discovery event.
101func (d *driver) DiscoverNew(dType discoverapi.DiscoveryType, data interface{}) error {
102	return nil
103}
104
105// DiscoverDelete is a notification for a discovery delete event.
106func (d *driver) DiscoverDelete(dType discoverapi.DiscoveryType, data interface{}) error {
107	return nil
108}
109
110func (d *driver) EventNotify(etype driverapi.EventType, nid, tableName, key string, value []byte) {
111}
112
113func (d *driver) DecodeTableEntry(tablename string, key string, value []byte) (string, map[string]string) {
114	return "", nil
115}
116