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)
335 long long int start = time_msec();
336 long long int elapsed = 0;
338 uint8_t curr_cookie[CFG_COOKIE_LEN];
341 COVERAGE_INC(cfg_lock);
345 /* Open lock file. */
346 fd = open_lockfile(lock_name);
351 /* Try to lock it. This will block (if 'timeout' > 0). */
352 error = try_lock(fd, timeout > 0);
354 elapsed = time_msec() - start;
360 /* Lock failed. Close the lock file and reopen it on the next
361 * iteration, just in case someone deletes it underneath us (even
362 * though that should not happen). */
364 if (error != EINTR) {
365 /* Hard error, give up. */
366 COVERAGE_INC(cfg_lock_error);
367 VLOG_WARN("%s: failed to lock file "
368 "(after %lld ms, with %d-ms timeout): %s",
369 lock_name, elapsed, timeout, strerror(error));
373 /* Probably, the periodic timer set up by time_init() woke up us. Just
374 * check whether it's time to give up. */
375 if (timeout != INT_MAX && elapsed >= timeout) {
376 COVERAGE_INC(cfg_lock_timeout);
377 VLOG_WARN("%s: giving up on lock file after %lld ms",
381 COVERAGE_INC(cfg_lock_retry);
384 VLOG_WARN("%s: waited %lld ms for lock file", lock_name, elapsed);
391 cfg_get_cookie(curr_cookie);
393 if (memcmp(curr_cookie, cookie, sizeof *curr_cookie)) {
394 /* Configuration has changed, so reject. */
404 do_write_config(const void *data, size_t len)
409 file = fopen(tmp_name, "w");
411 VLOG_WARN("could not open %s for writing: %s",
412 tmp_name, strerror(errno));
416 fwrite(data, 1, len, file);
418 /* This is essentially equivalent to:
419 * error = ferror(file) || fflush(file) || fclose(file);
420 * but it doesn't short-circuit, so that it always closes 'file'. */
421 error = ferror(file);
422 error = fflush(file) || error;
423 error = fclose(file) || error;
425 VLOG_WARN("problem writing to %s: %s", tmp_name, strerror(errno));
429 if (rename(tmp_name, cfg_name) < 0) {
430 VLOG_WARN("could not rename %s to %s: %s",
431 tmp_name, cfg_name, strerror(errno));
440 /* Write the current configuration into the configuration file. Returns 0 if
441 * successful, otherwise a negative errno value. */
450 ? svec_join(&cfg, "\n", "\n")
451 : xstrdup("# This file intentionally left blank.\n"));
452 retval = do_write_config(content, strlen(content));
459 cfg_write_data(uint8_t *data, size_t len)
461 int retval = do_write_config(data, len);
468 /* Returns true if the configuration has changed since the last time it was
469 * read or written. */
477 cfg_buf_put(struct ofpbuf *buffer)
481 for (i = 0; i < cfg.n; i++) {
482 ofpbuf_put(buffer, cfg.names[i], strlen(cfg.names[i]));
483 ofpbuf_put(buffer, "\n", 1);
487 /* Formats the printf()-style format string in the parameter 'format', which
488 * must be the function's last parameter, into string variable 'dst'. The
489 * function is responsible for freeing 'dst'. */
490 #define FORMAT_KEY(FORMAT, DST) \
493 va_start(args__, FORMAT); \
494 (DST) = xvasprintf(FORMAT, args__); \
498 /* Returns true if the configuration includes a key named 'key'. */
500 cfg_has(const char *key_, ...)
505 FORMAT_KEY(key_, key);
506 retval = find_key(key) != NULL;
512 cfg_is_valid(enum cfg_flags flags, const char *key_, ...)
514 char *key, **first, **last, **p;
518 FORMAT_KEY(key_, key);
519 first = find_key_le(key);
520 last = find_key_ge(key);
522 retval = ((!(flags & CFG_REQUIRED) || n)
523 && (!(flags & CFG_MULTIPLE) || n <= 1));
524 for (p = first; retval && p < last; p++) {
525 retval = is_type(strchr(*p, '=') + 1, flags);
531 /* Returns true if the configuration includes at least one key whose name
532 * begins with 'section' followed by a dot. */
534 cfg_has_section(const char *section_, ...)
542 va_start(args, section_);
543 ds_put_format_valist(§ion, section_, args);
544 ds_put_char(§ion, '.');
547 for (p = cfg.names; *p; p++) { /* XXX this is inefficient */
548 if (!strncmp(section.string, *p, section.length)) {
554 ds_destroy(§ion);
558 /* Returns the number of values for the given 'key'. The return value is 0 if
559 * no values exist for 'key'. */
561 cfg_count(const char *key_, ...)
566 FORMAT_KEY(key_, key);
567 retval = find_key_ge(key) - find_key_le(key);
572 /* Fills 'svec' with all of the immediate subsections of 'section'. For
573 * example, if 'section' is "bridge" and keys bridge.a, bridge.b, bridge.b.c,
574 * and bridge.c.x.y.z exist, then 'svec' would be initialized to a, b, and
575 * c. The caller must first initialize 'svec'. */
577 cfg_get_subsections(struct svec *svec, const char *section_, ...)
584 va_start(args, section_);
585 ds_put_format_valist(§ion, section_, args);
586 ds_put_char(§ion, '.');
590 for (p = cfg.names; *p; p++) { /* XXX this is inefficient */
591 if (!strncmp(section.string, *p, section.length)) {
592 const char *ss = *p + section.length;
593 size_t ss_len = strcspn(ss, ".=");
594 svec_add_nocopy(svec, xmemdup0(ss, ss_len));
598 ds_destroy(§ion);
602 cfg_add_entry(const char *entry_, ...)
606 FORMAT_KEY(entry_, entry);
607 svec_add_nocopy(&cfg, entry);
609 svec_terminate(&cfg);
614 cfg_del_entry(const char *entry_, ...)
618 FORMAT_KEY(entry_, entry);
619 svec_del(&cfg, entry);
620 svec_terminate(&cfg);
626 cfg_del_section(const char *section_, ...)
633 va_start(args, section_);
634 ds_put_format_valist(§ion, section_, args);
635 ds_put_char(§ion, '.');
638 for (p = cfg.names; *p; p++) {
639 if (!strncmp(section.string, *p, section.length)) {
645 svec_terminate(&cfg);
647 ds_destroy(§ion);
652 cfg_del_match(const char *pattern_, ...)
654 bool matched = false;
658 FORMAT_KEY(pattern_, pattern);
660 for (p = cfg.names; *p; p++) {
661 if (!fnmatch(pattern, *p, 0)) {
669 svec_terminate(&cfg);
676 /* Fills 'svec' with all of the key-value pairs that have sections that
677 * begin with 'section'. The caller must first initialize 'svec'. */
679 cfg_get_section(struct svec *svec, const char *section_, ...)
686 va_start(args, section_);
687 ds_put_format_valist(§ion, section_, args);
688 ds_put_char(§ion, '.');
691 for (p = cfg.names; *p; p++) { /* XXX this is inefficient */
692 if (!strncmp(section.string, *p, section.length)) {
696 ds_destroy(§ion);
699 /* Returns the value numbered 'idx' of 'key'. Returns a null pointer if 'idx'
700 * is greater than or equal to cfg_count(key). The caller must not modify or
701 * free the returned string or retain its value beyond the next call to
704 cfg_get_string(int idx, const char *key_, ...)
709 FORMAT_KEY(key_, key);
710 retval = get_nth_value(idx, key);
715 /* Returns the value numbered 'idx' of 'key'. Returns a null pointer if 'idx'
716 * is greater than or equal to cfg_count(key) or if the value 'idx' of 'key' is
717 * not a valid key. The caller must not modify or free the returned string or
718 * retain its value beyond the next call to cfg_read(). */
720 cfg_get_key(int idx, const char *key_, ...)
722 const char *value, *retval;
725 FORMAT_KEY(key_, key);
726 value = get_nth_value(idx, key);
727 retval = value && is_key(value) ? value : NULL;
732 /* Returns the value numbered 'idx' of 'key', converted to an integer. Returns
733 * 0 if 'idx' is greater than or equal to cfg_count(key) or if the value 'idx'
734 * of 'key' is not a valid integer. */
736 cfg_get_int(int idx, const char *key_, ...)
742 FORMAT_KEY(key_, key);
743 value = get_nth_value(idx, key);
744 retval = value && is_int(value) ? atoi(value) : 0;
749 /* Returns the value numbered 'idx' of 'key', converted to a boolean value.
750 * Returns false if 'idx' is greater than or equal to cfg_count(key) or if the
751 * value 'idx' of 'key' is not a valid boolean. */
753 cfg_get_bool(int idx, const char *key_, ...)
759 FORMAT_KEY(key_, key);
760 value = get_nth_value(idx, key);
761 retval = value && is_bool(value) ? !strcmp(value, "true") : false;
766 /* Returns the value numbered 'idx' of 'key', converted to an IP address in
767 * network byte order. Returns 0 if 'idx' is greater than or equal to
768 * cfg_count(key) or if the value 'idx' of 'key' is not a valid IP address (as
769 * determined by inet_aton()). */
771 cfg_get_ip(int idx, const char *key_, ...)
777 FORMAT_KEY(key_, key);
778 value = get_nth_value(idx, key);
779 if (!value || !inet_aton(value, &addr)) {
780 addr.s_addr = htonl(0);
786 /* Returns the value numbered 'idx' of 'key', converted to an MAC address in
787 * host byte order. Returns 0 if 'idx' is greater than or equal to
788 * cfg_count(key) or if the value 'idx' of 'key' is not a valid MAC address in
789 * the format "##:##:##:##:##:##". */
791 cfg_get_mac(int idx, const char *key_, ...)
793 uint8_t mac[ETH_ADDR_LEN];
797 FORMAT_KEY(key_, key);
798 value = get_nth_value(idx, key);
799 if (!value || !parse_mac(value, mac)) {
800 memset(mac, 0, sizeof mac);
803 return eth_addr_to_uint64(mac);
806 /* Returns the value numbered 'idx' of 'key', parsed as an datapath ID.
807 * Returns 0 if 'idx' is greater than or equal to cfg_count(key) or if the
808 * value 'idx' of 'key' is not a valid datapath ID consisting of exactly 12
809 * hexadecimal digits. */
811 cfg_get_dpid(int idx, const char *key_, ...)
817 FORMAT_KEY(key_, key);
818 value = get_nth_value(idx, key);
819 if (!value || !parse_dpid(value, &dpid)) {
826 /* Returns the value numbered 'idx' of 'key', converted to an integer. Returns
827 * -1 if 'idx' is greater than or equal to cfg_count(key) or if the value 'idx'
828 * of 'key' is not a valid integer between 0 and 4095. */
830 cfg_get_vlan(int idx, const char *key_, ...)
836 FORMAT_KEY(key_, key);
837 value = get_nth_value(idx, key);
838 if (value && is_int(value)) {
839 retval = atoi(value);
840 if (retval < 0 || retval > 4095) {
850 /* Fills 'svec' with all of the string values of 'key'. The caller must
851 * first initialize 'svec'. */
853 cfg_get_all_strings(struct svec *svec, const char *key_, ...)
858 FORMAT_KEY(key_, key);
860 for (p = find_key_le(key), q = find_key_ge(key); p < q; p++) {
861 svec_add(svec, extract_value(*p));
866 /* Fills 'svec' with all of the values of 'key' that are valid keys.
867 * Values of 'key' that are not valid keys are omitted. The caller
868 * must first initialize 'svec'. */
870 cfg_get_all_keys(struct svec *svec, const char *key_, ...)
875 FORMAT_KEY(key_, key);
877 for (p = find_key_le(key), q = find_key_ge(key); p < q; p++) {
878 const char *value = extract_value(*p);
880 svec_add(svec, value);
887 has_double_dot(const char *key, size_t len)
892 for (i = 0; i < len - 1; i++) {
893 if (key[i] == '.' && key[i + 1] == '.') {
902 is_valid_key(const char *key, size_t len,
903 const char *file_name, int line_number, const char *id)
906 VLOG_ERR("%s:%d: missing %s name", file_name, line_number, id);
908 } else if (key[0] == '.') {
909 VLOG_ERR("%s:%d: %s name \"%.*s\" begins with invalid character '.'",
910 file_name, line_number, id, (int) len, key);
912 } else if (key[len - 1] == '.') {
913 VLOG_ERR("%s:%d: %s name \"%.*s\" ends with invalid character '.'",
914 file_name, line_number, id, (int) len, key);
916 } else if (has_double_dot(key, len)) {
917 VLOG_ERR("%s:%d: %s name \"%.*s\" contains '..', which is not allowed",
918 file_name, line_number, id, (int) len, key);
926 parse_section(const char *file_name, int line_number, const char *s)
933 /* Skip [ and any white space. */
935 s += strspn(s, CC_SPACE);
937 /* Obtain the section name. */
938 len = strspn(s, CC_KEY);
939 if (!is_valid_key(s, len, file_name, line_number, "section")) {
942 ds_put_buffer(§ion, s, len);
945 /* Obtain the subsection name, if any. */
946 s += strspn(s, CC_SPACE);
949 len = strspn(s, CC_KEY);
950 if (!is_valid_key(s, len, file_name, line_number, "subsection")) {
953 ds_put_char(§ion, '.');
954 ds_put_buffer(§ion, s, len);
957 VLOG_ERR("%s:%d: missing '\"' following subsection name",
958 file_name, line_number);
962 s += strspn(s, CC_SPACE);
967 VLOG_ERR("%s:%d: missing ']' following section name",
968 file_name, line_number);
972 s += strspn(s, CC_SPACE);
974 VLOG_ERR("%s:%d: trailing garbage following ']'",
975 file_name, line_number);
979 return ds_cstr(§ion);
982 ds_destroy(§ion);
987 parse_setting(const char *file_name, int line_number, const char *section,
990 struct ds key = DS_EMPTY_INITIALIZER;
991 struct ds value = DS_EMPTY_INITIALIZER;
995 ds_put_format(&key, "%s.", section);
998 /* Obtain the key. */
999 len = strspn(s, CC_KEY);
1001 VLOG_ERR("%s:%d: missing key name", file_name, line_number);
1004 if (!is_valid_key(s, len, file_name, line_number, "key")) {
1007 ds_put_buffer(&key, s, len);
1011 s += strspn(s, CC_SPACE);
1013 VLOG_ERR("%s:%d: missing '=' following key", file_name, line_number);
1017 s += strspn(s, CC_SPACE);
1019 /* Obtain the value. */
1020 ds_put_cstr(&value, s);
1021 while (value.length > 0 && strchr(CC_SPACE, ds_last(&value))) {
1025 /* Add the setting. */
1026 svec_add_nocopy(&cfg, xasprintf("%s=%s", ds_cstr(&key), ds_cstr(&value)));
1034 compare_key(const char *a, const char *b)
1037 int ac = *a == '\0' || *a == '=' ? INT_MAX : *a;
1038 int bc = *b == '\0' || *b == '=' ? INT_MAX : *b;
1040 return ac < bc ? -1 : 1;
1041 } else if (ac == INT_MAX) {
1049 /* Returns the address of the greatest configuration string with a key less
1050 * than or equal to 'key'. Returns the address of the null terminator if all
1051 * configuration strings are greater than 'key'. */
1053 find_key_le(const char *key)
1058 int half = len >> 1;
1059 int middle = low + half;
1060 if (compare_key(cfg.names[middle], key) < 0) {
1067 return &cfg.names[low];
1070 /* Returns the address of the least configuration string with a key greater
1071 * than or equal to 'key'. Returns the address of the null terminator if all
1072 * configuration strings are less than 'key'. */
1074 find_key_ge(const char *key)
1079 int half = len >> 1;
1080 int middle = low + half;
1081 if (compare_key(cfg.names[middle], key) > 0) {
1088 return &cfg.names[low];
1092 find_key(const char *key)
1094 char **p = find_key_le(key);
1095 return p < &cfg.names[cfg.n] && !compare_key(*p, key) ? *p : NULL;
1099 parse_mac(const char *s, uint8_t mac[6])
1101 return sscanf(s, "%"SCNx8":%"SCNx8":%"SCNx8":%"SCNx8":%"SCNx8":%"SCNx8,
1102 &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]) == 6;
1106 parse_dpid(const char *s, uint64_t *dpid)
1108 if (strlen(s) == 12 && strspn(s, "0123456789abcdefABCDEF") == 12) {
1109 *dpid = strtoll(s, NULL, 16);
1117 is_key(const char *s)
1119 /* XXX needs to check the same things as is_valid_key() too. */
1120 return *s && s[strspn(s, CC_KEY)] == '\0';
1124 is_int(const char *s)
1126 return *s && s[strspn(s, CC_DIGIT)] == '\0';
1130 is_bool(const char *s)
1132 return !strcmp(s, "true") || !strcmp(s, "false");
1136 extract_value(const char *key)
1138 const char *p = strchr(key, '=');
1139 return p ? p + 1 : NULL;
1143 get_nth_value(int idx, const char *key)
1145 char **p = find_key_le(key);
1146 char **q = find_key_ge(key);
1147 return idx < q - p ? extract_value(p[idx]) : NULL;
1151 is_type(const char *s, enum cfg_flags flags)
1153 uint8_t mac[ETH_ADDR_LEN];
1154 struct in_addr addr;
1157 return (flags & CFG_STRING
1158 || (flags & CFG_KEY && is_key(s))
1159 || (flags & CFG_INT && is_int(s))
1160 || (flags & CFG_BOOL && is_bool(s))
1161 || (flags & CFG_IP && inet_aton(s, &addr))
1162 || (flags & CFG_MAC && parse_mac(s, mac))
1163 || (flags & CFG_DPID && parse_dpid(s, &dpid)));