• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..--

docker/04-Jan-2025-536380

libcoap/04-Jan-2025-24,48116,307

mbedtls-2.4.0/04-Jan-2025-174,048123,507

python-websocket-server/04-Jan-2025-840631

systemd/04-Jan-2025-5640

tinydtls-0.8.2/04-Jan-2025-25,52417,937

virtual-hub/04-Jan-2025-586444

.gitignoreD04-Jan-20252.3 KiB117106

MakefileD04-Jan-20252.3 KiB8659

README NAT.mdD04-Jan-20252.8 KiB8160

README.dockerD04-Jan-20251.6 KiB5535

README.legacyD04-Jan-20255.9 KiB238150

README.mdD04-Jan-20257.7 KiB268220

avahi-daemon.confD04-Jan-20251,017 5022

avahi-daemon.shD04-Jan-202545 41

big-file.htmlD04-Jan-20251.5 KiB1614

ca.crtD04-Jan-20251.1 KiB2019

client.crtD04-Jan-20251,001 1817

client_privkey.pemD04-Jan-20251.6 KiB2827

coap-client.cD04-Jan-202547.3 KiB1,9121,506

dnsmasq.confD04-Jan-2025483 2111

dnsmasq.shD04-Jan-202543 41

dnsmasq_nat.confD04-Jan-2025195 127

docker.confD04-Jan-20251 KiB4328

docker.conf.stopD04-Jan-2025153 53

dtls-client.cD04-Jan-202522 KiB666508

dtls-server.cD04-Jan-202511 KiB463326

echo-apps-cert.pemD04-Jan-20251.1 KiB1918

echo-apps-key.pemD04-Jan-20251.6 KiB2827

echo-client.cD04-Jan-202522.6 KiB771647

echo-server.cD04-Jan-202514.1 KiB630492

http-server.pyD04-Jan-2025806 3424

https-server.pemD04-Jan-20252.7 KiB4746

https-server.pyD04-Jan-20251.4 KiB5228

index.htmlD04-Jan-2025178 98

loop-ppp-dev.shD04-Jan-2025929 3410

loop-pppd.shD04-Jan-20251 KiB4018

loop-radvd.shD04-Jan-20251.7 KiB7445

loop-slip-tap.shD04-Jan-20251.2 KiB4822

loop-slip.shD04-Jan-20251.2 KiB4521

loop-socat.shD04-Jan-2025927 339

monitor_15_4.cD04-Jan-202510.1 KiB506382

nat.confD04-Jan-2025685 2916

nat.conf.stopD04-Jan-2025229 75

nat.pngD04-Jan-202563 KiB

net-capture.pyD04-Jan-20253.6 KiB12393

net-setup.shD04-Jan-20253.2 KiB149100

radvd_native_posix.confD04-Jan-2025577 3426

radvd_slip.confD04-Jan-2025577 3426

start-leshan.shD04-Jan-2025822 1911

stop-leshan.shD04-Jan-2025152 52

stunnel.confD04-Jan-20251.1 KiB4841

stunnel.shD04-Jan-2025739 256

stunnel_sc.confD04-Jan-2025721 3227

tcptest.pyD04-Jan-20253.4 KiB11979

throughput-client.cD04-Jan-202518 KiB596497

tunslip6.cD04-Jan-202527.7 KiB1,172952

websocket-console.pyD04-Jan-2025586 3017

zephyr-websocket-server.pyD04-Jan-2025943 3018

zeth-multiface.confD04-Jan-20251.7 KiB5738

zeth-multiface.conf.stopD04-Jan-2025308 149

zeth-tunnel.confD04-Jan-20252.4 KiB7048

zeth-tunnel.conf.stopD04-Jan-2025507 2015

zeth-vlan.confD04-Jan-20251.8 KiB6343

zeth.confD04-Jan-2025502 2112

zeth.conf.stopD04-Jan-202598 63

zeth0-gptp.confD04-Jan-2025139 74

zeth1-gptp.confD04-Jan-2025140 74

README NAT.md

