From 25467c3a2d21fabee17a87b68fde73c728c82352 Mon Sep 17 00:00:00 2001 From: rd235 Date: Mon, 10 Jan 2011 14:41:35 +0000 Subject: [PATCH] Basic support for libvirt (uml, qemu/kvm) git-svn-id: https://vde.svn.sourceforge.net/svnroot/vde/trunk@457 d37a7db1-d92d-0410-89df-f68f52f87b57 --- vde-2/libvirt/README | 22 ++++++ vde-2/libvirt/libvirt-0.8.7.vde.patch | 140 ++++++++++++++++++++++++++++++++++ vde-2/src/vde_switch/plugins/iplog.c | 40 +++++----- 3 files changed, 184 insertions(+), 18 deletions(-) create mode 100644 vde-2/libvirt/README create mode 100644 vde-2/libvirt/libvirt-0.8.7.vde.patch diff --git a/vde-2/libvirt/README b/vde-2/libvirt/README new file mode 100644 index 0000000..bf308b4 --- /dev/null +++ b/vde-2/libvirt/README @@ -0,0 +1,22 @@ +This patch defines and manages the syntax: + + + + + ... + + + + + +the switch tag can be omitted: vde uses the default switch. +qemu/kvm support: tested. +user-mode linux support is included but not tested yet. +libvirt vde support for virtualbox has not been coded yet. + +INSTALL: +download libvirt-0.8.7 +..../libvirt-0.8.7$ patch -p 1 < libvirt-0.8.7.vde.patch +..../libvirt-0.8.7$ configure +..../libvirt-0.8.7$ make +..../libvirt-0.8.7$ sudo make install diff --git a/vde-2/libvirt/libvirt-0.8.7.vde.patch b/vde-2/libvirt/libvirt-0.8.7.vde.patch new file mode 100644 index 0000000..baba961 --- /dev/null +++ b/vde-2/libvirt/libvirt-0.8.7.vde.patch @@ -0,0 +1,140 @@ +--- a/src/lxc/lxc_driver.c 2011-01-10 11:49:49.000000000 +0100 ++++ b/src/lxc/lxc_driver.c 2011-01-10 11:50:03.000000000 +0100 +@@ -1083,6 +1083,7 @@ + case VIR_DOMAIN_NET_TYPE_INTERNAL: + case VIR_DOMAIN_NET_TYPE_DIRECT: + case VIR_DOMAIN_NET_TYPE_LAST: ++ case VIR_DOMAIN_NET_TYPE_VDE: + break; + } + +--- a/src/uml/uml_conf.c 2011-01-10 12:03:54.000000000 +0100 ++++ b/src/uml/uml_conf.c 2011-01-10 13:26:08.000000000 +0100 +@@ -269,6 +269,14 @@ + virBufferVSprintf(&buf, "tuntap,%s", def->ifname); + break; + ++ case VIR_DOMAIN_NET_TYPE_VDE: ++ /* ethNNN=vde,vde_switch,macaddr,port,group,mode,description */ ++ if (def->data.vde.vdeswitch) { ++ virBufferVSprintf(&buf, "vde,%s", def->data.vde.vdeswitch); ++ } else ++ virBufferAddLit(&buf, "vde"); ++ break; ++ + case VIR_DOMAIN_NET_TYPE_INTERNAL: + umlReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("internal networking type not supported")); +--- a/src/conf/domain_conf.h 2011-01-10 11:41:07.000000000 +0100 ++++ b/src/conf/domain_conf.h 2011-01-10 13:21:08.000000000 +0100 +@@ -288,6 +288,7 @@ + VIR_DOMAIN_NET_TYPE_BRIDGE, + VIR_DOMAIN_NET_TYPE_INTERNAL, + VIR_DOMAIN_NET_TYPE_DIRECT, ++ VIR_DOMAIN_NET_TYPE_VDE, + + VIR_DOMAIN_NET_TYPE_LAST, + }; +@@ -336,6 +337,9 @@ + int mode; + virVirtualPortProfileParams virtPortProfile; + } direct; ++ struct { ++ char *vdeswitch; ++ } vde; + } data; + char *ifname; + virDomainDeviceInfo info; +--- a/src/conf/domain_conf.c 2011-01-10 11:42:04.000000000 +0100 ++++ b/src/conf/domain_conf.c 2011-01-10 14:49:46.000000000 +0100 +@@ -182,7 +182,8 @@ + "network", + "bridge", + "internal", +- "direct") ++ "direct", ++ "vde") + + VIR_ENUM_IMPL(virDomainChrChannelTarget, + VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_LAST, +@@ -598,6 +599,10 @@ + VIR_FREE(def->data.direct.linkdev); + break; + ++ case VIR_DOMAIN_NET_TYPE_VDE: ++ VIR_FREE(def->data.vde.vdeswitch); ++ break; ++ + case VIR_DOMAIN_NET_TYPE_USER: + case VIR_DOMAIN_NET_TYPE_LAST: + break; +@@ -2293,6 +2298,7 @@ + char *internal = NULL; + char *devaddr = NULL; + char *mode = NULL; ++ char *vdeswitch = NULL; + virNWFilterHashTablePtr filterparams = NULL; + virVirtualPortProfileParams virtPort; + bool virtPortParsed = false; +@@ -2379,7 +2385,11 @@ + xmlStrEqual(cur->name, BAD_CAST "state")) { + /* Legacy back-compat. Don't add any more attributes here */ + devaddr = virXMLPropString(cur, "devaddr"); +- } ++ } else if ((vdeswitch == NULL) && ++ def->type == VIR_DOMAIN_NET_TYPE_VDE && ++ xmlStrEqual(cur->name, BAD_CAST "switch")) { ++ vdeswitch = virXMLPropString(cur, "path"); ++ } + } + cur = cur->next; + } +@@ -2529,6 +2539,11 @@ + + break; + ++ case VIR_DOMAIN_NET_TYPE_VDE: ++ def->data.vde.vdeswitch = vdeswitch; ++ vdeswitch = NULL; ++ break; ++ + case VIR_DOMAIN_NET_TYPE_USER: + case VIR_DOMAIN_NET_TYPE_LAST: + break; +@@ -6263,6 +6278,12 @@ + " "); + break; + ++ case VIR_DOMAIN_NET_TYPE_VDE: ++ if (def->data.vde.vdeswitch) ++ virBufferEscapeString(buf, " \n", ++ def->data.vde.vdeswitch); ++ break; ++ + case VIR_DOMAIN_NET_TYPE_USER: + case VIR_DOMAIN_NET_TYPE_LAST: + break; +--- a/src/qemu/qemu_command.c 2011-01-10 13:11:17.000000000 +0100 ++++ b/src/qemu/qemu_command.c 2011-01-10 13:26:28.000000000 +0100 +@@ -1602,12 +1602,21 @@ + case VIR_DOMAIN_NET_TYPE_BRIDGE: + case VIR_DOMAIN_NET_TYPE_INTERNAL: + case VIR_DOMAIN_NET_TYPE_DIRECT: ++ case VIR_DOMAIN_NET_TYPE_VDE: + case VIR_DOMAIN_NET_TYPE_LAST: + break; + } + type_sep = ','; + break; + ++ case VIR_DOMAIN_NET_TYPE_VDE: ++ virBufferAddLit(&buf, "vde"); ++ if (net->data.vde.vdeswitch) ++ virBufferVSprintf(&buf, "%csock=%s", ++ type_sep, ++ net->data.vde.vdeswitch); ++ break; ++ + case VIR_DOMAIN_NET_TYPE_USER: + default: + virBufferAddLit(&buf, "user"); diff --git a/vde-2/src/vde_switch/plugins/iplog.c b/vde-2/src/vde_switch/plugins/iplog.c index 3585d0a..a07e2bb 100644 --- a/vde-2/src/vde_switch/plugins/iplog.c +++ b/vde-2/src/vde_switch/plugins/iplog.c @@ -183,12 +183,14 @@ static void ip_find_in_hash_update(int len,unsigned char *addr,int vlan,int port } now=qtime(); e->last_seen = now; - if(e->port != port) { + if(e->port != port || e->vlan != vlan) { e->port=port; + e->vlan = vlan; char hostname[100]; char msg[256]; char lf[]="\n"; - struct iovec iov[]={{msg,0},{lf,1}}; + char stime[26]; + struct iovec iov[]={{stime+4,16},{msg,0},{lf,1}}; if ((len==4 && ip42string((uint32_t *)addr,hostname,sizeof(hostname))==0) || (len==16 && ip62string((uint32_t *)addr,hostname,sizeof(hostname))==0)) { @@ -198,11 +200,13 @@ static void ip_find_in_hash_update(int len,unsigned char *addr,int vlan,int port username="(none)"; else username=pwd->pw_name; - iov[0].iov_len=snprintf(msg,sizeof(msg),"ipv%d %s port=%d user=%s", - (len==4)?4:6, hostname, port, username); - if (logfilefd >= 0) - writev(logfilefd,iov,2); - else if (logfilefd != -1) + iov[1].iov_len=snprintf(msg,sizeof(msg),"ipv%d %s port=%d vlan=%d user=%s", + (len==4)?4:6, hostname, port, vlan, username); + if (logfilefd >= 0) { + time_t ntime=time(&ntime); + ctime_r(&ntime,stime); + writev(logfilefd,iov,3); + } else if (logfilefd != -1) syslog(LOG_INFO, msg); DBGOUT(D_LOGIP_NEWIP,"%s",msg); } @@ -254,14 +258,6 @@ static void ip_hash_gc(void *arg) ip_for_all_hash(ip_gc, &t); } -/* delete all ip address on a specific port (when the port is closed) */ -static void port_gc(struct ip_hash_entry *e, void *arg) -{ - int *port=arg; - if(*port == e->port) - delete_hash_entry(e); -} - /* upcall from vde: new incomping packet */ #define UINT32(X) (((uint32_t *)&(X))) static int iplog_pktin(struct dbgcl *event,void *arg,va_list v) @@ -321,6 +317,14 @@ static int iplog_pktin(struct dbgcl *event,void *arg,va_list v) return 0; } +/* delete all ip address on a specific port (when the port is closed) */ +static void port_gc(struct ip_hash_entry *e, void *arg) +{ + int *port=arg; + if(*port == e->port) + delete_hash_entry(e); +} + /* upcall from vde: a port has been closed */ static int iplog_port_minus(struct dbgcl *event,void *arg,va_list v) { @@ -329,7 +333,7 @@ static int iplog_port_minus(struct dbgcl *event,void *arg,va_list v) return 0; } -/*user interface: chowinfo */ +/*user interface: showinfo */ static int ipshowinfo(FILE *fd) { printoutc(fd,"iplog: ip/port/user loggin plugin"); @@ -473,7 +477,7 @@ static void n2mask(int len,int n, uint32_t *out) out[i]=*(((uint32_t *)m)+i); } -/* cumpute the number of bits from a mask */ +/* compute the number of bits from a mask */ static int mask2n(int len, void *addr) { char *m=addr; @@ -700,7 +704,7 @@ static int iplog_ipsearch(FILE *fd,char *addr) struct sockaddr_in6 *ip6addr=(struct sockaddr_in6 *) ai->ai_addr; iplog_ipsearch_item(16, ip6addr->sin6_addr.s6_addr , fd); } else - return rv=EINVAL; + rv=EINVAL; freeaddrinfo(ai); return rv; } -- 2.11.4.GIT