From bef86e79cd89c8080278045771d6e6c93ea5b2d0 Mon Sep 17 00:00:00 2001 From: Leandro Pereira Date: Thu, 1 Jun 2017 15:12:57 -0700 Subject: [PATCH 1/7] samples: dns_resolve: Clarify documentation about DNS configuration Add clarification that the DNS server configuration must be edited in the respective prj.conf file. JIRA: ZEP-2040 Signed-off-by: Leandro Pereira --- samples/net/dns_resolve/README.rst | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/samples/net/dns_resolve/README.rst b/samples/net/dns_resolve/README.rst index 7529493c09593..d48684434a47e 100644 --- a/samples/net/dns_resolve/README.rst +++ b/samples/net/dns_resolve/README.rst @@ -35,6 +35,7 @@ Requirements Dnsmasq version 2.76 Copyright (c) 2000-2016 Simon Kelley + Wiring ****** @@ -74,7 +75,6 @@ for example: CONFIG_NET_APP_MY_IPV6_ADDR="2001:db8::1" CONFIG_NET_APP_PEER_IPV6_ADDR="2001:db8::2" - are the IPv6 addresses for the DNS client running Zephyr and the DNS server, respectively. @@ -88,7 +88,6 @@ The net-tools can be downloaded from https://github.com/zephyrproject-rtos/net-tools - Open a terminal window and type: .. code-block:: console @@ -96,8 +95,23 @@ Open a terminal window and type: $ cd net-tools $ ./dnsmasq.sh +('su' or 'sudo' may be required.) -NOTE: some systems may require root privileges to run dnsmaq, use sudo or su. +The default project configurations settings for this sample uses the public +Google DNS servers. In order to use the local dnsmasq server, please edit +the appropriate 'prj.conf' file and update the DNS server addresses. For +instance, if using the usual IP addresses assigned to testing, update them +to the following values: + +.. code-block:: console + + CONFIG_DNS_SERVER1="192.0.2.2:5353" + CONFIG_DNS_SERVER2="[2001:db8::2]:5353" + +.. note:: + DNS uses port 53 by default, but the dnsmasq.conf file provided by + net-tools uses port 5353 to allow executing the daemon without + superuser privileges. If dnsmasq fails to start with an error like this: @@ -105,7 +119,6 @@ If dnsmasq fails to start with an error like this: dnsmasq: failed to create listening socket for port 5353: Address already in use - Open a terminal window and type: .. code-block:: console @@ -115,7 +128,6 @@ Open a terminal window and type: Try to launch the dnsmasq application again. - QEMU x86 ======== From 38f855083eccda98715e874ca3289ad420ee0dd9 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sun, 4 Jun 2017 14:28:04 +0300 Subject: [PATCH 2/7] net: context: Operations on unused context should lead to EBADF. Semantics of ENOENT error as used previously is "named entity not found", whereas for "I/O handle is not valid", there's EBADF. For example, POSIX/SUSV2 doesn't even list ENOENT as a possible error for accept(), connect(), recv(), etc. whereas it lists EBADF, e.g.: http://pubs.opengroup.org/onlinepubs/7908799/xns/connect.html Signed-off-by: Paul Sokolovsky --- subsys/net/ip/net_context.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/subsys/net/ip/net_context.c b/subsys/net/ip/net_context.c index 1da453727ce68..fce03a6d6368e 100644 --- a/subsys/net/ip/net_context.c +++ b/subsys/net/ip/net_context.c @@ -646,7 +646,7 @@ int net_context_listen(struct net_context *context, int backlog) NET_ASSERT(PART_OF_ARRAY(contexts, context)); if (!net_context_is_used(context)) { - return -ENOENT; + return -EBADF; } #if defined(CONFIG_NET_OFFLOAD) @@ -1064,7 +1064,7 @@ int net_context_connect(struct net_context *context, #endif if (!net_context_is_used(context)) { - return -ENOENT; + return -EBADF; } if (addr->family != net_context_get_family(context)) { @@ -1577,7 +1577,7 @@ int net_context_accept(struct net_context *context, NET_ASSERT(PART_OF_ARRAY(contexts, context)); if (!net_context_is_used(context)) { - return -ENOENT; + return -EBADF; } #if defined(CONFIG_NET_OFFLOAD) @@ -1748,7 +1748,7 @@ static int sendto(struct net_pkt *pkt, int ret; if (!net_context_is_used(context)) { - return -ENOENT; + return -EBADF; } #if defined(CONFIG_NET_TCP) @@ -2051,7 +2051,7 @@ int net_context_recv(struct net_context *context, NET_ASSERT(context); if (!net_context_is_used(context)) { - return -ENOENT; + return -EBADF; } #if defined(CONFIG_NET_OFFLOAD) From 832a07567f5d866809c1986a8a0b193c65f4d705 Mon Sep 17 00:00:00 2001 From: Jukka Rissanen Date: Mon, 5 Jun 2017 14:52:12 +0300 Subject: [PATCH 3/7] net: https: Allow mbedtls debugging for https-server The mbedtls debugging function was set before the ssl config struct was initialized. This meant that it was not possible to activate mbedtls debug prints. This commit sets the debug print option after the config struct has been initialized. Fixed also the debug prints which print extra \n which looks very bad in debugging outputs. This commit does not enable mbedtls debugging, it just makes it possible to output mbedtls debug prints. In order to get mbedlts debug prints one needs to do this: * set DEBUG_THRESHOLD to >0 in http_server.c * enable CONFIG_NET_DEBUG_HTTP in project config file * enable MBEDTLS_DEBUG_C in mbedtls config file (see file pointed by CONFIG_MBEDTLS_CFG_FILE option) * in qemu, one needs to increase the size of the available RAM, this setting does the trick, CONFIG_RAM_SIZE=300 Signed-off-by: Jukka Rissanen --- subsys/net/lib/http/http_server.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/subsys/net/lib/http/http_server.c b/subsys/net/lib/http/http_server.c index c267633fc4dbc..bddbcd26462a3 100644 --- a/subsys/net/lib/http/http_server.c +++ b/subsys/net/lib/http/http_server.c @@ -29,6 +29,13 @@ static void https_disable(struct http_server_ctx *ctx); #if defined(MBEDTLS_DEBUG_C) #include +/* - Debug levels (from ext/lib/crypto/mbedtls/include/mbedtls/debug.h) + * - 0 No debug + * - 1 Error + * - 2 State change + * - 3 Informational + * - 4 Verbose + */ #define DEBUG_THRESHOLD 0 #endif @@ -958,6 +965,7 @@ static void my_debug(void *ctx, int level, const char *file, int line, const char *str) { const char *p, *basename; + int len; ARG_UNUSED(ctx); @@ -969,6 +977,12 @@ static void my_debug(void *ctx, int level, } + /* Avoid printing double newlines */ + len = strlen(str); + if (str[len - 1] == '\n') { + ((char *)str)[len - 1] = '\0'; + } + NET_DBG("%s:%04d: |%d| %s", basename, line, level, str); } #endif /* MBEDTLS_DEBUG_C && CONFIG_NET_DEBUG_HTTP */ @@ -1281,11 +1295,6 @@ static void https_handler(struct http_server_ctx *ctx) heap_init(ctx); -#if defined(MBEDTLS_DEBUG_C) && defined(CONFIG_NET_DEBUG_HTTP) - mbedtls_debug_set_threshold(DEBUG_THRESHOLD); - mbedtls_ssl_conf_dbg(&ctx->https.mbedtls.conf, my_debug, NULL); -#endif - #if defined(MBEDTLS_X509_CRT_PARSE_C) mbedtls_x509_crt_init(&ctx->https.mbedtls.srvcert); #endif @@ -1296,6 +1305,11 @@ static void https_handler(struct http_server_ctx *ctx) mbedtls_entropy_init(&ctx->https.mbedtls.entropy); mbedtls_ctr_drbg_init(&ctx->https.mbedtls.ctr_drbg); +#if defined(MBEDTLS_DEBUG_C) && defined(CONFIG_NET_DEBUG_HTTP) + mbedtls_debug_set_threshold(DEBUG_THRESHOLD); + mbedtls_ssl_conf_dbg(&ctx->https.mbedtls.conf, my_debug, NULL); +#endif + /* Load the certificates and private RSA key. This needs to be done * by the user so we call a callback that user must have provided. */ From d88877eb6c96b40c91ac3f8a059f4acda47b89a1 Mon Sep 17 00:00:00 2001 From: Ravi kumar Veeramally Date: Mon, 5 Jun 2017 13:56:18 +0300 Subject: [PATCH 4/7] net: rpl: Update RPL header Empty RPL HBH header will be inserted while finalizing IPv6 packet but updated after finding nexthop and sent the packet. In case of Bluetooth or multicast dst address it was missed. Resulted in empty RPL HBH header and packet dropped at peer node. It should be updated in all circumstances. Jira: ZEP-2088 Signed-off-by: Ravi kumar Veeramally --- subsys/net/ip/ipv6.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/subsys/net/ip/ipv6.c b/subsys/net/ip/ipv6.c index faf3861995059..854371aaeb08a 100644 --- a/subsys/net/ip/ipv6.c +++ b/subsys/net/ip/ipv6.c @@ -855,11 +855,23 @@ struct net_pkt *net_ipv6_prepare_for_send(struct net_pkt *pkt) * https://jira.zephyrproject.org/browse/ZEP-1656 */ if (atomic_test_bit(net_pkt_iface(pkt)->flags, NET_IF_POINTOPOINT)) { + /* Update RPL header */ + if (net_rpl_update_header(pkt, &NET_IPV6_HDR(pkt)->dst) < 0) { + net_pkt_unref(pkt); + return NULL; + } + return pkt; } if (net_pkt_ll_dst(pkt)->addr || net_is_ipv6_addr_mcast(&NET_IPV6_HDR(pkt)->dst)) { + /* Update RPL header */ + if (net_rpl_update_header(pkt, &NET_IPV6_HDR(pkt)->dst) < 0) { + net_pkt_unref(pkt); + return NULL; + } + return update_ll_reserve(pkt, &NET_IPV6_HDR(pkt)->dst); } From 48eed00da572a71f90f5e232387f7dd57bc579c3 Mon Sep 17 00:00:00 2001 From: Ravi kumar Veeramally Date: Mon, 5 Jun 2017 15:58:16 +0300 Subject: [PATCH 5/7] net: 6lo: Fix source address uncompression When src and dst addresses are compressed based on context information, uncompression method should verify CID bit, SAC and DAC bits and context ID's. But it has missed some cases which resulted in invalid uncompressed IPv6 header. e.g. CID is set, SAC is 0 and DAC is 1 and context id's provided. Uncompression method assumed that src address is compressed based on context information but it is not. Signed-off-by: Ravi kumar Veeramally --- subsys/net/ip/6lo.c | 89 +++++++++--------------- tests/net/6lo/src/main.c | 24 ++++++- tests/net/ieee802154/fragment/src/main.c | 4 +- 3 files changed, 57 insertions(+), 60 deletions(-) diff --git a/subsys/net/ip/6lo.c b/subsys/net/ip/6lo.c index ab53cb9b7db8c..924d78aaf2311 100644 --- a/subsys/net/ip/6lo.c +++ b/subsys/net/ip/6lo.c @@ -862,11 +862,6 @@ static inline u8_t uncompress_sa(struct net_pkt *pkt, struct net_ipv6_hdr *ipv6, u8_t offset) { - if (CIPHC[1] & NET_6LO_IPHC_SAC_1) { - NET_DBG("SAC_1"); - NET_DBG("SAM_00 unspecified address"); - return offset; - } NET_DBG("SAC_0"); @@ -913,16 +908,11 @@ static inline u8_t uncompress_sa_ctx(struct net_pkt *pkt, u8_t offset, struct net_6lo_context *ctx) { - if (!ctx) { - return uncompress_sa(pkt, ipv6, offset); - } + NET_DBG("SAC_1"); switch (CIPHC[1] & NET_6LO_IPHC_SAM_11) { case NET_6LO_IPHC_SAM_00: - NET_DBG("SAM_00 full src addr inlined"); - - memcpy(ipv6->src.s6_addr, &CIPHC[offset], 16); - offset += 16; + NET_DBG("SAM_00 unspecified address"); break; case NET_6LO_IPHC_SAM_01: NET_DBG("SAM_01 last 64 bits are inlined"); @@ -978,8 +968,6 @@ static inline u8_t uncompress_da_mcast(struct net_pkt *pkt, NET_DBG("Dst is multicast"); if (CIPHC[1] & NET_6LO_IPHC_DAC_1) { - /* TODO: DAM00 Unicast-Prefix-based IPv6 Multicast Addresses */ - /* Reserved DAM_01, DAM_10, DAM_11 */ NET_WARN("Unsupported DAM options"); return 0; } @@ -1033,17 +1021,12 @@ static inline u8_t uncompress_da(struct net_pkt *pkt, struct net_ipv6_hdr *ipv6, u8_t offset) { + NET_DBG("DAC_0"); + if (CIPHC[1] & NET_6LO_IPHC_M_1) { return uncompress_da_mcast(pkt, ipv6, offset); } - if (CIPHC[1] & NET_6LO_IPHC_DAC_1) { - /* Invalid case: ctx doesn't exists , but DAC is 1*/ - return 0; - } - - NET_DBG("DAC_0"); - switch (CIPHC[1] & NET_6LO_IPHC_DAM_11) { case NET_6LO_IPHC_DAM_00: NET_DBG("DAM_00 full dst addr inlined"); @@ -1087,21 +1070,12 @@ static inline u8_t uncompress_da_ctx(struct net_pkt *pkt, u8_t offset, struct net_6lo_context *ctx) { - if (!ctx) { - return uncompress_da(pkt, ipv6, offset); - } + NET_DBG("DAC_1"); if (CIPHC[1] & NET_6LO_IPHC_M_1) { return uncompress_da_mcast(pkt, ipv6, offset); } - if (!(CIPHC[1] & NET_6LO_IPHC_DAC_1)) { - /* Invalid case: ctx exists but DAC is 0. */ - return 0; - } - - NET_DBG("DAC_1"); - switch (CIPHC[1] & NET_6LO_IPHC_DAM_11) { case NET_6LO_IPHC_DAM_01: NET_DBG("DAM_01 last 64 bits are inlined"); @@ -1210,7 +1184,7 @@ static inline u8_t uncompress_nh_udp(struct net_pkt *pkt, #if defined(CONFIG_NET_6LO_CONTEXT) /* Helper function to uncompress src and dst contexts */ -static inline bool uncompress_cid(struct net_pkt *pkt, +static inline void uncompress_cid(struct net_pkt *pkt, struct net_6lo_context **src, struct net_6lo_context **dst) { @@ -1230,17 +1204,6 @@ static inline bool uncompress_cid(struct net_pkt *pkt, if (!(*dst)) { NET_DBG("Unknown dst cid %d", cid); } - - /* If CID flag set and src or dst context not available means, - * either we don't have context information or we received - * corrupted packet. - */ - if (!*src && !*dst) { - NET_ERR("Context information does not exist in cache"); - return false; - } - - return true; } #endif @@ -1259,10 +1222,7 @@ static inline bool uncompress_IPHC_header(struct net_pkt *pkt) if (CIPHC[1] & NET_6LO_IPHC_CID_1) { #if defined(CONFIG_NET_6LO_CONTEXT) - if (!uncompress_cid(pkt, &src, &dst)) { - return false; - } - + uncompress_cid(pkt, &src, &dst); offset++; #else NET_WARN("Context based uncompression not enabled"); @@ -1298,9 +1258,15 @@ static inline bool uncompress_IPHC_header(struct net_pkt *pkt) /* Uncompress Source Address */ #if defined(CONFIG_NET_6LO_CONTEXT) - offset = uncompress_sa_ctx(pkt, ipv6, offset, src); - if (!offset) { - goto fail; + if (CIPHC[1] & NET_6LO_IPHC_SAC_1) { + if (!src) { + NET_ERR("SAC is set but src context doesn't exists"); + goto fail; + } + + offset = uncompress_sa_ctx(pkt, ipv6, offset, src); + } else { + offset = uncompress_sa(pkt, ipv6, offset); } #else offset = uncompress_sa(pkt, ipv6, offset); @@ -1308,15 +1274,26 @@ static inline bool uncompress_IPHC_header(struct net_pkt *pkt) /* Uncompress Destination Address */ #if defined(CONFIG_NET_6LO_CONTEXT) - offset = uncompress_da_ctx(pkt, ipv6, offset, dst); - if (!offset) { - goto fail; + if (CIPHC[1] & NET_6LO_IPHC_DAC_1) { + if (CIPHC[1] & NET_6LO_IPHC_M_1) { + /* TODO: DAM00 Unicast-Prefix-based IPv6 Multicast + * Addresses. DAM_01, DAM_10 and DAM_11 are reserved. + */ + NET_ERR("DAC_1 and M_1 is not supported"); + goto fail; + } + + if (!dst) { + NET_ERR("DAC is set but dst context doesn't exists"); + goto fail; + } + + offset = uncompress_da_ctx(pkt, ipv6, offset, dst); + } else { + offset = uncompress_da(pkt, ipv6, offset); } #else offset = uncompress_da(pkt, ipv6, offset); - if (!offset) { - goto fail; - } #endif net_buf_add(frag, NET_IPV6H_LEN); diff --git a/tests/net/6lo/src/main.c b/tests/net/6lo/src/main.c index 66a76eb109fc4..835a977e4bc67 100644 --- a/tests/net/6lo/src/main.c +++ b/tests/net/6lo/src/main.c @@ -456,7 +456,7 @@ static struct net_6lo_data test_data_4 = { .ipv6.len = { 0x00, 0x00 }, .ipv6.nexthdr = IPPROTO_UDP, .ipv6.hop_limit = 0xff, - .ipv6.src = src_sac1_sam00, + .ipv6.src = src_sam00, .ipv6.dst = dst_m1_dam00, .nh.udp.src_port = htons(udp_src_port_16bit), .nh.udp.dst_port = htons(udp_dst_port_16bit), @@ -795,6 +795,25 @@ static struct net_6lo_data test_data_22 = { .small = true, .iphc = true }; + +static struct net_6lo_data test_data_23 = { + .ipv6.vtc = 0x60, + .ipv6.tcflow = 0x20, + .ipv6.flow = 0x3412, + .ipv6.len = { 0x00, 0x00 }, + .ipv6.nexthdr = IPPROTO_UDP, + .ipv6.hop_limit = 0xff, + .ipv6.src = src_sam00, + .ipv6.dst = dst_dac1_dam01, + .nh.udp.src_port = htons(udp_src_port_8bit_y), + .nh.udp.dst_port = htons(udp_dst_port_8bit), + .nh.udp.len = 0x00, + .nh.udp.chksum = 0x00, + .nh_udp = true, + .nh_icmp = false, + .small = false, + .iphc = true +}; #endif static int test_6lo(struct net_6lo_data *data) @@ -856,7 +875,7 @@ static const struct { { "test_6lo_sam00_dam00", &test_data_1}, { "test_6lo_sam01_dam01", &test_data_2}, { "test_6lo_sam10_dam10", &test_data_3}, - { "test_6lo_sac1_sam00_m1_dam00", &test_data_4}, + { "test_6lo_sam00_m1_dam00", &test_data_4}, { "test_6lo_sam01_m1_dam01", &test_data_5}, { "test_6lo_sam10_m1_dam10", &test_data_6}, { "test_6lo_sam10_m1_dam10_no_udp", &test_data_7}, @@ -876,6 +895,7 @@ static const struct { { "test_6lo_sac1_sam01_m1_dam01", &test_data_20}, { "test_6lo_sac1_sam10_m1_dam10", &test_data_21}, { "test_6lo_sac1_sam11_m1_dam10", &test_data_22}, + { "test_6lo_sac0_sam00_dac1_dam01", &test_data_23}, #endif }; diff --git a/tests/net/ieee802154/fragment/src/main.c b/tests/net/ieee802154/fragment/src/main.c index 34f9d6ca0de21..bf94cd447b456 100644 --- a/tests/net/ieee802154/fragment/src/main.c +++ b/tests/net/ieee802154/fragment/src/main.c @@ -337,7 +337,7 @@ static struct net_fragment_data test_data_4 = { .ipv6.len = { 0x00, 0x00 }, .ipv6.nexthdr = IPPROTO_UDP, .ipv6.hop_limit = 0xff, - .ipv6.src = src_sac1_sam00, + .ipv6.src = src_sam00, .ipv6.dst = dst_m1_dam00, .udp.src_port = htons(udp_src_port_16bit), .udp.dst_port = htons(udp_dst_port_16bit), @@ -506,7 +506,7 @@ static const struct { { "test_fragment_sam00_dam00", &test_data_1}, { "test_fragment_sam01_dam01", &test_data_2}, { "test_fragment_sam10_dam10", &test_data_3}, - { "test_fragment_sac1_sam00_m1_dam00", &test_data_4}, + { "test_fragment_sam00_m1_dam00", &test_data_4}, { "test_fragment_sam01_m1_dam01", &test_data_5}, { "test_fragment_sam10_m1_dam10", &test_data_6}, { "test_fragment_ipv6_dispatch_small", &test_data_7}, From 368cf69fde2be38afa28b565ef14006d6ed9a58f Mon Sep 17 00:00:00 2001 From: Jukka Rissanen Date: Wed, 7 Jun 2017 13:18:03 +0300 Subject: [PATCH 6/7] samples: net: Fix README.rst file documentation Various network samples contained QEMU slip setup instructions or those instructions were missing. A reference doc in doc/subsystems/networking/qemu_setup.rst file already has the setup instructions for QEMU. So add a reference to that file in samples/net/*/README.rst files and remove unnecessary slip setup instructions in relevant files. Fix various typos in readme files at the same time. Signed-off-by: Jukka Rissanen --- samples/net/coaps_client/README.rst | 2 +- samples/net/coaps_server/README.rst | 2 +- samples/net/dhcpv4_client/README.rst | 22 ++++-------------- samples/net/dns_resolve/README.rst | 28 ++++------------------- samples/net/echo_client/README.rst | 27 +++++++++------------- samples/net/echo_server/README.rst | 23 ++++++++----------- samples/net/http_client/README.rst | 17 +++++++------- samples/net/http_server/README.rst | 7 +++--- samples/net/mbedtls_dtlsclient/README.rst | 4 ++-- samples/net/mbedtls_dtlsserver/README.rst | 2 +- samples/net/telnet/README.rst | 17 ++------------ 11 files changed, 48 insertions(+), 103 deletions(-) diff --git a/samples/net/coaps_client/README.rst b/samples/net/coaps_client/README.rst index c8266c499da51..2cdd265697b57 100644 --- a/samples/net/coaps_client/README.rst +++ b/samples/net/coaps_client/README.rst @@ -10,7 +10,7 @@ This sample code shows a CoAP over DTLS client using mbedTLS on top of Zephyr. Building and Running ******************** -Follow the steps for testing :ref:`networking with Qemu `. +Follow the steps for testing :ref:`networking_with_qemu`. Run the server application at samples/net/coaps_server, with the following command: diff --git a/samples/net/coaps_server/README.rst b/samples/net/coaps_server/README.rst index 2a630150141f1..7d229253f4b53 100644 --- a/samples/net/coaps_server/README.rst +++ b/samples/net/coaps_server/README.rst @@ -10,7 +10,7 @@ This sample code shows a CoAP over DTLS server using mbedTLS on top of Zephyr. Building and Running ******************** -Follow the steps for testing :ref:`networking with Qemu `. +Follow the steps for testing :ref:`networking_with_qemu`. In the application directory type: diff --git a/samples/net/dhcpv4_client/README.rst b/samples/net/dhcpv4_client/README.rst index 0da1e5252979d..24cbef425653d 100644 --- a/samples/net/dhcpv4_client/README.rst +++ b/samples/net/dhcpv4_client/README.rst @@ -13,33 +13,19 @@ information to a serial console. Requirements ************ -- :ref:`networking with Qemu ` +- :ref:`networking_with_qemu` Building and Running ******************** -QEMU x86 -======== +Running DHCPv4 client in Linux Host +=================================== These are instructions for how to use this sample application using QEMU on a Linux host to negotiate IP address from DHCPv4 server running on Linux host. -Follow readme from: - - Run 'loop_socat' and 'loop-slip-tap' scripts from net-tools. - - https://github.com/zephyrproject-rtos/net-tools - -.. code-block:: console - - $ ./loop_socat.sh - -In another window: - -.. code-block:: console - - $ sudo ./loop-slip-tap.sh +To use QEMU for testing, follow the :ref:`networking_with_qemu` guide. Here's a sample server configuration file '/etc/dhcpd/dhcp.conf' used to configure the DHCPv4 server: diff --git a/samples/net/dns_resolve/README.rst b/samples/net/dns_resolve/README.rst index d48684434a47e..fe0d1898d7373 100644 --- a/samples/net/dns_resolve/README.rst +++ b/samples/net/dns_resolve/README.rst @@ -21,7 +21,7 @@ For more information about DNS configuration variables, see: Requirements ************ -- :ref:`networking with Qemu ` +- :ref:`networking_with_qemu` - screen terminal emulator or equivalent. @@ -82,11 +82,8 @@ DNS server ========== The dnsmasq tool may be used for testing purposes. Sample dnsmasq start -script can be found in net-tools project. - -The net-tools can be downloaded from - - https://github.com/zephyrproject-rtos/net-tools +script can be downloaded from the zephyrproject-rtos/net-tools project area: +https://github.com/zephyrproject-rtos/net-tools Open a terminal window and type: @@ -131,24 +128,7 @@ Try to launch the dnsmasq application again. QEMU x86 ======== -Open a terminal window and type: - -.. code-block:: console - - $ make - - -Run 'loop_socat.sh' and 'loop-slip-tap.sh' as shown in the net-tools README -at: - - https://github.com/zephyrproject-rtos/net-tools - - -Open a terminal where the project was build (i.e. :file:`samples/net/dns_resolve`) and type: - -.. code-block:: console - - $ make run +To use QEMU for testing, follow the :ref:`networking_with_qemu` guide. FRDM K64F diff --git a/samples/net/echo_client/README.rst b/samples/net/echo_client/README.rst index a459cce96bb9a..cd14c19c677b3 100644 --- a/samples/net/echo_client/README.rst +++ b/samples/net/echo_client/README.rst @@ -13,12 +13,17 @@ and then verify it matches the data that was sent. The source code for this sample application can be found at: :file:`samples/net/echo_client`. +Requirements +************ + +- :ref:`networking_with_qemu` + Building and Running ******************** There are multiple ways to use this application. One of the most common usage scenario is to run echo-client application inside QEMU. This is -described in :ref:`networking with QEMU `. +described in :ref:`networking_with_qemu`. There are configuration files for different boards and setups in the echo-client directory: @@ -68,25 +73,15 @@ Build echo-client sample application like this: Make can select the default configuration file based on the BOARD you've specified automatically so you might not always need to mention it. -Running echo-server Linux Host -============================== +Running echo-server in Linux Host +================================= There is one useful testing scenario that can be used with Linux host. Here echo-client is run in QEMU and echo-server is run in Linux host. -Run 'loop_socat' and 'loop-slip-tap' scripts from net-tools in Linux host. - -.. code-block:: console - - $ ./loop_socat.sh +To use QEMU for testing, follow the :ref:`networking_with_qemu` guide. -In another window: - -.. code-block:: console - - $ sudo ./loop-slip-tap.sh - -In third window: +In a terminal window: .. code-block:: console @@ -96,5 +91,5 @@ Run echo-client application in QEMU: .. code-block:: console - $ cd $ZEPHYR_BASE/samples/net/echo-client + $ cd $ZEPHYR_BASE/samples/net/echo_client $ make pristine && make qemu diff --git a/samples/net/echo_server/README.rst b/samples/net/echo_server/README.rst index 341022df71093..aabd91058470e 100644 --- a/samples/net/echo_server/README.rst +++ b/samples/net/echo_server/README.rst @@ -14,12 +14,17 @@ them back. The source code for this sample application can be found at: :file:`samples/net/echo_server`. +Requirements +************ + +- :ref:`networking_with_qemu` + Building and Running ******************** There are multiple ways to use this application. One of the most common usage scenario is to run echo-server application inside QEMU. This is -described in :ref:`networking with QEMU `. +described in :ref:`networking_with_qemu`. There are configuration files for different boards and setups in the echo-server directory: @@ -75,26 +80,16 @@ Running echo-client in Linux Host There is one useful testing scenario that can be used with Linux host. Here echo-server is run in QEMU and echo-client is run in Linux host. -Run 'loop_socat' and 'loop-slip-tap' scripts from net-tools in Linux host. - -.. code-block:: console - - $ ./loop_socat.sh - -In another window: - -.. code-block:: console - - $ sudo ./loop-slip-tap.sh +To use QEMU for testing, follow the :ref:`networking_with_qemu` guide. Run echo-server application in QEMU: .. code-block:: console - $ cd $ZEPHYR_BASE/samples/net/echo-server + $ cd $ZEPHYR_BASE/samples/net/echo_server $ make pristine && make qemu -In third window: +In a terminal window: .. code-block:: console diff --git a/samples/net/http_client/README.rst b/samples/net/http_client/README.rst index 9574cad1fdc97..dd49c09673371 100644 --- a/samples/net/http_client/README.rst +++ b/samples/net/http_client/README.rst @@ -16,16 +16,20 @@ The source code for this sample application can be found at: Requirements ************ -- QEMU +- :ref:`networking_with_qemu` - Terminal emulator software - HTTP Server - DNS server (optional) + Building and Running ******************** Open the project configuration file for your platform, for example: :file:`prj_qemu_x86.conf` is the configuration file for QEMU. + +To use QEMU for testing, follow the :ref:`networking_with_qemu` guide. + For IPv4 networks, set the following variables: .. code-block:: console @@ -69,12 +73,9 @@ port is 8000. HTTP Server =========== -A very simple HTTP server is provided in net-tool project. - -The net-tools can be downloaded from - - https://github.com/zephyrproject-rtos/net-tools - +Sample code for a very simple HTTP server can be downloaded from the +zephyrproject-rtos/net-tools project area: +https://github.com/zephyrproject-rtos/net-tools Open a terminal window and type: @@ -87,7 +88,7 @@ Open a terminal window and type: DNS setup ========= -The net-tool project provides a simple DNS resolver. You can activate +The net-tools project provides a simple DNS resolver. You can activate it like this if you want to test the DNS resolving with HTTP client. Open a terminal window and type: diff --git a/samples/net/http_server/README.rst b/samples/net/http_server/README.rst index adb5416ee0387..9cd602a4d415b 100644 --- a/samples/net/http_server/README.rst +++ b/samples/net/http_server/README.rst @@ -23,8 +23,10 @@ Requirements - Linux machine with wget and the screen terminal emulator - Either QEMU or real device like Freedom Board (FRDM-K64F) +- For QEMU see this :ref:`networking_with_qemu` - LAN for testing purposes (Ethernet) + Building and Running ******************** @@ -33,6 +35,8 @@ If you want to modify the http-server sample application, please check the configuration settings in :file:`samples/net/http_server/src/main.c` file and also in the :file:`samples/net/http_server/src/config.h` file. +To use QEMU for testing, follow the :ref:`networking_with_qemu` guide. + This sample code supports both static and dynamic (DHCPv4) IP addresses that can be defined in the project configuration file: @@ -249,9 +253,6 @@ In order to compile and run the code execute: make BOARD=qemu_x86 run -The sample code supports only one hard-coded valid URL (index.html) and -will return 404 code for other requests. - Sample Output ============= diff --git a/samples/net/mbedtls_dtlsclient/README.rst b/samples/net/mbedtls_dtlsclient/README.rst index 991e81dd65f48..dc8dc94eab4ea 100644 --- a/samples/net/mbedtls_dtlsclient/README.rst +++ b/samples/net/mbedtls_dtlsclient/README.rst @@ -10,7 +10,7 @@ This sample code shows a simple DTLS client using mbed TLS on top of Zephyr Building and running ******************** -Follow the steps for testing :ref:`networking with Qemu `. +Follow the steps for testing :ref:`networking_with_qemu`. Obtain the mbed TLS code from: @@ -50,7 +50,7 @@ From the application directory type $ make run -This will result in Qemu running with the following output: +This will result in QEMU running with the following output: .. code-block:: console diff --git a/samples/net/mbedtls_dtlsserver/README.rst b/samples/net/mbedtls_dtlsserver/README.rst index 627651f4914fc..9bd1fc6129688 100644 --- a/samples/net/mbedtls_dtlsserver/README.rst +++ b/samples/net/mbedtls_dtlsserver/README.rst @@ -10,7 +10,7 @@ This sample code shows a simple DTLS server using mbedTLS on top of Zephyr. Building and Running ******************** -Follow the steps for testing :ref:`networking with Qemu `. +Follow the steps for testing :ref:`networking_with_qemu`. In the application directory type: diff --git a/samples/net/telnet/README.rst b/samples/net/telnet/README.rst index a2ee9a57e96b3..bf5d698778363 100644 --- a/samples/net/telnet/README.rst +++ b/samples/net/telnet/README.rst @@ -15,7 +15,7 @@ using a telnet client. Requirements ************ -- :ref:`Networking with Qemu ` +- :ref:`networking_with_qemu` Building and Running @@ -27,20 +27,7 @@ QEMU x86 These are instructions for how to use this sample application using QEMU on a Linux host connected to a network with DHCP service. -To use QEMU for testing, follow the :ref:`Networking with Qemu -` guide. - -Run 'loop_socat' and 'loop-slip-tap' scripts from net-tools. - -.. code-block:: console - - $ ./loop_socat.sh - -In another window: - -.. code-block:: console - - $ sudo ./loop-slip-tap.sh +To use QEMU for testing, follow the :ref:`networking_with_qemu` guide. Run Zephyr samples/net/telnet application in QEMU: From 8af96db8d3a75600bc722d8e11c96622160d7130 Mon Sep 17 00:00:00 2001 From: Jukka Rissanen Date: Fri, 9 Jun 2017 12:40:12 +0300 Subject: [PATCH 7/7] net: tcp: Check pkt before sending RESET In certain TCP states we should not try to send RESET segment to peer. So check this and do not try to use NULL pkt to send a message. Signed-off-by: Jukka Rissanen --- subsys/net/ip/net_context.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/net/ip/net_context.c b/subsys/net/ip/net_context.c index fce03a6d6368e..32c61fe2cb308 100644 --- a/subsys/net/ip/net_context.c +++ b/subsys/net/ip/net_context.c @@ -776,7 +776,7 @@ static int send_reset(struct net_context *context, int ret; ret = net_tcp_prepare_reset(context->tcp, remote, &pkt); - if (ret) { + if (ret || !pkt) { return ret; }