Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce POSIX socket driver microlibrary #65

Closed
wants to merge 3 commits into from

Conversation

nderjung
Copy link
Member

@nderjung nderjung commented Sep 28, 2020

This patch series introduces the posix-socket microlibrary within the Unikraft core in order to facilitate the use of multiple POSIX-compliant socket implementations which target specific AF family numbers.

This library allows for the registration of socket interfaces, listed within struct posix_socket_ops, and exposes unikernel-wide prototypes for socket(), accept(), bind(), listen(), connect(), send(), recv() and friends in order to access them via a corresponding AF family number. The implementing library simply needs to register against the desired interfaces with a glue function:

#include <uk/socket.h>
#include "my_socket.h"

static struct posix_socket_ops mysock_socket_ops = {
  /* The initialization function on socket registration. */
  .init        = mysock_lib_init,
  /* POSIX interfaces */
  .create      = mysock_glue_create,
  .accept      = mysock_glue_accept,
  .bind        = mysock_glue_bind,
  .shutdown    = mysock_glue_shutdown,
  .getpeername = mysock_glue_getpeername,
  .getsockname = mysock_glue_getsockname,
  .getsockopt  = mysock_glue_getsockopt,
  .setsockopt  = mysock_glue_setsockopt,
  .connect     = mysock_glue_connect,
  .listen      = mysock_glue_listen,
  .recvfrom    = mysock_glue_recvfrom,
  .recvmsg     = mysock_glue_recvmsg,
  .sendmsg     = mysock_glue_sendmsg,
  .sendto      = mysock_glue_sendto,
  /* vfscore ops */
  .read        = mysock_glue_read,
  .write       = mysock_glue_write,
  .close       = mysock_glue_close,
  .ioctl       = mysock_glue_ioctl,
};

Each glue function accepts traditional parameters for the POSIX interface as side from the file descriptor, traditionally int fd or int sock, which has instead been cast as void *. This allows the implementing library to use internal socket file descriptor or reference. The creation of a socket via socket() and accept() have also been cast to return void * in line with internal needs of the implementing library. This makes sense for implementing libraries which use a structure instead of a file descriptor identification integer. An additional parameter, struct posix_socket_driver, is passed to each interface which can store private data as well as a preferred memory allocator. The glue for each interface simply needs to call the appropriate method internally, for example:

static int
mysock_glue_bind(struct posix_socket_driver *d,
        void *sock, const struct sockaddr *addr, socklen_t addr_len)
{
  struct my_socket *mysock;
  int ret;

  mysock = (struct my_socket *)sock;
  ret = mysock_bind(mysock, addr, addr_len);
  if (ret < 0)
    ret = -errno;

  return ret;
}

The library selects the appropriate implementation based on the AF family number and registers the required interfaces using a newly exposed macro:

POSIX_SOCKET_FAMILY_REGISTER(AF_INET,  &mysock_socket_ops);

Implementing libraries can register as many AF numbers as desired or specify new families which are not listed in the <sys/socket.h> header. To access the relevant implementation, the application simply needs to call the socket() method with the relevant AF family number.

This PR is now part of a larger group of dependent PRs which must be merged in the following order:

  1. Remove poll/select and eventfd stubs lib-newlib#23
  2. VFS Eventpoll API #484
  3. Introduce POSIX socket driver microlibrary #65 (this PR)
  4. Switch to lib/posix-socket lib-lwip#17
  5. Introduce lib/posix-event #485

Warning Without having merged all of these PRs, network is no longer functional. All PRs should thus be checked and reviewed first and then merged in quick succession.

@nderjung nderjung added kind/enhancement New feature or request area/lib Internal Unikraft Microlibrary topic/posix Topics pertaining to POSIX standard lib/posix-socket Abstraction for communication sockets new/library This PR or Issue intends to add a new library to Unikraft labels Sep 28, 2020
@nderjung nderjung changed the title Introduce POSIX socket driver microlibrary WIP: Introduce POSIX socket driver microlibrary Sep 28, 2020
@nderjung nderjung linked an issue Sep 28, 2020 that may be closed by this pull request
@nderjung
Copy link
Member Author

I need to remove the uk ring commits from this series. I will force push an update.

