]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/libsystemd-network/dhcp-internal.h
dhcp: split out dhcp-network.h from dhcp-internal.h
[thirdparty/systemd.git] / src / libsystemd-network / dhcp-internal.h
CommitLineData
db9ecf05 1/* SPDX-License-Identifier: LGPL-2.1-or-later */
524cf458
PF
2#pragma once
3
4/***
810adae9 5 Copyright © 2013 Intel Corporation. All rights reserved.
524cf458
PF
6***/
7
07630cea 8#include <stdint.h>
524cf458 9
574cc928 10#include "sd-dhcp-client.h"
07630cea 11
fd9b7f5b 12#include "dhcp-client-internal.h"
524cf458 13#include "dhcp-protocol.h"
5977b71f 14#include "network-common.h"
524cf458 15
461dbb2f
YW
16typedef struct sd_dhcp_option {
17 unsigned n_ref;
18
19 uint8_t option;
20 void *data;
21 size_t length;
22} sd_dhcp_option;
23
ddb82ec2
LP
24typedef struct DHCPServerData {
25 struct in_addr *addr;
26 size_t size;
27} DHCPServerData;
28
8d71f2b3
YW
29typedef struct sd_dhcp_client sd_dhcp_client;
30
04b28be1 31int dhcp_option_append(DHCPMessage *message, size_t size, size_t *offset, uint8_t overload,
20b958bf 32 uint8_t code, size_t optlen, const void *optval);
11c38d3e
YA
33int dhcp_option_find_option(uint8_t *options, size_t length, uint8_t wanted_code, size_t *ret_offset);
34int dhcp_option_remove_option(uint8_t *options, size_t buflen, uint8_t option_code);
524cf458 35
ccf86354 36typedef int (*dhcp_option_callback_t)(uint8_t code, uint8_t len,
e4735228 37 const void *option, void *userdata);
cf597f65 38
7b1fac1e 39int dhcp_option_parse(DHCPMessage *message, size_t len, dhcp_option_callback_t cb, void *userdata, char **ret_error_message);
cf597f65 40
930133d5
RH
41int dhcp_option_parse_string(const uint8_t *option, size_t len, char **ret);
42
76253e73 43int dhcp_message_init(DHCPMessage *message, uint8_t op, uint32_t xid,
97fa338d
YW
44 uint8_t type, uint16_t arp_type, uint8_t hlen, const uint8_t *chaddr,
45 size_t optlen, size_t *optoffset);
cf597f65 46
0bbc2c1f 47uint16_t dhcp_packet_checksum(uint8_t *buf, size_t len);
a838c939 48
63edaa62
TG
49void dhcp_packet_append_ip_headers(DHCPPacket *packet, be32_t source_addr,
50 uint16_t source, be32_t destination_addr,
afe42aef 51 uint16_t destination, uint16_t len, int ip_service_type);
cf597f65 52
9faed222 53int dhcp_packet_verify_headers(DHCPPacket *packet, size_t len, bool checksum, uint16_t port);
ee57a737 54
574cc928
TG
55/* If we are invoking callbacks of a dhcp-client, ensure unreffing the
56 * client from the callback doesn't destroy the object we are working
57 * on */
58#define DHCP_CLIENT_DONT_DESTROY(client) \
4afd3348 59 _cleanup_(sd_dhcp_client_unrefp) _unused_ sd_dhcp_client *_dont_destroy_##client = sd_dhcp_client_ref(client)
574cc928 60
a0c2541b 61#define log_dhcp_client_errno(client, error, fmt, ...) \
00dd6d77 62 log_interface_prefix_full_errno( \
a0c2541b 63 "DHCPv4 client: ", \
5977b71f 64 sd_dhcp_client, client, \
a0c2541b 65 error, fmt, ##__VA_ARGS__)
35388783 66#define log_dhcp_client(client, fmt, ...) \
00dd6d77
ZJS
67 log_interface_prefix_full_errno_zerook( \
68 "DHCPv4 client: ", \
5977b71f 69 sd_dhcp_client, client, \
00dd6d77 70 0, fmt, ##__VA_ARGS__)