Simon Kuenzer [Mon, 9 Nov 2020 16:06:23 +0000 (17:06 +0100)]
cc.h: Disable Ethernet frame padding
We set ETH_PAD_SIZE to 0 and remove support from uknetdev.c. This is done
because some uknetdev drivers will not support it (e.g., netfront) and
according to https://lwn.net/Articles/89597/, the gains of doing padding
is negligible on the CPU architectures that we currently support while
potentially hurting DMA engine performances that may get involved with
the respective driver and/or hypervisor.
Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu> Reviewed-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
Simon Kuenzer [Mon, 9 Nov 2020 16:06:22 +0000 (17:06 +0100)]
uknetdev: Per device `lwip_data` to callbacks
In order to hand-over per device `lwip_data` to the rx/tx packet allocation
function (`netif_alloc_rxpkts()`), we move storing the reference to the
allocator that used for packet allocations to `lwip_data`. In the future,
this can be used to enable per device buffer pools (e.g.,
with `ukallocpool`) for faster allocation and freeing requests.
Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu> Reviewed-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
The uknetdev library provides the way to check if interrupts are
supported on a uk_netdev. If the device does not support interrupt
the lwip stack would create a thread to poll the receive queue for
packets.
Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu> Reviewed-by: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
Reserves space for per-network-device (uknetdev). This will be later
used to store network stack specific specific information in the netdevice.
Reserving this memory allows us to store the memory continuously in the
netdev instead of additional dereferences.
Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu> Reviewed-by: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
Costin Lupu [Tue, 3 Mar 2020 14:14:43 +0000 (16:14 +0200)]
init.c: Retrieve IP v4 address from device information
IP addresses for netfront devices on Xen may be configured using Xenstore.
Therefore we should first try to get the IP address from device before taking
it from elsewhere.
Signed-off-by: Costin Lupu <costin.lupu@cs.pub.ro> Reviewed-by: Hugo Lefeuvre <hugo.lefeuvre@neclab.eu>
Simon Kuenzer [Mon, 17 Feb 2020 12:23:08 +0000 (13:23 +0100)]
net/if.h: Add include guard
Expose `struct ifconf` also when _GNU_SOURCE is defined but add an
include guard for the header. This way, double definitons of the
struct are avoided.
Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu> Reviewed-by: Felipe Huici <felipe.huici@neclab.eu>
Felipe Huici [Fri, 14 Feb 2020 13:12:14 +0000 (14:12 +0100)]
Fix compile error when enabling Operation mode (Mainloop (non-threaded).
Enabling operating mode non-threaded (aka CONFIG_LWIP_NOTHREADS)
disables the socket API from lwip. This commit makes it so that our
socket-related glue code isn't added to the build if this option is
enabled.
Signed-off-by: Felipe Huici <felipe.huici@neclab.eu> Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
Simon Kuenzer [Thu, 13 Feb 2020 22:50:54 +0000 (23:50 +0100)]
uknetdev: Yield receive thread on full stack queue
When a too high rate of network traffic is received, the netdev's receive
thread may never yield and only forwards packets to the lwip stack
thread. This works as expected until the input queue runs full. If the
the stack is never able to process them, the stack becomes completely
unresponsive. Instead of dropping just a few packets all successive
packets are dropped.
This commit introduces a thread yield when this condition is met and
gives the chance to process queued packets.
Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu> Reviewed-by: Felipe Huici <felipe.huici@neclab.eu>
Simon Kuenzer [Wed, 12 Feb 2020 14:31:38 +0000 (15:31 +0100)]
Stub getservbyport_r()
Building lwip breaks when nolibc is selected. getservbyport_r() was
relying on definitions which aren't available with nolibc. This commit
stubs this function because it seems that it wasn't used and tested so
far.
Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu> Reviewed-by: Felipe Huici <felipe.huici@neclab.eu>
Simon Kuenzer [Wed, 12 Feb 2020 14:31:29 +0000 (15:31 +0100)]
ppoll()/generic select() only available with libc
The options LWIP_SOCKET_SELECT_GENERIC_FDS and LWIP_SOCKET_PPOLL are
only made available when a proper libc (HAVE_LIBC) is added and
enabled to the build. These options do not work with nolibc.
Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu> Reviewed-by: Felipe Huici <felipe.huici@neclab.eu>
Costin Lupu [Sat, 16 Nov 2019 21:50:52 +0000 (23:50 +0200)]
sockets.c: Make select() not return errors when using it with file descriptor types other than sockets
lwip's select() implementation supports only sockets. Up until now, we returned
errors when using select() with other file descriptor types. These changes make
it possible to use other file descriptor types as well, even though they will
be ignored.
Signed-off-by: Costin Lupu <costin.lupu@cs.pub.ro> Reviewed-by: Stefan Teodorescu <stefanl.teodorescu@gmail.com>
Felipe Huici [Mon, 21 Oct 2019 13:46:35 +0000 (15:46 +0200)]
Add getservbyport_r and if_indextoname
Add stub for if_indextoname and full definition, taken from musl, for
getservbyport_r . if_indextoname's stub returns 0 (i.e., interface 0),
which should be good enough for our purposes.
Signed-off-by: Felipe Huici <felipe.huici@neclab.eu> Reviewed-by: Vlad-Andrei Badoiu <vlad_andrei.badoiu@stud.acs.upb.ro>
Felipe Huici [Mon, 21 Oct 2019 13:46:34 +0000 (15:46 +0200)]
Add IPv6 macro definitions
Add IN6_IS_ADDR_MULTICAST, IN6_IS_ADDR_LINKLOCAL and
IN6_IS_ADDR_MC_LINKLOCAL macro definitions. These are defined by libc,
but not included in by our netinet/in.h glue when sockets are enabled,
breaking builds that depend on these and sockets.
Signed-off-by: Felipe Huici <felipe.huici@neclab.eu> Reviewed-by: Vlad-Andrei Badoiu <vlad_andrei.badoiu@stud.acs.upb.ro>
Felipe Huici [Wed, 18 Sep 2019 09:21:26 +0000 (11:21 +0200)]
Remove exportsyms.uk
For now we remove exportsyms.uk . This is to prevent a lot of
unnecessary confusion (and wasted time) arising from undefined
reference linker errors when the actual sybol is actually in the
sources. We may revert this at some later point in time.
Signed-off-by: Felipe Huici <felipe.huici@neclab.eu> Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
We currently just set a stub for .vop_getattr operation in order to avoid
crashes. And since we are here, this patch also disables the cast-function-type
warnings which annoyingly apear for each source file that sets some filesystem
callbacks.
It's simpler to suppress the warning rather than add '__unused' qualifier each
time. This also seems it was the initial intention behind using
'-Wunused-parameter', given that all warnings are enabled by default.
* As we did in commit b0dc593d, we use function wrappers instead of macros for
gethostbyname() and gethostbyname_r()
* Add missing declarations of functions implemented or stubbed in glue code
Bogdan Lascu [Fri, 23 Aug 2019 11:53:44 +0000 (14:53 +0300)]
Define getaddrinfo() and freeaddrinfo() as functions instead of wrappers
Commit 28138d6d added getaddrinfo() and freeaddrinfo() as wrappers. However,
it's not necessary for a source file to include the netdb.h header where they
are defined when it uses them. So their definitions are needed as functions and
not as macros.
Bogdan Lascu [Fri, 16 Aug 2019 07:09:42 +0000 (10:09 +0300)]
lwipopts.h: Use libc ioctl.h if available
If we do have a libc ioctl.h header then we should be using it because it
usually contains a larger number of constants with better value assignments than
the ones in lwip.
Costin Lupu [Fri, 16 Aug 2019 07:09:40 +0000 (10:09 +0300)]
Adapt getnameinfo() function to Unikraft
This is how you adapt a function to Unikraft:
1. Add license if it is missing; in our case, getnameinfo() was initially taken
from musl to OsV and enhanced a bit, so we had to add the BSD license of OsV and
the MIT license of musl; we decided to take the OsV implementation because it
also checks the local /etc/hosts file before issuing DNS requests
2. Use Unikraft headers
3. Fix checkpatch issues
4. Disable some unsupported functionality; in our case, we don't support name
requests for getnameinfo(); we could have if the DNS implementation of lwip
supported DNS resource records
5. Define constants that are not already provided by the origin code
6. Add its source file to Makefile.uk
7. Export the function
Signed-off-by: Costin Lupu <costin.lupu@cs.pub.ro> Reviewed-by: Felipe Huici <felipe.huici@neclab.eu>
Mihai Pogonaru [Sat, 29 Jun 2019 13:54:57 +0000 (16:54 +0300)]
Update the number of remaining unprocessed bytes correctly
Update uio structure in sock_net_write/read. VFSCORE expects the
update of the resid member of uio such that it reflects the
number of bytes that remain unprocessed.
Set the UK_VFSCORE_NOPOS flag on the socket vfscore_file. This
flag informs VFSCORE to do not update the offset of our socket
file since it doesn't make sense for sockets.
Signed-off-by: Mihai Pogonaru <pogonarumihai@gmail.com> Reviewed-by: Costin Lupu <costin.lupu@cs.pub.ro>
Mihai Pogonaru [Sat, 29 Jun 2019 13:54:56 +0000 (16:54 +0300)]
Use vfs functions to allocate/free the resources used for a socket (Part I)
This part changes LWIP so that it lets vfs to free the resources
used to integrate sockets in vfs.
Right now sock_net_close frees the vfscore_file, dentry and vnode
used for the socket. This can cause problems since vfs unlocks the
vnode after calling sock_net_close so it accesses freed memory.
We will let vfs handle the freeing of the resources used for a
socket by setting the dentry refcount to 1 such that, when a socket is
closed (so its vfscore_file is also closed), the dentry's refcount
hits 0, the dentry is deleted so the vnode refcount hits 0
and it is also deleted.
Signed-off-by: Mihai Pogonaru <pogonarumihai@gmail.com> Reviewed-by: Costin Lupu <costin.lupu@cs.pub.ro>
Mihai Pogonaru [Sat, 15 Jun 2019 13:18:19 +0000 (16:18 +0300)]
Provide gethostbyname and gethostbyname_r
Define gethostbyname and gethostbyname_r as their LWIP counterparts.
The defines are in place in origin/netdb.h, but they are protected by
LWIP_COMPAT_SOCKETS, which for us is defined as 0 since we provide
wrappers for most of socket.h functions.
Signed-off-by: Mihai Pogonaru <pogonarumihai@gmail.com> Reviewed-by: Costin Lupu <costin.lupu@cs.pub.ro>
Florian Schmidt [Mon, 20 May 2019 11:29:51 +0000 (13:29 +0200)]
Provide poll() and select() wrappers around lwip versions
This takes the vfscore-provided file descriptors, translates them into
lwip file descriptors, and will run the lwip versions on those sockets.
If any of the file descriptors provided isn't an LWIP socket, the call
will fail with a return of -1, errno EBADF.
Signed-off-by: Florian Schmidt <florian.schmidt@neclab.eu> Reviewed-by: Felipe Huici <felipe.huici@neclab.eu>
Florian Schmidt [Mon, 20 May 2019 11:29:50 +0000 (13:29 +0200)]
sockets.c: Refuse to deal with non-sockets
Otherwise, socket_net_file_get() will try to look up lwip's file
descriptors for file objects not created by lwip, reading garbage from
where it expects sock_fd in sock_net_file.
Signed-off-by: Florian Schmidt <florian.schmidt@neclab.eu> Reviewed-by: Felipe Huici <felipe.huici@neclab.eu>
Florian Schmidt [Mon, 20 May 2019 11:29:48 +0000 (13:29 +0200)]
Don't provide file status flags when we have a libc
Instead, trust that they will show up during compilation, just maybe a
bit later. Otherwise, we might very well end up with conflicting
definitions for the values of these flags.
Signed-off-by: Florian Schmidt <florian.schmidt@neclab.eu> Reviewed-by: Felipe Huici <felipe.huici@neclab.eu>
Florian Schmidt [Mon, 20 May 2019 11:29:44 +0000 (13:29 +0200)]
Move export.syms to exportsyms.uk
This file was ignored up to now because it followed a superseded naming
standard. This patch also adds lwip_htonl, lwip_htons, and lwip_select
to exportsyms.uk, because those are known to be used by applications,
and provided via #defines of their non-prefixed versions.
Signed-off-by: Florian Schmidt <florian.schmidt@neclab.eu> Reviewed-by: Felipe Huici <felipe.huici@neclab.eu>
Sharan Santhanam [Mon, 27 May 2019 13:00:33 +0000 (15:00 +0200)]
liblwip: Remove vfscore_put_fd from socket_close
This patch fixes a bug in the function sock_net_close. The close
function frees up a descriptor that was removed by fdrop. The fdrop
function invokes the close callback after it had removed the fd
from its list.
Simon Kuenzer [Wed, 8 May 2019 09:54:53 +0000 (11:54 +0200)]
Adopt to latest libuklock, libukmpi changes
lwip's semaphores are implemented based on semphores provided by
libuklock and lwip's mailboxes are implemented based on mailboxes
provided by libukmpi. The API of both have changed recently;
originally with commit a48d634 ("lib/uklock: Use timeout equal to 0
for trying down a semaphore"): A passed timeout of `0` is now
immediately returning instead of blocking the current thread until the
according event happened.
This patch also depends on the Unikraft patch 734930 ("lib/ukmpi:
Provide blocking uk_mbox_recv()"):
https://patchwork.unikraft.org/patch/734930/
Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu> Reviewed-by: Costin Lupu <costin.lupu@cs.pub.ro>
Florian Schmidt [Mon, 18 Feb 2019 09:30:26 +0000 (10:30 +0100)]
uknetdev_output: Fix loop iterator
Setting q to p->next leads to an infinite loop if p has at least two
segments. The correct way is to iterate over q so we actually progress
through the list.
Signed-off-by: Florian Schmidt <florian.schmidt@neclab.eu> Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
Simon Kuenzer [Thu, 7 Feb 2019 23:00:35 +0000 (00:00 +0100)]
Netif status print callback
Introduce a status print hook to all netifs operated by the lwIP
stack. State changes (e.g., assigning of an IP, bringing device up or
down) are printed to the standard console. Because the stack is not
printing any message to the console with the default configuration, we
enable this print hook as default.
Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu> Reviewed-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
Simon Kuenzer [Thu, 7 Feb 2019 23:00:34 +0000 (00:00 +0100)]
Attach uknetdev netifs during boot
Scan for uknetdev devices and attach them automatically to the lwIP
stack during initialization. If DHCP support is enabled, the stack
will query for an address on the interfaces.
Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu> Reviewed-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
Simon Kuenzer [Thu, 7 Feb 2019 23:00:33 +0000 (00:00 +0100)]
Netif driver for libuknetdev devices
Introduces a netif driver for libuknetdev devices. Packet buffers are
allocated on the heap for now. Receive interrupts are supported and
enabled when lwIP is operated in "threaded" mode. Zero-copy receive is
implemented with packet buffers having two personalities: pbuf and netbuf.
Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu> Reviewed-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
Simon Kuenzer [Thu, 7 Feb 2019 23:00:32 +0000 (00:00 +0100)]
Update to lwIP 2.1.2
Update lwIP from 2.0.3 to the latest relase 2.1.2 from Dec 2018. We
transform the rather beta state of our glue library to a more stable
implementation based on the latest staging branch of Unikraft towards
release 0.3.
This commit provides the following features as selectable options from
lwIP:
- Two operation modes: "threaded" or as (part of a) "mainloop"
- IPv4 support
- Experimental IPv6 support (incomplete)
- Protocols: UDP, TCP, ICMP, IGMP, SNMP
- DNS resolver
- DHCPv4 client
- Socket API
Sharan Santhanam [Fri, 15 Jun 2018 20:53:48 +0000 (22:53 +0200)]
Expose socket header & disable socket polling
In this patch, we expose the socket API through lwIP. In its current
implementation, we do disable support for select()/poll() on a file
descriptor since an implementation is missing in vfscore.
We are going to add this feature again in the near future.