1 /* Copyright (c) 2008 The Board of Trustees of The Leland Stanford
4 * We are making the OpenFlow specification and associated documentation
5 * (Software) available for public use and benefit with the expectation
6 * that others will use, modify and enhance the Software and contribute
7 * those enhancements back to the community. However, since we would
8 * like to make the Software available for broadest use, with as few
9 * restrictions as possible permission is hereby granted, free of
10 * charge, to any person obtaining a copy of this Software to deal in
11 * the Software under the copyrights without restriction, including
12 * without limitation the rights to use, copy, modify, merge, publish,
13 * distribute, sublicense, and/or sell copies of the Software, and to
14 * permit persons to whom the Software is furnished to do so, subject to
15 * the following conditions:
17 * The above copyright notice and this permission notice shall be
18 * included in all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
24 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
25 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
26 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 * The name and trademarks of copyright holder(s) may NOT be used in
30 * advertising or publicity pertaining to the Software or any
31 * derivatives without specific, written prior permission.
36 #include <arpa/inet.h>
43 #include "dynamic-string.h"
45 #define THIS_MODULE VLM_dhcp
48 /* Information about a DHCP argument type. */
50 const char *name; /* Name. */
51 size_t size; /* Number of bytes per argument. */
54 static struct arg_type types[] = {
55 #define DHCP_ARG(NAME, SIZE) [DHCP_ARG_##NAME] = {#NAME, SIZE},
60 /* Information about a DHCP option. */
62 const char *name; /* Name. */
63 enum dhcp_arg_type type; /* Argument type. */
64 size_t min_args; /* Minimum number of arguments. */
65 size_t max_args; /* Maximum number of arguments. */
68 static struct option_class classes[DHCP_N_OPTIONS] = {
69 [0 ... 255] = {NULL, DHCP_ARG_UINT8, 0, SIZE_MAX},
70 #define DHCP_OPT(NAME, CODE, TYPE, MIN, MAX) \
71 [CODE] = {#NAME, DHCP_ARG_##TYPE, MIN, MAX},
76 /* A single (bad) DHCP message can in theory dump out many, many log messages,
77 * especially at high logging levels, so the burst size is set quite high
78 * here to avoid missing useful information. */
79 struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(60, 600);
81 static void copy_data(struct dhcp_msg *);
84 dhcp_type_name(enum dhcp_msg_type type)
87 #define DHCP_MSG(NAME, VALUE) case NAME: return #NAME;
91 return "<<unknown DHCP message type>>";
94 /* Initializes 'msg' as a DHCP message. The message should be freed with
95 * dhcp_msg_uninit() when it is no longer needed. */
97 dhcp_msg_init(struct dhcp_msg *msg)
99 memset(msg, 0, sizeof *msg);
102 /* Frees the contents of 'msg'. The caller is responsible for freeing 'msg',
105 dhcp_msg_uninit(struct dhcp_msg *msg)
112 /* Initializes 'dst' as a copy of 'src'. 'dst' (and 'src') should be freed
113 * with dhcp_msg_uninit() when it is no longer needed. */
115 dhcp_msg_copy(struct dhcp_msg *dst, const struct dhcp_msg *src)
118 dst->data_allocated = src->data_used;
120 dst->data = xmalloc(dst->data_allocated);
125 prealloc_data(struct dhcp_msg *msg, size_t n)
127 size_t needed = msg->data_used + n;
128 if (needed > msg->data_allocated) {
129 uint8_t *old_data = msg->data;
130 msg->data_allocated = MAX(needed * 2, 64);
131 msg->data = xmalloc(msg->data_allocated);
140 append_data(struct dhcp_msg *msg, const void *data, size_t n)
142 uint8_t *p = &msg->data[msg->data_used];
149 copy_data(struct dhcp_msg *msg)
154 for (code = 0; code < DHCP_N_OPTIONS; code++) {
155 struct dhcp_option *opt = &msg->options[code];
157 assert(msg->data_used + opt->n <= msg->data_allocated);
158 opt->data = append_data(msg, opt->data, opt->n);
163 /* Appends the 'n' bytes in 'data' to the DHCP option in 'msg' represented by
164 * 'code' (which must be in the range 0...DHCP_N_OPTIONS). */
166 dhcp_msg_put(struct dhcp_msg *msg, int code,
167 const void *data, size_t n)
169 struct dhcp_option *opt;
170 if (code == DHCP_CODE_PAD || code == DHCP_CODE_END) {
174 opt = &msg->options[code];
175 prealloc_data(msg, n + opt->n);
177 if (&msg->data[msg->data_used - opt->n] != opt->data) {
178 opt->data = append_data(msg, opt->data, opt->n);
180 append_data(msg, data, n);
182 opt->data = append_data(msg, data, n);
187 /* Appends the boolean value 'b', as a octet with value 0 (false) or 1 (true),
188 * to the DHCP option in 'msg' represented by 'code' (which must be in the
189 * range 0...DHCP_N_OPTIONS). */
191 dhcp_msg_put_bool(struct dhcp_msg *msg, int code, bool b_)
194 dhcp_msg_put(msg, code, &b, 1);
197 /* Appends the number of seconds 'secs', as a 32-bit number in network byte
198 * order, to the DHCP option in 'msg' represented by 'code' (which must be in
199 * the range 0...DHCP_N_OPTIONS). */
201 dhcp_msg_put_secs(struct dhcp_msg *msg, int code, uint32_t secs_)
203 uint32_t secs = htonl(secs_);
204 dhcp_msg_put(msg, code, &secs, sizeof secs);
207 /* Appends the IP address 'ip', as a 32-bit number in network byte order, to
208 * the DHCP option in 'msg' represented by 'code' (which must be in the range
209 * 0...DHCP_N_OPTIONS). */
211 dhcp_msg_put_ip(struct dhcp_msg *msg, int code, uint32_t ip)
213 dhcp_msg_put(msg, code, &ip, sizeof ip);
216 /* Appends the ASCII string 'string', to the DHCP option in 'msg' represented
217 * by 'code' (which must be in the range 0...DHCP_N_OPTIONS). */
219 dhcp_msg_put_string(struct dhcp_msg *msg, int code, const char *string)
221 dhcp_msg_put(msg, code, string, strlen(string));
224 /* Appends octet 'x' to DHCP option in 'msg' represented by 'code' (which must
225 * be in the range 0...DHCP_N_OPTIONS). */
227 dhcp_msg_put_uint8(struct dhcp_msg *msg, int code, uint8_t x)
229 dhcp_msg_put(msg, code, &x, sizeof x);
232 /* Appends the 'n' octets in 'data' to DHCP option in 'msg' represented by
233 * 'code' (which must be in the range 0...DHCP_N_OPTIONS). */
234 void dhcp_msg_put_uint8_array(struct dhcp_msg *msg, int code,
235 const uint8_t data[], size_t n)
237 dhcp_msg_put(msg, code, data, n);
240 /* Appends the 16-bit value in 'x', in network byte order, to DHCP option in
241 * 'msg' represented by 'code' (which must be in the range
242 * 0...DHCP_N_OPTIONS). */
244 dhcp_msg_put_uint16(struct dhcp_msg *msg, int code, uint16_t x_)
246 uint16_t x = htons(x_);
247 dhcp_msg_put(msg, code, &x, sizeof x);
251 /* Appends the 'n' 16-bit values in 'data', in network byte order, to DHCP
252 * option in 'msg' represented by 'code' (which must be in the range
253 * 0...DHCP_N_OPTIONS). */
255 dhcp_msg_put_uint16_array(struct dhcp_msg *msg, int code,
256 const uint16_t data[], size_t n)
260 for (i = 0; i < n; i++) {
261 dhcp_msg_put_uint16(msg, code, data[i]);
265 /* Returns a pointer to the 'size' bytes starting at byte offset 'offset' in
266 * the DHCP option in 'msg' represented by 'code' (which must be in the range
267 * 0...DHCP_N_OPTIONS). If the option has fewer than 'offset + size' bytes,
268 * returns a null pointer. */
270 dhcp_msg_get(const struct dhcp_msg *msg, int code,
271 size_t offset, size_t size)
273 const struct dhcp_option *opt = &msg->options[code];
274 return offset + size <= opt->n ? (const char *) opt->data + offset : NULL;
277 /* Stores in '*out' the boolean value at byte offset 'offset' in the DHCP
278 * option in 'msg' represented by 'code' (which must be in the range
279 * 0...DHCP_N_OPTIONS). Returns true if successful, false if the option has
280 * fewer than 'offset + 1' bytes. */
282 dhcp_msg_get_bool(const struct dhcp_msg *msg, int code, size_t offset,
285 const uint8_t *uint8 = dhcp_msg_get(msg, code, offset, sizeof *uint8);
294 /* Stores in '*out' the 32-bit count of seconds at offset 'offset' (in
295 * 4-byte increments) in the DHCP option in 'msg' represented by 'code'
296 * (which must be in the range 0...DHCP_N_OPTIONS). The value is converted to
297 * native byte order. Returns true if successful, false if the option has
298 * fewer than '4 * (offset + 1)' bytes. */
300 dhcp_msg_get_secs(const struct dhcp_msg *msg, int code, size_t offset,
303 const uint32_t *uint32 = dhcp_msg_get(msg, code, offset * sizeof *uint32,
306 *out = ntohl(*uint32);
313 /* Stores in '*out' the IP address at offset 'offset' (in 4-byte increments) in
314 * the DHCP option in 'msg' represented by 'code' (which must be in the range
315 * 0...DHCP_N_OPTIONS). The IP address is stored in network byte order.
316 * Returns true if successful, false if the option has fewer than '4 * (offset
319 dhcp_msg_get_ip(const struct dhcp_msg *msg, int code,
320 size_t offset, uint32_t *out)
322 const uint32_t *uint32 = dhcp_msg_get(msg, code, offset * sizeof *uint32,
332 /* Returns the string in the DHCP option in 'msg' represented by 'code' (which
333 * must be in the range 0...DHCP_N_OPTIONS). The caller is responsible for
334 * freeing the string with free().
336 * If 'msg' has no option represented by 'code', returns a null pointer. (If
337 * the option was specified but had no content, then an empty string is
338 * returned, not a null pointer.) */
340 dhcp_msg_get_string(const struct dhcp_msg *msg, int code)
342 const struct dhcp_option *opt = &msg->options[code];
343 return opt->data ? xmemdup0(opt->data, opt->n) : NULL;
346 /* Stores in '*out' the octet at byte offset 'offset' in the DHCP option in
347 * 'msg' represented by 'code' (which must be in the range 0...DHCP_N_OPTIONS).
348 * Returns true if successful, false if the option has fewer than 'offset + 1'
351 dhcp_msg_get_uint8(const struct dhcp_msg *msg, int code,
352 size_t offset, uint8_t *out)
354 const uint8_t *uint8 = dhcp_msg_get(msg, code, offset, sizeof *uint8);
363 /* Stores in '*out' the 16-bit value at offset 'offset' (in 2-byte units) in
364 * the DHCP option in 'msg' represented by 'code' (which must be in the range
365 * 0...DHCP_N_OPTIONS). The value is converted to native byte order. Returns
366 * true if successful, false if the option has fewer than '2 * (offset + 1)'
369 dhcp_msg_get_uint16(const struct dhcp_msg *msg, int code,
370 size_t offset, uint16_t *out)
372 const uint16_t *uint16 = dhcp_msg_get(msg, code, offset * sizeof *uint16,
375 *out = ntohs(*uint16);
382 /* Appends a string representing 'duration' seconds to 'ds'. */
384 put_duration(struct ds *ds, unsigned int duration)
387 if (duration >= 86400) {
388 ds_put_format(ds, "%ud", duration / 86400);
391 if (duration >= 3600) {
392 ds_put_format(ds, "%uh", duration / 3600);
395 if (duration >= 60) {
396 ds_put_format(ds, "%umin", duration / 60);
400 ds_put_format(ds, "%us", duration);
403 ds_put_cstr(ds, "0s");
407 /* Appends a string representation of 'opt', which has the given 'code', to
410 dhcp_option_to_string(const struct dhcp_option *opt, int code, struct ds *ds)
412 struct option_class *class = &classes[code];
413 const struct arg_type *type = &types[class->type];
418 for (cp = class->name; *cp; cp++) {
419 unsigned char c = *cp;
420 ds_put_char(ds, c == '_' ? '-' : tolower(c));
423 ds_put_format(ds, "option-%d", code);
425 ds_put_char(ds, '=');
427 if (!opt->data || !opt->n) {
428 ds_put_cstr(ds, opt->data ? "empty" : "null");
432 if (class->type == DHCP_ARG_STRING) {
433 ds_put_char(ds, '"');
434 ds_put_printable(ds, opt->data, opt->n);
435 ds_put_char(ds, '"');
438 for (offset = 0; offset + type->size <= opt->n; offset += type->size) {
439 const void *p = (const char *) opt->data + offset;
440 const uint8_t *uint8 = p;
441 const uint32_t *uint32 = p;
442 const uint16_t *uint16 = p;
444 if (offset && class->type != DHCP_ARG_STRING) {
445 ds_put_cstr(ds, class->type == DHCP_ARG_UINT8 ? ":" : ", ");
447 switch (class->type) {
451 ds_put_format(ds, IP_FMT, IP_ARGS(uint32));
454 ds_put_format(ds, "%02"PRIx8, *uint8);
456 case DHCP_ARG_UINT16:
457 ds_put_format(ds, "%"PRIu16, ntohs(*uint16));
459 case DHCP_ARG_UINT32:
460 ds_put_format(ds, "%"PRIu32, ntohl(*uint32));
463 put_duration(ds, ntohl(*uint32));
465 case DHCP_ARG_STRING:
467 case DHCP_ARG_BOOLEAN:
469 ds_put_cstr(ds, "false");
470 } else if (*uint8 == 1) {
471 ds_put_cstr(ds, "true");
473 ds_put_format(ds, "**%"PRIu8"**", *uint8);
478 if (offset != opt->n) {
480 ds_put_cstr(ds, ", ");
482 ds_put_cstr(ds, "**leftovers:");
483 for (; offset < opt->n; offset++) {
484 const void *p = (const char *) opt->data + offset;
485 const uint8_t *uint8 = p;
486 ds_put_format(ds, " %"PRIu8, *uint8);
488 ds_put_cstr(ds, "**");
493 /* Returns true if 'a' and 'b' have the same content, false otherwise. */
495 dhcp_option_equals(const struct dhcp_option *a, const struct dhcp_option *b)
497 return ((a->data != NULL) == (b->data != NULL)
499 && !memcmp(a->data, b->data, a->n));
502 /* Replaces 'ds' by a string representation of 'msg'. If 'multiline' is
503 * false, 'ds' receives a single-line representation of 'msg', otherwise a
504 * multiline representation. */
506 dhcp_msg_to_string(const struct dhcp_msg *msg, bool multiline, struct ds *ds)
508 char separator = multiline ? '\n' : ' ';
512 ds_put_format(ds, "op=%s",
513 (msg->op == DHCP_BOOTREQUEST ? "request"
514 : msg->op == DHCP_BOOTREPLY ? "reply"
516 ds_put_format(ds, "%ctype=%s", separator, dhcp_type_name(msg->type));
517 ds_put_format(ds, "%cxid=0x%08"PRIx32, separator, msg->xid);
518 ds_put_format(ds, "%csecs=", separator);
519 put_duration(ds, msg->secs);
521 ds_put_format(ds, "%cflags=", separator);
522 if (msg->flags & DHCP_FLAGS_BROADCAST) {
523 ds_put_cstr(ds, "[BROADCAST]");
525 if (msg->flags & DHCP_FLAGS_MBZ) {
526 ds_put_format(ds, "[0x%04"PRIx16"]", msg->flags & DHCP_FLAGS_MBZ);
530 ds_put_format(ds, "%cciaddr="IP_FMT, separator, IP_ARGS(&msg->ciaddr));
533 ds_put_format(ds, "%cyiaddr="IP_FMT, separator, IP_ARGS(&msg->yiaddr));
536 ds_put_format(ds, "%csiaddr="IP_FMT, separator, IP_ARGS(&msg->siaddr));
539 ds_put_format(ds, "%cgiaddr="IP_FMT, separator, IP_ARGS(&msg->giaddr));
541 ds_put_format(ds, "%cchaddr="ETH_ADDR_FMT,
542 separator, ETH_ADDR_ARGS(msg->chaddr));
544 for (code = 0; code < DHCP_N_OPTIONS; code++) {
545 const struct dhcp_option *opt = &msg->options[code];
547 ds_put_char(ds, separator);
548 dhcp_option_to_string(opt, code, ds);
552 ds_put_char(ds, separator);
558 parse_options(struct dhcp_msg *msg, const char *name, void *data, size_t size,
569 code = buffer_try_pull(&b, 1);
570 if (!code || *code == DHCP_CODE_END) {
572 } else if (*code == DHCP_CODE_PAD) {
576 len = buffer_try_pull(&b, 1);
578 VLOG_DBG_RL(&rl, "reached end of %s expecting length byte", name);
582 payload = buffer_try_pull(&b, *len);
584 VLOG_DBG_RL(&rl, "expected %"PRIu8" bytes of option-%"PRIu8" "
585 "payload with only %zu bytes of %s left",
586 *len, *code, b.size, name);
589 dhcp_msg_put(msg, *code + option_offset, payload, *len);
594 validate_options(struct dhcp_msg *msg)
598 for (code = 0; code < DHCP_N_OPTIONS; code++) {
599 struct dhcp_option *opt = &msg->options[code];
600 struct option_class *class = &classes[code];
601 struct arg_type *type = &types[class->type];
603 size_t n_elems = opt->n / type->size;
604 size_t remainder = opt->n % type->size;
607 VLOG_DBG_RL(&rl, "%s option has %zu %zu-byte %s arguments "
608 "with %zu bytes left over",
609 class->name, n_elems, type->size,
610 type->name, remainder);
613 if (n_elems < class->min_args || n_elems > class->max_args) {
614 VLOG_DBG_RL(&rl, "%s option has %zu %zu-byte %s arguments but "
615 "between %zu and %zu are required",
616 class->name, n_elems, type->size, type->name,
617 class->min_args, class->max_args);
621 struct ds ds = DS_EMPTY_INITIALIZER;
622 VLOG_DBG_RL(&rl, "%s option contains: %s", class->name,
623 dhcp_option_to_string(opt, code, &ds));
633 /* Attempts to parse 'b' as a DHCP message. If successful, initializes '*msg'
634 * to the parsed message and returns 0. Otherwise, returns a positive errno
635 * value and '*msg' is indeterminate. */
637 dhcp_parse(struct dhcp_msg *msg, const struct buffer *b_)
639 struct buffer b = *b_;
640 struct dhcp_header *dhcp;
645 dhcp = buffer_try_pull(&b, sizeof *dhcp);
647 VLOG_DBG_RL(&rl, "buffer too small for DHCP header (%zu bytes)",
652 if (dhcp->op != DHCP_BOOTREPLY && dhcp->op != DHCP_BOOTREQUEST) {
653 VLOG_DBG_RL(&rl, "invalid DHCP op (%"PRIu8")", dhcp->op);
656 if (dhcp->htype != ARP_HRD_ETHERNET) {
657 VLOG_DBG_RL(&rl, "invalid DHCP htype (%"PRIu8")", dhcp->htype);
660 if (dhcp->hlen != ETH_ADDR_LEN) {
661 VLOG_DBG_RL(&rl, "invalid DHCP hlen (%"PRIu8")", dhcp->hlen);
667 msg->xid = ntohl(dhcp->xid);
668 msg->secs = ntohs(dhcp->secs);
669 msg->flags = ntohs(dhcp->flags);
670 msg->ciaddr = dhcp->ciaddr;
671 msg->yiaddr = dhcp->yiaddr;
672 msg->siaddr = dhcp->siaddr;
673 msg->giaddr = dhcp->giaddr;
674 memcpy(msg->chaddr, dhcp->chaddr, ETH_ADDR_LEN);
676 cookie = buffer_try_pull(&b, sizeof cookie);
678 if (ntohl(*cookie) == DHCP_OPTS_COOKIE) {
681 parse_options(msg, "options", b.data, b.size, 0);
682 if (dhcp_msg_get_uint8(msg, DHCP_CODE_OPTION_OVERLOAD,
685 parse_options(msg, "file", dhcp->file, sizeof dhcp->file,
689 parse_options(msg, "sname",
690 dhcp->sname, sizeof dhcp->sname, 0);
694 VLOG_DBG_RL(&rl, "bad DHCP options cookie: %08"PRIx32,
698 VLOG_DBG_RL(&rl, "DHCP packet has no options");
701 vendor_class = dhcp_msg_get_string(msg, DHCP_CODE_VENDOR_CLASS);
702 if (vendor_class && !strcmp(vendor_class, "OpenFlow")) {
703 parse_options(msg, "vendor-specific",
704 msg->options[DHCP_CODE_VENDOR_SPECIFIC].data,
705 msg->options[DHCP_CODE_VENDOR_SPECIFIC].n,
710 validate_options(msg);
711 if (!dhcp_msg_get_uint8(msg, DHCP_CODE_DHCP_MSG_TYPE, 0, &type)) {
712 VLOG_DBG_RL(&rl, "missing DHCP message type");
713 dhcp_msg_uninit(msg);
720 if (VLOG_IS_DBG_ENABLED()) {
724 ds_put_hex_dump(&ds, b_->data, b_->size, 0, true);
725 VLOG_DBG_RL(&rl, "invalid DHCP message dump:\n%s", ds_cstr(&ds));
728 dhcp_msg_to_string(msg, false, &ds);
729 VLOG_DBG_RL(&rl, "partially dissected DHCP message: %s", ds_cstr(&ds));
737 put_option_chunk(struct buffer *b, uint8_t code, void *data, size_t n)
744 buffer_put(b, header, sizeof header);
745 buffer_put(b, data, n);
749 put_option(struct buffer *b, uint8_t code, void *data, size_t n)
753 /* Divide the data into chunks of 255 bytes or less. Make
754 * intermediate chunks multiples of 8 bytes in case the
755 * recipient validates a chunk at a time instead of the
756 * concatenated value. */
759 size_t chunk = n > 255 ? 248 : n;
760 put_option_chunk(b, code, p, chunk);
765 /* Option should be present but carry no data. */
766 put_option_chunk(b, code, NULL, 0);
771 /* Appends to 'b' the DHCP message represented by 'msg'. */
773 dhcp_assemble(const struct dhcp_msg *msg, struct buffer *b)
775 const uint8_t end = DHCP_CODE_END;
776 uint32_t cookie = htonl(DHCP_OPTS_COOKIE);
777 struct buffer vnd_data;
778 struct dhcp_header dhcp;
781 memset(&dhcp, 0, sizeof dhcp);
783 dhcp.htype = ARP_HRD_ETHERNET;
784 dhcp.hlen = ETH_ADDR_LEN;
786 dhcp.xid = htonl(msg->xid);
787 dhcp.secs = htons(msg->secs);
788 dhcp.flags = htons(msg->flags);
789 dhcp.ciaddr = msg->ciaddr;
790 dhcp.yiaddr = msg->yiaddr;
791 dhcp.siaddr = msg->siaddr;
792 dhcp.giaddr = msg->giaddr;
793 memcpy(dhcp.chaddr, msg->chaddr, ETH_ADDR_LEN);
794 buffer_put(b, &dhcp, sizeof dhcp);
795 buffer_put(b, &cookie, sizeof cookie);
797 /* Put DHCP message type first. (The ordering is not required but it
800 uint8_t type = msg->type;
801 put_option(b, DHCP_CODE_DHCP_MSG_TYPE, &type, 1);
804 /* Put the standard options. */
805 for (i = 0; i < DHCP_VENDOR_OFS; i++) {
806 const struct dhcp_option *option = &msg->options[i];
807 put_option(b, i, option->data, option->n);
810 /* Assemble vendor specific option and put it. */
811 buffer_init(&vnd_data, 0);
812 for (i = DHCP_VENDOR_OFS; i < DHCP_N_OPTIONS; i++) {
813 const struct dhcp_option *option = &msg->options[i];
814 put_option(&vnd_data, i - DHCP_VENDOR_OFS, option->data, option->n);
817 put_option(b, DHCP_CODE_VENDOR_SPECIFIC, vnd_data.data, vnd_data.size);
819 buffer_uninit(&vnd_data);
821 /* Put end-of-options option. */
822 buffer_put(b, &end, sizeof end);