sd-dhcp-client.c revision f7926298e934c91dc2d152f4223cafbd202c907c
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering This file is part of systemd.
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering Copyright (C) 2013 Intel Corporation. All rights reserved.
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering systemd is free software; you can redistribute it and/or modify it
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering under the terms of the GNU Lesser General Public License as published by
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering (at your option) any later version.
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering systemd is distributed in the hope that it will be useful, but
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering Lesser General Public License for more details.
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering You should have received a copy of the GNU Lesser General Public License
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poetteringstatic const uint8_t default_req_opts[] = {
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poetteringstatic int client_receive_message_raw(sd_event_source *s, int fd,
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poetteringstatic int client_receive_message_udp(sd_event_source *s, int fd,
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poetteringstatic sd_dhcp_client *client_stop(sd_dhcp_client *client, int error);
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poetteringint sd_dhcp_client_set_callback(sd_dhcp_client *client, sd_dhcp_client_cb_t cb,
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poetteringint sd_dhcp_client_set_request_option(sd_dhcp_client *client, uint8_t option) {
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering assert_return (IN_SET(client->state, DHCP_STATE_INIT,
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering for (i = 0; i < client->req_opts_size; i++)
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering if (!GREEDY_REALLOC(client->req_opts, client->req_opts_allocated,
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering client->req_opts[client->req_opts_size++] = option;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poetteringint sd_dhcp_client_set_request_address(sd_dhcp_client *client,
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering assert_return (IN_SET(client->state, DHCP_STATE_INIT,
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poetteringint sd_dhcp_client_set_index(sd_dhcp_client *client, int interface_index) {
bool need_restart = false;
need_restart = true;
if (!client)
return -EADDRNOTAVAIL;
return client;
if (error < 0)
switch(error) {
case DHCP_EVENT_STOP:
case DHCP_EVENT_NO_LEASE:
if (client)
return client;
if (!packet)
return -ENOMEM;
case DHCP_STATE_REQUESTING:
case DHCP_STATE_INIT_REBOOT:
case DHCP_STATE_RENEWING:
case DHCP_STATE_REBINDING:
case DHCP_STATE_INIT:
case DHCP_STATE_SELECTING:
case DHCP_STATE_REBOOTING:
case DHCP_STATE_BOUND:
case DHCP_STATE_STOPPED:
return -EINVAL;
case DHCP_STATE_REQUESTING:
case DHCP_STATE_INIT_REBOOT:
case DHCP_STATE_RENEWING:
case DHCP_STATE_REBINDING:
void *userdata) {
assert(s);
goto error;
case DHCP_STATE_RENEWING:
case DHCP_STATE_REBINDING:
case DHCP_STATE_REBOOTING:
goto error;
goto error;
case DHCP_STATE_INIT:
case DHCP_STATE_INIT_REBOOT:
case DHCP_STATE_SELECTING:
case DHCP_STATE_REQUESTING:
case DHCP_STATE_BOUND:
case DHCP_STATE_STOPPED:
r = -EINVAL;
goto error;
goto error;
goto error;
case DHCP_STATE_INIT:
goto error;
case DHCP_STATE_SELECTING:
goto error;
case DHCP_STATE_INIT_REBOOT:
case DHCP_STATE_REQUESTING:
case DHCP_STATE_RENEWING:
case DHCP_STATE_REBINDING:
goto error;
case DHCP_STATE_REBOOTING:
case DHCP_STATE_BOUND:
case DHCP_STATE_STOPPED:
r = -EINVAL;
goto error;
client);
goto error;
goto error;
goto error;
void *userdata) {
void *userdata) {
if (r != DHCP_OFFER) {
return -ENOMSG;
return -ENOMSG;
return -ENOMSG;
if (r == DHCP_NAK) {
return DHCP_EVENT_NO_LEASE;
if (r != DHCP_ACK) {
return -ENOMSG;
return -ENOMSG;
return -ENOMSG;
r = DHCP_EVENT_IP_CHANGE;
int len) {
int r = 0, notify_event = 0;
ETH_ALEN)) {
case DHCP_STATE_SELECTING:
goto error;
goto error;
} else if (r == -ENOMSG)
case DHCP_STATE_REBOOTING:
case DHCP_STATE_REQUESTING:
case DHCP_STATE_RENEWING:
case DHCP_STATE_REBINDING:
if (r == DHCP_EVENT_NO_LEASE) {
goto error;
goto error;
goto error;
else if (r != DHCP_EVENT_IP_ACQUIRE)
notify_event = r;
goto error;
if (notify_event) {
if (!client ||
} else if (r == -ENOMSG)
case DHCP_STATE_INIT:
case DHCP_STATE_INIT_REBOOT:
case DHCP_STATE_BOUND:
case DHCP_STATE_STOPPED:
r = -EINVAL;
goto error;
if (r < 0 || r == DHCP_EVENT_NO_LEASE)
assert(s);
if (buflen < 0)
return -EIO;
if (!message)
return -ENOMEM;
if (len < 0) {
bool checksum = true;
assert(s);
if (buflen < 0)
return -EIO;
if (!packet)
return -ENOMEM;
if (len < 0) {
int priority) {
if (event)
if (!client)
return NULL;
if (client)
return client;
return NULL;
return client;
if (!client)
return -ENOMEM;
return -ENOMEM;