Debian Codegraph @

src/libsystemd-network/dhcp-client-internal.h

raw
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 #include "sd-dhcp-client.h"
5
6 #include "dhcp-client-id-internal.h"
7 #include "dhcp-forward.h"
8 #include "dhcp-protocol.h"
9 #include "ether-addr-util.h"
10 #include "iovec-wrapper.h"
11 #include "network-common.h"
12
13 struct sd_dhcp_client {
14 unsigned n_ref;
15
16 int socket_fd; /* socket fd set externally, used by unit tests */
17
18 DHCPState state;
19 sd_event *event;
20 int event_priority;
21 sd_event_source *timeout_resend;
22
23 int ifindex;
24 char *ifname;
25
26 sd_device *dev;
27
28 uint16_t port;
29 uint16_t server_port;
30 sd_event_source *receive_message;
31 bool request_broadcast;
32 Set *req_opts;
33 bool anonymize;
34 bool rapid_commit;
35 be32_t last_addr;
36 struct hw_addr_data hw_addr;
37 struct hw_addr_data bcast_addr;
38 uint16_t arp_type;
39 sd_dhcp_client_id client_id;
40 char *hostname;
41 char *vendor_class_identifier;
42 char *mudurl;
43 struct iovec_wrapper user_class;
44 uint32_t mtu;
45 usec_t fallback_lease_lifetime;
46 uint32_t xid;
47 usec_t start_time;
48 usec_t t1_time;
49 usec_t t2_time;
50 usec_t expire_time;
51 uint64_t discover_attempt;
52 uint64_t request_attempt;
53 uint64_t max_discover_attempts;
54 TLV *extra_options;
55 TLV *vendor_options;
56 sd_event_source *timeout_t1;
57 sd_event_source *timeout_t2;
58 sd_event_source *timeout_expire;
59 sd_dhcp_client_callback_t callback;
60 void *userdata;
61 sd_dhcp_client_callback_t state_callback;
62 void *state_userdata;
63 sd_dhcp_lease *lease;
64 usec_t start_delay;
65 uint8_t ip_service_type;
66 int socket_priority;
67 bool ipv6_acquired;
68 bool bootp;
69 bool send_release;
70 };
71
72 int dhcp_client_set_state_callback(
73 sd_dhcp_client *client,
74 sd_dhcp_client_callback_t cb,
75 void *userdata);
76 int dhcp_client_get_state(sd_dhcp_client *client);
77
78 int dhcp_client_set_extra_options(sd_dhcp_client *client, TLV *options);
79 int dhcp_client_set_vendor_options(sd_dhcp_client *client, TLV *options);
80 int dhcp_client_set_user_class(sd_dhcp_client *client, const struct iovec_wrapper *user_class);
81
82 int client_receive_message_raw(
83 sd_event_source *s,
84 int fd,
85 uint32_t revents,
86 void *userdata);
87 int client_receive_message_udp(
88 sd_event_source *s,
89 int fd,
90 uint32_t revents,
91 void *userdata);
92
93 /* If we are invoking callbacks of a dhcp-client, ensure unreffing the
94 * client from the callback doesn't destroy the object we are working
95 * on */
96 #define DHCP_CLIENT_DONT_DESTROY(client) \
97 _cleanup_(sd_dhcp_client_unrefp) _unused_ sd_dhcp_client *_dont_destroy_##client = sd_dhcp_client_ref(client)
98
99 #define log_dhcp_client_errno(client, error, fmt, ...) \
100 log_interface_prefix_full_errno( \
101 "DHCPv4 client: ", \
102 sd_dhcp_client, client, \
103 error, fmt, ##__VA_ARGS__)
104 #define log_dhcp_client(client, fmt, ...) \
105 log_interface_prefix_full_errno_zerook( \
106 "DHCPv4 client: ", \
107 sd_dhcp_client, client, \
108 0, fmt, ##__VA_ARGS__)