Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
100b7a72
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,体验更适合开发者的 AI 搜索 >>
提交
100b7a72
编写于
11月 19, 2014
作者:
L
Laine Stump
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
util: new functions for setting bridge and bridge port attributes
These functions all set/get items in the sysfs for a bridge device.
上级
7b499262
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
266 addition
and
3 deletion
+266
-3
src/libvirt_private.syms
src/libvirt_private.syms
+6
-0
src/util/virnetdevbridge.c
src/util/virnetdevbridge.c
+233
-2
src/util/virnetdevbridge.h
src/util/virnetdevbridge.h
+27
-1
未找到文件。
src/libvirt_private.syms
浏览文件 @
100b7a72
...
...
@@ -1663,9 +1663,15 @@ virNetDevBridgeCreate;
virNetDevBridgeDelete;
virNetDevBridgeGetSTP;
virNetDevBridgeGetSTPDelay;
virNetDevBridgeGetVlanFiltering;
virNetDevBridgePortGetLearning;
virNetDevBridgePortGetUnicastFlood;
virNetDevBridgePortSetLearning;
virNetDevBridgePortSetUnicastFlood;
virNetDevBridgeRemovePort;
virNetDevBridgeSetSTP;
virNetDevBridgeSetSTPDelay;
virNetDevBridgeSetVlanFiltering;
# util/virnetdevmacvlan.h
...
...
src/util/virnetdevbridge.c
浏览文件 @
100b7a72
/*
* Copyright (C) 2007-201
3
Red Hat, Inc.
* Copyright (C) 2007-201
4
Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
...
...
@@ -219,6 +219,170 @@ static int virNetDevBridgeGet(const char *brname,
}
#endif
/* __linux__ */
#if defined(__linux__)
static
int
virNetDevBridgePortSet
(
const
char
*
brname
,
const
char
*
ifname
,
const
char
*
paramname
,
unsigned
long
value
)
{
char
*
path
=
NULL
;
char
valuestr
[
INT_BUFSIZE_BOUND
(
value
)];
int
ret
=
-
1
;
snprintf
(
valuestr
,
sizeof
(
valuestr
),
"%lu"
,
value
);
if
(
virAsprintf
(
&
path
,
"%s/%s/brif/%s/%s"
,
SYSFS_NET_DIR
,
brname
,
ifname
,
paramname
)
<
0
)
return
-
1
;
if
(
!
virFileExists
(
path
))
errno
=
EINVAL
;
else
ret
=
virFileWriteStr
(
path
,
valuestr
,
0
);
if
(
ret
<
0
)
{
virReportSystemError
(
errno
,
_
(
"Unable to set bridge %s port %s %s to %s"
),
brname
,
ifname
,
paramname
,
valuestr
);
}
VIR_FREE
(
path
);
return
ret
;
}
static
int
virNetDevBridgePortGet
(
const
char
*
brname
,
const
char
*
ifname
,
const
char
*
paramname
,
unsigned
long
*
value
)
{
char
*
path
=
NULL
;
char
*
valuestr
=
NULL
;
int
ret
=
-
1
;
if
(
virAsprintf
(
&
path
,
"%s/%s/brif/%s/%s"
,
SYSFS_NET_DIR
,
brname
,
ifname
,
paramname
)
<
0
)
return
-
1
;
if
(
virFileReadAll
(
path
,
INT_BUFSIZE_BOUND
(
unsigned
long
),
&
valuestr
)
<
0
)
goto
cleanup
;
if
(
virStrToLong_ul
(
valuestr
,
NULL
,
10
,
value
)
<
0
)
{
virReportSystemError
(
EINVAL
,
_
(
"Unable to get bridge %s port %s %s"
),
brname
,
ifname
,
paramname
);
goto
cleanup
;
}
ret
=
0
;
cleanup:
VIR_FREE
(
path
);
VIR_FREE
(
valuestr
);
return
ret
;
}
int
virNetDevBridgePortGetLearning
(
const
char
*
brname
,
const
char
*
ifname
,
bool
*
enable
)
{
int
ret
=
-
1
;
unsigned
long
value
;
if
(
virNetDevBridgePortGet
(
brname
,
ifname
,
"learning"
,
&
value
)
<
0
)
goto
cleanup
;
*
enable
=
!!
value
;
ret
=
0
;
cleanup:
return
ret
;
}
int
virNetDevBridgePortSetLearning
(
const
char
*
brname
,
const
char
*
ifname
,
bool
enable
)
{
return
virNetDevBridgePortSet
(
brname
,
ifname
,
"learning"
,
enable
?
1
:
0
);
}
int
virNetDevBridgePortGetUnicastFlood
(
const
char
*
brname
,
const
char
*
ifname
,
bool
*
enable
)
{
int
ret
=
-
1
;
unsigned
long
value
;
if
(
virNetDevBridgePortGet
(
brname
,
ifname
,
"unicast_flood"
,
&
value
)
<
0
)
goto
cleanup
;
*
enable
=
!!
value
;
ret
=
0
;
cleanup:
return
ret
;
}
int
virNetDevBridgePortSetUnicastFlood
(
const
char
*
brname
,
const
char
*
ifname
,
bool
enable
)
{
return
virNetDevBridgePortSet
(
brname
,
ifname
,
"unicast_flood"
,
enable
?
1
:
0
);
}
#else
int
virNetDevBridgePortGetLearning
(
const
char
*
brname
ATTRIBUTE_UNUSED
,
const
char
*
ifname
ATTRIBUTE_UNUSED
,
bool
*
enable
ATTRIBUTE_UNUSED
)
{
virReportSystemError
(
ENOSYS
,
"%s"
,
_
(
"Unable to get bridge port learning on this platform"
));
return
-
1
;
}
int
virNetDevBridgePortSetLearning
(
const
char
*
brname
ATTRIBUTE_UNUSED
,
const
char
*
ifname
ATTRIBUTE_UNUSED
,
bool
enable
)
{
virReportSystemError
(
ENOSYS
,
"%s"
,
_
(
"Unable to set bridge port learning on this platform"
));
return
-
1
;
}
int
virNetDevBridgePortGetUnicastFlood
(
const
char
*
brname
ATTRIBUTE_UNUSED
,
const
char
*
ifname
ATTRIBUTE_UNUSED
,
bool
*
enable
ATTRIBUTE_UNUSED
)
{
virReportSystemError
(
ENOSYS
,
"%s"
,
_
(
"Unable to get bridge port unicast_flood on this platform"
));
return
-
1
;
}
int
virNetDevBridgePortSetUnicastFlood
(
const
char
*
brname
ATTRIBUTE_UNUSED
,
const
char
*
ifname
ATTRIBUTE_UNUSED
,
bool
enable
ATTRIBUTE_UNUSED
)
{
virReportSystemError
(
ENOSYS
,
"%s"
,
_
(
"Unable to set bridge port unicast_flood on this platform"
));
return
-
1
;
}
#endif
/**
* virNetDevBridgeCreate:
...
...
@@ -517,7 +681,7 @@ int virNetDevBridgeSetSTPDelay(const char *brname,
* @brname: the bridge device name
* @delayms: the forward delay in milliseconds
*
* Retrives the forward delay for the bridge device @brname
* Retri
e
ves the forward delay for the bridge device @brname
* storing it in @delayms. The forward delay is only meaningful
* if STP is enabled
*
...
...
@@ -682,3 +846,70 @@ int virNetDevBridgeGetSTP(const char *brname,
return
-
1
;
}
#endif
#if defined(HAVE_STRUCT_IFREQ) && defined(__linux__)
/**
* virNetDevBridgeGetVlanFiltering:
* @brname: the bridge device name
* @enable: true or false
*
* Retrieves the vlan_filtering setting for the bridge device @brname
* storing it in @enable.
*
* Returns 0 on success, -1 on error
*/
int
virNetDevBridgeGetVlanFiltering
(
const
char
*
brname
,
bool
*
enable
)
{
int
ret
=
-
1
;
unsigned
long
value
;
if
(
virNetDevBridgeGet
(
brname
,
"vlan_filtering"
,
&
value
,
-
1
,
NULL
)
<
0
)
goto
cleanup
;
*
enable
=
!!
value
;
ret
=
0
;
cleanup:
return
ret
;
}
/**
* virNetDevBridgeSetVlanFiltering:
* @brname: the bridge name
* @enable: true or false
*
* Set the bridge vlan_filtering mode
*
* Returns 0 in case of success or -1 on failure
*/
int
virNetDevBridgeSetVlanFiltering
(
const
char
*
brname
,
bool
enable
)
{
return
virNetDevBridgeSet
(
brname
,
"vlan_filtering"
,
enable
?
1
:
0
,
-
1
,
NULL
);
}
#else
int
virNetDevBridgeGetVlanFiltering
(
const
char
*
brname
ATTRIBUTE_UNUSED
,
bool
*
enable
ATTRIBUTE_UNUSED
)
{
virReportSystemError
(
ENOSYS
,
"%s"
,
_
(
"Unable to get bridge vlan_filtering on this platform"
));
return
-
1
;
}
int
virNetDevBridgeSetVlanFiltering
(
const
char
*
brname
ATTRIBUTE_UNUSED
,
bool
enable
ATTRIBUTE_UNUSED
)
{
virReportSystemError
(
ENOSYS
,
"%s"
,
_
(
"Unable to set bridge vlan_filtering on this platform"
));
return
-
1
;
}
#endif
src/util/virnetdevbridge.h
浏览文件 @
100b7a72
/*
* Copyright (C) 2007-201
1
Red Hat, Inc.
* Copyright (C) 2007-201
2, 2014
Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
...
...
@@ -51,4 +51,30 @@ int virNetDevBridgeGetSTP(const char *brname,
bool
*
enable
)
ATTRIBUTE_NONNULL
(
1
)
ATTRIBUTE_NONNULL
(
2
)
ATTRIBUTE_RETURN_CHECK
;
int
virNetDevBridgeSetVlanFiltering
(
const
char
*
brname
,
bool
enable
)
ATTRIBUTE_NONNULL
(
1
)
ATTRIBUTE_RETURN_CHECK
;
int
virNetDevBridgeGetVlanFiltering
(
const
char
*
brname
,
bool
*
enable
)
ATTRIBUTE_NONNULL
(
1
)
ATTRIBUTE_NONNULL
(
2
)
ATTRIBUTE_RETURN_CHECK
;
int
virNetDevBridgePortGetLearning
(
const
char
*
brname
,
const
char
*
ifname
,
bool
*
enable
)
ATTRIBUTE_NONNULL
(
1
)
ATTRIBUTE_NONNULL
(
2
)
ATTRIBUTE_NONNULL
(
3
)
ATTRIBUTE_RETURN_CHECK
;
int
virNetDevBridgePortSetLearning
(
const
char
*
brname
,
const
char
*
ifname
,
bool
enable
)
ATTRIBUTE_NONNULL
(
1
)
ATTRIBUTE_NONNULL
(
2
)
ATTRIBUTE_RETURN_CHECK
;
int
virNetDevBridgePortGetUnicastFlood
(
const
char
*
brname
,
const
char
*
ifname
,
bool
*
enable
)
ATTRIBUTE_NONNULL
(
1
)
ATTRIBUTE_NONNULL
(
2
)
ATTRIBUTE_NONNULL
(
3
)
ATTRIBUTE_RETURN_CHECK
;
int
virNetDevBridgePortSetUnicastFlood
(
const
char
*
brname
,
const
char
*
ifname
,
bool
enable
)
ATTRIBUTE_NONNULL
(
1
)
ATTRIBUTE_NONNULL
(
2
)
ATTRIBUTE_RETURN_CHECK
;
#endif
/* __VIR_NETDEV_BRIDGE_H__ */
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录