6 #include <satcat5/ip_address.h>
7 #include <satcat5/ip_dispatch.h>
9 using satcat5::eth::MACADDR_BROADCAST;
10 using satcat5::eth::MACADDR_NONE;
13 using satcat5::eth::VTAG_NONE;
17 namespace ip = satcat5::ip;
21 #ifndef SATCAT5_ARP_RETRY_MSEC
22 #define SATCAT5_ARP_RETRY_MSEC 100
29 , m_arp_tref(SATCAT5_CLOCK->now())
30 , m_dstmac(MACADDR_BROADCAST)
31 , m_dstaddr(ip::ADDR_NONE)
32 , m_gateway(ip::ADDR_NONE)
38 #if SATCAT5_ALLOW_DELETION
42 m_iface->arp()->
remove(
this);
48 if (
iface && !m_iface) {
50 m_iface->arp()->
add(
this);
63 m_dstmac = route.dstmac;
64 m_gateway = route.gateway;
66 m_arp_tref = SATCAT5_CLOCK->now();
73 m_igmp.
join(m_iface->igmp(), m_gateway);
90 m_gateway = ip::ADDR_NONE;
92 m_ready = (dstmac != MACADDR_NONE) ? 1 : 0;
96 m_gateway = m_dstaddr;
97 m_igmp.
join(m_iface->igmp(), m_gateway);
103 if (m_iface && !m_ready) {
104 m_iface->arp()->
send_query(m_gateway, m_vtag);
111 m_igmp.
leave(m_iface->igmp());
115 m_dstmac = MACADDR_BROADCAST;
116 m_dstaddr = ip::ADDR_NONE;
117 m_gateway = ip::ADDR_NONE;
127 return m_iface->
open_write(m_dstmac, m_vtag, m_dstaddr, m_proto, len);
128 }
else if (m_iface && m_arp_tref.
interval_msec(SATCAT5_ARP_RETRY_MSEC)) {
130 m_iface->arp()->
send_query(m_gateway, m_vtag);
140 if (!m_iface)
return false;
141 bool eth_match = m_dstmac.
is_multicast() || m_dstmac == m_iface->reply_mac();
142 bool ip_match = m_dstaddr.
is_multicast() || m_dstaddr == m_iface->reply_ip();
143 bool vid_check = m_iface->reply_vtag().
vid() && m_vtag.
vid();
144 bool vid_match = (!vid_check) || (m_iface->reply_vtag().
vid() == m_vtag.
vid());
145 return eth_match && ip_match && vid_match;
149 return m_iface && m_iface->reply_is_multicast();
154 m_dstmac = m_iface->reply_mac();
155 m_dstaddr = m_iface->reply_ip();
156 m_gateway = ip::ADDR_NONE;
163 if (ip == m_gateway) {
171 if ((dstaddr == m_dstaddr) && (gateway != m_gateway)) {
177 if (route.dstmac.is_valid()) m_dstmac = route.dstmac;
bool send_query(const satcat5::ip::Addr &target, const satcat5::eth::VlanTag &vtag=satcat5::eth::VTAG_NONE)
Send a query for a given IP address.
void add(satcat5::eth::ArpListener *evt)
Register an event-listener.
void remove(satcat5::eth::ArpListener *evt)
Unregister an event-listener.
Abstract API for writing byte-streams and packets.
Connection metadata for an IPv4 address.
void connect(const satcat5::ip::Addr &dstaddr, const satcat5::eth::VlanTag &vtag=satcat5::eth::VTAG_NONE)
Automatic address resolution using routing table + ARP.
void close() override
Close any open connections and revert to idle.
void arp_event(const satcat5::eth::MacAddr &mac, const satcat5::ip::Addr &ip) override
Callback for any announced MAC/IP address pair.
void save_reply_address() override
Bind this Address object to the parent interface's current reply address, as provided in net::Dispatc...
bool reply_is_multicast() const override
Was the parent interface's incoming message sent to a multicast address? (i.e., Could that message ha...
satcat5::net::Dispatch * iface() const override
Fetch a pointer to the underlying interface.
void gateway_change(const satcat5::ip::Addr &dstaddr, const satcat5::ip::Addr &gateway) override
Callback for changes to gateway configuration.
satcat5::io::Writeable * open_write(unsigned len) override
Open a new frame to the designated address and type.
bool matches_reply_address() const override
Does this Address object match the parent interface's current reply address? Multicast destinations s...
bool is_multicast() const override
Is the destination a broadcast or multicast address? Child MUST override these method.
void retry() override
If this Address is not in the ready() state, reattempt any steps required to do so,...
void init(satcat5::ip::Dispatch *iface)
Deferred initialization of the upstream interface.
Address(satcat5::ip::Dispatch *iface, u8 proto)
Create this object and bind it to a network interface.
Protocol handler and dispatch unit for Internet Protocol v4 (IPv4).
satcat5::io::Writeable * open_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.
satcat5::ip::Route route_lookup(const satcat5::ip::Addr &dstaddr) const
Routing table shortcuts.
The "Dispatch" is a generic interface that knows how to read a designated protocol layer and sort inc...
An Ethernet MAC address (with serializable interface).
bool is_multicast() const
Broadcast, L2 multicast, or L3 multicast.
bool is_unicast() const
Any normal single-destination address.
Header contents for an 802.1Q Virtual-LAN tag.
u16 vid() const
Accessors for each individual field.
void join(satcat5::igmp::Client *igmp, const satcat5::ip::Addr &addr)
Join a multicast group.
void leave(satcat5::igmp::Client *igmp)
Leave a multicast group.
IPv4 address is a 32-bit unsigned integer.
bool is_multicast() const
IP multicast (224.*.*.*)
bool is_unicast() const
Any normal single-destination address.
bool is_broadcast() const
Limited broadcast (255.255.255.255)
bool interval_msec(unsigned msec)
Test an interval measured in milliseconds.