-static void lustre_lnet_clean_ip2nets(struct lustre_lnet_ip2nets *ip2nets)
-{
- struct lustre_lnet_ip_range_descr *ipr, *tmp;
- struct cfs_expr_list *el, *el_tmp;
-
- list_for_each_entry_safe(ipr, tmp,
- &ip2nets->ip2nets_ip_ranges,
- ipr_entry) {
- list_del(&ipr->ipr_entry);
- list_for_each_entry_safe(el, el_tmp, &ipr->ipr_expr,
- el_link) {
- list_del(&el->el_link);
- cfs_expr_list_free(el);
- }
- free(ipr);
- }
-}
-
-/*
- * returns an rc < 0 if there is an error
- * otherwise it returns the number IPs generated
- * it also has out params: net - network name
- */
-static int lnet_expr2ips(char *nidstr, __u32 *ip_list,
- struct lustre_lnet_ip2nets *ip2nets,
- __u32 *net, char *err_str)
-{
- struct lustre_lnet_ip_range_descr *ipr;
- char *comp1, *comp2;
- int ip_idx = MAX_NUM_IPS - 1;
- int ip_range_len, rc = LUSTRE_CFG_RC_NO_ERR;
- __u32 net_type;
- char ip_range[LNET_MAX_STR_LEN];
-
- /* separate the two components of the NID */
- comp1 = nidstr;
- comp2 = strchr(nidstr, '@');
- if (comp2 == NULL) {
- snprintf(err_str,
- LNET_MAX_STR_LEN,
- "\"cannot parse NID %s\"", nidstr);
- err_str[LNET_MAX_STR_LEN - 1] = '\0';
- rc = LUSTRE_CFG_RC_BAD_PARAM;
- goto out;
- }
-
- /* length of the expected ip-range */
- ip_range_len = comp2 - comp1;
- if (ip_range_len >= LNET_MAX_STR_LEN) {
- snprintf(err_str,
- LNET_MAX_STR_LEN,
- "\"too long ip_range '%s'\"", nidstr);
- err_str[LNET_MAX_STR_LEN - 1] = '\0';
- rc = LUSTRE_CFG_RC_BAD_PARAM;
- goto out;
- }
-
- /* move beyond '@' */
- comp2++;
-
- /*
- * if the net component is either o2ib or tcp then we expect
- * an IP range which could only be a single IP address.
- * Parse that.
- */
- *net = libcfs_str2net(comp2);
- net_type = LNET_NETTYP(*net);
- /* expression support is for o2iblnd and socklnd only */
- if (net_type != O2IBLND && net_type != SOCKLND)
- return LUSTRE_CFG_RC_SKIP;
-
- strncpy(ip_range, comp1, ip_range_len);
- ip_range[ip_range_len] = '\0';
- ip2nets->ip2nets_net.nw_id = *net;
-
- rc = lustre_lnet_add_ip_range(&ip2nets->ip2nets_ip_ranges, ip_range);
- if (rc != LUSTRE_CFG_RC_NO_ERR) {
- snprintf(err_str,
- LNET_MAX_STR_LEN,
- "\"cannot parse ip_range '%.100s'\"", ip_range);
- err_str[LNET_MAX_STR_LEN - 1] = '\0';
- rc = LUSTRE_CFG_RC_BAD_PARAM;
- goto out;
- }
-
- /*
- * Generate all the IP Addresses from the parsed range. For sanity
- * we allow only a max of MAX_NUM_IPS nids to be configured for
- * a single peer.
- */
- list_for_each_entry(ipr, &ip2nets->ip2nets_ip_ranges, ipr_entry)
- ip_idx = cfs_ip_addr_range_gen(ip_list, MAX_NUM_IPS,
- &ipr->ipr_expr);
-
- if (ip_idx == MAX_NUM_IPS - 1) {
- snprintf(err_str, LNET_MAX_STR_LEN,
- "no NIDs provided for configuration");
- err_str[LNET_MAX_STR_LEN - 1] = '\0';
- rc = LUSTRE_CFG_RC_NO_MATCH;
- goto out;
- } else if (ip_idx == -1) {
- rc = LUSTRE_CFG_RC_LAST_ELEM;
- } else {
- rc = ip_idx;
- }
-
-out:
- return rc;
-}
-