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 }