SatCat5
satcat5::ip::Dispatch Class Referencefinal

Detailed Description

Protocol handler and dispatch unit for Internet Protocol v4 (IPv4).

This class implements the "net::Dispatch" API for IPv4 frames.

The IP dispatch subsystem must be attached to an Ethernet interface, accepting all incoming traffic with EtherType 0x0800 (IPv4). Incoming packets are checked for validity and then sorted by IP protocol number (i.e., ICMP, UDP, TCP, etc.).

The system includes static routing tables for next-hop routing, inheriting all functionality from the ip::Table class.

For an all-in-one container with ip::Dispatch and other components required for UDP communications, use ip::Stack.

Definition at line 39 of file ip_dispatch.h.

#include <ip_dispatch.h>

Inheritance diagram for satcat5::ip::Dispatch:
[legend]
Collaboration diagram for satcat5::ip::Dispatch:
[legend]

Public Member Functions

 Dispatch (const satcat5::ip::Addr &addr, satcat5::eth::Dispatch *iface, satcat5::ip::Table *route)
 Link this object to an Ethernet interface. More...
 
satcat5::io::Writeableopen_reply (const satcat5::net::Type &type, unsigned len) override
 Get Writeable object for reply to the last received datagram.
 
satcat5::io::Writeableopen_write (const satcat5::eth::MacAddr &mac, const satcat5::eth::VlanTag &vtag, const satcat5::ip::Addr &ip, u8 protocol, unsigned len)
 Get Writeable object for sending to a specific IP/MAC address.
 
void set_addr (const satcat5::ip::Addr &addr)
 Set the local IP-address.
 
satcat5::ip::Header next_header (u8 protocol, const satcat5::ip::Addr &dst, unsigned inner_bytes, u8 ttl=SATCAT5_IP_TTL)
 Create a basic IPv4 header with the specified information. More...
 
satcat5::eth::ProtoArparp ()
 
satcat5::ip::ProtoIcmpicmp ()
 
satcat5::igmp::Clientigmp ()
 
satcat5::eth::Dispatchiface () const
 
satcat5::ip::Addr ipaddr () const
 
satcat5::eth::MacAddr macaddr () const
 
satcat5::eth::VlanTag reply_vtag () const
 
satcat5::eth::MacAddr reply_mac () const
 
bool reply_is_multicast () const
 
satcat5::ip::Addr reply_ip () const
 
const satcat5::ip::Headerreply_hdr () const
 
void set_ipaddr (const satcat5::ip::Addr &addr)
 
void set_macaddr (const satcat5::eth::MacAddr &macaddr)
 
satcat5::ip::Tabletable ()
 
void set_ident (u16 ident)
 For testing purposes only, reset the "ident" field. More...
 
virtual void gateway_change (const satcat5::ip::Addr &dstaddr, const satcat5::ip::Addr &gateway)
 Callback for changes to gateway configuration. More...
 
void add (satcat5::net::Protocol *proto)
 Register a Protocol object.
 
void remove (satcat5::net::Protocol *proto)
 Unregister a Protocol object.
 
bool bound (const satcat5::net::Type &type) const
 Check if a given net::Type has a matching Protocol.
 
void route_clear (bool lockdown=true)
 Routing table shortcuts. More...
 
bool route_cache (const satcat5::ip::Addr &gateway, const satcat5::eth::MacAddr &dstmac)
 Routing table shortcuts. More...
 
bool route_default (const satcat5::ip::Addr &gateway, const satcat5::eth::MacAddr &dstmac=satcat5::eth::MACADDR_NONE)
 Routing table shortcuts. More...
 
bool route_local (const satcat5::ip::Subnet &subnet)
 Routing table shortcuts. More...
 
bool route_simple (const satcat5::ip::Addr &gateway, const satcat5::ip::Mask &subnet=satcat5::ip::MASK_24)
 Routing table shortcuts. More...
 
bool route_static (const satcat5::ip::Subnet &subnet, const satcat5::ip::Addr &gateway, const satcat5::eth::MacAddr &dstmac=satcat5::eth::MACADDR_NONE)
 Routing table shortcuts. More...
 
bool route_remove (const satcat5::ip::Subnet &subnet)
 Routing table shortcuts. More...
 
bool route_remove (const satcat5::ip::Addr &addr)
 Routing table shortcuts. More...
 
satcat5::ip::Route route_lookup (const satcat5::ip::Addr &dstaddr) const
 Routing table shortcuts. More...
 

Protected Member Functions

void arp_event (const satcat5::eth::MacAddr &mac, const satcat5::ip::Addr &ip) override
 Callback for any announced MAC/IP address pair. More...
 
void frame_rcvd (satcat5::io::LimitedRead &src) override
 Dispatch calls frame_rcvd(...) for each incoming frame with with a matching net::Type value. More...
 
bool deliver (const satcat5::net::Type &type, satcat5::io::Readable *src, unsigned len)
 Deliver current message by calling Protocol::frame_rcvd(...). More...
 

Protected Attributes

satcat5::eth::Dispatch *const m_iface
 
satcat5::ip::Table *const m_route
 
satcat5::ip::Addr m_addr
 
satcat5::eth::ProtoArp m_arp
 
satcat5::ip::ProtoIcmp m_icmp
 
satcat5::igmp::Client m_igmp
 
satcat5::ip::Addr m_reply_dst
 
satcat5::ip::Addr m_reply_src
 
satcat5::ip::Header m_reply_hdr
 
u16 m_ident
 
satcat5::net::Type m_filter
 Incoming packet filter.
 
