File: options_linux.go

package info (click to toggle)
docker.io 28.5.2%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 69,048 kB
  • sloc: sh: 5,867; makefile: 863; ansic: 184; python: 162; asm: 159
file content (131 lines) | stat: -rw-r--r-- 3,448 bytes parent folder | download
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
package osl

import (
	"fmt"
	"net"
	"time"
)

func (nh *neigh) processNeighOptions(options ...NeighOption) {
	for _, opt := range options {
		if opt != nil {
			opt(nh)
		}
	}
}

// WithLinkName sets the srcName of the link to use in the neighbor entry.
func WithLinkName(name string) NeighOption {
	return func(nh *neigh) {
		nh.linkName = name
	}
}

// WithFamily sets the address-family for the neighbor entry. e.g. [syscall.AF_BRIDGE].
func WithFamily(family int) NeighOption {
	return func(nh *neigh) {
		nh.family = family
	}
}

// WithIsBridge sets whether the interface is a bridge.
func WithIsBridge(isBridge bool) IfaceOption {
	return func(i *Interface) error {
		i.bridge = isBridge
		return nil
	}
}

// WithMaster sets the master interface (if any) for this interface. The
// master interface name should refer to the srcName of a previously added
// interface of type bridge.
func WithMaster(name string) IfaceOption {
	return func(i *Interface) error {
		i.master = name
		return nil
	}
}

// WithMACAddress sets the interface MAC-address.
func WithMACAddress(mac net.HardwareAddr) IfaceOption {
	return func(i *Interface) error {
		i.mac = mac
		return nil
	}
}

// WithIPv4Address sets the IPv4 address of the interface.
func WithIPv4Address(addr *net.IPNet) IfaceOption {
	return func(i *Interface) error {
		i.address = addr
		return nil
	}
}

// WithIPv6Address sets the IPv6 address of the interface.
func WithIPv6Address(addr *net.IPNet) IfaceOption {
	return func(i *Interface) error {
		i.addressIPv6 = addr
		return nil
	}
}

// WithLinkLocalAddresses set the link-local IP addresses of the interface.
func WithLinkLocalAddresses(list []*net.IPNet) IfaceOption {
	return func(i *Interface) error {
		i.llAddrs = list
		return nil
	}
}

// WithRoutes sets the interface routes.
func WithRoutes(routes []*net.IPNet) IfaceOption {
	return func(i *Interface) error {
		i.routes = routes
		return nil
	}
}

// WithSysctls sets the interface sysctls.
func WithSysctls(sysctls []string) IfaceOption {
	return func(i *Interface) error {
		i.sysctls = sysctls
		return nil
	}
}

// WithAdvertiseAddrNMsgs sets the number of unsolicited ARP/NA messages that will
// be sent to advertise a network interface's addresses.
func WithAdvertiseAddrNMsgs(nMsgs int) IfaceOption {
	return func(i *Interface) error {
		if nMsgs < AdvertiseAddrNMsgsMin || nMsgs > AdvertiseAddrNMsgsMax {
			return fmt.Errorf("AdvertiseAddrNMsgs %d is not in the range %d to %d",
				nMsgs, AdvertiseAddrNMsgsMin, AdvertiseAddrNMsgsMax)
		}
		i.advertiseAddrNMsgs = nMsgs
		return nil
	}
}

// WithAdvertiseAddrInterval sets the interval between unsolicited ARP/NA messages
// sent to advertise a network interface's addresses.
func WithAdvertiseAddrInterval(interval time.Duration) IfaceOption {
	return func(i *Interface) error {
		if interval < AdvertiseAddrIntervalMin || interval > AdvertiseAddrIntervalMax {
			return fmt.Errorf("AdvertiseAddrNMsgs %d is not in the range %v to %v milliseconds",
				interval, AdvertiseAddrIntervalMin, AdvertiseAddrIntervalMax)
		}
		i.advertiseAddrInterval = interval
		return nil
	}
}

// WithCreatedInContainer can be used to say the network driver created the
// interface in the container's network namespace (and, therefore, it doesn't
// need to be moved into that namespace.)
func WithCreatedInContainer(cic bool) IfaceOption {
	return func(i *Interface) error {
		i.createdInContainer = cic
		return nil
	}
}