sd-dhcp-lease.c revision 8fb494435889dcb9e1c09b8c7220e47bab717bf9
/***
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 "fileio.h"
#include "unaligned.h"
#include "in-addr-util.h"
#include "hostname-util.h"
#include "dhcp-protocol.h"
#include "dhcp-lease-internal.h"
#include "sd-dhcp-lease.h"
#include "network-internal.h"
#include "dns-domain.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->vendor_specific)
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:
if(len >= 4)
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:
{
char *e;
if (r < 0)
return r;
/* Chop off trailing dot of domain name that some DHCP
* servers send us back. Internally we want to store
* host names without trailing dots and
* host_name_is_valid() doesn't accept them. */
if (e)
*e = 0;
if (is_localhost(domainname))
break;
r = dns_name_is_valid(domainname);
if (r <= 0) {
if (r < 0)
if (r == 0)
break;
}
domainname = NULL;
break;
}
case DHCP_OPTION_HOST_NAME:
{
char *e;
if (r < 0)
return r;
if (e)
*e = 0;
break;
break;
}
case DHCP_OPTION_ROOT_PATH:
if (r < 0)
return r;
break;
break;
break;
break;
break;
if (r < 0)
return r;
break;
if (len >= 1) {
if (!lease->vendor_specific)
return -ENOMEM;
}
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)
if (r >= 0) {
_cleanup_free_ char *client_id_hex;
if (!client_id_hex) {
r = -ENOMEM;
goto finish;
}
}
if (r >= 0) {
if (!option_hex) {
r = -ENOMEM;
goto finish;
}
}
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,
"CLIENTID", &client_id_hex,
"VENDOR_SPECIFIC", &vendor_specific_hex,
NULL);
if (r < 0) {
if (r == -ENOENT)
return 0;
}
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;
}
if (client_id_hex) {
return -EINVAL;
r = unhexmem(client_id_hex, strlen(client_id_hex), (void**) &lease->client_id, &lease->client_id_len);
if (r < 0)
return r;
}
if (vendor_specific_hex) {
return -EINVAL;
r = unhexmem(vendor_specific_hex, strlen(vendor_specific_hex), (void**) &lease->vendor_specific, &lease->vendor_specific_len);
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;
}
size_t *client_id_len) {
return 0;
}
lease->client_id_len = 0;
if (client_id) {
}
return 0;
}