1# Create NAT and routing for Zephyr native network on Linux
2
3This page describes how you can set up a networking rules that allows you to run Zephyr applications
4build to native_posix or QEMU targets and get them to access public Internet.
5
6
7
8![Network overview](nat.png)
9
10Zephyr applications, when build on native_posix or various qemu targets,
11run simulated Ethernet driver that attaches itself to a network interface called zeth.
12This is Linux TAP interface so it can send and receive Ethernet frames.
13
14In order to have networking with Zephyr, you need to configure IP address on linux kernel side,
15set up the routing and have NAT (Network Address Translation / IP masquerading) for outbound
16traffic.
17
18Optionally, having dnsmasq to serve as small stand-alone DHCP and DNS server helps.
19When running dnsmasq, it must bind into the zeth interface, so it does not serve any
20requests coming from outside network.
21
22## Building the Zephyr application for native networking
23
24At minimun, you need following Kconfig settings for your *native_posix* application to have
25working network
26
27```
28# General network requirements
29CONFIG_NETWORKING=y
30CONFIG_NET_IPV4=y
31CONFIG_NET_TCP=y
32CONFIG_NET_UDP=y
33CONFIG_NET_SOCKETS=y
34
35# Native posix requirements
36CONFIG_ENTROPY_GENERATOR=y
37CONFIG_TEST_RANDOM_GENERATOR=y
38
39CONFIG_NET_L2_ETHERNET=y
40CONFIG_ETH_NATIVE_POSIX=y
41CONFIG_ETH_NATIVE_POSIX_RANDOM_MAC=y
42
43# IPv4 config
44CONFIG_NET_CONFIG_SETTINGS=y
45CONFIG_NET_CONFIG_NEED_IPV4=y
46CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.0.2.1"
47CONFIG_NET_CONFIG_MY_IPV4_GW="192.0.2.2"
48CONFIG_DNS_RESOLVER=y
49CONFIG_DNS_RESOLVER_MAX_SERVERS=1
50CONFIG_DNS_SERVER_IP_ADDRESSES=y
51CONFIG_DNS_SERVER1="192.0.2.2"
52```
53
54## Running the native_posix app
55
56You can test your configuration for example in `zephyr/samples/net/sockets/http_get` by creating
57a file called `boards/native_posix.conf` with the content from the sample above.
58
59```sh
60cd zephyr/samples/net/sockets/http_get
61# create boards/native_posix.conf
62
63# Building the application
64west build -b native_posix -- -DOVERLAY_CONFIG=overlay-tls.conf
65
66# Run the application
67# Note that you need to run it realtime (-rt) so responses don't timeout,
68# otherwise it would run faster.
69# Also any TLS/DTLS traffic needs proper seed or random generator,
70# $RANDOM is adequate enough for testing purposes, not secure though,
71./build/zephyr/zephyr.elf -rt -seed=$RANDOM
72
73# Run application that use shell, for example lwm2m_client
74# These spawn the shell and logs into a virtual serial port on /dev/pts/X
75# it is easier to open a x-terminal to this serial port when you start the application
76./build/zephyr/zephyr.elf -rt -seed=$RANDOM -attach_uart
77```
78
79You might need to supply also `-attach_uart_cmd` parameter, in case default X-terminal is not
80installed. For example `-attach_uart_cmd='x-terminal-emulator -e screen %s &'` works.
81

README.docker

1# Testing with net-tools and Docker
2
3* Create Docker image
4
5	cd docker/
6	docker build -t net-tools .
7
8* Setup network interfaces, IP addresses and routes
9
10	sudo ./net-setup.sh --config docker.conf start
11
12* Run Docker image
13
14  Set the docker internal network name to the value $DOCKER_USER_INTERFACE
15  in docker.config above, default is 'net-tools0'. The bridge network that
16  docker creates will be printed on standard out, it's bridge interface
17  name will be br-XXXXXXXXXXXX. Check that the IPv4 and IPv6 addresses
18  given on the docker command line match the subnets in 'docker.conf'.
19
20  Interactively:
21
22	docker run --hostname=zephyr --name=net-tools \
23	       --ip=192.0.2.2 --ip6=2001:db8::2 \
24	       --rm -it --network=net-tools0 net-tools sh
25
26        exit with Ctrl-p ctrl-q to execute tests from the command line
27
28  Non-interactively
29
30	docker run --hostname=zephyr --name=net-tools \
31	       --ip=192.0.2.2 --ip6=2001:db8::2 \
32	       --rm -dt --network=net-tools0 net-tools sh
33
34* Run Qemu / native-posix image
35
36	rm -rf build && mkdir build
37
38	cmake -GNinja -DBOARD=native_posix -B build
39	   or
40	cmake -GNinja -DBOARD=qemu_x86 -DOVERLAY_CONFIG=overlay-e1000.conf \
41	   -B build
42
43	ninja -C build run
44
45* Execute tests like echo-client
46
47	docker container exec net-tools /net-tools/echo-client 2001:db8::1
48	docker container exec net-tools /net-tools/echo-client -t 2001:db8::1
49	docker container exec net-tools /net-tools/echo-client 192.0.2.1
50	docker container exec net-tools /net-tools/echo-client -t 192.0.2.1
51
52* Remove the network setup:
53
54	sudo ./net-setup.sh --config docker.conf stop
55

