Commit Graph

3009 Commits

Author SHA1 Message Date
Kian Karas
46a8c665d7 net/tcp: fix missing error code propagation
If devif_send() failed its returned error code was not propagated
to user space. Instead, a send length of zero was returned (in
violation of POSIX).
2024-06-22 19:26:14 -03:00
Kian Karas
324446bbba net/udp: fix net_[un]lock() in udp_bind
net_unlock() called without a previous call to net_lock().

Error introduced by b10d6be17a
2024-06-22 19:26:14 -03:00
Zhe Weng
2c303f213f net/netfilter: Add filter table in ip6tables
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2024-06-20 09:43:05 +08:00
Zhe Weng
c72edb0637 net: Add set/getsockopt options compatible with ip6tables
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2024-06-20 09:43:05 +08:00
Zhe Weng
9637c10696 net/netfilter: Add filter table in iptables.
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2024-06-20 09:43:05 +08:00
Zhe Weng
f7181676b7 net: Support IP packet filter
Add a firewall compatible with Linux's iptables and ip6tables, with chains at similar points in the packet processing path.

NIC ─> ipv[46]_input ┬> ipv[46]_forward ─> [FORWARD] ┬> devif_poll_out ─> NIC
                     │                               │
                     │          ┌>  tcp  ┐           │
                     │          ├>  udp  ┤           │
                     └> [INPUT] ┼> icmp  ┼> [OUTPUT] ┘
                                ├> icmp6 ┤
                                └>  ...  ┘

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2024-06-20 09:43:05 +08:00
gaohedong
dc651e090e net/can: Add SO_RCVBUF option for can socket
If the CAN stack receiving packets fast, but the application layer reading packets slow. Then `conn->readahead` will continue to grow, leading to memory leaks. Finally CAN stack potentially starve out all IOB buffers. To prevent memory leaks, users can restrict can socket buffer length.

Signed-off-by: gaohedong <gaohedong@xiaomi.com>
2024-06-14 19:54:07 +08:00
zhushiqi
d029e88472 nuttx/net: fixed bind can not return error when used same addr.
Signed-off-by: zhushiqi <hiccupzhu@gmail.com>
2024-06-13 22:00:41 +08:00
meijian
f4d9005bea netlink: fix IPV6 macro bug
Signed-off-by: meijian <meijian@xiaomi.com>
2024-06-06 09:27:50 +02:00
Tiago Medicci Serrano
96f83bb03a net: Enable CONFIG_NET_ARP_SEND by default
Enable logic to send ARP requests if the target IP address mapping
does not appear in the ARP table.

Please check the comment in https://github.com/apache/nuttx/issues/12446#issuecomment-2145856778
2024-06-06 02:40:16 +08:00
zhanghongyu
9472426f69 net/inet: Rename ttl to s_ttl in sconn.
uniform naming convention

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2024-06-05 23:22:15 +08:00
liqinhui
05b101134a net:Support jumbo frame prealloc the iob for the ICMP/UDP/TCP.
For the ICMP, UDP and TCP, pre-alloc an iob for a jumbo frame.

Signed-off-by: liqinhui <liqinhui@xiaomi.com>
2024-06-02 09:31:37 -03:00
raiden00pl
c09f7f7864 cmake: add missing arp_acd.c file 2024-06-02 09:27:36 -03:00
raiden00pl
b01e8b1b6e net/ipfrag/Kconfig: NET_IPFRAG depends on IOB_NCHAINS > 0 2024-06-02 09:27:36 -03:00
meijian
0bad215cf8 net/tcp: fix tcp will not close when tcp retransmission reaches TCP_MAXRTX
In "psock_send_eventhandler",when retransmit count bigger TCP_MAXRTX nuttx will set release wrb. But before this it will also set "conn->tx_unacked = 0" if we only retransmit one packet(conn->tx_unacked == sent),and In func "tcp_timer" only "conn->tx_unacked > 0" will close the tcp conn. So app will never close if nuttx retransmit over max timers.

