route: Support removing entries with unknown gateway

This commit is contained in:
Maciej 2022-07-01 17:23:41 +02:00 committed by Sam Atkins
parent bea1668159
commit 20430ffeae

View file

@ -166,7 +166,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
} }
auto gateway = AK::IPv4Address::from_string(value_gateway_address); auto gateway = AK::IPv4Address::from_string(value_gateway_address);
if (!gateway.has_value()) { if (action_add && !gateway.has_value()) {
warnln("Invalid gateway IPv4 address: '{}'", value_gateway_address); warnln("Invalid gateway IPv4 address: '{}'", value_gateway_address);
return 1; return 1;
} }
@ -185,14 +185,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
rt.rt_dev = const_cast<char*>(value_interface.characters_without_null_termination()); rt.rt_dev = const_cast<char*>(value_interface.characters_without_null_termination());
rt.rt_gateway.sa_family = AF_INET; rt.rt_gateway.sa_family = AF_INET;
((sockaddr_in&)rt.rt_dst).sin_addr.s_addr = destination.value().to_in_addr_t(); ((sockaddr_in&)rt.rt_dst).sin_addr.s_addr = destination.value().to_in_addr_t();
((sockaddr_in&)rt.rt_gateway).sin_addr.s_addr = gateway.value().to_in_addr_t(); ((sockaddr_in&)rt.rt_gateway).sin_addr.s_addr = gateway.value_or(IPv4Address {}).to_in_addr_t();
((sockaddr_in&)rt.rt_genmask).sin_addr.s_addr = genmask.value().to_in_addr_t(); ((sockaddr_in&)rt.rt_genmask).sin_addr.s_addr = genmask.value().to_in_addr_t();
rt.rt_flags = RTF_UP; rt.rt_flags = RTF_UP;
if (!value_host_address.is_empty()) if (!value_host_address.is_empty())
rt.rt_flags |= RTF_HOST; rt.rt_flags |= RTF_HOST;
if (gateway.has_value())
rt.rt_flags |= RTF_GATEWAY; rt.rt_flags |= RTF_GATEWAY;
if (action_add) if (action_add)