Skip to content

Commit

Permalink
Merge pull request #412 from swiftstack/bugfix-ha-push
Browse files Browse the repository at this point in the history
Fix to accept IP addresses that include a netmask for VirtualIPAddr..
  • Loading branch information
craig harmer authored Dec 24, 2019
2 parents 6d65c70 + 45d8cad commit c75c8f8
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 14 deletions.
28 changes: 19 additions & 9 deletions confgen/api_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package confgen
import (
"fmt"
"io/ioutil"
"net"
"os"
"strconv"
"strings"
Expand Down Expand Up @@ -122,12 +123,13 @@ type SMBVG struct {

// VolumeGroup contains VolumeGroup conf settings
type VolumeGroup struct {
PrimaryPeer string //
SMB SMBVG // SMB specific settings of the VG
VirtualHostName string // Must be unique
VirtualIPAddr string // Must be unique
VolumeGroupName string // Must be unique
VolumeMap volumeMap //
PrimaryPeer string //
SMB SMBVG // SMB specific settings of the VG
VirtualHostName string // Must be unique
VirtualIPAddr net.IP // Must be unique
VirtualIPMask *net.IPNet // not necessarily unique
VolumeGroupName string // Must be unique
VolumeMap volumeMap //
}

type volumeGroupMap map[string]*VolumeGroup // Key=VolumeGroup.volumeGroupName
Expand Down Expand Up @@ -774,13 +776,21 @@ func populateVolumeGroup(confMap conf.ConfMap, globalVolumeGroupMap volumeGroupM
return
}

// Fetch the virtual IP address for the group and strip off the netmask (if any).
// virtualIPAddrSet is not used so we don't "fix it".
// Fetch the virtual IP address for the group. It must be be a valid
// (parsable) CIDR notation IP address. Hold onto the netmask
// separtely. This code also has the effect of converting an IP address to
// canonical form (RFC-4291 or RFC-4632).
virtualIPAddr, err = fetchStringSet(confMap, volumeGroupSection, "VirtualIPAddr", virtualIPAddrSet)
if nil != err {
return
}
volumeGroup.VirtualIPAddr = strings.Split(virtualIPAddr, "/")[0]
volumeGroup.VirtualIPAddr, volumeGroup.VirtualIPMask, err = net.ParseCIDR(virtualIPAddr)
if nil != err {
err = fmt.Errorf("ParseCIDR() for config file variable [%s][%s] value '%s' failed: %v",
volumeGroupSection, "VirtualIPAddr", virtualIPAddr, err)

return
}

volumeGroup.VirtualHostName, err = fetchStringSet(confMap, volumeGroupSection, "VirtualHostname", virtualHostNameSet)
if nil != err {
Expand Down
2 changes: 1 addition & 1 deletion confgen/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func createSMBConf(initialDirPath string, localVolumeGroupMap volumeGroupMap) (e
}

for _, volumeGroup = range localVolumeGroupMap {
vipDirPath = initialDirPath + "/" + vipsDirName + "/" + volumeGroup.VirtualIPAddr
vipDirPath = initialDirPath + "/" + vipsDirName + "/" + volumeGroup.VirtualIPAddr.String()

err = os.Mkdir(vipDirPath, confDirPerm)
if nil != err {
Expand Down
26 changes: 22 additions & 4 deletions liveness/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,10 +597,19 @@ func (dummy *globalsStruct) SignaledFinish(confMap conf.ConfMap) (err error) {
if "" == virtualIPAddr {
volumeGroup.virtualIPAddr = globals.myPublicIPAddr
} else {

// virtualIPAddr must be a valid IP address or valid
// IP address in CIDR notation
volumeGroup.virtualIPAddr = net.ParseIP(virtualIPAddr)
if nil == volumeGroup.virtualIPAddr {
err = fmt.Errorf("Cannot parse [VolumeGroup:%v]VirtualIPAddr", volumeGroupName)
return

volumeGroup.virtualIPAddr, _, err = net.ParseCIDR(virtualIPAddr)
if err != nil {
err = fmt.Errorf("Cannot parse [VolumeGroup:%v]VirtualIPAddr: '%s' "+
" as IP address or CIDR IP address: %v",
volumeGroupName, virtualIPAddr, err)
return
}
}
}

Expand All @@ -627,10 +636,19 @@ func (dummy *globalsStruct) SignaledFinish(confMap conf.ConfMap) (err error) {
if "" == virtualIPAddr {
volumeGroup.virtualIPAddr = peer.publicIPAddr
} else {

// virtualIPAddr must be a valid IP address or valid
// IP address in CIDR notation
volumeGroup.virtualIPAddr = net.ParseIP(virtualIPAddr)
if nil == volumeGroup.virtualIPAddr {
err = fmt.Errorf("Cannot parse [VolumeGroup:%v]VirtualIPAddr", volumeGroupName)
return

volumeGroup.virtualIPAddr, _, err = net.ParseCIDR(virtualIPAddr)
if err != nil {
err = fmt.Errorf("Cannot parse [VolumeGroup:%v]VirtualIPAddr: '%s' "+
" as IP address or CIDR IP address: %v",
volumeGroupName, virtualIPAddr, err)
return
}
}
}

Expand Down

0 comments on commit c75c8f8

Please sign in to comment.