]>
Commit | Line | Data |
---|---|---|
65f568bb TG |
1 | /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ |
2 | ||
a2cdd907 LP |
3 | #pragma once |
4 | ||
65f568bb TG |
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 | ||
a33dece5 LP |
24 | #include <linux/netlink.h> |
25 | ||
65f568bb | 26 | #include "refcnt.h" |
e16bcf98 | 27 | #include "prioq.h" |
8cec01b9 | 28 | #include "list.h" |
e16bcf98 TG |
29 | |
30 | #include "sd-rtnl.h" | |
31 | ||
59a7a684 | 32 | #define RTNL_DEFAULT_TIMEOUT ((usec_t) (25 * USEC_PER_SEC)) |
3815f36f TG |
33 | |
34 | #define RTNL_WQUEUE_MAX 1024 | |
35 | #define RTNL_RQUEUE_MAX 64*1024 | |
36 | ||
37 | #define RTNL_CONTAINER_DEPTH 32 | |
38 | ||
e16bcf98 TG |
39 | struct reply_callback { |
40 | sd_rtnl_message_handler_t callback; | |
41 | void *userdata; | |
42 | usec_t timeout; | |
43 | uint64_t serial; | |
44 | unsigned prioq_idx; | |
45 | }; | |
65f568bb | 46 | |
8cec01b9 TG |
47 | struct match_callback { |
48 | sd_rtnl_message_handler_t callback; | |
23a7f0f7 | 49 | uint16_t type; |
8cec01b9 TG |
50 | void *userdata; |
51 | ||
52 | LIST_FIELDS(struct match_callback, match_callbacks); | |
53 | }; | |
54 | ||
65f568bb TG |
55 | struct sd_rtnl { |
56 | RefCount n_ref; | |
57 | ||
58 | int fd; | |
59 | ||
60 | union { | |
61 | struct sockaddr sa; | |
62 | struct sockaddr_nl nl; | |
63 | } sockaddr; | |
64 | ||
4555ec72 TG |
65 | sd_rtnl_message **rqueue; |
66 | unsigned rqueue_size; | |
67 | ||
68 | sd_rtnl_message **wqueue; | |
69 | unsigned wqueue_size; | |
70 | ||
71 | bool processing:1; | |
72 | ||
d4bbdb77 TG |
73 | uint32_t serial; |
74 | ||
e16bcf98 TG |
75 | struct Prioq *reply_callbacks_prioq; |
76 | Hashmap *reply_callbacks; | |
77 | ||
8cec01b9 TG |
78 | LIST_HEAD(struct match_callback, match_callbacks); |
79 | ||
adf412b9 | 80 | pid_t original_pid; |
b4f2a5b1 TG |
81 | |
82 | sd_event_source *io_event_source; | |
83 | sd_event_source *time_event_source; | |
6203e07a | 84 | sd_event_source *exit_event_source; |
b4f2a5b1 | 85 | sd_event *event; |
65f568bb | 86 | }; |
98dd77e8 | 87 | |
3815f36f TG |
88 | struct sd_rtnl_message { |
89 | RefCount n_ref; | |
4555ec72 | 90 | |
4fb7242c TG |
91 | sd_rtnl *rtnl; |
92 | ||
3815f36f TG |
93 | struct nlmsghdr *hdr; |
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 */ | |
3dd215e0 TG |
97 | size_t *rta_offset_tb[RTNL_CONTAINER_DEPTH]; |
98 | unsigned short rta_tb_size[RTNL_CONTAINER_DEPTH]; | |
3815f36f TG |
99 | bool sealed:1; |
100 | }; | |
9d0db178 | 101 | |
4fb7242c | 102 | int message_new(sd_rtnl *rtnl, sd_rtnl_message **ret, size_t initial_size); |
9d0db178 | 103 | |
65f568bb TG |
104 | int socket_write_message(sd_rtnl *nl, sd_rtnl_message *m); |
105 | int socket_read_message(sd_rtnl *nl, sd_rtnl_message **ret); | |
e16bcf98 | 106 | |
44caa5e7 SS |
107 | int rtnl_message_read_internal(sd_rtnl_message *m, unsigned short type, void **data); |
108 | int rtnl_message_parse(sd_rtnl_message *m, | |
109 | size_t **rta_offset_tb, | |
110 | unsigned short *rta_tb_size, | |
111 | int max, | |
112 | struct rtattr *rta, | |
113 | unsigned int rt_len); | |
114 | ||
e16bcf98 TG |
115 | /* Make sure callbacks don't destroy the rtnl connection */ |
116 | #define RTNL_DONT_DESTROY(rtnl) \ | |
cf6a8911 | 117 | _cleanup_rtnl_unref_ _unused_ sd_rtnl *_dont_destroy_##rtnl = sd_rtnl_ref(rtnl) |