/* ipmip_sysvar.h - ipmip_sysvar.h */ /* ****************************************************************************** * HEADER FILE * * Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: ipmip_sysvar.h,v $ $Revision: 1.17 $ * $Source: /home/interpeak/CVSRoot/ipmip/include/private/ipmip_sysvar.h,v $ * $Author: jhorteli $ $Date: 2010-12-07 09:55:01 $ * $State: Exp $ $Locker: $ * * INTERPEAK_COPYRIGHT_STRING * Design and implementation by Joel Hortelius ****************************************************************************** */ #ifndef IPMIP_SYSVAR_H #define IPMIP_SYSVAR_H /* **************************************************************************** * 1 DESCRIPTION **************************************************************************** * System configuration base functions. Base functions that provide wildcard * and 'printf' similar syntax in order to retrieve system configuration * variables. */ /* DESCRIPTION System configuration base functions. Base functions that provide wildcard and 'printf' similar syntax in order to retrieve system configuration variables. EXAMPLE Basic example as to how the sysvar utility functions are used. .CS void read_configuration_parameters(Ipmip_if_t *iff) { Ip_u16 lifetime = ipmip_sysvar_ushort(0, "ipmip6ha.interface.%s.lifetime", iff->ifname); Ip_bool AlwaysVerifyTunnelSrc = ipmip_sysvar_bool(IP_FALSE, "ipmip6ha.interface.%s.AlwaysVerifyTunnelSrc", iff->ifname); Ip_u32 BRIMaxRetriesNumber = ipmip_sysvar_u32(1, "ipmip6ha.interface.%s.BRIMaxRetriesNumber", iff->ifname); } .CE */ /* **************************************************************************** * 2 CONFIGURATION **************************************************************************** */ /* **************************************************************************** * 3 INCLUDE FILES **************************************************************************** */ #include #ifdef __cplusplus extern "C" { #endif /* **************************************************************************** * 4 DEFINES **************************************************************************** */ /* */ #define IPMIP_SYSVAR_MODE_DISABLED 0 #define IPMIP_SYSVAR_MODE_OPTIONAL 1 #define IPMIP_SYSVAR_MODE_REQUIRED 2 /* **************************************************************************** * 5 TYPES **************************************************************************** */ struct Ipmip_proc; struct Ipmip_context; /* * Description: Callback invoked for each matching entry in the sysvar * table. * Parameters: key - The entire name of the sysvar key * subkey - The wildcard part of the matched sysvar key * value - The value of the sysvar key * data - Opaque data supplied with the call. */ typedef void (*Ipmip_sysvar_foreach_t) (struct Ipmip_proc *proc, const char *key, const char *subkey, const char *value, void *data); typedef void (*Ipmip_sysvar_foreach_ext_t) (struct Ipmip_context *ctx, struct Ipmip_proc *proc, const char *key, const char *subkey, const char *value, void *data); typedef struct Ipmip_sysvar_key_map { int key; const char *str; } Ipmip_sysvar_key_map_t; extern const char *ipmip_sysvar_mode_desc[]; extern const Ipmip_sysvar_key_map_t ipmip_sysvar_bool_ops[]; extern const Ipmip_sysvar_key_map_t ipmip_sysvar_tunnel_mask[]; /* **************************************************************************** * 6 FUNCTIONS **************************************************************************** */ /******************************************************************************* * * ipmip_vsysvar - ipmip_vsysvar * * Return the configuration system variable value pointer to * by the format string and the provided optional arguments. * The return value is dynamically allocated, and must be * freed by the caller. * * Parameters: * \is * \i format * Format string * \i ap * Optional arguments * \ie * * RETURNS: The configuration string value * * ERRNO: * */ IP_GLOBAL char * ipmip_vsysvar ( const char *format, va_list ap ); /******************************************************************************* * * ipmip_sysvar - ipmip_sysvar * * Return the configuration system variable value pointer to * by the format string and the provided optional arguments. * The return value is dynamically allocated, and must be * freed by the caller. * * Parameters: * \is * \i format * Format string * \i ... * Optional arguments * \ie * * RETURNS: The configuration string value * * ERRNO: * */ IP_GLOBAL char * ipmip_sysvar ( const char *format, /* args*/ ... ); /******************************************************************************* * * ipmip_sysvar_set - ipmip_sysvar_set * * Set a particular system variable * * Parameters: * \is * \i value * value * \i format * Format string * \i ... * Optional arguments * \ie * * RETURNS: * * ERRNO: * */ IP_GLOBAL void ipmip_sysvar_set ( const char *value, const char *format, /* args*/ ... ); /******************************************************************************* * * ipmip_sysvar_set_ulong - ipmip_sysvar_set_ulong * * Set a particular system variable * * Parameters: * \is * \i value * Value * \i format * Format string * \i ... * Optional arguments * \ie * * RETURNS: * * ERRNO: * */ IP_GLOBAL void ipmip_sysvar_set_ulong ( unsigned long value, const char *format, /* args*/ ... ); /******************************************************************************* * * ipmip_sysvar_unset - ipmip_sysvar_unset * * Unset a particular system variable * * Parameters: * \is * \i format * Format string * \i ... * Optional arguments * \ie * * RETURNS: * * ERRNO: * */ IP_GLOBAL void ipmip_sysvar_unset ( const char *format, /* args*/ ... ); /******************************************************************************* * * ipmip_sysvar_mode - ipmip_sysvar_mode * * Parse and return a mode value, where mode is either DISABLED, * OPTIONAL or REQUIRED. DISABLED equals integer 0, or 'disable', * 'disabled', 'false' or 'no'. OPTIONAL equals integer 1, or * 'optional' or 'may'. REQUIRED equals 'yes', 'true', integer 2, * 'enable', 'enabled' or 'required' * * Parameters: * \is * \i defval * The default value. * \i format * Format string * \i ... * Optional arguments * \ie * * RETURNS: IPMIP4_SYSVAR_MODE_DISABLED, IPMIP4_SYSVAR_MODE_OPTIONAL or * IPMIP4_SYSVAR_MODE_REQUIRED * * ERRNO: * */ IP_GLOBAL int ipmip_sysvar_mode ( int defval, const char *format, /* args*/ ... ); /******************************************************************************* * * ipmip_sysvar_bool - ipmip_sysvar_bool * * Parse and return a boolean value; A boolean value is either * a numerical value, where != 0,enabled, enable, yes or true * equals IP_TRUE, or 0, disabled, disable, no or false which equals * IP_FALSE. If the system variable doesn't exist, the provided * default value will be returned. * * Parameters: * \is * \i defval * The default value. * \i format * Format string * \i ... * Optional arguments * \ie * * RETURNS: The configuration value; IP_TRUE or IP_FALSE. * * ERRNO: * */ IP_GLOBAL Ip_bool ipmip_sysvar_bool ( Ip_bool defval, const char *format, /* args*/ ... ); /******************************************************************************* * * ipmip_sysvar_key - ipmip_sysvar_key * * Parse a sysvar key and map it to an option * * Parameters: * \is * \i defval * Default value * \i map * Key options * \i format * Format string * \i ... * Optional arguments * \ie * * RETURNS: -1 on failure; key value otherwise. * * ERRNO: * */ IP_GLOBAL int ipmip_sysvar_key ( int defval, Ipmip_sysvar_key_map_t *map, const char *format, /* args*/ ... ); /******************************************************************************* * * ipmip_sysvar_ulong - ipmip_sysvar_ulong * * Parse and return an unsigned long value; If the system variable * doesn't exist, the provided default value will be returned. * * Parameters: * \is * \i defval * The default value. * \i format * Format string * \i ... * Optional arguments * \ie * * RETURNS: The configuration integer value * * ERRNO: * */ IP_GLOBAL unsigned long ipmip_sysvar_ulong ( unsigned long defval, const char *format, /* args*/ ... ); /******************************************************************************* * * ipmip_sysvar_u32 - ipmip_sysvar_u32 * * Parse and return an u32; If the system variable * doesn't exist, the provided default value will be returned. * * Parameters: * \is * \i defval * The default value. * \i format * Format string * \i ... * Optional arguments * \ie * * RETURNS: The configuration integer value * * ERRNO: * */ IP_GLOBAL Ip_u32 ipmip_sysvar_u32 ( Ip_u32 defval, const char *format, /* args*/ ... ); /******************************************************************************* * * ipmip_sysvar_ushort - ipmip_sysvar_ushort * * Parse and return an unsigned short value; If the system variable * doesn't exist, the provided default value will be returned. * * Parameters: * \is * \i defval * The default value. * \i format * Format string * \i ... * Optional arguments * \ie * * RETURNS: The configuration integer value * * ERRNO: * */ IP_GLOBAL unsigned short ipmip_sysvar_ushort ( unsigned short defval, const char *format, /* args*/ ... ); /******************************************************************************* * * ipmip_sysvar_long - ipmip_sysvar_long * * Parse and return a long value; If the system variable * doesn't exist, the provided default value will be returned. * * Parameters: * \is * \i defval * The default value. * \i format * Format string * \i ... * Optional arguments * \ie * * RETURNS: The configuration integer value * * ERRNO: * */ IP_GLOBAL long ipmip_sysvar_long ( long defval, const char *format, /* args*/ ... ); /******************************************************************************* * * ipmip_sysvar_short - ipmip_sysvar_short * * Parse and return a long value; If the system variable * doesn't exist, the provided default value will be returned. * * Parameters: * \is * \i defval * The default value. * \i format * Format string * \i ... * Optional arguments * \ie * * RETURNS: The configuration integer value * * ERRNO: * */ IP_GLOBAL short ipmip_sysvar_short ( short defval, const char *format, /* args*/ ... ); #ifdef IPMIP_USE_INET /******************************************************************************* * * ipmip_sysvar_inet - ipmip_sysvar_inet * * Read a sysvar variable and convert it to an IPv4 address and * prefix. If plen is specified; it will look for / prefix * indicator, if not available, prefix will be 32. * * Parameters: * \is * \i defip * Default value * \i addr * The addr to store the result in. * \i plen * Prefix length.[may be NULL] * \i format * Format string * \i ... * Arguments. * \ie * * RETURNS: IP_TRUE on success; IP_FALSE otherwise * * ERRNO: * */ IP_GLOBAL Ip_bool ipmip_sysvar_inet ( Ip_u32 defip, Ip_u32 *addr, Ip_u32 *plen, const char *format, /* args*/ ... ); #endif #ifdef IPMIP_USE_INET6 /******************************************************************************* * * ipmip_sysvar_inet6 - ipmip_sysvar_inet6 * * Read a sysvar variable and convert it to an IPv6 address and * prefix. If plen is specified; it will look for / prefix * indicator, if not available, prefix will be 32. * * Parameters: * \is * \i defip * Default value * \i addr * The addr to store the result in. * \i plen * Prefix length.[may be NULL] * \i format * Format string * \i ... * Arguments. * \ie * * RETURNS: IP_TRUE on success; IP_FALSE otherwise * * ERRNO: * */ IP_GLOBAL Ip_bool ipmip_sysvar_inet6 ( const struct Ip_in6_addr *defaddr6, struct Ip_in6_addr *addr, Ip_u8 *plen, const char *format, /* args*/ ... ); #endif /******************************************************************************* * * ipmip_sysvar_foreach - ipmip_sysvar_foreach * * Iterate and expand tables in sysvar. * * Parameters: * \is * \i proc * The process context associated with the currently executing thread. Each * thread and/or process in MIP must have its own unique process context. * If a process is started using ipmip_proc_start, the process context will * be allocated automatically by the IPMIP framework. Otherwise it must * be allocated using ipmip_proc_alloc(). * \i cb_func * The sysvar foreach callback * \i cookie * Opaque data. * \i format * The format key * \i ... * Arguments * \ie * * RETURNS: No return value * * ERRNO: * */ IP_GLOBAL void ipmip_sysvar_foreach ( struct Ipmip_proc *proc, Ipmip_sysvar_foreach_t cb_func, void *cookie, const char *format, /* args*/ ... ); /******************************************************************************* * * ipmip_sysvar_foreach_ext - ipmip_sysvar_foreach_ext * * Iterate and expand tables in sysvar. * * Parameters: * \is * \i ctx * The generic mobility singleton context for IPMIP. For each started mobility * entity, there exists a mobility context which tracks configuration, system * events, available features and started processes. The mobility context is * created using ipmip_context_create(). See ipmip_context.h for more information * regarding the mobility entity context singleton. * \i proc * The process context associated with the currently executing thread. Each * thread and/or process in MIP must have its own unique process context. * If a process is started using ipmip_proc_start, the process context will * be allocated automatically by the IPMIP framework. Otherwise it must * be allocated using ipmip_proc_alloc(). * \i cb_func * The sysvar foreach callback * \i cookie * Opaque data. * \i format * The format key * \i ... * Arguments * \ie * * RETURNS: No return value * * ERRNO: * */ IP_GLOBAL void ipmip_sysvar_foreach_ext ( struct Ipmip_context *ctx, struct Ipmip_proc *proc, Ipmip_sysvar_foreach_ext_t cb_func, void *cookie, const char *format, /* args*/ ... ); /******************************************************************************* * * ipmip_sysvar_array - ipmip_sysvar_array * * Parse and return an array of configuration options where each * string will be matched to a configuration value and returned * in a dynamically allocated integer array terminated with the * value 0xffffffff. The integer array must be freed by the caller. * * Parameters: * \is * \i ops * Options for parsing the strings * \i format * Format string * \i ... * Optional arguments * \ie * * RETURNS: The integer array. * * ERRNO: * */ IP_GLOBAL int * ipmip_sysvar_array ( Ipmip_sysvar_key_map_t *ops, const char *format, /* args*/ ... ); /******************************************************************************* * * ipmip_sysvar_strlist - ipmip_sysvar_strlist * * Parse and return a string array of the format * .. where length * is 1 byte, and string is a zero terminated; the length includes * the zero termination and the length byte; the array is * terminated by a length byte with value 0. The returned data is * dynamically allocated and must be freed by the caller. num * entries is a one byte entry indicating the number of strings * stored in the array. * * Parameters: * \is * \i format * Format string * \i ... * format arguments * \ie * * RETURNS: The strlist array * * ERRNO: * */ IP_GLOBAL Ip_u8 * ipmip_sysvar_strlist ( const char *format, /* args*/ ... ); /******************************************************************************* * * ipmip_sysvar_strarr - ipmip_sysvar_strarr * * Parse and return an IP_NULL string pointer array * * Parameters: * \is * \i format * Format string * \i ... * format arguments * \ie * * RETURNS: The string pointer array * * ERRNO: * */ IP_GLOBAL char **ipmip_sysvar_strarr ( const char *format, /* args*/ ... ); /******************************************************************************* * * ipmip_sysvar_cmd_str_to_key - ipmip_sysvar_cmd_str_to_key * * Converts the string representation in map to the numeric value. * * Parameters: * \is * \i map * The int to string map to use. * \i str * The string to lookup * \ie * * RETURNS: The numeric representation * * ERRNO: * */ IP_GLOBAL int ipmip_sysvar_cmd_str_to_key ( const Ipmip_sysvar_key_map_t *map, const char *str ); #ifdef __cplusplus } #endif #endif /* **************************************************************************** * END OF FILE **************************************************************************** */