diff options
author | Tom Gundersen <teg@jklm.no> | 2013-12-07 21:18:44 +0100 |
---|---|---|
committer | Tom Gundersen <teg@jklm.no> | 2013-12-16 17:28:18 +0100 |
commit | 1f01fb4f29bbe6aff952331a538fb3cc7f52dab4 (patch) | |
tree | 2b11faabf119d3eeb835db6a5b88f94e05514c14 /src/libsystemd-rtnl | |
parent | fc25d7f8050f262fa6cafeb2a1032e6eb3e7b412 (diff) |
rtnl: simplify route_new()
Drop most of the arguments and instead introduce set_dst_prefixlen().
Diffstat (limited to 'src/libsystemd-rtnl')
-rw-r--r-- | src/libsystemd-rtnl/rtnl-message.c | 28 | ||||
-rw-r--r-- | src/libsystemd-rtnl/test-rtnl.c | 4 |
2 files changed, 17 insertions, 15 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; |