Merge pull request #28871 from ssahani/route-hoplimit
network: static route - Allow to configure per route hop liimt
This commit is contained in:
@@ -1617,6 +1617,13 @@ allow my_server_t localnet_peer_t:peer recv;</programlisting>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><varname>HopLimit=</varname></term>
|
||||
<listitem>
|
||||
<para> Configures per route hop limit. See also <varname>IPv6HopLimit=</varname>.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><varname>Protocol=</varname></term>
|
||||
<listitem>
|
||||
|
||||
@@ -197,6 +197,7 @@ Route.IPv6Preference, config_parse_ipv6_route_preference,
|
||||
Route.Protocol, config_parse_route_protocol, 0, 0
|
||||
Route.Type, config_parse_route_type, 0, 0
|
||||
Route.TCPRetransmissionTimeOutSec, config_parse_route_tcp_rto, 0, 0
|
||||
Route.HopLimit, config_parse_route_hop_limit, 0, 0
|
||||
Route.InitialCongestionWindow, config_parse_route_tcp_window, 0, 0
|
||||
Route.InitialAdvertisedReceiveWindow, config_parse_route_tcp_window, 0, 0
|
||||
Route.TCPAdvertisedMaximumSegmentSize, config_parse_tcp_advmss, 0, 0
|
||||
|
||||
@@ -2532,6 +2532,67 @@ int config_parse_route_type(
|
||||
return 0;
|
||||
}
|
||||
|
||||
int config_parse_route_hop_limit(
|
||||
const char *unit,
|
||||
const char *filename,
|
||||
unsigned line,
|
||||
const char *section,
|
||||
unsigned section_line,
|
||||
const char *lvalue,
|
||||
int ltype,
|
||||
const char *rvalue,
|
||||
void *data,
|
||||
void *userdata) {
|
||||
|
||||
_cleanup_(route_free_or_set_invalidp) Route *n = NULL;
|
||||
Network *network = userdata;
|
||||
uint32_t k;
|
||||
int r;
|
||||
|
||||
assert(filename);
|
||||
assert(section);
|
||||
assert(lvalue);
|
||||
assert(rvalue);
|
||||
assert(data);
|
||||
|
||||
r = route_new_static(network, filename, section_line, &n);
|
||||
if (r == -ENOMEM)
|
||||
return log_oom();
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"Failed to allocate route, ignoring assignment: %m");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (isempty(rvalue)) {
|
||||
n->hop_limit = 0;
|
||||
TAKE_PTR(n);
|
||||
return 0;
|
||||
}
|
||||
|
||||
r = safe_atou32(rvalue, &k);
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"Could not parse route hop limit %s \"%s\", ignoring assignment: %m", lvalue, rvalue);
|
||||
return 0;
|
||||
}
|
||||
if (k > 255) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, 0,
|
||||
"Specified route hop limit %s \"%s\" is too large, ignoring assignment: %m", lvalue, rvalue);
|
||||
return 0;
|
||||
}
|
||||
if (k == 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, 0,
|
||||
"Invalid route hop limit %s \"%s\", ignoring assignment: %m", lvalue, rvalue);
|
||||
return 0;
|
||||
}
|
||||
|
||||
n->hop_limit = k;
|
||||
|
||||
TAKE_PTR(n);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int config_parse_tcp_congestion(
|
||||
const char *unit,
|
||||
const char *filename,
|
||||
|
||||
@@ -125,6 +125,7 @@ CONFIG_PARSER_PROTOTYPE(config_parse_ipv6_route_preference);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_route_protocol);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_route_type);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_route_tcp_window);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_route_hop_limit);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_tcp_window);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_route_tcp_rto);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_route_mtu);
|
||||
|
||||
@@ -44,6 +44,10 @@ InitialAdvertisedReceiveWindow=30
|
||||
Destination=192.168.1.3
|
||||
TCPAdvertisedMaximumSegmentSize=30
|
||||
|
||||
[Route]
|
||||
Destination=192.168.1.4
|
||||
HopLimit=122
|
||||
|
||||
[Route]
|
||||
Type=blackhole
|
||||
Destination=202.54.1.2
|
||||
|
||||
@@ -2946,6 +2946,7 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
|
||||
self.assertIn('192.168.1.1 proto static scope link initcwnd 20', output)
|
||||
self.assertIn('192.168.1.2 proto static scope link initrwnd 30', output)
|
||||
self.assertIn('192.168.1.3 proto static scope link advmss 30', output)
|
||||
self.assertIn('192.168.1.4 proto static scope link hoplimit 122', output)
|
||||
self.assertIn('multicast 149.10.123.4 proto static', output)
|
||||
|
||||
print('### ip -4 route show dev dummy98 default')
|
||||
|
||||
Reference in New Issue
Block a user