/* Plugin includes */
#include "pud.h"
-#include "netTools.h"
#include "networkInterfaces.h"
+#include "netTools.h"
+#include "posFile.h"
+#include "configTools.h"
/* OLSR includes */
-#include "olsr_types.h"
-#include "olsr_cfg.h"
+#include <olsr_protocol.h>
+#include <olsr.h>
/* System includes */
-#include <assert.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-#include <net/if.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <sys/socket.h>
#include <unistd.h>
-#include <nmea/util.h>
-
-/*
- * Utility functions
- */
-
-/**
- Determine the address of the port in an OLSR socket address
-
- @param ipVersion
- The IP version (AF_INET or AF_INET6)
- @param addr
- A pointer to OLSR socket address
- @param port
- A pointer to the location where the pointer to the port will be stored
- */
-static void getOlsrSockaddrPortAddress(int ipVersion,
- union olsr_sockaddr * addr, in_port_t ** port) {
- if (ipVersion == AF_INET) {
- *port = &addr->in4.sin_port;
- } else {
- *port = &addr->in6.sin6_port;
- }
-}
-
-/**
- Get pointers to the IP address and port in an OLSR socket address
- @param ipVersion
- The IP version (AF_INET or AF_INET6)
- @param addr
- A pointer to OLSR socket address
- @param ipAddress
- A pointer to the location where the pointer to the IP address will be stored
- @param port
- A pointer to the location where the pointer to the port will be stored
- */
-static void getOlsrSockAddrAndPortAddresses(int ipVersion,
- union olsr_sockaddr * addr, void ** ipAddress, in_port_t ** port) {
- if (ipVersion == AF_INET) {
- *ipAddress = (void *) &addr->in4.sin_addr;
- *port = (void *) &addr->in4.sin_port;
- } else {
- *ipAddress = (void *) &addr->in6.sin6_addr;
- *port = (void *) &addr->in6.sin6_port;
- }
-}
-
-/**
- Read an unsigned long long number from a value string
-
- @param valueName
- the name of the value
- @param value
- the string to convert to a number
- @param valueNumber
- a pointer to the location where to store the number upon successful conversion
-
- @return
- - true on success
- - false otherwise
- */
-static bool readULL(const char * valueName, const char * value,
- unsigned long long * valueNumber) {
- char * endPtr = NULL;
- unsigned long long valueNew;
-
- errno = 0;
- valueNew = strtoull(value, &endPtr, 10);
-
- if (!((endPtr != value) && (*value != '\0') && (*endPtr == '\0'))) {
- /* invalid conversion */
- pudError(true, "Configured %s (%s) could not be converted to a number",
- valueName, value);
- return false;
- }
-
- *valueNumber = valueNew;
-
- return true;
-}
+#include <nmea/parse.h>
+#include <OlsrdPudWireFormat/nodeIdConversion.h>
+#include <limits.h>
-/**
- Read a double number from a value string
-
- @param valueName
- the name of the value
- @param value
- the string to convert to a number
- @param valueNumber
- a pointer to the location where to store the number upon successful conversion
+/* forward declarations */
+static bool setupNodeIdBinaryAndValidate(NodeIdType nodeIdTypeNumber);
- @return
- - true on success
- - false otherwise
+/*
+ * Note:
+ * Setters must return true when an error is detected, false otherwise
*/
-static bool readDouble(const char * valueName, const char * value,
- double * valueNumber) {
- char * endPtr = NULL;
- double valueNew;
-
- errno = 0;
- valueNew = strtod(value, &endPtr);
-
- if (!((endPtr != value) && (*value != '\0') && (*endPtr == '\0'))) {
- /* invalid conversion */
- pudError(true, "Configured %s (%s) could not be converted to a number",
- valueName, value);
- return false;
- }
-
- *valueNumber = valueNew;
-
- return true;
-}
/*
* nodeIdType
return nodeIdType;
}
-/**
- Set the node ID type.
-
- @param value
- The value of the node ID type to set (a number in string representation)
- @param data
- Unused
- @param addon
- Unused
-
- @return
- - true when an error is detected
- - false otherwise
- */
-int setNodeIdType(const char *value, void *data __attribute__ ((unused)),
- set_plugin_parameter_addon addon __attribute__ ((unused))) {
- static const char * valueName = PUD_NODE_ID_TYPE_NAME;
+static int setNodeIdType(const char *value, const char * valueName) {
unsigned long long nodeIdTypeNew;
- assert (value != NULL);
-
- if (!readULL(valueName, value, &nodeIdTypeNew)) {
+ if (!readULL(valueName, value, &nodeIdTypeNew, 10)) {
return true;
}
if (!isValidNodeIdType(nodeIdTypeNew)) {
- pudError(false, "Configured %s (%llu) is reserved", valueName,
+ pudError(false, "Value in parameter %s (%llu) is reserved", valueName,
nodeIdTypeNew);
return true;
}
* nodeId
*/
-/**
- The type that is used to store the nodeId as a binary representation
- */
-typedef union _nodeIdBinaryType {
- unsigned long long longValue;
-} nodeIdBinaryType;
-
-/** The maximum length of a nodeId */
-#define PUD_NODEIDMAXLENGTH 255
-
/** The nodeId buffer */
-static unsigned char nodeId[PUD_NODEIDMAXLENGTH + 1];
+static unsigned char nodeId[PUD_TX_NODEID_BUFFERSIZE];
/** The length of the string in the nodeId buffer */
static size_t nodeIdLength = 0;
/** True when the nodeId is set */
static bool nodeIdSet = false;
-/** The nodeId as a binary representation */
+/** The nodeId as a binary representation, with status */
static nodeIdBinaryType nodeIdBinary;
-/** True when the nodeIdBinary is set */
-static bool nodeIdBinarySet = false;
-
-/**
- @return
- The node ID
- */
-unsigned char * getNodeId(void) {
- return getNodeIdWithLength(NULL);
-}
-
/**
Get the nodeId and its length
@return
The node ID
*/
-unsigned char * getNodeIdWithLength(size_t *length) {
+unsigned char * getNodeId(size_t *length) {
if (!nodeIdSet) {
setNodeId("", NULL, (set_plugin_parameter_addon) {.pc = NULL});
}
}
/**
- Set the node ID.
-
- @param value
- The value of the node ID to set (in string representation)
- @param data
- Unused
- @param addon
- Unused
+ Get the nodeIdBinary
@return
- - true when an error is detected
- - false otherwise
+ The node ID in binary representation
*/
+nodeIdBinaryType * getNodeIdBinary(void) {
+ if (!nodeIdBinary.set) {
+ setNodeId("", NULL, (set_plugin_parameter_addon) {.pc = NULL});
+ }
+
+ return &nodeIdBinary;
+}
+
int setNodeId(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))) {
- static const char * valueName = PUD_NODE_ID_NAME;
size_t valueLength;
+ char * number;
+ char * identification;
assert (value != NULL);
- valueLength = strlen(value);
- if (valueLength > PUD_NODEIDMAXLENGTH) {
- pudError(false, "Configured %s is too long, maximum length is"
- " %u, current length is %lu", valueName, PUD_NODEIDMAXLENGTH,
- (unsigned long) valueLength);
- return true;
- }
-
- strcpy((char *) &nodeId[0], value);
- nodeIdLength = valueLength;
- nodeIdSet = true;
+ nodeId[0] = '\0';
+ nodeIdLength = 0;
+ nodeIdSet = false;
+ nodeIdBinary.set = false;
- return false;
+ valueLength = strlen(value);
+ number = olsr_malloc(valueLength + 1, "setNodeId");
+ strcpy(number, value);
+
+ /* split "number,identification" */
+ identification = strchr(number, ',');
+ if (identification) {
+ *identification = '\0';
+ identification++;
+ }
+
+ /* parse number into nodeIdType (if present) */
+ valueLength = strlen(number);
+ if (valueLength && setNodeIdType(number, PUD_NODE_ID_NAME)) {
+ free(number);
+ return true;
+ }
+
+ /* copy identification into nodeId (if present) */
+ if (identification) {
+ valueLength = strlen(identification);
+ if (valueLength > (PUD_TX_NODEID_BUFFERSIZE - 1)) {
+ pudError(false, "Value in parameter %s is too long, maximum length is"
+ " %u, current length is %lu", PUD_NODE_ID_NAME, (PUD_TX_NODEID_BUFFERSIZE - 1),
+ (unsigned long) valueLength);
+ free(number);
+ return true;
+ }
+
+ if (valueLength) {
+ strcpy((char *) &nodeId[0], identification);
+ nodeIdLength = valueLength;
+ nodeIdSet = true;
+ }
+ }
+
+ free(number);
+
+ /* fill in automatic values */
+ if (!nodeIdSet) {
+ if (nodeIdType == PUD_NODEIDTYPE_DNS) {
+ memset(nodeId, 0, sizeof(nodeId));
+ errno = 0;
+ if (gethostname((char *)&nodeId[0], sizeof(nodeId) - 1) < 0) {
+ pudError(true, "Could not get the host name");
+ return true;
+ }
+
+ nodeIdLength = strlen((char *)nodeId);
+ nodeIdSet = true;
+ } else if ((nodeIdType != PUD_NODEIDTYPE_MAC) && (nodeIdType != PUD_NODEIDTYPE_IPV4)
+ && (nodeIdType != PUD_NODEIDTYPE_IPV6)) {
+ pudError(false, "No node ID set while one is required for nodeId type %u", nodeIdType);
+ return true;
+ }
+ }
+
+ if (!setupNodeIdBinaryAndValidate(nodeIdType)) {
+ pudError(false, "nodeId (type %u) is incorrectly configured", nodeIdType);
+ return true;
+ }
+
+ return false;
}
/*
* nodeId Validation
*/
+/**
+ Validate whether the configured nodeId is valid w.r.t. the configured
+ nodeIdType, for types that are MAC addresses
+
+ @return
+ - true when ok
+ - false on failure
+ */
+static bool intSetupNodeIdBinaryMAC(void) {
+ unsigned char * mac = getMainIpMacAddress();
+ if (!mac) {
+ return false;
+ }
+
+ return setupNodeIdBinaryMAC(&nodeIdBinary, mac);
+}
+
/**
Validate whether the configured nodeId is valid w.r.t. the configured
nodeIdType, for types that fit in an unsigned long long (64 bits)
- @param valueBuffer
- the buffer in which the value must be stored
@param min
the minimum value
@param max
the maximum value
@param bytes
the number of bytes in the buffer
+
+ @return
+ - true when ok
+ - false on failure
*/
-static bool setupNodeIdBinaryLongLong(
- nodeIdBinaryType * valueBuffer, unsigned long long min,
- unsigned long long max,
- unsigned int bytes) {
- if (!nodeIdBinarySet) {
- if (!readULL(PUD_NODE_ID_NAME, (char *) &nodeId[0],
- &nodeIdBinary.longValue)) {
- return false;
- }
- nodeIdBinarySet = true;
- }
- valueBuffer->longValue = nodeIdBinary.longValue;
+static bool intSetupNodeIdBinaryLongLong(unsigned long long min,
+ unsigned long long max, unsigned int bytes) {
+ unsigned long long longValue = 0;
+ if (!readULL(PUD_NODE_ID_NAME, (char *) getNodeId(NULL), &longValue, 10)) {
+ return false;
+ }
- if (setupNodeIdNumberForOlsrCache(valueBuffer->longValue, min, max,
- bytes)) {
- return true;
- }
+ if ((longValue < min) || (longValue > max)) {
+ pudError(false, "%s value %llu is out of range [%llu,%llu]",
+ PUD_NODE_ID_NAME, longValue, min, max);
+ return false;
+ }
- pudError(false, "%s value %llu is out of range [%llu,%llu]",
- PUD_NODE_ID_NAME, valueBuffer->longValue, min, max);
- return false;
+ return setupNodeIdBinaryLongLong(&nodeIdBinary, longValue, bytes);
+}
+
+/**
+ Validate whether the configured nodeId is valid w.r.t. the configured
+ nodeIdType, for types that fit in a double unsigned long long (128 bits) with
+ a certain split that defined by chars1
+
+ @param chars1
+ the number of characters of the first part
+ @param min1
+ the minimum value of the first part
+ @param max1
+ the maximum value of the first part
+ @param bytes1
+ the number of bytes of the first part in the buffer
+ @param min2
+ the minimum value of the second part
+ @param max2
+ the maximum value of the second part
+ @param bytes2
+ the number of bytes of the second part in the buffer
+ @param base
+ the base of the number conversion: 10 for decimal, 16 for hexadecimal
+
+ @return
+ - true when ok
+ - false on failure
+ */
+static bool intSetupNodeIdBinaryDoubleLongLong(
+ unsigned char * dst,
+ unsigned int chars1,
+ unsigned long long min1, unsigned long long max1,
+ unsigned int bytes1,
+ unsigned long long min2, unsigned long long max2,
+ unsigned int bytes2,
+ int base) {
+ unsigned long long longValue1 = 0;
+ unsigned long long longValue2 = 0;
+
+ unsigned char * node_id = getNodeId(NULL);
+ size_t node_id_len = strlen((char *)node_id);
+
+ assert(chars1 > 0);
+ assert(bytes1 > 0);
+ assert(bytes2 > 0);
+
+ /* part 1 */
+ if (node_id_len > 0) {
+ unsigned char first[chars1 + 1];
+ int cpylen = node_id_len < chars1 ? node_id_len : chars1;
+
+ memcpy(first, node_id, cpylen);
+ first[cpylen] = '\0';
+
+ if (!readULL(PUD_NODE_ID_NAME, (char *)first, &longValue1, base)) {
+ return false;
+ }
+
+ if ((longValue1 < min1) || (longValue1 > max1)) {
+ pudError(false, "First %u character(s) of %s value %llu are out of range [%llu,%llu]",
+ cpylen, PUD_NODE_ID_NAME, longValue1, min1, max1);
+ return false;
+ }
+ }
+
+ /* part 2 */
+ if (node_id_len > chars1) {
+ if (!readULL(PUD_NODE_ID_NAME, (char *)&node_id[chars1], &longValue2, base)) {
+ return false;
+ }
+
+ if ((longValue2 < min2) || (longValue2 > max2)) {
+ pudError(false, "Last %u character(s) of %s value %llu are out of range [%llu,%llu]",
+ (unsigned int)(node_id_len - chars1), PUD_NODE_ID_NAME, longValue2, min2, max2);
+ return false;
+ }
+ } else {
+ /* longvalue1 is the only value, so it is the least significant value:
+ * exchange the 2 values */
+ unsigned long long tmp = longValue1;
+ longValue1 = longValue2;
+ longValue2 = tmp;
+ }
+
+ return setupNodeIdBinaryDoubleLongLong(&nodeIdBinary,
+ longValue1, &dst[0], bytes1,
+ longValue2, &dst[bytes1], bytes2);
}
/**
Validate whether the configured nodeId is valid w.r.t. the configured
nodeIdType, for types that are strings
+
+ @return
+ - true when ok
+ - false on failure
*/
-static bool setupNodeIdNumberForOlsrCacheAndValidateString(void) {
- bool invalidChars;
- char report[256];
+static bool intSetupNodeIdBinaryString(void) {
+ const char * invalidCharName;
+ size_t nodeidlength;
+ char * nodeid = (char *) getNodeId(&nodeidlength);
+
+ invalidCharName = nmea_parse_sentence_has_invalid_chars(nodeid, nodeidlength);
+ if (invalidCharName) {
+ char report[256];
+ snprintf(report, sizeof(report), "Configured %s (%s),"
+ " contains invalid NMEA characters (%s)", PUD_NODE_ID_NAME, nodeid, invalidCharName);
+ pudError(false, "%s", &report[0]);
+ return false;
+ }
+
+ if (nodeidlength > (PUD_TX_NODEID_BUFFERSIZE - 1)) {
+ pudError(false, "Length of parameter %s (%s) is too great", PUD_NODE_ID_NAME, &nodeid[0]);
+ return false;
+ }
- invalidChars = nmea_string_has_invalid_chars((char *) getNodeId(),
- PUD_NODE_ID_NAME, &report[0], sizeof(report));
- if (invalidChars) {
- pudError(false, &report[0]);
+ return setupNodeIdBinaryString(&nodeIdBinary, nodeid, nodeidlength);
+}
+
+/**
+ Validate whether the configured nodeId is valid w.r.t. the configured
+ nodeIdType, for types that are IP addresses
+
+ @return
+ - true when ok
+ - false on failure
+ */
+static bool intSetupNodeIdBinaryIp(void) {
+ void * src;
+ size_t length;
+ if (olsr_cnf->ip_version == AF_INET) {
+ src = &olsr_cnf->main_addr.v4;
+ length = sizeof(struct in_addr);
+ } else {
+ src = &olsr_cnf->main_addr.v6;
+ length = sizeof(struct in6_addr);
}
- return !invalidChars;
+
+ return setupNodeIdBinaryIp(&nodeIdBinary, src, length);
}
/**
Validate whether the configured nodeId is valid w.r.t. the configured
- nodeIdType
+ nodeIdType and setup the binary value
@return
- true when ok
- false on failure
*/
static bool setupNodeIdBinaryAndValidate(NodeIdType nodeIdTypeNumber) {
- nodeIdBinaryType valueBuffer;
-
- memset(&valueBuffer, 0, sizeof(nodeIdBinaryType));
switch (nodeIdTypeNumber) {
- case PUD_NODEIDTYPE_IPV4: /* IPv4 address */
- case PUD_NODEIDTYPE_IPV6: /* IPv6 address */
case PUD_NODEIDTYPE_MAC: /* hardware address */
- /* explicit return: configured nodeId is not relevant */
- return true;
+ return intSetupNodeIdBinaryMAC();
case PUD_NODEIDTYPE_MSISDN: /* an MSISDN number */
- return setupNodeIdBinaryLongLong(
- &valueBuffer, 0LL, 999999999999999LL,
- PUD_NODEIDTYPE_MSISDN_BYTES);
+ return intSetupNodeIdBinaryLongLong(PUD_NODEIDTYPE_MSISDN_MIN,
+ PUD_NODEIDTYPE_MSISDN_MAX, PUD_NODEIDTYPE_MSISDN_BYTES);
case PUD_NODEIDTYPE_TETRA: /* a Tetra number */
- return setupNodeIdBinaryLongLong(
- &valueBuffer, 0LL, 99999999999999999LL,
- PUD_NODEIDTYPE_TETRA_BYTES);
+ return intSetupNodeIdBinaryLongLong(PUD_NODEIDTYPE_TETRA_MIN,
+ PUD_NODEIDTYPE_TETRA_MAX, PUD_NODEIDTYPE_TETRA_BYTES);
case PUD_NODEIDTYPE_DNS: /* DNS name */
- return setupNodeIdNumberForOlsrCacheAndValidateString();
+ return intSetupNodeIdBinaryString();
+
+ case PUD_NODEIDTYPE_IPV4: /* IPv4 address */
+ case PUD_NODEIDTYPE_IPV6: /* IPv6 address */
+ return intSetupNodeIdBinaryIp();
+
+ case PUD_NODEIDTYPE_UUID: /* a UUID number */
+ return intSetupNodeIdBinaryDoubleLongLong(
+ &nodeIdBinary.buffer.uuid[0],
+ PUD_NODEIDTYPE_UUID_CHARS1,
+ PUD_NODEIDTYPE_UUID_MIN1, PUD_NODEIDTYPE_UUID_MAX1,
+ PUD_NODEIDTYPE_UUID_BYTES1,
+ PUD_NODEIDTYPE_UUID_MIN2, PUD_NODEIDTYPE_UUID_MAX2,
+ PUD_NODEIDTYPE_UUID_BYTES - PUD_NODEIDTYPE_UUID_BYTES1,
+ 16);
case PUD_NODEIDTYPE_MMSI: /* an AIS MMSI number */
- return setupNodeIdBinaryLongLong(
- &valueBuffer, 0LL, 999999999LL, PUD_NODEIDTYPE_MMSI_BYTES);
+ return intSetupNodeIdBinaryLongLong(PUD_NODEIDTYPE_MMSI_MIN,
+ PUD_NODEIDTYPE_MMSI_MAX, PUD_NODEIDTYPE_MMSI_BYTES);
case PUD_NODEIDTYPE_URN: /* a URN number */
- return setupNodeIdBinaryLongLong(
- &valueBuffer, 0LL, 16777215LL, PUD_NODEIDTYPE_URN_BYTES);
+ return intSetupNodeIdBinaryLongLong(PUD_NODEIDTYPE_URN_MIN,
+ PUD_NODEIDTYPE_URN_MAX, PUD_NODEIDTYPE_URN_BYTES);
+
+ case PUD_NODEIDTYPE_MIP: /* a MIP OID number */
+ return intSetupNodeIdBinaryDoubleLongLong(
+ &nodeIdBinary.buffer.mip[0],
+ PUD_NODEIDTYPE_MIP_CHARS1,
+ PUD_NODEIDTYPE_MIP_MIN1, PUD_NODEIDTYPE_MIP_MAX1,
+ PUD_NODEIDTYPE_MIP_BYTES1,
+ PUD_NODEIDTYPE_MIP_MIN2, PUD_NODEIDTYPE_MIP_MAX2,
+ PUD_NODEIDTYPE_MIP_BYTES - PUD_NODEIDTYPE_MIP_BYTES1,
+ 10);
case PUD_NODEIDTYPE_192:
- return setupNodeIdBinaryLongLong(
- &valueBuffer, 0LL, 9999999LL, PUD_NODEIDTYPE_192_BYTES);
+ return intSetupNodeIdBinaryLongLong(PUD_NODEIDTYPE_192_MIN,
+ PUD_NODEIDTYPE_192_MAX, PUD_NODEIDTYPE_192_BYTES);
case PUD_NODEIDTYPE_193:
- return setupNodeIdBinaryLongLong(
- &valueBuffer, 0LL, 999999LL, PUD_NODEIDTYPE_193_BYTES);
+ return intSetupNodeIdBinaryLongLong(PUD_NODEIDTYPE_193_MIN,
+ PUD_NODEIDTYPE_193_MAX, PUD_NODEIDTYPE_193_BYTES);
case PUD_NODEIDTYPE_194:
- return setupNodeIdBinaryLongLong(
- &valueBuffer, 1LL, 8191LL, PUD_NODEIDTYPE_194_BYTES);
+ return intSetupNodeIdBinaryLongLong(PUD_NODEIDTYPE_194_MIN,
+ PUD_NODEIDTYPE_194_MAX, PUD_NODEIDTYPE_194_BYTES);
- default: /* unsupported */
- /* explicit return: configured nodeId is not relevant, will
- * fallback to IP addresses */
- return true;
+ default:
+ pudError(false, "nodeId type %u is not supported", nodeIdTypeNumber);
+ return false;
}
return false;
return false;
}
-/**
- Add a receive non-OLSR interface
-
- @param value
- The name of the non-OLSR interface to add
- @param data
- Unused
- @param addon
- Unused
-
- @return
- - true when an error is detected
- - false otherwise
- */
int addRxNonOlsrInterface(const char *value, void *data __attribute__ ((unused)),
set_plugin_parameter_addon addon __attribute__ ((unused))) {
- unsigned long valueLength;
+ size_t valueLength;
+
+ if (rxNonOlsrInterfaceCount >= PUD_RX_NON_OLSR_IF_MAX) {
+ pudError(false, "Can't configure more than %u receive interfaces",
+ PUD_RX_NON_OLSR_IF_MAX);
+ return true;
+ }
assert (value != NULL);
valueLength = strlen(value);
if (valueLength > IFNAMSIZ) {
- pudError(false, "Configured %s (%s) is too long,"
+ pudError(false, "Value of parameter %s (%s) is too long,"
" maximum length is %u, current length is %lu",
- PUD_RX_NON_OLSR_IF_NAME, value, IFNAMSIZ, valueLength);
+ PUD_RX_NON_OLSR_IF_NAME, value, IFNAMSIZ, (long unsigned int)valueLength);
return true;
}
if (!isRxNonOlsrInterface(value)) {
- if (rxNonOlsrInterfaceCount >= PUD_RX_NON_OLSR_IF_MAX) {
- pudError(false, "Can't configure more than %u receive interfaces",
- PUD_RX_NON_OLSR_IF_MAX);
- return true;
- }
-
strcpy((char *) &rxNonOlsrInterfaceNames[rxNonOlsrInterfaceCount][0],
value);
rxNonOlsrInterfaceCount++;
return false;
}
+/**
+ * @return the number of configured non-olsr receive interfaces
+ */
+unsigned int getRxNonOlsrInterfaceCount(void) {
+ return rxNonOlsrInterfaceCount;
+}
+
+/**
+ * @param idx the index of the configured non-olsr receive interface
+ * @return the index-th interface name
+ */
+unsigned char * getRxNonOlsrInterfaceName(unsigned int idx) {
+ return &rxNonOlsrInterfaceNames[idx][0];
+}
+
/*
* rxAllowedSourceIpAddress
*/
#define PUD_RX_ALLOWED_SOURCE_IP_MAX 32
/** Array with RX allowed source IP addresses */
-static struct sockaddr rxAllowedSourceIpAddresses[PUD_RX_ALLOWED_SOURCE_IP_MAX];
+static union olsr_sockaddr rxAllowedSourceIpAddresses[PUD_RX_ALLOWED_SOURCE_IP_MAX];
/** The number of RX allowed source IP addresses in the array */
static unsigned int rxAllowedSourceIpAddressesCount = 0;
address
- false otherwise
*/
-bool isRxAllowedSourceIpAddress(struct sockaddr * sender) {
- void * addr;
- unsigned int addrSize;
+bool isRxAllowedSourceIpAddress(union olsr_sockaddr * sender) {
unsigned int i;
if (rxAllowedSourceIpAddressesCount == 0) {
return false;
}
- if (sender->sa_family == AF_INET) {
- addr = (void *) (&((struct sockaddr_in *) sender)->sin_addr);
- addrSize = sizeof(struct in_addr);
- } else {
- addr = (void *) (&((struct sockaddr_in6 *) sender)->sin6_addr);
- addrSize = sizeof(struct in6_addr);
- }
-
for (i = 0; i < rxAllowedSourceIpAddressesCount; i++) {
- if ((rxAllowedSourceIpAddresses[i].sa_family == sender->sa_family)
- && (memcmp(&rxAllowedSourceIpAddresses[i].sa_data, addr,
- addrSize) == 0)) {
- return true;
+ if (sender->in.sa_family != rxAllowedSourceIpAddresses[i].in.sa_family) {
+ continue;
+ }
+
+ if (sender->in.sa_family == AF_INET) {
+ if (memcmp(&rxAllowedSourceIpAddresses[i].in4.sin_addr, &sender->in4.sin_addr, sizeof(struct in_addr))
+ == 0) {
+ return true;
+ }
+ } else {
+ if (memcmp(&rxAllowedSourceIpAddresses[i].in6.sin6_addr, &sender->in6.sin6_addr, sizeof(struct in6_addr))
+ == 0) {
+ return true;
+ }
}
}
return false;
}
-/**
- Set the RX allowed source IP addresses.
-
- @param value
- The RX allowed source IP address (in string representation)
- @param data
- Unused
- @param addon
- Unused
-
- @return
- - true when an error is detected
- - false otherwise
- */
int addRxAllowedSourceIpAddress(const char *value, void *data __attribute__ ((unused)),
set_plugin_parameter_addon addon __attribute__ ((unused))) {
static const char * valueName = PUD_RX_ALLOWED_SOURCE_IP_NAME;
- const char * valueInternal = value;
- int conversion;
- struct sockaddr addr;
-
- assert (value != NULL);
-
- memset(&addr, 0, sizeof(addr));
+ union olsr_sockaddr addr;
+ bool addrSet = false;
- addr.sa_family = olsr_cnf->ip_version;
- conversion = inet_pton(olsr_cnf->ip_version, valueInternal, &addr.sa_data);
- if (conversion != 1) {
- pudError((conversion == -1) ? true : false,
- "Configured %s (%s) is not an IP address", valueName,
- valueInternal);
+ if (rxAllowedSourceIpAddressesCount >= PUD_RX_ALLOWED_SOURCE_IP_MAX) {
+ pudError(false, "Can't configure more than %u allowed source IP"
+ " addresses", PUD_RX_ALLOWED_SOURCE_IP_MAX);
return true;
}
- if ((rxAllowedSourceIpAddressesCount == 0) || !isRxAllowedSourceIpAddress(&addr)) {
- if (rxAllowedSourceIpAddressesCount >= PUD_RX_ALLOWED_SOURCE_IP_MAX) {
- pudError(false, "Can't configure more than %u allowed source IP"
- " addresses", PUD_RX_ALLOWED_SOURCE_IP_MAX);
- return true;
- }
+ if (!readIPAddress(valueName, value, 0, &addr, &addrSet)) {
+ return true;
+ }
- memcpy(&rxAllowedSourceIpAddresses[rxAllowedSourceIpAddressesCount],
- &addr, sizeof(addr));
+ if (!isRxAllowedSourceIpAddress(&addr)) {
+ rxAllowedSourceIpAddresses[rxAllowedSourceIpAddressesCount] = addr;
rxAllowedSourceIpAddressesCount++;
}
}
/*
- * rxMcAddr
+ * rxMcAddr + rxMcPort
*/
/** The rx multicast address */
*/
union olsr_sockaddr * getRxMcAddr(void) {
if (!rxMcAddrSet) {
- setRxMcAddr(NULL, NULL, ((set_plugin_parameter_addon) {.pc = NULL}));
+ setRxMcAddr((olsr_cnf->ip_version == AF_INET) ? PUD_RX_MC_ADDR_4_DEFAULT : PUD_RX_MC_ADDR_6_DEFAULT,
+ NULL, ((set_plugin_parameter_addon) {.pc = NULL}));
}
return &rxMcAddr;
}
-/**
- Set the receive multicast address. Sets the address to its default value when
- the value is NULL. Also sets the port to its default value when the address
- was not yet set.
-
- @param value
- The receive multicast address (in string representation)
- @param data
- Unused
- @param addon
- Unused
-
- @return
- - true when an error is detected
- - false otherwise
- */
int setRxMcAddr(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))) {
static const char * valueName = PUD_RX_MC_ADDR_NAME;
- void * ipAddress;
- in_port_t * port;
- const char * valueInternal = value;
- int conversion;
-
- getOlsrSockAddrAndPortAddresses(olsr_cnf->ip_version, &rxMcAddr, &ipAddress,
- &port);
- if (olsr_cnf->ip_version == AF_INET) {
- rxMcAddr.in4.sin_family = olsr_cnf->ip_version;
- if (valueInternal == NULL) {
- valueInternal = PUD_RX_MC_ADDR_4_DEFAULT;
- }
- } else {
- rxMcAddr.in6.sin6_family = olsr_cnf->ip_version;
- if (valueInternal == NULL) {
- valueInternal = PUD_RX_MC_ADDR_6_DEFAULT;
- }
- }
- if (!rxMcAddrSet) {
- *port = htons(PUD_RX_MC_PORT_DEFAULT);
- }
-
- conversion = inet_pton(olsr_cnf->ip_version, valueInternal, ipAddress);
- if (conversion != 1) {
- pudError((conversion == -1) ? true : false,
- "Configured %s (%s) is not an IP address", valueName,
- valueInternal);
- return true;
+ if (!readIPAddress(valueName, value, PUD_RX_MC_PORT_DEFAULT, &rxMcAddr, &rxMcAddrSet)) {
+ return true;
}
- if (!isMulticast(olsr_cnf->ip_version, &rxMcAddr)) {
- pudError(false, "Configured %s (%s) is not a multicast address",
- valueName, valueInternal);
+ if (!isMulticast(&rxMcAddr)) {
+ pudError(false, "Value of parameter %s (%s) is not a multicast address",
+ valueName, value);
return true;
}
- rxMcAddrSet = true;
return false;
}
-/*
- * rxMcPort
- */
-
/**
@return
The receive multicast port (in network byte order)
*/
unsigned short getRxMcPort(void) {
- in_port_t * port;
- getOlsrSockaddrPortAddress(olsr_cnf->ip_version, getRxMcAddr(), &port);
- return *port;
+ return getOlsrSockaddrPort(getRxMcAddr(), PUD_RX_MC_PORT_DEFAULT);
}
-/**
- Set the receive multicast port
-
- @param value
- The receive multicast port (a number in string representation)
- @param data
- Unused
- @param addon
- Unused
-
- @return
- - true when an error is detected
- - false otherwise
- */
int setRxMcPort(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))) {
static const char * valueName = PUD_RX_MC_PORT_NAME;
- unsigned long long rxMcPortNew;
- in_port_t * port;
- union olsr_sockaddr * addr = getRxMcAddr();
-
- assert (value != NULL);
+ unsigned short rxMcPortNew;
- if (!readULL(valueName, value, &rxMcPortNew)) {
+ if (!readUS(valueName, value, &rxMcPortNew)) {
return true;
}
- if ((rxMcPortNew < 1) || (rxMcPortNew > 65535)) {
- pudError(false, "Configured %s (%llu) is outside of"
- " valid range 1-65535", valueName, rxMcPortNew);
+ if (rxMcPortNew < 1) {
+ pudError(false, "Value of parameter %s (%u) is outside of valid range 1-65535", valueName, rxMcPortNew);
return true;
}
- getOlsrSockaddrPortAddress(olsr_cnf->ip_version, addr, &port);
- *port = htons((uint16_t) rxMcPortNew);
+ setOlsrSockaddrPort(getRxMcAddr(), htons((in_port_t) rxMcPortNew));
return false;
}
/*
- * txNonOlsrIf
+ * positionFile
*/
-/** The maximum number of rx non-olsr interfaces */
-#define PUD_TX_NON_OLSR_IF_MAX 32
-
-/** Array with tx non-olsr interface names */
-static unsigned char txNonOlsrInterfaceNames[PUD_TX_NON_OLSR_IF_MAX][IFNAMSIZ + 1];
+/** The positionFile buffer */
+static char positionFile[PATH_MAX + 1];
-/** The number of tx interface names in the array */
-static unsigned int txNonOlsrInterfaceCount = 0;
+/** True when the positionFile is set */
+static bool positionFileSet = false;
/**
- Determine whether a give interface name is configured as a transmit non-OLSR
- interface.
+ @return
+ The positionFile (NULL when not set)
+ */
+char * getPositionFile(void) {
+ if (!positionFileSet) {
+ return NULL;
+ }
+
+ return &positionFile[0];
+}
+
+int setPositionFile(const char *value, void *data __attribute__ ((unused)),
+ set_plugin_parameter_addon addon __attribute__ ((unused))) {
+ size_t valueLength;
+
+ assert(value != NULL);
+
+ valueLength = strlen(value);
+ if (valueLength > PATH_MAX) {
+ pudError(false, "Value of parameter %s is too long, maximum length is"
+ " %u, current length is %lu", PUD_POSFILE_NAME, PATH_MAX, (unsigned long) valueLength);
+ return true;
+ }
+
+ strcpy((char *) &positionFile[0], value);
+ positionFileSet = true;
+
+ return false;
+}
+
+/*
+ * positionFilePeriod
+ */
+
+/** The positionFilePeriod value (milliseconds) */
+unsigned long long positionFilePeriod = PUD_POSFILEPERIOD_DEFAULT;
+
+/**
+ @return
+ The positionFilePeriod (in milliseconds)
+ */
+unsigned long long getPositionFilePeriod(void) {
+ return positionFilePeriod;
+}
+
+/**
+ Set the positionFilePeriod
+
+ @param value
+ The positionFilePeriod (a number in string representation)
+ @param data
+ Unused
+ @param addon
+ Unused
+
+ @return
+ - true when an error is detected
+ - false otherwise
+ */
+int setPositionFilePeriod(const char *value, void *data __attribute__ ((unused)),
+ set_plugin_parameter_addon addon __attribute__ ((unused))) {
+ static const char * valueName = PUD_POSFILEPERIOD_NAME;
+ unsigned long long positionFilePeriodNew;
+
+ assert(value != NULL);
+
+ if (!readULL(valueName, value, &positionFilePeriodNew, 10)) {
+ return true;
+ }
+
+ if ((positionFilePeriodNew != 0)
+ && ((positionFilePeriodNew < PUD_POSFILEPERIOD_MIN) || (positionFilePeriodNew > PUD_POSFILEPERIOD_MAX))) {
+ pudError(false, "Configured %s (%llu) is outside of"
+ " valid range %llu-%llu", valueName, positionFilePeriodNew, PUD_POSFILEPERIOD_MIN, PUD_POSFILEPERIOD_MAX);
+ return true;
+ }
+
+ positionFilePeriod = positionFilePeriodNew;
+
+ return false;
+}
+
+/*
+ * txNonOlsrIf
+ */
+
+/** The maximum number of tx non-olsr interfaces */
+#define PUD_TX_NON_OLSR_IF_MAX 32
+
+/** Array with tx non-olsr interface names */
+static unsigned char txNonOlsrInterfaceNames[PUD_TX_NON_OLSR_IF_MAX][IFNAMSIZ + 1];
+
+/** The number of tx interface names in the array */
+static unsigned int txNonOlsrInterfaceCount = 0;
+
+/**
+ Determine whether a give interface name is configured as a transmit non-OLSR
+ interface.
@param ifName
The interface to check
assert (ifName != NULL);
for (i = 0; i < txNonOlsrInterfaceCount; i++) {
- if (strncmp((char *) &txNonOlsrInterfaceNames[i][0], ifName, IFNAMSIZ
- + 1) == 0) {
+ if (strncmp((char *) &txNonOlsrInterfaceNames[i][0], ifName, IFNAMSIZ + 1) == 0) {
return true;
}
}
return false;
}
-/**
- Add a transmit non-OLSR interface
-
- @param value
- The name of the non-OLSR interface to add
- @param data
- Unused
- @param addon
- Unused
-
- @return
- - true when an error is detected
- - false otherwise
- */
int addTxNonOlsrInterface(const char *value, void *data __attribute__ ((unused)),
set_plugin_parameter_addon addon __attribute__ ((unused))) {
- unsigned long valueLength;
+ size_t valueLength;
assert (value != NULL);
+ if (txNonOlsrInterfaceCount >= PUD_TX_NON_OLSR_IF_MAX) {
+ pudError(false, "Can not configure more than %u transmit interfaces", PUD_TX_NON_OLSR_IF_MAX);
+ return true;
+ }
+
valueLength = strlen(value);
if (valueLength > IFNAMSIZ) {
- pudError(false, "Configured %s (%s) is too long,"
- " maximum length is %u, current length is %lu",
- PUD_TX_NON_OLSR_IF_NAME, value, IFNAMSIZ, valueLength);
+ pudError(false, "Value of parameter %s (%s) is too long, maximum length is %u, current length is %lu",
+ PUD_TX_NON_OLSR_IF_NAME, value, IFNAMSIZ, (long unsigned int)valueLength);
return true;
}
if (!isTxNonOlsrInterface(value)) {
- if (txNonOlsrInterfaceCount >= PUD_TX_NON_OLSR_IF_MAX) {
- pudError(false, "Can not configure more than %u transmit"
- " interfaces", PUD_TX_NON_OLSR_IF_MAX);
- return true;
- }
-
- strcpy((char *) &txNonOlsrInterfaceNames[txNonOlsrInterfaceCount][0],
- value);
+ strcpy((char *) &txNonOlsrInterfaceNames[txNonOlsrInterfaceCount][0], value);
txNonOlsrInterfaceCount++;
}
return false;
}
+/**
+ * @return the number of configured non-olsr transmit interfaces
+ */
+unsigned int getTxNonOlsrInterfaceCount(void) {
+ return txNonOlsrInterfaceCount;
+}
+
+/**
+ * @param idx the index of the configured non-olsr transmit interface
+ * @return the index-th interface name
+ */
+unsigned char * getTxNonOlsrInterfaceName(unsigned int idx) {
+ return &txNonOlsrInterfaceNames[idx][0];
+}
+
/*
- * txMcAddr
+ * txMcAddr + txMcPort
*/
/** The tx multicast address */
*/
union olsr_sockaddr * getTxMcAddr(void) {
if (!txMcAddrSet) {
- setTxMcAddr(NULL, NULL, ((set_plugin_parameter_addon) {.pc = NULL}));
+ setTxMcAddr((olsr_cnf->ip_version == AF_INET) ? PUD_TX_MC_ADDR_4_DEFAULT : PUD_TX_MC_ADDR_6_DEFAULT,
+ NULL, ((set_plugin_parameter_addon) {.pc = NULL}));
}
return &txMcAddr;
}
-/**
- Set the transmit multicast address. Sets the address to its default value when
- the value is NULL. Also sets the port to its default value when the address
- was not yet set.
-
- @param value
- The transmit multicast address (in string representation)
- @param data
- Unused
- @param addon
- Unused
-
- @return
- - true when an error is detected
- - false otherwise
- */
int setTxMcAddr(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))) {
static const char * valueName = PUD_TX_MC_ADDR_NAME;
- void * ipAddress;
- in_port_t * port;
- const char * valueInternal = value;
- int conversion;
- getOlsrSockAddrAndPortAddresses(olsr_cnf->ip_version, &txMcAddr, &ipAddress,
- &port);
- if (olsr_cnf->ip_version == AF_INET) {
- txMcAddr.in4.sin_family = olsr_cnf->ip_version;
- if (valueInternal == NULL) {
- valueInternal = PUD_TX_MC_ADDR_4_DEFAULT;
- }
- } else {
- txMcAddr.in6.sin6_family = olsr_cnf->ip_version;
- if (valueInternal == NULL) {
- valueInternal = PUD_TX_MC_ADDR_6_DEFAULT;
- }
+ if (!readIPAddress(valueName, value, PUD_TX_MC_PORT_DEFAULT, &txMcAddr, &txMcAddrSet)) {
+ return true;
}
- if (!txMcAddrSet) {
- *port = htons(PUD_TX_MC_PORT_DEFAULT);
+ if (!isMulticast(&txMcAddr)) {
+ pudError(false, "Value of parameter %s (%s) is not a multicast address",
+ valueName, value);
+ return true;
}
- conversion = inet_pton(olsr_cnf->ip_version, valueInternal, ipAddress);
- if (conversion != 1) {
- pudError((conversion == -1) ? true : false,
- "Configured %s (%s) is not an IP address", valueName,
- valueInternal);
+ return false;
+}
+
+/**
+ @return
+ The transmit multicast port (in network byte order)
+ */
+unsigned short getTxMcPort(void) {
+ return getOlsrSockaddrPort(getTxMcAddr(), PUD_TX_MC_PORT_DEFAULT);
+}
+
+int setTxMcPort(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))) {
+ static const char * valueName = PUD_TX_MC_PORT_NAME;
+ unsigned short txMcPortNew;
+
+ if (!readUS(valueName, value, &txMcPortNew)) {
return true;
}
- if (!isMulticast(olsr_cnf->ip_version, &txMcAddr)) {
- pudError(false, "Configured %s (%s) is not a multicast address",
- valueName, valueInternal);
+ if (txMcPortNew < 1) {
+ pudError(false, "Value of parameter %s (%u) is outside of valid range 1-65535", valueName, txMcPortNew);
return true;
}
- txMcAddrSet = true;
+ setOlsrSockaddrPort(getTxMcAddr(), htons((in_port_t) txMcPortNew));
+
return false;
}
/*
- * txMcPort
+ * txTtl
*/
+/** The tx TTL */
+static unsigned char txTtl = PUD_TX_TTL_DEFAULT;
+
/**
@return
- The transmit multicast port (in network byte order)
+ The transmit multicast IP packet time-to-live
*/
-unsigned short getTxMcPort(void) {
- in_port_t * port;
- getOlsrSockaddrPortAddress(olsr_cnf->ip_version, getTxMcAddr(), &port);
- return *port;
+unsigned char getTxTtl(void) {
+ return txTtl;
}
-/**
- Set the transmit multicast port
+int setTxTtl(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))) {
+ static const char * valueName = PUD_TX_TTL_NAME;
- @param value
- The transmit multicast port (a number in string representation)
- @param data
- Unused
- @param addon
- Unused
+ if (!readUC(valueName, value, &txTtl)) {
+ return true;
+ }
+
+ if ((txTtl < 1) /* || (txTtl > MAX_TTL) */) {
+ pudError(false, "Value of parameter %s (%u) is outside of"
+ " valid range 1-%u", valueName, txTtl, MAX_TTL);
+ return true;
+ }
+ return false;
+}
+
+/*
+ * txNmeaMessagePrefix
+ */
+
+/** The exact length of the tx NMEA message prefix */
+#define PUD_TXNMEAMESSAGEPREFIXLENGTH 4
+
+/** The tx NMEA message prefix buffer */
+static unsigned char txNmeaMessagePrefix[PUD_TXNMEAMESSAGEPREFIXLENGTH + 1];
+
+/** True when the tx NMEA message prefix is set */
+static bool txNmeaMessagePrefixSet = false;
+
+/**
@return
- - true when an error is detected
- - false otherwise
+ The transmit multicast NMEA message prefix
*/
-int setTxMcPort(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))) {
- static const char * valueName = PUD_TX_MC_PORT_NAME;
- unsigned long long txMcPortNew;
- in_port_t * port;
- union olsr_sockaddr * addr = getTxMcAddr();
+unsigned char * getTxNmeaMessagePrefix(void) {
+ if (!txNmeaMessagePrefixSet) {
+ setTxNmeaMessagePrefix(PUD_TX_NMEAMESSAGEPREFIX_DEFAULT, NULL,
+ (set_plugin_parameter_addon) {.pc = NULL});
+ }
+ return &txNmeaMessagePrefix[0];
+}
+
+int setTxNmeaMessagePrefix(const char *value, void *data __attribute__ ((unused)),
+ set_plugin_parameter_addon addon __attribute__ ((unused))) {
+ const char * invalidCharName;
+ static const char * valueName = PUD_TX_NMEAMESSAGEPREFIX_NAME;
+ size_t valueLength;
assert (value != NULL);
- if (!readULL(valueName, value, &txMcPortNew)) {
+ valueLength = strlen(value);
+ if (valueLength != PUD_TXNMEAMESSAGEPREFIXLENGTH) {
+ pudError(false, "Length of parameter %s (%s) must be exactly %u characters",
+ valueName, value, PUD_TXNMEAMESSAGEPREFIXLENGTH);
return true;
}
- if ((txMcPortNew < 1) || (txMcPortNew > 65535)) {
- pudError(false, "Configured %s (%llu) is outside of"
- " valid range 1-65535", valueName, txMcPortNew);
+ invalidCharName = nmea_parse_sentence_has_invalid_chars(value, valueLength);
+ if (invalidCharName) {
+ char report[256];
+ snprintf(report, sizeof(report), "Configured %s (%s),"
+ " contains invalid NMEA characters (%s)", valueName, value, invalidCharName);
+ pudError(false, "%s", report);
+ return true;
+ }
+
+ if ((strchr(value, ' ') != NULL) || (strchr(value, '\t') != NULL)) {
+ pudError(false, "Value of parameter %s (%s) can not contain whitespace",
+ valueName, value);
return true;
}
- getOlsrSockaddrPortAddress(olsr_cnf->ip_version, addr, &port);
- *port = htons((uint16_t) txMcPortNew);
-
+ strcpy((char *) &txNmeaMessagePrefix[0], value);
+ txNmeaMessagePrefixSet = true;
return false;
}
/*
- * uplinkAddr
+ * uplinkAddr + uplinkPort
*/
/** The uplink address */
/** True when the uplink address is set */
static bool uplinkAddrSet = false;
-/** True when the uplink address is set */
-static bool uplinkPortSet = false;
-
/**
@return
- true when the uplink address is set
*/
union olsr_sockaddr * getUplinkAddr(void) {
if (!uplinkAddrSet) {
- setUplinkAddr(NULL, NULL, ((set_plugin_parameter_addon) {.pc = NULL}));
+ setUplinkAddr((olsr_cnf->ip_version == AF_INET) ? PUD_UPLINK_ADDR_4_DEFAULT : PUD_UPLINK_ADDR_6_DEFAULT,
+ NULL, ((set_plugin_parameter_addon) {.pc = NULL}));
}
return &uplinkAddr;
}
-/**
- Set the uplink address. Sets the address to its default value when
- the value is NULL. Also sets the port to its default value when the address
- was not yet set.
-
- @param value
- The uplink address (in string representation)
- @param data
- Unused
- @param addon
- Unused
-
- @return
- - true when an error is detected
- - false otherwise
- */
int setUplinkAddr(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))) {
- static const char * valueName = PUD_UPLINK_ADDR_NAME;
- void * ipAddress;
- in_port_t * port;
- const char * valueInternal = value;
- int conversion;
- bool defaultValue = false;
-
- getOlsrSockAddrAndPortAddresses(olsr_cnf->ip_version, &uplinkAddr,
- &ipAddress, &port);
- if (olsr_cnf->ip_version == AF_INET) {
- uplinkAddr.in4.sin_family = olsr_cnf->ip_version;
- if (valueInternal == NULL) {
- valueInternal = PUD_UPLINK_ADDR_4_DEFAULT;
- defaultValue = true;
- }
- } else {
- uplinkAddr.in6.sin6_family = olsr_cnf->ip_version;
- if (valueInternal == NULL) {
- valueInternal = PUD_UPLINK_ADDR_6_DEFAULT;
- defaultValue = true;
- }
- }
-
- if (!uplinkPortSet) {
- *port = htons(PUD_UPLINK_PORT_DEFAULT);
- uplinkPortSet = true;
- }
-
- conversion = inet_pton(olsr_cnf->ip_version, valueInternal, ipAddress);
- if (conversion != 1) {
- pudError((conversion == -1) ? true : false,
- "Configured %s (%s) is not an IP address", valueName,
- valueInternal);
- return true;
- }
-
- if (!defaultValue) {
- uplinkAddrSet = true;
- }
-
- return false;
+ return !readIPAddress(PUD_UPLINK_ADDR_NAME, value, PUD_UPLINK_PORT_DEFAULT, &uplinkAddr, &uplinkAddrSet);
}
-/*
- * uplinkPort
- */
-
/**
@return
The uplink port (in network byte order)
*/
unsigned short getUplinkPort(void) {
- in_port_t * port;
- getOlsrSockaddrPortAddress(olsr_cnf->ip_version, getUplinkAddr(), &port);
- return *port;
+ return getOlsrSockaddrPort(getUplinkAddr(), PUD_UPLINK_PORT_DEFAULT);
}
-/**
- Set the uplink port
-
- @param value
- The uplink port (a number in string representation)
- @param data
- Unused
- @param addon
- Unused
-
- @return
- - true when an error is detected
- - false otherwise
- */
int setUplinkPort(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))) {
static const char * valueName = PUD_UPLINK_PORT_NAME;
- unsigned long long uplinkPortNew;
- in_port_t * port;
- union olsr_sockaddr * addr = getUplinkAddr();
-
- assert (value != NULL);
+ unsigned short uplinkPortNew;
- if (!readULL(valueName, value, &uplinkPortNew)) {
+ if (!readUS(valueName, value, &uplinkPortNew)) {
return true;
}
- if ((uplinkPortNew < 1) || (uplinkPortNew > 65535)) {
- pudError(false, "Configured %s (%llu) is outside of"
- " valid range 1-65535", valueName, uplinkPortNew);
+ if (uplinkPortNew < 1) {
+ pudError(false, "Value of parameter %s (%u) is outside of valid range 1-65535", valueName, uplinkPortNew);
return true;
}
- getOlsrSockaddrPortAddress(olsr_cnf->ip_version, addr, &port);
- *port = htons((uint16_t) uplinkPortNew);
- uplinkPortSet = true;
+ setOlsrSockaddrPort(getUplinkAddr(), htons((in_port_t) uplinkPortNew));
return false;
}
-
/*
* downlinkPort
*/
return downlinkPort;
}
-/**
- Set the downlink port
-
- @param value
- The downlink port (a number in string representation)
- @param data
- Unused
- @param addon
- Unused
-
- @return
- - true when an error is detected
- - false otherwise
- */
int setDownlinkPort(const char *value, void *data __attribute__ ((unused)),
set_plugin_parameter_addon addon __attribute__ ((unused))) {
static const char * valueName = PUD_DOWNLINK_PORT_NAME;
- unsigned long long downlinkPortNew;
+ unsigned short downlinkPortNew;
- assert(value != NULL);
-
- if (!readULL(valueName, value, &downlinkPortNew)) {
+ if (!readUS(valueName, value, &downlinkPortNew)) {
return true;
}
- if ((downlinkPortNew < 1) || (downlinkPortNew > 65535)) {
- pudError(false, "Configured %s (%llu) is outside of"
- " valid range 1-65535", valueName, downlinkPortNew);
+ if (downlinkPortNew < 1) {
+ pudError(false, "Value of parameter %s (%u) is outside of valid range 1-65535", valueName, downlinkPortNew);
return true;
}
return false;
}
-/*
- * txTtl
- */
-
-/** The tx TTL */
-static unsigned char txTtl = PUD_TX_TTL_DEFAULT;
-
-/**
- @return
- The transmit multicast IP packet time-to-live
- */
-unsigned char getTxTtl(void) {
- return txTtl;
-}
-
-/**
- Set the transmit multicast IP packet time-to-live
-
- @param value
- The transmit multicast IP packet time-to-live (a number in string representation)
- @param data
- Unused
- @param addon
- Unused
-
- @return
- - true when an error is detected
- - false otherwise
- */
-int setTxTtl(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))) {
- static const char * valueName = PUD_TX_TTL_NAME;
- unsigned long long txTtlNew;
-
- assert (value != NULL);
-
- if (!readULL(valueName, value, &txTtlNew)) {
- return true;
- }
-
- if ((txTtlNew < 1) || (txTtlNew > MAX_TTL)) {
- pudError(false, "Configured %s (%llu) is outside of"
- " valid range 1-%u", valueName, txTtlNew, MAX_TTL);
- return true;
- }
-
- txTtl = txTtlNew;
-
- return false;
-}
-
-/*
- * txNmeaMessagePrefix
- */
-
-/** The exact length of the tx NMEA message prefix */
-#define PUD_TXNMEAMESSAGEPREFIXLENGTH 4
-
-/** The tx NMEA message prefix buffer */
-static unsigned char txNmeaMessagePrefix[PUD_TXNMEAMESSAGEPREFIXLENGTH + 1];
-
-/** True when the tx NMEA message prefix is set */
-static bool txNmeaMessagePrefixSet = false;
-
-/**
- @return
- The transmit multicast NMEA message prefix
- */
-unsigned char * getTxNmeaMessagePrefix(void) {
- if (!txNmeaMessagePrefixSet) {
- setTxNmeaMessagePrefix(PUD_TX_NMEAMESSAGEPREFIX_DEFAULT, NULL,
- (set_plugin_parameter_addon) {.pc = NULL});
- }
- return &txNmeaMessagePrefix[0];
-}
-
-/**
- Set the transmit multicast NMEA message prefix
-
- @param value
- The transmit multicast NMEA message prefix (in string representation)
- @param data
- Unused
- @param addon
- Unused
-
- @return
- - true when an error is detected
- - false otherwise
- */
-int setTxNmeaMessagePrefix(const char *value, void *data __attribute__ ((unused)),
- set_plugin_parameter_addon addon __attribute__ ((unused))) {
- static const char * valueName = PUD_TX_NMEAMESSAGEPREFIX_NAME;
- size_t valueLength;
- bool invalidChars;
- char report[256];
-
- assert (value != NULL);
-
- valueLength = strlen(value);
- if (valueLength != PUD_TXNMEAMESSAGEPREFIXLENGTH) {
- pudError(false, "Configured %s (%s) must be %u exactly characters",
- valueName, value, PUD_TXNMEAMESSAGEPREFIXLENGTH);
- return true;
- }
-
- invalidChars = nmea_string_has_invalid_chars(value, valueName, &report[0],
- sizeof(report));
- if (invalidChars) {
- pudError(false, &report[0]);
- return true;
- }
-
- if ((strchr(value, ' ') != NULL) || (strchr(value, '\t') != NULL)) {
- pudError(false, "Configured %s (%s) can not contain whitespace",
- valueName, value);
- return true;
- }
-
- strcpy((char *) &txNmeaMessagePrefix[0], value);
- txNmeaMessagePrefixSet = true;
- return false;
-}
-
/*
* olsrTtl
*/
return olsrTtl;
}
-/**
- Set the OLSR multicast IP packet time-to-live
-
- @param value
- The OLSR multicast IP packet time-to-live (a number in string representation)
- @param data
- Unused
- @param addon
- Unused
-
- @return
- - true when an error is detected
- - false otherwise
- */
int setOlsrTtl(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))) {
static const char * valueName = PUD_OLSR_TTL_NAME;
- unsigned long long olsrTtlNew;
- assert (value != NULL);
-
- if (!readULL(valueName, value, &olsrTtlNew)) {
+ if (!readUC(valueName, value, &olsrTtl)) {
return true;
}
- if ((olsrTtlNew < 1) || (olsrTtlNew > MAX_TTL)) {
- pudError(false, "Configured %s (%llu) is outside of valid range 1-%u",
- valueName, olsrTtlNew, MAX_TTL);
+ if ((olsrTtl < 1) /* || (olsrTtl > MAX_TTL) */) {
+ pudError(false, "Value of parameter %s (%u) is outside of valid range 1-%u",
+ valueName, olsrTtl, MAX_TTL);
return true;
}
- olsrTtl = olsrTtlNew;
-
return false;
}
return updateIntervalStationary;
}
-/**
- Set stationary interval update plugin parameter
-
- @param value
- The stationary interval update plugin parameter (in seconds)
- @param data
- Unused
- @param addon
- Unused
-
- @return
- - true when an error is detected
- - false otherwise
- */
int setUpdateIntervalStationary(const char *value, void *data __attribute__ ((unused)),
set_plugin_parameter_addon addon __attribute__ ((unused))) {
static const char * valueName = PUD_UPDATE_INTERVAL_STATIONARY_NAME;
- unsigned long long updateIntervalStationaryNew;
- assert (value != NULL);
-
- if (!readULL(valueName, value, &updateIntervalStationaryNew)) {
+ if (!readULL(valueName, value, &updateIntervalStationary, 10)) {
return true;
}
- if (updateIntervalStationaryNew < 1) {
- pudError(false, "Configured %s must be at least 1", valueName);
+ if (updateIntervalStationary < 1) {
+ pudError(false, "Value of parameter %s must be at least 1", valueName);
return true;
}
- updateIntervalStationary = updateIntervalStationaryNew;
-
return false;
}
return updateIntervalMoving;
}
-/**
- Set moving interval update plugin parameter
-
- @param value
- The moving interval update plugin parameter (in seconds)
- @param data
- Unused
- @param addon
- Unused
-
- @return
- - true when an error is detected
- - false otherwise
- */
int setUpdateIntervalMoving(const char *value, void *data __attribute__ ((unused)),
set_plugin_parameter_addon addon __attribute__ ((unused))) {
static const char * valueName = PUD_UPDATE_INTERVAL_MOVING_NAME;
- unsigned long long updateIntervalMovingNew;
-
- assert (value != NULL);
- if (!readULL(valueName, value, &updateIntervalMovingNew)) {
+ if (!readULL(valueName, value, &updateIntervalMoving, 10)) {
return true;
}
- if (updateIntervalMovingNew < 1) {
- pudError(false, "Configured %s must be at least 1", valueName);
+ if (updateIntervalMoving < 1) {
+ pudError(false, "Value of parameter %s must be at least 1", valueName);
return true;
}
- updateIntervalMoving = updateIntervalMovingNew;
-
return false;
}
return uplinkUpdateIntervalStationary;
}
-/**
- Set uplink stationary interval update plugin parameter
-
- @param value
- The uplink stationary interval update plugin parameter (in seconds)
- @param data
- Unused
- @param addon
- Unused
-
- @return
- - true when an error is detected
- - false otherwise
- */
int setUplinkUpdateIntervalStationary(const char *value, void *data __attribute__ ((unused)),
set_plugin_parameter_addon addon __attribute__ ((unused))) {
static const char * valueName = PUD_UPLINK_UPDATE_INTERVAL_STATIONARY_NAME;
- unsigned long long uplinkUpdateIntervalStationaryNew;
- assert (value != NULL);
-
- if (!readULL(valueName, value, &uplinkUpdateIntervalStationaryNew)) {
+ if (!readULL(valueName, value, &uplinkUpdateIntervalStationary, 10)) {
return true;
}
- if (uplinkUpdateIntervalStationaryNew < 1) {
- pudError(false, "Configured %s must be at least 1", valueName);
+ if (uplinkUpdateIntervalStationary < 1) {
+ pudError(false, "Value of parameter %s must be at least 1", valueName);
return true;
}
- uplinkUpdateIntervalStationary = uplinkUpdateIntervalStationaryNew;
-
return false;
}
return uplinkUpdateIntervalMoving;
}
-/**
- Set uplink moving interval update plugin parameter
-
- @param value
- The uplink moving interval update plugin parameter (in seconds)
- @param data
- Unused
- @param addon
- Unused
-
- @return
- - true when an error is detected
- - false otherwise
- */
int setUplinkUpdateIntervalMoving(const char *value, void *data __attribute__ ((unused)),
set_plugin_parameter_addon addon __attribute__ ((unused))) {
static const char * valueName = PUD_UPLINK_UPDATE_INTERVAL_MOVING_NAME;
- unsigned long long uplinkUpdateIntervalMovingNew;
- assert (value != NULL);
+ if (!readULL(valueName, value, &uplinkUpdateIntervalMoving, 10)) {
+ return true;
+ }
- if (!readULL(valueName, value, &uplinkUpdateIntervalMovingNew)) {
+ if (uplinkUpdateIntervalMoving < 1) {
+ pudError(false, "Value of parameter %s must be at least 1", valueName);
return true;
}
- if (uplinkUpdateIntervalMovingNew < 1) {
- pudError(false, "Configured %s must be at least 1", valueName);
+ return false;
+}
+
+/*
+ * gatewayDeterminationInterval
+ */
+
+/** The gateway determination interval plugin parameter (in seconds) */
+static unsigned long long gatewayDeterminationInterval = PUD_GATEWAY_DETERMINATION_INTERVAL_DEFAULT;
+
+/**
+ @return
+ The gateway determination interval plugin parameter (in seconds)
+ */
+unsigned long long getGatewayDeterminationInterval(void) {
+ return gatewayDeterminationInterval;
+}
+
+int setGatewayDeterminationInterval(const char *value, void *data __attribute__ ((unused)),
+ set_plugin_parameter_addon addon __attribute__ ((unused))) {
+ static const char * valueName = PUD_GATEWAY_DETERMINATION_INTERVAL_NAME;
+
+ if (!readULL(valueName, value, &gatewayDeterminationInterval, 10)) {
return true;
}
- uplinkUpdateIntervalMoving = uplinkUpdateIntervalMovingNew;
+ if (gatewayDeterminationInterval < 1) {
+ pudError(false, "Value of parameter %s must be at least 1", valueName);
+ return true;
+ }
return false;
}
return movingSpeedThreshold;
}
-/**
- Set moving speed threshold plugin parameter
-
- @param value
- The moving speed threshold plugin parameter (in kph)
- @param data
- Unused
- @param addon
- Unused
-
- @return
- - true when an error is detected
- - false otherwise
- */
int setMovingSpeedThreshold(const char *value, void *data __attribute__ ((unused)),
set_plugin_parameter_addon addon __attribute__ ((unused))) {
- static const char * valueName = PUD_MOVING_SPEED_THRESHOLD_NAME;
- unsigned long long movingSpeedThresholdNew;
-
- assert (value != NULL);
-
- if (!readULL(valueName, value, &movingSpeedThresholdNew)) {
- return true;
- }
-
- movingSpeedThreshold = movingSpeedThresholdNew;
-
- return false;
+ return !readULL(PUD_MOVING_SPEED_THRESHOLD_NAME, value, &movingSpeedThreshold, 10);
}
/*
return movingDistanceThreshold;
}
-/**
- Set moving distance threshold plugin parameter
-
- @param value
- The moving distance threshold plugin parameter (in meter)
- @param data
- Unused
- @param addon
- Unused
-
- @return
- - true when an error is detected
- - false otherwise
- */
int setMovingDistanceThreshold(const char *value, void *data __attribute__ ((unused)),
set_plugin_parameter_addon addon __attribute__ ((unused))) {
- static const char * valueName = PUD_MOVING_DISTANCE_THRESHOLD_NAME;
- unsigned long long movingDistanceThresholdNew;
-
- assert (value != NULL);
-
- if (!readULL(valueName, value, &movingDistanceThresholdNew)) {
- return true;
- }
-
- movingDistanceThreshold = movingDistanceThresholdNew;
-
- return false;
+ return !readULL(PUD_MOVING_DISTANCE_THRESHOLD_NAME, value, &movingDistanceThreshold, 10);
}
/*
* dopMultiplier
*/
-/* The DOP multiplier plugin parameter */
+/** The DOP multiplier plugin parameter */
static double dopMultiplier = PUD_DOP_MULTIPLIER_DEFAULT;
/**
return dopMultiplier;
}
-/**
- Set DOP multiplier plugin parameter
-
- @param value
- The DOP multiplier plugin parameter
- @param data
- Unused
- @param addon
- Unused
-
- @return
- - true when an error is detected
- - false otherwise
- */
int setDopMultiplier(const char *value, void *data __attribute__ ((unused)),
set_plugin_parameter_addon addon __attribute__ ((unused))) {
- static const char * valueName = PUD_DOP_MULTIPLIER_NAME;
- double dopMultiplierNew;
-
- assert (value != NULL);
-
- if (!readDouble(valueName, value, &dopMultiplierNew)) {
- return true;
- }
-
- dopMultiplier = dopMultiplierNew;
-
- return false;
+ return !readDouble(PUD_DOP_MULTIPLIER_NAME, value, &dopMultiplier);
}
/*
return defaultHdop;
}
-/**
- Set default HDOP plugin parameter
-
- @param value
- The default HDOP plugin parameter (in meters)
- @param data
- Unused
- @param addon
- Unused
-
- @return
- - true when an error is detected
- - false otherwise
- */
int setDefaultHdop(const char *value, void *data __attribute__ ((unused)),
set_plugin_parameter_addon addon __attribute__ ((unused))) {
- static const char * valueName = PUD_MOVING_DISTANCE_THRESHOLD_NAME;
- unsigned long long defaultHdopNew;
-
- assert (value != NULL);
-
- if (!readULL(valueName, value, &defaultHdopNew)) {
- return true;
- }
-
- defaultHdop = defaultHdopNew;
-
- return false;
+ return !readULL(PUD_DEFAULT_HDOP_NAME, value, &defaultHdop, 10);
}
/*
return defaultVdop;
}
-/**
- Set default VDOP plugin parameter
-
- @param value
- The default VDOP plugin parameter (in meters)
- @param data
- Unused
- @param addon
- Unused
-
- @return
- - true when an error is detected
- - false otherwise
- */
int setDefaultVdop(const char *value, void *data __attribute__ ((unused)),
set_plugin_parameter_addon addon __attribute__ ((unused))) {
- static const char * valueName = PUD_MOVING_DISTANCE_THRESHOLD_NAME;
- unsigned long long defaultVdopNew;
-
- assert (value != NULL);
-
- if (!readULL(valueName, value, &defaultVdopNew)) {
- return true;
- }
-
- defaultVdop = defaultVdopNew;
-
- return false;
+ return !readULL(PUD_DEFAULT_VDOP_NAME, value, &defaultVdop, 10);
}
/*
return averageDepth;
}
-/**
- Set average depth plugin parameter
-
- @param value
- The average depth plugin parameter
- @param data
- Unused
- @param addon
- Unused
-
- @return
- - true when an error is detected
- - false otherwise
- */
int setAverageDepth(const char *value, void *data __attribute__ ((unused)),
set_plugin_parameter_addon addon __attribute__ ((unused))) {
static const char * valueName = PUD_AVERAGE_DEPTH_NAME;
- unsigned long long averageDepthNew;
-
- assert (value != NULL);
- if (!readULL(valueName, value, &averageDepthNew)) {
+ if (!readULL(valueName, value, &averageDepth, 10)) {
return true;
}
- if (averageDepthNew < 1) {
- pudError(false, "Configured %s must be at least 1", valueName);
+ if (averageDepth < 1) {
+ pudError(false, "Value of parameter %s must be at least 1", valueName);
return true;
}
- averageDepth = averageDepthNew;
-
return false;
}
return hysteresisCountToStationary;
}
-/**
- Set hysteresis count plugin parameter
-
- @param value
- The hysteresis count plugin parameter
- @param data
- Unused
- @param addon
- Unused
-
- @return
- - true when an error is detected
- - false otherwise
- */
int setHysteresisCountToStationary(const char *value, void *data __attribute__ ((unused)),
set_plugin_parameter_addon addon __attribute__ ((unused))) {
- static const char * valueName = PUD_HYSTERESIS_COUNT_2STAT_NAME;
- unsigned long long hysteresisCountNew;
-
- assert (value != NULL);
-
- if (!readULL(valueName, value, &hysteresisCountNew)) {
- return true;
- }
-
- hysteresisCountToStationary = hysteresisCountNew;
-
- return false;
+ return !readULL(PUD_HYSTERESIS_COUNT_2STAT_NAME, value, &hysteresisCountToStationary, 10);
}
/*
return hysteresisCountToMoving;
}
-/**
- Set hysteresis count plugin parameter
+int setHysteresisCountToMoving(const char *value, void *data __attribute__ ((unused)),
+ set_plugin_parameter_addon addon __attribute__ ((unused))) {
+ return !readULL(PUD_HYSTERESIS_COUNT_2MOV_NAME, value, &hysteresisCountToMoving, 10);
+}
- @param value
- The hysteresis count plugin parameter
- @param data
- Unused
- @param addon
- Unused
+/*
+ * gatewayHysteresisCountToStationary
+ */
+
+/** The hysteresis count for changing state from moving to stationary */
+static unsigned long long gatewayHysteresisCountToStationary = PUD_GAT_HYSTERESIS_COUNT_2STAT_DEFAULT;
+/**
@return
- - true when an error is detected
- - false otherwise
+ The hysteresis count for changing state from moving to stationary
*/
-int setHysteresisCountToMoving(const char *value, void *data __attribute__ ((unused)),
+unsigned long long getGatewayHysteresisCountToStationary(void) {
+ return gatewayHysteresisCountToStationary;
+}
+
+int setGatewayHysteresisCountToStationary(const char *value, void *data __attribute__ ((unused)),
set_plugin_parameter_addon addon __attribute__ ((unused))) {
- static const char * valueName = PUD_HYSTERESIS_COUNT_2MOV_NAME;
- unsigned long long hysteresisCountNew;
+ return !readULL(PUD_GAT_HYSTERESIS_COUNT_2STAT_NAME, value, &gatewayHysteresisCountToStationary, 10);
+}
- assert (value != NULL);
+/*
+ * gatewayHysteresisCountToMoving
+ */
- if (!readULL(valueName, value, &hysteresisCountNew)) {
- return true;
- }
+/** The hysteresis count for changing state from stationary to moving */
+static unsigned long long gatewayHysteresisCountToMoving = PUD_GAT_HYSTERESIS_COUNT_2MOV_DEFAULT;
- hysteresisCountToMoving = hysteresisCountNew;
+/**
+ @return
+ The hysteresis count for changing state from stationary to moving
+ */
+unsigned long long getGatewayHysteresisCountToMoving(void) {
+ return gatewayHysteresisCountToMoving;
+}
- return false;
+int setGatewayHysteresisCountToMoving(const char *value, void *data __attribute__ ((unused)),
+ set_plugin_parameter_addon addon __attribute__ ((unused))) {
+ return !readULL(PUD_GAT_HYSTERESIS_COUNT_2MOV_NAME, value, &gatewayHysteresisCountToMoving, 10);
}
/*
* useDeDup
*/
-/* when true then duplicate message detection is performed */
+/** when true then duplicate message detection is performed */
static bool useDeDup = PUD_USE_DEDUP_DEFAULT;
/**
return useDeDup;
}
-/**
- Set duplicate message detection setting plugin parameter
-
- @param value
- The duplicate message detection setting plugin parameter
- @param data
- Unused
- @param addon
- Unused
-
- @return
- - true when an error is detected
- - false otherwise
- */
int setUseDeDup(const char *value, void *data __attribute__ ((unused)),
set_plugin_parameter_addon addon __attribute__ ((unused))) {
- static const char * valueName = PUD_USE_DEDUP_NAME;
- unsigned long long useDeDupNew;
-
- assert (value != NULL);
-
- if (!readULL(valueName, value, &useDeDupNew)) {
- return true;
- }
-
- if ((useDeDupNew != 0) && (useDeDupNew != 1)) {
- pudError(false, "Configured %s must be 0 (false) or 1 (true)",
- valueName);
- return true;
- }
-
- useDeDup = (useDeDupNew == 1);
-
- return false;
+ return !readBool(PUD_USE_DEDUP_NAME, value, &useDeDup);
}
/*
* deDupDepth
*/
-/** The hysteresis count for changing state from stationary to moving */
+/** The deduplication depth */
static unsigned long long deDupDepth = PUD_DEDUP_DEPTH_DEFAULT;
/**
@return
- The hysteresis count for changing state from stationary to moving
+ The deduplication depth
*/
unsigned long long getDeDupDepth(void) {
return deDupDepth;
}
-/**
- Set de-duplication depth plugin parameter
-
- @param value
- The de-duplication depth plugin parameter
- @param data
- Unused
- @param addon
- Unused
-
- @return
- - true when an error is detected
- - false otherwise
- */
int setDeDupDepth(const char *value, void *data __attribute__ ((unused)),
set_plugin_parameter_addon addon __attribute__ ((unused))) {
- static const char * valueName = PUD_DEDUP_DEPTH_NAME;
- unsigned long long deDupDepthNew;
-
- assert (value != NULL);
-
- if (!readULL(valueName, value, &deDupDepthNew)) {
- return true;
- }
-
- deDupDepth = deDupDepthNew;
-
- return false;
+ return !readULL(PUD_DEDUP_DEPTH_NAME, value, &deDupDepth, 10);
}
/*
* useLoopback
*/
-/* when true then loopback is performed */
+/** when true then loopback is performed */
static bool useLoopback = PUD_USE_LOOPBACK_DEFAULT;
/**
return useLoopback;
}
-/**
- Set loopback usage plugin parameter
-
- @param value
- The loopback usage plugin parameter
- @param data
- Unused
- @param addon
- Unused
-
- @return
- - true when an error is detected
- - false otherwise
- */
int setUseLoopback(const char *value, void *data __attribute__ ((unused)),
set_plugin_parameter_addon addon __attribute__ ((unused))) {
- static const char * valueName = PUD_USE_LOOPBACK_NAME;
- unsigned long long useLoopbackNew;
-
- assert (value != NULL);
-
- if (!readULL(valueName, value, &useLoopbackNew)) {
- return true;
- }
-
- if ((useLoopbackNew != 0) && (useLoopbackNew != 1)) {
- pudError(false, "Configured %s must be 0 (false) or 1 (true)",
- valueName);
- return true;
- }
-
- useLoopback = (useLoopbackNew == 1);
-
- return false;
+ return !readBool(PUD_USE_LOOPBACK_NAME, value, &useLoopback);
}
/*
unsigned int checkConfig(void) {
int retval = true;
- if (!olsr_cnf->smart_gw_active) {
- pudError(false, "Smart Gateway must be active");
- retval = false;
- }
-
if (rxNonOlsrInterfaceCount == 0) {
pudError(false, "No receive non-OLSR interfaces configured");
retval = false;
retval = false;
}
- if (!nodeIdSet) {
- if (nodeIdType == PUD_NODEIDTYPE_DNS) {
- char name[PUD_NODEIDMAXLENGTH + 1];
-
- errno = 0;
- if (gethostname(&name[0], sizeof(name)) < 0) {
- pudError(true, "Could not get the host name");
- retval = false;
- } else {
- setNodeId(&name[0], NULL,
- (set_plugin_parameter_addon) {.pc = NULL});
- }
- } else if ((nodeIdType != PUD_NODEIDTYPE_MAC) && (nodeIdType
- != PUD_NODEIDTYPE_IPV4) && (nodeIdType != PUD_NODEIDTYPE_IPV6)) {
- pudError(false, "No node ID set while one is required for"
- " node type %u", nodeIdType);
- retval = false;
- }
- }
-
- if (!setupNodeIdBinaryAndValidate(nodeIdType)) {
- retval = false;
- }
-
if (updateIntervalMoving > updateIntervalStationary) {
pudError(false,"The update interval for moving situations must not be"
" larger than that for stationary situations");
retval = false;
}
- if (getUplinkPort() == getDownlinkPort()) {
+ if (isUplinkAddrSet() && (getUplinkPort() == getDownlinkPort())) {
pudError(false, "The uplink port and the downlink port must not be the same");
retval = false;
}
- false otherwise
*/
unsigned int checkRunSetup(void) {
- int retval = true;
- unsigned int i;
-
- /* any receive interface name that is configured but is not the name of an
- * actual receive interface is not a valid interface name */
- for (i = 0; i < rxNonOlsrInterfaceCount; i++) {
- unsigned char * nonOlsrInterfaceName = &rxNonOlsrInterfaceNames[i][0];
-
- TRxTxNetworkInterface * interfaceObject = getRxNetworkInterfaces();
- bool found = false;
- while (interfaceObject != NULL) {
- if (strncmp((char *) nonOlsrInterfaceName,
- (char *) &interfaceObject->name[0], IFNAMSIZ + 1) == 0) {
- found = true;
- break;
- }
- interfaceObject = interfaceObject->next;
- }
- if (!found) {
- pudError(false, "Configured receive non-OLSR interface %s is not"
- " a known interface name", nonOlsrInterfaceName);
- retval = false;
- }
- }
-
- /* any transmit interface name that is configured but is not the name of an
- * actual transmit interface is not a valid interface name */
- for (i = 0; i < txNonOlsrInterfaceCount; i++) {
- unsigned char * nonOlsrInterfaceName = &txNonOlsrInterfaceNames[i][0];
-
- TRxTxNetworkInterface * interfaceObject = getTxNetworkInterfaces();
- bool found = false;
- while (interfaceObject != NULL) {
- if (strncmp((char *) nonOlsrInterfaceName,
- (char *) &interfaceObject->name[0], IFNAMSIZ + 1) == 0) {
- found = true;
- break;
- }
- interfaceObject = interfaceObject->next;
- }
- if (!found) {
- pudError(false, "Configured transmit non-OLSR interface %s is not"
- " a known interface name", nonOlsrInterfaceName);
- retval = false;
- }
- }
-
- return retval;
+ return true;
}