2008-04-12 00:14:55 +08:00
|
|
|
/*
|
|
|
|
* dhcpcd - DHCP client daemon
|
2011-03-25 01:59:20 +08:00
|
|
|
* Copyright (c) 2006-2011 Roy Marples <roy@marples.name>
|
2008-04-12 00:14:55 +08:00
|
|
|
* All rights reserved
|
|
|
|
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/ioctl.h>
|
2008-09-02 23:11:01 +08:00
|
|
|
#include <sys/param.h>
|
2008-04-12 00:14:55 +08:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
2008-09-04 07:36:46 +08:00
|
|
|
#include <arpa/inet.h>
|
2008-04-12 00:14:55 +08:00
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_arp.h>
|
2009-04-17 21:31:41 +08:00
|
|
|
#ifdef AF_LINK
|
|
|
|
# include <net/if_dl.h>
|
|
|
|
# include <net/if_types.h>
|
|
|
|
#endif
|
2008-04-12 00:14:55 +08:00
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/ip.h>
|
|
|
|
#define __FAVOR_BSD /* Nasty glibc hack so we can use BSD semantics for UDP */
|
|
|
|
#include <netinet/udp.h>
|
|
|
|
#undef __FAVOR_BSD
|
2009-04-17 20:49:25 +08:00
|
|
|
#ifdef AF_PACKET
|
|
|
|
# include <netpacket/packet.h>
|
|
|
|
#endif
|
2008-07-17 06:23:07 +08:00
|
|
|
#ifdef SIOCGIFMEDIA
|
2009-04-17 20:49:25 +08:00
|
|
|
# include <net/if_media.h>
|
2008-09-02 23:11:01 +08:00
|
|
|
#endif
|
2008-04-12 00:14:55 +08:00
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <errno.h>
|
2009-04-17 20:49:25 +08:00
|
|
|
#include <ifaddrs.h>
|
|
|
|
#include <fnmatch.h>
|
2008-04-12 00:14:55 +08:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2008-09-06 02:24:34 +08:00
|
|
|
#include <syslog.h>
|
2008-04-12 00:14:55 +08:00
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "common.h"
|
|
|
|
#include "dhcp.h"
|
2008-09-02 21:28:11 +08:00
|
|
|
#include "if-options.h"
|
2012-02-13 16:37:54 +08:00
|
|
|
#include "ipv6rs.h"
|
2008-04-12 00:14:55 +08:00
|
|
|
#include "net.h"
|
2008-05-15 20:48:01 +08:00
|
|
|
#include "signals.h"
|
2008-04-12 00:14:55 +08:00
|
|
|
|
2008-09-04 16:31:00 +08:00
|
|
|
static char hwaddr_buffer[(HWADDR_LEN * 3) + 1];
|
|
|
|
|
2009-10-15 08:30:54 +08:00
|
|
|
int socket_afnet = -1;
|
|
|
|
|
2008-04-12 00:14:55 +08:00
|
|
|
int
|
|
|
|
inet_ntocidr(struct in_addr address)
|
|
|
|
{
|
|
|
|
int cidr = 0;
|
|
|
|
uint32_t mask = htonl(address.s_addr);
|
|
|
|
|
|
|
|
while (mask) {
|
|
|
|
cidr++;
|
|
|
|
mask <<= 1;
|
|
|
|
}
|
|
|
|
return cidr;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-08-22 17:48:25 +08:00
|
|
|
inet_cidrtoaddr(int cidr, struct in_addr *addr)
|
2008-04-12 00:14:55 +08:00
|
|
|
{
|
|
|
|
int ocets;
|
|
|
|
|
2009-03-06 00:31:44 +08:00
|
|
|
if (cidr < 1 || cidr > 32) {
|
2008-04-12 00:14:55 +08:00
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
ocets = (cidr + 7) / 8;
|
|
|
|
|
|
|
|
addr->s_addr = 0;
|
|
|
|
if (ocets > 0) {
|
|
|
|
memset(&addr->s_addr, 255, (size_t)ocets - 1);
|
2009-08-12 16:38:41 +08:00
|
|
|
memset((unsigned char *)&addr->s_addr + (ocets - 1),
|
2009-02-12 01:56:22 +08:00
|
|
|
(256 - (1 << (32 - cidr) % 8)), 1);
|
2008-04-12 00:14:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
get_netmask(uint32_t addr)
|
|
|
|
{
|
|
|
|
uint32_t dst;
|
|
|
|
|
|
|
|
if (addr == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
dst = htonl(addr);
|
|
|
|
if (IN_CLASSA(dst))
|
|
|
|
return ntohl(IN_CLASSA_NET);
|
2008-08-26 21:27:07 +08:00
|
|
|
if (IN_CLASSB(dst))
|
2008-04-12 00:14:55 +08:00
|
|
|
return ntohl(IN_CLASSB_NET);
|
2008-08-26 21:27:07 +08:00
|
|
|
if (IN_CLASSC(dst))
|
2008-04-12 00:14:55 +08:00
|
|
|
return ntohl(IN_CLASSC_NET);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
hwaddr_ntoa(const unsigned char *hwaddr, size_t hwlen)
|
|
|
|
{
|
2008-09-04 16:31:00 +08:00
|
|
|
char *p = hwaddr_buffer;
|
2008-04-12 00:14:55 +08:00
|
|
|
size_t i;
|
|
|
|
|
2008-09-16 17:55:46 +08:00
|
|
|
for (i = 0; i < hwlen && i < HWADDR_LEN; i++) {
|
2008-04-12 00:14:55 +08:00
|
|
|
if (i > 0)
|
|
|
|
*p ++= ':';
|
|
|
|
p += snprintf(p, 3, "%.2x", hwaddr[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
*p ++= '\0';
|
|
|
|
|
2008-09-04 16:31:00 +08:00
|
|
|
return hwaddr_buffer;
|
2008-04-12 00:14:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
hwaddr_aton(unsigned char *buffer, const char *addr)
|
|
|
|
{
|
|
|
|
char c[3];
|
|
|
|
const char *p = addr;
|
|
|
|
unsigned char *bp = buffer;
|
|
|
|
size_t len = 0;
|
|
|
|
|
|
|
|
c[2] = '\0';
|
|
|
|
while (*p) {
|
|
|
|
c[0] = *p++;
|
|
|
|
c[1] = *p++;
|
|
|
|
/* Ensure that digits are hex */
|
2008-04-17 18:08:48 +08:00
|
|
|
if (isxdigit((unsigned char)c[0]) == 0 ||
|
|
|
|
isxdigit((unsigned char)c[1]) == 0)
|
2008-04-17 17:57:19 +08:00
|
|
|
{
|
2008-04-12 00:14:55 +08:00
|
|
|
errno = EINVAL;
|
|
|
|
return 0;
|
|
|
|
}
|
2008-07-02 18:29:24 +08:00
|
|
|
/* We should have at least two entries 00:01 */
|
|
|
|
if (len == 0 && *p == '\0') {
|
|
|
|
errno = EINVAL;
|
|
|
|
return 0;
|
|
|
|
}
|
2008-07-02 17:48:53 +08:00
|
|
|
/* Ensure that next data is EOL or a seperator with data */
|
|
|
|
if (!(*p == '\0' || (*p == ':' && *(p + 1) != '\0'))) {
|
|
|
|
errno = EINVAL;
|
|
|
|
return 0;
|
|
|
|
}
|
2008-06-29 18:55:21 +08:00
|
|
|
if (*p)
|
|
|
|
p++;
|
2008-04-12 00:14:55 +08:00
|
|
|
if (bp)
|
|
|
|
*bp++ = (unsigned char)strtol(c, NULL, 16);
|
2008-07-02 18:29:24 +08:00
|
|
|
len++;
|
2008-04-12 00:14:55 +08:00
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2008-09-02 21:28:11 +08:00
|
|
|
struct interface *
|
|
|
|
init_interface(const char *ifname)
|
|
|
|
{
|
|
|
|
struct ifreq ifr;
|
|
|
|
struct interface *iface = NULL;
|
|
|
|
|
|
|
|
memset(&ifr, 0, sizeof(ifr));
|
|
|
|
strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
|
2009-10-15 08:30:54 +08:00
|
|
|
if (ioctl(socket_afnet, SIOCGIFFLAGS, &ifr) == -1)
|
2008-09-02 21:28:11 +08:00
|
|
|
goto eexit;
|
|
|
|
|
|
|
|
iface = xzalloc(sizeof(*iface));
|
|
|
|
strlcpy(iface->name, ifname, sizeof(iface->name));
|
2009-03-20 01:52:12 +08:00
|
|
|
iface->flags = ifr.ifr_flags;
|
2008-09-17 18:32:55 +08:00
|
|
|
/* We reserve the 100 range for virtual interfaces, if and when
|
|
|
|
* we can work them out. */
|
|
|
|
iface->metric = 200 + if_nametoindex(iface->name);
|
2009-01-23 06:52:41 +08:00
|
|
|
if (getifssid(ifname, iface->ssid) != -1) {
|
|
|
|
iface->wireless = 1;
|
2008-09-17 18:32:55 +08:00
|
|
|
iface->metric += 100;
|
2009-01-23 06:52:41 +08:00
|
|
|
}
|
2008-09-02 21:28:11 +08:00
|
|
|
|
2009-10-15 08:30:54 +08:00
|
|
|
if (ioctl(socket_afnet, SIOCGIFMTU, &ifr) == -1)
|
2008-09-02 21:28:11 +08:00
|
|
|
goto eexit;
|
|
|
|
/* Ensure that the MTU is big enough for DHCP */
|
|
|
|
if (ifr.ifr_mtu < MTU_MIN) {
|
|
|
|
ifr.ifr_mtu = MTU_MIN;
|
|
|
|
strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
|
2009-10-15 08:30:54 +08:00
|
|
|
if (ioctl(socket_afnet, SIOCSIFMTU, &ifr) == -1)
|
2008-09-02 21:28:11 +08:00
|
|
|
goto eexit;
|
|
|
|
}
|
|
|
|
|
2008-09-02 23:11:01 +08:00
|
|
|
snprintf(iface->leasefile, sizeof(iface->leasefile),
|
2009-02-12 01:56:22 +08:00
|
|
|
LEASEFILE, ifname);
|
2008-09-02 21:28:11 +08:00
|
|
|
/* 0 is a valid fd, so init to -1 */
|
|
|
|
iface->raw_fd = -1;
|
|
|
|
iface->udp_fd = -1;
|
|
|
|
iface->arp_fd = -1;
|
2009-08-06 05:16:09 +08:00
|
|
|
goto exit;
|
2008-09-02 21:28:11 +08:00
|
|
|
|
|
|
|
eexit:
|
|
|
|
free(iface);
|
2009-08-06 05:16:09 +08:00
|
|
|
iface = NULL;
|
|
|
|
exit:
|
|
|
|
return iface;
|
2008-09-02 21:28:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
free_interface(struct interface *iface)
|
|
|
|
{
|
|
|
|
if (!iface)
|
|
|
|
return;
|
2012-02-13 16:37:54 +08:00
|
|
|
ipv6rs_free(iface);
|
2008-09-02 21:28:11 +08:00
|
|
|
if (iface->state) {
|
|
|
|
free_options(iface->state->options);
|
|
|
|
free(iface->state->old);
|
|
|
|
free(iface->state->new);
|
|
|
|
free(iface->state->offer);
|
|
|
|
free(iface->state);
|
|
|
|
}
|
2012-03-28 00:30:33 +08:00
|
|
|
free(iface->buffer);
|
2008-09-02 21:28:11 +08:00
|
|
|
free(iface->clientid);
|
|
|
|
free(iface);
|
|
|
|
}
|
|
|
|
|
2009-10-14 23:16:07 +08:00
|
|
|
int
|
|
|
|
carrier_status(struct interface *iface)
|
|
|
|
{
|
2009-10-15 08:30:54 +08:00
|
|
|
int ret;
|
2009-10-14 23:16:07 +08:00
|
|
|
struct ifreq ifr;
|
|
|
|
#ifdef SIOCGIFMEDIA
|
|
|
|
struct ifmediareq ifmr;
|
|
|
|
#endif
|
|
|
|
#ifdef __linux__
|
|
|
|
char *p;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
memset(&ifr, 0, sizeof(ifr));
|
|
|
|
strlcpy(ifr.ifr_name, iface->name, sizeof(ifr.ifr_name));
|
|
|
|
#ifdef __linux__
|
|
|
|
/* We can only test the real interface up */
|
|
|
|
if ((p = strchr(ifr.ifr_name, ':')))
|
|
|
|
*p = '\0';
|
|
|
|
#endif
|
|
|
|
|
2009-10-15 08:30:54 +08:00
|
|
|
if (ioctl(socket_afnet, SIOCGIFFLAGS, &ifr) == -1)
|
2009-10-14 23:16:07 +08:00
|
|
|
return -1;
|
|
|
|
iface->flags = ifr.ifr_flags;
|
|
|
|
|
|
|
|
ret = -1;
|
|
|
|
#ifdef SIOCGIFMEDIA
|
|
|
|
memset(&ifmr, 0, sizeof(ifmr));
|
|
|
|
strlcpy(ifmr.ifm_name, iface->name, sizeof(ifmr.ifm_name));
|
2009-10-15 08:30:54 +08:00
|
|
|
if (ioctl(socket_afnet, SIOCGIFMEDIA, &ifmr) != -1 &&
|
2009-10-14 23:16:07 +08:00
|
|
|
ifmr.ifm_status & IFM_AVALID)
|
|
|
|
ret = (ifmr.ifm_status & IFM_ACTIVE) ? 1 : 0;
|
|
|
|
#endif
|
|
|
|
if (ret == -1)
|
|
|
|
ret = (ifr.ifr_flags & IFF_RUNNING) ? 1 : 0;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
up_interface(struct interface *iface)
|
|
|
|
{
|
|
|
|
struct ifreq ifr;
|
|
|
|
int retval = -1;
|
|
|
|
#ifdef __linux__
|
|
|
|
char *p;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
memset(&ifr, 0, sizeof(ifr));
|
|
|
|
strlcpy(ifr.ifr_name, iface->name, sizeof(ifr.ifr_name));
|
|
|
|
#ifdef __linux__
|
|
|
|
/* We can only bring the real interface up */
|
|
|
|
if ((p = strchr(ifr.ifr_name, ':')))
|
|
|
|
*p = '\0';
|
|
|
|
#endif
|
2009-10-15 08:30:54 +08:00
|
|
|
if (ioctl(socket_afnet, SIOCGIFFLAGS, &ifr) == 0) {
|
2009-10-14 23:16:07 +08:00
|
|
|
if ((ifr.ifr_flags & IFF_UP))
|
|
|
|
retval = 0;
|
|
|
|
else {
|
|
|
|
ifr.ifr_flags |= IFF_UP;
|
2009-10-15 08:30:54 +08:00
|
|
|
if (ioctl(socket_afnet, SIOCSIFFLAGS, &ifr) == 0)
|
2009-10-14 23:16:07 +08:00
|
|
|
retval = 0;
|
|
|
|
}
|
|
|
|
iface->flags = ifr.ifr_flags;
|
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2009-04-17 20:49:25 +08:00
|
|
|
struct interface *
|
|
|
|
discover_interfaces(int argc, char * const *argv)
|
2008-04-12 00:14:55 +08:00
|
|
|
{
|
2009-04-17 20:49:25 +08:00
|
|
|
struct ifaddrs *ifaddrs, *ifa;
|
|
|
|
char *p;
|
2012-03-20 17:19:01 +08:00
|
|
|
int i, sdl_type;
|
2009-04-17 20:49:25 +08:00
|
|
|
struct interface *ifp, *ifs, *ifl;
|
|
|
|
#ifdef __linux__
|
|
|
|
char ifn[IF_NAMESIZE];
|
|
|
|
#endif
|
|
|
|
#ifdef AF_LINK
|
|
|
|
const struct sockaddr_dl *sdl;
|
2010-08-04 14:44:56 +08:00
|
|
|
#ifdef IFLR_ACTIVE
|
|
|
|
struct if_laddrreq iflr;
|
|
|
|
int socket_aflink;
|
|
|
|
|
|
|
|
socket_aflink = socket(AF_LINK, SOCK_DGRAM, 0);
|
|
|
|
if (socket_aflink == -1)
|
|
|
|
return NULL;
|
|
|
|
memset(&iflr, 0, sizeof(iflr));
|
|
|
|
#endif
|
2009-04-17 20:49:25 +08:00
|
|
|
#elif AF_PACKET
|
|
|
|
const struct sockaddr_ll *sll;
|
|
|
|
#endif
|
2008-04-12 00:14:55 +08:00
|
|
|
|
2009-04-17 20:49:25 +08:00
|
|
|
if (getifaddrs(&ifaddrs) == -1)
|
|
|
|
return NULL;
|
2008-04-12 00:14:55 +08:00
|
|
|
|
2009-04-17 20:49:25 +08:00
|
|
|
ifs = ifl = NULL;
|
|
|
|
for (ifa = ifaddrs; ifa; ifa = ifa->ifa_next) {
|
2009-05-11 15:16:24 +08:00
|
|
|
if (ifa->ifa_addr != NULL) {
|
2009-04-17 20:49:25 +08:00
|
|
|
#ifdef AF_LINK
|
2009-05-11 15:16:24 +08:00
|
|
|
if (ifa->ifa_addr->sa_family != AF_LINK)
|
|
|
|
continue;
|
2009-04-17 20:49:25 +08:00
|
|
|
#elif AF_PACKET
|
2009-05-11 15:16:24 +08:00
|
|
|
if (ifa->ifa_addr->sa_family != AF_PACKET)
|
|
|
|
continue;
|
2009-04-17 20:49:25 +08:00
|
|
|
#endif
|
2009-05-11 15:16:24 +08:00
|
|
|
}
|
|
|
|
|
2009-04-20 02:23:47 +08:00
|
|
|
/* It's possible for an interface to have >1 AF_LINK.
|
|
|
|
* For our purposes, we use the first one. */
|
|
|
|
for (ifp = ifs; ifp; ifp = ifp->next)
|
|
|
|
if (strcmp(ifp->name, ifa->ifa_name) == 0)
|
|
|
|
break;
|
|
|
|
if (ifp)
|
|
|
|
continue;
|
2009-04-17 20:49:25 +08:00
|
|
|
if (argc > 0) {
|
|
|
|
for (i = 0; i < argc; i++) {
|
|
|
|
#ifdef __linux__
|
|
|
|
/* Check the real interface name */
|
|
|
|
strlcpy(ifn, argv[i], sizeof(ifn));
|
|
|
|
p = strchr(ifn, ':');
|
|
|
|
if (p)
|
|
|
|
*p = '\0';
|
|
|
|
if (strcmp(ifn, ifa->ifa_name) == 0)
|
|
|
|
break;
|
|
|
|
#else
|
|
|
|
if (strcmp(argv[i], ifa->ifa_name) == 0)
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
if (i == argc)
|
|
|
|
continue;
|
|
|
|
p = argv[i];
|
|
|
|
} else {
|
2009-09-01 15:45:11 +08:00
|
|
|
/* -1 means we're discovering against a specific
|
|
|
|
* interface, but we still need the below rules
|
|
|
|
* to apply. */
|
|
|
|
if (argc == -1 && strcmp(argv[0], ifa->ifa_name) != 0)
|
|
|
|
continue;
|
2009-04-17 20:49:25 +08:00
|
|
|
for (i = 0; i < ifdc; i++)
|
|
|
|
if (!fnmatch(ifdv[i], ifa->ifa_name, 0))
|
|
|
|
break;
|
|
|
|
if (i < ifdc)
|
|
|
|
continue;
|
|
|
|
for (i = 0; i < ifac; i++)
|
|
|
|
if (!fnmatch(ifav[i], ifa->ifa_name, 0))
|
|
|
|
break;
|
|
|
|
if (ifac && i == ifac)
|
|
|
|
continue;
|
|
|
|
p = ifa->ifa_name;
|
|
|
|
}
|
|
|
|
if ((ifp = init_interface(p)) == NULL)
|
|
|
|
continue;
|
2009-08-06 05:16:09 +08:00
|
|
|
|
2009-10-14 23:16:07 +08:00
|
|
|
/* Bring the interface up if not already */
|
2009-11-20 23:14:27 +08:00
|
|
|
if (!(ifp->flags & IFF_UP)
|
2009-10-14 23:16:07 +08:00
|
|
|
#ifdef SIOCGIFMEDIA
|
2009-11-20 23:14:27 +08:00
|
|
|
&& carrier_status(ifp) != -1
|
2009-10-14 23:16:07 +08:00
|
|
|
#endif
|
2009-11-20 23:14:27 +08:00
|
|
|
)
|
|
|
|
{
|
|
|
|
if (up_interface(ifp) == 0)
|
|
|
|
options |= DHCPCD_WAITUP;
|
|
|
|
else
|
|
|
|
syslog(LOG_ERR, "%s: up_interface: %m", ifp->name);
|
|
|
|
}
|
2009-08-06 05:16:09 +08:00
|
|
|
|
2012-03-20 17:19:01 +08:00
|
|
|
sdl_type = 0;
|
2009-04-17 20:49:25 +08:00
|
|
|
/* Don't allow loopback unless explicit */
|
|
|
|
if (ifp->flags & IFF_LOOPBACK) {
|
2009-04-21 03:40:09 +08:00
|
|
|
if (argc == 0 && ifac == 0) {
|
2009-04-17 20:49:25 +08:00
|
|
|
free_interface(ifp);
|
|
|
|
continue;
|
2008-04-12 00:14:55 +08:00
|
|
|
}
|
2009-05-11 15:16:24 +08:00
|
|
|
} else if (ifa->ifa_addr != NULL) {
|
2009-04-17 20:49:25 +08:00
|
|
|
#ifdef AF_LINK
|
|
|
|
sdl = (const struct sockaddr_dl *)(void *)ifa->ifa_addr;
|
2010-08-04 14:44:56 +08:00
|
|
|
|
|
|
|
#ifdef IFLR_ACTIVE
|
|
|
|
/* We need to check for active address */
|
|
|
|
strlcpy(iflr.iflr_name, ifp->name,
|
|
|
|
sizeof(iflr.iflr_name));
|
|
|
|
memcpy(&iflr.addr, ifa->ifa_addr,
|
|
|
|
MIN(ifa->ifa_addr->sa_len, sizeof(iflr.addr)));
|
|
|
|
iflr.flags = IFLR_PREFIX;
|
|
|
|
iflr.prefixlen = sdl->sdl_alen * NBBY;
|
|
|
|
if (ioctl(socket_aflink, SIOCGLIFADDR, &iflr) == -1 ||
|
|
|
|
!(iflr.flags & IFLR_ACTIVE))
|
|
|
|
{
|
|
|
|
free_interface(ifp);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-03-20 17:19:01 +08:00
|
|
|
sdl_type = sdl->sdl_type;
|
2009-04-17 20:49:25 +08:00
|
|
|
switch(sdl->sdl_type) {
|
2012-03-20 17:19:01 +08:00
|
|
|
case IFT_BRIDGE: /* FALLTHROUGH */
|
|
|
|
case IFT_L2VLAN: /* FALLTHOUGH */
|
|
|
|
case IFT_L3IPVLAN: /* FALLTHROUGH */
|
2009-04-17 20:49:25 +08:00
|
|
|
case IFT_ETHER:
|
|
|
|
ifp->family = ARPHRD_ETHER;
|
2008-04-12 00:14:55 +08:00
|
|
|
break;
|
2009-04-17 20:49:25 +08:00
|
|
|
case IFT_IEEE1394:
|
|
|
|
ifp->family = ARPHRD_IEEE1394;
|
|
|
|
break;
|
2012-03-22 03:11:07 +08:00
|
|
|
#ifdef IFT_INFINIBAND
|
2012-03-20 17:19:01 +08:00
|
|
|
case IFT_INFINIBAND:
|
|
|
|
ifp->family = ARPHRD_INFINIBAND;
|
|
|
|
break;
|
2012-03-22 03:11:07 +08:00
|
|
|
#endif
|
2009-04-17 20:49:25 +08:00
|
|
|
}
|
|
|
|
ifp->hwlen = sdl->sdl_alen;
|
2009-04-17 21:42:44 +08:00
|
|
|
#ifndef CLLADDR
|
|
|
|
# define CLLADDR(s) ((const char *)((s)->sdl_data + (s)->sdl_nlen))
|
|
|
|
#endif
|
2009-04-17 21:31:41 +08:00
|
|
|
memcpy(ifp->hwaddr, CLLADDR(sdl), ifp->hwlen);
|
2009-04-17 20:49:25 +08:00
|
|
|
#elif AF_PACKET
|
|
|
|
sll = (const struct sockaddr_ll *)(void *)ifa->ifa_addr;
|
2012-03-20 17:19:01 +08:00
|
|
|
ifp->family = sdl_type = sll->sll_hatype;
|
2009-04-17 20:49:25 +08:00
|
|
|
ifp->hwlen = sll->sll_halen;
|
|
|
|
if (ifp->hwlen != 0)
|
|
|
|
memcpy(ifp->hwaddr, sll->sll_addr, ifp->hwlen);
|
|
|
|
#endif
|
2009-08-06 05:39:42 +08:00
|
|
|
}
|
|
|
|
|
2009-10-15 15:32:49 +08:00
|
|
|
/* We only work on ethernet by default */
|
|
|
|
if (!(ifp->flags & IFF_POINTOPOINT) &&
|
|
|
|
ifp->family != ARPHRD_ETHER)
|
|
|
|
{
|
|
|
|
if (argc == 0 && ifac == 0) {
|
|
|
|
free_interface(ifp);
|
|
|
|
continue;
|
|
|
|
}
|
2010-01-14 07:54:45 +08:00
|
|
|
switch (ifp->family) {
|
|
|
|
case ARPHRD_IEEE1394: /* FALLTHROUGH */
|
|
|
|
case ARPHRD_INFINIBAND:
|
|
|
|
/* We don't warn for supported families */
|
|
|
|
break;
|
|
|
|
default:
|
2009-08-06 05:39:42 +08:00
|
|
|
syslog(LOG_WARNING,
|
2012-03-20 17:19:01 +08:00
|
|
|
"%s: unsupported interface type %.2x"
|
|
|
|
", falling back to ethernet",
|
|
|
|
ifp->name, sdl_type);
|
|
|
|
ifp->family = ARPHRD_ETHER;
|
|
|
|
break;
|
2010-01-14 07:54:45 +08:00
|
|
|
}
|
2008-04-12 00:14:55 +08:00
|
|
|
}
|
2010-02-27 04:37:30 +08:00
|
|
|
|
|
|
|
/* Handle any platform init for the interface */
|
|
|
|
if (if_init(ifp) == -1) {
|
|
|
|
syslog(LOG_ERR, "%s: if_init: %m", p);
|
|
|
|
free_interface(ifp);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-04-17 20:49:25 +08:00
|
|
|
if (ifl)
|
|
|
|
ifl->next = ifp;
|
2008-04-12 00:14:55 +08:00
|
|
|
else
|
2009-04-17 20:49:25 +08:00
|
|
|
ifs = ifp;
|
|
|
|
ifl = ifp;
|
|
|
|
}
|
|
|
|
freeifaddrs(ifaddrs);
|
2010-08-04 14:44:56 +08:00
|
|
|
|
|
|
|
#ifdef IFLR_ACTIVE
|
|
|
|
close(socket_aflink);
|
|
|
|
#endif
|
|
|
|
|
2009-04-17 20:49:25 +08:00
|
|
|
return ifs;
|
|
|
|
}
|
2008-04-12 00:14:55 +08:00
|
|
|
|
2009-04-17 20:49:25 +08:00
|
|
|
int
|
|
|
|
do_address(const char *ifname,
|
|
|
|
struct in_addr *addr, struct in_addr *net, struct in_addr *dst, int act)
|
|
|
|
{
|
|
|
|
struct ifaddrs *ifaddrs, *ifa;
|
|
|
|
const struct sockaddr_in *a, *n, *d;
|
|
|
|
int retval;
|
2008-04-12 00:14:55 +08:00
|
|
|
|
2009-04-17 20:49:25 +08:00
|
|
|
if (getifaddrs(&ifaddrs) == -1)
|
|
|
|
return -1;
|
2008-08-15 00:15:45 +08:00
|
|
|
|
2009-04-17 20:49:25 +08:00
|
|
|
retval = 0;
|
|
|
|
for (ifa = ifaddrs; ifa; ifa = ifa->ifa_next) {
|
2009-05-11 07:31:55 +08:00
|
|
|
if (ifa->ifa_addr == NULL ||
|
|
|
|
ifa->ifa_addr->sa_family != AF_INET ||
|
2009-04-17 20:49:25 +08:00
|
|
|
strcmp(ifa->ifa_name, ifname) != 0)
|
2008-09-16 17:55:46 +08:00
|
|
|
continue;
|
2009-04-27 22:00:39 +08:00
|
|
|
a = (const struct sockaddr_in *)(void *)ifa->ifa_addr;
|
|
|
|
n = (const struct sockaddr_in *)(void *)ifa->ifa_netmask;
|
2009-04-17 20:49:25 +08:00
|
|
|
if (ifa->ifa_flags & IFF_POINTOPOINT)
|
2009-04-17 21:31:41 +08:00
|
|
|
d = (const struct sockaddr_in *)(void *)
|
2009-08-12 16:38:41 +08:00
|
|
|
ifa->ifa_dstaddr;
|
2009-04-17 20:49:25 +08:00
|
|
|
else
|
|
|
|
d = NULL;
|
|
|
|
if (act == 1) {
|
|
|
|
addr->s_addr = a->sin_addr.s_addr;
|
|
|
|
net->s_addr = n->sin_addr.s_addr;
|
2010-11-12 05:07:50 +08:00
|
|
|
if (dst) {
|
|
|
|
if (ifa->ifa_flags & IFF_POINTOPOINT)
|
|
|
|
dst->s_addr = d->sin_addr.s_addr;
|
|
|
|
else
|
|
|
|
dst->s_addr = INADDR_ANY;
|
|
|
|
}
|
2009-04-17 20:49:25 +08:00
|
|
|
retval = 1;
|
|
|
|
break;
|
2008-04-12 00:14:55 +08:00
|
|
|
}
|
2009-04-17 20:49:25 +08:00
|
|
|
if (addr->s_addr == a->sin_addr.s_addr &&
|
|
|
|
(net == NULL || net->s_addr == n->sin_addr.s_addr))
|
|
|
|
{
|
|
|
|
retval = 1;
|
|
|
|
break;
|
2008-04-12 00:14:55 +08:00
|
|
|
}
|
|
|
|
}
|
2009-04-17 20:49:25 +08:00
|
|
|
freeifaddrs(ifaddrs);
|
2008-04-12 00:14:55 +08:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
do_mtu(const char *ifname, short int mtu)
|
|
|
|
{
|
|
|
|
struct ifreq ifr;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
memset(&ifr, 0, sizeof(ifr));
|
|
|
|
strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
|
|
|
|
ifr.ifr_mtu = mtu;
|
2009-10-15 08:30:54 +08:00
|
|
|
r = ioctl(socket_afnet, mtu ? SIOCSIFMTU : SIOCGIFMTU, &ifr);
|
2008-04-12 00:14:55 +08:00
|
|
|
if (r == -1)
|
|
|
|
return -1;
|
|
|
|
return ifr.ifr_mtu;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
free_routes(struct rt *routes)
|
|
|
|
{
|
|
|
|
struct rt *r;
|
|
|
|
|
|
|
|
while (routes) {
|
|
|
|
r = routes->next;
|
|
|
|
free(routes);
|
|
|
|
routes = r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
open_udp_socket(struct interface *iface)
|
|
|
|
{
|
2008-04-26 15:39:23 +08:00
|
|
|
int s;
|
2008-09-04 16:31:00 +08:00
|
|
|
struct sockaddr_in sin;
|
2008-07-30 19:05:45 +08:00
|
|
|
int n;
|
|
|
|
#ifdef SO_BINDTODEVICE
|
|
|
|
struct ifreq ifr;
|
2008-11-18 06:50:37 +08:00
|
|
|
char *p;
|
2008-07-30 19:05:45 +08:00
|
|
|
#endif
|
2008-04-26 15:39:23 +08:00
|
|
|
|
|
|
|
if ((s = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1)
|
|
|
|
return -1;
|
|
|
|
|
2008-07-30 19:05:45 +08:00
|
|
|
n = 1;
|
2008-04-26 15:39:23 +08:00
|
|
|
if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &n, sizeof(n)) == -1)
|
|
|
|
goto eexit;
|
2008-07-30 19:05:45 +08:00
|
|
|
#ifdef SO_BINDTODEVICE
|
|
|
|
memset(&ifr, 0, sizeof(ifr));
|
|
|
|
strlcpy(ifr.ifr_name, iface->name, sizeof(ifr.ifr_name));
|
2008-11-18 06:50:37 +08:00
|
|
|
/* We can only bind to the real device */
|
|
|
|
p = strchr(ifr.ifr_name, ':');
|
|
|
|
if (p)
|
|
|
|
*p = '\0';
|
2009-02-12 01:56:22 +08:00
|
|
|
if (setsockopt(s, SOL_SOCKET, SO_BINDTODEVICE, &ifr,
|
|
|
|
sizeof(ifr)) == -1)
|
2008-07-30 19:05:45 +08:00
|
|
|
goto eexit;
|
|
|
|
#endif
|
|
|
|
/* As we don't use this socket for receiving, set the
|
|
|
|
* receive buffer to 1 */
|
|
|
|
n = 1;
|
2008-04-26 15:39:23 +08:00
|
|
|
if (setsockopt(s, SOL_SOCKET, SO_RCVBUF, &n, sizeof(n)) == -1)
|
|
|
|
goto eexit;
|
2008-09-04 16:31:00 +08:00
|
|
|
memset(&sin, 0, sizeof(sin));
|
|
|
|
sin.sin_family = AF_INET;
|
|
|
|
sin.sin_port = htons(DHCP_CLIENT_PORT);
|
|
|
|
sin.sin_addr.s_addr = iface->addr.s_addr;
|
|
|
|
if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) == -1)
|
2008-04-26 15:39:23 +08:00
|
|
|
goto eexit;
|
2008-04-12 00:14:55 +08:00
|
|
|
|
2008-04-26 15:39:23 +08:00
|
|
|
iface->udp_fd = s;
|
2008-06-11 06:23:57 +08:00
|
|
|
set_cloexec(s);
|
2008-04-26 15:39:23 +08:00
|
|
|
return 0;
|
2008-04-12 00:14:55 +08:00
|
|
|
|
|
|
|
eexit:
|
2008-04-26 15:39:23 +08:00
|
|
|
close(s);
|
|
|
|
return -1;
|
2008-04-12 00:14:55 +08:00
|
|
|
}
|
|
|
|
|
2008-04-21 03:02:19 +08:00
|
|
|
ssize_t
|
|
|
|
send_packet(const struct interface *iface, struct in_addr to,
|
2009-02-12 01:56:22 +08:00
|
|
|
const uint8_t *data, ssize_t len)
|
2008-04-21 03:02:19 +08:00
|
|
|
{
|
2008-09-04 16:31:00 +08:00
|
|
|
struct sockaddr_in sin;
|
|
|
|
|
|
|
|
memset(&sin, 0, sizeof(sin));
|
|
|
|
sin.sin_family = AF_INET;
|
|
|
|
sin.sin_addr.s_addr = to.s_addr;
|
|
|
|
sin.sin_port = htons(DHCP_SERVER_PORT);
|
|
|
|
return sendto(iface->udp_fd, data, len, 0,
|
2009-02-12 01:56:22 +08:00
|
|
|
(struct sockaddr *)&sin, sizeof(sin));
|
2008-04-21 03:02:19 +08:00
|
|
|
}
|
|
|
|
|
2008-04-12 00:14:55 +08:00
|
|
|
struct udp_dhcp_packet
|
|
|
|
{
|
|
|
|
struct ip ip;
|
|
|
|
struct udphdr udp;
|
|
|
|
struct dhcp_message dhcp;
|
|
|
|
};
|
2008-06-09 04:07:54 +08:00
|
|
|
const size_t udp_dhcp_len = sizeof(struct udp_dhcp_packet);
|
2008-04-12 00:14:55 +08:00
|
|
|
|
|
|
|
static uint16_t
|
2008-05-15 18:10:39 +08:00
|
|
|
checksum(const void *data, uint16_t len)
|
2008-04-12 00:14:55 +08:00
|
|
|
{
|
2008-05-16 04:58:31 +08:00
|
|
|
const uint8_t *addr = data;
|
2008-04-12 00:14:55 +08:00
|
|
|
uint32_t sum = 0;
|
|
|
|
|
2008-05-15 18:10:39 +08:00
|
|
|
while (len > 1) {
|
2008-05-16 04:58:31 +08:00
|
|
|
sum += addr[0] * 256 + addr[1];
|
|
|
|
addr += 2;
|
2008-05-15 18:10:39 +08:00
|
|
|
len -= 2;
|
2008-04-12 00:14:55 +08:00
|
|
|
}
|
|
|
|
|
2008-05-15 18:10:39 +08:00
|
|
|
if (len == 1)
|
2008-05-16 04:58:31 +08:00
|
|
|
sum += *addr * 256;
|
2008-05-15 18:10:39 +08:00
|
|
|
|
2008-04-12 00:14:55 +08:00
|
|
|
sum = (sum >> 16) + (sum & 0xffff);
|
|
|
|
sum += (sum >> 16);
|
|
|
|
|
2008-05-16 04:58:31 +08:00
|
|
|
sum = htons(sum);
|
|
|
|
|
2008-04-12 00:14:55 +08:00
|
|
|
return ~sum;
|
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t
|
|
|
|
make_udp_packet(uint8_t **packet, const uint8_t *data, size_t length,
|
2009-02-12 01:56:22 +08:00
|
|
|
struct in_addr source, struct in_addr dest)
|
2008-04-12 00:14:55 +08:00
|
|
|
{
|
|
|
|
struct udp_dhcp_packet *udpp;
|
|
|
|
struct ip *ip;
|
|
|
|
struct udphdr *udp;
|
|
|
|
|
|
|
|
udpp = xzalloc(sizeof(*udpp));
|
|
|
|
ip = &udpp->ip;
|
|
|
|
udp = &udpp->udp;
|
|
|
|
|
|
|
|
/* OK, this is important :)
|
|
|
|
* We copy the data to our packet and then create a small part of the
|
|
|
|
* ip structure and an invalid ip_len (basically udp length).
|
|
|
|
* We then fill the udp structure and put the checksum
|
|
|
|
* of the whole packet into the udp checksum.
|
|
|
|
* Finally we complete the ip structure and ip checksum.
|
|
|
|
* If we don't do the ordering like so then the udp checksum will be
|
|
|
|
* broken, so find another way of doing it! */
|
|
|
|
|
|
|
|
memcpy(&udpp->dhcp, data, length);
|
|
|
|
|
|
|
|
ip->ip_p = IPPROTO_UDP;
|
|
|
|
ip->ip_src.s_addr = source.s_addr;
|
|
|
|
if (dest.s_addr == 0)
|
|
|
|
ip->ip_dst.s_addr = INADDR_BROADCAST;
|
|
|
|
else
|
|
|
|
ip->ip_dst.s_addr = dest.s_addr;
|
|
|
|
|
|
|
|
udp->uh_sport = htons(DHCP_CLIENT_PORT);
|
|
|
|
udp->uh_dport = htons(DHCP_SERVER_PORT);
|
|
|
|
udp->uh_ulen = htons(sizeof(*udp) + length);
|
|
|
|
ip->ip_len = udp->uh_ulen;
|
2008-05-15 18:10:39 +08:00
|
|
|
udp->uh_sum = checksum(udpp, sizeof(*udpp));
|
2008-04-12 00:14:55 +08:00
|
|
|
|
|
|
|
ip->ip_v = IPVERSION;
|
2010-03-13 04:33:15 +08:00
|
|
|
ip->ip_hl = sizeof(*ip) >> 2;
|
|
|
|
ip->ip_id = arc4random() & UINT16_MAX;
|
2008-04-12 00:14:55 +08:00
|
|
|
ip->ip_ttl = IPDEFTTL;
|
2010-03-13 04:33:15 +08:00
|
|
|
ip->ip_len = htons(sizeof(*ip) + sizeof(*udp) + length);
|
2008-05-15 18:10:39 +08:00
|
|
|
ip->ip_sum = checksum(ip, sizeof(*ip));
|
2008-04-12 00:14:55 +08:00
|
|
|
|
|
|
|
*packet = (uint8_t *)udpp;
|
|
|
|
return sizeof(*ip) + sizeof(*udp) + length;
|
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t
|
|
|
|
get_udp_data(const uint8_t **data, const uint8_t *udp)
|
|
|
|
{
|
2008-05-15 18:10:39 +08:00
|
|
|
struct udp_dhcp_packet packet;
|
|
|
|
|
|
|
|
memcpy(&packet, udp, sizeof(packet));
|
|
|
|
*data = udp + offsetof(struct udp_dhcp_packet, dhcp);
|
2009-02-12 01:56:22 +08:00
|
|
|
return ntohs(packet.ip.ip_len) -
|
|
|
|
sizeof(packet.ip) -
|
|
|
|
sizeof(packet.udp);
|
2008-04-12 00:14:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2011-03-25 01:59:20 +08:00
|
|
|
valid_udp_packet(const uint8_t *data, size_t data_len, struct in_addr *from,
|
|
|
|
int noudpcsum)
|
2008-04-12 00:14:55 +08:00
|
|
|
{
|
2008-05-15 18:10:39 +08:00
|
|
|
struct udp_dhcp_packet packet;
|
2008-11-10 19:15:27 +08:00
|
|
|
uint16_t bytes, udpsum;
|
2008-04-12 00:14:55 +08:00
|
|
|
|
2009-03-11 01:28:18 +08:00
|
|
|
if (data_len < sizeof(packet.ip)) {
|
|
|
|
if (from)
|
|
|
|
from->s_addr = INADDR_ANY;
|
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
memcpy(&packet, data, MIN(data_len, sizeof(packet)));
|
|
|
|
if (from)
|
|
|
|
from->s_addr = packet.ip.ip_src.s_addr;
|
2009-02-28 16:59:48 +08:00
|
|
|
if (data_len > sizeof(packet)) {
|
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
2008-11-10 19:15:27 +08:00
|
|
|
if (checksum(&packet.ip, sizeof(packet.ip)) != 0) {
|
2008-04-12 00:14:55 +08:00
|
|
|
errno = EINVAL;
|
2008-05-15 18:10:39 +08:00
|
|
|
return -1;
|
2008-04-12 00:14:55 +08:00
|
|
|
}
|
|
|
|
|
2008-11-10 19:15:27 +08:00
|
|
|
bytes = ntohs(packet.ip.ip_len);
|
2009-02-28 16:59:48 +08:00
|
|
|
if (data_len < bytes) {
|
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
2011-03-25 01:59:20 +08:00
|
|
|
|
|
|
|
if (noudpcsum == 0) {
|
|
|
|
udpsum = packet.udp.uh_sum;
|
|
|
|
packet.udp.uh_sum = 0;
|
|
|
|
packet.ip.ip_hl = 0;
|
|
|
|
packet.ip.ip_v = 0;
|
|
|
|
packet.ip.ip_tos = 0;
|
|
|
|
packet.ip.ip_len = packet.udp.uh_ulen;
|
|
|
|
packet.ip.ip_id = 0;
|
|
|
|
packet.ip.ip_off = 0;
|
|
|
|
packet.ip.ip_ttl = 0;
|
|
|
|
packet.ip.ip_sum = 0;
|
|
|
|
if (udpsum && checksum(&packet, bytes) != udpsum) {
|
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
2008-04-12 00:14:55 +08:00
|
|
|
}
|
|
|
|
|
2008-11-19 23:01:20 +08:00
|
|
|
return 0;
|
2008-04-12 00:14:55 +08:00
|
|
|
}
|