summaryrefslogtreecommitdiff
path: root/src/libsystemd-rtnl
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2013-12-06 18:16:16 +0100
committerTom Gundersen <teg@jklm.no>2013-12-16 17:28:18 +0100
commitfc25d7f8050f262fa6cafeb2a1032e6eb3e7b412 (patch)
tree97369539c35eacfa87c33e859bea8f7acd267223 /src/libsystemd-rtnl
parent23a7f0f721ff4e3b3fd4ed87f7d8e01ebad20093 (diff)
rtnl: simplify link_new()
Drop most of the arguments and instead introduce link_set_{flags,type}.
Diffstat (limited to 'src/libsystemd-rtnl')
-rw-r--r--src/libsystemd-rtnl/rtnl-message.c24
-rw-r--r--src/libsystemd-rtnl/rtnl-util.c4
-rw-r--r--src/libsystemd-rtnl/test-rtnl.c16
3 files changed, 31 insertions, 13 deletions
diff --git a/src/libsystemd-rtnl/rtnl-message.c b/src/libsystemd-rtnl/rtnl-message.c
index 870fdcdf2..8a3aa63ba 100644
--- a/src/libsystemd-rtnl/rtnl-message.c
+++ b/src/libsystemd-rtnl/rtnl-message.c
@@ -160,7 +160,27 @@ int sd_rtnl_message_route_new(uint16_t nlmsg_type, unsigned char rtm_family,
return 0;
}
-int sd_rtnl_message_link_new(uint16_t nlmsg_type, int index, unsigned type, unsigned flags, sd_rtnl_message **ret) {
+int sd_rtnl_message_link_set_flags(sd_rtnl_message *m, unsigned flags) {
+ struct ifinfomsg *ifi;
+
+ ifi = NLMSG_DATA(m->hdr);
+
+ ifi->ifi_flags = flags;
+
+ return 0;
+}
+
+int sd_rtnl_message_link_set_type(sd_rtnl_message *m, unsigned type) {
+ struct ifinfomsg *ifi;
+
+ ifi = NLMSG_DATA(m->hdr);
+
+ ifi->ifi_type = type;
+
+ return 0;
+}
+
+int sd_rtnl_message_link_new(uint16_t nlmsg_type, int index, sd_rtnl_message **ret) {
struct ifinfomsg *ifi;
int r;
@@ -181,8 +201,6 @@ int sd_rtnl_message_link_new(uint16_t nlmsg_type, int index, unsigned type, unsi
ifi->ifi_family = AF_UNSPEC;
ifi->ifi_index = index;
- ifi->ifi_type = type;
- ifi->ifi_flags = flags;
ifi->ifi_change = 0xffffffff;
return 0;
diff --git a/src/libsystemd-rtnl/rtnl-util.c b/src/libsystemd-rtnl/rtnl-util.c
index 4e7661bb7..264b72ec3 100644
--- a/src/libsystemd-rtnl/rtnl-util.c
+++ b/src/libsystemd-rtnl/rtnl-util.c
@@ -34,7 +34,7 @@ int rtnl_set_link_name(sd_rtnl *rtnl, int ifindex, const char *name) {
assert(ifindex > 0);
assert(name);
- r = sd_rtnl_message_link_new(RTM_SETLINK, ifindex, 0, 0, &message);
+ r = sd_rtnl_message_link_new(RTM_SETLINK, ifindex, &message);
if (r < 0)
return r;
@@ -61,7 +61,7 @@ int rtnl_set_link_properties(sd_rtnl *rtnl, int ifindex, const char *alias,
if (!alias && !mac && mtu == 0)
return 0;
- r = sd_rtnl_message_link_new(RTM_SETLINK, ifindex, 0, 0, &message);
+ r = sd_rtnl_message_link_new(RTM_SETLINK, ifindex, &message);
if (r < 0)
return r;
diff --git a/src/libsystemd-rtnl/test-rtnl.c b/src/libsystemd-rtnl/test-rtnl.c
index 6c34a8537..409a0fa7b 100644
--- a/src/libsystemd-rtnl/test-rtnl.c
+++ b/src/libsystemd-rtnl/test-rtnl.c
@@ -37,7 +37,7 @@ static void test_link_configure(sd_rtnl *rtnl, int ifindex) {
void *data;
/* we'd really like to test NEWLINK, but let's not mess with the running kernel */
- assert(sd_rtnl_message_link_new(RTM_GETLINK, ifindex, 0, 0, &message) >= 0);
+ assert(sd_rtnl_message_link_new(RTM_GETLINK, ifindex, &message) >= 0);
assert(sd_rtnl_message_append(message, IFLA_IFNAME, name) >= 0);
assert(sd_rtnl_message_append(message, IFLA_ADDRESS, ether_aton(mac)) >= 0);
assert(sd_rtnl_message_append(message, IFLA_MTU, &mtu) >= 0);
@@ -142,7 +142,7 @@ static void test_event_loop(int ifindex) {
assert(ifname);
assert(sd_rtnl_open(0, &rtnl) >= 0);
- assert(sd_rtnl_message_link_new(RTM_GETLINK, ifindex, 0, 0, &m) >= 0);
+ assert(sd_rtnl_message_link_new(RTM_GETLINK, ifindex, &m) >= 0);
assert(sd_rtnl_call_async(rtnl, m, &link_handler, ifname, 0, NULL) >= 0);
@@ -176,7 +176,7 @@ static void test_async(int ifindex) {
assert(sd_rtnl_open(0, &rtnl) >= 0);
- assert(sd_rtnl_message_link_new(RTM_GETLINK, ifindex, 0, 0, &m) >= 0);
+ assert(sd_rtnl_message_link_new(RTM_GETLINK, ifindex, &m) >= 0);
assert(sd_rtnl_call_async(rtnl, m, &link_handler, ifname, 0, &serial) >= 0);
@@ -191,8 +191,8 @@ static void test_pipe(int ifindex) {
assert(sd_rtnl_open(0, &rtnl) >= 0);
- assert(sd_rtnl_message_link_new(RTM_GETLINK, ifindex, 0, 0, &m1) >= 0);
- assert(sd_rtnl_message_link_new(RTM_GETLINK, ifindex, 0, 0, &m2) >= 0);
+ assert(sd_rtnl_message_link_new(RTM_GETLINK, ifindex, &m1) >= 0);
+ assert(sd_rtnl_message_link_new(RTM_GETLINK, ifindex, &m2) >= 0);
counter ++;
assert(sd_rtnl_call_async(rtnl, m1, &pipe_handler, &counter, 0, NULL) >= 0);
@@ -211,7 +211,7 @@ static void test_container(void) {
uint16_t type;
void *data;
- assert(sd_rtnl_message_link_new(RTM_NEWLINK, 0, 0, 0, &m) >= 0);
+ assert(sd_rtnl_message_link_new(RTM_NEWLINK, 0, &m) >= 0);
assert(sd_rtnl_message_open_container(m, IFLA_LINKINFO) >= 0);
assert(sd_rtnl_message_open_container(m, IFLA_LINKINFO) == -EINVAL);
@@ -275,7 +275,7 @@ int main(void) {
test_link_configure(rtnl, if_loopback);
- assert(sd_rtnl_message_link_new(RTM_GETLINK, if_loopback, 0, 0, &m) >= 0);
+ assert(sd_rtnl_message_link_new(RTM_GETLINK, if_loopback, &m) >= 0);
assert(m);
assert(sd_rtnl_message_get_type(m, &type) >= 0);
@@ -294,7 +294,7 @@ int main(void) {
assert((m = sd_rtnl_message_unref(m)) == NULL);
assert((r = sd_rtnl_message_unref(r)) == NULL);
- assert(sd_rtnl_message_link_new(RTM_GETLINK, if_loopback, 0, 0, &m) >= 0);
+ assert(sd_rtnl_message_link_new(RTM_GETLINK, if_loopback, &m) >= 0);
assert(m);
assert(sd_rtnl_message_append(m, IFLA_MTU, &mtu) >= 0);