@razvand razvand requested review from ungps and razvand April 16, 2021 13:24
@nderjung nderjung changed the title WIP: Introduce POSIX socket driver microlibrary Introduce POSIX socket driver microlibrary Apr 19, 2021
@nderjung
Copy link
Member Author

This PR is ready for review :)

Copy link

@ungps ungps left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello.

I looked two times over the commits during the past week and there wasn't much to say, I just left some comments (mostly nitpicks). It looks good, although there is a compilation error. I fetched the branch and tried to build it, but header sys/socket.h is missing.

In file included from /home/ubuntu/unikraft/lib/posix-socket/driver.c:38:
/home/ubuntu/unikraft/lib/posix-socket/include/uk/socket_driver.h:49:10: fatal error: sys/socket.h: No such file or directory
   49 | #include <sys/socket.h>
      |          ^~~~~~~~~~~~~~
compilation terminated.

This header can be found in lwip library, but that is an external library. It doesn't make sense to me to have an internal library dependant on an external one. Even if we were to compile with lwip, there are another errors and warning (such as conflicting types for a couple of functions):

/home/ubuntu/unikraft/lib/posix-socket/driver.c: In function ‘posix_socket_get_family’:
/home/ubuntu/unikraft/lib/posix-socket/driver.c:149:29: warning: unused parameter ‘sock’ [-Wunused-parameter]
  149 | posix_socket_get_family(int sock)
      |                         ~~~~^~~~
  CC      libposix_socket: socket_vnops.o
In file included from /home/ubuntu/unikraft/lib/nolibc/include/fcntl.h:19,
                 from /home/ubuntu/unikraft/lib/vfscore/include/vfscore/fs.h:4,
                 from /home/ubuntu/unikraft/lib/posix-socket/socket_vnops.c:38:
/home/ubuntu/unikraft/lib/nolibc/arch/x86_64/bits/fcntl.h:6: warning: "O_NONBLOCK" redefined
    6 | #define O_NONBLOCK    04000
      | 
In file included from /home/ubuntu/libs/lwip/include/sys/socket.h:46,
                 from /home/ubuntu/unikraft/lib/posix-socket/include/uk/socket_driver.h:49,
                 from /home/ubuntu/unikraft/lib/posix-socket/socket_vnops.c:35:
/home/ubuntu/apps/app-httpreply/build/liblwip/origin/lwip-2.1.2/src/include/lwip/sockets.h:478: note: this is the location of the previous definition
  478 | #define O_NONBLOCK  1 /* nonblocking I/O */
      | 
In file included from /home/ubuntu/unikraft/lib/vfscore/include/vfscore/fs.h:4,
                 from /home/ubuntu/unikraft/lib/posix-socket/socket_vnops.c:38:
/home/ubuntu/unikraft/lib/nolibc/include/fcntl.h:40: warning: "O_RDONLY" redefined
   40 | #define O_RDONLY  00
      | 
In file included from /home/ubuntu/libs/lwip/include/sys/socket.h:46,
                 from /home/ubuntu/unikraft/lib/posix-socket/include/uk/socket_driver.h:49,
                 from /home/ubuntu/unikraft/lib/posix-socket/socket_vnops.c:35:
/home/ubuntu/apps/app-httpreply/build/liblwip/origin/lwip-2.1.2/src/include/lwip/sockets.h:484: note: this is the location of the previous definition
  484 | #define O_RDONLY    2
      | 
In file included from /home/ubuntu/unikraft/lib/vfscore/include/vfscore/fs.h:4,
                 from /home/ubuntu/unikraft/lib/posix-socket/socket_vnops.c:38:
/home/ubuntu/unikraft/lib/nolibc/include/fcntl.h:41: warning: "O_WRONLY" redefined
   41 | #define O_WRONLY  01
      | 
In file included from /home/ubuntu/libs/lwip/include/sys/socket.h:46,
                 from /home/ubuntu/unikraft/lib/posix-socket/include/uk/socket_driver.h:49,
                 from /home/ubuntu/unikraft/lib/posix-socket/socket_vnops.c:35:
/home/ubuntu/apps/app-httpreply/build/liblwip/origin/lwip-2.1.2/src/include/lwip/sockets.h:487: note: this is the location of the previous definition
  487 | #define O_WRONLY    4
      | 
