Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Lwip
提交
4ee67658
T
Third Party Lwip
项目概览
OpenHarmony
/
Third Party Lwip
8 个月 前同步成功
通知
5
Star
23
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
Third Party Lwip
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
4ee67658
编写于
12月 02, 2021
作者:
M
maosiping
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
蓝牙网络代理
Signed-off-by:
N
maosiping
<
maosiping@huawei.com
>
上级
c6a30e4f
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
1039 addition
and
0 deletion
+1039
-0
src/api/sockets.c
src/api/sockets.c
+64
-0
src/core/distributed_net/distributed_net.c
src/core/distributed_net/distributed_net.c
+152
-0
src/core/distributed_net/distributed_net_core.c
src/core/distributed_net/distributed_net_core.c
+237
-0
src/core/distributed_net/distributed_net_utils.c
src/core/distributed_net/distributed_net_utils.c
+100
-0
src/core/distributed_net/udp_transmit.c
src/core/distributed_net/udp_transmit.c
+134
-0
src/core/dns.c
src/core/dns.c
+81
-0
src/include/lwip/distributed_net/distributed_net.h
src/include/lwip/distributed_net/distributed_net.h
+78
-0
src/include/lwip/distributed_net/distributed_net_core.h
src/include/lwip/distributed_net/distributed_net_core.h
+76
-0
src/include/lwip/distributed_net/distributed_net_utils.h
src/include/lwip/distributed_net/distributed_net_utils.h
+43
-0
src/include/lwip/distributed_net/udp_transmit.h
src/include/lwip/distributed_net/udp_transmit.h
+58
-0
src/include/lwip/sockets.h
src/include/lwip/sockets.h
+16
-0
未找到文件。
src/api/sockets.c
浏览文件 @
4ee67658
...
...
@@ -54,6 +54,10 @@
#include "lwip/netif.h"
#include "lwip/priv/tcpip_priv.h"
#include "lwip/mld6.h"
#if LWIP_ENABLE_DISTRIBUTED_NET
#include "lwip/distributed_net/distributed_net.h"
#include "lwip/distributed_net/distributed_net_core.h"
#endif
/* LWIP_ENABLE_DISTRIBUTED_NET */
#if LWIP_CHECKSUM_ON_COPY
#include "lwip/inet_chksum.h"
#endif
...
...
@@ -772,6 +776,17 @@ lwip_bind(int s, const struct sockaddr *name, socklen_t namelen)
int
lwip_close
(
int
s
)
{
#if LWIP_ENABLE_DISTRIBUTED_NET
if
(
!
is_distributed_net_enabled
())
{
return
lwip_close_internal
(
s
);
}
return
distributed_net_close
(
s
);
}
int
lwip_close_internal
(
int
s
)
{
#endif
struct
lwip_sock
*
sock
;
int
is_tcp
=
0
;
err_t
err
;
...
...
@@ -813,6 +828,17 @@ lwip_close(int s)
int
lwip_connect
(
int
s
,
const
struct
sockaddr
*
name
,
socklen_t
namelen
)
{
#if LWIP_ENABLE_DISTRIBUTED_NET
if
(
!
is_distributed_net_enabled
())
{
return
lwip_connect_internal
(
s
,
name
,
namelen
);
}
return
distributed_net_connect
(
s
,
name
,
namelen
);
}
int
lwip_connect_internal
(
int
s
,
const
struct
sockaddr
*
name
,
socklen_t
namelen
)
{
#endif
struct
lwip_sock
*
sock
;
err_t
err
;
...
...
@@ -1201,6 +1227,17 @@ ssize_t
lwip_recvfrom
(
int
s
,
void
*
mem
,
size_t
len
,
int
flags
,
struct
sockaddr
*
from
,
socklen_t
*
fromlen
)
{
#if LWIP_ENABLE_DISTRIBUTED_NET && LWIP_USE_GET_HOST_BY_NAME_EXTERNAL
if
(
!
is_distributed_net_enabled
())
{
return
lwip_recvfrom_internal
(
s
,
mem
,
len
,
flags
,
from
,
fromlen
);
}
return
distributed_net_recvfrom
(
s
,
mem
,
len
,
flags
,
from
,
fromlen
);
}
ssize_t
lwip_recvfrom_internal
(
int
s
,
void
*
mem
,
size_t
len
,
int
flags
,
struct
sockaddr
*
from
,
socklen_t
*
fromlen
)
{
#endif
struct
lwip_sock
*
sock
;
ssize_t
ret
;
...
...
@@ -1399,7 +1436,11 @@ lwip_send(int s, const void *data, size_t size, int flags)
if
(
NETCONNTYPE_GROUP
(
netconn_type
(
sock
->
conn
))
!=
NETCONN_TCP
)
{
#if (LWIP_UDP || LWIP_RAW)
done_socket
(
sock
);
#if LWIP_ENABLE_DISTRIBUTED_NET
return
lwip_sendto_internal
(
s
,
data
,
size
,
flags
,
NULL
,
0
);
#else
return
lwip_sendto
(
s
,
data
,
size
,
flags
,
NULL
,
0
);
#endif
#else
/* (LWIP_UDP || LWIP_RAW) */
sock_set_errno
(
sock
,
err_to_errno
(
ERR_ARG
));
done_socket
(
sock
);
...
...
@@ -1423,6 +1464,17 @@ lwip_send(int s, const void *data, size_t size, int flags)
ssize_t
lwip_sendmsg
(
int
s
,
const
struct
msghdr
*
msg
,
int
flags
)
{
#if LWIP_ENABLE_DISTRIBUTED_NET
if
(
!
is_distributed_net_enabled
())
{
return
lwip_sendmsg_internal
(
s
,
msg
,
flags
);
}
return
distributed_net_sendmsg
(
s
,
msg
,
flags
);
}
ssize_t
lwip_sendmsg_internal
(
int
s
,
const
struct
msghdr
*
msg
,
int
flags
)
{
#endif
struct
lwip_sock
*
sock
;
#if LWIP_TCP
u8_t
write_flags
;
...
...
@@ -1587,6 +1639,18 @@ ssize_t
lwip_sendto
(
int
s
,
const
void
*
data
,
size_t
size
,
int
flags
,
const
struct
sockaddr
*
to
,
socklen_t
tolen
)
{
#if LWIP_ENABLE_DISTRIBUTED_NET
if
(
!
is_distributed_net_enabled
())
{
return
lwip_sendto_internal
(
s
,
data
,
size
,
flags
,
to
,
tolen
);
}
return
distributed_net_sendto
(
s
,
data
,
size
,
flags
,
to
,
tolen
);
}
ssize_t
lwip_sendto_internal
(
int
s
,
const
void
*
data
,
size_t
size
,
int
flags
,
const
struct
sockaddr
*
to
,
socklen_t
tolen
)
{
#endif
struct
lwip_sock
*
sock
;
err_t
err
;
u16_t
short_size
;
...
...
src/core/distributed_net/distributed_net.c
0 → 100644
浏览文件 @
4ee67658
/* Copyright (c) 2021-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "lwip/opt.h"
#if LWIP_ENABLE_DISTRIBUTED_NET
#include "lwip/distributed_net/distributed_net.h"
#include "lwip/priv/sockets_priv.h"
static
sys_mutex_t
g_mutex
=
{
0
};
static
u8_t
g_is_distributed_net_enabled
=
0
;
static
u16_t
g_local_tcp_server_port
=
0
;
static
u16_t
g_local_udp_server_port
=
0
;
static
u8_t
g_is_distributed_net_socket
[
NUM_SOCKETS
]
=
{
0
};
#if LWIP_DISTRIBUTED_NET_TRY_CONNECT
static
int
try_connect_to_local_tcp_server
(
u16_t
tcp_port
)
{
struct
sockaddr_in
addr
=
{
0
};
(
void
)
memset_s
(
&
addr
,
sizeof
(
struct
sockaddr_in
),
0
,
sizeof
(
struct
sockaddr_in
));
INIT_SOCK_ADDR
(
&
addr
,
LOCAL_SERVER_IP
,
tcp_port
);
int
sock
=
lwip_socket
(
AF_INET
,
SOCK_STREAM
,
0
);
if
(
sock
<
0
)
{
return
-
1
;
}
int
ret
=
lwip_connect_internal
(
sock
,
(
struct
sockaddr
*
)
&
addr
,
sizeof
(
addr
));
(
void
)
lwip_close_internal
(
sock
);
return
ret
;
}
#endif
void
set_distributed_net_socket
(
int
sock
)
{
int
index
=
SOCKET_TO_INDEX
(
sock
);
if
(
index
>=
0
&&
index
<
NUM_SOCKETS
)
{
sys_mutex_lock
(
&
g_mutex
);
g_is_distributed_net_socket
[
index
]
=
1
;
sys_mutex_unlock
(
&
g_mutex
);
}
}
void
reset_distributed_net_socket
(
int
sock
)
{
int
index
=
SOCKET_TO_INDEX
(
sock
);
if
(
index
>=
0
&&
index
<
NUM_SOCKETS
)
{
sys_mutex_lock
(
&
g_mutex
);
g_is_distributed_net_socket
[
index
]
=
0
;
sys_mutex_unlock
(
&
g_mutex
);
}
}
u16_t
get_local_tcp_server_port
(
void
)
{
sys_mutex_lock
(
&
g_mutex
);
u16_t
ret
=
g_local_tcp_server_port
;
sys_mutex_unlock
(
&
g_mutex
);
return
ret
;
}
u16_t
get_local_udp_server_port
(
void
)
{
sys_mutex_lock
(
&
g_mutex
);
u16_t
ret
=
g_local_udp_server_port
;
sys_mutex_unlock
(
&
g_mutex
);
return
ret
;
}
u8_t
is_distributed_net_enabled
(
void
)
{
sys_mutex_lock
(
&
g_mutex
);
u16_t
ret
=
g_is_distributed_net_enabled
;
sys_mutex_unlock
(
&
g_mutex
);
return
ret
;
}
int
enable_distributed_net
(
u16_t
tcp_port
,
u16_t
udp_port
)
{
LWIP_DEBUGF
(
SOCKETS_DEBUG
,
(
"enable distributed_net"
));
if
(
is_distributed_net_enabled
())
{
if
(
get_local_tcp_server_port
()
==
tcp_port
&&
get_local_udp_server_port
()
==
udp_port
)
{
return
0
;
}
set_errno
(
EINVAL
);
return
-
1
;
}
#if LWIP_DISTRIBUTED_NET_TRY_CONNECT
if
(
try_connect_to_local_tcp_server
(
tcp_port
)
<
0
)
{
return
-
1
;
}
#endif
sys_mutex_lock
(
&
g_mutex
);
g_is_distributed_net_enabled
=
1
;
g_local_tcp_server_port
=
tcp_port
;
g_local_udp_server_port
=
udp_port
;
sys_mutex_unlock
(
&
g_mutex
);
return
0
;
}
int
disable_distributed_net
(
void
)
{
LWIP_DEBUGF
(
SOCKETS_DEBUG
,
(
"disable distributed_net"
));
sys_mutex_lock
(
&
g_mutex
);
for
(
int
i
=
0
;
i
<
NUM_SOCKETS
;
++
i
)
{
if
(
g_is_distributed_net_socket
[
i
])
{
(
void
)
lwip_close_internal
(
INDEX_TO_SOCKET
(
i
));
}
}
g_local_tcp_server_port
=
0
;
g_local_udp_server_port
=
0
;
g_is_distributed_net_enabled
=
0
;
(
void
)
memset_s
(
g_is_distributed_net_socket
,
sizeof
(
g_is_distributed_net_socket
),
0
,
sizeof
(
g_is_distributed_net_socket
));
sys_mutex_unlock
(
&
g_mutex
);
return
0
;
}
#endif
/* LWIP_ENABLE_DISTRIBUTED_NET */
\ No newline at end of file
src/core/distributed_net/distributed_net_core.c
0 → 100644
浏览文件 @
4ee67658
/* Copyright (c) 2021-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "lwip/opt.h"
#if LWIP_ENABLE_DISTRIBUTED_NET
#include "lwip/distributed_net/distributed_net_core.h"
#include "lwip/distributed_net/distributed_net_utils.h"
#include "lwip/distributed_net/udp_transmit.h"
#include "lwip/priv/sockets_priv.h"
int
distributed_net_connect
(
int
sock
,
const
struct
sockaddr
*
addr
,
socklen_t
addr_len
)
{
CHECK_PARA
(
SOCKET_TO_INDEX
(
sock
)
>=
0
&&
SOCKET_TO_INDEX
(
sock
)
<
NUM_SOCKETS
,
EBADF
);
CHECK_PARA
(
addr
!=
NULL
,
EINVAL
);
CHECK_PARA
(
addr_len
>
0
,
EINVAL
);
struct
sockaddr_in
addr_in
=
{
0
};
(
void
)
memset_s
(
&
addr_in
,
sizeof
(
addr_in
),
0
,
sizeof
(
addr_in
));
(
void
)
memcpy_s
(
&
addr_in
,
sizeof
(
addr_in
),
addr
,
MIN
(
sizeof
(
addr_in
),
addr_len
));
if
(
is_no_proxy_network_segment
(
&
addr_in
))
{
return
lwip_connect_internal
(
sock
,
addr
,
addr_len
);
}
(
void
)
memset_s
(
&
addr_in
,
sizeof
(
addr_in
),
0
,
sizeof
(
addr_in
));
INIT_SOCK_ADDR
(
&
addr_in
,
LOCAL_SERVER_IP
,
get_local_tcp_server_port
());
if
(
lwip_connect_internal
(
sock
,
(
struct
sockaddr
*
)
&
addr_in
,
sizeof
(
addr_in
))
<
0
)
{
return
-
1
;
}
set_distributed_net_socket
(
sock
);
(
void
)
memset_s
(
&
addr_in
,
sizeof
(
addr_in
),
0
,
sizeof
(
addr_in
));
(
void
)
memcpy_s
(
&
addr_in
,
sizeof
(
addr_in
),
addr
,
MIN
(
sizeof
(
addr_in
),
addr_len
));
tcp_connect_data
data
=
{
0
};
(
void
)
memset_s
(
&
data
,
sizeof
(
data
),
0
,
sizeof
(
data
));
(
void
)
strcpy_s
(
data
.
dest_addr
,
sizeof
(
data
.
dest_addr
),
inet_ntoa
(
addr_in
.
sin_addr
));
data
.
dest_port
=
ntohs
(
addr_in
.
sin_port
);
if
(
lwip_send
(
sock
,
&
data
,
sizeof
(
data
),
0
)
<
0
)
{
reset_distributed_net_socket
(
sock
);
return
-
1
;
}
return
0
;
}
ssize_t
distributed_net_sendto
(
int
sock
,
const
void
*
buf
,
size_t
buf_len
,
int
flags
,
const
struct
sockaddr
*
addr
,
socklen_t
addr_len
)
{
CHECK_PARA
(
SOCKET_TO_INDEX
(
sock
)
>=
0
&&
SOCKET_TO_INDEX
(
sock
)
<
NUM_SOCKETS
,
EBADF
);
CHECK_PARA
(
buf
!=
NULL
,
EINVAL
);
CHECK_PARA
(
buf_len
>
0
,
EINVAL
);
int
type
=
0
;
socklen_t
type_len
=
sizeof
(
type
);
if
(
lwip_getsockopt
(
sock
,
SOL_SOCKET
,
SO_TYPE
,
(
void
*
)
&
type
,
&
type_len
)
<
0
)
{
return
-
1
;
}
if
(
type
!=
SOCK_DGRAM
)
{
return
lwip_sendto_internal
(
sock
,
buf
,
buf_len
,
flags
,
addr
,
addr_len
);
}
struct
sockaddr_in
addr_in
=
{
0
};
(
void
)
memset_s
(
&
addr_in
,
sizeof
(
addr_in
),
0
,
sizeof
(
addr_in
));
if
(
addr
!=
NULL
&&
addr_len
!=
0
)
{
(
void
)
memcpy_s
(
&
addr_in
,
sizeof
(
addr_in
),
addr
,
MIN
(
sizeof
(
addr_in
),
addr_len
));
}
if
(
is_no_proxy_network_segment
(
&
addr_in
))
{
return
lwip_sendto_internal
(
sock
,
buf
,
buf_len
,
flags
,
addr
,
addr_len
);
}
if
(
!
IS_DNS_PORT
(
addr_in
)
||
IS_LOCAL_UDP_SERVER_ADDR
(
&
addr_in
))
{
set_errno
(
EPERM
);
return
-
1
;
}
ssize_t
ret
=
udp_transmit_sendto
(
sock
,
buf
,
buf_len
,
&
addr_in
);
return
ret
>
0
?
UDP_PAYLOAD_LEN
(
ret
)
:
-
1
;
}
ssize_t
distributed_net_sendmsg
(
int
sock
,
const
struct
msghdr
*
hdr
,
int
flags
)
{
CHECK_PARA
(
SOCKET_TO_INDEX
(
sock
)
>=
0
&&
SOCKET_TO_INDEX
(
sock
)
<
NUM_SOCKETS
,
EBADF
);
CHECK_PARA
(
hdr
!=
NULL
,
EINVAL
);
CHECK_PARA
(
hdr
->
msg_iov
!=
NULL
,
EINVAL
);
CHECK_PARA
(
hdr
->
msg_iovlen
>
0
,
EINVAL
);
int
type
=
0
;
socklen_t
type_len
=
sizeof
(
type
);
if
(
lwip_getsockopt
(
sock
,
SOL_SOCKET
,
SO_TYPE
,
(
void
*
)
&
type
,
&
type_len
)
<
0
)
{
return
-
1
;
}
if
(
type
!=
SOCK_DGRAM
)
{
return
lwip_sendmsg_internal
(
sock
,
hdr
,
flags
);
}
const
struct
sockaddr
*
addr
=
(
const
struct
sockaddr
*
)
hdr
->
msg_name
;
socklen_t
addr_len
=
hdr
->
msg_namelen
;
struct
sockaddr_in
addr_in
=
{
0
};
(
void
)
memset_s
(
&
addr_in
,
sizeof
(
addr_in
),
0
,
sizeof
(
addr_in
));
if
(
addr
!=
NULL
&&
addr_len
!=
0
)
{
(
void
)
memcpy_s
(
&
addr_in
,
sizeof
(
addr_in
),
addr
,
MIN
(
sizeof
(
addr_in
),
addr_len
));
}
if
(
is_no_proxy_network_segment
(
&
addr_in
))
{
return
lwip_sendmsg_internal
(
sock
,
hdr
,
flags
);
}
if
(
!
IS_DNS_PORT
(
addr_in
)
||
IS_LOCAL_UDP_SERVER_ADDR
(
&
addr_in
))
{
set_errno
(
EPERM
);
return
-
1
;
}
ssize_t
ret
=
udp_transmit_sendmsg
(
sock
,
hdr
);
return
ret
>
0
?
UDP_PAYLOAD_LEN
(
ret
)
:
-
1
;
}
int
distributed_net_close
(
int
sock
)
{
CHECK_PARA
(
SOCKET_TO_INDEX
(
sock
)
>=
0
&&
SOCKET_TO_INDEX
(
sock
)
<
NUM_SOCKETS
,
EBADF
);
reset_distributed_net_socket
(
sock
);
return
lwip_close_internal
(
sock
);
}
#if LWIP_USE_GET_HOST_BY_NAME_EXTERNAL
typedef
union
{
struct
sockaddr
sa
;
#if LWIP_IPV6
struct
sockaddr_in6
sin6
;
#endif
/* LWIP_IPV6 */
#if LWIP_IPV4
struct
sockaddr_in
sin
;
#endif
/* LWIP_IPV4 */
}
aligned_sockaddr
;
ssize_t
distributed_net_recvfrom
(
int
sock
,
void
*
buf
,
size_t
buf_len
,
int
flags
,
struct
sockaddr
*
from
,
socklen_t
*
from_len
)
{
CHECK_PARA
(
SOCKET_TO_INDEX
(
sock
)
>=
0
&&
SOCKET_TO_INDEX
(
sock
)
<
NUM_SOCKETS
,
EBADF
);
CHECK_PARA
(
buf
!=
NULL
,
EINVAL
);
CHECK_PARA
(
buf_len
>
0
,
EINVAL
);
int
type
=
0
;
socklen_t
type_len
=
sizeof
(
type
);
if
(
lwip_getsockopt
(
sock
,
SOL_SOCKET
,
SO_TYPE
,
(
void
*
)
&
type
,
&
type_len
)
<
0
)
{
return
-
1
;
}
if
(
type
!=
SOCK_DGRAM
)
{
return
lwip_recvfrom_internal
(
sock
,
buf
,
buf_len
,
flags
,
from
,
from_len
);
}
size_t
new_buf_len
=
buf_len
+
sizeof
(
udp_data
);
void
*
new_buf
=
mem_malloc
(
new_buf_len
);
if
(
new_buf
==
NULL
)
{
set_errno
(
ENOMEM
);
return
-
1
;
}
aligned_sockaddr
addr_from
=
{
0
};
socklen_t
addr_from_len
=
sizeof
(
addr_from
);
ssize_t
ret
=
lwip_recvfrom_internal
(
sock
,
new_buf
,
new_buf_len
,
flags
,
(
struct
sockaddr
*
)
&
addr_from
,
&
addr_from_len
);
if
(
ret
<=
0
)
{
mem_free
(
new_buf
);
return
ret
;
}
if
(
!
IS_LOCAL_UDP_SERVER_ADDR
((
struct
sockaddr_in
*
)(
&
addr_from
)))
{
(
void
)
memcpy_s
(
buf
,
buf_len
,
new_buf
,
ret
);
if
(
from
!=
NULL
&&
from_len
!=
NULL
)
{
if
(
*
from_len
>
addr_from_len
)
{
*
from_len
=
addr_from_len
;
}
(
void
)
memcpy_s
(
from
,
*
from_len
,
&
addr_from
,
*
from_len
);
mem_free
(
new_buf
);
return
ret
;
}
}
if
(
ret
<=
sizeof
(
udp_data
))
{
mem_free
(
new_buf
);
set_errno
(
EINVAL
);
return
-
1
;
}
udp_data
*
data
=
(
udp_data
*
)
new_buf
;
(
void
)
memcpy_s
(
buf
,
buf_len
,
data
->
payload
,
ret
-
sizeof
(
udp_data
));
if
(
from
!=
NULL
&&
from_len
!=
NULL
)
{
(
void
)
memcpy_s
(
from
,
*
from_len
,
&
addr_from
,
MIN
(
addr_from_len
,
*
from_len
));
if
(
*
from_len
>=
sizeof
(
struct
sockaddr_in
)
-
SIN_ZERO_LEN
)
{
struct
sockaddr_in
*
temp_addr
=
(
struct
sockaddr_in
*
)
from
;
INIT_SOCK_ADDR
(
temp_addr
,
data
->
dest_addr
,
data
->
dest_port
);
if
(
*
from_len
>
sizeof
(
struct
sockaddr_in
))
{
*
from_len
=
sizeof
(
struct
sockaddr_in
);
}
}
}
mem_free
(
new_buf
);
return
ret
-
(
ssize_t
)
sizeof
(
udp_data
);
}
#endif
/* LWIP_USE_GET_HOST_BY_NAME_EXTERNAL */
#endif
/* LWIP_ENABLE_DISTRIBUTED_NET */
src/core/distributed_net/distributed_net_utils.c
0 → 100644
浏览文件 @
4ee67658
/* Copyright (c) 2021-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "lwip/opt.h"
#if LWIP_ENABLE_DISTRIBUTED_NET
#include "lwip/distributed_net/distributed_net_utils.h"
typedef
struct
no_proxy_network_segment
{
const
char
*
ip
;
const
in_addr_t
mask_len
;
}
no_proxy_network_segment
;
static
const
no_proxy_network_segment
g_special_network_segment
[]
=
{
{
"127.0.0.0"
,
8
},
{
"192.0.0.0"
,
29
},
{
"192.0.2.0"
,
24
},
{
"192.168.0.0"
,
16
},
{
"192.18.0.0"
,
15
},
{
"192.51.100.0"
,
24
},
{
"0.0.0.0"
,
8
},
{
"100.64.0.0"
,
10
},
{
"169.254.0.0"
,
16
},
{
"172.16.0.0"
,
12
},
{
"203.0.113.0"
,
24
},
{
"224.0.0.0"
,
4
},
{
"240.0.0.0"
,
4
},
/* {"10.0.0.0", 8}, */
{
"255.255.255.255"
,
32
},
};
static
in_addr_t
mask_len_to_mask
(
u32_t
mask_len
)
{
if
(
mask_len
>
32
)
{
return
UINT_MAX
;
}
u8_t
num
[
4
]
=
{
0
};
for
(
int
i
=
0
;
i
<
4
;
++
i
)
{
u32_t
len
=
(
mask_len
>
8
?
8
:
mask_len
);
if
(
len
>
0
)
{
u8_t
byte
=
0x80
;
// binary 1000|0000
u8_t
bit
=
0x80
;
// binary 1000|0000
for
(
u32_t
j
=
0
;
j
<
len
-
1
;
++
j
)
{
byte
=
(
bit
>>
1U
)
|
byte
;
bit
>>=
1U
;
}
num
[
i
]
=
byte
;
}
if
(
mask_len
<
8
)
{
break
;
}
mask_len
-=
8
;
}
int
mask
=
0
;
(
void
)
memcpy_s
(
&
mask
,
sizeof
(
int
),
num
,
sizeof
(
int
));
return
mask
;
}
u8_t
is_no_proxy_network_segment
(
const
struct
sockaddr_in
*
addr_in
)
{
for
(
int
i
=
0
;
i
<
sizeof
(
g_special_network_segment
)
/
sizeof
(
g_special_network_segment
[
0
]);
++
i
)
{
ip4_addr_t
ip4_ip
=
{
addr_in
->
sin_addr
.
s_addr
};
ip4_addr_t
ip4_net_ip
=
{
ipaddr_addr
(
g_special_network_segment
[
i
].
ip
)};
ip4_addr_t
ip4_mask
=
{
mask_len_to_mask
(
g_special_network_segment
[
i
].
mask_len
)};
if
(
ip4_addr_netcmp
(
&
ip4_ip
,
&
ip4_net_ip
,
&
ip4_mask
))
{
return
1
;
}
}
return
0
;
}
#endif
/* LWIP_ENABLE_DISTRIBUTED_NET */
\ No newline at end of file
src/core/distributed_net/udp_transmit.c
0 → 100644
浏览文件 @
4ee67658
/* Copyright (c) 2021-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "lwip/opt.h"
#if LWIP_ENABLE_DISTRIBUTED_NET
#include "lwip/distributed_net/udp_transmit.h"
static
s32_t
get_msg_data_len
(
const
struct
msghdr
*
hdr
)
{
if
(
hdr
->
msg_iovlen
>
MAX_IOV_NUM
)
{
return
-
1
;
}
s32_t
data_len
=
0
;
for
(
int
i
=
0
;
i
<
hdr
->
msg_iovlen
;
++
i
)
{
if
(
hdr
->
msg_iov
[
i
].
iov_len
>
MAX_UDP_PAYLOAD_LEN
)
{
set_errno
(
EMSGSIZE
);
return
-
1
;
}
data_len
+=
(
s32_t
)
hdr
->
msg_iov
[
i
].
iov_len
;
if
(
data_len
>
MAX_UDP_PAYLOAD_LEN
)
{
set_errno
(
EMSGSIZE
);
return
-
1
;
}
}
return
data_len
;
}
ssize_t
udp_transmit_sendto
(
int
sock
,
const
void
*
buf
,
size_t
buf_len
,
const
struct
sockaddr_in
*
dest_addr
)
{
if
(
buf_len
>
MAX_UDP_PAYLOAD_LEN
)
{
set_errno
(
EMSGSIZE
);
return
-
1
;
}
udp_data
data
=
{
0
};
(
void
)
memset_s
(
&
data
,
sizeof
(
data
),
0
,
sizeof
(
data
));
(
void
)
strcpy_s
(
data
.
dest_addr
,
sizeof
(
data
.
dest_addr
),
inet_ntoa
(
dest_addr
->
sin_addr
));
data
.
dest_port
=
ntohs
(
dest_addr
->
sin_port
);
struct
iovec
iov
[
2
]
=
{
0
};
(
void
)
memset_s
(
iov
,
sizeof
(
iov
),
0
,
sizeof
(
iov
));
iov
[
0
].
iov_base
=
(
void
*
)
&
data
;
iov
[
0
].
iov_len
=
sizeof
(
data
);
iov
[
1
].
iov_base
=
(
void
*
)
buf
;
iov
[
1
].
iov_len
=
buf_len
;
struct
sockaddr_in
transmit_addr
=
{
0
};
(
void
)
memset_s
(
&
transmit_addr
,
sizeof
(
transmit_addr
),
0
,
sizeof
(
transmit_addr
));
INIT_SOCK_ADDR
(
&
transmit_addr
,
LOCAL_SERVER_IP
,
get_local_udp_server_port
());
struct
msghdr
send_hdr
=
{
0
};
(
void
)
memset_s
(
&
send_hdr
,
sizeof
(
send_hdr
),
0
,
sizeof
(
send_hdr
));
SET_MSG_ADDR
(
&
send_hdr
,
&
transmit_addr
,
sizeof
(
transmit_addr
));
send_hdr
.
msg_iov
=
iov
;
send_hdr
.
msg_iovlen
=
2
;
return
lwip_sendmsg_internal
(
sock
,
&
send_hdr
,
0
);
}
ssize_t
udp_transmit_sendmsg
(
int
sock
,
const
struct
msghdr
*
hdr
)
{
if
(
get_msg_data_len
(
hdr
)
<
0
)
{
return
-
1
;
}
struct
sockaddr_in
temp_addr_in
=
{
0
};
(
void
)
memset_s
(
&
temp_addr_in
,
sizeof
(
temp_addr_in
),
0
,
sizeof
(
temp_addr_in
));
(
void
)
memcpy_s
(
&
temp_addr_in
,
sizeof
(
temp_addr_in
),
hdr
->
msg_name
,
MIN
(
sizeof
(
temp_addr_in
),
hdr
->
msg_namelen
));
udp_data
data
=
{
0
};
(
void
)
memset_s
(
&
data
,
sizeof
(
data
),
0
,
sizeof
(
data
));
(
void
)
strcpy_s
(
data
.
dest_addr
,
sizeof
(
data
.
dest_addr
),
inet_ntoa
(
temp_addr_in
.
sin_addr
));
data
.
dest_port
=
ntohs
(
temp_addr_in
.
sin_port
);
u32_t
size
=
sizeof
(
struct
iovec
)
*
(
hdr
->
msg_iovlen
+
1
);
struct
iovec
*
iov
=
mem_malloc
(
size
);
if
(
iov
==
NULL
)
{
set_errno
(
ENOMEM
);
return
-
1
;
}
(
void
)
memset_s
(
iov
,
size
,
0
,
size
);
iov
[
0
].
iov_base
=
(
void
*
)
&
data
;
iov
[
0
].
iov_len
=
sizeof
(
data
);
for
(
int
i
=
0
;
i
<
hdr
->
msg_iovlen
;
++
i
)
{
iov
[
i
+
1
].
iov_base
=
hdr
->
msg_iov
[
i
].
iov_base
;
iov
[
i
+
1
].
iov_len
=
hdr
->
msg_iov
[
i
].
iov_len
;
}
struct
sockaddr_in
transmit_addr
=
{
0
};
(
void
)
memset_s
(
&
transmit_addr
,
sizeof
(
transmit_addr
),
0
,
sizeof
(
transmit_addr
));
INIT_SOCK_ADDR
(
&
transmit_addr
,
LOCAL_SERVER_IP
,
get_local_udp_server_port
());
struct
msghdr
send_hdr
=
{
0
};
(
void
)
memset_s
(
&
send_hdr
,
sizeof
(
send_hdr
),
0
,
sizeof
(
send_hdr
));
SET_MSG_ADDR
(
&
send_hdr
,
&
transmit_addr
,
sizeof
(
transmit_addr
));
send_hdr
.
msg_iov
=
iov
;
send_hdr
.
msg_iovlen
=
hdr
->
msg_iovlen
+
1
;
ssize_t
ret
=
lwip_sendmsg_internal
(
sock
,
&
send_hdr
,
0
);
mem_free
(
iov
);
return
ret
;
}
#endif
/* LWIP_ENABLE_DISTRIBUTED_NET */
src/core/dns.c
浏览文件 @
4ee67658
...
...
@@ -86,6 +86,11 @@
#include "lwip/opt.h"
#if LWIP_ENABLE_DISTRIBUTED_NET && !LWIP_USE_GET_HOST_BY_NAME_EXTERNAL
#include "lwip/distributed_net/distributed_net.h"
#include "lwip/distributed_net/udp_transmit.h"
#endif
#if LWIP_DNS
/* don't build if not configured for use in lwipopts.h */
#include "lwip/def.h"
...
...
@@ -778,8 +783,18 @@ dns_send(u8_t idx)
}
/* if here, we have either a new query or a retry on a previous query to process */
#if LWIP_ENABLE_DISTRIBUTED_NET && !LWIP_USE_GET_HOST_BY_NAME_EXTERNAL
if
(
is_distributed_net_enabled
())
{
p
=
pbuf_alloc
(
PBUF_TRANSPORT
,
(
u16_t
)(
sizeof
(
udp_data
)
+
SIZEOF_DNS_HDR
+
strlen
(
entry
->
name
)
+
2
+
SIZEOF_DNS_QUERY
),
PBUF_RAM
);
}
else
{
p
=
pbuf_alloc
(
PBUF_TRANSPORT
,
(
u16_t
)(
SIZEOF_DNS_HDR
+
strlen
(
entry
->
name
)
+
2
+
SIZEOF_DNS_QUERY
),
PBUF_RAM
);
}
#else
p
=
pbuf_alloc
(
PBUF_TRANSPORT
,
(
u16_t
)(
SIZEOF_DNS_HDR
+
strlen
(
entry
->
name
)
+
2
+
SIZEOF_DNS_QUERY
),
PBUF_RAM
);
#endif
if
(
p
!=
NULL
)
{
const
ip_addr_t
*
dst
;
u16_t
dst_port
;
...
...
@@ -788,12 +803,41 @@ dns_send(u8_t idx)
hdr
.
id
=
lwip_htons
(
entry
->
txid
);
hdr
.
flags1
=
DNS_FLAG1_RD
;
hdr
.
numquestions
=
PP_HTONS
(
1
);
#if LWIP_ENABLE_DISTRIBUTED_NET && !LWIP_USE_GET_HOST_BY_NAME_EXTERNAL
if
(
is_distributed_net_enabled
())
{
udp_data
udp_data_hdr
=
{
0
};
(
void
)
memset_s
(
&
udp_data_hdr
,
sizeof
(
udp_data_hdr
),
0
,
sizeof
(
udp_data_hdr
));
dst
=
&
dns_servers
[
entry
->
server_idx
];
#if LWIP_IPV6
(
void
)
strcpy_s
(
udp_data_hdr
.
dest_addr
,
sizeof
(
udp_data_hdr
.
dest_addr
),
ip4addr_ntoa
(
&
dst
->
u_addr
.
ip4
));
#else
(
void
)
strcpy_s
(
udp_data_hdr
.
dest_addr
,
sizeof
(
udp_data_hdr
.
dest_addr
),
ip4addr_ntoa
(
dst
));
#endif
udp_data_hdr
.
dest_port
=
DNS_SERVER_PORT
;
pbuf_take
(
p
,
&
udp_data_hdr
,
sizeof
(
udp_data_hdr
));
pbuf_take_at
(
p
,
&
hdr
,
SIZEOF_DNS_HDR
,
sizeof
(
udp_data_hdr
));
}
else
{
pbuf_take
(
p
,
&
hdr
,
SIZEOF_DNS_HDR
);
}
#else
pbuf_take
(
p
,
&
hdr
,
SIZEOF_DNS_HDR
);
#endif
hostname
=
entry
->
name
;
--
hostname
;
/* convert hostname into suitable query format. */
#if LWIP_ENABLE_DISTRIBUTED_NET && !LWIP_USE_GET_HOST_BY_NAME_EXTERNAL
if
(
is_distributed_net_enabled
())
{
query_idx
=
sizeof
(
udp_data
)
+
SIZEOF_DNS_HDR
;
}
else
{
query_idx
=
SIZEOF_DNS_HDR
;
}
#else
query_idx
=
SIZEOF_DNS_HDR
;
#endif
do
{
++
hostname
;
hostname_part
=
hostname
;
...
...
@@ -851,7 +895,25 @@ dns_send(u8_t idx)
dst_port
=
DNS_SERVER_PORT
;
dst
=
&
dns_servers
[
entry
->
server_idx
];
}
#if LWIP_ENABLE_DISTRIBUTED_NET && !LWIP_USE_GET_HOST_BY_NAME_EXTERNAL
if
(
is_distributed_net_enabled
())
{
ip_addr_t
local_addr
=
{
0
};
dst_port
=
get_local_udp_server_port
();
#if LWIP_IPV6
local_addr
.
u_addr
.
ip4
.
addr
=
ipaddr_addr
(
LOCAL_SERVER_IP
);
local_addr
.
type
=
IPADDR_TYPE_V4
;
#else
local_addr
.
addr
=
ipaddr_addr
(
LOCAL_SERVER_IP
);
#endif
err
=
udp_sendto
(
dns_pcbs
[
pcb_idx
],
p
,
&
local_addr
,
dst_port
);
}
else
{
err
=
udp_sendto
(
dns_pcbs
[
pcb_idx
],
p
,
dst
,
dst_port
);
}
#else
err
=
udp_sendto
(
dns_pcbs
[
pcb_idx
],
p
,
dst
,
dst_port
);
#endif
/* free pbuf */
pbuf_free
(
p
);
...
...
@@ -1222,9 +1284,28 @@ dns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr,
{
/* Check whether response comes from the same network address to which the
question was sent. (RFC 5452) */
#if LWIP_ENABLE_DISTRIBUTED_NET && !LWIP_USE_GET_HOST_BY_NAME_EXTERNAL
if
(
is_distributed_net_enabled
())
{
#if LWIP_IPV6
if
(
addr
->
type
!=
IPADDR_TYPE_V4
||
addr
->
u_addr
.
ip4
.
addr
!=
ipaddr_addr
(
LOCAL_SERVER_IP
)
||
port
!=
get_local_udp_server_port
())
{
goto
ignore_packet
;
/* ignore this packet */
}
#else
if
(
addr
->
addr
!=
ipaddr_addr
(
LOCAL_SERVER_IP
)
||
port
!=
get_local_udp_server_port
())
{
goto
ignore_packet
;
/* ignore this packet */
}
#endif
}
else
{
if
(
!
ip_addr_cmp
(
addr
,
&
dns_servers
[
entry
->
server_idx
]))
{
goto
ignore_packet
;
/* ignore this packet */
}
}
#else
if
(
!
ip_addr_cmp
(
addr
,
&
dns_servers
[
entry
->
server_idx
]))
{
goto
ignore_packet
;
/* ignore this packet */
}
#endif
}
/* Check if the name in the "question" part match with the name in the entry and
...
...
src/include/lwip/distributed_net/distributed_net.h
0 → 100644
浏览文件 @
4ee67658
/* Copyright (c) 2021-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef LWIP_HDR_DISTRIBUTED_NET_H
#define LWIP_HDR_DISTRIBUTED_NET_H
#include "lwip/opt.h"
#if LWIP_ENABLE_DISTRIBUTED_NET
#include "lwip/sockets.h"
#define IP4_MAX_ADDR_LEN 16
/* strlen(255.255.255.255) + 1 */
#define LOCAL_SERVER_IP "127.0.0.1"
#define SOCKET_TO_INDEX(socket) ((socket)-LWIP_SOCKET_OFFSET)
#define INDEX_TO_SOCKET(index) ((index) + LWIP_SOCKET_OFFSET)
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define INIT_SOCK_ADDR(addr, ip_string, port) \
do { \
(addr)->sin_family = AF_INET; \
(addr)->sin_port = lwip_htons(port); \
(addr)->sin_addr.s_addr = ipaddr_addr(ip_string); \
} while (0)
#define SET_MSG_ADDR(hdr, addr, addr_len) \
do { \
((struct msghdr *)(hdr))->msg_name = (void *)(addr); \
((struct msghdr *)(hdr))->msg_namelen = (addr_len); \
} while (0)
void
set_distributed_net_socket
(
int
sock
);
void
reset_distributed_net_socket
(
int
sock
);
u16_t
get_local_tcp_server_port
(
void
);
u16_t
get_local_udp_server_port
(
void
);
u8_t
is_distributed_net_enabled
(
void
);
int
enable_distributed_net
(
u16_t
tcp_port
,
u16_t
udp_port
);
int
disable_distributed_net
(
void
);
#endif
/* LWIP_ENABLE_DISTRIBUTED_NET */
#endif
/* LWIP_HDR_DISTRIBUTED_NET_H */
src/include/lwip/distributed_net/distributed_net_core.h
0 → 100644
浏览文件 @
4ee67658
/* Copyright (c) 2021-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef LWIP_HDR_DISTRIBUTED_NET_CORE_H
#define LWIP_HDR_DISTRIBUTED_NET_CORE_H
#include "lwip/opt.h"
#if LWIP_ENABLE_DISTRIBUTED_NET
#include "lwip/distributed_net/distributed_net.h"
#include "lwip/sockets.h"
#define DNS_PORT 53
#define CHECK_PARA(exp, err) \
do { \
if (!(exp)) { \
set_errno(err); \
return -1; \
} \
} while (0)
#define IS_LOCAL_UDP_SERVER_ADDR(addr) \
((addr)->sin_addr.s_addr == ipaddr_addr(LOCAL_SERVER_IP) && (addr)->sin_port == ntohs(get_local_udp_server_port()))
#define IS_DNS_PORT(addr) (ntohs((addr).sin_port) == DNS_PORT)
typedef
struct
tcp_connect_data
{
char
dest_addr
[
IP4_MAX_ADDR_LEN
];
u32_t
dest_port
;
}
tcp_connect_data
;
int
distributed_net_connect
(
int
sock
,
const
struct
sockaddr
*
addr
,
socklen_t
addr_len
);
ssize_t
distributed_net_sendto
(
int
sock
,
const
void
*
buf
,
size_t
buf_len
,
int
flags
,
const
struct
sockaddr
*
addr
,
socklen_t
addr_len
);
ssize_t
distributed_net_sendmsg
(
int
sock
,
const
struct
msghdr
*
hdr
,
int
flags
);
int
distributed_net_close
(
int
sock
);
#if LWIP_USE_GET_HOST_BY_NAME_EXTERNAL
ssize_t
distributed_net_recvfrom
(
int
sock
,
void
*
buf
,
size_t
buf_len
,
int
flags
,
struct
sockaddr
*
from
,
socklen_t
*
from_len
);
#endif
/* LWIP_USE_GET_HOST_BY_NAME_EXTERNAL */
#endif
/* LWIP_ENABLE_DISTRIBUTED_NET */
#endif
/* LWIP_HDR_DISTRIBUTED_NET_CORE_H */
src/include/lwip/distributed_net/distributed_net_utils.h
0 → 100644
浏览文件 @
4ee67658
/* Copyright (c) 2021-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef LWIP_HDR_DISTRIBUTED_NET_UTILS_H
#define LWIP_HDR_DISTRIBUTED_NET_UTILS_H
#include "lwip/opt.h"
#if LWIP_ENABLE_DISTRIBUTED_NET
#include "lwip/sockets.h"
u8_t
is_no_proxy_network_segment
(
const
struct
sockaddr_in
*
addr_in
);
#endif
/* LWIP_ENABLE_DISTRIBUTED_NET */
#endif
/* LWIP_HDR_DISTRIBUTED_NET_UTILS_H */
src/include/lwip/distributed_net/udp_transmit.h
0 → 100644
浏览文件 @
4ee67658
/* Copyright (c) 2021-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef LWIP_HDR_UDP_TRANSMIT_H
#define LWIP_HDR_UDP_TRANSMIT_H
#include "lwip/opt.h"
#if LWIP_ENABLE_DISTRIBUTED_NET
#include "lwip/distributed_net/distributed_net.h"
#include "lwip/sockets.h"
#define MAX_UDP_PAYLOAD_LEN 2048
#define MAX_IOV_NUM 2048
#define UDP_PAYLOAD_LEN(send_len) ((send_len) - (ssize_t)sizeof(udp_data))
typedef
struct
udp_data
{
char
dest_addr
[
IP4_MAX_ADDR_LEN
];
u32_t
dest_port
;
char
payload
[];
}
udp_data
;
ssize_t
udp_transmit_sendto
(
int
sock
,
const
void
*
buf
,
size_t
buf_len
,
const
struct
sockaddr_in
*
dest_addr
);
ssize_t
udp_transmit_sendmsg
(
int
sock
,
const
struct
msghdr
*
hdr
);
#endif
/* LWIP_ENABLE_DISTRIBUTED_NET */
#endif
/* LWIP_HDR_UDP_TRANSMIT_H */
src/include/lwip/sockets.h
浏览文件 @
4ee67658
...
...
@@ -608,6 +608,22 @@ int lwip_fcntl(int s, int cmd, int val);
const
char
*
lwip_inet_ntop
(
int
af
,
const
void
*
src
,
char
*
dst
,
socklen_t
size
);
int
lwip_inet_pton
(
int
af
,
const
char
*
src
,
void
*
dst
);
#if LWIP_ENABLE_DISTRIBUTED_NET
int
lwip_connect_internal
(
int
s
,
const
struct
sockaddr
*
name
,
socklen_t
namelen
);
ssize_t
lwip_sendto_internal
(
int
s
,
const
void
*
data
,
size_t
size
,
int
flags
,
const
struct
sockaddr
*
to
,
socklen_t
tolen
);
ssize_t
lwip_sendmsg_internal
(
int
s
,
const
struct
msghdr
*
msg
,
int
flags
);
#if LWIP_USE_GET_HOST_BY_NAME_EXTERNAL
ssize_t
lwip_recvfrom_internal
(
int
s
,
void
*
mem
,
size_t
len
,
int
flags
,
struct
sockaddr
*
from
,
socklen_t
*
fromlen
);
#endif
/* LWIP_USE_GET_HOST_BY_NAME_EXTERNAL */
int
lwip_close_internal
(
int
s
);
#endif
#if LWIP_COMPAT_SOCKETS
#if LWIP_COMPAT_SOCKETS != 2
/** @ingroup socket */
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录