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
|
// +build windows
package ipmanager
import (
"encoding/binary"
"log"
"net"
"github.com/cybertec-postgresql/vip-manager/iphlpapi"
)
// configureAddress assigns virtual IP address
func (c *BasicConfigurer) configureAddress() bool {
log.Printf("Configuring address %s on %s", c.getCIDR(), c.Iface.Name)
var (
ip uint32 = binary.LittleEndian.Uint32(c.VIP.To4())
mask uint32 = binary.LittleEndian.Uint32(c.Netmask)
nteinstance uint32
)
iface, err := net.InterfaceByName(c.Iface.Name)
if err != nil {
log.Printf("Got error: %v", err)
return false
}
err = iphlpapi.AddIPAddress(ip, mask, uint32(iface.Index), &c.ntecontext, &nteinstance)
if err != nil {
log.Printf("Got error: %v", err)
return false
}
// For now it is save to say that also working even if a
// gratuitous arp message could not be send but logging an
// errror should be enough.
//_ = c.ARPSendGratuitous()
return true
}
// deconfigureAddress drops virtual IP address
func (c *BasicConfigurer) deconfigureAddress() bool {
log.Printf("Removing address %s on %s", c.getCIDR(), c.Iface.Name)
err := iphlpapi.DeleteIPAddress(c.ntecontext)
if err != nil {
log.Printf("Got error: %v", err)
return false
}
return true
}
|