@@ -33,6 +33,18 @@ func mustParseCIDR(s string) *net.IPNet {
33
33
return ipNet
34
34
}
35
35
36
+ // AddressConfigType defines valid network link configuration types.
37
+ // See interfaces(5) for details.
38
+ type AddressConfigType string
39
+
40
+ const (
41
+ ConfigUnknown AddressConfigType = ""
42
+ ConfigDHCP AddressConfigType = "dhcp"
43
+ ConfigStatic AddressConfigType = "static"
44
+ ConfigManual AddressConfigType = "manual"
45
+ ConfigLoopback AddressConfigType = "loopback"
46
+ )
47
+
36
48
// AddressType represents the possible ways of specifying a machine location by
37
49
// either a hostname resolvable by dns lookup, or IPv4 or IPv6 address.
38
50
type AddressType string
@@ -83,6 +95,12 @@ type Address interface {
83
95
84
96
// AddressScope returns the scope of the address.
85
97
AddressScope () Scope
98
+
99
+ // AddressCIDR returns the subnet CIDR of the address.
100
+ AddressCIDR () string
101
+
102
+ // AddressConfigType returns the configuration method of the address.
103
+ AddressConfigType () AddressConfigType
86
104
}
87
105
88
106
// ScopeMatchFunc is an alias for a function that accepts an Address,
@@ -105,9 +123,22 @@ func ExactScopeMatch(addr Address, addrScopes ...Scope) bool {
105
123
// directly on a machine or container, or returned for requests where space
106
124
// information is irrelevant to usage.
107
125
type MachineAddress struct {
126
+ // Value is an IP address or hostname.
108
127
Value string
109
- Type AddressType
128
+
129
+ // Type indicates the form of the address value;
130
+ // IPv4, IPv6 or host-name.
131
+ Type AddressType
132
+
133
+ // Scope indicates the visibility of this address.
110
134
Scope Scope
135
+
136
+ // CIDR is used for IP addresses to indicate
137
+ // the subnet that they are part of.
138
+ CIDR string
139
+
140
+ // ConfigType denotes how this address was configured.
141
+ ConfigType AddressConfigType
111
142
}
112
143
113
144
// Host returns the value for the host-name/IP address.
@@ -125,6 +156,16 @@ func (a MachineAddress) AddressScope() Scope {
125
156
return a .Scope
126
157
}
127
158
159
+ // AddressCIDR returns the subnet CIDR of the address.
160
+ func (a MachineAddress ) AddressCIDR () string {
161
+ return a .CIDR
162
+ }
163
+
164
+ // AddressConfigType returns the configuration method of the address.
165
+ func (a MachineAddress ) AddressConfigType () AddressConfigType {
166
+ return a .ConfigType
167
+ }
168
+
128
169
// GoString implements fmt.GoStringer.
129
170
func (a MachineAddress ) GoString () string {
130
171
return a .String ()
@@ -146,6 +187,8 @@ func (a MachineAddress) IP() net.IP {
146
187
147
188
// ValueForCIDR returns the value of the address combined with a subnet mask
148
189
// indicated by the input CIDR.
190
+ // TODO (manadart 2020-07-10): This should evolve to use the address CIDR
191
+ // directly instead of receiving a value, once we clean up InterfaceInfo.
149
192
func (a MachineAddress ) ValueForCIDR (cidr string ) (string , error ) {
150
193
_ , ipNet , err := net .ParseCIDR (cidr )
151
194
if err != nil {
@@ -313,7 +356,7 @@ func (a ProviderAddress) String() string {
313
356
buf .WriteByte ('@' )
314
357
buf .WriteString (string (a .SpaceName ))
315
358
}
316
- if a .ProviderSpaceID != Id ( "" ) {
359
+ if a .ProviderSpaceID != "" {
317
360
if ! spaceFound {
318
361
buf .WriteByte ('@' )
319
362
}
@@ -448,13 +491,6 @@ func (a SpaceAddress) GoString() string {
448
491
return a .String ()
449
492
}
450
493
451
- // Converts the space address to a net.IP address assuming the space address is
452
- // either v4 or v6. If the SpaceAddress value is not a valid ip address nil is
453
- // returned
454
- func (a SpaceAddress ) IP () net.IP {
455
- return net .ParseIP (a .Value )
456
- }
457
-
458
494
// String returns a string representation of the address, in the form:
459
495
// `<scope>:<address-value>@space:<space-id>`; for example:
460
496
//
0 commit comments