Signed-off-by: meijian <meijian@xiaomi.com>
2024-05-22 17:46:04 -03:00
yinshengkai
20ebe0e64c Replace all asserts in kernel code with ASSERT
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-05-17 10:18:16 -03:00
meijian
d199249769 [net][udp] fix udp wrb-iob leak when NIC was down
Signed-off-by: meijian <meijian@xiaomi.com>
2024-05-15 11:12:36 +08:00
meijian
11dfc5809a [ipv6][netlink] add netlink report when get ipv6 address by icmpv6
Signed-off-by: meijian <meijian@xiaomi.com>
2024-05-14 16:00:45 -03:00
meijian
35f8c19112 [net][route] fix Mico definition bug
Signed-off-by: meijian <meijian@xiaomi.com>
2024-05-14 22:05:35 +08:00
meijian
4702a09538 net/netlink: Add RTM preifx notify support
Signed-off-by: meijian <meijian@xiaomi.com>
2024-05-14 10:05:37 -03:00
meijian
8eaefd2424 net/netlink: Add RTM neigh notify support
Signed-off-by: meijian <meijian@xiaomi.com>
2024-05-14 10:05:37 -03:00
meijian
34aeeb024c net/netlink: Add RTM route support
Signed-off-by: meijian <meijian@xiaomi.com>
2024-05-14 10:05:37 -03:00
meijian
98d5e118c0 [icmpv6] fix resource leak of icmpv6
Signed-off-by: meijian <meijian@xiaomi.com>
2024-05-14 16:25:56 +08:00
simbit18
09bfaa7292 fix nxstyle
fix Relative file path does not match actual file.
2024-05-11 01:19:06 +08:00
zhanghongyu
45568229ef tcp: decouple TCP_NODELAY and NET_TCP_KEEPALIVE
TCP_NODELAY is an independent configuration and does not depend on TCP_KEEPALIVE

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2024-04-29 17:45:14 +08:00
zhanghongyu
0cd893fb5a icmpv6_neighbor: Simply skip IPv6 conflict detection on L3 Nic
Otherwise, the IP address is always considered to conflict, and the ipv6
address cannot be effectively obtained.
Later we will look at how to perform conflict detection on L3 network cards

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2024-04-29 17:44:40 +08:00
zhanghongyu
f739fd010d icmpv6_neighbor: skip neighbor solicitation on L3 Nic
Otherwise, sending will fail because the neighbor table cannot be found

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2024-04-29 17:44:40 +08:00
Zhe Weng
41ab3a9cfe net/udp_input: Only dup packets for broadcast / multicast.
We found previous multicast support (https://github.com/apache/nuttx/pull/12015) harms some unicast situation, and the `udp_input` should not dup packets for unicast.
Now, we only pass broadcast / multicast packets into each listener and let the code under control of `CONFIG_NET_BROADCAST`.

Ref: https://github.com/torvalds/linux/blob/v6.8/net/ipv4/udp.c#L2219

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2024-04-24 08:24:47 +02:00
Zhe Weng
3a844d8dd7 net/netlink: Add NETLINK_NETFILTER's CONNTRACK support
Now we only supports conntrack info from NAT entries, to let our apps in user space know the mapping status in NAT.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2024-04-18 13:03:59 +08:00
Zhe Weng
9b77bb16c9 net/netlink: Move netlink_add_terminator as public
Prepare for other netlink dumps.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2024-04-18 13:03:59 +08:00
Zhe Weng
b0cf0acc66 net/nat: Add foreach interface for entries
Prepare for netlink conntrack dump of entries.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2024-04-18 13:03:59 +08:00
Zhe Weng
932c41debb net/nat: Remove unnecessary logic in inbound logic
Finish https://github.com/apache/nuttx/pull/12116#discussion_r1560880897

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2024-04-12 14:39:01 +02:00
Zhe Weng
17584eaa4f net/nat: Rename struct ipv*_nat_entry to ipv*_nat_entry_t
I found `struct ipv*_nat_entry` is missing `_s` suffix, but the name is too long in some cases, so maybe `ipv*_nat_entry_t` could be better.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2024-04-12 14:39:01 +02:00
Zhe Weng
e543a8086e net: Optimize TCP/UDP port selection
Optimize TCP/UDP port selection, and fix possibly dead loop.

Finish discussion in https://github.com/apache/nuttx/pull/12116#discussion_r1560851977

Note:
Linux also uses EADDRINUSE for failing in finding a portno, according to https://man7.org/linux/man-pages/man2/bind.2.html

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2024-04-12 15:46:29 +08:00
Zhe Weng
4eddf84a76 net/nat: Optimize port selection
And fix possibly dead loop.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2024-04-11 22:23:29 +08:00
Zhe Weng
f3b34c84c2 net/nat: Support IPv6 Masquerading (NAT66)
Notes:
1. This version of NAT66 is a stateful one like NAT44, corresponding to Linux's MASQUERADE target of ip6tables.  We can support stateless NAT66 & NPTv6 later by slightly modify the address & port selection logic (maybe just match the rules and skip the entry find).
2. We're using same flag `IFF_NAT` for both NAT44 & NAT66 to make control easier.  Which means, if we enable NAT, both NAT44 & NAT66 will be enabled.  If we don't want one of them, we can just disable that one in Kconfig.
3. Maybe we can accelerate the checksum adjustment by pre-calculate a difference of checksum, and apply it to each packet, instead of calling `net_chksum_adjust` each time.  Just a thought, maybe do it later.
4. IP fragment segments on NAT66 connections are not supported yet.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2024-04-11 22:23:29 +08:00
Zhe Weng
676826cb7c net/utils: Add net_ipv6_payload to get IPv6 L4 payload
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2024-04-11 22:23:29 +08:00
Zhe Weng
f2ff5cee03 net/nat: Make some IPv4 NAT functions as common
To prepare for future IPv6 NAT functions.
- Rename common ipv4_nat_xxx to nat_xxx
- Move some common definitions into header

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2024-04-11 22:23:29 +08:00
meijian
93beeeeab0 [tcp/udp] fix port generation not in range
(port % max + min)may overflow uint16

Signed-off-by: meijian <meijian@xiaomi.com>
2024-04-09 23:35:55 +08:00
wangchen
b446a002db net:add customizable default max & min port
add customizable default max & min port

Signed-off-by: wangchen <wangchen41@xiaomi.com>
2024-04-09 23:35:55 +08:00
Zhe Weng
7f1e80f0de net/nat: Slightly optimize the IPv4 NAT
1. Reduce getting `old_ip` in `ipv4_nat_ip_adjust`.
2. Some format change.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2024-04-09 14:44:26 +08:00
zhanghongyu
a9bff735e7 net/can: deliver data into multiple CAN conn bound to same dev
Because CAN is a broadcast protocol, each conn needs to be given independent data to avoid mutual interference.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2024-04-09 00:25:44 +08:00
Zhe Weng
a1a09f271f net/nat: Support Symmetric NAT
The symmetric NAT limits one external port to be used with only one peer ip:port.

Note:
1. To avoid using too much #ifdef, we're always passing peer_ip and peer_port as arguments, but won't use them under full cone NAT, let the compiler optimize them.
2. We need to find port binding without peer ip:port, so don't add peer ip:port into hash key.
3. Symmetric NAT needs to *select another external port if a port is used by any other NAT entry*, this behavior is exactly same as Full Cone NAT, so we don't need to change anything related to `ipv4_nat_port_inuse`.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2024-04-07 23:57:55 +08:00
Xiang Xiao
2fd73bd82f net: Fix max conn always one less than configured value
return NULL only when the total number is larger than configured value

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2024-04-07 10:42:56 -03:00
Zhe Weng
806d783fd6 net/udp: Deliver data into multiple UDP conn bound to same port
Note: We'll only get multiple conn bound to same port when we support SO_REUSEADDR

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2024-03-29 11:52:24 +08:00
Zhe Weng
408320f2ba net/udp: Support deliver multicast packets back to local apps
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2024-03-29 11:52:24 +08:00
Zhe Weng
2a342d2424 net/netdev: Add netdev_iob_clone helper
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2024-03-29 11:52:24 +08:00
zhanghongyu
3956a52c58 net/tcp: return true only when send window updates
return true even when window has not changed will cause delayed ack cannot take effect.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2024-03-13 22:24:04 +08:00
Xiang Xiao
615c4bc6e9 net/local: Fix the wrong direction of threshold setting
reader should set POLLIN threshold, writer should set POLLOUT threshold.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2024-03-10 11:44:33 -03:00
Xiang Xiao
b0e3a35c39 net/local: Skip poll_notify in local_event_pollsetup if no event happen
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2024-03-10 11:44:33 -03:00