kedge/internal/cni/bridge.go
Tyler King 6058e62348 Initial commit: Kedge network automation platform
Go-based network automation with YANG models, gRPC, Ansible,
Terraform, and Kubernetes integration.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-26 12:09:30 -05:00

37 lines
958 B
Go

package cni
import (
"fmt"
"github.com/vishvananda/netlink"
"github.com/guildhouse-co/kedge/internal/topology"
)
// attachUnderlayRoutes connects the host-side veth to VLAN bridge interfaces
// for underlay mode routing.
func attachUnderlayRoutes(hostVeth string, routes []SubnetRoute, topo *topology.MeshTopology) error {
if len(routes) == 0 {
return nil
}
hostLink, err := netlink.LinkByName(hostVeth)
if err != nil {
return fmt.Errorf("host veth %s not found: %w", hostVeth, err)
}
for _, route := range routes {
bridgeName := route.Via // e.g., "vlan100"
bridge, err := netlink.LinkByName(bridgeName)
if err != nil {
return fmt.Errorf("bridge %s not found for route %s: %w", bridgeName, route.Dst, err)
}
// Attach host veth to the VLAN bridge.
if err := netlink.LinkSetMaster(hostLink, bridge); err != nil {
return fmt.Errorf("failed to attach %s to bridge %s: %w", hostVeth, bridgeName, err)
}
}
return nil
}