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
+61 -3
View File
@@ -7,6 +7,7 @@ A lightweight VRRP (Virtual Router Redundancy Protocol) implementation in Go, de
- **VRRP Protocol**: RFC 3768/5798 compliant implementation
- **High Availability**: Automatic failover with priority-based master election
- **Health Checking**: TCP, HTTP/HTTPS, ICMP ping, and script-based checks
- **Unicast Support**: Direct peer communication for restricted network environments (macvlan, cloud)
- **Easy Deployment**: Built-in install command with systemd/init.d support
- **Hot Reload**: Configuration reload via SIGHUP without service restart
- **Zero Dependencies**: Single static binary, no runtime dependencies
@@ -145,6 +146,54 @@ vrrp_instances:
- "192.168.1.100/24" # Must match
```
### Unicast Configuration (for macvlan / cloud environments)
In environments where multicast is not available (macvlan networks, public clouds, etc.), use unicast to send VRRP advertisements directly to peer IPs:
**Node 1 (MASTER)**:
```yaml
global:
router_id: "node1"
vrrp_instances:
- name: "VI_1"
interface: "eth0"
state: "MASTER"
virtual_router_id: 51
priority: 100
advert_interval: 1
auth_type: "PASS"
auth_pass: "secret123"
virtual_ips:
- "192.168.1.100/24"
unicast_src_ip: "192.168.1.10"
unicast_peers:
- "192.168.1.11"
```
**Node 2 (BACKUP)**:
```yaml
global:
router_id: "node2"
vrrp_instances:
- name: "VI_1"
interface: "eth0"
state: "BACKUP"
virtual_router_id: 51
priority: 50
advert_interval: 1
auth_type: "PASS"
auth_pass: "secret123"
virtual_ips:
- "192.168.1.100/24"
unicast_src_ip: "192.168.1.11"
unicast_peers:
- "192.168.1.10"
```
See `etc/config.unicast.yaml` for a complete unicast example.
### Health Checking
```yaml
@@ -245,9 +294,17 @@ sudo kill -HUP $(pgrep go-alived)
| VirtualBox | Full | Bridged network + promiscuous mode |
| Docker | Limited | Requires `--privileged --net=host` |
| OpenWrt/iStoreOS | Full | Use `--method service` for install |
| AWS/Aliyun/Azure | None | Multicast disabled |
| macvlan networks | Full | Use unicast mode |
| AWS/Aliyun/Azure/GCP | Limited | Use unicast mode |
> **Note**: VRRP requires multicast support (224.0.0.18). Most public clouds disable multicast at the network layer. Use cloud-native HA solutions instead.
> **Note**: VRRP defaults to multicast (224.0.0.18). In environments where multicast is disabled or unavailable (public clouds, macvlan networks), use **unicast mode** by configuring `unicast_src_ip` and `unicast_peers`.
## Requirements
- Go 1.21+ (for building)
- Linux/macOS with root privileges (for raw sockets and interface management)
- Network interface with IPv4 address
- Multicast support (default mode) **or** unicast configuration (for restricted environments)
## Troubleshooting
@@ -266,7 +323,8 @@ sudo go-alived run -c /etc/go-alived/config.yaml
**3. Both nodes become MASTER (split-brain)**
- Check network connectivity between nodes
- Verify `virtual_router_id` matches
- Ensure multicast traffic is allowed
- In multicast mode: ensure multicast traffic is allowed
- In unicast mode: verify `unicast_peers` and `unicast_src_ip` are correct
**4. VIP not pingable after failover**
- Gratuitous ARP may be blocked