Documentation
¶
Index ¶
- Constants
- Variables
- func Version() string
- type ARPOperation
- type ARPWriter
- type ARPv4LinkLayerHandler
- type ARPv4Pdu
- func (a *ARPv4Pdu) BuildARPResponseWithConfig(config *InterfaceConfig) *ARPv4Pdu
- func (a *ARPv4Pdu) IsArpRequestForConfig(config *InterfaceConfig) bool
- func (a *ARPv4Pdu) IsArpResponse() bool
- func (a *ARPv4Pdu) IsEthernetAndIPv4() bool
- func (a *ARPv4Pdu) MarshalBinary() ([]byte, error)
- func (a *ARPv4Pdu) UnmarshalBinary(payload []byte) error
- type ARPv4Table
- type ARPv4Writer
- type FrameIn
- type FrameOut
- type ICMPPacket
- type IPProtocol
- type IPv4LinkLayerInputHandler
- type IPv4LinkLayerOutputHandler
- type IPv4Pdu
- type IcmpHandler
- type IcmpType
- type InterfaceConfig
- type InternetLayerHandler
- type InternetLayerStrategy
- type InternetLayerStrategyImpl
- type InternetV4PacketIn
- type InternetV4PacketOut
- type Internetv4LayerHandler
- type LinkLayerHandler
- type LinkLayerListener
- func (l *LinkLayerListener) AddInterface(iface *InterfaceConfig)
- func (l *LinkLayerListener) IcmpPing(ip net.IP, numPings uint16)
- func (l *LinkLayerListener) Interfaces() []*InterfaceConfig
- func (l *LinkLayerListener) ListenAndServe(ctx context.Context)
- func (l *LinkLayerListener) RouteTable() *RouteTable
- type LinkLayerStrategy
- type RouteInfo
- type RouteTable
- type RouteType
- type TransportLayerHandler
Constants ¶
View Source
const ( HardwareAddrLen = 6 InterfaceConfigFormatString = "interfaceName:IPv4/Mask" )
View Source
const ( DefaultIPv4Version = 4 IPv4IHL = 5 DefaultIPv4TTL = 64 IPv4HeaderLength = 20 )
Variables ¶
View Source
var ( HandledPdu = errors.New("this pdu is processed. this is intended behaviour") ErrDropPdu = errors.New("no action for given PDU found. dropping it") ErrNoRoute = errors.New("no route found") ErrNoLinkLayerHandler = errors.New("no link layer handler for given etherType found") ErrUnsupportedArpProtocol = errors.New("unsupported ARP Version. requires ethernet+IPv4") ErrNotAnMACHardwareAddress = errors.New("provided hardware address was no MAC address") ErrNotAnIPv4Address = errors.New("ip address it not an IPv4 address") ErrNoInternetLayerHandler = errors.New("no internet layer handler for given IPProtocol found") ErrARPTimeout = errors.New("ARP timeout. no MAC found for this IP Address") ErrARPPacketConn = errors.New("outbound PacketConn was nil") ErrNotANetworkAddress = errors.New("not a correct network address") ErrNextHopNotOnLinkLocalNetwork = errors.New("next hop is not on local network of the outbound interface") ErrLinkLocalRouteShouldNotHaveNextHop = errors.New("a link-local route should not have a next hop address defined") ErrInvalidInterfaceConfigString = errors.New("invalid interface config string. malformed input, should have following format: '" + InterfaceConfigFormatString + "'") )
View Source
var EmptyHardwareAddr = []byte{
0x0, 0x0, 0x0,
0x0, 0x0, 0x0,
}
Functions ¶
Types ¶
type ARPOperation ¶
type ARPOperation uint16
const ( ARPOperationRequest ARPOperation = 1 ARPOperationResponse ARPOperation = 2 HTYPEEthernet = 1 )
type ARPv4LinkLayerHandler ¶
type ARPv4LinkLayerHandler struct {
// contains filtered or unexported fields
}
func NewARPv4LinkLayerHandler ¶
func NewARPv4LinkLayerHandler(publishCh chan<- *ethernet.Frame) *ARPv4LinkLayerHandler
func (*ARPv4LinkLayerHandler) RunHandler ¶
func (llh *ARPv4LinkLayerHandler) RunHandler(ctx context.Context)
func (*ARPv4LinkLayerHandler) SupplierC ¶
func (llh *ARPv4LinkLayerHandler) SupplierC() chan<- FrameIn
type ARPv4Pdu ¶
type ARPv4Pdu struct {
HTYPE uint16
PTYPE ethernet.EtherType
HLEN uint8
PLEN uint8
Operation ARPOperation
SrcHardwareAddr []byte
SrcProtoAddr []byte
DstHardwareAddr []byte
DstProtoAddr []byte
}
func (*ARPv4Pdu) BuildARPResponseWithConfig ¶
func (a *ARPv4Pdu) BuildARPResponseWithConfig(config *InterfaceConfig) *ARPv4Pdu
func (*ARPv4Pdu) IsArpRequestForConfig ¶
func (a *ARPv4Pdu) IsArpRequestForConfig(config *InterfaceConfig) bool
func (*ARPv4Pdu) IsArpResponse ¶
func (*ARPv4Pdu) IsEthernetAndIPv4 ¶
func (*ARPv4Pdu) MarshalBinary ¶
func (*ARPv4Pdu) UnmarshalBinary ¶
type ARPv4Table ¶
type ARPv4Table struct {
// contains filtered or unexported fields
}
func NewARPv4Table ¶
func NewARPv4Table(ifconfig *InterfaceConfig, arpWriter ARPWriter) *ARPv4Table
func (*ARPv4Table) Store ¶
func (a *ARPv4Table) Store(ipAddr, macAddr []byte) error
type ARPv4Writer ¶
type ARPv4Writer struct {
// contains filtered or unexported fields
}
func NewARPv4Writer ¶
func NewARPv4Writer(ifconfig *InterfaceConfig) *ARPv4Writer
func (*ARPv4Writer) Initialize ¶
func (a *ARPv4Writer) Initialize(c net.PacketConn)
func (*ARPv4Writer) SendArpRequest ¶
func (a *ARPv4Writer) SendArpRequest(ip net.IP) error
type FrameIn ¶
type FrameIn struct {
Frame *ethernet.Frame
Interface *InterfaceConfig
}
type ICMPPacket ¶
type ICMPPacket struct {
IcmpType IcmpType
IcmpCode uint8
Checksum uint16
Id uint16
Seq uint16
Data []byte
}
func (*ICMPPacket) MakeResponse ¶
func (icmp *ICMPPacket) MakeResponse()
func (*ICMPPacket) MarshalBinary ¶
func (icmp *ICMPPacket) MarshalBinary() ([]byte, error)
func (*ICMPPacket) UnmarshalBinary ¶
func (icmp *ICMPPacket) UnmarshalBinary(data []byte) error
type IPProtocol ¶
type IPProtocol uint8
const ( IPProtocolICMPv4 IPProtocol = 1 IPProtocolIPv4 IPProtocol = 4 IPProtocolTCP IPProtocol = 6 IPProtocolUDP IPProtocol = 17 )
type IPv4LinkLayerInputHandler ¶
type IPv4LinkLayerInputHandler struct {
// contains filtered or unexported fields
}
func NewIPv4LinkLayerInputHandler ¶
func NewIPv4LinkLayerInputHandler(publishCh chan<- *InternetV4PacketIn) *IPv4LinkLayerInputHandler
func (*IPv4LinkLayerInputHandler) RunHandler ¶
func (llh *IPv4LinkLayerInputHandler) RunHandler(ctx context.Context)
func (*IPv4LinkLayerInputHandler) SupplierC ¶
func (llh *IPv4LinkLayerInputHandler) SupplierC() chan<- FrameIn
type IPv4LinkLayerOutputHandler ¶
type IPv4LinkLayerOutputHandler struct {
// contains filtered or unexported fields
}
func NewIPv4LinkLayerOutputHandler ¶
func NewIPv4LinkLayerOutputHandler(publishCh chan<- *ethernet.Frame) *IPv4LinkLayerOutputHandler
func (*IPv4LinkLayerOutputHandler) RunHandler ¶
func (h *IPv4LinkLayerOutputHandler) RunHandler(ctx context.Context)
func (*IPv4LinkLayerOutputHandler) SupplierC ¶
func (h *IPv4LinkLayerOutputHandler) SupplierC() chan *InternetV4PacketOut
type IPv4Pdu ¶
type IPv4Pdu struct {
Version uint8
TOS uint8
TotalLength uint16
Id uint16
Flags byte
FragOffset uint16
TTL uint8
Protocol IPProtocol
HeaderChecksum uint16
SrcIP net.IP
DstIP net.IP
Payload []byte
}
func NewIPv4Pdu ¶
func NewIPv4Pdu(srcIp, dstIp net.IP, ipProto IPProtocol, payload []byte) *IPv4Pdu
func (*IPv4Pdu) MarshalBinary ¶
func (*IPv4Pdu) UnmarshalBinary ¶
type IcmpHandler ¶
type IcmpHandler struct {
// contains filtered or unexported fields
}
func NewIcmpHandler ¶
func NewIcmpHandler(publishCh chan<- *IPv4Pdu) *IcmpHandler
func (*IcmpHandler) RunHandler ¶
func (i *IcmpHandler) RunHandler(ctx context.Context)
func (*IcmpHandler) SupplierC ¶
func (i *IcmpHandler) SupplierC() chan<- *IPv4Pdu
type InterfaceConfig ¶
type InterfaceConfig struct {
InterfaceName string
HardwareAddr *net.HardwareAddr
Addr *net.IPNet
RealIPAddr *net.IPNet
ArpTable *ARPv4Table
// contains filtered or unexported fields
}
func NewInterfaceConfig ¶
func NewInterfaceConfig(name string, addr *net.IPNet) (*InterfaceConfig, error)
func ParseInterfaceConfig ¶
func ParseInterfaceConfig(config string) (*InterfaceConfig, error)
func (*InterfaceConfig) SetupAndListen ¶
func (*InterfaceConfig) WriteFrame ¶
func (i *InterfaceConfig) WriteFrame(f *ethernet.Frame) error
type InternetLayerHandler ¶
type InternetLayerHandler interface {
RunHandler(ctx context.Context)
SupplierC() chan *InternetV4PacketIn
}
type InternetLayerStrategy ¶
type InternetLayerStrategy interface {
GetHandler(ipProto IPProtocol) (TransportLayerHandler, error)
}
type InternetLayerStrategyImpl ¶
type InternetLayerStrategyImpl struct {
// contains filtered or unexported fields
}
func NewInternetLayerStrategy ¶
func NewInternetLayerStrategy(icmpHandler *IcmpHandler) *InternetLayerStrategyImpl
func (*InternetLayerStrategyImpl) GetHandler ¶
func (l *InternetLayerStrategyImpl) GetHandler(ipProto IPProtocol) (TransportLayerHandler, error)
type InternetV4PacketIn ¶
type InternetV4PacketIn struct {
Packet *IPv4Pdu
Ifconfig *InterfaceConfig
}
type InternetV4PacketOut ¶
type Internetv4LayerHandler ¶
type Internetv4LayerHandler struct {
// contains filtered or unexported fields
}
func NewInternetLayerHandler ¶
func NewInternetLayerHandler(publishCh chan<- *InternetV4PacketOut, routeTable *RouteTable) *Internetv4LayerHandler
func (*Internetv4LayerHandler) RunHandler ¶
func (h *Internetv4LayerHandler) RunHandler(ctx context.Context)
func (*Internetv4LayerHandler) SetStrategy ¶
func (h *Internetv4LayerHandler) SetStrategy(s InternetLayerStrategy)
func (*Internetv4LayerHandler) SupplierC ¶
func (h *Internetv4LayerHandler) SupplierC() chan *InternetV4PacketIn
func (*Internetv4LayerHandler) SupplierLocalC ¶
func (h *Internetv4LayerHandler) SupplierLocalC() chan *IPv4Pdu
type LinkLayerHandler ¶
type LinkLayerHandler interface {
SupplierC() chan<- FrameIn
}
type LinkLayerListener ¶
type LinkLayerListener struct {
// contains filtered or unexported fields
}
func NewLinkLayerListener ¶
func NewLinkLayerListener(interfaces ...*InterfaceConfig) *LinkLayerListener
func (*LinkLayerListener) AddInterface ¶
func (l *LinkLayerListener) AddInterface(iface *InterfaceConfig)
func (*LinkLayerListener) IcmpPing ¶
func (l *LinkLayerListener) IcmpPing(ip net.IP, numPings uint16)
func (*LinkLayerListener) Interfaces ¶
func (l *LinkLayerListener) Interfaces() []*InterfaceConfig
func (*LinkLayerListener) ListenAndServe ¶
func (l *LinkLayerListener) ListenAndServe(ctx context.Context)
func (*LinkLayerListener) RouteTable ¶
func (l *LinkLayerListener) RouteTable() *RouteTable
type LinkLayerStrategy ¶
type LinkLayerStrategy struct {
// contains filtered or unexported fields
}
func NewLinkLayerStrategy ¶
func NewLinkLayerStrategy(strategies map[ethernet.EtherType]LinkLayerHandler) *LinkLayerStrategy
func (*LinkLayerStrategy) GetHandler ¶
func (l *LinkLayerStrategy) GetHandler(etherType ethernet.EtherType) (LinkLayerHandler, error)
func (*LinkLayerStrategy) GetSupportedEtherTypes ¶
func (l *LinkLayerStrategy) GetSupportedEtherTypes() []ethernet.EtherType
type RouteInfo ¶
type RouteTable ¶
type RouteTable struct {
// contains filtered or unexported fields
}
func NewRouteTable ¶
func NewRouteTable() *RouteTable
func (*RouteTable) AddRoute ¶
func (table *RouteTable) AddRoute(config RouteInfo) error
func (*RouteTable) DeleteRouteAtIndex ¶
func (table *RouteTable) DeleteRouteAtIndex(index uint)
func (*RouteTable) GetRoutes ¶
func (table *RouteTable) GetRoutes() []RouteInfo
func (*RouteTable) MustAddRoute ¶
func (table *RouteTable) MustAddRoute(config RouteInfo)
func (*RouteTable) RoutePacket ¶
func (table *RouteTable) RoutePacket(ip IPv4Pdu) (*IPv4Pdu, *RouteInfo, error)
type TransportLayerHandler ¶
type TransportLayerHandler interface {
SupplierC() chan<- *IPv4Pdu
}
Source Files
¶
- arp_table.go
- arp_writer.go
- arpv4_pdu.go
- checksum.go
- errors.go
- icmpv4_pdu.go
- interface_config.go
- internet_layer_handler.go
- internet_layer_strategy.go
- ipv4_pdu.go
- link_layer_handler.go
- link_layer_handler_arp.go
- link_layer_handler_ip.go
- link_layer_listener.go
- link_layer_strategy.go
- route_table.go
- transport_layer_handler.go
- transport_layer_handler_icmp.go
- version.go
Click to show internal directories.
Click to hide internal directories.

