From: Mr NeilBrown Date: Tue, 24 Nov 2020 23:10:14 +0000 (+1100) Subject: LU-9859 lnet: simplifiy cfs_ip_addr_parse() X-Git-Tag: 2.15.58~73 X-Git-Url: https://git.whamcloud.com/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F42%2F50842%2F9;p=fs%2Flustre-release.git LU-9859 lnet: simplifiy cfs_ip_addr_parse() cfs_ip_add_parse() is now always passed a string that it is safe to modify. So change the parsing to benefit from this and use standard tools like strsep(). Note that the 'len' argument is now ignored. It cannot be removed without a larger change. Test-Parameters: trivial testlist=sanity-lnet Signed-off-by: Mr NeilBrown Change-Id: Ice492edf109dca2e411132b891514f0caa535d8c Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/50842 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Frank Sehr Reviewed-by: Oleg Drokin Reviewed-by: James Simmons Reviewed-by: Chris Horn --- diff --git a/lnet/lnet/config.c b/lnet/lnet/config.c index cfa55c4..d5eb3ed 100644 --- a/lnet/lnet/config.c +++ b/lnet/lnet/config.c @@ -1247,13 +1247,13 @@ lnet_parse_routes(const char *routes, int *im_a_router) } static int -lnet_match_network_token(char *token, int len, __u32 *ipaddrs, int nip) +lnet_match_network_token(char *token, __u32 *ipaddrs, int nip) { LIST_HEAD(list); int rc; int i; - rc = cfs_ip_addr_parse(token, len, &list); + rc = cfs_ip_addr_parse(token, 0, &list); if (rc != 0) return rc; @@ -1272,7 +1272,6 @@ lnet_match_network_tokens(char *net_entry, __u32 *ipaddrs, int nip) int matched = 0; int ntokens = 0; - int len; char *net = NULL; char *sep; char *token; @@ -1283,32 +1282,23 @@ lnet_match_network_tokens(char *net_entry, __u32 *ipaddrs, int nip) /* work on a copy of the string */ strcpy(tokens, net_entry); sep = tokens; - for (;;) { + while (sep) { /* scan for token start */ - while (isspace(*sep)) - sep++; + sep = skip_spaces(sep); if (*sep == 0) break; - token = sep++; - - /* scan for token end */ - while (*sep != 0 && !isspace(*sep)) - sep++; - if (*sep != 0) - *sep++ = 0; + token = strsep(&sep, " \t\n\r\v\f"); if (ntokens++ == 0) { net = token; continue; } - len = strlen(token); - - rc = lnet_match_network_token(token, len, ipaddrs, nip); + rc = lnet_match_network_token(token, ipaddrs, nip); if (rc < 0) { lnet_syntax("ip2nets", net_entry, - (int)(token - tokens), len); + (int)(token - tokens), strlen(token)); return rc; } diff --git a/lnet/lnet/nidstrings.c b/lnet/lnet/nidstrings.c index ae28f92..3c822a4 100644 --- a/lnet/lnet/nidstrings.c +++ b/lnet/lnet/nidstrings.c @@ -552,41 +552,32 @@ libcfs_ip_str2addr_size(const char *str, int nob, /* Used by lnet/config.c so it can't be static */ int -cfs_ip_addr_parse(char *str, int len, struct list_head *list) +cfs_ip_addr_parse(char *str, int len_ignored, 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; + int rc = 0; + int i = 0; - while (src.ls_str != NULL) { - struct cfs_lstr res; + str = strim(str); + while (rc == 0 && str) { + char *res; - if (!cfs_gettok(&src, '.', &res)) { + res = strsep(&str, "."); + res = strim(res); + if (!*res) { rc = -EINVAL; - goto out; + } else if ((rc = cfs_expr_list_parse(res, strlen(res), + 0, 255, &el)) == 0) { + list_add_tail(&el->el_link, list); + i++; } - - 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) + if (rc == 0 && i == 4) return 0; - - rc = -EINVAL; -out: cfs_expr_list_free_list(list); - return rc; + return rc ?: -EINVAL; } /**