node = cur->u.s.car;
if (sexpr_lookup(node, "device/vif")) {
const char *tmp2, *model, *type;
- char buf[50];
tmp2 = sexpr_node(node, "device/vif/script");
tmp = sexpr_node(node, "device/vif/bridge");
model = sexpr_node(node, "device/vif/model");
}
tmp = sexpr_node(node, "device/vif/vifname");
- if (!tmp) {
- snprintf(buf, sizeof(buf), "vif%d.%d", def->id, vif_index);
- tmp = buf;
+ /* If vifname is specified in xend config, include it in net
+ * definition regardless of domain state. If vifname is not
+ * specified, only generate one if domain is active (id != -1). */
+ if (tmp) {
+ if (!(net->ifname = strdup(tmp)))
+ goto no_memory;
+ } else if (def->id != -1) {
+ if (virAsprintf(&net->ifname, "vif%d.%d", def->id, vif_index) < 0)
+ goto no_memory;
}
- if (!(net->ifname = strdup(tmp)))
- goto no_memory;
tmp = sexpr_node(node, "device/vif/mac");
if (tmp) {