changeset 2195:97118e44508a draft

Fix vendor options a litle
author Roy Marples <roy@marples.name>
date Fri, 06 Dec 2013 19:15:06 +0000
parents e65989e20e61
children daa4ed46377e
files dhcp-common.c dhcp.c if-options.c
diffstat 3 files changed, 25 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/dhcp-common.c	Fri Dec 06 17:47:53 2013 +0000
+++ b/dhcp-common.c	Fri Dec 06 19:15:06 2013 +0000
@@ -643,11 +643,11 @@
 						if (oopt == NULL)
 							/* Report error? */
 							continue;
-						eopt = oopt;
 					}
 					n += dhcp_envoption(
 					    env == NULL ? NULL : &env[n], pfx,
-					    ifname, eopt,
+					    ifname,
+					    eopt->type & OPTION ? oopt : eopt,
 					    dgetopt, eod, eol);
 					break;
 				}
--- a/dhcp.c	Fri Dec 06 17:47:53 2013 +0000
+++ b/dhcp.c	Fri Dec 06 19:15:06 2013 +0000
@@ -1159,21 +1159,23 @@
 			continue;
 		if (dhcp_getoverride(ifo, opt->option))
 			continue;
-		if ((p = get_option(dhcp, opt->option, &pl)))
+		if ((p = get_option(dhcp, opt->option, &pl))) {
 			ep += dhcp_envoption(ep, prefix, ifp->name,
 			    opt, dhcp_getoption, p, pl);
-		/* Grab the Vendor-Identifying Vendor Options, RFC 3925 */
-		if (opt->option == DHO_VIVSO && pl > (int)sizeof(uint32_t)) {
-			memcpy(&en, p, sizeof(en));
-			en = ntohl(en);
-			vo = vivso_find(en, ifp);
-			if (vo) {
-				/* Skip over en + total size */
-				p += sizeof(en) + 1;
-				pl -= sizeof(en) + 1;
-				ep += dhcp_envoption(ep, prefix, ifp->name,
-				    vo, dhcp_getoption, p, pl);
-				printf ("%p\n", ep);
+			if (opt->option == DHO_VIVSO &&
+			    pl > (int)sizeof(uint32_t))
+			{
+			        memcpy(&en, p, sizeof(en));
+				en = ntohl(en);
+				vo = vivso_find(en, ifp);
+				if (vo) {
+					/* Skip over en + total size */
+					p += sizeof(en) + 1;
+					pl -= sizeof(en) + 1;
+					ep += dhcp_envoption(ep, prefix,
+					    ifp->name,
+					    vo, dhcp_getoption, p, pl);
+				}
 			}
 		}
 	}
--- a/if-options.c	Fri Dec 06 17:47:53 2013 +0000
+++ b/if-options.c	Fri Dec 06 19:15:06 2013 +0000
@@ -1404,19 +1404,22 @@
 				return -1;
 			}
 		}
-		ndop = NULL;
 		if (opt != O_EMBED) {
-			for (dl = 0; dl < *dop_len; dl++) {
-				ndop = &(*dop)[dl];
+			for (dl = 0, ndop = *dop; dl < *dop_len; dl++, ndop++)
+			{
 				/* type 0 seems freshly malloced struct
 				 * for us to use */
 				if (ndop->option == u || ndop->type == 0)
 					break;
 			}
-		}
+			if (dl == *dop_len)
+				ndop = NULL;
+		} else
+			ndop = NULL;
 		if (ndop == NULL) {
 			if ((ndop = realloc(*dop,
-			    sizeof(**dop) * ((*dop_len) + 1))) == NULL) {
+			    sizeof(**dop) * ((*dop_len) + 1))) == NULL)
+			{
 				syslog(LOG_ERR, "%s: %m", __func__);
 				return -1;
 			}