sd-dhcp-server.c revision 969b009d9416806911b9b52e7e7bc619c0c1a931
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright (C) 2013 Intel Corporation. All rights reserved.
Copyright (C) 2014 Tom Gundersen
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <netinet/if_ether.h>
#include "sd-dhcp-server.h"
#include "dhcp-server-internal.h"
#include "dhcp-internal.h"
return 0;
}
if (server)
return server;
}
}
return NULL;
}
if (!server)
return -ENOMEM;
return 0;
}
int r;
if (event)
else {
if (r < 0)
return r;
}
return 0;
}
return 0;
}
}
return 0;
}
union sockaddr_union link = {
};
int r;
if (r < 0)
return r;
return 0;
}
union sockaddr_union dest = {
};
};
.msg_iovlen = 1,
.msg_control = cmsgbuf,
.msg_controllen = sizeof(cmsgbuf),
};
struct in_pktinfo *pktinfo;
int r;
/* we attach source interface and address info to the message
rather than binding the socket. This will be mostly useful
when we gain support for arbitrary number of server addresses
*/
if (r < 0)
return -errno;
return 0;
}
}
int r;
if (r < 0)
return r;
DHCP_OPTION_END, 0, NULL);
if (r < 0)
return r;
/* RFC 2131 Section 4.1
If the ’giaddr’ field in a DHCP message from a client is non-zero,
the server sends any return messages to the ’DHCP server’ port on the
BOOTP relay agent whose address appears in ’giaddr’. If the ’giaddr’
field is zero and the ’ciaddr’ field is nonzero, then the server
unicasts DHCPOFFER and DHCPACK messages to the address in ’ciaddr’.
If ’giaddr’ is zero and ’ciaddr’ is zero, and the broadcast bit is
set, then the server broadcasts DHCPOFFER and DHCPACK messages to
0xffffffff. If the broadcast bit is not set and ’giaddr’ is zero and
’ciaddr’ is zero, then the server unicasts DHCPOFFER and DHCPACK
messages to the client’s hardware address and ’yiaddr’ address. In
all cases, when ’giaddr’ is zero, the server broadcasts any DHCPNAK
messages to 0xffffffff.
Section 4.3.2
If ’giaddr’ is set in the DHCPREQUEST message, the client is on a
different subnet. The server MUST set the broadcast bit in the
DHCPNAK, so that the relay agent will broadcast the DHCPNAK to the
client, because the client may not have a correct network address
or subnet mask, and the client may not be answering ARP requests.
*/
sizeof(DHCPMessage) + optoffset);
else
/* we cannot send UDP packet to specific MAC address when the address is
not yet configured, so must fall back to raw packets */
sizeof(DHCPPacket) + optoffset);
}
void *user_data) {
switch(code) {
if (len == 4)
break;
if (len >= 2) {
if (!data)
return -ENOMEM;
}
break;
if (len == 2)
- sizeof(DHCPPacket);
break;
}
return 0;
}
if (!req)
return;
}
/* set client id based on mac address if client did not send an explicit one */
if (!data)
return -ENOMEM;
}
return 0;
}
int type, r;
return 0;
if (!req)
return -ENOMEM;
if (type < 0)
return 0;
if (r < 0)
/* this only fails on critical errors */
return r;
return 1;
}
.msg_iovlen = 1,
.msg_control = cmsgbuf,
.msg_controllen = sizeof(cmsgbuf),
};
if (r < 0)
return r;
if (buflen < 0)
return -EIO;
if (!message)
return -ENOMEM;
return 0;
return 0;
/* TODO figure out if this can be done as a filter on the socket, like for IPv6 */
return 0;
break;
}
}
}
int r;
if (r < 0) {
r = -errno;
return r;
}
if (r < 0) {
return r;
}
if (r < 0) {
return r;
}
if (r < 0) {
return r;
}
return 0;
}