diff options
author | Francis Dupont <fdupont@isc.org> | 2017-11-13 10:24:11 +0100 |
---|---|---|
committer | Francis Dupont <fdupont@isc.org> | 2019-11-12 09:01:49 +0100 |
commit | 72ca08be6bb6d6fff5228f728937d2329f1ced52 (patch) | |
tree | 11d28589140b184cc930f75a5d2f79e641956b30 | |
parent | 378b8c3a02c8553de242041683282688fba7c512 (diff) | |
download | isc-dhcp-72ca08be6bb6d6fff5228f728937d2329f1ced52.tar.gz |
Add flex-id path
-rw-r--r-- | keama/confparse.c | 8 | ||||
-rw-r--r-- | keama/data.c | 11 | ||||
-rw-r--r-- | keama/data.h | 2 | ||||
-rw-r--r-- | keama/keama.8 | 9 | ||||
-rw-r--r-- | keama/keama.c | 6 | ||||
-rw-r--r-- | keama/keama.h | 3 | ||||
-rw-r--r-- | keama/print.c | 12 | ||||
-rw-r--r-- | keama/reduce.c | 12 | ||||
-rw-r--r-- | keama/tests/README | 1 | ||||
-rw-r--r-- | keama/tests/env | 3 | ||||
-rw-r--r-- | keama/tests/hostidentifier4.inL (renamed from keama/tests/hostidentifier4.notyet) | 0 | ||||
-rw-r--r-- | keama/tests/hostidentifier4.out | 79 | ||||
-rw-r--r-- | keama/tests/runone.sh | 1 |
13 files changed, 121 insertions, 26 deletions
diff --git a/keama/confparse.c b/keama/confparse.c index 8d731b33..82c7d9e4 100644 --- a/keama/confparse.c +++ b/keama/confparse.c @@ -1282,6 +1282,9 @@ parse_host_declaration(struct parse *cfile) if (data->type != ELEMENT_STRING) parse_error(cfile, "option data must be a " "string or binary option"); + /* quote data if it is a text */ + if (strcmp(option->format, "t") == 0) + data = createString(quote(stringValue(data))); concatString(host_id, stringValue(data)); expr = createString(host_id); @@ -1360,6 +1363,7 @@ static void add_host_id_option(struct parse *cfile, const struct option *option, int relays) { + struct string *path; struct string *expr; struct element *params; struct element *entry; @@ -1381,7 +1385,9 @@ add_host_id_option(struct parse *cfile, TAILQ_INSERT_TAIL(&hooks->comments, comment); entry = createMap(); listPush(hooks, entry); - params = createString(makeString(-1, "/path/libdhcp_flex_id.so")); + path = makeString(-1, hook_path); + appendString(path, "libdhcp_flex_id.so"); + params = createString(path); comment = createComment("/// Please update the path here"); TAILQ_INSERT_TAIL(¶ms->comments, comment); mapSet(entry, params, "library"); diff --git a/keama/data.c b/keama/data.c index 6a441d7d..2235fe3a 100644 --- a/keama/data.c +++ b/keama/data.c @@ -352,6 +352,17 @@ eqString(const struct string *s, const struct string *o) return ISC_TF(memcmp(s->content, o->content, s->length) == 0); } +struct string * +quote(struct string *s) +{ + struct string *result; + + result = makeString(-1, "'"); + concatString(result, s); + appendString(result, "'"); + return result; +} + struct comment * createComment(const char *line) { diff --git a/keama/data.h b/keama/data.h index 94850712..b8078cc3 100644 --- a/keama/data.h +++ b/keama/data.h @@ -183,6 +183,8 @@ struct string *makeStringArray(int l, const char *s, char fmt); void appendString(struct string *s, const char *a); void concatString(struct string *s, const struct string *a); isc_boolean_t eqString(const struct string *s, const struct string *o); +/* quoting */ +struct string *quote(struct string *); /* Comments */ struct comment { diff --git a/keama/keama.8 b/keama/keama.8 index 146dfc46..75cdd863 100644 --- a/keama/keama.8 +++ b/keama/keama.8 @@ -40,6 +40,10 @@ keama - Kea Migration Assistant .I {perform|fatal|pass} ] [ +.B -l +.I hook-library-path +] +[ .B -i .I input-file ] @@ -62,10 +66,13 @@ option. The input configuration is for DHCPv6. Incompatible with the \fB-4\fR option. .TP --r +-r \fIaction\fR Specify what to do with hostnames: resolve them into their first address, raise a fatal error or pass them silently. .TP +-p hook-library-path +Specify the path where hook libraries (e.g. flex-id) can be found +.TP -i input-file Specify the ISC DHCP configuration file to read. When it is not given the standard input is used. diff --git a/keama/keama.c b/keama/keama.c index 589ed707..5e86d0af 100644 --- a/keama/keama.c +++ b/keama/keama.c @@ -33,6 +33,7 @@ #include "keama.h" #define KEAMA_USAGE "Usage: keama [-4|-6] [-r {perform|fatal|pass}\\n" \ + " [-l hook-library-path]" \ " [-i input-file] [-o output-file]\n" static void @@ -46,6 +47,7 @@ usage(const char *sfmt, const char *sarg) { } int local_family = 0; +char *hook_path = "/path/"; char *input_file = NULL; char *output_file = NULL; FILE *input = NULL; @@ -83,6 +85,10 @@ main(int argc, char **argv) { resolve = pass; else usage(bad_resolve, argv[i]); + } else if (strcmp(argv[i], "-l") == 0) { + if (++i == argc) + usage(use_noarg, argv[i - 1]); + hook_path = argv[i]; } else if (strcmp(argv[i], "-i") == 0) { if (++i == argc) usage(use_noarg, argv[i - 1]); diff --git a/keama/keama.h b/keama/keama.h index 025fafd3..97e98cc4 100644 --- a/keama/keama.h +++ b/keama/keama.h @@ -299,6 +299,9 @@ struct option { /* Kea parse tools */ void stackPush(struct parse *cfile, struct element *elem); +/* From command line */ +char *hook_path; + /* From common/parse.c */ void parse_error(struct parse *, const char *, ...) __attribute__((__format__(__printf__,2,3))) diff --git a/keama/print.c b/keama/print.c index bfa7414d..be85bd4d 100644 --- a/keama/print.c +++ b/keama/print.c @@ -33,7 +33,6 @@ #include <string.h> #include <unistd.h> -static struct string *quote(struct string *); static void debug(const char* fmt, ...); const char * @@ -1479,17 +1478,6 @@ print_numeric_expression(struct element *expr, isc_boolean_t *lose) return result->content; } -static struct string * -quote(struct string *s) -{ - struct string *result; - - result = makeString(-1, "'"); - concatString(result, s); - appendString(result, "'"); - return result; -} - static void debug(const char* fmt, ...) { diff --git a/keama/reduce.c b/keama/reduce.c index d5ed87b7..24939473 100644 --- a/keama/reduce.c +++ b/keama/reduce.c @@ -35,7 +35,6 @@ static struct element *reduce_equal_expression(struct element *left, struct element *right); -static struct string *quote(struct string *); static void debug(const char* fmt, ...); /* @@ -1005,17 +1004,6 @@ reduce_equal_expression(struct element *left, struct element *right) return createString(result); } -static struct string * -quote(struct string *s) -{ - struct string *result; - - result = makeString(-1, "'"); - concatString(result, s); - appendString(result, "'"); - return result; -} - static void debug(const char* fmt, ...) { diff --git a/keama/tests/README b/keama/tests/README index 499b6522..48372b6a 100644 --- a/keama/tests/README +++ b/keama/tests/README @@ -11,6 +11,7 @@ Extensions: - .msg = resultat (first line of standard error) for error test - .in4 = source for working test in DHCPv4 - .in6 = source for working test in DHCPv6 + - .inL = source for working test in DHCPv4 with -l $HOOK - .out = resultat for working test There is no working test in DHCPv4 and DHCPv6. The body of the name of a working test must include 4 or 6 so diff --git a/keama/tests/env b/keama/tests/env new file mode 100644 index 00000000..9fe0fcd4 --- /dev/null +++ b/keama/tests/env @@ -0,0 +1,3 @@ +setenv KEA4 /tmp/kea/src/bin/dhcp4/kea-dhcp4 +setenv KEA6 /tmp/kea/src/bin/dhcp6/kea-dhcp6 +setenv HOOK /tmp/kea/premium/src/hooks/dhcp/flex_id/.libs/ diff --git a/keama/tests/hostidentifier4.notyet b/keama/tests/hostidentifier4.inL index 5576307b..5576307b 100644 --- a/keama/tests/hostidentifier4.notyet +++ b/keama/tests/hostidentifier4.inL diff --git a/keama/tests/hostidentifier4.out b/keama/tests/hostidentifier4.out new file mode 100644 index 00000000..beea9985 --- /dev/null +++ b/keama/tests/hostidentifier4.out @@ -0,0 +1,79 @@ +{ + # host declaration with flexible identifiers config + # authoritative is mandatory + /// This configuration declares some subnets but has no interfaces-config + /// Reference Kea #5256 + "Dhcp4": { + "subnet4": [ + # subnet4 declaration + { + "subnet": "10.5.5.0/27", + "pools": [ + { + "pool": "10.5.5.5 - 10.5.5.10" + } + ], + "reservations": [ + # host declarations + { + "hostname": "test1", + "flex-id": "'test1'", + "option-data": [ + { + "space": "dhcp4", + "name": "domain-search", + "code": 119, +// "original-data": "\"example.com\", \"example.org\"", + "data": "example.com, example.org" + } + ], +// /// valid-lifetime in unsupported scope +// "valid-lifetime": 1800, + "ip-address": "10.5.5.1" +// "extra-ip-addresses": [ +// "10.10.10.10" +// ] + }, + { + "hostname": "test2", + "hw-address": "00:07:0e:36:48:19", + "ip-address": "10.5.5.2" + } + ] + }, + { + "subnet": "10.10.10.0/27", + "reservations": [ +// { +// "hostname": "test3", +// "hw-address": "fddi 00:07:0e:36:48:19", +// "ip-address": "10.10.10.1" +// } + ] + } + ], + "option-def": [ + # option definition + { + "space": "dhcp4", + "name": "my-id", + "code": 250, + "type": "string" + } + ], + "host-reservation-identifiers": [ + "flex-id", + "hw-address" + ], + /// The flexible host identifier is a premium feature + "hooks-libraries": [ + { + /// Please update the path here + "library": "/tmp/kea/premium/src/hooks/dhcp/flex_id/.libs/libdhcp_flex_id.so", + "parameters": { + "identifier-expression": "option[250].hex" + } + } + ] + } +} diff --git a/keama/tests/runone.sh b/keama/tests/runone.sh index 30b499c8..3524af2e 100644 --- a/keama/tests/runone.sh +++ b/keama/tests/runone.sh @@ -45,6 +45,7 @@ case $trail in 6) options="-6";; F) options="-4 -r fatal";; P) options="-4 -r pass";; + L) options="-4 -l $HOOK";; *) echo "unrecognized trail '$trail' in '$full'" >&2; exit 1;; esac |