lcrzo_conf(3)

NAME
lcrzo_conf - lcrzo library : configuration (arp, devices, routes)

CONTENTS
/*    Laurent Constantin's network library (lcrzo)
                 lcrzo_conf module
  Functions herein obtains configuration of the local computer.
*/
/*-------------------------------------------------------------*/
/***************************************************************
 * Note about lcrzo_conf :                                     *
 * Configuration obtained by this module is a copy of the      *
 * configuration of the local computer. Then the user can      *
 * modify it using "xx_add" and "xx_del" functions : the       *
 * configuration of lcrzo is modified, but not the             *
 * configuration of the computer.                              *
 * For examples the configuration of the local computer can    *
 * be (obtained with lcrzo_conf_print) :                       */
/*
Devices
  device  ethernet          ip          /netmask        mtu
  lo      loopback          127.0.0.1   /255.0.0.0      3924 up
  eth0    00:00:33:AC:C2:24 192.168.1.1 /255.255.255.0  1500 up
  eth0:1  00:00:33:AC:C2:24 192.168.2.1 /255.255.255.0  1500 up,alias
  eth1    00:00:43:BC:D2:34 192.168.3.1 /255.255.255.0  1500 up
Arp
  eth0    00:00:33:AC:C2:24 192.168.1.1   (permanent)
  eth0:1  00:00:33:AC:C2:24 192.168.2.1   (permanent)
  eth1    00:00:43:BC:D2:34 192.168.3.1   (permanent)
  eth0    12:34:56:78:90:ab 192.168.1.254 (-1s)
Routes
  device  destination  /netmask         ip_source     gateway
  lo      127.0.0.1    /255.255.255.255 local_device                 0,up
  eth0    192.168.1.1  /255.255.255.255 local_device                 0,up
  eth0:1  192.168.2.1  /255.255.255.255 local_device                 0,up
  eth1    192.168.3.1  /255.255.255.255 local_device                 0,up
  eth0    192.168.1.0  /255.255.255.0   192.168.1.1                  0,up
  eth0:1  192.168.2.0  /255.255.255.0   192.168.2.1                  0,up
  eth1    192.168.3.0  /255.255.255.0   192.168.3.1                  0,up
  lo      127.0.0.0    /255.0.0.0       127.0.0.1                    0,up
  eth0    0.0.0.0      /0.0.0.0         192.168.1.1   192.168.1.254  0,up
 ***************************************************************/
/***************************************************************
 * Functions lcrzo_conf_xxx_del_system permit to remove        *
 * unwanted configuration of the local system. For example,    *
 *  before :                                                   *
 *    device eth0...                                           *
 *    device eth1...                                           *
 *  after lcrzo_conf_device_del_system("eth0", ...)            *
 *    device eth1...                                           *
 *                                                             *
 * Functions lcrzo_conf_xxx_add_user permit to add             *
 * a user configuration which can be prioritary (or not) over  *
 * system configuration. For example,                          *
 *  before :                                                   *
 *    device eth0 a...                                         *
 *    device eth1 b...                                         *
 *  after lcrzo_conf_devices_add_user(TRUE, "eth0", c...) and  *
 *  lcrzo_conf_devices_add_user(FALSE, "eth1", d...)           *
 *    device eth0 c...                                         *
 *    device eth1 b... (do not see user'choice because FALSE)  *
 *                                                             *
 * Functions lcrzo_conf_xxx_del_user permit to remove an       *
 * user added configuration.                                   *
 ***************************************************************/
