1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
6 This file is part of systemd.
8 Copyright 2013 Tom Gundersen <teg@jklm.no>
10 systemd is free software; you can redistribute it and/or modify it
11 under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
15 systemd is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
20 You should have received a copy of the GNU Lesser General Public License
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
24 #include <linux/netlink.h>
32 #define RTNL_DEFAULT_TIMEOUT ((usec_t) (10 * USEC_PER_SEC))
34 #define RTNL_WQUEUE_MAX 1024
35 #define RTNL_RQUEUE_MAX 64*1024
37 #define RTNL_CONTAINER_DEPTH 32
39 struct reply_callback {
40 sd_rtnl_message_handler_t callback;
47 struct match_callback {
48 sd_rtnl_message_handler_t callback;
52 LIST_FIELDS(struct match_callback, match_callbacks);
62 struct sockaddr_nl nl;
65 sd_rtnl_message **rqueue;
68 sd_rtnl_message **wqueue;
75 struct Prioq *reply_callbacks_prioq;
76 Hashmap *reply_callbacks;
78 LIST_HEAD(struct match_callback, match_callbacks);
82 sd_event_source *io_event_source;
83 sd_event_source *time_event_source;
84 sd_event_source *exit_event_source;
88 struct sd_rtnl_message {
94 size_t container_offsets[RTNL_CONTAINER_DEPTH]; /* offset from hdr to each container's start */
95 unsigned n_containers; /* number of containers */
96 size_t next_rta_offset; /* offset from hdr to next rta */
101 int message_new(sd_rtnl *rtnl, sd_rtnl_message **ret, size_t initial_size);
103 int socket_write_message(sd_rtnl *nl, sd_rtnl_message *m);
104 int socket_read_message(sd_rtnl *nl, sd_rtnl_message **ret);
106 /* Make sure callbacks don't destroy the rtnl connection */
107 #define RTNL_DONT_DESTROY(rtnl) \
108 _cleanup_rtnl_unref_ _unused_ sd_rtnl *_dont_destroy_##rtnl = sd_rtnl_ref(rtnl)