Network Block Device  @PACKAGE_VERSION@
Macros | Functions
nbdsrv.c File Reference
#include "config.h"
#include "nbd-debug.h"
#include <nbdsrv.h>
#include <assert.h>
#include <ctype.h>
#include <netdb.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <syslog.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <cliserv.h>

Go to the source code of this file.

Macros

#define LINELEN   256
 Size of static buffer used to read the authorization file (yuck) 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)
 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 LINELEN   256

Size of static buffer used to read the authorization file (yuck)

Definition at line 19 of file nbdsrv.c.

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().