/*-------------------------------------------------------------*/
/* Name : lcrzo_conf_fprint
   Description :
     Print the configuration of lcrzo.
   Input parameter(s) :
     *pf : FILE where the function prints
   Input/output parameter(s) :
   Output parameter(s) :
   Normal return values :
     LCRZO_ERR_OK : ok
*/
int lcrzo_conf_fprint(LCRZOFILE *pf);
#define lcrzo_conf_print() lcrzo_conf_fprint(stdout)
/*-------------------------------------------------------------*/
/* Hardware types */
#define LCRZO_DEVICE_HWTYPE_UNKNOWN      0
#define LCRZO_DEVICE_HWTYPE_UNKNOWN_txt  "unknown"
#define LCRZO_DEVICE_HWTYPE_ETHER        1
#define LCRZO_DEVICE_HWTYPE_ETHER_txt    "ethernet"
#define LCRZO_DEVICE_HWTYPE_LOOPBACK     2
#define LCRZO_DEVICE_HWTYPE_LOOPBACK_txt "loopback"
#define LCRZO_DEVICE_HWTYPE_PPP          3
#define LCRZO_DEVICE_HWTYPE_PPP_txt      "ppp"
#define LCRZO_DEVICE_HWTYPE_PLIP         4
#define LCRZO_DEVICE_HWTYPE_PLIP_txt     "plip"
#define LCRZO_DEVICE_HWTYPE_SLIP         5
#define LCRZO_DEVICE_HWTYPE_SLIP_txt     "slip"
/*-------------------------------------------------------------*/
/* Name : lcrzo_conf_devices_add_user
   Description :
     Add a device to the configuration of lcrzo.
   Input parameter(s) :
     priorityoversystem : if this configuration is prioritary
                          over the system configuration
     device : device name
     etha : associated Ethernet address
     ipl : associated IP address
     netmask : associated netmask
     mtu : associated mtu
     isup : if this device is up
     isanalias : if this device is an alias
   Input/output parameter(s) :
   Output parameter(s) :
   Normal return values :
     LCRZO_ERR_OK : ok
*/
int lcrzo_conf_devices_add_user(lcrzo_bool priorityoversystem,
                                lcrzo_constdevice device,
				lcrzo_int16 hwtype,
			        lcrzo_constetha etha,
			        lcrzo_ipl ipl,
			        lcrzo_ipl netmask,
			        lcrzo_uint32 mtu,
			        lcrzo_bool isup,
			        lcrzo_bool isanalias,
				lcrzo_bool ispointtopoint,
				lcrzo_ipl pointtopointipl);
/* Name : lcrzo_conf_devices_del_xxx
   Description :
     Delete a device from the configuration (system or user)
     of lcrzo.
   Input parameter(s) :
     device : device name to delete
     etha : associated Ethernet address
     ipl : associated IP address
   Input/output parameter(s) :
   Output parameter(s) :
   Normal return values :
     LCRZO_ERR_OK : ok
*/
int lcrzo_conf_devices_del_system(lcrzo_constdevice device,
				  lcrzo_int16 hwtype,
			          lcrzo_constetha etha,
			          lcrzo_ipl ipl);
int lcrzo_conf_devices_del_user(lcrzo_constdevice device,
				lcrzo_int16 hwtype,
				lcrzo_constetha etha,
			        lcrzo_ipl ipl);
/* Name : lcrzo_conf_devices_count
   Description :
     Count the number of devices
   Input parameter(s) :
   Input/output parameter(s) :
   Output parameter(s) :
     *pcount : number of devices
   Normal return values :
     LCRZO_ERR_OK : ok
*/
int lcrzo_conf_devices_count(lcrzo_int32 *pcount);
/**********************************************
 * Note about positions :                     *
 * Warning : 0 is an invalid value            *
 * Here are possible values for a position :  *
 *  +1 : first item                           *
 *  +2 : second item                          *
 *  ...                                       *
 * Moreover, we can count from the end :      *
 *  -1 : last item                            *
 *  -2 : last but one item                    *
 *  ...                                       *
 **********************************************/
/* Name : lcrzo_conf_devices_value_pos
   Description :
     Get the device located at the wanted position
   Input parameter(s) :
     pos : position of the wanted device (cf. the above frame to
           know possible values)
   Input/output parameter(s) :
   Output parameter(s) :
     device : device name
     etha : associated Ethernet address
     *pipl : associated IP address
     *pnetmask : associated netmask
     *pmtu : associated mtu
     *pisup : if this device is up
     *pisanalias : if this device is an alias
   Normal return values :
     LCRZO_ERR_OK : ok
*/
int lcrzo_conf_devices_value_pos(lcrzo_int32 pos,
				 lcrzo_device device,
				 lcrzo_int16 *phwtype,
				 lcrzo_etha etha,
				 lcrzo_ipl *pipl,
				 lcrzo_ipl *pnetmask,
				 lcrzo_uint32 *pmtu,
				 lcrzo_bool *pisup,
				 lcrzo_bool *pisanalias,
				 lcrzo_bool *pispointtopoint,
				 lcrzo_ipl *ppointtopointipl);
