resync with udhcp cvs
This commit is contained in:
parent
d7e1a6c6eb
commit
1eb7a17b12
@ -38,14 +38,5 @@ config CONFIG_FEATURE_UDHCP_DEBUG
|
|||||||
help
|
help
|
||||||
Please submit a patch to add help text for this item.
|
Please submit a patch to add help text for this item.
|
||||||
|
|
||||||
config CONFIG_FEATURE_UDHCPC_IP
|
|
||||||
bool " Compile udhcpc with ip support"
|
|
||||||
default n
|
|
||||||
depends on CONFIG_UDHCPC
|
|
||||||
help
|
|
||||||
Say yes if you are using the ip command instead of route and ifconfig
|
|
||||||
in your scripts to bring up the interface.
|
|
||||||
This is needed as ip wants the subnet as a bitprefix not an ip value.
|
|
||||||
|
|
||||||
endmenu
|
endmenu
|
||||||
|
|
||||||
|
@ -69,6 +69,7 @@ The paramaters for enviromental variables are as follows:
|
|||||||
$1 - What action the script should perform
|
$1 - What action the script should perform
|
||||||
interface - The interface this was obtained on
|
interface - The interface this was obtained on
|
||||||
ip - The obtained IP
|
ip - The obtained IP
|
||||||
|
mask - The number of bits in the netmask (ie: 24)
|
||||||
siaddr - The bootp next server option
|
siaddr - The bootp next server option
|
||||||
sname - The bootp server name option
|
sname - The bootp server name option
|
||||||
boot_file - The bootp boot file option
|
boot_file - The bootp boot file option
|
||||||
|
@ -248,7 +248,7 @@ int main(int argc, char *argv[])
|
|||||||
switch (c) {
|
switch (c) {
|
||||||
case 'c':
|
case 'c':
|
||||||
len = strlen(optarg) > 255 ? 255 : strlen(optarg);
|
len = strlen(optarg) > 255 ? 255 : strlen(optarg);
|
||||||
free(client_config.clientid);
|
if (client_config.clientid) free(client_config.clientid);
|
||||||
client_config.clientid = xmalloc(len + 2);
|
client_config.clientid = xmalloc(len + 2);
|
||||||
client_config.clientid[OPT_CODE] = DHCP_CLIENT_ID;
|
client_config.clientid[OPT_CODE] = DHCP_CLIENT_ID;
|
||||||
client_config.clientid[OPT_LEN] = len;
|
client_config.clientid[OPT_LEN] = len;
|
||||||
@ -264,7 +264,7 @@ int main(int argc, char *argv[])
|
|||||||
case 'h':
|
case 'h':
|
||||||
case 'H':
|
case 'H':
|
||||||
len = strlen(optarg) > 255 ? 255 : strlen(optarg);
|
len = strlen(optarg) > 255 ? 255 : strlen(optarg);
|
||||||
free(client_config.hostname);
|
if (client_config.hostname) free(client_config.hostname);
|
||||||
client_config.hostname = xmalloc(len + 2);
|
client_config.hostname = xmalloc(len + 2);
|
||||||
client_config.hostname[OPT_CODE] = DHCP_HOST_NAME;
|
client_config.hostname[OPT_CODE] = DHCP_HOST_NAME;
|
||||||
client_config.hostname[OPT_LEN] = len;
|
client_config.hostname[OPT_LEN] = len;
|
||||||
|
@ -28,7 +28,7 @@ struct lease_t {
|
|||||||
u_int32_t expires;
|
u_int32_t expires;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef COMBINED_BINARY
|
#ifdef BB_VER
|
||||||
int dumpleases_main(int argc, char *argv[])
|
int dumpleases_main(int argc, char *argv[])
|
||||||
#else
|
#else
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
|
@ -38,7 +38,7 @@ static int read_str(char *line, void *arg)
|
|||||||
{
|
{
|
||||||
char **dest = arg;
|
char **dest = arg;
|
||||||
|
|
||||||
free(*dest);
|
if (*dest) free(*dest);
|
||||||
*dest = strdup(line);
|
*dest = strdup(line);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -13,16 +13,11 @@
|
|||||||
#include "options.h"
|
#include "options.h"
|
||||||
#include "leases.h"
|
#include "leases.h"
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
/* supported options are easily added here */
|
/* supported options are easily added here */
|
||||||
struct dhcp_option options[] = {
|
struct dhcp_option options[] = {
|
||||||
/* name[10] flags code */
|
/* name[10] flags code */
|
||||||
#ifdef CONFIG_FEATURE_UDHCPC_IP
|
{"subnet", OPTION_IP | OPTION_REQ, 0x01},
|
||||||
{"subnet", OPTION_IP | OPTION_REQ | OPTION_PREFIX, 0x01},
|
|
||||||
#else
|
|
||||||
{"subnet", OPTION_IP | OPTION_REQ, 0x01},
|
|
||||||
#endif
|
|
||||||
{"timezone", OPTION_S32, 0x02},
|
{"timezone", OPTION_S32, 0x02},
|
||||||
{"router", OPTION_IP | OPTION_LIST | OPTION_REQ, 0x03},
|
{"router", OPTION_IP | OPTION_LIST | OPTION_REQ, 0x03},
|
||||||
{"timesvr", OPTION_IP | OPTION_LIST, 0x04},
|
{"timesvr", OPTION_IP | OPTION_LIST, 0x04},
|
||||||
|
@ -4,8 +4,6 @@
|
|||||||
|
|
||||||
#include "packet.h"
|
#include "packet.h"
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
#define TYPE_MASK 0x0F
|
#define TYPE_MASK 0x0F
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
@ -22,7 +20,6 @@ enum {
|
|||||||
|
|
||||||
#define OPTION_REQ 0x10 /* have the client request this option */
|
#define OPTION_REQ 0x10 /* have the client request this option */
|
||||||
#define OPTION_LIST 0x20 /* There can be a list of 1 or more of these */
|
#define OPTION_LIST 0x20 /* There can be a list of 1 or more of these */
|
||||||
#define OPTION_PREFIX 0x40 /* ip wants a prefix instead of a ip for subnet */
|
|
||||||
|
|
||||||
struct dhcp_option {
|
struct dhcp_option {
|
||||||
char name[10];
|
char name[10];
|
||||||
|
@ -37,8 +37,6 @@
|
|||||||
#include "options.h"
|
#include "options.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
/* get a rough idea of how long an option will be (rounding up...) */
|
/* get a rough idea of how long an option will be (rounding up...) */
|
||||||
static int max_option_length[] = {
|
static int max_option_length[] = {
|
||||||
[OPTION_IP] = sizeof("255.255.255.255 "),
|
[OPTION_IP] = sizeof("255.255.255.255 "),
|
||||||
@ -60,41 +58,22 @@ static int upper_length(int length, struct dhcp_option *option)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int sprintip(char *dest, char *pre, unsigned char *ip) {
|
static int sprintip(char *dest, char *pre, unsigned char *ip)
|
||||||
return sprintf(dest, "%s%d.%d.%d.%d ", pre, ip[0], ip[1], ip[2], ip[3]);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef CONFIG_FEATURE_UDHCPC_IP
|
|
||||||
/* convert a netmask (255.255.255.0) into the length (24) */
|
|
||||||
static int inet_ntom (const char *src, short *dst)
|
|
||||||
{
|
{
|
||||||
in_addr_t mask, num;
|
return sprintf(dest, "%s%d.%d.%d.%d", pre, ip[0], ip[1], ip[2], ip[3]);
|
||||||
|
|
||||||
mask = ntohl(*(unsigned int *)src);
|
|
||||||
|
|
||||||
for (num = mask; num & 1; num >>= 1);
|
|
||||||
|
|
||||||
if (num != 0 && mask != 0)
|
|
||||||
{
|
|
||||||
for (num = ~mask; num & 1; num >>= 1);
|
|
||||||
if (num)
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (num = 0; mask; mask <<= 1)
|
|
||||||
num++;
|
|
||||||
|
|
||||||
*dst = num;
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sprintprefix(char *dest, char *pre, unsigned char *ip) {
|
|
||||||
short sdest = 0;
|
/* really simple implementation, just count the bits */
|
||||||
inet_ntom(ip, &sdest);
|
static int mton(struct in_addr *mask)
|
||||||
return sprintf(dest, "%s%hd ", pre, sdest);
|
{
|
||||||
|
int i;
|
||||||
|
/* note: mask will always be in network byte order, so
|
||||||
|
* there are no endian issues */
|
||||||
|
for (i = 31; i >= 0 && !((mask->s_addr >> i) & 1); i--);
|
||||||
|
return i + 1;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Fill dest with the text of option 'option'. */
|
/* Fill dest with the text of option 'option'. */
|
||||||
static void fill_options(char *dest, unsigned char *option, struct dhcp_option *type_p)
|
static void fill_options(char *dest, unsigned char *option, struct dhcp_option *type_p)
|
||||||
@ -117,41 +96,30 @@ static void fill_options(char *dest, unsigned char *option, struct dhcp_option *
|
|||||||
*(dest++) = '/';
|
*(dest++) = '/';
|
||||||
option += 4;
|
option += 4;
|
||||||
optlen = 4;
|
optlen = 4;
|
||||||
#ifndef CONFIG_FEATURE_UDHCPC_IP
|
|
||||||
case OPTION_IP: /* Works regardless of host byte order. */
|
case OPTION_IP: /* Works regardless of host byte order. */
|
||||||
#endif
|
|
||||||
dest += sprintip(dest, "", option);
|
dest += sprintip(dest, "", option);
|
||||||
break;
|
break;
|
||||||
#ifdef CONFIG_FEATURE_UDHCPC_IP
|
|
||||||
case OPTION_IP: /* Works regardless of host byte order. */
|
|
||||||
if (type_p->flags & OPTION_PREFIX) {
|
|
||||||
dest += sprintprefix(dest, "", option);
|
|
||||||
} else {
|
|
||||||
dest += sprintip(dest, "", option);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
case OPTION_BOOLEAN:
|
case OPTION_BOOLEAN:
|
||||||
dest += sprintf(dest, *option ? "yes " : "no ");
|
dest += sprintf(dest, *option ? "yes" : "no");
|
||||||
break;
|
break;
|
||||||
case OPTION_U8:
|
case OPTION_U8:
|
||||||
dest += sprintf(dest, "%u ", *option);
|
dest += sprintf(dest, "%u", *option);
|
||||||
break;
|
break;
|
||||||
case OPTION_U16:
|
case OPTION_U16:
|
||||||
memcpy(&val_u16, option, 2);
|
memcpy(&val_u16, option, 2);
|
||||||
dest += sprintf(dest, "%u ", ntohs(val_u16));
|
dest += sprintf(dest, "%u", ntohs(val_u16));
|
||||||
break;
|
break;
|
||||||
case OPTION_S16:
|
case OPTION_S16:
|
||||||
memcpy(&val_s16, option, 2);
|
memcpy(&val_s16, option, 2);
|
||||||
dest += sprintf(dest, "%d ", ntohs(val_s16));
|
dest += sprintf(dest, "%d", ntohs(val_s16));
|
||||||
break;
|
break;
|
||||||
case OPTION_U32:
|
case OPTION_U32:
|
||||||
memcpy(&val_u32, option, 4);
|
memcpy(&val_u32, option, 4);
|
||||||
dest += sprintf(dest, "%lu ", (unsigned long) ntohl(val_u32));
|
dest += sprintf(dest, "%lu", (unsigned long) ntohl(val_u32));
|
||||||
break;
|
break;
|
||||||
case OPTION_S32:
|
case OPTION_S32:
|
||||||
memcpy(&val_s32, option, 4);
|
memcpy(&val_s32, option, 4);
|
||||||
dest += sprintf(dest, "%ld ", (long) ntohl(val_s32));
|
dest += sprintf(dest, "%ld", (long) ntohl(val_s32));
|
||||||
break;
|
break;
|
||||||
case OPTION_STRING:
|
case OPTION_STRING:
|
||||||
memcpy(dest, option, len);
|
memcpy(dest, option, len);
|
||||||
@ -161,6 +129,7 @@ static void fill_options(char *dest, unsigned char *option, struct dhcp_option *
|
|||||||
option += optlen;
|
option += optlen;
|
||||||
len -= optlen;
|
len -= optlen;
|
||||||
if (len <= 0) break;
|
if (len <= 0) break;
|
||||||
|
dest += sprintf(dest, " ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -186,6 +155,7 @@ static char **fill_envp(struct dhcpMessage *packet)
|
|||||||
int i, j;
|
int i, j;
|
||||||
char **envp;
|
char **envp;
|
||||||
unsigned char *temp;
|
unsigned char *temp;
|
||||||
|
struct in_addr subnet;
|
||||||
char over = 0;
|
char over = 0;
|
||||||
|
|
||||||
if (packet == NULL)
|
if (packet == NULL)
|
||||||
@ -202,23 +172,32 @@ static char **fill_envp(struct dhcpMessage *packet)
|
|||||||
}
|
}
|
||||||
|
|
||||||
envp = xmalloc((num_options + 5) * sizeof(char *));
|
envp = xmalloc((num_options + 5) * sizeof(char *));
|
||||||
envp[0] = xmalloc(sizeof("interface=") + strlen(client_config.interface));
|
j = 0;
|
||||||
|
envp[j++] = xmalloc(sizeof("interface=") + strlen(client_config.interface));
|
||||||
sprintf(envp[0], "interface=%s", client_config.interface);
|
sprintf(envp[0], "interface=%s", client_config.interface);
|
||||||
envp[1] = find_env("PATH", "PATH=/bin:/usr/bin:/sbin:/usr/sbin");
|
envp[j++] = find_env("PATH", "PATH=/bin:/usr/bin:/sbin:/usr/sbin");
|
||||||
envp[2] = find_env("HOME", "HOME=/");
|
envp[j++] = find_env("HOME", "HOME=/");
|
||||||
|
|
||||||
if (packet == NULL) {
|
if (packet == NULL) {
|
||||||
envp[3] = NULL;
|
envp[j++] = NULL;
|
||||||
return envp;
|
return envp;
|
||||||
}
|
}
|
||||||
|
|
||||||
envp[3] = xmalloc(sizeof("ip=255.255.255.255"));
|
envp[j] = xmalloc(sizeof("ip=255.255.255.255"));
|
||||||
sprintip(envp[3], "ip=", (unsigned char *) &packet->yiaddr);
|
sprintip(envp[j++], "ip=", (unsigned char *) &packet->yiaddr);
|
||||||
for (i = 0, j = 4; options[i].code; i++) {
|
|
||||||
if ((temp = get_option(packet, options[i].code))) {
|
|
||||||
envp[j] = xmalloc(upper_length(temp[OPT_LEN - 2], &options[i]) + strlen(options[i].name) + 2);
|
for (i = 0; options[i].code; i++) {
|
||||||
fill_options(envp[j], temp, &options[i]);
|
if (!(temp = get_option(packet, options[i].code)))
|
||||||
j++;
|
continue;
|
||||||
|
envp[j] = xmalloc(upper_length(temp[OPT_LEN - 2], &options[i]) + strlen(options[i].name) + 2);
|
||||||
|
fill_options(envp[j++], temp, &options[i]);
|
||||||
|
|
||||||
|
/* Fill in a subnet bits option for things like /24 */
|
||||||
|
if (options[i].code == DHCP_SUBNET) {
|
||||||
|
envp[j] = xmalloc(sizeof("mask=32"));
|
||||||
|
memcpy(&subnet, temp, 4);
|
||||||
|
sprintf(envp[j++], "mask=%d", mton(&subnet));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (packet->siaddr) {
|
if (packet->siaddr) {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#ifndef _UDHCP_VERSION_H
|
#ifndef _UDHCP_VERSION_H
|
||||||
#define _UDHCP_VERSION_H
|
#define _UDHCP_VERSION_H
|
||||||
|
|
||||||
#define VERSION "0.9.8"
|
#define VERSION "0.9.9-pre"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user