From: Roy Marples Date: Wed, 2 Sep 2009 20:16:07 +0000 (+0000) Subject: Allow an un-encapsulated vendor option. X-Git-Tag: v5.0.8~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8e99a6829016c40be439d1828afd0593ab319942;p=thirdparty%2Fdhcpcd.git Allow an un-encapsulated vendor option. --- diff --git a/dhcpcd.8.in b/dhcpcd.8.in index d0743b0e..50a26a54 100644 --- a/dhcpcd.8.in +++ b/dhcpcd.8.in @@ -22,7 +22,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd July 26, 2009 +.Dd September 1, 2009 .Dt DHCPCD 8 SMM .Os .Sh NAME @@ -324,14 +324,19 @@ default, without having to know things like hardware address or hostname. Add an enscapulated vendor option. .Ar code should be between 1 and 254 inclusive. +To add a raw vendor string, omit +.Ar code +but keep the comma. Examples. .Pp Set the vendor option 01 with an IP address. .D1 dhcpcd \-v 01,192.168.0.2 eth0 Set the vendor option 02 with a hex code. .D1 dhcpcd \-v 02,01:02:03:04:05 eth0 -Do the above and set a third option with a string and not an IP address. -.D1 dhcpcd \-v 01,192.168.0.2 \-v 02,01:02:03:04:05 \-v 03,\e"192.168.0.2\e" eth0 +Set the vendor option 03 with an IP address as a string. +.D1 dhcpcd \-v 03,\e"192.168.0.2\e" eth0 +Set un-encapulated vendor option to hello world. +.D1 dhcpcd \-v ,\e"hello world\e" eth0 .It Fl x , -exit This will signal an existing .Nm diff --git a/dhcpcd.conf.5.in b/dhcpcd.conf.5.in index 05b29927..904eb29f 100644 --- a/dhcpcd.conf.5.in +++ b/dhcpcd.conf.5.in @@ -22,7 +22,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd July 26, 2009 +.Dd September 1, 2009 .Dt DHCPCD.CONF 5 SMM .Os .Sh NAME @@ -256,6 +256,9 @@ You can specify more than one. Add an enscapulated vendor option. .Ar code should be between 1 and 254 inclusive. +To add a raw vendor string, omit +.Ar code +but keep the comma. Examples. .Pp Set the vendor option 01 with an IP address. @@ -264,6 +267,8 @@ Set the vendor option 02 with a hex code. .D1 vendor 02,01:02:03:04:05 Set the vendor option 03 with an IP address as a string. .D1 vendor 03,\e"192.168.0.2\e" +Set un-encapulated vendor option to hello world. +.D1 vendor ,\e"hello world\e" .It Ic vendorclassid Ar string Change the default vendorclassid sent from dhcpcd-version. If not set then none is sent. diff --git a/if-options.c b/if-options.c index 65e8b5db..959fcba8 100644 --- a/if-options.c +++ b/if-options.c @@ -454,6 +454,27 @@ parse_option(struct if_options *ifo, int opt, const char *arg) syslog(LOG_ERR, "invalid vendor format"); return -1; } + + /* If vendor starts with , then it is not encapsulated */ + if (p == arg) { + arg++; + s = parse_string((char *)ifo->vendor + 1, + VENDOR_MAX_LEN, arg); + if (s == -1) { + syslog(LOG_ERR, "vendor: %m"); + return -1; + } + ifo->vendor[0] = (uint8_t)s; + ifo->options |= DHCPCD_VENDORRAW; + break; + } + + /* Encapsulated vendor options */ + if (ifo->options & DHCPCD_VENDORRAW) { + ifo->options &= ~DHCPCD_VENDORRAW; + ifo->vendor[0] = 0; + } + *p = '\0'; i = atoint(arg); arg = p + 1; @@ -814,7 +835,7 @@ read_config(const char *file, } /* Terminate the encapsulated options */ - if (ifo && ifo->vendor[0]) { + if (ifo && ifo->vendor[0] && !(ifo->options & DHCPCD_VENDORRAW)) { ifo->vendor[0]++; ifo->vendor[ifo->vendor[0]] = DHO_END; } @@ -834,7 +855,7 @@ add_options(struct if_options *ifo, int argc, char **argv) break; } /* Terminate the encapsulated options */ - if (r == 1 && ifo->vendor[0]) { + if (r == 1 && ifo->vendor[0] && !(ifo->options & DHCPCD_VENDORRAW)) { ifo->vendor[0]++; ifo->vendor[ifo->vendor[0]] = DHO_END; } diff --git a/if-options.h b/if-options.h index 46534ea7..0c2818fd 100644 --- a/if-options.h +++ b/if-options.h @@ -69,6 +69,7 @@ #define DHCPCD_LINK (1 << 20) #define DHCPCD_QUIET (1 << 21) #define DHCPCD_BACKGROUND (1 << 22) +#define DHCPCD_VENDORRAW (1 << 23) extern const struct option cf_options[];