satcat5::util::List< satcat5::net::Protocolm_list
 Linked list of Protocol objects.
 

Private Attributes

satcat5::eth::ArpListenerm_next
 

Constructor & Destructor Documentation

◆ Dispatch()

Dispatch::Dispatch ( const satcat5::ip::Addr addr,
satcat5::eth::Dispatch iface,
satcat5::ip::Table route 
)

Link this object to an Ethernet interface.

Constructor requires the local address (may be ADDR_NONE), an Ethernet interface, and a time reference. The address may be changed later if desired.

Definition at line 21 of file ip_dispatch.cc.

Member Function Documentation

◆ arp_event()

void Dispatch::arp_event ( const satcat5::eth::MacAddr mac,
const satcat5::ip::Addr ip 
)
overrideprotectedvirtual

Callback for any announced MAC/IP address pair.

Child class MUST override this method.

Implements satcat5::eth::ArpListener.

Definition at line 101 of file ip_dispatch.cc.

◆ deliver()

bool Dispatch::deliver ( const satcat5::net::Type type,
satcat5::io::Readable src,
unsigned  len 
)
protectedinherited

Deliver current message by calling Protocol::frame_rcvd(...).

Note: Caller is responsible for read_finalize(), if required.

Returns
True if a matching Protocol is found.

Definition at line 25 of file net_dispatch.cc.

◆ frame_rcvd()

void Dispatch::frame_rcvd ( satcat5::io::LimitedRead src)
overrideprotectedvirtual

Dispatch calls frame_rcvd(...) for each incoming frame with with a matching net::Type value.

The child class SHOULD read the frame contents from the provided "src" object, which is only valid until the function returns.

To send a reply:

  • Call m_iface->open_reply() to obtain a Writable object. (This also writes out any applicable frame headers.)
  • Write frame contents, then call write_finalize().

The child class MUST override this method.

Implements satcat5::net::Protocol.

Definition at line 106 of file ip_dispatch.cc.

◆ gateway_change()

virtual void satcat5::eth::ArpListener::gateway_change ( const satcat5::ip::Addr dstaddr,
const satcat5::ip::Addr gateway 
)
inlinevirtualinherited

Callback for changes to gateway configuration.

Child class MAY override this method.

Reimplemented in satcat5::ip::Address, and satcat5::test::CountArpResponse.

Definition at line 56 of file eth_arp.h.

◆ next_header()

Header Dispatch::next_header ( u8  protocol,
const satcat5::ip::Addr dst,
unsigned  inner_bytes,
u8  ttl = SATCAT5_IP_TTL 
)

Create a basic IPv4 header with the specified information.

  • protocol Packet type (ICMP/UDP/etc)
  • dst Destination IP address
  • inner_bytes Length of contained packet
  • ttl Time-to-live (optional)

Definition at line 79 of file ip_dispatch.cc.

◆ route_cache()

bool satcat5::ip::Dispatch::route_cache ( const satcat5::ip::Addr gateway,
const satcat5::eth::MacAddr dstmac 
)
inline

Routing table shortcuts.

See also
ip_table.h

Definition at line 85 of file ip_dispatch.h.

◆ route_clear()

void satcat5::ip::Dispatch::route_clear ( bool  lockdown = true)
inline

Routing table shortcuts.

See also
ip_table.h

Definition at line 83 of file ip_dispatch.h.

◆ route_default()

bool satcat5::ip::Dispatch::route_default ( const satcat5::ip::Addr gateway,
const satcat5::eth::MacAddr dstmac = satcat5::eth::MACADDR_NONE 
)
inline

Routing table shortcuts.

See also
ip_table.h

Definition at line 89 of file ip_dispatch.h.

◆ route_local()

bool satcat5::ip::Dispatch::route_local ( const satcat5::ip::Subnet subnet)
inline

Routing table shortcuts.

See also
ip_table.h

Definition at line 93 of file ip_dispatch.h.

◆ route_lookup()

satcat5::ip::Route satcat5::ip::Dispatch::route_lookup ( const satcat5::ip::Addr dstaddr) const
inline

Routing table shortcuts.

See also
ip_table.h

Definition at line 108 of file ip_dispatch.h.

◆ route_remove() [1/2]

bool satcat5::ip::Dispatch::route_remove ( const satcat5::ip::Addr addr)
inline

Routing table shortcuts.

See also
ip_table.h

Definition at line 106 of file ip_dispatch.h.

◆ route_remove() [2/2]

bool satcat5::ip::Dispatch::route_remove ( const satcat5::ip::Subnet subnet)
inline

Routing table shortcuts.

See also
ip_table.h

Definition at line 104 of file ip_dispatch.h.

◆ route_simple()

bool satcat5::ip::Dispatch::route_simple ( const satcat5::ip::Addr gateway,
const satcat5::ip::Mask subnet = satcat5::ip::MASK_24 
)
inline

Routing table shortcuts.

See also
ip_table.h

Definition at line 95 of file ip_dispatch.h.

◆ route_static()

bool satcat5::ip::Dispatch::route_static ( const satcat5::ip::Subnet subnet,
const satcat5::ip::Addr gateway,
const satcat5::eth::MacAddr dstmac = satcat5::eth::MACADDR_NONE 
)
inline

Routing table shortcuts.

See also
ip_table.h

Definition at line 99 of file ip_dispatch.h.

◆ set_ident()

void satcat5::ip::Dispatch::set_ident ( u16  ident)
inline

For testing purposes only, reset the "ident" field.

(This is unsafe, but simplifies certain unit tests.)

Definition at line 145 of file ip_dispatch.h.


The documentation for this class was generated from the following files: