Bladeren bron

[dhcp] Append new DHCP options versus prepend

Change the behaviour for adding DHCP options into a DHCP packet so
that we now append options, rather than insert them in front of
whatever options might already be present.

Apparently, the DHCP relay logic on a Nortel 470-48T layer 2 switch
cares about the order of DHCP options.  If we build a DHCP packet
pre-populated with some options, their order will now be preserved,
except for encapsulated options.

Signed-off-by: Marty Connor <mdc@etherboot.org>
tags/v1.0.0-rc1
Shao Miller 14 jaren geleden
bovenliggende
commit
cf5e79adc9
1 gewijzigde bestanden met toevoegingen van 15 en 4 verwijderingen
  1. 15
    4
      src/net/dhcpopts.c

+ 15
- 4
src/net/dhcpopts.c Bestand weergeven

103
  * DHCP option block.  Encapsulated options may be searched for by
103
  * DHCP option block.  Encapsulated options may be searched for by
104
  * using DHCP_ENCAP_OPT() to construct the tag value.
104
  * using DHCP_ENCAP_OPT() to construct the tag value.
105
  *
105
  *
106
- * If the option is encapsulated, and @c encapsulator is non-NULL, it
106
+ * If the option is encapsulated, and @c encap_offset is non-NULL, it
107
  * will be filled in with the offset of the encapsulating option.
107
  * will be filled in with the offset of the encapsulating option.
108
  *
108
  *
109
  * This routine is designed to be paranoid.  It does not assume that
109
  * This routine is designed to be paranoid.  It does not assume that
136
 		if ( remaining < 0 )
136
 		if ( remaining < 0 )
137
 			break;
137
 			break;
138
 		/* Check for explicit end marker */
138
 		/* Check for explicit end marker */
139
-		if ( option->tag == DHCP_END )
140
-			break;
139
+		if ( option->tag == DHCP_END ) {
140
+			if ( tag == DHCP_END )
141
+				/* Special case where the caller is interested
142
+				 * in whether we have this marker or not.
143
+				 */
144
+				return offset;
145
+			else
146
+				break;
147
+		}
141
 		/* Check for matching tag */
148
 		/* Check for matching tag */
142
 		if ( option->tag == tag ) {
149
 		if ( option->tag == tag ) {
143
 			DBGC ( options, "DHCPOPT %p found %s (length %d)\n",
150
 			DBGC ( options, "DHCPOPT %p found %s (length %d)\n",
256
 	static const uint8_t empty_encapsulator[] = { DHCP_END };
263
 	static const uint8_t empty_encapsulator[] = { DHCP_END };
257
 	int offset;
264
 	int offset;
258
 	int encap_offset = -1;
265
 	int encap_offset = -1;
259
-	int creation_offset = 0;
266
+	int creation_offset;
260
 	struct dhcp_option *option;
267
 	struct dhcp_option *option;
261
 	unsigned int encap_tag = DHCP_ENCAPSULATOR ( tag );
268
 	unsigned int encap_tag = DHCP_ENCAPSULATOR ( tag );
262
 	size_t old_len = 0;
269
 	size_t old_len = 0;
267
 	if ( tag == DHCP_PAD )
274
 	if ( tag == DHCP_PAD )
268
 		return -ENOTTY;
275
 		return -ENOTTY;
269
 
276
 
277
+	creation_offset = find_dhcp_option_with_encap ( options, DHCP_END,
278
+							NULL );
279
+	if ( creation_offset < 0 )
280
+		creation_offset = options->len;
270
 	/* Find old instance of this option, if any */
281
 	/* Find old instance of this option, if any */
271
 	offset = find_dhcp_option_with_encap ( options, tag, &encap_offset );
282
 	offset = find_dhcp_option_with_encap ( options, tag, &encap_offset );
272
 	if ( offset >= 0 ) {
283
 	if ( offset >= 0 ) {

Laden…
Annuleren
Opslaan