/* Name : lcrzo_conf_devices_fprint
   Description :
     Print the configuration of devices of lcrzo.
   Input parameter(s) :
     *pf : FILE where the function prints
   Input/output parameter(s) :
   Output parameter(s) :
   Normal return values :
     LCRZO_ERR_OK : ok
*/
int lcrzo_conf_devices_fprint(LCRZOFILE *pf);
#define lcrzo_conf_devices_print() lcrzo_conf_devices_fprint(stdout)
/*-------------------------------------------------------------*/
/* Name : lcrzo_conf_arp_add_user
   Description :
     Add an arp entry to the configuration of lcrzo.
   Input parameter(s) :
     priorityoversystem : if this configuration is prioritary
                          over the system configuration
     device : device name
     etha : Ethernet address
     ipl : IP address
     ispermanent : if this arp entry is permanent
   Input/output parameter(s) :
   Output parameter(s) :
   Normal return values :
     LCRZO_ERR_OK : ok
*/
int lcrzo_conf_arp_add_user(lcrzo_bool priorityoversystem,
                            lcrzo_constdevice device,
		            lcrzo_constetha etha,
		            lcrzo_ipl ipl,
		            lcrzo_bool ispermanent);
/* Name : lcrzo_conf_arp_del_xxx
   Description :
     Delete an arp entry from the configuration (system or user)
     of lcrzo.
   Input parameter(s) :
     device : device name
     etha : Ethernet address
     ipl : IP address
   Input/output parameter(s) :
   Output parameter(s) :
   Normal return values :
     LCRZO_ERR_OK : ok
*/
int lcrzo_conf_arp_del_system(lcrzo_constdevice device,
		              lcrzo_constetha etha,
		              lcrzo_ipl ipl);
int lcrzo_conf_arp_del_user(lcrzo_constdevice device,
		            lcrzo_constetha etha,
		            lcrzo_ipl ipl);
/* Name : lcrzo_conf_arp_count
   Description :
     Count the number of arp entries
   Input parameter(s) :
   Input/output parameter(s) :
   Output parameter(s) :
     *pcount : number of entries
   Normal return values :
     LCRZO_ERR_OK : ok
*/
int lcrzo_conf_arp_count(lcrzo_int32 *pcount);
/* Name : lcrzo_conf_arp_value_pos
   Description :
     Get the arp entry located at the wanted position
   Input parameter(s) :
     pos : position of the wanted arp entry
   Input/output parameter(s) :
   Output parameter(s) :
     device : device name
     etha : Ethernet address
     *pipl : IP address
     *pispermanent : if this arp entry is permanent
     *ptimeset : time to which this arp entry was set
   Normal return values :
     LCRZO_ERR_OK : ok
*/
int lcrzo_conf_arp_value_pos(lcrzo_int32 pos,
			     lcrzo_device device,
			     lcrzo_etha etha,
			     lcrzo_ipl *pipl,
			     lcrzo_bool *pispermanent,
			     lcrzo_uint32 *ptimeset);
/* Name : lcrzo_conf_arp_fprint
   Description :
     Print the arp configuration of lcrzo.
   Input parameter(s) :
     *pf : FILE where the function prints
   Input/output parameter(s) :
   Output parameter(s) :
   Normal return values :
     LCRZO_ERR_OK : ok
*/
int lcrzo_conf_arp_fprint(LCRZOFILE *pf);
#define lcrzo_conf_arp_print() lcrzo_conf_arp_fprint(stdout)
/*-------------------------------------------------------------*/
/* Name : lcrzo_conf_routes_add_user
   Description :
     Add a route to the configuration of lcrzo.
   Input parameter(s) :
     priorityoversystem : if this configuration is prioritary
                          over the system configuration
     device : device name
     dest/mask : IP address/netmask
     ipsource : source IP address to use (if 0, local device)
     gateway : gateway to use (if 0, dest is on LAN)
     isup : if this route is up
   Input/output parameter(s) :
   Output parameter(s) :
   Normal return values :
     LCRZO_ERR_OK : ok
*/
int lcrzo_conf_routes_add_user(lcrzo_bool priorityoversystem,
                               lcrzo_constdevice device,
			       lcrzo_ipl dest,
			       lcrzo_ipl mask,
			       lcrzo_ipl ipsource,
			       lcrzo_ipl gateway,
                               lcrzo_uint32 metric,
			       lcrzo_bool isup);
