1 #include "configuration.h"
6 #include "networkInterfaces.h"
9 #include "olsr_types.h"
18 #include <netinet/in.h>
19 #include <arpa/inet.h>
20 #include <sys/socket.h>
22 #include <nmea/util.h>
29 Determine the address of the port in an OLSR socket address
32 The IP version (AF_INET or AF_INET6)
34 A pointer to OLSR socket address
38 static in_port_t * getOlsrSockaddrPort(int ipVersion, union olsr_sockaddr * addr) {
39 if (ipVersion == AF_INET) {
40 return &addr->in4.sin_port;
42 return &addr->in6.sin6_port;
47 Get pointer to the IP address and port in an OLSR socket address
49 The IP version (AF_INET or AF_INET6)
51 A pointer to OLSR socket address
53 A pointer to the location where the pointer to the IP address will be stored
55 A pointer to the location where the pointer to the port will be stored
57 static void getOlsrSockAddrAndPort(int ipVersion, union olsr_sockaddr * addr,
58 void ** ipAddress, in_port_t ** port) {
59 if (ipVersion == AF_INET) {
60 *ipAddress = (void *) &addr->in4.sin_addr;
61 *port = (void *) &addr->in4.sin_port;
63 *ipAddress = (void *) &addr->in6.sin6_addr;
64 *port = (void *) &addr->in6.sin6_port;
69 Read an unsigned long long number from a value string
74 the string to convert to a number
76 a pointer to the location where to store the number upon successful conversion
82 static bool readULL(const char * valueName, const char * value,
83 unsigned long long * valueNumber) {
85 unsigned long long valueNew;
88 valueNew = strtoull(value, &endPtr, 10);
90 if (!((endPtr != value) && (*value != '\0') && (*endPtr == '\0'))) {
91 /* invalid conversion */
92 pudError(true, "Configured %s (%s) could not be converted to a number",
97 *valueNumber = valueNew;
103 Read a double number from a value string
106 the name of the value
108 the string to convert to a number
110 a pointer to the location where to store the number upon successful conversion
116 static bool readDouble(const char * valueName, const char * value,
117 double * valueNumber) {
118 char * endPtr = NULL;
122 valueNew = strtod(value, &endPtr);
124 if (!((endPtr != value) && (*value != '\0') && (*endPtr == '\0'))) {
125 /* invalid conversion */
126 pudError(true, "Configured %s (%s) could not be converted to a number",
131 *valueNumber = valueNew;
140 /** The nodeIdType */
141 static NodeIdType nodeIdType = PUD_NODE_ID_TYPE_DEFAULT;
147 NodeIdType getNodeIdTypeNumber(void) {
152 Set the node ID type.
155 The value of the node ID type to set (a number in string representation)
162 - true when an error is detected
165 int setNodeIdType(const char *value, void *data __attribute__ ((unused)),
166 set_plugin_parameter_addon addon __attribute__ ((unused))) {
167 static const char * valueName = PUD_NODE_ID_TYPE_NAME;
168 unsigned long long nodeIdTypeNew;
170 assert (value != NULL);
172 if (!readULL(valueName, value, &nodeIdTypeNew)) {
176 if (nodeIdTypeNew > PUD_NODE_ID_TYPE_MAX) {
177 pudError(false, "Configured %s (%llu) is out of range 0-%u", valueName,
178 nodeIdTypeNew, PUD_NODE_ID_TYPE_MAX);
182 switch (nodeIdTypeNew) {
183 case PUD_NODEIDTYPE_MAC:
184 case PUD_NODEIDTYPE_MSISDN:
185 case PUD_NODEIDTYPE_TETRA:
186 case PUD_NODEIDTYPE_DNS:
187 case PUD_NODEIDTYPE_IPV4:
188 case PUD_NODEIDTYPE_IPV6:
189 case PUD_NODEIDTYPE_192:
190 case PUD_NODEIDTYPE_193:
191 case PUD_NODEIDTYPE_194:
195 pudError(false, "Configured %s (%llu) is reserved", valueName,
200 nodeIdType = nodeIdTypeNew;
209 /** The maximum length of a nodeId */
210 #define PUD_NODEIDMAXLENGTH 255
212 /** The nodeId buffer */
213 static unsigned char nodeId[PUD_NODEIDMAXLENGTH + 1];
215 /** The length of the string in the nodeId buffer */
216 static size_t nodeIdLength = 0;
218 /** True when the nodeId is set */
219 static bool nodeIdSet = false;
221 /** The nodeId as a nuber */
222 static unsigned long long nodeIdNumber = 0;
224 /** True when the nodeIdNumber is set */
225 static bool nodeIdNumberSet = false;
231 unsigned char * getNodeId(void) {
232 return getNodeIdWithLength(NULL);
237 A pointer to the node ID number
242 bool getNodeIdAsNumber(unsigned long long * value) {
243 if (!nodeIdNumberSet) {
244 if (!readULL(PUD_NODE_ID_NAME, (char *) &nodeId[0], &nodeIdNumber)) {
247 nodeIdNumberSet = true;
249 *value = nodeIdNumber;
254 Get the nodeId and its length
257 a pointer to the variable in which to store the nodeId length (allowed to be
258 NULL, in which case the length is not stored)
263 unsigned char * getNodeIdWithLength(size_t *length) {
265 setNodeId("", NULL, (set_plugin_parameter_addon) {.pc = NULL});
268 if (length != NULL) {
269 *length = nodeIdLength;
279 The value of the node ID to set (in string representation)
286 - true when an error is detected
289 int setNodeId(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))) {
290 static const char * valueName = PUD_NODE_ID_NAME;
293 assert (value != NULL);
295 valueLength = strlen(value);
296 if (valueLength > PUD_NODEIDMAXLENGTH) {
297 pudError(false, "Configured %s is too long, maximum length is"
298 " %u, current length is %lu", valueName, PUD_NODEIDMAXLENGTH,
299 (unsigned long) valueLength);
303 strcpy((char *) &nodeId[0], value);
304 nodeIdLength = valueLength;
314 /** The size of the cached nodeId buffer */
315 #define PUD_CACHED_NODEID_BUFFER_SIZE 16
317 /** The cached nodeId buffer: contains a pre-processed version of the nodeId
318 in order to improve performance. It is currently used for nodeIdTypes
319 PUD_NODEIDTYPE_MSISDN, PUD_NODEIDTYPE_TETRA, PUD_NODEIDTYPE_192,
320 PUD_NODEIDTYPE_193 (so basically for numbers that will not change) */
321 static unsigned char cachedNodeIdBuffer[PUD_CACHED_NODEID_BUFFER_SIZE];
323 /** The number of bytes stored in cachedNodeIdBuffer */
324 static unsigned int cachedNodeIdBufferLength = 0;
328 A pointer to the location in which to store a pointer to the nodeId cache
331 A pointer to the location in which to store the number of bytes in the buffer
333 void getNodeIdNumberForOlsrCache(unsigned char ** buffer, unsigned int * length) {
334 *buffer = &cachedNodeIdBuffer[0];
335 *length = cachedNodeIdBufferLength;
339 Check a nodeId number for validity and if valid set it up in the
340 cachedNodeIdBuffer. The valid range for the number is [min, max].
343 The lower bound for a valid number
345 The upper bound for a valid number
347 The number of bytes used by the number in the wire format
350 - true when the number is valid
353 static bool setupNodeIdNumberForOlsrCache(unsigned long long min,
354 unsigned long long max, unsigned int bytes) {
355 unsigned long long val;
357 assert (bytes <= PUD_CACHED_NODEID_BUFFER_SIZE);
359 if (!getNodeIdAsNumber(&val)) {
363 if ((val >= min) && (val <= max)) {
366 cachedNodeIdBuffer[i] = val & 0xff;
373 cachedNodeIdBufferLength = bytes;
377 pudError(false, "%s value %llu is out of range [%llu,%llu]",
378 PUD_NODE_ID_NAME, val, min, max);
387 Validate whether the configured nodeId is valid w.r.t. the configured
394 static bool setupNodeIdNumberForOlsrCacheAndValidate(NodeIdType nodeIdTypeNumber) {
395 switch (nodeIdTypeNumber) {
396 case PUD_NODEIDTYPE_IPV4: /* IPv4 address */
397 case PUD_NODEIDTYPE_IPV6: /* IPv6 address */
398 case PUD_NODEIDTYPE_MAC: /* hardware address */
399 /* explicit return: configured nodeId is not relevant */
402 case PUD_NODEIDTYPE_MSISDN: /* an MSISDN number */
403 return setupNodeIdNumberForOlsrCache(0LL, 999999999999999LL, 7);
405 case PUD_NODEIDTYPE_TETRA: /* a Tetra number */
406 return setupNodeIdNumberForOlsrCache(0LL, 99999999999999999LL, 8);
408 case PUD_NODEIDTYPE_DNS: /* DNS name */
413 invalidChars = nmea_string_has_invalid_chars((char *) getNodeId(),
414 PUD_NODE_ID_NAME, &report[0], sizeof(report));
416 pudError(false, &report[0]);
418 return !invalidChars;
421 case PUD_NODEIDTYPE_192:
422 return setupNodeIdNumberForOlsrCache(0LL, 9999999LL, 3);
424 case PUD_NODEIDTYPE_193:
425 return setupNodeIdNumberForOlsrCache(0LL, 999999LL, 3);
427 case PUD_NODEIDTYPE_194:
428 return setupNodeIdNumberForOlsrCache(1LL, 8191LL, 2);
430 default: /* unsupported */
431 /* explicit return: configured nodeId is not relevant, will
432 * fallback to IP addresses */
443 /** The maximum number of RX non-OLSR interfaces */
444 #define PUD_RX_NON_OLSR_IF_MAX 32
446 /** Array with RX non-OLSR interface names */
447 static unsigned char rxNonOlsrInterfaceNames[PUD_RX_NON_OLSR_IF_MAX][IFNAMSIZ + 1];
449 /** The number of RX non-OLSR interface names in the array */
450 static unsigned int rxNonOlsrInterfaceCount = 0;
453 Determine whether a give interface name is configured as a receive non-OLSR
457 The interface name to check
460 - true when the given interface name is configured as a receive non-OLSR
464 bool isRxNonOlsrInterface(const char *ifName) {
467 assert (ifName != NULL);
469 for (i = 0; i < rxNonOlsrInterfaceCount; i++) {
470 if (strncmp((char *) &rxNonOlsrInterfaceNames[i][0], ifName, IFNAMSIZ
480 Add a receive non-OLSR interface
483 The name of the non-OLSR interface to add
490 - true when an error is detected
493 int addRxNonOlsrInterface(const char *value, void *data __attribute__ ((unused)),
494 set_plugin_parameter_addon addon __attribute__ ((unused))) {
495 unsigned long valueLength;
497 assert (value != NULL);
499 valueLength = strlen(value);
500 if (valueLength > IFNAMSIZ) {
501 pudError(false, "Configured %s (%s) is too long,"
502 " maximum length is %u, current length is %lu",
503 PUD_RX_NON_OLSR_IF_NAME, value, IFNAMSIZ, valueLength);
507 if (!isRxNonOlsrInterface(value)) {
508 if (rxNonOlsrInterfaceCount >= PUD_RX_NON_OLSR_IF_MAX) {
509 pudError(false, "Can't configure more than %u receive interfaces",
510 PUD_RX_NON_OLSR_IF_MAX);
514 strcpy((char *) &rxNonOlsrInterfaceNames[rxNonOlsrInterfaceCount][0],
516 rxNonOlsrInterfaceCount++;
523 * rxAllowedSourceIpAddress
526 /** The maximum number of RX allowed source IP addresses */
527 #define PUD_RX_ALLOWED_SOURCE_IP_MAX 32
529 /** Array with RX allowed source IP addresses */
530 static struct sockaddr rxAllowedSourceIpAddresses[PUD_RX_ALLOWED_SOURCE_IP_MAX];
532 /** The number of RX allowed source IP addresses in the array */
533 static unsigned int rxAllowedSourceIpAddressesCount = 0;
536 Determine whether a give IP address is configured as an allowed source IP
540 The IP address to check
543 - true when the given IP address is configured as an allowed source IP
547 bool isRxAllowedSourceIpAddress(struct sockaddr * sender) {
549 unsigned int addrSize;
552 if (rxAllowedSourceIpAddressesCount == 0) {
556 if (sender == NULL) {
560 if (sender->sa_family == AF_INET) {
561 addr = (void *) (&((struct sockaddr_in *) sender)->sin_addr);
562 addrSize = sizeof(struct in_addr);
564 addr = (void *) (&((struct sockaddr_in6 *) sender)->sin6_addr);
565 addrSize = sizeof(struct in6_addr);
568 for (i = 0; i < rxAllowedSourceIpAddressesCount; i++) {
569 if ((rxAllowedSourceIpAddresses[i].sa_family == sender->sa_family)
570 && (memcmp(&rxAllowedSourceIpAddresses[i].sa_data, addr,
580 Set the RX allowed source IP addresses.
583 The RX allowed source IP address (in string representation)
590 - true when an error is detected
593 int addRxAllowedSourceIpAddress(const char *value, void *data __attribute__ ((unused)),
594 set_plugin_parameter_addon addon __attribute__ ((unused))) {
595 static const char * valueName = PUD_RX_ALLOWED_SOURCE_IP_NAME;
596 const char * valueInternal = value;
598 struct sockaddr addr;
600 assert (value != NULL);
602 memset(&addr, 0, sizeof(addr));
604 addr.sa_family = olsr_cnf->ip_version;
605 conversion = inet_pton(olsr_cnf->ip_version, valueInternal, &addr.sa_data);
606 if (conversion != 1) {
607 pudError((conversion == -1) ? true : false,
608 "Configured %s (%s) is not an IP address", valueName,
613 if ((rxAllowedSourceIpAddressesCount == 0) || !isRxAllowedSourceIpAddress(&addr)) {
614 if (rxAllowedSourceIpAddressesCount >= PUD_RX_ALLOWED_SOURCE_IP_MAX) {
615 pudError(false, "Can't configure more than %u allowed source IP"
616 " addresses", PUD_RX_ALLOWED_SOURCE_IP_MAX);
620 memcpy(&rxAllowedSourceIpAddresses[rxAllowedSourceIpAddressesCount],
621 &addr, sizeof(addr));
622 rxAllowedSourceIpAddressesCount++;
632 /** The rx multicast address */
633 static union olsr_sockaddr rxMcAddr;
635 /** True when the rx multicast address is set */
636 static bool rxMcAddrSet = false;
640 The receive multicast address (in network byte order). Sets both the address
641 and the port to their default values when the address was not yet set.
643 union olsr_sockaddr * getRxMcAddr(void) {
645 setRxMcAddr(NULL, NULL, ((set_plugin_parameter_addon) {.pc = NULL}));
651 Set the receive multicast address. Sets the address to its default value when
652 the value is NULL. Also sets the port to its default value when the address
656 The receive multicast address (in string representation)
663 - true when an error is detected
666 int setRxMcAddr(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))) {
667 static const char * valueName = PUD_RX_MC_ADDR_NAME;
670 const char * valueInternal = value;
673 getOlsrSockAddrAndPort(olsr_cnf->ip_version, &rxMcAddr, &ipAddress, &port);
674 if (olsr_cnf->ip_version == AF_INET) {
675 rxMcAddr.in4.sin_family = olsr_cnf->ip_version;
676 if (valueInternal == NULL) {
677 valueInternal = PUD_RX_MC_ADDR_4_DEFAULT;
680 rxMcAddr.in6.sin6_family = olsr_cnf->ip_version;
681 if (valueInternal == NULL) {
682 valueInternal = PUD_RX_MC_ADDR_6_DEFAULT;
687 *port = htons(PUD_RX_MC_PORT_DEFAULT);
690 conversion = inet_pton(olsr_cnf->ip_version, valueInternal, ipAddress);
691 if (conversion != 1) {
692 pudError((conversion == -1) ? true : false,
693 "Configured %s (%s) is not an IP address", valueName,
698 if (!isMulticast(olsr_cnf->ip_version, &rxMcAddr)) {
699 pudError(false, "Configured %s (%s) is not a multicast address",
700 valueName, valueInternal);
714 The receive multicast port (in network byte order)
716 unsigned short getRxMcPort(void) {
717 union olsr_sockaddr * addr = getRxMcAddr();
718 return *getOlsrSockaddrPort(olsr_cnf->ip_version, addr);
722 Set the receive multicast port
725 The receive multicast port (a number in string representation)
732 - true when an error is detected
735 int setRxMcPort(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))) {
736 static const char * valueName = PUD_RX_MC_PORT_NAME;
737 unsigned long long rxMcPortNew;
739 union olsr_sockaddr * addr = getRxMcAddr();
741 assert (value != NULL);
743 if (!readULL(valueName, value, &rxMcPortNew)) {
747 if ((rxMcPortNew < 1) || (rxMcPortNew > 65535)) {
748 pudError(false, "Configured %s (%llu) is outside of"
749 " valid range 1-65535", valueName, rxMcPortNew);
753 port = getOlsrSockaddrPort(olsr_cnf->ip_version, addr);
754 *port = htons((uint16_t) rxMcPortNew);
763 /** The maximum number of rx non-olsr interfaces */
764 #define PUD_TX_NON_OLSR_IF_MAX 32
766 /** Array with tx non-olsr interface names */
767 static unsigned char txNonOlsrInterfaceNames[PUD_TX_NON_OLSR_IF_MAX][IFNAMSIZ + 1];
769 /** The number of tx interface names in the array */
770 static unsigned int txNonOlsrInterfaceCount = 0;
773 Determine whether a give interface name is configured as a transmit non-OLSR
777 The interface to check
780 - true when the given interface name is configured as a transmit non-OLSR
784 bool isTxNonOlsrInterface(const char *ifName) {
787 assert (ifName != NULL);
789 for (i = 0; i < txNonOlsrInterfaceCount; i++) {
790 if (strncmp((char *) &txNonOlsrInterfaceNames[i][0], ifName, IFNAMSIZ
800 Add a transmit non-OLSR interface
803 The name of the non-OLSR interface to add
810 - true when an error is detected
813 int addTxNonOlsrInterface(const char *value, void *data __attribute__ ((unused)),
814 set_plugin_parameter_addon addon __attribute__ ((unused))) {
815 unsigned long valueLength;
817 assert (value != NULL);
819 valueLength = strlen(value);
820 if (valueLength > IFNAMSIZ) {
821 pudError(false, "Configured %s (%s) is too long,"
822 " maximum length is %u, current length is %lu",
823 PUD_TX_NON_OLSR_IF_NAME, value, IFNAMSIZ, valueLength);
827 if (!isTxNonOlsrInterface(value)) {
828 if (txNonOlsrInterfaceCount >= PUD_TX_NON_OLSR_IF_MAX) {
829 pudError(false, "Can not configure more than %u transmit"
830 " interfaces", PUD_TX_NON_OLSR_IF_MAX);
834 strcpy((char *) &txNonOlsrInterfaceNames[txNonOlsrInterfaceCount][0],
836 txNonOlsrInterfaceCount++;
846 /** The tx multicast address */
847 static union olsr_sockaddr txMcAddr;
849 /** True when the tx multicast address is set */
850 static bool txMcAddrSet = false;
854 The transmit multicast address (in network byte order). Sets both the address
855 and the port to their default values when the address was not yet set.
857 union olsr_sockaddr * getTxMcAddr(void) {
859 setTxMcAddr(NULL, NULL, ((set_plugin_parameter_addon) {.pc = NULL}));
865 Set the transmit multicast address. Sets the address to its default value when
866 the value is NULL. Also sets the port to its default value when the address
870 The transmit multicast address (in string representation)
877 - true when an error is detected
880 int setTxMcAddr(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))) {
881 static const char * valueName = PUD_TX_MC_ADDR_NAME;
884 const char * valueInternal = value;
887 getOlsrSockAddrAndPort(olsr_cnf->ip_version, &txMcAddr, &ipAddress, &port);
888 if (olsr_cnf->ip_version == AF_INET) {
889 txMcAddr.in4.sin_family = olsr_cnf->ip_version;
890 if (valueInternal == NULL) {
891 valueInternal = PUD_TX_MC_ADDR_4_DEFAULT;
894 txMcAddr.in6.sin6_family = olsr_cnf->ip_version;
895 if (valueInternal == NULL) {
896 valueInternal = PUD_TX_MC_ADDR_6_DEFAULT;
901 *port = htons(PUD_TX_MC_PORT_DEFAULT);
904 conversion = inet_pton(olsr_cnf->ip_version, valueInternal, ipAddress);
905 if (conversion != 1) {
906 pudError((conversion == -1) ? true : false,
907 "Configured %s (%s) is not an IP address", valueName,
912 if (!isMulticast(olsr_cnf->ip_version, &txMcAddr)) {
913 pudError(false, "Configured %s (%s) is not a multicast address",
914 valueName, valueInternal);
928 The transmit multicast port (in network byte order)
930 unsigned short getTxMcPort(void) {
931 union olsr_sockaddr * addr = getTxMcAddr();
932 return *getOlsrSockaddrPort(olsr_cnf->ip_version, addr);
936 Set the transmit multicast port
939 The transmit multicast port (a number in string representation)
946 - true when an error is detected
949 int setTxMcPort(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))) {
950 static const char * valueName = PUD_TX_MC_PORT_NAME;
951 unsigned long long txMcPortNew;
953 union olsr_sockaddr * addr = getTxMcAddr();
955 assert (value != NULL);
957 if (!readULL(valueName, value, &txMcPortNew)) {
961 if ((txMcPortNew < 1) || (txMcPortNew > 65535)) {
962 pudError(false, "Configured %s (%llu) is outside of"
963 " valid range 1-65535", valueName, txMcPortNew);
967 port = getOlsrSockaddrPort(olsr_cnf->ip_version, addr);
968 *port = htons((uint16_t) txMcPortNew);
978 static unsigned char txTtl = PUD_TX_TTL_DEFAULT;
982 The transmit multicast IP packet time-to-live
984 unsigned char getTxTtl(void) {
989 Set the transmit multicast IP packet time-to-live
992 The transmit multicast IP packet time-to-live (a number in string representation)
999 - true when an error is detected
1002 int setTxTtl(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))) {
1003 static const char * valueName = PUD_TX_TTL_NAME;
1004 unsigned long long txTtlNew;
1006 assert (value != NULL);
1008 if (!readULL(valueName, value, &txTtlNew)) {
1012 if ((txTtlNew < 1) || (txTtlNew > MAX_TTL)) {
1013 pudError(false, "Configured %s (%llu) is outside of"
1014 " valid range 1-%u", valueName, txTtlNew, MAX_TTL);
1024 * txNmeaMessagePrefix
1027 /** The exact length of the tx NMEA message prefix */
1028 #define PUD_TXNMEAMESSAGEPREFIXLENGTH 4
1030 /** The tx NMEA message prefix buffer */
1031 static unsigned char txNmeaMessagePrefix[PUD_TXNMEAMESSAGEPREFIXLENGTH + 1];
1033 /** True when the tx NMEA message prefix is set */
1034 static bool txNmeaMessagePrefixSet = false;
1038 The transmit multicast NMEA message prefix
1040 unsigned char * getTxNmeaMessagePrefix(void) {
1041 if (!txNmeaMessagePrefixSet) {
1042 setTxNmeaMessagePrefix(PUD_TX_NMEAMESSAGEPREFIX_DEFAULT, NULL,
1043 (set_plugin_parameter_addon) {.pc = NULL});
1045 return &txNmeaMessagePrefix[0];
1049 Set the transmit multicast NMEA message prefix
1052 The transmit multicast NMEA message prefix (in string representation)
1059 - true when an error is detected
1062 int setTxNmeaMessagePrefix(const char *value, void *data __attribute__ ((unused)),
1063 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1064 static const char * valueName = PUD_TX_NMEAMESSAGEPREFIX_NAME;
1069 assert (value != NULL);
1071 valueLength = strlen(value);
1072 if (valueLength != PUD_TXNMEAMESSAGEPREFIXLENGTH) {
1073 pudError(false, "Configured %s (%s) must be %u exactly characters",
1074 valueName, value, PUD_TXNMEAMESSAGEPREFIXLENGTH);
1078 invalidChars = nmea_string_has_invalid_chars(value, valueName, &report[0],
1081 pudError(false, &report[0]);
1085 if ((strchr(value, ' ') != NULL) || (strchr(value, '\t') != NULL)) {
1086 pudError(false, "Configured %s (%s) can not contain whitespace",
1091 strcpy((char *) &txNmeaMessagePrefix[0], value);
1092 txNmeaMessagePrefixSet = true;
1101 static unsigned char olsrTtl = PUD_OLSR_TTL_DEFAULT;
1105 The OLSR multicast IP packet time-to-live
1107 unsigned char getOlsrTtl(void) {
1112 Set the OLSR multicast IP packet time-to-live
1115 The OLSR multicast IP packet time-to-live (a number in string representation)
1122 - true when an error is detected
1125 int setOlsrTtl(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))) {
1126 static const char * valueName = PUD_OLSR_TTL_NAME;
1127 unsigned long long olsrTtlNew;
1129 assert (value != NULL);
1131 if (!readULL(valueName, value, &olsrTtlNew)) {
1135 if ((olsrTtlNew < 1) || (olsrTtlNew > MAX_TTL)) {
1136 pudError(false, "Configured %s (%llu) is outside of valid range 1-%u",
1137 valueName, olsrTtlNew, MAX_TTL);
1141 olsrTtl = olsrTtlNew;
1147 * updateIntervalStationary
1150 /** The stationary interval update plugin parameter (in seconds) */
1151 static unsigned long long updateIntervalStationary = PUD_UPDATE_INTERVAL_STATIONARY_DEFAULT;
1155 The stationary interval update plugin parameter (in seconds)
1157 unsigned long long getUpdateIntervalStationary(void) {
1158 return updateIntervalStationary;
1162 Set stationary interval update plugin parameter
1165 The stationary interval update plugin parameter (in seconds)
1172 - true when an error is detected
1175 int setUpdateIntervalStationary(const char *value, void *data __attribute__ ((unused)),
1176 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1177 static const char * valueName = PUD_UPDATE_INTERVAL_STATIONARY_NAME;
1178 unsigned long long updateIntervalStationaryNew;
1180 assert (value != NULL);
1182 if (!readULL(valueName, value, &updateIntervalStationaryNew)) {
1186 if (updateIntervalStationaryNew < 1) {
1187 pudError(false, "Configured %s must be at least 1", valueName);
1191 updateIntervalStationary = updateIntervalStationaryNew;
1197 * updateIntervalMoving
1200 /** The moving interval update plugin parameter (in seconds) */
1201 static unsigned long long updateIntervalMoving = PUD_UPDATE_INTERVAL_MOVING_DEFAULT;
1205 The moving interval update plugin parameter (in seconds)
1207 unsigned long long getUpdateIntervalMoving(void) {
1208 return updateIntervalMoving;
1212 Set moving interval update plugin parameter
1215 The moving interval update plugin parameter (in seconds)
1222 - true when an error is detected
1225 int setUpdateIntervalMoving(const char *value, void *data __attribute__ ((unused)),
1226 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1227 static const char * valueName = PUD_UPDATE_INTERVAL_MOVING_NAME;
1228 unsigned long long updateIntervalMovingNew;
1230 assert (value != NULL);
1232 if (!readULL(valueName, value, &updateIntervalMovingNew)) {
1236 if (updateIntervalMovingNew < 1) {
1237 pudError(false, "Configured %s must be at least 1", valueName);
1241 updateIntervalMoving = updateIntervalMovingNew;
1247 * movingSpeedThreshold
1250 /** The moving speed threshold plugin parameter (in kph) */
1251 static unsigned long long movingSpeedThreshold = PUD_MOVING_SPEED_THRESHOLD_DEFAULT;
1255 The moving speed threshold plugin parameter (in kph)
1257 unsigned long long getMovingSpeedThreshold(void) {
1258 return movingSpeedThreshold;
1262 Set moving speed threshold plugin parameter
1265 The moving speed threshold plugin parameter (in kph)
1272 - true when an error is detected
1275 int setMovingSpeedThreshold(const char *value, void *data __attribute__ ((unused)),
1276 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1277 static const char * valueName = PUD_MOVING_SPEED_THRESHOLD_NAME;
1278 unsigned long long movingSpeedThresholdNew;
1280 assert (value != NULL);
1282 if (!readULL(valueName, value, &movingSpeedThresholdNew)) {
1286 movingSpeedThreshold = movingSpeedThresholdNew;
1292 * movingDistanceThreshold
1295 /** The moving distance threshold plugin parameter (in meters) */
1296 static unsigned long long movingDistanceThreshold = PUD_MOVING_DISTANCE_THRESHOLD_DEFAULT;
1300 The moving distance threshold plugin parameter (in meters)
1302 unsigned long long getMovingDistanceThreshold(void) {
1303 return movingDistanceThreshold;
1307 Set moving distance threshold plugin parameter
1310 The moving distance threshold plugin parameter (in meter)
1317 - true when an error is detected
1320 int setMovingDistanceThreshold(const char *value, void *data __attribute__ ((unused)),
1321 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1322 static const char * valueName = PUD_MOVING_DISTANCE_THRESHOLD_NAME;
1323 unsigned long long movingDistanceThresholdNew;
1325 assert (value != NULL);
1327 if (!readULL(valueName, value, &movingDistanceThresholdNew)) {
1331 movingDistanceThreshold = movingDistanceThresholdNew;
1340 /* The DOP multiplier plugin parameter */
1341 static double dopMultiplier = PUD_DOP_MULTIPLIER_DEFAULT;
1345 The DOP multiplier plugin parameter
1347 double getDopMultiplier(void) {
1348 return dopMultiplier;
1352 Set DOP multiplier plugin parameter
1355 The DOP multiplier plugin parameter
1362 - true when an error is detected
1365 int setDopMultiplier(const char *value, void *data __attribute__ ((unused)),
1366 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1367 static const char * valueName = PUD_DOP_MULTIPLIER_NAME;
1368 double dopMultiplierNew;
1370 assert (value != NULL);
1372 if (!readDouble(valueName, value, &dopMultiplierNew)) {
1376 dopMultiplier = dopMultiplierNew;
1385 /** The default HDOP plugin parameter (in meters) */
1386 static unsigned long long defaultHdop = PUD_DEFAULT_HDOP_DEFAULT;
1390 The default HDOP plugin parameter (in meters)
1392 unsigned long long getDefaultHdop(void) {
1397 Set default HDOP plugin parameter
1400 The default HDOP plugin parameter (in meters)
1407 - true when an error is detected
1410 int setDefaultHdop(const char *value, void *data __attribute__ ((unused)),
1411 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1412 static const char * valueName = PUD_MOVING_DISTANCE_THRESHOLD_NAME;
1413 unsigned long long defaultHdopNew;
1415 assert (value != NULL);
1417 if (!readULL(valueName, value, &defaultHdopNew)) {
1421 defaultHdop = defaultHdopNew;
1430 /** The default VDOP plugin parameter (in meters) */
1431 static unsigned long long defaultVdop = PUD_DEFAULT_VDOP_DEFAULT;
1435 The default VDOP plugin parameter (in meters)
1437 unsigned long long getDefaultVdop(void) {
1442 Set default VDOP plugin parameter
1445 The default VDOP plugin parameter (in meters)
1452 - true when an error is detected
1455 int setDefaultVdop(const char *value, void *data __attribute__ ((unused)),
1456 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1457 static const char * valueName = PUD_MOVING_DISTANCE_THRESHOLD_NAME;
1458 unsigned long long defaultVdopNew;
1460 assert (value != NULL);
1462 if (!readULL(valueName, value, &defaultVdopNew)) {
1466 defaultVdop = defaultVdopNew;
1475 /** The depth of the average list */
1476 static unsigned long long averageDepth = PUD_AVERAGE_DEPTH_DEFAULT;
1480 The depth of the average list
1482 unsigned long long getAverageDepth(void) {
1483 return averageDepth;
1487 Set average depth plugin parameter
1490 The average depth plugin parameter
1497 - true when an error is detected
1500 int setAverageDepth(const char *value, void *data __attribute__ ((unused)),
1501 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1502 static const char * valueName = PUD_AVERAGE_DEPTH_NAME;
1503 unsigned long long averageDepthNew;
1505 assert (value != NULL);
1507 if (!readULL(valueName, value, &averageDepthNew)) {
1511 if (averageDepthNew < 1) {
1512 pudError(false, "Configured %s must be at least 1", valueName);
1516 averageDepth = averageDepthNew;
1522 * hysteresisCountToStationary
1525 /** The hysteresis count for changing state from moving to stationary */
1526 static unsigned long long hysteresisCountToStationary = PUD_HYSTERESIS_COUNT_2STAT_DEFAULT;
1530 The hysteresis count for changing state from moving to stationary
1532 unsigned long long getHysteresisCountToStationary(void) {
1533 return hysteresisCountToStationary;
1537 Set hysteresis count plugin parameter
1540 The hysteresis count plugin parameter
1547 - true when an error is detected
1550 int setHysteresisCountToStationary(const char *value, void *data __attribute__ ((unused)),
1551 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1552 static const char * valueName = PUD_HYSTERESIS_COUNT_2STAT_NAME;
1553 unsigned long long hysteresisCountNew;
1555 assert (value != NULL);
1557 if (!readULL(valueName, value, &hysteresisCountNew)) {
1561 hysteresisCountToStationary = hysteresisCountNew;
1567 * hysteresisCountToMoving
1570 /** The hysteresis count for changing state from stationary to moving */
1571 static unsigned long long hysteresisCountToMoving = PUD_HYSTERESIS_COUNT_2MOV_DEFAULT;
1575 The hysteresis count for changing state from stationary to moving
1577 unsigned long long getHysteresisCountToMoving(void) {
1578 return hysteresisCountToMoving;
1582 Set hysteresis count plugin parameter
1585 The hysteresis count plugin parameter
1592 - true when an error is detected
1595 int setHysteresisCountToMoving(const char *value, void *data __attribute__ ((unused)),
1596 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1597 static const char * valueName = PUD_HYSTERESIS_COUNT_2MOV_NAME;
1598 unsigned long long hysteresisCountNew;
1600 assert (value != NULL);
1602 if (!readULL(valueName, value, &hysteresisCountNew)) {
1606 hysteresisCountToMoving = hysteresisCountNew;
1615 /* when true then duplicate message detection is performed */
1616 static bool useDeDup = PUD_USE_DEDUP_DEFAULT;
1620 The duplicate message detection setting
1622 bool getUseDeDup(void) {
1627 Set duplicate message detection setting plugin parameter
1630 The duplicate message detection setting plugin parameter
1637 - true when an error is detected
1640 int setUseDeDup(const char *value, void *data __attribute__ ((unused)),
1641 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1642 static const char * valueName = PUD_USE_DEDUP_NAME;
1643 unsigned long long useDeDupNew;
1645 assert (value != NULL);
1647 if (!readULL(valueName, value, &useDeDupNew)) {
1651 if ((useDeDupNew != 0) && (useDeDupNew != 1)) {
1652 pudError(false, "Configured %s must be 0 (false) or 1 (true)",
1657 useDeDup = (useDeDupNew == 1);
1666 /** The hysteresis count for changing state from stationary to moving */
1667 static unsigned long long deDupDepth = PUD_DEDUP_DEPTH_DEFAULT;
1671 The hysteresis count for changing state from stationary to moving
1673 unsigned long long getDeDupDepth(void) {
1678 Set de-duplication depth plugin parameter
1681 The de-duplication depth plugin parameter
1688 - true when an error is detected
1691 int setDeDupDepth(const char *value, void *data __attribute__ ((unused)),
1692 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1693 static const char * valueName = PUD_DEDUP_DEPTH_NAME;
1694 unsigned long long deDupDepthNew;
1696 assert (value != NULL);
1698 if (!readULL(valueName, value, &deDupDepthNew)) {
1702 deDupDepth = deDupDepthNew;
1711 /* when true then loopback is performed */
1712 static bool useLoopback = PUD_USE_LOOPBACK_DEFAULT;
1716 The loopback usage setting
1718 bool getUseLoopback(void) {
1723 Set loopback usage plugin parameter
1726 The loopback usage plugin parameter
1733 - true when an error is detected
1736 int setUseLoopback(const char *value, void *data __attribute__ ((unused)),
1737 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1738 static const char * valueName = PUD_USE_LOOPBACK_NAME;
1739 unsigned long long useLoopbackNew;
1741 assert (value != NULL);
1743 if (!readULL(valueName, value, &useLoopbackNew)) {
1747 if ((useLoopbackNew != 0) && (useLoopbackNew != 1)) {
1748 pudError(false, "Configured %s must be 0 (false) or 1 (true)",
1753 useLoopback = (useLoopbackNew == 1);
1763 Check the configuration for consistency and validity.
1766 - true when the configuration is consistent and valid
1769 unsigned int checkConfig(void) {
1772 if (rxNonOlsrInterfaceCount == 0) {
1773 pudError(false, "No receive non-OLSR interfaces configured");
1777 if (txNonOlsrInterfaceCount == 0) {
1778 pudError(false, "No transmit non-OLSR interfaces configured");
1783 if (nodeIdType == PUD_NODEIDTYPE_DNS) {
1784 char name[PUD_NODEIDMAXLENGTH + 1];
1787 if (gethostname(&name[0], sizeof(name)) < 0) {
1788 pudError(true, "Could not get the host name");
1791 setNodeId(&name[0], NULL,
1792 (set_plugin_parameter_addon) {.pc = NULL});
1794 } else if ((nodeIdType != PUD_NODEIDTYPE_MAC) && (nodeIdType
1795 != PUD_NODEIDTYPE_IPV4) && (nodeIdType != PUD_NODEIDTYPE_IPV6)) {
1796 pudError(false, "No node ID set while one is required for"
1797 " node type %u", nodeIdType);
1802 if (!setupNodeIdNumberForOlsrCacheAndValidate(nodeIdType)) {
1806 if (updateIntervalMoving > updateIntervalStationary) {
1807 pudError(false,"The update interval for moving situations must not be"
1808 " larger than that for stationary situations");
1816 Check the configuration for consistency and validity after everything has been
1820 - true when the configuration is consistent and valid
1823 unsigned int checkRunSetup(void) {
1827 /* any receive interface name that is configured but is not the name of an
1828 * actual receive interface is not a valid interface name */
1829 for (i = 0; i < rxNonOlsrInterfaceCount; i++) {
1830 unsigned char * nonOlsrInterfaceName = &rxNonOlsrInterfaceNames[i][0];
1832 TRxTxNetworkInterface * interfaceObject = getRxNetworkInterfaces();
1834 while (interfaceObject != NULL) {
1835 if (strncmp((char *) nonOlsrInterfaceName,
1836 (char *) &interfaceObject->name[0], IFNAMSIZ + 1) == 0) {
1840 interfaceObject = interfaceObject->next;
1843 pudError(false, "Configured receive non-OLSR interface %s is not"
1844 " a known interface name", nonOlsrInterfaceName);
1849 /* any transmit interface name that is configured but is not the name of an
1850 * actual transmit interface is not a valid interface name */
1851 for (i = 0; i < txNonOlsrInterfaceCount; i++) {
1852 unsigned char * nonOlsrInterfaceName = &txNonOlsrInterfaceNames[i][0];
1854 TRxTxNetworkInterface * interfaceObject = getTxNetworkInterfaces();
1856 while (interfaceObject != NULL) {
1857 if (strncmp((char *) nonOlsrInterfaceName,
1858 (char *) &interfaceObject->name[0], IFNAMSIZ + 1) == 0) {
1862 interfaceObject = interfaceObject->next;
1865 pudError(false, "Configured transmit non-OLSR interface %s is not"
1866 " a known interface name", nonOlsrInterfaceName);