Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/openwrt/odhcp6c.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Dedecker <dedeckeh@gmail.com>2018-06-08 17:29:50 +0300
committerHans Dedecker <dedeckeh@gmail.com>2018-06-11 16:27:18 +0300
commitca8822bc7bd0797eaa6b6160f234471ee1a8fb2c (patch)
treee9ec5ac34dfbbadf2ee4ec93ae6861338713585b
parent5316d7f8bdcd8dd29286e98404a4f4fd2456500f (diff)
odhcp6c: add support for user string options
Support user defined options having a string as option value. The option value is detected as a string if it starts and ends with either a double or single quote. Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
-rw-r--r--src/odhcp6c.c49
-rw-r--r--src/odhcp6c.h1
2 files changed, 50 insertions, 0 deletions
diff --git a/src/odhcp6c.c b/src/odhcp6c.c
index 48e3dee..2fb8abf 100644
--- a/src/odhcp6c.c
+++ b/src/odhcp6c.c
@@ -560,6 +560,7 @@ static int usage(void)
" -x dns:2001:2001::1,2001:2001::2 - option 23\n"
" -x 15:office - option 15 (userclass)\n"
" -x 0x1f4:ABBA - option 500\n"
+ " -x 202:'\"file\"' - option 202\n"
" -c <clientid> Override client-ID (base-16 encoded 16-bit type + value)\n"
" -i <iface-id> Use a custom interface identifier for RA handling\n"
" -r <options> Options to be requested (comma-separated)\n"
@@ -969,6 +970,40 @@ static int parse_opt_u8(const char *src, uint8_t **dst)
return script_unhexlify(*dst, len, src);
}
+static int parse_opt_string(const char *src, uint8_t **dst, const bool array)
+{
+ int i_len = strlen(src);
+ int o_len = 0;
+ char *sep = get_sep_pos(src, ARRAY_SEP);
+
+ if (sep && !array)
+ return -1;
+
+ do {
+ if (sep) {
+ *sep = 0;
+ sep++;
+ }
+
+ int len = strlen(src);
+
+ *dst = realloc(*dst, o_len + len);
+ if (!*dst)
+ return -1;
+
+ memcpy(&((*dst)[o_len]), src, len);
+
+ o_len += len;
+ i_len -= strlen(src) + (sep ? 1 : 0);
+ src = sep;
+
+ if (sep)
+ sep = get_sep_pos(src, ARRAY_SEP);
+ } while (i_len);
+
+ return o_len;
+}
+
static int parse_opt_dns_string(const char *src, uint8_t **dst, const bool array)
{
int i_len = strlen(src);
@@ -1091,6 +1126,10 @@ static int parse_opt_data(const char *data, uint8_t **dst, const unsigned int ty
ret = parse_opt_u8(data, dst);
break;
+ case OPT_STR:
+ ret = parse_opt_string(data, dst, array);
+ break;
+
case OPT_DNS_STR:
ret = parse_opt_dns_string(data, dst, array);
break;
@@ -1151,6 +1190,16 @@ static int parse_opt(const char *opt)
type = dopt->flags & OPT_MASK_SIZE;
array = ((dopt->flags & OPT_ARRAY) == OPT_ARRAY) ? true : false;
+ } else if (data[0] == '"' || data[0] == '\'') {
+ char *end = strrchr(data + 1, data[0]);
+
+ if (end && (end == (data + strlen(data) - 1))) {
+ /* Raw option is specified as a string */
+ type = OPT_STR;
+ data++;
+ *end = '\0';
+ }
+
}
payload_len = parse_opt_data(data, &payload, type, array);
diff --git a/src/odhcp6c.h b/src/odhcp6c.h
index 3abe7b7..97809f1 100644
--- a/src/odhcp6c.h
+++ b/src/odhcp6c.h
@@ -325,6 +325,7 @@ struct odhcp6c_request_prefix {
enum odhcp6c_opt_flags {
OPT_U8 = 0,
OPT_IP6,
+ OPT_STR,
OPT_DNS_STR,
OPT_USER_CLASS,
OPT_MASK_SIZE = 0x0F,