PatchworkOS  1731ea3
A non-POSIX operating system.
Loading...
Searching...
No Matches
Networking Filesystem

Networking and Sockets. More...

Collaboration diagram for Networking Filesystem:

Detailed Description

Networking and Sockets.

The networking filesystem provides networking and socket IPC functionality to the operating system. It exposes a common interface for various networking protocols and inter-process communication (IPC) mechanisms.

Network Families

Network families represent different networking protocols or IPC mechanisms. Each family has its own directory in the filesystem, named after the family.

Each family directory contains factory files for creating sockets of different types, including stream, dgram, seqpacket, raw, and rdm.

Additionally, there is an addrs file that lists the addresses of all listening sockets within that family in the format:

int64_t y
Definition main.c:153
static uintptr_t address
Mapped virtual address of the HPET registers.
Definition hpet.c:95

Sockets

Sockets are created by opening a factory file, named after the socket type it will create, located in each socket family's directory. Once a socket is created, it will persist until the namespace that created it is destroyed and there are no more references to it.

For example, to create a local seqpacket socket, open the /local/seqpacket file. This returns a handle that when read returns the socket's ID, which corresponds to the path /<family_name>/<socket_id>/, for example /local/1234/, which stores the files used to interact with the socket.

The socket directory will only be visible in the namespace that created it.

The files used to interact with sockets are listed below.

accept

The /<family_name>/<socket_id>/accept file can be opened on a listening socket to accept incoming connections. Working in an similar way to the POSIX accept() function, the returned file descriptor represents the new connection.

If opened with :nonblock and there are no incoming connections, the open will fail with EAGAIN, otherwise it will block until a connection is available.

ctl

The /<family_name>/<socket_id>/ctl file is used to send "commands" to the socket by writing to it. Here is a list of supported commands:

data

The /<family_name>/<socket_id>/data file is used to send and receive data using the socket. Writing to this file sends data, reading from it receives data. (POSIX send() and recv() functions)

If opened with :nonblock, read and write operations will fail with EAGAIN if no data is available or there is no buffer space available, respectively. If not opened with :nonblock they will block, waiting for data or buffer space.

Data Structures

struct  socket_t
 Socket structure. More...
 
struct  netfs_family_t
 Socket Family structure. More...
 

Macros

#define NETFS_NAME   "netfs"
 The name of the networking filesystem.
 
#define NETFS_BACKLOG_DEFAULT   128
 The default backlog size for listening sockets.
 

Enumerations

enum  socket_type_t {
  SOCKET_STREAM = 1 << 0 , SOCKET_DGRAM = 1 << 1 , SOCKET_SEQPACKET = 1 << 2 , SOCKET_RAW = 1 << 3 ,
  SOCKET_RDM = 1 << 4 , SOCKET_TYPE_AMOUNT = 5
}
 Socket types. More...
 
enum  socket_state_t {
  SOCKET_NEW , SOCKET_BOUND , SOCKET_LISTENING , SOCKET_CONNECTING ,
  SOCKET_CONNECTED , SOCKET_CLOSING , SOCKET_CLOSED
}
 Socket states. More...
 

Functions

void netfs_init (void)
 Initialize the networking filesystem.
 
uint64_t netfs_family_register (netfs_family_t *family)
 Register a network family.
 
void netfs_family_unregister (netfs_family_t *family)
 Unregister a network family.
 

Macro Definition Documentation

◆ NETFS_NAME

#define NETFS_NAME   "netfs"

The name of the networking filesystem.

Definition at line 85 of file netfs.h.

◆ NETFS_BACKLOG_DEFAULT

#define NETFS_BACKLOG_DEFAULT   128

The default backlog size for listening sockets.

Definition at line 90 of file netfs.h.

Enumeration Type Documentation

◆ socket_type_t

Socket types.

Enumerator
SOCKET_STREAM 

A sequenced, reliable, two-way connection-based byte stream.

SOCKET_DGRAM 

A connectionless, unreliable datagram service.

SOCKET_SEQPACKET 

A sequenced, reliable, two-way connection-based packet stream.

SOCKET_RAW 

Provides raw network protocol access.

SOCKET_RDM 

A reliable datagram layer that does not guarantee ordering.

SOCKET_TYPE_AMOUNT 

Definition at line 96 of file netfs.h.

◆ socket_state_t

Socket states.

Enumerator
SOCKET_NEW 
SOCKET_BOUND 
SOCKET_LISTENING 
SOCKET_CONNECTING 
SOCKET_CONNECTED 
SOCKET_CLOSING 
SOCKET_CLOSED 

Definition at line 110 of file netfs.h.

Function Documentation

◆ netfs_init()

void netfs_init ( void  )

Initialize the networking filesystem.

Definition at line 805 of file netfs.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ netfs_family_register()

uint64_t netfs_family_register ( netfs_family_t family)

Register a network family.

Parameters
familyPointer to the network family structure.
Returns
On success, 0. On failure, ERR and errno is set.

Definition at line 813 of file netfs.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ netfs_family_unregister()

void netfs_family_unregister ( netfs_family_t family)

Unregister a network family.

Parameters
familyPointer to the network family structure.

Definition at line 832 of file netfs.c.

Here is the call graph for this function:
Here is the caller graph for this function: