Commit Graph

2781 Commits

Author SHA1 Message Date
zhanghongyu
c9a843bdca ipv6: support SOL_IPV6 options IPV6_UNICAST_HOPS and IPV6_MULTICAST_HOPS
Added simple support for IPV6_UNICAST_HOPS and IPV6_UNICAST_HOPS, the application can configure the ttl parameters of the socket in user mode.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-05-13 22:34:21 +08:00
zhanghongyu
1def5da221 net: move ttl field into socket_conn_s struct
move ttl filed from udp_conn_s to socket_conn_s structure to make it more than just control udp.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-05-13 12:39:53 +08:00
wangchen
2e6d0815b2 nuttx/net:Support to PMTUD
RFC 1191
When a router is unable to forward a datagram because it exceeds the
   MTU of the next-hop network and its Don't Fragment bit is set, the
   router is required to return an ICMP Destination Unreachable message
   to the source of the datagram, with the Code indicating
   "fragmentation needed and DF set".  To support the Path MTU Discovery
   technique specified in this memo, the router MUST include the MTU of
   that next-hop network in the low-order 16 bits of the ICMP header
   field that is labelled "unused" in the ICMP specification [7].  The
   high-order 16 bits remain unused, and MUST be set to zero.  Thus, the
   message has the following format:

       0                   1                   2                   3
       0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |   Type = 3    |   Code = 4    |           Checksum            |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |           unused = 0          |         Next-Hop MTU          |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |      Internet Header + 64 bits of Original Datagram Data      |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
RFC 1185
Packet Too Big Message

       0                   1                   2                   3
       0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |     Type      |     Code      |          Checksum             |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |                             MTU                               |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |                    As much of invoking packet                 |
      +               as will fit without the ICMPv6 packet           +
      |                       exceeding 576 octets                    |

   IPv6 Fields:

   Destination Address

                  Copied from the Source Address field of the invoking
                  packet.

   ICMPv6 Fields:

   Type           2

   Code           0

   MTU            The Maximum Transmission Unit of the next-hop link.

   Description

   A Packet Too Big MUST be sent by a router in response to a packet
   that it cannot forward because the packet is larger than the MTU of
   the outgoing link.  The information in this message is used as part
   of the Path MTU Discovery process [RFC-1191].

Signed-off-by: wangchen <wangchen41@xiaomi.com>
2023-05-12 10:21:52 -03:00
Tiago Medicci Serrano
4f4a00ab1f net/local: fix blocking local sockets
Commit 4d6a8663fa made pipes and
named pipes block when opening for O_WRONLY or O_RDONLY. Local
sockets, however, require `local_open_client_tx` to be non-blocking
to enable the server side to prevent the server side from blocking.
If set otherwise, it would deadly block. This commit sets the FIFO
as non-blocking temporarily, open the TX side and, if originally
blocking - restores it to that state.
2023-05-11 11:39:00 +08:00
zhanghongyu
91e13c47ae net: remove conn-related casts
remove redundant casts associated with psock

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-05-10 19:32:09 -03:00
zhanghongyu
e0816ff050 in.h: add SOL_IPV6 protocol-level socket option IPV6_RECVHOPLIMIT
added IPV6_RECVHOPLIMIT support so that fd of SOCK_RAW ICMPV6 can obtain ttl
information, some network related tools use this feature.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-05-10 18:00:15 +08:00
Ville Juven
1e9560e1e5 net/net_cmsg.c: Fix warning about using void* arithmetics
utils/net_cmsg.c: In function 'cmsg_append':
utils/net_cmsg.c:82:23: error: pointer of type 'void *' used in arithmetic [-Werror=pointer-arith]
   82 |   msg->msg_control    += cmsgspace;
      |                       ^~
cc1: all warnings being treated as errors

