sd-dhcp-lease.c revision 0b21bde96d6d33313bac42ae1d5802a83a4e7b2f
/***
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 "dhcp-protocol.h"
#include "dhcp-internal.h"
#include "dhcp-lease-internal.h"
#include "sd-dhcp-lease.h"
#include "sd-dhcp-client.h"
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;
}
return 0;
}
return 0;
}
return 0;
}
return 0;
}
if (lease)
return lease;
}
}
return NULL;
}
void *user_data) {
switch(code) {
if (len == 4) {
}
break;
if (len >= 4)
break;
case DHCP_OPTION_SUBNET_MASK:
if (len >= 4)
break;
case DHCP_OPTION_ROUTER:
if (len >= 4)
break;
return -ENOMEM;
}
break;
case DHCP_OPTION_NTP_SERVER:
return -ENOMEM;
}
break;
if (len >= 2) {
}
break;
case DHCP_OPTION_DOMAIN_NAME:
if (len >= 1) {
}
break;
case DHCP_OPTION_HOST_NAME:
if (len >= 1) {
}
break;
case DHCP_OPTION_ROOT_PATH:
if (len >= 1) {
}
break;
if (len == 4) {
}
break;
if (len == 4) {
}
break;
}
return 0;
}
if (!lease)
return -ENOMEM;
return 0;
}
char buf[INET_ADDRSTRLEN];
const char *string;
int r;
if (r < 0)
goto finish;
if (r < 0)
goto finish;
if (!string) {
r = -errno;
goto finish;
}
fprintf(f,
"# This is private data. Do not parse.\n"
"ADDRESS=%s\n", string);
if (r < 0)
goto finish;
if (!string) {
r = -errno;
goto finish;
}
fprintf(f,
"ROUTER=%s\n", string);
if (r < 0)
goto finish;
if (!string) {
r = -errno;
goto finish;
}
fprintf(f,
"NETMASK=%s\n", string);
if (r >= 0) {
if (!string) {
r = -errno;
goto finish;
}
fprintf(f,
"SERVER_ADDRESS=%s\n", string);
}
if (r >= 0) {
if (!string) {
r = -errno;
goto finish;
}
fprintf(f,
"NEXT_SERVER=%s\n", string);
}
if (r >= 0)
/* TODO: DNS. See resolv.conf writing in network-manager.c */
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,
"MTU", &mtu,
NULL);
if (r < 0) {
if (r == -ENOENT)
return 0;
return r;
}
if (r < 0)
return r;
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 (mtu) {
uint16_t u;
}
return 0;
}
/* fall back to the default subnet masks based on address class */
/* class A, leading bits: 0 */
/* class B, leading bits 10 */
/* class C, leading bits 110 */
else
/* class D or E, no default mask. give up */
return -ERANGE;
return 0;
}