README.legacy

1The comments and instructions below are for legacy IP stack in Zephyr.
2
3tunslip6
4========
5
6tunslip6 can be used in host side to create a tun device that
7is connected to a unix socket that qemu is providing. This
8way it is possible to pass packets between host and target
9system via slip protocol.
10
11You need to connect tunslip6 to the second qemu serial line
12through a UNIX socket (qemu option -serial unix:/tmp/slip-socket).
13
141) Start socat
15
16$ socat PTY,link=/tmp/slip.dev UNIX-LISTEN:/tmp/slip.sock
17
182) Start qemu, use the listener demo app. Note that you need to
19   set CONFIG_NETWORKING_UART=y in your configuration.
20
21   You might need to set the platform and ARCH like this if simple_uart
22   driver is not found in your default platform.
23
24$ make PLATFORM_CONFIG=basic_cortex_m3 ARCH=arm \
25     QEMU_EXTRA_FLAGS="-serial none -serial unix:/tmp/slip.sock" qemu
26
27  or just simply
28
29$ make qemu
30
313) Start tunslip6
32
33$ sudo ./tunslip6 -s `readlink /tmp/slip.dev` 2001:db8::1/64
34
354) Send data to listener
36
37$ nc -u -6 2001:db8::2 4242 <<EOF
38foobar
39EOF
40
41There are also convenience scripts for running socat, radvd and
42tunslip6 processes called loop-socat.sh, loop-radvd.sh and
43loop-slip.sh. So to simplify things you need three terminals
44for doing this:
45
46Terminal 1:
47$ ./loop-socat.sh
48
49Terminal 2:
50$ sudo ./loop-slip.sh
51
52Terminal 3:
53$ sudo ./loop-radvd.sh
54
55After running these scripts you do not need to manual restart
56them when qemu process stops.
57
58
59radvd
60=====
61In order the IPv6 stateless address auto configuration (SLAAC)
62to work, you need to run radvd or similar tool in host side.
63There is an example radvd.conf file present in the tools directory.
64
65$ sudo radvd -d 1 -C radvd.conf -m stderr
66
67
68tunslip
69=======
70
71tunslip if for IPv4 networks and it can be used in host side
72to create a tun device that is connected to a unix socket that
73qemu is providing. This way it is possible to pass packets
74between host and target system via slip protocol.
75
76You need to connect tunslip to the second qemu serial line
77through a UNIX socket (qemu option -serial unix:/tmp/slip-socket).
78
791) Start socat
80
81$ socat PTY,link=/tmp/slip.dev UNIX-LISTEN:/tmp/slip.sock
82
832) Start qemu, use the listener demo app. Note that you need to
84   set CONFIG_NETWORKING_UART=y in your configuration.
85
86   You might need to set the platform and ARCH like this if simple_uart
87   driver is not found in your default platform.
88
89$ make PLATFORM_CONFIG=basic_cortex_m3 ARCH=arm \
90     QEMU_EXTRA_FLAGS="-serial none -serial unix:/tmp/slip.sock" qemu
91
923) Start tunslip
93
94$ sudo ./tunslip -s `readlink /tmp/slip.dev` 192.0.2.1 255.255.255.0
95
964) Send data to listener
97
98$ nc -u 192.0.2.2 4242 <<EOF
99foobar
100EOF
101
102
103echo-client
104===========
105
106echo-client is a tool that is run in Linux host side and
107which sends pre-defined UDP data packets to echo-server
108application that is running in qemu side. This client
109process verifies that it is able to receive data correctly
110from the echo-server and thus verify that the upper layer
111networking components in Zephyr IP stack work properly.
112
113You needs to setup the slip connection (see the steps 1 to 3)
114in tunslip6 section of this document.
115
116Example:
117
118$ ./echo-client 2001:db8::2
119
120In order to send multicast IPv6 packets, one needs to
121give the network interface as a parameter.
122
123$ ./echo-client -i tun0 ff84::2
124
125
126echo-server
127===========
128
129echo-server is a tool that is run in Linux host side and
130which waits UDP data sent by echo-client application that
131is running in qemu side.
132
133You needs to setup the slip connection (see the steps 1 to 3)
134in tunslip6 section of this document. Make sure that the Linux
135host firewall is not blocking the packets that the echo-client
136running in qemu is sending via tun0 device.
137
138Example:
139
140$ sudo ./echo-server -i tun0
141
142
143dtls-client
144===========
145
146dtls-client is a tool that is run in Linux host side and
147which connects to dtls-server running in qemu.
148
149You needs to setup the slip connection (see the steps 1 to 3)
150in tunslip6 section of this document.
151
152Example:
153
154$ make dtls-client
155
156$ ./dtls-client -b 2001:db8::1 2001:db8::2
157
158
159dtls-server
160===========
161
162dtls-server is a tool that is run in Linux host side and
163which waits DTLS data sent by dtls-client application that
164is running in qemu side.
165
166You needs to setup the slip connection (see the steps 1 to 3)
167in tunslip6 section of this document.
168
169Example:
170
171$ make dtls-server
172
173$ ./dtls-server -i tun0
174
175monitor_15_4
176============
177
178monitor_15_4 is a tool that is run in Linux host side and
179which reads data from pipes which is written buy 15.4 test
180application from qemu. This is T juntion tool which reads
181and writes data from pipes and feed into pipes (this way
182both qemus communicate each other) and same time data
183written in PCAP format for wireshark monitoring.
184
185Please also read samples/network/test_15_4/README for
186how to configure and run two qemus.
187
188Make and run this tool
189
190$ make
191
192Usage : monitor_15_4 <sample pcap file> [<pipe_1> <pipe_2>]
193
194$ monitor_15_4 sample.pcap
195
196or
197
198$ monitor_15_4 sample.pcap /tmp/ip-15-4-1 /tmp/ip-15-4-2
199
200
201coap-client
202===========
203
204coap-client is a tool that is run in Linux host side and
205which connects to coap-server running in qemu.
206
207You needs to setup the slip connection (see the steps 1 to 3)
208in tunslip6 section of this document.
209
210Example:
211
212$ make coap-client
213
214If you want to use DTLS then run client like this
215$ sudo ./coap-client -i tun0 2001:db8::2
216
217For non-DTLS case, run client like this
218$ sudo ./coap-client -n -i tun0 2001:db8::2
219
220
221coap-observe-client
222===================
223
224You can test the coap-observe-client that is running in qemu
225using the coap-server example server that is found in libcoap.
226So get libcoap package which can be found here
227https://github.com/obgm/libcoap.git
228Compile and install the libcoap library in host.
229
230You needs to setup the slip connection (see the steps 1 to 3)
231in tunslip6 section of this document.
232
233$ /home/user/libcoap/examples/coap-server -A 2001:db8::1 -p 5683
234
235Then in the samples/network/coap_observe_client directory, say
236
237$ make qemu
238

