mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-02-02 09:47:03 +03:00
networkd: add support to set route table
networkd: add support to set route table 1. add support to configure the table id. if id is less than 256 we can fit this in the header of route as netlink property is a char. But in kernel this proepty is a unsigned 32. Hence if greater that 256 add this as RTA_TABLE attribute. 2. we are not setting the address family now. Now set this property.
This commit is contained in:
parent
ec1bb27931
commit
c953b24c65
@ -706,6 +706,14 @@
|
||||
<citerefentry project='man-pages'><refentrytitle>inet_pton</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term><varname>Table=<replaceable>num</replaceable></varname></term>
|
||||
<listitem>
|
||||
<para>The table identifier for the route (a number between 1 and 4294967295, or 0 to unset).
|
||||
The table can be retrieved using <command>ip route show table <replaceable>num</replaceable></command>.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
</refsect1>
|
||||
|
||||
|
@ -71,6 +71,7 @@ Route.Source, config_parse_destination,
|
||||
Route.Metric, config_parse_route_priority, 0, 0
|
||||
Route.Scope, config_parse_route_scope, 0, 0
|
||||
Route.PreferredSource, config_parse_preferred_src, 0, 0
|
||||
Route.Table, config_parse_route_table, 0, 0
|
||||
DHCP.ClientIdentifier, config_parse_dhcp_client_identifier, 0, offsetof(Network, dhcp_client_identifier)
|
||||
DHCP.UseDNS, config_parse_bool, 0, offsetof(Network, dhcp_use_dns)
|
||||
DHCP.UseNTP, config_parse_bool, 0, offsetof(Network, dhcp_use_ntp)
|
||||
|
@ -451,6 +451,10 @@ int route_configure(Route *route, Link *link,
|
||||
r = sd_netlink_message_append_in6_addr(req, RTA_GATEWAY, &route->gw.in6);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Could not append RTA_GATEWAY attribute: %m");
|
||||
|
||||
r = sd_rtnl_message_route_set_family(req, route->family);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Could not set route family: %m");
|
||||
}
|
||||
|
||||
if (route->dst_prefixlen) {
|
||||
@ -494,7 +498,26 @@ int route_configure(Route *route, Link *link,
|
||||
|
||||
r = sd_rtnl_message_route_set_flags(req, route->flags);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Colud not set flags: %m");
|
||||
return log_error_errno(r, "Could not set flags: %m");
|
||||
|
||||
if (route->table != RT_TABLE_DEFAULT) {
|
||||
|
||||
if (route->table < 256) {
|
||||
r = sd_rtnl_message_route_set_table(req, route->table);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Could not set route table: %m");
|
||||
} else {
|
||||
|
||||
r = sd_rtnl_message_route_set_table(req, RT_TABLE_UNSPEC);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Could not set route table: %m");
|
||||
|
||||
/* Table attribute to allow allow more than 256. */
|
||||
r = sd_netlink_message_append_data(req, RTA_TABLE, &route->table, sizeof(route->table));
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Could not append RTA_TABLE attribute: %m");
|
||||
}
|
||||
}
|
||||
|
||||
r = sd_netlink_message_append_u32(req, RTA_PRIORITY, route->priority);
|
||||
if (r < 0)
|
||||
@ -777,3 +800,42 @@ int config_parse_route_scope(const char *unit,
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int config_parse_route_table(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_ 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, section_line, &n);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = safe_atou32(rvalue, &k);
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_ERR, filename, line, r,
|
||||
"Could not parse route table number \"%s\", ignoring assignment: %m", rvalue);
|
||||
return 0;
|
||||
}
|
||||
|
||||
n->table = k;
|
||||
|
||||
n = NULL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ struct Route {
|
||||
unsigned char protocol; /* RTPROT_* */
|
||||
unsigned char tos;
|
||||
uint32_t priority; /* note that ip(8) calls this 'metric' */
|
||||
unsigned char table;
|
||||
uint32_t table;
|
||||
unsigned char pref;
|
||||
unsigned flags;
|
||||
|
||||
@ -74,3 +74,4 @@ int config_parse_preferred_src(const char *unit, const char *filename, unsigned
|
||||
int config_parse_destination(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);
|
||||
int config_parse_route_priority(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);
|
||||
int config_parse_route_scope(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);
|
||||
int config_parse_route_table(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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user