Network Block Device  @PACKAGE_VERSION@
Data Structures | Macros | Enumerations | Functions
nbdsrv.h File Reference
#include "lfs.h"
#include <glib.h>
#include <stdbool.h>
#include <stdint.h>
#include <sys/socket.h>
#include <sys/types.h>

Go to the source code of this file.

Data Structures

struct  SERVER
 Variables associated with a server. More...
 
struct  CLIENT
 Variables associated with a client connection. More...
 

Macros

#define NBDS_ERR   g_quark_from_static_string("server-error-quark")
 Error domain common for all NBD server errors. More...
 
#define msg(prio,...)   g_log(G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, __VA_ARGS__)
 Logging macros. More...
 
#define MY_NAME   "nbd_server"
 

Enumerations

enum  VIRT_STYLE { VIRT_NONE =0, VIRT_IPLIT, VIRT_IPHASH, VIRT_CIDR }
 Types of virtuatlization. More...
 
enum  NBDS_ERRS {
  NBDS_ERR_CFILE_NOTFOUND, NBDS_ERR_CFILE_MISSING_GENERIC, NBDS_ERR_CFILE_KEY_MISSING, NBDS_ERR_CFILE_VALUE_INVALID,
  NBDS_ERR_CFILE_VALUE_UNSUPPORTED, NBDS_ERR_CFILE_NO_EXPORTS, NBDS_ERR_CFILE_INCORRECT_PORT, NBDS_ERR_CFILE_DIR_UNKNOWN,
  NBDS_ERR_CFILE_READDIR_ERR, NBDS_ERR_SO_LINGER, NBDS_ERR_SO_REUSEADDR, NBDS_ERR_SO_KEEPALIVE,
  NBDS_ERR_GAI, NBDS_ERR_SOCKET, NBDS_ERR_BIND, NBDS_ERR_LISTEN,
  NBDS_ERR_SYS
}
 NBD server error codes. More...
 

Functions

bool address_matches (const char *mask, const struct sockaddr *addr, GError **err)
 Check whether a given address matches a given netmask. More...
 
uint8_t getmaskbyte (int masklen) G_GNUC_PURE
 Gets a byte to allow for address masking. More...
 
int authorized_client (CLIENT *opts)
 Check whether a client is allowed to connect. More...
 
SERVERdup_serve (const SERVER *const s)
 duplicate server More...
 
int append_serve (const SERVER *const s, GArray *const a)
 append new server to array More...
 
uint64_t size_autodetect (int fhandle)
 Detect the size of a file. More...
 

Macro Definition Documentation

#define msg (   prio,
  ... 
)    g_log(G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, __VA_ARGS__)

Logging macros.

Todo:
remove this. We should use g_log in all cases, and use the logging mangler to redirect to syslog if and when necessary.

Definition at line 117 of file nbdsrv.h.

Referenced by authorized_client(), copyonwrite_prepare(), handle_modern_connection(), handle_oldstyle_connection(), mainloop(), serveloop(), set_peername(), setup_servers(), setupexport(), and spawn_child().

#define MY_NAME   "nbd_server"

Definition at line 119 of file nbdsrv.h.

#define NBDS_ERR   g_quark_from_static_string("server-error-quark")

Error domain common for all NBD server errors.

Definition at line 81 of file nbdsrv.h.

Referenced by do_cfile_dir(), dosockopts(), main(), open_modern(), open_unix(), parse_cfile(), and setup_serve().

Enumeration Type Documentation

enum NBDS_ERRS

NBD server error codes.

Enumerator
NBDS_ERR_CFILE_NOTFOUND 

The configuration file is not found.

NBDS_ERR_CFILE_MISSING_GENERIC 

The (required) group "generic" is missing.

NBDS_ERR_CFILE_KEY_MISSING 

A (required) key is missing.

NBDS_ERR_CFILE_VALUE_INVALID 

A value is syntactically invalid.

NBDS_ERR_CFILE_VALUE_UNSUPPORTED 

A value is not supported in this build.

NBDS_ERR_CFILE_NO_EXPORTS 

A config file was specified that does not define any exports.

NBDS_ERR_CFILE_INCORRECT_PORT 

The reserved port was specified for an old-style export.

NBDS_ERR_CFILE_DIR_UNKNOWN 

A directory requested does not exist.

NBDS_ERR_CFILE_READDIR_ERR 

Error occurred during readdir()

NBDS_ERR_SO_LINGER 

Failed to set SO_LINGER to a socket.

NBDS_ERR_SO_REUSEADDR 

Failed to set SO_REUSEADDR to a socket.

NBDS_ERR_SO_KEEPALIVE 

Failed to set SO_KEEPALIVE to a socket.

NBDS_ERR_GAI 

Failed to get address info.

NBDS_ERR_SOCKET 

Failed to create a socket.

NBDS_ERR_BIND 

Failed to bind an address to socket.

NBDS_ERR_LISTEN 

Failed to start listening on a socket.

NBDS_ERR_SYS 

Underlying system call or library error.

Definition at line 86 of file nbdsrv.h.

enum VIRT_STYLE

Types of virtuatlization.

Enumerator
VIRT_NONE 

No virtualization.

VIRT_IPLIT 

Literal IP address as part of the filename.

VIRT_IPHASH 

Replacing all dots in an ip address by a / before doing the same as in IPLIT.

VIRT_CIDR 

Every subnet in its own directory.

Definition at line 18 of file nbdsrv.h.

Function Documentation

bool address_matches ( const char *  mask,
const struct sockaddr *  addr,
GError **  err 
)

Check whether a given address matches a given netmask.

Parameters
maskthe address or netmask to check against, in ASCII representation
addrthe address to check
Returns
true if the address matches the mask, false otherwise; in case of failure to parse netmask, returns false with err set appropriately.
Todo:
decide what to do with v6-mapped IPv4 addresses.

Definition at line 25 of file nbdsrv.c.

int append_serve ( const SERVER *const  s,
GArray *const  a 
)

append new server to array

Parameters
sserver
aserver array
Returns
0 success, -1 error

Definition at line 192 of file nbdsrv.c.

Referenced by append_new_servers(), main(), and parse_cfile().

int authorized_client ( CLIENT opts)

Check whether a client is allowed to connect.

Works with an authorization file which contains one line per machine or network, with CIDR-style netmasks.

Parameters
optsThe client who's trying to connect.
Returns
0 - authorization refused, 1 - OK

Definition at line 105 of file nbdsrv.c.

References msg.

Referenced by handle_modern_connection(), and handle_oldstyle_connection().

SERVER* dup_serve ( const SERVER *const  s)

duplicate server

Parameters
sthe old server we want to duplicate
Returns
new duplicated server

Definition at line 149 of file nbdsrv.c.

uint8_t getmaskbyte ( int  masklen)

Gets a byte to allow for address masking.

Parameters
masklenthe length of the requested mask.
Returns
if the length of the mask is 8 or longer, 0xFF. Otherwise, a byte with `masklen' number of leading bits set to 1, everything else set to 0.

Definition at line 93 of file nbdsrv.c.

Referenced by set_peername().

uint64_t size_autodetect ( int  fhandle)

Detect the size of a file.

Parameters
fhandleAn open filedescriptor
Returns
the size of the file, or UINT64_MAX if detection was impossible.

Definition at line 252 of file nbdsrv.c.

Referenced by setupexport().