Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
a1176529
L
libvirt
项目概览
openeuler
/
libvirt
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
L
libvirt
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
a1176529
编写于
1月 14, 2015
作者:
C
Cédric Bosdonnat
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use the network route definitions for domains
上级
ca481a6f
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
79 addition
and
173 deletion
+79
-173
docs/formatdomain.html.in
docs/formatdomain.html.in
+3
-6
docs/schemas/domaincommon.rng
docs/schemas/domaincommon.rng
+2
-27
docs/schemas/network.rng
docs/schemas/network.rng
+1
-1
docs/schemas/networkcommon.rng
docs/schemas/networkcommon.rng
+1
-1
src/conf/domain_conf.c
src/conf/domain_conf.c
+27
-94
src/conf/domain_conf.h
src/conf/domain_conf.h
+4
-10
src/conf/networkcommon_conf.c
src/conf/networkcommon_conf.c
+3
-3
src/conf/networkcommon_conf.h
src/conf/networkcommon_conf.h
+3
-3
src/lxc/lxc_container.c
src/lxc/lxc_container.c
+8
-14
src/lxc/lxc_native.c
src/lxc/lxc_native.c
+19
-6
tests/lxcconf2xmldata/lxcconf2xml-physnetwork.xml
tests/lxcconf2xmldata/lxcconf2xml-physnetwork.xml
+2
-2
tests/lxcconf2xmldata/lxcconf2xml-simple.xml
tests/lxcconf2xmldata/lxcconf2xml-simple.xml
+2
-2
tests/lxcxml2xmldata/lxc-hostdev.xml
tests/lxcxml2xmldata/lxc-hostdev.xml
+2
-2
tests/lxcxml2xmldata/lxc-idmap.xml
tests/lxcxml2xmldata/lxc-idmap.xml
+2
-2
未找到文件。
docs/formatdomain.html.in
浏览文件 @
a1176529
...
...
@@ -4371,12 +4371,9 @@ qemu-kvm -net nic,model=? /dev/null
<p>
<span
class=
"since"
>
Since 1.2.12
</span>
route elements can also be added
to define the network routes to use for the network device. This element
has a
<code>
family
</code>
attribute set either to
<code>
ipv4
</code>
or
<code>
ipv6
</code>
, a mandatory
<code>
via
</code>
attribute defining the
IP address to route throught and optional
<code>
address
</code>
and
<code>
prefix
</code>
attributes defining the target network range. If those aren't given, then
a default route will be set.
to define the network routes to use for the network device. The attributes
of this element are described in the documentation for the
<code>
route
</code>
element in
<a
href=
"formatnetwork.html#elementsStaticroute"
>
network definitions
</a>
.
This is only used by the LXC driver.
</p>
...
...
docs/schemas/domaincommon.rng
浏览文件 @
a1176529
...
...
@@ -2330,9 +2330,7 @@
</element>
</zeroOrMore>
<zeroOrMore>
<element
name=
"route"
>
<ref
name=
"route"
/>
</element>
<ref
name=
"route"
/>
</zeroOrMore>
<optional>
<element
name=
"script"
>
...
...
@@ -3602,27 +3600,6 @@
</element>
</define>
<define
name=
"route"
>
<interleave>
<attribute
name=
"family"
>
<ref
name=
"addr-family"
/>
</attribute>
<attribute
name=
"via"
>
<ref
name=
"ipAddr"
/>
</attribute>
<optional>
<attribute
name=
"address"
>
<ref
name=
"ipAddr"
/>
</attribute>
</optional>
<optional>
<attribute
name=
"prefix"
>
<ref
name=
"ipPrefix"
/>
</attribute>
</optional>
</interleave>
</define>
<define
name=
"hostdev"
>
<element
name=
"hostdev"
>
<interleave>
...
...
@@ -3859,9 +3836,7 @@
</element>
</zeroOrMore>
<zeroOrMore>
<element
name=
"route"
>
<ref
name=
"route"
/>
</element>
<ref
name=
"route"
/>
</zeroOrMore>
</interleave>
</define>
...
...
docs/schemas/network.rng
浏览文件 @
a1176529
...
...
@@ -371,7 +371,7 @@
</zeroOrMore>
<!-- <route> element -->
<zeroOrMore>
<ref
name=
"route
x
"
/>
<ref
name=
"route"
/>
</zeroOrMore>
</interleave>
</element>
...
...
docs/schemas/networkcommon.rng
浏览文件 @
a1176529
...
...
@@ -228,7 +228,7 @@
<!-- The (static) route element specifies a network address and gateway
address to access that network. Both the network address and
the gateway address must be specified. -->
<define
name=
'route
x
'
>
<define
name=
'route'
>
<element
name=
"route"
>
<optional>
<attribute
name=
"family"
><ref
name=
"addr-family"
/></attribute>
...
...
src/conf/domain_conf.c
浏览文件 @
a1176529
...
...
@@ -3,6 +3,7 @@
*
* Copyright (C) 2006-2014 Red Hat, Inc.
* Copyright (C) 2006-2008 Daniel P. Berrange
* Copyright (c) 2015 SUSE LINUX Products GmbH, Nuernberg, Germany.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
...
...
@@ -1448,10 +1449,10 @@ void virDomainNetDefFree(virDomainNetDefPtr def)
VIR_FREE(def->ips);
for (i = 0; i < def->nroutes; i++)
VIR_FREE
(def->routes[i]);
virNetworkRouteDefFree
(def->routes[i]);
VIR_FREE(def->routes);
virDomainDeviceInfoClear(&def->info);
virDomainDeviceInfoClear(&def->info);
VIR_FREE(def->filter);
virNWFilterHashTableFree(def->filterparams);
...
...
@@ -4810,64 +4811,6 @@ virDomainNetIpParseXML(xmlNodePtr node)
return NULL;
}
static virDomainNetRouteDefPtr
virDomainNetRouteParse(xmlNodePtr node)
{
virDomainNetRouteDefPtr route = NULL;
char *familyStr = NULL;
int family = AF_UNSPEC;
char *via = NULL;
char *to = NULL;
char *prefixStr = NULL;
to = virXMLPropString(node, "address");
if (!(via = virXMLPropString(node, "via"))) {
virReportError(VIR_ERR_INVALID_ARG, "%s",
_("Missing route address"));
goto error;
}
familyStr = virXMLPropString(node, "family");
if (familyStr && STREQ(familyStr, "ipv4"))
family = AF_INET;
else if (familyStr && STREQ(familyStr, "ipv6"))
family = AF_INET6;
else
family = virSocketAddrNumericFamily(via);
if (VIR_ALLOC(route) < 0)
goto error;
if (virSocketAddrParse(&route->via, via, family) < 0) {
virReportError(VIR_ERR_INVALID_ARG,
_("Failed to parse IP address: '%s'"),
via);
goto error;
}
if (to && virSocketAddrParse(&route->to, to, family) < 0) {
virReportError(VIR_ERR_INVALID_ARG,
_("Failed to parse IP address: '%s'"),
to);
goto error;
}
if (!(prefixStr = virXMLPropString(node, "prefix")) ||
(virStrToLong_ui(prefixStr, NULL, 10, &route->prefix) < 0)) {
}
return route;
error:
VIR_FREE(familyStr);
VIR_FREE(via);
VIR_FREE(to);
VIR_FREE(prefixStr);
VIR_FREE(route);
return NULL;
}
static int
virDomainHostdevDefParseXMLCaps(xmlNodePtr node ATTRIBUTE_UNUSED,
xmlXPathContextPtr ctxt,
...
...
@@ -4961,14 +4904,17 @@ virDomainHostdevDefParseXMLCaps(xmlNodePtr node ATTRIBUTE_UNUSED,
if (nroutenodes) {
size_t i;
for (i = 0; i < nroutenodes; i++) {
vir
DomainNetRouteDefPtr route = virDomainNetRouteParse(routenodes[i])
;
vir
NetworkRouteDefPtr route = NULL
;
if (!route)
if (!(route = virNetworkRouteDefParseXML(_("Domain hostdev device"),
routenodes[i],
ctxt)))
goto error;
if (VIR_APPEND_ELEMENT(def->source.caps.u.net.routes,
def->source.caps.u.net.nroutes, route) < 0) {
VIR_FREE
(route);
virNetworkRouteDefFree
(route);
goto error;
}
}
...
...
@@ -7429,7 +7375,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
size_t nips = 0;
virDomainNetIpDefPtr *ips = NULL;
size_t nroutes = 0;
vir
DomainNet
RouteDefPtr *routes = NULL;
vir
Network
RouteDefPtr *routes = NULL;
if (VIR_ALLOC(def) < 0)
return NULL;
...
...
@@ -7527,12 +7473,15 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
if (VIR_APPEND_ELEMENT(ips, nips, ip) < 0)
goto error;
} else if (xmlStrEqual(cur->name, BAD_CAST "route")) {
virDomainNetRouteDefPtr route = NULL;
if (!(route = virDomainNetRouteParse(cur)))
virNetworkRouteDefPtr route = NULL;
if (!(route = virNetworkRouteDefParseXML(_("Domain interface"),
cur, ctxt)))
goto error;
if (VIR_APPEND_ELEMENT(routes, nroutes, route) < 0)
if (VIR_APPEND_ELEMENT(routes, nroutes, route) < 0) {
virNetworkRouteDefFree(route);
goto error;
}
} else if (!ifname &&
xmlStrEqual(cur->name, BAD_CAST "target")) {
ifname = virXMLPropString(cur, "dev");
...
...
@@ -17271,35 +17220,17 @@ virDomainNetIpsFormat(virBufferPtr buf, virDomainNetIpDefPtr *ips, size_t nips)
}
}
static
void
static
int
virDomainNetRoutesFormat(virBufferPtr buf,
vir
DomainNet
RouteDefPtr *routes,
vir
Network
RouteDefPtr *routes,
size_t nroutes)
{
size_t i;
for (i = 0; i < nroutes; i++) {
virDomainNetRouteDefPtr route = routes[i];
const char *familyStr = NULL;
char *via = virSocketAddrFormat(&route->via);
char *to = NULL;
if (VIR_SOCKET_ADDR_IS_FAMILY(&route->via, AF_INET6))
familyStr = "ipv6";
else if (VIR_SOCKET_ADDR_IS_FAMILY(&route->via, AF_INET))
familyStr = "ipv4";
virBufferAsprintf(buf, "<route family='%s' via='%s'", familyStr, via);
if (VIR_SOCKET_ADDR_VALID(&route->to)) {
to = virSocketAddrFormat(&route->to);
virBufferAsprintf(buf, " address='%s'", to);
}
if (route->prefix > 0)
virBufferAsprintf(buf, " prefix='%d'", route->prefix);
virBufferAddLit(buf, "/>\n");
}
for (i = 0; i < nroutes; i++)
if (virNetworkRouteDefFormat(buf, routes[i]) < 0)
return -1;
return 0;
}
static int
...
...
@@ -17457,8 +17388,9 @@ virDomainHostdevDefFormatCaps(virBufferPtr buf,
if (def->source.caps.type == VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET) {
virDomainNetIpsFormat(buf, def->source.caps.u.net.ips,
def->source.caps.u.net.nips);
virDomainNetRoutesFormat(buf, def->source.caps.u.net.routes,
def->source.caps.u.net.nroutes);
if (virDomainNetRoutesFormat(buf, def->source.caps.u.net.routes,
def->source.caps.u.net.nroutes) < 0)
return -1;
}
return 0;
...
...
@@ -17848,7 +17780,8 @@ virDomainNetDefFormat(virBufferPtr buf,
}
virDomainNetIpsFormat(buf, def->ips, def->nips);
virDomainNetRoutesFormat(buf, def->routes, def->nroutes);
if (virDomainNetRoutesFormat(buf, def->routes, def->nroutes) < 0)
return -1;
virBufferEscapeString(buf, "<script path='%s'/>\n",
def->script);
...
...
src/conf/domain_conf.h
浏览文件 @
a1176529
...
...
@@ -3,6 +3,7 @@
*
* Copyright (C) 2006-2014 Red Hat, Inc.
* Copyright (C) 2006-2008 Daniel P. Berrange
* Copyright (c) 2015 SUSE LINUX Products GmbH, Nuernberg, Germany.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
...
...
@@ -35,6 +36,7 @@
# include "virthread.h"
# include "virhash.h"
# include "virsocketaddr.h"
# include "networkcommon_conf.h"
# include "nwfilter_params.h"
# include "numatune_conf.h"
# include "virnetdevmacvlan.h"
...
...
@@ -485,14 +487,6 @@ struct _virDomainNetIpDef {
unsigned
int
prefix
;
/* number of 1 bits in the net mask */
};
typedef
struct
_virDomainNetRouteDef
virDomainNetRouteDef
;
typedef
virDomainNetRouteDef
*
virDomainNetRouteDefPtr
;
struct
_virDomainNetRouteDef
{
virSocketAddr
via
;
virSocketAddr
to
;
unsigned
int
prefix
;
};
typedef
struct
_virDomainHostdevCaps
virDomainHostdevCaps
;
typedef
virDomainHostdevCaps
*
virDomainHostdevCapsPtr
;
struct
_virDomainHostdevCaps
{
...
...
@@ -509,7 +503,7 @@ struct _virDomainHostdevCaps {
size_t
nips
;
virDomainNetIpDefPtr
*
ips
;
size_t
nroutes
;
vir
DomainNet
RouteDefPtr
*
routes
;
vir
Network
RouteDefPtr
*
routes
;
}
net
;
}
u
;
};
...
...
@@ -1013,7 +1007,7 @@ struct _virDomainNetDef {
size_t
nips
;
virDomainNetIpDefPtr
*
ips
;
size_t
nroutes
;
vir
DomainNet
RouteDefPtr
*
routes
;
vir
Network
RouteDefPtr
*
routes
;
};
/* Used for prefix of ifname of any network name generated dynamically
...
...
src/conf/networkcommon_conf.c
浏览文件 @
a1176529
...
...
@@ -59,9 +59,9 @@ virNetworkRouteDefFree(virNetworkRouteDefPtr def)
virNetworkRouteDefPtr
virNetworkRouteDefCreate
(
const
char
*
errorDetail
,
char
*
family
,
char
*
address
,
char
*
netmask
,
char
*
gateway
,
c
onst
c
har
*
address
,
c
onst
c
har
*
netmask
,
c
onst
c
har
*
gateway
,
unsigned
int
prefix
,
bool
hasPrefix
,
unsigned
int
metric
,
...
...
src/conf/networkcommon_conf.h
浏览文件 @
a1176529
...
...
@@ -41,9 +41,9 @@ virNetworkRouteDefFree(virNetworkRouteDefPtr def);
virNetworkRouteDefPtr
virNetworkRouteDefCreate
(
const
char
*
networkName
,
char
*
family
,
char
*
address
,
char
*
netmask
,
char
*
gateway
,
c
onst
c
har
*
address
,
c
onst
c
har
*
netmask
,
c
onst
c
har
*
gateway
,
unsigned
int
prefix
,
bool
hasPrefix
,
unsigned
int
metric
,
...
...
src/lxc/lxc_container.c
浏览文件 @
a1176529
/*
* Copyright (C) 2008-2014 Red Hat, Inc.
* Copyright (C) 2008 IBM Corp.
* Copyright (c) 2015 SUSE LINUX Products GmbH, Nuernberg, Germany.
*
* lxc_container.c: file description
*
...
...
@@ -544,20 +545,13 @@ static int lxcContainerRenameAndEnableInterfaces(virDomainDefPtr vmDef,
/* Set the routes */
for
(
j
=
0
;
j
<
netDef
->
nroutes
;
j
++
)
{
virDomainNetRouteDefPtr
route
=
netDef
->
routes
[
j
];
if
(
VIR_SOCKET_ADDR_VALID
(
&
route
->
to
))
toStr
=
virSocketAddrFormat
(
&
route
->
to
);
else
if
(
VIR_STRDUP
(
toStr
,
"default"
)
<
0
)
goto
error_out
;
viaStr
=
virSocketAddrFormat
(
&
route
->
via
);
VIR_DEBUG
(
"Adding route %s/%d via %s"
,
toStr
,
route
->
prefix
,
viaStr
);
if
(
virNetDevAddRoute
(
newname
,
&
route
->
to
,
route
->
prefix
,
&
route
->
via
,
0
)
<
0
)
{
virReportError
(
VIR_ERR_SYSTEM_ERROR
,
_
(
"Failed to add route %s/%d via %s"
),
toStr
,
route
->
prefix
,
viaStr
);
virNetworkRouteDefPtr
route
=
netDef
->
routes
[
j
];
if
(
virNetDevAddRoute
(
newname
,
virNetworkRouteDefGetAddress
(
route
),
virNetworkRouteDefGetPrefix
(
route
),
virNetworkRouteDefGetGateway
(
route
),
virNetworkRouteDefGetMetric
(
route
))
<
0
)
{
goto
error_out
;
}
VIR_FREE
(
toStr
);
...
...
src/lxc/lxc_native.c
浏览文件 @
a1176529
...
...
@@ -2,7 +2,7 @@
* lxc_native.c: LXC native configuration import
*
* Copyright (c) 2014 Red Hat, Inc.
* Copyright (c) 2013 SUSE LINUX Products GmbH, Nuernberg, Germany.
* Copyright (c) 2013
-2015
SUSE LINUX Products GmbH, Nuernberg, Germany.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
...
...
@@ -433,24 +433,37 @@ typedef struct {
static
int
lxcAddNetworkRouteDefinition
(
const
char
*
address
,
int
family
,
vir
DomainNet
RouteDefPtr
**
routes
,
vir
Network
RouteDefPtr
**
routes
,
size_t
*
nroutes
)
{
virDomainNetRouteDefPtr
route
=
NULL
;
virNetworkRouteDefPtr
route
=
NULL
;
char
*
familyStr
=
NULL
;
char
*
zero
=
NULL
;
if
(
VIR_ALLOC
(
route
)
<
0
)
if
(
VIR_STRDUP
(
zero
,
family
==
AF_INET
?
VIR_SOCKET_ADDR_IPV4_ALL
:
VIR_SOCKET_ADDR_IPV6_ALL
)
<
0
)
goto
error
;
if
(
virSocketAddrParse
(
&
route
->
via
,
address
,
family
)
<
0
)
if
(
VIR_STRDUP
(
familyStr
,
family
==
AF_INET
?
"ipv4"
:
"ipv6"
)
<
0
)
goto
error
;
if
(
!
(
route
=
virNetworkRouteDefCreate
(
_
(
"Domain interface"
),
familyStr
,
zero
,
NULL
,
address
,
0
,
false
,
0
,
false
)))
goto
error
;
if
(
VIR_APPEND_ELEMENT
(
*
routes
,
*
nroutes
,
route
)
<
0
)
goto
error
;
VIR_FREE
(
familyStr
);
VIR_FREE
(
zero
);
return
0
;
error:
VIR_FREE
(
route
);
VIR_FREE
(
familyStr
);
VIR_FREE
(
zero
);
virNetworkRouteDefFree
(
route
);
return
-
1
;
}
...
...
tests/lxcconf2xmldata/lxcconf2xml-physnetwork.xml
浏览文件 @
a1176529
...
...
@@ -27,8 +27,8 @@
</source>
<ip
address=
'192.168.122.2'
family=
'ipv4'
prefix=
'24'
/>
<ip
address=
'2003:db8:1:0:214:1234:fe0b:3596'
family=
'ipv6'
prefix=
'64'
/>
<route
family=
'ipv4'
via
=
'192.168.122.1'
/>
<route
family=
'ipv6'
via
=
'2003:db8:1:0:214:1234:fe0b:3595'
/>
<route
family=
'ipv4'
address=
'0.0.0.0'
gateway
=
'192.168.122.1'
/>
<route
family=
'ipv6'
address=
'::'
gateway
=
'2003:db8:1:0:214:1234:fe0b:3595'
/>
</hostdev>
</devices>
</domain>
tests/lxcconf2xmldata/lxcconf2xml-simple.xml
浏览文件 @
a1176529
...
...
@@ -39,8 +39,8 @@
<source
bridge=
'virbr0'
/>
<ip
address=
'192.168.122.2'
family=
'ipv4'
prefix=
'24'
/>
<ip
address=
'2003:db8:1:0:214:1234:fe0b:3596'
family=
'ipv6'
prefix=
'64'
/>
<route
family=
'ipv4'
via
=
'192.168.122.1'
/>
<route
family=
'ipv6'
via
=
'2003:db8:1:0:214:1234:fe0b:3595'
/>
<route
family=
'ipv4'
address=
'0.0.0.0'
gateway
=
'192.168.122.1'
/>
<route
family=
'ipv6'
address=
'::'
gateway
=
'2003:db8:1:0:214:1234:fe0b:3595'
/>
<guest
dev=
'eth0'
/>
<link
state=
'up'
/>
</interface>
...
...
tests/lxcxml2xmldata/lxc-hostdev.xml
浏览文件 @
a1176529
...
...
@@ -37,8 +37,8 @@
</source>
<ip
address=
'192.168.122.2'
family=
'ipv4'
/>
<ip
address=
'2003:db8:1:0:214:1234:fe0b:3596'
family=
'ipv6'
prefix=
'24'
/>
<route
family=
'ipv4'
via
=
'192.168.122.1'
/>
<route
family=
'ipv6'
via
=
'2003:db8:1:0:214:1234:fe0b:3595'
/>
<route
family=
'ipv4'
address=
'0.0.0.0'
gateway
=
'192.168.122.1'
/>
<route
family=
'ipv6'
address=
'::'
gateway
=
'2003:db8:1:0:214:1234:fe0b:3595'
/>
</hostdev>
</devices>
</domain>
tests/lxcxml2xmldata/lxc-idmap.xml
浏览文件 @
a1176529
...
...
@@ -30,8 +30,8 @@
<source
bridge=
'bri0'
/>
<ip
address=
'192.168.122.12'
family=
'ipv4'
prefix=
'24'
/>
<ip
address=
'192.168.122.13'
family=
'ipv4'
prefix=
'24'
/>
<route
family=
'ipv4'
via
=
'192.168.122.1'
/>
<route
family=
'ipv4'
via=
'192.168.124.1'
address=
'192.168.124.0'
prefix=
'24
'
/>
<route
family=
'ipv4'
address=
'0.0.0.0'
gateway
=
'192.168.122.1'
/>
<route
family=
'ipv4'
address=
'192.168.124.0'
prefix=
'24'
gateway=
'192.168.124.1
'
/>
<target
dev=
'veth0'
/>
<guest
dev=
'eth2'
/>
</interface>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录