|
@@ -78,26 +78,32 @@ static inline unsigned int dhcp_option_len ( struct dhcp_option *option ) {
|
78
|
78
|
}
|
79
|
79
|
|
80
|
80
|
/**
|
81
|
|
- * Find DHCP option within block of raw data
|
|
81
|
+ * Find DHCP option within DHCP options block, and its encapsulator (if any)
|
82
|
82
|
*
|
83
|
83
|
* @v tag DHCP option tag to search for
|
84
|
|
- * @v data Data block
|
85
|
|
- * @v len Length of data block
|
|
84
|
+ * @v options DHCP options block
|
|
85
|
+ * @ret encapsulator Encapsulating option (if applicable, may be NULL)
|
86
|
86
|
* @ret option DHCP option, or NULL if not found
|
87
|
87
|
*
|
88
|
88
|
* Searches for the DHCP option matching the specified tag within the
|
89
|
89
|
* block of data. Encapsulated options may be searched for by using
|
90
|
|
- * DHCP_ENCAP_OPT() to construct the tag value.
|
|
90
|
+ * DHCP_ENCAP_OPT() to construct the tag value. If the option is an
|
|
91
|
+ * encapsulated option, and @c encapsulator is non-NULL, it will be
|
|
92
|
+ * filled in with a pointer to the encapsulating option, if present.
|
|
93
|
+ * Note that the encapsulating option may be present even if the
|
|
94
|
+ * encapsulated option is absent, in which case @c encapsulator will
|
|
95
|
+ * be set but the function will return NULL.
|
91
|
96
|
*
|
92
|
97
|
* This routine is designed to be paranoid. It does not assume that
|
93
|
98
|
* the option data is well-formatted, and so must guard against flaws
|
94
|
99
|
* such as options missing a @c DHCP_END terminator, or options whose
|
95
|
100
|
* length would take them beyond the end of the data block.
|
96
|
101
|
*/
|
97
|
|
-static struct dhcp_option * find_dhcp_option_raw ( unsigned int tag,
|
98
|
|
- void *data, size_t len ) {
|
99
|
|
- struct dhcp_option *option = data;
|
100
|
|
- ssize_t remaining = len;
|
|
102
|
+static struct dhcp_option *
|
|
103
|
+find_dhcp_option_encap ( unsigned int tag, struct dhcp_option_block *options,
|
|
104
|
+ struct dhcp_option **encapsulator ) {
|
|
105
|
+ struct dhcp_option *option = options->data;
|
|
106
|
+ ssize_t remaining = options->len;
|
101
|
107
|
unsigned int option_len;
|
102
|
108
|
|
103
|
109
|
while ( remaining ) {
|
|
@@ -118,10 +124,12 @@ static struct dhcp_option * find_dhcp_option_raw ( unsigned int tag,
|
118
|
124
|
/* Check for start of matching encapsulation block */
|
119
|
125
|
if ( DHCP_ENCAPSULATOR ( tag ) &&
|
120
|
126
|
( option->tag == DHCP_ENCAPSULATOR ( tag ) ) ) {
|
121
|
|
- /* Search within encapsulated option block */
|
122
|
|
- return find_dhcp_option_raw ( DHCP_ENCAPSULATED( tag ),
|
123
|
|
- &option->data,
|
124
|
|
- option->len );
|
|
127
|
+ /* Continue search within encapsulated option block */
|
|
128
|
+ if ( encapsulator )
|
|
129
|
+ *encapsulator = option;
|
|
130
|
+ remaining = option->len;
|
|
131
|
+ option = ( void * ) &option->data;
|
|
132
|
+ continue;
|
125
|
133
|
}
|
126
|
134
|
option = ( ( ( void * ) option ) + option_len );
|
127
|
135
|
}
|
|
@@ -129,19 +137,19 @@ static struct dhcp_option * find_dhcp_option_raw ( unsigned int tag,
|
129
|
137
|
}
|
130
|
138
|
|
131
|
139
|
/**
|
132
|
|
- * Find DHCP option within options block
|
|
140
|
+ * Find DHCP option within DHCP options block
|
133
|
141
|
*
|
134
|
142
|
* @v tag DHCP option tag to search for
|
135
|
143
|
* @v options DHCP options block
|
136
|
144
|
* @ret option DHCP option, or NULL if not found
|
137
|
145
|
*
|
138
|
146
|
* Searches for the DHCP option matching the specified tag within the
|
139
|
|
- * options block. Encapsulated options may be searched for by using
|
|
147
|
+ * block of data. Encapsulated options may be searched for by using
|
140
|
148
|
* DHCP_ENCAP_OPT() to construct the tag value.
|
141
|
149
|
*/
|
142
|
150
|
struct dhcp_option * find_dhcp_option ( unsigned int tag,
|
143
|
151
|
struct dhcp_option_block *options ) {
|
144
|
|
- return find_dhcp_option_raw ( tag, options->data, options->len );
|
|
152
|
+ return find_dhcp_option_encap ( tag, options, NULL );
|
145
|
153
|
}
|
146
|
154
|
|
147
|
155
|
/**
|