In file included from /home/ubuntu/unikraft/lib/vfscore/include/vfscore/fs.h:4,
                 from /home/ubuntu/unikraft/lib/posix-socket/socket_vnops.c:38:
/home/ubuntu/unikraft/lib/nolibc/include/fcntl.h:42: warning: "O_RDWR" redefined
   42 | #define O_RDWR    02
      | 
In file included from /home/ubuntu/libs/lwip/include/sys/socket.h:46,
                 from /home/ubuntu/unikraft/lib/posix-socket/include/uk/socket_driver.h:49,
                 from /home/ubuntu/unikraft/lib/posix-socket/socket_vnops.c:35:
/home/ubuntu/apps/app-httpreply/build/liblwip/origin/lwip-2.1.2/src/include/lwip/sockets.h:490: note: this is the location of the previous definition
  490 | #define O_RDWR      (O_RDONLY|O_WRONLY)
      | 
/home/ubuntu/unikraft/lib/posix-socket/socket_vnops.c:45:31: warning: cast between incompatible function types from ‘int (*)(void)’ to ‘int (*)(struct vnode *, struct vattr *)’ [-Wcast-function-type]
   45 | #define posix_socket_getattr ((vnop_getattr_t) vfscore_vop_einval)
      |                               ^
/home/ubuntu/unikraft/lib/posix-socket/socket_vnops.c:54:17: note: in expansion of macro ‘posix_socket_getattr’
   54 |  .vop_getattr = posix_socket_getattr,
      |                 ^~~~~~~~~~~~~~~~~~~~
/home/ubuntu/unikraft/lib/posix-socket/socket_vnops.c:46:32: warning: cast between incompatible function types from ‘int (*)(void)’ to ‘int (*)(struct vnode *)’ [-Wcast-function-type]
   46 | #define posix_socket_inactive ((vnop_inactive_t) vfscore_vop_nullop)
      |                                ^
/home/ubuntu/unikraft/lib/posix-socket/socket_vnops.c:55:18: note: in expansion of macro ‘posix_socket_inactive’
   55 |  .vop_inactive = posix_socket_inactive,
      |                  ^~~~~~~~~~~~~~~~~~~~~
/home/ubuntu/unikraft/lib/posix-socket/socket_vnops.c:58:28: warning: cast between incompatible function types from ‘int (*)(void)’ to ‘int (*)(struct mount *, struct vnode *)’ [-Wcast-function-type]
   58 | #define posix_socket_vget ((vfsop_vget_t) vfscore_nullop)
      |                            ^
/home/ubuntu/unikraft/lib/posix-socket/socket_vnops.c:62:14: note: in expansion of macro ‘posix_socket_vget’
   62 |  .vfs_vget = posix_socket_vget,
      |              ^~~~~~~~~~~~~~~~~
/home/ubuntu/unikraft/lib/posix-socket/socket_vnops.c: In function ‘posix_socket_vfscore_close’:
/home/ubuntu/unikraft/lib/posix-socket/socket_vnops.c:205:24: warning: unused parameter ‘vfscore_file’ [-Wunused-parameter]
  205 |   struct vfscore_file *vfscore_file)
      |   ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
  CC      libposix_socket: socket.o
In file included from /home/ubuntu/unikraft/lib/posix-socket/socket.c:35:
/home/ubuntu/unikraft/lib/posix-socket/include/uk/socket.h:43:2: error: unknown type name ‘uint32_t’
   43 |  uint32_t type;
      |  ^~~~~~~~
