This file is indexed.

/usr/share/gocode/src/github.com/docker/libnetwork/drivers/windows/overlay/ov_network_local_windows.go is in golang-github-docker-libnetwork-dev 0.8.0-dev.2+git20170202.599.45b4086-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
package overlay

import (
	"encoding/json"
	"fmt"
	"sync"

	"github.com/Microsoft/hcsshim"
	"github.com/Sirupsen/logrus"
	"github.com/docker/libnetwork/datastore"
)

const overlayNetworkPrefix = "overlay/network"

type localNetwork struct {
	id              string
	hnsID           string
	providerAddress string
	dbIndex         uint64
	dbExists        bool
	sync.Mutex
}

func (d *driver) findHnsNetwork(n *network) error {
	ln, err := d.getLocalNetworkFromStore(n.id)

	if err != nil {
		return err
	}

	if ln == nil {
		subnets := []hcsshim.Subnet{}

		for _, s := range n.subnets {
			subnet := hcsshim.Subnet{
				AddressPrefix: s.subnetIP.String(),
			}

			if s.gwIP != nil {
				subnet.GatewayAddress = s.gwIP.IP.String()
			}

			vsidPolicy, err := json.Marshal(hcsshim.VsidPolicy{
				Type: "VSID",
				VSID: uint(s.vni),
			})

			if err != nil {
				return err
			}

			subnet.Policies = append(subnet.Policies, vsidPolicy)
			subnets = append(subnets, subnet)
		}

		network := &hcsshim.HNSNetwork{
			Name:               n.name,
			Type:               d.Type(),
			Subnets:            subnets,
			NetworkAdapterName: n.interfaceName,
		}

		configurationb, err := json.Marshal(network)
		if err != nil {
			return err
		}

		configuration := string(configurationb)
		logrus.Infof("HNSNetwork Request =%v", configuration)

		hnsresponse, err := hcsshim.HNSNetworkRequest("POST", "", configuration)
		if err != nil {
			return err
		}

		n.hnsId = hnsresponse.Id
		n.providerAddress = hnsresponse.ManagementIP

		// Save local host specific info
		if err := d.writeLocalNetworkToStore(n); err != nil {
			return fmt.Errorf("failed to update data store for network %v: %v", n.id, err)
		}
	} else {
		n.hnsId = ln.hnsID
		n.providerAddress = ln.providerAddress
	}

	return nil
}

func (d *driver) getLocalNetworkFromStore(nid string) (*localNetwork, error) {

	if d.localStore == nil {
		return nil, fmt.Errorf("overlay local store not initialized, network not found")
	}

	n := &localNetwork{id: nid}
	if err := d.localStore.GetObject(datastore.Key(n.Key()...), n); err != nil {
		return nil, nil
	}

	return n, nil
}

func (d *driver) deleteLocalNetworkFromStore(n *network) error {
	if d.localStore == nil {
		return fmt.Errorf("overlay local store not initialized, network not deleted")
	}

	ln, err := d.getLocalNetworkFromStore(n.id)

	if err != nil {
		return err
	}

	if err = d.localStore.DeleteObjectAtomic(ln); err != nil {
		return err
	}

	return nil
}

func (d *driver) writeLocalNetworkToStore(n *network) error {
	if d.localStore == nil {
		return fmt.Errorf("overlay local store not initialized, network not added")
	}

	ln := &localNetwork{
		id:              n.id,
		hnsID:           n.hnsId,
		providerAddress: n.providerAddress,
	}

	if err := d.localStore.PutObjectAtomic(ln); err != nil {
		return err
	}
	return nil
}

func (n *localNetwork) DataScope() string {
	return datastore.LocalScope
}

func (n *localNetwork) New() datastore.KVObject {
	return &localNetwork{}
}

func (n *localNetwork) CopyTo(o datastore.KVObject) error {
	dstep := o.(*localNetwork)
	*dstep = *n
	return nil
}

func (n *localNetwork) Key() []string {
	return []string{overlayNetworkPrefix, n.id}
}

func (n *localNetwork) KeyPrefix() []string {
	return []string{overlayNetworkPrefix}
}

func (n *localNetwork) Index() uint64 {
	return n.dbIndex
}

func (n *localNetwork) SetIndex(index uint64) {
	n.dbIndex = index
	n.dbExists = true
}

func (n *localNetwork) Exists() bool {
	return n.dbExists
}

func (n *localNetwork) Skip() bool {
	return false
}

func (n *localNetwork) Value() []byte {
	b, err := json.Marshal(n)
	if err != nil {
		return nil
	}
	return b
}

func (n *localNetwork) SetValue(value []byte) error {
	return json.Unmarshal(value, n)
}

func (n *localNetwork) MarshalJSON() ([]byte, error) {
	networkMap := make(map[string]interface{})

	networkMap["id"] = n.id
	networkMap["hnsID"] = n.hnsID
	networkMap["providerAddress"] = n.providerAddress
	return json.Marshal(networkMap)
}

func (n *localNetwork) UnmarshalJSON(value []byte) error {
	var networkMap map[string]interface{}

	json.Unmarshal(value, &networkMap)

	n.id = networkMap["id"].(string)
	n.hnsID = networkMap["hnsID"].(string)
	n.providerAddress = networkMap["providerAddress"].(string)
	return nil
}