Using void pointers in arithmetic operations is a GCC extension, it is
not supported by the standard. Because what is the size of a void ?
2023-05-10 17:58:25 +08:00
zhanghongyu
e10fda570b udp: change PKTINFO flag to socket_conn_s struct
move the IPPROTO_IP/IPPROTO_IPV6 flag into the socket_conn_s structure to
make it more than just control udp.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-05-09 07:53:56 +02:00
Xiang Xiao
6f6fce95a2 Replace all sprintf with snprintf
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-05-08 09:57:01 +02:00
zhanghongyu
35dee8fdd2 icmpv6: add SOCK_RAW type support
The third-party library we are porting will send and receive ICMPV6 messages
(router_advert / router_solicit / neighbor_advert / neighbor_solicit etc.)
from the user mode itself, so we added the SOCK_RAW related implementation
for ICMPV6.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-05-07 22:43:10 +08:00
zhanghongyu
9f8d418cd1 forward: copy iob when broadcast forward
since iob offload, ipvx_dev_forward will remove d_iob, if there are multiple
devices, d_iob will be NULL when dev_forward is entered second time. and the
device that receives the packet cannot process the packet after forwarding it
so the iob copy is added.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-05-06 03:18:08 +08:00
Zhe Weng
26e2e1e32f net/udp: Remove wrong check in udp_readahead
- Before IOB offload, srcaddr / src_addr_size / ifindex are written into
  IOB by iob_trycopyin, so io_pktlen > 0 is always true, this check is
  correct at that time. (It won't fail with zero-length UDP datagram.)
- After IOB offload, srcaddr / src_addr_size / ifindex are written into
  offset 0, without increasing io_pktlen. So this check will fail with
  zero-length UDP datagram now.
- We need to support zero-length UDP datagram and this check is
  unnecessary at this point.
  - https://stackoverflow.com/questions/5307031/how-to-detect-receipt-of-a-0-length-udp-datagram
  - https://github.com/apache/nuttx/blob/nuttx-12.1.0/net/udp/udp_callback.c#L214

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-05-05 11:25:07 +03:00
zhanghongyu
bdb5639274 netlink: convert lltype to device type
adapts to third-party code compilation. in the process of porting ConnMan,
we encounter some situations where the structure is not defined, or the
returned data types do not match the expectations. Refer to the common
implementation of other systems and add relevant definitions.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-05-05 00:19:59 +08:00
zhanghongyu
646c41dced tcp_monitor: start_monitor return OK when connect closed by peer
If TCP_FIN is received before the user calls accept, the later accept will
report an error, then the previously received data cannot be read.

operation flow:
tcp_server_listen -> tcp_client_connect -> tcp_client_send ->
tcp_client_close -> tcp_server_accept(fix this error) -> tcp_server_recv

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-05-04 17:12:52 +03:00
zhanghongyu
c288752bef recvmsg: control msg support multi-attribute return
adapts to third-party code compilation. in the process of porting ConnMan,
multiple control message options are enabled, such as IPV6_RECVPKTINFO and
IPV6_RECVHOPLIMIT, so I changed the Filling implementation of the control
message.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-05-04 12:04:11 +02:00
Xiang Xiao
74e2b75857 net: Simplify the tcp/udp existence check
Replace defined(CONFIG_NET_TCP) && !defined(CONFIG_NET_TCP_NO_STACK) with NET_TCP_HAVE_STACK
Replace defined(CONFIG_NET_UDP) && !defined(CONFIG_NET_UDP_NO_STACK) with NET_UDP_HAVE_STACK

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-05-03 17:40:00 +03:00
Xiang Xiao
5de49d2939 net: Remove the extra space
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-05-03 15:18:21 +02:00
Xiang Xiao
df246461ec net/can: Remove the unnecessary "ret = OK;" in can_getsockopt
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-05-03 15:18:21 +02:00
wangchen
d197ca9967 net/procfs: Support to show MTU in netdev statistics
Usage:
ifconfig (interfacename)
example:
ifconfig eth0
eth0	Link encap:Ethernet HWaddr 42:d3:59:ad:5a:2f at RUNNING mtu 1500
	inet addr:10.0.1.2 DRaddr:10.0.1.1 Mask:255.255.255.0
	inet6 addr: fe80::40d3:59ff:fead:5a2f/64
	inet6 DRaddr: ::/64

Signed-off-by: wangchen <wangchen41@xiaomi.com>
2023-04-28 09:45:21 +08:00
chao an
2eb9abc3d8 net/can: fix can mssage corruption if enable NET_TIMESTAMP
Timestamp location in can message has changed,
In the original logic timestamp is saved at the end of the data segment:

io_data
   -------------------------------------------------
   |         CAN message            |  Time Stamp  |
   -------------------------------------------------
   |<---------------     io_len   ---------------->|

In the new structure timestamps will reuse NET_LL_GUARDSIZE to isolate CAN messages:
io_data       io_offset
   -------------------------------------------------
   |  Time Stamp  |         CAN message            |
   -------------------------------------------------
                  |<--------    io_len   --------->|

This PR will:
1. Increase NET_LL_GUARDSIZE to 16 (sizeof(struct timeval)) if NET_CAN && NET_TIMESTAMP are enabled
2. Apply timestamp to adapt to the new structure

Signed-off-by: chao an <anchao@xiaomi.com>
2023-04-27 00:30:58 +08:00
Petro Karashchenko
0a28b2a26e net/bluetooth: fix parameter indentation
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-04-24 09:35:58 -07:00
zhanghongyu
9162800255 tcp_input: drop SYN when no free node in the backlog
Wait for the client to retransmit the ack before trying to allocate the
backlog

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-04-24 01:52:33 +08:00
Zhe Weng
1aceb1d872 net/tcp: Fix clear condition in ofoseg input
We have a case that an http server gives out-of-ordered ACKs, and NuttX client makes `ofoseg`s with length 0, trying to rebuild / put them into `ofosegs` array, which is not intended (no available data and should be skipped). This breaks later logic and finally crashed in `tcp_ofoseg_bufsize` (`ofosegs[i].data` is `NULL`, which should never happen in normal logic).

Note:
- `iob_trimhead` won't return `NULL` when it's applying on normal IOB.
  - Keep `dev->d_iob == NULL` to avoid `iob_trimhead` changed.
- `iob_free_chain` will do nothing when applied to `NULL`.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-04-22 19:26:22 +08:00
zhanghongyu
6c73221dd4 forward: limit the forwarding range of broadcast packets
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-04-22 19:24:46 +08:00
Xiang Xiao
c6d210289f procfs: remove procfs_ from procfs_operations variables
to aglin the naming style with other implementation

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-04-22 03:33:50 -04:00
Xiang Xiao
149cafe450 procfs: Add g_ prefix to all procfs_operations
to conform the coding style

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-04-22 03:33:50 -04:00
zhanghongyu
93c3b8f19e tcp: add TCP_MAXSEG support
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-04-22 01:42:47 +08:00
zhanghongyu
bd4d7a1b76 tcp: accept conn inherits some properties of listener conn
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-04-22 01:42:47 +08:00
zhanghongyu
fdc6dbf176 netlink: add RTM_NEWADDR, RTM_DELADDR and RTM_GETADDR
We have projects that need to sense ip address changes in time,
and set ip address or clear ip address through netlink
so the relevant implementation is added.
The usage and command structure are consistent with linux

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-04-22 01:35:18 +08:00
Zhe Weng
9f8d587b64 net/rpmsg: Set family for rpaddr in ns_bind
The rpmsg addr get from socket accept has rp_family=0, which is not
intended, to avoid wrong logic in other place, set the rp_family
in ns_bind function.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-04-21 13:18:48 +03:00
zhangyuan21
c239d19df0 nuttx: add more dependent header file
Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
2023-04-11 09:13:32 +03:00
Zhe Weng
b058f37353 net/tcp: Reply RST when we cannot receive data
According to RFC 2525, Section 2.17:
"When an application closes a connection in such a way that it can no longer read any received data, the TCP SHOULD, per section 4.2.2.13 of RFC 1122, send a RST if there is any unread received data, or if any new data is received."

When our TCP socket is closed (even when the thread has exited), the peer can keep sending data and NuttX keeps replying ACK (we've tried for ~12h). This is not a good behavior (also different from Linux), so send RST instead of ACK for data receiving in FIN_WAIT.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-03-29 09:22:00 -03:00
Zhe Weng
61ff04b9e2 net/inet: Only setup poll for UDP when s_type == SOCK_DGRAM
Problem:
A SOCK_CTRL socket may be led to udp_pollsetup but never reaches
udp_pollteardown, it seems that we shouldn't call udp_pollsetup for
other socket types.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-03-29 09:18:36 -03:00
zhanghongyu
ec2b74df77 icmpv6: add RDNSS field support for send route advertise
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-03-17 16:50:37 -03:00
zhanghongyu
d9e009cb46 icmpv6: add route advertise RDNSS field handle when icmpv6_input
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-03-17 16:50:37 -03:00
zhangyuan21
fd9792b4bd net: use NXRMUTEX_INITIALIZER for rmutex init
Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
2023-03-15 13:57:08 +01:00
Zhe Weng
7b0d80c94a net/icmpv6: align structs to 2 bytes.
Fix following misaligned errors:

icmpv6/icmpv6_radvertise.c:145:21: runtime error: member access within misaligned address 0x573da9e6 for type 'struct icmpv6_router_advertise_s', which requires 4 byte alignment
0x573da9e6: note: pointer points here
 00 00 00 01 85 00  d6 14 00 00 00 00 01 01  12 8c 25 08 9c f8 04 00  00 00 ff 02 00 00 00 00  00 00
             ^
icmpv6/icmpv6_radvertise.c:167:21: runtime error: member access within misaligned address 0x573da9fe for type 'struct icmpv6_mtu_s', which requires 4 byte alignment
0x573da9fe: note: pointer points here
 af 78 ab 72 00 00  00 00 00 00 00 01 ff 00  00 01 04 00 00 00 ff 02  00 00 00 00 00 00 00 00  00 01
             ^
icmpv6/icmpv6_radvertise.c:176:23: runtime error: member access within misaligned address 0x573daa06 for type 'struct icmpv6_prefixinfo_s', which requires 4 byte alignment
0x573daa06: note: pointer points here
 00 00 05 dc ff 00  00 01 04 00 00 00 ff 02  00 00 00 00 00 00 00 00  00 01 ff 08 9c f8 04 00  00 00
             ^

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-03-10 09:41:02 +01:00
Xiang Xiao
75ecbd4382 net/local: Return the unblock handle correctly in local_accept
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-03-09 09:17:19 +01:00
Zhe Weng
0e018308a3 net/pkt: Add readahead queue for pkt, call input for tx on sim
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-03-08 23:09:25 +02:00
Xiang Xiao
9f4a15110c net: Finish FIONBIO default action if si_ioctl return OK
Continue the work: https://github.com/apache/nuttx/pull/6976

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-03-07 11:34:35 +02:00
Xiang Xiao
3c3dea5d7a net: Make si_poll callback optional
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-03-06 20:58:27 +02:00
Xiang Xiao
c39be172da net: Make si_accept callback optional
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-03-06 20:58:27 +02:00
Xiang Xiao
5dd037c599 net: Make si_connect callback optional
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-03-06 20:58:27 +02:00
Xiang Xiao
a97e2523a4 net: Make si_listen callback optional
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-03-06 20:58:27 +02:00
Xiang Xiao
2553b7701c net: Remove the empty si_getpeername implementation
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-03-06 20:58:27 +02:00
Xiang Xiao
9b3715050b net: Make si_getsockname callback optional
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-03-06 20:58:27 +02:00
Xiang Xiao
b3c1c55805 net: Make si_bind callback optional
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-03-06 20:58:27 +02:00
Zhe Weng
7111d23ae4 net/arp: Only parse ioctl request for valid cmd.
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-03-06 10:51:12 -03:00
Fotis Panagiotopoulos
5e625b9cdb Performance optimizations in connection allocations. 2023-02-28 14:23:16 +01:00
Xiang Xiao
2c5f653bfd Remove the tail spaces from all files except Documentation
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-02-26 13:24:24 -08:00