chiark / gitweb /
b23712011e510da733406b21fc85d55d106e7084
[elogind.git] / src / network / networkd-link.h
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 /***
4   This file is part of systemd.
5
6   Copyright 2013 Tom Gundersen <teg@jklm.no>
7
8   systemd is free software; you can redistribute it and/or modify it
9   under the terms of the GNU Lesser General Public License as published by
10   the Free Software Foundation; either version 2.1 of the License, or
11   (at your option) any later version.
12
13   systemd is distributed in the hope that it will be useful, but
14   WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16   Lesser General Public License for more details.
17
18   You should have received a copy of the GNU Lesser General Public License
19   along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 ***/
21
22 #pragma once
23
24 #include "networkd.h"
25
26 typedef enum LinkState {
27         LINK_STATE_PENDING,
28         LINK_STATE_ENSLAVING,
29         LINK_STATE_SETTING_ADDRESSES,
30         LINK_STATE_SETTING_ROUTES,
31         LINK_STATE_CONFIGURED,
32         LINK_STATE_UNMANAGED,
33         LINK_STATE_FAILED,
34         LINK_STATE_LINGER,
35         _LINK_STATE_MAX,
36         _LINK_STATE_INVALID = -1
37 } LinkState;
38
39 struct Link {
40         Manager *manager;
41
42         int n_ref;
43
44         int ifindex;
45         char *ifname;
46         char *state_file;
47         struct ether_addr mac;
48         uint32_t mtu;
49         struct udev_device *udev_device;
50
51         unsigned flags;
52         uint8_t kernel_operstate;
53
54         Network *network;
55
56         LinkState state;
57         LinkOperationalState operstate;
58
59         unsigned link_messages;
60         unsigned enslaving;
61
62         LIST_HEAD(Address, addresses);
63
64         sd_dhcp_client *dhcp_client;
65         sd_dhcp_lease *dhcp_lease;
66         char *lease_file;
67         uint16_t original_mtu;
68         unsigned dhcp4_messages;
69         bool dhcp4_configured;
70
71         sd_ipv4ll *ipv4ll;
72         bool ipv4ll_address;
73         bool ipv4ll_route;
74
75         bool static_configured;
76
77         LIST_HEAD(Address, pool_addresses);
78
79         sd_dhcp_server *dhcp_server;
80
81         sd_icmp6_nd *icmp6_router_discovery;
82         sd_dhcp6_client *dhcp6_client;
83
84         sd_lldp *lldp;
85         char *lldp_file;
86 };
87
88 Link *link_unref(Link *link);
89 Link *link_ref(Link *link);
90 int link_get(Manager *m, int ifindex, Link **ret);
91 int link_add(Manager *manager, sd_rtnl_message *message, Link **ret);
92 void link_drop(Link *link);
93
94 int link_address_drop_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata);
95 int link_route_drop_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata);
96
97 void link_enter_failed(Link *link);
98 int link_initialized(Link *link, struct udev_device *device);
99
100 void link_client_handler(Link *link);
101
102 int link_update(Link *link, sd_rtnl_message *message);
103 int link_rtnl_process_address(sd_rtnl *rtnl, sd_rtnl_message *message, void *userdata);
104
105 int link_save(Link *link);
106
107 int link_carrier_reset(Link *link);
108 bool link_has_carrier(Link *link);
109
110 int link_set_mtu(Link *link, uint32_t mtu);
111 int link_set_hostname(Link *link, const char *hostname);
112
113 int ipv4ll_configure(Link *link);
114 int dhcp4_configure(Link *link);
115 int icmp6_configure(Link *link);
116
117 const char* link_state_to_string(LinkState s) _const_;
118 LinkState link_state_from_string(const char *s) _pure_;
119
120 extern const sd_bus_vtable link_vtable[];
121
122 int link_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error);
123 int link_object_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error);
124 int link_send_changed(Link *link, const char *property, ...) _sentinel_;
125
126 DEFINE_TRIVIAL_CLEANUP_FUNC(Link*, link_unref);
127 #define _cleanup_link_unref_ _cleanup_(link_unrefp)
128
129 /* Macros which append INTERFACE= to the message */
130
131 #define log_link_full(link, level, error, fmt, ...) \
132         log_object_internal(level, error, __FILE__, __LINE__, __func__, "INTERFACE=", link->ifname, "%-*s: " fmt, IFNAMSIZ, link->ifname, ##__VA_ARGS__)
133
134 #define log_link_debug(link, ...)       log_link_full(link, LOG_DEBUG, 0, ##__VA_ARGS__)
135 #define log_link_info(link, ...)        log_link_full(link, LOG_INFO, 0, ##__VA_ARGS__)
136 #define log_link_notice(link, ...)      log_link_full(link, LOG_NOTICE, 0, ##__VA_ARGS__)
137 #define log_link_warning(link, ...)     log_link_full(link, LOG_WARNING, 0, ##__VA_ARGS__)
138 #define log_link_error(link, ...)       log_link_full(link, LOG_ERR, 0, ##__VA_ARGS__)
139
140 #define log_link_debug_errno(link, error, ...)   log_link_full(link, LOG_DEBUG, error, ##__VA_ARGS__)
141 #define log_link_info_errno(link, error, ...)    log_link_full(link, LOG_INFO, error, ##__VA_ARGS__)
142 #define log_link_notice_errno(link, error, ...)  log_link_full(link, LOG_NOTICE, error, ##__VA_ARGS__)
143 #define log_link_warning_errno(link, error, ...) log_link_full(link, LOG_WARNING, error, ##__VA_ARGS__)
144 #define log_link_error_errno(link, error, ...)   log_link_full(link, LOG_ERR, error, ##__VA_ARGS__)
145
146 #define log_link_struct(link, level, ...) log_struct(level, "INTERFACE=%s", link->ifname, __VA_ARGS__)
147
148 #define ADDRESS_FMT_VAL(address)            \
149         (address).s_addr & 0xFF,            \
150         ((address).s_addr >> 8) & 0xFF,     \
151         ((address).s_addr >> 16) & 0xFF,    \
152         (address).s_addr >> 24