barebox picotcp integration (2015.07.15)
Subsystems (3)
cover barebox picotcp integration (2015.07.15)
I have just published latest picotcp-enabled barebox. Please see my 20150715.picotcp branch in my github barebox repo
(https://github.com/frantony/barebox/tree/20150715.picotcp).
This version is based on the latest barebox-next and picotcp v1.5.0 (there is also picotcp v1.5.1, but is has no interested for barebox changes since v1.5.0).
Changes since 2015.06.14 (see http://lists.infradead.org/pipermail/barebox/2015-June/023749.html):
* drop picotcp tftp support;
make it possible to use some barebox' network applications on top of picotcp udp packet ip:
* use barebox' tftp support on top of picotcp;
* use barebox' nfs support on top of picotcp;
* use barebox' dns support on top of picotcp;
Anyway new 'picoping' command uses picotcp ICMP support because it makes possible to realize traditional *NIX 'ping' program behaviour in barebox.
* drop all unused picotcp files;
* import picotcp dhcp stuff temporary skipped we can revive it in any moment but
it's better to adapt barebox' dhcp implementation;
Here is note/todo list:
1. with picotcp we can't easely use 'tftp' command with old syntax
(no $<current network interface>.serverip anymore);
2. just now picotcp-based tftp/nfs file transfer is slower than
old realisation (partialy it is my bad, e.g. extra memory copy operation is used for code simplification); see Very Simple Benchmarks below for details;
3. rework barebox dhcp, ifup and netconsole realization for working on top of picotcp.
Very Simple Benchmarks
======================
I have sandbox barebox (192.168.1.2) and nfs- and tftp- servers on the same host (192.168.1.1). I copy 16MiB (16777216 bytes) file from server to sandbox barebox over network several times. I use time command inside sandox barebox for computing transfer time.
barebox at barebox sandbox:/ eth0.ipaddr=192.168.1.2 barebox at barebox sandbox:/ mount -t tftp 192.168.1.1 /mnt
...
barebox at barebox sandbox:/ time cp /mnt/16M .
time: 546ms
Here is typical transfer time values:
+--------+--------------+--------------+ | | U-boot | picotcp | | | stack | stack | +--------+--------------+--------------+ | | | | | tftp | 546ms | 859ms | | | | | +--------+--------------+--------------+ | | | | | nfs | 1037ms | 1393ms | | | | | +--------+--------------+--------------+
There are some rather simple possibilities to slighly improve picotcp-barebox performance:
* drop extra memory copy;
* drop extra pico_tick() calls (is_timeout() calls poller_call(), so there is no need
to call poller_call() explicitly in nfs/tftp code);
* there is an issue with sustained tftp small file copy. E.g.
barebox at barebox sandbox:/ ifconfig eth 192.168.1.2 255.255.255.0 Assigned ipv4 192.168.1.2 to device eth
barebox at barebox sandbox:/ mount -t tftp 192.168.1.1 /mnt barebox at barebox sandbox:/ while true; do time cp /mnt/1M . ; done
...
Warning: I have 122 timers
Warning: I have 121 timers
time: 48ms
Warning: I have 122 timers
Warning: I have 121 timers
time: 53ms
Warning: I have 122 timers
Warning: I have 121 timers
time: 54ms
Antony Pavlov (12):
picotcp: add barebox target support
picotcp: switch to Kbuild
net: add initial picotcp support
WIP: fs/nfs.c: convert to picotcp
WIP: fs/tftp.c: convert to picotcp
WIP: net/dns: convert to picotcp
net: picotcp: add test_picotcp command
net: picotcp: add ifconfig command
net: picotcp: add ping command
net: picotcp: add route command
sandbox_defconfig: switch to picotcp
WIP: sandbox_defconfig: enable network testing-related stuff
Makefile | 1 + arch/sandbox/configs/sandbox_defconfig | 12 ++ commands/Kconfig | 4 + fs/nfs.c | 150 +++++++++++++++++++++--- fs/tftp.c | 199 ++++++++++++++++++++++++++++---- include/net.h | 3 + include/pico_defines.h | 0 include/stdint.h | 1 + net/Kconfig | 17 +++ net/Makefile | 8 ++ net/dns.c | 101 ++++++++++++++-- net/eth.c | 71 ++++++++++++ net/net.c | 10 ++ net/picotcp.c | 20 ++++ net/picotcp/.gitignore | 1 + net/picotcp/Kconfig | 56 +++++++++ net/picotcp/Makefile | 30 +++++ net/picotcp/include/arch/pico_barebox.h | 76 ++++++++++++ net/picotcp/include/pico_config.h | 2 + net/picotcp/modules/Makefile | 8 ++ net/picotcp/stack/Makefile | 7 ++ net/picotcp_ifconfig.c | 116 +++++++++++++++++++ net/picotcp_ping.c | 85 ++++++++++++++ net/picotcp_route.c | 37 ++++++ net/picotcp_test_ipv4.c | 96 +++++++++++++++ 25 files changed, 1063 insertions(+), 48 deletions(-) create mode 100644 include/pico_defines.h create mode 100644 include/stdint.h create mode 100644 net/picotcp.c create mode 100644 net/picotcp/Kconfig create mode 100644 net/picotcp/Makefile create mode 100644 net/picotcp/include/arch/pico_barebox.h create mode 100644 net/picotcp/modules/Makefile create mode 100644 net/picotcp/stack/Makefile create mode 100644 net/picotcp_ifconfig.c create mode 100644 net/picotcp_ping.c create mode 100644 net/picotcp_route.c create mode 100644 net/picotcp_test_ipv4.c
Signature · 7 lines
2.1.4 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
RFC 1/12 picotcp: add barebox target support
--- net/picotcp/include/arch/pico_barebox.h | 76 +++++++++++++++++++++++++++++++++ net/picotcp/include/pico_config.h | 2 + 2 files changed, 78 insertions(+)
net/picotcp/include/arch/pico_barebox.h new file +76 -0
@@ -0,0 +1,76 @@ +#ifndef PICO_SUPPORT_BAREBOX +#define PICO_SUPPORT_BAREBOX + +#include <string.h> +#include <stdio.h> +#include <malloc.h> +#include <clock.h> +#include <linux/math64.h> + +/* +#define MEMORY_MEASURE +*/ +#define dbg printf + +#define stack_fill_pattern (...) do {} while(0) +#define stack_count_free_words (...) do {} while(0) +#define stack_get_free_words () (0) + +/* measure allocated memory */ +#ifdef MEMORY_MEASURE +extern uint32_t max_mem; +extern uint32_t cur_mem; + +static inline void *pico_zalloc (int x) +{ +uint32_t *ptr; +if ((cur_mem + x) > (10 *1024 )) +return NULL ; + + ptr = (uint32_t *)calloc (x +4 ,1 ); + *ptr = (uint32_t )x; + cur_mem += x; +if (cur_mem > max_mem) { + max_mem = cur_mem; + } + +return (void *)(ptr +1 ); +} + +static inline void pico_free (void *x) +{ +uint32_t *ptr = (uint32_t *)(((uint8_t *)x) -4 ); + cur_mem -= *ptr; +free (ptr); +} +#else + +#define pico_zalloc (x) calloc(x, 1) +#define pico_free (x) free(x) +#endif + +static inline uint32_t PICO_TIME (void ) +{ +uint64_t time; + + time =get_time_ns (); +do_div (time,1000000000 ); + +return (uint32_t ) time; +} + +static inline uint32_t PICO_TIME_MS (void ) +{ +uint64_t time; + + time =get_time_ns (); +do_div (time,1000000 ); + +return (uint32_t ) time; +} + +static inline void PICO_IDLE (void ) +{ +} + +#endif /* PICO_SUPPORT_BAREBOX */
net/picotcp/include/pico_config.h +2 -0
@@ -211,6 +211,8 @@ static inline uint64_t long_long_be(uint64_t le)# include "arch/pico_none.h" #elif definedGENERIC # include "arch/pico_generic_gcc.h" +#elif defined __BAREBOX__ +# include "arch/pico_barebox.h" #elif defined __KERNEL__# include "arch/pico_linux.h" /* #elif defined ... */
Signature · 7 lines
2.1.4 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
RFC 2/12 picotcp: switch to Kbuild
In reply to Antony Pavlov--- net/picotcp/.gitignore | 1 + net/picotcp/Kconfig | 34 ++++++++++++++++++++++++++++++++++ net/picotcp/Makefile | 30 ++++++++++++++++++++++++++++++ net/picotcp/modules/Makefile | 8 ++++++++ net/picotcp/stack/Makefile | 7 +++++++ 5 files changed, 80 insertions(+)
net/picotcp/.gitignore +1 -0
@@ -22,3 +22,4 @@ cscope.out *.gcov *.gcda *.gcno +*.o.cmd
net/picotcp/Kconfig new file +34 -0
@@ -0,0 +1,34 @@ +if NET_PICOTCP + +config NET_PICO_SUPPORT_IPV4 + bool + default y if NET_PICOTCP + +config NET_PICO_SUPPORT_IPFRAG + bool + default y if NET_PICO_SUPPORT_IPV4 + +config NET_PICO_SUPPORT_ICMP4 + bool + default y if NET_PICO_SUPPORT_IPV4 + +config NET_PICO_SUPPORT_UDP + bool + default y if NET_PICO_SUPPORT_IPV4 + + +config NET_PICO_SUPPORT_ETH + bool + default y if NET_PICOTCP + +config NET_PICO_SUPPORT_DEVLOOP + bool + default y if NET_PICOTCP + +comment "Misc options" + +config NET_PICO_BIGENDIAN + bool + prompt "bigendian picotcp" + +endif # NET_PICOTCP
net/picotcp/Makefile new file +30 -0
@@ -0,0 +1,30 @@ +ifeq ($(CONFIG_NET_PICO_SUPPORT_IPV4),y) +CPPFLAGS += -DPICO_SUPPORT_IPV4 +endif + +ifeq ($(CONFIG_NET_PICO_SUPPORT_ICMP4),y) +CPPFLAGS += -DPICO_SUPPORT_ICMP4 -DPICO_SUPPORT_PING +endif + +ifeq ($(CONFIG_NET_PICO_SUPPORT_IPFRAG),y) +CPPFLAGS += -DPICO_SUPPORT_IPFRAG +endif + +ifeq ($(CONFIG_NET_PICO_SUPPORT_UDP),y) +CPPFLAGS += -DPICO_SUPPORT_UDP +endif + +ifeq ($(CONFIG_NET_PICO_SUPPORT_ETH),y) +CPPFLAGS += -DPICO_SUPPORT_ETH +endif + +ifeq ($(CONFIG_NET_PICO_SUPPORT_DEVLOOP),y) +CPPFLAGS += -DPICO_SUPPORT_DEVLOOP +endif + +ifeq ($(CONFIG_NET_PICO_BIGENDIAN),y) +CPPFLAGS += -DPICO_BIGENDIAN +endif + +obj-y += modules/ +obj-y += stack/
net/picotcp/modules/Makefile new file +8 -0
@@ -0,0 +1,8 @@ +obj-$(CONFIG_NET_PICO_SUPPORT_IPV4) += pico_ipv4.o +obj-$(CONFIG_NET_PICO_SUPPORT_IPFRAG) += pico_fragments.o +obj-$(CONFIG_NET_PICO_SUPPORT_ICMP4) += pico_icmp4.o +obj-$(CONFIG_NET_PICO_SUPPORT_UDP) += pico_udp.o pico_socket_udp.o + +obj-$(CONFIG_NET_PICO_SUPPORT_ETH) += pico_arp.o +obj-$(CONFIG_NET_PICO_SUPPORT_DEVLOOP) += pico_dev_loop.o +obj-y += pico_dev_null.o
net/picotcp/stack/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +obj-y += pico_device.o +obj-y += pico_frame.o +obj-y += pico_protocol.o +obj-y += pico_socket.o +obj-y += pico_socket_multicast.o +obj-y += pico_stack.o +obj-y += pico_tree.o
Signature · 7 lines
2.1.4 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
RFC 3/12 net: add initial picotcp support
In reply to Antony PavlovThis commit adds initial picotcp support:
* build stuff (Kbuild fixes and fake stdint.h);
* "pico_adapter" code for connecting barebox ethernet interfaces to picotcp;
* picotcp start initialization and necessary poller.
--- Makefile | 1 + commands/Kconfig | 4 +++ include/net.h | 3 +++ include/pico_defines.h | 0 include/stdint.h | 1 + net/Kconfig | 17 ++++++++++++ net/Makefile | 3 +++ net/eth.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++ net/net.c | 10 +++++++ net/picotcp.c | 20 ++++++++++++++ 10 files changed, 130 insertions(+)
Makefile +1 -0
@@ -292,6 +292,7 @@ export MODVERDIR := $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/).tmp_ve # Use LINUXINCLUDE when you must reference the include/ directory. # Needed to be compatible with the O= option LINUXINCLUDE := -Iinclude -I$(srctree)/dts/include \ + -I$(srctree)/net/picotcp/include -I$(srctree)/net/picotcp/modules \ $(if $(KBUILD_SRC), -I$(srctree)/include) \ -I$(srctree)/arch/$(ARCH)/include \ -I$(objtree)/arch/$(ARCH)/include \
commands/Kconfig +4 -0
@@ -1184,6 +1184,7 @@ menu "Network" config CMD_DHCP bool select NET_DHCP + depends on NET_LEGACY prompt "dhcp" help DHCP client to obtain IP or boot params
@@ -1210,6 +1211,7 @@ config CMD_HOST config NET_CMD_IFUP bool prompt "ifup" + depends on NET_LEGACY help Bring up network interfaces based on config files.
@@ -1237,6 +1239,7 @@ config CMD_MIITOOL config CMD_PING tristate + depends on NET_LEGACY prompt "ping" help Send ICMP echo requests.
@@ -1245,6 +1248,7 @@ config CMD_PING config CMD_TFTP depends on FS_TFTP + depends on NET_LEGACY tristate prompt "tftp" help
include/net.h +3 -0
@@ -32,6 +32,8 @@struct device_d ; +#include <pico_stack.h> +struct eth_device {int active;
@@ -44,6 +46,7 @@ struct eth_device {int (*get_ethaddr) (struct eth_device *,u8 adr[6 ]);int (*set_ethaddr) (struct eth_device *,const unsigned char *adr); +struct pico_device *picodev;struct eth_device *next;void *priv;
include/pico_defines.h new file +0 -0
include/stdint.h new file +1 -0
@@ -0,0 +1 @@ +/* fake stdint.h for picotcp */
net/Kconfig +17 -0
@@ -3,6 +3,18 @@ menuconfig NET if NET +choice + prompt "network stack implementation" + +config NET_LEGACY + bool "legacy U-Boot network stack" + +config NET_PICOTCP + bool "picotcp network stack" + select POLLER + +endchoice + config NET_NFS bool prompt "nfs support"
@@ -10,6 +22,7 @@ config NET_NFS config NET_NETCONSOLE bool depends on !CONSOLE_NONE + depends on NET_LEGACY prompt "network console support" help This option adds support for a simple udp based network console.
@@ -20,10 +33,14 @@ config NET_RESOLV config NET_IFUP default y + depends on NET_LEGACY bool config NET_DHCP bool + depends on NET_LEGACY prompt "dhcp support" +source "net/picotcp/Kconfig" + endif
net/Makefile +3 -0
@@ -7,3 +7,6 @@ obj-$(CONFIG_CMD_PING) += ping.o obj-$(CONFIG_NET_RESOLV)+= dns.o obj-$(CONFIG_NET_NETCONSOLE) += netconsole.o obj-$(CONFIG_NET_IFUP) += ifup.o + +obj-$(CONFIG_NET_PICOTCP) += picotcp/ +obj-$(CONFIG_NET_PICOTCP) += picotcp.o
net/eth.c +71 -0
83 lines not on this page · raw message
net/net.c +10 -0
@@ -540,12 +540,22 @@ bad:return 0 ; } +#include <pico_stack.h> +int net_receive (struct eth_device *edev,unsigned char *pkt,int len) {struct ethernet *et = (struct ethernet *)pkt;int et_protlen =ntohs (et->et_protlen);int ret; +if (IS_ENABLED (CONFIG_NET_PICOTCP )) { +pico_stack_recv (edev->picodev, pkt, len); + +led_trigger_network (LED_TRIGGER_NET_RX ); + +return 0 ; + } +led_trigger_network (LED_TRIGGER_NET_RX );if (len <ETHER_HDR_SIZE ) {
net/picotcp.c new file +20 -0
@@ -0,0 +1,20 @@ +#include <init.h> +#include <poller.h> +#include <pico_stack.h> + +static struct poller_struct picotcp_poller; + +static void picotcp_poller_cb (struct poller_struct *poller) +{ +pico_stack_tick (); +} + +static int picotcp_net_init (void ) +{ +pico_stack_init (); + + picotcp_poller.func = picotcp_poller_cb; + +return poller_register (&picotcp_poller); +} +postcore_initcall (picotcp_net_init);
Signature · 7 lines
2.1.4 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
RFC 4/12 WIP: fs/nfs.c: convert to picotcp
In reply to Antony Pavlov--- fs/nfs.c | 150 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 133 insertions(+), 17 deletions(-)
fs/nfs.c +133 -17
@@ -37,6 +37,10 @@#include <byteorder.h> #include <globalvar.h> +#include <pico_socket.h> +#include <pico_ipv4.h> +#include <poller.h> +#include "parseopt.h" #define SUNRPC_PORT 111
@@ -131,9 +135,14 @@ struct rpc_reply {struct nfs_priv {struct net_connection *con;IPaddr_t server; + +struct pico_socket *sock; +union pico_address remote_address; +uint8_t *pkt; +char *path; -unsigned short mount_port; -unsigned short nfs_port; +uint16_t mount_port; +uint16_t nfs_port;uint32_t rpc_id;uint32_t rootfh_len;char rootfh[NFS3_FHSIZE ];
@@ -383,10 +392,16 @@ static int rpc_req(struct nfs_priv *npriv, int rpc_prog, int rpc_proc,struct rpc_call pkt;unsigned short dport;int ret; -unsigned char *payload =net_udp_get_payload (npriv->con); +unsigned char *payload;int nfserr;int tries =0 ; +if (IS_ENABLED (CONFIG_NET_LEGACY )) { + payload =net_udp_get_payload (npriv->con); + }else if (IS_ENABLED (CONFIG_NET_PICOTCP )) { + payload = npriv->pkt; + } + npriv->rpc_id++; pkt.id =hton32 (npriv->rpc_id);
@@ -398,7 +413,11 @@ static int rpc_req(struct nfs_priv *npriv, int rpc_prog, int rpc_proc,debug ("%s: prog: %d, proc: %d\n" , __func__, rpc_prog, rpc_proc);if (rpc_prog ==PROG_PORTMAP ) { - dport =SUNRPC_PORT ; +if (IS_ENABLED (CONFIG_NET_LEGACY )) { + dport =SUNRPC_PORT ; + }else if (IS_ENABLED (CONFIG_NET_PICOTCP )) { + dport =hton16 (SUNRPC_PORT ); + } pkt.vers =hton32 (2 ); }else if (rpc_prog ==PROG_MOUNT ) { dport = npriv->mount_port;
@@ -408,14 +427,25 @@ static int rpc_req(struct nfs_priv *npriv, int rpc_prog, int rpc_proc, pkt.vers =hton32 (3 ); } +/* FIXME: picotcp can skip extra copy here */ memcpy (payload, &pkt,sizeof (pkt));memcpy (payload +sizeof (pkt), data, datalen *sizeof (uint32_t )); - npriv->con->udp->uh_dport =hton16 (dport); +if (IS_ENABLED (CONFIG_NET_LEGACY )) { + npriv->con->udp->uh_dport =hton16 (dport); + } again: - ret =net_udp_send (npriv->con, + +if (IS_ENABLED (CONFIG_NET_LEGACY )) { + ret =net_udp_send (npriv->con,sizeof (pkt) + datalen *sizeof (uint32_t )); + }else if (IS_ENABLED (CONFIG_NET_PICOTCP )) { +/* FIXME: picotcp ret code meaning is different */ + ret =pico_socket_sendto (npriv->sock, npriv->pkt, +sizeof (pkt) + datalen *sizeof (uint32_t ), + &npriv->remote_address, dport); + } nfs_timer_start =get_time_ns ();
@@ -427,7 +457,13 @@ again: ret = -EINTR ;break ; } -net_poll (); + +if (IS_ENABLED (CONFIG_NET_LEGACY )) { +net_poll (); + }else if (IS_ENABLED (CONFIG_NET_PICOTCP )) { +/* do we really need it? is_timeout() can do this work for us. */ +poller_call (); + }if (is_timeout (nfs_timer_start,NFS_TIMEOUT )) { tries++;
@@ -1324,6 +1360,48 @@ static void nfs_set_rootarg(struct nfs_priv *npriv, struct fs_device_d *fsdev)free (str); } +static void nfs_cb (uint16_t ev,struct pico_socket *sock) +{ +struct nfs_priv *npriv = sock->priv; +char *pkt = npriv->pkt; +int len; +union pico_address ep; +uint16_t remote_port; + +if (ev ==PICO_SOCK_EV_ERR ) { +printf (" >>>>>> PICO_SOCK_EV_ERR <<<<<<< \n" ); +return ; + } + +/* FIXME: 2000 */ + len =pico_socket_recvfrom (sock, pkt,2000 , &ep, &remote_port); + + nfs_state =STATE_DONE ; + nfs_packet = pkt; + nfs_len = len; +} + +static struct pico_socket *nfs_socket_open (uint16_t localport) +{ +struct pico_socket *sock; +union pico_address local_address; + + sock =pico_socket_open (PICO_PROTO_IPV4 ,PICO_PROTO_UDP , nfs_cb); +if (!sock) +return NULL ; + + localport =short_be (localport); + +/* FIXME: use local_address == PICO_IPV4_INADDR_ANY */ +memset (&local_address,0 ,sizeof (union pico_address )); +if (pico_socket_bind (sock, &local_address, &localport) <0 ) { +pico_socket_close (sock); +return NULL ; + } + +return sock; +} +static int nfs_probe (struct device_d *dev) {struct fs_device_d *fsdev =dev_to_fs_device (dev);
@@ -1346,19 +1424,38 @@ static int nfs_probe(struct device_d *dev) npriv->path =xstrdup (path +1 ); - npriv->server =resolv (tmp); +if (IS_ENABLED (CONFIG_NET_LEGACY )) { + npriv->server =resolv (tmp); + }else if (IS_ENABLED (CONFIG_NET_PICOTCP )) { +/* FIXME: check corectness */ + npriv->remote_address.ip4.addr =resolv (tmp); + }debug ("nfs: server: %s path: %s\n" , tmp, npriv->path); - npriv->con =net_udp_new (npriv->server,0 , nfs_handler, npriv); -if (IS_ERR (npriv->con)) { - ret =PTR_ERR (npriv->con); - goto err1; +if (IS_ENABLED (CONFIG_NET_LEGACY )) { + npriv->con =net_udp_new (npriv->server,0 , nfs_handler, npriv); +if (IS_ERR (npriv->con)) { + ret =PTR_ERR (npriv->con); + goto err1; + } + +/* Need a priviliged source port */ +net_udp_bind (npriv->con,1000 ); + }else if (IS_ENABLED (CONFIG_NET_PICOTCP )) { +/* FIXME: 2048 */ + npriv->pkt =xzalloc (2048 ); + +/* Need a priviliged source port */ + npriv->sock =nfs_socket_open (1000 ); +if (!npriv->sock) { + ret =-1 ; + goto err1; + } + + npriv->sock->priv = npriv; } -/* Need a priviliged source port */ -net_udp_bind (npriv->con,1000 ); -parseopt_hu (fsdev->options,"mountport" , &npriv->mount_port);if (!npriv->mount_port) { ret =rpc_lookup_req (npriv,PROG_MOUNT ,3 );
@@ -1381,6 +1478,11 @@ static int nfs_probe(struct device_d *dev) }debug ("nfs port: %d\n" , npriv->nfs_port); +if (IS_ENABLED (CONFIG_NET_PICOTCP )) { + npriv->mount_port =hton16 (npriv->mount_port); + npriv->nfs_port =hton16 (npriv->nfs_port); + } + ret =nfs_mount_req (npriv);if (ret) {printf ("mounting failed with %d\n" , ret);
@@ -1394,8 +1496,16 @@ static int nfs_probe(struct device_d *dev)return 0 ; err2: -net_unregister (npriv->con); +if (IS_ENABLED (CONFIG_NET_LEGACY )) { +net_unregister (npriv->con); + }else if (IS_ENABLED (CONFIG_NET_PICOTCP )) { +pico_socket_close (npriv->sock); + } + err1: +if (IS_ENABLED (CONFIG_NET_PICOTCP )) { +free (npriv->pkt); + }free (npriv->path); err:free (tmp);
@@ -1410,7 +1520,13 @@ static void nfs_remove(struct device_d *dev)nfs_umount_req (npriv); -net_unregister (npriv->con); +if (IS_ENABLED (CONFIG_NET_LEGACY )) { +net_unregister (npriv->con); + }else if (IS_ENABLED (CONFIG_NET_PICOTCP )) { +pico_socket_close (npriv->sock); +free (npriv->pkt); + } +free (npriv->path);free (npriv); }
Signature · 7 lines
2.1.4 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [RFC 04/12] WIP: fs/nfs.c: convert to picotcp
Hi Antony,
Quoted 35 lines · Antony Pavlov
Signed-off-by Antony Pavlov <[email protected]>--- fs/nfs.c | 150 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 133 insertions(+), 17 deletions(-)fs/nfs.c +18
-5@@ -1346,19 +1424,38 @@ static int nfs_probe(struct device_d *dev) npriv->path =xstrdup (path +1 ); - npriv->server =resolv (tmp); +if (IS_ENABLED (CONFIG_NET_LEGACY )) { + npriv->server =resolv (tmp); + }else if (IS_ENABLED (CONFIG_NET_PICOTCP )) { +/* FIXME: check corectness */ + npriv->remote_address.ip4.addr =resolv (tmp); + }debug ("nfs: server: %s path: %s\n" , tmp, npriv->path); - npriv->con =net_udp_new (npriv->server,0 , nfs_handler, npriv); -if (IS_ERR (npriv->con)) { - ret =PTR_ERR (npriv->con); - goto err1; +if (IS_ENABLED (CONFIG_NET_LEGACY )) { + npriv->con =net_udp_new (npriv->server,0 , nfs_handler, npriv); +if (IS_ERR (npriv->con)) { + ret =PTR_ERR (npriv->con); + goto err1; + } + +/* Need a priviliged source port */ +net_udp_bind (npriv->con,1000 ); + }else if (IS_ENABLED (CONFIG_NET_PICOTCP )) { +/* FIXME: 2048 */ + npriv->pkt =xzalloc (2048 );
fs/nfs.c static int nfs_probe(struct device_d *dev) · line 1457
Quoted 10 lines
fs/nfs.c +9
-0+ +/* Need a priviliged source port */ + npriv->sock =nfs_socket_open (1000 ); +if (!npriv->sock) { + ret =-1 ; + goto err1; + } + + npriv->sock->priv = npriv; }
The different network stacks should be transparent to the users. Instead of implementing them in tftp/nfs/... I would expect the abstraction in the current network functions, something like:
struct net_connection *net_udp_new(IPaddr_t dest, uint16_t dport,
rx_handler_f *handler, void *ctx)
{
struct net_connection *con = net_new(dest, handler, ctx);
if (IS_ERR(con))
return con;
con->proto = IPPROTO_UDP;
con->udp->uh_dport = htons(dport);
con->udp->uh_sport = htons(net_udp_new_localport());
con->ip->protocol = IPPROTO_UDP;
if (IS_ENABLED(CONFIG_NET_PICOTCP)) {
con->sock = pico_socket_open(PICO_PROTO_IPV4, PICO_PROTO_UDP, handler);
}
return con;
}static inline int net_udp_bind(struct net_connection *con, int sport)
{
if (IS_ENABLED(CONFIG_NET_PICOTCP)) {
memset(&local_address, 0, sizeof(union pico_address));
pico_socket_bind(con->sock, &local_address, &sport);
} else {
con->udp->uh_sport = ntohs(sport);
}
return 0;
}int net_udp_send(struct net_connection *con, int len)
{
if (IS_ENABLED(CONFIG_NET_PICOTCP)) {
return pico_socket_sendto(con->sock, npriv->pkt,
sizeof(pkt) + datalen * sizeof(uint32_t),
con->ip->daddr, con->udp->uh_dport);
}
con->udp->uh_ulen = htons(len + 8);
con->udp->uh_sum = 0;
return net_ip_send(con, sizeof(struct udphdr) + len);
}The APIs between current barebox implementation and picotcp probably do not match exactly. Where the APIs don't match we can change the existing barebox API to what picotcp expects.
With that the remaining pieces like DHCP, netconsole and DNS would work without additional effort.
Sascha
Signature · 9 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [RFC 04/12] WIP: fs/nfs.c: convert to picotcp
Quoted 44 lines · On Thu, 16 Jul 2015 21:51:50 +0200 Sascha Hauer <[email protected]> wrote:
Hi Antony,
Quoted 41 lines · Antony Pavlov
Signed-off-by Antony Pavlov <[email protected]>--- fs/nfs.c | 150 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 133 insertions(+), 17 deletions(-)fs/nfs.c +24
-5@@ -1346,19 +1424,38 @@ static int nfs_probe(struct device_d *dev) npriv->path =xstrdup (path +1 ); - npriv->server =resolv (tmp); +if (IS_ENABLED (CONFIG_NET_LEGACY )) { + npriv->server =resolv (tmp); + }else if (IS_ENABLED (CONFIG_NET_PICOTCP )) { +/* FIXME: check corectness */ + npriv->remote_address.ip4.addr =resolv (tmp); + }debug ("nfs: server: %s path: %s\n" , tmp, npriv->path); - npriv->con =net_udp_new (npriv->server,0 , nfs_handler, npriv); -if (IS_ERR (npriv->con)) { - ret =PTR_ERR (npriv->con); - goto err1; +if (IS_ENABLED (CONFIG_NET_LEGACY )) { + npriv->con =net_udp_new (npriv->server,0 , nfs_handler, npriv); +if (IS_ERR (npriv->con)) { + ret =PTR_ERR (npriv->con); + goto err1; + } + +/* Need a priviliged source port */ +net_udp_bind (npriv->con,1000 ); + }else if (IS_ENABLED (CONFIG_NET_PICOTCP )) { +/* FIXME: 2048 */ + npriv->pkt =xzalloc (2048 ); + +/* Need a priviliged source port */ + npriv->sock =nfs_socket_open (1000 ); +if (!npriv->sock) { + ret =-1 ; + goto err1;
Quoted 8 lines
fs/nfs.c static int nfs_probe(struct device_d *dev) · line 1457
Quoted 4 lines
fs/nfs.c +3
-0+ } + + npriv->sock->priv = npriv; }The different network stacks should be transparent to the users. Instead of implementing them in tftp/nfs/... I would expect the abstraction in the current network functions, something like:
It's near impossible with current network stack implementation.
We have to drop direct access to net_connection private fields from application code; e.g. direct access to packet UDP fields in tftp code:
priv->tftp_con->udp->uh_dport = uh_sport;
My patch series was not intended to change legacy network code in any way. On the contrary it intentionaly keeps original code "as is".
This approach demonstrates in practice picotcp and legacy network stack differences, so future work on integration is much more evident.
I can start next round of picotcp integration with removing direct access to net_connection private fields from application code.
Quoted 45 lines
struct
net_connection*net_udp_new(IPaddr_t dest,uint16_tdport,
rx_handler_f*handler, void *ctx){ struct net_connection *con = net_new(dest, handler, ctx); if (IS_ERR(con)) return con; con->proto = IPPROTO_UDP; con->udp->uh_dport = htons(dport); con->udp->uh_sport = htons(net_udp_new_localport()); con->ip->protocol = IPPROTO_UDP; if (IS_ENABLED(CONFIG_NET_PICOTCP)) { con->sock = pico_socket_open(PICO_PROTO_IPV4, PICO_PROTO_UDP, handler); } return con; }static inline int
net_udp_bind(struct net_connection *con, int sport){ if (IS_ENABLED(CONFIG_NET_PICOTCP)) { memset(&local_address, 0, sizeof(union pico_address)); pico_socket_bind(con->sock, &local_address, &sport); } else { con->udp->uh_sport = ntohs(sport); } return 0; }int
net_udp_send(struct net_connection *con, int len){ if (IS_ENABLED(CONFIG_NET_PICOTCP)) { return pico_socket_sendto(con->sock, npriv->pkt, sizeof(pkt) + datalen * sizeof(uint32_t), con->ip->daddr, con->udp->uh_dport); } con->udp->uh_ulen = htons(len + 8); con->udp->uh_sum = 0; return net_ip_send(con, sizeof(struct udphdr) + len); }
Quoted 3 lines
The APIs between current barebox implementation and picotcp probably do not match exactly. Where the APIs don't match we can change the existing barebox API to what picotcp expects.
Yeah, picotcp uses more advanced API so we have to "pull up" existing API.
Quoted 3 lines
With that the remaining pieces like DHCP, netconsole and DNS would work without additional effort.
--
Best regards,
Antony Pavlov
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
RFC 5/12 WIP: fs/tftp.c: convert to picotcp
In reply to Antony Pavlov--- fs/tftp.c | 199 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 175 insertions(+), 24 deletions(-)
fs/tftp.c +175 -24
@@ -33,6 +33,10 @@#include <kfifo.h> #include <linux/sizes.h> +#include <pico_socket.h> +#include <pico_ipv4.h> +#include <poller.h> +#define TFTP_PORT 69/* Well known TFTP port number */ /* Seconds to wait before remote server is allowed to resend a lost packet */
@@ -84,10 +88,17 @@ struct file_priv {void *buf;int blocksize;int block_requested; + +struct pico_socket *sock; +union pico_address remote_address; +uint16_t remote_port; +uint8_t *pkt; };struct tftp_priv {IPaddr_t server; + +union pico_address pserver; };static int tftp_create (struct device_d *dev,const char *pathname,mode_t mode)
@@ -120,9 +131,15 @@ static int tftp_send(struct file_priv *priv)unsigned char *xp;int len =0 ;uint16_t *s; -unsigned char *pkt =net_udp_get_payload (priv->tftp_con); +uint8_t *pkt;int ret; +if (IS_ENABLED (CONFIG_NET_LEGACY )) { + pkt =net_udp_get_payload (priv->tftp_con); + }else if (IS_ENABLED (CONFIG_NET_PICOTCP )) { + pkt = priv->pkt; + } +debug ("%s: state %d\n" , __func__, priv->state);switch (priv->state) {
@@ -169,7 +186,13 @@ static int tftp_send(struct file_priv *priv)break ; } - ret =net_udp_send (priv->tftp_con, len); +if (IS_ENABLED (CONFIG_NET_LEGACY )) { + ret =net_udp_send (priv->tftp_con, len); + }else if (IS_ENABLED (CONFIG_NET_PICOTCP )) { +/* FIXME: convert PICOTCP error code to barebox error code */ + ret =pico_socket_sendto (priv->sock, priv->pkt, len, + &priv->remote_address, priv->remote_port); + }return ret; }
@@ -177,9 +200,15 @@ static int tftp_send(struct file_priv *priv)static int tftp_send_write (struct file_priv *priv,void *buf,int len) {uint16_t *s; -unsigned char *pkt =net_udp_get_payload (priv->tftp_con); +uint8_t *pkt;int ret; +if (IS_ENABLED (CONFIG_NET_LEGACY )) { + pkt =net_udp_get_payload (priv->tftp_con); + }else if (IS_ENABLED (CONFIG_NET_PICOTCP )) { + pkt = priv->pkt; + } + s = (uint16_t *)pkt; *s++ =htons (TFTP_DATA ); *s++ =htons (priv->block);
@@ -188,7 +217,14 @@ static int tftp_send_write(struct file_priv *priv, void *buf, int len) priv->state =STATE_LAST ; len +=4 ; - ret =net_udp_send (priv->tftp_con, len); +if (IS_ENABLED (CONFIG_NET_LEGACY )) { + ret =net_udp_send (priv->tftp_con, len); + }else if (IS_ENABLED (CONFIG_NET_PICOTCP )) { +/* FIXME: convert PICOTCP error code to barebox error code */ + ret =pico_socket_sendto (priv->sock, priv->pkt, len, + &priv->remote_address, priv->remote_port); + } + priv->last_block = priv->block; priv->state =STATE_WAITACK ;
@@ -216,7 +252,12 @@ static int tftp_poll(struct file_priv *priv)return -ETIMEDOUT ; } -net_poll (); +if (IS_ENABLED (CONFIG_NET_LEGACY )) { +net_poll (); + }else if (IS_ENABLED (CONFIG_NET_PICOTCP )) { +/* despite of is_timeout() can call poller_call() by itself ... */ +poller_call (); + }return 0 ; }
@@ -293,14 +334,24 @@ static void tftp_recv(struct file_priv *priv, priv->state =STATE_DONE ;break ; } - priv->tftp_con->udp->uh_dport = uh_sport; + +if (IS_ENABLED (CONFIG_NET_LEGACY )) { + priv->tftp_con->udp->uh_dport = uh_sport; + }else if (IS_ENABLED (CONFIG_NET_PICOTCP )) { + priv->remote_port = uh_sport; + } + priv->state =STATE_WDATA ;break ;case TFTP_OACK :tftp_parse_oack (priv, pkt, len); - priv->server_port =ntohs (uh_sport); - priv->tftp_con->udp->uh_dport = uh_sport; +if (IS_ENABLED (CONFIG_NET_LEGACY )) { + priv->server_port =ntohs (uh_sport); + priv->tftp_con->udp->uh_dport = uh_sport; + }else if (IS_ENABLED (CONFIG_NET_PICOTCP )) { + priv->remote_port = uh_sport; + }if (priv->push) {/* send first block */
@@ -321,8 +372,12 @@ static void tftp_recv(struct file_priv *priv,if (priv->state ==STATE_RRQ || priv->state ==STATE_OACK ) {/* first block received */ priv->state =STATE_RDATA ; - priv->tftp_con->udp->uh_dport = uh_sport; - priv->server_port =ntohs (uh_sport); +if (IS_ENABLED (CONFIG_NET_LEGACY )) { + priv->tftp_con->udp->uh_dport = uh_sport; + priv->server_port =ntohs (uh_sport); + }else if (IS_ENABLED (CONFIG_NET_PICOTCP )) { + priv->remote_port = uh_sport; + } priv->last_block =0 ;if (priv->block !=1 ) {/* Assertion */
@@ -381,6 +436,53 @@ static void tftp_handler(void *ctx, char *packet, unsigned len)tftp_recv (priv, pkt,net_eth_to_udplen (packet), udp->uh_sport); } +static void tftp_cb (uint16_t ev,struct pico_socket *sock) +{ +struct file_priv *priv = sock->priv; + +union pico_address ep; +uint16_t remote_port; +uint8_t *pkt = priv->pkt; +int len; + +if (ev ==PICO_SOCK_EV_ERR ) { +printf (" >>>>>> PICO_SOCK_EV_ERR <<<<<<< \n" ); +return ; + } + +/* +* we have to receive: +* opcode (2 bytes) +* block# (2 bytes) +* data (blocksize bytes) +*/ + len =pico_socket_recvfrom (sock, pkt, priv->blocksize +4 , + &ep, &remote_port); + +tftp_recv (priv, pkt, len, remote_port); +} + +static struct pico_socket *tftp_socket_open (uint16_t localport) +{ +struct pico_socket *sock; +union pico_address local_address; + + sock =pico_socket_open (PICO_PROTO_IPV4 ,PICO_PROTO_UDP , tftp_cb); +if (!sock) +return NULL ; + + localport =short_be (localport); + +/* FIXME: use local_address == PICO_IPV4_INADDR_ANY */ +memset (&local_address,0 ,sizeof (union pico_address )); +if (pico_socket_bind (sock, &local_address, &localport) <0 ) { +pico_socket_close (sock); +return NULL ; + } + +return sock; +} +static struct file_priv *tftp_do_open (struct device_d *dev,int accmode,const char *filename) {
@@ -426,17 +528,39 @@ static struct file_priv *tftp_do_open(struct device_d *dev, goto out; } - priv->tftp_con =net_udp_new (tpriv->server,TFTP_PORT , tftp_handler, - priv); -if (IS_ERR (priv->tftp_con)) { - ret =PTR_ERR (priv->tftp_con); - goto out1; +if (IS_ENABLED (CONFIG_NET_LEGACY )) { + priv->tftp_con =net_udp_new (tpriv->server,TFTP_PORT , tftp_handler, + priv); +if (IS_ERR (priv->tftp_con)) { + ret =PTR_ERR (priv->tftp_con); + goto out1; + } + + ret =tftp_send (priv); +if (ret) + goto out2; + }else if (IS_ENABLED (CONFIG_NET_PICOTCP )) { + priv->sock =tftp_socket_open (0 ); +if (!priv->sock) { + ret =-1 ; + goto out1; + } + + priv->sock->priv = priv; + +/* FIXME: add free */ + priv->pkt =xzalloc (2048 ); + priv->remote_address = tpriv->pserver; + priv->remote_port =short_be (TFTP_PORT ); + +/* FIXME: convert PICOTCP error code to barebox error code */ + ret =tftp_send (priv); +if (ret ==-1 ) + goto out2; + +poller_call (); } - ret =tftp_send (priv); -if (ret) - goto out2; -tftp_timer_reset (priv); while (priv->state != STATE_RDATA && priv->state != STATE_DONE &&
@@ -457,7 +581,11 @@ static struct file_priv *tftp_do_open(struct device_d *dev,return priv; out2: -net_unregister (priv->tftp_con); +if (IS_ENABLED (CONFIG_NET_LEGACY )) { +net_unregister (priv->tftp_con); + }else if (IS_ENABLED (CONFIG_NET_PICOTCP )) { +pico_socket_close (priv->sock); + } out1:kfifo_free (priv->fifo); out:
@@ -503,14 +631,32 @@ static int tftp_do_close(struct file_priv *priv) }if (!priv->push && priv->state !=STATE_DONE ) { -uint16_t *pkt =net_udp_get_payload (priv->tftp_con); +uint16_t *pkt; + +if (IS_ENABLED (CONFIG_NET_LEGACY )) { + pkt =net_udp_get_payload (priv->tftp_con); + }else if (IS_ENABLED (CONFIG_NET_PICOTCP )) { + pkt = (uint16_t *)priv->pkt; + } + *pkt++ =htons (TFTP_ERROR ); *pkt++ =0 ; *pkt++ =0 ; -net_udp_send (priv->tftp_con,6 ); + +if (IS_ENABLED (CONFIG_NET_LEGACY )) { +net_udp_send (priv->tftp_con,6 ); + }else if (IS_ENABLED (CONFIG_NET_PICOTCP )) { +pico_socket_sendto (priv->sock, priv->pkt,6 , + &priv->remote_address, priv->remote_port); + } + } + +if (IS_ENABLED (CONFIG_NET_LEGACY )) { +net_unregister (priv->tftp_con); + }else if (IS_ENABLED (CONFIG_NET_PICOTCP )) { +pico_socket_close (priv->sock); } -net_unregister (priv->tftp_con);kfifo_free (priv->fifo);free (priv->buf);free (priv);
@@ -630,7 +776,12 @@ static int tftp_probe(struct device_d *dev) dev->priv = priv; - priv->server =resolv (fsdev->backingstore); +if (IS_ENABLED (CONFIG_NET_LEGACY )) { + priv->server =resolv (fsdev->backingstore); + }else if (IS_ENABLED (CONFIG_NET_PICOTCP )) { +/* FIXME: check corectness */ + priv->pserver.ip4.addr =resolv (fsdev->backingstore); + }return 0 ; }
Signature · 7 lines
2.1.4 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
RFC 6/12 WIP: net/dns: convert to picotcp
In reply to Antony Pavlov--- net/dns.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 94 insertions(+), 7 deletions(-)
net/dns.c +94 -7
@@ -29,6 +29,10 @@#include <environment.h> #include <linux/err.h> +#include <pico_socket.h> +#include <pico_ipv4.h> +#include <poller.h> +#define DNS_PORT 53/* http://en.wikipedia.org/wiki/List_of_DNS_record_types */
@@ -59,15 +63,24 @@ static uint64_t dns_timer_start;static int dns_state;static IPaddr_t dns_ip; +static struct pico_socket *sock; +static uint8_t *pkt; +static int dns_send (char *name) {int ret;struct header *header;enum dns_query_type qtype =DNS_A_RECORD ; -unsigned char *packet =net_udp_get_payload (dns_con); +unsigned char *packet;unsigned char *p, *s, *fullname, *dotptr;const unsigned char *domain; +if (IS_ENABLED (CONFIG_NET_LEGACY )) { + packet =net_udp_get_payload (dns_con); + }else if (IS_ENABLED (CONFIG_NET_PICOTCP )) { + packet = pkt; + } +/* Prepare DNS packet header */ header = (struct header *)packet; header->tid =1 ;
@@ -109,7 +122,16 @@ static int dns_send(char *name) *p++ =0 ; *p++ =1 ;/* Class: inet, 0x0001 */ - ret =net_udp_send (dns_con, p - packet); +if (IS_ENABLED (CONFIG_NET_LEGACY )) { + ret =net_udp_send (dns_con, p - packet); + }else if (IS_ENABLED (CONFIG_NET_PICOTCP )) { +uint16_t remote_port; + + remote_port =htons (DNS_PORT ); +pico_socket_send (sock, pkt, p - packet); +/* FIXME */ + ret =0 ; + }free (fullname);
@@ -199,6 +221,44 @@ static void dns_handler(void *ctx, char *packet, unsigned len) net_eth_to_udplen(packet)); } +static void dns_cb (uint16_t ev,struct pico_socket *sock) +{ +union pico_address ep; +uint16_t remote_port; +int len; + +if (ev ==PICO_SOCK_EV_ERR ) { +printf (" >>>>>> PICO_SOCK_EV_ERR <<<<<<< \n" ); +return ; + } + +/* FIXME: 1500 */ + len =pico_socket_recvfrom (sock, pkt,1500 , &ep, &remote_port); + +dns_recv ((struct header *)pkt, len); +} + +static struct pico_socket *dns_socket_open (uint16_t localport) +{ +struct pico_socket *sock; +union pico_address local_address; + + sock =pico_socket_open (PICO_PROTO_IPV4 ,PICO_PROTO_UDP , dns_cb); +if (!sock) +return NULL ; + + localport =htons (localport); + +/* FIXME: use local_address == PICO_IPV4_INADDR_ANY */ +memset (&local_address,0 ,sizeof (union pico_address )); +if (pico_socket_bind (sock, &local_address, &localport) <0 ) { +pico_socket_close (sock); +return NULL ; + } + +return sock; +} +IPaddr_t resolv (char *host) {IPaddr_t ip;
@@ -223,9 +283,26 @@ IPaddr_t resolv(char *host)debug ("resolving host %s via nameserver %s\n" , host,ip_to_string (ip)); - dns_con =net_udp_new (ip,DNS_PORT , dns_handler,NULL ); -if (IS_ERR (dns_con)) -return PTR_ERR (dns_con); +if (IS_ENABLED (CONFIG_NET_LEGACY )) { + dns_con =net_udp_new (ip,DNS_PORT , dns_handler,NULL ); +if (IS_ERR (dns_con)) +return PTR_ERR (dns_con); + }else if (IS_ENABLED (CONFIG_NET_PICOTCP )) { +static union pico_address pico_dns_ip; + +pico_string_to_ipv4 (ns, &pico_dns_ip.ip4.addr); + + sock =dns_socket_open (0 ); +if (!sock) +return 0 ; + +if (pico_socket_connect (sock, &pico_dns_ip,htons (DNS_PORT )) <0 ) +return 0 ; + +/* FIXME: 2048 */ + pkt =xzalloc (2048 ); + } + dns_timer_start =get_time_ns ();dns_send (host);
@@ -233,7 +310,13 @@ IPaddr_t resolv(char *host)if (ctrlc ()) {break ; } -net_poll (); + +if (IS_ENABLED (CONFIG_NET_LEGACY )) { +net_poll (); + }else if (IS_ENABLED (CONFIG_NET_PICOTCP )) { +poller_call (); + } +if (is_timeout (dns_timer_start,SECOND )) { dns_timer_start =get_time_ns ();printf ("T " );
@@ -241,7 +324,11 @@ IPaddr_t resolv(char *host) } } -net_unregister (dns_con); +if (IS_ENABLED (CONFIG_NET_LEGACY )) { +net_unregister (dns_con); + }else if (IS_ENABLED (CONFIG_NET_PICOTCP )) { +free (pkt); + }return dns_ip; }
Signature · 7 lines
2.1.4 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
RFC 7/12 net: picotcp: add test_picotcp command
In reply to Antony PavlovSee original test_ipv4() from picotcp.git/test/unit/unit_ipv4.c.
--- net/Makefile | 2 ++ net/picotcp/Kconfig | 7 ++++ net/picotcp_test_ipv4.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+)
net/Makefile +2 -0
@@ -10,3 +10,5 @@ obj-$(CONFIG_NET_IFUP) += ifup.o obj-$(CONFIG_NET_PICOTCP) += picotcp/ obj-$(CONFIG_NET_PICOTCP) += picotcp.o + +obj-$(CONFIG_CMD_PICOTCP_TEST_IPV4) += picotcp_test_ipv4.o
net/picotcp/Kconfig +7 -0
@@ -31,4 +31,11 @@ config NET_PICO_BIGENDIAN bool prompt "bigendian picotcp" +comment "Commands" + +config CMD_PICOTCP_TEST_IPV4 + bool + depends on NET_PICO_SUPPORT_IPV4 + prompt "test_picotcp command" + endif # NET_PICOTCP
net/picotcp_test_ipv4.c new file +96 -0
96 lines not on this page · raw message
Signature · 7 lines
2.1.4 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
RFC 8/12 net: picotcp: add ifconfig command
In reply to Antony Pavlov--- net/Makefile | 1 + net/picotcp/Kconfig | 5 +++ net/picotcp_ifconfig.c | 116 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 122 insertions(+)
net/Makefile +1 -0
@@ -12,3 +12,4 @@ obj-$(CONFIG_NET_PICOTCP) += picotcp/ obj-$(CONFIG_NET_PICOTCP) += picotcp.o obj-$(CONFIG_CMD_PICOTCP_TEST_IPV4) += picotcp_test_ipv4.o +obj-$(CONFIG_CMD_PICOTCP_IFCONFIG) += picotcp_ifconfig.o
net/picotcp/Kconfig +5 -0
@@ -38,4 +38,9 @@ config CMD_PICOTCP_TEST_IPV4 depends on NET_PICO_SUPPORT_IPV4 prompt "test_picotcp command" +config CMD_PICOTCP_IFCONFIG + bool + depends on NET_PICO_SUPPORT_IPV4 + prompt "ifconfig command" + endif # NET_PICOTCP
net/picotcp_ifconfig.c new file +116 -0
116 lines not on this page · raw message
Signature · 7 lines
2.1.4 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
RFC 9/12 net: picotcp: add ping command
In reply to Antony Pavlov--- net/Makefile | 1 + net/picotcp/Kconfig | 5 ++++ net/picotcp_ping.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+)
net/Makefile +1 -0
@@ -13,3 +13,4 @@ obj-$(CONFIG_NET_PICOTCP) += picotcp.o obj-$(CONFIG_CMD_PICOTCP_TEST_IPV4) += picotcp_test_ipv4.o obj-$(CONFIG_CMD_PICOTCP_IFCONFIG) += picotcp_ifconfig.o +obj-$(CONFIG_CMD_PICOTCP_PING) += picotcp_ping.o
net/picotcp/Kconfig +5 -0
@@ -43,4 +43,9 @@ config CMD_PICOTCP_IFCONFIG depends on NET_PICO_SUPPORT_IPV4 prompt "ifconfig command" +config CMD_PICOTCP_PING + bool + depends on NET_PICO_SUPPORT_ICMP4 + prompt "ping command" + endif # NET_PICOTCP
net/picotcp_ping.c new file +85 -0
85 lines not on this page · raw message
Signature · 7 lines
2.1.4 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
RFC 10/12 net: picotcp: add route command
In reply to Antony Pavlov--- net/Makefile | 1 + net/picotcp/Kconfig | 5 +++++ net/picotcp_route.c | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+)
net/Makefile +1 -0
@@ -14,3 +14,4 @@ obj-$(CONFIG_NET_PICOTCP) += picotcp.o obj-$(CONFIG_CMD_PICOTCP_TEST_IPV4) += picotcp_test_ipv4.o obj-$(CONFIG_CMD_PICOTCP_IFCONFIG) += picotcp_ifconfig.o obj-$(CONFIG_CMD_PICOTCP_PING) += picotcp_ping.o +obj-$(CONFIG_CMD_PICOTCP_ROUTE) += picotcp_route.o
net/picotcp/Kconfig +5 -0
@@ -48,4 +48,9 @@ config CMD_PICOTCP_PING depends on NET_PICO_SUPPORT_ICMP4 prompt "ping command" +config CMD_PICOTCP_ROUTE + bool + depends on NET_PICO_SUPPORT_IPV4 + prompt "route command" + endif # NET_PICOTCP
net/picotcp_route.c new file +37 -0
@@ -0,0 +1,37 @@ +#include <common.h> +#include <command.h> +#include <complete.h> +#include <poller.h> + +#include <pico_stack.h> +#include <pico_ipv4.h> +#include <pico_icmp4.h> + +static int do_route (int argc,char *argv[]) +{ +struct pico_ipv4_route *r; +struct pico_tree_node *index; + +printf ("picotcp IPv4 routing table\n" ); +printf ("Destination Gateway Genmask Metric Iface\n" ); + + pico_tree_foreach(index, &Routes) { +char ipstr[32 ]; + + r = index->keyValue; + +pico_ipv4_to_string (ipstr, r->dest.addr); +printf ("%-16s" , ipstr); +pico_ipv4_to_string (ipstr, r->gateway.addr); +printf ("%-16s" , ipstr); +pico_ipv4_to_string (ipstr, r->netmask.addr); +printf ("%-16s" , ipstr); +printf ("%-7d%s\n" , r->metric, r->link->dev->name); + } + +return 0 ; +} + +BAREBOX_CMD_START (route) + .cmd = do_route, +BAREBOX_CMD_END
Signature · 7 lines
2.1.4 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
RFC 11/12 sandbox_defconfig: switch to picotcp
In reply to Antony PavlovPicotcp sandbox barebox howto
=============================
Compile sandbox barebox:
$ cd barebox.git $ unset ARCH $ unset CROSS_COMPILE $ make sandbox_defconfig ... $ make
Run barebox:
$ su # ./barebox
Testing ping
------------
While sandbox barebox is running setup a IP-address for your host 'barebox' network interface, e.g.:
# ifconfig barebox 192.168.1.1
Next, in sandbox barebox console setup network interface and try to ping host:
barebox:/ ifconfig eth 192.168.1.2 255.255.255.0 Assigned ipv4 192.168.1.2 to device eth barebox:/ picoping 192.168.1.1
48 bytes from 192.168.1.1: icmp_req=1 ttl=64 time=1 ms
...
48 bytes from 192.168.1.1: icmp_req=10 ttl=64 time=0 ms
Testing domain name resolving
-----------------------------
Install simple maradns name server on the host.
Edit /etc/maradns/mararc config file, add these lines:
csv2 = {}
csv2["example.com."] = "db.example.com"
bind_address = "192.168.1.1"
Edit /etc/maradns/db.example.com, add these lines:
example.com. 192.168.1.1 ~
www.example.com. 192.168.1.1 ~
barebox.example.com. 192.168.1.2 ~
Run sandbox barebox and setup the www.example.com IP-address for your host 'barebox' network interface, e.g.:
# ifconfig barebox 192.168.1.1
Restart maradns:
$ /etc/init.d/maradns restart
Check name resolution:
barebox@barebox sandbox:/ ifconfig eth 192.168.1.2 255.255.255.0 Assigned ipv4 192.168.1.2 to device eth barebox@barebox sandbox:/ net.nameserver=192.168.1.1 barebox@barebox sandbox:/ host barebox.example.com barebox.example.com is at 192.168.1.2
barebox@barebox sandbox:/ host www.example.com www.example.com is at 192.168.1.1
The same checks for barebox legacy network stack:
barebox@barebox sandbox:/ eth0.ipaddr=192.168.1.2 barebox@barebox sandbox:/ eth0.serverip=192.168.1.1 barebox@barebox sandbox:/ net.domainname=example.com barebox@barebox sandbox:/ net.nameserver=192.168.1.1 barebox@barebox sandbox:/ host barebox.example.com
warning: No MAC address set. Using random address 9a:a1:86:31:05:1e barebox.example.com is at 192.168.1.2
barebox@barebox sandbox:/ host www.example.com www.example.com is at 192.168.1.1
Testing dhcp (ad memorandum)
----------------------------
Configure your host dhcp server, e.g. add this
to your /etc/dhcp/dhcpd.conf:
subnet 192.168.1.0 netmask 255.255.255.0 {
range dynamic-bootp 192.168.1.26 192.168.1.29;
option routers 192.168.1.1;
option broadcast-address 192.168.1.255;
default-lease-time 600;
max-lease-time 7200;
}While sandbox barebox is running setup a IP-address for your host 'barebox' network interface and restart your host dhcp server, e.g.:
# ifconfig barebox 192.168.1.1 # /etc/init.d/isc-dhcp-server restart
Next, in your sandbox barebox console run 'dhclient':
barebox:/ dhclient eth
Assigned ipv4 0.0.0.0 to device eth Assigned ipv4 192.168.1.26 to device eth DHCP client: renewal time (T1) 300
DHCP client: rebinding time (T2) 525
DHCP client: lease time 496
DHCP client: IP assigned by the server: 192.168.1.26
--- arch/sandbox/configs/sandbox_defconfig | 7 +++++++ 1 file changed, 7 insertions(+)
arch/sandbox/configs/sandbox_defconfig +7 -0
@@ -31,6 +31,13 @@ CONFIG_CMD_OF_PROPERTY=y CONFIG_CMD_OF_DISPLAY_TIMINGS=y CONFIG_CMD_OFTREE=y CONFIG_NET=y +CONFIG_NET_PICOTCP=y +CONFIG_NET_NFS=y +CONFIG_NET_RESOLV=y +CONFIG_CMD_PICOTCP_TEST_IPV4=y +CONFIG_CMD_PICOTCP_IFCONFIG=y +CONFIG_CMD_PICOTCP_PING=y +CONFIG_CMD_PICOTCP_ROUTE=y CONFIG_OFDEVICE=y CONFIG_OF_BAREBOX_DRIVERS=y CONFIG_DRIVER_NET_TAP=y
Signature · 7 lines
2.1.4 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
RFC 12/12 WIP: sandbox_defconfig: enable network testing-related stuff
In reply to Antony Pavlov--- arch/sandbox/configs/sandbox_defconfig | 5 +++++ 1 file changed, 5 insertions(+)
arch/sandbox/configs/sandbox_defconfig +5 -0
@@ -1,3 +1,4 @@ +CONFIG_MALLOC_SIZE=0x4000000 CONFIG_HUSH_FANCY_PROMPT=y CONFIG_CMDLINE_EDITING=y CONFIG_AUTO_COMPLETE=y
@@ -16,6 +17,7 @@ CONFIG_CMD_PRINTENV=y CONFIG_CMD_MAGICVAR=y CONFIG_CMD_MAGICVAR_HELP=y CONFIG_CMD_SAVEENV=y +CONFIG_CMD_SHA1SUM=y CONFIG_CMD_SLEEP=y CONFIG_CMD_DHCP=y CONFIG_CMD_PING=y
@@ -30,6 +32,7 @@ CONFIG_CMD_OF_NODE=y CONFIG_CMD_OF_PROPERTY=y CONFIG_CMD_OF_DISPLAY_TIMINGS=y CONFIG_CMD_OFTREE=y +CONFIG_CMD_TIME=y CONFIG_NET=y CONFIG_NET_PICOTCP=y CONFIG_NET_NFS=y
@@ -45,3 +48,5 @@ CONFIG_DRIVER_NET_TAP=y # CONFIG_PINCTRL is not set CONFIG_FS_CRAMFS=y CONFIG_FS_TFTP=y +CONFIG_FS_NFS=y +CONFIG_DIGEST_SHA1_GENERIC=y
Signature · 7 lines
2.1.4 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox