Dibbler - a portable DHCPv6  1.0.2RC1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Portable.h File Reference
#include <stdint.h>
#include <unistd.h>
+ Include dependency graph for Portable.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  iface
struct  link_state_notify_t

Macros

#define ADD_ADDRESSES_WITH_LIFETIMES   0
#define BUFFER_TYPE   char
#define BULKLQ_ACCEPT   false
#define BULKLQ_MAX_CONNS   10
#define BULKLQ_TCP_PORT   547
#define BULKLQ_TIMEOUT   300
#define CLNTADDRMGR_FILE   "client-AddrMgr.xml"
#define CLNTCFGMGR_FILE   "client-CfgMgr.xml"
#define CLNTDUID_FILE   "client-duid"
#define CLNTIFACEMGR_FILE   "client-IfaceMgr.xml"
#define CLNTTRANSMGR_FILE   "client-TransMgr.xml"
#define DEFAULT_UMASK   027
#define DEFAULT_WORKDIR   "/var/lib/dibbler"
#define DIBBLER_COPYRIGHT1   "| Dibbler - a portable DHCPv6, version " DIBBLER_VERSION
#define DIBBLER_COPYRIGHT2   "| Authors : Tomasz Mrugalski<thomson(at)klub.com.pl>,Marek Senderski<msend(at)o2.pl>"
#define DIBBLER_COPYRIGHT3   "| Licence : GNU GPL v2 only. Developed at Gdansk University of Technology."
#define DIBBLER_COPYRIGHT4   "| Homepage: http://klub.com.pl/dhcpv6/"
#define DIBBLER_VERSION   "1.0.2RC1"
#define DNSUPDATE_DEFAULT_TIMEOUT   1000 /* in ms */
#define DNSUPDATE_DEFAULT_TTL   "2h"
#define INACTIVE_MODE_INTERVAL   3 /* 3 seconds */
#define LOWLEVEL_ERROR_BIND_FAILED   -4
#define LOWLEVEL_ERROR_BIND_IFACE   -2
#define LOWLEVEL_ERROR_FILE   -10
#define LOWLEVEL_ERROR_GETADDRINFO   -7
#define LOWLEVEL_ERROR_MCAST_HOPS   -5
#define LOWLEVEL_ERROR_MCAST_MEMBERSHIP   -6
#define LOWLEVEL_ERROR_NOT_IMPLEMENTED   -12
#define LOWLEVEL_ERROR_REUSE_FAILED   -9
#define LOWLEVEL_ERROR_SOCK_OPTS   -8
#define LOWLEVEL_ERROR_SOCKET   -11
#define LOWLEVEL_ERROR_UNSPEC   -1
#define LOWLEVEL_NO_ERROR   0
#define LOWLEVEL_TENTATIVE_DONT_KNOW   -1
#define LOWLEVEL_TENTATIVE_NO   0
#define LOWLEVEL_TENTATIVE_YES   1
#define MAX_IFNAME_LENGTH   255
#define MAX_LINK_STATE_CHANGES_AT_ONCE   16
#define OPTION_DNS_SERVERS_FILENAME   "option-dns-servers"
#define OPTION_DOMAINS_FILENAME   "option-domains"
#define OPTION_NIS_DOMAIN_FILENAME   "option-nis-domain"
#define OPTION_NIS_SERVERS_FILENAME   "option-nis-servers"
#define OPTION_NISP_DOMAIN_FILENAME   "option-nisplus-domain"
#define OPTION_NISP_SERVERS_FILENAME   "option-nisplus-servers"
#define OPTION_NTP_SERVERS_FILENAME   "option-ntp-servers"
#define OPTION_SIP_DOMAINS_FILENAME   "option-sip-domains"
#define OPTION_SIP_SERVERS_FILENAME   "option-sip-servers"
#define OPTION_TIMEZONE_FILENAME   "option-timezone"
#define RELCFGMGR_FILE   "relay-CfgMgr.xml"
#define RELIFACEMGR_FILE   "relay-IfaceMgr.xml"
#define RELTRANSMGR_FILE   "relay-TransMgr.xml"
#define REQIFACEMGR_FILE   "requestor-IfaceMgr.xml"
#define REQLOG_FILE   "dibbler-requestor.log"
#define SRVADDRMGR_FILE   "server-AddrMgr.xml"
#define SRVCACHE_FILE   "server-cache.xml"
#define SRVCFGMGR_FILE   "server-CfgMgr.xml"
#define SRVDUID_FILE   "server-duid"
#define SRVIFACEMGR_FILE   "server-IfaceMgr.xml"
#define SRVTRANSMGR_FILE   "server-TransMgr.xml"