/* Name : lcrzo_conf_routes_del_xxx
   Description :
     Delete a route from the configuration (system or user)
     of lcrzo.
   Input parameter(s) :
     dest/mask : IP address/mask of the route
   Input/output parameter(s) :
   Output parameter(s) :
   Normal return values :
     LCRZO_ERR_OK : ok
*/
int lcrzo_conf_routes_del_system(lcrzo_ipl dest,
			         lcrzo_ipl mask,
			         lcrzo_ipl gateway);
int lcrzo_conf_routes_del_user(lcrzo_ipl dest,
			       lcrzo_ipl mask,
			       lcrzo_ipl gateway);
/* Name : lcrzo_conf_routes_count
   Description :
     Count the number of routes
   Input parameter(s) :
   Input/output parameter(s) :
   Output parameter(s) :
     *pcount : number of routes
   Normal return values :
     LCRZO_ERR_OK : ok
*/
int lcrzo_conf_routes_count(lcrzo_int32 *pcount);
/* Name : lcrzo_conf_routes_value_pos
   Description :
     Get the route located at the wanted position
   Input parameter(s) :
     pos : position of the wanted route
   Input/output parameter(s) :
   Output parameter(s) :
     device : device name
     *pdest : IP address
     *pmask : netmask
     *pipsource : source IP address to use
     *pgateway : gateway to use
     *pisup : if this route is up
   Normal return values :
     LCRZO_ERR_OK : ok
*/
int lcrzo_conf_routes_value_pos(lcrzo_int32 pos,
				lcrzo_device device,
				lcrzo_ipl *pdest,
				lcrzo_ipl *pmask,
				lcrzo_ipl *pipsource,
				lcrzo_ipl *pgateway,
                                lcrzo_uint32 *pmetric,
				lcrzo_bool *pisup);
/* Name : lcrzo_conf_routes_fprint
   Description :
     Print the routing configuration of lcrzo.
   Input parameter(s) :
     *pf : FILE where the function prints
   Input/output parameter(s) :
   Output parameter(s) :
   Normal return values :
     LCRZO_ERR_OK : ok
*/
int lcrzo_conf_routes_fprint(LCRZOFILE *pf);
#define lcrzo_conf_routes_print() lcrzo_conf_routes_fprint(stdout)
/*-------------------------------------------------------------*/
/***************************************************************
 * Note about the following functions :                         *
 * The default values are correct for most applications.       *
 * You should modify their parameters only if you know         *
 * what you are doing.                                         *
 ***************************************************************/
