Skip to content

Commit

Permalink
check that the lease includes an IP address of the requested family b…
Browse files Browse the repository at this point in the history
…efore configuring the flannel interface
  • Loading branch information
thomasferrandiz committed Oct 11, 2024
1 parent 41d7069 commit 9334ff2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/backend/vxlan/vxlan.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,17 @@ func (be *VXLANBackend) RegisterNetwork(ctx context.Context, wg *sync.WaitGroup,
// This IP is just used as a source address for host to workload traffic (so
// the return path for the traffic has an address on the flannel network to use as the destination)
if config.EnableIPv4 {
if lease.Subnet.Empty() {
return nil, fmt.Errorf("failed to configure interface %s: IPv4 is enabled but the lease has no IPv4", dev.link.Attrs().Name)
}
if err := dev.Configure(ip.IP4Net{IP: lease.Subnet.IP, PrefixLen: 32}, config.Network); err != nil {
return nil, fmt.Errorf("failed to configure interface %s: %w", dev.link.Attrs().Name, err)
}
}
if config.EnableIPv6 {
if lease.IPv6Subnet.Empty() {
return nil, fmt.Errorf("failed to configure interface %s: IPv6 is enabled but the lease has no IPv6", v6Dev.link.Attrs().Name)
}
if err := v6Dev.ConfigureIPv6(ip.IP6Net{IP: lease.IPv6Subnet.IP, PrefixLen: 128}, config.IPv6Network); err != nil {
return nil, fmt.Errorf("failed to configure interface %s: %w", v6Dev.link.Attrs().Name, err)
}
Expand Down
8 changes: 8 additions & 0 deletions pkg/backend/wireguard/wireguard.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,21 @@ func (be *WireguardBackend) RegisterNetwork(ctx context.Context, wg *sync.WaitGr
}

if config.EnableIPv4 {
if lease.Subnet.Empty() {
return nil, fmt.Errorf("failed to configure wg interface: IPv4 is enabled but the lease has no IPv4")
}

err = dev.Configure(lease.Subnet.IP, config.Network)
if err != nil {
return nil, err
}
}

if config.EnableIPv6 {
if lease.IPv6Subnet.Empty() {
return nil, fmt.Errorf("failed to configure wg interface: IPv6 is enabled but the lease has no IPv6")
}

if cfg.Mode == Separate {
err = v6Dev.ConfigureV6(lease.IPv6Subnet.IP, config.IPv6Network)
} else {
Expand Down

0 comments on commit 9334ff2

Please sign in to comment.