[systemd-devel] [PATCH 12/24] sd-dhcp6-client: Add DHCPv6 Solicit message creation and sending
Zbigniew Jędrzejewski-Szmek
zbyszek at in.waw.pl
Wed Jun 18 06:58:09 PDT 2014
On Fri, Jun 13, 2014 at 04:45:02PM +0300, Patrik Flykt wrote:
> Implement the initial functionality used for creating a DHCPv6 Solicit
> message containing the needed options and send it to the DHCPv6
> broadcast address. Increase the sent message count and ensure that
> the Solicit Initial Retransmission Time is strictly greater than
> the Solicitation IRT as described in RFC 3315, section 17.1.2.
> ---
> src/libsystemd-network/dhcp6-internal.h | 4 ++
> src/libsystemd-network/sd-dhcp6-client.c | 111 +++++++++++++++++++++++++++++++
> 2 files changed, 115 insertions(+)
>
> diff --git a/src/libsystemd-network/dhcp6-internal.h b/src/libsystemd-network/dhcp6-internal.h
> index 7a491fb..31f5bd2 100644
> --- a/src/libsystemd-network/dhcp6-internal.h
> +++ b/src/libsystemd-network/dhcp6-internal.h
> @@ -27,6 +27,7 @@
> #include "sparse-endian.h"
> #include "sd-event.h"
> #include "list.h"
> +#include "macro.h"
>
> typedef struct DHCP6Address DHCP6Address;
>
> @@ -69,3 +70,6 @@ int dhcp6_option_parse(uint8_t **buf, size_t *buflen, uint16_t *optcode,
> int dhcp6_network_bind_udp_socket(int index, struct in6_addr *address);
> int dhcp6_network_send_udp_socket(int s, struct in6_addr *address,
> const void *packet, size_t len);
> +
> +const char *dhcp6_message_type_to_string(int s) _const_;
> +int dhcp6_message_type_from_string(const char *s) _pure_;
> diff --git a/src/libsystemd-network/sd-dhcp6-client.c b/src/libsystemd-network/sd-dhcp6-client.c
> index 048b4ea..bdd9177 100644
> --- a/src/libsystemd-network/sd-dhcp6-client.c
> +++ b/src/libsystemd-network/sd-dhcp6-client.c
> @@ -48,6 +48,9 @@ struct sd_dhcp6_client {
> struct ether_addr mac_addr;
> icmp6_nd *ra;
> DHCP6IA ia_na;
> + be32_t transaction_id;
> + int fd;
> + sd_event_source *receive_message;
> usec_t retransmit_time;
> uint8_t retransmit_count;
> sd_event_source *timeout_resend;
> @@ -62,6 +65,24 @@ struct sd_dhcp6_client {
> } _packed_ duid;
> };
>
> +const char * dhcp6_message_type_table[_DHCP6_MESSAGE_MAX] = {
> + [DHCP6_SOLICIT] = "SOLICIT",
> + [DHCP6_ADVERTISE] = "ADVERTISE",
> + [DHCP6_REQUEST] = "REQUEST",
> + [DHCP6_CONFIRM] = "CONFIRM",
> + [DHCP6_RENEW] = "RENEW",
> + [DHCP6_REBIND] = "REBIND",
> + [DHCP6_REPLY] = "REPLY",
> + [DHCP6_RELEASE] = "RELEASE",
> + [DHCP6_DECLINE] = "DECLINE",
> + [DHCP6_RECONFIGURE] = "RECONFIGURE",
> + [DHCP6_INFORMATION_REQUEST] = "INFORMATION-REQUEST",
> + [DHCP6_RELAY_FORW] = "RELAY-FORW",
> + [DHCP6_RELAY_REPL] = "RELAY-REPL",
> +};
> +
> +DEFINE_STRING_TABLE_LOOKUP(dhcp6_message_type, int);
> +
> int sd_dhcp6_client_set_callback(sd_dhcp6_client *client,
> sd_dhcp6_client_cb_t cb, void *userdata)
> {
> @@ -110,6 +131,15 @@ static int client_initialize(sd_dhcp6_client *client)
> {
> assert_return(client, -EINVAL);
>
> + client->receive_message =
> + sd_event_source_unref(client->receive_message);
> +
> + if (client->fd > 0)
> + safe_close(client->fd);
> + client->fd = -1;
client->fd = safe_close(client->fd);
That's what safe_close is for :)
Zbyszek
More information about the systemd-devel
mailing list