Functions

int dns_add (const char *ifname, int ifindex, const char *addrPlain)
int dns_del (const char *ifname, int ifindex, const char *addrPlain)
int domain_add (const char *ifname, int ifindex, const char *domain)
int domain_del (const char *ifname, int ifindex, const char *domain)
void doRevDnsAddress (char *src, char *dst)
void doRevDnsZoneRoot (char *src, char *dst, int lenght)
char * error_message ()
int execute (const char *filename, const char *argv[], const char *env[])
void fill_random (uint8_t *buffer, int len)
 fills specified buffer with random data
int get_hostname (char *hostname, int hostname_len)
 returns host name of this host
int get_mac_from_ipv6 (const char *iface_name, int ifindex, const char *v6addr, char *mac, int *mac_len)
 gets MAC address from the specified IPv6 address
char * getAAAKey (uint32_t SPI, uint32_t *len)
char * getAAAKeyFilename (uint32_t SPI)
uint32_t getAAASPIfromFile ()
struct ifaceif_list_get ()
void if_list_release (struct iface *list)
char * inet_ntop4 (const char *src, char *dst)
char * inet_ntop6 (const char *src, char *dst)
int inet_pton6 (const char *src, char *dst)
int ipaddr_add (const char *ifacename, int ifindex, const char *addr, unsigned long pref, unsigned long valid, int prefixLength)
int ipaddr_del (const char *ifacename, int ifindex, const char *addr, int prefixLength)
int ipaddr_update (const char *ifacename, int ifindex, const char *addr, unsigned long pref, unsigned long valid, int prefixLength)
int is_addr_tentative (char *ifacename, int iface, char *plainAddr)
void link_state_change_cleanup ()
void link_state_change_init (volatile struct link_state_notify_t *changed_links, volatile int *notify)
int lowlevelExit ()
int lowlevelInit ()
void microsleep (int microsecs)
int nisdomain_del (const char *ifname, int ifindex, const char *domain)
int nisdomain_set (const char *ifname, int ifindex, const char *domain)
int nisplusdomain_del (const char *ifname, int ifindex, const char *domain)
int nisplusdomain_set (const char *ifname, int ifindex, const char *domain)
int nisplusserver_add (const char *ifname, int ifindex, const char *addrPlain)
int nisplusserver_del (const char *ifname, int ifindex, const char *addrPlain)
int nisserver_add (const char *ifname, int ifindex, const char *addrPlain)
int nisserver_del (const char *ifname, int ifindex, const char *addrPlain)
int ntp_add (const char *ifname, int ifindex, const char *addrPlain)
int ntp_del (const char *ifname, int ifindex, const char *addrPlain)
int prefix_add (const char *ifname, int ifindex, const char *prefixPlain, int prefixLength, unsigned long prefered, unsigned long valid)
int prefix_del (const char *ifname, int ifindex, const char *prefixPlain, int prefixLength)
int prefix_update (const char *ifname, int ifindex, const char *prefixPlain, int prefixLength, unsigned long prefered, unsigned long valid)
void print_packed (char addr[])
void print_packed (char *addr)
uint16_t readUint16 (const char *buf)
 reads uint16_t from buffer in a portable way
uint32_t readUint32 (const char *buf)
 reads uint32_t from buffer in a portable way
uint64_t readUint64 (const char *buf)
 reads uint64_t from buffer in a portable way
uint8_t readUint8 (const char *buf)
int sipdomain_add (const char *ifname, int ifindex, const char *domain)
int sipdomain_del (const char *ifname, int ifindex, const char *domain)
int sipserver_add (const char *ifname, int ifindex, const char *addrPlain)
int sipserver_del (const char *ifname, int ifindex, const char *addrPlain)
int sock_add (char *ifacename, int ifaceid, char *addr, int port, int thisifaceonly, int reuse)
int sock_del (int fd)
int sock_recv (int fd, char *myPlainAddr, char *peerPlainAddr, char *buf, int buflen)
int sock_send (int fd, char *addr, char *buf, int buflen, int port, int iface)
int timezone_del (const char *ifname, int ifindex, const char *timezone)
int timezone_set (const char *ifname, int ifindex, const char *timezone)
void truncatePrefixFromConfig (char *src, char *dst, char lenght)
char * writeData (char *buf, char *data, size_t len)
char * writeUint16 (char *buf, uint16_t word)
 stores uint16_t to a buffer in a portable way
