/* * Read manager identifier (max 16 bytes). Check if it is a UUID and consists * of hexadecimal digits only. If so convert it to UUID. */ static bool getmgr2id(struct vdpnl_vsi *p, char *s) { bool is_good; size_t cnt = 0, i, slen = strlen(s); char *s_old = s; if (vdp_str2uuid(p->vsi_mgrid2, s, sizeof(p->vsi_mgrid2)) == 0) return true; /* Check for alphanumeric string */ for (i = 0; i < slen; ++i, ++s) if (isalnum(*s)) ++cnt; is_good = cnt == slen && cnt < sizeof(p->vsi_mgrid2); if (is_good) memcpy(p->vsi_mgrid2, s_old, cnt); return is_good; }
int oui_vdp_str2uuid(unsigned char *to, char *buffer, size_t max) { return vdp_str2uuid(to, buffer, max); }
static int str2vdpnl(char *argvalue, struct vdpnl_vsi *vsi) { int rc = -ENOMEM; unsigned int no; unsigned short idx; char *cmdstring, *token; cmdstring = strdup(argvalue); if (!cmdstring) goto out_free; rc = -EINVAL; /* 1st field is VSI command */ token = strtok(cmdstring, ","); if (!token || !getmode(vsi, token)) goto out_free; /* 2nd field is VSI Manager Identifer (16 bytes maximum) */ token = strtok(NULL, ","); if (!token || !getmgr2id(vsi, token)) goto out_free; /* 3rd field is type identifier */ token = strtok(NULL, ","); if (!token || !getnumber(token, 0, 0xffffff, &no)) goto out_free; vsi->vsi_typeid = no; /* 4th field is type version identifier */ token = strtok(NULL, ","); if (!token || !getnumber(token, 0, 0xff, &no)) goto out_free; vsi->vsi_typeversion = no; /* 5th field is filter VSI UUID */ token = strtok(NULL, ","); if (!token || vdp_str2uuid(vsi->vsi_uuid, token, sizeof(vsi->vsi_uuid))) goto out_free; vsi->vsi_idfmt = VDP22_ID_UUID; /* 6th field is migration hints */ token = strtok(NULL, ","); if (!token || !gethints(vsi, token)) goto out_free; /* * 7th and remaining fields are filter information format data. * All fields must have the same format. The first fid field determines * the format. */ for (idx = 0, token = strtok(NULL, ","); token != NULL; ++idx, token = strtok(NULL, ",")) { if (idx < vsi->macsz && !getfid(vsi, token, idx)) goto out_free; } /* Return error if no filter information provided */ if (idx) rc = 0; out_free: free(cmdstring); return rc; }