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 have sections that
680 * begin with 'section'. The caller must first initialize 'svec'. */
682 cfg_get_section(struct svec *svec, const char *section_, ...)
689 va_start(args, section_);
690 ds_put_format_valist(§ion, section_, args);
691 ds_put_char(§ion, '.');
694 for (p = cfg.names; *p; p++) { /* XXX this is inefficient */
695 if (!strncmp(section.string, *p, section.length)) {
699 ds_destroy(§ion);
702 /* Returns the value numbered 'idx' of 'key'. Returns a null pointer if 'idx'
703 * is greater than or equal to cfg_count(key). The caller must not modify or
704 * free the returned string or retain its value beyond the next call to
707 cfg_get_string(int idx, const char *key_, ...)
712 FORMAT_KEY(key_, key);
713 retval = get_nth_value(idx, key);
718 /* Returns the value numbered 'idx' of 'key'. Returns a null pointer if 'idx'
719 * is greater than or equal to cfg_count(key) or if the value 'idx' of 'key' is
720 * not a valid key. The caller must not modify or free the returned string or
721 * retain its value beyond the next call to cfg_read(). */
723 cfg_get_key(int idx, const char *key_, ...)
725 const char *value, *retval;
728 FORMAT_KEY(key_, key);
729 value = get_nth_value(idx, key);
730 retval = value && is_key(value) ? value : NULL;
735 /* Returns the value numbered 'idx' of 'key', converted to an integer. Returns
736 * 0 if 'idx' is greater than or equal to cfg_count(key) or if the value 'idx'
737 * of 'key' is not a valid integer. */
739 cfg_get_int(int idx, const char *key_, ...)
745 FORMAT_KEY(key_, key);
746 value = get_nth_value(idx, key);
747 retval = value && is_int(value) ? atoi(value) : 0;
752 /* Returns the value numbered 'idx' of 'key', converted to a boolean value.
753 * Returns false if 'idx' is greater than or equal to cfg_count(key) or if the
754 * value 'idx' of 'key' is not a valid boolean. */
756 cfg_get_bool(int idx, const char *key_, ...)
762 FORMAT_KEY(key_, key);
763 value = get_nth_value(idx, key);
764 retval = value && is_bool(value) ? !strcmp(value, "true") : false;
769 /* Returns the value numbered 'idx' of 'key', converted to an IP address in
770 * network byte order. Returns 0 if 'idx' is greater than or equal to
771 * cfg_count(key) or if the value 'idx' of 'key' is not a valid IP address (as
772 * determined by inet_aton()). */
774 cfg_get_ip(int idx, const char *key_, ...)
780 FORMAT_KEY(key_, key);
781 value = get_nth_value(idx, key);
782 if (!value || !inet_aton(value, &addr)) {
783 addr.s_addr = htonl(0);
789 /* Returns the value numbered 'idx' of 'key', converted to an MAC address in
790 * host byte order. Returns 0 if 'idx' is greater than or equal to
791 * cfg_count(key) or if the value 'idx' of 'key' is not a valid MAC address in
792 * the format "##:##:##:##:##:##". */
794 cfg_get_mac(int idx, const char *key_, ...)
796 uint8_t mac[ETH_ADDR_LEN];
800 FORMAT_KEY(key_, key);
801 value = get_nth_value(idx, key);
802 if (!value || !parse_mac(value, mac)) {
803 memset(mac, 0, sizeof mac);
806 return eth_addr_to_uint64(mac);
809 /* Returns the value numbered 'idx' of 'key', parsed as an datapath ID.
810 * Returns 0 if 'idx' is greater than or equal to cfg_count(key) or if the
811 * value 'idx' of 'key' is not a valid datapath ID consisting of exactly 12
812 * hexadecimal digits. */
814 cfg_get_dpid(int idx, const char *key_, ...)
820 FORMAT_KEY(key_, key);
821 value = get_nth_value(idx, key);
822 if (!value || !parse_dpid(value, &dpid)) {
829 /* Returns the value numbered 'idx' of 'key', converted to an integer. Returns
830 * -1 if 'idx' is greater than or equal to cfg_count(key) or if the value 'idx'
831 * of 'key' is not a valid integer between 0 and 4095. */
833 cfg_get_vlan(int idx, const char *key_, ...)
839 FORMAT_KEY(key_, key);
840 value = get_nth_value(idx, key);
841 if (value && is_int(value)) {
842 retval = atoi(value);
843 if (retval < 0 || retval > 4095) {
853 /* Fills 'svec' with all of the string values of 'key'. The caller must
854 * first initialize 'svec'. */
856 cfg_get_all_strings(struct svec *svec, const char *key_, ...)
861 FORMAT_KEY(key_, key);
863 for (p = find_key_le(key), q = find_key_ge(key); p < q; p++) {
864 svec_add(svec, extract_value(*p));
869 /* Fills 'svec' with all of the values of 'key' that are valid keys.
870 * Values of 'key' that are not valid keys are omitted. The caller
871 * must first initialize 'svec'. */
873 cfg_get_all_keys(struct svec *svec, const char *key_, ...)
878 FORMAT_KEY(key_, key);
880 for (p = find_key_le(key), q = find_key_ge(key); p < q; p++) {
881 const char *value = extract_value(*p);
883 svec_add(svec, value);
890 has_double_dot(const char *key, size_t len)
895 for (i = 0; i < len - 1; i++) {
896 if (key[i] == '.' && key[i + 1] == '.') {
905 is_valid_key(const char *key, size_t len,
906 const char *file_name, int line_number, const char *id)
909 VLOG_ERR("%s:%d: missing %s name", file_name, line_number, id);
911 } else if (key[0] == '.') {
912 VLOG_ERR("%s:%d: %s name \"%.*s\" begins with invalid character '.'",
913 file_name, line_number, id, (int) len, key);
915 } else if (key[len - 1] == '.') {
916 VLOG_ERR("%s:%d: %s name \"%.*s\" ends with invalid character '.'",
917 file_name, line_number, id, (int) len, key);
919 } else if (has_double_dot(key, len)) {
920 VLOG_ERR("%s:%d: %s name \"%.*s\" contains '..', which is not allowed",
921 file_name, line_number, id, (int) len, key);
929 parse_section(const char *file_name, int line_number, const char *s)
936 /* Skip [ and any white space. */
938 s += strspn(s, CC_SPACE);
940 /* Obtain the section name. */
941 len = strspn(s, CC_KEY);
942 if (!is_valid_key(s, len, file_name, line_number, "section")) {
945 ds_put_buffer(§ion, s, len);
948 /* Obtain the subsection name, if any. */
949 s += strspn(s, CC_SPACE);
952 len = strspn(s, CC_KEY);
953 if (!is_valid_key(s, len, file_name, line_number, "subsection")) {
956 ds_put_char(§ion, '.');
957 ds_put_buffer(§ion, s, len);
960 VLOG_ERR("%s:%d: missing '\"' following subsection name",
961 file_name, line_number);
965 s += strspn(s, CC_SPACE);
970 VLOG_ERR("%s:%d: missing ']' following section name",
971 file_name, line_number);
975 s += strspn(s, CC_SPACE);
977 VLOG_ERR("%s:%d: trailing garbage following ']'",
978 file_name, line_number);
982 return ds_cstr(§ion);
985 ds_destroy(§ion);
990 parse_setting(const char *file_name, int line_number, const char *section,
993 struct ds key = DS_EMPTY_INITIALIZER;
994 struct ds value = DS_EMPTY_INITIALIZER;
998 ds_put_format(&key, "%s.", section);
1001 /* Obtain the key. */
1002 len = strspn(s, CC_KEY);
1004 VLOG_ERR("%s:%d: missing key name", file_name, line_number);
1007 if (!is_valid_key(s, len, file_name, line_number, "key")) {
1010 ds_put_buffer(&key, s, len);
1014 s += strspn(s, CC_SPACE);
1016 VLOG_ERR("%s:%d: missing '=' following key", file_name, line_number);
1020 s += strspn(s, CC_SPACE);
1022 /* Obtain the value. */
1023 ds_put_cstr(&value, s);
1024 while (value.length > 0 && strchr(CC_SPACE, ds_last(&value))) {
1028 /* Add the setting. */
1029 svec_add_nocopy(&cfg, xasprintf("%s=%s", ds_cstr(&key), ds_cstr(&value)));
1037 compare_key(const char *a, const char *b)
1040 int ac = *a == '\0' || *a == '=' ? INT_MAX : *a;
1041 int bc = *b == '\0' || *b == '=' ? INT_MAX : *b;
1043 return ac < bc ? -1 : 1;
1044 } else if (ac == INT_MAX) {
1052 /* Returns the address of the greatest configuration string with a key less
1053 * than or equal to 'key'. Returns the address of the null terminator if all
1054 * configuration strings are greater than 'key'. */
1056 find_key_le(const char *key)
1061 int half = len >> 1;
1062 int middle = low + half;
1063 if (compare_key(cfg.names[middle], key) < 0) {
1070 return &cfg.names[low];
1073 /* Returns the address of the least configuration string with a key greater
1074 * than or equal to 'key'. Returns the address of the null terminator if all
1075 * configuration strings are less than 'key'. */
1077 find_key_ge(const char *key)
1082 int half = len >> 1;
1083 int middle = low + half;
1084 if (compare_key(cfg.names[middle], key) > 0) {
1091 return &cfg.names[low];
1095 find_key(const char *key)
1097 char **p = find_key_le(key);
1098 return p < &cfg.names[cfg.n] && !compare_key(*p, key) ? *p : NULL;
1102 parse_mac(const char *s, uint8_t mac[6])
1104 return sscanf(s, "%"SCNx8":%"SCNx8":%"SCNx8":%"SCNx8":%"SCNx8":%"SCNx8,
1105 &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]) == 6;
1109 parse_dpid(const char *s, uint64_t *dpid)
1111 if (strlen(s) == 12 && strspn(s, "0123456789abcdefABCDEF") == 12) {
1112 *dpid = strtoll(s, NULL, 16);
1120 is_key(const char *s)
1122 /* XXX needs to check the same things as is_valid_key() too. */
1123 return *s && s[strspn(s, CC_KEY)] == '\0';
1127 is_int(const char *s)
1129 return *s && s[strspn(s, CC_DIGIT)] == '\0';
1133 is_bool(const char *s)
1135 return !strcmp(s, "true") || !strcmp(s, "false");
1139 extract_value(const char *key)
1141 const char *p = strchr(key, '=');
1142 return p ? p + 1 : NULL;
1146 get_nth_value(int idx, const char *key)
1148 char **p = find_key_le(key);
1149 char **q = find_key_ge(key);
1150 return idx < q - p ? extract_value(p[idx]) : NULL;
1154 is_type(const char *s, enum cfg_flags flags)
1156 uint8_t mac[ETH_ADDR_LEN];
1157 struct in_addr addr;
1160 return (flags & CFG_STRING
1161 || (flags & CFG_KEY && is_key(s))
1162 || (flags & CFG_INT && is_int(s))
1163 || (flags & CFG_BOOL && is_bool(s))
1164 || (flags & CFG_IP && inet_aton(s, &addr))
1165 || (flags & CFG_MAC && parse_mac(s, mac))
1166 || (flags & CFG_DPID && parse_dpid(s, &dpid)));