char * writeUint32 (char *buf, uint32_t dword)
 stores uint32_t to a buffer in a portable way
char * writeUint64 (char *buf, uint64_t qword)
 stores uint64_t to a buffer in a portable way
char * writeUint8 (char *buf, uint8_t octet)

Macro Definition Documentation

#define ADD_ADDRESSES_WITH_LIFETIMES   0
#define BUFFER_TYPE   char
#define BULKLQ_ACCEPT   false
#define BULKLQ_MAX_CONNS   10
#define BULKLQ_TCP_PORT   547
#define BULKLQ_TIMEOUT   300
#define CLNTADDRMGR_FILE   "client-AddrMgr.xml"
#define CLNTCFGMGR_FILE   "client-CfgMgr.xml"
#define CLNTDUID_FILE   "client-duid"
#define CLNTIFACEMGR_FILE   "client-IfaceMgr.xml"
#define CLNTTRANSMGR_FILE   "client-TransMgr.xml"
#define DEFAULT_UMASK   027
#define DEFAULT_WORKDIR   "/var/lib/dibbler"
#define DIBBLER_COPYRIGHT1   "| Dibbler - a portable DHCPv6, version " DIBBLER_VERSION
#define DIBBLER_COPYRIGHT2   "| Authors : Tomasz Mrugalski<thomson(at)klub.com.pl>,Marek Senderski<msend(at)o2.pl>"
#define DIBBLER_COPYRIGHT3   "| Licence : GNU GPL v2 only. Developed at Gdansk University of Technology."
#define DIBBLER_COPYRIGHT4   "| Homepage: http://klub.com.pl/dhcpv6/"
#define DIBBLER_VERSION   "1.0.2RC1"
#define DNSUPDATE_DEFAULT_TIMEOUT   1000 /* in ms */
#define DNSUPDATE_DEFAULT_TTL   "2h"
#define INACTIVE_MODE_INTERVAL   3 /* 3 seconds */
#define LOWLEVEL_ERROR_BIND_FAILED   -4
#define LOWLEVEL_ERROR_BIND_IFACE   -2
#define LOWLEVEL_ERROR_FILE   -10
#define LOWLEVEL_ERROR_GETADDRINFO   -7
#define LOWLEVEL_ERROR_MCAST_HOPS   -5
#define LOWLEVEL_ERROR_MCAST_MEMBERSHIP   -6
#define LOWLEVEL_ERROR_NOT_IMPLEMENTED   -12
#define LOWLEVEL_ERROR_REUSE_FAILED   -9
#define LOWLEVEL_ERROR_SOCK_OPTS   -8
#define LOWLEVEL_ERROR_SOCKET   -11
#define LOWLEVEL_ERROR_UNSPEC   -1
#define LOWLEVEL_NO_ERROR   0
#define LOWLEVEL_TENTATIVE_DONT_KNOW   -1
#define LOWLEVEL_TENTATIVE_NO   0
#define LOWLEVEL_TENTATIVE_YES   1
#define MAX_IFNAME_LENGTH   255
#define MAX_LINK_STATE_CHANGES_AT_ONCE   16
#define OPTION_DNS_SERVERS_FILENAME   "option-dns-servers"
#define OPTION_DOMAINS_FILENAME   "option-domains"
#define OPTION_NIS_DOMAIN_FILENAME   "option-nis-domain"
#define OPTION_NIS_SERVERS_FILENAME   "option-nis-servers"
#define OPTION_NISP_DOMAIN_FILENAME   "option-nisplus-domain"
#define OPTION_NISP_SERVERS_FILENAME   "option-nisplus-servers"
#define OPTION_NTP_SERVERS_FILENAME   "option-ntp-servers"
#define OPTION_SIP_DOMAINS_FILENAME   "option-sip-domains"
#define OPTION_SIP_SERVERS_FILENAME   "option-sip-servers"
#define OPTION_TIMEZONE_FILENAME   "option-timezone"
#define RELCFGMGR_FILE   "relay-CfgMgr.xml"
#define RELIFACEMGR_FILE   "relay-IfaceMgr.xml"
#define RELTRANSMGR_FILE   "relay-TransMgr.xml"
#define REQIFACEMGR_FILE   "requestor-IfaceMgr.xml"
#define REQLOG_FILE   "dibbler-requestor.log"
#define SRVADDRMGR_FILE   "server-AddrMgr.xml"
#define SRVCACHE_FILE   "server-cache.xml"
#define SRVCFGMGR_FILE   "server-CfgMgr.xml"
#define SRVDUID_FILE   "server-duid"
#define SRVIFACEMGR_FILE   "server-IfaceMgr.xml"
#define SRVTRANSMGR_FILE   "server-TransMgr.xml"

