scan.c (7c478bd9) scan.c (d04ccbb3)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22/*
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21/*
23 * Copyright 1996-2001, 2003 Sun Microsystems, Inc. All rights reserved.
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 *
26 * Routines used to extract/insert DHCP options. Must be kept MT SAFE,
27 * as they are called from different threads.
28 */
29
30#pragma ident "%Z%%M% %I% %E% SMI"
31

--- 138 unchanged lines hidden (view full) ---

170 break;
171 default:
172 pl->opts[CD_OPTION_OVERLOAD] = NULL;
173 return (DHCP_BAD_OPT_OVLD);
174 }
175 }
176 return (0);
177}
23 * Use is subject to license terms.
24 *
25 * Routines used to extract/insert DHCP options. Must be kept MT SAFE,
26 * as they are called from different threads.
27 */
28
29#pragma ident "%Z%%M% %I% %E% SMI"
30

--- 138 unchanged lines hidden (view full) ---

169 break;
170 default:
171 pl->opts[CD_OPTION_OVERLOAD] = NULL;
172 return (DHCP_BAD_OPT_OVLD);
173 }
174 }
175 return (0);
176}
177
178/*
179 * Locate a DHCPv6 option or suboption within a buffer. DHCPv6 uses nested
180 * options within options, and this function is designed to work with both
181 * primary options and the suboptions contained within.
182 *
183 * The 'oldopt' is a previous option pointer, and is typically used to iterate
184 * over options of the same code number. The 'codenum' is in host byte order
185 * for simplicity. 'retlenp' may be NULL, and if present gets the _entire_
186 * option length (including header).
187 *
188 * Warning: the returned pointer has no particular alignment because DHCPv6
189 * defines options without alignment. The caller must deal with unaligned
190 * pointers carefully.
191 */
192dhcpv6_option_t *
193dhcpv6_find_option(const void *buffer, size_t buflen,
194 const dhcpv6_option_t *oldopt, uint16_t codenum, uint_t *retlenp)
195{
196 const uchar_t *bp;
197 dhcpv6_option_t d6o;
198 uint_t olen;
199
200 codenum = htons(codenum);
201 bp = buffer;
202 while (buflen >= sizeof (dhcpv6_option_t)) {
203 (void) memcpy(&d6o, bp, sizeof (d6o));
204 olen = ntohs(d6o.d6o_len) + sizeof (d6o);
205 if (olen > buflen)
206 break;
207 if (d6o.d6o_code != codenum ||
208 (oldopt != NULL && bp <= (const uchar_t *)oldopt)) {
209 bp += olen;
210 buflen -= olen;
211 continue;
212 }
213 if (retlenp != NULL)
214 *retlenp = olen;
215 /* LINTED: alignment */
216 return ((dhcpv6_option_t *)bp);
217 }
218 return (NULL);
219}
220
221/*
222 * Locate a DHCPv6 option within the top level of a PKT_LIST entry. DHCPv6
223 * uses nested options within options, and this function returns only the
224 * primary options. Use dhcpv6_find_option to traverse suboptions.
225 *
226 * See dhcpv6_find_option for usage details and warnings.
227 */
228dhcpv6_option_t *
229dhcpv6_pkt_option(const PKT_LIST *plp, const dhcpv6_option_t *oldopt,
230 uint16_t codenum, uint_t *retlenp)
231{
232 const dhcpv6_message_t *d6m;
233
234 if (plp == NULL || plp->pkt == NULL || plp->len < sizeof (*d6m))
235 return (NULL);
236 d6m = (const dhcpv6_message_t *)plp->pkt;
237 return (dhcpv6_find_option(d6m + 1, plp->len - sizeof (*d6m), oldopt,
238 codenum, retlenp));
239}