summaryrefslogtreecommitdiff
path: root/src/libsystemd
diff options
context:
space:
mode:
Diffstat (limited to 'src/libsystemd')
l---------src/libsystemd/sd-netlink/Makefile (renamed from src/libsystemd/sd-rtnl/Makefile)0
-rw-r--r--src/libsystemd/sd-netlink/local-addresses.c (renamed from src/libsystemd/sd-rtnl/local-addresses.c)62
-rw-r--r--src/libsystemd/sd-netlink/local-addresses.h (renamed from src/libsystemd/sd-rtnl/local-addresses.h)6
-rw-r--r--src/libsystemd/sd-netlink/netlink-internal.h (renamed from src/libsystemd/sd-rtnl/rtnl-internal.h)38
-rw-r--r--src/libsystemd/sd-netlink/netlink-message.c (renamed from src/libsystemd/sd-rtnl/rtnl-message.c)186
-rw-r--r--src/libsystemd/sd-netlink/netlink-types.c (renamed from src/libsystemd/sd-rtnl/rtnl-types.c)2
-rw-r--r--src/libsystemd/sd-netlink/netlink-types.h (renamed from src/libsystemd/sd-rtnl/rtnl-types.h)0
-rw-r--r--src/libsystemd/sd-netlink/netlink-util.c (renamed from src/libsystemd/sd-rtnl/rtnl-util.c)32
-rw-r--r--src/libsystemd/sd-netlink/netlink-util.h (renamed from src/libsystemd/sd-rtnl/rtnl-util.h)20
-rw-r--r--src/libsystemd/sd-netlink/sd-netlink.c (renamed from src/libsystemd/sd-rtnl/sd-rtnl.c)168
-rw-r--r--src/libsystemd/sd-netlink/test-local-addresses.c (renamed from src/libsystemd/sd-rtnl/test-local-addresses.c)0
-rw-r--r--src/libsystemd/sd-netlink/test-netlink.c443
-rw-r--r--src/libsystemd/sd-rtnl/test-rtnl.c443
13 files changed, 700 insertions, 700 deletions
diff --git a/src/libsystemd/sd-rtnl/Makefile b/src/libsystemd/sd-netlink/Makefile
index 94aaae2c4d..94aaae2c4d 120000
--- a/src/libsystemd/sd-rtnl/Makefile
+++ b/src/libsystemd/sd-netlink/Makefile
diff --git a/src/libsystemd/sd-rtnl/local-addresses.c b/src/libsystemd/sd-netlink/local-addresses.c
index f05cbf1f47..e2f637f7f9 100644
--- a/src/libsystemd/sd-rtnl/local-addresses.c
+++ b/src/libsystemd/sd-netlink/local-addresses.c
@@ -20,8 +20,8 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
-#include "sd-rtnl.h"
-#include "rtnl-util.h"
+#include "sd-netlink.h"
+#include "netlink-util.h"
#include "macro.h"
#include "local-addresses.h"
@@ -53,20 +53,20 @@ static int address_compare(const void *_a, const void *_b) {
return memcmp(&a->address, &b->address, FAMILY_ADDRESS_SIZE(a->family));
}
-int local_addresses(sd_rtnl *context, int ifindex, int af, struct local_address **ret) {
- _cleanup_rtnl_message_unref_ sd_rtnl_message *req = NULL, *reply = NULL;
- _cleanup_rtnl_unref_ sd_rtnl *rtnl = NULL;
+int local_addresses(sd_netlink *context, int ifindex, int af, struct local_address **ret) {
+ _cleanup_netlink_message_unref_ sd_netlink_message *req = NULL, *reply = NULL;
+ _cleanup_netlink_unref_ sd_netlink *rtnl = NULL;
_cleanup_free_ struct local_address *list = NULL;
size_t n_list = 0, n_allocated = 0;
- sd_rtnl_message *m;
+ sd_netlink_message *m;
int r;
assert(ret);
if (context)
- rtnl = sd_rtnl_ref(context);
+ rtnl = sd_netlink_ref(context);
else {
- r = sd_rtnl_open(&rtnl);
+ r = sd_netlink_open(&rtnl);
if (r < 0)
return r;
}
@@ -75,21 +75,21 @@ int local_addresses(sd_rtnl *context, int ifindex, int af, struct local_address
if (r < 0)
return r;
- r = sd_rtnl_call(rtnl, req, 0, &reply);
+ r = sd_netlink_call(rtnl, req, 0, &reply);
if (r < 0)
return r;
- for (m = reply; m; m = sd_rtnl_message_next(m)) {
+ for (m = reply; m; m = sd_netlink_message_next(m)) {
struct local_address *a;
unsigned char flags;
uint16_t type;
int ifi, family;
- r = sd_rtnl_message_get_errno(m);
+ r = sd_netlink_message_get_errno(m);
if (r < 0)
return r;
- r = sd_rtnl_message_get_type(m, &type);
+ r = sd_netlink_message_get_type(m, &type);
if (r < 0)
return r;
if (type != RTM_NEWADDR)
@@ -128,18 +128,18 @@ int local_addresses(sd_rtnl *context, int ifindex, int af, struct local_address
switch (family) {
case AF_INET:
- r = sd_rtnl_message_read_in_addr(m, IFA_LOCAL, &a->address.in);
+ r = sd_netlink_message_read_in_addr(m, IFA_LOCAL, &a->address.in);
if (r < 0) {
- r = sd_rtnl_message_read_in_addr(m, IFA_ADDRESS, &a->address.in);
+ r = sd_netlink_message_read_in_addr(m, IFA_ADDRESS, &a->address.in);
if (r < 0)
continue;
}
break;
case AF_INET6:
- r = sd_rtnl_message_read_in6_addr(m, IFA_LOCAL, &a->address.in6);
+ r = sd_netlink_message_read_in6_addr(m, IFA_LOCAL, &a->address.in6);
if (r < 0) {
- r = sd_rtnl_message_read_in6_addr(m, IFA_ADDRESS, &a->address.in6);
+ r = sd_netlink_message_read_in6_addr(m, IFA_ADDRESS, &a->address.in6);
if (r < 0)
continue;
}
@@ -164,20 +164,20 @@ int local_addresses(sd_rtnl *context, int ifindex, int af, struct local_address
return (int) n_list;
}
-int local_gateways(sd_rtnl *context, int ifindex, int af, struct local_address **ret) {
- _cleanup_rtnl_message_unref_ sd_rtnl_message *req = NULL, *reply = NULL;
- _cleanup_rtnl_unref_ sd_rtnl *rtnl = NULL;
+int local_gateways(sd_netlink *context, int ifindex, int af, struct local_address **ret) {
+ _cleanup_netlink_message_unref_ sd_netlink_message *req = NULL, *reply = NULL;
+ _cleanup_netlink_unref_ sd_netlink *rtnl = NULL;
_cleanup_free_ struct local_address *list = NULL;
- sd_rtnl_message *m = NULL;
+ sd_netlink_message *m = NULL;
size_t n_list = 0, n_allocated = 0;
int r;
assert(ret);
if (context)
- rtnl = sd_rtnl_ref(context);
+ rtnl = sd_netlink_ref(context);
else {
- r = sd_rtnl_open(&rtnl);
+ r = sd_netlink_open(&rtnl);
if (r < 0)
return r;
}
@@ -186,26 +186,26 @@ int local_gateways(sd_rtnl *context, int ifindex, int af, struct local_address *
if (r < 0)
return r;
- r = sd_rtnl_message_request_dump(req, true);
+ r = sd_netlink_message_request_dump(req, true);
if (r < 0)
return r;
- r = sd_rtnl_call(rtnl, req, 0, &reply);
+ r = sd_netlink_call(rtnl, req, 0, &reply);
if (r < 0)
return r;
- for (m = reply; m; m = sd_rtnl_message_next(m)) {
+ for (m = reply; m; m = sd_netlink_message_next(m)) {
struct local_address *a;
uint16_t type;
unsigned char dst_len, src_len;
uint32_t ifi;
int family;
- r = sd_rtnl_message_get_errno(m);
+ r = sd_netlink_message_get_errno(m);
if (r < 0)
return r;
- r = sd_rtnl_message_get_type(m, &type);
+ r = sd_netlink_message_get_type(m, &type);
if (r < 0)
return r;
if (type != RTM_NEWROUTE)
@@ -224,7 +224,7 @@ int local_gateways(sd_rtnl *context, int ifindex, int af, struct local_address *
if (src_len != 0)
continue;
- r = sd_rtnl_message_read_u32(m, RTA_OIF, &ifi);
+ r = sd_netlink_message_read_u32(m, RTA_OIF, &ifi);
if (r < 0)
return r;
if (ifindex > 0 && (int) ifi != ifindex)
@@ -243,13 +243,13 @@ int local_gateways(sd_rtnl *context, int ifindex, int af, struct local_address *
switch (family) {
case AF_INET:
- r = sd_rtnl_message_read_in_addr(m, RTA_GATEWAY, &a->address.in);
+ r = sd_netlink_message_read_in_addr(m, RTA_GATEWAY, &a->address.in);
if (r < 0)
continue;
break;
case AF_INET6:
- r = sd_rtnl_message_read_in6_addr(m, RTA_GATEWAY, &a->address.in6);
+ r = sd_netlink_message_read_in6_addr(m, RTA_GATEWAY, &a->address.in6);
if (r < 0)
continue;
@@ -258,7 +258,7 @@ int local_gateways(sd_rtnl *context, int ifindex, int af, struct local_address *
continue;
}
- sd_rtnl_message_read_u32(m, RTA_PRIORITY, &a->metric);
+ sd_netlink_message_read_u32(m, RTA_PRIORITY, &a->metric);
a->ifindex = ifi;
a->family = family;
diff --git a/src/libsystemd/sd-rtnl/local-addresses.h b/src/libsystemd/sd-netlink/local-addresses.h
index bdc28d3510..5d0f11a2c1 100644
--- a/src/libsystemd/sd-rtnl/local-addresses.h
+++ b/src/libsystemd/sd-netlink/local-addresses.h
@@ -22,7 +22,7 @@
***/
-#include "sd-rtnl.h"
+#include "sd-netlink.h"
#include "in-addr-util.h"
struct local_address {
@@ -32,6 +32,6 @@ struct local_address {
union in_addr_union address;
};
-int local_addresses(sd_rtnl *rtnl, int ifindex, int af, struct local_address **ret);
+int local_addresses(sd_netlink *rtnl, int ifindex, int af, struct local_address **ret);
-int local_gateways(sd_rtnl *rtnl, int ifindex, int af, struct local_address **ret);
+int local_gateways(sd_netlink *rtnl, int ifindex, int af, struct local_address **ret);
diff --git a/src/libsystemd/sd-rtnl/rtnl-internal.h b/src/libsystemd/sd-netlink/netlink-internal.h
index 05b88b1ad8..ff663f91ef 100644
--- a/src/libsystemd/sd-rtnl/rtnl-internal.h
+++ b/src/libsystemd/sd-netlink/netlink-internal.h
@@ -27,9 +27,9 @@
#include "prioq.h"
#include "list.h"
-#include "sd-rtnl.h"
+#include "sd-netlink.h"
-#include "rtnl-types.h"
+#include "netlink-types.h"
#define RTNL_DEFAULT_TIMEOUT ((usec_t) (25 * USEC_PER_SEC))
@@ -39,7 +39,7 @@
#define RTNL_CONTAINER_DEPTH 32
struct reply_callback {
- sd_rtnl_message_handler_t callback;
+ sd_netlink_message_handler_t callback;
void *userdata;
usec_t timeout;
uint64_t serial;
@@ -47,14 +47,14 @@ struct reply_callback {
};
struct match_callback {
- sd_rtnl_message_handler_t callback;
+ sd_netlink_message_handler_t callback;
uint16_t type;
void *userdata;
LIST_FIELDS(struct match_callback, match_callbacks);
};
-struct sd_rtnl {
+struct sd_netlink {
RefCount n_ref;
int fd;
@@ -64,15 +64,15 @@ struct sd_rtnl {
struct sockaddr_nl nl;
} sockaddr;
- sd_rtnl_message **rqueue;
+ sd_netlink_message **rqueue;
unsigned rqueue_size;
size_t rqueue_allocated;
- sd_rtnl_message **rqueue_partial;
+ sd_netlink_message **rqueue_partial;
unsigned rqueue_partial_size;
size_t rqueue_partial_allocated;
- sd_rtnl_message **wqueue;
+ sd_netlink_message **wqueue;
unsigned wqueue_size;
size_t wqueue_allocated;
@@ -96,10 +96,10 @@ struct sd_rtnl {
sd_event *event;
};
-struct sd_rtnl_message {
+struct sd_netlink_message {
RefCount n_ref;
- sd_rtnl *rtnl;
+ sd_netlink *rtnl;
struct nlmsghdr *hdr;
const struct NLTypeSystem *(container_type_system[RTNL_CONTAINER_DEPTH]); /* the type of the container and all its parents */
@@ -111,19 +111,19 @@ struct sd_rtnl_message {
bool sealed:1;
bool broadcast:1;
- sd_rtnl_message *next; /* next in a chain of multi-part messages */
+ sd_netlink_message *next; /* next in a chain of multi-part messages */
};
-int message_new(sd_rtnl *rtnl, sd_rtnl_message **ret, uint16_t type);
+int message_new(sd_netlink *rtnl, sd_netlink_message **ret, uint16_t type);
-int socket_write_message(sd_rtnl *nl, sd_rtnl_message *m);
-int socket_read_message(sd_rtnl *nl);
+int socket_write_message(sd_netlink *nl, sd_netlink_message *m);
+int socket_read_message(sd_netlink *nl);
-int rtnl_rqueue_make_room(sd_rtnl *rtnl);
-int rtnl_rqueue_partial_make_room(sd_rtnl *rtnl);
+int rtnl_rqueue_make_room(sd_netlink *rtnl);
+int rtnl_rqueue_partial_make_room(sd_netlink *rtnl);
-int rtnl_message_read_internal(sd_rtnl_message *m, unsigned short type, void **data);
-int rtnl_message_parse(sd_rtnl_message *m,
+int rtnl_message_read_internal(sd_netlink_message *m, unsigned short type, void **data);
+int rtnl_message_parse(sd_netlink_message *m,
size_t **rta_offset_tb,
unsigned short *rta_tb_size,
int max,
@@ -132,4 +132,4 @@ int rtnl_message_parse(sd_rtnl_message *m,
/* Make sure callbacks don't destroy the rtnl connection */
#define RTNL_DONT_DESTROY(rtnl) \
- _cleanup_rtnl_unref_ _unused_ sd_rtnl *_dont_destroy_##rtnl = sd_rtnl_ref(rtnl)
+ _cleanup_netlink_unref_ _unused_ sd_netlink *_dont_destroy_##rtnl = sd_netlink_ref(rtnl)
diff --git a/src/libsystemd/sd-rtnl/rtnl-message.c b/src/libsystemd/sd-netlink/netlink-message.c
index 79e67f6953..9c280b1699 100644
--- a/src/libsystemd/sd-rtnl/rtnl-message.c
+++ b/src/libsystemd/sd-netlink/netlink-message.c
@@ -29,18 +29,18 @@
#include "refcnt.h"
#include "missing.h"
-#include "sd-rtnl.h"
-#include "rtnl-util.h"
-#include "rtnl-internal.h"
-#include "rtnl-types.h"
+#include "sd-netlink.h"
+#include "netlink-util.h"
+#include "netlink-internal.h"
+#include "netlink-types.h"
#define GET_CONTAINER(m, i) ((i) < (m)->n_containers ? (struct rtattr*)((uint8_t*)(m)->hdr + (m)->container_offsets[i]) : NULL)
#define PUSH_CONTAINER(m, new) (m)->container_offsets[(m)->n_containers ++] = (uint8_t*)(new) - (uint8_t*)(m)->hdr;
#define RTA_TYPE(rta) ((rta)->rta_type & NLA_TYPE_MASK)
-static int message_new_empty(sd_rtnl *rtnl, sd_rtnl_message **ret) {
- sd_rtnl_message *m;
+static int message_new_empty(sd_netlink *rtnl, sd_netlink_message **ret) {
+ sd_netlink_message *m;
assert_return(ret, -EINVAL);
@@ -49,7 +49,7 @@ static int message_new_empty(sd_rtnl *rtnl, sd_rtnl_message **ret) {
buses and their queued messages. See sd-bus.
*/
- m = new0(sd_rtnl_message, 1);
+ m = new0(sd_netlink_message, 1);
if (!m)
return -ENOMEM;
@@ -62,8 +62,8 @@ static int message_new_empty(sd_rtnl *rtnl, sd_rtnl_message **ret) {
return 0;
}
-int message_new(sd_rtnl *rtnl, sd_rtnl_message **ret, uint16_t type) {
- _cleanup_rtnl_message_unref_ sd_rtnl_message *m = NULL;
+int message_new(sd_netlink *rtnl, sd_netlink_message **ret, uint16_t type) {
+ _cleanup_netlink_message_unref_ sd_netlink_message *m = NULL;
const NLType *nl_type;
size_t size;
int r;
@@ -95,7 +95,7 @@ int message_new(sd_rtnl *rtnl, sd_rtnl_message **ret, uint16_t type) {
return 0;
}
-int sd_rtnl_message_route_set_dst_prefixlen(sd_rtnl_message *m, unsigned char prefixlen) {
+int sd_rtnl_message_route_set_dst_prefixlen(sd_netlink_message *m, unsigned char prefixlen) {
struct rtmsg *rtm;
assert_return(m, -EINVAL);
@@ -113,7 +113,7 @@ int sd_rtnl_message_route_set_dst_prefixlen(sd_rtnl_message *m, unsigned char pr
return 0;
}
-int sd_rtnl_message_route_set_src_prefixlen(sd_rtnl_message *m, unsigned char prefixlen) {
+int sd_rtnl_message_route_set_src_prefixlen(sd_netlink_message *m, unsigned char prefixlen) {
struct rtmsg *rtm;
assert_return(m, -EINVAL);
@@ -131,7 +131,7 @@ int sd_rtnl_message_route_set_src_prefixlen(sd_rtnl_message *m, unsigned char pr
return 0;
}
-int sd_rtnl_message_route_set_scope(sd_rtnl_message *m, unsigned char scope) {
+int sd_rtnl_message_route_set_scope(sd_netlink_message *m, unsigned char scope) {
struct rtmsg *rtm;
assert_return(m, -EINVAL);
@@ -145,7 +145,7 @@ int sd_rtnl_message_route_set_scope(sd_rtnl_message *m, unsigned char scope) {
return 0;
}
-int sd_rtnl_message_route_get_family(sd_rtnl_message *m, int *family) {
+int sd_rtnl_message_route_get_family(sd_netlink_message *m, int *family) {
struct rtmsg *rtm;
assert_return(m, -EINVAL);
@@ -160,7 +160,7 @@ int sd_rtnl_message_route_get_family(sd_rtnl_message *m, int *family) {
return 0;
}
-int sd_rtnl_message_route_get_dst_prefixlen(sd_rtnl_message *m, unsigned char *dst_len) {
+int sd_rtnl_message_route_get_dst_prefixlen(sd_netlink_message *m, unsigned char *dst_len) {
struct rtmsg *rtm;
assert_return(m, -EINVAL);
@@ -175,7 +175,7 @@ int sd_rtnl_message_route_get_dst_prefixlen(sd_rtnl_message *m, unsigned char *d
return 0;
}
-int sd_rtnl_message_route_get_src_prefixlen(sd_rtnl_message *m, unsigned char *src_len) {
+int sd_rtnl_message_route_get_src_prefixlen(sd_netlink_message *m, unsigned char *src_len) {
struct rtmsg *rtm;
assert_return(m, -EINVAL);
@@ -190,7 +190,7 @@ int sd_rtnl_message_route_get_src_prefixlen(sd_rtnl_message *m, unsigned char *s
return 0;
}
-int sd_rtnl_message_new_route(sd_rtnl *rtnl, sd_rtnl_message **ret,
+int sd_rtnl_message_new_route(sd_netlink *rtnl, sd_netlink_message **ret,
uint16_t nlmsg_type, int rtm_family,
unsigned char rtm_protocol) {
struct rtmsg *rtm;
@@ -219,7 +219,7 @@ int sd_rtnl_message_new_route(sd_rtnl *rtnl, sd_rtnl_message **ret,
return 0;
}
-int sd_rtnl_message_neigh_set_flags(sd_rtnl_message *m, uint8_t flags) {
+int sd_rtnl_message_neigh_set_flags(sd_netlink_message *m, uint8_t flags) {
struct ndmsg *ndm;
assert_return(m, -EINVAL);
@@ -232,7 +232,7 @@ int sd_rtnl_message_neigh_set_flags(sd_rtnl_message *m, uint8_t flags) {
return 0;
}
-int sd_rtnl_message_neigh_set_state(sd_rtnl_message *m, uint16_t state) {
+int sd_rtnl_message_neigh_set_state(sd_netlink_message *m, uint16_t state) {
struct ndmsg *ndm;
assert_return(m, -EINVAL);
@@ -245,7 +245,7 @@ int sd_rtnl_message_neigh_set_state(sd_rtnl_message *m, uint16_t state) {
return 0;
}
-int sd_rtnl_message_neigh_get_flags(sd_rtnl_message *m, uint8_t *flags) {
+int sd_rtnl_message_neigh_get_flags(sd_netlink_message *m, uint8_t *flags) {
struct ndmsg *ndm;
assert_return(m, -EINVAL);
@@ -258,7 +258,7 @@ int sd_rtnl_message_neigh_get_flags(sd_rtnl_message *m, uint8_t *flags) {
return 0;
}
-int sd_rtnl_message_neigh_get_state(sd_rtnl_message *m, uint16_t *state) {
+int sd_rtnl_message_neigh_get_state(sd_netlink_message *m, uint16_t *state) {
struct ndmsg *ndm;
assert_return(m, -EINVAL);
@@ -271,7 +271,7 @@ int sd_rtnl_message_neigh_get_state(sd_rtnl_message *m, uint16_t *state) {
return 0;
}
-int sd_rtnl_message_neigh_get_family(sd_rtnl_message *m, int *family) {
+int sd_rtnl_message_neigh_get_family(sd_netlink_message *m, int *family) {
struct ndmsg *ndm;
assert_return(m, -EINVAL);
@@ -286,7 +286,7 @@ int sd_rtnl_message_neigh_get_family(sd_rtnl_message *m, int *family) {
return 0;
}
-int sd_rtnl_message_neigh_get_ifindex(sd_rtnl_message *m, int *index) {
+int sd_rtnl_message_neigh_get_ifindex(sd_netlink_message *m, int *index) {
struct ndmsg *ndm;
assert_return(m, -EINVAL);
@@ -301,7 +301,7 @@ int sd_rtnl_message_neigh_get_ifindex(sd_rtnl_message *m, int *index) {
return 0;
}
-int sd_rtnl_message_new_neigh(sd_rtnl *rtnl, sd_rtnl_message **ret, uint16_t nlmsg_type, int index, int ndm_family) {
+int sd_rtnl_message_new_neigh(sd_netlink *rtnl, sd_netlink_message **ret, uint16_t nlmsg_type, int index, int ndm_family) {
struct ndmsg *ndm;
int r;
@@ -326,7 +326,7 @@ int sd_rtnl_message_new_neigh(sd_rtnl *rtnl, sd_rtnl_message **ret, uint16_t nlm
return 0;
}
-int sd_rtnl_message_link_set_flags(sd_rtnl_message *m, unsigned flags, unsigned change) {
+int sd_rtnl_message_link_set_flags(sd_netlink_message *m, unsigned flags, unsigned change) {
struct ifinfomsg *ifi;
assert_return(m, -EINVAL);
@@ -342,7 +342,7 @@ int sd_rtnl_message_link_set_flags(sd_rtnl_message *m, unsigned flags, unsigned
return 0;
}
-int sd_rtnl_message_link_set_type(sd_rtnl_message *m, unsigned type) {
+int sd_rtnl_message_link_set_type(sd_netlink_message *m, unsigned type) {
struct ifinfomsg *ifi;
assert_return(m, -EINVAL);
@@ -356,7 +356,7 @@ int sd_rtnl_message_link_set_type(sd_rtnl_message *m, unsigned type) {
return 0;
}
-int sd_rtnl_message_link_set_family(sd_rtnl_message *m, unsigned family) {
+int sd_rtnl_message_link_set_family(sd_netlink_message *m, unsigned family) {
struct ifinfomsg *ifi;
assert_return(m, -EINVAL);
@@ -370,7 +370,7 @@ int sd_rtnl_message_link_set_family(sd_rtnl_message *m, unsigned family) {
return 0;
}
-int sd_rtnl_message_new_link(sd_rtnl *rtnl, sd_rtnl_message **ret,
+int sd_rtnl_message_new_link(sd_netlink *rtnl, sd_netlink_message **ret,
uint16_t nlmsg_type, int index) {
struct ifinfomsg *ifi;
int r;
@@ -394,7 +394,7 @@ int sd_rtnl_message_new_link(sd_rtnl *rtnl, sd_rtnl_message **ret,
return 0;
}
-int sd_rtnl_message_request_dump(sd_rtnl_message *m, int dump) {
+int sd_netlink_message_request_dump(sd_netlink_message *m, int dump) {
assert_return(m, -EINVAL);
assert_return(m->hdr, -EINVAL);
assert_return(m->hdr->nlmsg_type == RTM_GETLINK ||
@@ -411,7 +411,7 @@ int sd_rtnl_message_request_dump(sd_rtnl_message *m, int dump) {
return 0;
}
-int sd_rtnl_message_addr_set_prefixlen(sd_rtnl_message *m, unsigned char prefixlen) {
+int sd_rtnl_message_addr_set_prefixlen(sd_netlink_message *m, unsigned char prefixlen) {
struct ifaddrmsg *ifa;
assert_return(m, -EINVAL);
@@ -429,7 +429,7 @@ int sd_rtnl_message_addr_set_prefixlen(sd_rtnl_message *m, unsigned char prefixl
return 0;
}
-int sd_rtnl_message_addr_set_flags(sd_rtnl_message *m, unsigned char flags) {
+int sd_rtnl_message_addr_set_flags(sd_netlink_message *m, unsigned char flags) {
struct ifaddrmsg *ifa;
assert_return(m, -EINVAL);
@@ -443,7 +443,7 @@ int sd_rtnl_message_addr_set_flags(sd_rtnl_message *m, unsigned char flags) {
return 0;
}
-int sd_rtnl_message_addr_set_scope(sd_rtnl_message *m, unsigned char scope) {
+int sd_rtnl_message_addr_set_scope(sd_netlink_message *m, unsigned char scope) {
struct ifaddrmsg *ifa;
assert_return(m, -EINVAL);
@@ -457,7 +457,7 @@ int sd_rtnl_message_addr_set_scope(sd_rtnl_message *m, unsigned char scope) {
return 0;
}
-int sd_rtnl_message_addr_get_family(sd_rtnl_message *m, int *family) {
+int sd_rtnl_message_addr_get_family(sd_netlink_message *m, int *family) {
struct ifaddrmsg *ifa;
assert_return(m, -EINVAL);
@@ -472,7 +472,7 @@ int sd_rtnl_message_addr_get_family(sd_rtnl_message *m, int *family) {
return 0;
}
-int sd_rtnl_message_addr_get_prefixlen(sd_rtnl_message *m, unsigned char *prefixlen) {
+int sd_rtnl_message_addr_get_prefixlen(sd_netlink_message *m, unsigned char *prefixlen) {
struct ifaddrmsg *ifa;
assert_return(m, -EINVAL);
@@ -487,7 +487,7 @@ int sd_rtnl_message_addr_get_prefixlen(sd_rtnl_message *m, unsigned char *prefix
return 0;
}
-int sd_rtnl_message_addr_get_scope(sd_rtnl_message *m, unsigned char *scope) {
+int sd_rtnl_message_addr_get_scope(sd_netlink_message *m, unsigned char *scope) {
struct ifaddrmsg *ifa;
assert_return(m, -EINVAL);
@@ -502,7 +502,7 @@ int sd_rtnl_message_addr_get_scope(sd_rtnl_message *m, unsigned char *scope) {
return 0;
}
-int sd_rtnl_message_addr_get_flags(sd_rtnl_message *m, unsigned char *flags) {
+int sd_rtnl_message_addr_get_flags(sd_netlink_message *m, unsigned char *flags) {
struct ifaddrmsg *ifa;
assert_return(m, -EINVAL);
@@ -517,7 +517,7 @@ int sd_rtnl_message_addr_get_flags(sd_rtnl_message *m, unsigned char *flags) {
return 0;
}
-int sd_rtnl_message_addr_get_ifindex(sd_rtnl_message *m, int *ifindex) {
+int sd_rtnl_message_addr_get_ifindex(sd_netlink_message *m, int *ifindex) {
struct ifaddrmsg *ifa;
assert_return(m, -EINVAL);
@@ -532,7 +532,7 @@ int sd_rtnl_message_addr_get_ifindex(sd_rtnl_message *m, int *ifindex) {
return 0;
}
-int sd_rtnl_message_new_addr(sd_rtnl *rtnl, sd_rtnl_message **ret,
+int sd_rtnl_message_new_addr(sd_netlink *rtnl, sd_netlink_message **ret,
uint16_t nlmsg_type, int index,
int family) {
struct ifaddrmsg *ifa;
@@ -564,7 +564,7 @@ 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 sd_rtnl_message_new_addr_update(sd_netlink *rtnl, sd_netlink_message **ret,
int index, int family) {
int r;
@@ -577,14 +577,14 @@ int sd_rtnl_message_new_addr_update(sd_rtnl *rtnl, sd_rtnl_message **ret,
return 0;
}
-sd_rtnl_message *sd_rtnl_message_ref(sd_rtnl_message *m) {
+sd_netlink_message *sd_netlink_message_ref(sd_netlink_message *m) {
if (m)
assert_se(REFCNT_INC(m->n_ref) >= 2);
return m;
}
-sd_rtnl_message *sd_rtnl_message_unref(sd_rtnl_message *m) {
+sd_netlink_message *sd_netlink_message_unref(sd_netlink_message *m) {
if (m && REFCNT_DEC(m->n_ref) == 0) {
unsigned i;
@@ -593,7 +593,7 @@ sd_rtnl_message *sd_rtnl_message_unref(sd_rtnl_message *m) {
for (i = 0; i <= m->n_containers; i++)
free(m->rta_offset_tb[i]);
- sd_rtnl_message_unref(m->next);
+ sd_netlink_message_unref(m->next);
free(m);
}
@@ -601,7 +601,7 @@ sd_rtnl_message *sd_rtnl_message_unref(sd_rtnl_message *m) {
return NULL;
}
-int sd_rtnl_message_get_type(sd_rtnl_message *m, uint16_t *type) {
+int sd_netlink_message_get_type(sd_netlink_message *m, uint16_t *type) {
assert_return(m, -EINVAL);
assert_return(type, -EINVAL);
@@ -610,7 +610,7 @@ int sd_rtnl_message_get_type(sd_rtnl_message *m, uint16_t *type) {
return 0;
}
-int sd_rtnl_message_get_family(sd_rtnl_message *m, int *family) {
+int sd_netlink_message_get_family(sd_netlink_message *m, int *family) {
assert_return(m, -EINVAL);
assert_return(family, -EINVAL);
@@ -653,13 +653,13 @@ int sd_rtnl_message_get_family(sd_rtnl_message *m, int *family) {
return -EOPNOTSUPP;
}
-int sd_rtnl_message_is_broadcast(sd_rtnl_message *m) {
+int sd_netlink_message_is_broadcast(sd_netlink_message *m) {
assert_return(m, -EINVAL);
return m->broadcast;
}
-int sd_rtnl_message_link_get_ifindex(sd_rtnl_message *m, int *ifindex) {
+int sd_rtnl_message_link_get_ifindex(sd_netlink_message *m, int *ifindex) {
struct ifinfomsg *ifi;
assert_return(m, -EINVAL);
@@ -674,7 +674,7 @@ int sd_rtnl_message_link_get_ifindex(sd_rtnl_message *m, int *ifindex) {
return 0;
}
-int sd_rtnl_message_link_get_flags(sd_rtnl_message *m, unsigned *flags) {
+int sd_rtnl_message_link_get_flags(sd_netlink_message *m, unsigned *flags) {
struct ifinfomsg *ifi;
assert_return(m, -EINVAL);
@@ -689,7 +689,7 @@ int sd_rtnl_message_link_get_flags(sd_rtnl_message *m, unsigned *flags) {
return 0;
}
-int sd_rtnl_message_link_get_type(sd_rtnl_message *m, unsigned *type) {
+int sd_rtnl_message_link_get_type(sd_netlink_message *m, unsigned *type) {
struct ifinfomsg *ifi;
assert_return(m, -EINVAL);
@@ -706,7 +706,7 @@ int sd_rtnl_message_link_get_type(sd_rtnl_message *m, unsigned *type) {
/* If successful the updated message will be correctly aligned, if
unsuccessful the old message is untouched. */
-static int add_rtattr(sd_rtnl_message *m, unsigned short type, const void *data, size_t data_length) {
+static int add_rtattr(sd_netlink_message *m, unsigned short type, const void *data, size_t data_length) {
uint32_t rta_length;
size_t message_length, padding_length;
struct nlmsghdr *new_hdr;
@@ -767,7 +767,7 @@ static int add_rtattr(sd_rtnl_message *m, unsigned short type, const void *data,
return offset;
}
-static int message_attribute_has_type(sd_rtnl_message *m, uint16_t attribute_type, uint16_t data_type) {
+static int message_attribute_has_type(sd_netlink_message *m, uint16_t attribute_type, uint16_t data_type) {
const NLType *type;
int r;
@@ -781,7 +781,7 @@ static int message_attribute_has_type(sd_rtnl_message *m, uint16_t attribute_typ
return type->size;
}
-int sd_rtnl_message_append_string(sd_rtnl_message *m, unsigned short type, const char *data) {
+int sd_netlink_message_append_string(sd_netlink_message *m, unsigned short type, const char *data) {
size_t length, size;
int r;
@@ -809,7 +809,7 @@ int sd_rtnl_message_append_string(sd_rtnl_message *m, unsigned short type, const
return 0;
}
-int sd_rtnl_message_append_u8(sd_rtnl_message *m, unsigned short type, uint8_t data) {
+int sd_netlink_message_append_u8(sd_netlink_message *m, unsigned short type, uint8_t data) {
int r;
assert_return(m, -EINVAL);
@@ -827,7 +827,7 @@ int sd_rtnl_message_append_u8(sd_rtnl_message *m, unsigned short type, uint8_t d
}
-int sd_rtnl_message_append_u16(sd_rtnl_message *m, unsigned short type, uint16_t data) {
+int sd_netlink_message_append_u16(sd_netlink_message *m, unsigned short type, uint16_t data) {
int r;
assert_return(m, -EINVAL);
@@ -844,7 +844,7 @@ int sd_rtnl_message_append_u16(sd_rtnl_message *m, unsigned short type, uint16_t
return 0;
}
-int sd_rtnl_message_append_u32(sd_rtnl_message *m, unsigned short type, uint32_t data) {
+int sd_netlink_message_append_u32(sd_netlink_message *m, unsigned short type, uint32_t data) {
int r;
assert_return(m, -EINVAL);
@@ -861,7 +861,7 @@ int sd_rtnl_message_append_u32(sd_rtnl_message *m, unsigned short type, uint32_t
return 0;
}
-int sd_rtnl_message_append_in_addr(sd_rtnl_message *m, unsigned short type, const struct in_addr *data) {
+int sd_netlink_message_append_in_addr(sd_netlink_message *m, unsigned short type, const struct in_addr *data) {
int r;
assert_return(m, -EINVAL);
@@ -879,7 +879,7 @@ int sd_rtnl_message_append_in_addr(sd_rtnl_message *m, unsigned short type, cons
return 0;
}
-int sd_rtnl_message_append_in6_addr(sd_rtnl_message *m, unsigned short type, const struct in6_addr *data) {
+int sd_netlink_message_append_in6_addr(sd_netlink_message *m, unsigned short type, const struct in6_addr *data) {
int r;
assert_return(m, -EINVAL);
@@ -897,7 +897,7 @@ int sd_rtnl_message_append_in6_addr(sd_rtnl_message *m, unsigned short type, con
return 0;
}
-int sd_rtnl_message_append_ether_addr(sd_rtnl_message *m, unsigned short type, const struct ether_addr *data) {
+int sd_netlink_message_append_ether_addr(sd_netlink_message *m, unsigned short type, const struct ether_addr *data) {
int r;
assert_return(m, -EINVAL);
@@ -915,7 +915,7 @@ 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 sd_netlink_message_append_cache_info(sd_netlink_message *m, unsigned short type, const struct ifa_cacheinfo *info) {
int r;
assert_return(m, -EINVAL);
@@ -933,7 +933,7 @@ int sd_rtnl_message_append_cache_info(sd_rtnl_message *m, unsigned short type, c
return 0;
}
-int sd_rtnl_message_open_container(sd_rtnl_message *m, unsigned short type) {
+int sd_netlink_message_open_container(sd_netlink_message *m, unsigned short type) {
size_t size;
int r;
@@ -951,7 +951,7 @@ int sd_rtnl_message_open_container(sd_rtnl_message *m, unsigned short type) {
return r;
size = (size_t) r;
- r = sd_rtnl_message_get_family(m, &family);
+ r = sd_netlink_message_get_family(m, &family);
if (r < 0)
return r;
@@ -983,7 +983,7 @@ int sd_rtnl_message_open_container(sd_rtnl_message *m, unsigned short type) {
return 0;
}
-int sd_rtnl_message_open_container_union(sd_rtnl_message *m, unsigned short type, const char *key) {
+int sd_netlink_message_open_container_union(sd_netlink_message *m, unsigned short type, const char *key) {
const NLTypeSystemUnion *type_system_union;
int r;
@@ -1000,7 +1000,7 @@ int sd_rtnl_message_open_container_union(sd_rtnl_message *m, unsigned short type
if (r < 0)
return r;
- r = sd_rtnl_message_append_string(m, type_system_union->match, key);
+ r = sd_netlink_message_append_string(m, type_system_union->match, key);
if (r < 0)
return r;
@@ -1015,7 +1015,7 @@ int sd_rtnl_message_open_container_union(sd_rtnl_message *m, unsigned short type
}
-int sd_rtnl_message_close_container(sd_rtnl_message *m) {
+int sd_netlink_message_close_container(sd_netlink_message *m) {
assert_return(m, -EINVAL);
assert_return(!m->sealed, -EPERM);
assert_return(m->n_containers > 0, -EINVAL);
@@ -1026,7 +1026,7 @@ int sd_rtnl_message_close_container(sd_rtnl_message *m) {
return 0;
}
-int rtnl_message_read_internal(sd_rtnl_message *m, unsigned short type, void **data) {
+int rtnl_message_read_internal(sd_netlink_message *m, unsigned short type, void **data) {
struct rtattr *rta;
assert_return(m, -EINVAL);
@@ -1046,7 +1046,7 @@ int rtnl_message_read_internal(sd_rtnl_message *m, unsigned short type, void **d
return RTA_PAYLOAD(rta);
}
-int sd_rtnl_message_read_string(sd_rtnl_message *m, unsigned short type, const char **data) {
+int sd_netlink_message_read_string(sd_netlink_message *m, unsigned short type, const char **data) {
int r;
void *attr_data;
@@ -1068,7 +1068,7 @@ int sd_rtnl_message_read_string(sd_rtnl_message *m, unsigned short type, const c
return 0;
}
-int sd_rtnl_message_read_u8(sd_rtnl_message *m, unsigned short type, uint8_t *data) {
+int sd_netlink_message_read_u8(sd_netlink_message *m, unsigned short type, uint8_t *data) {
int r;
void *attr_data;
@@ -1090,7 +1090,7 @@ int sd_rtnl_message_read_u8(sd_rtnl_message *m, unsigned short type, uint8_t *da
return 0;
}
-int sd_rtnl_message_read_u16(sd_rtnl_message *m, unsigned short type, uint16_t *data) {
+int sd_netlink_message_read_u16(sd_netlink_message *m, unsigned short type, uint16_t *data) {
int r;
void *attr_data;
@@ -1112,7 +1112,7 @@ int sd_rtnl_message_read_u16(sd_rtnl_message *m, unsigned short type, uint16_t *
return 0;
}
-int sd_rtnl_message_read_u32(sd_rtnl_message *m, unsigned short type, uint32_t *data) {
+int sd_netlink_message_read_u32(sd_netlink_message *m, unsigned short type, uint32_t *data) {
int r;
void *attr_data;
@@ -1134,7 +1134,7 @@ int sd_rtnl_message_read_u32(sd_rtnl_message *m, unsigned short type, uint32_t *
return 0;
}
-int sd_rtnl_message_read_ether_addr(sd_rtnl_message *m, unsigned short type, struct ether_addr *data) {
+int sd_netlink_message_read_ether_addr(sd_netlink_message *m, unsigned short type, struct ether_addr *data) {
int r;
void *attr_data;
@@ -1156,7 +1156,7 @@ 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 sd_netlink_message_read_cache_info(sd_netlink_message *m, unsigned short type, struct ifa_cacheinfo *info) {
int r;
void *attr_data;
@@ -1178,7 +1178,7 @@ int sd_rtnl_message_read_cache_info(sd_rtnl_message *m, unsigned short type, str
return 0;
}
-int sd_rtnl_message_read_in_addr(sd_rtnl_message *m, unsigned short type, struct in_addr *data) {
+int sd_netlink_message_read_in_addr(sd_netlink_message *m, unsigned short type, struct in_addr *data) {
int r;
void *attr_data;
@@ -1200,7 +1200,7 @@ int sd_rtnl_message_read_in_addr(sd_rtnl_message *m, unsigned short type, struct
return 0;
}
-int sd_rtnl_message_read_in6_addr(sd_rtnl_message *m, unsigned short type, struct in6_addr *data) {
+int sd_netlink_message_read_in6_addr(sd_netlink_message *m, unsigned short type, struct in6_addr *data) {
int r;
void *attr_data;
@@ -1222,7 +1222,7 @@ int sd_rtnl_message_read_in6_addr(sd_rtnl_message *m, unsigned short type, struc
return 0;
}
-int sd_rtnl_message_enter_container(sd_rtnl_message *m, unsigned short type) {
+int sd_netlink_message_enter_container(sd_netlink_message *m, unsigned short type) {
const NLType *nl_type;
const NLTypeSystem *type_system;
void *container;
@@ -1258,7 +1258,7 @@ int sd_rtnl_message_enter_container(sd_rtnl_message *m, unsigned short type) {
{
const char *key;
- r = sd_rtnl_message_read_string(m, type_system_union->match, &key);
+ r = sd_netlink_message_read_string(m, type_system_union->match, &key);
if (r < 0)
return r;
@@ -1274,7 +1274,7 @@ int sd_rtnl_message_enter_container(sd_rtnl_message *m, unsigned short type) {
{
int family;
- r = sd_rtnl_message_get_family(m, &family);
+ r = sd_netlink_message_get_family(m, &family);
if (r < 0)
return r;
@@ -1287,7 +1287,7 @@ int sd_rtnl_message_enter_container(sd_rtnl_message *m, unsigned short type) {
break;
}
default:
- assert_not_reached("sd-rtnl: invalid type system union type");
+ assert_not_reached("sd-netlink: invalid type system union type");
}
} else
return -EINVAL;
@@ -1316,7 +1316,7 @@ int sd_rtnl_message_enter_container(sd_rtnl_message *m, unsigned short type) {
return 0;
}
-int sd_rtnl_message_exit_container(sd_rtnl_message *m) {
+int sd_netlink_message_exit_container(sd_netlink_message *m) {
assert_return(m, -EINVAL);
assert_return(m->sealed, -EINVAL);
assert_return(m->n_containers > 0, -EINVAL);
@@ -1330,27 +1330,27 @@ int sd_rtnl_message_exit_container(sd_rtnl_message *m) {
return 0;
}
-uint32_t rtnl_message_get_serial(sd_rtnl_message *m) {
+uint32_t rtnl_message_get_serial(sd_netlink_message *m) {
assert(m);
assert(m->hdr);
return m->hdr->nlmsg_seq;
}
-int sd_rtnl_message_is_error(sd_rtnl_message *m) {
+int sd_netlink_message_is_error(sd_netlink_message *m) {
assert_return(m, 0);
assert_return(m->hdr, 0);
return m->hdr->nlmsg_type == NLMSG_ERROR;
}
-int sd_rtnl_message_get_errno(sd_rtnl_message *m) {
+int sd_netlink_message_get_errno(sd_netlink_message *m) {
struct nlmsgerr *err;
assert_return(m, -EINVAL);
assert_return(m->hdr, -EINVAL);
- if (!sd_rtnl_message_is_error(m))
+ if (!sd_netlink_message_is_error(m))
return 0;
err = NLMSG_DATA(m->hdr);
@@ -1358,7 +1358,7 @@ int sd_rtnl_message_get_errno(sd_rtnl_message *m) {
return err->error;
}
-int rtnl_message_parse(sd_rtnl_message *m,
+int rtnl_message_parse(sd_netlink_message *m,
size_t **rta_offset_tb,
unsigned short *rta_tb_size,
int max,
@@ -1394,7 +1394,7 @@ int rtnl_message_parse(sd_rtnl_message *m,
}
/* returns the number of bytes sent, or a negative error code */
-int socket_write_message(sd_rtnl *nl, sd_rtnl_message *m) {
+int socket_write_message(sd_netlink *nl, sd_netlink_message *m) {
union {
struct sockaddr sa;
struct sockaddr_nl nl;
@@ -1480,8 +1480,8 @@ static int socket_recv_message(int fd, struct iovec *iov, uint32_t *_group, bool
* If nothing useful was received 0 is returned.
* On failure, a negative error code is returned.
*/
-int socket_read_message(sd_rtnl *rtnl) {
- _cleanup_rtnl_message_unref_ sd_rtnl_message *first = NULL;
+int socket_read_message(sd_netlink *rtnl) {
+ _cleanup_netlink_message_unref_ sd_netlink_message *first = NULL;
struct iovec iov = {};
uint32_t group = 0;
bool multi_part = false, done = false;
@@ -1534,7 +1534,7 @@ int socket_read_message(sd_rtnl *rtnl) {
}
for (new_msg = rtnl->rbuffer; NLMSG_OK(new_msg, len) && !done; new_msg = NLMSG_NEXT(new_msg, len)) {
- _cleanup_rtnl_message_unref_ sd_rtnl_message *m = NULL;
+ _cleanup_netlink_message_unref_ sd_netlink_message *m = NULL;
const NLType *nl_type;
if (!group && new_msg->nlmsg_pid != rtnl->sockaddr.nl.nl_pid)
@@ -1558,7 +1558,7 @@ int socket_read_message(sd_rtnl *rtnl) {
r = type_system_get_type(NULL, &nl_type, new_msg->nlmsg_type);
if (r < 0) {
if (r == -EOPNOTSUPP)
- log_debug("sd-rtnl: ignored message with unknown type: %i",
+ log_debug("sd-netlink: ignored message with unknown type: %i",
new_msg->nlmsg_type);
continue;
@@ -1566,7 +1566,7 @@ int socket_read_message(sd_rtnl *rtnl) {
/* check that the size matches the message type */
if (new_msg->nlmsg_len < NLMSG_LENGTH(nl_type->size)) {
- log_debug("sd-rtnl: message larger than expected, dropping");
+ log_debug("sd-netlink: message larger than expected, dropping");
continue;
}
@@ -1581,7 +1581,7 @@ int socket_read_message(sd_rtnl *rtnl) {
return -ENOMEM;
/* seal and parse the top-level message */
- r = sd_rtnl_message_rewind(m);
+ r = sd_netlink_message_rewind(m);
if (r < 0)
return r;
@@ -1593,7 +1593,7 @@ int socket_read_message(sd_rtnl *rtnl) {
}
if (len)
- log_debug("sd-rtnl: discarding %zu bytes of incoming message", len);
+ log_debug("sd-netlink: discarding %zu bytes of incoming message", len);
if (!first)
return 0;
@@ -1610,7 +1610,7 @@ int socket_read_message(sd_rtnl *rtnl) {
if (multi_part && (i < rtnl->rqueue_partial_size)) {
/* remove the message form the partial read queue */
memmove(rtnl->rqueue_partial + i,rtnl->rqueue_partial + i + 1,
- sizeof(sd_rtnl_message*) * (rtnl->rqueue_partial_size - i - 1));
+ sizeof(sd_netlink_message*) * (rtnl->rqueue_partial_size - i - 1));
rtnl->rqueue_partial_size --;
}
@@ -1633,7 +1633,7 @@ int socket_read_message(sd_rtnl *rtnl) {
}
}
-int sd_rtnl_message_rewind(sd_rtnl_message *m) {
+int sd_netlink_message_rewind(sd_netlink_message *m) {
const NLType *type;
unsigned i;
int r;
@@ -1685,14 +1685,14 @@ int sd_rtnl_message_rewind(sd_rtnl_message *m) {
return 0;
}
-void rtnl_message_seal(sd_rtnl_message *m) {
+void rtnl_message_seal(sd_netlink_message *m) {
assert(m);
assert(!m->sealed);
m->sealed = true;
}
-sd_rtnl_message *sd_rtnl_message_next(sd_rtnl_message *m) {
+sd_netlink_message *sd_netlink_message_next(sd_netlink_message *m) {
assert_return(m, NULL);
return m->next;
diff --git a/src/libsystemd/sd-rtnl/rtnl-types.c b/src/libsystemd/sd-netlink/netlink-types.c
index d211684ff1..273033770f 100644
--- a/src/libsystemd/sd-rtnl/rtnl-types.c
+++ b/src/libsystemd/sd-netlink/netlink-types.c
@@ -36,7 +36,7 @@
#include "macro.h"
#include "util.h"
-#include "rtnl-types.h"
+#include "netlink-types.h"
#include "missing.h"
static const NLTypeSystem rtnl_link_type_system;
diff --git a/src/libsystemd/sd-rtnl/rtnl-types.h b/src/libsystemd/sd-netlink/netlink-types.h
index de1544bf36..de1544bf36 100644
--- a/src/libsystemd/sd-rtnl/rtnl-types.h
+++ b/src/libsystemd/sd-netlink/netlink-types.h
diff --git a/src/libsystemd/sd-rtnl/rtnl-util.c b/src/libsystemd/sd-netlink/netlink-util.c
index c2b1a5c65d..482ff6b1c2 100644
--- a/src/libsystemd/sd-rtnl/rtnl-util.c
+++ b/src/libsystemd/sd-netlink/netlink-util.c
@@ -20,13 +20,13 @@
***/
-#include "sd-rtnl.h"
+#include "sd-netlink.h"
-#include "rtnl-util.h"
-#include "rtnl-internal.h"
+#include "netlink-util.h"
+#include "netlink-internal.h"
-int rtnl_set_link_name(sd_rtnl **rtnl, int ifindex, const char *name) {
- _cleanup_rtnl_message_unref_ sd_rtnl_message *message = NULL;
+int rtnl_set_link_name(sd_netlink **rtnl, int ifindex, const char *name) {
+ _cleanup_netlink_message_unref_ sd_netlink_message *message = NULL;
int r;
assert(rtnl);
@@ -34,7 +34,7 @@ int rtnl_set_link_name(sd_rtnl **rtnl, int ifindex, const char *name) {
assert(name);
if (!*rtnl) {
- r = sd_rtnl_open(rtnl);
+ r = sd_netlink_open(rtnl);
if (r < 0)
return r;
}
@@ -43,20 +43,20 @@ int rtnl_set_link_name(sd_rtnl **rtnl, int ifindex, const char *name) {
if (r < 0)
return r;
- r = sd_rtnl_message_append_string(message, IFLA_IFNAME, name);
+ r = sd_netlink_message_append_string(message, IFLA_IFNAME, name);
if (r < 0)
return r;
- r = sd_rtnl_call(*rtnl, message, 0, NULL);
+ r = sd_netlink_call(*rtnl, message, 0, NULL);
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_netlink **rtnl, int ifindex, const char *alias,
const struct ether_addr *mac, unsigned mtu) {
- _cleanup_rtnl_message_unref_ sd_rtnl_message *message = NULL;
+ _cleanup_netlink_message_unref_ sd_netlink_message *message = NULL;
int r;
assert(rtnl);
@@ -66,7 +66,7 @@ int rtnl_set_link_properties(sd_rtnl **rtnl, int ifindex, const char *alias,
return 0;
if (!*rtnl) {
- r = sd_rtnl_open(rtnl);
+ r = sd_netlink_open(rtnl);
if (r < 0)
return r;
}
@@ -76,31 +76,31 @@ int rtnl_set_link_properties(sd_rtnl **rtnl, int ifindex, const char *alias,
return r;
if (alias) {
- r = sd_rtnl_message_append_string(message, IFLA_IFALIAS, alias);
+ r = sd_netlink_message_append_string(message, IFLA_IFALIAS, alias);
if (r < 0)
return r;
}
if (mac) {
- r = sd_rtnl_message_append_ether_addr(message, IFLA_ADDRESS, mac);
+ r = sd_netlink_message_append_ether_addr(message, IFLA_ADDRESS, mac);
if (r < 0)
return r;
}
if (mtu > 0) {
- r = sd_rtnl_message_append_u32(message, IFLA_MTU, mtu);
+ r = sd_netlink_message_append_u32(message, IFLA_MTU, mtu);
if (r < 0)
return r;
}
- r = sd_rtnl_call(*rtnl, message, 0, NULL);
+ r = sd_netlink_call(*rtnl, message, 0, NULL);
if (r < 0)
return r;
return 0;
}
-int rtnl_message_new_synthetic_error(int error, uint32_t serial, sd_rtnl_message **ret) {
+int rtnl_message_new_synthetic_error(int error, uint32_t serial, sd_netlink_message **ret) {
struct nlmsgerr *err;
int r;
diff --git a/src/libsystemd/sd-rtnl/rtnl-util.h b/src/libsystemd/sd-netlink/netlink-util.h
index 9e4bdb867e..9df0aa28bf 100644
--- a/src/libsystemd/sd-rtnl/rtnl-util.h
+++ b/src/libsystemd/sd-netlink/netlink-util.h
@@ -23,25 +23,25 @@
#include "util.h"
-#include "sd-rtnl.h"
+#include "sd-netlink.h"
-int rtnl_message_new_synthetic_error(int error, uint32_t serial, sd_rtnl_message **ret);
-uint32_t rtnl_message_get_serial(sd_rtnl_message *m);
-void rtnl_message_seal(sd_rtnl_message *m);
+int rtnl_message_new_synthetic_error(int error, uint32_t serial, sd_netlink_message **ret);
+uint32_t rtnl_message_get_serial(sd_netlink_message *m);
+void rtnl_message_seal(sd_netlink_message *m);
bool rtnl_message_type_is_link(uint16_t type);
bool rtnl_message_type_is_addr(uint16_t type);
bool rtnl_message_type_is_route(uint16_t type);
bool rtnl_message_type_is_neigh(uint16_t type);
-int rtnl_set_link_name(sd_rtnl **rtnl, int ifindex, const char *name);
-int rtnl_set_link_properties(sd_rtnl **rtnl, int ifindex, const char *alias, const struct ether_addr *mac, unsigned mtu);
+int rtnl_set_link_name(sd_netlink **rtnl, int ifindex, const char *name);
+int rtnl_set_link_properties(sd_netlink **rtnl, int ifindex, const char *alias, const struct ether_addr *mac, unsigned mtu);
int rtnl_log_parse_error(int r);
int rtnl_log_create_error(int r);
-DEFINE_TRIVIAL_CLEANUP_FUNC(sd_rtnl*, sd_rtnl_unref);
-DEFINE_TRIVIAL_CLEANUP_FUNC(sd_rtnl_message*, sd_rtnl_message_unref);
+DEFINE_TRIVIAL_CLEANUP_FUNC(sd_netlink*, sd_netlink_unref);
+DEFINE_TRIVIAL_CLEANUP_FUNC(sd_netlink_message*, sd_netlink_message_unref);
-#define _cleanup_rtnl_unref_ _cleanup_(sd_rtnl_unrefp)
-#define _cleanup_rtnl_message_unref_ _cleanup_(sd_rtnl_message_unrefp)
+#define _cleanup_netlink_unref_ _cleanup_(sd_netlink_unrefp)
+#define _cleanup_netlink_message_unref_ _cleanup_(sd_netlink_message_unrefp)
diff --git a/src/libsystemd/sd-rtnl/sd-rtnl.c b/src/libsystemd/sd-netlink/sd-netlink.c
index 5bafc282c0..14cc75915d 100644
--- a/src/libsystemd/sd-rtnl/sd-rtnl.c
+++ b/src/libsystemd/sd-netlink/sd-netlink.c
@@ -27,16 +27,16 @@
#include "util.h"
#include "hashmap.h"
-#include "sd-rtnl.h"
-#include "rtnl-internal.h"
-#include "rtnl-util.h"
+#include "sd-netlink.h"
+#include "netlink-internal.h"
+#include "netlink-util.h"
-static int sd_rtnl_new(sd_rtnl **ret) {
- _cleanup_rtnl_unref_ sd_rtnl *rtnl = NULL;
+static int sd_netlink_new(sd_netlink **ret) {
+ _cleanup_netlink_unref_ sd_netlink *rtnl = NULL;
assert_return(ret, -EINVAL);
- rtnl = new0(sd_rtnl, 1);
+ rtnl = new0(sd_netlink, 1);
if (!rtnl)
return -ENOMEM;
@@ -72,14 +72,14 @@ static int sd_rtnl_new(sd_rtnl **ret) {
return 0;
}
-int sd_rtnl_new_from_netlink(sd_rtnl **ret, int fd) {
- _cleanup_rtnl_unref_ sd_rtnl *rtnl = NULL;
+int sd_netlink_new_from_netlink(sd_netlink **ret, int fd) {
+ _cleanup_netlink_unref_ sd_netlink *rtnl = NULL;
socklen_t addrlen;
int r;
assert_return(ret, -EINVAL);
- r = sd_rtnl_new(&rtnl);
+ r = sd_netlink_new(&rtnl);
if (r < 0)
return r;
@@ -97,7 +97,7 @@ int sd_rtnl_new_from_netlink(sd_rtnl **ret, int fd) {
return 0;
}
-static bool rtnl_pid_changed(sd_rtnl *rtnl) {
+static bool rtnl_pid_changed(sd_netlink *rtnl) {
assert(rtnl);
/* We don't support people creating an rtnl connection and
@@ -106,15 +106,15 @@ static bool rtnl_pid_changed(sd_rtnl *rtnl) {
return rtnl->original_pid != getpid();
}
-int sd_rtnl_open_fd(sd_rtnl **ret, int fd) {
- _cleanup_rtnl_unref_ sd_rtnl *rtnl = NULL;
+int sd_netlink_open_fd(sd_netlink **ret, int fd) {
+ _cleanup_netlink_unref_ sd_netlink *rtnl = NULL;
socklen_t addrlen;
int r, one = 1;
assert_return(ret, -EINVAL);
assert_return(fd >= 0, -EINVAL);
- r = sd_rtnl_new(&rtnl);
+ r = sd_netlink_new(&rtnl);
if (r < 0)
return r;
@@ -141,7 +141,7 @@ int sd_rtnl_open_fd(sd_rtnl **ret, int fd) {
return 0;
}
-int sd_rtnl_open(sd_rtnl **ret) {
+int sd_netlink_open(sd_netlink **ret) {
_cleanup_close_ int fd = -1;
int r;
@@ -149,7 +149,7 @@ int sd_rtnl_open(sd_rtnl **ret) {
if (fd < 0)
return -errno;
- r = sd_rtnl_open_fd(ret, fd);
+ r = sd_netlink_open_fd(ret, fd);
if (r < 0)
return r;
@@ -158,7 +158,7 @@ int sd_rtnl_open(sd_rtnl **ret) {
return 0;
}
-static int rtnl_join_broadcast_group(sd_rtnl *rtnl, unsigned group) {
+static int rtnl_join_broadcast_group(sd_netlink *rtnl, unsigned group) {
int r;
assert(rtnl);
@@ -172,11 +172,11 @@ static int rtnl_join_broadcast_group(sd_rtnl *rtnl, unsigned group) {
return 0;
}
-int sd_rtnl_inc_rcvbuf(const sd_rtnl *const rtnl, const int size) {
+int sd_netlink_inc_rcvbuf(const sd_netlink *const rtnl, const int size) {
return fd_inc_rcvbuf(rtnl->fd, size);
}
-sd_rtnl *sd_rtnl_ref(sd_rtnl *rtnl) {
+sd_netlink *sd_netlink_ref(sd_netlink *rtnl) {
assert_return(rtnl, NULL);
assert_return(!rtnl_pid_changed(rtnl), NULL);
@@ -186,7 +186,7 @@ sd_rtnl *sd_rtnl_ref(sd_rtnl *rtnl) {
return rtnl;
}
-sd_rtnl *sd_rtnl_unref(sd_rtnl *rtnl) {
+sd_netlink *sd_netlink_unref(sd_netlink *rtnl) {
if (!rtnl)
return NULL;
@@ -197,15 +197,15 @@ sd_rtnl *sd_rtnl_unref(sd_rtnl *rtnl) {
unsigned i;
for (i = 0; i < rtnl->rqueue_size; i++)
- sd_rtnl_message_unref(rtnl->rqueue[i]);
+ sd_netlink_message_unref(rtnl->rqueue[i]);
free(rtnl->rqueue);
for (i = 0; i < rtnl->rqueue_partial_size; i++)
- sd_rtnl_message_unref(rtnl->rqueue_partial[i]);
+ sd_netlink_message_unref(rtnl->rqueue_partial[i]);
free(rtnl->rqueue_partial);
for (i = 0; i < rtnl->wqueue_size; i++)
- sd_rtnl_message_unref(rtnl->wqueue[i]);
+ sd_netlink_message_unref(rtnl->wqueue[i]);
free(rtnl->wqueue);
free(rtnl->rbuffer);
@@ -230,7 +230,7 @@ sd_rtnl *sd_rtnl_unref(sd_rtnl *rtnl) {
return NULL;
}
-static void rtnl_seal_message(sd_rtnl *rtnl, sd_rtnl_message *m) {
+static void rtnl_seal_message(sd_netlink *rtnl, sd_netlink_message *m) {
assert(rtnl);
assert(!rtnl_pid_changed(rtnl));
assert(m);
@@ -245,8 +245,8 @@ static void rtnl_seal_message(sd_rtnl *rtnl, sd_rtnl_message *m) {
return;
}
-int sd_rtnl_send(sd_rtnl *nl,
- sd_rtnl_message *message,
+int sd_netlink_send(sd_netlink *nl,
+ sd_netlink_message *message,
uint32_t *serial) {
int r;
@@ -265,7 +265,7 @@ int sd_rtnl_send(sd_rtnl *nl,
else if (r == 0) {
/* nothing was sent, so let's put it on
* the queue */
- nl->wqueue[0] = sd_rtnl_message_ref(message);
+ nl->wqueue[0] = sd_netlink_message_ref(message);
nl->wqueue_size = 1;
}
} else {
@@ -278,7 +278,7 @@ int sd_rtnl_send(sd_rtnl *nl,
if (!GREEDY_REALLOC(nl->wqueue, nl->wqueue_allocated, nl->wqueue_size + 1))
return -ENOMEM;
- nl->wqueue[nl->wqueue_size ++] = sd_rtnl_message_ref(message);
+ nl->wqueue[nl->wqueue_size ++] = sd_netlink_message_ref(message);
}
if (serial)
@@ -287,7 +287,7 @@ int sd_rtnl_send(sd_rtnl *nl,
return 1;
}
-int rtnl_rqueue_make_room(sd_rtnl *rtnl) {
+int rtnl_rqueue_make_room(sd_netlink *rtnl) {
assert(rtnl);
if (rtnl->rqueue_size >= RTNL_RQUEUE_MAX) {
@@ -301,7 +301,7 @@ int rtnl_rqueue_make_room(sd_rtnl *rtnl) {
return 0;
}
-int rtnl_rqueue_partial_make_room(sd_rtnl *rtnl) {
+int rtnl_rqueue_partial_make_room(sd_netlink *rtnl) {
assert(rtnl);
if (rtnl->rqueue_partial_size >= RTNL_RQUEUE_MAX) {
@@ -316,7 +316,7 @@ int rtnl_rqueue_partial_make_room(sd_rtnl *rtnl) {
return 0;
}
-static int dispatch_rqueue(sd_rtnl *rtnl, sd_rtnl_message **message) {
+static int dispatch_rqueue(sd_netlink *rtnl, sd_netlink_message **message) {
int r;
assert(rtnl);
@@ -332,12 +332,12 @@ static int dispatch_rqueue(sd_rtnl *rtnl, sd_rtnl_message **message) {
/* Dispatch a queued message */
*message = rtnl->rqueue[0];
rtnl->rqueue_size --;
- memmove(rtnl->rqueue, rtnl->rqueue + 1, sizeof(sd_rtnl_message*) * rtnl->rqueue_size);
+ memmove(rtnl->rqueue, rtnl->rqueue + 1, sizeof(sd_netlink_message*) * rtnl->rqueue_size);
return 1;
}
-static int dispatch_wqueue(sd_rtnl *rtnl) {
+static int dispatch_wqueue(sd_netlink *rtnl) {
int r, ret = 0;
assert(rtnl);
@@ -351,9 +351,9 @@ static int dispatch_wqueue(sd_rtnl *rtnl) {
return ret;
else {
/* see equivalent in sd-bus.c */
- sd_rtnl_message_unref(rtnl->wqueue[0]);
+ sd_netlink_message_unref(rtnl->wqueue[0]);
rtnl->wqueue_size --;
- memmove(rtnl->wqueue, rtnl->wqueue + 1, sizeof(sd_rtnl_message*) * rtnl->wqueue_size);
+ memmove(rtnl->wqueue, rtnl->wqueue + 1, sizeof(sd_netlink_message*) * rtnl->wqueue_size);
ret = 1;
}
@@ -362,8 +362,8 @@ static int dispatch_wqueue(sd_rtnl *rtnl) {
return ret;
}
-static int process_timeout(sd_rtnl *rtnl) {
- _cleanup_rtnl_message_unref_ sd_rtnl_message *m = NULL;
+static int process_timeout(sd_netlink *rtnl) {
+ _cleanup_netlink_message_unref_ sd_netlink_message *m = NULL;
struct reply_callback *c;
usec_t n;
int r;
@@ -387,14 +387,14 @@ static int process_timeout(sd_rtnl *rtnl) {
r = c->callback(rtnl, m, c->userdata);
if (r < 0)
- log_debug_errno(r, "sd-rtnl: timedout callback failed: %m");
+ log_debug_errno(r, "sd-netlink: timedout callback failed: %m");
free(c);
return 1;
}
-static int process_reply(sd_rtnl *rtnl, sd_rtnl_message *m) {
+static int process_reply(sd_netlink *rtnl, sd_netlink_message *m) {
_cleanup_free_ struct reply_callback *c = NULL;
uint64_t serial;
uint16_t type;
@@ -411,7 +411,7 @@ static int process_reply(sd_rtnl *rtnl, sd_rtnl_message *m) {
if (c->timeout != 0)
prioq_remove(rtnl->reply_callbacks_prioq, c, &c->prioq_idx);
- r = sd_rtnl_message_get_type(m, &type);
+ r = sd_netlink_message_get_type(m, &type);
if (r < 0)
return 0;
@@ -420,12 +420,12 @@ static int process_reply(sd_rtnl *rtnl, sd_rtnl_message *m) {
r = c->callback(rtnl, m, c->userdata);
if (r < 0)
- log_debug_errno(r, "sd-rtnl: callback failed: %m");
+ log_debug_errno(r, "sd-netlink: callback failed: %m");
return 1;
}
-static int process_match(sd_rtnl *rtnl, sd_rtnl_message *m) {
+static int process_match(sd_netlink *rtnl, sd_netlink_message *m) {
struct match_callback *c;
uint16_t type;
int r;
@@ -433,7 +433,7 @@ static int process_match(sd_rtnl *rtnl, sd_rtnl_message *m) {
assert(rtnl);
assert(m);
- r = sd_rtnl_message_get_type(m, &type);
+ r = sd_netlink_message_get_type(m, &type);
if (r < 0)
return r;
@@ -442,7 +442,7 @@ static int process_match(sd_rtnl *rtnl, sd_rtnl_message *m) {
r = c->callback(rtnl, m, c->userdata);
if (r != 0) {
if (r < 0)
- log_debug_errno(r, "sd-rtnl: match callback failed: %m");
+ log_debug_errno(r, "sd-netlink: match callback failed: %m");
break;
}
@@ -452,8 +452,8 @@ static int process_match(sd_rtnl *rtnl, sd_rtnl_message *m) {
return 1;
}
-static int process_running(sd_rtnl *rtnl, sd_rtnl_message **ret) {
- _cleanup_rtnl_message_unref_ sd_rtnl_message *m = NULL;
+static int process_running(sd_netlink *rtnl, sd_netlink_message **ret) {
+ _cleanup_netlink_message_unref_ sd_netlink_message *m = NULL;
int r;
assert(rtnl);
@@ -472,7 +472,7 @@ static int process_running(sd_rtnl *rtnl, sd_rtnl_message **ret) {
if (!m)
goto null_message;
- if (sd_rtnl_message_is_broadcast(m)) {
+ if (sd_netlink_message_is_broadcast(m)) {
r = process_match(rtnl, m);
if (r != 0)
goto null_message;
@@ -498,7 +498,7 @@ null_message:
return r;
}
-int sd_rtnl_process(sd_rtnl *rtnl, sd_rtnl_message **ret) {
+int sd_netlink_process(sd_netlink *rtnl, sd_netlink_message **ret) {
RTNL_DONT_DESTROY(rtnl);
int r;
@@ -523,7 +523,7 @@ static usec_t calc_elapse(uint64_t usec) {
return now(CLOCK_MONOTONIC) + usec;
}
-static int rtnl_poll(sd_rtnl *rtnl, bool need_more, uint64_t timeout_usec) {
+static int rtnl_poll(sd_netlink *rtnl, bool need_more, uint64_t timeout_usec) {
struct pollfd p[1] = {};
struct timespec ts;
usec_t m = USEC_INFINITY;
@@ -531,7 +531,7 @@ static int rtnl_poll(sd_rtnl *rtnl, bool need_more, uint64_t timeout_usec) {
assert(rtnl);
- e = sd_rtnl_get_events(rtnl);
+ e = sd_netlink_get_events(rtnl);
if (e < 0)
return e;
@@ -544,7 +544,7 @@ static int rtnl_poll(sd_rtnl *rtnl, bool need_more, uint64_t timeout_usec) {
/* Caller wants to process if there is something to
* process, but doesn't care otherwise */
- r = sd_rtnl_get_timeout(rtnl, &until);
+ r = sd_netlink_get_timeout(rtnl, &until);
if (r < 0)
return r;
if (r > 0) {
@@ -567,7 +567,7 @@ static int rtnl_poll(sd_rtnl *rtnl, bool need_more, uint64_t timeout_usec) {
return r > 0 ? 1 : 0;
}
-int sd_rtnl_wait(sd_rtnl *nl, uint64_t timeout_usec) {
+int sd_netlink_wait(sd_netlink *nl, uint64_t timeout_usec) {
assert_return(nl, -EINVAL);
assert_return(!rtnl_pid_changed(nl), -ECHILD);
@@ -595,9 +595,9 @@ static int timeout_compare(const void *a, const void *b) {
return 0;
}
-int sd_rtnl_call_async(sd_rtnl *nl,
- sd_rtnl_message *m,
- sd_rtnl_message_handler_t callback,
+int sd_netlink_call_async(sd_netlink *nl,
+ sd_netlink_message *m,
+ sd_netlink_message_handler_t callback,
void *userdata,
uint64_t usec,
uint32_t *serial) {
@@ -628,7 +628,7 @@ int sd_rtnl_call_async(sd_rtnl *nl,
c->userdata = userdata;
c->timeout = calc_elapse(usec);
- k = sd_rtnl_send(nl, m, &s);
+ k = sd_netlink_send(nl, m, &s);
if (k < 0) {
free(c);
return k;
@@ -646,7 +646,7 @@ int sd_rtnl_call_async(sd_rtnl *nl,
r = prioq_put(nl->reply_callbacks_prioq, c, &c->prioq_idx);
if (r > 0) {
c->timeout = 0;
- sd_rtnl_call_async_cancel(nl, c->serial);
+ sd_netlink_call_async_cancel(nl, c->serial);
return r;
}
}
@@ -657,7 +657,7 @@ int sd_rtnl_call_async(sd_rtnl *nl,
return k;
}
-int sd_rtnl_call_async_cancel(sd_rtnl *nl, uint32_t serial) {
+int sd_netlink_call_async_cancel(sd_netlink *nl, uint32_t serial) {
struct reply_callback *c;
uint64_t s = serial;
@@ -676,10 +676,10 @@ int sd_rtnl_call_async_cancel(sd_rtnl *nl, uint32_t serial) {
return 1;
}
-int sd_rtnl_call(sd_rtnl *rtnl,
- sd_rtnl_message *message,
+int sd_netlink_call(sd_netlink *rtnl,
+ sd_netlink_message *message,
uint64_t usec,
- sd_rtnl_message **ret) {
+ sd_netlink_message **ret) {
usec_t timeout;
uint32_t serial;
int r;
@@ -688,7 +688,7 @@ int sd_rtnl_call(sd_rtnl *rtnl,
assert_return(!rtnl_pid_changed(rtnl), -ECHILD);
assert_return(message, -EINVAL);
- r = sd_rtnl_send(rtnl, message, &serial);
+ r = sd_netlink_send(rtnl, message, &serial);
if (r < 0)
return r;
@@ -704,21 +704,21 @@ int sd_rtnl_call(sd_rtnl *rtnl,
received_serial = rtnl_message_get_serial(rtnl->rqueue[i]);
if (received_serial == serial) {
- _cleanup_rtnl_message_unref_ sd_rtnl_message *incoming = NULL;
+ _cleanup_netlink_message_unref_ sd_netlink_message *incoming = NULL;
uint16_t type;
incoming = rtnl->rqueue[i];
/* found a match, remove from rqueue and return it */
memmove(rtnl->rqueue + i,rtnl->rqueue + i + 1,
- sizeof(sd_rtnl_message*) * (rtnl->rqueue_size - i - 1));
+ sizeof(sd_netlink_message*) * (rtnl->rqueue_size - i - 1));
rtnl->rqueue_size--;
- r = sd_rtnl_message_get_errno(incoming);
+ r = sd_netlink_message_get_errno(incoming);
if (r < 0)
return r;
- r = sd_rtnl_message_get_type(incoming, &type);
+ r = sd_netlink_message_get_type(incoming, &type);
if (r < 0)
return r;
@@ -766,7 +766,7 @@ int sd_rtnl_call(sd_rtnl *rtnl,
}
}
-int sd_rtnl_flush(sd_rtnl *rtnl) {
+int sd_netlink_flush(sd_netlink *rtnl) {
int r;
assert_return(rtnl, -EINVAL);
@@ -789,7 +789,7 @@ int sd_rtnl_flush(sd_rtnl *rtnl) {
}
}
-int sd_rtnl_get_events(sd_rtnl *rtnl) {
+int sd_netlink_get_events(sd_netlink *rtnl) {
int flags = 0;
assert_return(rtnl, -EINVAL);
@@ -803,7 +803,7 @@ int sd_rtnl_get_events(sd_rtnl *rtnl) {
return flags;
}
-int sd_rtnl_get_timeout(sd_rtnl *rtnl, uint64_t *timeout_usec) {
+int sd_netlink_get_timeout(sd_netlink *rtnl, uint64_t *timeout_usec) {
struct reply_callback *c;
assert_return(rtnl, -EINVAL);
@@ -827,12 +827,12 @@ int sd_rtnl_get_timeout(sd_rtnl *rtnl, uint64_t *timeout_usec) {
}
static int io_callback(sd_event_source *s, int fd, uint32_t revents, void *userdata) {
- sd_rtnl *rtnl = userdata;
+ sd_netlink *rtnl = userdata;
int r;
assert(rtnl);
- r = sd_rtnl_process(rtnl, NULL);
+ r = sd_netlink_process(rtnl, NULL);
if (r < 0)
return r;
@@ -840,12 +840,12 @@ static int io_callback(sd_event_source *s, int fd, uint32_t revents, void *userd
}
static int time_callback(sd_event_source *s, uint64_t usec, void *userdata) {
- sd_rtnl *rtnl = userdata;
+ sd_netlink *rtnl = userdata;
int r;
assert(rtnl);
- r = sd_rtnl_process(rtnl, NULL);
+ r = sd_netlink_process(rtnl, NULL);
if (r < 0)
return r;
@@ -853,14 +853,14 @@ static int time_callback(sd_event_source *s, uint64_t usec, void *userdata) {
}
static int prepare_callback(sd_event_source *s, void *userdata) {
- sd_rtnl *rtnl = userdata;
+ sd_netlink *rtnl = userdata;
int r, e;
usec_t until;
assert(s);
assert(rtnl);
- e = sd_rtnl_get_events(rtnl);
+ e = sd_netlink_get_events(rtnl);
if (e < 0)
return e;
@@ -868,7 +868,7 @@ static int prepare_callback(sd_event_source *s, void *userdata) {
if (r < 0)
return r;
- r = sd_rtnl_get_timeout(rtnl, &until);
+ r = sd_netlink_get_timeout(rtnl, &until);
if (r < 0)
return r;
if (r > 0) {
@@ -887,16 +887,16 @@ static int prepare_callback(sd_event_source *s, void *userdata) {
}
static int exit_callback(sd_event_source *event, void *userdata) {
- sd_rtnl *rtnl = userdata;
+ sd_netlink *rtnl = userdata;
assert(event);
- sd_rtnl_flush(rtnl);
+ sd_netlink_flush(rtnl);
return 1;
}
-int sd_rtnl_attach_event(sd_rtnl *rtnl, sd_event *event, int priority) {
+int sd_netlink_attach_event(sd_netlink *rtnl, sd_event *event, int priority) {
int r;
assert_return(rtnl, -EINVAL);
@@ -952,11 +952,11 @@ int sd_rtnl_attach_event(sd_rtnl *rtnl, sd_event *event, int priority) {
return 0;
fail:
- sd_rtnl_detach_event(rtnl);
+ sd_netlink_detach_event(rtnl);
return r;
}
-int sd_rtnl_detach_event(sd_rtnl *rtnl) {
+int sd_netlink_detach_event(sd_netlink *rtnl) {
assert_return(rtnl, -EINVAL);
assert_return(rtnl->event, -ENXIO);
@@ -975,9 +975,9 @@ int sd_rtnl_detach_event(sd_rtnl *rtnl) {
return 0;
}
-int sd_rtnl_add_match(sd_rtnl *rtnl,
+int sd_netlink_add_match(sd_netlink *rtnl,
uint16_t type,
- sd_rtnl_message_handler_t callback,
+ sd_netlink_message_handler_t callback,
void *userdata) {
_cleanup_free_ struct match_callback *c = NULL;
int r;
@@ -1027,9 +1027,9 @@ int sd_rtnl_add_match(sd_rtnl *rtnl,
return 0;
}
-int sd_rtnl_remove_match(sd_rtnl *rtnl,
+int sd_netlink_remove_match(sd_netlink *rtnl,
uint16_t type,
- sd_rtnl_message_handler_t callback,
+ sd_netlink_message_handler_t callback,
void *userdata) {
struct match_callback *c;
diff --git a/src/libsystemd/sd-rtnl/test-local-addresses.c b/src/libsystemd/sd-netlink/test-local-addresses.c
index 38cbcfbccb..38cbcfbccb 100644
--- a/src/libsystemd/sd-rtnl/test-local-addresses.c
+++ b/src/libsystemd/sd-netlink/test-local-addresses.c
diff --git a/src/libsystemd/sd-netlink/test-netlink.c b/src/libsystemd/sd-netlink/test-netlink.c
new file mode 100644
index 0000000000..60a4601e7e
--- /dev/null
+++ b/src/libsystemd/sd-netlink/test-netlink.c
@@ -0,0 +1,443 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+ This file is part of systemd.
+
+ Copyright 2013 Tom Gundersen <teg@jklm.no>
+
+ systemd is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ systemd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include <netinet/ether.h>
+#include <net/if.h>
+
+#include "util.h"
+#include "macro.h"
+#include "sd-netlink.h"
+#include "socket-util.h"
+#include "netlink-util.h"
+#include "event-util.h"
+#include "missing.h"
+
+static void test_message_link_bridge(sd_netlink *rtnl) {
+ _cleanup_netlink_message_unref_ sd_netlink_message *message = NULL;
+ uint32_t cost;
+
+ assert_se(sd_rtnl_message_new_link(rtnl, &message, RTM_NEWLINK, 1) >= 0);
+ assert_se(sd_rtnl_message_link_set_family(message, PF_BRIDGE) >= 0);
+ assert_se(sd_netlink_message_open_container(message, IFLA_PROTINFO) >= 0);
+ assert_se(sd_netlink_message_append_u32(message, IFLA_BRPORT_COST, 10) >= 0);
+ assert_se(sd_netlink_message_close_container(message) >= 0);
+
+ assert_se(sd_netlink_message_rewind(message) >= 0);
+
+ assert_se(sd_netlink_message_enter_container(message, IFLA_PROTINFO) >= 0);
+ assert_se(sd_netlink_message_read_u32(message, IFLA_BRPORT_COST, &cost) >= 0);
+ assert_se(cost == 10);
+ assert_se(sd_netlink_message_exit_container(message) >= 0);
+}
+
+static void test_link_configure(sd_netlink *rtnl, int ifindex) {
+ _cleanup_netlink_message_unref_ sd_netlink_message *message = NULL;
+ const char *mac = "98:fe:94:3f:c6:18", *name = "test";
+ char buffer[ETHER_ADDR_TO_STRING_MAX];
+ unsigned int mtu = 1450, mtu_out;
+ const char *name_out;
+ struct ether_addr mac_out;
+
+ /* we'd really like to test NEWLINK, but let's not mess with the running kernel */
+ assert_se(sd_rtnl_message_new_link(rtnl, &message, RTM_GETLINK, ifindex) >= 0);
+ assert_se(sd_netlink_message_append_string(message, IFLA_IFNAME, name) >= 0);
+ assert_se(sd_netlink_message_append_ether_addr(message, IFLA_ADDRESS, ether_aton(mac)) >= 0);
+ assert_se(sd_netlink_message_append_u32(message, IFLA_MTU, mtu) >= 0);
+
+ assert_se(sd_netlink_call(rtnl, message, 0, NULL) == 1);
+ assert_se(sd_netlink_message_rewind(message) >= 0);
+
+ assert_se(sd_netlink_message_read_string(message, IFLA_IFNAME, &name_out) >= 0);
+ assert_se(streq(name, name_out));
+
+ assert_se(sd_netlink_message_read_ether_addr(message, IFLA_ADDRESS, &mac_out) >= 0);
+ assert_se(streq(mac, ether_addr_to_string(&mac_out, buffer)));
+
+ assert_se(sd_netlink_message_read_u32(message, IFLA_MTU, &mtu_out) >= 0);
+ assert_se(mtu == mtu_out);
+}
+
+static void test_link_get(sd_netlink *rtnl, int ifindex) {
+ sd_netlink_message *m;
+ sd_netlink_message *r;
+ unsigned int mtu = 1500;
+ const char *str_data;
+ uint8_t u8_data;
+ uint32_t u32_data;
+ struct ether_addr eth_data;
+
+ assert_se(sd_rtnl_message_new_link(rtnl, &m, RTM_GETLINK, ifindex) >= 0);
+ assert_se(m);
+
+ /* u8 test cases */
+ assert_se(sd_netlink_message_append_u8(m, IFLA_CARRIER, 0) >= 0);
+ assert_se(sd_netlink_message_append_u8(m, IFLA_OPERSTATE, 0) >= 0);
+ assert_se(sd_netlink_message_append_u8(m, IFLA_LINKMODE, 0) >= 0);
+
+ /* u32 test cases */
+ assert_se(sd_netlink_message_append_u32(m, IFLA_MTU, mtu) >= 0);
+ assert_se(sd_netlink_message_append_u32(m, IFLA_GROUP, 0) >= 0);
+ assert_se(sd_netlink_message_append_u32(m, IFLA_TXQLEN, 0) >= 0);
+ assert_se(sd_netlink_message_append_u32(m, IFLA_NUM_TX_QUEUES, 0) >= 0);
+ assert_se(sd_netlink_message_append_u32(m, IFLA_NUM_RX_QUEUES, 0) >= 0);
+
+ assert_se(sd_netlink_call(rtnl, m, -1, &r) == 1);
+
+ assert_se(sd_netlink_message_read_string(r, IFLA_IFNAME, &str_data) == 0);
+
+ assert_se(sd_netlink_message_read_u8(r, IFLA_CARRIER, &u8_data) == 0);
+ assert_se(sd_netlink_message_read_u8(r, IFLA_OPERSTATE, &u8_data) == 0);
+ assert_se(sd_netlink_message_read_u8(r, IFLA_LINKMODE, &u8_data) == 0);
+
+ assert_se(sd_netlink_message_read_u32(r, IFLA_MTU, &u32_data) == 0);
+ assert_se(sd_netlink_message_read_u32(r, IFLA_GROUP, &u32_data) == 0);
+ assert_se(sd_netlink_message_read_u32(r, IFLA_TXQLEN, &u32_data) == 0);
+ assert_se(sd_netlink_message_read_u32(r, IFLA_NUM_TX_QUEUES, &u32_data) == 0);
+ assert_se(sd_netlink_message_read_u32(r, IFLA_NUM_RX_QUEUES, &u32_data) == 0);
+
+ assert_se(sd_netlink_message_read_ether_addr(r, IFLA_ADDRESS, &eth_data) == 0);
+
+ assert_se(sd_netlink_flush(rtnl) >= 0);
+ assert_se((m = sd_netlink_message_unref(m)) == NULL);
+ assert_se((r = sd_netlink_message_unref(r)) == NULL);
+}
+
+
+static void test_address_get(sd_netlink *rtnl, int ifindex) {
+ sd_netlink_message *m;
+ sd_netlink_message *r;
+ struct in_addr in_data;
+ struct ifa_cacheinfo cache;
+ const char *label;
+
+ assert_se(sd_rtnl_message_new_addr(rtnl, &m, RTM_GETADDR, ifindex, AF_INET) >= 0);
+ assert_se(m);
+
+ assert_se(sd_netlink_call(rtnl, m, -1, &r) == 1);
+
+ assert_se(sd_netlink_message_read_in_addr(r, IFA_LOCAL, &in_data) == 0);
+ assert_se(sd_netlink_message_read_in_addr(r, IFA_ADDRESS, &in_data) == 0);
+ assert_se(sd_netlink_message_read_string(r, IFA_LABEL, &label) == 0);
+ assert_se(sd_netlink_message_read_cache_info(r, IFA_CACHEINFO, &cache) == 0);
+
+ assert_se(sd_netlink_flush(rtnl) >= 0);
+ assert_se((m = sd_netlink_message_unref(m)) == NULL);
+ assert_se((r = sd_netlink_message_unref(r)) == NULL);
+
+}
+
+static void test_route(void) {
+ _cleanup_netlink_message_unref_ sd_netlink_message *req;
+ struct in_addr addr, addr_data;
+ uint32_t index = 2, u32_data;
+ int r;
+
+ r = sd_rtnl_message_new_route(NULL, &req, RTM_NEWROUTE, AF_INET, RTPROT_STATIC);
+ if (r < 0) {
+ log_error_errno(r, "Could not create RTM_NEWROUTE message: %m");
+ return;
+ }
+
+ addr.s_addr = htonl(INADDR_LOOPBACK);
+
+ r = sd_netlink_message_append_in_addr(req, RTA_GATEWAY, &addr);
+ if (r < 0) {
+ log_error_errno(r, "Could not append RTA_GATEWAY attribute: %m");
+ return;
+ }
+
+ r = sd_netlink_message_append_u32(req, RTA_OIF, index);
+ if (r < 0) {
+ log_error_errno(r, "Could not append RTA_OIF attribute: %m");
+ return;
+ }
+
+ assert_se(sd_netlink_message_rewind(req) >= 0);
+
+ assert_se(sd_netlink_message_read_in_addr(req, RTA_GATEWAY, &addr_data) >= 0);
+ assert_se(addr_data.s_addr == addr.s_addr);
+
+ assert_se(sd_netlink_message_read_u32(req, RTA_OIF, &u32_data) >= 0);
+ assert_se(u32_data == index);
+
+ assert_se((req = sd_netlink_message_unref(req)) == NULL);
+}
+
+static void test_multiple(void) {
+ sd_netlink *rtnl1, *rtnl2;
+
+ assert_se(sd_netlink_open(&rtnl1) >= 0);
+ assert_se(sd_netlink_open(&rtnl2) >= 0);
+
+ rtnl1 = sd_netlink_unref(rtnl1);
+ rtnl2 = sd_netlink_unref(rtnl2);
+}
+
+static int link_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata) {
+ char *ifname = userdata;
+ const char *data;
+
+ assert_se(rtnl);
+ assert_se(m);
+
+ log_info("got link info about %s", ifname);
+ free(ifname);
+
+ assert_se(sd_netlink_message_read_string(m, IFLA_IFNAME, &data) >= 0);
+ assert_se(streq(data, "lo"));
+
+ return 1;
+}
+
+static void test_event_loop(int ifindex) {
+ _cleanup_event_unref_ sd_event *event = NULL;
+ _cleanup_netlink_unref_ sd_netlink *rtnl = NULL;
+ _cleanup_netlink_message_unref_ sd_netlink_message *m = NULL;
+ char *ifname;
+
+ ifname = strdup("lo2");
+ assert_se(ifname);
+
+ assert_se(sd_netlink_open(&rtnl) >= 0);
+ assert_se(sd_rtnl_message_new_link(rtnl, &m, RTM_GETLINK, ifindex) >= 0);
+
+ assert_se(sd_netlink_call_async(rtnl, m, &link_handler, ifname, 0, NULL) >= 0);
+
+ assert_se(sd_event_default(&event) >= 0);
+
+ assert_se(sd_netlink_attach_event(rtnl, event, 0) >= 0);
+
+ assert_se(sd_event_run(event, 0) >= 0);
+
+ assert_se(sd_netlink_detach_event(rtnl) >= 0);
+
+ assert_se((rtnl = sd_netlink_unref(rtnl)) == NULL);
+}
+
+static int pipe_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata) {
+ int *counter = userdata;
+ int r;
+
+ (*counter) --;
+
+ r = sd_netlink_message_get_errno(m);
+
+ log_info_errno(r, "%d left in pipe. got reply: %m", *counter);
+
+ assert_se(r >= 0);
+
+ return 1;
+}
+
+static void test_async(int ifindex) {
+ _cleanup_netlink_unref_ sd_netlink *rtnl = NULL;
+ _cleanup_netlink_message_unref_ sd_netlink_message *m = NULL, *r = NULL;
+ uint32_t serial;
+ char *ifname;
+
+ ifname = strdup("lo");
+ assert_se(ifname);
+
+ assert_se(sd_netlink_open(&rtnl) >= 0);
+
+ assert_se(sd_rtnl_message_new_link(rtnl, &m, RTM_GETLINK, ifindex) >= 0);
+
+ assert_se(sd_netlink_call_async(rtnl, m, &link_handler, ifname, 0, &serial) >= 0);
+
+ assert_se(sd_netlink_wait(rtnl, 0) >= 0);
+ assert_se(sd_netlink_process(rtnl, &r) >= 0);
+
+ assert_se((rtnl = sd_netlink_unref(rtnl)) == NULL);
+}
+
+static void test_pipe(int ifindex) {
+ _cleanup_netlink_unref_ sd_netlink *rtnl = NULL;
+ _cleanup_netlink_message_unref_ sd_netlink_message *m1 = NULL, *m2 = NULL;
+ int counter = 0;
+
+ assert_se(sd_netlink_open(&rtnl) >= 0);
+
+ assert_se(sd_rtnl_message_new_link(rtnl, &m1, RTM_GETLINK, ifindex) >= 0);
+ assert_se(sd_rtnl_message_new_link(rtnl, &m2, RTM_GETLINK, ifindex) >= 0);
+
+ counter ++;
+ assert_se(sd_netlink_call_async(rtnl, m1, &pipe_handler, &counter, 0, NULL) >= 0);
+
+ counter ++;
+ assert_se(sd_netlink_call_async(rtnl, m2, &pipe_handler, &counter, 0, NULL) >= 0);
+
+ while (counter > 0) {
+ assert_se(sd_netlink_wait(rtnl, 0) >= 0);
+ assert_se(sd_netlink_process(rtnl, NULL) >= 0);
+ }
+
+ assert_se((rtnl = sd_netlink_unref(rtnl)) == NULL);
+}
+
+static void test_container(void) {
+ _cleanup_netlink_message_unref_ sd_netlink_message *m = NULL;
+ uint16_t u16_data;
+ uint32_t u32_data;
+ const char *string_data;
+
+ assert_se(sd_rtnl_message_new_link(NULL, &m, RTM_NEWLINK, 0) >= 0);
+
+ assert_se(sd_netlink_message_open_container(m, IFLA_LINKINFO) >= 0);
+ assert_se(sd_netlink_message_open_container_union(m, IFLA_INFO_DATA, "vlan") >= 0);
+ assert_se(sd_netlink_message_append_u16(m, IFLA_VLAN_ID, 100) >= 0);
+ assert_se(sd_netlink_message_close_container(m) >= 0);
+ assert_se(sd_netlink_message_append_string(m, IFLA_INFO_KIND, "vlan") >= 0);
+ assert_se(sd_netlink_message_close_container(m) >= 0);
+ assert_se(sd_netlink_message_close_container(m) == -EINVAL);
+
+ assert_se(sd_netlink_message_rewind(m) >= 0);
+
+ assert_se(sd_netlink_message_enter_container(m, IFLA_LINKINFO) >= 0);
+ assert_se(sd_netlink_message_read_string(m, IFLA_INFO_KIND, &string_data) >= 0);
+ assert_se(streq("vlan", string_data));
+
+ assert_se(sd_netlink_message_enter_container(m, IFLA_INFO_DATA) >= 0);
+ assert_se(sd_netlink_message_read_u16(m, IFLA_VLAN_ID, &u16_data) >= 0);
+ assert_se(sd_netlink_message_exit_container(m) >= 0);
+
+ assert_se(sd_netlink_message_read_string(m, IFLA_INFO_KIND, &string_data) >= 0);
+ assert_se(streq("vlan", string_data));
+ assert_se(sd_netlink_message_exit_container(m) >= 0);
+
+ assert_se(sd_netlink_message_read_u32(m, IFLA_LINKINFO, &u32_data) < 0);
+
+ assert_se(sd_netlink_message_exit_container(m) == -EINVAL);
+}
+
+static void test_match(void) {
+ _cleanup_netlink_unref_ sd_netlink *rtnl = NULL;
+
+ assert_se(sd_netlink_open(&rtnl) >= 0);
+
+ assert_se(sd_netlink_add_match(rtnl, RTM_NEWLINK, &link_handler, NULL) >= 0);
+ assert_se(sd_netlink_add_match(rtnl, RTM_NEWLINK, &link_handler, NULL) >= 0);
+
+ assert_se(sd_netlink_remove_match(rtnl, RTM_NEWLINK, &link_handler, NULL) == 1);
+ assert_se(sd_netlink_remove_match(rtnl, RTM_NEWLINK, &link_handler, NULL) == 1);
+ assert_se(sd_netlink_remove_match(rtnl, RTM_NEWLINK, &link_handler, NULL) == 0);
+
+ assert_se((rtnl = sd_netlink_unref(rtnl)) == NULL);
+}
+
+static void test_get_addresses(sd_netlink *rtnl) {
+ _cleanup_netlink_message_unref_ sd_netlink_message *req = NULL, *reply = NULL;
+ sd_netlink_message *m;
+
+ assert_se(sd_rtnl_message_new_addr(rtnl, &req, RTM_GETADDR, 0, AF_UNSPEC) >= 0);
+
+ assert_se(sd_netlink_call(rtnl, req, 0, &reply) >= 0);
+
+ for (m = reply; m; m = sd_netlink_message_next(m)) {
+ uint16_t type;
+ unsigned char scope, flags;
+ int family, ifindex;
+
+ assert_se(sd_netlink_message_get_type(m, &type) >= 0);
+ assert_se(type == RTM_NEWADDR);
+
+ assert_se(sd_rtnl_message_addr_get_ifindex(m, &ifindex) >= 0);
+ assert_se(sd_rtnl_message_addr_get_family(m, &family) >= 0);
+ assert_se(sd_rtnl_message_addr_get_scope(m, &scope) >= 0);
+ assert_se(sd_rtnl_message_addr_get_flags(m, &flags) >= 0);
+
+ assert_se(ifindex > 0);
+ assert_se(family == AF_INET || family == AF_INET6);
+
+ log_info("got IPv%u address on ifindex %i", family == AF_INET ? 4: 6, ifindex);
+ }
+}
+
+static void test_message(void) {
+ _cleanup_netlink_message_unref_ sd_netlink_message *m = NULL;
+
+ assert_se(rtnl_message_new_synthetic_error(-ETIMEDOUT, 1, &m) >= 0);
+ assert_se(sd_netlink_message_get_errno(m) == -ETIMEDOUT);
+}
+
+int main(void) {
+ sd_netlink *rtnl;
+ sd_netlink_message *m;
+ sd_netlink_message *r;
+ const char *string_data;
+ int if_loopback;
+ uint16_t type;
+
+ test_message();
+
+ test_match();
+
+ test_multiple();
+
+ test_route();
+
+ test_container();
+
+ assert_se(sd_netlink_open(&rtnl) >= 0);
+ assert_se(rtnl);
+
+ if_loopback = (int) if_nametoindex("lo");
+ assert_se(if_loopback > 0);
+
+ test_async(if_loopback);
+
+ test_pipe(if_loopback);
+
+ test_event_loop(if_loopback);
+
+ test_link_configure(rtnl, if_loopback);
+
+ test_get_addresses(rtnl);
+
+ test_message_link_bridge(rtnl);
+
+ assert_se(sd_rtnl_message_new_link(rtnl, &m, RTM_GETLINK, if_loopback) >= 0);
+ assert_se(m);
+
+ assert_se(sd_netlink_message_get_type(m, &type) >= 0);
+ assert_se(type == RTM_GETLINK);
+
+ assert_se(sd_netlink_message_read_string(m, IFLA_IFNAME, &string_data) == -EPERM);
+
+ assert_se(sd_netlink_call(rtnl, m, 0, &r) == 1);
+ assert_se(sd_netlink_message_get_type(r, &type) >= 0);
+ assert_se(type == RTM_NEWLINK);
+
+ assert_se((r = sd_netlink_message_unref(r)) == NULL);
+
+ assert_se(sd_netlink_call(rtnl, m, -1, &r) == -EPERM);
+ assert_se((m = sd_netlink_message_unref(m)) == NULL);
+ assert_se((r = sd_netlink_message_unref(r)) == NULL);
+
+ test_link_get(rtnl, if_loopback);
+ test_address_get(rtnl, if_loopback);
+
+ assert_se(sd_netlink_flush(rtnl) >= 0);
+ assert_se((m = sd_netlink_message_unref(m)) == NULL);
+ assert_se((r = sd_netlink_message_unref(r)) == NULL);
+ assert_se((rtnl = sd_netlink_unref(rtnl)) == NULL);
+
+ return EXIT_SUCCESS;
+}
diff --git a/src/libsystemd/sd-rtnl/test-rtnl.c b/src/libsystemd/sd-rtnl/test-rtnl.c
deleted file mode 100644
index 94b1cb7c72..0000000000
--- a/src/libsystemd/sd-rtnl/test-rtnl.c
+++ /dev/null
@@ -1,443 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2013 Tom Gundersen <teg@jklm.no>
-
- systemd is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as published by
- the Free Software Foundation; either version 2.1 of the License, or
- (at your option) any later version.
-
- systemd is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with systemd; If not, see <http://www.gnu.org/licenses/>.
-***/
-
-#include <netinet/ether.h>
-#include <net/if.h>
-
-#include "util.h"
-#include "macro.h"
-#include "sd-rtnl.h"
-#include "socket-util.h"
-#include "rtnl-util.h"
-#include "event-util.h"
-#include "missing.h"
-
-static void test_message_link_bridge(sd_rtnl *rtnl) {
- _cleanup_rtnl_message_unref_ sd_rtnl_message *message = NULL;
- uint32_t cost;
-
- assert_se(sd_rtnl_message_new_link(rtnl, &message, RTM_NEWLINK, 1) >= 0);
- assert_se(sd_rtnl_message_link_set_family(message, PF_BRIDGE) >= 0);
- assert_se(sd_rtnl_message_open_container(message, IFLA_PROTINFO) >= 0);
- assert_se(sd_rtnl_message_append_u32(message, IFLA_BRPORT_COST, 10) >= 0);
- assert_se(sd_rtnl_message_close_container(message) >= 0);
-
- assert_se(sd_rtnl_message_rewind(message) >= 0);
-
- assert_se(sd_rtnl_message_enter_container(message, IFLA_PROTINFO) >= 0);
- assert_se(sd_rtnl_message_read_u32(message, IFLA_BRPORT_COST, &cost) >= 0);
- assert_se(cost == 10);
- assert_se(sd_rtnl_message_exit_container(message) >= 0);
-}
-
-static void test_link_configure(sd_rtnl *rtnl, int ifindex) {
- _cleanup_rtnl_message_unref_ sd_rtnl_message *message = NULL;
- const char *mac = "98:fe:94:3f:c6:18", *name = "test";
- char buffer[ETHER_ADDR_TO_STRING_MAX];
- unsigned int mtu = 1450, mtu_out;
- const char *name_out;
- struct ether_addr mac_out;
-
- /* we'd really like to test NEWLINK, but let's not mess with the running kernel */
- assert_se(sd_rtnl_message_new_link(rtnl, &message, RTM_GETLINK, ifindex) >= 0);
- assert_se(sd_rtnl_message_append_string(message, IFLA_IFNAME, name) >= 0);
- assert_se(sd_rtnl_message_append_ether_addr(message, IFLA_ADDRESS, ether_aton(mac)) >= 0);
- assert_se(sd_rtnl_message_append_u32(message, IFLA_MTU, mtu) >= 0);
-
- assert_se(sd_rtnl_call(rtnl, message, 0, NULL) == 1);
- assert_se(sd_rtnl_message_rewind(message) >= 0);
-
- assert_se(sd_rtnl_message_read_string(message, IFLA_IFNAME, &name_out) >= 0);
- assert_se(streq(name, name_out));
-
- assert_se(sd_rtnl_message_read_ether_addr(message, IFLA_ADDRESS, &mac_out) >= 0);
- assert_se(streq(mac, ether_addr_to_string(&mac_out, buffer)));
-
- assert_se(sd_rtnl_message_read_u32(message, IFLA_MTU, &mtu_out) >= 0);
- assert_se(mtu == mtu_out);
-}
-
-static void test_link_get(sd_rtnl *rtnl, int ifindex) {
- sd_rtnl_message *m;
- sd_rtnl_message *r;
- unsigned int mtu = 1500;
- const char *str_data;
- uint8_t u8_data;
- uint32_t u32_data;
- struct ether_addr eth_data;
-
- assert_se(sd_rtnl_message_new_link(rtnl, &m, RTM_GETLINK, ifindex) >= 0);
- assert_se(m);
-
- /* u8 test cases */
- assert_se(sd_rtnl_message_append_u8(m, IFLA_CARRIER, 0) >= 0);
- assert_se(sd_rtnl_message_append_u8(m, IFLA_OPERSTATE, 0) >= 0);
- assert_se(sd_rtnl_message_append_u8(m, IFLA_LINKMODE, 0) >= 0);
-
- /* u32 test cases */
- assert_se(sd_rtnl_message_append_u32(m, IFLA_MTU, mtu) >= 0);
- assert_se(sd_rtnl_message_append_u32(m, IFLA_GROUP, 0) >= 0);
- assert_se(sd_rtnl_message_append_u32(m, IFLA_TXQLEN, 0) >= 0);
- assert_se(sd_rtnl_message_append_u32(m, IFLA_NUM_TX_QUEUES, 0) >= 0);
- assert_se(sd_rtnl_message_append_u32(m, IFLA_NUM_RX_QUEUES, 0) >= 0);
-
- assert_se(sd_rtnl_call(rtnl, m, -1, &r) == 1);
-
- assert_se(sd_rtnl_message_read_string(r, IFLA_IFNAME, &str_data) == 0);
-
- assert_se(sd_rtnl_message_read_u8(r, IFLA_CARRIER, &u8_data) == 0);
- assert_se(sd_rtnl_message_read_u8(r, IFLA_OPERSTATE, &u8_data) == 0);
- assert_se(sd_rtnl_message_read_u8(r, IFLA_LINKMODE, &u8_data) == 0);
-
- assert_se(sd_rtnl_message_read_u32(r, IFLA_MTU, &u32_data) == 0);
- assert_se(sd_rtnl_message_read_u32(r, IFLA_GROUP, &u32_data) == 0);
- assert_se(sd_rtnl_message_read_u32(r, IFLA_TXQLEN, &u32_data) == 0);
- assert_se(sd_rtnl_message_read_u32(r, IFLA_NUM_TX_QUEUES, &u32_data) == 0);
- assert_se(sd_rtnl_message_read_u32(r, IFLA_NUM_RX_QUEUES, &u32_data) == 0);
-
- assert_se(sd_rtnl_message_read_ether_addr(r, IFLA_ADDRESS, &eth_data) == 0);
-
- assert_se(sd_rtnl_flush(rtnl) >= 0);
- assert_se((m = sd_rtnl_message_unref(m)) == NULL);
- assert_se((r = sd_rtnl_message_unref(r)) == NULL);
-}
-
-
-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;
- const char *label;
-
- assert_se(sd_rtnl_message_new_addr(rtnl, &m, RTM_GETADDR, ifindex, AF_INET) >= 0);
- assert_se(m);
-
- assert_se(sd_rtnl_call(rtnl, m, -1, &r) == 1);
-
- 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);
- assert_se((r = sd_rtnl_message_unref(r)) == NULL);
-
-}
-
-static void test_route(void) {
- _cleanup_rtnl_message_unref_ sd_rtnl_message *req;
- struct in_addr addr, addr_data;
- uint32_t index = 2, u32_data;
- int r;
-
- r = sd_rtnl_message_new_route(NULL, &req, RTM_NEWROUTE, AF_INET, RTPROT_STATIC);
- if (r < 0) {
- log_error_errno(r, "Could not create RTM_NEWROUTE message: %m");
- return;
- }
-
- addr.s_addr = htonl(INADDR_LOOPBACK);
-
- r = sd_rtnl_message_append_in_addr(req, RTA_GATEWAY, &addr);
- if (r < 0) {
- log_error_errno(r, "Could not append RTA_GATEWAY attribute: %m");
- return;
- }
-
- r = sd_rtnl_message_append_u32(req, RTA_OIF, index);
- if (r < 0) {
- log_error_errno(r, "Could not append RTA_OIF attribute: %m");
- return;
- }
-
- assert_se(sd_rtnl_message_rewind(req) >= 0);
-
- assert_se(sd_rtnl_message_read_in_addr(req, RTA_GATEWAY, &addr_data) >= 0);
- assert_se(addr_data.s_addr == addr.s_addr);
-
- assert_se(sd_rtnl_message_read_u32(req, RTA_OIF, &u32_data) >= 0);
- assert_se(u32_data == index);
-
- assert_se((req = sd_rtnl_message_unref(req)) == NULL);
-}
-
-static void test_multiple(void) {
- sd_rtnl *rtnl1, *rtnl2;
-
- assert_se(sd_rtnl_open(&rtnl1) >= 0);
- assert_se(sd_rtnl_open(&rtnl2) >= 0);
-
- rtnl1 = sd_rtnl_unref(rtnl1);
- rtnl2 = sd_rtnl_unref(rtnl2);
-}
-
-static int link_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
- char *ifname = userdata;
- const char *data;
-
- assert_se(rtnl);
- assert_se(m);
-
- log_info("got link info about %s", ifname);
- free(ifname);
-
- assert_se(sd_rtnl_message_read_string(m, IFLA_IFNAME, &data) >= 0);
- assert_se(streq(data, "lo"));
-
- return 1;
-}
-
-static void test_event_loop(int ifindex) {
- _cleanup_event_unref_ sd_event *event = NULL;
- _cleanup_rtnl_unref_ sd_rtnl *rtnl = NULL;
- _cleanup_rtnl_message_unref_ sd_rtnl_message *m = NULL;
- char *ifname;
-
- ifname = strdup("lo2");
- assert_se(ifname);
-
- assert_se(sd_rtnl_open(&rtnl) >= 0);
- assert_se(sd_rtnl_message_new_link(rtnl, &m, RTM_GETLINK, ifindex) >= 0);
-
- assert_se(sd_rtnl_call_async(rtnl, m, &link_handler, ifname, 0, NULL) >= 0);
-
- assert_se(sd_event_default(&event) >= 0);
-
- assert_se(sd_rtnl_attach_event(rtnl, event, 0) >= 0);
-
- assert_se(sd_event_run(event, 0) >= 0);
-
- assert_se(sd_rtnl_detach_event(rtnl) >= 0);
-
- assert_se((rtnl = sd_rtnl_unref(rtnl)) == NULL);
-}
-
-static int pipe_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
- int *counter = userdata;
- int r;
-
- (*counter) --;
-
- r = sd_rtnl_message_get_errno(m);
-
- log_info_errno(r, "%d left in pipe. got reply: %m", *counter);
-
- assert_se(r >= 0);
-
- return 1;
-}
-
-static void test_async(int ifindex) {
- _cleanup_rtnl_unref_ sd_rtnl *rtnl = NULL;
- _cleanup_rtnl_message_unref_ sd_rtnl_message *m = NULL, *r = NULL;
- uint32_t serial;
- char *ifname;
-
- ifname = strdup("lo");
- assert_se(ifname);
-
- assert_se(sd_rtnl_open(&rtnl) >= 0);
-
- assert_se(sd_rtnl_message_new_link(rtnl, &m, RTM_GETLINK, ifindex) >= 0);
-
- assert_se(sd_rtnl_call_async(rtnl, m, &link_handler, ifname, 0, &serial) >= 0);
-
- assert_se(sd_rtnl_wait(rtnl, 0) >= 0);
- assert_se(sd_rtnl_process(rtnl, &r) >= 0);
-
- assert_se((rtnl = sd_rtnl_unref(rtnl)) == NULL);
-}
-
-static void test_pipe(int ifindex) {
- _cleanup_rtnl_unref_ sd_rtnl *rtnl = NULL;
- _cleanup_rtnl_message_unref_ sd_rtnl_message *m1 = NULL, *m2 = NULL;
- int counter = 0;
-
- assert_se(sd_rtnl_open(&rtnl) >= 0);
-
- assert_se(sd_rtnl_message_new_link(rtnl, &m1, RTM_GETLINK, ifindex) >= 0);
- assert_se(sd_rtnl_message_new_link(rtnl, &m2, RTM_GETLINK, ifindex) >= 0);
-
- counter ++;
- assert_se(sd_rtnl_call_async(rtnl, m1, &pipe_handler, &counter, 0, NULL) >= 0);
-
- counter ++;
- assert_se(sd_rtnl_call_async(rtnl, m2, &pipe_handler, &counter, 0, NULL) >= 0);
-
- while (counter > 0) {
- assert_se(sd_rtnl_wait(rtnl, 0) >= 0);
- assert_se(sd_rtnl_process(rtnl, NULL) >= 0);
- }
-
- assert_se((rtnl = sd_rtnl_unref(rtnl)) == NULL);
-}
-
-static void test_container(void) {
- _cleanup_rtnl_message_unref_ sd_rtnl_message *m = NULL;
- uint16_t u16_data;
- uint32_t u32_data;
- const char *string_data;
-
- assert_se(sd_rtnl_message_new_link(NULL, &m, RTM_NEWLINK, 0) >= 0);
-
- assert_se(sd_rtnl_message_open_container(m, IFLA_LINKINFO) >= 0);
- assert_se(sd_rtnl_message_open_container_union(m, IFLA_INFO_DATA, "vlan") >= 0);
- assert_se(sd_rtnl_message_append_u16(m, IFLA_VLAN_ID, 100) >= 0);
- assert_se(sd_rtnl_message_close_container(m) >= 0);
- assert_se(sd_rtnl_message_append_string(m, IFLA_INFO_KIND, "vlan") >= 0);
- assert_se(sd_rtnl_message_close_container(m) >= 0);
- assert_se(sd_rtnl_message_close_container(m) == -EINVAL);
-
- assert_se(sd_rtnl_message_rewind(m) >= 0);
-
- assert_se(sd_rtnl_message_enter_container(m, IFLA_LINKINFO) >= 0);
- assert_se(sd_rtnl_message_read_string(m, IFLA_INFO_KIND, &string_data) >= 0);
- assert_se(streq("vlan", string_data));
-
- assert_se(sd_rtnl_message_enter_container(m, IFLA_INFO_DATA) >= 0);
- assert_se(sd_rtnl_message_read_u16(m, IFLA_VLAN_ID, &u16_data) >= 0);
- assert_se(sd_rtnl_message_exit_container(m) >= 0);
-
- assert_se(sd_rtnl_message_read_string(m, IFLA_INFO_KIND, &string_data) >= 0);
- assert_se(streq("vlan", string_data));
- assert_se(sd_rtnl_message_exit_container(m) >= 0);
-
- assert_se(sd_rtnl_message_read_u32(m, IFLA_LINKINFO, &u32_data) < 0);
-
- assert_se(sd_rtnl_message_exit_container(m) == -EINVAL);
-}
-
-static void test_match(void) {
- _cleanup_rtnl_unref_ sd_rtnl *rtnl = NULL;
-
- assert_se(sd_rtnl_open(&rtnl) >= 0);
-
- assert_se(sd_rtnl_add_match(rtnl, RTM_NEWLINK, &link_handler, NULL) >= 0);
- assert_se(sd_rtnl_add_match(rtnl, RTM_NEWLINK, &link_handler, NULL) >= 0);
-
- assert_se(sd_rtnl_remove_match(rtnl, RTM_NEWLINK, &link_handler, NULL) == 1);
- assert_se(sd_rtnl_remove_match(rtnl, RTM_NEWLINK, &link_handler, NULL) == 1);
- assert_se(sd_rtnl_remove_match(rtnl, RTM_NEWLINK, &link_handler, NULL) == 0);
-
- assert_se((rtnl = sd_rtnl_unref(rtnl)) == NULL);
-}
-
-static void test_get_addresses(sd_rtnl *rtnl) {
- _cleanup_rtnl_message_unref_ sd_rtnl_message *req = NULL, *reply = NULL;
- sd_rtnl_message *m;
-
- assert_se(sd_rtnl_message_new_addr(rtnl, &req, RTM_GETADDR, 0, AF_UNSPEC) >= 0);
-
- assert_se(sd_rtnl_call(rtnl, req, 0, &reply) >= 0);
-
- for (m = reply; m; m = sd_rtnl_message_next(m)) {
- uint16_t type;
- unsigned char scope, flags;
- int family, ifindex;
-
- assert_se(sd_rtnl_message_get_type(m, &type) >= 0);
- assert_se(type == RTM_NEWADDR);
-
- assert_se(sd_rtnl_message_addr_get_ifindex(m, &ifindex) >= 0);
- assert_se(sd_rtnl_message_addr_get_family(m, &family) >= 0);
- assert_se(sd_rtnl_message_addr_get_scope(m, &scope) >= 0);
- assert_se(sd_rtnl_message_addr_get_flags(m, &flags) >= 0);
-
- assert_se(ifindex > 0);
- assert_se(family == AF_INET || family == AF_INET6);
-
- log_info("got IPv%u address on ifindex %i", family == AF_INET ? 4: 6, ifindex);
- }
-}
-
-static void test_message(void) {
- _cleanup_rtnl_message_unref_ sd_rtnl_message *m = NULL;
-
- assert_se(rtnl_message_new_synthetic_error(-ETIMEDOUT, 1, &m) >= 0);
- assert_se(sd_rtnl_message_get_errno(m) == -ETIMEDOUT);
-}
-
-int main(void) {
- sd_rtnl *rtnl;
- sd_rtnl_message *m;
- sd_rtnl_message *r;
- const char *string_data;
- int if_loopback;
- uint16_t type;
-
- test_message();
-
- test_match();
-
- test_multiple();
-
- test_route();
-
- test_container();
-
- assert_se(sd_rtnl_open(&rtnl) >= 0);
- assert_se(rtnl);
-
- if_loopback = (int) if_nametoindex("lo");
- assert_se(if_loopback > 0);
-
- test_async(if_loopback);
-
- test_pipe(if_loopback);
-
- test_event_loop(if_loopback);
-
- test_link_configure(rtnl, if_loopback);
-
- test_get_addresses(rtnl);
-
- test_message_link_bridge(rtnl);
-
- assert_se(sd_rtnl_message_new_link(rtnl, &m, RTM_GETLINK, if_loopback) >= 0);
- assert_se(m);
-
- assert_se(sd_rtnl_message_get_type(m, &type) >= 0);
- assert_se(type == RTM_GETLINK);
-
- assert_se(sd_rtnl_message_read_string(m, IFLA_IFNAME, &string_data) == -EPERM);
-
- assert_se(sd_rtnl_call(rtnl, m, 0, &r) == 1);
- assert_se(sd_rtnl_message_get_type(r, &type) >= 0);
- assert_se(type == RTM_NEWLINK);
-
- assert_se((r = sd_rtnl_message_unref(r)) == NULL);
-
- assert_se(sd_rtnl_call(rtnl, m, -1, &r) == -EPERM);
- assert_se((m = sd_rtnl_message_unref(m)) == NULL);
- assert_se((r = sd_rtnl_message_unref(r)) == NULL);
-
- test_link_get(rtnl, if_loopback);
- test_address_get(rtnl, if_loopback);
-
- assert_se(sd_rtnl_flush(rtnl) >= 0);
- assert_se((m = sd_rtnl_message_unref(m)) == NULL);
- assert_se((r = sd_rtnl_message_unref(r)) == NULL);
- assert_se((rtnl = sd_rtnl_unref(rtnl)) == NULL);
-
- return EXIT_SUCCESS;
-}