sd-dhcp-lease.c revision bab47929613f9e930dd241a01483b37d14b59c69
/***
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 (msb_octet < 128)
/* Class A */
*ret = 8;
else if (msb_octet < 192)
/* Class B */
*ret = 16;
else if (msb_octet < 224)
/* Class C */
*ret = 24;
else
/* Class D or E -- no subnet mask */
return -ERANGE;
return 0;
}
if (!len)
return 0;
if (len % 8 != 0)
return -EINVAL;
return -ENOMEM;
while (len >= 8) {
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;
}