chiark / gitweb /
9f54c8c391ba0c3ed3c8a42d00283b12176a6cbc
[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_INITIALIZING,
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 typedef enum LinkOperationalState {
40         LINK_OPERSTATE_UNKNOWN,
41         LINK_OPERSTATE_DORMANT,
42         LINK_OPERSTATE_CARRIER,
43         LINK_OPERSTATE_DEGRADED,
44         LINK_OPERSTATE_ROUTABLE,
45         _LINK_OPERSTATE_MAX,
46         _LINK_OPERSTATE_INVALID = -1
47 } LinkOperationalState;
48
49 struct Link {
50         Manager *manager;
51
52         int n_ref;
53
54         int ifindex;
55         char *ifname;
56         char *state_file;
57         struct ether_addr mac;
58         uint32_t mtu;
59         struct udev_device *udev_device;
60
61         unsigned flags;
62         uint8_t kernel_operstate;
63
64         Network *network;
65
66         LinkState state;
67         LinkOperationalState operstate;
68
69         unsigned addr_messages;
70         unsigned route_messages;
71         unsigned enslaving;
72
73         LIST_HEAD(Address, addresses);
74
75         sd_dhcp_client *dhcp_client;
76         sd_dhcp_lease *dhcp_lease;
77         char *lease_file;
78         uint16_t original_mtu;
79         sd_ipv4ll *ipv4ll;
80
81         LIST_HEAD(Address, pool_addresses);
82
83         sd_dhcp_server *dhcp_server;
84
85         sd_icmp6_nd *icmp6_router_discovery;
86         sd_dhcp6_client *dhcp6_client;
87 };
88
89 Link *link_unref(Link *link);
90 Link *link_ref(Link *link);
91 int link_get(Manager *m, int ifindex, Link **ret);
92 int link_add(Manager *manager, sd_rtnl_message *message, Link **ret);
93 void link_drop(Link *link);
94
95 int link_update(Link *link, sd_rtnl_message *message);
96 int link_rtnl_process_address(sd_rtnl *rtnl, sd_rtnl_message *message, void *userdata);
97
98 int link_initialized(Link *link, struct udev_device *device);
99
100 int link_save(Link *link);
101
102 bool link_has_carrier(unsigned flags, uint8_t operstate);
103
104 const char* link_state_to_string(LinkState s) _const_;
105 LinkState link_state_from_string(const char *s) _pure_;
106
107 const char* link_operstate_to_string(LinkOperationalState s) _const_;
108 LinkOperationalState link_operstate_from_string(const char *s) _pure_;
109
110 DEFINE_TRIVIAL_CLEANUP_FUNC(Link*, link_unref);
111 #define _cleanup_link_unref_ _cleanup_(link_unrefp)
112
113 /* Macros which append INTERFACE= to the message */
114
115 #define log_full_link(level, link, fmt, ...) log_meta_object(level, __FILE__, __LINE__, __func__, "INTERFACE=", link->ifname, "%-*s: " fmt, IFNAMSIZ, link->ifname, ##__VA_ARGS__)
116 #define log_debug_link(link, ...)       log_full_link(LOG_DEBUG, link, ##__VA_ARGS__)
117 #define log_info_link(link, ...)        log_full_link(LOG_INFO, link, ##__VA_ARGS__)
118 #define log_notice_link(link, ...)      log_full_link(LOG_NOTICE, link, ##__VA_ARGS__)
119 #define log_warning_link(link, ...)     log_full_link(LOG_WARNING, link, ##__VA_ARGS__)
120 #define log_error_link(link, ...)       log_full_link(LOG_ERR, link, ##__VA_ARGS__)
121
122 #define log_struct_link(level, link, ...) log_struct(level, "INTERFACE=%s", link->ifname, __VA_ARGS__)
123
124 #define ADDRESS_FMT_VAL(address)            \
125         (address).s_addr & 0xFF,            \
126         ((address).s_addr >> 8) & 0xFF,     \
127         ((address).s_addr >> 16) & 0xFF,    \
128         (address).s_addr >> 24