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

[Libvir] Support non-bridged network configs



The current code for parsing/serializing VIFs only really deals with the
default bridged networking config for Xen. So if one uses network-route
or network-nat it completely breaks. There is also no support for dealing
with IP address in the XML / SEXPR. The attached patch fixes both of these
issues, so we should be able to deal with any of the standard Xen networking
configs.

Regards,
Dan.
-- 
|=- Red Hat, Engineering, Emerging Technologies, Boston.  +1 978 392 2496 -=|
|=-           Perl modules: http://search.cpan.org/~danberr/              -=|
|=-               Projects: http://freshmeat.net/~danielpb/               -=|
|=-  GnuPG: 7D3B9505   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505  -=| 
diff -c -r1.72 xend_internal.c
*** src/xend_internal.c	10 Nov 2006 11:13:01 -0000	1.72
--- src/xend_internal.c	10 Nov 2006 22:24:39 -0000
***************
*** 1698,1735 ****
              if (drvType)
                  free(drvType);
          } else if (sexpr_lookup(node, "device/vif")) {
!             const char *tmp2;
! 
!             tmp = sexpr_node(node, "device/vif/bridge");
!             tmp2 = sexpr_node(node, "device/vif/script");
!             if ((tmp != NULL) || (strstr(tmp2, "bridge"))) {
                  virBufferVSprintf(&buf, "    <interface type='bridge'>\n");
!                 if (tmp != NULL)
!                     virBufferVSprintf(&buf, "      <source bridge='%s'/>\n",
!                                       tmp);
!                 tmp = sexpr_node(node, "device/vif/vifname");
!                 if (tmp != NULL)
!                     virBufferVSprintf(&buf, "      <target dev='%s'/>\n",
!                                       tmp);
!                 tmp = sexpr_node(node, "device/vif/mac");
!                 if (tmp != NULL)
!                     virBufferVSprintf(&buf, "      <mac address='%s'/>\n",
!                                       tmp);
!                 tmp = sexpr_node(node, "device/vif/ip");
!                 if (tmp != NULL)
!                     virBufferVSprintf(&buf, "      <ip address='%s'/>\n",
!                                       tmp);
                  if (tmp2 != NULL)
!                     virBufferVSprintf(&buf, "      <script path='%s'/>\n",
                                        tmp2);
-                 virBufferAdd(&buf, "    </interface>\n", 17);
              } else {
!                 char serial[1000];
! 
!                 TODO sexpr2string(node, serial, 1000);
!                 virBufferVSprintf(&buf, "<!-- Failed to parse vif: %s -->\n",
!                                   serial);
              }
          }
      }
  
--- 1698,1732 ----
              if (drvType)
                  free(drvType);
          } else if (sexpr_lookup(node, "device/vif")) {
!             tmp = sexpr_node(node, "device/vif/script");
!             if (tmp && strstr(tmp, "bridge")) {
!                 const char *tmp2;
                  virBufferVSprintf(&buf, "    <interface type='bridge'>\n");
! 
!                 tmp2 = sexpr_node(node, "device/vif/bridge");
                  if (tmp2 != NULL)
!                     virBufferVSprintf(&buf, "      <source bridge='%s'/>\n",
                                        tmp2);
              } else {
!                 virBufferVSprintf(&buf, "    <interface type='default'>\n");
              }
+             if (tmp)
+                 virBufferVSprintf(&buf, "      <script path='%s'/>\n",
+                                   tmp);
+ 
+             tmp = sexpr_node(node, "device/vif/vifname");
+             if (tmp)
+                 virBufferVSprintf(&buf, "      <target dev='%s'/>\n",
+                                   tmp);
+             tmp = sexpr_node(node, "device/vif/mac");
+             if (tmp)
+                 virBufferVSprintf(&buf, "      <mac address='%s'/>\n",
+                                   tmp);
+             tmp = sexpr_node(node, "device/vif/ip");
+             if (tmp)
+                 virBufferVSprintf(&buf, "      <ip address='%s'/>\n",
+                                   tmp);
+             virBufferAdd(&buf, "    </interface>\n", 17);
          }
      }
  
diff -c -r1.45 xml.c
*** src/xml.c	10 Nov 2006 11:13:01 -0000	1.45
--- src/xml.c	10 Nov 2006 22:24:41 -0000
***************
*** 1113,1118 ****
--- 1116,1122 ----
      xmlChar *source = NULL;
      xmlChar *mac = NULL;
      xmlChar *script = NULL;
+     xmlChar *ip = NULL;
      int typ = 0;
  
      type = xmlGetProp(node, BAD_CAST "type");
***************
*** 1139,1144 ****
--- 1143,1155 ----
              } else if ((script == NULL) &&
                         (xmlStrEqual(cur->name, BAD_CAST "script"))) {
                  script = xmlGetProp(cur, BAD_CAST "path");
+             } else if ((ip == NULL) &&
+                        (xmlStrEqual(cur->name, BAD_CAST "ip"))) {
+                 /* XXX in future expect to need to have > 1 ip
+                    address element - eg ipv4 & ipv6. For now
+                    xen only supports a single address though
+                    so lets ignore that complication */
+                 ip = xmlGetProp(cur, BAD_CAST "address");
              }
          }
          cur = cur->next;
***************
*** 1155,1160 ****
--- 1166,1173 ----
      }
      if (script != NULL)
          virBufferVSprintf(buf, "(script '%s')", script);
+     if (ip != NULL)
+         virBufferVSprintf(buf, "(ip '%s')", ip);
      if (hvm)
          virBufferAdd(buf, "(type ioemu)", 12);
  
***************
*** 1165,1170 ****
--- 1178,1185 ----
          xmlFree(source);
      if (script != NULL)
          xmlFree(script);
+     if (ip != NULL)
+         xmlFree(ip);
      return (0);
  }
  
diff -c -r1.2 sexpr2xml-fv-v2.xml
*** tests/sexpr2xmldata/sexpr2xml-fv-v2.xml	9 Oct 2006 14:32:07 -0000	1.2
--- tests/sexpr2xmldata/sexpr2xml-fv-v2.xml	10 Nov 2006 22:24:41 -0000
***************
*** 29,36 ****
      </disk>
      <interface type='bridge'>
        <source bridge='xenbr0'/>
-       <mac address='00:16:3e:1b:b1:47'/>
        <script path='vif-bridge'/>
      </interface>
      <graphics type='vnc' port='5903'/>
    </devices>
--- 29,36 ----
      </disk>
      <interface type='bridge'>
        <source bridge='xenbr0'/>
        <script path='vif-bridge'/>
+       <mac address='00:16:3e:1b:b1:47'/>
      </interface>
      <graphics type='vnc' port='5903'/>
    </devices>
diff -c -r1.2 sexpr2xml-fv.xml
*** tests/sexpr2xmldata/sexpr2xml-fv.xml	9 Oct 2006 14:32:07 -0000	1.2
--- tests/sexpr2xmldata/sexpr2xml-fv.xml	10 Nov 2006 22:24:41 -0000
***************
*** 23,30 ****
      </disk>
      <interface type='bridge'>
        <source bridge='xenbr0'/>
-       <mac address='00:16:3e:1b:b1:47'/>
        <script path='vif-bridge'/>
      </interface>
      <disk type='file' device='cdrom'>
        <driver name='file'/>
--- 23,30 ----
      </disk>
      <interface type='bridge'>
        <source bridge='xenbr0'/>
        <script path='vif-bridge'/>
+       <mac address='00:16:3e:1b:b1:47'/>
      </interface>
      <disk type='file' device='cdrom'>
        <driver name='file'/>

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