1 /* Copyright (c) 2008, 2009 Nicira Networks
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
18 #include <arpa/inet.h>
25 #include <netinet/in.h>
31 #include "dynamic-string.h"
38 #define THIS_MODULE VLM_cfg
41 /* XXX This file really needs a unit test! For a while, cfg_get_string(0,
42 * "bridge.a.controller") would return the value of
43 * "bridge.a.controller.in-band", if it existed, and I'm really not certain
44 * that the fix didn't break other things. */
46 /* Configuration file name. */
47 static char *cfg_name;
49 /* Put the temporary file in the same directory as cfg_name, so that
50 * they are guaranteed to be in the same file system and therefore we can
51 * rename() tmp_name over cfg_name. */
52 static char *tmp_name;
54 /* Lock information. */
55 static char *lock_name;
56 static int lock_fd = -1;
58 /* Flag to indicate whether local modifications have been made. */
61 static uint8_t cfg_cookie[CFG_COOKIE_LEN];
63 /* Current configuration. Maintained in sorted order. */
64 static struct svec cfg = SVEC_EMPTY_INITIALIZER;
66 static bool has_double_dot(const char *key, size_t len);
67 static bool is_valid_key(const char *key, size_t len,
68 const char *file_name, int line_number,
70 static char *parse_section(const char *file_name, int line_number,
72 static void parse_setting(const char *file_name, int line_number,
73 const char *section, const char *);
74 static int compare_key(const char *a, const char *b);
75 static char **find_key_le(const char *key);
76 static char **find_key_ge(const char *key);
77 static char *find_key(const char *);
78 static bool parse_mac(const char *, uint8_t mac[6]);
79 static bool parse_dpid(const char *, uint64_t *);
80 static bool is_key(const char *);
81 static bool is_int(const char *);
82 static bool is_bool(const char *);
83 static const char *extract_value(const char *key);
84 static const char *get_nth_value(int idx, const char *key);
85 static bool is_type(const char *s, enum cfg_flags);
87 #define CC_ALPHA "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
88 #define CC_DIGIT "0123456789"
89 #define CC_ALNUM CC_ALPHA CC_DIGIT
90 #define CC_SPACE " \t\r\n\v"
92 #define CC_FILE_NAME CC_ALNUM "._-"
93 #define CC_KEY CC_ALNUM "._-@$:+"
95 /* Sets 'file_name' as the configuration file read by cfg_read(). Returns 0 on
96 * success, otherwise a positive errno value if 'file_name' cannot be opened.
98 * This function does not actually read the named file or directory. Use
99 * cfg_read() to (re)read all the configuration files. */
101 cfg_set_file(const char *file_name)
111 cfg_name = lock_name = tmp_name = NULL;
114 /* Make sure that we can open this file for reading. */
115 fd = open(file_name, O_RDONLY);
121 cfg_name = xstrdup(file_name);
123 /* Put the temporary file in the same directory as cfg_name, so that they
124 * are guaranteed to be in the same file system, to guarantee that
125 * rename(tmp_name, cfg_name) will work. */
126 tmp_name = xasprintf("%s.~tmp~", file_name);
128 /* Put the lock file in the same directory as cfg_name, but prefixed by
129 * a dot so as not to garner administrator interest. */
130 slash = strrchr(file_name, '/');
132 lock_name = xasprintf("%.*s/.%s.~lock~",
133 slash - file_name, file_name, slash + 1);
135 lock_name = xasprintf(".%s.~lock~", file_name);
138 VLOG_INFO("using \"%s\" as configuration file, \"%s\" as lock file",
139 file_name, lock_name);
149 if (SHA1Reset(&context) != shaSuccess) {
152 for (i = 0; i < cfg.n; i++) {
153 if (SHA1Input(&context, (uint8_t *)cfg.names[i],
154 strlen(cfg.names[i])) != shaSuccess) {
157 SHA1Input(&context, (uint8_t *)"\n", 1);
159 if (SHA1Result(&context, cfg_cookie) != shaSuccess) {
166 /* Reads all of the configuration files or directories that have been added
167 * with cfg_add_file(), merges their content. Any previous configuration is
168 * replaced. Returns 0 if successful, otherwise a positive errno value. */
183 /* Save old configuration data and clear the active configuration. */
185 svec_swap(&old_cfg, &cfg);
187 /* Read new configuration. */
188 VLOG_DBG("reading configuration from %s", cfg_name);
190 file = fopen(cfg_name, "r");
192 VLOG_ERR("failed to open \"%s\": %s", cfg_name, strerror(errno));
199 while (!ds_get_line(&ds, file)) {
200 const char *s = ds_cstr(&ds);
201 size_t indent = strspn(s, CC_SPACE);
205 if (*s == '#' || *s == '\0') {
206 /* Ignore comments and lines that contain only white space. */
207 } else if (*s == '[') {
210 section = parse_section(cfg_name, line_number, s);
212 VLOG_ERR("%s:%d: ignoring indented section header",
213 cfg_name, line_number);
215 } else if (indent && !section) {
216 VLOG_ERR("%s:%d: ignoring indented line outside any section",
217 cfg_name, line_number);
223 parse_setting(cfg_name, line_number, section, s);
230 svec_terminate(&cfg);
235 if (VLOG_IS_DBG_ENABLED()) {
236 struct svec removed, added;
239 svec_diff(&old_cfg, &cfg, &removed, NULL, &added);
240 if (removed.n || added.n) {
241 VLOG_DBG("configuration changes:");
242 for (i = 0; i < removed.n; i++) {
243 VLOG_DBG("-%s", removed.names[i]);
245 for (i = 0; i < added.n; i++) {
246 VLOG_DBG("+%s", added.names[i]);
249 VLOG_DBG("configuration unchanged");
251 svec_destroy(&added);
252 svec_destroy(&removed);
254 svec_destroy(&old_cfg);
261 /* Fills 'svec' with the entire configuration file. */
263 cfg_get_all(struct svec *svec)
266 svec_append(svec, &cfg);
270 cfg_get_cookie(uint8_t *cookie)
276 memcpy(cookie, cfg_cookie, sizeof(cfg_cookie));
284 COVERAGE_INC(cfg_unlock);
291 open_lockfile(const char *name)
294 /* Try to open an existing lock file. */
295 int fd = open(name, O_RDWR);
298 } else if (errno != ENOENT) {
299 VLOG_WARN("%s: failed to open lock file: %s",
300 name, strerror(errno));
304 /* Try to create a new lock file. */
305 VLOG_INFO("%s: lock file does not exist, creating", name);
306 fd = open(name, O_RDWR | O_CREAT | O_EXCL, 0600);
309 } else if (errno != EEXIST) {
310 VLOG_WARN("%s: failed to create lock file: %s",
311 name, strerror(errno));
315 /* Someone else created the lock file. Try again. */
320 try_lock(int fd, bool block)
323 memset(&l, 0, sizeof l);
325 l.l_whence = SEEK_SET;
328 return fcntl(fd, block ? F_SETLKW : F_SETLK, &l) == -1 ? errno : 0;
331 /* Locks the configuration file against modification by other processes and
332 * re-reads it from disk.
334 * The 'timeout' specifies the maximum number of milliseconds to wait for the
335 * config file to become free. Use 0 to avoid waiting or INT_MAX to wait
338 * Returns 0 on success, otherwise a positive errno value. */
340 cfg_lock(uint8_t *cookie, int timeout)
342 long long int start = time_msec();
343 long long int elapsed = 0;
345 uint8_t curr_cookie[CFG_COOKIE_LEN];
348 COVERAGE_INC(cfg_lock);
352 /* Open lock file. */
353 fd = open_lockfile(lock_name);
358 /* Try to lock it. This will block (if 'timeout' > 0). */
359 error = try_lock(fd, timeout > 0);
361 elapsed = time_msec() - start;
367 /* Lock failed. Close the lock file and reopen it on the next
368 * iteration, just in case someone deletes it underneath us (even
369 * though that should not happen). */
371 if (error != EINTR) {
372 /* Hard error, give up. */
373 COVERAGE_INC(cfg_lock_error);
374 VLOG_WARN("%s: failed to lock file "
375 "(after %lld ms, with %d-ms timeout): %s",
376 lock_name, elapsed, timeout, strerror(error));
380 /* Probably, the periodic timer set up by time_init() woke up us. Just
381 * check whether it's time to give up. */
382 if (timeout != INT_MAX && elapsed >= timeout) {
383 COVERAGE_INC(cfg_lock_timeout);
384 VLOG_WARN("%s: giving up on lock file after %lld ms",
388 COVERAGE_INC(cfg_lock_retry);
391 VLOG_WARN("%s: waited %lld ms for lock file", lock_name, elapsed);
398 cfg_get_cookie(curr_cookie);
400 if (memcmp(curr_cookie, cookie, sizeof *curr_cookie)) {
401 /* Configuration has changed, so reject. */
411 do_write_config(const void *data, size_t len)
416 file = fopen(tmp_name, "w");
418 VLOG_WARN("could not open %s for writing: %s",
419 tmp_name, strerror(errno));
423 fwrite(data, 1, len, file);
425 /* This is essentially equivalent to:
426 * error = ferror(file) || fflush(file) || fclose(file);
427 * but it doesn't short-circuit, so that it always closes 'file'. */
428 error = ferror(file);
429 error = fflush(file) || error;
430 error = fclose(file) || error;
432 VLOG_WARN("problem writing to %s: %s", tmp_name, strerror(errno));
436 if (rename(tmp_name, cfg_name) < 0) {
437 VLOG_WARN("could not rename %s to %s: %s",
438 tmp_name, cfg_name, strerror(errno));
447 /* Write the current configuration into the configuration file. Returns 0 if
448 * successful, otherwise a negative errno value. */
457 ? svec_join(&cfg, "\n", "\n")
458 : xstrdup("# This file intentionally left blank.\n"));
459 retval = do_write_config(content, strlen(content));
466 cfg_write_data(uint8_t *data, size_t len)
468 int retval = do_write_config(data, len);
475 /* Returns true if the configuration has changed since the last time it was
476 * read or written. */
484 cfg_buf_put(struct ofpbuf *buffer)
488 for (i = 0; i < cfg.n; i++) {
489 ofpbuf_put(buffer, cfg.names[i], strlen(cfg.names[i]));
490 ofpbuf_put(buffer, "\n", 1);
494 /* Formats the printf()-style format string in the parameter 'format', which
495 * must be the function's last parameter, into string variable 'dst'. The
496 * function is responsible for freeing 'dst'. */
497 #define FORMAT_KEY(FORMAT, DST) \
500 va_start(args__, FORMAT); \
501 (DST) = xvasprintf(FORMAT, args__); \
505 /* Returns true if the configuration includes a key named 'key'. */
507 cfg_has(const char *key_, ...)
512 FORMAT_KEY(key_, key);
513 retval = find_key(key) != NULL;
519 cfg_is_valid(enum cfg_flags flags, const char *key_, ...)
521 char *key, **first, **last, **p;
525 FORMAT_KEY(key_, key);
526 first = find_key_le(key);
527 last = find_key_ge(key);
529 retval = ((!(flags & CFG_REQUIRED) || n)
530 && (!(flags & CFG_MULTIPLE) || n <= 1));
531 for (p = first; retval && p < last; p++) {
532 retval = is_type(strchr(*p, '=') + 1, flags);
538 /* Returns true if the configuration includes at least one key whose name
539 * begins with 'section' followed by a dot. */
541 cfg_has_section(const char *section_, ...)
549 va_start(args, section_);
550 ds_put_format_valist(§ion, section_, args);
551 ds_put_char(§ion, '.');
554 for (p = cfg.names; *p; p++) { /* XXX this is inefficient */
555 if (!strncmp(section.string, *p, section.length)) {
561 ds_destroy(§ion);
565 /* Returns the number of values for the given 'key'. The return value is 0 if
566 * no values exist for 'key'. */
568 cfg_count(const char *key_, ...)
573 FORMAT_KEY(key_, key);
574 retval = find_key_ge(key) - find_key_le(key);
579 /* Fills 'svec' with all of the immediate subsections of 'section'. For
580 * example, if 'section' is "bridge" and keys bridge.a, bridge.b, bridge.b.c,
581 * and bridge.c.x.y.z exist, then 'svec' would be initialized to a, b, and
582 * c. The caller must first initialize 'svec'. */
584 cfg_get_subsections(struct svec *svec, const char *section_, ...)
591 va_start(args, section_);
592 ds_put_format_valist(§ion, section_, args);
593 ds_put_char(§ion, '.');
597 for (p = cfg.names; *p; p++) { /* XXX this is inefficient */
598 if (!strncmp(section.string, *p, section.length)) {
599 const char *ss = *p + section.length;
600 size_t ss_len = strcspn(ss, ".=");
601 svec_add_nocopy(svec, xmemdup0(ss, ss_len));
605 ds_destroy(§ion);
609 cfg_add_entry(const char *entry_, ...)
613 FORMAT_KEY(entry_, entry);
614 svec_add_nocopy(&cfg, entry);
616 svec_terminate(&cfg);
621 cfg_del_entry(const char *entry_, ...)
625 FORMAT_KEY(entry_, entry);
626 svec_del(&cfg, entry);
627 svec_terminate(&cfg);
633 cfg_del_section(const char *section_, ...)
640 va_start(args, section_);
641 ds_put_format_valist(§ion, section_, args);
642 ds_put_char(§ion, '.');
645 for (p = cfg.names; *p; p++) {
646 if (!strncmp(section.string, *p, section.length)) {
652 svec_terminate(&cfg);
654 ds_destroy(§ion);
659 cfg_del_match(const char *pattern_, ...)
661 bool matched = false;
665 FORMAT_KEY(pattern_, pattern);
667 for (p = cfg.names; *p; p++) {
668 if (!fnmatch(pattern, *p, 0)) {
676 svec_terminate(&cfg);
683 /* Fills 'svec' with all of the key-value pairs that have sections that
684 * begin with 'section'. The caller must first initialize 'svec'. */
686 cfg_get_section(struct svec *svec, const char *section_, ...)
693 va_start(args, section_);
694 ds_put_format_valist(§ion, section_, args);
695 ds_put_char(§ion, '.');
698 for (p = cfg.names; *p; p++) { /* XXX this is inefficient */
699 if (!strncmp(section.string, *p, section.length)) {
703 ds_destroy(§ion);
706 /* Returns the value numbered 'idx' of 'key'. Returns a null pointer if 'idx'
707 * is greater than or equal to cfg_count(key). The caller must not modify or
708 * free the returned string or retain its value beyond the next call to
711 cfg_get_string(int idx, const char *key_, ...)
716 FORMAT_KEY(key_, key);
717 retval = get_nth_value(idx, key);
722 /* Returns the value numbered 'idx' of 'key'. Returns a null pointer if 'idx'
723 * is greater than or equal to cfg_count(key) or if the value 'idx' of 'key' is
724 * not a valid key. The caller must not modify or free the returned string or
725 * retain its value beyond the next call to cfg_read(). */
727 cfg_get_key(int idx, const char *key_, ...)
729 const char *value, *retval;
732 FORMAT_KEY(key_, key);
733 value = get_nth_value(idx, key);
734 retval = value && is_key(value) ? value : NULL;
739 /* Returns the value numbered 'idx' of 'key', converted to an integer. Returns
740 * 0 if 'idx' is greater than or equal to cfg_count(key) or if the value 'idx'
741 * of 'key' is not a valid integer. */
743 cfg_get_int(int idx, const char *key_, ...)
749 FORMAT_KEY(key_, key);
750 value = get_nth_value(idx, key);
751 retval = value && is_int(value) ? atoi(value) : 0;
756 /* Returns the value numbered 'idx' of 'key', converted to a boolean value.
757 * Returns false if 'idx' is greater than or equal to cfg_count(key) or if the
758 * value 'idx' of 'key' is not a valid boolean. */
760 cfg_get_bool(int idx, const char *key_, ...)
766 FORMAT_KEY(key_, key);
767 value = get_nth_value(idx, key);
768 retval = value && is_bool(value) ? !strcmp(value, "true") : false;
773 /* Returns the value numbered 'idx' of 'key', converted to an IP address in
774 * network byte order. Returns 0 if 'idx' is greater than or equal to
775 * cfg_count(key) or if the value 'idx' of 'key' is not a valid IP address (as
776 * determined by inet_aton()). */
778 cfg_get_ip(int idx, const char *key_, ...)
784 FORMAT_KEY(key_, key);
785 value = get_nth_value(idx, key);
786 if (!value || !inet_aton(value, &addr)) {
787 addr.s_addr = htonl(0);
793 /* Returns the value numbered 'idx' of 'key', converted to an MAC address in
794 * host byte order. Returns 0 if 'idx' is greater than or equal to
795 * cfg_count(key) or if the value 'idx' of 'key' is not a valid MAC address in
796 * the format "##:##:##:##:##:##". */
798 cfg_get_mac(int idx, const char *key_, ...)
800 uint8_t mac[ETH_ADDR_LEN];
804 FORMAT_KEY(key_, key);
805 value = get_nth_value(idx, key);
806 if (!value || !parse_mac(value, mac)) {
807 memset(mac, 0, sizeof mac);
810 return eth_addr_to_uint64(mac);
813 /* Returns the value numbered 'idx' of 'key', parsed as an datapath ID.
814 * Returns 0 if 'idx' is greater than or equal to cfg_count(key) or if the
815 * value 'idx' of 'key' is not a valid datapath ID consisting of exactly 12
816 * hexadecimal digits. */
818 cfg_get_dpid(int idx, const char *key_, ...)
824 FORMAT_KEY(key_, key);
825 value = get_nth_value(idx, key);
826 if (!value || !parse_dpid(value, &dpid)) {
833 /* Returns the value numbered 'idx' of 'key', converted to an integer. Returns
834 * -1 if 'idx' is greater than or equal to cfg_count(key) or if the value 'idx'
835 * of 'key' is not a valid integer between 0 and 4095. */
837 cfg_get_vlan(int idx, const char *key_, ...)
843 FORMAT_KEY(key_, key);
844 value = get_nth_value(idx, key);
845 if (value && is_int(value)) {
846 retval = atoi(value);
847 if (retval < 0 || retval > 4095) {
857 /* Fills 'svec' with all of the string values of 'key'. The caller must
858 * first initialize 'svec'. */
860 cfg_get_all_strings(struct svec *svec, const char *key_, ...)
865 FORMAT_KEY(key_, key);
867 for (p = find_key_le(key), q = find_key_ge(key); p < q; p++) {
868 svec_add(svec, extract_value(*p));
873 /* Fills 'svec' with all of the values of 'key' that are valid keys.
874 * Values of 'key' that are not valid keys are omitted. The caller
875 * must first initialize 'svec'. */
877 cfg_get_all_keys(struct svec *svec, const char *key_, ...)
882 FORMAT_KEY(key_, key);
884 for (p = find_key_le(key), q = find_key_ge(key); p < q; p++) {
885 const char *value = extract_value(*p);
887 svec_add(svec, value);
894 has_double_dot(const char *key, size_t len)
899 for (i = 0; i < len - 1; i++) {
900 if (key[i] == '.' && key[i + 1] == '.') {
909 is_valid_key(const char *key, size_t len,
910 const char *file_name, int line_number, const char *id)
913 VLOG_ERR("%s:%d: missing %s name", file_name, line_number, id);
915 } else if (key[0] == '.') {
916 VLOG_ERR("%s:%d: %s name \"%.*s\" begins with invalid character '.'",
917 file_name, line_number, id, (int) len, key);
919 } else if (key[len - 1] == '.') {
920 VLOG_ERR("%s:%d: %s name \"%.*s\" ends with invalid character '.'",
921 file_name, line_number, id, (int) len, key);
923 } else if (has_double_dot(key, len)) {
924 VLOG_ERR("%s:%d: %s name \"%.*s\" contains '..', which is not allowed",
925 file_name, line_number, id, (int) len, key);
933 parse_section(const char *file_name, int line_number, const char *s)
940 /* Skip [ and any white space. */
942 s += strspn(s, CC_SPACE);
944 /* Obtain the section name. */
945 len = strspn(s, CC_KEY);
946 if (!is_valid_key(s, len, file_name, line_number, "section")) {
949 ds_put_buffer(§ion, s, len);
952 /* Obtain the subsection name, if any. */
953 s += strspn(s, CC_SPACE);
956 len = strspn(s, CC_KEY);
957 if (!is_valid_key(s, len, file_name, line_number, "subsection")) {
960 ds_put_char(§ion, '.');
961 ds_put_buffer(§ion, s, len);
964 VLOG_ERR("%s:%d: missing '\"' following subsection name",
965 file_name, line_number);
969 s += strspn(s, CC_SPACE);
974 VLOG_ERR("%s:%d: missing ']' following section name",
975 file_name, line_number);
979 s += strspn(s, CC_SPACE);
981 VLOG_ERR("%s:%d: trailing garbage following ']'",
982 file_name, line_number);
986 return ds_cstr(§ion);
989 ds_destroy(§ion);
994 parse_setting(const char *file_name, int line_number, const char *section,
997 struct ds key = DS_EMPTY_INITIALIZER;
998 struct ds value = DS_EMPTY_INITIALIZER;
1002 ds_put_format(&key, "%s.", section);
1005 /* Obtain the key. */
1006 len = strspn(s, CC_KEY);
1008 VLOG_ERR("%s:%d: missing key name", file_name, line_number);
1011 if (!is_valid_key(s, len, file_name, line_number, "key")) {
1014 ds_put_buffer(&key, s, len);
1018 s += strspn(s, CC_SPACE);
1020 VLOG_ERR("%s:%d: missing '=' following key", file_name, line_number);
1024 s += strspn(s, CC_SPACE);
1026 /* Obtain the value. */
1027 ds_put_cstr(&value, s);
1028 while (value.length > 0 && strchr(CC_SPACE, ds_last(&value))) {
1032 /* Add the setting. */
1033 svec_add_nocopy(&cfg, xasprintf("%s=%s", ds_cstr(&key), ds_cstr(&value)));
1041 compare_key(const char *a, const char *b)
1044 int ac = *a == '\0' || *a == '=' ? INT_MAX : *a;
1045 int bc = *b == '\0' || *b == '=' ? INT_MAX : *b;
1047 return ac < bc ? -1 : 1;
1048 } else if (ac == INT_MAX) {
1056 /* Returns the address of the greatest configuration string with a key less
1057 * than or equal to 'key'. Returns the address of the null terminator if all
1058 * configuration strings are greater than 'key'. */
1060 find_key_le(const char *key)
1065 int half = len >> 1;
1066 int middle = low + half;
1067 if (compare_key(cfg.names[middle], key) < 0) {
1074 return &cfg.names[low];
1077 /* Returns the address of the least configuration string with a key greater
1078 * than or equal to 'key'. Returns the address of the null terminator if all
1079 * configuration strings are less than 'key'. */
1081 find_key_ge(const char *key)
1086 int half = len >> 1;
1087 int middle = low + half;
1088 if (compare_key(cfg.names[middle], key) > 0) {
1095 return &cfg.names[low];
1099 find_key(const char *key)
1101 char **p = find_key_le(key);
1102 return p < &cfg.names[cfg.n] && !compare_key(*p, key) ? *p : NULL;
1106 parse_mac(const char *s, uint8_t mac[6])
1108 return sscanf(s, "%"SCNx8":%"SCNx8":%"SCNx8":%"SCNx8":%"SCNx8":%"SCNx8,
1109 &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]) == 6;
1113 parse_dpid(const char *s, uint64_t *dpid)
1115 if (strlen(s) == 12 && strspn(s, "0123456789abcdefABCDEF") == 12) {
1116 *dpid = strtoll(s, NULL, 16);
1124 is_key(const char *s)
1126 /* XXX needs to check the same things as is_valid_key() too. */
1127 return *s && s[strspn(s, CC_KEY)] == '\0';
1131 is_int(const char *s)
1133 return *s && s[strspn(s, CC_DIGIT)] == '\0';
1137 is_bool(const char *s)
1139 return !strcmp(s, "true") || !strcmp(s, "false");
1143 extract_value(const char *key)
1145 const char *p = strchr(key, '=');
1146 return p ? p + 1 : NULL;
1150 get_nth_value(int idx, const char *key)
1152 char **p = find_key_le(key);
1153 char **q = find_key_ge(key);
1154 return idx < q - p ? extract_value(p[idx]) : NULL;
1158 is_type(const char *s, enum cfg_flags flags)
1160 uint8_t mac[ETH_ADDR_LEN];
1161 struct in_addr addr;
1164 return (flags & CFG_STRING
1165 || (flags & CFG_KEY && is_key(s))
1166 || (flags & CFG_INT && is_int(s))
1167 || (flags & CFG_BOOL && is_bool(s))
1168 || (flags & CFG_IP && inet_aton(s, &addr))
1169 || (flags & CFG_MAC && parse_mac(s, mac))
1170 || (flags & CFG_DPID && parse_dpid(s, &dpid)));