2011-03-31 09:29:22 +05:30
|
|
|
/* ndhc.c - DHCP client
|
2011-06-11 20:49:05 +05:30
|
|
|
* Time-stamp: <2011-06-11 11:13:32 njk>
|
2010-11-12 14:32:18 +05:30
|
|
|
*
|
2011-03-31 09:29:22 +05:30
|
|
|
* (c) 2004-2011 Nicholas J. Kain <njkain at gmail dot com>
|
2010-11-12 14:32:18 +05:30
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
2010-11-13 01:03:17 +05:30
|
|
|
|
2010-11-12 14:32:18 +05:30
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <string.h>
|
2010-12-01 23:41:09 +05:30
|
|
|
#include <sys/epoll.h>
|
2010-12-01 23:05:13 +05:30
|
|
|
#include <sys/signalfd.h>
|
2010-11-12 14:32:18 +05:30
|
|
|
#include <net/if.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <pwd.h>
|
|
|
|
#include <grp.h>
|
|
|
|
|
2010-11-13 05:14:49 +05:30
|
|
|
#include "ndhc-defines.h"
|
2010-12-24 16:30:37 +05:30
|
|
|
#include "config.h"
|
2010-11-12 14:32:18 +05:30
|
|
|
#include "options.h"
|
|
|
|
#include "packet.h"
|
2010-12-24 20:02:58 +05:30
|
|
|
#include "timeout.h"
|
|
|
|
#include "sys.h"
|
2010-12-24 20:42:41 +05:30
|
|
|
#include "ifchange.h"
|
2010-12-24 20:28:47 +05:30
|
|
|
#include "arp.h"
|
2011-03-30 00:07:45 +05:30
|
|
|
#include "netlink.h"
|
2011-04-20 02:07:43 +05:30
|
|
|
#include "leasefile.h"
|
2011-03-30 00:07:45 +05:30
|
|
|
|
2010-11-12 14:32:18 +05:30
|
|
|
#include "log.h"
|
2010-11-12 16:12:07 +05:30
|
|
|
#include "chroot.h"
|
2010-11-12 19:34:43 +05:30
|
|
|
#include "cap.h"
|
2010-11-12 16:12:07 +05:30
|
|
|
#include "strl.h"
|
2010-11-13 05:14:49 +05:30
|
|
|
#include "pidfile.h"
|
2010-11-12 22:49:52 +05:30
|
|
|
#include "malloc.h"
|
2010-12-02 10:03:25 +05:30
|
|
|
#include "io.h"
|
2010-11-12 14:32:18 +05:30
|
|
|
|
2010-11-12 15:14:25 +05:30
|
|
|
#define VERSION "1.0"
|
|
|
|
|
2010-12-24 17:30:42 +05:30
|
|
|
struct client_state_t cs = {
|
2010-12-24 17:37:48 +05:30
|
|
|
.dhcpState = DS_INIT_SELECTING,
|
|
|
|
.arpPrevState = DS_NULL,
|
2011-03-30 01:04:00 +05:30
|
|
|
.ifsPrevState = IFS_NONE,
|
2010-12-24 17:37:48 +05:30
|
|
|
.listenMode = LM_NONE,
|
2010-12-24 17:30:42 +05:30
|
|
|
.packetNum = 0,
|
|
|
|
.xid = 0,
|
|
|
|
.timeout = 0,
|
2011-03-31 05:43:48 +05:30
|
|
|
.oldTimeout = 0,
|
2010-12-24 17:30:42 +05:30
|
|
|
.leaseStartTime = 0,
|
|
|
|
.requestedIP = 0,
|
|
|
|
.serverAddr = 0,
|
2011-03-31 05:43:48 +05:30
|
|
|
.routerAddr = 0,
|
2010-12-24 17:30:42 +05:30
|
|
|
.lease = 0,
|
|
|
|
.t1 = 0,
|
|
|
|
.t2 = 0,
|
|
|
|
.epollFd = -1,
|
|
|
|
.signalFd = -1,
|
|
|
|
.listenFd = -1,
|
|
|
|
.arpFd = -1,
|
2011-03-30 01:04:00 +05:30
|
|
|
.nlFd = -1,
|
2011-03-31 08:47:27 +05:30
|
|
|
.routerArp = "\0\0\0\0\0\0",
|
2010-12-24 17:30:42 +05:30
|
|
|
};
|
2010-11-12 14:32:18 +05:30
|
|
|
|
|
|
|
struct client_config_t client_config = {
|
2010-11-13 01:03:17 +05:30
|
|
|
/* Default options. */
|
|
|
|
.abort_if_no_lease = 0,
|
|
|
|
.foreground = 0,
|
|
|
|
.quit_after_lease = 0,
|
|
|
|
.background_if_no_lease = 0,
|
|
|
|
.interface = "eth0",
|
|
|
|
.clientid = NULL,
|
|
|
|
.hostname = NULL,
|
|
|
|
.ifindex = 0,
|
2011-03-31 08:47:27 +05:30
|
|
|
.arp = "\0\0\0\0\0\0",
|
2010-11-12 14:32:18 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
static void show_usage(void)
|
|
|
|
{
|
2010-11-13 01:03:17 +05:30
|
|
|
printf(
|
2010-11-12 14:32:18 +05:30
|
|
|
"Usage: ndhc [OPTIONS]\n\n"
|
|
|
|
" -c, --clientid=CLIENTID Client identifier\n"
|
|
|
|
" -H, --hostname=HOSTNAME Client hostname\n"
|
|
|
|
" -h Alias for -H\n"
|
|
|
|
" -f, --foreground Do not fork after getting lease\n"
|
|
|
|
" -b, --background Fork to background if lease cannot be\n"
|
|
|
|
" immediately negotiated.\n"
|
2010-11-13 06:13:16 +05:30
|
|
|
" -p, --pidfile File to which the pid will be written\n"
|
2010-11-12 14:32:18 +05:30
|
|
|
" -i, --interface=INTERFACE Interface to use (default: eth0)\n"
|
|
|
|
" -n, --now Exit with failure if lease cannot be\n"
|
|
|
|
" immediately negotiated.\n"
|
|
|
|
" -q, --quit Quit after obtaining lease\n"
|
|
|
|
" -r, --request=IP IP address to request (default: none)\n"
|
|
|
|
" -u, --user Change privileges to this user\n"
|
|
|
|
" -C, --chroot Directory to which udhcp should chroot\n"
|
|
|
|
" -v, --version Display version\n"
|
2010-11-13 01:03:17 +05:30
|
|
|
);
|
|
|
|
exit(EXIT_SUCCESS);
|
2010-11-12 14:32:18 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/* perform a renew */
|
|
|
|
static void perform_renew(void)
|
|
|
|
{
|
2010-11-13 01:03:17 +05:30
|
|
|
log_line("Performing a DHCP renew...");
|
2010-12-02 10:03:25 +05:30
|
|
|
retry:
|
2010-12-24 17:30:42 +05:30
|
|
|
switch (cs.dhcpState) {
|
2010-12-24 17:37:48 +05:30
|
|
|
case DS_BOUND:
|
2010-12-24 20:11:52 +05:30
|
|
|
change_listen_mode(&cs, LM_KERNEL);
|
2010-12-24 17:37:48 +05:30
|
|
|
case DS_ARP_CHECK:
|
2010-12-02 10:03:25 +05:30
|
|
|
// Cancel arp ping in progress and treat as previous state.
|
2010-12-24 20:02:58 +05:30
|
|
|
epoll_del(&cs, cs.arpFd);
|
2011-03-31 08:47:27 +05:30
|
|
|
close(cs.arpFd);
|
2010-12-24 17:30:42 +05:30
|
|
|
cs.arpFd = -1;
|
|
|
|
cs.dhcpState = cs.arpPrevState;
|
2010-12-02 10:03:25 +05:30
|
|
|
goto retry;
|
2010-12-24 17:37:48 +05:30
|
|
|
case DS_RENEWING:
|
|
|
|
case DS_REBINDING:
|
|
|
|
cs.dhcpState = DS_RENEW_REQUESTED;
|
2010-11-13 01:03:17 +05:30
|
|
|
break;
|
2010-12-24 17:37:48 +05:30
|
|
|
case DS_RENEW_REQUESTED: /* impatient are we? fine, square 1 */
|
2010-12-24 20:42:41 +05:30
|
|
|
ifchange(NULL, IFCHANGE_DECONFIG);
|
2010-12-24 17:37:48 +05:30
|
|
|
case DS_REQUESTING:
|
|
|
|
case DS_RELEASED:
|
2010-12-24 20:11:52 +05:30
|
|
|
change_listen_mode(&cs, LM_RAW);
|
2010-12-24 17:37:48 +05:30
|
|
|
cs.dhcpState = DS_INIT_SELECTING;
|
2010-11-13 01:03:17 +05:30
|
|
|
break;
|
2010-12-24 17:37:48 +05:30
|
|
|
case DS_INIT_SELECTING:
|
2010-12-24 00:11:25 +05:30
|
|
|
default:
|
2010-11-13 01:03:17 +05:30
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* start things over */
|
2010-12-24 17:30:42 +05:30
|
|
|
cs.packetNum = 0;
|
2010-11-13 01:03:17 +05:30
|
|
|
|
|
|
|
/* Kill any timeouts because the user wants this to hurry along */
|
2010-12-24 17:30:42 +05:30
|
|
|
cs.timeout = 0;
|
2010-11-12 14:32:18 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* perform a release */
|
|
|
|
static void perform_release(void)
|
|
|
|
{
|
2010-11-14 05:19:46 +05:30
|
|
|
struct in_addr temp_saddr, temp_raddr;
|
2010-11-13 01:03:17 +05:30
|
|
|
|
|
|
|
/* send release packet */
|
2010-12-24 17:37:48 +05:30
|
|
|
if (cs.dhcpState == DS_BOUND || cs.dhcpState == DS_RENEWING ||
|
|
|
|
cs.dhcpState == DS_REBINDING || cs.dhcpState == DS_ARP_CHECK) {
|
2010-12-24 17:30:42 +05:30
|
|
|
temp_saddr.s_addr = cs.serverAddr;
|
|
|
|
temp_raddr.s_addr = cs.requestedIP;
|
2010-11-13 01:03:17 +05:30
|
|
|
log_line("Unicasting a release of %s to %s.",
|
2010-11-14 05:19:46 +05:30
|
|
|
inet_ntoa(temp_raddr), inet_ntoa(temp_saddr));
|
2010-12-24 17:30:42 +05:30
|
|
|
send_release(cs.serverAddr, cs.requestedIP); /* unicast */
|
2010-12-24 20:42:41 +05:30
|
|
|
ifchange(NULL, IFCHANGE_DECONFIG);
|
2010-11-13 01:03:17 +05:30
|
|
|
}
|
|
|
|
log_line("Entering released state.");
|
|
|
|
|
2010-12-24 17:37:48 +05:30
|
|
|
if (cs.dhcpState == DS_ARP_CHECK) {
|
2010-12-24 20:02:58 +05:30
|
|
|
epoll_del(&cs, cs.arpFd);
|
2011-03-31 08:47:27 +05:30
|
|
|
close(cs.arpFd);
|
2010-12-24 17:30:42 +05:30
|
|
|
cs.arpFd = -1;
|
2010-12-02 10:03:25 +05:30
|
|
|
}
|
2010-12-24 20:11:52 +05:30
|
|
|
change_listen_mode(&cs, LM_NONE);
|
2010-12-24 17:37:48 +05:30
|
|
|
cs.dhcpState = DS_RELEASED;
|
2010-12-24 17:30:42 +05:30
|
|
|
cs.timeout = -1;
|
2010-11-12 14:32:18 +05:30
|
|
|
}
|
|
|
|
|
2010-12-01 23:05:13 +05:30
|
|
|
static void signal_dispatch()
|
|
|
|
{
|
|
|
|
int t, off = 0;
|
|
|
|
struct signalfd_siginfo si;
|
|
|
|
again:
|
2010-12-24 17:30:42 +05:30
|
|
|
t = read(cs.signalFd, (char *)&si + off, sizeof si - off);
|
2010-12-01 23:05:13 +05:30
|
|
|
if (t < sizeof si - off) {
|
|
|
|
if (t < 0) {
|
|
|
|
if (t == EAGAIN || t == EWOULDBLOCK || t == EINTR)
|
|
|
|
goto again;
|
|
|
|
else
|
|
|
|
suicide("signalfd read error");
|
|
|
|
}
|
|
|
|
off += t;
|
|
|
|
}
|
|
|
|
switch (si.ssi_signo) {
|
|
|
|
case SIGUSR1:
|
2010-11-13 01:03:17 +05:30
|
|
|
perform_renew();
|
2010-12-01 23:05:13 +05:30
|
|
|
break;
|
|
|
|
case SIGUSR2:
|
2010-11-13 01:03:17 +05:30
|
|
|
perform_release();
|
2010-12-01 23:05:13 +05:30
|
|
|
break;
|
|
|
|
case SIGTERM:
|
2010-11-13 01:03:17 +05:30
|
|
|
log_line("Received SIGTERM. Exiting gracefully.");
|
|
|
|
exit(EXIT_SUCCESS);
|
2010-12-01 23:05:13 +05:30
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void do_work(void)
|
|
|
|
{
|
2010-12-24 17:30:42 +05:30
|
|
|
struct epoll_event events[3];
|
2010-12-02 10:45:03 +05:30
|
|
|
long long last_awake;
|
2010-12-24 00:11:25 +05:30
|
|
|
int timeout_delta;
|
2010-11-13 01:03:17 +05:30
|
|
|
|
2010-12-24 17:30:42 +05:30
|
|
|
cs.epollFd = epoll_create1(0);
|
|
|
|
if (cs.epollFd == -1)
|
2010-12-01 23:41:09 +05:30
|
|
|
suicide("epoll_create1 failed");
|
2010-12-27 20:35:43 +05:30
|
|
|
setup_signals(&cs);
|
2011-03-30 01:04:00 +05:30
|
|
|
epoll_add(&cs, cs.nlFd);
|
2010-12-24 20:11:52 +05:30
|
|
|
change_listen_mode(&cs, LM_RAW);
|
2010-12-24 20:02:58 +05:30
|
|
|
handle_timeout(&cs);
|
2010-11-13 01:03:17 +05:30
|
|
|
|
2010-12-01 23:41:09 +05:30
|
|
|
for (;;) {
|
2010-12-02 10:45:03 +05:30
|
|
|
last_awake = curms();
|
2010-12-24 17:30:42 +05:30
|
|
|
int r = epoll_wait(cs.epollFd, events, 3, cs.timeout);
|
2010-12-01 23:41:09 +05:30
|
|
|
if (r == -1) {
|
|
|
|
if (errno == EINTR)
|
|
|
|
continue;
|
|
|
|
else
|
|
|
|
suicide("epoll_wait failed");
|
|
|
|
}
|
|
|
|
for (int i = 0; i < r; ++i) {
|
|
|
|
int fd = events[i].data.fd;
|
2010-12-24 17:30:42 +05:30
|
|
|
if (fd == cs.signalFd)
|
2010-12-01 23:41:09 +05:30
|
|
|
signal_dispatch();
|
2010-12-24 17:30:42 +05:30
|
|
|
else if (fd == cs.listenFd)
|
2010-12-24 19:25:59 +05:30
|
|
|
handle_packet(&cs);
|
2010-12-24 17:30:42 +05:30
|
|
|
else if (fd == cs.arpFd)
|
2010-12-24 20:02:58 +05:30
|
|
|
handle_arp_response(&cs);
|
2011-03-30 01:04:00 +05:30
|
|
|
else if (fd == cs.nlFd)
|
|
|
|
handle_nl_message(&cs);
|
2010-12-01 23:41:09 +05:30
|
|
|
else
|
|
|
|
suicide("epoll_wait: unknown fd");
|
2010-11-13 01:03:17 +05:30
|
|
|
}
|
2010-12-02 10:45:03 +05:30
|
|
|
|
|
|
|
timeout_delta = curms() - last_awake;
|
2010-12-24 17:30:42 +05:30
|
|
|
cs.timeout -= timeout_delta;
|
|
|
|
if (cs.timeout <= 0) {
|
|
|
|
cs.timeout = 0;
|
2010-12-24 20:02:58 +05:30
|
|
|
handle_timeout(&cs);
|
2010-12-23 22:04:57 +05:30
|
|
|
}
|
2010-11-13 01:03:17 +05:30
|
|
|
}
|
2010-11-12 14:32:18 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2010-11-13 06:13:16 +05:30
|
|
|
char chroot_dir[MAX_PATH_LENGTH] = "";
|
2010-11-13 01:03:17 +05:30
|
|
|
int c, len;
|
|
|
|
struct passwd *pwd;
|
|
|
|
uid_t uid = 0;
|
|
|
|
gid_t gid = 0;
|
|
|
|
static struct option arg_options[] = {
|
|
|
|
{"clientid", required_argument, 0, 'c'},
|
|
|
|
{"foreground", no_argument, 0, 'f'},
|
|
|
|
{"background", no_argument, 0, 'b'},
|
2010-11-13 05:14:49 +05:30
|
|
|
{"pidfile", required_argument, 0, 'p'},
|
2011-04-20 02:07:43 +05:30
|
|
|
{"leasefile", required_argument, 0, 'l'},
|
2010-11-13 01:03:17 +05:30
|
|
|
{"hostname", required_argument, 0, 'H'},
|
|
|
|
{"hostname", required_argument, 0, 'h'},
|
|
|
|
{"interface", required_argument, 0, 'i'},
|
|
|
|
{"now", no_argument, 0, 'n'},
|
|
|
|
{"quit", no_argument, 0, 'q'},
|
|
|
|
{"request", required_argument, 0, 'r'},
|
|
|
|
{"version", no_argument, 0, 'v'},
|
|
|
|
{"user", required_argument, 0, 'u'},
|
|
|
|
{"chroot", required_argument, 0, 'C'},
|
|
|
|
{"help", no_argument, 0, '?'},
|
|
|
|
{0, 0, 0, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* get options */
|
|
|
|
while (1) {
|
|
|
|
int option_index = 0;
|
2011-04-20 02:07:43 +05:30
|
|
|
c = getopt_long(argc, argv, "c:fbp:H:h:i:np:l:qr:u:C:v", arg_options,
|
2010-11-13 01:03:17 +05:30
|
|
|
&option_index);
|
|
|
|
if (c == -1) break;
|
|
|
|
|
|
|
|
switch (c) {
|
|
|
|
case 'c':
|
2010-12-24 20:57:24 +05:30
|
|
|
len = strlen(optarg) > 64 ? 64 : strlen(optarg);
|
2010-11-13 01:03:17 +05:30
|
|
|
if (client_config.clientid)
|
|
|
|
free(client_config.clientid);
|
2011-03-30 16:35:00 +05:30
|
|
|
client_config.clientid =
|
2011-03-31 09:29:22 +05:30
|
|
|
alloc_dhcp_client_id_option(0, (uint8_t *)optarg, len);
|
2010-11-13 01:03:17 +05:30
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
client_config.foreground = 1;
|
2010-12-23 22:04:57 +05:30
|
|
|
gflags_detach = 0;
|
2010-11-13 01:03:17 +05:30
|
|
|
break;
|
|
|
|
case 'b':
|
|
|
|
client_config.background_if_no_lease = 1;
|
2010-12-23 22:04:57 +05:30
|
|
|
gflags_detach = 1;
|
2010-11-13 01:03:17 +05:30
|
|
|
break;
|
2010-11-13 05:14:49 +05:30
|
|
|
case 'p':
|
2010-11-13 06:13:16 +05:30
|
|
|
strlcpy(pidfile, optarg, sizeof pidfile);
|
2010-11-13 05:14:49 +05:30
|
|
|
break;
|
2011-04-20 02:07:43 +05:30
|
|
|
case 'l':
|
|
|
|
set_leasefile(optarg);
|
|
|
|
break;
|
2010-11-13 01:03:17 +05:30
|
|
|
case 'h':
|
|
|
|
case 'H':
|
2010-12-24 20:57:24 +05:30
|
|
|
len = strlen(optarg) > 64 ? 64 : strlen(optarg);
|
2010-11-13 01:03:17 +05:30
|
|
|
if (client_config.hostname)
|
|
|
|
free(client_config.hostname);
|
2011-03-30 16:35:00 +05:30
|
|
|
client_config.hostname =
|
2011-03-31 09:29:22 +05:30
|
|
|
alloc_option(DHCP_HOST_NAME, (uint8_t *)optarg, len);
|
2010-11-13 01:03:17 +05:30
|
|
|
break;
|
|
|
|
case 'i':
|
2010-12-24 21:14:06 +05:30
|
|
|
client_config.interface = optarg;
|
2010-11-13 01:03:17 +05:30
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
client_config.abort_if_no_lease = 1;
|
|
|
|
break;
|
|
|
|
case 'q':
|
|
|
|
client_config.quit_after_lease = 1;
|
|
|
|
break;
|
|
|
|
case 'r':
|
2010-12-24 17:30:42 +05:30
|
|
|
cs.requestedIP = inet_addr(optarg);
|
2010-11-13 01:03:17 +05:30
|
|
|
break;
|
|
|
|
case 'u':
|
|
|
|
pwd = getpwnam(optarg);
|
|
|
|
if (pwd) {
|
|
|
|
uid = (int)pwd->pw_uid;
|
|
|
|
gid = (int)pwd->pw_gid;
|
|
|
|
} else {
|
|
|
|
printf("Bad username provided.\n");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'C':
|
|
|
|
strlcpy(chroot_dir, optarg, sizeof chroot_dir);
|
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
printf("ndhc, version " VERSION "\n\n");
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
show_usage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
log_line("ndhc client " VERSION " started.");
|
|
|
|
|
2010-11-13 06:38:16 +05:30
|
|
|
if (client_config.foreground && !client_config.background_if_no_lease) {
|
|
|
|
if (file_exists(pidfile, "w") == -1) {
|
|
|
|
log_line("FATAL - cannot open pidfile for write!");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
write_pid(pidfile);
|
|
|
|
}
|
|
|
|
|
2011-03-30 01:04:00 +05:30
|
|
|
if (nl_open(&cs) < 0) {
|
2011-03-30 00:07:45 +05:30
|
|
|
log_line("FATAL - failed to open netlink socket");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2011-03-30 01:04:00 +05:30
|
|
|
if (nl_getifdata(client_config.interface, &cs) < 0) {
|
2011-03-30 00:07:45 +05:30
|
|
|
log_line("FATAL - failed to get interface MAC and index");
|
2010-11-13 01:03:17 +05:30
|
|
|
exit(EXIT_FAILURE);
|
2011-03-30 00:07:45 +05:30
|
|
|
}
|
2010-11-13 01:03:17 +05:30
|
|
|
|
|
|
|
if (!client_config.clientid) {
|
2011-03-30 16:35:00 +05:30
|
|
|
client_config.clientid =
|
|
|
|
alloc_dhcp_client_id_option(1, client_config.arp, 6);
|
2010-11-13 01:03:17 +05:30
|
|
|
}
|
|
|
|
|
2011-04-20 02:07:43 +05:30
|
|
|
open_leasefile();
|
|
|
|
|
2010-11-13 01:03:17 +05:30
|
|
|
if (chdir(chroot_dir)) {
|
|
|
|
printf("Failed to chdir(%s)!\n", chroot_dir);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (chroot(chroot_dir)) {
|
|
|
|
printf("Failed to chroot(%s)!\n", chroot_dir);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
set_cap(uid, gid,
|
|
|
|
"cap_net_bind_service,cap_net_broadcast,cap_net_raw=ep");
|
|
|
|
drop_root(uid, gid);
|
|
|
|
|
2010-12-24 20:42:41 +05:30
|
|
|
ifchange(NULL, IFCHANGE_DECONFIG);
|
2010-11-13 01:03:17 +05:30
|
|
|
|
|
|
|
do_work();
|
|
|
|
|
2011-03-30 01:04:00 +05:30
|
|
|
nl_close(&cs);
|
2010-11-13 01:03:17 +05:30
|
|
|
return EXIT_SUCCESS;
|
2010-11-12 14:32:18 +05:30
|
|
|
}
|