diff options
-rw-r--r-- | bootp.c | 5 | ||||
-rw-r--r-- | common/options.c | 43 | ||||
-rw-r--r-- | dhcp.c | 19 | ||||
-rw-r--r-- | options.c | 43 | ||||
-rw-r--r-- | server/bootp.c | 5 | ||||
-rw-r--r-- | server/dhcp.c | 19 |
6 files changed, 72 insertions, 62 deletions
@@ -42,7 +42,7 @@ #ifndef lint static char copyright[] = -"$Id: bootp.c,v 1.21 1996/12/31 02:00:33 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium. All rights reserved.\n"; +"$Id: bootp.c,v 1.22 1997/02/18 14:28:54 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium. All rights reserved.\n"; #endif /* not lint */ #include "dhcpd.h" @@ -193,7 +193,8 @@ void bootp (packet) /* Pack the options into the buffer. Unlike DHCP, we can't pack options into the filename and server name buffers. */ - cons_options (packet, &outgoing, options, 0, 0); + outgoing.packet_length = + cons_options (packet, outgoing.raw, options, 0, 0); if (outgoing.packet_length < BOOTP_MIN_LEN) outgoing.packet_length = BOOTP_MIN_LEN; diff --git a/common/options.c b/common/options.c index 53dd0224..4f73c900 100644 --- a/common/options.c +++ b/common/options.c @@ -42,7 +42,7 @@ #ifndef lint static char copyright[] = -"$Id: options.c,v 1.19 1996/09/11 05:52:18 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium. All rights reserved.\n"; +"$Id: options.c,v 1.20 1997/02/18 14:28:54 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium. All rights reserved.\n"; #endif /* not lint */ #define DHCP_OPTION_DATA @@ -155,9 +155,9 @@ void parse_option_buffer (packet, buffer, length) three seperate buffers if needed. This allows us to cons up a set of vendor options using the same routine. */ -void cons_options (inpacket, outpacket, options, overload, terminate) +int cons_options (inpacket, outpacket, options, overload, terminate) struct packet *inpacket; - struct packet *outpacket; + struct dhcp_packet *outpacket; struct tree_cache **options; int overload; /* Overload flags that may be set. */ int terminate; @@ -168,6 +168,7 @@ void cons_options (inpacket, outpacket, options, overload, terminate) int main_buffer_size; int mainbufix, bufix; int option_size; + int length; /* If the client has provided a maximum DHCP message size, use that. Otherwise, we use the default MTU size (576 bytes). */ @@ -225,7 +226,7 @@ void cons_options (inpacket, outpacket, options, overload, terminate) terminate); /* Put the cookie up front... */ - memcpy (outpacket -> raw -> options, DHCP_OPTIONS_COOKIE, 4); + memcpy (outpacket -> options, DHCP_OPTIONS_COOKIE, 4); mainbufix = 4; /* If we're going to have to overload, store the overload @@ -233,57 +234,57 @@ void cons_options (inpacket, outpacket, options, overload, terminate) whole thing in the packet's option buffer and leave it at that. */ if (option_size <= main_buffer_size - mainbufix) { - memcpy (&outpacket -> raw -> options [mainbufix], + memcpy (&outpacket -> options [mainbufix], buffer, option_size); mainbufix += option_size; if (mainbufix < main_buffer_size) - outpacket -> raw -> options [mainbufix++] + outpacket -> options [mainbufix++] = DHO_END; - outpacket -> packet_length = DHCP_FIXED_NON_UDP + mainbufix; + length = DHCP_FIXED_NON_UDP + mainbufix; } else { - outpacket -> raw -> options [mainbufix++] = + outpacket -> options [mainbufix++] = DHO_DHCP_OPTION_OVERLOAD; - outpacket -> raw -> options [mainbufix++] = 1; + outpacket -> options [mainbufix++] = 1; if (option_size > main_buffer_size - mainbufix + DHCP_FILE_LEN) - outpacket -> raw -> options [mainbufix++] = 3; + outpacket -> options [mainbufix++] = 3; else - outpacket -> raw -> options [mainbufix++] = 1; + outpacket -> options [mainbufix++] = 1; - memcpy (&outpacket -> raw -> options [mainbufix], + memcpy (&outpacket -> options [mainbufix], buffer, main_buffer_size - mainbufix); bufix = main_buffer_size - mainbufix; - outpacket -> packet_length = DHCP_FIXED_NON_UDP + mainbufix; + length = DHCP_FIXED_NON_UDP + mainbufix; if (overload & 1) { if (option_size - bufix <= DHCP_FILE_LEN) { - memcpy (outpacket -> raw -> file, + memcpy (outpacket -> file, &buffer [bufix], option_size - bufix); mainbufix = option_size - bufix; if (mainbufix < DHCP_FILE_LEN) - outpacket -> raw -> file [mainbufix++] + outpacket -> file [mainbufix++] = DHO_END; while (mainbufix < DHCP_FILE_LEN) - outpacket -> raw -> file [mainbufix++] + outpacket -> file [mainbufix++] = DHO_PAD; } else { - memcpy (outpacket -> raw -> file, + memcpy (outpacket -> file, &buffer [bufix], DHCP_FILE_LEN); bufix += DHCP_FILE_LEN; } } if ((overload & 2) && option_size < bufix) { - memcpy (outpacket -> raw -> sname, + memcpy (outpacket -> sname, &buffer [bufix], option_size - bufix); mainbufix = option_size - bufix; if (mainbufix < DHCP_SNAME_LEN) - outpacket -> raw -> file [mainbufix++] + outpacket -> file [mainbufix++] = DHO_END; while (mainbufix < DHCP_SNAME_LEN) - outpacket -> raw -> file [mainbufix++] + outpacket -> file [mainbufix++] = DHO_PAD; } } - return; + return length; } /* Store all the requested options into the requested buffer. */ @@ -42,7 +42,7 @@ #ifndef lint static char copyright[] = -"$Id: dhcp.c,v 1.36 1997/01/03 11:39:27 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium. All rights reserved.\n"; +"$Id: dhcp.c,v 1.37 1997/02/18 14:28:53 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium. All rights reserved.\n"; #endif /* not lint */ #include "dhcpd.h" @@ -362,7 +362,8 @@ void nak_lease (packet, cip) (unsigned char *)0; /* Set up the option buffer... */ - cons_options (packet, &outgoing, options, 0, 0); + outgoing.packet_length = + cons_options (packet, outgoing.raw, options, 0, 0); /* memset (&raw.ciaddr, 0, sizeof raw.ciaddr);*/ memcpy (&raw.siaddr, server_identifier.iabuf, 4); @@ -416,7 +417,7 @@ void nak_lease (packet, cip) Otherwise, broadcast it on the local network. */ if (raw.giaddr.s_addr) { to.sin_addr = raw.giaddr; - to.sin_port = server_port; + to.sin_port = local_port; if (outgoing.packet_length < BOOTP_MIN_LEN) outgoing.packet_length = BOOTP_MIN_LEN; @@ -812,9 +813,11 @@ void ack_lease (packet, lease, offer, when) if (packet -> options [DHO_HOST_NAME].data && packet -> options [DHO_HOST_NAME].data [packet -> options [DHO_HOST_NAME].len - 1] == '\0') - cons_options (packet, &outgoing, options, bufs, 1); + outgoing.packet_length = + cons_options (packet, outgoing.raw, options, bufs, 1); else - cons_options (packet, &outgoing, options, bufs, 0); + outgoing.packet_length = + cons_options (packet, outgoing.raw, options, bufs, 0); if (!offer && outgoing.packet_length < BOOTP_MIN_LEN) outgoing.packet_length = BOOTP_MIN_LEN; @@ -881,7 +884,7 @@ void ack_lease (packet, lease, offer, when) /* If this was gatewayed, send it back to the gateway... */ if (raw.giaddr.s_addr) { to.sin_addr = raw.giaddr; - to.sin_port = server_port; + to.sin_port = local_port; if (outgoing.packet_length < BOOTP_MIN_LEN) outgoing.packet_length = BOOTP_MIN_LEN; @@ -901,7 +904,7 @@ void ack_lease (packet, lease, offer, when) } else if (raw.ciaddr.s_addr && offer == DHCPACK && !(raw.flags & htons (BOOTP_BROADCAST))) { to.sin_addr = packet -> raw -> ciaddr; - to.sin_port = htons (ntohs (server_port) + 1); /* XXX */ + to.sin_port = remote_port; /* XXX */ #ifdef USE_FALLBACK result = send_fallback (&fallback_interface, @@ -915,7 +918,7 @@ void ack_lease (packet, lease, offer, when) /* Otherwise, broadcast it on the local network. */ } else { to.sin_addr.s_addr = htonl (INADDR_BROADCAST); - to.sin_port = htons (ntohs (server_port) + 1); /* XXX */ + to.sin_port = remote_port; /* XXX */ } @@ -42,7 +42,7 @@ #ifndef lint static char copyright[] = -"$Id: options.c,v 1.19 1996/09/11 05:52:18 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium. All rights reserved.\n"; +"$Id: options.c,v 1.20 1997/02/18 14:28:54 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium. All rights reserved.\n"; #endif /* not lint */ #define DHCP_OPTION_DATA @@ -155,9 +155,9 @@ void parse_option_buffer (packet, buffer, length) three seperate buffers if needed. This allows us to cons up a set of vendor options using the same routine. */ -void cons_options (inpacket, outpacket, options, overload, terminate) +int cons_options (inpacket, outpacket, options, overload, terminate) struct packet *inpacket; - struct packet *outpacket; + struct dhcp_packet *outpacket; struct tree_cache **options; int overload; /* Overload flags that may be set. */ int terminate; @@ -168,6 +168,7 @@ void cons_options (inpacket, outpacket, options, overload, terminate) int main_buffer_size; int mainbufix, bufix; int option_size; + int length; /* If the client has provided a maximum DHCP message size, use that. Otherwise, we use the default MTU size (576 bytes). */ @@ -225,7 +226,7 @@ void cons_options (inpacket, outpacket, options, overload, terminate) terminate); /* Put the cookie up front... */ - memcpy (outpacket -> raw -> options, DHCP_OPTIONS_COOKIE, 4); + memcpy (outpacket -> options, DHCP_OPTIONS_COOKIE, 4); mainbufix = 4; /* If we're going to have to overload, store the overload @@ -233,57 +234,57 @@ void cons_options (inpacket, outpacket, options, overload, terminate) whole thing in the packet's option buffer and leave it at that. */ if (option_size <= main_buffer_size - mainbufix) { - memcpy (&outpacket -> raw -> options [mainbufix], + memcpy (&outpacket -> options [mainbufix], buffer, option_size); mainbufix += option_size; if (mainbufix < main_buffer_size) - outpacket -> raw -> options [mainbufix++] + outpacket -> options [mainbufix++] = DHO_END; - outpacket -> packet_length = DHCP_FIXED_NON_UDP + mainbufix; + length = DHCP_FIXED_NON_UDP + mainbufix; } else { - outpacket -> raw -> options [mainbufix++] = + outpacket -> options [mainbufix++] = DHO_DHCP_OPTION_OVERLOAD; - outpacket -> raw -> options [mainbufix++] = 1; + outpacket -> options [mainbufix++] = 1; if (option_size > main_buffer_size - mainbufix + DHCP_FILE_LEN) - outpacket -> raw -> options [mainbufix++] = 3; + outpacket -> options [mainbufix++] = 3; else - outpacket -> raw -> options [mainbufix++] = 1; + outpacket -> options [mainbufix++] = 1; - memcpy (&outpacket -> raw -> options [mainbufix], + memcpy (&outpacket -> options [mainbufix], buffer, main_buffer_size - mainbufix); bufix = main_buffer_size - mainbufix; - outpacket -> packet_length = DHCP_FIXED_NON_UDP + mainbufix; + length = DHCP_FIXED_NON_UDP + mainbufix; if (overload & 1) { if (option_size - bufix <= DHCP_FILE_LEN) { - memcpy (outpacket -> raw -> file, + memcpy (outpacket -> file, &buffer [bufix], option_size - bufix); mainbufix = option_size - bufix; if (mainbufix < DHCP_FILE_LEN) - outpacket -> raw -> file [mainbufix++] + outpacket -> file [mainbufix++] = DHO_END; while (mainbufix < DHCP_FILE_LEN) - outpacket -> raw -> file [mainbufix++] + outpacket -> file [mainbufix++] = DHO_PAD; } else { - memcpy (outpacket -> raw -> file, + memcpy (outpacket -> file, &buffer [bufix], DHCP_FILE_LEN); bufix += DHCP_FILE_LEN; } } if ((overload & 2) && option_size < bufix) { - memcpy (outpacket -> raw -> sname, + memcpy (outpacket -> sname, &buffer [bufix], option_size - bufix); mainbufix = option_size - bufix; if (mainbufix < DHCP_SNAME_LEN) - outpacket -> raw -> file [mainbufix++] + outpacket -> file [mainbufix++] = DHO_END; while (mainbufix < DHCP_SNAME_LEN) - outpacket -> raw -> file [mainbufix++] + outpacket -> file [mainbufix++] = DHO_PAD; } } - return; + return length; } /* Store all the requested options into the requested buffer. */ diff --git a/server/bootp.c b/server/bootp.c index d2855705..c98c45df 100644 --- a/server/bootp.c +++ b/server/bootp.c @@ -42,7 +42,7 @@ #ifndef lint static char copyright[] = -"$Id: bootp.c,v 1.21 1996/12/31 02:00:33 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium. All rights reserved.\n"; +"$Id: bootp.c,v 1.22 1997/02/18 14:28:54 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium. All rights reserved.\n"; #endif /* not lint */ #include "dhcpd.h" @@ -193,7 +193,8 @@ void bootp (packet) /* Pack the options into the buffer. Unlike DHCP, we can't pack options into the filename and server name buffers. */ - cons_options (packet, &outgoing, options, 0, 0); + outgoing.packet_length = + cons_options (packet, outgoing.raw, options, 0, 0); if (outgoing.packet_length < BOOTP_MIN_LEN) outgoing.packet_length = BOOTP_MIN_LEN; diff --git a/server/dhcp.c b/server/dhcp.c index 39e2969d..3be7e5f9 100644 --- a/server/dhcp.c +++ b/server/dhcp.c @@ -42,7 +42,7 @@ #ifndef lint static char copyright[] = -"$Id: dhcp.c,v 1.36 1997/01/03 11:39:27 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium. All rights reserved.\n"; +"$Id: dhcp.c,v 1.37 1997/02/18 14:28:53 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium. All rights reserved.\n"; #endif /* not lint */ #include "dhcpd.h" @@ -362,7 +362,8 @@ void nak_lease (packet, cip) (unsigned char *)0; /* Set up the option buffer... */ - cons_options (packet, &outgoing, options, 0, 0); + outgoing.packet_length = + cons_options (packet, outgoing.raw, options, 0, 0); /* memset (&raw.ciaddr, 0, sizeof raw.ciaddr);*/ memcpy (&raw.siaddr, server_identifier.iabuf, 4); @@ -416,7 +417,7 @@ void nak_lease (packet, cip) Otherwise, broadcast it on the local network. */ if (raw.giaddr.s_addr) { to.sin_addr = raw.giaddr; - to.sin_port = server_port; + to.sin_port = local_port; if (outgoing.packet_length < BOOTP_MIN_LEN) outgoing.packet_length = BOOTP_MIN_LEN; @@ -812,9 +813,11 @@ void ack_lease (packet, lease, offer, when) if (packet -> options [DHO_HOST_NAME].data && packet -> options [DHO_HOST_NAME].data [packet -> options [DHO_HOST_NAME].len - 1] == '\0') - cons_options (packet, &outgoing, options, bufs, 1); + outgoing.packet_length = + cons_options (packet, outgoing.raw, options, bufs, 1); else - cons_options (packet, &outgoing, options, bufs, 0); + outgoing.packet_length = + cons_options (packet, outgoing.raw, options, bufs, 0); if (!offer && outgoing.packet_length < BOOTP_MIN_LEN) outgoing.packet_length = BOOTP_MIN_LEN; @@ -881,7 +884,7 @@ void ack_lease (packet, lease, offer, when) /* If this was gatewayed, send it back to the gateway... */ if (raw.giaddr.s_addr) { to.sin_addr = raw.giaddr; - to.sin_port = server_port; + to.sin_port = local_port; if (outgoing.packet_length < BOOTP_MIN_LEN) outgoing.packet_length = BOOTP_MIN_LEN; @@ -901,7 +904,7 @@ void ack_lease (packet, lease, offer, when) } else if (raw.ciaddr.s_addr && offer == DHCPACK && !(raw.flags & htons (BOOTP_BROADCAST))) { to.sin_addr = packet -> raw -> ciaddr; - to.sin_port = htons (ntohs (server_port) + 1); /* XXX */ + to.sin_port = remote_port; /* XXX */ #ifdef USE_FALLBACK result = send_fallback (&fallback_interface, @@ -915,7 +918,7 @@ void ack_lease (packet, lease, offer, when) /* Otherwise, broadcast it on the local network. */ } else { to.sin_addr.s_addr = htonl (INADDR_BROADCAST); - to.sin_port = htons (ntohs (server_port) + 1); /* XXX */ + to.sin_port = remote_port; /* XXX */ } |