]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/network/networkd-link.h
networkd: link - split out dhcp4 handling
[thirdparty/systemd.git] / src / network / networkd-link.h
CommitLineData
0b1831c2
TG
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
26typedef 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
39typedef 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
49struct 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
3c9b8860 69 unsigned link_messages;
0b1831c2
TG
70 unsigned enslaving;
71
72 LIST_HEAD(Address, addresses);
73
74 sd_dhcp_client *dhcp_client;
75 sd_dhcp_lease *dhcp_lease;
76 char *lease_file;
77 uint16_t original_mtu;
3c9b8860
TG
78 unsigned dhcp4_messages;
79 bool dhcp4_configured;
b22d8a00 80
0b1831c2 81 sd_ipv4ll *ipv4ll;
b22d8a00
TG
82 bool ipv4ll_address;
83 bool ipv4ll_route;
0b1831c2 84
3c9b8860
TG
85 bool static_configured;
86
0b1831c2
TG
87 LIST_HEAD(Address, pool_addresses);
88
89 sd_dhcp_server *dhcp_server;
90
91 sd_icmp6_nd *icmp6_router_discovery;
92 sd_dhcp6_client *dhcp6_client;
93};
94
95Link *link_unref(Link *link);
96Link *link_ref(Link *link);
97int link_get(Manager *m, int ifindex, Link **ret);
98int link_add(Manager *manager, sd_rtnl_message *message, Link **ret);
99void link_drop(Link *link);
100
b22d8a00
TG
101int link_get_address_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata);
102int link_address_drop_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata);
103int link_route_drop_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata);
0b1831c2 104
b22d8a00 105void link_enter_failed(Link *link);
0b1831c2
TG
106int link_initialized(Link *link, struct udev_device *device);
107
b22d8a00
TG
108void link_client_handler(Link *link);
109
110int link_update(Link *link, sd_rtnl_message *message);
111int link_rtnl_process_address(sd_rtnl *rtnl, sd_rtnl_message *message, void *userdata);
112
0b1831c2
TG
113int link_save(Link *link);
114
115bool link_has_carrier(unsigned flags, uint8_t operstate);
116
3c9b8860
TG
117int link_set_mtu(Link *link, uint32_t mtu);
118int link_set_hostname(Link *link, const char *hostname);
119
b22d8a00 120int ipv4ll_configure(Link *link);
3c9b8860 121int dhcp4_configure(Link *link);
b22d8a00 122
0b1831c2
TG
123const char* link_state_to_string(LinkState s) _const_;
124LinkState link_state_from_string(const char *s) _pure_;
125
126const char* link_operstate_to_string(LinkOperationalState s) _const_;
127LinkOperationalState link_operstate_from_string(const char *s) _pure_;
128
129DEFINE_TRIVIAL_CLEANUP_FUNC(Link*, link_unref);
130#define _cleanup_link_unref_ _cleanup_(link_unrefp)
131
132/* Macros which append INTERFACE= to the message */
133
134#define log_full_link(level, link, fmt, ...) log_meta_object(level, __FILE__, __LINE__, __func__, "INTERFACE=", link->ifname, "%-*s: " fmt, IFNAMSIZ, link->ifname, ##__VA_ARGS__)
135#define log_debug_link(link, ...) log_full_link(LOG_DEBUG, link, ##__VA_ARGS__)
136#define log_info_link(link, ...) log_full_link(LOG_INFO, link, ##__VA_ARGS__)
137#define log_notice_link(link, ...) log_full_link(LOG_NOTICE, link, ##__VA_ARGS__)
138#define log_warning_link(link, ...) log_full_link(LOG_WARNING, link, ##__VA_ARGS__)
139#define log_error_link(link, ...) log_full_link(LOG_ERR, link, ##__VA_ARGS__)
140
141#define log_struct_link(level, link, ...) log_struct(level, "INTERFACE=%s", link->ifname, __VA_ARGS__)
142
143#define ADDRESS_FMT_VAL(address) \
144 (address).s_addr & 0xFF, \
145 ((address).s_addr >> 8) & 0xFF, \
146 ((address).s_addr >> 16) & 0xFF, \
147 (address).s_addr >> 24