Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
8174e41b
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
8174e41b
编写于
9月 12, 2018
作者:
S
Shi Lei
提交者:
Michal Privoznik
9月 12, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
util: netdev: use VIR_AUTOCLOSE instead of VIR_FORCE_CLOSE
Signed-off-by:
N
Shi Lei
<
shi_lei@massclouds.com
>
上级
4f446cad
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
85 addition
and
166 deletion
+85
-166
src/util/virnetdev.c
src/util/virnetdev.c
+85
-166
未找到文件。
src/util/virnetdev.c
浏览文件 @
8174e41b
...
@@ -200,27 +200,22 @@ virNetDevSetupControl(const char *ifname ATTRIBUTE_UNUSED,
...
@@ -200,27 +200,22 @@ virNetDevSetupControl(const char *ifname ATTRIBUTE_UNUSED,
*/
*/
int
virNetDevExists
(
const
char
*
ifname
)
int
virNetDevExists
(
const
char
*
ifname
)
{
{
int
fd
=
-
1
;
int
ret
=
-
1
;
struct
ifreq
ifr
;
struct
ifreq
ifr
;
VIR_AUTOCLOSE
fd
=
-
1
;
if
((
fd
=
virNetDevSetupControl
(
ifname
,
&
ifr
))
<
0
)
if
((
fd
=
virNetDevSetupControl
(
ifname
,
&
ifr
))
<
0
)
return
-
1
;
return
-
1
;
if
(
ioctl
(
fd
,
SIOCGIFFLAGS
,
&
ifr
))
{
if
(
ioctl
(
fd
,
SIOCGIFFLAGS
,
&
ifr
))
{
if
(
errno
==
ENODEV
||
errno
==
ENXIO
)
if
(
errno
==
ENODEV
||
errno
==
ENXIO
)
ret
=
0
;
return
0
;
else
virReportSystemError
(
errno
,
_
(
"Unable to check interface flags for %s"
),
ifname
);
goto
cleanup
;
}
ret
=
1
;
virReportSystemError
(
errno
,
_
(
"Unable to check interface flags for %s"
),
ifname
);
return
-
1
;
}
cleanup:
return
1
;
VIR_FORCE_CLOSE
(
fd
);
return
ret
;
}
}
#else
#else
int
virNetDevExists
(
const
char
*
ifname
)
int
virNetDevExists
(
const
char
*
ifname
)
...
@@ -251,20 +246,20 @@ virNetDevSetMACInternal(const char *ifname,
...
@@ -251,20 +246,20 @@ virNetDevSetMACInternal(const char *ifname,
const
virMacAddr
*
macaddr
,
const
virMacAddr
*
macaddr
,
bool
quiet
)
bool
quiet
)
{
{
int
fd
=
-
1
;
int
ret
=
-
1
;
struct
ifreq
ifr
;
struct
ifreq
ifr
;
char
macstr
[
VIR_MAC_STRING_BUFLEN
];
char
macstr
[
VIR_MAC_STRING_BUFLEN
];
VIR_AUTOCLOSE
fd
=
-
1
;
if
((
fd
=
virNetDevSetupControl
(
ifname
,
&
ifr
))
<
0
)
if
((
fd
=
virNetDevSetupControl
(
ifname
,
&
ifr
))
<
0
)
return
-
1
;
return
-
1
;
/* To fill ifr.ifr_hdaddr.sa_family field */
/* To fill ifr.ifr_hdaddr.sa_family field */
if
(
ioctl
(
fd
,
SIOCGIFHWADDR
,
&
ifr
)
<
0
)
{
if
(
ioctl
(
fd
,
SIOCGIFHWADDR
,
&
ifr
)
<
0
)
{
virReportSystemError
(
errno
,
virReportSystemError
(
errno
,
_
(
"Cannot get interface MAC on '%s'"
),
_
(
"Cannot get interface MAC on '%s'"
),
ifname
);
ifname
);
goto
cleanup
;
VIR_DEBUG
(
"SIOCSIFHWADDR %s get MAC - Fail"
,
ifname
);
return
-
1
;
}
}
virMacAddrGetRaw
(
macaddr
,
(
unsigned
char
*
)
ifr
.
ifr_hwaddr
.
sa_data
);
virMacAddrGetRaw
(
macaddr
,
(
unsigned
char
*
)
ifr
.
ifr_hwaddr
.
sa_data
);
...
@@ -272,24 +267,22 @@ virNetDevSetMACInternal(const char *ifname,
...
@@ -272,24 +267,22 @@ virNetDevSetMACInternal(const char *ifname,
if
(
ioctl
(
fd
,
SIOCSIFHWADDR
,
&
ifr
)
<
0
)
{
if
(
ioctl
(
fd
,
SIOCSIFHWADDR
,
&
ifr
)
<
0
)
{
if
(
quiet
&&
if
(
quiet
&&
(
errno
==
EADDRNOTAVAIL
||
errno
==
EPERM
))
(
errno
==
EADDRNOTAVAIL
||
errno
==
EPERM
))
{
goto
cleanup
;
VIR_DEBUG
(
"SIOCSIFHWADDR %s MAC=%s - Fail"
,
ifname
,
virMacAddrFormat
(
macaddr
,
macstr
));
return
-
1
;
}
virReportSystemError
(
errno
,
virReportSystemError
(
errno
,
_
(
"Cannot set interface MAC to %s on '%s'"
),
_
(
"Cannot set interface MAC to %s on '%s'"
),
virMacAddrFormat
(
macaddr
,
macstr
),
ifname
);
virMacAddrFormat
(
macaddr
,
macstr
),
ifname
);
goto
cleanup
;
return
-
1
;
}
}
ret
=
0
;
VIR_DEBUG
(
"SIOCSIFHWADDR %s MAC=%s - Success"
,
ifname
,
virMacAddrFormat
(
macaddr
,
macstr
));
cleanup:
return
0
;
VIR_DEBUG
(
"SIOCSIFHWADDR %s MAC=%s - %s"
,
ifname
,
virMacAddrFormat
(
macaddr
,
macstr
),
ret
<
0
?
"Fail"
:
"Success"
);
VIR_FORCE_CLOSE
(
fd
);
return
ret
;
}
}
...
@@ -305,8 +298,7 @@ virNetDevSetMACInternal(const char *ifname,
...
@@ -305,8 +298,7 @@ virNetDevSetMACInternal(const char *ifname,
struct
ifreq
ifr
;
struct
ifreq
ifr
;
struct
sockaddr_dl
sdl
;
struct
sockaddr_dl
sdl
;
char
mac
[
VIR_MAC_STRING_BUFLEN
+
1
]
=
":"
;
char
mac
[
VIR_MAC_STRING_BUFLEN
+
1
]
=
":"
;
int
s
;
VIR_AUTOCLOSE
s
=
-
1
;
int
ret
=
-
1
;
if
((
s
=
virNetDevSetupControl
(
ifname
,
&
ifr
))
<
0
)
if
((
s
=
virNetDevSetupControl
(
ifname
,
&
ifr
))
<
0
)
return
-
1
;
return
-
1
;
...
@@ -320,23 +312,19 @@ virNetDevSetMACInternal(const char *ifname,
...
@@ -320,23 +312,19 @@ virNetDevSetMACInternal(const char *ifname,
if
(
ioctl
(
s
,
SIOCSIFLLADDR
,
&
ifr
)
<
0
)
{
if
(
ioctl
(
s
,
SIOCSIFLLADDR
,
&
ifr
)
<
0
)
{
if
(
quiet
&&
if
(
quiet
&&
(
errno
==
EADDRNOTAVAIL
||
errno
==
EPERM
))
(
errno
==
EADDRNOTAVAIL
||
errno
==
EPERM
))
{
goto
cleanup
;
VIR_DEBUG
(
"SIOCSIFLLADDR %s MAC=%s - Fail"
,
ifname
,
mac
+
1
);
return
-
1
;
}
virReportSystemError
(
errno
,
virReportSystemError
(
errno
,
_
(
"Cannot set interface MAC to %s on '%s'"
),
_
(
"Cannot set interface MAC to %s on '%s'"
),
mac
+
1
,
ifname
);
mac
+
1
,
ifname
);
goto
cleanup
;
return
-
1
;
}
}
ret
=
0
;
VIR_DEBUG
(
"SIOCSIFLLADDR %s MAC=%s - Success"
,
ifname
,
mac
+
1
);
cleanup:
return
0
;
VIR_DEBUG
(
"SIOCSIFLLADDR %s MAC=%s - %s"
,
ifname
,
mac
+
1
,
ret
<
0
?
"Fail"
:
"Success"
);
VIR_FORCE_CLOSE
(
s
);
return
ret
;
}
}
...
@@ -379,9 +367,8 @@ virNetDevSetMAC(const char *ifname,
...
@@ -379,9 +367,8 @@ virNetDevSetMAC(const char *ifname,
int
virNetDevGetMAC
(
const
char
*
ifname
,
int
virNetDevGetMAC
(
const
char
*
ifname
,
virMacAddrPtr
macaddr
)
virMacAddrPtr
macaddr
)
{
{
int
fd
=
-
1
;
int
ret
=
-
1
;
struct
ifreq
ifr
;
struct
ifreq
ifr
;
VIR_AUTOCLOSE
fd
=
-
1
;
if
((
fd
=
virNetDevSetupControl
(
ifname
,
&
ifr
))
<
0
)
if
((
fd
=
virNetDevSetupControl
(
ifname
,
&
ifr
))
<
0
)
return
-
1
;
return
-
1
;
...
@@ -390,16 +377,12 @@ int virNetDevGetMAC(const char *ifname,
...
@@ -390,16 +377,12 @@ int virNetDevGetMAC(const char *ifname,
virReportSystemError
(
errno
,
virReportSystemError
(
errno
,
_
(
"Cannot get interface MAC on '%s'"
),
_
(
"Cannot get interface MAC on '%s'"
),
ifname
);
ifname
);
goto
cleanup
;
return
-
1
;
}
}
virMacAddrSetRaw
(
macaddr
,
(
unsigned
char
*
)
ifr
.
ifr_hwaddr
.
sa_data
);
virMacAddrSetRaw
(
macaddr
,
(
unsigned
char
*
)
ifr
.
ifr_hwaddr
.
sa_data
);
ret
=
0
;
return
0
;
cleanup:
VIR_FORCE_CLOSE
(
fd
);
return
ret
;
}
}
#else
#else
int
virNetDevGetMAC
(
const
char
*
ifname
,
int
virNetDevGetMAC
(
const
char
*
ifname
,
...
@@ -424,9 +407,8 @@ int virNetDevGetMAC(const char *ifname,
...
@@ -424,9 +407,8 @@ int virNetDevGetMAC(const char *ifname,
*/
*/
int
virNetDevGetMTU
(
const
char
*
ifname
)
int
virNetDevGetMTU
(
const
char
*
ifname
)
{
{
int
fd
=
-
1
;
int
ret
=
-
1
;
struct
ifreq
ifr
;
struct
ifreq
ifr
;
VIR_AUTOCLOSE
fd
=
-
1
;
if
((
fd
=
virNetDevSetupControl
(
ifname
,
&
ifr
))
<
0
)
if
((
fd
=
virNetDevSetupControl
(
ifname
,
&
ifr
))
<
0
)
return
-
1
;
return
-
1
;
...
@@ -435,14 +417,10 @@ int virNetDevGetMTU(const char *ifname)
...
@@ -435,14 +417,10 @@ int virNetDevGetMTU(const char *ifname)
virReportSystemError
(
errno
,
virReportSystemError
(
errno
,
_
(
"Cannot get interface MTU on '%s'"
),
_
(
"Cannot get interface MTU on '%s'"
),
ifname
);
ifname
);
goto
cleanup
;
return
-
1
;
}
}
ret
=
ifr
.
ifr_mtu
;
return
ifr
.
ifr_mtu
;
cleanup:
VIR_FORCE_CLOSE
(
fd
);
return
ret
;
}
}
#else
#else
int
virNetDevGetMTU
(
const
char
*
ifname
)
int
virNetDevGetMTU
(
const
char
*
ifname
)
...
@@ -468,9 +446,8 @@ int virNetDevGetMTU(const char *ifname)
...
@@ -468,9 +446,8 @@ int virNetDevGetMTU(const char *ifname)
*/
*/
int
virNetDevSetMTU
(
const
char
*
ifname
,
int
mtu
)
int
virNetDevSetMTU
(
const
char
*
ifname
,
int
mtu
)
{
{
int
fd
=
-
1
;
int
ret
=
-
1
;
struct
ifreq
ifr
;
struct
ifreq
ifr
;
VIR_AUTOCLOSE
fd
=
-
1
;
if
((
fd
=
virNetDevSetupControl
(
ifname
,
&
ifr
))
<
0
)
if
((
fd
=
virNetDevSetupControl
(
ifname
,
&
ifr
))
<
0
)
return
-
1
;
return
-
1
;
...
@@ -481,14 +458,10 @@ int virNetDevSetMTU(const char *ifname, int mtu)
...
@@ -481,14 +458,10 @@ int virNetDevSetMTU(const char *ifname, int mtu)
virReportSystemError
(
errno
,
virReportSystemError
(
errno
,
_
(
"Cannot set interface MTU on '%s'"
),
_
(
"Cannot set interface MTU on '%s'"
),
ifname
);
ifname
);
goto
cleanup
;
return
-
1
;
}
}
ret
=
0
;
return
0
;
cleanup:
VIR_FORCE_CLOSE
(
fd
);
return
ret
;
}
}
#else
#else
int
virNetDevSetMTU
(
const
char
*
ifname
,
int
mtu
ATTRIBUTE_UNUSED
)
int
virNetDevSetMTU
(
const
char
*
ifname
,
int
mtu
ATTRIBUTE_UNUSED
)
...
@@ -592,9 +565,8 @@ int virNetDevSetNamespace(const char *ifname, pid_t pidInNs)
...
@@ -592,9 +565,8 @@ int virNetDevSetNamespace(const char *ifname, pid_t pidInNs)
*/
*/
int
virNetDevSetName
(
const
char
*
ifname
,
const
char
*
newifname
)
int
virNetDevSetName
(
const
char
*
ifname
,
const
char
*
newifname
)
{
{
int
fd
=
-
1
;
int
ret
=
-
1
;
struct
ifreq
ifr
;
struct
ifreq
ifr
;
VIR_AUTOCLOSE
fd
=
-
1
;
if
((
fd
=
virNetDevSetupControl
(
ifname
,
&
ifr
))
<
0
)
if
((
fd
=
virNetDevSetupControl
(
ifname
,
&
ifr
))
<
0
)
return
-
1
;
return
-
1
;
...
@@ -604,7 +576,7 @@ int virNetDevSetName(const char* ifname, const char *newifname)
...
@@ -604,7 +576,7 @@ int virNetDevSetName(const char* ifname, const char *newifname)
virReportSystemError
(
ERANGE
,
virReportSystemError
(
ERANGE
,
_
(
"Network interface name '%s' is too long"
),
_
(
"Network interface name '%s' is too long"
),
newifname
);
newifname
);
goto
cleanup
;
return
-
1
;
}
}
# else
# else
ifr
.
ifr_data
=
(
caddr_t
)
newifname
;
ifr
.
ifr_data
=
(
caddr_t
)
newifname
;
...
@@ -614,14 +586,10 @@ int virNetDevSetName(const char* ifname, const char *newifname)
...
@@ -614,14 +586,10 @@ int virNetDevSetName(const char* ifname, const char *newifname)
virReportSystemError
(
errno
,
virReportSystemError
(
errno
,
_
(
"Unable to rename '%s' to '%s'"
),
_
(
"Unable to rename '%s' to '%s'"
),
ifname
,
newifname
);
ifname
,
newifname
);
goto
cleanup
;
return
-
1
;
}
}
ret
=
0
;
return
0
;
cleanup:
VIR_FORCE_CLOSE
(
fd
);
return
ret
;
}
}
#else
#else
int
virNetDevSetName
(
const
char
*
ifname
,
const
char
*
newifname
)
int
virNetDevSetName
(
const
char
*
ifname
,
const
char
*
newifname
)
...
@@ -638,10 +606,9 @@ int virNetDevSetName(const char* ifname, const char *newifname)
...
@@ -638,10 +606,9 @@ int virNetDevSetName(const char* ifname, const char *newifname)
static
int
static
int
virNetDevSetIFFlag
(
const
char
*
ifname
,
int
flag
,
bool
val
)
virNetDevSetIFFlag
(
const
char
*
ifname
,
int
flag
,
bool
val
)
{
{
int
fd
=
-
1
;
int
ret
=
-
1
;
struct
ifreq
ifr
;
struct
ifreq
ifr
;
int
ifflags
;
int
ifflags
;
VIR_AUTOCLOSE
fd
=
-
1
;
if
((
fd
=
virNetDevSetupControl
(
ifname
,
&
ifr
))
<
0
)
if
((
fd
=
virNetDevSetupControl
(
ifname
,
&
ifr
))
<
0
)
return
-
1
;
return
-
1
;
...
@@ -650,7 +617,7 @@ virNetDevSetIFFlag(const char *ifname, int flag, bool val)
...
@@ -650,7 +617,7 @@ virNetDevSetIFFlag(const char *ifname, int flag, bool val)
virReportSystemError
(
errno
,
virReportSystemError
(
errno
,
_
(
"Cannot get interface flags on '%s'"
),
_
(
"Cannot get interface flags on '%s'"
),
ifname
);
ifname
);
goto
cleanup
;
return
-
1
;
}
}
if
(
val
)
if
(
val
)
...
@@ -664,15 +631,11 @@ virNetDevSetIFFlag(const char *ifname, int flag, bool val)
...
@@ -664,15 +631,11 @@ virNetDevSetIFFlag(const char *ifname, int flag, bool val)
virReportSystemError
(
errno
,
virReportSystemError
(
errno
,
_
(
"Cannot set interface flags on '%s'"
),
_
(
"Cannot set interface flags on '%s'"
),
ifname
);
ifname
);
goto
cleanup
;
return
-
1
;
}
}
}
}
ret
=
0
;
return
0
;
cleanup:
VIR_FORCE_CLOSE
(
fd
);
return
ret
;
}
}
#else
#else
static
int
static
int
...
@@ -765,9 +728,8 @@ virNetDevSetRcvAllMulti(const char *ifname,
...
@@ -765,9 +728,8 @@ virNetDevSetRcvAllMulti(const char *ifname,
static
int
static
int
virNetDevGetIFFlag
(
const
char
*
ifname
,
int
flag
,
bool
*
val
)
virNetDevGetIFFlag
(
const
char
*
ifname
,
int
flag
,
bool
*
val
)
{
{
int
fd
=
-
1
;
int
ret
=
-
1
;
struct
ifreq
ifr
;
struct
ifreq
ifr
;
VIR_AUTOCLOSE
fd
=
-
1
;
if
((
fd
=
virNetDevSetupControl
(
ifname
,
&
ifr
))
<
0
)
if
((
fd
=
virNetDevSetupControl
(
ifname
,
&
ifr
))
<
0
)
return
-
1
;
return
-
1
;
...
@@ -776,15 +738,11 @@ virNetDevGetIFFlag(const char *ifname, int flag, bool *val)
...
@@ -776,15 +738,11 @@ virNetDevGetIFFlag(const char *ifname, int flag, bool *val)
virReportSystemError
(
errno
,
virReportSystemError
(
errno
,
_
(
"Cannot get interface flags on '%s'"
),
_
(
"Cannot get interface flags on '%s'"
),
ifname
);
ifname
);
goto
cleanup
;
return
-
1
;
}
}
*
val
=
(
ifr
.
ifr_flags
&
flag
)
?
true
:
false
;
*
val
=
(
ifr
.
ifr_flags
&
flag
)
?
true
:
false
;
ret
=
0
;
return
0
;
cleanup:
VIR_FORCE_CLOSE
(
fd
);
return
ret
;
}
}
#else
#else
static
int
static
int
...
@@ -909,9 +867,8 @@ char *virNetDevGetName(int ifindex)
...
@@ -909,9 +867,8 @@ char *virNetDevGetName(int ifindex)
#if defined(SIOCGIFINDEX) && defined(HAVE_STRUCT_IFREQ)
#if defined(SIOCGIFINDEX) && defined(HAVE_STRUCT_IFREQ)
int
virNetDevGetIndex
(
const
char
*
ifname
,
int
*
ifindex
)
int
virNetDevGetIndex
(
const
char
*
ifname
,
int
*
ifindex
)
{
{
int
ret
=
-
1
;
struct
ifreq
ifreq
;
struct
ifreq
ifreq
;
int
fd
=
socket
(
VIR_NETDEV_FAMILY
,
SOCK_DGRAM
,
0
);
VIR_AUTOCLOSE
fd
=
socket
(
VIR_NETDEV_FAMILY
,
SOCK_DGRAM
,
0
);
if
(
fd
<
0
)
{
if
(
fd
<
0
)
{
virReportSystemError
(
errno
,
"%s"
,
virReportSystemError
(
errno
,
"%s"
,
...
@@ -925,13 +882,13 @@ int virNetDevGetIndex(const char *ifname, int *ifindex)
...
@@ -925,13 +882,13 @@ int virNetDevGetIndex(const char *ifname, int *ifindex)
virReportSystemError
(
ERANGE
,
virReportSystemError
(
ERANGE
,
_
(
"invalid interface name %s"
),
_
(
"invalid interface name %s"
),
ifname
);
ifname
);
goto
cleanup
;
return
-
1
;
}
}
if
(
ioctl
(
fd
,
SIOCGIFINDEX
,
&
ifreq
)
<
0
)
{
if
(
ioctl
(
fd
,
SIOCGIFINDEX
,
&
ifreq
)
<
0
)
{
virReportSystemError
(
errno
,
virReportSystemError
(
errno
,
_
(
"Unable to get index for interface %s"
),
ifname
);
_
(
"Unable to get index for interface %s"
),
ifname
);
goto
cleanup
;
return
-
1
;
}
}
# ifdef HAVE_STRUCT_IFREQ_IFR_INDEX
# ifdef HAVE_STRUCT_IFREQ_IFR_INDEX
...
@@ -939,11 +896,7 @@ int virNetDevGetIndex(const char *ifname, int *ifindex)
...
@@ -939,11 +896,7 @@ int virNetDevGetIndex(const char *ifname, int *ifindex)
# else
# else
*
ifindex
=
ifreq
.
ifr_ifindex
;
*
ifindex
=
ifreq
.
ifr_ifindex
;
# endif
# endif
ret
=
0
;
return
0
;
cleanup:
VIR_FORCE_CLOSE
(
fd
);
return
ret
;
}
}
#else
/* ! SIOCGIFINDEX */
#else
/* ! SIOCGIFINDEX */
int
virNetDevGetIndex
(
const
char
*
ifname
ATTRIBUTE_UNUSED
,
int
virNetDevGetIndex
(
const
char
*
ifname
ATTRIBUTE_UNUSED
,
...
@@ -1013,8 +966,7 @@ int virNetDevGetVLanID(const char *ifname, int *vlanid)
...
@@ -1013,8 +966,7 @@ int virNetDevGetVLanID(const char *ifname, int *vlanid)
struct
vlan_ioctl_args
vlanargs
=
{
struct
vlan_ioctl_args
vlanargs
=
{
.
cmd
=
GET_VLAN_VID_CMD
,
.
cmd
=
GET_VLAN_VID_CMD
,
};
};
int
ret
=
-
1
;
VIR_AUTOCLOSE
fd
=
socket
(
PF_PACKET
,
SOCK_DGRAM
,
0
);
int
fd
=
socket
(
PF_PACKET
,
SOCK_DGRAM
,
0
);
if
(
fd
<
0
)
{
if
(
fd
<
0
)
{
virReportSystemError
(
errno
,
"%s"
,
virReportSystemError
(
errno
,
"%s"
,
...
@@ -1026,22 +978,17 @@ int virNetDevGetVLanID(const char *ifname, int *vlanid)
...
@@ -1026,22 +978,17 @@ int virNetDevGetVLanID(const char *ifname, int *vlanid)
virReportSystemError
(
ERANGE
,
virReportSystemError
(
ERANGE
,
_
(
"invalid interface name %s"
),
_
(
"invalid interface name %s"
),
ifname
);
ifname
);
goto
cleanup
;
return
-
1
;
}
}
if
(
ioctl
(
fd
,
SIOCGIFVLAN
,
&
vlanargs
)
!=
0
)
{
if
(
ioctl
(
fd
,
SIOCGIFVLAN
,
&
vlanargs
)
!=
0
)
{
virReportSystemError
(
errno
,
virReportSystemError
(
errno
,
_
(
"Unable to get VLAN for interface %s"
),
ifname
);
_
(
"Unable to get VLAN for interface %s"
),
ifname
);
goto
cleanup
;
return
-
1
;
}
}
*
vlanid
=
vlanargs
.
u
.
VID
;
*
vlanid
=
vlanargs
.
u
.
VID
;
ret
=
0
;
return
0
;
cleanup:
VIR_FORCE_CLOSE
(
fd
);
return
ret
;
}
}
#else
/* ! SIOCGIFVLAN */
#else
/* ! SIOCGIFVLAN */
int
virNetDevGetVLanID
(
const
char
*
ifname
ATTRIBUTE_UNUSED
,
int
virNetDevGetVLanID
(
const
char
*
ifname
ATTRIBUTE_UNUSED
,
...
@@ -1070,55 +1017,43 @@ int virNetDevGetVLanID(const char *ifname ATTRIBUTE_UNUSED,
...
@@ -1070,55 +1017,43 @@ int virNetDevGetVLanID(const char *ifname ATTRIBUTE_UNUSED,
int
virNetDevValidateConfig
(
const
char
*
ifname
,
int
virNetDevValidateConfig
(
const
char
*
ifname
,
const
virMacAddr
*
macaddr
,
int
ifindex
)
const
virMacAddr
*
macaddr
,
int
ifindex
)
{
{
int
fd
=
-
1
;
int
ret
=
-
1
;
struct
ifreq
ifr
;
struct
ifreq
ifr
;
int
idx
;
int
idx
;
int
rc
;
int
rc
;
VIR_AUTOCLOSE
fd
=
-
1
;
if
((
rc
=
virNetDevExists
(
ifname
))
<
0
)
if
((
rc
=
virNetDevExists
(
ifname
))
<
0
)
return
-
1
;
return
-
1
;
if
(
rc
==
0
)
{
if
(
rc
==
0
)
ret
=
0
;
return
0
;
goto
cleanup
;
}
if
(
macaddr
!=
NULL
)
{
if
(
macaddr
!=
NULL
)
{
if
((
fd
=
virNetDevSetupControl
(
ifname
,
&
ifr
))
<
0
)
if
((
fd
=
virNetDevSetupControl
(
ifname
,
&
ifr
))
<
0
)
return
-
1
;
return
-
1
;
if
(
ioctl
(
fd
,
SIOCGIFHWADDR
,
&
ifr
)
<
0
)
{
if
(
ioctl
(
fd
,
SIOCGIFHWADDR
,
&
ifr
)
<
0
)
{
if
(
errno
==
ENODEV
)
{
if
(
errno
==
ENODEV
)
ret
=
0
;
return
0
;
goto
cleanup
;
}
virReportSystemError
(
errno
,
virReportSystemError
(
errno
,
_
(
"could not get MAC address of interface %s"
),
_
(
"could not get MAC address of interface %s"
),
ifname
);
ifname
);
goto
cleanup
;
return
-
1
;
}
}
if
(
virMacAddrCmpRaw
(
macaddr
,
if
(
virMacAddrCmpRaw
(
macaddr
,
(
unsigned
char
*
)
ifr
.
ifr_hwaddr
.
sa_data
)
!=
0
)
{
(
unsigned
char
*
)
ifr
.
ifr_hwaddr
.
sa_data
)
!=
0
)
ret
=
0
;
return
0
;
goto
cleanup
;
}
}
}
if
(
ifindex
!=
-
1
)
{
if
(
ifindex
!=
-
1
)
{
if
(
virNetDevGetIndex
(
ifname
,
&
idx
)
<
0
)
if
(
virNetDevGetIndex
(
ifname
,
&
idx
)
<
0
)
goto
cleanup
;
return
-
1
;
if
(
idx
!=
ifindex
)
{
if
(
idx
!=
ifindex
)
ret
=
0
;
return
0
;
goto
cleanup
;
}
}
}
ret
=
1
;
return
1
;
cleanup:
VIR_FORCE_CLOSE
(
fd
);
return
ret
;
}
}
#else
#else
int
virNetDevValidateConfig
(
const
char
*
ifname
ATTRIBUTE_UNUSED
,
int
virNetDevValidateConfig
(
const
char
*
ifname
ATTRIBUTE_UNUSED
,
...
@@ -2649,9 +2584,8 @@ virNetDevGetLinkInfo(const char *ifname,
...
@@ -2649,9 +2584,8 @@ virNetDevGetLinkInfo(const char *ifname,
int
virNetDevAddMulti
(
const
char
*
ifname
,
int
virNetDevAddMulti
(
const
char
*
ifname
,
virMacAddrPtr
macaddr
)
virMacAddrPtr
macaddr
)
{
{
int
fd
=
-
1
;
int
ret
=
-
1
;
struct
ifreq
ifr
;
struct
ifreq
ifr
;
VIR_AUTOCLOSE
fd
=
-
1
;
if
((
fd
=
virNetDevSetupControl
(
ifname
,
&
ifr
))
<
0
)
if
((
fd
=
virNetDevSetupControl
(
ifname
,
&
ifr
))
<
0
)
return
-
1
;
return
-
1
;
...
@@ -2664,13 +2598,10 @@ int virNetDevAddMulti(const char *ifname,
...
@@ -2664,13 +2598,10 @@ int virNetDevAddMulti(const char *ifname,
virReportSystemError
(
errno
,
virReportSystemError
(
errno
,
_
(
"Cannot add multicast MAC %s on '%s' interface"
),
_
(
"Cannot add multicast MAC %s on '%s' interface"
),
virMacAddrFormat
(
macaddr
,
macstr
),
ifname
);
virMacAddrFormat
(
macaddr
,
macstr
),
ifname
);
goto
cleanup
;
return
-
1
;
}
}
ret
=
0
;
return
0
;
cleanup:
VIR_FORCE_CLOSE
(
fd
);
return
ret
;
}
}
#else
#else
int
virNetDevAddMulti
(
const
char
*
ifname
ATTRIBUTE_UNUSED
,
int
virNetDevAddMulti
(
const
char
*
ifname
ATTRIBUTE_UNUSED
,
...
@@ -2698,9 +2629,8 @@ int virNetDevAddMulti(const char *ifname ATTRIBUTE_UNUSED,
...
@@ -2698,9 +2629,8 @@ int virNetDevAddMulti(const char *ifname ATTRIBUTE_UNUSED,
int
virNetDevDelMulti
(
const
char
*
ifname
,
int
virNetDevDelMulti
(
const
char
*
ifname
,
virMacAddrPtr
macaddr
)
virMacAddrPtr
macaddr
)
{
{
int
fd
=
-
1
;
int
ret
=
-
1
;
struct
ifreq
ifr
;
struct
ifreq
ifr
;
VIR_AUTOCLOSE
fd
=
-
1
;
if
((
fd
=
virNetDevSetupControl
(
ifname
,
&
ifr
))
<
0
)
if
((
fd
=
virNetDevSetupControl
(
ifname
,
&
ifr
))
<
0
)
return
-
1
;
return
-
1
;
...
@@ -2713,13 +2643,10 @@ int virNetDevDelMulti(const char *ifname,
...
@@ -2713,13 +2643,10 @@ int virNetDevDelMulti(const char *ifname,
virReportSystemError
(
errno
,
virReportSystemError
(
errno
,
_
(
"Cannot add multicast MAC %s on '%s' interface"
),
_
(
"Cannot add multicast MAC %s on '%s' interface"
),
virMacAddrFormat
(
macaddr
,
macstr
),
ifname
);
virMacAddrFormat
(
macaddr
,
macstr
),
ifname
);
goto
cleanup
;
return
-
1
;
}
}
ret
=
0
;
return
0
;
cleanup:
VIR_FORCE_CLOSE
(
fd
);
return
ret
;
}
}
#else
#else
int
virNetDevDelMulti
(
const
char
*
ifname
ATTRIBUTE_UNUSED
,
int
virNetDevDelMulti
(
const
char
*
ifname
ATTRIBUTE_UNUSED
,
...
@@ -3388,10 +3315,9 @@ int virNetDevSetCoalesce(const char *ifname,
...
@@ -3388,10 +3315,9 @@ int virNetDevSetCoalesce(const char *ifname,
virNetDevCoalescePtr
coalesce
,
virNetDevCoalescePtr
coalesce
,
bool
update
)
bool
update
)
{
{
int
fd
=
-
1
;
int
ret
=
-
1
;
struct
ifreq
ifr
;
struct
ifreq
ifr
;
struct
ethtool_coalesce
coal
=
{
0
};
struct
ethtool_coalesce
coal
=
{
0
};
VIR_AUTOCLOSE
fd
=
-
1
;
if
(
!
coalesce
&&
!
update
)
if
(
!
coalesce
&&
!
update
)
return
0
;
return
0
;
...
@@ -3433,7 +3359,7 @@ int virNetDevSetCoalesce(const char *ifname,
...
@@ -3433,7 +3359,7 @@ int virNetDevSetCoalesce(const char *ifname,
virReportSystemError
(
errno
,
virReportSystemError
(
errno
,
_
(
"Cannot set coalesce info on '%s'"
),
_
(
"Cannot set coalesce info on '%s'"
),
ifname
);
ifname
);
goto
cleanup
;
return
-
1
;
}
}
if
(
coalesce
)
{
if
(
coalesce
)
{
...
@@ -3467,10 +3393,7 @@ int virNetDevSetCoalesce(const char *ifname,
...
@@ -3467,10 +3393,7 @@ int virNetDevSetCoalesce(const char *ifname,
}
}
}
}
ret
=
0
;
return
0
;
cleanup:
VIR_FORCE_CLOSE
(
fd
);
return
ret
;
}
}
# else
# else
int
virNetDevSetCoalesce
(
const
char
*
ifname
,
int
virNetDevSetCoalesce
(
const
char
*
ifname
,
...
@@ -3503,30 +3426,26 @@ virNetDevGetFeatures(const char *ifname,
...
@@ -3503,30 +3426,26 @@ virNetDevGetFeatures(const char *ifname,
virBitmapPtr
*
out
)
virBitmapPtr
*
out
)
{
{
struct
ifreq
ifr
;
struct
ifreq
ifr
;
int
ret
=
-
1
;
VIR_AUTOCLOSE
fd
=
-
1
;
int
fd
=
-
1
;
if
(
!
(
*
out
=
virBitmapNew
(
VIR_NET_DEV_FEAT_LAST
)))
if
(
!
(
*
out
=
virBitmapNew
(
VIR_NET_DEV_FEAT_LAST
)))
return
-
1
;
return
-
1
;
if
((
fd
=
virNetDevSetupControl
(
ifname
,
&
ifr
))
<
0
)
if
((
fd
=
virNetDevSetupControl
(
ifname
,
&
ifr
))
<
0
)
goto
cleanup
;
return
-
1
;
virNetDevGetEthtoolFeatures
(
*
out
,
fd
,
&
ifr
);
virNetDevGetEthtoolFeatures
(
*
out
,
fd
,
&
ifr
);
if
(
virNetDevGetEthtoolGFeatures
(
*
out
,
fd
,
&
ifr
)
<
0
)
if
(
virNetDevGetEthtoolGFeatures
(
*
out
,
fd
,
&
ifr
)
<
0
)
goto
cleanup
;
return
-
1
;
if
(
virNetDevRDMAFeature
(
ifname
,
out
)
<
0
)
if
(
virNetDevRDMAFeature
(
ifname
,
out
)
<
0
)
goto
cleanup
;
return
-
1
;
if
(
virNetDevSwitchdevFeature
(
ifname
,
out
)
<
0
)
if
(
virNetDevSwitchdevFeature
(
ifname
,
out
)
<
0
)
goto
cleanup
;
return
-
1
;
ret
=
0
;
return
0
;
cleanup:
VIR_FORCE_CLOSE
(
fd
);
return
ret
;
}
}
#else
#else
int
int
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录