diff options
Diffstat (limited to 'networking/udhcp')
-rw-r--r-- | networking/udhcp/AUTHORS | 1 | ||||
-rw-r--r-- | networking/udhcp/ChangeLog | 2 | ||||
-rw-r--r-- | networking/udhcp/Makefile | 2 | ||||
-rw-r--r-- | networking/udhcp/Makefile.in | 2 | ||||
-rw-r--r-- | networking/udhcp/README | 16 | ||||
-rw-r--r-- | networking/udhcp/README.udhcpc | 10 | ||||
-rw-r--r-- | networking/udhcp/README.udhcpd | 8 | ||||
-rw-r--r-- | networking/udhcp/arpping.c | 16 | ||||
-rw-r--r-- | networking/udhcp/arpping.h | 2 | ||||
-rw-r--r-- | networking/udhcp/clientpacket.c | 32 | ||||
-rw-r--r-- | networking/udhcp/common.c | 2 | ||||
-rw-r--r-- | networking/udhcp/common.h | 2 | ||||
-rw-r--r-- | networking/udhcp/dhcpc.c | 48 | ||||
-rw-r--r-- | networking/udhcp/dhcpd.c | 34 | ||||
-rw-r--r-- | networking/udhcp/dhcpd.h | 4 | ||||
-rw-r--r-- | networking/udhcp/dumpleases.c | 10 | ||||
-rw-r--r-- | networking/udhcp/files.c | 44 | ||||
-rw-r--r-- | networking/udhcp/frontend.c | 4 | ||||
-rw-r--r-- | networking/udhcp/leases.c | 30 | ||||
-rw-r--r-- | networking/udhcp/options.c | 30 | ||||
-rw-r--r-- | networking/udhcp/packet.c | 18 | ||||
-rw-r--r-- | networking/udhcp/packet.h | 2 | ||||
-rw-r--r-- | networking/udhcp/script.c | 10 | ||||
-rw-r--r-- | networking/udhcp/serverpacket.c | 48 | ||||
-rw-r--r-- | networking/udhcp/socket.c | 8 |
25 files changed, 192 insertions, 193 deletions
diff --git a/networking/udhcp/AUTHORS b/networking/udhcp/AUTHORS index bb58de1..f3f4336 100644 --- a/networking/udhcp/AUTHORS +++ b/networking/udhcp/AUTHORS @@ -8,7 +8,6 @@ Chris Trew <christ@moreton.com.au> Other Credits: -------------- Moreton Bay (http://www.moretonbay.com/) -Lineo (http://opensource.lineo.com) Vladimir Oleynik <dzo@simtrea.ru> Size optimizations diff --git a/networking/udhcp/ChangeLog b/networking/udhcp/ChangeLog index f1aac06..2feffc7 100644 --- a/networking/udhcp/ChangeLog +++ b/networking/udhcp/ChangeLog @@ -39,7 +39,7 @@ (Ted Lemon <Ted.Lemon@nominum.com>) + Improved (hopefully) NAKing behavior (me) + Added -b option (Jouni Malinen) -+ Compute checksums correctly on big endian hosts ++ Compute checksums correctly on big endian hosts (Jouni Malinen <jkmaline@cc.hut.fi>) 0.9.7 (020526) diff --git a/networking/udhcp/Makefile b/networking/udhcp/Makefile index ee34d48..2b79d22 100644 --- a/networking/udhcp/Makefile +++ b/networking/udhcp/Makefile @@ -1,6 +1,6 @@ # Makefile for busybox # -# Copyright (C) 1999-2003 by Erik Andersen <andersen@codepoet.org> +# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> # # 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 diff --git a/networking/udhcp/Makefile.in b/networking/udhcp/Makefile.in index 4d3f270..b480794 100644 --- a/networking/udhcp/Makefile.in +++ b/networking/udhcp/Makefile.in @@ -1,6 +1,6 @@ # Makefile for busybox # -# Copyright (C) 1999-2003 by Erik Andersen <andersen@codepoet.org> +# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> # # 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 diff --git a/networking/udhcp/README b/networking/udhcp/README index eddb24b..dd99294 100644 --- a/networking/udhcp/README +++ b/networking/udhcp/README @@ -10,30 +10,30 @@ compile time options ------------------- The Makefile contains three of the compile time options: - + UDHCP_DEBUG: If UDHCP_DEBUG is defined, udhcpd will output extra debugging output, compile with -g, and not fork to the background when run. UDHCP_SYSLOG: If UDHCP_SYSLOG is defined, udhcpd will log all its messages syslog, otherwise, it will attempt to log them to stdout. - + COMBINED_BINARY: If COMBINED_BINARY is define, one binary, udhcpd, is created. If called as udhcpd, the dhcp server will be started. If called as udhcpc, the dhcp client will be started. - + dhcpd.h contains the other three compile time options: - + LEASE_TIME: The default lease time if not specified in the config file. LEASES_FILE: The default file for storing leases. - + DHCPD_CONFIG_FILE: The defualt config file to use. - + options.c contains a set of dhcp options for the client: name[10]: The name of the option as it will appear in scripts - + flags: The type of option, as well as if it will be requested by the client (OPTION_REQ) @@ -45,7 +45,7 @@ busybox drop-in udhcp is now a drop-in component for busybox (http://busybox.net). To update busybox to the latest revision, simply do a: -cp *.[ch] README AUTHORS COPYING ChangeLog TODO \ +cp *.[ch] README AUTHORS COPYING ChangeLog TODO \ <busybox_source>/networking/udhcp The only two files udhcp does not provide are config.in and diff --git a/networking/udhcp/README.udhcpc b/networking/udhcp/README.udhcpc index 8aee981..d720a37 100644 --- a/networking/udhcp/README.udhcpc +++ b/networking/udhcp/README.udhcpc @@ -36,20 +36,20 @@ udhcp client scripts When an event occurs, udhcpc calls the action script. udhcpc never does any configuration of the network interface itself, but instead relies on -a set of scripts. The script by default is +a set of scripts. The script by default is /usr/share/udhcpc/default.script but this can be changed via the command line arguments. The three possible arguments to the script are: deconfig: This argument is used when udhcpc starts, and when a leases is lost. The script must put the interface in an up, but deconfigured state, ie: ifconfig $interface 0.0.0.0. - + bound: This argument is used when udhcpc moves from an unbound, to a bound state. All of the paramaters are set in enviromental variables, The script should configure the interface, - and set any other relavent parameters (default gateway, dns server, + and set any other relavent parameters (default gateway, dns server, etc). - + renew: This argument is used when a DHCP lease is renewed. All of the paramaters are set in enviromental variables. This argument is used when the interface is already configured, so the IP address, @@ -133,7 +133,7 @@ compile time options options.c contains a set of dhcp options for the client: name[10]: The name of the option as it will appear in scripts - + flags: The type of option, as well as if it will be requested by the client (OPTION_REQ) diff --git a/networking/udhcp/README.udhcpd b/networking/udhcp/README.udhcpd index bc6137d..169de78 100644 --- a/networking/udhcp/README.udhcpd +++ b/networking/udhcp/README.udhcpd @@ -14,7 +14,7 @@ udhcpd.leases The udhcpd.leases behavior is designed for an embedded system. The file is written either every auto_time seconds, or when a SIGUSR1 -is received (the auto_time timer restarts if a SIGUSR1 is received). +is received (the auto_time timer restarts if a SIGUSR1 is received). If you send a SIGTERM to udhcpd directly after a SIGUSR1, udhcpd will finish writing the leases file and wait for the aftermentioned script to be executed and finish before quiting, so you do not need to sleep @@ -50,10 +50,10 @@ available options and comments describing them in samples/udhcpd.conf compile time options ------------------- - + dhcpd.h contains the other two compile time options: - + LEASE_TIME: The default lease time if not specified in the config file. - + DHCPD_CONFIG_FILE: The defualt config file to use. diff --git a/networking/udhcp/arpping.c b/networking/udhcp/arpping.c index 23c7d46..ab4c6d2 100644 --- a/networking/udhcp/arpping.c +++ b/networking/udhcp/arpping.c @@ -25,8 +25,8 @@ * interface - interface to use * retn: 1 addr free * 0 addr used - * -1 error - */ + * -1 error + */ /* FIXME: match response against chaddr */ int arpping(uint32_t yiaddr, uint32_t ip, uint8_t *mac, char *interface) @@ -51,7 +51,7 @@ int arpping(uint32_t yiaddr, uint32_t ip, uint8_t *mac, char *interface) #endif return -1; } - + if (setsockopt(s, SOL_SOCKET, SO_BROADCAST, &optval, sizeof(optval)) == -1) { LOG(LOG_ERR, "Could not setsocketopt on raw socket"); close(s); @@ -71,12 +71,12 @@ int arpping(uint32_t yiaddr, uint32_t ip, uint8_t *mac, char *interface) memcpy(arp.sInaddr, &ip, sizeof(ip)); /* source IP address */ memcpy(arp.sHaddr, mac, 6); /* source hardware address */ memcpy(arp.tInaddr, &yiaddr, sizeof(yiaddr)); /* target IP address */ - + memset(&addr, 0, sizeof(addr)); strcpy(addr.sa_data, interface); if (sendto(s, &arp, sizeof(arp), 0, &addr, sizeof(addr)) < 0) rv = 0; - + /* wait arp reply, and check it */ tm.tv_usec = 0; time(&prevTime); @@ -89,8 +89,8 @@ int arpping(uint32_t yiaddr, uint32_t ip, uint8_t *mac, char *interface) if (errno != EINTR) rv = 0; } else if (FD_ISSET(s, &fdset)) { if (recv(s, &arp, sizeof(arp), 0) < 0 ) rv = 0; - if (arp.operation == htons(ARPOP_REPLY) && - bcmp(arp.tHaddr, mac, 6) == 0 && + if (arp.operation == htons(ARPOP_REPLY) && + bcmp(arp.tHaddr, mac, 6) == 0 && *((uint32_t *) arp.sInaddr) == yiaddr) { DEBUG(LOG_INFO, "Valid arp reply receved for this address"); rv = 0; @@ -101,6 +101,6 @@ int arpping(uint32_t yiaddr, uint32_t ip, uint8_t *mac, char *interface) time(&prevTime); } close(s); - DEBUG(LOG_INFO, "%salid arp replies for this address", rv ? "No v" : "V"); + DEBUG(LOG_INFO, "%salid arp replies for this address", rv ? "No v" : "V"); return rv; } diff --git a/networking/udhcp/arpping.h b/networking/udhcp/arpping.h index 6cbd297..6f27d9f 100644 --- a/networking/udhcp/arpping.h +++ b/networking/udhcp/arpping.h @@ -15,7 +15,7 @@ struct arpMsg { u_char h_dest[6]; /* destination ether addr */ u_char h_source[6]; /* source ether addr */ u_short h_proto; /* packet type ID field */ - + /* ARP packet */ uint16_t htype; /* hardware type (must be ARPHRD_ETHER) */ uint16_t ptype; /* protocol type (must be ETH_P_IP) */ diff --git a/networking/udhcp/clientpacket.c b/networking/udhcp/clientpacket.c index 6838c07..5b27004 100644 --- a/networking/udhcp/clientpacket.c +++ b/networking/udhcp/clientpacket.c @@ -18,7 +18,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - + #include <string.h> #include <sys/socket.h> #include <features.h> @@ -73,7 +73,7 @@ static void init_packet(struct dhcpMessage *packet, char type) char vendor, length; char str[sizeof("udhcp "VERSION)]; } vendor_id = { DHCP_VENDOR, sizeof("udhcp "VERSION) - 1, "udhcp "VERSION}; - + init_header(packet, type); memcpy(packet->chaddr, client_config.arp, 6); add_option_string(packet->options, client_config.clientid); @@ -112,7 +112,7 @@ int send_discover(unsigned long xid, unsigned long requested) add_requests(&packet); LOG(LOG_DEBUG, "Sending discover..."); - return raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST, + return raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST, SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex); } @@ -128,11 +128,11 @@ int send_selecting(unsigned long xid, unsigned long server, unsigned long reques add_simple_option(packet.options, DHCP_REQUESTED_IP, requested); add_simple_option(packet.options, DHCP_SERVER_ID, server); - + add_requests(&packet); addr.s_addr = requested; LOG(LOG_DEBUG, "Sending select for %s...", inet_ntoa(addr)); - return raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST, + return raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST, SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex); } @@ -149,12 +149,12 @@ int send_renew(unsigned long xid, unsigned long server, unsigned long ciaddr) add_requests(&packet); LOG(LOG_DEBUG, "Sending renew..."); - if (server) + if (server) ret = kernel_packet(&packet, ciaddr, CLIENT_PORT, server, SERVER_PORT); else ret = raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST, SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex); return ret; -} +} /* Unicasts a DHCP release message */ @@ -165,7 +165,7 @@ int send_release(unsigned long server, unsigned long ciaddr) init_packet(&packet, DHCPRELEASE); packet.xid = random_xid(); packet.ciaddr = ciaddr; - + add_simple_option(packet.options, DHCP_REQUESTED_IP, ciaddr); add_simple_option(packet.options, DHCP_SERVER_ID, server); @@ -189,20 +189,20 @@ int get_raw_packet(struct dhcpMessage *payload, int fd) usleep(500000); /* possible down interface, looping condition */ return -1; } - + if (bytes < (int) (sizeof(struct iphdr) + sizeof(struct udphdr))) { DEBUG(LOG_INFO, "message too short, ignoring"); return -2; } - + if (bytes < ntohs(packet.ip.tot_len)) { DEBUG(LOG_INFO, "Truncated packet"); return -2; } - + /* ignore any extra garbage bytes */ bytes = ntohs(packet.ip.tot_len); - + /* Make sure its the right packet for us, and that it passes sanity checks */ if (packet.ip.protocol != IPPROTO_UDP || packet.ip.version != IPVERSION || packet.ip.ihl != sizeof(packet.ip) >> 2 || packet.udp.dest != htons(CLIENT_PORT) || @@ -219,7 +219,7 @@ int get_raw_packet(struct dhcpMessage *payload, int fd) DEBUG(LOG_INFO, "bad IP header checksum, ignoring"); return -1; } - + /* verify the UDP checksum by replacing the header with a psuedo header */ source = packet.ip.saddr; dest = packet.ip.daddr; @@ -235,14 +235,14 @@ int get_raw_packet(struct dhcpMessage *payload, int fd) DEBUG(LOG_ERR, "packet with bad UDP checksum received, ignoring"); return -2; } - + memcpy(payload, &(packet.data), bytes - (sizeof(packet.ip) + sizeof(packet.udp))); - + if (ntohl(payload->cookie) != DHCP_MAGIC) { LOG(LOG_ERR, "received bogus message (bad magic) -- ignoring"); return -2; } DEBUG(LOG_INFO, "oooooh!!! got some!"); return bytes - (sizeof(packet.ip) + sizeof(packet.udp)); - + } diff --git a/networking/udhcp/common.c b/networking/udhcp/common.c index 8542c66..5dad7d5 100644 --- a/networking/udhcp/common.c +++ b/networking/udhcp/common.c @@ -55,7 +55,7 @@ static inline void sanitize_fds(void) void background(const char *pidfile) { #ifdef __uClinux__ - LOG(LOG_ERR, "Cannot background in uclinux (yet)"); + LOG(LOG_ERR, "Cannot background in uclinux (yet)"); #else /* __uClinux__ */ int pid_fd; diff --git a/networking/udhcp/common.h b/networking/udhcp/common.h index 78eb1c1..677bbfd 100644 --- a/networking/udhcp/common.h +++ b/networking/udhcp/common.h @@ -43,7 +43,7 @@ void background(const char *pidfile); void start_log_and_pid(const char *client_server, const char *pidfile); void background(const char *pidfile); void udhcp_logging(int level, const char *fmt, ...); - + #define LOG(level, str, args...) udhcp_logging(level, str, ## args) #ifdef UDHCP_DEBUG diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index 2ba42d2..dda6789 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c @@ -18,7 +18,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - + #include <sys/time.h> #include <sys/file.h> #include <unistd.h> @@ -152,7 +152,7 @@ static void perform_release(void) temp_addr.s_addr = server_addr; sprintf(buffer, "%s", inet_ntoa(temp_addr)); temp_addr.s_addr = requested_ip; - LOG(LOG_INFO, "Unicasting a release of %s to %s", + LOG(LOG_INFO, "Unicasting a release of %s to %s", inet_ntoa(temp_addr), buffer); send_release(server_addr, requested_ip); /* unicast */ run_script(NULL, "deconfig"); @@ -213,7 +213,7 @@ int main(int argc, char *argv[]) int option_index = 0; c = getopt_long(argc, argv, "c:fbH:h:i:np:qr:s:v", arg_options, &option_index); if (c == -1) break; - + switch (c) { case 'c': len = strlen(optarg) > 255 ? 255 : strlen(optarg); @@ -269,10 +269,10 @@ int main(int argc, char *argv[]) /* Start the log, sanitize fd's, and write a pid file */ start_log_and_pid("udhcpc", client_config.pidfile); - if (read_interface(client_config.interface, &client_config.ifindex, + if (read_interface(client_config.interface, &client_config.ifindex, NULL, client_config.arp) < 0) return 1; - + if (!client_config.clientid) { client_config.clientid = xmalloc(6 + 3); client_config.clientid[OPT_CODE] = DHCP_CLIENT_ID; @@ -282,8 +282,8 @@ int main(int argc, char *argv[]) } /* setup the signal pipe */ - udhcp_sp_setup(); - + udhcp_sp_setup(); + state = INIT_SELECTING; run_script(NULL, "deconfig"); change_mode(LISTEN_RAW); @@ -321,7 +321,7 @@ int main(int argc, char *argv[]) /* send discover packet */ send_discover(xid, requested_ip); /* broadcast */ - + timeout = now + ((packet_num == 2) ? 4 : 2); packet_num++; } else { @@ -345,7 +345,7 @@ int main(int argc, char *argv[]) if (state == RENEW_REQUESTED) send_renew(xid, server_addr, requested_ip); /* unicast */ else send_selecting(xid, server_addr, requested_ip); /* broadcast */ - + timeout = now + ((packet_num == 2) ? 10 : 2); packet_num++; } else { @@ -373,7 +373,7 @@ int main(int argc, char *argv[]) } else { /* send a request packet */ send_renew(xid, server_addr, requested_ip); /* unicast */ - + t1 = (t2 - t1) / 2 + t1; timeout = t1 + start; } @@ -403,28 +403,28 @@ int main(int argc, char *argv[]) } } else if (retval > 0 && listen_mode != LISTEN_NONE && FD_ISSET(fd, &rfds)) { /* a packet is ready, read it */ - + if (listen_mode == LISTEN_KERNEL) len = get_packet(&packet, fd); else len = get_raw_packet(&packet, fd); - + if (len == -1 && errno != EINTR) { DEBUG(LOG_INFO, "error on read, %m, reopening socket"); change_mode(listen_mode); /* just close and reopen */ } if (len < 0) continue; - + if (packet.xid != xid) { DEBUG(LOG_INFO, "Ignoring XID %lx (our xid is %lx)", (unsigned long) packet.xid, xid); continue; } - + if ((message = get_option(&packet, DHCP_MESSAGE_TYPE)) == NULL) { DEBUG(LOG_ERR, "couldnt get option from packet -- ignoring"); continue; } - + switch (state) { case INIT_SELECTING: /* Must be a DHCPOFFER to one of our xid's */ @@ -433,7 +433,7 @@ int main(int argc, char *argv[]) memcpy(&server_addr, temp, 4); xid = packet.xid; requested_ip = packet.yiaddr; - + /* enter requesting state */ state = REQUESTING; timeout = now; @@ -455,14 +455,14 @@ int main(int argc, char *argv[]) memcpy(&lease, temp, 4); lease = ntohl(lease); } - + /* enter bound state */ t1 = lease / 2; - + /* little fixed point for n * .875 */ t2 = (lease * 0x7) >> 3; temp_addr.s_addr = packet.yiaddr; - LOG(LOG_INFO, "Lease of %s obtained, lease time %ld", + LOG(LOG_INFO, "Lease of %s obtained, lease time %ld", inet_ntoa(temp_addr), lease); start = now; timeout = t1 + start; @@ -472,7 +472,7 @@ int main(int argc, char *argv[]) state = BOUND; change_mode(LISTEN_NONE); - if (client_config.quit_after_lease) + if (client_config.quit_after_lease) return 0; if (!client_config.foreground) client_background(); @@ -492,10 +492,10 @@ int main(int argc, char *argv[]) } break; /* case BOUND, RELEASED: - ignore all packets */ - } + } } else if (retval > 0 && (sig = udhcp_sp_read(&rfds))) { switch (sig) { - case SIGUSR1: + case SIGUSR1: perform_renew(); break; case SIGUSR2: @@ -506,12 +506,12 @@ int main(int argc, char *argv[]) return 0; } } else if (retval == -1 && errno == EINTR) { - /* a signal was caught */ + /* a signal was caught */ } else { /* An error occured */ DEBUG(LOG_ERR, "Error on select"); } - + } return 0; } diff --git a/networking/udhcp/dhcpd.c b/networking/udhcp/dhcpd.c index 8c944f2..6f38f07 100644 --- a/networking/udhcp/dhcpd.c +++ b/networking/udhcp/dhcpd.c @@ -51,12 +51,12 @@ struct dhcpOfferedAddr *leases; struct server_config_t server_config; -#ifdef COMBINED_BINARY +#ifdef COMBINED_BINARY int udhcpd_main(int argc, char *argv[]) #else int main(int argc, char *argv[]) #endif -{ +{ fd_set rfds; struct timeval tv; int server_socket = -1; @@ -70,7 +70,7 @@ int main(int argc, char *argv[]) struct dhcpOfferedAddr *lease; int max_sock; unsigned long num_ips; - + memset(&server_config, 0, sizeof(struct server_config_t)); read_config(argc < 2 ? DHCPD_CONF_FILE : argv[1]); @@ -82,7 +82,7 @@ int main(int argc, char *argv[]) server_config.lease = ntohl(server_config.lease); } else server_config.lease = LEASE_TIME; - + /* Sanity check */ num_ips = ntohl(server_config.end) - ntohl(server_config.start); if (server_config.max_leases > num_ips) { @@ -113,7 +113,7 @@ int main(int argc, char *argv[]) if ((server_socket = listen_socket(INADDR_ANY, SERVER_PORT, server_config.interface)) < 0) { LOG(LOG_ERR, "FATAL: couldn't create server socket, %m"); return 2; - } + } max_sock = udhcp_sp_fd_set(&rfds, server_socket); if (server_config.auto_time) { @@ -121,7 +121,7 @@ int main(int argc, char *argv[]) tv.tv_usec = 0; } if (!server_config.auto_time || tv.tv_sec > 0) { - retval = select(max_sock + 1, &rfds, NULL, NULL, + retval = select(max_sock + 1, &rfds, NULL, NULL, server_config.auto_time ? &tv : NULL); } else retval = 0; /* If we already timed out, fall through */ @@ -133,7 +133,7 @@ int main(int argc, char *argv[]) DEBUG(LOG_INFO, "error on select"); continue; } - + switch (udhcp_sp_read(&rfds)) { case SIGUSR1: LOG(LOG_INFO, "Received a SIGUSR1"); @@ -161,17 +161,17 @@ int main(int argc, char *argv[]) DEBUG(LOG_ERR, "couldn't get option from packet, ignoring"); continue; } - + /* ADDME: look for a static lease */ lease = find_lease_by_chaddr(packet.chaddr); switch (state[0]) { case DHCPDISCOVER: DEBUG(LOG_INFO,"received DISCOVER"); - + if (sendOffer(&packet) < 0) { LOG(LOG_ERR, "send OFFER failed"); } - break; + break; case DHCPREQUEST: DEBUG(LOG_INFO, "received REQUEST"); @@ -180,12 +180,12 @@ int main(int argc, char *argv[]) if (requested) memcpy(&requested_align, requested, 4); if (server_id) memcpy(&server_id_align, server_id, 4); - + if (lease) { /*ADDME: or static lease */ if (server_id) { /* SELECTING State */ DEBUG(LOG_INFO, "server_id = %08x", ntohl(server_id_align)); - if (server_id_align == server_config.server && requested && + if (server_id_align == server_config.server && requested && requested_align == lease->yiaddr) { sendACK(&packet, lease->yiaddr); } @@ -203,9 +203,9 @@ int main(int argc, char *argv[]) /* don't know what to do!!!! */ sendNAK(&packet); } - } + } } - + /* what to do if we have no record of the client */ } else if (server_id) { /* SELECTING State */ @@ -218,7 +218,7 @@ int main(int argc, char *argv[]) memset(lease->chaddr, 0, 16); /* make some contention for this address */ } else sendNAK(&packet); - } else if (requested_align < server_config.start || + } else if (requested_align < server_config.start || requested_align > server_config.end) { sendNAK(&packet); } /* else remain silent */ @@ -232,7 +232,7 @@ int main(int argc, char *argv[]) if (lease) { memset(lease->chaddr, 0, 16); lease->expires = time(0) + server_config.decline_time; - } + } break; case DHCPRELEASE: DEBUG(LOG_INFO,"received RELEASE"); @@ -241,7 +241,7 @@ int main(int argc, char *argv[]) case DHCPINFORM: DEBUG(LOG_INFO,"received INFORM"); send_inform(&packet); - break; + break; default: LOG(LOG_WARNING, "unsupported DHCP message (%02x) -- ignoring", state[0]); } diff --git a/networking/udhcp/dhcpd.h b/networking/udhcp/dhcpd.h index 9256344..39658a8 100644 --- a/networking/udhcp/dhcpd.h +++ b/networking/udhcp/dhcpd.h @@ -124,10 +124,10 @@ struct server_config_t { uint32_t siaddr; /* next server bootp option */ char *sname; /* bootp server name */ char *boot_file; /* bootp boot file option */ -}; +}; extern struct server_config_t server_config; extern struct dhcpOfferedAddr *leases; - + #endif diff --git a/networking/udhcp/dumpleases.c b/networking/udhcp/dumpleases.c index e2b1931..a9036df 100644 --- a/networking/udhcp/dumpleases.c +++ b/networking/udhcp/dumpleases.c @@ -47,7 +47,7 @@ int main(int argc, char *argv[]) const char *file = LEASES_FILE; struct dhcpOfferedAddr lease; struct in_addr addr; - + static const struct option options[] = { {"absolute", 0, 0, 'a'}, {"remaining", 0, 0, 'r'}, @@ -59,7 +59,7 @@ int main(int argc, char *argv[]) int option_index = 0; c = getopt_long(argc, argv, "arf:", options, &option_index); if (c == -1) break; - + switch (c) { case 'a': mode = ABSOLUTE; break; case 'r': mode = REMAINING; break; @@ -70,10 +70,10 @@ int main(int argc, char *argv[]) show_usage(); } } - + fp = xfopen(file, "r"); - printf("Mac Address IP-Address Expires %s\n", mode == REMAINING ? "in" : "at"); + printf("Mac Address IP-Address Expires %s\n", mode == REMAINING ? "in" : "at"); /* "00:00:00:00:00:00 255.255.255.255 Wed Jun 30 21:49:08 1993" */ while (fread(&lease, sizeof(lease), 1, fp)) { @@ -105,6 +105,6 @@ int main(int argc, char *argv[]) } else printf("%s", ctime(&expires)); } fclose(fp); - + return 0; } diff --git a/networking/udhcp/files.c b/networking/udhcp/files.c index 0802bb3..89287ca 100644 --- a/networking/udhcp/files.c +++ b/networking/udhcp/files.c @@ -1,8 +1,8 @@ -/* +/* * files.c -- DHCP server file manipulation * * Rewrite by Russ Dill <Russ.Dill@asu.edu> July 2001 */ - + #include <sys/socket.h> #include <arpa/inet.h> #include <string.h> @@ -16,7 +16,7 @@ #include "options.h" #include "common.h" -/* +/* * Domain names may have 254 chars, and string options can be 254 * chars long. However, 80 bytes will be enough for most, and won't * hog up memory. If you have a special application, change it @@ -31,7 +31,7 @@ static int read_ip(const char *line, void *arg) int retval = 1; if (!inet_aton(line, addr)) { - if ((host = gethostbyname(line))) + if ((host = gethostbyname(line))) addr->s_addr = *((unsigned long *) host->h_addr_list[0]); else retval = 0; } @@ -42,10 +42,10 @@ static int read_ip(const char *line, void *arg) static int read_str(const char *line, void *arg) { char **dest = arg; - + if (*dest) free(*dest); *dest = strdup(line); - + return 1; } @@ -69,7 +69,7 @@ static int read_yn(const char *line, void *arg) else if (!strcasecmp("no", line)) *dest = 0; else retval = 0; - + return retval; } @@ -89,11 +89,11 @@ static int read_opt(const char *const_line, void *arg) /* Cheat, the only const line we'll actually get is "" */ line = (char *) const_line; if (!(opt = strtok(line, " \t="))) return 0; - + for (option = dhcp_options; option->code; option++) if (!strcasecmp(option->name, opt)) break; - + if (!option->code) return 0; do { @@ -134,17 +134,17 @@ static int read_opt(const char *const_line, void *arg) retval = (endptr[0] == '\0'); break; case OPTION_U32: - *result_u32 = htonl(strtoul(val, &endptr, 0)); + *result_u32 = htonl(strtoul(val, &endptr, 0)); retval = (endptr[0] == '\0'); break; case OPTION_S32: - *result_u32 = htonl(strtol(val, &endptr, 0)); + *result_u32 = htonl(strtol(val, &endptr, 0)); retval = (endptr[0] == '\0'); break; default: break; } - if (retval) + if (retval) attach_option(opt_list, option, opt, length); } while (retval && option->flags & OPTION_LIST); return retval; @@ -193,7 +193,7 @@ int read_config(const char *file) LOG(LOG_ERR, "unable to open config file: %s", file); return 0; } - + while (fgets(buffer, READ_CONFIG_BUF_SIZE, in)) { lm++; if (strchr(buffer, '\n')) *(strchr(buffer, '\n')) = '\0'; @@ -203,14 +203,14 @@ int read_config(const char *file) if (strchr(buffer, '#')) *(strchr(buffer, '#')) = '\0'; if (!(token = strtok(buffer, " \t"))) continue; - if (!(line = strtok(NULL, ""))) continue; - + if (!(line = strtok(NULL, ""))) continue; + /* eat leading whitespace */ line = line + strspn(line, " \t="); /* eat trailing whitespace */ for (i = strlen(line); i > 0 && isspace(line[i - 1]); i--); line[i] = '\0'; - + for (i = 0; keywords[i].keyword[0]; i++) if (!strcasecmp(token, keywords[i].keyword)) if (!keywords[i].handler(line, keywords[i].var)) { @@ -232,12 +232,12 @@ void write_leases(void) char buf[255]; time_t curr = time(0); unsigned long tmp_time; - + if (!(fp = fopen(server_config.lease_file, "w"))) { LOG(LOG_ERR, "Unable to open %s for writing", server_config.lease_file); return; } - + for (i = 0; i < server_config.max_leases; i++) { if (leases[i].yiaddr != 0) { @@ -257,7 +257,7 @@ void write_leases(void) } } fclose(fp); - + if (server_config.notify_file) { sprintf(buf, "%s %s", server_config.notify_file, server_config.lease_file); system(buf); @@ -270,12 +270,12 @@ void read_leases(const char *file) FILE *fp; unsigned int i = 0; struct dhcpOfferedAddr lease; - + if (!(fp = fopen(file, "r"))) { LOG(LOG_ERR, "Unable to open %s for reading", file); return; } - + while (i < server_config.max_leases && (fread(&lease, sizeof lease, 1, fp) == 1)) { /* ADDME: is it a static lease */ if (lease.yiaddr >= server_config.start && lease.yiaddr <= server_config.end) { @@ -284,7 +284,7 @@ void read_leases(const char *file) if (!(add_lease(lease.chaddr, lease.yiaddr, lease.expires))) { LOG(LOG_WARNING, "Too many leases while loading %s\n", file); break; - } + } i++; } } diff --git a/networking/udhcp/frontend.c b/networking/udhcp/frontend.c index de57795..fa77ab9 100644 --- a/networking/udhcp/frontend.c +++ b/networking/udhcp/frontend.c @@ -7,10 +7,10 @@ int main(int argc, char *argv[]) { int ret = 0; char *base = strrchr(argv[0], '/'); - + if (strstr(base ? (base + 1) : argv[0], "dhcpd")) ret = udhcpd_main(argc, argv); else ret = udhcpc_main(argc, argv); - + return ret; } diff --git a/networking/udhcp/leases.c b/networking/udhcp/leases.c index dce0566..d478880 100644 --- a/networking/udhcp/leases.c +++ b/networking/udhcp/leases.c @@ -1,5 +1,5 @@ -/* - * leases.c -- tools to manage DHCP leases +/* + * leases.c -- tools to manage DHCP leases * Russ Dill <Russ.Dill@asu.edu> July 2001 */ @@ -23,9 +23,9 @@ uint8_t blank_chaddr[] = {[0 ... 15] = 0}; void clear_lease(uint8_t *chaddr, uint32_t yiaddr) { unsigned int i, j; - + for (j = 0; j < 16 && !chaddr[j]; j++); - + for (i = 0; i < server_config.max_leases; i++) if ((j != 16 && !memcmp(leases[i].chaddr, chaddr, 16)) || (yiaddr && leases[i].yiaddr == yiaddr)) { @@ -38,18 +38,18 @@ void clear_lease(uint8_t *chaddr, uint32_t yiaddr) struct dhcpOfferedAddr *add_lease(uint8_t *chaddr, uint32_t yiaddr, unsigned long lease) { struct dhcpOfferedAddr *oldest; - + /* clean out any old ones */ clear_lease(chaddr, yiaddr); - + oldest = oldest_expired_lease(); - + if (oldest) { memcpy(oldest->chaddr, chaddr, 16); oldest->yiaddr = yiaddr; oldest->expires = time(0) + lease; } - + return oldest; } @@ -58,7 +58,7 @@ struct dhcpOfferedAddr *add_lease(uint8_t *chaddr, uint32_t yiaddr, unsigned lon int lease_expired(struct dhcpOfferedAddr *lease) { return (lease->expires < (unsigned long) time(0)); -} +} /* Find the oldest expired lease, NULL if there are no expired leases */ @@ -68,14 +68,14 @@ struct dhcpOfferedAddr *oldest_expired_lease(void) unsigned long oldest_lease = time(0); unsigned int i; - + for (i = 0; i < server_config.max_leases; i++) if (oldest_lease > leases[i].expires) { oldest_lease = leases[i].expires; oldest = &(leases[i]); } return oldest; - + } @@ -86,7 +86,7 @@ struct dhcpOfferedAddr *find_lease_by_chaddr(uint8_t *chaddr) for (i = 0; i < server_config.max_leases; i++) if (!memcmp(leases[i].chaddr, chaddr, 16)) return &(leases[i]); - + return NULL; } @@ -98,7 +98,7 @@ struct dhcpOfferedAddr *find_lease_by_yiaddr(uint32_t yiaddr) for (i = 0; i < server_config.max_leases; i++) if (leases[i].yiaddr == yiaddr) return &(leases[i]); - + return NULL; } @@ -120,10 +120,10 @@ static int check_ip(uint32_t addr) /* find an assignable address, it check_expired is true, we check all the expired leases as well. * Maybe this should try expired leases by age... */ -uint32_t find_address(int check_expired) +uint32_t find_address(int check_expired) { uint32_t addr, ret; - struct dhcpOfferedAddr *lease = NULL; + struct dhcpOfferedAddr *lease = NULL; addr = ntohl(server_config.start); /* addr is in host order here */ for (;addr <= ntohl(server_config.end); addr++) { diff --git a/networking/udhcp/options.c b/networking/udhcp/options.c index 1bdf257..d75bc5a 100644 --- a/networking/udhcp/options.c +++ b/networking/udhcp/options.c @@ -1,8 +1,8 @@ -/* - * options.c -- DHCP server option packet tools +/* + * options.c -- DHCP server option packet tools * Rewrite by Russ Dill <Russ.Dill@asu.edu> July 2001 */ - + #include <stdlib.h> #include <string.h> @@ -64,7 +64,7 @@ uint8_t *get_option(struct dhcpMessage *packet, int code) int i, length; uint8_t *optionptr; int over = 0, done = 0, curr = OPTION_FIELD; - + optionptr = packet->options; i = 0; length = 308; @@ -79,7 +79,7 @@ uint8_t *get_option(struct dhcpMessage *packet, int code) return NULL; } return optionptr + i + 2; - } + } switch (optionptr[i + OPT_CODE]) { case DHCP_PADDING: i++; @@ -114,10 +114,10 @@ uint8_t *get_option(struct dhcpMessage *packet, int code) /* return the position of the 'end' option (no bounds checking) */ -int end_option(uint8_t *optionptr) +int end_option(uint8_t *optionptr) { int i = 0; - + while (optionptr[i] != DHCP_END) { if (optionptr[i] == DHCP_PADDING) i++; else i += optionptr[i + OPT_LEN] + 2; @@ -131,7 +131,7 @@ int end_option(uint8_t *optionptr) int add_option_string(uint8_t *optionptr, uint8_t *string) { int end = end_option(optionptr); - + /* end position + string length + option code/length + end option */ if (end + string[OPT_LEN] + 2 + 1 >= 308) { LOG(LOG_ERR, "Option 0x%02x did not fit into the packet!", string[OPT_CODE]); @@ -162,12 +162,12 @@ int add_simple_option(uint8_t *optionptr, uint8_t code, uint32_t data) if (dhcp_options[i].code == code) { length = option_lengths[dhcp_options[i].flags & TYPE_MASK]; } - + if (!length) { DEBUG(LOG_ERR, "Could not add option 0x%02x", code); return 0; } - + option[OPT_CODE] = code; option[OPT_LEN] = length; @@ -202,7 +202,7 @@ void attach_option(struct option_set **opt_list, struct dhcp_option *option, cha DEBUG(LOG_INFO, "Attaching option %s to existing member of list", option->name); if (option->flags & OPTION_LIST) { if (existing->data[OPT_LEN] + length <= 255) { - existing->data = realloc(existing->data, + existing->data = realloc(existing->data, existing->data[OPT_LEN] + length + 2); memcpy(existing->data + existing->data[OPT_LEN] + 2, buffer, length); existing->data[OPT_LEN] += length; @@ -210,19 +210,19 @@ void attach_option(struct option_set **opt_list, struct dhcp_option *option, cha } /* else, ignore the new data */ } else { DEBUG(LOG_INFO, "Attaching option %s to list", option->name); - + /* make a new option */ new = xmalloc(sizeof(struct option_set)); new->data = xmalloc(length + 2); new->data[OPT_CODE] = option->code; new->data[OPT_LEN] = length; memcpy(new->data + 2, buffer, length); - + curr = opt_list; while (*curr && (*curr)->data[OPT_CODE] < option->code) curr = &(*curr)->next; - + new->next = *curr; - *curr = new; + *curr = new; } } diff --git a/networking/udhcp/packet.c b/networking/udhcp/packet.c index a3c7ae1..7cbd83a 100644 --- a/networking/udhcp/packet.c +++ b/networking/udhcp/packet.c @@ -66,7 +66,7 @@ int get_packet(struct dhcpMessage *packet, int fd) return -2; } DEBUG(LOG_INFO, "Received a packet"); - + if (packet->op == BOOTREQUEST && (vendor = get_option(packet, DHCP_VENDOR))) { for (i = 0; broken_vendors[i][0]; i++) { if (vendor[OPT_LEN - 2] == (uint8_t) strlen(broken_vendors[i]) && @@ -77,7 +77,7 @@ int get_packet(struct dhcpMessage *packet, int fd) } } } - + return bytes; } @@ -126,10 +126,10 @@ int raw_packet(struct dhcpMessage *payload, uint32_t source_ip, int source_port, DEBUG(LOG_ERR, "socket call failed: %m"); return -1; } - + memset(&dest, 0, sizeof(dest)); memset(&packet, 0, sizeof(packet)); - + dest.sll_family = AF_PACKET; dest.sll_protocol = htons(ETH_P_IP); dest.sll_ifindex = ifindex; @@ -150,7 +150,7 @@ int raw_packet(struct dhcpMessage *payload, uint32_t source_ip, int source_port, packet.ip.tot_len = packet.udp.len; memcpy(&(packet.data), payload, sizeof(struct dhcpMessage)); packet.udp.check = checksum(&packet, sizeof(struct udp_dhcp_packet)); - + packet.ip.tot_len = htons(sizeof(struct udp_dhcp_packet)); packet.ip.ihl = sizeof(packet.ip) >> 2; packet.ip.version = IPVERSION; @@ -173,10 +173,10 @@ int kernel_packet(struct dhcpMessage *payload, uint32_t source_ip, int source_po int n = 1; int fd, result; struct sockaddr_in client; - + if ((fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) return -1; - + if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *) &n, sizeof(n)) == -1) return -1; @@ -191,7 +191,7 @@ int kernel_packet(struct dhcpMessage *payload, uint32_t source_ip, int source_po memset(&client, 0, sizeof(client)); client.sin_family = AF_INET; client.sin_port = htons(dest_port); - client.sin_addr.s_addr = dest_ip; + client.sin_addr.s_addr = dest_ip; if (connect(fd, (struct sockaddr *)&client, sizeof(struct sockaddr)) == -1) return -1; @@ -199,4 +199,4 @@ int kernel_packet(struct dhcpMessage *payload, uint32_t source_ip, int source_po result = write(fd, payload, sizeof(struct dhcpMessage)); close(fd); return result; -} +} diff --git a/networking/udhcp/packet.h b/networking/udhcp/packet.h index 22c4d09..f5859e8 100644 --- a/networking/udhcp/packet.h +++ b/networking/udhcp/packet.h @@ -20,7 +20,7 @@ struct dhcpMessage { uint8_t sname[64]; uint8_t file[128]; uint32_t cookie; - uint8_t options[308]; /* 312 - cookie */ + uint8_t options[308]; /* 312 - cookie */ }; struct udp_dhcp_packet { diff --git a/networking/udhcp/script.c b/networking/udhcp/script.c index b7d7862..cae4db7 100644 --- a/networking/udhcp/script.c +++ b/networking/udhcp/script.c @@ -1,6 +1,6 @@ /* script.c * - * Functions to call the DHCP client notification scripts + * Functions to call the DHCP client notification scripts * * Russ Dill <Russ.Dill@asu.edu> July 2001 * @@ -157,7 +157,7 @@ static char **fill_envp(struct dhcpMessage *packet) if (!(over & FILE_FIELD) && packet->file[0]) num_options++; if (!(over & SNAME_FIELD) && packet->sname[0]) num_options++; } - + envp = xcalloc(sizeof(char *), num_options + 5); j = 0; asprintf(&envp[j++], "interface=%s", client_config.interface); @@ -220,13 +220,13 @@ void run_script(struct dhcpMessage *packet, const char *name) return; } else if (pid == 0) { envp = fill_envp(packet); - + /* close fd's? */ - + /* exec script */ execle(client_config.script, client_config.script, name, NULL, envp); LOG(LOG_ERR, "script %s failed: %m", client_config.script); exit(1); - } + } } diff --git a/networking/udhcp/serverpacket.c b/networking/udhcp/serverpacket.c index d39e6ba..937436a 100644 --- a/networking/udhcp/serverpacket.c +++ b/networking/udhcp/serverpacket.c @@ -45,7 +45,7 @@ static int send_packet_to_client(struct dhcpMessage *payload, int force_broadcas { uint8_t *chaddr; uint32_t ciaddr; - + if (force_broadcast) { DEBUG(LOG_INFO, "broadcasting packet to client (NAK)"); ciaddr = INADDR_BROADCAST; @@ -63,7 +63,7 @@ static int send_packet_to_client(struct dhcpMessage *payload, int force_broadcas ciaddr = payload->yiaddr; chaddr = payload->chaddr; } - return raw_packet(payload, server_config.server, SERVER_PORT, + return raw_packet(payload, server_config.server, SERVER_PORT, ciaddr, CLIENT_PORT, chaddr, server_config.ifindex); } @@ -101,7 +101,7 @@ static void add_bootp_options(struct dhcpMessage *packet) if (server_config.boot_file) strncpy(packet->file, server_config.boot_file, sizeof(packet->file) - 1); } - + /* send a DHCP OFFER to a DHCP DISCOVER */ int sendOffer(struct dhcpMessage *oldpacket) @@ -114,14 +114,14 @@ int sendOffer(struct dhcpMessage *oldpacket) struct in_addr addr; init_packet(&packet, oldpacket, DHCPOFFER); - + /* ADDME: if static, short circuit */ /* the client is in our lease/offered table */ if ((lease = find_lease_by_chaddr(oldpacket->chaddr))) { - if (!lease_expired(lease)) + if (!lease_expired(lease)) lease_time_align = lease->expires - time(0); packet.yiaddr = lease->yiaddr; - + /* Or the client has a requested ip */ } else if ((req = get_option(oldpacket, DHCP_REQUESTED_IP)) && @@ -131,10 +131,10 @@ int sendOffer(struct dhcpMessage *oldpacket) /* and the ip is in the lease range */ ntohl(req_align) >= ntohl(server_config.start) && ntohl(req_align) <= ntohl(server_config.end) && - + /* and its not already taken/offered */ /* ADDME: check that its not a static lease */ ((!(lease = find_lease_by_yiaddr(req_align)) || - + /* or its taken, but expired */ /* ADDME: or maybe in here */ lease_expired(lease)))) { packet.yiaddr = req_align; /* FIXME: oh my, is there a host using this IP? */ @@ -142,32 +142,32 @@ int sendOffer(struct dhcpMessage *oldpacket) /* otherwise, find a free IP */ /*ADDME: is it a static lease? */ } else { packet.yiaddr = find_address(0); - + /* try for an expired lease */ if (!packet.yiaddr) packet.yiaddr = find_address(1); } - + if(!packet.yiaddr) { LOG(LOG_WARNING, "no IP addresses to give -- OFFER abandoned"); return -1; } - + if (!add_lease(packet.chaddr, packet.yiaddr, server_config.offer_time)) { LOG(LOG_WARNING, "lease pool is full -- OFFER abandoned"); return -1; - } + } if ((lease_time = get_option(oldpacket, DHCP_LEASE_TIME))) { memcpy(&lease_time_align, lease_time, 4); lease_time_align = ntohl(lease_time_align); - if (lease_time_align > server_config.lease) + if (lease_time_align > server_config.lease) lease_time_align = server_config.lease; } /* Make sure we aren't just using the lease time from the previous offer */ - if (lease_time_align < server_config.min_lease) + if (lease_time_align < server_config.min_lease) lease_time_align = server_config.lease; - /* ADDME: end of short circuit */ + /* ADDME: end of short circuit */ add_simple_option(packet.options, DHCP_LEASE_TIME, htonl(lease_time_align)); curr = server_config.options; @@ -178,7 +178,7 @@ int sendOffer(struct dhcpMessage *oldpacket) } add_bootp_options(&packet); - + addr.s_addr = packet.yiaddr; LOG(LOG_INFO, "sending OFFER of %s", inet_ntoa(addr)); return send_packet(&packet, 0); @@ -190,7 +190,7 @@ int sendNAK(struct dhcpMessage *oldpacket) struct dhcpMessage packet; init_packet(&packet, oldpacket, DHCPNAK); - + DEBUG(LOG_INFO, "sending NAK"); return send_packet(&packet, 1); } @@ -206,18 +206,18 @@ int sendACK(struct dhcpMessage *oldpacket, uint32_t yiaddr) init_packet(&packet, oldpacket, DHCPACK); packet.yiaddr = yiaddr; - + if ((lease_time = get_option(oldpacket, DHCP_LEASE_TIME))) { memcpy(&lease_time_align, lease_time, 4); lease_time_align = ntohl(lease_time_align); - if (lease_time_align > server_config.lease) + if (lease_time_align > server_config.lease) lease_time_align = server_config.lease; - else if (lease_time_align < server_config.min_lease) + else if (lease_time_align < server_config.min_lease) lease_time_align = server_config.lease; } - + add_simple_option(packet.options, DHCP_LEASE_TIME, htonl(lease_time_align)); - + curr = server_config.options; while (curr) { if (curr->data[OPT_CODE] != DHCP_LEASE_TIME) @@ -230,7 +230,7 @@ int sendACK(struct dhcpMessage *oldpacket, uint32_t yiaddr) addr.s_addr = packet.yiaddr; LOG(LOG_INFO, "sending ACK to %s", inet_ntoa(addr)); - if (send_packet(&packet, 0) < 0) + if (send_packet(&packet, 0) < 0) return -1; add_lease(packet.chaddr, packet.yiaddr, lease_time_align); @@ -245,7 +245,7 @@ int send_inform(struct dhcpMessage *oldpacket) struct option_set *curr; init_packet(&packet, oldpacket, DHCPACK); - + curr = server_config.options; while (curr) { if (curr->data[OPT_CODE] != DHCP_LEASE_TIME) diff --git a/networking/udhcp/socket.c b/networking/udhcp/socket.c index 582f0fc..7b05752 100644 --- a/networking/udhcp/socket.c +++ b/networking/udhcp/socket.c @@ -55,7 +55,7 @@ int read_interface(char *interface, int *ifindex, uint32_t *addr, uint8_t *arp) ifr.ifr_addr.sa_family = AF_INET; strcpy(ifr.ifr_name, interface); - if (addr) { + if (addr) { if (ioctl(fd, SIOCGIFADDR, &ifr) == 0) { our_ip = (struct sockaddr_in *) &ifr.ifr_addr; *addr = our_ip->sin_addr.s_addr; @@ -65,7 +65,7 @@ int read_interface(char *interface, int *ifindex, uint32_t *addr, uint8_t *arp) return -1; } } - + if (ioctl(fd, SIOCGIFINDEX, &ifr) == 0) { DEBUG(LOG_INFO, "adapter index %d", ifr.ifr_ifindex); *ifindex = ifr.ifr_ifindex; @@ -102,7 +102,7 @@ int listen_socket(uint32_t ip, int port, char *inf) DEBUG(LOG_ERR, "socket call failed: %m"); return -1; } - + memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_port = htons(port); @@ -127,6 +127,6 @@ int listen_socket(uint32_t ip, int port, char *inf) close(fd); return -1; } - + return fd; } |