SatCat5
ip_address.h
1 // Copyright 2021-2025 The Aerospace Corporation.
3 // This file is a part of SatCat5, licensed under CERN-OHL-W v2 or later.
5 // IPv4 address with automatic or manual MAC-address resolution
6 
7 #pragma once
8 
9 #include <satcat5/eth_arp.h>
10 #include <satcat5/igmp_client.h>
11 #include <satcat5/ip_dispatch.h>
12 #include <satcat5/net_core.h>
13 #include <satcat5/timeref.h>
14 
15 namespace satcat5 {
16  namespace ip {
35  class Address final
36  : public satcat5::net::Address
38  {
39  public:
45  ~Address() SATCAT5_OPTIONAL_DTOR;
46 
51 
56  void connect(
57  const satcat5::ip::Addr& dstaddr,
58  const satcat5::eth::VlanTag& vtag = satcat5::eth::VTAG_NONE);
59 
61  void connect(
62  const satcat5::ip::Addr& dstaddr,
63  const satcat5::eth::MacAddr& dstmac,
64  const satcat5::eth::VlanTag& vtag = satcat5::eth::VTAG_NONE);
65 
66  // Required overrides from net::Address:
67  void close() override;
68  bool ready() const override {return m_ready;}
69  void retry() override;
70  satcat5::net::Dispatch* iface() const override;
71  satcat5::io::Writeable* open_write(unsigned len) override;
72  bool is_multicast() const override;
73  bool matches_reply_address() const override;
74  bool reply_is_multicast() const override;
75  void save_reply_address() override;
76 
77  // Various accessors.
78  inline satcat5::eth::MacAddr dstmac() const
79  { return m_dstmac; }
80  inline satcat5::eth::MacAddr srcmac() const
81  { return m_iface->macaddr(); }
82  inline satcat5::eth::VlanTag vtag() const
83  { return m_vtag; }
84  inline satcat5::eth::Dispatch* eth() const
85  { return m_iface->iface(); }
86  inline satcat5::eth::Header eth_header() const
87  { return {dstmac(), srcmac(), satcat5::eth::ETYPE_IPV4, vtag()}; }
88  inline satcat5::ip::Addr dstaddr() const
89  { return m_dstaddr; }
90  inline satcat5::ip::Addr gateway() const
91  { return m_gateway; }
92 
93  protected:
94  void arp_event(
95  const satcat5::eth::MacAddr& mac,
96  const satcat5::ip::Addr& ip) override;
97  void gateway_change(
98  const satcat5::ip::Addr& dstaddr,
99  const satcat5::ip::Addr& gateway) override;
100 
101  satcat5::ip::Dispatch* m_iface;
102  const u8 m_proto;
103  u8 m_ready;
104  satcat5::util::TimeVal m_arp_tref;
105  satcat5::eth::MacAddr m_dstmac;
106  satcat5::ip::Addr m_dstaddr;
107  satcat5::ip::Addr m_gateway;
108  satcat5::eth::VlanTag m_vtag;
109  satcat5::igmp::Address m_igmp;
110  };
111  }
112 }
Callback interface for responding to ARP and ICMP events.
Definition: eth_arp.h:46
Implemention of "net::Dispatch" for Ethernet frames.
Definition: eth_dispatch.h:21
Abstract API for writing byte-streams and packets.
Definition: io_writeable.h:24
Connection metadata for an IPv4 address.
Definition: ip_address.h:38
bool ready() const override
Is this address object ready for use? Child MUST override this method.
Definition: ip_address.h:68
void connect(const satcat5::ip::Addr &dstaddr, const satcat5::eth::VlanTag &vtag=satcat5::eth::VTAG_NONE)
Automatic address resolution using routing table + ARP.
Definition: ip_address.cc:54
void close() override
Close any open connections and revert to idle.
Definition: ip_address.cc:108
void arp_event(const satcat5::eth::MacAddr &mac, const satcat5::ip::Addr &ip) override
Callback for any announced MAC/IP address pair.
Definition: ip_address.cc:161
void save_reply_address() override
Bind this Address object to the parent interface's current reply address, as provided in net::Dispatc...
Definition: ip_address.cc:152
bool reply_is_multicast() const override
Was the parent interface's incoming message sent to a multicast address? (i.e., Could that message ha...
Definition: ip_address.cc:148
satcat5::net::Dispatch * iface() const override
Fetch a pointer to the underlying interface.
Definition: ip_address.cc:121
void gateway_change(const satcat5::ip::Addr &dstaddr, const satcat5::ip::Addr &gateway) override
Callback for changes to gateway configuration.
Definition: ip_address.cc:169
satcat5::io::Writeable * open_write(unsigned len) override
Open a new frame to the designated address and type.
Definition: ip_address.cc:124
bool matches_reply_address() const override
Does this Address object match the parent interface's current reply address? Multicast destinations s...
Definition: ip_address.cc:139
bool is_multicast() const override
Is the destination a broadcast or multicast address? Child MUST override these method.
Definition: ip_address.cc:135
void retry() override
If this Address is not in the ready() state, reattempt any steps required to do so,...
Definition: ip_address.cc:101
void init(satcat5::ip::Dispatch *iface)
Deferred initialization of the upstream interface.
Definition: ip_address.cc:47
Address(satcat5::ip::Dispatch *iface, u8 proto)
Create this object and bind it to a network interface.
Definition: ip_address.cc:25
Protocol handler and dispatch unit for Internet Protocol v4 (IPv4).
Definition: ip_dispatch.h:43
Defines a generic API for sending data to a specific destination, such as a MAC address,...
Definition: net_address.h:30
The "Dispatch" is a generic interface that knows how to read a designated protocol layer and sort inc...
Definition: net_dispatch.h:36
Protocol handler for the Address Resolution Protocol (ARP)
Client-side implementation of the Internet Group Management Protocol (IGMP)
Generic network Dispatch API.
An Ethernet frame header.
Definition: eth_header.h:167
An Ethernet MAC address (with serializable interface).
Definition: eth_header.h:29
Header contents for an 802.1Q Virtual-LAN tag.
Definition: eth_header.h:124
Client state for an IGMP multicast subscription.
Definition: igmp_client.h:145
IPv4 address is a 32-bit unsigned integer.
Definition: ip_core.h:15
Timestamp for measuring elapsed time.
Definition: timeref.h:48
TimeRef and TimeVal define the API for monotonic timers.