diff options
| author | Rob Landley <rob@landley.net> | 2006-05-28 01:06:36 +0000 |
|---|---|---|
| committer | Rob Landley <rob@landley.net> | 2006-05-28 01:06:36 +0000 |
| commit | 3f78561d63290c53ca8bb3cd6314ca7357a617ee (patch) | |
| tree | 03b3973eeaee9635c77c21028133374d66f2aa18 | |
| parent | 8fba99f35e46d234b47d652225bb80846cae369c (diff) | |
| download | busybox-w32-3f78561d63290c53ca8bb3cd6314ca7357a617ee.tar.gz busybox-w32-3f78561d63290c53ca8bb3cd6314ca7357a617ee.tar.bz2 busybox-w32-3f78561d63290c53ca8bb3cd6314ca7357a617ee.zip | |
My first bout of untangling udhcp. Make lots of gratuitous #defines go
away, substitutie BB_VER for an external VERSION, use busybox CONFIG symbols
rather than checking for them then defining others, etc. Lots more cleanup
to do...
| -rw-r--r-- | networking/udhcp/Makefile | 27 | ||||
| -rw-r--r-- | networking/udhcp/clientpacket.c | 30 | ||||
| -rw-r--r-- | networking/udhcp/common.c | 13 | ||||
| -rw-r--r-- | networking/udhcp/common.h | 23 | ||||
| -rw-r--r-- | networking/udhcp/dhcpc.c | 33 | ||||
| -rw-r--r-- | networking/udhcp/dhcpd.c | 23 | ||||
| -rw-r--r-- | networking/udhcp/dhcpd.h | 1 | ||||
| -rw-r--r-- | networking/udhcp/files.c | 15 | ||||
| -rw-r--r-- | networking/udhcp/libbb_udhcp.h | 65 | ||||
| -rw-r--r-- | networking/udhcp/packet.c | 14 | ||||
| -rw-r--r-- | networking/udhcp/packet.h | 10 | ||||
| -rw-r--r-- | networking/udhcp/script.c | 29 | ||||
| -rw-r--r-- | networking/udhcp/script.h | 6 | ||||
| -rw-r--r-- | networking/udhcp/serverpacket.c | 6 | ||||
| -rw-r--r-- | networking/udhcp/static_leases.c | 2 | ||||
| -rw-r--r-- | networking/udhcp/static_leases.h | 4 | ||||
| -rw-r--r-- | networking/udhcp/version.h | 6 |
17 files changed, 86 insertions, 221 deletions
diff --git a/networking/udhcp/Makefile b/networking/udhcp/Makefile index dbea9d4d0..23131f8f0 100644 --- a/networking/udhcp/Makefile +++ b/networking/udhcp/Makefile | |||
| @@ -2,27 +2,14 @@ | |||
| 2 | # | 2 | # |
| 3 | # Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> | 3 | # Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> |
| 4 | # | 4 | # |
| 5 | # This program is free software; you can redistribute it and/or modify | 5 | # Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
| 6 | # it under the terms of the GNU General Public License as published by | ||
| 7 | # the Free Software Foundation; either version 2 of the License, or | ||
| 8 | # (at your option) any later version. | ||
| 9 | # | ||
| 10 | # This program is distributed in the hope that it will be useful, | ||
| 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 13 | # General Public License for more details. | ||
| 14 | # | ||
| 15 | # You should have received a copy of the GNU General Public License | ||
| 16 | # along with this program; if not, write to the Free Software | ||
| 17 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 18 | # | ||
| 19 | 6 | ||
| 20 | ifndef top_srcdir | 7 | #ifndef top_srcdir |
| 21 | top_srcdir=../.. | 8 | #top_srcdir=../.. |
| 22 | endif | 9 | #endif |
| 23 | ifndef top_builddir | 10 | #ifndef top_builddir |
| 24 | top_builddir=../.. | 11 | #top_builddir=../.. |
| 25 | endif | 12 | #endif |
| 26 | srcdir=$(top_srcdir)/networking/udhcp | 13 | srcdir=$(top_srcdir)/networking/udhcp |
| 27 | UDHCP_DIR:=./ | 14 | UDHCP_DIR:=./ |
| 28 | include $(top_srcdir)/Rules.mak | 15 | include $(top_srcdir)/Rules.mak |
diff --git a/networking/udhcp/clientpacket.c b/networking/udhcp/clientpacket.c index 88d4d88dc..14e6c6678 100644 --- a/networking/udhcp/clientpacket.c +++ b/networking/udhcp/clientpacket.c | |||
| @@ -4,19 +4,7 @@ | |||
| 4 | * | 4 | * |
| 5 | * Russ Dill <Russ.Dill@asu.edu> July 2001 | 5 | * Russ Dill <Russ.Dill@asu.edu> July 2001 |
| 6 | * | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify | 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
| 8 | * it under the terms of the GNU General Public License as published by | ||
| 9 | * the Free Software Foundation; either version 2 of the License, or | ||
| 10 | * (at your option) any later version. | ||
| 11 | * | ||
| 12 | * This program is distributed in the hope that it will be useful, | ||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 15 | * GNU General Public License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU General Public License | ||
| 18 | * along with this program; if not, write to the Free Software | ||
| 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
| 20 | */ | 8 | */ |
| 21 | 9 | ||
| 22 | #include <string.h> | 10 | #include <string.h> |
| @@ -69,7 +57,7 @@ unsigned long random_xid(void) | |||
| 69 | /* initialize a packet with the proper defaults */ | 57 | /* initialize a packet with the proper defaults */ |
| 70 | static void init_packet(struct dhcpMessage *packet, char type) | 58 | static void init_packet(struct dhcpMessage *packet, char type) |
| 71 | { | 59 | { |
| 72 | init_header(packet, type); | 60 | udhcp_init_header(packet, type); |
| 73 | memcpy(packet->chaddr, client_config.arp, 6); | 61 | memcpy(packet->chaddr, client_config.arp, 6); |
| 74 | if (client_config.clientid) | 62 | if (client_config.clientid) |
| 75 | add_option_string(packet->options, client_config.clientid); | 63 | add_option_string(packet->options, client_config.clientid); |
| @@ -109,7 +97,7 @@ int send_discover(unsigned long xid, unsigned long requested) | |||
| 109 | 97 | ||
| 110 | add_requests(&packet); | 98 | add_requests(&packet); |
| 111 | LOG(LOG_DEBUG, "Sending discover..."); | 99 | LOG(LOG_DEBUG, "Sending discover..."); |
| 112 | return raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST, | 100 | return udhcp_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST, |
| 113 | SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex); | 101 | SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex); |
| 114 | } | 102 | } |
| 115 | 103 | ||
| @@ -129,7 +117,7 @@ int send_selecting(unsigned long xid, unsigned long server, unsigned long reques | |||
| 129 | add_requests(&packet); | 117 | add_requests(&packet); |
| 130 | addr.s_addr = requested; | 118 | addr.s_addr = requested; |
| 131 | LOG(LOG_DEBUG, "Sending select for %s...", inet_ntoa(addr)); | 119 | LOG(LOG_DEBUG, "Sending select for %s...", inet_ntoa(addr)); |
| 132 | return raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST, | 120 | return udhcp_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST, |
| 133 | SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex); | 121 | SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex); |
| 134 | } | 122 | } |
| 135 | 123 | ||
| @@ -147,8 +135,8 @@ int send_renew(unsigned long xid, unsigned long server, unsigned long ciaddr) | |||
| 147 | add_requests(&packet); | 135 | add_requests(&packet); |
| 148 | LOG(LOG_DEBUG, "Sending renew..."); | 136 | LOG(LOG_DEBUG, "Sending renew..."); |
| 149 | if (server) | 137 | if (server) |
| 150 | ret = kernel_packet(&packet, ciaddr, CLIENT_PORT, server, SERVER_PORT); | 138 | ret = udhcp_kernel_packet(&packet, ciaddr, CLIENT_PORT, server, SERVER_PORT); |
| 151 | else ret = raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST, | 139 | else ret = udhcp_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST, |
| 152 | SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex); | 140 | SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex); |
| 153 | return ret; | 141 | return ret; |
| 154 | } | 142 | } |
| @@ -167,7 +155,7 @@ int send_release(unsigned long server, unsigned long ciaddr) | |||
| 167 | add_simple_option(packet.options, DHCP_SERVER_ID, server); | 155 | add_simple_option(packet.options, DHCP_SERVER_ID, server); |
| 168 | 156 | ||
| 169 | LOG(LOG_DEBUG, "Sending release..."); | 157 | LOG(LOG_DEBUG, "Sending release..."); |
| 170 | return kernel_packet(&packet, ciaddr, CLIENT_PORT, server, SERVER_PORT); | 158 | return udhcp_kernel_packet(&packet, ciaddr, CLIENT_PORT, server, SERVER_PORT); |
| 171 | } | 159 | } |
| 172 | 160 | ||
| 173 | 161 | ||
| @@ -212,7 +200,7 @@ int get_raw_packet(struct dhcpMessage *payload, int fd) | |||
| 212 | /* check IP checksum */ | 200 | /* check IP checksum */ |
| 213 | check = packet.ip.check; | 201 | check = packet.ip.check; |
| 214 | packet.ip.check = 0; | 202 | packet.ip.check = 0; |
| 215 | if (check != checksum(&(packet.ip), sizeof(packet.ip))) { | 203 | if (check != udhcp_checksum(&(packet.ip), sizeof(packet.ip))) { |
| 216 | DEBUG(LOG_INFO, "bad IP header checksum, ignoring"); | 204 | DEBUG(LOG_INFO, "bad IP header checksum, ignoring"); |
| 217 | return -1; | 205 | return -1; |
| 218 | } | 206 | } |
| @@ -228,7 +216,7 @@ int get_raw_packet(struct dhcpMessage *payload, int fd) | |||
| 228 | packet.ip.saddr = source; | 216 | packet.ip.saddr = source; |
| 229 | packet.ip.daddr = dest; | 217 | packet.ip.daddr = dest; |
| 230 | packet.ip.tot_len = packet.udp.len; /* cheat on the psuedo-header */ | 218 | packet.ip.tot_len = packet.udp.len; /* cheat on the psuedo-header */ |
| 231 | if (check && check != checksum(&packet, bytes)) { | 219 | if (check && check != udhcp_checksum(&packet, bytes)) { |
| 232 | DEBUG(LOG_ERR, "packet with bad UDP checksum received, ignoring"); | 220 | DEBUG(LOG_ERR, "packet with bad UDP checksum received, ignoring"); |
| 233 | return -2; | 221 | return -2; |
| 234 | } | 222 | } |
diff --git a/networking/udhcp/common.c b/networking/udhcp/common.c index 589214bce..2c902fc01 100644 --- a/networking/udhcp/common.c +++ b/networking/udhcp/common.c | |||
| @@ -50,7 +50,7 @@ static inline void sanitize_fds(void) | |||
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | 52 | ||
| 53 | void background(const char *pidfile) | 53 | void udhcp_background(const char *pidfile) |
| 54 | { | 54 | { |
| 55 | #ifdef __uClinux__ | 55 | #ifdef __uClinux__ |
| 56 | LOG(LOG_ERR, "Cannot background in uclinux (yet)"); | 56 | LOG(LOG_ERR, "Cannot background in uclinux (yet)"); |
| @@ -69,7 +69,7 @@ void background(const char *pidfile) | |||
| 69 | } | 69 | } |
| 70 | 70 | ||
| 71 | 71 | ||
| 72 | #ifdef UDHCP_SYSLOG | 72 | #ifdef CONFIG_FEATURE_UDHCP_SYSLOG |
| 73 | 73 | ||
| 74 | void udhcp_logging(int level, const char *fmt, ...) | 74 | void udhcp_logging(int level, const char *fmt, ...) |
| 75 | { | 75 | { |
| @@ -115,7 +115,7 @@ void udhcp_logging(int level, const char *fmt, ...) | |||
| 115 | #endif | 115 | #endif |
| 116 | 116 | ||
| 117 | 117 | ||
| 118 | void start_log_and_pid(const char *client_server, const char *pidfile) | 118 | void udhcp_start_log_and_pid(const char *client_server, const char *pidfile) |
| 119 | { | 119 | { |
| 120 | int pid_fd; | 120 | int pid_fd; |
| 121 | 121 | ||
| @@ -129,9 +129,8 @@ void start_log_and_pid(const char *client_server, const char *pidfile) | |||
| 129 | /* equivelent of doing a fflush after every \n */ | 129 | /* equivelent of doing a fflush after every \n */ |
| 130 | setlinebuf(stdout); | 130 | setlinebuf(stdout); |
| 131 | 131 | ||
| 132 | #ifdef UDHCP_SYSLOG | 132 | if (ENABLE_FEATURE_UDHCP_SYSLOG) |
| 133 | openlog(client_server, LOG_PID | LOG_CONS, LOG_LOCAL0); | 133 | openlog(client_server, LOG_PID | LOG_CONS, LOG_LOCAL0); |
| 134 | #endif | ||
| 135 | 134 | ||
| 136 | udhcp_logging(LOG_INFO, "%s (v%s) started", client_server, VERSION); | 135 | udhcp_logging(LOG_INFO, "%s (v%s) started", client_server, BB_VER); |
| 137 | } | 136 | } |
diff --git a/networking/udhcp/common.h b/networking/udhcp/common.h index 071a5c428..77e689446 100644 --- a/networking/udhcp/common.h +++ b/networking/udhcp/common.h | |||
| @@ -3,29 +3,15 @@ | |||
| 3 | * Russ Dill <Russ.Dill@asu.edu> September 2001 | 3 | * Russ Dill <Russ.Dill@asu.edu> September 2001 |
| 4 | * Rewritten by Vladimir Oleynik <dzo@simtreas.ru> (C) 2003 | 4 | * Rewritten by Vladimir Oleynik <dzo@simtreas.ru> (C) 2003 |
| 5 | * | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify | 6 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
| 7 | * it under the terms of the GNU General Public License as published by | ||
| 8 | * the Free Software Foundation; either version 2 of the License, or | ||
| 9 | * (at your option) any later version. | ||
| 10 | * | ||
| 11 | * This program is distributed in the hope that it will be useful, | ||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | * GNU General Public License for more details. | ||
| 15 | * | ||
| 16 | * You should have received a copy of the GNU General Public License | ||
| 17 | * along with this program; if not, write to the Free Software | ||
| 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
| 19 | */ | 7 | */ |
| 20 | 8 | ||
| 21 | #ifndef _COMMON_H | 9 | #ifndef _COMMON_H |
| 22 | #define _COMMON_H | 10 | #define _COMMON_H |
| 23 | 11 | ||
| 24 | #include "version.h" | ||
| 25 | #include "libbb_udhcp.h" | 12 | #include "libbb_udhcp.h" |
| 26 | 13 | ||
| 27 | 14 | ||
| 28 | #ifndef UDHCP_SYSLOG | ||
| 29 | enum syslog_levels { | 15 | enum syslog_levels { |
| 30 | LOG_EMERG = 0, | 16 | LOG_EMERG = 0, |
| 31 | LOG_ALERT, | 17 | LOG_ALERT, |
| @@ -35,18 +21,13 @@ enum syslog_levels { | |||
| 35 | LOG_INFO, | 21 | LOG_INFO, |
| 36 | LOG_DEBUG | 22 | LOG_DEBUG |
| 37 | }; | 23 | }; |
| 38 | #else | ||
| 39 | #include <syslog.h> | 24 | #include <syslog.h> |
| 40 | #endif | ||
| 41 | 25 | ||
| 42 | long uptime(void); | 26 | long uptime(void); |
| 43 | void background(const char *pidfile); | ||
| 44 | void start_log_and_pid(const char *client_server, const char *pidfile); | ||
| 45 | void udhcp_logging(int level, const char *fmt, ...); | ||
| 46 | 27 | ||
| 47 | #define LOG(level, str, args...) udhcp_logging(level, str, ## args) | 28 | #define LOG(level, str, args...) udhcp_logging(level, str, ## args) |
| 48 | 29 | ||
| 49 | #ifdef UDHCP_DEBUG | 30 | #if ENABLE_FEATURE_UDHCP_DEBUG |
| 50 | # define DEBUG(level, str, args...) LOG(level, str, ## args) | 31 | # define DEBUG(level, str, args...) LOG(level, str, ## args) |
| 51 | #else | 32 | #else |
| 52 | # define DEBUG(level, str, args...) do {;} while(0) | 33 | # define DEBUG(level, str, args...) do {;} while(0) |
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index 1d9ab6db6..c36c87602 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c | |||
| @@ -27,7 +27,6 @@ | |||
| 27 | #include "options.h" | 27 | #include "options.h" |
| 28 | #include "clientpacket.h" | 28 | #include "clientpacket.h" |
| 29 | #include "clientsocket.h" | 29 | #include "clientsocket.h" |
| 30 | #include "script.h" | ||
| 31 | #include "socket.h" | 30 | #include "socket.h" |
| 32 | #include "signalpipe.h" | 31 | #include "signalpipe.h" |
| 33 | 32 | ||
| @@ -120,7 +119,7 @@ static void perform_renew(void) | |||
| 120 | state = RENEW_REQUESTED; | 119 | state = RENEW_REQUESTED; |
| 121 | break; | 120 | break; |
| 122 | case RENEW_REQUESTED: /* impatient are we? fine, square 1 */ | 121 | case RENEW_REQUESTED: /* impatient are we? fine, square 1 */ |
| 123 | run_script(NULL, "deconfig"); | 122 | udhcp_run_script(NULL, "deconfig"); |
| 124 | case REQUESTING: | 123 | case REQUESTING: |
| 125 | case RELEASED: | 124 | case RELEASED: |
| 126 | change_mode(LISTEN_RAW); | 125 | change_mode(LISTEN_RAW); |
| @@ -152,7 +151,7 @@ static void perform_release(void) | |||
| 152 | LOG(LOG_INFO, "Unicasting a release of %s to %s", | 151 | LOG(LOG_INFO, "Unicasting a release of %s to %s", |
| 153 | inet_ntoa(temp_addr), buffer); | 152 | inet_ntoa(temp_addr), buffer); |
| 154 | send_release(server_addr, requested_ip); /* unicast */ | 153 | send_release(server_addr, requested_ip); /* unicast */ |
| 155 | run_script(NULL, "deconfig"); | 154 | udhcp_run_script(NULL, "deconfig"); |
| 156 | } | 155 | } |
| 157 | LOG(LOG_INFO, "Entering released state"); | 156 | LOG(LOG_INFO, "Entering released state"); |
| 158 | 157 | ||
| @@ -164,7 +163,7 @@ static void perform_release(void) | |||
| 164 | 163 | ||
| 165 | static void client_background(void) | 164 | static void client_background(void) |
| 166 | { | 165 | { |
| 167 | background(client_config.pidfile); | 166 | udhcp_background(client_config.pidfile); |
| 168 | client_config.foreground = 1; /* Do not fork again. */ | 167 | client_config.foreground = 1; /* Do not fork again. */ |
| 169 | client_config.background_if_no_lease = 0; | 168 | client_config.background_if_no_lease = 0; |
| 170 | } | 169 | } |
| @@ -297,7 +296,7 @@ int main(int argc, char *argv[]) | |||
| 297 | client_config.retries = atoi(optarg); | 296 | client_config.retries = atoi(optarg); |
| 298 | break; | 297 | break; |
| 299 | case 'v': | 298 | case 'v': |
| 300 | printf("udhcpcd, version %s\n\n", VERSION); | 299 | printf("version %s\n\n", BB_VER); |
| 301 | return 0; | 300 | return 0; |
| 302 | break; | 301 | break; |
| 303 | default: | 302 | default: |
| @@ -306,7 +305,7 @@ int main(int argc, char *argv[]) | |||
| 306 | } | 305 | } |
| 307 | 306 | ||
| 308 | /* Start the log, sanitize fd's, and write a pid file */ | 307 | /* Start the log, sanitize fd's, and write a pid file */ |
| 309 | start_log_and_pid("udhcpc", client_config.pidfile); | 308 | udhcp_start_log_and_pid("udhcpc", client_config.pidfile); |
| 310 | 309 | ||
| 311 | if (read_interface(client_config.interface, &client_config.ifindex, | 310 | if (read_interface(client_config.interface, &client_config.ifindex, |
| 312 | NULL, client_config.arp) < 0) | 311 | NULL, client_config.arp) < 0) |
| @@ -322,12 +321,12 @@ int main(int argc, char *argv[]) | |||
| 322 | } | 321 | } |
| 323 | 322 | ||
| 324 | if (!client_config.vendorclass) { | 323 | if (!client_config.vendorclass) { |
| 325 | client_config.vendorclass = xmalloc(sizeof("udhcp "VERSION) + 2); | 324 | client_config.vendorclass = xmalloc(sizeof("udhcp "BB_VER) + 2); |
| 326 | client_config.vendorclass[OPT_CODE] = DHCP_VENDOR; | 325 | client_config.vendorclass[OPT_CODE] = DHCP_VENDOR; |
| 327 | client_config.vendorclass[OPT_LEN] = sizeof("udhcp "VERSION) - 1; | 326 | client_config.vendorclass[OPT_LEN] = sizeof("udhcp "BB_VER) - 1; |
| 328 | client_config.vendorclass[OPT_DATA] = 1; | 327 | client_config.vendorclass[OPT_DATA] = 1; |
| 329 | memcpy(&client_config.vendorclass[OPT_DATA], | 328 | memcpy(&client_config.vendorclass[OPT_DATA], |
| 330 | "udhcp "VERSION, sizeof("udhcp "VERSION) - 1); | 329 | "udhcp "BB_VER, sizeof("udhcp "BB_VER) - 1); |
| 331 | } | 330 | } |
| 332 | 331 | ||
| 333 | 332 | ||
| @@ -335,7 +334,7 @@ int main(int argc, char *argv[]) | |||
| 335 | udhcp_sp_setup(); | 334 | udhcp_sp_setup(); |
| 336 | 335 | ||
| 337 | state = INIT_SELECTING; | 336 | state = INIT_SELECTING; |
| 338 | run_script(NULL, "deconfig"); | 337 | udhcp_run_script(NULL, "deconfig"); |
| 339 | change_mode(LISTEN_RAW); | 338 | change_mode(LISTEN_RAW); |
| 340 | 339 | ||
| 341 | for (;;) { | 340 | for (;;) { |
| @@ -375,7 +374,7 @@ int main(int argc, char *argv[]) | |||
| 375 | timeout = now + client_config.timeout; | 374 | timeout = now + client_config.timeout; |
| 376 | packet_num++; | 375 | packet_num++; |
| 377 | } else { | 376 | } else { |
| 378 | run_script(NULL, "leasefail"); | 377 | udhcp_run_script(NULL, "leasefail"); |
| 379 | if (client_config.background_if_no_lease) { | 378 | if (client_config.background_if_no_lease) { |
| 380 | LOG(LOG_INFO, "No lease, forking to background."); | 379 | LOG(LOG_INFO, "No lease, forking to background."); |
| 381 | client_background(); | 380 | client_background(); |
| @@ -400,7 +399,7 @@ int main(int argc, char *argv[]) | |||
| 400 | packet_num++; | 399 | packet_num++; |
| 401 | } else { | 400 | } else { |
| 402 | /* timed out, go back to init state */ | 401 | /* timed out, go back to init state */ |
| 403 | if (state == RENEW_REQUESTED) run_script(NULL, "deconfig"); | 402 | if (state == RENEW_REQUESTED) udhcp_run_script(NULL, "deconfig"); |
| 404 | state = INIT_SELECTING; | 403 | state = INIT_SELECTING; |
| 405 | timeout = now; | 404 | timeout = now; |
| 406 | packet_num = 0; | 405 | packet_num = 0; |
| @@ -434,7 +433,7 @@ int main(int argc, char *argv[]) | |||
| 434 | /* timed out, enter init state */ | 433 | /* timed out, enter init state */ |
| 435 | state = INIT_SELECTING; | 434 | state = INIT_SELECTING; |
| 436 | LOG(LOG_INFO, "Lease lost, entering init state"); | 435 | LOG(LOG_INFO, "Lease lost, entering init state"); |
| 437 | run_script(NULL, "deconfig"); | 436 | udhcp_run_script(NULL, "deconfig"); |
| 438 | timeout = now; | 437 | timeout = now; |
| 439 | packet_num = 0; | 438 | packet_num = 0; |
| 440 | change_mode(LISTEN_RAW); | 439 | change_mode(LISTEN_RAW); |
| @@ -455,7 +454,7 @@ int main(int argc, char *argv[]) | |||
| 455 | /* a packet is ready, read it */ | 454 | /* a packet is ready, read it */ |
| 456 | 455 | ||
| 457 | if (listen_mode == LISTEN_KERNEL) | 456 | if (listen_mode == LISTEN_KERNEL) |
| 458 | len = get_packet(&packet, fd); | 457 | len = udhcp_get_packet(&packet, fd); |
| 459 | else len = get_raw_packet(&packet, fd); | 458 | else len = get_raw_packet(&packet, fd); |
| 460 | 459 | ||
| 461 | if (len == -1 && errno != EINTR) { | 460 | if (len == -1 && errno != EINTR) { |
| @@ -523,7 +522,7 @@ int main(int argc, char *argv[]) | |||
| 523 | start = now; | 522 | start = now; |
| 524 | timeout = t1 + start; | 523 | timeout = t1 + start; |
| 525 | requested_ip = packet.yiaddr; | 524 | requested_ip = packet.yiaddr; |
| 526 | run_script(&packet, | 525 | udhcp_run_script(&packet, |
| 527 | ((state == RENEWING || state == REBINDING) ? "renew" : "bound")); | 526 | ((state == RENEWING || state == REBINDING) ? "renew" : "bound")); |
| 528 | 527 | ||
| 529 | state = BOUND; | 528 | state = BOUND; |
| @@ -536,9 +535,9 @@ int main(int argc, char *argv[]) | |||
| 536 | } else if (*message == DHCPNAK) { | 535 | } else if (*message == DHCPNAK) { |
| 537 | /* return to init state */ | 536 | /* return to init state */ |
| 538 | LOG(LOG_INFO, "Received DHCP NAK"); | 537 | LOG(LOG_INFO, "Received DHCP NAK"); |
| 539 | run_script(&packet, "nak"); | 538 | udhcp_run_script(&packet, "nak"); |
| 540 | if (state != REQUESTING) | 539 | if (state != REQUESTING) |
| 541 | run_script(NULL, "deconfig"); | 540 | udhcp_run_script(NULL, "deconfig"); |
| 542 | state = INIT_SELECTING; | 541 | state = INIT_SELECTING; |
| 543 | timeout = now; | 542 | timeout = now; |
| 544 | requested_ip = 0; | 543 | requested_ip = 0; |
diff --git a/networking/udhcp/dhcpd.c b/networking/udhcp/dhcpd.c index 6c5a753eb..29ca06a68 100644 --- a/networking/udhcp/dhcpd.c +++ b/networking/udhcp/dhcpd.c | |||
| @@ -6,19 +6,7 @@ | |||
| 6 | * | 6 | * |
| 7 | * Rewrite by Russ Dill <Russ.Dill@asu.edu> July 2001 | 7 | * Rewrite by Russ Dill <Russ.Dill@asu.edu> July 2001 |
| 8 | * | 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify | 9 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
| 10 | * it under the terms of the GNU General Public License as published by | ||
| 11 | * the Free Software Foundation; either version 2 of the License, or | ||
| 12 | * (at your option) any later version. | ||
| 13 | * | ||
| 14 | * This program is distributed in the hope that it will be useful, | ||
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 17 | * GNU General Public License for more details. | ||
| 18 | * | ||
| 19 | * You should have received a copy of the GNU General Public License | ||
| 20 | * along with this program; if not, write to the Free Software | ||
| 21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
| 22 | */ | 10 | */ |
| 23 | 11 | ||
| 24 | #include <fcntl.h> | 12 | #include <fcntl.h> |
| @@ -66,7 +54,7 @@ int udhcpd_main(int argc, char *argv[]) | |||
| 66 | read_config(argc < 2 ? DHCPD_CONF_FILE : argv[1]); | 54 | read_config(argc < 2 ? DHCPD_CONF_FILE : argv[1]); |
| 67 | 55 | ||
| 68 | /* Start the log, sanitize fd's, and write a pid file */ | 56 | /* Start the log, sanitize fd's, and write a pid file */ |
| 69 | start_log_and_pid("udhcpd", server_config.pidfile); | 57 | udhcp_start_log_and_pid("udhcpd", server_config.pidfile); |
| 70 | 58 | ||
| 71 | if ((option = find_option(server_config.options, DHCP_LEASE_TIME))) { | 59 | if ((option = find_option(server_config.options, DHCP_LEASE_TIME))) { |
| 72 | memcpy(&server_config.lease, option->data + 2, 4); | 60 | memcpy(&server_config.lease, option->data + 2, 4); |
| @@ -90,9 +78,8 @@ int udhcpd_main(int argc, char *argv[]) | |||
| 90 | &server_config.server, server_config.arp) < 0) | 78 | &server_config.server, server_config.arp) < 0) |
| 91 | return 1; | 79 | return 1; |
| 92 | 80 | ||
| 93 | #ifndef UDHCP_DEBUG | 81 | if (!ENABLE_FEATURE_UDHCP_DEBUG) |
| 94 | background(server_config.pidfile); /* hold lock during fork. */ | 82 | udhcp_background(server_config.pidfile); /* hold lock during fork. */ |
| 95 | #endif | ||
| 96 | 83 | ||
| 97 | /* Setup the signal pipe */ | 84 | /* Setup the signal pipe */ |
| 98 | udhcp_sp_setup(); | 85 | udhcp_sp_setup(); |
| @@ -139,7 +126,7 @@ int udhcpd_main(int argc, char *argv[]) | |||
| 139 | default: continue; /* signal or error (probably EINTR) */ | 126 | default: continue; /* signal or error (probably EINTR) */ |
| 140 | } | 127 | } |
| 141 | 128 | ||
| 142 | if ((bytes = get_packet(&packet, server_socket)) < 0) { /* this waits for a packet - idle */ | 129 | if ((bytes = udhcp_get_packet(&packet, server_socket)) < 0) { /* this waits for a packet - idle */ |
| 143 | if (bytes == -1 && errno != EINTR) { | 130 | if (bytes == -1 && errno != EINTR) { |
| 144 | DEBUG(LOG_INFO, "error on read, %m, reopening socket"); | 131 | DEBUG(LOG_INFO, "error on read, %m, reopening socket"); |
| 145 | close(server_socket); | 132 | close(server_socket); |
diff --git a/networking/udhcp/dhcpd.h b/networking/udhcp/dhcpd.h index a060002cd..37ebbe326 100644 --- a/networking/udhcp/dhcpd.h +++ b/networking/udhcp/dhcpd.h | |||
| @@ -7,7 +7,6 @@ | |||
| 7 | 7 | ||
| 8 | #include "libbb_udhcp.h" | 8 | #include "libbb_udhcp.h" |
| 9 | #include "leases.h" | 9 | #include "leases.h" |
| 10 | #include "version.h" | ||
| 11 | 10 | ||
| 12 | /************************************/ | 11 | /************************************/ |
| 13 | /* Defaults _you_ may want to tweak */ | 12 | /* Defaults _you_ may want to tweak */ |
diff --git a/networking/udhcp/files.c b/networking/udhcp/files.c index fe853c7cc..d2ca2363f 100644 --- a/networking/udhcp/files.c +++ b/networking/udhcp/files.c | |||
| @@ -241,9 +241,7 @@ static int read_staticlease(const char *const_line, void *arg) | |||
| 241 | 241 | ||
| 242 | addStaticLease(arg, mac_bytes, ip); | 242 | addStaticLease(arg, mac_bytes, ip); |
| 243 | 243 | ||
| 244 | #ifdef UDHCP_DEBUG | 244 | if (ENABLE_FEATURE_UDHCP_DEBUG) printStaticLeases(arg); |
| 245 | printStaticLeases(arg); | ||
| 246 | #endif | ||
| 247 | 245 | ||
| 248 | return 1; | 246 | return 1; |
| 249 | 247 | ||
| @@ -280,9 +278,6 @@ int read_config(const char *file) | |||
| 280 | { | 278 | { |
| 281 | FILE *in; | 279 | FILE *in; |
| 282 | char buffer[READ_CONFIG_BUF_SIZE], *token, *line; | 280 | char buffer[READ_CONFIG_BUF_SIZE], *token, *line; |
| 283 | #ifdef UDHCP_DEBUG | ||
| 284 | char orig[READ_CONFIG_BUF_SIZE]; | ||
| 285 | #endif | ||
| 286 | int i, lm = 0; | 281 | int i, lm = 0; |
| 287 | 282 | ||
| 288 | for (i = 0; keywords[i].keyword[0]; i++) | 283 | for (i = 0; keywords[i].keyword[0]; i++) |
| @@ -295,11 +290,11 @@ int read_config(const char *file) | |||
| 295 | } | 290 | } |
| 296 | 291 | ||
| 297 | while (fgets(buffer, READ_CONFIG_BUF_SIZE, in)) { | 292 | while (fgets(buffer, READ_CONFIG_BUF_SIZE, in)) { |
| 293 | char debug_orig[READ_CONFIG_BUF_SIZE]; | ||
| 294 | |||
| 298 | lm++; | 295 | lm++; |
| 299 | if (strchr(buffer, '\n')) *(strchr(buffer, '\n')) = '\0'; | 296 | if (strchr(buffer, '\n')) *(strchr(buffer, '\n')) = '\0'; |
| 300 | #ifdef UDHCP_DEBUG | 297 | if (ENABLE_FEATURE_UDHCP_DEBUG) strcpy(debug_orig, buffer); |
| 301 | strcpy(orig, buffer); | ||
| 302 | #endif | ||
| 303 | if (strchr(buffer, '#')) *(strchr(buffer, '#')) = '\0'; | 298 | if (strchr(buffer, '#')) *(strchr(buffer, '#')) = '\0'; |
| 304 | 299 | ||
| 305 | if (!(token = strtok(buffer, " \t"))) continue; | 300 | if (!(token = strtok(buffer, " \t"))) continue; |
| @@ -315,7 +310,7 @@ int read_config(const char *file) | |||
| 315 | if (!strcasecmp(token, keywords[i].keyword)) | 310 | if (!strcasecmp(token, keywords[i].keyword)) |
| 316 | if (!keywords[i].handler(line, keywords[i].var)) { | 311 | if (!keywords[i].handler(line, keywords[i].var)) { |
| 317 | LOG(LOG_ERR, "Failure parsing line %d of %s", lm, file); | 312 | LOG(LOG_ERR, "Failure parsing line %d of %s", lm, file); |
| 318 | DEBUG(LOG_ERR, "unable to parse '%s'", orig); | 313 | DEBUG(LOG_ERR, "unable to parse '%s'", debug_orig); |
| 319 | /* reset back to the default value */ | 314 | /* reset back to the default value */ |
| 320 | keywords[i].handler(keywords[i].def, keywords[i].var); | 315 | keywords[i].handler(keywords[i].def, keywords[i].var); |
| 321 | } | 316 | } |
diff --git a/networking/udhcp/libbb_udhcp.h b/networking/udhcp/libbb_udhcp.h index cce826786..c47af2d0a 100644 --- a/networking/udhcp/libbb_udhcp.h +++ b/networking/udhcp/libbb_udhcp.h | |||
| @@ -6,40 +6,29 @@ | |||
| 6 | #ifndef _LIBBB_UDHCP_H | 6 | #ifndef _LIBBB_UDHCP_H |
| 7 | #define _LIBBB_UDHCP_H | 7 | #define _LIBBB_UDHCP_H |
| 8 | 8 | ||
| 9 | #include "packet.h" | ||
| 10 | #include "busybox.h" | ||
| 11 | |||
| 9 | #ifdef CONFIG_INSTALL_NO_USR | 12 | #ifdef CONFIG_INSTALL_NO_USR |
| 10 | # define DEFAULT_SCRIPT "/share/udhcpc/default.script" | 13 | # define DEFAULT_SCRIPT "/share/udhcpc/default.script" |
| 11 | #else | 14 | #else |
| 12 | # define DEFAULT_SCRIPT "/usr/share/udhcpc/default.script" | 15 | # define DEFAULT_SCRIPT "/usr/share/udhcpc/default.script" |
| 13 | #endif | 16 | #endif |
| 14 | 17 | ||
| 15 | #ifdef IN_BUSYBOX | ||
| 16 | #include "busybox.h" | ||
| 17 | 18 | ||
| 18 | #ifdef CONFIG_FEATURE_UDHCP_SYSLOG | ||
| 19 | #define UDHCP_SYSLOG | ||
| 20 | #endif | ||
| 21 | |||
| 22 | #ifdef CONFIG_FEATURE_UDHCP_DEBUG | ||
| 23 | #define UDHCP_DEBUG | ||
| 24 | #endif | ||
| 25 | 19 | ||
| 26 | #define COMBINED_BINARY | 20 | #define COMBINED_BINARY |
| 27 | #include "version.h" | ||
| 28 | 21 | ||
| 29 | #define xfopen bb_xfopen | 22 | #define xfopen bb_xfopen |
| 30 | 23 | ||
| 31 | /* make safe the exported namespace */ | 24 | void udhcp_background(const char *pidfile); |
| 32 | /* from common.h */ | 25 | void udhcp_start_log_and_pid(const char *client_server, const char *pidfile); |
| 33 | #define background udhcp_background | 26 | void udhcp_logging(int level, const char *fmt, ...); |
| 34 | #define start_log_and_pid udhcp_start_log_and_pid | 27 | |
| 35 | /* from script.h */ | 28 | void udhcp_run_script(struct dhcpMessage *packet, const char *name); |
| 36 | #define run_script udhcp_run_script | 29 | |
| 37 | /* from packet.h */ | 30 | // Still need to clean these up... |
| 38 | #define init_header udhcp_init_header | 31 | |
| 39 | #define get_packet udhcp_get_packet | ||
| 40 | #define checksum udhcp_checksum | ||
| 41 | #define raw_packet udhcp_raw_packet | ||
| 42 | #define kernel_packet udhcp_kernel_packet | ||
| 43 | /* from pidfile.h */ | 32 | /* from pidfile.h */ |
| 44 | #define pidfile_acquire udhcp_pidfile_acquire | 33 | #define pidfile_acquire udhcp_pidfile_acquire |
| 45 | #define pidfile_write_release udhcp_pidfile_write_release | 34 | #define pidfile_write_release udhcp_pidfile_write_release |
| @@ -57,36 +46,4 @@ | |||
| 57 | /* from dhcpd.h */ | 46 | /* from dhcpd.h */ |
| 58 | #define server_config udhcp_server_config | 47 | #define server_config udhcp_server_config |
| 59 | 48 | ||
| 60 | #else /* ! IN_BUSYBOX */ | ||
| 61 | |||
| 62 | #include <stdlib.h> | ||
| 63 | #include <stdio.h> | ||
| 64 | #include <sys/sysinfo.h> | ||
| 65 | |||
| 66 | #ifndef ATTRIBUTE_NORETURN | ||
| 67 | #define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__)) | ||
| 68 | #endif /* ATTRIBUTE_NORETURN */ | ||
| 69 | |||
| 70 | #ifndef ATTRIBUTE_PACKED | ||
| 71 | #define ATTRIBUTE_PACKED __attribute__ ((__packed__)) | ||
| 72 | #endif /* ATTRIBUTE_PACKED */ | ||
| 73 | |||
| 74 | #define TRUE 1 | ||
| 75 | #define FALSE 0 | ||
| 76 | |||
| 77 | #define xmalloc malloc | ||
| 78 | #define xcalloc calloc | ||
| 79 | |||
| 80 | static inline FILE *xfopen(const char *file, const char *mode) | ||
| 81 | { | ||
| 82 | FILE *fp; | ||
| 83 | if (!(fp = fopen(file, mode))) { | ||
| 84 | perror("could not open input file"); | ||
| 85 | exit(0); | ||
| 86 | } | ||
| 87 | return fp; | ||
| 88 | } | ||
| 89 | |||
| 90 | #endif /* IN_BUSYBOX */ | ||
| 91 | |||
| 92 | #endif /* _LIBBB_UDHCP_H */ | 49 | #endif /* _LIBBB_UDHCP_H */ |
diff --git a/networking/udhcp/packet.c b/networking/udhcp/packet.c index ae06d53cc..8cf9fe283 100644 --- a/networking/udhcp/packet.c +++ b/networking/udhcp/packet.c | |||
| @@ -20,7 +20,7 @@ | |||
| 20 | #include "options.h" | 20 | #include "options.h" |
| 21 | 21 | ||
| 22 | 22 | ||
| 23 | void init_header(struct dhcpMessage *packet, char type) | 23 | void udhcp_init_header(struct dhcpMessage *packet, char type) |
| 24 | { | 24 | { |
| 25 | memset(packet, 0, sizeof(struct dhcpMessage)); | 25 | memset(packet, 0, sizeof(struct dhcpMessage)); |
| 26 | switch (type) { | 26 | switch (type) { |
| @@ -44,7 +44,7 @@ void init_header(struct dhcpMessage *packet, char type) | |||
| 44 | 44 | ||
| 45 | 45 | ||
| 46 | /* read a packet from socket fd, return -1 on read error, -2 on packet error */ | 46 | /* read a packet from socket fd, return -1 on read error, -2 on packet error */ |
| 47 | int get_packet(struct dhcpMessage *packet, int fd) | 47 | int udhcp_get_packet(struct dhcpMessage *packet, int fd) |
| 48 | { | 48 | { |
| 49 | static const char broken_vendors[][8] = { | 49 | static const char broken_vendors[][8] = { |
| 50 | "MSFT 98", | 50 | "MSFT 98", |
| @@ -82,7 +82,7 @@ int get_packet(struct dhcpMessage *packet, int fd) | |||
| 82 | } | 82 | } |
| 83 | 83 | ||
| 84 | 84 | ||
| 85 | uint16_t checksum(void *addr, int count) | 85 | uint16_t udhcp_checksum(void *addr, int count) |
| 86 | { | 86 | { |
| 87 | /* Compute Internet Checksum for "count" bytes | 87 | /* Compute Internet Checksum for "count" bytes |
| 88 | * beginning at location "addr". | 88 | * beginning at location "addr". |
| @@ -113,7 +113,7 @@ uint16_t checksum(void *addr, int count) | |||
| 113 | 113 | ||
| 114 | 114 | ||
| 115 | /* Construct a ip/udp header for a packet, and specify the source and dest hardware address */ | 115 | /* Construct a ip/udp header for a packet, and specify the source and dest hardware address */ |
| 116 | int raw_packet(struct dhcpMessage *payload, uint32_t source_ip, int source_port, | 116 | int udhcp_raw_packet(struct dhcpMessage *payload, uint32_t source_ip, int source_port, |
| 117 | uint32_t dest_ip, int dest_port, uint8_t *dest_arp, int ifindex) | 117 | uint32_t dest_ip, int dest_port, uint8_t *dest_arp, int ifindex) |
| 118 | { | 118 | { |
| 119 | int fd; | 119 | int fd; |
| @@ -148,13 +148,13 @@ int raw_packet(struct dhcpMessage *payload, uint32_t source_ip, int source_port, | |||
| 148 | packet.udp.len = htons(sizeof(packet.udp) + sizeof(struct dhcpMessage)); /* cheat on the psuedo-header */ | 148 | packet.udp.len = htons(sizeof(packet.udp) + sizeof(struct dhcpMessage)); /* cheat on the psuedo-header */ |
| 149 | packet.ip.tot_len = packet.udp.len; | 149 | packet.ip.tot_len = packet.udp.len; |
| 150 | memcpy(&(packet.data), payload, sizeof(struct dhcpMessage)); | 150 | memcpy(&(packet.data), payload, sizeof(struct dhcpMessage)); |
| 151 | packet.udp.check = checksum(&packet, sizeof(struct udp_dhcp_packet)); | 151 | packet.udp.check = udhcp_checksum(&packet, sizeof(struct udp_dhcp_packet)); |
| 152 | 152 | ||
| 153 | packet.ip.tot_len = htons(sizeof(struct udp_dhcp_packet)); | 153 | packet.ip.tot_len = htons(sizeof(struct udp_dhcp_packet)); |
| 154 | packet.ip.ihl = sizeof(packet.ip) >> 2; | 154 | packet.ip.ihl = sizeof(packet.ip) >> 2; |
| 155 | packet.ip.version = IPVERSION; | 155 | packet.ip.version = IPVERSION; |
| 156 | packet.ip.ttl = IPDEFTTL; | 156 | packet.ip.ttl = IPDEFTTL; |
| 157 | packet.ip.check = checksum(&(packet.ip), sizeof(packet.ip)); | 157 | packet.ip.check = udhcp_checksum(&(packet.ip), sizeof(packet.ip)); |
| 158 | 158 | ||
| 159 | result = sendto(fd, &packet, sizeof(struct udp_dhcp_packet), 0, (struct sockaddr *) &dest, sizeof(dest)); | 159 | result = sendto(fd, &packet, sizeof(struct udp_dhcp_packet), 0, (struct sockaddr *) &dest, sizeof(dest)); |
| 160 | if (result <= 0) { | 160 | if (result <= 0) { |
| @@ -166,7 +166,7 @@ int raw_packet(struct dhcpMessage *payload, uint32_t source_ip, int source_port, | |||
| 166 | 166 | ||
| 167 | 167 | ||
| 168 | /* Let the kernel do all the work for packet generation */ | 168 | /* Let the kernel do all the work for packet generation */ |
| 169 | int kernel_packet(struct dhcpMessage *payload, uint32_t source_ip, int source_port, | 169 | int udhcp_kernel_packet(struct dhcpMessage *payload, uint32_t source_ip, int source_port, |
| 170 | uint32_t dest_ip, int dest_port) | 170 | uint32_t dest_ip, int dest_port) |
| 171 | { | 171 | { |
| 172 | int n = 1; | 172 | int n = 1; |
diff --git a/networking/udhcp/packet.h b/networking/udhcp/packet.h index f5859e824..f595422e4 100644 --- a/networking/udhcp/packet.h +++ b/networking/udhcp/packet.h | |||
| @@ -29,12 +29,12 @@ struct udp_dhcp_packet { | |||
| 29 | struct dhcpMessage data; | 29 | struct dhcpMessage data; |
| 30 | }; | 30 | }; |
| 31 | 31 | ||
| 32 | void init_header(struct dhcpMessage *packet, char type); | 32 | void udhcp_init_header(struct dhcpMessage *packet, char type); |
| 33 | int get_packet(struct dhcpMessage *packet, int fd); | 33 | int udhcp_get_packet(struct dhcpMessage *packet, int fd); |
| 34 | uint16_t checksum(void *addr, int count); | 34 | uint16_t udhcp_checksum(void *addr, int count); |
| 35 | int raw_packet(struct dhcpMessage *payload, uint32_t source_ip, int source_port, | 35 | int udhcp_raw_packet(struct dhcpMessage *payload, uint32_t source_ip, int source_port, |
| 36 | uint32_t dest_ip, int dest_port, uint8_t *dest_arp, int ifindex); | 36 | uint32_t dest_ip, int dest_port, uint8_t *dest_arp, int ifindex); |
| 37 | int kernel_packet(struct dhcpMessage *payload, uint32_t source_ip, int source_port, | 37 | int udhcp_kernel_packet(struct dhcpMessage *payload, uint32_t source_ip, int source_port, |
| 38 | uint32_t dest_ip, int dest_port); | 38 | uint32_t dest_ip, int dest_port); |
| 39 | 39 | ||
| 40 | 40 | ||
diff --git a/networking/udhcp/script.c b/networking/udhcp/script.c index 2a4732104..d1b272de6 100644 --- a/networking/udhcp/script.c +++ b/networking/udhcp/script.c | |||
| @@ -4,19 +4,7 @@ | |||
| 4 | * | 4 | * |
| 5 | * Russ Dill <Russ.Dill@asu.edu> July 2001 | 5 | * Russ Dill <Russ.Dill@asu.edu> July 2001 |
| 6 | * | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify | 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
| 8 | * it under the terms of the GNU General Public License as published by | ||
| 9 | * the Free Software Foundation; either version 2 of the License, or | ||
| 10 | * (at your option) any later version. | ||
| 11 | * | ||
| 12 | * This program is distributed in the hope that it will be useful, | ||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 15 | * GNU General Public License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU General Public License | ||
| 18 | * along with this program; if not, write to the Free Software | ||
| 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
| 20 | */ | 8 | */ |
| 21 | 9 | ||
| 22 | #include <string.h> | 10 | #include <string.h> |
| @@ -33,7 +21,6 @@ | |||
| 33 | #include "options.h" | 21 | #include "options.h" |
| 34 | #include "dhcpd.h" | 22 | #include "dhcpd.h" |
| 35 | #include "dhcpc.h" | 23 | #include "dhcpc.h" |
| 36 | #include "script.h" | ||
| 37 | 24 | ||
| 38 | /* get a rough idea of how long an option will be (rounding up...) */ | 25 | /* get a rough idea of how long an option will be (rounding up...) */ |
| 39 | static const int max_option_length[] = { | 26 | static const int max_option_length[] = { |
| @@ -161,10 +148,10 @@ static char **fill_envp(struct dhcpMessage *packet) | |||
| 161 | 148 | ||
| 162 | envp = xzalloc(sizeof(char *) * (num_options + 5)); | 149 | envp = xzalloc(sizeof(char *) * (num_options + 5)); |
| 163 | j = 0; | 150 | j = 0; |
| 164 | asprintf(&envp[j++], "interface=%s", client_config.interface); | 151 | envp[j++] = bb_xasprintf("interface=%s", client_config.interface); |
| 165 | asprintf(&envp[j++], "%s=%s", "PATH", | 152 | envp[j++] = bb_xasprintf("PATH=%s", |
| 166 | getenv("PATH") ? : "/bin:/usr/bin:/sbin:/usr/sbin"); | 153 | getenv("PATH") ? : "/bin:/usr/bin:/sbin:/usr/sbin"); |
| 167 | asprintf(&envp[j++], "%s=%s", "HOME", getenv("HOME") ? : "/"); | 154 | envp[j++] = bb_xasprintf("HOME=%s", getenv("HOME") ? : "/"); |
| 168 | 155 | ||
| 169 | if (packet == NULL) return envp; | 156 | if (packet == NULL) return envp; |
| 170 | 157 | ||
| @@ -182,7 +169,7 @@ static char **fill_envp(struct dhcpMessage *packet) | |||
| 182 | /* Fill in a subnet bits option for things like /24 */ | 169 | /* Fill in a subnet bits option for things like /24 */ |
| 183 | if (dhcp_options[i].code == DHCP_SUBNET) { | 170 | if (dhcp_options[i].code == DHCP_SUBNET) { |
| 184 | memcpy(&subnet, temp, 4); | 171 | memcpy(&subnet, temp, 4); |
| 185 | asprintf(&envp[j++], "mask=%d", mton(&subnet)); | 172 | envp[j++] = bb_xasprintf("mask=%d", mton(&subnet)); |
| 186 | } | 173 | } |
| 187 | } | 174 | } |
| 188 | if (packet->siaddr) { | 175 | if (packet->siaddr) { |
| @@ -192,19 +179,19 @@ static char **fill_envp(struct dhcpMessage *packet) | |||
| 192 | if (!(over & FILE_FIELD) && packet->file[0]) { | 179 | if (!(over & FILE_FIELD) && packet->file[0]) { |
| 193 | /* watch out for invalid packets */ | 180 | /* watch out for invalid packets */ |
| 194 | packet->file[sizeof(packet->file) - 1] = '\0'; | 181 | packet->file[sizeof(packet->file) - 1] = '\0'; |
| 195 | asprintf(&envp[j++], "boot_file=%s", packet->file); | 182 | envp[j++] = bb_xasprintf("boot_file=%s", packet->file); |
| 196 | } | 183 | } |
| 197 | if (!(over & SNAME_FIELD) && packet->sname[0]) { | 184 | if (!(over & SNAME_FIELD) && packet->sname[0]) { |
| 198 | /* watch out for invalid packets */ | 185 | /* watch out for invalid packets */ |
| 199 | packet->sname[sizeof(packet->sname) - 1] = '\0'; | 186 | packet->sname[sizeof(packet->sname) - 1] = '\0'; |
| 200 | asprintf(&envp[j++], "sname=%s", packet->sname); | 187 | envp[j++] = bb_xasprintf("sname=%s", packet->sname); |
| 201 | } | 188 | } |
| 202 | return envp; | 189 | return envp; |
| 203 | } | 190 | } |
| 204 | 191 | ||
| 205 | 192 | ||
| 206 | /* Call a script with a par file and env vars */ | 193 | /* Call a script with a par file and env vars */ |
| 207 | void run_script(struct dhcpMessage *packet, const char *name) | 194 | void udhcp_run_script(struct dhcpMessage *packet, const char *name) |
| 208 | { | 195 | { |
| 209 | int pid; | 196 | int pid; |
| 210 | char **envp, **curr; | 197 | char **envp, **curr; |
diff --git a/networking/udhcp/script.h b/networking/udhcp/script.h deleted file mode 100644 index 71003311c..000000000 --- a/networking/udhcp/script.h +++ /dev/null | |||
| @@ -1,6 +0,0 @@ | |||
| 1 | #ifndef _SCRIPT_H | ||
| 2 | #define _SCRIPT_H | ||
| 3 | |||
| 4 | extern void run_script(struct dhcpMessage *packet, const char *name); | ||
| 5 | |||
| 6 | #endif | ||
diff --git a/networking/udhcp/serverpacket.c b/networking/udhcp/serverpacket.c index fe880b4a0..e40432ebe 100644 --- a/networking/udhcp/serverpacket.c +++ b/networking/udhcp/serverpacket.c | |||
| @@ -36,7 +36,7 @@ static int send_packet_to_relay(struct dhcpMessage *payload) | |||
| 36 | { | 36 | { |
| 37 | DEBUG(LOG_INFO, "Forwarding packet to relay"); | 37 | DEBUG(LOG_INFO, "Forwarding packet to relay"); |
| 38 | 38 | ||
| 39 | return kernel_packet(payload, server_config.server, SERVER_PORT, | 39 | return udhcp_kernel_packet(payload, server_config.server, SERVER_PORT, |
| 40 | payload->giaddr, SERVER_PORT); | 40 | payload->giaddr, SERVER_PORT); |
| 41 | } | 41 | } |
| 42 | 42 | ||
| @@ -64,7 +64,7 @@ static int send_packet_to_client(struct dhcpMessage *payload, int force_broadcas | |||
| 64 | ciaddr = payload->yiaddr; | 64 | ciaddr = payload->yiaddr; |
| 65 | chaddr = payload->chaddr; | 65 | chaddr = payload->chaddr; |
| 66 | } | 66 | } |
| 67 | return raw_packet(payload, server_config.server, SERVER_PORT, | 67 | return udhcp_raw_packet(payload, server_config.server, SERVER_PORT, |
| 68 | ciaddr, CLIENT_PORT, chaddr, server_config.ifindex); | 68 | ciaddr, CLIENT_PORT, chaddr, server_config.ifindex); |
| 69 | } | 69 | } |
| 70 | 70 | ||
| @@ -83,7 +83,7 @@ static int send_packet(struct dhcpMessage *payload, int force_broadcast) | |||
| 83 | 83 | ||
| 84 | static void init_packet(struct dhcpMessage *packet, struct dhcpMessage *oldpacket, char type) | 84 | static void init_packet(struct dhcpMessage *packet, struct dhcpMessage *oldpacket, char type) |
| 85 | { | 85 | { |
| 86 | init_header(packet, type); | 86 | udhcp_init_header(packet, type); |
| 87 | packet->xid = oldpacket->xid; | 87 | packet->xid = oldpacket->xid; |
| 88 | memcpy(packet->chaddr, oldpacket->chaddr, 16); | 88 | memcpy(packet->chaddr, oldpacket->chaddr, 16); |
| 89 | packet->flags = oldpacket->flags; | 89 | packet->flags = oldpacket->flags; |
diff --git a/networking/udhcp/static_leases.c b/networking/udhcp/static_leases.c index 1124d39de..524798316 100644 --- a/networking/udhcp/static_leases.c +++ b/networking/udhcp/static_leases.c | |||
| @@ -93,7 +93,7 @@ uint32_t reservedIp(struct static_lease *lease_struct, uint32_t ip) | |||
| 93 | 93 | ||
| 94 | } | 94 | } |
| 95 | 95 | ||
| 96 | #ifdef UDHCP_DEBUG | 96 | #ifdef CONFIG_FEATURE_UDHCP_DEBUG |
| 97 | /* Print out static leases just to check what's going on */ | 97 | /* Print out static leases just to check what's going on */ |
| 98 | /* Takes the address of the pointer to the static_leases linked list */ | 98 | /* Takes the address of the pointer to the static_leases linked list */ |
| 99 | void printStaticLeases(struct static_lease **arg) | 99 | void printStaticLeases(struct static_lease **arg) |
diff --git a/networking/udhcp/static_leases.h b/networking/udhcp/static_leases.h index d06520b23..81708ffea 100644 --- a/networking/udhcp/static_leases.h +++ b/networking/udhcp/static_leases.h | |||
| @@ -14,10 +14,8 @@ uint32_t getIpByMac(struct static_lease *lease_struct, void *arg); | |||
| 14 | /* Check to see if an ip is reserved as a static ip */ | 14 | /* Check to see if an ip is reserved as a static ip */ |
| 15 | uint32_t reservedIp(struct static_lease *lease_struct, uint32_t ip); | 15 | uint32_t reservedIp(struct static_lease *lease_struct, uint32_t ip); |
| 16 | 16 | ||
| 17 | #ifdef UDHCP_DEBUG | 17 | /* Print out static leases just to check what's going on (debug code) */ |
| 18 | /* Print out static leases just to check what's going on */ | ||
| 19 | void printStaticLeases(struct static_lease **lease_struct); | 18 | void printStaticLeases(struct static_lease **lease_struct); |
| 20 | #endif | ||
| 21 | 19 | ||
| 22 | #endif | 20 | #endif |
| 23 | 21 | ||
diff --git a/networking/udhcp/version.h b/networking/udhcp/version.h deleted file mode 100644 index 3862539f5..000000000 --- a/networking/udhcp/version.h +++ /dev/null | |||
| @@ -1,6 +0,0 @@ | |||
| 1 | #ifndef _UDHCP_VERSION_H | ||
| 2 | #define _UDHCP_VERSION_H | ||
| 3 | |||
| 4 | #define VERSION "0.9.9-pre" | ||
| 5 | |||
| 6 | #endif | ||
