Skip to content

SLIP: Switch to poll based design#9396

Merged
acassis merged 1 commit intoapache:masterfrom
secore-ly:slip-rewrite
May 26, 2023
Merged

SLIP: Switch to poll based design#9396
acassis merged 1 commit intoapache:masterfrom
secore-ly:slip-rewrite

Conversation

@michi-jung
Copy link
Contributor

Summary

This is a refactored version of the SLIP network driver. Updates include:

  1. The original design started two kernel threads per SLIP device. The refactored version uses file_poll to essentially be driven by the UART RX and TX interrupts and pushes work to the low priority work queue.

  2. The SLIP byte un-/stuffing is more efficient now, using memcpy instead of handling each byte individually.

  3. The switch of the old SLIP driver to IOBs caused buffer overwrites if packets were sent that would not fit into a single IOB. This is fixed now.

Impact

Changes are contained to the SLIP network driver. This fix is reducing latency, improving throughput and is more resource efficient.

Testing

Working fine for me with LwM2M, Telnet, and iperf

This is a refactored version of the SLIP network driver.  Updates
include:

1. The original design started two kernel threads per SLIP device.
   The refactored version uses file_poll to essentially be driven
   by the UART RX and TX interrupts and pushes work to the low
   priority work queue.

2. The SLIP byte un-/stuffing is more efficient now, using memcpy
   instead of handling each byte individually.

3. The switch of the old SLIP driver to IOBs caused buffer overwrites
   if packets were sent that would not fit into a single IOB.  This is
   fixed now.

Signed-off-by: Michael Jung <michael.jung@secore.ly>
@acassis
Copy link
Contributor

acassis commented May 26, 2023

Very nice @michi-jung ! I want to create a video tutorial explaining how to use SLIP. My last video was about using ZMODEM, so SLIP demo should be nice! Was it easy to use/test?

@acassis acassis merged commit 2e27698 into apache:master May 26, 2023
@acassis
Copy link
Contributor

acassis commented May 27, 2023

@xiaoxiang781216
Copy link
Contributor

  1. The switch of the old SLIP driver to IOBs caused buffer overwrites if packets were sent that would not fit into a single IOB. This is fixed now.

@michi-jung but the change need resolve two big buffer and copy them to/from iob. Why not simply extend iob to SLIP MTU or support the chain IOB instead?

@michi-jung
Copy link
Contributor Author

michi-jung commented May 28, 2023

@michi-jung did you test with Linux? http://patrickst.blogspot.com/2011/11/tcpip-over-slip-on-gnulinux-ubuntu.html

Hi @acassis, yes, only on Debian 11 (bullseye). To setup a point-to-point connection the following was sufficient for me (as root or with an account with sufficient capabilities):

slattach -L -s 115200 -p slip /dev/ttyUSB0 &
ifconfig sl0 10.0.0.1 pointtopoint 10.0.0.2 up
route add 10.0.0.2 dev sl0

To enable access to the network access from you devices to the wider network, you have to enable ip forwarding and network address translation on the host:

echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o enp0s31f6 -j MASQUERADE
iptables -A FORWARD -i enp0s31f6 -o sl0 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i sl0 -o enp0s31f6 -j ACCEPT

Since the MTU for SLIP is very small (296 bytes), IP packets from the internet will often be fragmented by the host before being forwarded to the device. Thus, you should have IP defragmentation enabled in NuttX (CONFIG_NET_IPFRAG=y).

@michi-jung
Copy link
Contributor Author

@michi-jung but the change need resolve two big buffer and copy them to/from iob. Why not simply extend iob to SLIP MTU or support the chain IOB instead?

I tried to avoid the complexity of doing the byte de-/stuffing in IOBs. And the two buffers are still smaller than the two stacks required by the tx and rx kernel threads in the old design.

However, it is of course possible to do this in IOBs. I will open an issue to investigate this in the future. I am currently short on time, but will do this over the next couple of weeks.

@xiaoxiang781216
Copy link
Contributor

Thanks, @michi-jung

@michi-jung michi-jung deleted the slip-rewrite branch January 11, 2026 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants