sd-dhcp-lease.c revision 1caa12d0a8a818d5f2545aab809b3fdfec73871d
/***
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 <stdlib.h>
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <net/ethernet.h>
#include "util.h"
#include "list.h"
#include "mkdir.h"
#include "fileio.h"
#include "unaligned.h"
#include "in-addr-util.h"
#include "dhcp-protocol.h"
#include "dhcp-internal.h"
#include "dhcp-lease-internal.h"
#include "sd-dhcp-lease.h"
#include "sd-dhcp-client.h"
#include "network-internal.h"
return 0;
}
return 0;
}
else
return -ENOENT;
return 0;
}
} else
return -ENOENT;
return 0;
}
} else
return -ENOENT;
return 0;
}
if (lease->domainname)
else
return -ENOENT;
return 0;
}
else
return -ENOENT;
return 0;
}
else
return -ENOENT;
return 0;
}
else
return -ENOENT;
return 0;
}
return 0;
}
return 0;
}
return 0;
}
if (lease->static_route_size) {
return lease->static_route_size;
} else
return -ENOENT;
return 0;
}
if (lease)
return lease;
}
}
return NULL;
}
if (len == 4) {
}
}
}
if (len == 2) {
}
}
if (len == 4)
}
if (len == 1)
}
if (len == 1) {
}
}
if (len >= 1) {
char *string;
if (!string)
return -errno;
}
return 0;
}
static int lease_parse_in_addrs_aux(const uint8_t *option, size_t len, struct in_addr **ret, size_t *ret_size, size_t mult) {
if (!addresses)
return -ENOMEM;
}
return 0;
}
static int lease_parse_in_addrs(const uint8_t *option, size_t len, struct in_addr **ret, size_t *ret_size) {
}
static int lease_parse_in_addrs_pairs(const uint8_t *option, size_t len, struct in_addr **ret, size_t *ret_size) {
}
if (!len)
return 0;
if (len % 8 != 0)
return -EINVAL;
return -ENOMEM;
while (len >= 8) {
int r;
if (r < 0) {
log_error("Failed to determine destination prefix length from class based IP, ignoring");
continue;
}
option += 4;
option += 4;
len -= 8;
(*routes_size)++;
}
return 0;
}
/* parses RFC3442 Classless Static Route Option */
static int lease_parse_classless_routes(const uint8_t *option, size_t len, struct sd_dhcp_route **routes,
/* option format: (subnet-mask-width significant-subnet-octets gateway-ip)* */
while (len > 0) {
struct sd_dhcp_route *route;
return -ENOMEM;
option++;
len--;
/* can't have more than 4 octets in IPv4 */
return -EINVAL;
option += dst_octets;
len -= dst_octets;
if (len < 4)
return -EINVAL;
option += 4;
len -= 4;
(*routes_size)++;
}
return 0;
}
void *user_data) {
int r;
switch(code) {
case DHCP_OPTION_TIME_OFFSET:
break;
break;
break;
break;
case DHCP_OPTION_SUBNET_MASK:
break;
case DHCP_OPTION_BROADCAST:
break;
case DHCP_OPTION_ROUTER:
break;
if (r < 0)
return r;
break;
case DHCP_OPTION_NTP_SERVER:
if (r < 0)
return r;
break;
if (r < 0)
return r;
break;
case DHCP_OPTION_STATIC_ROUTE:
if (r < 0)
return r;
break;
break;
break;
break;
break;
case DHCP_OPTION_DOMAIN_NAME:
{
if (r < 0)
return r;
break;
domainname = NULL;
break;
}
case DHCP_OPTION_HOST_NAME:
{
if (r < 0)
return r;
break;
break;
}
case DHCP_OPTION_ROOT_PATH:
if (r < 0)
return r;
break;
break;
break;
break;
break;
if (r < 0)
return r;
break;
}
return 0;
}
if (!lease)
return -ENOMEM;
return 0;
}
const char *string;
struct sd_dhcp_route *routes;
int r;
if (r < 0)
goto finish;
if (r < 0)
goto finish;
fprintf(f,
"# This is private data. Do not parse.\n"
if (r < 0)
goto finish;
if (r >= 0)
if (r >= 0)
fprintf(f, "SERVER_ADDRESS=%s\n",
if (r >= 0)
if (r >= 0)
fputs("DNS=", f);
if (r >= 0)
serialize_in_addrs(f, addresses, r);
fputs("\n", f);
fputs("NTP=", f);
if (r >= 0)
serialize_in_addrs(f, addresses, r);
fputs("\n", f);
if (r >= 0)
if (r >= 0)
if (r >= 0)
if (r >= 0)
r = 0;
fflush(f);
r = -errno;
}
if (r < 0)
return r;
}
int r;
r = dhcp_lease_new(&lease);
if (r < 0)
return r;
"ADDRESS", &address,
"ROUTER", &router,
"NETMASK", &netmask,
"SERVER_IDENTIFIER", &server_address,
"NEXT_SERVER", &next_server,
"DNS", &dns,
"NTP", &ntp,
"MTU", &mtu,
"ROUTES", &routes,
NULL);
if (r < 0) {
if (r == -ENOENT)
return 0;
return r;
}
if (r < 0)
return r;
if (router) {
if (r < 0)
return r;
}
if (r < 0)
return r;
if (server_address) {
if (r < 0)
return r;
}
if (next_server) {
if (r < 0)
return r;
}
if (dns) {
if (r < 0)
return r;
}
if (ntp) {
if (r < 0)
return r;
}
if (mtu) {
uint16_t u;
}
if (routes) {
if (r < 0)
return r;
}
return 0;
}
int r;
/* fall back to the default subnet masks based on address class */
if (r < 0)
return r;
return 0;
}