Documentation
¶
Overview ¶
Package bridge implements the KNE packet bridge Wire service daemon.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client connects to a remote bridge server and bridges packets and link state to a local interface.
func NewClient ¶
func NewClient(cfg ClientConfig) (*Client, error)
NewClient constructs a new bridge Client.
type ClientConfig ¶
type ClientConfig struct {
// PeerAddress is the host:port of the remote bridge server.
PeerAddress string
// LocalInterface is the local network interface to bridge (e.g., "eth1").
LocalInterface string
// RemoteInterface is the remote interface name passed in gRPC metadata. Defaults to LocalInterface.
RemoteInterface string
// DialOpts allows custom gRPC dial options (useful for in-memory testing).
DialOpts []grpc.DialOption
// SocketOpener allows overriding the raw socket constructor for testing.
SocketOpener func(ifaceName string) (ReadWriter, error)
// LinkOpener allows overriding the link-state constructor for testing.
// Defaults to NewNetlinkLink. If it fails, the client bridges frames
// without link state.
LinkOpener func(ifaceName string) (Link, error)
// RetryInterval is the delay before reconnecting if disconnected. Default 2s.
RetryInterval time.Duration
// UseALTS specifies whether to use ALTS transport credentials for DirectPath on GCE.
UseALTS bool
}
ClientConfig holds configuration for the bridge client.
type InterfaceDemux ¶
type InterfaceDemux struct {
// contains filtered or unexported fields
}
InterfaceDemux coordinates a single raw socket reader per interface with multiple gRPC clients. This design prevents socket buffer race conditions and distributes captured frames to all active subscribers. It also distributes the link state of the interface to all subscribers and applies link state received from any of them.
type Link ¶ added in v0.3.5
type Link interface {
// SetAdminUp sets the interface administratively up or down.
SetAdminUp(up bool) error
// Current returns the current state of the interface.
Current() (LinkObservation, error)
// Events returns a channel of state changes. Changes may be coalesced, so
// a reader sees the latest state but not necessarily every transition.
// The channel is closed by Close.
Events() <-chan LinkObservation
// Close stops observing the interface.
Close() error
}
Link controls and observes the link state of one local network interface.
A bridge propagates link state across a Wire by setting its interface administratively up or down, which the device at the other end of the link sees as a carrier change, and by reporting the carrier of its interface, which reflects the admin state of that device.
func NewNetlinkLink ¶ added in v0.3.5
NewNetlinkLink returns a Link for the named interface in the current network namespace.
type LinkObservation ¶ added in v0.3.5
type LinkObservation struct {
// AdminUp reports whether the interface is administratively up (IFF_UP).
AdminUp bool
// Carrier reports whether the interface has carrier (IFF_LOWER_UP). On a
// meshnet link it is true only while the device at the other end of the
// link is administratively up.
Carrier bool
}
LinkObservation is the state of a local network interface.
type ReadWriter ¶
type ReadWriter interface {
ReadPacket() ([]byte, error)
WritePacket(pkt []byte) error
Close() error
}
ReadWriter abstracts the physical or simulated raw packet I/O for an interface. Implementations MUST ensure that Close() interrupts any pending or concurrent ReadPacket() calls.
type Server ¶
type Server struct {
wpb.UnimplementedWireServer
// contains filtered or unexported fields
}
Server implements the wpb.WireServer gRPC service.
func (*Server) Close ¶
Close closes all underlying raw sockets and demuxers, waiting for read loops to finish.
func (*Server) SetLinkOpener ¶ added in v0.3.5
SetLinkOpener overrides the default link-state factory for hermetic testing. A nil opener disables link state.
func (*Server) SetSocketOpener ¶
func (s *Server) SetSocketOpener(opener func(ifaceName string) (ReadWriter, error))
SetSocketOpener overrides the default socket factory for hermetic testing.
func (*Server) Transmit ¶
func (s *Server) Transmit(stream wpb.Wire_TransmitServer) error
Transmit handles bidirectional packet streaming over the Wire service. It extracts the target interface from gRPC incoming metadata ("interface"), streams egress packets from the interface to gRPC, and writes ingress gRPC packets to the interface.
type SocketHandler ¶
type SocketHandler struct {
// contains filtered or unexported fields
}
SocketHandler manages a raw AF_PACKET socket bound to a specific Linux network interface. It integrates with the Go runtime netpoller so that ReadPacket blocks without spinning, and Close() immediately interrupts pending reads and prevents use-after-close errors.
func NewSocketHandler ¶
func NewSocketHandler(ifaceName string) (*SocketHandler, error)
NewSocketHandler creates and configures a raw AF_PACKET socket in promiscuous mode for the given interface.
func (*SocketHandler) Close ¶
func (s *SocketHandler) Close() error
Close closes the underlying raw socket file descriptor once. Closing interrupts any blocked or future ReadPacket / WritePacket calls via the runtime netpoller.
func (*SocketHandler) ReadPacket ¶
func (s *SocketHandler) ReadPacket() ([]byte, error)
ReadPacket reads a single raw Ethernet frame from the socket, ignoring outgoing echo frames.
func (*SocketHandler) WritePacket ¶
func (s *SocketHandler) WritePacket(pkt []byte) error
WritePacket writes a raw Ethernet frame directly to the network interface.