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 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)
// 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.
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) 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.