summaryrefslogtreecommitdiff
path: root/src/libsystemd/sd-rtnl
diff options
context:
space:
mode:
Diffstat (limited to 'src/libsystemd/sd-rtnl')
-rw-r--r--src/libsystemd/sd-rtnl/rtnl-message.c50
-rw-r--r--src/libsystemd/sd-rtnl/rtnl-types.c2
-rw-r--r--src/libsystemd/sd-rtnl/rtnl-types.h1
-rw-r--r--src/libsystemd/sd-rtnl/test-rtnl.c2
4 files changed, 54 insertions, 1 deletions
diff --git a/src/libsystemd/sd-rtnl/rtnl-message.c b/src/libsystemd/sd-rtnl/rtnl-message.c
index 4ace94ce18..e5854de4c6 100644
--- a/src/libsystemd/sd-rtnl/rtnl-message.c
+++ b/src/libsystemd/sd-rtnl/rtnl-message.c
@@ -286,6 +286,19 @@ int sd_rtnl_message_new_addr(sd_rtnl *rtnl, sd_rtnl_message **ret,
return 0;
}
+int sd_rtnl_message_new_addr_update(sd_rtnl *rtnl, sd_rtnl_message **ret,
+ int index, unsigned char family) {
+ int r;
+
+ r = sd_rtnl_message_new_addr(rtnl, ret, RTM_NEWADDR, index, family);
+ if (r < 0)
+ return r;
+
+ (*ret)->hdr->nlmsg_flags |= NLM_F_REPLACE;
+
+ return 0;
+}
+
sd_rtnl_message *sd_rtnl_message_ref(sd_rtnl_message *m) {
if (m)
assert_se(REFCNT_INC(m->n_ref) >= 2);
@@ -559,6 +572,24 @@ int sd_rtnl_message_append_ether_addr(sd_rtnl_message *m, unsigned short type, c
return 0;
}
+int sd_rtnl_message_append_cache_info(sd_rtnl_message *m, unsigned short type, const struct ifa_cacheinfo *info) {
+ int r;
+
+ assert_return(m, -EINVAL);
+ assert_return(!m->sealed, -EPERM);
+ assert_return(info, -EINVAL);
+
+ r = message_attribute_has_type(m, type, NLA_CACHE_INFO);
+ if (r < 0)
+ return r;
+
+ r = add_rtattr(m, type, info, sizeof(struct ifa_cacheinfo));
+ if (r < 0)
+ return r;
+
+ return 0;
+}
+
int sd_rtnl_message_open_container(sd_rtnl_message *m, unsigned short type) {
size_t size;
int r;
@@ -741,6 +772,25 @@ int sd_rtnl_message_read_ether_addr(sd_rtnl_message *m, unsigned short type, str
return 0;
}
+int sd_rtnl_message_read_cache_info(sd_rtnl_message *m, unsigned short type, struct ifa_cacheinfo *info) {
+ int r;
+ void *attr_data;
+
+ r = message_attribute_has_type(m, type, NLA_CACHE_INFO);
+ if (r < 0)
+ return r;
+
+ r = rtnl_message_read_internal(m, type, &attr_data);
+ if (r < 0)
+ return r;
+ else if ((size_t)r < sizeof(struct ifa_cacheinfo))
+ return -EIO;
+
+ memcpy(info, attr_data, sizeof(struct ifa_cacheinfo));
+
+ return 0;
+}
+
int sd_rtnl_message_read_in_addr(sd_rtnl_message *m, unsigned short type, struct in_addr *data) {
int r;
void *attr_data;
diff --git a/src/libsystemd/sd-rtnl/rtnl-types.c b/src/libsystemd/sd-rtnl/rtnl-types.c
index 29ee5bc1c8..4e70c95127 100644
--- a/src/libsystemd/sd-rtnl/rtnl-types.c
+++ b/src/libsystemd/sd-rtnl/rtnl-types.c
@@ -216,9 +216,9 @@ static const NLType rtnl_address_types[IFA_MAX + 1] = {
[IFA_LOCAL] = { .type = NLA_IN_ADDR },
[IFA_LABEL] = { .type = NLA_STRING, .size = IFNAMSIZ - 1 },
[IFA_BROADCAST] = { .type = NLA_IN_ADDR }, /* 6? */
+ [IFA_CACHEINFO] = { .type = NLA_CACHE_INFO, .size = sizeof(struct ifa_cacheinfo) },
/*
[IFA_ANYCAST],
- [IFA_CACHEINFO] = { .len = sizeof(struct ifa_cacheinfo) },
[IFA_MULTICAST],
*/
#ifdef IFA_FLAGS
diff --git a/src/libsystemd/sd-rtnl/rtnl-types.h b/src/libsystemd/sd-rtnl/rtnl-types.h
index 2425dc92a3..7ce9597c84 100644
--- a/src/libsystemd/sd-rtnl/rtnl-types.h
+++ b/src/libsystemd/sd-rtnl/rtnl-types.h
@@ -31,6 +31,7 @@ enum {
NLA_STRING,
NLA_IN_ADDR,
NLA_ETHER_ADDR,
+ NLA_CACHE_INFO,
NLA_NESTED,
NLA_UNION,
};
diff --git a/src/libsystemd/sd-rtnl/test-rtnl.c b/src/libsystemd/sd-rtnl/test-rtnl.c
index 44369628f4..529231a70a 100644
--- a/src/libsystemd/sd-rtnl/test-rtnl.c
+++ b/src/libsystemd/sd-rtnl/test-rtnl.c
@@ -106,6 +106,7 @@ static void test_address_get(sd_rtnl *rtnl, int ifindex) {
sd_rtnl_message *m;
sd_rtnl_message *r;
struct in_addr in_data;
+ struct ifa_cacheinfo cache;
char *label;
assert_se(sd_rtnl_message_new_addr(rtnl, &m, RTM_GETADDR, ifindex, AF_INET) >= 0);
@@ -116,6 +117,7 @@ static void test_address_get(sd_rtnl *rtnl, int ifindex) {
assert_se(sd_rtnl_message_read_in_addr(r, IFA_LOCAL, &in_data) == 0);
assert_se(sd_rtnl_message_read_in_addr(r, IFA_ADDRESS, &in_data) == 0);
assert_se(sd_rtnl_message_read_string(r, IFA_LABEL, &label) == 0);
+ assert_se(sd_rtnl_message_read_cache_info(r, IFA_CACHEINFO, &cache) == 0);
assert_se(sd_rtnl_flush(rtnl) >= 0);
assert_se((m = sd_rtnl_message_unref(m)) == NULL);