X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=blobdiff_plain;f=lnet%2Flnet%2Fnidstrings.c;h=916a6b6aa7df692b97cdde6fa3808e010090d71d;hp=103ef2cbab538dfdc9ebae6aeba149a2516acf16;hb=31114c83e492a1f831165bb2b96496560967b42d;hpb=010bfd300128003b0a8e258d05f7156a0ec30af9 diff --git a/lnet/lnet/nidstrings.c b/lnet/lnet/nidstrings.c index 103ef2c..916a6b6 100644 --- a/lnet/lnet/nidstrings.c +++ b/lnet/lnet/nidstrings.c @@ -123,6 +123,45 @@ libcfs_ip_str2addr(const char *str, int nob, __u32 *addr) return 0; } +/* Used by lnet/config.c so it can't be static */ +int +cfs_ip_addr_parse(char *str, int len, struct list_head *list) +{ + struct cfs_expr_list *el; + struct cfs_lstr src; + int rc; + int i; + + src.ls_str = str; + src.ls_len = len; + i = 0; + + while (src.ls_str != NULL) { + struct cfs_lstr res; + + if (!cfs_gettok(&src, '.', &res)) { + rc = -EINVAL; + goto out; + } + + rc = cfs_expr_list_parse(res.ls_str, res.ls_len, 0, 255, &el); + if (rc != 0) + goto out; + + list_add_tail(&el->el_link, list); + i++; + } + + if (i == 4) + return 0; + + rc = -EINVAL; +out: + cfs_expr_list_free_list(list); + + return rc; +} + static int libcfs_ip_addr_range_print(char *buffer, int count, struct list_head *list) { @@ -139,6 +178,28 @@ libcfs_ip_addr_range_print(char *buffer, int count, struct list_head *list) } /** + * Matches address (\a addr) against address set encoded in \a list. + * + * \retval 1 if \a addr matches + * \retval 0 otherwise + */ +int +cfs_ip_addr_match(__u32 addr, struct list_head *list) +{ + struct cfs_expr_list *el; + int i = 0; + + list_for_each_entry_reverse(el, list, el_link) { + if (!cfs_expr_list_match(addr & 0xff, el)) + return 0; + addr >>= 8; + i++; + } + + return i == 4; +} + +/** * Print the network part of the nidrange \a nr into the specified \a buffer. * * \retval number of characters written