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;
315 Validate whether the configured nodeId is valid w.r.t. the configured
322 static bool setupNodeIdNumberForOlsrCacheAndValidate(NodeIdType nodeIdTypeNumber) {
323 unsigned long long val = 0LL;
324 unsigned long long min = 0LL;
325 unsigned long long max = 0LL;
326 unsigned int bytes = 0;
328 switch (nodeIdTypeNumber) {
329 case PUD_NODEIDTYPE_IPV4: /* IPv4 address */
330 case PUD_NODEIDTYPE_IPV6: /* IPv6 address */
331 case PUD_NODEIDTYPE_MAC: /* hardware address */
332 /* explicit return: configured nodeId is not relevant */
335 case PUD_NODEIDTYPE_MSISDN: /* an MSISDN number */
337 max = 999999999999999LL;
338 bytes = PUD_NODEIDTYPE_MSISDN_BYTES;
341 case PUD_NODEIDTYPE_TETRA: /* a Tetra number */
343 max = 99999999999999999LL;
344 bytes = PUD_NODEIDTYPE_TETRA_BYTES;
347 case PUD_NODEIDTYPE_DNS: /* DNS name */
352 invalidChars = nmea_string_has_invalid_chars((char *) getNodeId(),
353 PUD_NODE_ID_NAME, &report[0], sizeof(report));
355 pudError(false, &report[0]);
357 return !invalidChars;
360 case PUD_NODEIDTYPE_192:
363 bytes = PUD_NODEIDTYPE_192_BYTES;
366 case PUD_NODEIDTYPE_193:
369 bytes = PUD_NODEIDTYPE_193_BYTES;
372 case PUD_NODEIDTYPE_194:
375 bytes = PUD_NODEIDTYPE_194_BYTES;
378 default: /* unsupported */
379 /* explicit return: configured nodeId is not relevant, will
380 * fallback to IP addresses */
385 if (!getNodeIdAsNumber(&val)) {
389 if (setupNodeIdNumberForOlsrCache(val, min, max, bytes) ) {
393 pudError(false, "%s value %llu is out of range [%llu,%llu]",
394 PUD_NODE_ID_NAME, val, min, max);
402 /** The maximum number of RX non-OLSR interfaces */
403 #define PUD_RX_NON_OLSR_IF_MAX 32
405 /** Array with RX non-OLSR interface names */
406 static unsigned char rxNonOlsrInterfaceNames[PUD_RX_NON_OLSR_IF_MAX][IFNAMSIZ + 1];
408 /** The number of RX non-OLSR interface names in the array */
409 static unsigned int rxNonOlsrInterfaceCount = 0;
412 Determine whether a give interface name is configured as a receive non-OLSR
416 The interface name to check
419 - true when the given interface name is configured as a receive non-OLSR
423 bool isRxNonOlsrInterface(const char *ifName) {
426 assert (ifName != NULL);
428 for (i = 0; i < rxNonOlsrInterfaceCount; i++) {
429 if (strncmp((char *) &rxNonOlsrInterfaceNames[i][0], ifName, IFNAMSIZ
439 Add a receive non-OLSR interface
442 The name of the non-OLSR interface to add
449 - true when an error is detected
452 int addRxNonOlsrInterface(const char *value, void *data __attribute__ ((unused)),
453 set_plugin_parameter_addon addon __attribute__ ((unused))) {
454 unsigned long valueLength;
456 assert (value != NULL);
458 valueLength = strlen(value);
459 if (valueLength > IFNAMSIZ) {
460 pudError(false, "Configured %s (%s) is too long,"
461 " maximum length is %u, current length is %lu",
462 PUD_RX_NON_OLSR_IF_NAME, value, IFNAMSIZ, valueLength);
466 if (!isRxNonOlsrInterface(value)) {
467 if (rxNonOlsrInterfaceCount >= PUD_RX_NON_OLSR_IF_MAX) {
468 pudError(false, "Can't configure more than %u receive interfaces",
469 PUD_RX_NON_OLSR_IF_MAX);
473 strcpy((char *) &rxNonOlsrInterfaceNames[rxNonOlsrInterfaceCount][0],
475 rxNonOlsrInterfaceCount++;
482 * rxAllowedSourceIpAddress
485 /** The maximum number of RX allowed source IP addresses */
486 #define PUD_RX_ALLOWED_SOURCE_IP_MAX 32
488 /** Array with RX allowed source IP addresses */
489 static struct sockaddr rxAllowedSourceIpAddresses[PUD_RX_ALLOWED_SOURCE_IP_MAX];
491 /** The number of RX allowed source IP addresses in the array */
492 static unsigned int rxAllowedSourceIpAddressesCount = 0;
495 Determine whether a give IP address is configured as an allowed source IP
499 The IP address to check
502 - true when the given IP address is configured as an allowed source IP
506 bool isRxAllowedSourceIpAddress(struct sockaddr * sender) {
508 unsigned int addrSize;
511 if (rxAllowedSourceIpAddressesCount == 0) {
515 if (sender == NULL) {
519 if (sender->sa_family == AF_INET) {
520 addr = (void *) (&((struct sockaddr_in *) sender)->sin_addr);
521 addrSize = sizeof(struct in_addr);
523 addr = (void *) (&((struct sockaddr_in6 *) sender)->sin6_addr);
524 addrSize = sizeof(struct in6_addr);
527 for (i = 0; i < rxAllowedSourceIpAddressesCount; i++) {
528 if ((rxAllowedSourceIpAddresses[i].sa_family == sender->sa_family)
529 && (memcmp(&rxAllowedSourceIpAddresses[i].sa_data, addr,
539 Set the RX allowed source IP addresses.
542 The RX allowed source IP address (in string representation)
549 - true when an error is detected
552 int addRxAllowedSourceIpAddress(const char *value, void *data __attribute__ ((unused)),
553 set_plugin_parameter_addon addon __attribute__ ((unused))) {
554 static const char * valueName = PUD_RX_ALLOWED_SOURCE_IP_NAME;
555 const char * valueInternal = value;
557 struct sockaddr addr;
559 assert (value != NULL);
561 memset(&addr, 0, sizeof(addr));
563 addr.sa_family = olsr_cnf->ip_version;
564 conversion = inet_pton(olsr_cnf->ip_version, valueInternal, &addr.sa_data);
565 if (conversion != 1) {
566 pudError((conversion == -1) ? true : false,
567 "Configured %s (%s) is not an IP address", valueName,
572 if ((rxAllowedSourceIpAddressesCount == 0) || !isRxAllowedSourceIpAddress(&addr)) {
573 if (rxAllowedSourceIpAddressesCount >= PUD_RX_ALLOWED_SOURCE_IP_MAX) {
574 pudError(false, "Can't configure more than %u allowed source IP"
575 " addresses", PUD_RX_ALLOWED_SOURCE_IP_MAX);
579 memcpy(&rxAllowedSourceIpAddresses[rxAllowedSourceIpAddressesCount],
580 &addr, sizeof(addr));
581 rxAllowedSourceIpAddressesCount++;
591 /** The rx multicast address */
592 static union olsr_sockaddr rxMcAddr;
594 /** True when the rx multicast address is set */
595 static bool rxMcAddrSet = false;
599 The receive multicast address (in network byte order). Sets both the address
600 and the port to their default values when the address was not yet set.
602 union olsr_sockaddr * getRxMcAddr(void) {
604 setRxMcAddr(NULL, NULL, ((set_plugin_parameter_addon) {.pc = NULL}));
610 Set the receive multicast address. Sets the address to its default value when
611 the value is NULL. Also sets the port to its default value when the address
615 The receive multicast address (in string representation)
622 - true when an error is detected
625 int setRxMcAddr(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))) {
626 static const char * valueName = PUD_RX_MC_ADDR_NAME;
629 const char * valueInternal = value;
632 getOlsrSockAddrAndPort(olsr_cnf->ip_version, &rxMcAddr, &ipAddress, &port);
633 if (olsr_cnf->ip_version == AF_INET) {
634 rxMcAddr.in4.sin_family = olsr_cnf->ip_version;
635 if (valueInternal == NULL) {
636 valueInternal = PUD_RX_MC_ADDR_4_DEFAULT;
639 rxMcAddr.in6.sin6_family = olsr_cnf->ip_version;
640 if (valueInternal == NULL) {
641 valueInternal = PUD_RX_MC_ADDR_6_DEFAULT;
646 *port = htons(PUD_RX_MC_PORT_DEFAULT);
649 conversion = inet_pton(olsr_cnf->ip_version, valueInternal, ipAddress);
650 if (conversion != 1) {
651 pudError((conversion == -1) ? true : false,
652 "Configured %s (%s) is not an IP address", valueName,
657 if (!isMulticast(olsr_cnf->ip_version, &rxMcAddr)) {
658 pudError(false, "Configured %s (%s) is not a multicast address",
659 valueName, valueInternal);
673 The receive multicast port (in network byte order)
675 unsigned short getRxMcPort(void) {
676 union olsr_sockaddr * addr = getRxMcAddr();
677 return *getOlsrSockaddrPort(olsr_cnf->ip_version, addr);
681 Set the receive multicast port
684 The receive multicast port (a number in string representation)
691 - true when an error is detected
694 int setRxMcPort(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))) {
695 static const char * valueName = PUD_RX_MC_PORT_NAME;
696 unsigned long long rxMcPortNew;
698 union olsr_sockaddr * addr = getRxMcAddr();
700 assert (value != NULL);
702 if (!readULL(valueName, value, &rxMcPortNew)) {
706 if ((rxMcPortNew < 1) || (rxMcPortNew > 65535)) {
707 pudError(false, "Configured %s (%llu) is outside of"
708 " valid range 1-65535", valueName, rxMcPortNew);
712 port = getOlsrSockaddrPort(olsr_cnf->ip_version, addr);
713 *port = htons((uint16_t) rxMcPortNew);
722 /** The maximum number of rx non-olsr interfaces */
723 #define PUD_TX_NON_OLSR_IF_MAX 32
725 /** Array with tx non-olsr interface names */
726 static unsigned char txNonOlsrInterfaceNames[PUD_TX_NON_OLSR_IF_MAX][IFNAMSIZ + 1];
728 /** The number of tx interface names in the array */
729 static unsigned int txNonOlsrInterfaceCount = 0;
732 Determine whether a give interface name is configured as a transmit non-OLSR
736 The interface to check
739 - true when the given interface name is configured as a transmit non-OLSR
743 bool isTxNonOlsrInterface(const char *ifName) {
746 assert (ifName != NULL);
748 for (i = 0; i < txNonOlsrInterfaceCount; i++) {
749 if (strncmp((char *) &txNonOlsrInterfaceNames[i][0], ifName, IFNAMSIZ
759 Add a transmit non-OLSR interface
762 The name of the non-OLSR interface to add
769 - true when an error is detected
772 int addTxNonOlsrInterface(const char *value, void *data __attribute__ ((unused)),
773 set_plugin_parameter_addon addon __attribute__ ((unused))) {
774 unsigned long valueLength;
776 assert (value != NULL);
778 valueLength = strlen(value);
779 if (valueLength > IFNAMSIZ) {
780 pudError(false, "Configured %s (%s) is too long,"
781 " maximum length is %u, current length is %lu",
782 PUD_TX_NON_OLSR_IF_NAME, value, IFNAMSIZ, valueLength);
786 if (!isTxNonOlsrInterface(value)) {
787 if (txNonOlsrInterfaceCount >= PUD_TX_NON_OLSR_IF_MAX) {
788 pudError(false, "Can not configure more than %u transmit"
789 " interfaces", PUD_TX_NON_OLSR_IF_MAX);
793 strcpy((char *) &txNonOlsrInterfaceNames[txNonOlsrInterfaceCount][0],
795 txNonOlsrInterfaceCount++;
805 /** The tx multicast address */
806 static union olsr_sockaddr txMcAddr;
808 /** True when the tx multicast address is set */
809 static bool txMcAddrSet = false;
813 The transmit multicast address (in network byte order). Sets both the address
814 and the port to their default values when the address was not yet set.
816 union olsr_sockaddr * getTxMcAddr(void) {
818 setTxMcAddr(NULL, NULL, ((set_plugin_parameter_addon) {.pc = NULL}));
824 Set the transmit multicast address. Sets the address to its default value when
825 the value is NULL. Also sets the port to its default value when the address
829 The transmit multicast address (in string representation)
836 - true when an error is detected
839 int setTxMcAddr(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))) {
840 static const char * valueName = PUD_TX_MC_ADDR_NAME;
843 const char * valueInternal = value;
846 getOlsrSockAddrAndPort(olsr_cnf->ip_version, &txMcAddr, &ipAddress, &port);
847 if (olsr_cnf->ip_version == AF_INET) {
848 txMcAddr.in4.sin_family = olsr_cnf->ip_version;
849 if (valueInternal == NULL) {
850 valueInternal = PUD_TX_MC_ADDR_4_DEFAULT;
853 txMcAddr.in6.sin6_family = olsr_cnf->ip_version;
854 if (valueInternal == NULL) {
855 valueInternal = PUD_TX_MC_ADDR_6_DEFAULT;
860 *port = htons(PUD_TX_MC_PORT_DEFAULT);
863 conversion = inet_pton(olsr_cnf->ip_version, valueInternal, ipAddress);
864 if (conversion != 1) {
865 pudError((conversion == -1) ? true : false,
866 "Configured %s (%s) is not an IP address", valueName,
871 if (!isMulticast(olsr_cnf->ip_version, &txMcAddr)) {
872 pudError(false, "Configured %s (%s) is not a multicast address",
873 valueName, valueInternal);
887 The transmit multicast port (in network byte order)
889 unsigned short getTxMcPort(void) {
890 union olsr_sockaddr * addr = getTxMcAddr();
891 return *getOlsrSockaddrPort(olsr_cnf->ip_version, addr);
895 Set the transmit multicast port
898 The transmit multicast port (a number in string representation)
905 - true when an error is detected
908 int setTxMcPort(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))) {
909 static const char * valueName = PUD_TX_MC_PORT_NAME;
910 unsigned long long txMcPortNew;
912 union olsr_sockaddr * addr = getTxMcAddr();
914 assert (value != NULL);
916 if (!readULL(valueName, value, &txMcPortNew)) {
920 if ((txMcPortNew < 1) || (txMcPortNew > 65535)) {
921 pudError(false, "Configured %s (%llu) is outside of"
922 " valid range 1-65535", valueName, txMcPortNew);
926 port = getOlsrSockaddrPort(olsr_cnf->ip_version, addr);
927 *port = htons((uint16_t) txMcPortNew);
936 /** The uplink address */
937 static union olsr_sockaddr uplinkAddr;
939 /** True when the uplink address is set */
940 static bool uplinkAddrSet = false;
942 /** True when the uplink address is set */
943 static bool uplinkPortSet = false;
947 - true when the uplink address is set
950 bool isUplinkAddrSet(void) {
951 return uplinkAddrSet;
956 The uplink address (in network byte order). Sets both the address
957 and the port to their default values when the address was not yet set.
959 union olsr_sockaddr * getUplinkAddr(void) {
960 if (!uplinkAddrSet) {
961 setUplinkAddr(NULL, NULL, ((set_plugin_parameter_addon) {.pc = NULL}));
967 Set the uplink address. Sets the address to its default value when
968 the value is NULL. Also sets the port to its default value when the address
972 The uplink address (in string representation)
979 - true when an error is detected
982 int setUplinkAddr(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))) {
983 static const char * valueName = PUD_UPLINK_ADDR_NAME;
986 const char * valueInternal = value;
988 bool defaultValue = false;
990 getOlsrSockAddrAndPort(olsr_cnf->ip_version, &uplinkAddr, &ipAddress, &port);
991 if (olsr_cnf->ip_version == AF_INET) {
992 uplinkAddr.in4.sin_family = olsr_cnf->ip_version;
993 if (valueInternal == NULL) {
994 valueInternal = PUD_UPLINK_ADDR_4_DEFAULT;
998 uplinkAddr.in6.sin6_family = olsr_cnf->ip_version;
999 if (valueInternal == NULL) {
1000 valueInternal = PUD_UPLINK_ADDR_6_DEFAULT;
1001 defaultValue = true;
1005 if (!uplinkPortSet) {
1006 *port = htons(PUD_UPLINK_PORT_DEFAULT);
1007 uplinkPortSet = true;
1010 conversion = inet_pton(olsr_cnf->ip_version, valueInternal, ipAddress);
1011 if (conversion != 1) {
1012 pudError((conversion == -1) ? true : false,
1013 "Configured %s (%s) is not an IP address", valueName,
1018 if (!defaultValue) {
1019 uplinkAddrSet = true;
1031 The uplink port (in network byte order)
1033 unsigned short getUplinkPort(void) {
1034 union olsr_sockaddr * addr = getUplinkAddr();
1035 return *getOlsrSockaddrPort(olsr_cnf->ip_version, addr);
1042 The uplink port (a number in string representation)
1049 - true when an error is detected
1052 int setUplinkPort(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))) {
1053 static const char * valueName = PUD_UPLINK_PORT_NAME;
1054 unsigned long long uplinkPortNew;
1056 union olsr_sockaddr * addr = getUplinkAddr();
1058 assert (value != NULL);
1060 if (!readULL(valueName, value, &uplinkPortNew)) {
1064 if ((uplinkPortNew < 1) || (uplinkPortNew > 65535)) {
1065 pudError(false, "Configured %s (%llu) is outside of"
1066 " valid range 1-65535", valueName, uplinkPortNew);
1070 port = getOlsrSockaddrPort(olsr_cnf->ip_version, addr);
1071 *port = htons((uint16_t) uplinkPortNew);
1072 uplinkPortSet = true;
1082 /** the downlink port */
1083 unsigned short downlinkPort = 0;
1085 /** true when the downlinkPort is set */
1086 bool downlinkPortSet = false;
1090 The downlink port (in network byte order)
1092 unsigned short getDownlinkPort(void) {
1093 if (!downlinkPortSet) {
1094 downlinkPort = htons(PUD_DOWNLINK_PORT_DEFAULT);
1095 downlinkPortSet = true;
1098 return downlinkPort;
1102 Set the downlink port
1105 The downlink port (a number in string representation)
1112 - true when an error is detected
1115 int setDownlinkPort(const char *value, void *data __attribute__ ((unused)),
1116 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1117 static const char * valueName = PUD_DOWNLINK_PORT_NAME;
1118 unsigned long long downlinkPortNew;
1120 assert(value != NULL);
1122 if (!readULL(valueName, value, &downlinkPortNew)) {
1126 if ((downlinkPortNew < 1) || (downlinkPortNew > 65535)) {
1127 pudError(false, "Configured %s (%llu) is outside of"
1128 " valid range 1-65535", valueName, downlinkPortNew);
1132 downlinkPort = htons(downlinkPortNew);
1133 downlinkPortSet = true;
1143 static unsigned char txTtl = PUD_TX_TTL_DEFAULT;
1147 The transmit multicast IP packet time-to-live
1149 unsigned char getTxTtl(void) {
1154 Set the transmit multicast IP packet time-to-live
1157 The transmit multicast IP packet time-to-live (a number in string representation)
1164 - true when an error is detected
1167 int setTxTtl(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))) {
1168 static const char * valueName = PUD_TX_TTL_NAME;
1169 unsigned long long txTtlNew;
1171 assert (value != NULL);
1173 if (!readULL(valueName, value, &txTtlNew)) {
1177 if ((txTtlNew < 1) || (txTtlNew > MAX_TTL)) {
1178 pudError(false, "Configured %s (%llu) is outside of"
1179 " valid range 1-%u", valueName, txTtlNew, MAX_TTL);
1189 * txNmeaMessagePrefix
1192 /** The exact length of the tx NMEA message prefix */
1193 #define PUD_TXNMEAMESSAGEPREFIXLENGTH 4
1195 /** The tx NMEA message prefix buffer */
1196 static unsigned char txNmeaMessagePrefix[PUD_TXNMEAMESSAGEPREFIXLENGTH + 1];
1198 /** True when the tx NMEA message prefix is set */
1199 static bool txNmeaMessagePrefixSet = false;
1203 The transmit multicast NMEA message prefix
1205 unsigned char * getTxNmeaMessagePrefix(void) {
1206 if (!txNmeaMessagePrefixSet) {
1207 setTxNmeaMessagePrefix(PUD_TX_NMEAMESSAGEPREFIX_DEFAULT, NULL,
1208 (set_plugin_parameter_addon) {.pc = NULL});
1210 return &txNmeaMessagePrefix[0];
1214 Set the transmit multicast NMEA message prefix
1217 The transmit multicast NMEA message prefix (in string representation)
1224 - true when an error is detected
1227 int setTxNmeaMessagePrefix(const char *value, void *data __attribute__ ((unused)),
1228 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1229 static const char * valueName = PUD_TX_NMEAMESSAGEPREFIX_NAME;
1234 assert (value != NULL);
1236 valueLength = strlen(value);
1237 if (valueLength != PUD_TXNMEAMESSAGEPREFIXLENGTH) {
1238 pudError(false, "Configured %s (%s) must be %u exactly characters",
1239 valueName, value, PUD_TXNMEAMESSAGEPREFIXLENGTH);
1243 invalidChars = nmea_string_has_invalid_chars(value, valueName, &report[0],
1246 pudError(false, &report[0]);
1250 if ((strchr(value, ' ') != NULL) || (strchr(value, '\t') != NULL)) {
1251 pudError(false, "Configured %s (%s) can not contain whitespace",
1256 strcpy((char *) &txNmeaMessagePrefix[0], value);
1257 txNmeaMessagePrefixSet = true;
1266 static unsigned char olsrTtl = PUD_OLSR_TTL_DEFAULT;
1270 The OLSR multicast IP packet time-to-live
1272 unsigned char getOlsrTtl(void) {
1277 Set the OLSR multicast IP packet time-to-live
1280 The OLSR multicast IP packet time-to-live (a number in string representation)
1287 - true when an error is detected
1290 int setOlsrTtl(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))) {
1291 static const char * valueName = PUD_OLSR_TTL_NAME;
1292 unsigned long long olsrTtlNew;
1294 assert (value != NULL);
1296 if (!readULL(valueName, value, &olsrTtlNew)) {
1300 if ((olsrTtlNew < 1) || (olsrTtlNew > MAX_TTL)) {
1301 pudError(false, "Configured %s (%llu) is outside of valid range 1-%u",
1302 valueName, olsrTtlNew, MAX_TTL);
1306 olsrTtl = olsrTtlNew;
1312 * updateIntervalStationary
1315 /** The stationary interval update plugin parameter (in seconds) */
1316 static unsigned long long updateIntervalStationary = PUD_UPDATE_INTERVAL_STATIONARY_DEFAULT;
1320 The stationary interval update plugin parameter (in seconds)
1322 unsigned long long getUpdateIntervalStationary(void) {
1323 return updateIntervalStationary;
1327 Set stationary interval update plugin parameter
1330 The stationary interval update plugin parameter (in seconds)
1337 - true when an error is detected
1340 int setUpdateIntervalStationary(const char *value, void *data __attribute__ ((unused)),
1341 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1342 static const char * valueName = PUD_UPDATE_INTERVAL_STATIONARY_NAME;
1343 unsigned long long updateIntervalStationaryNew;
1345 assert (value != NULL);
1347 if (!readULL(valueName, value, &updateIntervalStationaryNew)) {
1351 if (updateIntervalStationaryNew < 1) {
1352 pudError(false, "Configured %s must be at least 1", valueName);
1356 updateIntervalStationary = updateIntervalStationaryNew;
1362 * updateIntervalMoving
1365 /** The moving interval update plugin parameter (in seconds) */
1366 static unsigned long long updateIntervalMoving = PUD_UPDATE_INTERVAL_MOVING_DEFAULT;
1370 The moving interval update plugin parameter (in seconds)
1372 unsigned long long getUpdateIntervalMoving(void) {
1373 return updateIntervalMoving;
1377 Set moving interval update plugin parameter
1380 The moving interval update plugin parameter (in seconds)
1387 - true when an error is detected
1390 int setUpdateIntervalMoving(const char *value, void *data __attribute__ ((unused)),
1391 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1392 static const char * valueName = PUD_UPDATE_INTERVAL_MOVING_NAME;
1393 unsigned long long updateIntervalMovingNew;
1395 assert (value != NULL);
1397 if (!readULL(valueName, value, &updateIntervalMovingNew)) {
1401 if (updateIntervalMovingNew < 1) {
1402 pudError(false, "Configured %s must be at least 1", valueName);
1406 updateIntervalMoving = updateIntervalMovingNew;
1412 * uplinkUpdateIntervalStationary
1415 /** The uplink stationary interval update plugin parameter (in seconds) */
1416 static unsigned long long uplinkUpdateIntervalStationary = PUD_UPLINK_UPDATE_INTERVAL_STATIONARY_DEFAULT;
1420 The uplink stationary interval update plugin parameter (in seconds)
1422 unsigned long long getUplinkUpdateIntervalStationary(void) {
1423 return uplinkUpdateIntervalStationary;
1427 Set uplink stationary interval update plugin parameter
1430 The uplink stationary interval update plugin parameter (in seconds)
1437 - true when an error is detected
1440 int setUplinkUpdateIntervalStationary(const char *value, void *data __attribute__ ((unused)),
1441 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1442 static const char * valueName = PUD_UPLINK_UPDATE_INTERVAL_STATIONARY_NAME;
1443 unsigned long long uplinkUpdateIntervalStationaryNew;
1445 assert (value != NULL);
1447 if (!readULL(valueName, value, &uplinkUpdateIntervalStationaryNew)) {
1451 if (uplinkUpdateIntervalStationaryNew < 1) {
1452 pudError(false, "Configured %s must be at least 1", valueName);
1456 uplinkUpdateIntervalStationary = uplinkUpdateIntervalStationaryNew;
1462 * uplinkUpdateIntervalMoving
1465 /** The uplink moving interval update plugin parameter (in seconds) */
1466 static unsigned long long uplinkUpdateIntervalMoving = PUD_UPLINK_UPDATE_INTERVAL_MOVING_DEFAULT;
1470 The uplink moving interval update plugin parameter (in seconds)
1472 unsigned long long getUplinkUpdateIntervalMoving(void) {
1473 return uplinkUpdateIntervalMoving;
1477 Set uplink moving interval update plugin parameter
1480 The uplink moving interval update plugin parameter (in seconds)
1487 - true when an error is detected
1490 int setUplinkUpdateIntervalMoving(const char *value, void *data __attribute__ ((unused)),
1491 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1492 static const char * valueName = PUD_UPLINK_UPDATE_INTERVAL_MOVING_NAME;
1493 unsigned long long uplinkUpdateIntervalMovingNew;
1495 assert (value != NULL);
1497 if (!readULL(valueName, value, &uplinkUpdateIntervalMovingNew)) {
1501 if (uplinkUpdateIntervalMovingNew < 1) {
1502 pudError(false, "Configured %s must be at least 1", valueName);
1506 uplinkUpdateIntervalMoving = uplinkUpdateIntervalMovingNew;
1512 * movingSpeedThreshold
1515 /** The moving speed threshold plugin parameter (in kph) */
1516 static unsigned long long movingSpeedThreshold = PUD_MOVING_SPEED_THRESHOLD_DEFAULT;
1520 The moving speed threshold plugin parameter (in kph)
1522 unsigned long long getMovingSpeedThreshold(void) {
1523 return movingSpeedThreshold;
1527 Set moving speed threshold plugin parameter
1530 The moving speed threshold plugin parameter (in kph)
1537 - true when an error is detected
1540 int setMovingSpeedThreshold(const char *value, void *data __attribute__ ((unused)),
1541 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1542 static const char * valueName = PUD_MOVING_SPEED_THRESHOLD_NAME;
1543 unsigned long long movingSpeedThresholdNew;
1545 assert (value != NULL);
1547 if (!readULL(valueName, value, &movingSpeedThresholdNew)) {
1551 movingSpeedThreshold = movingSpeedThresholdNew;
1557 * movingDistanceThreshold
1560 /** The moving distance threshold plugin parameter (in meters) */
1561 static unsigned long long movingDistanceThreshold = PUD_MOVING_DISTANCE_THRESHOLD_DEFAULT;
1565 The moving distance threshold plugin parameter (in meters)
1567 unsigned long long getMovingDistanceThreshold(void) {
1568 return movingDistanceThreshold;
1572 Set moving distance threshold plugin parameter
1575 The moving distance threshold plugin parameter (in meter)
1582 - true when an error is detected
1585 int setMovingDistanceThreshold(const char *value, void *data __attribute__ ((unused)),
1586 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1587 static const char * valueName = PUD_MOVING_DISTANCE_THRESHOLD_NAME;
1588 unsigned long long movingDistanceThresholdNew;
1590 assert (value != NULL);
1592 if (!readULL(valueName, value, &movingDistanceThresholdNew)) {
1596 movingDistanceThreshold = movingDistanceThresholdNew;
1605 /* The DOP multiplier plugin parameter */
1606 static double dopMultiplier = PUD_DOP_MULTIPLIER_DEFAULT;
1610 The DOP multiplier plugin parameter
1612 double getDopMultiplier(void) {
1613 return dopMultiplier;
1617 Set DOP multiplier plugin parameter
1620 The DOP multiplier plugin parameter
1627 - true when an error is detected
1630 int setDopMultiplier(const char *value, void *data __attribute__ ((unused)),
1631 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1632 static const char * valueName = PUD_DOP_MULTIPLIER_NAME;
1633 double dopMultiplierNew;
1635 assert (value != NULL);
1637 if (!readDouble(valueName, value, &dopMultiplierNew)) {
1641 dopMultiplier = dopMultiplierNew;
1650 /** The default HDOP plugin parameter (in meters) */
1651 static unsigned long long defaultHdop = PUD_DEFAULT_HDOP_DEFAULT;
1655 The default HDOP plugin parameter (in meters)
1657 unsigned long long getDefaultHdop(void) {
1662 Set default HDOP plugin parameter
1665 The default HDOP plugin parameter (in meters)
1672 - true when an error is detected
1675 int setDefaultHdop(const char *value, void *data __attribute__ ((unused)),
1676 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1677 static const char * valueName = PUD_MOVING_DISTANCE_THRESHOLD_NAME;
1678 unsigned long long defaultHdopNew;
1680 assert (value != NULL);
1682 if (!readULL(valueName, value, &defaultHdopNew)) {
1686 defaultHdop = defaultHdopNew;
1695 /** The default VDOP plugin parameter (in meters) */
1696 static unsigned long long defaultVdop = PUD_DEFAULT_VDOP_DEFAULT;
1700 The default VDOP plugin parameter (in meters)
1702 unsigned long long getDefaultVdop(void) {
1707 Set default VDOP plugin parameter
1710 The default VDOP plugin parameter (in meters)
1717 - true when an error is detected
1720 int setDefaultVdop(const char *value, void *data __attribute__ ((unused)),
1721 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1722 static const char * valueName = PUD_MOVING_DISTANCE_THRESHOLD_NAME;
1723 unsigned long long defaultVdopNew;
1725 assert (value != NULL);
1727 if (!readULL(valueName, value, &defaultVdopNew)) {
1731 defaultVdop = defaultVdopNew;
1740 /** The depth of the average list */
1741 static unsigned long long averageDepth = PUD_AVERAGE_DEPTH_DEFAULT;
1745 The depth of the average list
1747 unsigned long long getAverageDepth(void) {
1748 return averageDepth;
1752 Set average depth plugin parameter
1755 The average depth plugin parameter
1762 - true when an error is detected
1765 int setAverageDepth(const char *value, void *data __attribute__ ((unused)),
1766 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1767 static const char * valueName = PUD_AVERAGE_DEPTH_NAME;
1768 unsigned long long averageDepthNew;
1770 assert (value != NULL);
1772 if (!readULL(valueName, value, &averageDepthNew)) {
1776 if (averageDepthNew < 1) {
1777 pudError(false, "Configured %s must be at least 1", valueName);
1781 averageDepth = averageDepthNew;
1787 * hysteresisCountToStationary
1790 /** The hysteresis count for changing state from moving to stationary */
1791 static unsigned long long hysteresisCountToStationary = PUD_HYSTERESIS_COUNT_2STAT_DEFAULT;
1795 The hysteresis count for changing state from moving to stationary
1797 unsigned long long getHysteresisCountToStationary(void) {
1798 return hysteresisCountToStationary;
1802 Set hysteresis count plugin parameter
1805 The hysteresis count plugin parameter
1812 - true when an error is detected
1815 int setHysteresisCountToStationary(const char *value, void *data __attribute__ ((unused)),
1816 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1817 static const char * valueName = PUD_HYSTERESIS_COUNT_2STAT_NAME;
1818 unsigned long long hysteresisCountNew;
1820 assert (value != NULL);
1822 if (!readULL(valueName, value, &hysteresisCountNew)) {
1826 hysteresisCountToStationary = hysteresisCountNew;
1832 * hysteresisCountToMoving
1835 /** The hysteresis count for changing state from stationary to moving */
1836 static unsigned long long hysteresisCountToMoving = PUD_HYSTERESIS_COUNT_2MOV_DEFAULT;
1840 The hysteresis count for changing state from stationary to moving
1842 unsigned long long getHysteresisCountToMoving(void) {
1843 return hysteresisCountToMoving;
1847 Set hysteresis count plugin parameter
1850 The hysteresis count plugin parameter
1857 - true when an error is detected
1860 int setHysteresisCountToMoving(const char *value, void *data __attribute__ ((unused)),
1861 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1862 static const char * valueName = PUD_HYSTERESIS_COUNT_2MOV_NAME;
1863 unsigned long long hysteresisCountNew;
1865 assert (value != NULL);
1867 if (!readULL(valueName, value, &hysteresisCountNew)) {
1871 hysteresisCountToMoving = hysteresisCountNew;
1880 /* when true then duplicate message detection is performed */
1881 static bool useDeDup = PUD_USE_DEDUP_DEFAULT;
1885 The duplicate message detection setting
1887 bool getUseDeDup(void) {
1892 Set duplicate message detection setting plugin parameter
1895 The duplicate message detection setting plugin parameter
1902 - true when an error is detected
1905 int setUseDeDup(const char *value, void *data __attribute__ ((unused)),
1906 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1907 static const char * valueName = PUD_USE_DEDUP_NAME;
1908 unsigned long long useDeDupNew;
1910 assert (value != NULL);
1912 if (!readULL(valueName, value, &useDeDupNew)) {
1916 if ((useDeDupNew != 0) && (useDeDupNew != 1)) {
1917 pudError(false, "Configured %s must be 0 (false) or 1 (true)",
1922 useDeDup = (useDeDupNew == 1);
1931 /** The hysteresis count for changing state from stationary to moving */
1932 static unsigned long long deDupDepth = PUD_DEDUP_DEPTH_DEFAULT;
1936 The hysteresis count for changing state from stationary to moving
1938 unsigned long long getDeDupDepth(void) {
1943 Set de-duplication depth plugin parameter
1946 The de-duplication depth plugin parameter
1953 - true when an error is detected
1956 int setDeDupDepth(const char *value, void *data __attribute__ ((unused)),
1957 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1958 static const char * valueName = PUD_DEDUP_DEPTH_NAME;
1959 unsigned long long deDupDepthNew;
1961 assert (value != NULL);
1963 if (!readULL(valueName, value, &deDupDepthNew)) {
1967 deDupDepth = deDupDepthNew;
1976 /* when true then loopback is performed */
1977 static bool useLoopback = PUD_USE_LOOPBACK_DEFAULT;
1981 The loopback usage setting
1983 bool getUseLoopback(void) {
1988 Set loopback usage plugin parameter
1991 The loopback usage plugin parameter
1998 - true when an error is detected
2001 int setUseLoopback(const char *value, void *data __attribute__ ((unused)),
2002 set_plugin_parameter_addon addon __attribute__ ((unused))) {
2003 static const char * valueName = PUD_USE_LOOPBACK_NAME;
2004 unsigned long long useLoopbackNew;
2006 assert (value != NULL);
2008 if (!readULL(valueName, value, &useLoopbackNew)) {
2012 if ((useLoopbackNew != 0) && (useLoopbackNew != 1)) {
2013 pudError(false, "Configured %s must be 0 (false) or 1 (true)",
2018 useLoopback = (useLoopbackNew == 1);
2028 Check the configuration for consistency and validity.
2031 - true when the configuration is consistent and valid
2034 unsigned int checkConfig(void) {
2037 if (rxNonOlsrInterfaceCount == 0) {
2038 pudError(false, "No receive non-OLSR interfaces configured");
2042 if (txNonOlsrInterfaceCount == 0) {
2043 pudError(false, "No transmit non-OLSR interfaces configured");
2048 if (nodeIdType == PUD_NODEIDTYPE_DNS) {
2049 char name[PUD_NODEIDMAXLENGTH + 1];
2052 if (gethostname(&name[0], sizeof(name)) < 0) {
2053 pudError(true, "Could not get the host name");
2056 setNodeId(&name[0], NULL,
2057 (set_plugin_parameter_addon) {.pc = NULL});
2059 } else if ((nodeIdType != PUD_NODEIDTYPE_MAC) && (nodeIdType
2060 != PUD_NODEIDTYPE_IPV4) && (nodeIdType != PUD_NODEIDTYPE_IPV6)) {
2061 pudError(false, "No node ID set while one is required for"
2062 " node type %u", nodeIdType);
2067 if (!setupNodeIdNumberForOlsrCacheAndValidate(nodeIdType)) {
2071 if (updateIntervalMoving > updateIntervalStationary) {
2072 pudError(false,"The update interval for moving situations must not be"
2073 " larger than that for stationary situations");
2077 if (uplinkUpdateIntervalMoving > uplinkUpdateIntervalStationary) {
2078 pudError(false,"The uplink update interval for moving situations must not be"
2079 " larger than that for stationary situations");
2083 if (getUplinkPort() == getDownlinkPort()) {
2084 pudError(false, "The uplink port and the downlink port must not be the same");
2092 Check the configuration for consistency and validity after everything has been
2096 - true when the configuration is consistent and valid
2099 unsigned int checkRunSetup(void) {
2103 /* any receive interface name that is configured but is not the name of an
2104 * actual receive interface is not a valid interface name */
2105 for (i = 0; i < rxNonOlsrInterfaceCount; i++) {
2106 unsigned char * nonOlsrInterfaceName = &rxNonOlsrInterfaceNames[i][0];
2108 TRxTxNetworkInterface * interfaceObject = getRxNetworkInterfaces();
2110 while (interfaceObject != NULL) {
2111 if (strncmp((char *) nonOlsrInterfaceName,
2112 (char *) &interfaceObject->name[0], IFNAMSIZ + 1) == 0) {
2116 interfaceObject = interfaceObject->next;
2119 pudError(false, "Configured receive non-OLSR interface %s is not"
2120 " a known interface name", nonOlsrInterfaceName);
2125 /* any transmit interface name that is configured but is not the name of an
2126 * actual transmit interface is not a valid interface name */
2127 for (i = 0; i < txNonOlsrInterfaceCount; i++) {
2128 unsigned char * nonOlsrInterfaceName = &txNonOlsrInterfaceNames[i][0];
2130 TRxTxNetworkInterface * interfaceObject = getTxNetworkInterfaces();
2132 while (interfaceObject != NULL) {
2133 if (strncmp((char *) nonOlsrInterfaceName,
2134 (char *) &interfaceObject->name[0], IFNAMSIZ + 1) == 0) {
2138 interfaceObject = interfaceObject->next;
2141 pudError(false, "Configured transmit non-OLSR interface %s is not"
2142 " a known interface name", nonOlsrInterfaceName);