feat: add VRRP unicast peer support for macvlan and restricted network environments
Release / Build darwin-amd64 (push) Has been cancelled
Release / Build linux-amd64 (push) Has been cancelled
Release / Build darwin-arm64 (push) Has been cancelled
Release / Build linux-arm64 (push) Has been cancelled
Release / Create Release (push) Has been cancelled

- Add unicast_src_ip and unicast_peers config fields
- NewUnicastSocket binds to source IP for proper packet reception
- SendTo() sends VRRP advertisements directly to peer IPs
- Receive loop filters packets from non-peer sources in unicast mode
- Backward compatible: multicast mode used when unicast_peers is empty
- Add unicast config example (etc/config.unicast.yaml)
- Update README with unicast documentation and examples
This commit is contained in:
loveuer
2026-06-07 13:11:34 +08:00
parent 3fc3c860bc
commit 00eba85e39
7 changed files with 281 additions and 32 deletions
+17
View File
@@ -2,6 +2,7 @@ package config
import (
"fmt"
"net"
"os"
"time"
@@ -33,6 +34,8 @@ type VRRPInstance struct {
NotifyBackup string `yaml:"notify_backup"`
NotifyFault string `yaml:"notify_fault"`
TrackScripts []string `yaml:"track_scripts"`
UnicastSrcIP string `yaml:"unicast_src_ip"`
UnicastPeers []string `yaml:"unicast_peers"`
}
type HealthChecker struct {
@@ -84,6 +87,20 @@ func validate(cfg *Config) error {
if len(vrrp.VirtualIPs) == 0 {
return fmt.Errorf("vrrp_instances[%d].virtual_ips cannot be empty", i)
}
if len(vrrp.UnicastPeers) > 0 {
for j, peer := range vrrp.UnicastPeers {
if ip := net.ParseIP(peer); ip == nil || ip.To4() == nil {
return fmt.Errorf("vrrp_instances[%d].unicast_peers[%d] is not a valid IPv4 address: %s", i, j, peer)
}
}
}
if vrrp.UnicastSrcIP != "" {
if ip := net.ParseIP(vrrp.UnicastSrcIP); ip == nil || ip.To4() == nil {
return fmt.Errorf("vrrp_instances[%d].unicast_src_ip is not a valid IPv4 address: %s", i, vrrp.UnicastSrcIP)
}
}
}
return nil