chiark / gitweb /
libsystemd-dhcp: merge into libsystemd
[elogind.git] / src / libsystemd-rtnl / rtnl-internal.h
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 #pragma once
4
5 /***
6   This file is part of systemd.
7
8   Copyright 2013 Tom Gundersen <teg@jklm.no>
9
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.
14
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.
19
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/>.
22 ***/
23
24 #include <linux/netlink.h>
25
26 #include "refcnt.h"
27 #include "prioq.h"
28 #include "list.h"
29
30 #include "sd-rtnl.h"
31
32 struct reply_callback {
33         sd_rtnl_message_handler_t callback;
34         void *userdata;
35         usec_t timeout;
36         uint64_t serial;
37         unsigned prioq_idx;
38 };
39
40 struct match_callback {
41         sd_rtnl_message_handler_t callback;
42         uint16_t type;
43         void *userdata;
44
45         LIST_FIELDS(struct match_callback, match_callbacks);
46 };
47
48 struct sd_rtnl {
49         RefCount n_ref;
50
51         int fd;
52
53         union {
54                 struct sockaddr sa;
55                 struct sockaddr_nl nl;
56         } sockaddr;
57
58         sd_rtnl_message **rqueue;
59         unsigned rqueue_size;
60
61         sd_rtnl_message **wqueue;
62         unsigned wqueue_size;
63
64         bool processing:1;
65
66         uint32_t serial;
67
68         struct Prioq *reply_callbacks_prioq;
69         Hashmap *reply_callbacks;
70
71         LIST_HEAD(struct match_callback, match_callbacks);
72
73         pid_t original_pid;
74
75         sd_event_source *io_event_source;
76         sd_event_source *time_event_source;
77         sd_event_source *exit_event_source;
78         sd_event *event;
79 };
80
81 #define RTNL_DEFAULT_TIMEOUT ((usec_t) (10 * USEC_PER_SEC))
82
83 #define RTNL_WQUEUE_MAX 1024
84 #define RTNL_RQUEUE_MAX 64*1024
85
86 int message_new_synthetic_error(int error, uint32_t serial, sd_rtnl_message **ret);
87 uint32_t message_get_serial(sd_rtnl_message *m);
88 int message_seal(sd_rtnl *nl, sd_rtnl_message *m);
89
90 bool message_type_is_link(uint16_t type);
91 bool message_type_is_addr(uint16_t type);
92 bool message_type_is_route(uint16_t type);
93
94 int socket_write_message(sd_rtnl *nl, sd_rtnl_message *m);
95 int socket_read_message(sd_rtnl *nl, sd_rtnl_message **ret);
96
97 /* Make sure callbacks don't destroy the rtnl connection */
98 #define RTNL_DONT_DESTROY(rtnl) \
99         _cleanup_sd_rtnl_unref_ _unused_ sd_rtnl *_dont_destroy_##rtnl = sd_rtnl_ref(rtnl)