}
+/**
+ * Convert a virNWFilterHashTable into a string of comma-separated
+ * variable names.
+ */
+struct printString
+{
+ virBuffer buf;
+ const char *separator;
+ bool reportMAC;
+ bool reportIP;
+};
+
+
+static void
+printString(void *payload ATTRIBUTE_UNUSED, const void *name, void *data)
+{
+ struct printString *ps = data;
+
+ if ((STREQ((char *)name, NWFILTER_STD_VAR_IP ) && !ps->reportIP ) ||
+ (STREQ((char *)name, NWFILTER_STD_VAR_MAC) && !ps->reportMAC))
+ return;
+
+ if (virBufferUse(&ps->buf) && ps->separator)
+ virBufferAdd(&ps->buf, ps->separator, -1);
+
+ virBufferAdd(&ps->buf, name, -1);
+}
+
+/**
+ * virNWFilterPrintVars
+ *
+ * @var: hash table containing variables
+ * @separator: separator to use between variable names, i.e., ", "
+ * @reportMAC: whether to report the 'MAC' variable
+ * @reportIP : whether to report the IP variable
+ *
+ * Returns a string of comma separated variable names
+ */
+static char *
+virNWFilterPrintVars(virHashTablePtr vars,
+ const char *separator,
+ bool reportMAC,
+ bool reportIP)
+{
+ struct printString ps = {
+ .buf = VIR_BUFFER_INITIALIZER,
+ .separator = separator,
+ .reportMAC = reportMAC,
+ .reportIP = reportIP,
+ };
+
+ virHashForEach(vars, printString, &ps);
+
+ if (virBufferError(&ps.buf)) {
+ virBufferFreeAndReset(&ps.buf);
+ virReportOOMError();
+ return NULL;
+ }
+ return virBufferContentAndReset(&ps.buf);
+}
+
+
/**
* virNWFilterRuleInstantiate:
* @conn: pointer to virConnect object
virNWFilterRuleInstPtr *insts = NULL;
void **ptrs = NULL;
int instantiate = 1;
+ char *buf;
virNWFilterHashTablePtr missing_vars = virNWFilterHashTableCreate(0);
if (!missing_vars) {
}
goto err_exit;
}
- rc = 1;
- goto err_exit;
+ goto err_unresolvable_vars;
} else if (virHashSize(missing_vars->hashTable) > 1) {
- rc = 1;
- goto err_exit;
+ goto err_unresolvable_vars;
} else if (!forceWithPendingReq &&
virNWFilterLookupLearnReq(ifindex) != NULL) {
goto err_exit;
virNWFilterHashTableFree(missing_vars);
return rc;
+
+err_unresolvable_vars:
+
+ buf = virNWFilterPrintVars(missing_vars->hashTable, ", ", false, false);
+ if (buf) {
+ virNWFilterReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Cannot instantiate filter due to unresolvable "
+ "variables: %s"), buf);
+ VIR_FREE(buf);
+ }
+
+ rc = 1;
+ goto err_exit;
}