added env var for mask bits

This commit is contained in:
Russ Dill 2002-12-11 20:53:58 +00:00
parent fd015edaa9
commit bd709948ee
5 changed files with 41 additions and 13 deletions

View File

@ -1,3 +1,7 @@
0.9.9 (pending)
+ added an new enviromental variable: $mask. It contains the number
of subnet bits for tools like ip route that require it.
0.9.8 (021031)
+ split up README files (me)
+ use /dev/urandom to seed xid's (instead of time(0)) (me)

View File

@ -69,6 +69,7 @@ The paramaters for enviromental variables are as follows:
$1 - What action the script should perform
interface - The interface this was obtained on
ip - The obtained IP
mask - The number of bits in the netmask (ie: 24)
siaddr - The bootp next server option
sname - The bootp server name option
boot_file - The bootp boot file option

1
TODO
View File

@ -10,6 +10,7 @@ TODO
+ make sure packet generation works on a wide varitey of arches
+ Interoperability testing
+ Hooks within the DHCP server
* Server notification when a lease is added/removed
+ Additional bootp support in client/server
+ Make serverid option in server configurable
+ Possibly add failure message to DHCP NAK

View File

@ -58,11 +58,23 @@ 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]);
}
/* really simple implementation, just count the bits */
static int mton(struct in_addr *mask)
{
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;
}
/* Fill dest with the text of option 'option'. */
static void fill_options(char *dest, unsigned char *option, struct dhcp_option *type_p)
{
@ -142,6 +154,7 @@ static char **fill_envp(struct dhcpMessage *packet)
int i, j;
char **envp;
unsigned char *temp;
struct in_addr subnet;
char over = 0;
if (packet == NULL)
@ -158,23 +171,32 @@ static char **fill_envp(struct dhcpMessage *packet)
}
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);
envp[1] = find_env("PATH", "PATH=/bin:/usr/bin:/sbin:/usr/sbin");
envp[2] = find_env("HOME", "HOME=/");
envp[j++] = find_env("PATH", "PATH=/bin:/usr/bin:/sbin:/usr/sbin");
envp[j++] = find_env("HOME", "HOME=/");
if (packet == NULL) {
envp[3] = NULL;
envp[j++] = NULL;
return envp;
}
envp[3] = xmalloc(sizeof("ip=255.255.255.255"));
sprintip(envp[3], "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);
fill_options(envp[j], temp, &options[i]);
j++;
envp[j] = xmalloc(sizeof("ip=255.255.255.255"));
sprintip(envp[j++], "ip=", (unsigned char *) &packet->yiaddr);
for (i = 0; options[i].code; i++) {
if (!(temp = get_option(packet, options[i].code)))
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) {

View File

@ -1,6 +1,6 @@
#ifndef _UDHCP_VERSION_H
#define _UDHCP_VERSION_H
#define VERSION "0.9.8"
#define VERSION "0.9.9-pre"
#endif