Loopback device will consume the d_iob packet in upper layer protocol,
in order to avoid null pointer access, reprepare iob buffer before polling connections
Signed-off-by: chao an <anchao@xiaomi.com>
l3/l4 stack will decouple the reference of d_buf gradually, Only legacy
devices still retain d_buf support, new net devices will use d_iob
Signed-off-by: chao an <anchao@xiaomi.com>
Fix icmpv6_reply logic broken by commit 48311cc61f and 391b501639.
- 48311cc61f "Fix unaligned memory access when creating ICMP Port Unreachable messages"
- It removed `htonl` function outside `data`, then the byte order may be wrong, so add `htons` back.
- 391b501639 "net: extract l3 header build code into new functions"
- It mis-removed the `memmove`, and the icmpv6 has no payload copied after this commit.
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
Set IPv4 flag before processing ipforward, otherwise the ICMP packet responded by ipforward may sometimes be regarded as IPv6.
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
Split out ipv4_nat_in/outbound_internal which returns entry instead of error code, for later ICMP error types, does not change any current logic.
Reason: Outer packet doesn't have information of port, so we need to find entry by inner packet, and apply the entry to outer packet.
| Outer Packet: SRC = Peer IP<No Port>, DST = External IP<No Port> |
| Inner Packet: SRC = External IP:Port, DST = Peer IP:Port |
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
This commit is for later ICMP error types processing, and does not change any current logic.
Reason for supporting both side of modification is that an inbound ICMP Error MSG may carry original packet like this:
| IP HDR: SRC = Peer IP, DST = External IP |
| ICMP HDR: ERROR MSG |
| <Origin> IP HDR: SRC = External IP, DST = Peer IP |
| <Origin> L4 HDR: SRC = External Port, DST = Peer Port |
So we need to support inbound translation (External -> Local) on SRC or DST of each header.
And so do the outbound direction.
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
devif_loopback needs to be applied on l2 data, and was broken by commit below, now fix it.
| commit 8850dee746
| Author: chao an <anchao@xiaomi.com>
| Date: Sun Nov 27 03:31:07 2022 +0800
|
| net/devif: move preprocess of txpoll into common code
|
| Signed-off-by: chao an <anchao@xiaomi.com>
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
devif/ipv4_input.c: In function ‘ipv4_in’:
devif/ipv4_input.c:305:15: warning: declaration of ‘ret’ shadows a previous local [-Wshadow]
305 | int ret = ipv4_forward(dev, ipv4);
| ^~~
devif/ipv4_input.c:151:7: note: shadowed declaration is here
151 | int ret = OK;
| ^~~
Signed-off-by: chao an <anchao@xiaomi.com>
The following APIs need to be overriden by the arch after enabling
CONFIG_NET_ARCH_CHKSUM, move these functions to the common header
file to avoid prototype conflicts
uint16_t chksum(uint16_t sum, FAR const uint8_t *data, uint16_t len);
uint16_t net_chksum(FAR uint16_t *data, uint16_t len);
uint16_t ipv4_upperlayer_chksum(FAR struct net_driver_s *dev, uint8_t proto);
uint16_t ipv6_upperlayer_chksum(FAR struct net_driver_s *dev,
uint8_t proto, unsigned int iplen);
uint16_t ipv4_chksum(FAR struct ipv4_hdr_s *ipv4);
Signed-off-by: chao an <anchao@xiaomi.com>
TX poll callback in device lo(loopback) can be replaced by devif_loopback()
from devif_poll() hook, remove duplicate code to reuse this logic
Signed-off-by: chao an <anchao@xiaomi.com>
Add link layer length in loopback is unnecessary after below change checkin:
| commit 6fa60627eb
| Author: chao an <anchao@xiaomi.com>
| Date: Sun Nov 27 02:13:21 2022 +0800
|
| net/devif/ip: build l2 header on the IP layer
|
| Signed-off-by: chao an <anchao@xiaomi.com>
Signed-off-by: chao an <anchao@xiaomi.com>
fix build break if enable CONFIG_NET_IPv6 only
In file included from tcp/tcp_sendfile.c:38:
tcp/tcp_sendfile.c: In function ‘sendfile_eventhandler’:
tcp/tcp_sendfile.c:173:27: error: ‘struct tcp_conn_s’ has no member named ‘domain’
173 | DEBUGASSERT(conn->domain == PF_INET6);
| ^~
Signed-off-by: chao an <anchao@xiaomi.com>
inet/ipv4_setsockopt.c: In function ‘ipv4_setsockopt’:
inet/ipv4_setsockopt.c:200:19: error: invalid use of undefined type ‘struct udp_conn_s’
200 | conn->ttl = ttl;
| ^~
inet/ipv4_setsockopt.c:223:19: error: invalid use of undefined type ‘struct udp_conn_s’
223 | conn->flags |= _UDP_FLAG_PKTINFO;
| ^~
inet/ipv4_setsockopt.c:223:30: error: ‘_UDP_FLAG_PKTINFO’ undeclared (first use in this function)
223 | conn->flags |= _UDP_FLAG_PKTINFO;
| ^~~~~~~~~~~~~~~~~
inet/ipv4_setsockopt.c:223:30: note: each undeclared identifier is reported only once for each function it appears in
inet/ipv4_setsockopt.c:227:19: error: invalid use of undefined type ‘struct udp_conn_s’
227 | conn->flags &= ~_UDP_FLAG_PKTINFO;
Signed-off-by: ligd <liguiding1@xiaomi.com>
ARP support is only built if the Ethernet link layer is supported.
Continue and send the ARP request only if this device uses the
Ethernet link layer protocol.
Signed-off-by: chao an <anchao@xiaomi.com>
The `datalen` indicates the whole len of original packet, which will become the payload inside icmpv6 packet.
Using `datalen = (ipv4->len[0] << 8) + ipv4->len[1]` in icmp_reply is correct, because it includes IPv4 header, but when coming to IPv6, the `len` does not include the header, so we need to add it back.
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
Issue:
recv return 0 means peer side has already closed the connection according to
man page's description.
0 is returned without set errno when TCP rx timeout happens with current
design.
Solution:
return result instead of ir_result when ir_result is 0, then -1 will be
returned with errno set to EAGAIN for tcp rx buffer empty case.
Signed-off-by: liangchaozhong <liangchaozhong@xiaomi.com>
when usrsock client try to connect usrsock server local_loop
socket with an invalid port, server cannot find a listener conn
to handle this connet request, then it will response a TCP_RESET
packet via nuttx existing processing, when before conn recv this
RESET packet, it will trigger usrsock_rpmsg_server poll return
and send REMOTE_CLOSE event to usrsock client.
so usrsock connect_event fucntion need handle this event.
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>