6 #include <satcat5/router2_basic_nat.h>
9 using satcat5::ip::checksum;
15 , m_ext(satcat5::ip::DEFAULT_ROUTE)
16 , m_int(satcat5::ip::DEFAULT_ROUTE)
23 if (ip_ext.
mask != ip_int.
mask)
return false;
35 static inline u16 upper(u32 x)
36 {
return u16(x >> 16); }
37 static inline u16 lower(u32 x)
38 {
return u16(x & 0xFFFF); }
40 static void translate_packet(
55 }
else if (pkt.
is_ip()) {
62 pkt.
ip.
data[6] += diff_msb;
63 pkt.
ip.
data[7] += diff_lsb;
67 pkt.
ip.
data[8] += diff_msb;
68 pkt.
ip.
data[9] += diff_lsb;
74 for (
unsigned a = 0 ; a < changed ; ++a) {
85 translate_packet(pkt, m_ext, m_int);
89 translate_packet(pkt, m_int, m_ext);
Generic packetized I/O interface for use with SwitchCore.
Basic Network Address Translation (NAT) for the IPv4 router.
void ingress(satcat5::eth::PluginPacket &pkt) override
Packet-received callback.
void egress(satcat5::eth::PluginPacket &pkt) override
Packet-transmit callback.
bool config(const satcat5::ip::Subnet &ip_ext, const satcat5::ip::Subnet &ip_int)
Change the NAT configuration.
Ephemeral data structure provided to plugin callbacks.
satcat5::ip::Header ip
Copy of additional header fields, if present.
bool is_ip() const
Accessors and shortcuts for packet metadata.
satcat5::tcp::Header tcp
Copy of additional header fields, if present.
bool is_arp() const
Accessors and shortcuts for packet metadata.
satcat5::eth::ArpHeader arp
Copy of additional header fields, if present.
bool is_tcp() const
Accessors and shortcuts for packet metadata.
void adjust()
Notify parent that header contents have changed.
u32 value
Raw access to the underlying representation.
An IPv4 subnet consists of a base address and a subnet mask.
satcat5::ip::Mask mask
Subnet mask.
constexpr bool contains(const satcat5::ip::Addr &other) const
Does this subnet contain the given address?
satcat5::ip::Addr addr
Base address.