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);
146 struct sha1_ctx context;
150 for (i = 0; i < cfg.n; i++) {
151 sha1_update(&context, cfg.names[i], strlen(cfg.names[i]));
152 sha1_update(&context, "\n", 1);
154 sha1_final(&context, cfg_cookie);
159 /* Reads all of the configuration files or directories that have been added
160 * with cfg_add_file(), merges their content. Any previous configuration is
161 * replaced. Returns 0 if successful, otherwise a positive errno value. */
176 /* Save old configuration data and clear the active configuration. */
178 svec_swap(&old_cfg, &cfg);
180 /* Read new configuration. */
181 VLOG_DBG("reading configuration from %s", cfg_name);
183 file = fopen(cfg_name, "r");
185 VLOG_ERR("failed to open \"%s\": %s", cfg_name, strerror(errno));
192 while (!ds_get_line(&ds, file)) {
193 const char *s = ds_cstr(&ds);
194 size_t indent = strspn(s, CC_SPACE);
198 if (*s == '#' || *s == '\0') {
199 /* Ignore comments and lines that contain only white space. */
200 } else if (*s == '[') {
203 section = parse_section(cfg_name, line_number, s);
205 VLOG_ERR("%s:%d: ignoring indented section header",
206 cfg_name, line_number);
208 } else if (indent && !section) {
209 VLOG_ERR("%s:%d: ignoring indented line outside any section",
210 cfg_name, line_number);
216 parse_setting(cfg_name, line_number, section, s);
223 svec_terminate(&cfg);
228 if (VLOG_IS_DBG_ENABLED()) {
229 struct svec removed, added;
232 svec_diff(&old_cfg, &cfg, &removed, NULL, &added);
233 if (removed.n || added.n) {
234 VLOG_DBG("configuration changes:");
235 for (i = 0; i < removed.n; i++) {
236 VLOG_DBG("-%s", removed.names[i]);
238 for (i = 0; i < added.n; i++) {
239 VLOG_DBG("+%s", added.names[i]);
242 VLOG_DBG("configuration unchanged");
244 svec_destroy(&added);
245 svec_destroy(&removed);
247 svec_destroy(&old_cfg);
254 /* Fills 'svec' with the entire configuration file. */
256 cfg_get_all(struct svec *svec)
259 svec_append(svec, &cfg);
263 cfg_get_cookie(uint8_t *cookie)
269 memcpy(cookie, cfg_cookie, sizeof(cfg_cookie));
277 COVERAGE_INC(cfg_unlock);
284 open_lockfile(const char *name)
287 /* Try to open an existing lock file. */
288 int fd = open(name, O_RDWR);
291 } else if (errno != ENOENT) {
292 VLOG_WARN("%s: failed to open lock file: %s",
293 name, strerror(errno));
297 /* Try to create a new lock file. */
298 VLOG_INFO("%s: lock file does not exist, creating", name);
299 fd = open(name, O_RDWR | O_CREAT | O_EXCL, 0600);
302 } else if (errno != EEXIST) {
303 VLOG_WARN("%s: failed to create lock file: %s",
304 name, strerror(errno));
308 /* Someone else created the lock file. Try again. */
313 try_lock(int fd, bool block)
316 memset(&l, 0, sizeof l);
318 l.l_whence = SEEK_SET;
321 return fcntl(fd, block ? F_SETLKW : F_SETLK, &l) == -1 ? errno : 0;
324 /* Locks the configuration file against modification by other processes and
325 * re-reads it from disk.
327 * The 'timeout' specifies the maximum number of milliseconds to wait for the
328 * config file to become free. Use 0 to avoid waiting or INT_MAX to wait
331 * Returns 0 on success, otherwise a positive errno value. */
333 cfg_lock(uint8_t *cookie, int timeout)
336 long long int elapsed = 0;
338 uint8_t curr_cookie[CFG_COOKIE_LEN];
341 COVERAGE_INC(cfg_lock);
348 /* Open lock file. */
349 fd = open_lockfile(lock_name);
354 /* Try to lock it. This will block (if 'timeout' > 0). */
355 error = try_lock(fd, timeout > 0);
357 elapsed = time_msec() - start;
363 /* Lock failed. Close the lock file and reopen it on the next
364 * iteration, just in case someone deletes it underneath us (even
365 * though that should not happen). */
367 if (error != EINTR) {
368 /* Hard error, give up. */
369 COVERAGE_INC(cfg_lock_error);
370 VLOG_WARN("%s: failed to lock file "
371 "(after %lld ms, with %d-ms timeout): %s",
372 lock_name, elapsed, timeout, strerror(error));
376 /* Probably, the periodic timer set up by time_init() woke up us. Just
377 * check whether it's time to give up. */
378 if (timeout != INT_MAX && elapsed >= timeout) {
379 COVERAGE_INC(cfg_lock_timeout);
380 VLOG_WARN("%s: giving up on lock file after %lld ms",
384 COVERAGE_INC(cfg_lock_retry);
387 VLOG_WARN("%s: waited %lld ms for lock file", lock_name, elapsed);
394 cfg_get_cookie(curr_cookie);
396 if (memcmp(curr_cookie, cookie, sizeof *curr_cookie)) {
397 /* Configuration has changed, so reject. */
407 do_write_config(const void *data, size_t len)
412 file = fopen(tmp_name, "w");
414 VLOG_WARN("could not open %s for writing: %s",
415 tmp_name, strerror(errno));
419 fwrite(data, 1, len, file);
421 /* This is essentially equivalent to:
422 * error = ferror(file) || fflush(file) || fclose(file);
423 * but it doesn't short-circuit, so that it always closes 'file'. */
424 error = ferror(file);
425 error = fflush(file) || error;
426 error = fclose(file) || error;
428 VLOG_WARN("problem writing to %s: %s", tmp_name, strerror(errno));
432 if (rename(tmp_name, cfg_name) < 0) {
433 VLOG_WARN("could not rename %s to %s: %s",
434 tmp_name, cfg_name, strerror(errno));
443 /* Write the current configuration into the configuration file. Returns 0 if
444 * successful, otherwise a negative errno value. */
453 ? svec_join(&cfg, "\n", "\n")
454 : xstrdup("# This file intentionally left blank.\n"));
455 retval = do_write_config(content, strlen(content));
462 cfg_write_data(uint8_t *data, size_t len)
464 int retval = do_write_config(data, len);
471 /* Returns true if the configuration has changed since the last time it was
472 * read or written. */
480 cfg_buf_put(struct ofpbuf *buffer)
484 for (i = 0; i < cfg.n; i++) {
485 ofpbuf_put(buffer, cfg.names[i], strlen(cfg.names[i]));
486 ofpbuf_put(buffer, "\n", 1);
490 /* Formats the printf()-style format string in the parameter 'format', which
491 * must be the function's last parameter, into string variable 'dst'. The
492 * function is responsible for freeing 'dst'. */
493 #define FORMAT_KEY(FORMAT, DST) \
496 va_start(args__, FORMAT); \
497 (DST) = xvasprintf(FORMAT, args__); \
501 /* Returns true if the configuration includes a key named 'key'. */
503 cfg_has(const char *key_, ...)
508 FORMAT_KEY(key_, key);
509 retval = find_key(key) != NULL;
515 cfg_is_valid(enum cfg_flags flags, const char *key_, ...)
517 char *key, **first, **last, **p;
521 FORMAT_KEY(key_, key);
522 first = find_key_le(key);
523 last = find_key_ge(key);
525 retval = ((!(flags & CFG_REQUIRED) || n)
526 && (!(flags & CFG_MULTIPLE) || n <= 1));
527 for (p = first; retval && p < last; p++) {
528 retval = is_type(strchr(*p, '=') + 1, flags);
534 /* Returns true if the configuration includes at least one key whose name
535 * begins with 'section' followed by a dot. */
537 cfg_has_section(const char *section_, ...)
545 va_start(args, section_);
546 ds_put_format_valist(§ion, section_, args);
547 ds_put_char(§ion, '.');
550 for (p = cfg.names; *p; p++) { /* XXX this is inefficient */
551 if (!strncmp(section.string, *p, section.length)) {
557 ds_destroy(§ion);
561 /* Returns the number of values for the given 'key'. The return value is 0 if
562 * no values exist for 'key'. */
564 cfg_count(const char *key_, ...)
569 FORMAT_KEY(key_, key);
570 retval = find_key_ge(key) - find_key_le(key);
575 /* Fills 'svec' with all of the immediate subsections of 'section'. For
576 * example, if 'section' is "bridge" and keys bridge.a, bridge.b, bridge.b.c,
577 * and bridge.c.x.y.z exist, then 'svec' would be initialized to a, b, and
578 * c. The caller must first initialize 'svec'. */
580 cfg_get_subsections(struct svec *svec, const char *section_, ...)
587 va_start(args, section_);
588 ds_put_format_valist(§ion, section_, args);
589 ds_put_char(§ion, '.');
593 for (p = cfg.names; *p; p++) { /* XXX this is inefficient */
594 if (!strncmp(section.string, *p, section.length)) {
595 const char *ss = *p + section.length;
596 size_t ss_len = strcspn(ss, ".=");
597 svec_add_nocopy(svec, xmemdup0(ss, ss_len));
601 ds_destroy(§ion);
605 cfg_add_entry(const char *entry_, ...)
609 FORMAT_KEY(entry_, entry);
610 svec_add_nocopy(&cfg, entry);
612 svec_terminate(&cfg);
617 cfg_del_entry(const char *entry_, ...)
621 FORMAT_KEY(entry_, entry);
622 svec_del(&cfg, entry);
623 svec_terminate(&cfg);
629 cfg_del_section(const char *section_, ...)
636 va_start(args, section_);
637 ds_put_format_valist(§ion, section_, args);
638 ds_put_char(§ion, '.');
641 for (p = cfg.names; *p; p++) {
642 if (!strncmp(section.string, *p, section.length)) {
648 svec_terminate(&cfg);
650 ds_destroy(§ion);
655 cfg_del_match(const char *pattern_, ...)
657 bool matched = false;
661 FORMAT_KEY(pattern_, pattern);
663 for (p = cfg.names; *p; p++) {
664 if (!fnmatch(pattern, *p, 0)) {
672 svec_terminate(&cfg);
679 /* Fills 'svec' with all of the key-value pairs that match shell glob pattern
680 * 'pattern'. The caller must first initialize 'svec'. */
682 cfg_get_matches(struct svec *svec, const char *pattern_, ...)
687 FORMAT_KEY(pattern_, pattern);
689 for (p = cfg.names; *p; p++) {
690 if (!fnmatch(pattern, *p, 0)) {
698 /* Fills 'svec' with all of the key-value pairs that have sections that
699 * begin with 'section'. The caller must first initialize 'svec'. */
701 cfg_get_section(struct svec *svec, const char *section_, ...)
708 va_start(args, section_);
709 ds_put_format_valist(§ion, section_, args);
710 ds_put_char(§ion, '.');
713 for (p = cfg.names; *p; p++) { /* XXX this is inefficient */
714 if (!strncmp(section.string, *p, section.length)) {
718 ds_destroy(§ion);
721 /* Returns the value numbered 'idx' of 'key'. Returns a null pointer if 'idx'
722 * is greater than or equal to cfg_count(key). The caller must not modify or
723 * free the returned string or retain its value beyond the next call to
726 cfg_get_string(int idx, const char *key_, ...)
731 FORMAT_KEY(key_, key);
732 retval = get_nth_value(idx, key);
737 /* Returns the value numbered 'idx' of 'key'. Returns a null pointer if 'idx'
738 * is greater than or equal to cfg_count(key) or if the value 'idx' of 'key' is
739 * not a valid key. The caller must not modify or free the returned string or
740 * retain its value beyond the next call to cfg_read(). */
742 cfg_get_key(int idx, const char *key_, ...)
744 const char *value, *retval;
747 FORMAT_KEY(key_, key);
748 value = get_nth_value(idx, key);
749 retval = value && is_key(value) ? value : NULL;
754 /* Returns the value numbered 'idx' of 'key', converted to an integer. Returns
755 * 0 if 'idx' is greater than or equal to cfg_count(key) or if the value 'idx'
756 * of 'key' is not a valid integer. */
758 cfg_get_int(int idx, const char *key_, ...)
764 FORMAT_KEY(key_, key);
765 value = get_nth_value(idx, key);
766 retval = value && is_int(value) ? atoi(value) : 0;
771 /* Returns the value numbered 'idx' of 'key', converted to a boolean value.
772 * Returns false if 'idx' is greater than or equal to cfg_count(key) or if the
773 * value 'idx' of 'key' is not a valid boolean. */
775 cfg_get_bool(int idx, const char *key_, ...)
781 FORMAT_KEY(key_, key);
782 value = get_nth_value(idx, key);
783 retval = value && is_bool(value) ? !strcmp(value, "true") : false;
788 /* Returns the value numbered 'idx' of 'key', converted to an IP address in
789 * network byte order. Returns 0 if 'idx' is greater than or equal to
790 * cfg_count(key) or if the value 'idx' of 'key' is not a valid IP address (as
791 * determined by inet_aton()). */
793 cfg_get_ip(int idx, const char *key_, ...)
799 FORMAT_KEY(key_, key);
800 value = get_nth_value(idx, key);
801 if (!value || !inet_aton(value, &addr)) {
802 addr.s_addr = htonl(0);
808 /* Returns the value numbered 'idx' of 'key', converted to an MAC address in
809 * host byte order. Returns 0 if 'idx' is greater than or equal to
810 * cfg_count(key) or if the value 'idx' of 'key' is not a valid MAC address in
811 * the format "##:##:##:##:##:##". */
813 cfg_get_mac(int idx, const char *key_, ...)
815 uint8_t mac[ETH_ADDR_LEN];
819 FORMAT_KEY(key_, key);
820 value = get_nth_value(idx, key);
821 if (!value || !parse_mac(value, mac)) {
822 memset(mac, 0, sizeof mac);
825 return eth_addr_to_uint64(mac);
828 /* Returns the value numbered 'idx' of 'key', parsed as an datapath ID.
829 * Returns 0 if 'idx' is greater than or equal to cfg_count(key) or if the
830 * value 'idx' of 'key' is not a valid datapath ID consisting of exactly 12
831 * hexadecimal digits. */
833 cfg_get_dpid(int idx, const char *key_, ...)
839 FORMAT_KEY(key_, key);
840 value = get_nth_value(idx, key);
841 if (!value || !parse_dpid(value, &dpid)) {
848 /* Returns the value numbered 'idx' of 'key', converted to an integer. Returns
849 * -1 if 'idx' is greater than or equal to cfg_count(key) or if the value 'idx'
850 * of 'key' is not a valid integer between 0 and 4095. */
852 cfg_get_vlan(int idx, const char *key_, ...)
858 FORMAT_KEY(key_, key);
859 value = get_nth_value(idx, key);
860 if (value && is_int(value)) {
861 retval = atoi(value);
862 if (retval < 0 || retval > 4095) {
872 /* Fills 'svec' with all of the string values of 'key'. The caller must
873 * first initialize 'svec'. */
875 cfg_get_all_strings(struct svec *svec, const char *key_, ...)
880 FORMAT_KEY(key_, key);
882 for (p = find_key_le(key), q = find_key_ge(key); p < q; p++) {
883 svec_add(svec, extract_value(*p));
888 /* Fills 'svec' with all of the values of 'key' that are valid keys.
889 * Values of 'key' that are not valid keys are omitted. The caller
890 * must first initialize 'svec'. */
892 cfg_get_all_keys(struct svec *svec, const char *key_, ...)
897 FORMAT_KEY(key_, key);
899 for (p = find_key_le(key), q = find_key_ge(key); p < q; p++) {
900 const char *value = extract_value(*p);
902 svec_add(svec, value);
909 has_double_dot(const char *key, size_t len)
914 for (i = 0; i < len - 1; i++) {
915 if (key[i] == '.' && key[i + 1] == '.') {
924 is_valid_key(const char *key, size_t len,
925 const char *file_name, int line_number, const char *id)
928 VLOG_ERR("%s:%d: missing %s name", file_name, line_number, id);
930 } else if (key[0] == '.') {
931 VLOG_ERR("%s:%d: %s name \"%.*s\" begins with invalid character '.'",
932 file_name, line_number, id, (int) len, key);
934 } else if (key[len - 1] == '.') {
935 VLOG_ERR("%s:%d: %s name \"%.*s\" ends with invalid character '.'",
936 file_name, line_number, id, (int) len, key);
938 } else if (has_double_dot(key, len)) {
939 VLOG_ERR("%s:%d: %s name \"%.*s\" contains '..', which is not allowed",
940 file_name, line_number, id, (int) len, key);
948 parse_section(const char *file_name, int line_number, const char *s)
955 /* Skip [ and any white space. */
957 s += strspn(s, CC_SPACE);
959 /* Obtain the section name. */
960 len = strspn(s, CC_KEY);
961 if (!is_valid_key(s, len, file_name, line_number, "section")) {
964 ds_put_buffer(§ion, s, len);
967 /* Obtain the subsection name, if any. */
968 s += strspn(s, CC_SPACE);
971 len = strspn(s, CC_KEY);
972 if (!is_valid_key(s, len, file_name, line_number, "subsection")) {
975 ds_put_char(§ion, '.');
976 ds_put_buffer(§ion, s, len);
979 VLOG_ERR("%s:%d: missing '\"' following subsection name",
980 file_name, line_number);
984 s += strspn(s, CC_SPACE);
989 VLOG_ERR("%s:%d: missing ']' following section name",
990 file_name, line_number);
994 s += strspn(s, CC_SPACE);
996 VLOG_ERR("%s:%d: trailing garbage following ']'",
997 file_name, line_number);
1001 return ds_cstr(§ion);
1004 ds_destroy(§ion);
1009 parse_setting(const char *file_name, int line_number, const char *section,
1012 struct ds key = DS_EMPTY_INITIALIZER;
1013 struct ds value = DS_EMPTY_INITIALIZER;
1017 ds_put_format(&key, "%s.", section);
1020 /* Obtain the key. */
1021 len = strspn(s, CC_KEY);
1023 VLOG_ERR("%s:%d: missing key name", file_name, line_number);
1026 if (!is_valid_key(s, len, file_name, line_number, "key")) {
1029 ds_put_buffer(&key, s, len);
1033 s += strspn(s, CC_SPACE);
1035 VLOG_ERR("%s:%d: missing '=' following key", file_name, line_number);
1039 s += strspn(s, CC_SPACE);
1041 /* Obtain the value. */
1042 ds_put_cstr(&value, s);
1043 while (value.length > 0 && strchr(CC_SPACE, ds_last(&value))) {
1047 /* Add the setting. */
1048 svec_add_nocopy(&cfg, xasprintf("%s=%s", ds_cstr(&key), ds_cstr(&value)));
1056 compare_key(const char *a, const char *b)
1059 int ac = *a == '\0' || *a == '=' ? INT_MAX : *a;
1060 int bc = *b == '\0' || *b == '=' ? INT_MAX : *b;
1062 return ac < bc ? -1 : 1;
1063 } else if (ac == INT_MAX) {
1071 /* Returns the address of the greatest configuration string with a key less
1072 * than or equal to 'key'. Returns the address of the null terminator if all
1073 * configuration strings are greater than 'key'. */
1075 find_key_le(const char *key)
1080 int half = len >> 1;
1081 int middle = low + half;
1082 if (compare_key(cfg.names[middle], key) < 0) {
1089 return &cfg.names[low];
1092 /* Returns the address of the least configuration string with a key greater
1093 * than or equal to 'key'. Returns the address of the null terminator if all
1094 * configuration strings are less than 'key'. */
1096 find_key_ge(const char *key)
1101 int half = len >> 1;
1102 int middle = low + half;
1103 if (compare_key(cfg.names[middle], key) > 0) {
1110 return &cfg.names[low];
1114 find_key(const char *key)
1116 char **p = find_key_le(key);
1117 return p < &cfg.names[cfg.n] && !compare_key(*p, key) ? *p : NULL;
1121 parse_mac(const char *s, uint8_t mac[6])
1123 return (sscanf(s, ETH_ADDR_SCAN_FMT, ETH_ADDR_SCAN_ARGS(mac))
1124 == ETH_ADDR_SCAN_COUNT);
1128 parse_dpid(const char *s, uint64_t *dpid)
1130 if (strlen(s) == 12 && strspn(s, "0123456789abcdefABCDEF") == 12) {
1131 *dpid = strtoll(s, NULL, 16);
1139 is_key(const char *s)
1141 /* XXX needs to check the same things as is_valid_key() too. */
1142 return *s && s[strspn(s, CC_KEY)] == '\0';
1146 is_int(const char *s)
1148 return *s && s[strspn(s, CC_DIGIT)] == '\0';
1152 is_bool(const char *s)
1154 return !strcmp(s, "true") || !strcmp(s, "false");
1158 extract_value(const char *key)
1160 const char *p = strchr(key, '=');
1161 return p ? p + 1 : NULL;
1165 get_nth_value(int idx, const char *key)
1167 char **p = find_key_le(key);
1168 char **q = find_key_ge(key);
1169 return idx < q - p ? extract_value(p[idx]) : NULL;
1173 is_type(const char *s, enum cfg_flags flags)
1175 uint8_t mac[ETH_ADDR_LEN];
1176 struct in_addr addr;
1179 return (flags & CFG_STRING
1180 || (flags & CFG_KEY && is_key(s))
1181 || (flags & CFG_INT && is_int(s))
1182 || (flags & CFG_BOOL && is_bool(s))
1183 || (flags & CFG_IP && inet_aton(s, &addr))
1184 || (flags & CFG_MAC && parse_mac(s, mac))
1185 || (flags & CFG_DPID && parse_dpid(s, &dpid)));