[libvirt] [PATCH] Support script setting for bridge-type interfaces

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



# HG changeset patch
# User john.levon@xxxxxxx
# Date 1232562793 28800
# Node ID e0b0295722ecf4645983e3a9a090e0aaabc40da7
# Parent  ce10bb67bbcee1a49b900e260a65ccfb1b69588b
Support script setting for bridge-type interfaces

Fix back-compatibility by allowing non-default scripts in interfaces
of bridge type again.

Signed-off-by: John Levon <john.levon@xxxxxxx>

diff --git a/src/domain_conf.c b/src/domain_conf.c
--- a/src/domain_conf.c
+++ b/src/domain_conf.c
@@ -288,6 +288,7 @@ void virDomainNetDefFree(virDomainNetDef
 
     case VIR_DOMAIN_NET_TYPE_BRIDGE:
         VIR_FREE(def->data.bridge.brname);
+        VIR_FREE(def->data.bridge.script);
         break;
     }
 
@@ -897,7 +898,8 @@ virDomainNetDefParseXML(virConnectPtr co
                     VIR_FREE(ifname);
                 }
             } else if ((script == NULL) &&
-                       (def->type == VIR_DOMAIN_NET_TYPE_ETHERNET) &&
+                       (def->type == VIR_DOMAIN_NET_TYPE_ETHERNET ||
+                        def->type == VIR_DOMAIN_NET_TYPE_BRIDGE) &&
                        xmlStrEqual(cur->name, BAD_CAST "script")) {
                 script = virXMLPropString(cur, "path");
             } else if (xmlStrEqual (cur->name, BAD_CAST "model")) {
@@ -948,6 +950,10 @@ virDomainNetDefParseXML(virConnectPtr co
         }
         def->data.bridge.brname = bridge;
         bridge = NULL;
+        if (script != NULL) {
+            def->data.bridge.script = script;
+            script = NULL;
+        }
         break;
 
     case VIR_DOMAIN_NET_TYPE_CLIENT:
@@ -2883,6 +2889,9 @@ virDomainNetDefFormat(virConnectPtr conn
     case VIR_DOMAIN_NET_TYPE_BRIDGE:
         virBufferEscapeString(buf, "      <source bridge='%s'/>\n",
                               def->data.bridge.brname);
+        if (def->data.bridge.script)
+            virBufferEscapeString(buf, "      <script path='%s'/>\n",
+                                  def->data.bridge.script);
         break;
 
     case VIR_DOMAIN_NET_TYPE_SERVER:
diff --git a/src/domain_conf.h b/src/domain_conf.h
--- a/src/domain_conf.h
+++ b/src/domain_conf.h
@@ -154,6 +154,7 @@ struct _virDomainNetDef {
         } network;
         struct {
             char *brname;
+            char *script;
         } bridge;
     } data;
     char *ifname;
diff --git a/src/xend_internal.c b/src/xend_internal.c
--- a/src/xend_internal.c
+++ b/src/xend_internal.c
@@ -60,6 +60,12 @@
 #define XEN_SCHED_CRED_NPARAM   2
 
 #endif /* PROXY */
+
+#ifdef __sun
+#define DEFAULT_VIF_SCRIPT "vif-vnic"
+#else
+#define DEFAULT_VIF_SCRIPT "vif-bridge"
+#endif
 
 #ifdef WITH_RHEL5_API
 #define XEND_CONFIG_MAX_VERS_NET_TYPE_IOEMU 0
@@ -1739,15 +1745,22 @@ xenDaemonParseSxprNets(virConnectPtr con
             if (VIR_ALLOC(net) < 0)
                 goto no_memory;
 
-            if ((tmp2 && strstr(tmp2, "bridge")) || tmp) {
+            if (tmp != NULL || (STREQ(tmp2, DEFAULT_VIF_SCRIPT))) {
                 net->type = VIR_DOMAIN_NET_TYPE_BRIDGE;
                 /* XXX virtual network reverse resolve */
 
                 if (tmp &&
                     !(net->data.bridge.brname = strdup(tmp)))
                     goto no_memory;
+                if (tmp2 &&
+                    net->type == VIR_DOMAIN_NET_TYPE_BRIDGE &&
+                    !(net->data.bridge.script = strdup(tmp2)))
+                    goto no_memory;
             } else {
                 net->type = VIR_DOMAIN_NET_TYPE_ETHERNET;
+                if (tmp2 &&
+                    !(net->data.ethernet.script = strdup(tmp2)))
+                    goto no_memory;
             }
 
             tmp = sexpr_node(node, "device/vif/vifname");
@@ -1784,11 +1797,6 @@ xenDaemonParseSxprNets(virConnectPtr con
             tmp = sexpr_node(node, "device/vif/ip");
             if (tmp &&
                 !(net->data.ethernet.ipaddr = strdup(tmp)))
-                goto no_memory;
-
-            if (tmp2 &&
-                net->type == VIR_DOMAIN_NET_TYPE_ETHERNET &&
-                !(net->data.ethernet.script = strdup(tmp2)))
                 goto no_memory;
 
             if (model &&
@@ -5069,6 +5077,8 @@ xenDaemonFormatSxprNet(virConnectPtr con
                        int xendConfigVersion,
                        int isAttach)
 {
+    const char *script = DEFAULT_VIF_SCRIPT;
+
     if (def->type != VIR_DOMAIN_NET_TYPE_BRIDGE &&
         def->type != VIR_DOMAIN_NET_TYPE_NETWORK &&
         def->type != VIR_DOMAIN_NET_TYPE_ETHERNET) {
@@ -5090,7 +5100,10 @@ xenDaemonFormatSxprNet(virConnectPtr con
     switch (def->type) {
     case VIR_DOMAIN_NET_TYPE_BRIDGE:
         virBufferVSprintf(buf, "(bridge '%s')", def->data.bridge.brname);
-        virBufferAddLit(buf, "(script 'vif-bridge')");
+        if (def->data.bridge.script)
+            script = def->data.bridge.script;
+
+        virBufferVSprintf(buf, "(script '%s')", script);
         break;
 
     case VIR_DOMAIN_NET_TYPE_NETWORK:
@@ -5113,7 +5126,7 @@ xenDaemonFormatSxprNet(virConnectPtr con
             return -1;
         }
         virBufferVSprintf(buf, "(bridge '%s')", bridge);
-        virBufferAddLit(buf, "(script 'vif-bridge')");
+        virBufferVSprintf(buf, "(script '%s')", script);
         VIR_FREE(bridge);
     }
     break;
diff --git a/src/xm_internal.c b/src/xm_internal.c
--- a/src/xm_internal.c
+++ b/src/xm_internal.c
@@ -1057,14 +1057,19 @@ xenXMDomainConfigParse(virConnectPtr con
                 net->mac[5] = rawmac[5];
             }
 
-            if (bridge[0] || STREQ(script, "vif-bridge"))
+            if (bridge[0] || STREQ(script, "vif-bridge") ||
+                STREQ(script, "vif-vnic")) {
                 net->type = VIR_DOMAIN_NET_TYPE_BRIDGE;
-            else
+            } else {
                 net->type = VIR_DOMAIN_NET_TYPE_ETHERNET;
+            }
 
             if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE) {
                 if (bridge[0] &&
                     !(net->data.bridge.brname = strdup(bridge)))
+                    goto no_memory;
+                if (script[0] &&
+                    !(net->data.bridge.script = strdup(script)))
                     goto no_memory;
             } else {
                 if (script[0] &&
diff --git a/tests/sexpr2xmldata/sexpr2xml-curmem.xml b/tests/sexpr2xmldata/sexpr2xml-curmem.xml
--- a/tests/sexpr2xmldata/sexpr2xml-curmem.xml
+++ b/tests/sexpr2xmldata/sexpr2xml-curmem.xml
@@ -24,6 +24,7 @@
     <interface type='bridge'>
       <mac address='00:16:3e:1d:06:15'/>
       <source bridge='xenbr0'/>
+      <script path='vif-bridge'/>
       <target dev='vif5.0'/>
     </interface>
     <console type='pty'>
diff --git a/tests/sexpr2xmldata/sexpr2xml-disk-block-shareable.xml b/tests/sexpr2xmldata/sexpr2xml-disk-block-shareable.xml
--- a/tests/sexpr2xmldata/sexpr2xml-disk-block-shareable.xml
+++ b/tests/sexpr2xmldata/sexpr2xml-disk-block-shareable.xml
@@ -22,6 +22,7 @@
     <interface type='bridge'>
       <mac address='00:16:3e:23:9e:eb'/>
       <source bridge='xenbr0'/>
+      <script path='vif-bridge'/>
       <target dev='vif6.0'/>
     </interface>
     <console type='pty'>
diff --git a/tests/sexpr2xmldata/sexpr2xml-fv-localtime.xml b/tests/sexpr2xmldata/sexpr2xml-fv-localtime.xml
--- a/tests/sexpr2xmldata/sexpr2xml-fv-localtime.xml
+++ b/tests/sexpr2xmldata/sexpr2xml-fv-localtime.xml
@@ -32,6 +32,7 @@
     <interface type='bridge'>
       <mac address='00:16:3e:1b:b1:47'/>
       <source bridge='xenbr0'/>
+      <script path='vif-bridge'/>
       <target dev='vif3.0'/>
     </interface>
     <input type='mouse' bus='ps2'/>
diff --git a/tests/sexpr2xmldata/sexpr2xml-fv-parallel-tcp.xml b/tests/sexpr2xmldata/sexpr2xml-fv-parallel-tcp.xml
--- a/tests/sexpr2xmldata/sexpr2xml-fv-parallel-tcp.xml
+++ b/tests/sexpr2xmldata/sexpr2xml-fv-parallel-tcp.xml
@@ -32,6 +32,7 @@
     <interface type='bridge'>
       <mac address='00:16:3e:1b:b1:47'/>
       <source bridge='xenbr0'/>
+      <script path='vif-bridge'/>
       <target dev='vif1.0'/>
     </interface>
     <parallel type='tcp'>
diff --git a/tests/sexpr2xmldata/sexpr2xml-fv-serial-file.xml b/tests/sexpr2xmldata/sexpr2xml-fv-serial-file.xml
--- a/tests/sexpr2xmldata/sexpr2xml-fv-serial-file.xml
+++ b/tests/sexpr2xmldata/sexpr2xml-fv-serial-file.xml
@@ -32,6 +32,7 @@
     <interface type='bridge'>
       <mac address='00:16:3e:1b:b1:47'/>
       <source bridge='xenbr0'/>
+      <script path='vif-bridge'/>
       <target dev='vif1.0'/>
     </interface>
     <serial type='file'>
diff --git a/tests/sexpr2xmldata/sexpr2xml-fv-serial-null.xml b/tests/sexpr2xmldata/sexpr2xml-fv-serial-null.xml
--- a/tests/sexpr2xmldata/sexpr2xml-fv-serial-null.xml
+++ b/tests/sexpr2xmldata/sexpr2xml-fv-serial-null.xml
@@ -32,6 +32,7 @@
     <interface type='bridge'>
       <mac address='00:16:3e:1b:b1:47'/>
       <source bridge='xenbr0'/>
+      <script path='vif-bridge'/>
       <target dev='vif1.0'/>
     </interface>
     <serial type='null'>
diff --git a/tests/sexpr2xmldata/sexpr2xml-fv-serial-pipe.xml b/tests/sexpr2xmldata/sexpr2xml-fv-serial-pipe.xml
--- a/tests/sexpr2xmldata/sexpr2xml-fv-serial-pipe.xml
+++ b/tests/sexpr2xmldata/sexpr2xml-fv-serial-pipe.xml
@@ -32,6 +32,7 @@
     <interface type='bridge'>
       <mac address='00:16:3e:1b:b1:47'/>
       <source bridge='xenbr0'/>
+      <script path='vif-bridge'/>
       <target dev='vif1.0'/>
     </interface>
     <serial type='pipe'>
diff --git a/tests/sexpr2xmldata/sexpr2xml-fv-serial-pty.xml b/tests/sexpr2xmldata/sexpr2xml-fv-serial-pty.xml
--- a/tests/sexpr2xmldata/sexpr2xml-fv-serial-pty.xml
+++ b/tests/sexpr2xmldata/sexpr2xml-fv-serial-pty.xml
@@ -32,6 +32,7 @@
     <interface type='bridge'>
       <mac address='00:16:3e:1b:b1:47'/>
       <source bridge='xenbr0'/>
+      <script path='vif-bridge'/>
       <target dev='vif1.0'/>
     </interface>
     <serial type='pty'>
diff --git a/tests/sexpr2xmldata/sexpr2xml-fv-serial-stdio.xml b/tests/sexpr2xmldata/sexpr2xml-fv-serial-stdio.xml
--- a/tests/sexpr2xmldata/sexpr2xml-fv-serial-stdio.xml
+++ b/tests/sexpr2xmldata/sexpr2xml-fv-serial-stdio.xml
@@ -32,6 +32,7 @@
     <interface type='bridge'>
       <mac address='00:16:3e:1b:b1:47'/>
       <source bridge='xenbr0'/>
+      <script path='vif-bridge'/>
       <target dev='vif1.0'/>
     </interface>
     <serial type='stdio'>
diff --git a/tests/sexpr2xmldata/sexpr2xml-fv-serial-tcp-telnet.xml b/tests/sexpr2xmldata/sexpr2xml-fv-serial-tcp-telnet.xml
--- a/tests/sexpr2xmldata/sexpr2xml-fv-serial-tcp-telnet.xml
+++ b/tests/sexpr2xmldata/sexpr2xml-fv-serial-tcp-telnet.xml
@@ -32,6 +32,7 @@
     <interface type='bridge'>
       <mac address='00:16:3e:1b:b1:47'/>
       <source bridge='xenbr0'/>
+      <script path='vif-bridge'/>
       <target dev='vif1.0'/>
     </interface>
     <serial type='tcp'>
diff --git a/tests/sexpr2xmldata/sexpr2xml-fv-serial-tcp.xml b/tests/sexpr2xmldata/sexpr2xml-fv-serial-tcp.xml
--- a/tests/sexpr2xmldata/sexpr2xml-fv-serial-tcp.xml
+++ b/tests/sexpr2xmldata/sexpr2xml-fv-serial-tcp.xml
@@ -32,6 +32,7 @@
     <interface type='bridge'>
       <mac address='00:16:3e:1b:b1:47'/>
       <source bridge='xenbr0'/>
+      <script path='vif-bridge'/>
       <target dev='vif1.0'/>
     </interface>
     <serial type='tcp'>
diff --git a/tests/sexpr2xmldata/sexpr2xml-fv-serial-udp.xml b/tests/sexpr2xmldata/sexpr2xml-fv-serial-udp.xml
--- a/tests/sexpr2xmldata/sexpr2xml-fv-serial-udp.xml
+++ b/tests/sexpr2xmldata/sexpr2xml-fv-serial-udp.xml
@@ -32,6 +32,7 @@
     <interface type='bridge'>
       <mac address='00:16:3e:1b:b1:47'/>
       <source bridge='xenbr0'/>
+      <script path='vif-bridge'/>
       <target dev='vif1.0'/>
     </interface>
     <serial type='udp'>
diff --git a/tests/sexpr2xmldata/sexpr2xml-fv-serial-unix.xml b/tests/sexpr2xmldata/sexpr2xml-fv-serial-unix.xml
--- a/tests/sexpr2xmldata/sexpr2xml-fv-serial-unix.xml
+++ b/tests/sexpr2xmldata/sexpr2xml-fv-serial-unix.xml
@@ -32,6 +32,7 @@
     <interface type='bridge'>
       <mac address='00:16:3e:1b:b1:47'/>
       <source bridge='xenbr0'/>
+      <script path='vif-bridge'/>
       <target dev='vif1.0'/>
     </interface>
     <serial type='unix'>
diff --git a/tests/sexpr2xmldata/sexpr2xml-fv-sound-all.xml b/tests/sexpr2xmldata/sexpr2xml-fv-sound-all.xml
--- a/tests/sexpr2xmldata/sexpr2xml-fv-sound-all.xml
+++ b/tests/sexpr2xmldata/sexpr2xml-fv-sound-all.xml
@@ -32,6 +32,7 @@
     <interface type='bridge'>
       <mac address='00:16:3e:1b:b1:47'/>
       <source bridge='xenbr0'/>
+      <script path='vif-bridge'/>
       <target dev='vif3.0'/>
     </interface>
     <input type='mouse' bus='ps2'/>
diff --git a/tests/sexpr2xmldata/sexpr2xml-fv-sound.xml b/tests/sexpr2xmldata/sexpr2xml-fv-sound.xml
--- a/tests/sexpr2xmldata/sexpr2xml-fv-sound.xml
+++ b/tests/sexpr2xmldata/sexpr2xml-fv-sound.xml
@@ -32,6 +32,7 @@
     <interface type='bridge'>
       <mac address='00:16:3e:1b:b1:47'/>
       <source bridge='xenbr0'/>
+      <script path='vif-bridge'/>
       <target dev='vif3.0'/>
     </interface>
     <input type='mouse' bus='ps2'/>
diff --git a/tests/sexpr2xmldata/sexpr2xml-fv-usbmouse.xml b/tests/sexpr2xmldata/sexpr2xml-fv-usbmouse.xml
--- a/tests/sexpr2xmldata/sexpr2xml-fv-usbmouse.xml
+++ b/tests/sexpr2xmldata/sexpr2xml-fv-usbmouse.xml
@@ -32,6 +32,7 @@
     <interface type='bridge'>
       <mac address='00:16:3e:1b:b1:47'/>
       <source bridge='xenbr0'/>
+      <script path='vif-bridge'/>
       <target dev='vif3.0'/>
     </interface>
     <input type='mouse' bus='usb'/>
diff --git a/tests/sexpr2xmldata/sexpr2xml-fv-usbtablet.xml b/tests/sexpr2xmldata/sexpr2xml-fv-usbtablet.xml
--- a/tests/sexpr2xmldata/sexpr2xml-fv-usbtablet.xml
+++ b/tests/sexpr2xmldata/sexpr2xml-fv-usbtablet.xml
@@ -32,6 +32,7 @@
     <interface type='bridge'>
       <mac address='00:16:3e:1b:b1:47'/>
       <source bridge='xenbr0'/>
+      <script path='vif-bridge'/>
       <target dev='vif3.0'/>
     </interface>
     <input type='tablet' bus='usb'/>
diff --git a/tests/sexpr2xmldata/sexpr2xml-fv-utc.xml b/tests/sexpr2xmldata/sexpr2xml-fv-utc.xml
--- a/tests/sexpr2xmldata/sexpr2xml-fv-utc.xml
+++ b/tests/sexpr2xmldata/sexpr2xml-fv-utc.xml
@@ -32,6 +32,7 @@
     <interface type='bridge'>
       <mac address='00:16:3e:1b:b1:47'/>
       <source bridge='xenbr0'/>
+      <script path='vif-bridge'/>
       <target dev='vif3.0'/>
     </interface>
     <input type='mouse' bus='ps2'/>
diff --git a/tests/sexpr2xmldata/sexpr2xml-fv-v2.xml b/tests/sexpr2xmldata/sexpr2xml-fv-v2.xml
--- a/tests/sexpr2xmldata/sexpr2xml-fv-v2.xml
+++ b/tests/sexpr2xmldata/sexpr2xml-fv-v2.xml
@@ -32,6 +32,7 @@
     <interface type='bridge'>
       <mac address='00:16:3e:1b:b1:47'/>
       <source bridge='xenbr0'/>
+      <script path='vif-bridge'/>
       <target dev='vif3.0'/>
     </interface>
     <input type='mouse' bus='ps2'/>
diff --git a/tests/sexpr2xmldata/sexpr2xml-fv.xml b/tests/sexpr2xmldata/sexpr2xml-fv.xml
--- a/tests/sexpr2xmldata/sexpr2xml-fv.xml
+++ b/tests/sexpr2xmldata/sexpr2xml-fv.xml
@@ -32,6 +32,7 @@
     <interface type='bridge'>
       <mac address='00:16:3e:1b:b1:47'/>
       <source bridge='xenbr0'/>
+      <script path='vif-bridge'/>
       <target dev='vif3.0'/>
     </interface>
     <input type='mouse' bus='ps2'/>
diff --git a/tests/sexpr2xmldata/sexpr2xml-net-bridged.xml b/tests/sexpr2xmldata/sexpr2xml-net-bridged.xml
--- a/tests/sexpr2xmldata/sexpr2xml-net-bridged.xml
+++ b/tests/sexpr2xmldata/sexpr2xml-net-bridged.xml
@@ -23,6 +23,7 @@
     <interface type='bridge'>
       <mac address='00:11:22:33:44:55'/>
       <source bridge='xenbr2'/>
+      <script path='vif-bridge'/>
       <target dev='vif6.0'/>
     </interface>
     <console type='pty'>
diff --git a/tests/sexpr2xmldata/sexpr2xml-net-e1000.xml b/tests/sexpr2xmldata/sexpr2xml-net-e1000.xml
--- a/tests/sexpr2xmldata/sexpr2xml-net-e1000.xml
+++ b/tests/sexpr2xmldata/sexpr2xml-net-e1000.xml
@@ -23,6 +23,7 @@
     <interface type='bridge'>
       <mac address='00:11:22:33:44:55'/>
       <source bridge='xenbr2'/>
+      <script path='vif-bridge'/>
       <target dev='vif6.0'/>
       <model type='e1000'/>
     </interface>

--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]