/* to allow the update of the configuration */
int lcrzo_conf_set_sysrenew_allow(lcrzo_bool yes);
int lcrzo_conf_set_sysrenew_allow_devices(lcrzo_bool yes);
int lcrzo_conf_set_sysrenew_allow_arpperm(lcrzo_bool yes);
int lcrzo_conf_set_sysrenew_allow_arpcache(lcrzo_bool yes);
int lcrzo_conf_set_sysrenew_allow_routes(lcrzo_bool yes);
int lcrzo_conf_get_sysrenew_allow(lcrzo_bool *pyes);
int lcrzo_conf_get_sysrenew_allow_devices(lcrzo_bool *pyes);
int lcrzo_conf_get_sysrenew_allow_arpperm(lcrzo_bool *pyes);
int lcrzo_conf_get_sysrenew_allow_arpcache(lcrzo_bool *pyes);
int lcrzo_conf_get_sysrenew_allow_routes(lcrzo_bool *pyes);
/* lifetime of permanent entries before having to update them */
int lcrzo_conf_set_permentriesperiod(lcrzo_uint32 period);
int lcrzo_conf_get_permentriesperiod(lcrzo_uint32 *pperiod);
/* lifetime of cached entries */
int lcrzo_conf_set_cacheentriestimeout(lcrzo_uint32 timeout);
int lcrzo_conf_get_cacheentriestimeout(lcrzo_uint32 *ptimeout);
/*-------------------------------------------------------------*/
/* to force an update of the system configuration */
int lcrzo_conf_renewnow_system(void);
int lcrzo_conf_devices_renewnow_system(void);
int lcrzo_conf_arpperm_renewnow_system(void);
int lcrzo_conf_arpcache_renewnow_system(void);
int lcrzo_conf_routes_renewnow_system(void);
/*-------------------------------------------------------------*/
/* flush the system/user configuration */
int lcrzo_conf_flush_system(void);
int lcrzo_conf_devices_flush_system(void);
int lcrzo_conf_arpperm_flush_system(void);
int lcrzo_conf_arpcache_flush_system(void);
int lcrzo_conf_routes_flush_system(void);
int lcrzo_conf_flush_user(void);
int lcrzo_conf_devices_flush_user(void);
int lcrzo_conf_arpperm_flush_user(void);
int lcrzo_conf_arpcache_flush_user(void);
int lcrzo_conf_routes_flush_user(void);
/*-------------------------------------------------------------*/
/* Name : lcrzo_conf_route_to_host
   Description :
     Determine device, sources addresses and destination Ethernet
     address to use to send an IP packet to a host.
   Input parameter(s) :
     hostipl : host to reach
   Input/output parameter(s) :
   Output parameter(s) :
     device : device to use
     srcetha : Ethernet source address to use
     destetha : Ethernet destination address to use
     *psrcipl : IP source address to use
     *prouteripl : IP address of the router (or 0 if hostipl is
                   on the local LAN)
   Normal return values :
     LCRZO_ERR_OK : ok (set: all ; *prouteripl==0 if hostipl
                    is on the LAN)
     LCRZO_ERR_OKROUTELOCALDEV : hostipl is the address of a
                                 local device (set : device)
     LCRZO_ERR_OKROUTEHOSTUNREACH : hostipl in on LAN, but we
                                    can't get its Ethernet address
				    (set : device, srcetha, *psrcipl,
				    *prouteripl==0)
     LCRZO_ERR_OKROUTEGWUNREACH : hostipl in behind a router, but we
                                  can't get the Ethernet address of
                                  the router (set : device,
				  srcetha, *psrcipl, *prouteripl)
     LCRZO_ERR_OKROUTENOTETHER : Ethernet is not used to reach
                                 destination (set : device,
				 *psrcipl, *prouteripl)
     LCRZO_ERR_OKROUTENOTFOUND : the routing table doesn't contain
                                 a route to hostipl (set : none)
*/
int lcrzo_conf_route_to_host(lcrzo_ipl hostipl,
			     lcrzo_device device,
			     lcrzo_etha srcetha,
			     lcrzo_etha destetha,
			     lcrzo_ipl *psrcipl,
			     lcrzo_ipl *prouteripl);
/*-------------------------------------------------------------*/
/* Name : lcrzo_conf_route_to_host_ip
   Description :
     Determine device and addresses to use to send an IP packet
     to a host.
   Input parameter(s) :
     hostipl : host to reach
   Input/output parameter(s) :
   Output parameter(s) :
     device : device to use (for example to sniff)
     *psrcipl : IP source address to use
     *prouteripl : IP address of the router (or 0 if hostipl is
                   on the local LAN)
   Normal return values :
     LCRZO_ERR_OK : ok (set: all ; *prouteripl==0 if hostipl
                    is on the LAN)
     LCRZO_ERR_OKROUTELOCALDEV : hostipl is the address of a
                                 local device (set : device)
     LCRZO_ERR_OKROUTENOTFOUND : the routing table doesn't contain
                                 a route to hostipl (set : none)
*/
int lcrzo_conf_route_to_host_ip(lcrzo_ipl hostipl,
				lcrzo_device device,
				lcrzo_ipl *psrcipl,
				lcrzo_ipl *prouteripl);
/*-------------------------------------------------------------*/
/* for debugging purposes only */
int lcrzo_conf_debug_fprint(LCRZOFILE *pf);
#define lcrzo_conf_debug_print() lcrzo_conf_debug_fprint(stdout)

SEE ALSO
lcrzo(3), lcrzo_types(3), lcrzo_data(3), lcrzo_string(3), lcrzo_time(3), lcrzo_file(3), lcrzo_address(3), lcrzo_device(3), lcrzo_list(3), lcrzo_process(3), lcrzo_ipc(3), lcrzo_header(3), lcrzo_ipopt(3), lcrzo_tcpopt(3), lcrzo_packet(3), lcrzo_icmp(3), lcrzo_print(3), lcrzo_record(3), lcrzo_conf(3), lcrzo_spoof(3), lcrzo_sniff(3), lcrzo_sock(3), lcrzo_wait(3), lcrzo_global(3), lcrzo_error(3) lcrzo_misc(3), lcrzo_obso(3),