README.md

1[![Run Status](https://api.shippable.com/projects/58ffb2b81fb3ec0700e1602f/badge?branch=master)](https://app.shippable.com/github/zephyrproject-rtos/net-tools)
2
3# Networking Tools
4
5The comments and instructions below are for the new IP stack in Zephyr.
6
7In a Zephyr default setup, the network tools are pre-installed under the
8`tools` directory.
9
10Here are instructions how to communicate between Zephyr that is running
11inside QEMU, and host device that is running Linux.
12
13For setting up routing and NAT rules to allow access to external networks, please see
14the [README NAT.md](README%20NAT.md)
15
16You need to run *socat* and *tunslip* to create a minimally working
17network setup.
18
19There are convenience scripts (_loop-socat.sh_ and _loop-slip-tap.sh_) for
20running socat and tunslip6 processes. For running these, you need two
21terminals.
22
23Terminal 1:
24```
25$ ./loop-socat.sh
26```
27
28Terminal 2:
29```
30$ sudo ./loop-slip-tap.sh
31```
32
33After running these scripts you do not need to manually restart
34them when qemu process stops.
35
36In the Qemu side, you need to compile the kernel with proper config.
37Minimally you need these settings active in your project config file.
38```
39CONFIG_NETWORKING=y
40CONFIG_NET_IPV6=y
41CONFIG_NET_IPV4=y
42CONFIG_NET_YAIP=y
43CONFIG_NET_UDP=y
44CONFIG_NET_LOG=y
45CONFIG_NET_SLIP=y
46CONFIG_SLIP_TAP=y
47CONFIG_SYS_LOG=y
48CONFIG_SYS_LOG_SHOW_COLOR=y
49CONFIG_NANO_TIMEOUTS=y
50CONFIG_TEST_RANDOM_GENERATOR=y
51```
52
53After you have the loop scripts and Qemu running running you can communicate
54with the Zephyr.
55
56If your have echo-server running in the Qemu, then you can use the echo-client
57tool in net-tools directory to communicate with it.
58```
59# ./echo-client -i tap0 2001:db8::1
60```
61The IP stack responds to ping requests if properly configured.
62```
63$ ping6 -I tap0 -c 1 2001:db8::1
64```
65You can attach wireshark to tap0 interface to see what data is being
66transferred.
67
68If building with CONFIG_NET_TCP=y in your project config file, it's possible
69to run the echo-server sample in Zephyr, and then test the TCP stack using
70the supplied tcptest.py script:
71```
72$ ./tcptest.py tap0 2001:db8::1
73```
74This script will send numbers to the echo-server program, read them back,
75and compare if it got the exact bytes back.  Transmission errors, timeouts,
76and time to get the response are all recorded and printed to the standard
77output.
78
79Be sure to use Python 3, as it requires a function from the socket module
80that's only available in this version (wrapper around if_nametoindex(3)).
81
82
83## Using net-setup.sh script to setup host side ethernet interface
84
85The net-setup.sh script can setup an ethernet interface to the host.
86User is able to setup a configuration file that will contain
87commands to setup IP addresses and routes to the host interface.
88This net-setup.sh script will need to be run as a root user.
89
90If no parameters are given, then "zeth" network interface and "zeth.conf"
91configuration file are used. The script waits until user presses CTRL-c
92and then removes the network interface.
93```
94$ net-setup.sh
95```
96```
97$ net-setup.sh --config zeth-vlan.conf
98```
99```
100$ net-setup.sh --config my-own-config.conf --iface foobar
101```
102
103It is also possible to let the script return and then stop the network
104interface later. Is can be done by first creating the interface with
105"start" or "up" command, and then later remove the interface with
106"stop" or "down" command.
107```
108$ net-setup.sh start
109do your things here
110$ net-setup.sh stop
111```
112```
113$ net-setup.sh --config my-own-config.conf up
114do your things here
115$ net-setup.sh --config my-own-config.conf down
116```
117
118Any extra parameters that the script does not know, are passed directly
119to "ip" command.
120```
121$ net-setup.sh --config my-own-config.conf --iface foo user bar
122```
123
124## Using encrypted SSL link with echo-* programs
125
126Install stunnel
127
128Fedora:
129```
130$ dnf install stunnel
131```
132Ubuntu:
133```
134$ apt-get install stunnel4 -y
135```
136Finally run the stunnel script in Linux
137```
138$ ./stunnel.sh
139```
140And connect echo-client to this SSL tunnel (note that the IP address
141is the address of Linux host where the tunnel end point is located).
142```
143$ ./echo-client -p 4243 2001:db8::2 -t
144```
145If you are running echo-client in Zephyr QEMU, then run echo-server like
146this:
147```
148$ ./echo-server -p 4244 -i tap0
149```
150
151If you want to re-create the certificates in echo-server and echo-client in
152Zephyr net samples, then they can be created like this (note that you do not
153need to do this as the certs have been prepared already in echo-server and
154echo-client sample sources):
155```
156$ openssl genrsa -out echo-apps-key.pem 2048
157$ openssl req -new -x509 -key echo-apps-key.pem -out echo-apps-cert.pem \
158    -days 10000 -subj '/CN=localhost'
159```
160The cert that is to be embedded into test_certs.h in echo-server and
161echo-client, can be generated like this:
162```
163$ openssl x509 -in echo-apps-cert.pem -outform DER | \
164    hexdump -e '8/1 "0x%02x, " "\n"' | sed 's/0x  ,//g'
165```
166The private key to be embedded into test_certs.h in echo-server can be
167generated like this:
168```
169$ openssl pkcs8 -topk8 -inform PEM -outform DER -nocrypt \
170    -in echo-apps-key.pem | hexdump -e '8/1 "0x%02x, " "\n"' | \
171    sed 's/0x  ,//g'
172```
173
174If you want to re-create the signed certificates in echo-server in Zephyr
175net samples and echo-client in net-tools, then they can be created like this
176(note that you do not need to do this as the certs have been prepared already
177in echo-server and echo-client sources):
178```
179CA
180--
181$ openssl genrsa -out ca_privkey.pem 2048
182$ openssl req -new -x509 -days 36500 -key ca_privkey.pem -out ca.crt -subj "/CN=exampleCA"
183
184Convert to DER format
185$ openssl x509 -in ca.crt -outform DER -out ca.der
186```
187
188```
189Client
190------
191$ openssl genrsa -out client_privkey.pem 2048
192$ openssl req -new -key client_privkey.pem -out client.csr -subj "/CN=exampleClient"
193$ openssl x509 -req -CA ca.crt -CAkey ca_privkey.pem -days 36500 -in client.csr -CAcreateserial -out client.crt
194```
195
196```
197Server
198------
199$ openssl genrsa -out server_privkey.pem 2048
200$ openssl req -new -key server_privkey.pem -out server.csr -subj "/CN=localhost"
201$ openssl x509 -req -CA ca.crt -CAkey ca_privkey.pem -days 36500 -in server.csr -CAcreateserial -out server.crt
202
203Convert to DER format
204$ openssl x509 -in server.crt -outform DER -out server.der
205$ openssl pkcs8 -topk8 -inform PEM -outform DER -nocrypt -in server_privkey.pem -out server_privkey.der
206```
207
208Copy ca.crt, client.crt and client_privkey.pem to net-tools.
209Copy ca.der, server.der and server_privkey.der to samples/net/sockets/echo-server/src/.
210
211Enable NET_SAMPLE_CERTS_WITH_SC in samples/net/sockets/echo-server and build the sample.
212Use stunnel_sc.conf in stunnel.sh to run echo-client with signed certificates.
213
214## Using DTLS link with echo-* programs
215
216For DTLS client functionality, you can do this
217
218```
219$ ./dtls-client -c echo-apps-cert.pem 2001:db8::1
220```
221or
222```
223$ ./dtls-client -c echo-apps-cert.pem 192.0.2.1
224```
225For DTLS server functionality, you can do this
226
227```
228$ ./dtls-server
229```
230
231## TLS connecitivity errors
232
233If you see this error print in zephyr console
234
235[net/app] [ERR] _net_app_ssl_mainloop: Closing connection -0x7180 (SSL - Verification of the message MAC failed)
236
237Then increasing the mbedtls heap size might help. So you can set the option
238CONFIG_MBEDTLS_HEAP_SIZE to some higher value.
239
240Example:
241```
242CONFIG_MBEDTLS_HEAP_SIZE=30000
243```
244
245## PPP Connectivity
246
247You can test the PPP connectivity running in Qemu in Zephyr using pppd that is
248running in Linux host. You need to run *socat* and *pppd* to create
249a minimally working network setup.
250
251There are convenience scripts (_loop-ppp-dev.sh_ and _loop-pppd.sh_) for
252running socat and pppd processes. For running these, you need two
253terminals.
254
255Terminal 1:
256```
257$ ./loop-ppp-dev.sh
258```
259
260Terminal 2:
261```
262$ sudo ./loop-pppd.sh
263```
264
265After this, start PPP enabled Zephyr application. For example Zephyr
266*echo-server* sample in samples/net/sockets/echo_server has _overlay-ppp.conf_
267file that enables PPP support.
268