sd-dhcp-client.c revision 6236f49b230568ba3163df71fd7d386d354091de
d8c9d3a468e61ee2a2b2c3454e662398b0885411Zbigniew Jędrzejewski-Szmek This file is part of systemd.
d8c9d3a468e61ee2a2b2c3454e662398b0885411Zbigniew Jędrzejewski-Szmek Copyright (C) 2013 Intel Corporation. All rights reserved.
d8c9d3a468e61ee2a2b2c3454e662398b0885411Zbigniew Jędrzejewski-Szmek systemd is free software; you can redistribute it and/or modify it
d8c9d3a468e61ee2a2b2c3454e662398b0885411Zbigniew Jędrzejewski-Szmek under the terms of the GNU Lesser General Public License as published by
d8c9d3a468e61ee2a2b2c3454e662398b0885411Zbigniew Jędrzejewski-Szmek the Free Software Foundation; either version 2.1 of the License, or
d8c9d3a468e61ee2a2b2c3454e662398b0885411Zbigniew Jędrzejewski-Szmek (at your option) any later version.
d8c9d3a468e61ee2a2b2c3454e662398b0885411Zbigniew Jędrzejewski-Szmek systemd is distributed in the hope that it will be useful, but
d8c9d3a468e61ee2a2b2c3454e662398b0885411Zbigniew Jędrzejewski-Szmek WITHOUT ANY WARRANTY; without even the implied warranty of
d8c9d3a468e61ee2a2b2c3454e662398b0885411Zbigniew Jędrzejewski-Szmek MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
d8c9d3a468e61ee2a2b2c3454e662398b0885411Zbigniew Jędrzejewski-Szmek Lesser General Public License for more details.
d8c9d3a468e61ee2a2b2c3454e662398b0885411Zbigniew Jędrzejewski-Szmek You should have received a copy of the GNU Lesser General Public License
d8c9d3a468e61ee2a2b2c3454e662398b0885411Zbigniew Jędrzejewski-Szmek along with systemd; If not, see <http://www.gnu.org/licenses/>.
d8c9d3a468e61ee2a2b2c3454e662398b0885411Zbigniew Jędrzejewski-Szmek sd_event_source *timeout_resend;
613b411c947635136637f8cdd66b94512f761eabLennart Poetteringstatic const uint8_t default_req_opts[] = {
613b411c947635136637f8cdd66b94512f761eabLennart Poetteringstatic int client_receive_message_raw(sd_event_source *s, int fd,
613b411c947635136637f8cdd66b94512f761eabLennart Poetteringstatic int client_receive_message_udp(sd_event_source *s, int fd,
613b411c947635136637f8cdd66b94512f761eabLennart Poetteringint sd_dhcp_client_set_callback(sd_dhcp_client *client, sd_dhcp_client_cb_t cb,
613b411c947635136637f8cdd66b94512f761eabLennart Poetteringint sd_dhcp_client_set_request_option(sd_dhcp_client *client, uint8_t option) {
613b411c947635136637f8cdd66b94512f761eabLennart Poettering assert_return (client->state == DHCP_STATE_INIT, -EBUSY);
613b411c947635136637f8cdd66b94512f761eabLennart Poettering for (i = 0; i < client->req_opts_size; i++)
613b411c947635136637f8cdd66b94512f761eabLennart Poettering if (!GREEDY_REALLOC(client->req_opts, client->req_opts_allocated,
613b411c947635136637f8cdd66b94512f761eabLennart Poettering client->req_opts[client->req_opts_size++] = option;
d8c9d3a468e61ee2a2b2c3454e662398b0885411Zbigniew Jędrzejewski-Szmekint sd_dhcp_client_set_request_address(sd_dhcp_client *client,
d8c9d3a468e61ee2a2b2c3454e662398b0885411Zbigniew Jędrzejewski-Szmek const struct in_addr *last_addr) {
6b46ea73e3b1d8a1e65f58ac04772821bd4a72fbLennart Poettering assert_return(client->state == DHCP_STATE_INIT, -EBUSY);
6b46ea73e3b1d8a1e65f58ac04772821bd4a72fbLennart Poetteringint sd_dhcp_client_set_index(sd_dhcp_client *client, int interface_index) {
6b46ea73e3b1d8a1e65f58ac04772821bd4a72fbLennart Poettering assert_return(client->state == DHCP_STATE_INIT, -EBUSY);
6b46ea73e3b1d8a1e65f58ac04772821bd4a72fbLennart Poettering assert_return(interface_index >= -1, -EINVAL);
613b411c947635136637f8cdd66b94512f761eabLennart Poetteringint sd_dhcp_client_set_mac(sd_dhcp_client *client,
d8c9d3a468e61ee2a2b2c3454e662398b0885411Zbigniew Jędrzejewski-Szmek const struct ether_addr *addr) {
return -EADDRNOTAVAIL;
optlen);
if (!discover)
return -ENOMEM;
if (!request)
return -ENOMEM;
&optlen);
case DHCP_STATE_INIT_REBOOT:
case DHCP_STATE_REQUESTING:
case DHCP_STATE_INIT:
case DHCP_STATE_SELECTING:
case DHCP_STATE_REBOOTING:
case DHCP_STATE_BOUND:
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:
case DHCP_STATE_INIT:
case DHCP_STATE_INIT_REBOOT:
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_INIT_REBOOT:
case DHCP_STATE_REQUESTING:
case DHCP_STATE_RENEWING:
case DHCP_STATE_REBINDING:
goto error;
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;
ETH_ALEN)) {
case DHCP_STATE_SELECTING:
client);
goto error;
goto error;
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)
case DHCP_STATE_INIT:
case DHCP_STATE_INIT_REBOOT:
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;