Function Documentation

int dns_add ( const char *  ifname,
int  ifindex,
const char *  addrPlain 
)
int dns_del ( const char *  ifname,
int  ifindex,
const char *  addrPlain 
)
int domain_add ( const char *  ifname,
int  ifindex,
const char *  domain 
)
int domain_del ( const char *  ifname,
int  ifindex,
const char *  domain 
)
void doRevDnsAddress ( char *  src,
char *  dst 
)

converts packed address to a reverse string used in DNS Updates

Parameters
src- packed address
dst- output buffer (e.g. 1.2.3.0.0.0.0.0.0.0.0.0.0.e.f.f.3.ip6.arpa)
void doRevDnsZoneRoot ( char *  src,
char *  dst,
int  length 
)

function converts address to a DNS zone root with specified length

Parameters
src- packed address, e.g. 3ffe::123
dst- dns zone root, e.g. 0.0.0.0.e.f.f.3.ip6.arpa
length- zone length, e.g. 96
Todo:
: what to do with prefixes which do not divide by 4?
char* error_message ( )
int execute ( const char *  filename,
const char *  argv[],
const char *  env[] 
)
void fill_random ( uint8_t *  buffer,
int  len 
)

fills specified buffer with random data

Parameters
bufferrandom data will be written here
lenlength of the buffer
int get_hostname ( char *  hostname,
int  hostname_len 
)

returns host name of this host

Parameters
hostnamebuffer (hostname will be stored here)
hostname_lenlength of the buffer
Returns
LOWLEVEL_NO_ERROR if successful, appropriate LOWLEVEL_ERROR_* otherwise
int get_mac_from_ipv6 ( const char *  iface_name,
int  ifindex,
const char *  v6addr,
char *  mac,
int *  mac_len 
)

gets MAC address from the specified IPv6 address

This is called immediately after we received message from that address, so the neighbor cache is guaranteed to have entry for it. This is highly os specific

Parameters
iface_namenetwork interface name
ifindexnetwork interface index
v6addrtext represenation of the IPv6 address
macpointer to MAC buffer (length specified in mac_len)
mac_lenspecifies MAC buffer length. Must be set so number of bytes set by the function
Returns
0 if successful, negative values if there are errors
Todo:
: Implement this for BSD see "/usr/sbin/ndp -a -n"
Todo:
: Implement this for Linux see "/sbin/ip -6 neigh"
Todo:
: Implement this for Solaris
char* getAAAKey ( uint32_t  SPI,
uint32_t len 
)
char* getAAAKeyFilename ( uint32_t  SPI)
uint32_t getAAASPIfromFile ( )
struct iface* if_list_get ( )
read
Todo:
: Ugly workaround. Please remove one BSD guys fix their kernel.
void if_list_release ( struct iface list)
char* inet_ntop4 ( const char *  src,
char *  dst 
)
char* inet_ntop6 ( const char *  src,
char *  dst 
)
int inet_pton6 ( const char *  src,
char *  dst 
)
int ipaddr_add ( const char *  ifacename,
int  ifindex,
const char *  addr,
unsigned long  pref,
unsigned long  valid,
int  prefixLength 
)
int ipaddr_del ( const char *  ifacename,
int  ifindex,
const char *  addr,
int  prefixLength 
)
int ipaddr_update ( const char *  ifacename,
int  ifindex,
const char *  addr,
unsigned long  pref,
unsigned long  valid,
int  prefixLength 
)
Todo:
: implement this
Todo:
: Linux kernel currently does not provide API for dynamic addresses
Todo:
: implement this
int is_addr_tentative ( char *  ifacename,
int  iface,
char *  plainAddr 
)
Todo:
: implement this
Todo:
: implement this
void link_state_change_cleanup ( )

cleanup code for link state monitoring

void link_state_change_init ( volatile struct link_state_notify_t monitored_links,
volatile int *  notify 
)

begin link monitoring

