chiark / gitweb /
sd-rtnl: minor fixes
authorTom Gundersen <teg@jklm.no>
Tue, 29 Oct 2013 14:03:27 +0000 (15:03 +0100)
committerTom Gundersen <teg@jklm.no>
Tue, 29 Oct 2013 15:12:11 +0000 (16:12 +0100)
src/libsystemd-rtnl/rtnl-message.c
src/libsystemd-rtnl/sd-rtnl.c
src/libsystemd-rtnl/test-rtnl.c
src/systemd/sd-rtnl.h

index 82ec1c97abaac50d0615fc6670d698a3a7c473df..80ffb347ddcb4de15f5746ee19fe6604c55f9461 100644 (file)
@@ -45,7 +45,7 @@ static int message_new(sd_rtnl_message **ret, size_t initial_size) {
         sd_rtnl_message *m;
 
         assert_return(ret, -EINVAL);
-        assert_return(initial_size > 0, -EINVAL);
+        assert_return(initial_size >= sizeof(struct nlmsghdr), -EINVAL);
 
         m = new0(sd_rtnl_message, 1);
         if (!m)
@@ -67,7 +67,7 @@ static int message_new(sd_rtnl_message **ret, size_t initial_size) {
         return 0;
 }
 
-int sd_rtnl_message_link_new(__u16 nlmsg_type, int index, unsigned int type, unsigned int flags, sd_rtnl_message **ret) {
+int sd_rtnl_message_link_new(uint16_t nlmsg_type, int index, unsigned int type, unsigned int flags, sd_rtnl_message **ret) {
         struct ifinfomsg *ifi;
         int r;
 
@@ -82,7 +82,7 @@ int sd_rtnl_message_link_new(__u16 nlmsg_type, int index, unsigned int type, uns
         (*ret)->hdr->nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
         (*ret)->hdr->nlmsg_type = nlmsg_type;
 
-        ifi = (struct ifinfomsg *) NLMSG_DATA((*ret)->hdr);
+        ifi = NLMSG_DATA((*ret)->hdr);
 
         ifi->ifi_family = AF_UNSPEC;
         ifi->ifi_index = index;
@@ -93,7 +93,7 @@ int sd_rtnl_message_link_new(__u16 nlmsg_type, int index, unsigned int type, uns
         return 0;
 }
 
-int sd_rtnl_message_addr_new(__u16 nlmsg_type, int index, unsigned char family, unsigned char prefixlen, unsigned char flags, unsigned char scope, sd_rtnl_message **ret) {
+int sd_rtnl_message_addr_new(uint16_t nlmsg_type, int index, unsigned char family, unsigned char prefixlen, unsigned char flags, unsigned char scope, sd_rtnl_message **ret) {
         struct ifaddrmsg *ifa;
         int r;
 
@@ -108,7 +108,7 @@ int sd_rtnl_message_addr_new(__u16 nlmsg_type, int index, unsigned char family,
         (*ret)->hdr->nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg));
         (*ret)->hdr->nlmsg_type = nlmsg_type;
 
-        ifa = (struct ifaddrmsg *) NLMSG_DATA((*ret)->hdr);
+        ifa = NLMSG_DATA((*ret)->hdr);
 
         ifa->ifa_family = family;
         ifa->ifa_prefixlen = prefixlen;
@@ -135,7 +135,7 @@ sd_rtnl_message *sd_rtnl_message_unref(sd_rtnl_message *m) {
         return NULL;
 }
 
-int sd_rtnl_message_get_type(sd_rtnl_message *m, __u16 *type) {
+int sd_rtnl_message_get_type(sd_rtnl_message *m, uint16_t *type) {
         assert_return(m, -EINVAL);
         assert_return(type, -EINVAL);
 
@@ -147,7 +147,7 @@ int sd_rtnl_message_get_type(sd_rtnl_message *m, __u16 *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) {
-        __u32 rta_length, message_length;
+        uint32_t rta_length, message_length;
         struct nlmsghdr *new_hdr;
         struct rtattr *rta;
 
@@ -187,7 +187,7 @@ static int add_rtattr(sd_rtnl_message *m, unsigned short type, const void *data,
 }
 
 int sd_rtnl_message_append(sd_rtnl_message *m, unsigned short type, const void *data) {
-        __u16 rtm_type;
+        uint16_t rtm_type;
         struct ifaddrmsg *ifa;
 
         assert_return(m, -EINVAL);
@@ -258,7 +258,7 @@ static int message_read(sd_rtnl_message *m, unsigned short *type, void **data) {
 }
 
 int sd_rtnl_message_read(sd_rtnl_message *m, unsigned short *type, void **data) {
-        __u16 rtm_type;
+        uint16_t rtm_type;
 
         assert_return(m, -EINVAL);
         assert_return(data, -EINVAL);
@@ -270,7 +270,7 @@ int sd_rtnl_message_read(sd_rtnl_message *m, unsigned short *type, void **data)
                 case RTM_DELLINK:
                 case RTM_GETLINK:
                         if (!m->next_rta) {
-                                struct ifinfomsg *ifi = (struct ifinfomsg *) NLMSG_DATA(m->hdr);
+                                struct ifinfomsg *ifi = NLMSG_DATA(m->hdr);
 
                                 m->next_rta = IFLA_RTA(ifi);
                                 m->remaining_size = IFLA_PAYLOAD(m->hdr);
@@ -280,7 +280,7 @@ int sd_rtnl_message_read(sd_rtnl_message *m, unsigned short *type, void **data)
                 case RTM_DELADDR:
                 case RTM_GETADDR:
                         if (!m->next_rta) {
-                                struct ifaddrmsg *ifa = (struct ifaddrmsg *) NLMSG_DATA(m->hdr);
+                                struct ifaddrmsg *ifa = NLMSG_DATA(m->hdr);
 
                                 m->next_rta = IFA_RTA(ifa);
                                 m->remaining_size = IFLA_PAYLOAD(m->hdr);
@@ -327,15 +327,15 @@ static int message_receive_need(sd_rtnl *rtnl, size_t *need) {
         assert_return(need, -EINVAL);
 
         /* ioctl(rtnl->fd, FIONREAD, &need)
-        Does not appear to work on netlink sockets. libnl uses
-        MSG_PEEK instead. I don't know if that is worth the
-        extra roundtrip.
-
-        For now we simply use the maximum message size the kernel
-        may use (NLMSG_GOODSIZE), and then realloc to the actual
-        size after reading the message (hence avoiding huge memory
-        usage in case many small messages are kept around) */
-        *need = getpagesize();
+           Does not appear to work on netlink sockets. libnl uses
+           MSG_PEEK instead. I don't know if that is worth the
+           extra roundtrip.
+
+           For now we simply use the maximum message size the kernel
+           may use (NLMSG_GOODSIZE), and then realloc to the actual
+           size after reading the message (hence avoiding huge memory
+           usage in case many small messages are kept around) */
+        *need = page_size();
         if (*need > 8192UL)
                 *need = 8192UL;
 
@@ -361,7 +361,7 @@ int socket_write_message(sd_rtnl *nl, sd_rtnl_message *m) {
  * which has a valid header and the correct size.
  * If nothing useful was received 0 is returned.
  * On failure, a negative error code is returned.
-*/
+ */
 int socket_read_message(sd_rtnl *nl, sd_rtnl_message **ret) {
         sd_rtnl_message *m;
         socklen_t addr_len = sizeof(nl->sockaddr);
@@ -400,12 +400,12 @@ int socket_read_message(sd_rtnl *nl, sd_rtnl_message **ret) {
         else if (nl->sockaddr.nl.nl_pid != 0)
                 k = 0; /* not from the kernel */
         else if ((size_t) k < sizeof(struct nlmsghdr) ||
-                 (size_t) k < m->hdr->nlmsg_len)
+                        (size_t) k < m->hdr->nlmsg_len)
                 k = -EIO; /* too small (we do accept too big though) */
         else if (m->hdr->nlmsg_type == NLMSG_NOOP)
                 k = 0;
         else if (m->hdr->nlmsg_type == NLMSG_ERROR &&
-                 m->hdr->nlmsg_len < NLMSG_LENGTH(sizeof(struct nlmsgerr)))
+                        m->hdr->nlmsg_len < NLMSG_LENGTH(sizeof(struct nlmsgerr)))
                 k = -EIO;
         else if ((pid_t) m->hdr->nlmsg_pid != getpid())
                 k = 0; /* not for us */
index abf45d0eed109b971e0c9c94700c6e693f666a56..9c4a218b83f1087eb0b58fbfc35f52c20da8ca43 100644 (file)
@@ -47,7 +47,7 @@ static int sd_rtnl_new(sd_rtnl **ret) {
         return 0;
 }
 
-int sd_rtnl_open(__u32 groups, sd_rtnl **ret) {
+int sd_rtnl_open(uint32_t groups, sd_rtnl **ret) {
         sd_rtnl *rtnl;
         int r;
 
@@ -94,9 +94,9 @@ sd_rtnl *sd_rtnl_unref(sd_rtnl *rtnl) {
 }
 
 int sd_rtnl_send_with_reply_and_block(sd_rtnl *nl,
-                                        sd_rtnl_message *message,
-                                        uint64_t usec,
-                                        sd_rtnl_message **ret) {
+                sd_rtnl_message *message,
+                uint64_t usec,
+                sd_rtnl_message **ret) {
         struct pollfd p[1] = {};
         sd_rtnl_message *reply;
         struct timespec left;
index 4079e9ec97c9d74aeed3bfa6b4cd8c65f18d8471..1cdd6e115d4daef164ec5d717400663949261c3f 100644 (file)
@@ -28,7 +28,7 @@
 
 static void test_link_configure(sd_rtnl *rtnl, int ifindex) {
         _cleanup_sd_rtnl_message_unref_ sd_rtnl_message *message;
-        __u16 type;
+        uint16_t type;
         const char *mac = "98:fe:94:3f:c6:18", *name = "test";
         unsigned int mtu = 1450;
         void *data;
@@ -60,7 +60,7 @@ int main(void) {
         sd_rtnl_message *r;
         void *data;
         int if_loopback;
-        __u16 type;
+        uint16_t type;
         unsigned int mtu = 0;
         unsigned int *mtu_reply;
 
index 5f5f3e3d2049b7f6cadafd7fa6bb1bc6b25c0f30..a2400d8485d55ba620c99ebcaa4b5d359ab7125c 100644 (file)
@@ -28,7 +28,7 @@ typedef struct sd_rtnl sd_rtnl;
 typedef struct sd_rtnl_message sd_rtnl_message;
 
 /* bus */
-int sd_rtnl_open(__u32 groups, sd_rtnl **nl);
+int sd_rtnl_open(uint32_t groups, sd_rtnl **nl);
 
 sd_rtnl *sd_rtnl_ref(sd_rtnl *nl);
 sd_rtnl *sd_rtnl_unref(sd_rtnl *nl);
@@ -36,12 +36,12 @@ sd_rtnl *sd_rtnl_unref(sd_rtnl *nl);
 int sd_rtnl_send_with_reply_and_block(sd_rtnl *nl, sd_rtnl_message *message, uint64_t timeout, sd_rtnl_message **reply);
 
 /* messages */
-int sd_rtnl_message_link_new(__u16 msg_type, int index, unsigned int type, unsigned int flags, sd_rtnl_message **ret);
-int sd_rtnl_message_addr_new(__u16 msg_type, int index, unsigned char family, unsigned char prefixlen, unsigned char flags, unsigned char scope, sd_rtnl_message **ret);
+int sd_rtnl_message_link_new(uint16_t msg_type, int index, unsigned int type, unsigned int flags, sd_rtnl_message **ret);
+int sd_rtnl_message_addr_new(uint16_t msg_type, int index, unsigned char family, unsigned char prefixlen, unsigned char flags, unsigned char scope, sd_rtnl_message **ret);
 sd_rtnl_message *sd_rtnl_message_ref(sd_rtnl_message *m);
 sd_rtnl_message *sd_rtnl_message_unref(sd_rtnl_message *m);
 
-int sd_rtnl_message_get_type(sd_rtnl_message *m, __u16 *type);
+int sd_rtnl_message_get_type(sd_rtnl_message *m, uint16_t *type);
 int sd_rtnl_message_append(sd_rtnl_message *m, unsigned short type, const void *data);
 int sd_rtnl_message_read(sd_rtnl_message *m, unsigned short *type, void **data);