Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
jobily
Runtime
提交
a4129114
R
Runtime
项目概览
jobily
/
Runtime
12 个月 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Runtime
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a4129114
编写于
1月 22, 2020
作者:
A
Adeel Mujahid
提交者:
Stephen Toub
1月 22, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Enable NetworkAddressChange on FreeBSD (#1602)
上级
7a02a535
变更
8
显示空白变更内容
内联
并排
Showing
8 changed file
with
69 addition
and
15 deletion
+69
-15
src/libraries/Common/src/Interop/Unix/System.Native/Interop.NetworkChange.cs
...n/src/Interop/Unix/System.Native/Interop.NetworkChange.cs
+0
-0
src/libraries/Native/Unix/System.Native/CMakeLists.txt
src/libraries/Native/Unix/System.Native/CMakeLists.txt
+6
-0
src/libraries/Native/Unix/System.Native/pal_networkchange.c
src/libraries/Native/Unix/System.Native/pal_networkchange.c
+56
-1
src/libraries/Native/Unix/System.Native/pal_networkchange.h
src/libraries/Native/Unix/System.Native/pal_networkchange.h
+0
-1
src/libraries/System.Net.NetworkInformation/src/System.Net.NetworkInformation.csproj
...tworkInformation/src/System.Net.NetworkInformation.csproj
+7
-6
src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.Unix.cs
...ystem/Net/NetworkInformation/NetworkAddressChange.Unix.cs
+0
-0
src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkAddressChangedTests.cs
...ation/tests/FunctionalTests/NetworkAddressChangedTests.cs
+0
-2
src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkAvailabilityChangedTests.cs
.../tests/FunctionalTests/NetworkAvailabilityChangedTests.cs
+0
-5
未找到文件。
src/libraries/Common/src/Interop/
Linu
x/System.Native/Interop.NetworkChange.cs
→
src/libraries/Common/src/Interop/
Uni
x/System.Native/Interop.NetworkChange.cs
浏览文件 @
a4129114
文件已移动
src/libraries/Native/Unix/System.Native/CMakeLists.txt
浏览文件 @
a4129114
...
...
@@ -29,6 +29,12 @@ if (CMAKE_SYSTEM_NAME STREQUAL Linux)
if
(
!HAVE_LINUX_RTNETLINK_H
)
message
(
FATAL_ERROR
"Could not find linux/rtnetlink.h"
)
endif
()
elseif
(
CMAKE_SYSTEM_NAME STREQUAL FreeBSD
)
set
(
NATIVE_SOURCES
${
NATIVE_SOURCES
}
pal_networkchange.c
)
if
(
!HAVE_RT_MSGHDR
)
message
(
FATAL_ERROR
"Could not find net/route.h"
)
endif
()
endif
()
if
(
GEN_SHARED_LIB
)
...
...
src/libraries/Native/Unix/System.Native/pal_networkchange.c
浏览文件 @
a4129114
...
...
@@ -10,28 +10,40 @@
#include "pal_utilities.h"
#include <errno.h>
#include <linux/rtnetlink.h>
#include <net/if.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <unistd.h>
#if HAVE_LINUX_RTNETLINK_H
#include <linux/rtnetlink.h>
#elif HAVE_RT_MSGHDR
#include <net/route.h>
#else
#error System must have linux/rtnetlink.h or net/route.h.
#endif
#pragma clang diagnostic ignored "-Wcast-align" // NLMSG_* macros trigger this
Error
SystemNative_CreateNetworkChangeListenerSocket
(
int32_t
*
retSocket
)
{
#if HAVE_LINUX_RTNETLINK_H
struct
sockaddr_nl
sa
;
memset
(
&
sa
,
0
,
sizeof
(
struct
sockaddr_nl
));
sa
.
nl_family
=
AF_NETLINK
;
sa
.
nl_groups
=
RTMGRP_LINK
|
RTMGRP_IPV4_IFADDR
|
RTMGRP_IPV4_ROUTE
|
RTMGRP_IPV6_ROUTE
;
int32_t
sock
=
socket
(
AF_NETLINK
,
SOCK_RAW
,
NETLINK_ROUTE
);
#elif HAVE_RT_MSGHDR
int32_t
sock
=
socket
(
PF_ROUTE
,
SOCK_RAW
,
0
);
#endif
if
(
sock
==
-
1
)
{
*
retSocket
=
-
1
;
return
(
Error
)(
SystemNative_ConvertErrorPlatformToPal
(
errno
));
}
#if HAVE_LINUX_RTNETLINK_H
if
(
bind
(
sock
,
(
struct
sockaddr
*
)(
&
sa
),
sizeof
(
sa
))
!=
0
)
{
*
retSocket
=
-
1
;
...
...
@@ -39,6 +51,7 @@ Error SystemNative_CreateNetworkChangeListenerSocket(int32_t* retSocket)
close
(
sock
);
return
palError
;
}
#endif
*
retSocket
=
sock
;
return
Error_SUCCESS
;
...
...
@@ -50,6 +63,7 @@ Error SystemNative_CloseNetworkChangeListenerSocket(int32_t socket)
return
err
==
0
||
CheckInterrupted
(
err
)
?
Error_SUCCESS
:
(
Error
)(
SystemNative_ConvertErrorPlatformToPal
(
errno
));
}
#if HAVE_LINUX_RTNETLINK_H
static
NetworkChangeKind
ReadNewLinkMessage
(
struct
nlmsghdr
*
hdr
)
{
assert
(
hdr
!=
NULL
);
...
...
@@ -117,3 +131,44 @@ void SystemNative_ReadEvents(int32_t sock, NetworkChangeEvent onNetworkChange)
}
}
}
#elif HAVE_RT_MSGHDR
void
SystemNative_ReadEvents
(
int32_t
sock
,
NetworkChangeEvent
onNetworkChange
)
{
char
buffer
[
4096
];
ssize_t
count
=
read
(
sock
,
buffer
,
sizeof
(
buffer
));
if
(
count
<
0
)
{
return
;
}
struct
rt_msghdr
msghdr
;
for
(
char
*
ptr
=
buffer
;
(
ptr
+
sizeof
(
struct
rt_msghdr
))
<=
(
buffer
+
count
);
ptr
+=
msghdr
.
rtm_msglen
)
{
memcpy
(
&
msghdr
,
ptr
,
sizeof
(
msghdr
));
if
(
msghdr
.
rtm_version
!=
RTM_VERSION
)
{
// version mismatch
return
;
}
switch
(
msghdr
.
rtm_type
)
{
case
RTM_NEWADDR
:
onNetworkChange
(
sock
,
AddressAdded
);
break
;
case
RTM_DELADDR
:
onNetworkChange
(
sock
,
AddressRemoved
);
break
;
case
RTM_ADD
:
case
RTM_DELETE
:
case
RTM_REDIRECT
:
{
onNetworkChange
(
sock
,
AvailabilityChanged
);
return
;
}
default:
break
;
}
}
}
#endif
src/libraries/Native/Unix/System.Native/pal_networkchange.h
浏览文件 @
a4129114
...
...
@@ -6,7 +6,6 @@
#include "pal_compiler.h"
#include "pal_types.h"
#include <linux/netlink.h>
typedef
enum
{
...
...
src/libraries/System.Net.NetworkInformation/src/System.Net.NetworkInformation.csproj
浏览文件 @
a4129114
...
...
@@ -189,7 +189,6 @@
<Compile Include="System\Net\NetworkInformation\LinuxIcmpV6Statistics.cs" />
<Compile Include="System\Net\NetworkInformation\LinuxTcpStatistics.cs" />
<Compile Include="System\Net\NetworkInformation\LinuxUdpStatistics.cs" />
<Compile Include="System\Net\NetworkInformation\NetworkAddressChange.Linux.cs" />
<Compile Include="System\Net\NetworkInformation\IPGlobalPropertiesPal.Linux.cs" />
<Compile Include="System\Net\NetworkInformation\LinuxIPAddressInformation.cs" />
<Compile Include="System\Net\NetworkInformation\LinuxIPGlobalProperties.cs" />
...
...
@@ -212,9 +211,6 @@
<Compile Include="$(CommonPath)Interop\Linux\Interop.LinuxNetDeviceFlags.cs">
<Link>Common\Interop\Linux\Interop.LinuxNetDeviceFlags.cs</Link>
</Compile>
<Compile Include="$(CommonPath)Interop\Linux\System.Native\Interop.NetworkChange.cs">
<Link>Common\Interop\Linux\System.Native\Interop.NetworkChange.cs</Link>
</Compile>
</ItemGroup>
<!-- OSX -->
<ItemGroup Condition=" '$(TargetsOsx)' == 'true' or '$(TargetsFreeBSD)' == 'true'">
...
...
@@ -260,11 +256,16 @@
</Compile>
</ItemGroup>
<ItemGroup Condition=" '$(TargetsFreeBSD)' == 'true'">
<Compile Include="System\Net\NetworkInformation\NetworkAddressChange.UnknownUnix.cs" />
<Compile Include="$(CommonPath)Interop\FreeBSD\Interop.Libraries.cs">
<Link>Common\Interop\FreeBSD\Interop.Libraries.cs</Link>
</Compile>
</ItemGroup>
<ItemGroup Condition=" '$(TargetsLinux)' == 'true' OR '$(TargetsFreeBSD)' == 'true'">
<Compile Include="System\Net\NetworkInformation\NetworkAddressChange.Unix.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.NetworkChange.cs">
<Link>Common\Interop\Unix\System.Native\Interop.NetworkChange.cs</Link>
</Compile>
</ItemGroup>
<!-- Unknown Unix -->
<ItemGroup Condition=" '$(TargetsUnknownUnix)' == 'true' ">
<Compile Include="System\Net\NetworkInformation\IPGlobalPropertiesPal.UnknownUnix.cs" />
...
...
@@ -293,7 +294,7 @@
<Reference Include="System.IO.FileSystem" />
<Reference Include="System.Threading.Thread" />
</ItemGroup>
<ItemGroup Condition="'$(TargetsLinux)' == 'true'">
<ItemGroup Condition="'$(TargetsLinux)' == 'true'
OR '$(TargetsFreeBSD)' == 'true'
">
<Reference Include="System.Threading.Timer" />
</ItemGroup>
</Project>
src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.
Linu
x.cs
→
src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.
Uni
x.cs
浏览文件 @
a4129114
文件已移动
src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkAddressChangedTests.cs
浏览文件 @
a4129114
...
...
@@ -13,7 +13,6 @@ public partial class NetworkChangedTests
private
readonly
NetworkAddressChangedEventHandler
_addressHandler
=
delegate
{
};
[
Fact
]
[
ActiveIssue
(
"https://github.com/dotnet/corefx/issues/33530"
,
TestPlatforms
.
FreeBSD
)]
public
void
NetworkAddressChanged_AddRemove_Success
()
{
NetworkChange
.
NetworkAddressChanged
+=
_addressHandler
;
...
...
@@ -21,7 +20,6 @@ public void NetworkAddressChanged_AddRemove_Success()
}
[
Fact
]
[
ActiveIssue
(
"https://github.com/dotnet/corefx/issues/33530"
,
TestPlatforms
.
FreeBSD
)]
public
void
NetworkAddressChanged_JustRemove_Success
()
{
NetworkChange
.
NetworkAddressChanged
-=
_addressHandler
;
...
...
src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkAvailabilityChangedTests.cs
浏览文件 @
a4129114
...
...
@@ -13,7 +13,6 @@ public partial class NetworkChangedTests
private
readonly
NetworkAvailabilityChangedEventHandler
_availabilityHandler
=
delegate
{
};
[
Fact
]
[
ActiveIssue
(
"https://github.com/dotnet/corefx/issues/33530"
,
TestPlatforms
.
FreeBSD
)]
public
void
NetworkAvailabilityChanged_AddRemove_Success
()
{
NetworkChange
.
NetworkAvailabilityChanged
+=
_availabilityHandler
;
...
...
@@ -21,14 +20,12 @@ public void NetworkAvailabilityChanged_AddRemove_Success()
}
[
Fact
]
[
ActiveIssue
(
"https://github.com/dotnet/corefx/issues/33530"
,
TestPlatforms
.
FreeBSD
)]
public
void
NetworkAvailabilityChanged_JustRemove_Success
()
{
NetworkChange
.
NetworkAvailabilityChanged
-=
_availabilityHandler
;
}
[
Fact
]
[
ActiveIssue
(
"https://github.com/dotnet/corefx/issues/33530"
,
TestPlatforms
.
FreeBSD
)]
public
void
NetworkAddressChanged_Add_DoesNotBlock
()
{
// Register without unregistering.
...
...
@@ -42,7 +39,6 @@ public void NetworkAddressChanged_Add_DoesNotBlock()
}
[
Fact
]
[
ActiveIssue
(
"https://github.com/dotnet/corefx/issues/33530"
,
TestPlatforms
.
FreeBSD
)]
public
void
NetworkAddressChanged_AddAndRemove_NetworkAvailabilityChanged_JustRemove_Success
()
{
NetworkChange
.
NetworkAddressChanged
+=
_addressHandler
;
...
...
@@ -55,7 +51,6 @@ public void NetworkAddressChanged_AddAndRemove_NetworkAvailabilityChanged_JustRe
[
InlineData
(
false
,
true
)]
[
InlineData
(
true
,
false
)]
[
InlineData
(
true
,
true
)]
[
ActiveIssue
(
"https://github.com/dotnet/corefx/issues/33530"
,
TestPlatforms
.
FreeBSD
)]
public
void
NetworkAvailabilityChanged_NetworkAddressChanged_AddAndRemove_Success
(
bool
addAddressFirst
,
bool
removeAddressFirst
)
{
if
(
addAddressFirst
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录