Kernel: Implement basic gateway for network interfaces
This commit is contained in:
@@ -45,6 +45,9 @@ namespace Kernel
|
||||
if (ipv4_address == s_broadcast_ipv4)
|
||||
return s_broadcast_mac;
|
||||
|
||||
if (interface.get_ipv4_address().mask(interface.get_netmask()) != ipv4_address.mask(interface.get_netmask()))
|
||||
ipv4_address = interface.get_gateway();
|
||||
|
||||
{
|
||||
LockGuard _(m_lock);
|
||||
if (m_arp_table.contains(ipv4_address))
|
||||
|
||||
@@ -171,6 +171,22 @@ namespace Kernel
|
||||
dprintln("Netmask set to {}", m_interface->get_netmask());
|
||||
return 0;
|
||||
}
|
||||
case SIOCGIFGWADDR:
|
||||
{
|
||||
auto& ifru_gwaddr = *reinterpret_cast<sockaddr_in*>(&ifreq->ifr_ifru.ifru_gwaddr);
|
||||
ifru_gwaddr.sin_family = AF_INET;
|
||||
ifru_gwaddr.sin_addr.s_addr = m_interface->get_gateway().raw;
|
||||
return 0;
|
||||
}
|
||||
case SIOCSIFGWADDR:
|
||||
{
|
||||
auto& ifru_gwaddr = *reinterpret_cast<const sockaddr_in*>(&ifreq->ifr_ifru.ifru_gwaddr);
|
||||
if (ifru_gwaddr.sin_family != AF_INET)
|
||||
return BAN::Error::from_errno(EADDRNOTAVAIL);
|
||||
m_interface->set_gateway(BAN::IPv4Address { ifru_gwaddr.sin_addr.s_addr });
|
||||
dprintln("Gateway set to {}", m_interface->get_gateway());
|
||||
return 0;
|
||||
}
|
||||
case SIOCGIFHWADDR:
|
||||
{
|
||||
auto mac_address = m_interface->get_mac_address();
|
||||
|
||||
Reference in New Issue
Block a user