chiark / gitweb /
sd-rtnl: multi-part message - store as linked-list rather than independent messages
[elogind.git] / src / libsystemd / sd-rtnl / rtnl-internal.h
index 5dc66ac9d6f7eadbeb0798a54847b31ef1780c90..2f788d04f6cd08c2402ba0a9d0aa1d5073d45d41 100644 (file)
 
 #include "sd-rtnl.h"
 
+#include "rtnl-types.h"
+
+#define RTNL_DEFAULT_TIMEOUT ((usec_t) (25 * USEC_PER_SEC))
+
+#define RTNL_WQUEUE_MAX 1024
+#define RTNL_RQUEUE_MAX 64*1024
+
+#define RTNL_CONTAINER_DEPTH 32
+
 struct reply_callback {
         sd_rtnl_message_handler_t callback;
         void *userdata;
@@ -57,9 +66,11 @@ struct sd_rtnl {
 
         sd_rtnl_message **rqueue;
         unsigned rqueue_size;
+        size_t rqueue_allocated;
 
         sd_rtnl_message **wqueue;
         unsigned wqueue_size;
+        size_t wqueue_allocated;
 
         bool processing:1;
 
@@ -78,24 +89,38 @@ struct sd_rtnl {
         sd_event *event;
 };
 
-#define RTNL_DEFAULT_TIMEOUT ((usec_t) (10 * USEC_PER_SEC))
+struct sd_rtnl_message {
+        RefCount n_ref;
 
-#define RTNL_WQUEUE_MAX 1024
-#define RTNL_RQUEUE_MAX 64*1024
+        sd_rtnl *rtnl;
 
-#define RTNL_CONTAINER_DEPTH 32
+        struct nlmsghdr *hdr;
+        const struct NLTypeSystem *(container_type_system[RTNL_CONTAINER_DEPTH]); /* the type of the container and all its parents */
+        size_t container_offsets[RTNL_CONTAINER_DEPTH]; /* offset from hdr to each container's start */
+        unsigned n_containers; /* number of containers */
+        size_t next_rta_offset; /* offset from hdr to next rta */
+        size_t *rta_offset_tb[RTNL_CONTAINER_DEPTH];
+        unsigned short rta_tb_size[RTNL_CONTAINER_DEPTH];
+        bool sealed:1;
 
-int message_new_synthetic_error(int error, uint32_t serial, sd_rtnl_message **ret);
-uint32_t message_get_serial(sd_rtnl_message *m);
-int message_seal(sd_rtnl *nl, sd_rtnl_message *m);
+        sd_rtnl_message *next; /* next in a chain of multi-part messages */
+};
 
-bool message_type_is_link(uint16_t type);
-bool message_type_is_addr(uint16_t type);
-bool message_type_is_route(uint16_t type);
+int message_new(sd_rtnl *rtnl, sd_rtnl_message **ret, uint16_t type);
 
 int socket_write_message(sd_rtnl *nl, sd_rtnl_message *m);
-int socket_read_message(sd_rtnl *nl, sd_rtnl_message **ret);
+int socket_read_message(sd_rtnl *nl);
+
+int rtnl_rqueue_make_room(sd_rtnl *rtnl);
+
+int rtnl_message_read_internal(sd_rtnl_message *m, unsigned short type, void **data);
+int rtnl_message_parse(sd_rtnl_message *m,
+                       size_t **rta_offset_tb,
+                       unsigned short *rta_tb_size,
+                       int max,
+                       struct rtattr *rta,
+                       unsigned int rt_len);
 
 /* Make sure callbacks don't destroy the rtnl connection */
 #define RTNL_DONT_DESTROY(rtnl) \
-        _cleanup_sd_rtnl_unref_ _unused_ sd_rtnl *_dont_destroy_##rtnl = sd_rtnl_ref(rtnl)
+        _cleanup_rtnl_unref_ _unused_ sd_rtnl *_dont_destroy_##rtnl = sd_rtnl_ref(rtnl)