sd-dhcp-client.c revision 0f941add365638ad487ba94017cc2cf1f8d45195
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer This file is part of systemd.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer Copyright (C) 2013 Intel Corporation. All rights reserved.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer systemd is free software; you can redistribute it and/or modify it
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer under the terms of the GNU Lesser General Public License as published by
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer the Free Software Foundation; either version 2.1 of the License, or
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer (at your option) any later version.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer systemd is distributed in the hope that it will be useful, but
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer WITHOUT ANY WARRANTY; without even the implied warranty of
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer Lesser General Public License for more details.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer You should have received a copy of the GNU Lesser General Public License
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer along with systemd; If not, see <http://www.gnu.org/licenses/>.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer unsigned int attempt;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyerstatic int client_receive_message_raw(sd_event_source *s, int fd,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyerstatic int client_receive_message_udp(sd_event_source *s, int fd,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyerint sd_dhcp_client_set_callback(sd_dhcp_client *client, sd_dhcp_client_cb_t cb,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyerint sd_dhcp_client_set_request_option(sd_dhcp_client *client, uint8_t option) {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer assert_return (client->state == DHCP_STATE_INIT, -EBUSY);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if (!GREEDY_REALLOC(client->req_opts, client->req_opts_allocated,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer client->req_opts[client->req_opts_size++] = option;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyerint sd_dhcp_client_set_request_address(sd_dhcp_client *client,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer assert_return(client->state == DHCP_STATE_INIT, -EBUSY);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyerint sd_dhcp_client_set_index(sd_dhcp_client *client, int interface_index) {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer assert_return(client->state == DHCP_STATE_INIT, -EBUSY);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyerint sd_dhcp_client_set_mac(sd_dhcp_client *client,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer assert_return(client->state == DHCP_STATE_INIT, -EBUSY);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyerint sd_dhcp_client_get_lease(sd_dhcp_client *client, sd_dhcp_lease **ret) {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyerstatic int client_notify(sd_dhcp_client *client, int event) {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyerstatic int client_initialize(sd_dhcp_client *client) {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer sd_event_source_unref(client->receive_message);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer client->timeout_resend = sd_event_source_unref(client->timeout_resend);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer client->timeout_t1 = sd_event_source_unref(client->timeout_t1);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer client->timeout_t2 = sd_event_source_unref(client->timeout_t2);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer client->timeout_expire = sd_event_source_unref(client->timeout_expire);
optlen);
int err = 0;
if (!discover)
return -ENOMEM;
if (err < 0)
return err;
if (err < 0)
return err;
if (err < 0)
return err;
if (err < 0)
return err;
int err;
if (!request)
return -ENOMEM;
if (err < 0)
return err;
if (err < 0)
return err;
if (err < 0)
return err;
if (err < 0)
return err;
if (err < 0)
return err;
void *userdata) {
assert(s);
goto error;
case DHCP_STATE_RENEWING:
case DHCP_STATE_REBINDING:
case DHCP_STATE_INIT:
case DHCP_STATE_INIT_REBOOT:
case DHCP_STATE_REBOOTING:
case DHCP_STATE_SELECTING:
case DHCP_STATE_REQUESTING:
case DHCP_STATE_BOUND:
goto error;
goto error;
case DHCP_STATE_INIT:
goto error;
case DHCP_STATE_SELECTING:
goto error;
case DHCP_STATE_REQUESTING:
case DHCP_STATE_RENEWING:
case DHCP_STATE_REBINDING:
goto error;
case DHCP_STATE_INIT_REBOOT:
case DHCP_STATE_REBOOTING:
case DHCP_STATE_BOUND:
client);
goto error;
goto error;
goto error;
void *userdata) {
void *userdata) {
if (r != DHCP_OFFER)
return -ENOMSG;
return -ENOMSG;
if (r == DHCP_NAK) {
return DHCP_EVENT_NO_LEASE;
if (r != DHCP_ACK)
return -ENOMSG;
return -ENOMSG;
r = DHCP_EVENT_IP_CHANGE;
return -EINVAL;
return -EINVAL;
return -EINVAL;
return -EINVAL;
return -EINVAL;
return -EINVAL;
int r = 0, notify_event = 0;
ETHER_ADDR_LEN)) {
case DHCP_STATE_SELECTING:
client);
goto error;
goto error;
case DHCP_STATE_REQUESTING:
case DHCP_STATE_RENEWING:
case DHCP_STATE_REBINDING:
if (r == DHCP_EVENT_NO_LEASE)
goto error;
else if (r != DHCP_EVENT_IP_ACQUIRE)
notify_event = r;
goto error;
if (notify_event)
case DHCP_STATE_INIT:
case DHCP_STATE_INIT_REBOOT:
case DHCP_STATE_REBOOTING:
case DHCP_STATE_BOUND:
if (r < 0 || r == DHCP_EVENT_NO_LEASE)
assert(s);
if (r < 0 || buflen <= 0)
if (!message)
return -ENOMEM;
if (len < 0)
time_now);
bool checksum = true;
assert(s);
if (r < 0 || buflen <= 0)
if (!packet)
return -ENOMEM;
if (len < 0) {
int priority) {
if (event)
if (!client)
return NULL;
if (!client)
if (!client)
return -ENOMEM;
return -ENOMEM;