[BusyBox] udhcp patches/ use actual and not maximum length for xmit
Rainer Weikusat
rainer.weikusat at sncag.com
Tue Feb 1 09:43:00 UTC 2005
This is the last 'feature patch' insofar it leaves the basic
architecture of udhcp unmodified. It keeps track of the actual length
of a dhcp packet and uses that for transmission instead of
the 'minimum maximum IP datagram size' of 576 octet. Additionally,
it avoids a couple of compiler warnings.
? busybox/networking/udhcp/endianess.h
? busybox/scripts/config/a.out
? busybox/scripts/config/lxtemp.c
Index: busybox//networking/udhcp/Makefile.in
===================================================================
RCS file: /data/repo/busybox/networking/udhcp/Makefile.in,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- busybox//networking/udhcp/Makefile.in 2 Dec 2004 16:07:30 -0000 1.2
+++ busybox//networking/udhcp/Makefile.in 31 Jan 2005 14:49:11 -0000 1.3
@@ -50,4 +50,4 @@
$(AR) -ro $@ $(UDHCP_OBJS)
$(UDHCP_OBJS): $(UDHCP_DIR)%.o : $(srcdir)/%.c
- $(CC) $(CFLAGS) -DUDHCP_SYSLOG $(EXTRA_CFLAGS) -DIN_BUSYBOX -c $< -o $@
+ $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -DIN_BUSYBOX -c $< -o $@
Index: busybox//networking/udhcp/clientpacket.c
===================================================================
RCS file: /data/repo/busybox/networking/udhcp/clientpacket.c,v
retrieving revision 1.1.1.2
retrieving revision 1.5
diff -u -r1.1.1.2 -r1.5
--- busybox//networking/udhcp/clientpacket.c 28 Jan 2005 17:58:06 -0000 1.1.1.2
+++ busybox//networking/udhcp/clientpacket.c 31 Jan 2005 15:07:07 -0000 1.5
@@ -67,93 +67,92 @@
/* initialize a packet with the proper defaults */
-static void init_packet(struct dhcpMessage *packet, char type)
+static void init_packet(struct dhcp_message *msg, char type, unsigned long xid)
{
struct vendor {
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);
- if (client_config.hostname) add_option_string(packet->options, client_config.hostname);
- if (client_config.fqdn) add_option_string(packet->options, client_config.fqdn);
- add_option_string(packet->options, (uint8_t *) &vendor_id);
+ init_header(msg, type);
+ memcpy(&msg->payload.chaddr, client_config.arp, 6);
+ msg->payload.xid = xid;
+
+ add_option_string(msg, client_config.clientid);
+ if (client_config.hostname) add_option_string(msg, client_config.hostname);
+ if (client_config.fqdn) add_option_string(msg, client_config.fqdn);
+ add_option_string(msg, (uint8_t *) &vendor_id);
}
/* Add a parameter request list for stubborn DHCP servers. Pull the data
* from the struct in options.c. Don't do bounds checking here because it
* goes towards the head of the packet. */
-static void add_requests(struct dhcpMessage *packet)
+static void add_requests(struct dhcp_message *msg)
{
- int end = end_option(packet->options);
+ int end = end_option(msg);
int i, len = 0;
- packet->options[end + OPT_CODE] = DHCP_PARAM_REQ;
+ msg->payload.options[end + OPT_CODE] = DHCP_PARAM_REQ;
for (i = 0; dhcp_options[i].code; i++)
if (dhcp_options[i].flags & OPTION_REQ)
- packet->options[end + OPT_DATA + len++] = dhcp_options[i].code;
- packet->options[end + OPT_LEN] = len;
- packet->options[end + OPT_DATA + len] = DHCP_END;
-
+ msg->payload.options[end + OPT_DATA + len++] = dhcp_options[i].code;
+ msg->payload.options[end + OPT_LEN] = len;
+ msg->payload.options[end + OPT_DATA + len] = DHCP_END;
+ msg->len += len + 2;
}
/* Broadcast a DHCP discover packet to the network, with an optionally requested IP */
int send_discover(unsigned long xid, unsigned long requested)
{
- struct dhcpMessage packet;
+ struct dhcp_message msg;
- init_packet(&packet, DHCPDISCOVER);
- packet.xid = xid;
+ init_packet(&msg, DHCPDISCOVER, xid);
if (requested)
- add_simple_option(packet.options, DHCP_REQUESTED_IP, requested);
+ add_simple_option(&msg, DHCP_REQUESTED_IP, requested);
- add_requests(&packet);
+ add_requests(&msg);
LOG(LOG_DEBUG, "Sending discover...");
- return raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST,
- SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex);
+ return raw_packet(&msg, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST,
+ SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex);
}
/* Broadcasts a DHCP request message */
int send_selecting(unsigned long xid, unsigned long server, unsigned long requested)
{
- struct dhcpMessage packet;
+ struct dhcp_message msg;
struct in_addr addr;
- init_packet(&packet, DHCPREQUEST);
- packet.xid = xid;
-
- add_simple_option(packet.options, DHCP_REQUESTED_IP, requested);
- add_simple_option(packet.options, DHCP_SERVER_ID, server);
+ init_packet(&msg, DHCPREQUEST, xid);
+
+ add_simple_option(&msg, DHCP_REQUESTED_IP, requested);
+ add_simple_option(&msg, DHCP_SERVER_ID, server);
- add_requests(&packet);
+ add_requests(&msg);
addr.s_addr = requested;
LOG(LOG_DEBUG, "Sending select for %s...", inet_ntoa(addr));
- return raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST,
- SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex);
+ return raw_packet(&msg, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST,
+ SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex);
}
/* Unicasts or broadcasts a DHCP renew message */
int send_renew(unsigned long xid, unsigned long server, unsigned long ciaddr)
{
- struct dhcpMessage packet;
+ struct dhcp_message msg;
int ret = 0;
- init_packet(&packet, DHCPREQUEST);
- packet.xid = xid;
- packet.ciaddr = ciaddr;
+ init_packet(&msg, DHCPREQUEST, xid);
+ msg.payload.ciaddr = ciaddr;
- add_requests(&packet);
+ add_requests(&msg);
LOG(LOG_DEBUG, "Sending renew...");
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);
+ ret = kernel_packet(&msg, ciaddr, CLIENT_PORT, server, SERVER_PORT);
+ else ret = raw_packet(&msg, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST,
+ SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex);
return ret;
}
@@ -161,22 +160,21 @@
/* Unicasts a DHCP release message */
int send_release(unsigned long server, unsigned long ciaddr)
{
- struct dhcpMessage packet;
+ struct dhcp_message msg;
- init_packet(&packet, DHCPRELEASE);
- packet.xid = random_xid();
- packet.ciaddr = ciaddr;
+ init_packet(&msg, DHCPRELEASE, random_xid());
+ msg.payload.ciaddr = ciaddr;
- add_simple_option(packet.options, DHCP_REQUESTED_IP, ciaddr);
- add_simple_option(packet.options, DHCP_SERVER_ID, server);
+ add_simple_option(&msg, DHCP_REQUESTED_IP, ciaddr);
+ add_simple_option(&msg, DHCP_SERVER_ID, server);
LOG(LOG_DEBUG, "Sending release...");
- return kernel_packet(&packet, ciaddr, CLIENT_PORT, server, SERVER_PORT);
+ return kernel_packet(&msg, ciaddr, CLIENT_PORT, server, SERVER_PORT);
}
/* return -1 on errors that are fatal for the socket, -2 for those that aren't */
-int get_raw_packet(struct dhcpMessage *payload, int fd)
+int get_raw_packet(struct dhcp_payload *payload, int fd)
{
int bytes;
struct udp_dhcp_packet packet;
@@ -216,7 +214,7 @@
/* check IP checksum */
check = packet.ip.check;
packet.ip.check = 0;
- if (check != checksum(&(packet.ip), sizeof(packet.ip))) {
+ if (check != checksum((uint8_t *)&(packet.ip), sizeof(packet.ip))) {
DEBUG(LOG_INFO, "bad IP header checksum, ignoring");
return -1;
}
@@ -232,7 +230,7 @@
packet.ip.saddr = source;
packet.ip.daddr = dest;
packet.ip.tot_len = packet.udp.len; /* cheat on the psuedo-header */
- if (check && check != checksum(&packet, bytes)) {
+ if (check && check != checksum((uint8_t *)&packet, bytes)) {
DEBUG(LOG_ERR, "packet with bad UDP checksum received, ignoring");
return -2;
}
Index: busybox//networking/udhcp/clientpacket.h
===================================================================
RCS file: /data/repo/busybox/networking/udhcp/clientpacket.h,v
retrieving revision 1.1.1.1
retrieving revision 1.3
diff -u -r1.1.1.1 -r1.3
--- busybox//networking/udhcp/clientpacket.h 30 Nov 2004 16:02:32 -0000 1.1.1.1
+++ busybox//networking/udhcp/clientpacket.h 31 Jan 2005 15:07:07 -0000 1.3
@@ -9,6 +9,6 @@
int send_renew(unsigned long xid, unsigned long server, unsigned long ciaddr);
int send_renew(unsigned long xid, unsigned long server, unsigned long ciaddr);
int send_release(unsigned long server, unsigned long ciaddr);
-int get_raw_packet(struct dhcpMessage *payload, int fd);
+int get_raw_packet(struct dhcp_payload *payload, int fd);
#endif
Index: busybox//networking/udhcp/common.c
===================================================================
RCS file: /data/repo/busybox/networking/udhcp/common.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- busybox//networking/udhcp/common.c 1 Dec 2004 21:19:10 -0000 1.3
+++ busybox//networking/udhcp/common.c 31 Jan 2005 15:07:07 -0000 1.4
@@ -64,7 +64,7 @@
#ifdef __uClinux__
LOG(LOG_ERR, "Cannot background in uclinux (yet)");
#else /* __uClinux__ */
- int pid_fd;
+ int pid_fd = 0; /* silence compiler */
/* hold lock during fork. */
if (pidfile) pid_fd = pidfile_acquire(pidfile);
Index: busybox//networking/udhcp/dhcpc.c
===================================================================
RCS file: /data/repo/busybox/networking/udhcp/dhcpc.c,v
retrieving revision 1.1.1.2
retrieving revision 1.3
diff -u -r1.1.1.2 -r1.3
--- busybox//networking/udhcp/dhcpc.c 28 Jan 2005 17:58:06 -0000 1.1.1.2
+++ busybox//networking/udhcp/dhcpc.c 31 Jan 2005 15:07:07 -0000 1.3
@@ -188,7 +188,7 @@
int retval;
struct timeval tv;
int c, len;
- struct dhcpMessage packet;
+ struct dhcp_payload packet;
struct in_addr temp_addr;
long now;
int max_fd;
Index: busybox//networking/udhcp/dhcpd.c
===================================================================
RCS file: /data/repo/busybox/networking/udhcp/dhcpd.c,v
retrieving revision 1.9
retrieving revision 1.11
diff -u -r1.9 -r1.11
--- busybox//networking/udhcp/dhcpd.c 1 Dec 2004 22:17:42 -0000 1.9
+++ busybox//networking/udhcp/dhcpd.c 31 Jan 2005 15:07:07 -0000 1.11
@@ -109,7 +109,7 @@
static int process_packet(int fd)
{
- struct dhcpMessage packet;
+ struct dhcp_payload packet;
struct dhcpOfferedAddr static_lease, *lease;
uint32_t static_lease_ip;
uint8_t *state, *server_id, *requested;
Index: busybox//networking/udhcp/options.c
===================================================================
RCS file: /data/repo/busybox/networking/udhcp/options.c,v
retrieving revision 1.1.1.2
retrieving revision 1.5
diff -u -r1.1.1.2 -r1.5
--- busybox//networking/udhcp/options.c 28 Jan 2005 17:58:06 -0000 1.1.1.2
+++ busybox//networking/udhcp/options.c 31 Jan 2005 15:07:07 -0000 1.5
@@ -61,7 +61,7 @@
/* get an option with bounds checking (warning, not aligned). */
-uint8_t *get_option(struct dhcpMessage *packet, int code)
+uint8_t *get_option(struct dhcp_payload *packet, int code)
{
int i, length;
uint8_t *optionptr;
@@ -116,8 +116,9 @@
/* return the position of the 'end' option (no bounds checking) */
-int end_option(uint8_t *optionptr)
+int end_option(struct dhcp_message *msg)
{
+ uint8_t *optionptr = msg->payload.options;
int i = 0;
while (optionptr[i] != DHCP_END) {
@@ -130,24 +131,28 @@
/* add an option string to the options (an option string contains an option code,
* length, then data) */
-int add_option_string(uint8_t *optionptr, uint8_t *string)
+int add_option_string(struct dhcp_message *msg, uint8_t *string)
{
- int end = end_option(optionptr);
+ uint8_t *optionptr = msg->payload.options;
+ int opt_len, end = end_option(msg);
+ opt_len = string[OPT_LEN] + 2;
+
/* end position + string length + option code/length + end option */
- if (end + string[OPT_LEN] + 2 + 1 >= 308) {
+ if (end + opt_len + 1 >= 308) {
LOG(LOG_ERR, "Option 0x%02x did not fit into the packet!", string[OPT_CODE]);
return 0;
}
DEBUG(LOG_INFO, "adding option 0x%02x", string[OPT_CODE]);
memcpy(optionptr + end, string, string[OPT_LEN] + 2);
optionptr[end + string[OPT_LEN] + 2] = DHCP_END;
- return string[OPT_LEN] + 2;
+ msg->len += opt_len;
+ return opt_len;
}
/* add a one to four byte option to a packet */
-int add_simple_option(uint8_t *optionptr, uint8_t code, uint32_t data)
+int add_simple_option(struct dhcp_message *msg, uint8_t code, uint32_t data)
{
char length = 0;
int i;
@@ -179,7 +184,7 @@
case 4: *u32 = data; break;
}
memcpy(option + 2, &aligned, length);
- return add_option_string(optionptr, option);
+ return add_option_string(msg, option);
}
Index: busybox//networking/udhcp/options.h
===================================================================
RCS file: /data/repo/busybox/networking/udhcp/options.h,v
retrieving revision 1.1.1.1
retrieving revision 1.4
diff -u -r1.1.1.1 -r1.4
--- busybox//networking/udhcp/options.h 30 Nov 2004 16:02:32 -0000 1.1.1.1
+++ busybox//networking/udhcp/options.h 31 Jan 2005 15:07:07 -0000 1.4
@@ -30,10 +30,10 @@
extern struct dhcp_option dhcp_options[];
extern int option_lengths[];
-uint8_t *get_option(struct dhcpMessage *packet, int code);
-int end_option(uint8_t *optionptr);
-int add_option_string(uint8_t *optionptr, uint8_t *string);
-int add_simple_option(uint8_t *optionptr, uint8_t code, uint32_t data);
+uint8_t *get_option(struct dhcp_payload *packet, int code);
+int end_option(struct dhcp_message *msg);
+int add_option_string(struct dhcp_message *msg, uint8_t *string);
+int add_simple_option(struct dhcp_message *msg, uint8_t code, uint32_t data);
struct option_set *find_option(struct option_set *opt_list, char code);
void attach_option(struct option_set **opt_list, struct dhcp_option *option, char *buffer, int length);
Index: busybox//networking/udhcp/packet.c
===================================================================
RCS file: /data/repo/busybox/networking/udhcp/packet.c,v
retrieving revision 1.5
retrieving revision 1.10
diff -u -r1.5 -r1.10
--- busybox//networking/udhcp/packet.c 30 Jan 2005 17:11:33 -0000 1.5
+++ busybox//networking/udhcp/packet.c 31 Jan 2005 15:07:07 -0000 1.10
@@ -1,6 +1,7 @@
#include <unistd.h>
#include <string.h>
#include <netinet/in.h>
+#include <stddef.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <features.h>
@@ -21,30 +22,35 @@
#include "options.h"
#include "common.h"
-void init_header(struct dhcpMessage *packet, char type)
+void init_header(struct dhcp_message *msg, char type)
{
- memset(packet, 0, sizeof(struct dhcpMessage));
+ struct dhcp_payload *p;
+
+ p = &msg->payload;
+ memset(p, 0, sizeof(*p));
switch (type) {
case DHCPDISCOVER:
case DHCPREQUEST:
case DHCPRELEASE:
case DHCPINFORM:
- packet->op = BOOTREQUEST;
+ p->op = BOOTREQUEST;
break;
case DHCPOFFER:
case DHCPACK:
case DHCPNAK:
- packet->op = BOOTREPLY;
+ p->op = BOOTREPLY;
}
- packet->htype = ETH_10MB;
- packet->hlen = ETH_10MB_LEN;
- packet->cookie = htonl(DHCP_MAGIC);
- packet->options[0] = DHCP_END;
- add_simple_option(packet->options, DHCP_MESSAGE_TYPE, type);
+ p->htype = ETH_10MB;
+ p->hlen = ETH_10MB_LEN;
+ p->cookie = htonl(DHCP_MAGIC);
+ p->options[0] = DHCP_END;
+
+ msg->len = offsetof(struct dhcp_payload, options) + 1;
+ add_simple_option(msg, DHCP_MESSAGE_TYPE, type);
}
/* read a packet from socket fd, return -1 on read error, -2 on packet error */
-int get_packet(struct dhcpMessage *packet, int fd)
+int get_packet(struct dhcp_payload *packet, int fd)
{
int bytes;
int i;
@@ -54,10 +60,10 @@
};
char unsigned *vendor;
- memset(packet, 0, sizeof(struct dhcpMessage));
+ memset(packet, 0, sizeof(struct dhcp_payload));
read_again:
- bytes = read(fd, packet, sizeof(struct dhcpMessage));
+ bytes = read(fd, packet, sizeof(struct dhcp_payload));
if (bytes < 0)
switch (errno) {
case EINTR:
@@ -140,13 +146,14 @@
}
/* Construct a ip/udp header for a packet, and specify the source and dest hardware address */
-int raw_packet(struct dhcpMessage *payload, uint32_t source_ip, int source_port,
+int raw_packet(struct dhcp_message *msg, uint32_t source_ip, int source_port,
uint32_t dest_ip, int dest_port, uint8_t *dest_arp, int ifindex)
{
int fd;
int result;
struct sockaddr_ll dest;
struct udp_dhcp_packet packet;
+ unsigned len;
if ((fd = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP))) < 0) {
DEBUG(LOG_ERR, "socket call failed: %m");
@@ -154,18 +161,37 @@
}
memset(&packet, 0, sizeof(packet));
-
+
+ len = sizeof(packet.udp) + msg->len;
packet.ip.protocol = IPPROTO_UDP;
packet.ip.saddr = source_ip;
packet.ip.daddr = dest_ip;
packet.udp.source = htons(source_port);
packet.udp.dest = htons(dest_port);
- packet.udp.len = htons(sizeof(packet.udp) + sizeof(*payload)); /* cheat on the psuedo-header */
+ packet.udp.len = htons(len);
packet.ip.tot_len = packet.udp.len;
- memcpy(&(packet.data), payload, sizeof(*payload));
- packet.udp.check = checksum((uint8_t *)&packet, sizeof(packet));
+ memcpy(&(packet.data), &msg->payload, msg->len);
+
+ /*
+ HACK ALERT
+
+ The UDP checksum is defined to be calculated over
+ the UDP header and data, conceptually prefixed
+ by a 'pseudo header' that contains the (IP) source
+ and destination addresses, the (IP) protocol
+ and the total length of the UDP 'packet'.
+
+ Here, a real IP header is used in place of the
+ pseudo header, which has all of its fields except
+ the ones which are part of the pseudo-header set
+ to zero. The sum needs to be calculated over the
+ total length of the IP header, because the field
+ layout of that and the pseudo header is different.
+ */
+ len += sizeof(packet.ip);
+ packet.udp.check = checksum((uint8_t *)&packet, len);
- packet.ip.tot_len = htons(sizeof(packet));
+ packet.ip.tot_len = htons(len);
packet.ip.ihl = sizeof(packet.ip) >> 2;
packet.ip.version = IPVERSION;
packet.ip.ttl = IPDEFTTL;
@@ -176,14 +202,14 @@
dest.sll_ifindex = ifindex;
dest.sll_halen = 6;
memcpy(dest.sll_addr, dest_arp, 6);
- result = do_sendto(fd, &packet, sizeof(packet), (struct sockaddr *)&dest,
+ result = do_sendto(fd, &packet, len, (struct sockaddr *)&dest,
sizeof(dest));
close(fd);
return result;
}
/* Let the kernel do all the work for packet generation */
-int kernel_packet(struct dhcpMessage *payload, uint32_t source_ip, int source_port,
+int kernel_packet(struct dhcp_message *msg, uint32_t source_ip, int source_port,
uint32_t dest_ip, int dest_port)
{
int n = 1;
@@ -204,7 +230,7 @@
sa.sin_family = AF_INET;
sa.sin_port = htons(dest_port);
sa.sin_addr.s_addr = dest_ip;
- result = do_sendto(fd, payload, sizeof(*payload), (struct sockaddr *)&sa,
+ result = do_sendto(fd, &msg->payload, msg->len, (struct sockaddr *)&sa,
sizeof(sa));
close(fd);
return result;
Index: busybox//networking/udhcp/packet.h
===================================================================
RCS file: /data/repo/busybox/networking/udhcp/packet.h,v
retrieving revision 1.2
retrieving revision 1.5
diff -u -r1.2 -r1.5
--- busybox//networking/udhcp/packet.h 30 Jan 2005 16:36:41 -0000 1.2
+++ busybox//networking/udhcp/packet.h 31 Jan 2005 15:07:07 -0000 1.5
@@ -4,7 +4,7 @@
#include <netinet/udp.h>
#include <netinet/ip.h>
-struct dhcpMessage {
+struct dhcp_payload {
uint8_t op;
uint8_t htype;
uint8_t hlen;
@@ -23,19 +23,23 @@
uint8_t options[308]; /* 312 - cookie */
};
+struct dhcp_message {
+ struct dhcp_payload payload;
+ size_t len;
+};
+
struct udp_dhcp_packet {
struct iphdr ip;
struct udphdr udp;
- struct dhcpMessage data;
+ struct dhcp_payload data;
};
-void init_header(struct dhcpMessage *packet, char type);
-int get_packet(struct dhcpMessage *packet, int fd);
+void init_header(struct dhcp_message *msg, char type);
+int get_packet(struct dhcp_payload *packet, int fd);
uint16_t checksum(uint8_t *addr, unsigned count);
-int raw_packet(struct dhcpMessage *payload, uint32_t source_ip, int source_port,
- uint32_t dest_ip, int dest_port, uint8_t *dest_arp, int ifindex);
-int kernel_packet(struct dhcpMessage *payload, uint32_t source_ip, int source_port,
- uint32_t dest_ip, int dest_port);
-
+int raw_packet(struct dhcp_message *msg, uint32_t source_ip, int source_port,
+ uint32_t dest_ip, int dest_port, uint8_t *dest_arp, int ifindex);
+int kernel_packet(struct dhcp_message *msg, uint32_t source_ip, int source_port,
+ uint32_t dest_ip, int dest_port);
#endif
Index: busybox//networking/udhcp/script.c
===================================================================
RCS file: /data/repo/busybox/networking/udhcp/script.c,v
retrieving revision 1.1.1.1
retrieving revision 1.3
diff -u -r1.1.1.1 -r1.3
--- busybox//networking/udhcp/script.c 30 Nov 2004 16:02:32 -0000 1.1.1.1
+++ busybox//networking/udhcp/script.c 31 Jan 2005 15:07:07 -0000 1.3
@@ -133,7 +133,7 @@
/* put all the parameters into an environment */
-static char **fill_envp(struct dhcpMessage *packet)
+static char **fill_envp(struct dhcp_payload *packet)
{
int num_options = 0;
int i, j;
@@ -203,7 +203,7 @@
/* Call a script with a par file and env vars */
-void run_script(struct dhcpMessage *packet, const char *name)
+void run_script(struct dhcp_payload *packet, const char *name)
{
int pid;
char **envp, **curr;
Index: busybox//networking/udhcp/script.h
===================================================================
RCS file: /data/repo/busybox/networking/udhcp/script.h,v
retrieving revision 1.1.1.1
retrieving revision 1.3
diff -u -r1.1.1.1 -r1.3
--- busybox//networking/udhcp/script.h 30 Nov 2004 16:02:32 -0000 1.1.1.1
+++ busybox//networking/udhcp/script.h 31 Jan 2005 15:07:07 -0000 1.3
@@ -1,6 +1,6 @@
#ifndef _SCRIPT_H
#define _SCRIPT_H
-void run_script(struct dhcpMessage *packet, const char *name);
+void run_script(struct dhcp_payload *packet, const char *name);
#endif
Index: busybox//networking/udhcp/serverpacket.c
===================================================================
RCS file: /data/repo/busybox/networking/udhcp/serverpacket.c,v
retrieving revision 1.1.1.1
retrieving revision 1.5
diff -u -r1.1.1.1 -r1.5
--- busybox//networking/udhcp/serverpacket.c 30 Nov 2004 16:02:32 -0000 1.1.1.1
+++ busybox//networking/udhcp/serverpacket.c 31 Jan 2005 15:07:07 -0000 1.5
@@ -32,17 +32,17 @@
#include "static_leases.h"
/* send a packet to giaddr using the kernel ip stack */
-static int send_packet_to_relay(struct dhcpMessage *payload)
+static int send_packet_to_relay(struct dhcp_message *msg)
{
DEBUG(LOG_INFO, "Forwarding packet to relay");
- return kernel_packet(payload, server_config.server, SERVER_PORT,
- payload->giaddr, SERVER_PORT);
+ return kernel_packet(msg, server_config.server, SERVER_PORT,
+ msg->payload.giaddr, SERVER_PORT);
}
/* send a packet to a specific arp address and ip address by creating our own ip packet */
-static int send_packet_to_client(struct dhcpMessage *payload, int force_broadcast)
+static int send_packet_to_client(struct dhcp_message *msg, int force_broadcast)
{
uint8_t *chaddr;
uint32_t ciaddr;
@@ -51,50 +51,50 @@
DEBUG(LOG_INFO, "broadcasting packet to client (NAK)");
ciaddr = INADDR_BROADCAST;
chaddr = MAC_BCAST_ADDR;
- } else if (payload->ciaddr) {
+ } else if (msg->payload.ciaddr) {
DEBUG(LOG_INFO, "unicasting packet to client ciaddr");
- ciaddr = payload->ciaddr;
- chaddr = payload->chaddr;
- } else if (ntohs(payload->flags) & BROADCAST_FLAG) {
+ ciaddr = msg->payload.ciaddr;
+ chaddr = msg->payload.chaddr;
+ } else if (ntohs(msg->payload.flags) & BROADCAST_FLAG) {
DEBUG(LOG_INFO, "broadcasting packet to client (requested)");
ciaddr = INADDR_BROADCAST;
chaddr = MAC_BCAST_ADDR;
} else {
DEBUG(LOG_INFO, "unicasting packet to client yiaddr");
- ciaddr = payload->yiaddr;
- chaddr = payload->chaddr;
+ ciaddr = msg->payload.yiaddr;
+ chaddr = msg->payload.chaddr;
}
- return raw_packet(payload, server_config.server, SERVER_PORT,
- ciaddr, CLIENT_PORT, chaddr, server_config.ifindex);
+ return raw_packet(msg, server_config.server, SERVER_PORT,
+ ciaddr, CLIENT_PORT, chaddr, server_config.ifindex);
}
/* send a dhcp packet, if force broadcast is set, the packet will be broadcast to the client */
-static int send_packet(struct dhcpMessage *payload, int force_broadcast)
+static int send_packet(struct dhcp_message *msg, int force_broadcast)
{
int ret;
- if (payload->giaddr)
- ret = send_packet_to_relay(payload);
- else ret = send_packet_to_client(payload, force_broadcast);
+ if (msg->payload.giaddr)
+ ret = send_packet_to_relay(msg);
+ else ret = send_packet_to_client(msg, force_broadcast);
return ret;
}
-static void init_packet(struct dhcpMessage *packet, struct dhcpMessage *oldpacket, char type)
+static void init_packet(struct dhcp_message *msg, struct dhcp_payload *oldpacket, char type)
{
- init_header(packet, type);
- packet->xid = oldpacket->xid;
- memcpy(packet->chaddr, oldpacket->chaddr, 16);
- packet->flags = oldpacket->flags;
- packet->giaddr = oldpacket->giaddr;
- packet->ciaddr = oldpacket->ciaddr;
- add_simple_option(packet->options, DHCP_SERVER_ID, server_config.server);
+ init_header(msg, type);
+ msg->payload.xid = oldpacket->xid;
+ memcpy(msg->payload.chaddr, oldpacket->chaddr, 16);
+ msg->payload.flags = oldpacket->flags;
+ msg->payload.giaddr = oldpacket->giaddr;
+ msg->payload.ciaddr = oldpacket->ciaddr;
+ add_simple_option(msg, DHCP_SERVER_ID, server_config.server);
}
/* add in the bootp options */
-static void add_bootp_options(struct dhcpMessage *packet)
+static void add_bootp_options(struct dhcp_payload *packet)
{
packet->siaddr = server_config.siaddr;
if (server_config.sname)
@@ -105,9 +105,9 @@
/* send a DHCP OFFER to a DHCP DISCOVER */
-int sendOffer(struct dhcpMessage *oldpacket)
+int sendOffer(struct dhcp_payload *oldpacket)
{
- struct dhcpMessage packet;
+ struct dhcp_message msg;
struct dhcpOfferedAddr *lease = NULL;
uint32_t req_align, lease_time_align = server_config.lease;
uint8_t *req, *lease_time;
@@ -116,7 +116,7 @@
uint32_t static_lease_ip;
- init_packet(&packet, oldpacket, DHCPOFFER);
+ init_packet(&msg, oldpacket, DHCPOFFER);
static_lease_ip = getIpByMac(server_config.static_leases, oldpacket->chaddr);
@@ -127,7 +127,7 @@
if ((lease = find_lease_by_chaddr(oldpacket->chaddr))) {
if (!lease_expired(lease))
lease_time_align = lease->expires - time(0);
- packet.yiaddr = lease->yiaddr;
+ msg.payload.yiaddr = lease->yiaddr;
/* Or the client has a requested ip */
} else if ((req = get_option(oldpacket, DHCP_REQUESTED_IP)) &&
@@ -145,23 +145,23 @@
/* 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? */
+ msg.payload.yiaddr = req_align; /* FIXME: oh my, is there a host using this IP? */
/* otherwise, find a free IP */
} else {
/* Is it a static lease? (No, because find_address skips static lease) */
- packet.yiaddr = find_address(0);
+ msg.payload.yiaddr = find_address(0);
/* try for an expired lease */
- if (!packet.yiaddr) packet.yiaddr = find_address(1);
+ if (!msg.payload.yiaddr) msg.payload.yiaddr = find_address(1);
}
- if(!packet.yiaddr) {
+ if(!msg.payload.yiaddr) {
LOG(LOG_WARNING, "no IP addresses to give -- OFFER abandoned");
return -1;
}
- if (!add_lease(packet.chaddr, packet.yiaddr, server_config.offer_time)) {
+ if (!add_lease(msg.payload.chaddr, msg.payload.yiaddr, server_config.offer_time)) {
LOG(LOG_WARNING, "lease pool is full -- OFFER abandoned");
return -1;
}
@@ -181,47 +181,47 @@
else
{
/* It is a static lease... use it */
- packet.yiaddr = static_lease_ip;
+ msg.payload.yiaddr = static_lease_ip;
}
- add_simple_option(packet.options, DHCP_LEASE_TIME, htonl(lease_time_align));
+ add_simple_option(&msg, DHCP_LEASE_TIME, htonl(lease_time_align));
curr = server_config.options;
while (curr) {
if (curr->data[OPT_CODE] != DHCP_LEASE_TIME)
- add_option_string(packet.options, curr->data);
+ add_option_string(&msg, curr->data);
curr = curr->next;
}
- add_bootp_options(&packet);
+ add_bootp_options(&msg.payload);
- addr.s_addr = packet.yiaddr;
+ addr.s_addr = msg.payload.yiaddr;
LOG(LOG_INFO, "sending OFFER of %s", inet_ntoa(addr));
- return send_packet(&packet, 0);
+ return send_packet(&msg, 0);
}
-int sendNAK(struct dhcpMessage *oldpacket)
+int sendNAK(struct dhcp_payload *oldpacket)
{
- struct dhcpMessage packet;
+ struct dhcp_message msg;
- init_packet(&packet, oldpacket, DHCPNAK);
+ init_packet(&msg, oldpacket, DHCPNAK);
DEBUG(LOG_INFO, "sending NAK");
- return send_packet(&packet, 1);
+ return send_packet(&msg, 1);
}
-int sendACK(struct dhcpMessage *oldpacket, uint32_t yiaddr)
+int sendACK(struct dhcp_payload *oldpacket, uint32_t yiaddr)
{
- struct dhcpMessage packet;
+ struct dhcp_message msg;
struct option_set *curr;
uint8_t *lease_time;
uint32_t lease_time_align = server_config.lease;
struct in_addr addr;
- init_packet(&packet, oldpacket, DHCPACK);
- packet.yiaddr = yiaddr;
+ init_packet(&msg, oldpacket, DHCPACK);
+ msg.payload.yiaddr = yiaddr;
if ((lease_time = get_option(oldpacket, DHCP_LEASE_TIME))) {
memcpy(&lease_time_align, lease_time, 4);
@@ -232,44 +232,44 @@
lease_time_align = server_config.lease;
}
- add_simple_option(packet.options, DHCP_LEASE_TIME, htonl(lease_time_align));
+ add_simple_option(&msg, DHCP_LEASE_TIME, htonl(lease_time_align));
curr = server_config.options;
while (curr) {
if (curr->data[OPT_CODE] != DHCP_LEASE_TIME)
- add_option_string(packet.options, curr->data);
+ add_option_string(&msg, curr->data);
curr = curr->next;
}
- add_bootp_options(&packet);
+ add_bootp_options(&msg.payload);
- addr.s_addr = packet.yiaddr;
+ addr.s_addr = msg.payload.yiaddr;
LOG(LOG_INFO, "sending ACK to %s", inet_ntoa(addr));
- if (send_packet(&packet, 0) < 0)
+ if (send_packet(&msg, 0) < 0)
return -1;
- add_lease(packet.chaddr, packet.yiaddr, lease_time_align);
+ add_lease(msg.payload.chaddr, msg.payload.yiaddr, lease_time_align);
return 0;
}
-int send_inform(struct dhcpMessage *oldpacket)
+int send_inform(struct dhcp_payload *oldpacket)
{
- struct dhcpMessage packet;
+ struct dhcp_message msg;
struct option_set *curr;
- init_packet(&packet, oldpacket, DHCPACK);
+ init_packet(&msg, oldpacket, DHCPACK);
curr = server_config.options;
while (curr) {
if (curr->data[OPT_CODE] != DHCP_LEASE_TIME)
- add_option_string(packet.options, curr->data);
+ add_option_string(&msg, curr->data);
curr = curr->next;
}
- add_bootp_options(&packet);
+ add_bootp_options(&msg.payload);
- return send_packet(&packet, 0);
+ return send_packet(&msg, 0);
}
Index: busybox//networking/udhcp/serverpacket.h
===================================================================
RCS file: /data/repo/busybox/networking/udhcp/serverpacket.h,v
retrieving revision 1.1.1.1
retrieving revision 1.3
diff -u -r1.1.1.1 -r1.3
--- busybox//networking/udhcp/serverpacket.h 30 Nov 2004 16:02:32 -0000 1.1.1.1
+++ busybox//networking/udhcp/serverpacket.h 31 Jan 2005 15:07:07 -0000 1.3
@@ -3,10 +3,10 @@
#include "packet.h"
-int sendOffer(struct dhcpMessage *oldpacket);
-int sendNAK(struct dhcpMessage *oldpacket);
-int sendACK(struct dhcpMessage *oldpacket, uint32_t yiaddr);
-int send_inform(struct dhcpMessage *oldpacket);
+int sendOffer(struct dhcp_payload *oldpacket);
+int sendNAK(struct dhcp_payload *oldpacket);
+int sendACK(struct dhcp_payload *oldpacket, uint32_t yiaddr);
+int send_inform(struct dhcp_payload *oldpacket);
#endif
More information about the busybox
mailing list