summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libsystemd-rtnl/rtnl-message.c28
-rw-r--r--src/libsystemd-rtnl/test-rtnl.c4
-rw-r--r--src/network/networkd-route.c10
-rw-r--r--src/systemd/sd-rtnl.h5
4 files changed, 29 insertions, 18 deletions
diff --git a/src/libsystemd-rtnl/rtnl-message.c b/src/libsystemd-rtnl/rtnl-message.c
index 8a3aa63baf..f8f2bcd4a6 100644
--- a/src/libsystemd-rtnl/rtnl-message.c
+++ b/src/libsystemd-rtnl/rtnl-message.c
@@ -125,15 +125,23 @@ bool message_type_is_addr(uint16_t type) {
}
}
+int sd_rtnl_message_route_set_dst_prefixlen(sd_rtnl_message *m, unsigned char prefixlen) {
+ struct rtmsg *rtm;
+
+ rtm = NLMSG_DATA(m->hdr);
+
+ rtm->rtm_dst_len = prefixlen;
+
+ return 0;
+}
+
int sd_rtnl_message_route_new(uint16_t nlmsg_type, unsigned char rtm_family,
- unsigned char rtm_dst_len, unsigned char rtm_src_len,
- unsigned char rtm_tos, unsigned char rtm_table,
- unsigned char rtm_scope, unsigned char rtm_protocol,
- unsigned char rtm_type, unsigned rtm_flags, sd_rtnl_message **ret) {
+ sd_rtnl_message **ret) {
struct rtmsg *rtm;
int r;
assert_return(message_type_is_route(nlmsg_type), -EINVAL);
+ assert_return(rtm_family == AF_INET || rtm_family == AF_INET6, -EINVAL);
assert_return(ret, -EINVAL);
r = message_new(ret, NLMSG_SPACE(sizeof(struct rtmsg)));
@@ -148,14 +156,10 @@ int sd_rtnl_message_route_new(uint16_t nlmsg_type, unsigned char rtm_family,
rtm = NLMSG_DATA((*ret)->hdr);
rtm->rtm_family = rtm_family;
- rtm->rtm_dst_len = rtm_dst_len;
- rtm->rtm_src_len = rtm_src_len;
- rtm->rtm_tos = rtm_tos;
- rtm->rtm_table = rtm_table;
- rtm->rtm_protocol = rtm_protocol;
- rtm->rtm_scope = rtm_scope;
- rtm->rtm_type = rtm_type;
- rtm->rtm_flags = rtm_flags;
+ rtm->rtm_scope = RT_SCOPE_UNIVERSE;
+ rtm->rtm_type = RTN_UNICAST;
+ rtm->rtm_table = RT_TABLE_MAIN;
+ rtm->rtm_protocol = RTPROT_BOOT;
return 0;
}
diff --git a/src/libsystemd-rtnl/test-rtnl.c b/src/libsystemd-rtnl/test-rtnl.c
index 409a0fa7b2..bfcfc85d93 100644
--- a/src/libsystemd-rtnl/test-rtnl.c
+++ b/src/libsystemd-rtnl/test-rtnl.c
@@ -65,9 +65,7 @@ static void test_route(void) {
void *data;
int r;
- r = sd_rtnl_message_route_new(RTM_NEWROUTE, AF_INET, 0, 0, 0,
- RT_TABLE_MAIN, RT_SCOPE_UNIVERSE, RTPROT_BOOT,
- RTN_UNICAST, 0, &req);
+ r = sd_rtnl_message_route_new(RTM_NEWROUTE, AF_INET, &req);
if (r < 0) {
log_error("Could not create RTM_NEWROUTE message: %s", strerror(-r));
return;
diff --git a/src/network/networkd-route.c b/src/network/networkd-route.c
index 1ea6237cc7..f8580e93c8 100644
--- a/src/network/networkd-route.c
+++ b/src/network/networkd-route.c
@@ -86,9 +86,7 @@ int route_configure(Route *route, Link *link,
assert(link->ifindex > 0);
assert(route->family == AF_INET || route->family == AF_INET6);
- r = sd_rtnl_message_route_new(RTM_NEWROUTE, route->family, route->dst_prefixlen,
- 0, 0, RT_TABLE_MAIN, RT_SCOPE_UNIVERSE,
- RTPROT_BOOT, RTN_UNICAST, 0, &req);
+ r = sd_rtnl_message_route_new(RTM_NEWROUTE, route->family, &req);
if (r < 0) {
log_error("Could not create RTM_NEWROUTE message: %s", strerror(-r));
return r;
@@ -106,6 +104,12 @@ int route_configure(Route *route, Link *link,
return r;
}
+ r = sd_rtnl_message_route_set_dst_prefixlen(req, route->dst_prefixlen);
+ if (r < 0) {
+ log_error("Could not set destination prefix length: %s", strerror(-r));
+ return r;
+ }
+
r = sd_rtnl_message_append(req, RTA_OIF, &link->ifindex);
if (r < 0) {
log_error("Could not append RTA_OIF attribute: %s", strerror(-r));
diff --git a/src/systemd/sd-rtnl.h b/src/systemd/sd-rtnl.h
index 066d778ce1..f851afa54b 100644
--- a/src/systemd/sd-rtnl.h
+++ b/src/systemd/sd-rtnl.h
@@ -69,10 +69,13 @@ int sd_rtnl_message_addr_new(uint16_t msg_type, int index, unsigned char family,
unsigned char prefixlen, unsigned char flags,
unsigned char scope, sd_rtnl_message **ret);
int sd_rtnl_message_route_new(uint16_t nlmsg_type, unsigned char rtm_family,
+ sd_rtnl_message **ret);
+/*
unsigned char rtm_dst_len, unsigned char rtm_src_len,
unsigned char rtm_tos, unsigned char rtm_table,
unsigned char rtm_scope, unsigned char rtm_protocol,
unsigned char rtm_type, unsigned flags, sd_rtnl_message **ret);
+*/
sd_rtnl_message *sd_rtnl_message_ref(sd_rtnl_message *m);
sd_rtnl_message *sd_rtnl_message_unref(sd_rtnl_message *m);
@@ -84,6 +87,8 @@ int sd_rtnl_message_link_set_type(sd_rtnl_message *m, unsigned type);
int sd_rtnl_message_link_get_ifindex(sd_rtnl_message *m, int *ifindex);
int sd_rtnl_message_link_get_flags(sd_rtnl_message *m, unsigned *flags);
+int sd_rtnl_message_route_set_dst_prefixlen(sd_rtnl_message *m, unsigned char prefixlen);
+
int sd_rtnl_message_append(sd_rtnl_message *m, unsigned short type, const void *data);
int sd_rtnl_message_open_container(sd_rtnl_message *m, unsigned short type);
int sd_rtnl_message_close_container(sd_rtnl_message *m);