Merge pull request #29652 from yuwata/dhcp-cleanup-headers
dhcp: cleanup headers
This commit is contained in:
@@ -1,12 +1,50 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
#pragma once
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include "sd-dhcp-client.h"
|
||||
|
||||
extern const struct hash_ops dhcp_option_hash_ops;
|
||||
#include "macro.h"
|
||||
#include "network-common.h"
|
||||
|
||||
typedef enum DHCPState {
|
||||
DHCP_STATE_STOPPED,
|
||||
DHCP_STATE_INIT,
|
||||
DHCP_STATE_SELECTING,
|
||||
DHCP_STATE_INIT_REBOOT,
|
||||
DHCP_STATE_REBOOTING,
|
||||
DHCP_STATE_REQUESTING,
|
||||
DHCP_STATE_BOUND,
|
||||
DHCP_STATE_RENEWING,
|
||||
DHCP_STATE_REBINDING,
|
||||
_DHCP_STATE_MAX,
|
||||
_DHCP_STATE_INVALID = -EINVAL,
|
||||
} DHCPState;
|
||||
|
||||
const char *dhcp_state_to_string(DHCPState s) _const_;
|
||||
|
||||
typedef struct sd_dhcp_client sd_dhcp_client;
|
||||
|
||||
int dhcp_client_set_state_callback(
|
||||
sd_dhcp_client *client,
|
||||
sd_dhcp_client_callback_t cb,
|
||||
void *userdata);
|
||||
int dhcp_client_get_state(sd_dhcp_client *client);
|
||||
|
||||
/* If we are invoking callbacks of a dhcp-client, ensure unreffing the
|
||||
* client from the callback doesn't destroy the object we are working
|
||||
* on */
|
||||
#define DHCP_CLIENT_DONT_DESTROY(client) \
|
||||
_cleanup_(sd_dhcp_client_unrefp) _unused_ sd_dhcp_client *_dont_destroy_##client = sd_dhcp_client_ref(client)
|
||||
|
||||
#define log_dhcp_client_errno(client, error, fmt, ...) \
|
||||
log_interface_prefix_full_errno( \
|
||||
"DHCPv4 client: ", \
|
||||
sd_dhcp_client, client, \
|
||||
error, fmt, ##__VA_ARGS__)
|
||||
#define log_dhcp_client(client, fmt, ...) \
|
||||
log_interface_prefix_full_errno_zerook( \
|
||||
"DHCPv4 client: ", \
|
||||
sd_dhcp_client, client, \
|
||||
0, fmt, ##__VA_ARGS__)
|
||||
|
||||
@@ -1,90 +0,0 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
#pragma once
|
||||
|
||||
/***
|
||||
Copyright © 2013 Intel Corporation. All rights reserved.
|
||||
***/
|
||||
|
||||
#include <linux/if_packet.h>
|
||||
#include <net/ethernet.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "sd-dhcp-client.h"
|
||||
|
||||
#include "dhcp-client-internal.h"
|
||||
#include "dhcp-protocol.h"
|
||||
#include "ether-addr-util.h"
|
||||
#include "network-common.h"
|
||||
#include "socket-util.h"
|
||||
|
||||
typedef struct sd_dhcp_option {
|
||||
unsigned n_ref;
|
||||
|
||||
uint8_t option;
|
||||
void *data;
|
||||
size_t length;
|
||||
} sd_dhcp_option;
|
||||
|
||||
typedef struct DHCPServerData {
|
||||
struct in_addr *addr;
|
||||
size_t size;
|
||||
} DHCPServerData;
|
||||
|
||||
typedef struct sd_dhcp_client sd_dhcp_client;
|
||||
|
||||
int dhcp_network_bind_raw_socket(
|
||||
int ifindex,
|
||||
union sockaddr_union *link,
|
||||
uint32_t xid,
|
||||
const struct hw_addr_data *hw_addr,
|
||||
const struct hw_addr_data *bcast_addr,
|
||||
uint16_t arp_type,
|
||||
uint16_t port,
|
||||
bool so_priority_set,
|
||||
int so_priority);
|
||||
int dhcp_network_bind_udp_socket(int ifindex, be32_t address, uint16_t port, int ip_service_type);
|
||||
int dhcp_network_send_raw_socket(int s, const union sockaddr_union *link,
|
||||
const void *packet, size_t len);
|
||||
int dhcp_network_send_udp_socket(int s, be32_t address, uint16_t port,
|
||||
const void *packet, size_t len);
|
||||
|
||||
int dhcp_option_append(DHCPMessage *message, size_t size, size_t *offset, uint8_t overload,
|
||||
uint8_t code, size_t optlen, const void *optval);
|
||||
int dhcp_option_find_option(uint8_t *options, size_t length, uint8_t wanted_code, size_t *ret_offset);
|
||||
int dhcp_option_remove_option(uint8_t *options, size_t buflen, uint8_t option_code);
|
||||
|
||||
typedef int (*dhcp_option_callback_t)(uint8_t code, uint8_t len,
|
||||
const void *option, void *userdata);
|
||||
|
||||
int dhcp_option_parse(DHCPMessage *message, size_t len, dhcp_option_callback_t cb, void *userdata, char **ret_error_message);
|
||||
|
||||
int dhcp_option_parse_string(const uint8_t *option, size_t len, char **ret);
|
||||
|
||||
int dhcp_message_init(DHCPMessage *message, uint8_t op, uint32_t xid,
|
||||
uint8_t type, uint16_t arp_type, uint8_t hlen, const uint8_t *chaddr,
|
||||
size_t optlen, size_t *optoffset);
|
||||
|
||||
uint16_t dhcp_packet_checksum(uint8_t *buf, size_t len);
|
||||
|
||||
void dhcp_packet_append_ip_headers(DHCPPacket *packet, be32_t source_addr,
|
||||
uint16_t source, be32_t destination_addr,
|
||||
uint16_t destination, uint16_t len, int ip_service_type);
|
||||
|
||||
int dhcp_packet_verify_headers(DHCPPacket *packet, size_t len, bool checksum, uint16_t port);
|
||||
|
||||
/* If we are invoking callbacks of a dhcp-client, ensure unreffing the
|
||||
* client from the callback doesn't destroy the object we are working
|
||||
* on */
|
||||
#define DHCP_CLIENT_DONT_DESTROY(client) \
|
||||
_cleanup_(sd_dhcp_client_unrefp) _unused_ sd_dhcp_client *_dont_destroy_##client = sd_dhcp_client_ref(client)
|
||||
|
||||
#define log_dhcp_client_errno(client, error, fmt, ...) \
|
||||
log_interface_prefix_full_errno( \
|
||||
"DHCPv4 client: ", \
|
||||
sd_dhcp_client, client, \
|
||||
error, fmt, ##__VA_ARGS__)
|
||||
#define log_dhcp_client(client, fmt, ...) \
|
||||
log_interface_prefix_full_errno_zerook( \
|
||||
"DHCPv4 client: ", \
|
||||
sd_dhcp_client, client, \
|
||||
0, fmt, ##__VA_ARGS__)
|
||||
@@ -8,8 +8,7 @@
|
||||
#include "sd-dhcp-client.h"
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "dhcp-internal.h"
|
||||
#include "dhcp-protocol.h"
|
||||
#include "dhcp-option.h"
|
||||
#include "list.h"
|
||||
#include "time-util.h"
|
||||
|
||||
|
||||
@@ -13,9 +13,9 @@
|
||||
#include <linux/if_infiniband.h>
|
||||
#include <linux/if_packet.h>
|
||||
|
||||
#include "dhcp-internal.h"
|
||||
#include "dhcp-network.h"
|
||||
#include "dhcp-protocol.h"
|
||||
#include "fd-util.h"
|
||||
#include "socket-util.h"
|
||||
#include "unaligned.h"
|
||||
|
||||
static int _bind_raw_socket(
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "ether-addr-util.h"
|
||||
#include "socket-util.h"
|
||||
|
||||
int dhcp_network_bind_raw_socket(
|
||||
int ifindex,
|
||||
union sockaddr_union *link,
|
||||
uint32_t xid,
|
||||
const struct hw_addr_data *hw_addr,
|
||||
const struct hw_addr_data *bcast_addr,
|
||||
uint16_t arp_type,
|
||||
uint16_t port,
|
||||
bool so_priority_set,
|
||||
int so_priority);
|
||||
int dhcp_network_bind_udp_socket(
|
||||
int ifindex,
|
||||
be32_t address,
|
||||
uint16_t port,
|
||||
int ip_service_type);
|
||||
int dhcp_network_send_raw_socket(
|
||||
int s,
|
||||
const union sockaddr_union *link,
|
||||
const void *packet,
|
||||
size_t len);
|
||||
int dhcp_network_send_udp_socket(
|
||||
int s,
|
||||
be32_t address,
|
||||
uint16_t port,
|
||||
const void *packet,
|
||||
size_t len);
|
||||
@@ -8,9 +8,10 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "dhcp-internal.h"
|
||||
#include "dhcp-option.h"
|
||||
#include "dhcp-server-internal.h"
|
||||
#include "memory-util.h"
|
||||
#include "ordered-set.h"
|
||||
#include "strv.h"
|
||||
#include "utf8.h"
|
||||
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "sd-dhcp-option.h"
|
||||
|
||||
#include "dhcp-protocol.h"
|
||||
#include "hash-funcs.h"
|
||||
|
||||
struct sd_dhcp_option {
|
||||
unsigned n_ref;
|
||||
|
||||
uint8_t option;
|
||||
void *data;
|
||||
size_t length;
|
||||
};
|
||||
|
||||
extern const struct hash_ops dhcp_option_hash_ops;
|
||||
|
||||
typedef struct DHCPServerData {
|
||||
struct in_addr *addr;
|
||||
size_t size;
|
||||
} DHCPServerData;
|
||||
|
||||
int dhcp_option_append(
|
||||
DHCPMessage *message,
|
||||
size_t size,
|
||||
size_t *offset,
|
||||
uint8_t overload,
|
||||
uint8_t code,
|
||||
size_t optlen,
|
||||
const void *optval);
|
||||
int dhcp_option_find_option(uint8_t *options, size_t length, uint8_t wanted_code, size_t *ret_offset);
|
||||
int dhcp_option_remove_option(uint8_t *options, size_t buflen, uint8_t option_code);
|
||||
|
||||
typedef int (*dhcp_option_callback_t)(uint8_t code, uint8_t len, const void *option, void *userdata);
|
||||
|
||||
int dhcp_option_parse(
|
||||
DHCPMessage *message,
|
||||
size_t len,
|
||||
dhcp_option_callback_t cb,
|
||||
void *userdata,
|
||||
char **ret_error_message);
|
||||
|
||||
int dhcp_option_parse_string(const uint8_t *option, size_t len, char **ret);
|
||||
@@ -8,8 +8,8 @@
|
||||
#include <net/if_arp.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "dhcp-internal.h"
|
||||
#include "dhcp-protocol.h"
|
||||
#include "dhcp-option.h"
|
||||
#include "dhcp-packet.h"
|
||||
#include "memory-util.h"
|
||||
|
||||
#define DHCP_CLIENT_MIN_OPTIONS_SIZE 312
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "dhcp-protocol.h"
|
||||
|
||||
int dhcp_message_init(
|
||||
DHCPMessage *message,
|
||||
uint8_t op,
|
||||
uint32_t xid,
|
||||
uint8_t type,
|
||||
uint16_t arp_type,
|
||||
uint8_t hlen,
|
||||
const uint8_t *chaddr,
|
||||
size_t optlen,
|
||||
size_t *optoffset);
|
||||
|
||||
uint16_t dhcp_packet_checksum(uint8_t *buf, size_t len);
|
||||
|
||||
void dhcp_packet_append_ip_headers(
|
||||
DHCPPacket *packet,
|
||||
be32_t source_addr,
|
||||
uint16_t source,
|
||||
be32_t destination_addr,
|
||||
uint16_t destination,
|
||||
uint16_t len,
|
||||
int ip_service_type);
|
||||
|
||||
int dhcp_packet_verify_headers(DHCPPacket *packet, size_t len, bool checksum, uint16_t port);
|
||||
@@ -1,18 +0,0 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
|
||||
#include "dhcp-protocol.h"
|
||||
#include "string-table.h"
|
||||
|
||||
static const char* const dhcp_state_table[_DHCP_STATE_MAX] = {
|
||||
[DHCP_STATE_STOPPED] = "stopped",
|
||||
[DHCP_STATE_INIT] = "initialization",
|
||||
[DHCP_STATE_SELECTING] = "selecting",
|
||||
[DHCP_STATE_INIT_REBOOT] = "init-reboot",
|
||||
[DHCP_STATE_REBOOTING] = "rebooting",
|
||||
[DHCP_STATE_REQUESTING] = "requesting",
|
||||
[DHCP_STATE_BOUND] = "bound",
|
||||
[DHCP_STATE_RENEWING] = "renewing",
|
||||
[DHCP_STATE_REBINDING] = "rebinding",
|
||||
};
|
||||
|
||||
DEFINE_STRING_TABLE_LOOKUP_TO_STRING(dhcp_state, DHCPState);
|
||||
@@ -9,6 +9,8 @@
|
||||
#include <netinet/udp.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "sd-dhcp-protocol.h"
|
||||
|
||||
#include "macro.h"
|
||||
#include "sparse-endian.h"
|
||||
#include "time-util.h"
|
||||
@@ -59,22 +61,6 @@ enum {
|
||||
DHCP_PORT_CLIENT = 68,
|
||||
};
|
||||
|
||||
enum DHCPState {
|
||||
DHCP_STATE_STOPPED,
|
||||
DHCP_STATE_INIT,
|
||||
DHCP_STATE_SELECTING,
|
||||
DHCP_STATE_INIT_REBOOT,
|
||||
DHCP_STATE_REBOOTING,
|
||||
DHCP_STATE_REQUESTING,
|
||||
DHCP_STATE_BOUND,
|
||||
DHCP_STATE_RENEWING,
|
||||
DHCP_STATE_REBINDING,
|
||||
_DHCP_STATE_MAX,
|
||||
_DHCP_STATE_INVALID = -EINVAL,
|
||||
};
|
||||
|
||||
typedef enum DHCPState DHCPState;
|
||||
|
||||
enum {
|
||||
BOOTREQUEST = 1,
|
||||
BOOTREPLY = 2,
|
||||
@@ -114,5 +100,3 @@ enum {
|
||||
DHCP_FQDN_FLAG_E = (1 << 2),
|
||||
DHCP_FQDN_FLAG_N = (1 << 3),
|
||||
};
|
||||
|
||||
const char *dhcp_state_to_string(DHCPState s) _const_;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include "sd-dhcp-server.h"
|
||||
#include "sd-event.h"
|
||||
|
||||
#include "dhcp-internal.h"
|
||||
#include "dhcp-option.h"
|
||||
#include "network-common.h"
|
||||
#include "ordered-set.h"
|
||||
#include "time-util.h"
|
||||
|
||||
@@ -4,12 +4,12 @@
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "fuzz.h"
|
||||
#include "sd-event.h"
|
||||
|
||||
#include "sd-dhcp-client.c"
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "dhcp-network.h"
|
||||
#include "fuzz.h"
|
||||
|
||||
int dhcp_network_bind_raw_socket(
|
||||
int ifindex,
|
||||
union sockaddr_union *link,
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "fuzz.h"
|
||||
|
||||
#include "sd-dhcp-server.c"
|
||||
|
||||
#include "fuzz.h"
|
||||
|
||||
ssize_t sendto(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen) {
|
||||
return len;
|
||||
}
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "fuzz.h"
|
||||
|
||||
#include "sd-dhcp-server.c"
|
||||
|
||||
#include "fuzz.h"
|
||||
|
||||
/* stub out network so that the server doesn't send */
|
||||
ssize_t sendto(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen) {
|
||||
return len;
|
||||
|
||||
@@ -6,7 +6,6 @@ sources = files(
|
||||
'dhcp-network.c',
|
||||
'dhcp-option.c',
|
||||
'dhcp-packet.c',
|
||||
'dhcp-protocol.c',
|
||||
'dhcp6-network.c',
|
||||
'dhcp6-option.c',
|
||||
'dhcp6-protocol.c',
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "dhcp-lease-internal.h"
|
||||
#include "extract-word.h"
|
||||
#include "hexdecoct.h"
|
||||
#include "in-addr-util.h"
|
||||
#include "log.h"
|
||||
#include "network-internal.h"
|
||||
#include "parse-util.h"
|
||||
|
||||
@@ -15,10 +15,12 @@
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "device-util.h"
|
||||
#include "dhcp-client-internal.h"
|
||||
#include "dhcp-identifier.h"
|
||||
#include "dhcp-internal.h"
|
||||
#include "dhcp-lease-internal.h"
|
||||
#include "dhcp-protocol.h"
|
||||
#include "dhcp-network.h"
|
||||
#include "dhcp-option.h"
|
||||
#include "dhcp-packet.h"
|
||||
#include "dns-domain.h"
|
||||
#include "ether-addr-util.h"
|
||||
#include "event-util.h"
|
||||
@@ -30,6 +32,7 @@
|
||||
#include "random-util.h"
|
||||
#include "set.h"
|
||||
#include "sort-util.h"
|
||||
#include "string-table.h"
|
||||
#include "string-util.h"
|
||||
#include "strv.h"
|
||||
#include "time-util.h"
|
||||
@@ -2425,3 +2428,17 @@ int sd_dhcp_client_new(sd_dhcp_client **ret, int anonymize) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const char* const dhcp_state_table[_DHCP_STATE_MAX] = {
|
||||
[DHCP_STATE_STOPPED] = "stopped",
|
||||
[DHCP_STATE_INIT] = "initialization",
|
||||
[DHCP_STATE_SELECTING] = "selecting",
|
||||
[DHCP_STATE_INIT_REBOOT] = "init-reboot",
|
||||
[DHCP_STATE_REBOOTING] = "rebooting",
|
||||
[DHCP_STATE_REQUESTING] = "requesting",
|
||||
[DHCP_STATE_BOUND] = "bound",
|
||||
[DHCP_STATE_RENEWING] = "renewing",
|
||||
[DHCP_STATE_REBINDING] = "rebinding",
|
||||
};
|
||||
|
||||
DEFINE_STRING_TABLE_LOOKUP_TO_STRING(dhcp_state, DHCPState);
|
||||
|
||||
@@ -13,9 +13,8 @@
|
||||
#include "sd-dhcp-lease.h"
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "dhcp-internal.h"
|
||||
#include "dhcp-lease-internal.h"
|
||||
#include "dhcp-protocol.h"
|
||||
#include "dhcp-option.h"
|
||||
#include "dns-domain.h"
|
||||
#include "env-file.h"
|
||||
#include "fd-util.h"
|
||||
@@ -24,6 +23,7 @@
|
||||
#include "hexdecoct.h"
|
||||
#include "hostname-util.h"
|
||||
#include "in-addr-util.h"
|
||||
#include "network-common.h"
|
||||
#include "network-internal.h"
|
||||
#include "parse-util.h"
|
||||
#include "stdio-util.h"
|
||||
|
||||
@@ -10,7 +10,9 @@
|
||||
#include "sd-id128.h"
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "dhcp-internal.h"
|
||||
#include "dhcp-network.h"
|
||||
#include "dhcp-option.h"
|
||||
#include "dhcp-packet.h"
|
||||
#include "dhcp-server-internal.h"
|
||||
#include "dns-domain.h"
|
||||
#include "fd-util.h"
|
||||
|
||||
@@ -18,8 +18,9 @@
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "dhcp-identifier.h"
|
||||
#include "dhcp-internal.h"
|
||||
#include "dhcp-protocol.h"
|
||||
#include "dhcp-network.h"
|
||||
#include "dhcp-option.h"
|
||||
#include "dhcp-packet.h"
|
||||
#include "ether-addr-util.h"
|
||||
#include "fd-util.h"
|
||||
#include "random-util.h"
|
||||
|
||||
@@ -7,8 +7,9 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "dhcp-internal.h"
|
||||
#include "dhcp-protocol.h"
|
||||
#include "dhcp-option.h"
|
||||
#include "dhcp-packet.h"
|
||||
#include "ether-addr-util.h"
|
||||
#include "macro.h"
|
||||
#include "memory-util.h"
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "bus-error.h"
|
||||
#include "bus-locator.h"
|
||||
#include "dhcp-identifier.h"
|
||||
#include "dhcp-client-internal.h"
|
||||
#include "dhcp-option.h"
|
||||
#include "dhcp6-internal.h"
|
||||
#include "escape.h"
|
||||
#include "hexdecoct.h"
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
#include "bus-common-errors.h"
|
||||
#include "bus-util.h"
|
||||
#include "dhcp-client-internal.h"
|
||||
#include "dhcp-protocol.h"
|
||||
#include "networkd-dhcp4-bus.h"
|
||||
#include "networkd-link-bus.h"
|
||||
#include "networkd-manager.h"
|
||||
|
||||
Reference in New Issue
Block a user