Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
12a75f37
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看板
提交
12a75f37
编写于
7月 23, 2014
作者:
C
Cédric Bosdonnat
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
lxc conf2xml: convert IP addresses
上级
ecdc9383
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
97 addition
and
51 deletion
+97
-51
src/lxc/lxc_native.c
src/lxc/lxc_native.c
+93
-51
tests/lxcconf2xmldata/lxcconf2xml-simple.config
tests/lxcconf2xmldata/lxcconf2xml-simple.config
+2
-0
tests/lxcconf2xmldata/lxcconf2xml-simple.xml
tests/lxcconf2xmldata/lxcconf2xml-simple.xml
+2
-0
未找到文件。
src/lxc/lxc_native.c
浏览文件 @
12a75f37
...
...
@@ -413,79 +413,83 @@ lxcCreateHostdevDef(int mode, int type, const char *data)
return
hostdev
;
}
typedef
struct
{
virDomainDefPtr
def
;
char
*
type
;
char
*
link
;
char
*
mac
;
char
*
flag
;
char
*
macvlanmode
;
char
*
vlanid
;
char
*
name
;
virDomainNetIpDefPtr
*
ips
;
size_t
nips
;
bool
privnet
;
size_t
networks
;
}
lxcNetworkParseData
;
static
int
lxcAddNetworkDefinition
(
virDomainDefPtr
def
,
const
char
*
type
,
const
char
*
linkdev
,
const
char
*
mac
,
const
char
*
flag
,
const
char
*
macvlanmode
,
const
char
*
vlanid
,
const
char
*
name
)
lxcAddNetworkDefinition
(
lxcNetworkParseData
*
data
)
{
virDomainNetDefPtr
net
=
NULL
;
virDomainHostdevDefPtr
hostdev
=
NULL
;
bool
isPhys
,
isVlan
=
false
;
size_t
i
;
if
((
type
==
NULL
)
||
STREQ
(
type
,
"empty"
)
||
STREQ
(
type
,
"
"
)
||
STREQ
(
type
,
"none"
))
if
((
data
->
type
==
NULL
)
||
STREQ
(
data
->
type
,
"empty
"
)
||
STREQ
(
data
->
type
,
""
)
||
STREQ
(
data
->
type
,
"none"
))
return
0
;
isPhys
=
STREQ
(
type
,
"phys"
);
isVlan
=
STREQ
(
type
,
"vlan"
);
if
(
type
!=
NULL
&&
(
isPhys
||
isVlan
))
{
if
(
!
linkdev
)
{
isPhys
=
STREQ
(
data
->
type
,
"phys"
);
isVlan
=
STREQ
(
data
->
type
,
"vlan"
);
if
(
data
->
type
!=
NULL
&&
(
isPhys
||
isVlan
))
{
if
(
!
data
->
link
)
{
virReportError
(
VIR_ERR_CONFIG_UNSUPPORTED
,
"%s"
,
_
(
"Missing 'link' attribute for NIC"
));
goto
error
;
}
if
(
!
(
hostdev
=
lxcCreateHostdevDef
(
VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES
,
VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET
,
linkdev
)))
data
->
link
)))
goto
error
;
/* This still requires the user to manually setup the vlan interface
* on the host */
if
(
isVlan
&&
vlanid
)
{
if
(
isVlan
&&
data
->
vlanid
)
{
VIR_FREE
(
hostdev
->
source
.
caps
.
u
.
net
.
iface
);
if
(
virAsprintf
(
&
hostdev
->
source
.
caps
.
u
.
net
.
iface
,
"%s.%s"
,
linkdev
,
vlanid
)
<
0
)
"%s.%s"
,
data
->
link
,
data
->
vlanid
)
<
0
)
goto
error
;
}
if
(
VIR_EXPAND_N
(
d
ef
->
hostdevs
,
def
->
nhostdevs
,
1
)
<
0
)
if
(
VIR_EXPAND_N
(
d
ata
->
def
->
hostdevs
,
data
->
def
->
nhostdevs
,
1
)
<
0
)
goto
error
;
d
ef
->
hostdevs
[
def
->
nhostdevs
-
1
]
=
hostdev
;
d
ata
->
def
->
hostdevs
[
data
->
def
->
nhostdevs
-
1
]
=
hostdev
;
}
else
{
if
(
!
(
net
=
lxcCreateNetDef
(
type
,
linkdev
,
mac
,
flag
,
macvlanmode
,
name
)))
if
(
!
(
net
=
lxcCreateNetDef
(
data
->
type
,
data
->
link
,
data
->
mac
,
data
->
flag
,
data
->
macvlanmode
,
data
->
name
)))
goto
error
;
if
(
VIR_EXPAND_N
(
def
->
nets
,
def
->
nnets
,
1
)
<
0
)
net
->
ips
=
data
->
ips
;
net
->
nips
=
data
->
nips
;
if
(
VIR_EXPAND_N
(
data
->
def
->
nets
,
data
->
def
->
nnets
,
1
)
<
0
)
goto
error
;
d
ef
->
nets
[
def
->
nnets
-
1
]
=
net
;
d
ata
->
def
->
nets
[
data
->
def
->
nnets
-
1
]
=
net
;
}
return
1
;
error:
for
(
i
=
0
;
i
<
data
->
nips
;
i
++
)
VIR_FREE
(
data
->
ips
[
i
]);
VIR_FREE
(
data
->
ips
);
virDomainNetDefFree
(
net
);
virDomainHostdevDefFree
(
hostdev
);
return
-
1
;
}
typedef
struct
{
virDomainDefPtr
def
;
char
*
type
;
char
*
link
;
char
*
mac
;
char
*
flag
;
char
*
macvlanmode
;
char
*
vlanid
;
char
*
name
;
bool
privnet
;
size_t
networks
;
}
lxcNetworkParseData
;
static
int
lxcNetworkWalkCallback
(
const
char
*
name
,
virConfValuePtr
value
,
void
*
data
)
{
...
...
@@ -494,12 +498,7 @@ lxcNetworkWalkCallback(const char *name, virConfValuePtr value, void *data)
if
(
STREQ
(
name
,
"lxc.network.type"
))
{
/* Store the previous NIC */
status
=
lxcAddNetworkDefinition
(
parseData
->
def
,
parseData
->
type
,
parseData
->
link
,
parseData
->
mac
,
parseData
->
flag
,
parseData
->
macvlanmode
,
parseData
->
vlanid
,
parseData
->
name
);
status
=
lxcAddNetworkDefinition
(
parseData
);
if
(
status
<
0
)
return
-
1
;
...
...
@@ -517,6 +516,9 @@ lxcNetworkWalkCallback(const char *name, virConfValuePtr value, void *data)
parseData
->
vlanid
=
NULL
;
parseData
->
name
=
NULL
;
parseData
->
ips
=
NULL
;
parseData
->
nips
=
0
;
/* Keep the new value */
parseData
->
type
=
value
->
str
;
}
...
...
@@ -532,10 +534,42 @@ lxcNetworkWalkCallback(const char *name, virConfValuePtr value, void *data)
parseData
->
vlanid
=
value
->
str
;
else
if
(
STREQ
(
name
,
"lxc.network.name"
))
parseData
->
name
=
value
->
str
;
else
if
(
STRPREFIX
(
name
,
"lxc.network"
))
else
if
(
STREQ
(
name
,
"lxc.network.ipv4"
)
||
STREQ
(
name
,
"lxc.network.ipv6"
))
{
int
family
=
AF_INET
;
char
**
ipparts
=
NULL
;
virDomainNetIpDefPtr
ip
=
NULL
;
if
(
VIR_ALLOC
(
ip
)
<
0
)
return
-
1
;
if
(
STREQ
(
name
,
"lxc.network.ipv6"
))
family
=
AF_INET6
;
ipparts
=
virStringSplit
(
value
->
str
,
"/"
,
2
);
if
(
virStringListLength
(
ipparts
)
!=
2
||
virSocketAddrParse
(
&
ip
->
address
,
ipparts
[
0
],
family
)
<
0
||
virStrToLong_ui
(
ipparts
[
1
],
NULL
,
10
,
&
ip
->
prefix
)
<
0
)
{
virReportError
(
VIR_ERR_INVALID_ARG
,
_
(
"Invalid CIDR address: '%s'"
),
value
->
str
);
virStringFreeList
(
ipparts
);
VIR_FREE
(
ip
);
return
-
1
;
}
virStringFreeList
(
ipparts
);
if
(
VIR_APPEND_ELEMENT
(
parseData
->
ips
,
parseData
->
nips
,
ip
)
<
0
)
{
VIR_FREE
(
ip
);
return
-
1
;
}
}
else
if
(
STRPREFIX
(
name
,
"lxc.network"
))
{
VIR_WARN
(
"Unhandled network property: %s = %s"
,
name
,
value
->
str
);
}
return
0
;
}
...
...
@@ -544,19 +578,20 @@ static int
lxcConvertNetworkSettings
(
virDomainDefPtr
def
,
virConfPtr
properties
)
{
int
status
;
int
result
=
-
1
;
size_t
i
;
lxcNetworkParseData
data
=
{
def
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
,
true
,
0
};
NULL
,
NULL
,
NULL
,
NULL
,
0
,
true
,
0
};
if
(
virConfWalk
(
properties
,
lxcNetworkWalkCallback
,
&
data
)
<
0
)
goto
error
;
virConfWalk
(
properties
,
lxcNetworkWalkCallback
,
&
data
);
/* Add the last network definition found */
status
=
lxcAddNetworkDefinition
(
def
,
data
.
type
,
data
.
link
,
data
.
mac
,
data
.
flag
,
data
.
macvlanmode
,
data
.
vlanid
,
data
.
name
);
status
=
lxcAddNetworkDefinition
(
&
data
);
if
(
status
<
0
)
return
-
1
;
goto
error
;
else
if
(
status
>
0
)
data
.
networks
++
;
else
if
(
data
.
type
!=
NULL
&&
STREQ
(
data
.
type
,
"none"
))
...
...
@@ -566,8 +601,15 @@ lxcConvertNetworkSettings(virDomainDefPtr def, virConfPtr properties)
/* When no network type is provided LXC only adds loopback */
def
->
features
[
VIR_DOMAIN_FEATURE_PRIVNET
]
=
VIR_TRISTATE_SWITCH_ON
;
}
result
=
0
;
return
0
;
return
result
;
error:
for
(
i
=
0
;
i
<
data
.
nips
;
i
++
)
VIR_FREE
(
data
.
ips
[
i
]);
VIR_FREE
(
data
.
ips
);
return
-
1
;
}
static
int
...
...
tests/lxcconf2xmldata/lxcconf2xml-simple.config
浏览文件 @
12a75f37
...
...
@@ -6,6 +6,8 @@ lxc.network.flags = up
lxc
.
network
.
link
=
virbr0
lxc
.
network
.
hwaddr
=
02
:
00
:
15
:
8
f
:
05
:
c1
lxc
.
network
.
name
=
eth0
lxc
.
network
.
ipv4
=
192
.
168
.
122
.
2
/
24
lxc
.
network
.
ipv6
=
2003
:
db8
:
1
:
0
:
214
:
1234
:
fe0b
:
3596
/
64
#remove next line if host DNS configuration should not be available to container
lxc
.
mount
.
entry
=
proc
proc
proc
nodev
,
noexec
,
nosuid
0
0
...
...
tests/lxcconf2xmldata/lxcconf2xml-simple.xml
浏览文件 @
12a75f37
...
...
@@ -37,6 +37,8 @@
<interface
type=
'bridge'
>
<mac
address=
'02:00:15:8f:05:c1'
/>
<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'
/>
<guest
dev=
'eth0'
/>
<link
state=
'up'
/>
</interface>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录