2009-03-04 11:32:55 +08:00
|
|
|
/*
|
|
|
|
* Copyright 2008, The Android Open Source Project
|
|
|
|
*
|
2015-03-04 16:13:10 +08:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2009-03-04 11:32:55 +08:00
|
|
|
*
|
2015-03-04 16:13:10 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2009-03-04 11:32:55 +08:00
|
|
|
*
|
2015-03-04 16:13:10 +08:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
2009-03-04 11:32:55 +08:00
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Utilities for managing the dhcpcd DHCP client daemon */
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2010-11-18 03:47:23 +08:00
|
|
|
#include <string.h>
|
2009-03-04 11:32:55 +08:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
|
|
|
|
#include <cutils/properties.h>
|
|
|
|
|
2009-12-15 07:41:54 +08:00
|
|
|
static const char DAEMON_NAME[] = "dhcpcd";
|
|
|
|
static const char DAEMON_PROP_NAME[] = "init.svc.dhcpcd";
|
|
|
|
static const char HOSTNAME_PROP_NAME[] = "net.hostname";
|
2009-03-04 11:32:55 +08:00
|
|
|
static const char DHCP_PROP_NAME_PREFIX[] = "dhcp";
|
2012-07-24 08:39:30 +08:00
|
|
|
static const char DHCP_CONFIG_PATH[] = "/system/etc/dhcpcd/dhcpcd.conf";
|
2010-12-22 02:31:05 +08:00
|
|
|
static const int NAP_TIME = 200; /* wait for 200ms at a time */
|
2009-03-04 11:32:55 +08:00
|
|
|
/* when polling for property values */
|
2011-02-23 17:58:36 +08:00
|
|
|
static const char DAEMON_NAME_RENEW[] = "iprenew";
|
2015-03-04 16:13:10 +08:00
|
|
|
static char errmsg[100] = "\0";
|
2012-05-24 01:30:05 +08:00
|
|
|
/* interface length for dhcpcd daemon start (dhcpcd_<interface> as defined in init.rc file)
|
|
|
|
* or for filling up system properties dhcpcd.<interface>.ipaddress, dhcpcd.<interface>.dns1
|
|
|
|
* and other properties on a successful bind
|
|
|
|
*/
|
|
|
|
#define MAX_INTERFACE_LENGTH 25
|
|
|
|
|
|
|
|
/*
|
|
|
|
* P2p interface names increase sequentially p2p-p2p0-1, p2p-p2p0-2.. after
|
|
|
|
* group formation. This does not work well with system properties which can quickly
|
|
|
|
* exhaust or for specifiying a dhcp start target in init which requires
|
|
|
|
* interface to be pre-defined in init.rc file.
|
|
|
|
*
|
|
|
|
* This function returns a common string p2p for all p2p interfaces.
|
|
|
|
*/
|
|
|
|
void get_p2p_interface_replacement(const char *interface, char *p2p_interface) {
|
|
|
|
/* Use p2p for any interface starting with p2p. */
|
|
|
|
if (strncmp(interface, "p2p",3) == 0) {
|
|
|
|
strncpy(p2p_interface, "p2p", MAX_INTERFACE_LENGTH);
|
|
|
|
} else {
|
|
|
|
strncpy(p2p_interface, interface, MAX_INTERFACE_LENGTH);
|
|
|
|
}
|
|
|
|
}
|
2009-03-04 11:32:55 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait for a system property to be assigned a specified value.
|
|
|
|
* If desired_value is NULL, then just wait for the property to
|
|
|
|
* be created with any value. maxwait is the maximum amount of
|
|
|
|
* time in seconds to wait before giving up.
|
|
|
|
*/
|
|
|
|
static int wait_for_property(const char *name, const char *desired_value, int maxwait)
|
|
|
|
{
|
|
|
|
char value[PROPERTY_VALUE_MAX] = {'\0'};
|
2010-12-22 02:31:05 +08:00
|
|
|
int maxnaps = (maxwait * 1000) / NAP_TIME;
|
2009-03-04 11:32:55 +08:00
|
|
|
|
|
|
|
if (maxnaps < 1) {
|
|
|
|
maxnaps = 1;
|
|
|
|
}
|
|
|
|
|
2015-02-27 16:49:39 +08:00
|
|
|
while (maxnaps-- >= 0) {
|
2009-03-04 11:32:55 +08:00
|
|
|
if (property_get(name, value, NULL)) {
|
2015-03-04 16:13:10 +08:00
|
|
|
if (desired_value == NULL ||
|
2009-03-04 11:32:55 +08:00
|
|
|
strcmp(value, desired_value) == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2015-02-27 16:49:39 +08:00
|
|
|
if (maxnaps >= 0) {
|
|
|
|
usleep(NAP_TIME * 1000);
|
|
|
|
}
|
2009-03-04 11:32:55 +08:00
|
|
|
}
|
|
|
|
return -1; /* failure */
|
|
|
|
}
|
|
|
|
|
2011-01-15 06:35:42 +08:00
|
|
|
static int fill_ip_info(const char *interface,
|
|
|
|
char *ipaddr,
|
|
|
|
char *gateway,
|
|
|
|
uint32_t *prefixLength,
|
2013-01-10 08:22:12 +08:00
|
|
|
char *dns[],
|
2011-01-15 06:35:42 +08:00
|
|
|
char *server,
|
2012-04-19 12:54:55 +08:00
|
|
|
uint32_t *lease,
|
2012-11-14 02:56:01 +08:00
|
|
|
char *vendorInfo,
|
2013-07-25 08:37:05 +08:00
|
|
|
char *domain,
|
|
|
|
char *mtu)
|
2009-03-04 11:32:55 +08:00
|
|
|
{
|
|
|
|
char prop_name[PROPERTY_KEY_MAX];
|
|
|
|
char prop_value[PROPERTY_VALUE_MAX];
|
2012-05-24 01:30:05 +08:00
|
|
|
/* Interface name after converting p2p0-p2p0-X to p2p to reuse system properties */
|
|
|
|
char p2p_interface[MAX_INTERFACE_LENGTH];
|
2013-01-10 08:22:12 +08:00
|
|
|
int x;
|
2012-05-24 01:30:05 +08:00
|
|
|
|
|
|
|
get_p2p_interface_replacement(interface, p2p_interface);
|
2009-03-04 11:32:55 +08:00
|
|
|
|
2012-05-24 01:30:05 +08:00
|
|
|
snprintf(prop_name, sizeof(prop_name), "%s.%s.ipaddress", DHCP_PROP_NAME_PREFIX, p2p_interface);
|
2011-01-15 06:35:42 +08:00
|
|
|
property_get(prop_name, ipaddr, NULL);
|
|
|
|
|
2012-05-24 01:30:05 +08:00
|
|
|
snprintf(prop_name, sizeof(prop_name), "%s.%s.gateway", DHCP_PROP_NAME_PREFIX, p2p_interface);
|
2011-01-15 06:35:42 +08:00
|
|
|
property_get(prop_name, gateway, NULL);
|
|
|
|
|
2012-05-24 01:30:05 +08:00
|
|
|
snprintf(prop_name, sizeof(prop_name), "%s.%s.server", DHCP_PROP_NAME_PREFIX, p2p_interface);
|
2011-04-16 07:04:24 +08:00
|
|
|
property_get(prop_name, server, NULL);
|
|
|
|
|
|
|
|
//TODO: Handle IPv6 when we change system property usage
|
2012-12-08 02:36:29 +08:00
|
|
|
if (gateway[0] == '\0' || strncmp(gateway, "0.0.0.0", 7) == 0) {
|
2011-04-16 07:04:24 +08:00
|
|
|
//DHCP server is our best bet as gateway
|
|
|
|
strncpy(gateway, server, PROPERTY_VALUE_MAX);
|
|
|
|
}
|
|
|
|
|
2012-05-24 01:30:05 +08:00
|
|
|
snprintf(prop_name, sizeof(prop_name), "%s.%s.mask", DHCP_PROP_NAME_PREFIX, p2p_interface);
|
2011-01-15 06:35:42 +08:00
|
|
|
if (property_get(prop_name, prop_value, NULL)) {
|
|
|
|
int p;
|
|
|
|
// this conversion is v4 only, but this dhcp client is v4 only anyway
|
|
|
|
in_addr_t mask = ntohl(inet_addr(prop_value));
|
|
|
|
// Check netmask is a valid IP address. ntohl gives NONE response (all 1's) for
|
|
|
|
// non 255.255.255.255 inputs. if we get that value check if it is legit..
|
|
|
|
if (mask == INADDR_NONE && strcmp(prop_value, "255.255.255.255") != 0) {
|
|
|
|
snprintf(errmsg, sizeof(errmsg), "DHCP gave invalid net mask %s", prop_value);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
for (p = 0; p < 32; p++) {
|
|
|
|
if (mask == 0) break;
|
|
|
|
// check for non-contiguous netmask, e.g., 255.254.255.0
|
|
|
|
if ((mask & 0x80000000) == 0) {
|
|
|
|
snprintf(errmsg, sizeof(errmsg), "DHCP gave invalid net mask %s", prop_value);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
mask = mask << 1;
|
|
|
|
}
|
|
|
|
*prefixLength = p;
|
2009-03-04 11:32:55 +08:00
|
|
|
}
|
2011-01-15 06:35:42 +08:00
|
|
|
|
2013-01-10 08:22:12 +08:00
|
|
|
for (x=0; dns[x] != NULL; x++) {
|
|
|
|
snprintf(prop_name, sizeof(prop_name), "%s.%s.dns%d", DHCP_PROP_NAME_PREFIX, p2p_interface, x+1);
|
|
|
|
property_get(prop_name, dns[x], NULL);
|
|
|
|
}
|
2011-01-15 06:35:42 +08:00
|
|
|
|
2012-05-24 01:30:05 +08:00
|
|
|
snprintf(prop_name, sizeof(prop_name), "%s.%s.leasetime", DHCP_PROP_NAME_PREFIX, p2p_interface);
|
2009-03-04 11:32:55 +08:00
|
|
|
if (property_get(prop_name, prop_value, NULL)) {
|
|
|
|
*lease = atol(prop_value);
|
|
|
|
}
|
2012-04-19 12:54:55 +08:00
|
|
|
|
2012-05-24 01:30:05 +08:00
|
|
|
snprintf(prop_name, sizeof(prop_name), "%s.%s.vendorInfo", DHCP_PROP_NAME_PREFIX,
|
|
|
|
p2p_interface);
|
2012-04-19 12:54:55 +08:00
|
|
|
property_get(prop_name, vendorInfo, NULL);
|
|
|
|
|
2012-11-14 02:56:01 +08:00
|
|
|
snprintf(prop_name, sizeof(prop_name), "%s.%s.domain", DHCP_PROP_NAME_PREFIX,
|
|
|
|
p2p_interface);
|
|
|
|
property_get(prop_name, domain, NULL);
|
|
|
|
|
2013-07-25 08:37:05 +08:00
|
|
|
snprintf(prop_name, sizeof(prop_name), "%s.%s.mtu", DHCP_PROP_NAME_PREFIX,
|
|
|
|
p2p_interface);
|
|
|
|
property_get(prop_name, mtu, NULL);
|
|
|
|
|
2011-01-15 06:35:42 +08:00
|
|
|
return 0;
|
2009-03-04 11:32:55 +08:00
|
|
|
}
|
|
|
|
|
2015-02-19 18:15:34 +08:00
|
|
|
/*
|
|
|
|
* Get any available DHCP results.
|
|
|
|
*/
|
|
|
|
int dhcp_get_results(const char *interface,
|
|
|
|
char *ipaddr,
|
|
|
|
char *gateway,
|
|
|
|
uint32_t *prefixLength,
|
|
|
|
char *dns[],
|
|
|
|
char *server,
|
|
|
|
uint32_t *lease,
|
|
|
|
char *vendorInfo,
|
|
|
|
char *domain,
|
|
|
|
char *mtu)
|
|
|
|
{
|
|
|
|
char result_prop_name[PROPERTY_KEY_MAX];
|
|
|
|
char prop_value[PROPERTY_VALUE_MAX];
|
|
|
|
|
|
|
|
/* Interface name after converting p2p0-p2p0-X to p2p to reuse system properties */
|
|
|
|
char p2p_interface[MAX_INTERFACE_LENGTH];
|
|
|
|
get_p2p_interface_replacement(interface, p2p_interface);
|
|
|
|
snprintf(result_prop_name, sizeof(result_prop_name), "%s.%s.result",
|
|
|
|
DHCP_PROP_NAME_PREFIX,
|
|
|
|
p2p_interface);
|
|
|
|
|
|
|
|
memset(prop_value, '\0', PROPERTY_VALUE_MAX);
|
|
|
|
if (!property_get(result_prop_name, prop_value, NULL)) {
|
|
|
|
snprintf(errmsg, sizeof(errmsg), "%s", "DHCP result property was not set");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (strcmp(prop_value, "ok") == 0) {
|
|
|
|
if (fill_ip_info(interface, ipaddr, gateway, prefixLength, dns,
|
|
|
|
server, lease, vendorInfo, domain, mtu) == -1) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
snprintf(errmsg, sizeof(errmsg), "DHCP result was %s", prop_value);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-04 11:32:55 +08:00
|
|
|
/*
|
|
|
|
* Start the dhcp client daemon, and wait for it to finish
|
|
|
|
* configuring the interface.
|
2011-11-10 03:10:50 +08:00
|
|
|
*
|
|
|
|
* The device init.rc file needs a corresponding entry for this work.
|
|
|
|
*
|
|
|
|
* Example:
|
2012-07-24 08:39:30 +08:00
|
|
|
* service dhcpcd_<interface> /system/bin/dhcpcd -ABKL -f dhcpcd.conf
|
2009-03-04 11:32:55 +08:00
|
|
|
*/
|
2015-02-19 18:15:34 +08:00
|
|
|
int dhcp_start(const char *interface)
|
2009-03-04 11:32:55 +08:00
|
|
|
{
|
|
|
|
char result_prop_name[PROPERTY_KEY_MAX];
|
2011-02-23 17:58:36 +08:00
|
|
|
char daemon_prop_name[PROPERTY_KEY_MAX];
|
2009-03-04 11:32:55 +08:00
|
|
|
char prop_value[PROPERTY_VALUE_MAX] = {'\0'};
|
2012-07-24 08:39:30 +08:00
|
|
|
char daemon_cmd[PROPERTY_VALUE_MAX * 2 + sizeof(DHCP_CONFIG_PATH)];
|
2009-03-04 11:32:55 +08:00
|
|
|
const char *ctrl_prop = "ctl.start";
|
|
|
|
const char *desired_status = "running";
|
2012-05-24 01:30:05 +08:00
|
|
|
/* Interface name after converting p2p0-p2p0-X to p2p to reuse system properties */
|
|
|
|
char p2p_interface[MAX_INTERFACE_LENGTH];
|
2011-07-30 03:07:34 +08:00
|
|
|
|
2012-05-24 01:30:05 +08:00
|
|
|
get_p2p_interface_replacement(interface, p2p_interface);
|
2009-03-04 11:32:55 +08:00
|
|
|
|
|
|
|
snprintf(result_prop_name, sizeof(result_prop_name), "%s.%s.result",
|
|
|
|
DHCP_PROP_NAME_PREFIX,
|
2012-05-24 01:30:05 +08:00
|
|
|
p2p_interface);
|
2011-02-23 17:58:36 +08:00
|
|
|
|
|
|
|
snprintf(daemon_prop_name, sizeof(daemon_prop_name), "%s_%s",
|
|
|
|
DAEMON_PROP_NAME,
|
2012-05-24 01:30:05 +08:00
|
|
|
p2p_interface);
|
2011-02-23 17:58:36 +08:00
|
|
|
|
2009-03-04 11:32:55 +08:00
|
|
|
/* Erase any previous setting of the dhcp result property */
|
|
|
|
property_set(result_prop_name, "");
|
|
|
|
|
|
|
|
/* Start the daemon and wait until it's ready */
|
2009-12-15 07:41:54 +08:00
|
|
|
if (property_get(HOSTNAME_PROP_NAME, prop_value, NULL) && (prop_value[0] != '\0'))
|
2012-07-24 08:39:30 +08:00
|
|
|
snprintf(daemon_cmd, sizeof(daemon_cmd), "%s_%s:-f %s -h %s %s", DAEMON_NAME,
|
|
|
|
p2p_interface, DHCP_CONFIG_PATH, prop_value, interface);
|
2009-12-15 07:41:54 +08:00
|
|
|
else
|
2012-07-24 08:39:30 +08:00
|
|
|
snprintf(daemon_cmd, sizeof(daemon_cmd), "%s_%s:-f %s %s", DAEMON_NAME,
|
2013-01-05 01:53:42 +08:00
|
|
|
p2p_interface, DHCP_CONFIG_PATH, interface);
|
2009-12-15 07:41:54 +08:00
|
|
|
memset(prop_value, '\0', PROPERTY_VALUE_MAX);
|
|
|
|
property_set(ctrl_prop, daemon_cmd);
|
2011-02-23 17:58:36 +08:00
|
|
|
if (wait_for_property(daemon_prop_name, desired_status, 10) < 0) {
|
2009-03-04 11:32:55 +08:00
|
|
|
snprintf(errmsg, sizeof(errmsg), "%s", "Timed out waiting for dhcpcd to start");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Wait for the daemon to return a result */
|
|
|
|
if (wait_for_property(result_prop_name, NULL, 30) < 0) {
|
|
|
|
snprintf(errmsg, sizeof(errmsg), "%s", "Timed out waiting for DHCP to finish");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-02-19 18:15:34 +08:00
|
|
|
return 0;
|
2009-03-04 11:32:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stop the DHCP client daemon.
|
|
|
|
*/
|
|
|
|
int dhcp_stop(const char *interface)
|
|
|
|
{
|
|
|
|
char result_prop_name[PROPERTY_KEY_MAX];
|
2011-02-23 17:58:36 +08:00
|
|
|
char daemon_prop_name[PROPERTY_KEY_MAX];
|
|
|
|
char daemon_cmd[PROPERTY_VALUE_MAX * 2];
|
2009-03-04 11:32:55 +08:00
|
|
|
const char *ctrl_prop = "ctl.stop";
|
|
|
|
const char *desired_status = "stopped";
|
|
|
|
|
2012-05-24 01:30:05 +08:00
|
|
|
char p2p_interface[MAX_INTERFACE_LENGTH];
|
2011-07-30 03:07:34 +08:00
|
|
|
|
2012-05-24 01:30:05 +08:00
|
|
|
get_p2p_interface_replacement(interface, p2p_interface);
|
2011-07-30 03:07:34 +08:00
|
|
|
|
2009-03-04 11:32:55 +08:00
|
|
|
snprintf(result_prop_name, sizeof(result_prop_name), "%s.%s.result",
|
|
|
|
DHCP_PROP_NAME_PREFIX,
|
2012-05-24 01:30:05 +08:00
|
|
|
p2p_interface);
|
2011-02-23 17:58:36 +08:00
|
|
|
|
|
|
|
snprintf(daemon_prop_name, sizeof(daemon_prop_name), "%s_%s",
|
|
|
|
DAEMON_PROP_NAME,
|
2012-05-24 01:30:05 +08:00
|
|
|
p2p_interface);
|
2011-02-23 17:58:36 +08:00
|
|
|
|
2012-05-24 01:30:05 +08:00
|
|
|
snprintf(daemon_cmd, sizeof(daemon_cmd), "%s_%s", DAEMON_NAME, p2p_interface);
|
2011-02-23 17:58:36 +08:00
|
|
|
|
2009-03-04 11:32:55 +08:00
|
|
|
/* Stop the daemon and wait until it's reported to be stopped */
|
2011-02-23 17:58:36 +08:00
|
|
|
property_set(ctrl_prop, daemon_cmd);
|
|
|
|
if (wait_for_property(daemon_prop_name, desired_status, 5) < 0) {
|
2009-03-04 11:32:55 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
property_set(result_prop_name, "failed");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Release the current DHCP client lease.
|
|
|
|
*/
|
|
|
|
int dhcp_release_lease(const char *interface)
|
|
|
|
{
|
2011-02-23 17:58:36 +08:00
|
|
|
char daemon_prop_name[PROPERTY_KEY_MAX];
|
|
|
|
char daemon_cmd[PROPERTY_VALUE_MAX * 2];
|
2009-03-04 11:32:55 +08:00
|
|
|
const char *ctrl_prop = "ctl.stop";
|
|
|
|
const char *desired_status = "stopped";
|
|
|
|
|
2012-05-24 01:30:05 +08:00
|
|
|
char p2p_interface[MAX_INTERFACE_LENGTH];
|
2011-07-30 03:07:34 +08:00
|
|
|
|
2012-05-24 01:30:05 +08:00
|
|
|
get_p2p_interface_replacement(interface, p2p_interface);
|
2011-07-30 03:07:34 +08:00
|
|
|
|
2011-02-23 17:58:36 +08:00
|
|
|
snprintf(daemon_prop_name, sizeof(daemon_prop_name), "%s_%s",
|
|
|
|
DAEMON_PROP_NAME,
|
2012-05-24 01:30:05 +08:00
|
|
|
p2p_interface);
|
2011-02-23 17:58:36 +08:00
|
|
|
|
2012-05-24 01:30:05 +08:00
|
|
|
snprintf(daemon_cmd, sizeof(daemon_cmd), "%s_%s", DAEMON_NAME, p2p_interface);
|
2011-02-23 17:58:36 +08:00
|
|
|
|
2009-03-04 11:32:55 +08:00
|
|
|
/* Stop the daemon and wait until it's reported to be stopped */
|
2011-02-23 17:58:36 +08:00
|
|
|
property_set(ctrl_prop, daemon_cmd);
|
|
|
|
if (wait_for_property(daemon_prop_name, desired_status, 5) < 0) {
|
2009-03-04 11:32:55 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *dhcp_get_errmsg() {
|
|
|
|
return errmsg;
|
|
|
|
}
|
2011-02-23 17:58:36 +08:00
|
|
|
|
|
|
|
/**
|
2011-11-10 03:10:50 +08:00
|
|
|
* The device init.rc file needs a corresponding entry.
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* service iprenew_<interface> /system/bin/dhcpcd -n
|
|
|
|
*
|
2011-02-23 17:58:36 +08:00
|
|
|
*/
|
2015-02-19 18:15:34 +08:00
|
|
|
int dhcp_start_renew(const char *interface)
|
2011-02-23 17:58:36 +08:00
|
|
|
{
|
|
|
|
char result_prop_name[PROPERTY_KEY_MAX];
|
|
|
|
char prop_value[PROPERTY_VALUE_MAX] = {'\0'};
|
|
|
|
char daemon_cmd[PROPERTY_VALUE_MAX * 2];
|
|
|
|
const char *ctrl_prop = "ctl.start";
|
|
|
|
|
2012-05-24 01:30:05 +08:00
|
|
|
char p2p_interface[MAX_INTERFACE_LENGTH];
|
2011-07-30 03:07:34 +08:00
|
|
|
|
2012-05-24 01:30:05 +08:00
|
|
|
get_p2p_interface_replacement(interface, p2p_interface);
|
2011-07-30 03:07:34 +08:00
|
|
|
|
2011-02-23 17:58:36 +08:00
|
|
|
snprintf(result_prop_name, sizeof(result_prop_name), "%s.%s.result",
|
|
|
|
DHCP_PROP_NAME_PREFIX,
|
2012-05-24 01:30:05 +08:00
|
|
|
p2p_interface);
|
2011-02-23 17:58:36 +08:00
|
|
|
|
|
|
|
/* Erase any previous setting of the dhcp result property */
|
|
|
|
property_set(result_prop_name, "");
|
|
|
|
|
|
|
|
/* Start the renew daemon and wait until it's ready */
|
2011-07-30 03:07:34 +08:00
|
|
|
snprintf(daemon_cmd, sizeof(daemon_cmd), "%s_%s:%s", DAEMON_NAME_RENEW,
|
2012-05-24 01:30:05 +08:00
|
|
|
p2p_interface, interface);
|
2011-02-23 17:58:36 +08:00
|
|
|
memset(prop_value, '\0', PROPERTY_VALUE_MAX);
|
|
|
|
property_set(ctrl_prop, daemon_cmd);
|
|
|
|
|
|
|
|
/* Wait for the daemon to return a result */
|
|
|
|
if (wait_for_property(result_prop_name, NULL, 30) < 0) {
|
|
|
|
snprintf(errmsg, sizeof(errmsg), "%s", "Timed out waiting for DHCP Renew to finish");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-02-19 18:15:34 +08:00
|
|
|
return 0;
|
2011-02-23 17:58:36 +08:00
|
|
|
}
|