Parameters
monitored_linkshead of the monitored links list
notifypointer to variable that is going to be modifed if change is detected
int lowlevelExit ( )
int lowlevelInit ( )
void microsleep ( int  microsecs)
int nisdomain_del ( const char *  ifname,
int  ifindex,
const char *  domain 
)
int nisdomain_set ( const char *  ifname,
int  ifindex,
const char *  domain 
)
int nisplusdomain_del ( const char *  ifname,
int  ifindex,
const char *  domain 
)
int nisplusdomain_set ( const char *  ifname,
int  ifindex,
const char *  domain 
)
int nisplusserver_add ( const char *  ifname,
int  ifindex,
const char *  addrPlain 
)
int nisplusserver_del ( const char *  ifname,
int  ifindex,
const char *  addrPlain 
)
int nisserver_add ( const char *  ifname,
int  ifindex,
const char *  addrPlain 
)
int nisserver_del ( const char *  ifname,
int  ifindex,
const char *  addrPlain 
)
int ntp_add ( const char *  ifname,
int  ifindex,
const char *  addrPlain 
)
int ntp_del ( const char *  ifname,
int  ifindex,
const char *  addrPlain 
)
int prefix_add ( const char *  ifname,
int  ifindex,
const char *  prefixPlain,
int  prefixLength,
unsigned long  prefered,
unsigned long  valid 
)

adds prefix - if this node has IPv6 forwarding disabled, it will configure that prefix on the interface, which prefix has been received on. If the forwarding is enabled, it will be assigned to all other up, running and multicast capable interfaces. In both cases, radvd.conf file will be created.

Parameters
ifnameinterface name
ifindexinterface index
prefixPlainprefix (specified in human readable format)
prefixLengthprefix length
preferedpreferred lifetime
validvalid lifetime
Returns
negative error code or 0 if successful
Todo:
: implement this
Todo:
: implement this
int prefix_del ( const char *  ifname,
int  ifindex,
const char *  prefixPlain,
int  prefixLength 
)
Todo:
: implement this
Todo:
: implement this
int prefix_update ( const char *  ifname,
int  ifindex,
const char *  prefixPlain,
int  prefixLength,
unsigned long  prefered,
unsigned long  valid 
)
Todo:
: implement this
Todo:
: implement this
void print_packed ( char  addr[])
void print_packed ( char *  addr)
uint16_t readUint16 ( const char *  buf)

reads uint16_t from buffer in a portable way

Buffer must be at least 2 bytes long.

Parameters
bufpointer to first byte of buffer
Returns
read 16-bits value
uint32_t readUint32 ( const char *  buf)

reads uint32_t from buffer in a portable way

Buffer must be at least 4 bytes long.

Parameters
bufpointer to first address of buffer
Returns
read value
uint64_t readUint64 ( const char *  buf)

reads uint64_t from buffer in a portable way

Buffer must be at least 8 bytes long.

Parameters
bufpointer to first address of buffer
Returns
read value
uint8_t readUint8 ( const char *  buf)
int sipdomain_add ( const char *  ifname,
int  ifindex,
const char *  domain 
)
int sipdomain_del ( const char *  ifname,
int  ifindex,
const char *  domain 
)
int sipserver_add ( const char *  ifname,
int  ifindex,
const char *  addrPlain 
)
int sipserver_del ( const char *  ifname,
int  ifindex,
const char *  addrPlain 
)
int sock_add ( char *  ifacename,
int  ifaceid,
char *  addr,
int  port,
int  thisifaceonly,
int  reuse 
)
int sock_del ( int  fd)
int sock_recv ( int  fd,
char *  myPlainAddr,
char *  peerPlainAddr,
char *  buf,
int  buflen 
)
int sock_send ( int  fd,
char *  addr,
char *  buf,
int  buflen,
int  port,
int  iface 
)
int timezone_del ( const char *  ifname,
int  ifindex,
const char *  timezone 
)
int timezone_set ( const char *  ifname,
int  ifindex,
const char *  timezone 
)
void truncatePrefixFromConfig ( char *  src,
char *  dst,
char  lenght 
)
char* writeData ( char *  buf,
char *  data,
size_t  len 
)
char* writeUint16 ( char *  buf,
uint16_t  word 
)

stores uint16_t to a buffer in a portable way

Buffer must be at least 2 bytes long.

Parameters
bufpointer to first byte of buffer
word16-bits value to be stored
Returns
pointer to the next byte after stored value
char* writeUint32 ( char *  buf,
uint32_t  dword 
)

stores uint32_t to a buffer in a portable way

Buffer must be at least 4 bytes long.

Parameters
bufpointer to first byte of buffer
dword32-bits value to be stored
Returns
pointer to the next byte after stored value
char* writeUint64 ( char *  buf,
uint64_t  qword 
)

stores uint64_t to a buffer in a portable way

Buffer must be at least 8 bytes long.

Parameters
bufpointer to first byte of buffer
qword64-bits value to be stored
Returns
pointer to the next byte after stored value
char* writeUint8 ( char *  buf,
uint8_t  octet 
)