Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 61 additions & 42 deletions README.md

Large diffs are not rendered by default.

7 changes: 1 addition & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ go 1.23.0
toolchain go1.24.1

require (
github.com/google/gopacket v1.1.19
github.com/hashicorp/consul/api v1.31.2
github.com/mdlayher/arp v0.0.0-20220512170110-6706a2966875
github.com/spf13/pflag v1.0.6
github.com/spf13/viper v1.20.0
go.etcd.io/etcd/client/v3 v3.5.19
Expand All @@ -31,12 +31,8 @@ require (
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
github.com/hashicorp/golang-lru v1.0.2 // indirect
github.com/hashicorp/serf v0.10.1 // indirect
github.com/josharian/native v1.1.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mdlayher/ethernet v0.0.0-20220221185849-529eae5b6118 // indirect
github.com/mdlayher/packet v1.1.2 // indirect
github.com/mdlayher/socket v0.5.1 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
Expand All @@ -51,7 +47,6 @@ require (
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8 // indirect
golang.org/x/net v0.36.0 // indirect
golang.org/x/sync v0.11.0 // indirect
golang.org/x/text v0.22.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20241209162323-e6fa225c2576 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241223144023-3abc09e42ca8 // indirect
Expand Down
25 changes: 5 additions & 20 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ github.com/google/btree v1.0.1 h1:gK4Kx5IaGY9CD5sPJ36FHiBJ6ZXl0kilRiiCj+jdYp4=
github.com/google/btree v1.0.1/go.mod h1:xXMiIv4Fb/0kKde4SpL7qlzvu5cMJDRkFDxJfI9uaxA=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/gopacket v1.1.19 h1:ves8RnFZPGiFnTS0uPQStjwru6uO6h+nlr9j6fL7kF8=
github.com/google/gopacket v1.1.19/go.mod h1:iJ8V8n6KS+z2U1A8pUwu8bW5SyEMkXJB8Yo/Vo+TKTo=
github.com/hashicorp/consul/api v1.31.2 h1:NicObVJHcCmyOIl7Z9iHPvvFrocgTYo9cITSGg0/7pw=
github.com/hashicorp/consul/api v1.31.2/go.mod h1:Z8YgY0eVPukT/17ejW+l+C7zJmKwgPHtjU1q16v/Y40=
github.com/hashicorp/consul/sdk v0.16.1 h1:V8TxTnImoPD5cj0U9Spl0TUxcytjcbbJeADFF07KdHg=
Expand Down Expand Up @@ -102,9 +102,6 @@ github.com/hashicorp/memberlist v0.5.0 h1:EtYPN8DpAURiapus508I4n9CzHs2W+8NZGbmmR
github.com/hashicorp/memberlist v0.5.0/go.mod h1:yvyXLpo0QaGE59Y7hDTsTzDD25JYBZ4mHgHUZ8lrOI0=
github.com/hashicorp/serf v0.10.1 h1:Z1H2J60yRKvfDYAOZLd2MU0ND4AH/WDz7xYHDWQsIPY=
github.com/hashicorp/serf v0.10.1/go.mod h1:yL2t6BqATOLGc5HF7qbFkTfXoPIY0WZdWHfEvMqbG+4=
github.com/josharian/native v1.0.0/go.mod h1:7X/raswPFr05uY3HiLlYeyQntB6OO7E/d2Cu7qoaN2w=
github.com/josharian/native v1.1.0 h1:uuaP0hAbW7Y4l0ZRQ6C9zfb7Mg1mbFKry/xzDAfmtLA=
github.com/josharian/native v1.1.0/go.mod h1:7X/raswPFr05uY3HiLlYeyQntB6OO7E/d2Cu7qoaN2w=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
Expand Down Expand Up @@ -135,16 +132,6 @@ github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/mdlayher/arp v0.0.0-20220512170110-6706a2966875 h1:ql8x//rJsHMjS+qqEag8n3i4azw1QneKh5PieH9UEbY=
github.com/mdlayher/arp v0.0.0-20220512170110-6706a2966875/go.mod h1:kfOoFJuHWp76v1RgZCb9/gVUc7XdY877S2uVYbNliGc=
github.com/mdlayher/ethernet v0.0.0-20220221185849-529eae5b6118 h1:2oDp6OOhLxQ9JBoUuysVz9UZ9uI6oLUbvAZu0x8o+vE=
github.com/mdlayher/ethernet v0.0.0-20220221185849-529eae5b6118/go.mod h1:ZFUnHIVchZ9lJoWoEGUg8Q3M4U8aNNWA3CVSUTkW4og=
github.com/mdlayher/packet v1.0.0/go.mod h1:eE7/ctqDhoiRhQ44ko5JZU2zxB88g+JH/6jmnjzPjOU=
github.com/mdlayher/packet v1.1.2 h1:3Up1NG6LZrsgDVn6X4L9Ge/iyRyxFEFD9o6Pr3Q1nQY=
github.com/mdlayher/packet v1.1.2/go.mod h1:GEu1+n9sG5VtiRE4SydOmX5GTwyyYlteZiFU+x0kew4=
github.com/mdlayher/socket v0.2.1/go.mod h1:QLlNPkFR88mRUNQIzRBMfXxwKal8H7u1h3bL1CV+f0E=
github.com/mdlayher/socket v0.5.1 h1:VZaqt6RkGkt2OE9l3GcC6nZkqD3xKeQLyfleW/uBcos=
github.com/mdlayher/socket v0.5.1/go.mod h1:TjPLHI1UgwEv5J1B5q0zTZq12A/6H7nKmtTanQE37IQ=
github.com/miekg/dns v1.1.26/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso=
github.com/miekg/dns v1.1.41 h1:WMszZWJG0XmzbK9FEmzH2TVcqYzFesusSIB41b8KHxY=
github.com/miekg/dns v1.1.41/go.mod h1:p6aan82bvRIyn+zDIv9xYNUpwa73JcSh9BKwknJysuI=
Expand Down Expand Up @@ -239,12 +226,12 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8 h1:yqrTHse8TCMW1M1ZCP+VAR/l0kKxwaAIqN/il7x4voA=
golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8/go.mod h1:tujkw807nyEEAamNbDrEGzRav+ilXA7PCRAd6xsmwiU=
golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
Expand All @@ -260,8 +247,6 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w=
golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand All @@ -281,7 +266,6 @@ golang.org/x/sys v0.0.0-20210303074136-134d130e1a04/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand All @@ -298,6 +282,7 @@ golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190907020128-2ca718005c18/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
45 changes: 40 additions & 5 deletions ipmanager/basicConfigurer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import (
"net"
"strings"

arp "github.com/mdlayher/arp"
"github.com/google/gopacket"
"github.com/google/gopacket/layers"
)

// BasicConfigurer can be used to enable vip-management on nodes
Expand All @@ -16,7 +17,6 @@ import (
// nearby routers and other devices.
type BasicConfigurer struct {
*IPConfiguration
arpClient *arp.Client
ntecontext uint32 //used by Windows to delete IP address
}

Expand Down Expand Up @@ -48,8 +48,43 @@ func (c *BasicConfigurer) queryAddress() bool {
return false
}

func (c *BasicConfigurer) cleanupArp() {
if c.arpClient != nil {
c.arpClient.Close()
const (
MACAddressSize = 6
IPv4AddressSize = 4
)

// createGratuitousARP prepares a packet with a gratuitous ARP request
func (c *BasicConfigurer) createGratuitousARP() ([]byte, error) {
// Create the Ethernet layer
ethLayer := &layers.Ethernet{
SrcMAC: c.Iface.HardwareAddr,
DstMAC: net.HardwareAddr{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, // Broadcast
EthernetType: layers.EthernetTypeARP,
}

// Create the ARP layer
arpLayer := &layers.ARP{
AddrType: layers.LinkTypeEthernet,
Protocol: layers.EthernetTypeIPv4,
HwAddressSize: MACAddressSize,
ProtAddressSize: IPv4AddressSize,
Operation: layers.ARPReply, // Gratuitous ARP is sent as a reply
SourceHwAddress: c.Iface.HardwareAddr,
SourceProtAddress: c.IPConfiguration.VIP.AsSlice(),
DstHwAddress: c.Iface.HardwareAddr, // Gratuitous ARP targets itself
DstProtAddress: c.IPConfiguration.VIP.AsSlice(),
}

// Create a packet with the layers
buffer := gopacket.NewSerializeBuffer()
opts := gopacket.SerializeOptions{
FixLengths: true,
ComputeChecksums: true,
}

if err := gopacket.SerializeLayers(buffer, opts, ethLayer, arpLayer); err != nil {
return nil, err
}

return buffer.Bytes(), nil
}
146 changes: 31 additions & 115 deletions ipmanager/basicConfigurer_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,46 @@ package ipmanager
import (
"net"
"os/exec"
"time"

arp "github.com/mdlayher/arp"
"syscall"
)

const (
arpRequestOp = 1
arpReplyOp = 2
)
// htons converts uint16 to network byte order
func htons(i uint16) uint16 {
return (i<<8)&0xff00 | i>>8
}

var (
ethernetBroadcast = net.HardwareAddr{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
)
func sendPacketLinux(iface net.Interface, packetData []byte) error {
fd, err := syscall.Socket(syscall.AF_PACKET, syscall.SOCK_RAW, int(htons(syscall.ETH_P_ALL)))
if err != nil {
return err
}
defer syscall.Close(fd)

// configureAddress assigns virtual IP address
func (c *BasicConfigurer) configureAddress() bool {
if c.arpClient == nil {
if err := c.createArpClient(); err != nil {
log.Error("Couldn't create an Arp client:", err)
}
var sll syscall.SockaddrLinklayer
sll.Protocol = htons(syscall.ETH_P_ARP)
sll.Ifindex = iface.Index
sll.Hatype = syscall.ARPHRD_ETHER
sll.Pkttype = syscall.PACKET_BROADCAST

if err = syscall.Bind(fd, &sll); err != nil {
return err
}

log.Infof("Configuring address %s on %s", c.getCIDR(), c.Iface.Name)
return syscall.Sendto(fd, packetData, 0, &sll)
}

// configureAddress assigns virtual IP address
func (c *BasicConfigurer) configureAddress() bool {
log.Infof("Configuring address %s on %s", c.getCIDR(), c.Iface.Name)
result := c.runAddressConfiguration("add")

if result {
// 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()
if buff, err := c.createGratuitousARP(); err != nil {
log.Warn("Failed to compose gratuitous ARP request: ", err)
} else {
if err := sendPacketLinux(c.Iface, buff); err != nil {
log.Warn("Failed to send gratuitous ARP request: ", err)
}
}
}

return result
Expand Down Expand Up @@ -64,96 +73,3 @@ func (c *BasicConfigurer) runAddressConfiguration(action string) bool {
}
return true
}

func (c *BasicConfigurer) createArpClient() (err error) {
for i := 0; i < c.RetryNum; i++ {
if c.arpClient, err = arp.Dial(&c.Iface); err == nil {
return
}
log.Infof("Problems with producing the arp client: %s", err)
time.Sleep(time.Duration(c.RetryAfter) * time.Millisecond)
}
return
}

// sends a gratuitous ARP request and reply
func (c *BasicConfigurer) arpSendGratuitous() error {
/* While RFC 2002 does not say whether a gratuitous ARP request or reply is preferred
* to update ones neighbours' MAC tables, the Wireshark Wiki recommends sending both.
* https://wiki.wireshark.org/Gratuitous_ARP
* This site also recommends sending a reply, as requests might be ignored by some hardware:
* https://support.citrix.com/article/CTX112701
*/
if c.arpClient == nil {
log.Info("No arp client available, skip send gratuitous ARP")
return nil
}
gratuitousReplyPackage, err := arp.NewPacket(
arpReplyOp,
c.Iface.HardwareAddr,
c.VIP,
c.Iface.HardwareAddr,
c.VIP,
)
if err != nil {
log.Infof("Gratuitous arp reply package is malformed: %s", err)
return err
}

/* RFC 2002 specifies (in section 4.6) that a gratuitous ARP request
* should "not set" the target Hardware Address (THA).
* Since the arp package offers no option to leave the THA out, we specify the Zero-MAC.
* If parsing that fails for some reason, we'll just use the local interface's address.
* The field is probably ignored by the receivers' implementation anyway.
*/
arpRequestDestMac, err := net.ParseMAC("00:00:00:00:00:00")
if err != nil {
// not entirely RFC-2002 conform but better then nothing.
arpRequestDestMac = c.Iface.HardwareAddr
}

gratuitousRequestPackage, err := arp.NewPacket(
arpRequestOp,
c.Iface.HardwareAddr,
c.VIP,
arpRequestDestMac,
c.VIP,
)
if err != nil {
log.Infof("Gratuitous arp request package is malformed: %s", err)
return err
}

for i := 0; i < c.RetryNum; i++ {
errReply := c.arpClient.WriteTo(gratuitousReplyPackage, ethernetBroadcast)
if err != nil {
log.Error("Couldn't write to the arpClient:", errReply)
} else {
log.Info("Sent gratuitous ARP reply")
}

errRequest := c.arpClient.WriteTo(gratuitousRequestPackage, ethernetBroadcast)
if err != nil {
log.Error("Couldn't write to the arpClient:", errRequest)
} else {
log.Info("Sent gratuitous ARP request")
}

if errReply != nil || errRequest != nil {
/* If something went wrong while sending the packages, we'll recreate the ARP client for the next try,
* to avoid having a stale client that gives "network is down" error.
*/
err = c.createArpClient()
} else {
//TODO: think about whether to leave this out to achieve simple repeat sending of GARP packages
break
}
time.Sleep(time.Duration(c.RetryAfter) * time.Millisecond)
}
if err != nil {
log.Error("Too many retries", err)
return err
}

return nil
}
24 changes: 20 additions & 4 deletions ipmanager/basicConfigurer_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ import (
"github.com/cybertec-postgresql/vip-manager/iphlpapi"
)

func sendPacketWindows(iface net.Interface, packetData []byte) error {
// Open a raw socket using Winsock
conn, err := net.Dial("ip4:ethernet", iface.HardwareAddr.String())
if err != nil {
return err
}
defer conn.Close()
// Send the packet
_, err = conn.Write(packetData)
return err
}

// configureAddress assigns virtual IP address
func (c *BasicConfigurer) configureAddress() bool {
log.Infof("Configuring address %s on %s", c.getCIDR(), c.Iface.Name)
Expand All @@ -25,10 +37,14 @@ func (c *BasicConfigurer) configureAddress() bool {
log.Error("Failed to add address: ", 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()

if buff, err := c.createGratuitousARP(); err != nil {
log.Warn("Failed to compose gratuitous ARP request: ", err)
} else {
if err := sendPacketWindows(c.Iface, buff); err != nil {
log.Warn("Failed to send gratuitous ARP request: ", err)
}
}
return true
}

Expand Down
5 changes: 0 additions & 5 deletions ipmanager/hetznerConfigurer.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,3 @@ func (c *HetznerConfigurer) runAddressConfiguration() bool {
c.cachedState = unknown
return false
}

func (c *HetznerConfigurer) cleanupArp() {
// dummy function as the usage of interfaces requires us to have this function.
// It is sufficient for the leader to tell Hetzner to switch the IP, no cleanup needed.
}
Loading
Loading