chiark / gitweb /
sd-network: split the operstate 'unknown' into 'down' and 'up'
[elogind.git] / src / systemd / sd-rtnl.h
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 #ifndef foosdrtnlhfoo
4 #define foosdrtnlhfoo
5
6 /***
7   This file is part of systemd.
8
9   Copyright 2013 Tom Gundersen <teg@jklm.no>
10
11   systemd is free software; you can redistribute it and/or modify it
12   under the terms of the GNU Lesser General Public License as published by
13   the Free Software Foundation; either version 2.1 of the License, or
14   (at your option) any later version.
15
16   systemd is distributed in the hope that it will be useful, but
17   WITHOUT ANY WARRANTY; without even the implied warranty of
18   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19   Lesser General Public License for more details.
20
21   You should have received a copy of the GNU Lesser General Public License
22   along with systemd; If not, see <http://www.gnu.org/licenses/>.
23 ***/
24
25 #include <inttypes.h>
26 #include <netinet/in.h>
27 #include <netinet/ether.h>
28 #include <linux/rtnetlink.h>
29
30 #include "sd-event.h"
31 #include "_sd-common.h"
32
33 _SD_BEGIN_DECLARATIONS;
34
35 typedef struct sd_rtnl sd_rtnl;
36 typedef struct sd_rtnl_message sd_rtnl_message;
37
38 /* callback */
39
40 typedef int (*sd_rtnl_message_handler_t)(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata);
41
42 /* bus */
43 int sd_rtnl_open(sd_rtnl **nl, unsigned n_groups, ...);
44
45 sd_rtnl *sd_rtnl_ref(sd_rtnl *nl);
46 sd_rtnl *sd_rtnl_unref(sd_rtnl *nl);
47
48 int sd_rtnl_send(sd_rtnl *nl, sd_rtnl_message *message, uint32_t *serial);
49 int sd_rtnl_call_async(sd_rtnl *nl, sd_rtnl_message *message,
50                        sd_rtnl_message_handler_t callback,
51                        void *userdata, uint64_t usec, uint32_t *serial);
52 int sd_rtnl_call_async_cancel(sd_rtnl *nl, uint32_t serial);
53 int sd_rtnl_call(sd_rtnl *nl, sd_rtnl_message *message, uint64_t timeout,
54                  sd_rtnl_message **reply);
55
56
57 int sd_rtnl_get_events(sd_rtnl *nl);
58 int sd_rtnl_get_timeout(sd_rtnl *nl, uint64_t *timeout);
59 int sd_rtnl_process(sd_rtnl *nl, sd_rtnl_message **ret);
60 int sd_rtnl_wait(sd_rtnl *nl, uint64_t timeout);
61 int sd_rtnl_flush(sd_rtnl *nl);
62
63 int sd_rtnl_add_match(sd_rtnl *nl, uint16_t match, sd_rtnl_message_handler_t c, void *userdata);
64 int sd_rtnl_remove_match(sd_rtnl *nl, uint16_t match, sd_rtnl_message_handler_t c, void *userdata);
65
66 int sd_rtnl_attach_event(sd_rtnl *nl, sd_event *e, int priority);
67 int sd_rtnl_detach_event(sd_rtnl *nl);
68
69 /* messages */
70 int sd_rtnl_message_new_link(sd_rtnl *rtnl, sd_rtnl_message **ret, uint16_t msg_type, int index);
71 int sd_rtnl_message_new_addr_update(sd_rtnl *rtnl, sd_rtnl_message **ret, int index, int family);
72 int sd_rtnl_message_new_addr(sd_rtnl *rtnl, sd_rtnl_message **ret, uint16_t msg_type, int index,
73                              int family);
74 int sd_rtnl_message_new_route(sd_rtnl *rtnl, sd_rtnl_message **ret, uint16_t nlmsg_type,
75                               int rtm_family, unsigned char rtm_protocol);
76
77 sd_rtnl_message *sd_rtnl_message_ref(sd_rtnl_message *m);
78 sd_rtnl_message *sd_rtnl_message_unref(sd_rtnl_message *m);
79
80 int sd_rtnl_message_request_dump(sd_rtnl_message *m, int dump);
81 int sd_rtnl_message_get_errno(sd_rtnl_message *m);
82 int sd_rtnl_message_get_type(sd_rtnl_message *m, uint16_t *type);
83 int sd_rtnl_message_is_broadcast(sd_rtnl_message *m);
84
85 int sd_rtnl_message_addr_set_prefixlen(sd_rtnl_message *m, unsigned char prefixlen);
86 int sd_rtnl_message_addr_set_scope(sd_rtnl_message *m, unsigned char scope);
87 int sd_rtnl_message_addr_set_flags(sd_rtnl_message *m, unsigned char flags);
88 int sd_rtnl_message_addr_get_family(sd_rtnl_message *m, int *family);
89 int sd_rtnl_message_addr_get_prefixlen(sd_rtnl_message *m, unsigned char *prefixlen);
90 int sd_rtnl_message_addr_get_scope(sd_rtnl_message *m, unsigned char *scope);
91 int sd_rtnl_message_addr_get_flags(sd_rtnl_message *m, unsigned char *flags);
92 int sd_rtnl_message_addr_get_ifindex(sd_rtnl_message *m, int *ifindex);
93
94 int sd_rtnl_message_link_set_flags(sd_rtnl_message *m, unsigned flags, unsigned change);
95 int sd_rtnl_message_link_set_type(sd_rtnl_message *m, unsigned type);
96 int sd_rtnl_message_link_get_ifindex(sd_rtnl_message *m, int *ifindex);
97 int sd_rtnl_message_link_get_flags(sd_rtnl_message *m, unsigned *flags);
98 int sd_rtnl_message_link_get_type(sd_rtnl_message *m, unsigned *type);
99
100 int sd_rtnl_message_route_set_dst_prefixlen(sd_rtnl_message *m, unsigned char prefixlen);
101 int sd_rtnl_message_route_set_scope(sd_rtnl_message *m, unsigned char scope);
102
103 int sd_rtnl_message_append_string(sd_rtnl_message *m, unsigned short type, const char *data);
104 int sd_rtnl_message_append_u8(sd_rtnl_message *m, unsigned short type, uint8_t data);
105 int sd_rtnl_message_append_u16(sd_rtnl_message *m, unsigned short type, uint16_t data);
106 int sd_rtnl_message_append_u32(sd_rtnl_message *m, unsigned short type, uint32_t data);
107 int sd_rtnl_message_append_in_addr(sd_rtnl_message *m, unsigned short type, const struct in_addr *data);
108 int sd_rtnl_message_append_in6_addr(sd_rtnl_message *m, unsigned short type, const struct in6_addr *data);
109 int sd_rtnl_message_append_ether_addr(sd_rtnl_message *m, unsigned short type, const struct ether_addr *data);
110 int sd_rtnl_message_append_cache_info(sd_rtnl_message *m, unsigned short type, const struct ifa_cacheinfo *info);
111
112 int sd_rtnl_message_open_container(sd_rtnl_message *m, unsigned short type);
113 int sd_rtnl_message_open_container_union(sd_rtnl_message *m, unsigned short type, const char *key);
114 int sd_rtnl_message_close_container(sd_rtnl_message *m);
115
116 int sd_rtnl_message_read_string(sd_rtnl_message *m, unsigned short type, const char **data);
117 int sd_rtnl_message_read_u8(sd_rtnl_message *m, unsigned short type, uint8_t *data);
118 int sd_rtnl_message_read_u16(sd_rtnl_message *m, unsigned short type, uint16_t *data);
119 int sd_rtnl_message_read_u32(sd_rtnl_message *m, unsigned short type, uint32_t *data);
120 int sd_rtnl_message_read_ether_addr(sd_rtnl_message *m, unsigned short type, struct ether_addr *data);
121 int sd_rtnl_message_read_cache_info(sd_rtnl_message *m, unsigned short type, struct ifa_cacheinfo *info);
122 int sd_rtnl_message_read_in_addr(sd_rtnl_message *m, unsigned short type, struct in_addr *data);
123 int sd_rtnl_message_read_in6_addr(sd_rtnl_message *m, unsigned short type, struct in6_addr *data);
124 int sd_rtnl_message_enter_container(sd_rtnl_message *m, unsigned short type);
125 int sd_rtnl_message_exit_container(sd_rtnl_message *m);
126
127 int sd_rtnl_message_rewind(sd_rtnl_message *m);
128
129 sd_rtnl_message *sd_rtnl_message_next(sd_rtnl_message *m);
130
131 _SD_END_DECLARATIONS;
132
133 #endif