summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorThomas Markwalder <tmark@isc.org>2016-03-04 14:16:29 -0500
committerThomas Markwalder <tmark@isc.org>2016-03-04 14:16:29 -0500
commitcc1bd34e09bad3313a16d89f7ad491ff16754dc7 (patch)
treeaefafa2e9b960601a4071c684b1dc58905be90d3 /common
parent7f4e6f97789799a76aa0b8b5ffab39042bcbff5e (diff)
downloadisc-dhcp-cc1bd34e09bad3313a16d89f7ad491ff16754dc7.tar.gz
[master] Added lease-id-format to server and client
Merges in rt26378
Diffstat (limited to 'common')
-rw-r--r--common/conflex.c11
-rw-r--r--common/print.c100
2 files changed, 108 insertions, 3 deletions
diff --git a/common/conflex.c b/common/conflex.c
index a1ba95fd..fe994acf 100644
--- a/common/conflex.c
+++ b/common/conflex.c
@@ -3,7 +3,7 @@
Lexical scanner for dhcpd config file... */
/*
- * Copyright (c) 2004-2015 by Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (c) 2004-2016 by Internet Systems Consortium, Inc. ("ISC")
* Copyright (c) 1995-2003 by Internet Software Consortium
*
* Permission to use, copy, modify, and distribute this software for any
@@ -1050,6 +1050,9 @@ intern(char *atom, enum dhcp_token dfv) {
return HOSTNAME;
if (!strcasecmp (atom + 1, "elp"))
return TOKEN_HELP;
+ if (!strcasecmp (atom + 1, "ex")) {
+ return TOKEN_HEX;
+ }
break;
case 'i':
if (!strcasecmp(atom+1, "a-na"))
@@ -1136,6 +1139,9 @@ intern(char *atom, enum dhcp_token dfv) {
if (!strcasecmp(atom+1, "ittle-endian")) {
return TOKEN_LITTLE_ENDIAN;
}
+ if (!strcasecmp (atom + 1, "ease-id-format")) {
+ return LEASE_ID_FORMAT;
+ }
break;
case 'm':
if (!strncasecmp (atom + 1, "ax", 2)) {
@@ -1236,6 +1242,9 @@ intern(char *atom, enum dhcp_token dfv) {
return OF;
if (!strcasecmp (atom + 1, "wner"))
return OWNER;
+ if (!strcasecmp (atom + 1, "ctal")) {
+ return TOKEN_OCTAL;
+ }
break;
case 'p':
if (!strcasecmp (atom + 1, "arse-vendor-option"))
diff --git a/common/print.c b/common/print.c
index dfe0593b..40b64fb6 100644
--- a/common/print.c
+++ b/common/print.c
@@ -3,7 +3,7 @@
Turn data structures into printable text. */
/*
- * Copyright (c) 2009-2014 by Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (c) 2009-2014,2016 by Internet Systems Consortium, Inc. ("ISC")
* Copyright (c) 2004-2007 by Internet Systems Consortium, Inc. ("ISC")
* Copyright (c) 1995-2003 by Internet Software Consortium
*
@@ -69,7 +69,7 @@ char *quotify_string (const char *s, const char *file, int line)
return buf;
}
-char *quotify_buf (const unsigned char *s, unsigned len,
+char *quotify_buf (const unsigned char *s, unsigned len, char enclose_char,
const char *file, int line)
{
unsigned nulen = 0;
@@ -87,9 +87,17 @@ char *quotify_buf (const unsigned char *s, unsigned len,
nulen++;
}
+ if (enclose_char) {
+ nulen +=2 ;
+ }
+
buf = dmalloc (nulen + 1, MDL);
if (buf) {
nsp = buf;
+ if (enclose_char) {
+ *nsp++ = enclose_char;
+ }
+
for (i = 0; i < len; i++) {
if (s [i] == ' ')
*nsp++ = ' ';
@@ -102,6 +110,10 @@ char *quotify_buf (const unsigned char *s, unsigned len,
} else
*nsp++ = s [i];
}
+
+ if (enclose_char) {
+ *nsp++ = enclose_char;
+ }
*nsp++ = 0;
}
return buf;
@@ -1517,3 +1529,87 @@ print_time(TIME t)
return buf;
}
+
+/* !brief Return the given data as a string of hex digits "xx:xx:xx ..."
+ *
+ * Converts the given data into a null-terminated, string of hex digits,
+ * stored in an allocated buffer. It is the caller's responsiblity to free
+ * the buffer.
+ *
+ * \param s - pointer to the data to convert
+ * \param len - length of the data to convert
+ * \param file - source file of invocation
+ * \param line - line number of invocation
+ *
+ * \return Returns an allocated buffer containing the hex string
+*/
+char *buf_to_hex (const unsigned char *s, unsigned len,
+ const char *file, int line)
+{
+ unsigned nulen = 0;
+ char *buf;
+
+ /* If somebody hands us length of zero, we'll give them
+ * back an empty string */
+ if (!len) {
+ buf = dmalloc (1, MDL);
+ if (buf) {
+ *buf = 0x0;
+ }
+
+ return (buf);
+ }
+
+
+ /* Figure out how big it needs to be. print_to_hex uses
+ * "%02x:" per character. Note since there's no trailing colon
+ * we'll have room for the null */
+ nulen = (len * 3);
+
+ /* Allocate our buffer */
+ buf = dmalloc (nulen, MDL);
+
+ /* Hex-ify it */
+ if (buf) {
+ print_hex_only (len, s, nulen, buf);
+ }
+
+ return buf;
+}
+
+/* !brief Formats data into a string based on a lease id format
+ *
+ * Takes the given data and returns an allocated string whose contents are
+ * the string version of that data, formatted according to the output lease
+ * id format. Note it is the caller's responsiblity to delete the string.
+ *
+ * Currently two formats are supported:
+ *
+ * OCTAL - Default or "legacy" CSL format enclosed in quotes '"'.
+ *
+ * HEX - Bytes represented as string colon seperated of hex digit pairs
+ * (xx:xx:xx...)
+ *
+ * \param s - data to convert
+ * \param len - length of the data to convert
+ * \param format - desired format of the result
+ * \param file - source file of invocation
+ * \param line - line number of invocation
+ *
+ * \return A pointer to the allocated, null-terminated string
+*/
+char *format_lease_id(const unsigned char *s, unsigned len,
+ int format, const char *file, int line) {
+ char *idstr = NULL;
+
+ switch (format) {
+ case TOKEN_HEX:
+ idstr = buf_to_hex(s, len, MDL);
+ break;
+ case TOKEN_OCTAL:
+ default:
+ idstr = quotify_buf(s, len, '"', MDL);
+ break;
+ }
+ return (idstr);
+}