/home/ubuntu/unikraft/lib/posix-socket/socket.c: In function ‘getnameinfo’:
/home/ubuntu/unikraft/lib/posix-socket/socket.c:378:45: warning: unused parameter ‘sa’ [-Wunused-parameter]
  378 | getnameinfo(const struct sockaddr *restrict sa, socklen_t sl,
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
/home/ubuntu/unikraft/lib/posix-socket/socket.c:378:59: warning: unused parameter ‘sl’ [-Wunused-parameter]
  378 | getnameinfo(const struct sockaddr *restrict sa, socklen_t sl,
      |                                                 ~~~~~~~~~~^~
/home/ubuntu/unikraft/lib/posix-socket/socket.c:379:18: warning: unused parameter ‘node’ [-Wunused-parameter]
  379 |   char *restrict node, socklen_t nodelen, char *restrict serv,
      |   ~~~~~~~~~~~~~~~^~~~
/home/ubuntu/unikraft/lib/posix-socket/socket.c:379:34: warning: unused parameter ‘nodelen’ [-Wunused-parameter]
  379 |   char *restrict node, socklen_t nodelen, char *restrict serv,
      |                        ~~~~~~~~~~^~~~~~~
/home/ubuntu/unikraft/lib/posix-socket/socket.c:379:58: warning: unused parameter ‘serv’ [-Wunused-parameter]
  379 |   char *restrict node, socklen_t nodelen, char *restrict serv,
      |                                           ~~~~~~~~~~~~~~~^~~~
/home/ubuntu/unikraft/lib/posix-socket/socket.c:380:13: warning: unused parameter ‘servlen’ [-Wunused-parameter]
  380 |   socklen_t servlen, int flags)
      |   ~~~~~~~~~~^~~~~~~
/home/ubuntu/unikraft/lib/posix-socket/socket.c:380:26: warning: unused parameter ‘flags’ [-Wunused-parameter]
  380 |   socklen_t servlen, int flags)
      |                      ~~~~^~~~~
/home/ubuntu/unikraft/lib/posix-socket/socket.c: At top level:
/home/ubuntu/unikraft/lib/posix-socket/socket.c:467:1: error: conflicting types for ‘recv’
  467 | recv(int sock, void *buf, size_t len, int flags)
      | ^~~~
In file included from /home/ubuntu/unikraft/lib/posix-socket/include/uk/socket_driver.h:49,
                 from /home/ubuntu/unikraft/lib/posix-socket/include/uk/socket.h:56,
                 from /home/ubuntu/unikraft/lib/posix-socket/socket.c:35:
/home/ubuntu/libs/lwip/include/sys/socket.h:95:5: note: previous declaration of ‘recv’ was here
   95 | int recv(int s, void *mem, size_t len, int flags);
      |     ^~~~
