"Robert P. J. Day" | 63fc1a9 | 2006-07-02 19:47:05 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 2 | /* dhcpd.c |
| 3 | * |
| 4 | * udhcp Server |
| 5 | * Copyright (C) 1999 Matthew Ramsay <matthewr@moreton.com.au> |
| 6 | * Chris Trew <ctrew@moreton.com.au> |
| 7 | * |
| 8 | * Rewrite by Russ Dill <Russ.Dill@asu.edu> July 2001 |
| 9 | * |
Rob Landley | 3f78561 | 2006-05-28 01:06:36 +0000 | [diff] [blame] | 10 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 11 | */ |
| 12 | |
Denis Vlasenko | af1c843 | 2007-03-26 13:22:35 +0000 | [diff] [blame] | 13 | #include <syslog.h> |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 14 | #include "common.h" |
Denis Vlasenko | d55fe3e | 2008-02-04 13:12:16 +0000 | [diff] [blame] | 15 | #include "dhcpc.h" |
Denis Vlasenko | 5a3395b | 2006-11-18 19:51:32 +0000 | [diff] [blame] | 16 | #include "dhcpd.h" |
| 17 | #include "options.h" |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 18 | |
| 19 | |
| 20 | /* globals */ |
| 21 | struct dhcpOfferedAddr *leases; |
Denis Vlasenko | deabacd | 2007-09-30 17:55:43 +0000 | [diff] [blame] | 22 | /* struct server_config_t server_config is in bb_common_bufsiz1 */ |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 23 | |
| 24 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 25 | int udhcpd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 26 | int udhcpd_main(int argc UNUSED_PARAM, char **argv) |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 27 | { |
| 28 | fd_set rfds; |
Denis Vlasenko | 0416e3d | 2009-01-01 17:52:09 +0000 | [diff] [blame] | 29 | int server_socket = -1, retval, max_sock; |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 30 | struct dhcpMessage packet; |
Rob Landley | 9ffd423 | 2006-05-21 18:30:35 +0000 | [diff] [blame] | 31 | uint8_t *state, *server_id, *requested; |
Denis Vlasenko | efb545b | 2008-12-08 22:56:18 +0000 | [diff] [blame] | 32 | uint32_t server_id_aligned = server_id_aligned; /* for compiler */ |
| 33 | uint32_t requested_aligned = requested_aligned; |
| 34 | uint32_t static_lease_ip; |
Denis Vlasenko | 42b3dea | 2007-07-03 15:47:50 +0000 | [diff] [blame] | 35 | unsigned timeout_end; |
| 36 | unsigned num_ips; |
Denis Vlasenko | 3d17d2b | 2007-08-14 16:45:29 +0000 | [diff] [blame] | 37 | unsigned opt; |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 38 | struct option_set *option; |
Rob Landley | 9ffd423 | 2006-05-21 18:30:35 +0000 | [diff] [blame] | 39 | struct dhcpOfferedAddr *lease, static_lease; |
Denis Vlasenko | d55fe3e | 2008-02-04 13:12:16 +0000 | [diff] [blame] | 40 | USE_FEATURE_UDHCP_PORT(char *str_P;) |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 41 | |
Denis Vlasenko | d55fe3e | 2008-02-04 13:12:16 +0000 | [diff] [blame] | 42 | #if ENABLE_FEATURE_UDHCP_PORT |
| 43 | SERVER_PORT = 67; |
| 44 | CLIENT_PORT = 68; |
| 45 | #endif |
| 46 | |
| 47 | opt = getopt32(argv, "fS" USE_FEATURE_UDHCP_PORT("P:", &str_P)); |
Denis Vlasenko | 9f7b92a | 2007-08-15 20:03:36 +0000 | [diff] [blame] | 48 | argv += optind; |
Denis Vlasenko | af1c843 | 2007-03-26 13:22:35 +0000 | [diff] [blame] | 49 | |
Denis Vlasenko | 3d17d2b | 2007-08-14 16:45:29 +0000 | [diff] [blame] | 50 | if (!(opt & 1)) { /* no -f */ |
Denis Vlasenko | c82b510 | 2007-07-01 17:05:57 +0000 | [diff] [blame] | 51 | bb_daemonize_or_rexec(0, argv); |
Denis Vlasenko | 4b924f3 | 2007-05-30 00:29:55 +0000 | [diff] [blame] | 52 | logmode &= ~LOGMODE_STDIO; |
Denis Vlasenko | af1c843 | 2007-03-26 13:22:35 +0000 | [diff] [blame] | 53 | } |
| 54 | |
Denis Vlasenko | 3d17d2b | 2007-08-14 16:45:29 +0000 | [diff] [blame] | 55 | if (opt & 2) { /* -S */ |
Denis Vlasenko | af1c843 | 2007-03-26 13:22:35 +0000 | [diff] [blame] | 56 | openlog(applet_name, LOG_PID, LOG_LOCAL0); |
| 57 | logmode |= LOGMODE_SYSLOG; |
| 58 | } |
Denis Vlasenko | d55fe3e | 2008-02-04 13:12:16 +0000 | [diff] [blame] | 59 | #if ENABLE_FEATURE_UDHCP_PORT |
| 60 | if (opt & 4) { /* -P */ |
| 61 | SERVER_PORT = xatou16(str_P); |
| 62 | CLIENT_PORT = SERVER_PORT + 1; |
| 63 | } |
| 64 | #endif |
Denis Vlasenko | af1c843 | 2007-03-26 13:22:35 +0000 | [diff] [blame] | 65 | /* Would rather not do read_config before daemonization - |
| 66 | * otherwise NOMMU machines will parse config twice */ |
Denis Vlasenko | 9f7b92a | 2007-08-15 20:03:36 +0000 | [diff] [blame] | 67 | read_config(argv[0] ? argv[0] : DHCPD_CONF_FILE); |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 68 | |
Denis Vlasenko | 80edead | 2007-08-02 22:31:05 +0000 | [diff] [blame] | 69 | /* Make sure fd 0,1,2 are open */ |
| 70 | bb_sanitize_stdio(); |
| 71 | /* Equivalent of doing a fflush after every \n */ |
| 72 | setlinebuf(stdout); |
| 73 | |
| 74 | /* Create pidfile */ |
| 75 | write_pidfile(server_config.pidfile); |
| 76 | /* if (!..) bb_perror_msg("cannot create pidfile %s", pidfile); */ |
| 77 | |
Denis Vlasenko | def8898 | 2007-10-07 17:06:01 +0000 | [diff] [blame] | 78 | bb_info_msg("%s (v"BB_VER") started", applet_name); |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 79 | |
Denis Vlasenko | af1c843 | 2007-03-26 13:22:35 +0000 | [diff] [blame] | 80 | option = find_option(server_config.options, DHCP_LEASE_TIME); |
Denis Vlasenko | 6e6d331 | 2007-05-03 23:39:35 +0000 | [diff] [blame] | 81 | server_config.lease = LEASE_TIME; |
Denis Vlasenko | af1c843 | 2007-03-26 13:22:35 +0000 | [diff] [blame] | 82 | if (option) { |
Denis Vlasenko | efb545b | 2008-12-08 22:56:18 +0000 | [diff] [blame] | 83 | move_from_unaligned32(server_config.lease, option->data + 2); |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 84 | server_config.lease = ntohl(server_config.lease); |
Denis Vlasenko | 6e6d331 | 2007-05-03 23:39:35 +0000 | [diff] [blame] | 85 | } |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 86 | |
| 87 | /* Sanity check */ |
Denis Vlasenko | c82b510 | 2007-07-01 17:05:57 +0000 | [diff] [blame] | 88 | num_ips = server_config.end_ip - server_config.start_ip + 1; |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 89 | if (server_config.max_leases > num_ips) { |
Denis Vlasenko | 42b3dea | 2007-07-03 15:47:50 +0000 | [diff] [blame] | 90 | bb_error_msg("max_leases=%u is too big, setting to %u", |
| 91 | (unsigned)server_config.max_leases, num_ips); |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 92 | server_config.max_leases = num_ips; |
| 93 | } |
| 94 | |
Denis Vlasenko | c82b510 | 2007-07-01 17:05:57 +0000 | [diff] [blame] | 95 | leases = xzalloc(server_config.max_leases * sizeof(*leases)); |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 96 | read_leases(server_config.lease_file); |
| 97 | |
Denis Vlasenko | f1980f6 | 2008-09-26 09:34:59 +0000 | [diff] [blame] | 98 | if (udhcp_read_interface(server_config.interface, &server_config.ifindex, |
Denis Vlasenko | 80edead | 2007-08-02 22:31:05 +0000 | [diff] [blame] | 99 | &server_config.server, server_config.arp)) { |
Denis Vlasenko | 6e6d331 | 2007-05-03 23:39:35 +0000 | [diff] [blame] | 100 | retval = 1; |
| 101 | goto ret; |
| 102 | } |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 103 | |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 104 | /* Setup the signal pipe */ |
| 105 | udhcp_sp_setup(); |
| 106 | |
Denis Vlasenko | 42b3dea | 2007-07-03 15:47:50 +0000 | [diff] [blame] | 107 | timeout_end = monotonic_sec() + server_config.auto_time; |
Denis Vlasenko | 5a3395b | 2006-11-18 19:51:32 +0000 | [diff] [blame] | 108 | while (1) { /* loop until universe collapses */ |
Denis Vlasenko | 0416e3d | 2009-01-01 17:52:09 +0000 | [diff] [blame] | 109 | int bytes; |
| 110 | struct timeval tv; |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 111 | |
Denis Vlasenko | e2d3ded | 2006-11-27 23:43:28 +0000 | [diff] [blame] | 112 | if (server_socket < 0) { |
Denis Vlasenko | f1980f6 | 2008-09-26 09:34:59 +0000 | [diff] [blame] | 113 | server_socket = udhcp_listen_socket(/*INADDR_ANY,*/ SERVER_PORT, |
Denis Vlasenko | 6e6d331 | 2007-05-03 23:39:35 +0000 | [diff] [blame] | 114 | server_config.interface); |
Denis Vlasenko | e2d3ded | 2006-11-27 23:43:28 +0000 | [diff] [blame] | 115 | } |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 116 | |
| 117 | max_sock = udhcp_sp_fd_set(&rfds, server_socket); |
| 118 | if (server_config.auto_time) { |
Denis Vlasenko | 42b3dea | 2007-07-03 15:47:50 +0000 | [diff] [blame] | 119 | tv.tv_sec = timeout_end - monotonic_sec(); |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 120 | tv.tv_usec = 0; |
| 121 | } |
Denis Vlasenko | 6e6d331 | 2007-05-03 23:39:35 +0000 | [diff] [blame] | 122 | retval = 0; |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 123 | if (!server_config.auto_time || tv.tv_sec > 0) { |
| 124 | retval = select(max_sock + 1, &rfds, NULL, NULL, |
| 125 | server_config.auto_time ? &tv : NULL); |
Denis Vlasenko | 6e6d331 | 2007-05-03 23:39:35 +0000 | [diff] [blame] | 126 | } |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 127 | if (retval == 0) { |
| 128 | write_leases(); |
Denis Vlasenko | 42b3dea | 2007-07-03 15:47:50 +0000 | [diff] [blame] | 129 | timeout_end = monotonic_sec() + server_config.auto_time; |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 130 | continue; |
Denis Vlasenko | 6e6d331 | 2007-05-03 23:39:35 +0000 | [diff] [blame] | 131 | } |
| 132 | if (retval < 0 && errno != EINTR) { |
Denis Vlasenko | 3538b9a | 2006-09-06 18:36:50 +0000 | [diff] [blame] | 133 | DEBUG("error on select"); |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 134 | continue; |
| 135 | } |
| 136 | |
| 137 | switch (udhcp_sp_read(&rfds)) { |
| 138 | case SIGUSR1: |
Denis Vlasenko | 3538b9a | 2006-09-06 18:36:50 +0000 | [diff] [blame] | 139 | bb_info_msg("Received a SIGUSR1"); |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 140 | write_leases(); |
| 141 | /* why not just reset the timeout, eh */ |
Denis Vlasenko | 42b3dea | 2007-07-03 15:47:50 +0000 | [diff] [blame] | 142 | timeout_end = monotonic_sec() + server_config.auto_time; |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 143 | continue; |
| 144 | case SIGTERM: |
Denis Vlasenko | 3538b9a | 2006-09-06 18:36:50 +0000 | [diff] [blame] | 145 | bb_info_msg("Received a SIGTERM"); |
Denis Vlasenko | 6e6d331 | 2007-05-03 23:39:35 +0000 | [diff] [blame] | 146 | goto ret0; |
Denis Vlasenko | 0416e3d | 2009-01-01 17:52:09 +0000 | [diff] [blame] | 147 | case 0: /* no signal: read a packet */ |
| 148 | break; |
| 149 | default: /* signal or error (probably EINTR): back to select */ |
| 150 | continue; |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 151 | } |
| 152 | |
Denis Vlasenko | 0416e3d | 2009-01-01 17:52:09 +0000 | [diff] [blame] | 153 | bytes = udhcp_recv_kernel_packet(&packet, server_socket); |
Denis Vlasenko | af1c843 | 2007-03-26 13:22:35 +0000 | [diff] [blame] | 154 | if (bytes < 0) { |
Denis Vlasenko | 0416e3d | 2009-01-01 17:52:09 +0000 | [diff] [blame] | 155 | /* bytes can also be -2 ("bad packet data") */ |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 156 | if (bytes == -1 && errno != EINTR) { |
Denis Vlasenko | 3538b9a | 2006-09-06 18:36:50 +0000 | [diff] [blame] | 157 | DEBUG("error on read, %s, reopening socket", strerror(errno)); |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 158 | close(server_socket); |
| 159 | server_socket = -1; |
| 160 | } |
| 161 | continue; |
| 162 | } |
| 163 | |
Denis Vlasenko | af1c843 | 2007-03-26 13:22:35 +0000 | [diff] [blame] | 164 | state = get_option(&packet, DHCP_MESSAGE_TYPE); |
| 165 | if (state == NULL) { |
Denis Vlasenko | a959588 | 2006-09-29 21:30:43 +0000 | [diff] [blame] | 166 | bb_error_msg("cannot get option from packet, ignoring"); |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 167 | continue; |
| 168 | } |
| 169 | |
| 170 | /* Look for a static lease */ |
| 171 | static_lease_ip = getIpByMac(server_config.static_leases, &packet.chaddr); |
Denis Vlasenko | 5a3395b | 2006-11-18 19:51:32 +0000 | [diff] [blame] | 172 | if (static_lease_ip) { |
Denis Vlasenko | 3538b9a | 2006-09-06 18:36:50 +0000 | [diff] [blame] | 173 | bb_info_msg("Found static lease: %x", static_lease_ip); |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 174 | |
| 175 | memcpy(&static_lease.chaddr, &packet.chaddr, 16); |
| 176 | static_lease.yiaddr = static_lease_ip; |
| 177 | static_lease.expires = 0; |
| 178 | |
| 179 | lease = &static_lease; |
Denis Vlasenko | 5a3395b | 2006-11-18 19:51:32 +0000 | [diff] [blame] | 180 | } else { |
| 181 | lease = find_lease_by_chaddr(packet.chaddr); |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | switch (state[0]) { |
| 185 | case DHCPDISCOVER: |
Denis Vlasenko | 3538b9a | 2006-09-06 18:36:50 +0000 | [diff] [blame] | 186 | DEBUG("Received DISCOVER"); |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 187 | |
Denis Vlasenko | 6de8994 | 2008-05-21 07:05:06 +0000 | [diff] [blame] | 188 | if (send_offer(&packet) < 0) { |
Denis Vlasenko | a959588 | 2006-09-29 21:30:43 +0000 | [diff] [blame] | 189 | bb_error_msg("send OFFER failed"); |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 190 | } |
| 191 | break; |
| 192 | case DHCPREQUEST: |
Denis Vlasenko | 3538b9a | 2006-09-06 18:36:50 +0000 | [diff] [blame] | 193 | DEBUG("received REQUEST"); |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 194 | |
| 195 | requested = get_option(&packet, DHCP_REQUESTED_IP); |
| 196 | server_id = get_option(&packet, DHCP_SERVER_ID); |
| 197 | |
Denis Vlasenko | efb545b | 2008-12-08 22:56:18 +0000 | [diff] [blame] | 198 | if (requested) |
| 199 | move_from_unaligned32(requested_aligned, requested); |
| 200 | if (server_id) |
| 201 | move_from_unaligned32(server_id_aligned, server_id); |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 202 | |
| 203 | if (lease) { |
| 204 | if (server_id) { |
| 205 | /* SELECTING State */ |
Denis Vlasenko | efb545b | 2008-12-08 22:56:18 +0000 | [diff] [blame] | 206 | DEBUG("server_id = %08x", ntohl(server_id_aligned)); |
| 207 | if (server_id_aligned == server_config.server |
| 208 | && requested |
| 209 | && requested_aligned == lease->yiaddr |
Denis Vlasenko | af1c843 | 2007-03-26 13:22:35 +0000 | [diff] [blame] | 210 | ) { |
Denis Vlasenko | 6de8994 | 2008-05-21 07:05:06 +0000 | [diff] [blame] | 211 | send_ACK(&packet, lease->yiaddr); |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 212 | } |
Denis Vlasenko | af1c843 | 2007-03-26 13:22:35 +0000 | [diff] [blame] | 213 | } else if (requested) { |
| 214 | /* INIT-REBOOT State */ |
Denis Vlasenko | efb545b | 2008-12-08 22:56:18 +0000 | [diff] [blame] | 215 | if (lease->yiaddr == requested_aligned) |
Denis Vlasenko | 6de8994 | 2008-05-21 07:05:06 +0000 | [diff] [blame] | 216 | send_ACK(&packet, lease->yiaddr); |
Denis Vlasenko | af1c843 | 2007-03-26 13:22:35 +0000 | [diff] [blame] | 217 | else |
Denis Vlasenko | 6de8994 | 2008-05-21 07:05:06 +0000 | [diff] [blame] | 218 | send_NAK(&packet); |
Denis Vlasenko | af1c843 | 2007-03-26 13:22:35 +0000 | [diff] [blame] | 219 | } else if (lease->yiaddr == packet.ciaddr) { |
| 220 | /* RENEWING or REBINDING State */ |
Denis Vlasenko | 6de8994 | 2008-05-21 07:05:06 +0000 | [diff] [blame] | 221 | send_ACK(&packet, lease->yiaddr); |
| 222 | } else { /* don't know what to do!!!! */ |
| 223 | send_NAK(&packet); |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | /* what to do if we have no record of the client */ |
| 227 | } else if (server_id) { |
| 228 | /* SELECTING State */ |
| 229 | |
| 230 | } else if (requested) { |
| 231 | /* INIT-REBOOT State */ |
Denis Vlasenko | efb545b | 2008-12-08 22:56:18 +0000 | [diff] [blame] | 232 | lease = find_lease_by_yiaddr(requested_aligned); |
Denis Vlasenko | af1c843 | 2007-03-26 13:22:35 +0000 | [diff] [blame] | 233 | if (lease) { |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 234 | if (lease_expired(lease)) { |
| 235 | /* probably best if we drop this lease */ |
| 236 | memset(lease->chaddr, 0, 16); |
| 237 | /* make some contention for this address */ |
Denis Vlasenko | af1c843 | 2007-03-26 13:22:35 +0000 | [diff] [blame] | 238 | } else |
Denis Vlasenko | 6de8994 | 2008-05-21 07:05:06 +0000 | [diff] [blame] | 239 | send_NAK(&packet); |
Denis Vlasenko | c82b510 | 2007-07-01 17:05:57 +0000 | [diff] [blame] | 240 | } else { |
Denis Vlasenko | efb545b | 2008-12-08 22:56:18 +0000 | [diff] [blame] | 241 | uint32_t r = ntohl(requested_aligned); |
Denis Vlasenko | c82b510 | 2007-07-01 17:05:57 +0000 | [diff] [blame] | 242 | if (r < server_config.start_ip |
| 243 | || r > server_config.end_ip |
| 244 | ) { |
Denis Vlasenko | 6de8994 | 2008-05-21 07:05:06 +0000 | [diff] [blame] | 245 | send_NAK(&packet); |
Denis Vlasenko | c82b510 | 2007-07-01 17:05:57 +0000 | [diff] [blame] | 246 | } |
Denis Vlasenko | e6bce97 | 2007-07-01 17:11:54 +0000 | [diff] [blame] | 247 | /* else remain silent */ |
| 248 | } |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 249 | |
| 250 | } else { |
Denis Vlasenko | af1c843 | 2007-03-26 13:22:35 +0000 | [diff] [blame] | 251 | /* RENEWING or REBINDING State */ |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 252 | } |
| 253 | break; |
| 254 | case DHCPDECLINE: |
Denis Vlasenko | 3538b9a | 2006-09-06 18:36:50 +0000 | [diff] [blame] | 255 | DEBUG("Received DECLINE"); |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 256 | if (lease) { |
| 257 | memset(lease->chaddr, 0, 16); |
Denis Vlasenko | 04158e0 | 2009-02-02 10:48:06 +0000 | [diff] [blame^] | 258 | lease->expires = time(NULL) + server_config.decline_time; |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 259 | } |
| 260 | break; |
| 261 | case DHCPRELEASE: |
Denis Vlasenko | 3538b9a | 2006-09-06 18:36:50 +0000 | [diff] [blame] | 262 | DEBUG("Received RELEASE"); |
Denis Vlasenko | 6e6d331 | 2007-05-03 23:39:35 +0000 | [diff] [blame] | 263 | if (lease) |
Denis Vlasenko | 04158e0 | 2009-02-02 10:48:06 +0000 | [diff] [blame^] | 264 | lease->expires = time(NULL); |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 265 | break; |
| 266 | case DHCPINFORM: |
Denis Vlasenko | 3538b9a | 2006-09-06 18:36:50 +0000 | [diff] [blame] | 267 | DEBUG("Received INFORM"); |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 268 | send_inform(&packet); |
| 269 | break; |
| 270 | default: |
Denis Vlasenko | 3538b9a | 2006-09-06 18:36:50 +0000 | [diff] [blame] | 271 | bb_info_msg("Unsupported DHCP message (%02x) - ignoring", state[0]); |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 272 | } |
| 273 | } |
Denis Vlasenko | 6e6d331 | 2007-05-03 23:39:35 +0000 | [diff] [blame] | 274 | ret0: |
| 275 | retval = 0; |
| 276 | ret: |
Denis Vlasenko | 42b3dea | 2007-07-03 15:47:50 +0000 | [diff] [blame] | 277 | /*if (server_config.pidfile) - server_config.pidfile is never NULL */ |
Denis Vlasenko | 6e6d331 | 2007-05-03 23:39:35 +0000 | [diff] [blame] | 278 | remove_pidfile(server_config.pidfile); |
| 279 | return retval; |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 280 | } |