|
SatCat5
|
Connection metadata for an IPv4 address.
This class stores all required metadata required to reach a specified IPv4 address, including MAC address and VLAN tags. This is in contrast with the barebones ip::Addr object, which stores only the destination IPv4 address as a 32-bit integer.
The ip::Address class implements the full net::Address API. To send an IPv4 datagram to the specified address, call the open_write method, then write and finalize packet contents.
In manual mode, the user specifies both MAC and IP addresses. In automatic mode, this class automatically issues queries the routing table and ARP cache (ip::Table). If the next-hop MAC address is not cached, it automatically issues an ARP request.
Once created, the ip::Address object also tracks related ICMP requests, such as redirects forwarding traffic to a different next-hop gateway address, repeating MAC resolution as needed.
Definition at line 35 of file ip_address.h.
#include <ip_address.h>
Public Member Functions | |
| Address (satcat5::ip::Dispatch *iface, u8 proto) | |
| Create this object and bind it to a network interface. More... | |
| void | init (satcat5::ip::Dispatch *iface) |
| Deferred initialization of the upstream interface. More... | |
| void | connect (const satcat5::ip::Addr &dstaddr, const satcat5::eth::VlanTag &vtag=satcat5::eth::VTAG_NONE) |
| Automatic address resolution using routing table + ARP. More... | |
| void | connect (const satcat5::ip::Addr &dstaddr, const satcat5::eth::MacAddr &dstmac, const satcat5::eth::VlanTag &vtag=satcat5::eth::VTAG_NONE) |
| Manual address resolution, user supplies IP + MAC. | |
| void | close () override |
| Close any open connections and revert to idle. More... | |
| bool | ready () const override |
| Is this address object ready for use? Child MUST override this method. | |
| void | retry () override |
| If this Address is not in the ready() state, reattempt any steps required to do so, such as MAC address resolution. More... | |
| satcat5::net::Dispatch * | iface () const override |
| Fetch a pointer to the underlying interface. More... | |
| satcat5::io::Writeable * | open_write (unsigned len) override |
| Open a new frame to the designated address and type. More... | |
| bool | is_multicast () const override |
| Is the destination a broadcast or multicast address? Child MUST override these method. | |
| bool | matches_reply_address () const override |
| Does this Address object match the parent interface's current reply address? Multicast destinations should match any source address expected to receive the multicast message. More... | |
| bool | reply_is_multicast () const override |
| Was the parent interface's incoming message sent to a multicast address? (i.e., Could that message have many other recipients?) Child MUST override this method. | |
| void | save_reply_address () override |
| Bind this Address object to the parent interface's current reply address, as provided in net::Dispatch::open_reply(). More... | |
| satcat5::eth::MacAddr | dstmac () const |
| satcat5::eth::MacAddr | srcmac () const |
| satcat5::eth::VlanTag | vtag () const |
| satcat5::eth::Dispatch * | eth () const |
| satcat5::eth::Header | eth_header () const |
| satcat5::ip::Addr | dstaddr () const |
| satcat5::ip::Addr | gateway () const |
| bool | write_packet (unsigned nbytes, const void *data) |
| All-in-one call that writes an entire packet. 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 | gateway_change (const satcat5::ip::Addr &dstaddr, const satcat5::ip::Addr &gateway) override |
| Callback for changes to gateway configuration. More... | |
Protected Attributes | |
| satcat5::ip::Dispatch * | m_iface |
| const u8 | m_proto |
| u8 | m_ready |
| satcat5::util::TimeVal | m_arp_tref |
| satcat5::eth::MacAddr | m_dstmac |
| satcat5::ip::Addr | m_dstaddr |
| satcat5::ip::Addr | m_gateway |
| satcat5::eth::VlanTag | m_vtag |
| satcat5::igmp::Address | m_igmp |
Private Attributes | |
| satcat5::eth::ArpListener * | m_next |
| Address::Address | ( | satcat5::ip::Dispatch * | iface, |
| u8 | proto | ||
| ) |
Create this object and bind it to a network interface.
The upstream interface may be null.
| iface | Pointer to the upstream IP interface. |
| proto | IPv4 protocol number, such as ip::PROTO_UDP. |
Definition at line 25 of file ip_address.cc.
|
overrideprotectedvirtual |
Callback for any announced MAC/IP address pair.
Child class MUST override this method.
Implements satcat5::eth::ArpListener.
Definition at line 161 of file ip_address.cc.
|
overridevirtual |
Close any open connections and revert to idle.
Child MUST override this method.
Implements satcat5::net::Address.
Definition at line 108 of file ip_address.cc.
| void Address::connect | ( | const satcat5::ip::Addr & | dstaddr, |
| const satcat5::eth::VlanTag & | vtag = satcat5::eth::VTAG_NONE |
||
| ) |
Automatic address resolution using routing table + ARP.
Connecting to a multicast address automatically initiates an IGMP subscription for incoming and outgoing multicast packets.
Definition at line 54 of file ip_address.cc.
|
overrideprotectedvirtual |
Callback for changes to gateway configuration.
Child class MAY override this method.
Reimplemented from satcat5::eth::ArpListener.
Definition at line 169 of file ip_address.cc.
|
overridevirtual |
Fetch a pointer to the underlying interface.
Child MUST override this method.
Implements satcat5::net::Address.
Definition at line 121 of file ip_address.cc.
| void Address::init | ( | satcat5::ip::Dispatch * | iface | ) |
Deferred initialization of the upstream interface.
Used infrequently. If the constructor's interface argument is null, use this method to later assign the upstream interface.
Definition at line 47 of file ip_address.cc.
|
overridevirtual |
Does this Address object match the parent interface's current reply address? Multicast destinations should match any source address expected to receive the multicast message.
Child MUST override this method.
Implements satcat5::net::Address.
Definition at line 139 of file ip_address.cc.
|
overridevirtual |
Open a new frame to the designated address and type.
Child MUST override this method.
Implements satcat5::net::Address.
Definition at line 124 of file ip_address.cc.
|
overridevirtual |
If this Address is not in the ready() state, reattempt any steps required to do so, such as MAC address resolution.
Child SHOULD override this method if applicable.
Reimplemented from satcat5::net::Address.
Definition at line 101 of file ip_address.cc.
|
overridevirtual |
Bind this Address object to the parent interface's current reply address, as provided in net::Dispatch::open_reply().
Child MUST override this method.
Implements satcat5::net::Address.
Definition at line 152 of file ip_address.cc.
|
inherited |
All-in-one call that writes an entire packet.
Equivalent to open_write(), io::Writeable::write_bytes(), io::Writeable::write_finalize().
Definition at line 11 of file net_address.cc.