/home/ubuntu/unikraft/lib/posix-socket/socket.c:505:1: error: conflicting types for ‘recvfrom’
  505 | recvfrom(int sock, void *buf, size_t len, int flags,
      | ^~~~~~~~
In file included from /home/ubuntu/unikraft/lib/posix-socket/include/uk/socket_driver.h:49,
                 from /home/ubuntu/unikraft/lib/posix-socket/include/uk/socket.h:56,
                 from /home/ubuntu/unikraft/lib/posix-socket/socket.c:35:
/home/ubuntu/libs/lwip/include/sys/socket.h:96:5: note: previous declaration of ‘recvfrom’ was here
   96 | int recvfrom(int s, void *mem, size_t len, int flags,
      |     ^~~~~~~~
/home/ubuntu/unikraft/lib/posix-socket/socket.c:544:1: error: conflicting types for ‘recvmsg’
  544 | recvmsg(int sock, struct msghdr *msg, int flags)
      | ^~~~~~~
In file included from /home/ubuntu/unikraft/lib/posix-socket/include/uk/socket_driver.h:49,
                 from /home/ubuntu/unikraft/lib/posix-socket/include/uk/socket.h:56,
                 from /home/ubuntu/unikraft/lib/posix-socket/socket.c:35:
/home/ubuntu/libs/lwip/include/sys/socket.h:98:5: note: previous declaration of ‘recvmsg’ was here
   98 | int recvmsg(int s, struct msghdr *msg, int flags);
      |     ^~~~~~~
/home/ubuntu/unikraft/lib/posix-socket/socket.c:582:1: error: conflicting types for ‘send’
  582 | send(int sock, const void *buf, size_t len, int flags)
      | ^~~~
In file included from /home/ubuntu/unikraft/lib/posix-socket/include/uk/socket_driver.h:49,
                 from /home/ubuntu/unikraft/lib/posix-socket/include/uk/socket.h:56,
                 from /home/ubuntu/unikraft/lib/posix-socket/socket.c:35:
/home/ubuntu/libs/lwip/include/sys/socket.h:99:5: note: previous declaration of ‘send’ was here
   99 | int send(int s, const void *dataptr, size_t size, int flags);
      |     ^~~~
/home/ubuntu/unikraft/lib/posix-socket/socket.c:620:1: error: conflicting types for ‘sendmsg’
  620 | sendmsg(int sock, const struct msghdr *msg, int flags)
      | ^~~~~~~
In file included from /home/ubuntu/unikraft/lib/posix-socket/include/uk/socket_driver.h:49,
                 from /home/ubuntu/unikraft/lib/posix-socket/include/uk/socket.h:56,
                 from /home/ubuntu/unikraft/lib/posix-socket/socket.c:35:
/home/ubuntu/libs/lwip/include/sys/socket.h:100:5: note: previous declaration of ‘sendmsg’ was here
  100 | int sendmsg(int s, const struct msghdr *message, int flags);
      |     ^~~~~~~
/home/ubuntu/unikraft/lib/posix-socket/socket.c:658:1: error: conflicting types for ‘sendto’
  658 | sendto(int sock, const void *buf, size_t len, int flags,
      | ^~~~~~
In file included from /home/ubuntu/unikraft/lib/posix-socket/include/uk/socket_driver.h:49,
                 from /home/ubuntu/unikraft/lib/posix-socket/include/uk/socket.h:56,
                 from /home/ubuntu/unikraft/lib/posix-socket/socket.c:35:
/home/ubuntu/libs/lwip/include/sys/socket.h:101:5: note: previous declaration of ‘sendto’ was here
  101 | int sendto(int s, const void *dataptr, size_t size, int flags,
      |     ^~~~~~
/home/ubuntu/unikraft/lib/posix-socket/socket.c: In function ‘socketpair’:
/home/ubuntu/unikraft/lib/posix-socket/socket.c:741:1: warning: label ‘EXIT’ defined but not used [-Wunused-label]
  741 | EXIT:
      | ^~~~
/home/ubuntu/unikraft/lib/posix-socket/socket.c:704:33: warning: unused variable ‘u2’ [-Wunused-variable]
  704 |  struct posix_socket_file *u1, *u2;
      |                                 ^~
/home/ubuntu/unikraft/lib/posix-socket/socket.c:704:28: warning: unused variable ‘u1’ [-Wunused-variable]
  704 |  struct posix_socket_file *u1, *u2;
      |                            ^~
make[3]: *** [/home/ubuntu/unikraft/support/build/Makefile.build:27: /home/ubuntu/apps/app-httpreply/build/libposix_socket/socket.o] Error 1
make[2]: *** [Makefile:990: sub-make] Error 2
make[1]: *** [Makefile:32: _all] Error 2
make[1]: Leaving directory '/home/ubuntu/unikraft'
make: *** [Makefile:6: all] Error 2

static int
posix_socket_family_lib_init(void)
{
uk_pr_info("Initializing socket handlers...\n");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a nitpick: I would move this message after the variable declarations. Again, it's just a nitpick, in the worst case scenario it will cause a warning.

vfs_file->f_dentry = s_dentry;
vfs_file->f_vfs_flags = UK_VFSCORE_NOPOS;

// s_vnode->v_data = file;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a nitpick, but I would drop this line.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line should not be commented out, turns out it is very important and an artifact of previous debugging :)

lib/posix-socket/include/uk/socket_driver.h Show resolved Hide resolved
@nderjung nderjung added this to In Progress in General Kanban May 10, 2021
@nderjung
Copy link
Member Author

nderjung commented Jul 9, 2021

Hey @marcrittinghaus, I have a few updates to this series out of this PR. I will incorporate your suggestions (thanks btw!) when i force-push to this PR.

@nderjung nderjung removed their assignment Nov 26, 2021
@razvand razvand removed their request for review November 27, 2021 10:26
@razvand razvand added this to the v0.7 - Mimas milestone Nov 27, 2021
@razvand razvand removed this from In Progress in General Kanban Nov 27, 2021
@nderjung nderjung requested a review from a team February 2, 2022 09:28
@marcrittinghaus
Copy link
Member

I already did a ton of changes to this library internally. I think it makes sense to update it before making any reviews. It also needs some more clean up.

@razvand razvand removed the request for review from a team February 5, 2022 05:32
@razvand
Copy link
Contributor

razvand commented Feb 5, 2022

@marcrittinghaus , maybe it makes sense that you update the PR contents (I think you can push to @nderjung 's brach (nderjung/posix-socket), and I will assign a reviewer and assignee to it. What do you think?

@marcrittinghaus
Copy link
Member

@craciunoiuc

Thanks for the feedback regarding EAGAIN. I have added checks in some places.

@marcrittinghaus
Copy link
Member

marcrittinghaus commented Jul 28, 2022

@craciunoiuc I changed the EAGAIN checks for the VNOPS to only affect the output and not the actual return values so EAGAIN is still regarded as an error condition and the application is notified correctly but without spamming the log.

@craciunoiuc
Copy link
Member

craciunoiuc commented Jul 28, 2022

All good on my side now

I'll do one more pass/test just in case to make sure nothing pops up.
Edit: Yup, all good

Your turn now @skuenzer ;)

@marcrittinghaus
Copy link
Member

@craciunoiuc, @razvand Just noticed that if the socket error message is off, the single-line if statement introduced in the last push would break. This fixes the issue.

Other than that, I tested this again with nginx and everything works. However, as @craciunoiuc also mentions on discord, we have to update the various network-enabled applications/libraries to reference posix-socket and posix-event instead of liblwip. But I would not do this as part of this PR series.

Copy link
Contributor

@razvand razvand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @marcrittinghaus . Thanks for the work. I used it before for binary compatibility and it did the trick. I will test it again.

I did a first read pass. See my suggestions as inline comments.

Apart from this, some other comments below.

There is an inconsistency between macros in sys/socket.h (as I understand, this is imported from OpenBSD) and the macros in Linux for address families. Some examples:

  • AF_BLUETOOTH is 32 - in Linux: 31
  • AF_ROUTE is 17 - in Linux: 16
  • AF_INET6 is 24 - in Linux: 10
  • AF_IPX is 23 - in Linux: 4

This may be an issue when using binary compatibility mode.

For Doxygen comments, there is an inconsistency around the use of dot (.) at the end of a comment line or not. Either should be OK, as long as it's consistent.

lib/nolibc/include/sys/socket.h Show resolved Hide resolved
lib/posix-socket/include/uk/socket_driver.h Outdated Show resolved Hide resolved
lib/posix-socket/include/uk/socket_driver.h Outdated Show resolved Hide resolved
lib/posix-socket/include/uk/socket_driver.h Outdated Show resolved Hide resolved
lib/posix-socket/include/uk/socket.h Show resolved Hide resolved
lib/posix-socket/include/uk/socket_vnops.h Outdated Show resolved Hide resolved
lib/posix-socket/include/uk/socket_vnops.h Outdated Show resolved Hide resolved
lib/posix-socket/include/uk/socket_vnops.h Outdated Show resolved Hide resolved
lib/posix-socket/socket.c Outdated Show resolved Hide resolved
trace_posix_socket_socketpair_ret(ret);
return ret;
EXIT_ERR_FREE_FD1:
/* TODO: Broken error handling. Leaking vfs_fd1! */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't vfs_fd1 be freed? Isn't there a free() equivalent to the posix_socket_alloc_fd() function?

lib/posix-socket/include/uk/socket_driver.h Outdated Show resolved Hide resolved
lib/posix-socket/include/uk/socket_driver.h Outdated Show resolved Hide resolved
This commit adds a reduced version of the <sys/socket.h> header for use
by the posix-socket library.

Signed-off-by: Alexander Jung <alex@unikraft.io>
Signed-off-by: Marc Rittinghaus <marc.rittinghaus@kit.edu>
@marcrittinghaus
Copy link
Member

There is an inconsistency between macros in sys/socket.h (as I understand, this is imported from OpenBSD) and the macros in Linux for address families. Some examples:

  • AF_BLUETOOTH is 32 - in Linux: 31
  • AF_ROUTE is 17 - in Linux: 16
  • AF_INET6 is 24 - in Linux: 10
  • AF_IPX is 23 - in Linux: 4

I redefined all of the address families by taking the values from musl. This should increase compatibility.

This library allows for the registration of socket drivers that
implement the posix_socket_ops interface and thereby expose a
POSIX-compliant socket API for a certain AF address family. Drivers
may register as many AF numbers as desired or specify new families
which are not listed in the <sys/socket.h> header. To access the
relevant implementation, the application simply creates a socket
with the required AF family number.

Signed-off-by: Alexander Jung <alex@unikraft.io>
Signed-off-by: Marc Rittinghaus <marc.rittinghaus@kit.edu>
@nderjung nderjung removed the request for review from a team August 15, 2022 16:23
@razvand razvand assigned razvand and unassigned skuenzer Aug 16, 2022
@razvand
Copy link
Contributor

razvand commented Aug 16, 2022

@marcrittinghaus , all is OK. @craciunoiuc , please approve this PR and then I'll approve it as well. I'll be careful to do the approval in the order signaled by @marcrittinghaus .

Copy link
Member

@craciunoiuc craciunoiuc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good on my side!

Reviewed-by: Cezar Craciunoiu cezar.craciunoiu@gmail.com

@unikraft-bot
Copy link
Member

⚠️ Checkpatch passed with warnings

Beep boop! I ran Unikraft's checkpatch.pl support script on your pull request but it encountered warnings:

SHA commit checkpatch
d02be9c lib/nolibc: Add socklen_t to shareddefs
cdf7e49 lib/nolibc: Add sys/socket header
1a74365 lib/posix-socket: Add POSIX socket driver library ⚠️

Truncated logs starting from first warning 1a74365:

WARNING:AVOID_EXTERNS: externs should be avoided in .c files
#168: FILE: lib/posix-socket/driver.c:44:
+extern struct posix_socket_driver posix_socket_driver_list_end[];

total: 0 errors, 1 warnings, 1994 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
      mechanically convert to the typical style using --fix or --fix-inplace.

/tmp/build/a53d4c5b/patches/0003-lib-posix-socket-Add-POSIX-socket-driver-library.patch has style problems, please review.

NOTE: Ignored message types: ASSIGN_IN_IF FILE_PATH_CHANGES NEW_TYPEDEFS OBSOLETE

NOTE: If any of the errors are false positives, please report
      them to the maintainer, see CHECKPATCH in MAINTAINERS.

View complete logs | Learn more about Unikraft's coding style and contribution guidelines.

@nderjung nderjung linked an issue Aug 16, 2022 that may be closed by this pull request
Copy link
Contributor

@razvand razvand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @marcrittinghaus, @nderjung . This works.

Reviewed-by: Razvan Deaconescu razvan.deaconescu@cs.pub.ro
Approved-by: Razvan Deaconescu razvan.deaconescu@cs.pub.ro

unikraft-bot pushed a commit that referenced this pull request Aug 16, 2022
This commit adds a reduced version of the <sys/socket.h> header for use
by the posix-socket library.

Signed-off-by: Alexander Jung <alex@unikraft.io>
Signed-off-by: Marc Rittinghaus <marc.rittinghaus@kit.edu>
Reviewed-by: Cezar Craciunoiu <cezar.craciunoiu@gmail.com>
Reviewed-by: Razvan Deaconescu <razvan.deaconescu@cs.pub.ro>
Approved-by: Razvan Deaconescu <razvan.deaconescu@cs.pub.ro>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #65
unikraft-bot pushed a commit that referenced this pull request Aug 16, 2022
This library allows for the registration of socket drivers that
implement the posix_socket_ops interface and thereby expose a
POSIX-compliant socket API for a certain AF address family. Drivers
may register as many AF numbers as desired or specify new families
which are not listed in the <sys/socket.h> header. To access the
relevant implementation, the application simply creates a socket
with the required AF family number.

Signed-off-by: Alexander Jung <alex@unikraft.io>
Signed-off-by: Marc Rittinghaus <marc.rittinghaus@kit.edu>
Reviewed-by: Cezar Craciunoiu <cezar.craciunoiu@gmail.com>
Reviewed-by: Razvan Deaconescu <razvan.deaconescu@cs.pub.ro>
Approved-by: Razvan Deaconescu <razvan.deaconescu@cs.pub.ro>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #65
@unikraft-bot unikraft-bot added the ci/merged Merged by CI label Aug 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/lib Internal Unikraft Microlibrary ci/merged Merged by CI kind/enhancement New feature or request lang/c Issues or PRs to do with C/C++ lib/nolibc Only neccessary subset of libc functionality lib/posix-socket Abstraction for communication sockets new/library This PR or Issue intends to add a new library to Unikraft topic/posix Topics pertaining to POSIX standard
Projects
Status: Done!
Status: Done
Status: review:invalid
Development

Successfully merging this pull request may close these issues.

Support for UNIX domain sockets Socket Support
8 participants