Skip to content

Commit

Permalink
Merge pull request #61 from rgooch/master
Browse files Browse the repository at this point in the history
Machine configuration: support marking interface with IP address as VLAN trunk.
  • Loading branch information
rgooch committed Mar 15, 2020
2 parents 84c3b1d + 944aa88 commit 209c605
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
10 changes: 8 additions & 2 deletions lib/net/configurator/compute.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func compute(machineInfo fm_proto.GetMachineInfoResponse,
netconf := &NetworkConfig{}
networkEntries := getNetworkEntries(machineInfo)
interfaces := make(map[string]net.Interface, len(_interfaces))
var vlanInterfaceNames []string
for name, iface := range _interfaces {
interfaces[name] = iface
}
Expand Down Expand Up @@ -155,6 +156,10 @@ func compute(machineInfo fm_proto.GetMachineInfoResponse,
} else if netconf.DefaultSubnet == nil {
netconf.DefaultSubnet = subnet
}
if networkEntry.VlanTrunk {
vlanInterfaceNames = append(vlanInterfaceNames, iface.Name)
netconf.vlanRawDevice = iface.Name
}
}
// All remaining interfaces which are marked as up will be used for VLAN
// trunk. If there multiple interfaces, they will be bonded.
Expand All @@ -164,13 +169,14 @@ func compute(machineInfo fm_proto.GetMachineInfoResponse,
} else {
netconf.bondSlaves = append(netconf.bondSlaves, name)
netconf.vlanRawDevice = name
vlanInterfaceNames = append(vlanInterfaceNames, name)
}
}
if len(interfaces) > 1 {
if len(vlanInterfaceNames) > 1 {
netconf.vlanRawDevice = "bond0"
}
sort.Strings(netconf.bondSlaves)
if len(interfaces) > 0 {
if len(vlanInterfaceNames) > 0 {
for _, networkEntry := range bondedNetworkEntries {
subnet := findMatchingSubnet(machineInfo.Subnets,
networkEntry.HostIpAddress)
Expand Down
28 changes: 16 additions & 12 deletions lib/net/configurator/debian.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func (netconf *NetworkConfig) printDebian(writer io.Writer) error {
fmt.Fprintln(writer)
fmt.Fprintln(writer, "auto lo")
fmt.Fprintln(writer, "iface lo inet loopback")
configuredInterfaces := make(map[string]struct{})
for _, iface := range netconf.normalInterfaces {
fmt.Fprintln(writer)
name := iface.netInterface.Name
Expand All @@ -37,6 +38,7 @@ func (netconf *NetworkConfig) printDebian(writer io.Writer) error {
iface.netInterface.HardwareAddr)
fmt.Fprintf(writer, "\tbridge_ports %s\n", iface.netInterface.Name)
}
configuredInterfaces[name] = struct{}{}
}
for _, iface := range netconf.bridgeOnlyInterfaces {
fmt.Fprintln(writer)
Expand All @@ -48,19 +50,21 @@ func (netconf *NetworkConfig) printDebian(writer io.Writer) error {
fmt.Fprintf(writer, "\tbridge_ports %s\n", iface.netInterface.Name)
}
if netconf.vlanRawDevice != "" {
fmt.Fprintln(writer)
fmt.Fprintf(writer, "auto %s\n", netconf.vlanRawDevice)
fmt.Fprintf(writer, "iface %s inet manual\n", netconf.vlanRawDevice)
if len(netconf.bondSlaves) > 1 {
fmt.Fprintf(writer, "\tup ip link set %s mtu 9000\n",
netconf.vlanRawDevice)
fmt.Fprintln(writer, "\tbond-mode 802.3ad")
fmt.Fprintln(writer, "\tbond-xmit_hash_policy 1")
fmt.Fprint(writer, "\tslaves")
for _, name := range netconf.bondSlaves {
fmt.Fprint(writer, " ", name)
}
if _, ok := configuredInterfaces[netconf.vlanRawDevice]; !ok {
fmt.Fprintln(writer)
fmt.Fprintf(writer, "auto %s\n", netconf.vlanRawDevice)
fmt.Fprintf(writer, "iface %s inet manual\n", netconf.vlanRawDevice)
if len(netconf.bondSlaves) > 1 {
fmt.Fprintf(writer, "\tup ip link set %s mtu 9000\n",
netconf.vlanRawDevice)
fmt.Fprintln(writer, "\tbond-mode 802.3ad")
fmt.Fprintln(writer, "\tbond-xmit_hash_policy 1")
fmt.Fprint(writer, "\tslaves")
for _, name := range netconf.bondSlaves {
fmt.Fprint(writer, " ", name)
}
fmt.Fprintln(writer)
}
}
for _, iface := range netconf.bondedInterfaces {
fmt.Fprintln(writer)
Expand Down
1 change: 1 addition & 0 deletions proto/fleetmanager/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ type NetworkEntry struct {
HostIpAddress net.IP `json:",omitempty"`
HostMacAddress HardwareAddr `json:",omitempty"`
SubnetId string `json:",omitempty"`
VlanTrunk bool `json:",omitempty"`
}

type PowerOnMachineRequest struct {
Expand Down

0 comments on commit 209c605

Please sign in to comment.