chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
rtnl: when querying local addresses and gateways, take address family into account
[elogind.git]
/
src
/
libsystemd
/
sd-rtnl
/
rtnl-util.c
diff --git
a/src/libsystemd/sd-rtnl/rtnl-util.c
b/src/libsystemd/sd-rtnl/rtnl-util.c
index 0bc2c9b1f5720f68772d4264c61bbafb19a49720..194a267b04b88af126235ee2f63a17a9035871f7 100644
(file)
--- a/
src/libsystemd/sd-rtnl/rtnl-util.c
+++ b/
src/libsystemd/sd-rtnl/rtnl-util.c
@@
-26,7
+26,7
@@
#include "rtnl-util.h"
#include "rtnl-internal.h"
#include "rtnl-util.h"
#include "rtnl-internal.h"
-int rtnl_set_link_name(sd_rtnl *rtnl, int ifindex, const char *name) {
+int rtnl_set_link_name(sd_rtnl *
*
rtnl, int ifindex, const char *name) {
_cleanup_rtnl_message_unref_ sd_rtnl_message *message = NULL;
int r;
_cleanup_rtnl_message_unref_ sd_rtnl_message *message = NULL;
int r;
@@
-34,7
+34,13
@@
int rtnl_set_link_name(sd_rtnl *rtnl, int ifindex, const char *name) {
assert(ifindex > 0);
assert(name);
assert(ifindex > 0);
assert(name);
- r = sd_rtnl_message_new_link(rtnl, &message, RTM_SETLINK, ifindex);
+ if (!*rtnl) {
+ r = sd_rtnl_open(rtnl, 0);
+ if (r < 0)
+ return r;
+ }
+
+ r = sd_rtnl_message_new_link(*rtnl, &message, RTM_SETLINK, ifindex);
if (r < 0)
return r;
if (r < 0)
return r;
@@
-42,17
+48,16
@@
int rtnl_set_link_name(sd_rtnl *rtnl, int ifindex, const char *name) {
if (r < 0)
return r;
if (r < 0)
return r;
- r = sd_rtnl_call(rtnl, message, 0, NULL);
+ r = sd_rtnl_call(
*
rtnl, message, 0, NULL);
if (r < 0)
return r;
return 0;
}
if (r < 0)
return r;
return 0;
}
-int rtnl_set_link_properties(sd_rtnl *rtnl, int ifindex, const char *alias,
+int rtnl_set_link_properties(sd_rtnl *
*
rtnl, int ifindex, const char *alias,
const struct ether_addr *mac, unsigned mtu) {
_cleanup_rtnl_message_unref_ sd_rtnl_message *message = NULL;
const struct ether_addr *mac, unsigned mtu) {
_cleanup_rtnl_message_unref_ sd_rtnl_message *message = NULL;
- bool need_update = false;
int r;
assert(rtnl);
int r;
assert(rtnl);
@@
-61,7
+66,13
@@
int rtnl_set_link_properties(sd_rtnl *rtnl, int ifindex, const char *alias,
if (!alias && !mac && mtu == 0)
return 0;
if (!alias && !mac && mtu == 0)
return 0;
- r = sd_rtnl_message_new_link(rtnl, &message, RTM_SETLINK, ifindex);
+ if (!*rtnl) {
+ r = sd_rtnl_open(rtnl, 0);
+ if (r < 0)
+ return r;
+ }
+
+ r = sd_rtnl_message_new_link(*rtnl, &message, RTM_SETLINK, ifindex);
if (r < 0)
return r;
if (r < 0)
return r;
@@
-69,32
+80,23
@@
int rtnl_set_link_properties(sd_rtnl *rtnl, int ifindex, const char *alias,
r = sd_rtnl_message_append_string(message, IFLA_IFALIAS, alias);
if (r < 0)
return r;
r = sd_rtnl_message_append_string(message, IFLA_IFALIAS, alias);
if (r < 0)
return r;
-
- need_update = true;
-
}
if (mac) {
r = sd_rtnl_message_append_ether_addr(message, IFLA_ADDRESS, mac);
if (r < 0)
return r;
}
if (mac) {
r = sd_rtnl_message_append_ether_addr(message, IFLA_ADDRESS, mac);
if (r < 0)
return r;
-
- need_update = true;
}
if (mtu > 0) {
r = sd_rtnl_message_append_u32(message, IFLA_MTU, mtu);
if (r < 0)
return r;
}
if (mtu > 0) {
r = sd_rtnl_message_append_u32(message, IFLA_MTU, mtu);
if (r < 0)
return r;
-
- need_update = true;
}
}
- if (need_update) {
- r = sd_rtnl_call(rtnl, message, 0, NULL);
- if (r < 0)
- return r;
- }
+ r = sd_rtnl_call(*rtnl, message, 0, NULL);
+ if (r < 0)
+ return r;
return 0;
}
return 0;
}
@@
-120,6
+122,17
@@
int rtnl_message_new_synthetic_error(int error, uint32_t serial, sd_rtnl_message
return 0;
}
return 0;
}
+bool rtnl_message_type_is_neigh(uint16_t type) {
+ switch (type) {
+ case RTM_NEWNEIGH:
+ case RTM_GETNEIGH:
+ case RTM_DELNEIGH:
+ return true;
+ default:
+ return false;
+ }
+}
+
bool rtnl_message_type_is_route(uint16_t type) {
switch (type) {
case RTM_NEWROUTE:
bool rtnl_message_type_is_route(uint16_t type) {
switch (type) {
case RTM_NEWROUTE:
@@
-155,11
+168,9
@@
bool rtnl_message_type_is_addr(uint16_t type) {
}
int rtnl_log_parse_error(int r) {
}
int rtnl_log_parse_error(int r) {
- log_error("Failed to parse netlink message: %s", strerror(-r));
- return r;
+ return log_error_errno(r, "Failed to parse netlink message: %m");
}
int rtnl_log_create_error(int r) {
}
int rtnl_log_create_error(int r) {
- log_error("Failed to create netlink message: %s", strerror(-r));
- return r;
+ return log_error_errno(r, "Failed to create netlink message: %m");
}
}