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
36 A pointer to the location where the pointer to the port will be stored
38 static void getOlsrSockaddrPortAddress(int ipVersion,
39 union olsr_sockaddr * addr, in_port_t ** port) {
40 if (ipVersion == AF_INET) {
41 *port = &addr->in4.sin_port;
43 *port = &addr->in6.sin6_port;
48 Get pointers to the IP address and port in an OLSR socket address
50 The IP version (AF_INET or AF_INET6)
52 A pointer to OLSR socket address
54 A pointer to the location where the pointer to the IP address will be stored
56 A pointer to the location where the pointer to the port will be stored
58 static void getOlsrSockAddrAndPortAddresses(int ipVersion,
59 union olsr_sockaddr * addr, void ** ipAddress, in_port_t ** port) {
60 if (ipVersion == AF_INET) {
61 *ipAddress = (void *) &addr->in4.sin_addr;
62 *port = (void *) &addr->in4.sin_port;
64 *ipAddress = (void *) &addr->in6.sin6_addr;
65 *port = (void *) &addr->in6.sin6_port;
70 Read an unsigned long long number from a value string
75 the string to convert to a number
77 a pointer to the location where to store the number upon successful conversion
83 static bool readULL(const char * valueName, const char * value,
84 unsigned long long * valueNumber) {
86 unsigned long long valueNew;
89 valueNew = strtoull(value, &endPtr, 10);
91 if (!((endPtr != value) && (*value != '\0') && (*endPtr == '\0'))) {
92 /* invalid conversion */
93 pudError(true, "Configured %s (%s) could not be converted to a number",
98 *valueNumber = valueNew;
104 Read a double number from a value string
107 the name of the value
109 the string to convert to a number
111 a pointer to the location where to store the number upon successful conversion
117 static bool readDouble(const char * valueName, const char * value,
118 double * valueNumber) {
119 char * endPtr = NULL;
123 valueNew = strtod(value, &endPtr);
125 if (!((endPtr != value) && (*value != '\0') && (*endPtr == '\0'))) {
126 /* invalid conversion */
127 pudError(true, "Configured %s (%s) could not be converted to a number",
132 *valueNumber = valueNew;
141 /** The nodeIdType */
142 static NodeIdType nodeIdType = PUD_NODE_ID_TYPE_DEFAULT;
148 NodeIdType getNodeIdTypeNumber(void) {
153 Set the node ID type.
156 The value of the node ID type to set (a number in string representation)
163 - true when an error is detected
166 int setNodeIdType(const char *value, void *data __attribute__ ((unused)),
167 set_plugin_parameter_addon addon __attribute__ ((unused))) {
168 static const char * valueName = PUD_NODE_ID_TYPE_NAME;
169 unsigned long long nodeIdTypeNew;
171 assert (value != NULL);
173 if (!readULL(valueName, value, &nodeIdTypeNew)) {
177 if (!isValidNodeIdType(nodeIdTypeNew)) {
178 pudError(false, "Configured %s (%llu) is reserved", valueName,
183 nodeIdType = nodeIdTypeNew;
193 The type that is used to store the nodeId as a binary representation
195 typedef union _nodeIdBinaryType {
196 unsigned long long longValue;
199 /** The maximum length of a nodeId */
200 #define PUD_NODEIDMAXLENGTH 255
202 /** The nodeId buffer */
203 static unsigned char nodeId[PUD_NODEIDMAXLENGTH + 1];
205 /** The length of the string in the nodeId buffer */
206 static size_t nodeIdLength = 0;
208 /** True when the nodeId is set */
209 static bool nodeIdSet = false;
211 /** The nodeId as a binary representation */
212 static nodeIdBinaryType nodeIdBinary;
214 /** True when the nodeIdBinary is set */
215 static bool nodeIdBinarySet = false;
221 unsigned char * getNodeId(void) {
222 return getNodeIdWithLength(NULL);
226 Get the nodeId and its length
229 a pointer to the variable in which to store the nodeId length (allowed to be
230 NULL, in which case the length is not stored)
235 unsigned char * getNodeIdWithLength(size_t *length) {
237 setNodeId("", NULL, (set_plugin_parameter_addon) {.pc = NULL});
240 if (length != NULL) {
241 *length = nodeIdLength;
251 The value of the node ID to set (in string representation)
258 - true when an error is detected
261 int setNodeId(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))) {
262 static const char * valueName = PUD_NODE_ID_NAME;
265 assert (value != NULL);
267 valueLength = strlen(value);
268 if (valueLength > PUD_NODEIDMAXLENGTH) {
269 pudError(false, "Configured %s is too long, maximum length is"
270 " %u, current length is %lu", valueName, PUD_NODEIDMAXLENGTH,
271 (unsigned long) valueLength);
275 strcpy((char *) &nodeId[0], value);
276 nodeIdLength = valueLength;
287 Validate whether the configured nodeId is valid w.r.t. the configured
288 nodeIdType, for types that fit in an unsigned long long (64 bits)
295 the number of bytes in the buffer
297 static bool setupNodeIdBinaryLongLong(unsigned long long min,
298 unsigned long long max, unsigned int bytes) {
299 if (!nodeIdBinarySet) {
300 if (!readULL(PUD_NODE_ID_NAME, (char *) &nodeId[0],
301 &nodeIdBinary.longValue)) {
304 nodeIdBinarySet = true;
307 if (setupNodeIdNumberForOlsrCache(nodeIdBinary.longValue, min, max,
312 pudError(false, "%s value %llu is out of range [%llu,%llu]",
313 PUD_NODE_ID_NAME, nodeIdBinary.longValue, min, max);
318 Validate whether the configured nodeId is valid w.r.t. the configured
319 nodeIdType, for types that are strings
321 static bool setupNodeIdBinaryString(void) {
325 invalidChars = nmea_string_has_invalid_chars((char *) getNodeId(),
326 PUD_NODE_ID_NAME, &report[0], sizeof(report));
328 pudError(false, &report[0]);
330 return !invalidChars;
334 Validate whether the configured nodeId is valid w.r.t. the configured
341 static bool setupNodeIdBinaryAndValidate(NodeIdType nodeIdTypeNumber) {
342 switch (nodeIdTypeNumber) {
343 case PUD_NODEIDTYPE_IPV4: /* IPv4 address */
344 case PUD_NODEIDTYPE_IPV6: /* IPv6 address */
345 case PUD_NODEIDTYPE_MAC: /* hardware address */
346 /* explicit return: configured nodeId is not relevant */
349 case PUD_NODEIDTYPE_MSISDN: /* an MSISDN number */
350 return setupNodeIdBinaryLongLong(0LL, 999999999999999LL,
351 PUD_NODEIDTYPE_MSISDN_BYTES);
353 case PUD_NODEIDTYPE_TETRA: /* a Tetra number */
354 return setupNodeIdBinaryLongLong(0LL, 99999999999999999LL,
355 PUD_NODEIDTYPE_TETRA_BYTES);
357 case PUD_NODEIDTYPE_DNS: /* DNS name */
358 return setupNodeIdBinaryString();
360 case PUD_NODEIDTYPE_MMSI: /* an AIS MMSI number */
361 return setupNodeIdBinaryLongLong(0LL, 999999999LL,
362 PUD_NODEIDTYPE_MMSI_BYTES);
364 case PUD_NODEIDTYPE_URN: /* a URN number */
365 return setupNodeIdBinaryLongLong(0LL, 16777215LL,
366 PUD_NODEIDTYPE_URN_BYTES);
368 case PUD_NODEIDTYPE_192:
369 return setupNodeIdBinaryLongLong(0LL, 9999999LL,
370 PUD_NODEIDTYPE_192_BYTES);
372 case PUD_NODEIDTYPE_193:
373 return setupNodeIdBinaryLongLong(0LL, 999999LL,
374 PUD_NODEIDTYPE_193_BYTES);
376 case PUD_NODEIDTYPE_194:
377 return setupNodeIdBinaryLongLong(1LL, 8191LL, PUD_NODEIDTYPE_194_BYTES);
379 default: /* unsupported */
380 /* explicit return: configured nodeId is not relevant, will
381 * fallback to IP addresses */
392 /** The maximum number of RX non-OLSR interfaces */
393 #define PUD_RX_NON_OLSR_IF_MAX 32
395 /** Array with RX non-OLSR interface names */
396 static unsigned char rxNonOlsrInterfaceNames[PUD_RX_NON_OLSR_IF_MAX][IFNAMSIZ + 1];
398 /** The number of RX non-OLSR interface names in the array */
399 static unsigned int rxNonOlsrInterfaceCount = 0;
402 Determine whether a give interface name is configured as a receive non-OLSR
406 The interface name to check
409 - true when the given interface name is configured as a receive non-OLSR
413 bool isRxNonOlsrInterface(const char *ifName) {
416 assert (ifName != NULL);
418 for (i = 0; i < rxNonOlsrInterfaceCount; i++) {
419 if (strncmp((char *) &rxNonOlsrInterfaceNames[i][0], ifName, IFNAMSIZ
429 Add a receive non-OLSR interface
432 The name of the non-OLSR interface to add
439 - true when an error is detected
442 int addRxNonOlsrInterface(const char *value, void *data __attribute__ ((unused)),
443 set_plugin_parameter_addon addon __attribute__ ((unused))) {
444 unsigned long valueLength;
446 assert (value != NULL);
448 valueLength = strlen(value);
449 if (valueLength > IFNAMSIZ) {
450 pudError(false, "Configured %s (%s) is too long,"
451 " maximum length is %u, current length is %lu",
452 PUD_RX_NON_OLSR_IF_NAME, value, IFNAMSIZ, valueLength);
456 if (!isRxNonOlsrInterface(value)) {
457 if (rxNonOlsrInterfaceCount >= PUD_RX_NON_OLSR_IF_MAX) {
458 pudError(false, "Can't configure more than %u receive interfaces",
459 PUD_RX_NON_OLSR_IF_MAX);
463 strcpy((char *) &rxNonOlsrInterfaceNames[rxNonOlsrInterfaceCount][0],
465 rxNonOlsrInterfaceCount++;
472 * rxAllowedSourceIpAddress
475 /** The maximum number of RX allowed source IP addresses */
476 #define PUD_RX_ALLOWED_SOURCE_IP_MAX 32
478 /** Array with RX allowed source IP addresses */
479 static struct sockaddr rxAllowedSourceIpAddresses[PUD_RX_ALLOWED_SOURCE_IP_MAX];
481 /** The number of RX allowed source IP addresses in the array */
482 static unsigned int rxAllowedSourceIpAddressesCount = 0;
485 Determine whether a give IP address is configured as an allowed source IP
489 The IP address to check
492 - true when the given IP address is configured as an allowed source IP
496 bool isRxAllowedSourceIpAddress(struct sockaddr * sender) {
498 unsigned int addrSize;
501 if (rxAllowedSourceIpAddressesCount == 0) {
505 if (sender == NULL) {
509 if (sender->sa_family == AF_INET) {
510 addr = (void *) (&((struct sockaddr_in *) sender)->sin_addr);
511 addrSize = sizeof(struct in_addr);
513 addr = (void *) (&((struct sockaddr_in6 *) sender)->sin6_addr);
514 addrSize = sizeof(struct in6_addr);
517 for (i = 0; i < rxAllowedSourceIpAddressesCount; i++) {
518 if ((rxAllowedSourceIpAddresses[i].sa_family == sender->sa_family)
519 && (memcmp(&rxAllowedSourceIpAddresses[i].sa_data, addr,
529 Set the RX allowed source IP addresses.
532 The RX allowed source IP address (in string representation)
539 - true when an error is detected
542 int addRxAllowedSourceIpAddress(const char *value, void *data __attribute__ ((unused)),
543 set_plugin_parameter_addon addon __attribute__ ((unused))) {
544 static const char * valueName = PUD_RX_ALLOWED_SOURCE_IP_NAME;
545 const char * valueInternal = value;
547 struct sockaddr addr;
549 assert (value != NULL);
551 memset(&addr, 0, sizeof(addr));
553 addr.sa_family = olsr_cnf->ip_version;
554 conversion = inet_pton(olsr_cnf->ip_version, valueInternal, &addr.sa_data);
555 if (conversion != 1) {
556 pudError((conversion == -1) ? true : false,
557 "Configured %s (%s) is not an IP address", valueName,
562 if ((rxAllowedSourceIpAddressesCount == 0) || !isRxAllowedSourceIpAddress(&addr)) {
563 if (rxAllowedSourceIpAddressesCount >= PUD_RX_ALLOWED_SOURCE_IP_MAX) {
564 pudError(false, "Can't configure more than %u allowed source IP"
565 " addresses", PUD_RX_ALLOWED_SOURCE_IP_MAX);
569 memcpy(&rxAllowedSourceIpAddresses[rxAllowedSourceIpAddressesCount],
570 &addr, sizeof(addr));
571 rxAllowedSourceIpAddressesCount++;
581 /** The rx multicast address */
582 static union olsr_sockaddr rxMcAddr;
584 /** True when the rx multicast address is set */
585 static bool rxMcAddrSet = false;
589 The receive multicast address (in network byte order). Sets both the address
590 and the port to their default values when the address was not yet set.
592 union olsr_sockaddr * getRxMcAddr(void) {
594 setRxMcAddr(NULL, NULL, ((set_plugin_parameter_addon) {.pc = NULL}));
600 Set the receive multicast address. Sets the address to its default value when
601 the value is NULL. Also sets the port to its default value when the address
605 The receive multicast address (in string representation)
612 - true when an error is detected
615 int setRxMcAddr(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))) {
616 static const char * valueName = PUD_RX_MC_ADDR_NAME;
619 const char * valueInternal = value;
622 getOlsrSockAddrAndPortAddresses(olsr_cnf->ip_version, &rxMcAddr, &ipAddress,
624 if (olsr_cnf->ip_version == AF_INET) {
625 rxMcAddr.in4.sin_family = olsr_cnf->ip_version;
626 if (valueInternal == NULL) {
627 valueInternal = PUD_RX_MC_ADDR_4_DEFAULT;
630 rxMcAddr.in6.sin6_family = olsr_cnf->ip_version;
631 if (valueInternal == NULL) {
632 valueInternal = PUD_RX_MC_ADDR_6_DEFAULT;
637 *port = htons(PUD_RX_MC_PORT_DEFAULT);
640 conversion = inet_pton(olsr_cnf->ip_version, valueInternal, ipAddress);
641 if (conversion != 1) {
642 pudError((conversion == -1) ? true : false,
643 "Configured %s (%s) is not an IP address", valueName,
648 if (!isMulticast(olsr_cnf->ip_version, &rxMcAddr)) {
649 pudError(false, "Configured %s (%s) is not a multicast address",
650 valueName, valueInternal);
664 The receive multicast port (in network byte order)
666 unsigned short getRxMcPort(void) {
668 getOlsrSockaddrPortAddress(olsr_cnf->ip_version, getRxMcAddr(), &port);
673 Set the receive multicast port
676 The receive multicast port (a number in string representation)
683 - true when an error is detected
686 int setRxMcPort(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))) {
687 static const char * valueName = PUD_RX_MC_PORT_NAME;
688 unsigned long long rxMcPortNew;
690 union olsr_sockaddr * addr = getRxMcAddr();
692 assert (value != NULL);
694 if (!readULL(valueName, value, &rxMcPortNew)) {
698 if ((rxMcPortNew < 1) || (rxMcPortNew > 65535)) {
699 pudError(false, "Configured %s (%llu) is outside of"
700 " valid range 1-65535", valueName, rxMcPortNew);
704 getOlsrSockaddrPortAddress(olsr_cnf->ip_version, addr, &port);
705 *port = htons((uint16_t) rxMcPortNew);
714 /** The maximum number of rx non-olsr interfaces */
715 #define PUD_TX_NON_OLSR_IF_MAX 32
717 /** Array with tx non-olsr interface names */
718 static unsigned char txNonOlsrInterfaceNames[PUD_TX_NON_OLSR_IF_MAX][IFNAMSIZ + 1];
720 /** The number of tx interface names in the array */
721 static unsigned int txNonOlsrInterfaceCount = 0;
724 Determine whether a give interface name is configured as a transmit non-OLSR
728 The interface to check
731 - true when the given interface name is configured as a transmit non-OLSR
735 bool isTxNonOlsrInterface(const char *ifName) {
738 assert (ifName != NULL);
740 for (i = 0; i < txNonOlsrInterfaceCount; i++) {
741 if (strncmp((char *) &txNonOlsrInterfaceNames[i][0], ifName, IFNAMSIZ
751 Add a transmit non-OLSR interface
754 The name of the non-OLSR interface to add
761 - true when an error is detected
764 int addTxNonOlsrInterface(const char *value, void *data __attribute__ ((unused)),
765 set_plugin_parameter_addon addon __attribute__ ((unused))) {
766 unsigned long valueLength;
768 assert (value != NULL);
770 valueLength = strlen(value);
771 if (valueLength > IFNAMSIZ) {
772 pudError(false, "Configured %s (%s) is too long,"
773 " maximum length is %u, current length is %lu",
774 PUD_TX_NON_OLSR_IF_NAME, value, IFNAMSIZ, valueLength);
778 if (!isTxNonOlsrInterface(value)) {
779 if (txNonOlsrInterfaceCount >= PUD_TX_NON_OLSR_IF_MAX) {
780 pudError(false, "Can not configure more than %u transmit"
781 " interfaces", PUD_TX_NON_OLSR_IF_MAX);
785 strcpy((char *) &txNonOlsrInterfaceNames[txNonOlsrInterfaceCount][0],
787 txNonOlsrInterfaceCount++;
797 /** The tx multicast address */
798 static union olsr_sockaddr txMcAddr;
800 /** True when the tx multicast address is set */
801 static bool txMcAddrSet = false;
805 The transmit multicast address (in network byte order). Sets both the address
806 and the port to their default values when the address was not yet set.
808 union olsr_sockaddr * getTxMcAddr(void) {
810 setTxMcAddr(NULL, NULL, ((set_plugin_parameter_addon) {.pc = NULL}));
816 Set the transmit multicast address. Sets the address to its default value when
817 the value is NULL. Also sets the port to its default value when the address
821 The transmit multicast address (in string representation)
828 - true when an error is detected
831 int setTxMcAddr(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))) {
832 static const char * valueName = PUD_TX_MC_ADDR_NAME;
835 const char * valueInternal = value;
838 getOlsrSockAddrAndPortAddresses(olsr_cnf->ip_version, &txMcAddr, &ipAddress,
840 if (olsr_cnf->ip_version == AF_INET) {
841 txMcAddr.in4.sin_family = olsr_cnf->ip_version;
842 if (valueInternal == NULL) {
843 valueInternal = PUD_TX_MC_ADDR_4_DEFAULT;
846 txMcAddr.in6.sin6_family = olsr_cnf->ip_version;
847 if (valueInternal == NULL) {
848 valueInternal = PUD_TX_MC_ADDR_6_DEFAULT;
853 *port = htons(PUD_TX_MC_PORT_DEFAULT);
856 conversion = inet_pton(olsr_cnf->ip_version, valueInternal, ipAddress);
857 if (conversion != 1) {
858 pudError((conversion == -1) ? true : false,
859 "Configured %s (%s) is not an IP address", valueName,
864 if (!isMulticast(olsr_cnf->ip_version, &txMcAddr)) {
865 pudError(false, "Configured %s (%s) is not a multicast address",
866 valueName, valueInternal);
880 The transmit multicast port (in network byte order)
882 unsigned short getTxMcPort(void) {
884 getOlsrSockaddrPortAddress(olsr_cnf->ip_version, getTxMcAddr(), &port);
889 Set the transmit multicast port
892 The transmit multicast port (a number in string representation)
899 - true when an error is detected
902 int setTxMcPort(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))) {
903 static const char * valueName = PUD_TX_MC_PORT_NAME;
904 unsigned long long txMcPortNew;
906 union olsr_sockaddr * addr = getTxMcAddr();
908 assert (value != NULL);
910 if (!readULL(valueName, value, &txMcPortNew)) {
914 if ((txMcPortNew < 1) || (txMcPortNew > 65535)) {
915 pudError(false, "Configured %s (%llu) is outside of"
916 " valid range 1-65535", valueName, txMcPortNew);
920 getOlsrSockaddrPortAddress(olsr_cnf->ip_version, addr, &port);
921 *port = htons((uint16_t) txMcPortNew);
930 /** The uplink address */
931 static union olsr_sockaddr uplinkAddr;
933 /** True when the uplink address is set */
934 static bool uplinkAddrSet = false;
936 /** True when the uplink address is set */
937 static bool uplinkPortSet = false;
941 - true when the uplink address is set
944 bool isUplinkAddrSet(void) {
945 return uplinkAddrSet;
950 The uplink address (in network byte order). Sets both the address
951 and the port to their default values when the address was not yet set.
953 union olsr_sockaddr * getUplinkAddr(void) {
954 if (!uplinkAddrSet) {
955 setUplinkAddr(NULL, NULL, ((set_plugin_parameter_addon) {.pc = NULL}));
961 Set the uplink address. Sets the address to its default value when
962 the value is NULL. Also sets the port to its default value when the address
966 The uplink address (in string representation)
973 - true when an error is detected
976 int setUplinkAddr(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))) {
977 static const char * valueName = PUD_UPLINK_ADDR_NAME;
980 const char * valueInternal = value;
982 bool defaultValue = false;
984 getOlsrSockAddrAndPortAddresses(olsr_cnf->ip_version, &uplinkAddr,
986 if (olsr_cnf->ip_version == AF_INET) {
987 uplinkAddr.in4.sin_family = olsr_cnf->ip_version;
988 if (valueInternal == NULL) {
989 valueInternal = PUD_UPLINK_ADDR_4_DEFAULT;
993 uplinkAddr.in6.sin6_family = olsr_cnf->ip_version;
994 if (valueInternal == NULL) {
995 valueInternal = PUD_UPLINK_ADDR_6_DEFAULT;
1000 if (!uplinkPortSet) {
1001 *port = htons(PUD_UPLINK_PORT_DEFAULT);
1002 uplinkPortSet = true;
1005 conversion = inet_pton(olsr_cnf->ip_version, valueInternal, ipAddress);
1006 if (conversion != 1) {
1007 pudError((conversion == -1) ? true : false,
1008 "Configured %s (%s) is not an IP address", valueName,
1013 if (!defaultValue) {
1014 uplinkAddrSet = true;
1026 The uplink port (in network byte order)
1028 unsigned short getUplinkPort(void) {
1030 getOlsrSockaddrPortAddress(olsr_cnf->ip_version, getUplinkAddr(), &port);
1038 The uplink port (a number in string representation)
1045 - true when an error is detected
1048 int setUplinkPort(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))) {
1049 static const char * valueName = PUD_UPLINK_PORT_NAME;
1050 unsigned long long uplinkPortNew;
1052 union olsr_sockaddr * addr = getUplinkAddr();
1054 assert (value != NULL);
1056 if (!readULL(valueName, value, &uplinkPortNew)) {
1060 if ((uplinkPortNew < 1) || (uplinkPortNew > 65535)) {
1061 pudError(false, "Configured %s (%llu) is outside of"
1062 " valid range 1-65535", valueName, uplinkPortNew);
1066 getOlsrSockaddrPortAddress(olsr_cnf->ip_version, addr, &port);
1067 *port = htons((uint16_t) uplinkPortNew);
1068 uplinkPortSet = true;
1078 /** the downlink port */
1079 unsigned short downlinkPort = 0;
1081 /** true when the downlinkPort is set */
1082 bool downlinkPortSet = false;
1086 The downlink port (in network byte order)
1088 unsigned short getDownlinkPort(void) {
1089 if (!downlinkPortSet) {
1090 downlinkPort = htons(PUD_DOWNLINK_PORT_DEFAULT);
1091 downlinkPortSet = true;
1094 return downlinkPort;
1098 Set the downlink port
1101 The downlink port (a number in string representation)
1108 - true when an error is detected
1111 int setDownlinkPort(const char *value, void *data __attribute__ ((unused)),
1112 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1113 static const char * valueName = PUD_DOWNLINK_PORT_NAME;
1114 unsigned long long downlinkPortNew;
1116 assert(value != NULL);
1118 if (!readULL(valueName, value, &downlinkPortNew)) {
1122 if ((downlinkPortNew < 1) || (downlinkPortNew > 65535)) {
1123 pudError(false, "Configured %s (%llu) is outside of"
1124 " valid range 1-65535", valueName, downlinkPortNew);
1128 downlinkPort = htons(downlinkPortNew);
1129 downlinkPortSet = true;
1139 static unsigned char txTtl = PUD_TX_TTL_DEFAULT;
1143 The transmit multicast IP packet time-to-live
1145 unsigned char getTxTtl(void) {
1150 Set the transmit multicast IP packet time-to-live
1153 The transmit multicast IP packet time-to-live (a number in string representation)
1160 - true when an error is detected
1163 int setTxTtl(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))) {
1164 static const char * valueName = PUD_TX_TTL_NAME;
1165 unsigned long long txTtlNew;
1167 assert (value != NULL);
1169 if (!readULL(valueName, value, &txTtlNew)) {
1173 if ((txTtlNew < 1) || (txTtlNew > MAX_TTL)) {
1174 pudError(false, "Configured %s (%llu) is outside of"
1175 " valid range 1-%u", valueName, txTtlNew, MAX_TTL);
1185 * txNmeaMessagePrefix
1188 /** The exact length of the tx NMEA message prefix */
1189 #define PUD_TXNMEAMESSAGEPREFIXLENGTH 4
1191 /** The tx NMEA message prefix buffer */
1192 static unsigned char txNmeaMessagePrefix[PUD_TXNMEAMESSAGEPREFIXLENGTH + 1];
1194 /** True when the tx NMEA message prefix is set */
1195 static bool txNmeaMessagePrefixSet = false;
1199 The transmit multicast NMEA message prefix
1201 unsigned char * getTxNmeaMessagePrefix(void) {
1202 if (!txNmeaMessagePrefixSet) {
1203 setTxNmeaMessagePrefix(PUD_TX_NMEAMESSAGEPREFIX_DEFAULT, NULL,
1204 (set_plugin_parameter_addon) {.pc = NULL});
1206 return &txNmeaMessagePrefix[0];
1210 Set the transmit multicast NMEA message prefix
1213 The transmit multicast NMEA message prefix (in string representation)
1220 - true when an error is detected
1223 int setTxNmeaMessagePrefix(const char *value, void *data __attribute__ ((unused)),
1224 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1225 static const char * valueName = PUD_TX_NMEAMESSAGEPREFIX_NAME;
1230 assert (value != NULL);
1232 valueLength = strlen(value);
1233 if (valueLength != PUD_TXNMEAMESSAGEPREFIXLENGTH) {
1234 pudError(false, "Configured %s (%s) must be %u exactly characters",
1235 valueName, value, PUD_TXNMEAMESSAGEPREFIXLENGTH);
1239 invalidChars = nmea_string_has_invalid_chars(value, valueName, &report[0],
1242 pudError(false, &report[0]);
1246 if ((strchr(value, ' ') != NULL) || (strchr(value, '\t') != NULL)) {
1247 pudError(false, "Configured %s (%s) can not contain whitespace",
1252 strcpy((char *) &txNmeaMessagePrefix[0], value);
1253 txNmeaMessagePrefixSet = true;
1262 static unsigned char olsrTtl = PUD_OLSR_TTL_DEFAULT;
1266 The OLSR multicast IP packet time-to-live
1268 unsigned char getOlsrTtl(void) {
1273 Set the OLSR multicast IP packet time-to-live
1276 The OLSR multicast IP packet time-to-live (a number in string representation)
1283 - true when an error is detected
1286 int setOlsrTtl(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))) {
1287 static const char * valueName = PUD_OLSR_TTL_NAME;
1288 unsigned long long olsrTtlNew;
1290 assert (value != NULL);
1292 if (!readULL(valueName, value, &olsrTtlNew)) {
1296 if ((olsrTtlNew < 1) || (olsrTtlNew > MAX_TTL)) {
1297 pudError(false, "Configured %s (%llu) is outside of valid range 1-%u",
1298 valueName, olsrTtlNew, MAX_TTL);
1302 olsrTtl = olsrTtlNew;
1308 * updateIntervalStationary
1311 /** The stationary interval update plugin parameter (in seconds) */
1312 static unsigned long long updateIntervalStationary = PUD_UPDATE_INTERVAL_STATIONARY_DEFAULT;
1316 The stationary interval update plugin parameter (in seconds)
1318 unsigned long long getUpdateIntervalStationary(void) {
1319 return updateIntervalStationary;
1323 Set stationary interval update plugin parameter
1326 The stationary interval update plugin parameter (in seconds)
1333 - true when an error is detected
1336 int setUpdateIntervalStationary(const char *value, void *data __attribute__ ((unused)),
1337 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1338 static const char * valueName = PUD_UPDATE_INTERVAL_STATIONARY_NAME;
1339 unsigned long long updateIntervalStationaryNew;
1341 assert (value != NULL);
1343 if (!readULL(valueName, value, &updateIntervalStationaryNew)) {
1347 if (updateIntervalStationaryNew < 1) {
1348 pudError(false, "Configured %s must be at least 1", valueName);
1352 updateIntervalStationary = updateIntervalStationaryNew;
1358 * updateIntervalMoving
1361 /** The moving interval update plugin parameter (in seconds) */
1362 static unsigned long long updateIntervalMoving = PUD_UPDATE_INTERVAL_MOVING_DEFAULT;
1366 The moving interval update plugin parameter (in seconds)
1368 unsigned long long getUpdateIntervalMoving(void) {
1369 return updateIntervalMoving;
1373 Set moving interval update plugin parameter
1376 The moving interval update plugin parameter (in seconds)
1383 - true when an error is detected
1386 int setUpdateIntervalMoving(const char *value, void *data __attribute__ ((unused)),
1387 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1388 static const char * valueName = PUD_UPDATE_INTERVAL_MOVING_NAME;
1389 unsigned long long updateIntervalMovingNew;
1391 assert (value != NULL);
1393 if (!readULL(valueName, value, &updateIntervalMovingNew)) {
1397 if (updateIntervalMovingNew < 1) {
1398 pudError(false, "Configured %s must be at least 1", valueName);
1402 updateIntervalMoving = updateIntervalMovingNew;
1408 * uplinkUpdateIntervalStationary
1411 /** The uplink stationary interval update plugin parameter (in seconds) */
1412 static unsigned long long uplinkUpdateIntervalStationary = PUD_UPLINK_UPDATE_INTERVAL_STATIONARY_DEFAULT;
1416 The uplink stationary interval update plugin parameter (in seconds)
1418 unsigned long long getUplinkUpdateIntervalStationary(void) {
1419 return uplinkUpdateIntervalStationary;
1423 Set uplink stationary interval update plugin parameter
1426 The uplink stationary interval update plugin parameter (in seconds)
1433 - true when an error is detected
1436 int setUplinkUpdateIntervalStationary(const char *value, void *data __attribute__ ((unused)),
1437 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1438 static const char * valueName = PUD_UPLINK_UPDATE_INTERVAL_STATIONARY_NAME;
1439 unsigned long long uplinkUpdateIntervalStationaryNew;
1441 assert (value != NULL);
1443 if (!readULL(valueName, value, &uplinkUpdateIntervalStationaryNew)) {
1447 if (uplinkUpdateIntervalStationaryNew < 1) {
1448 pudError(false, "Configured %s must be at least 1", valueName);
1452 uplinkUpdateIntervalStationary = uplinkUpdateIntervalStationaryNew;
1458 * uplinkUpdateIntervalMoving
1461 /** The uplink moving interval update plugin parameter (in seconds) */
1462 static unsigned long long uplinkUpdateIntervalMoving = PUD_UPLINK_UPDATE_INTERVAL_MOVING_DEFAULT;
1466 The uplink moving interval update plugin parameter (in seconds)
1468 unsigned long long getUplinkUpdateIntervalMoving(void) {
1469 return uplinkUpdateIntervalMoving;
1473 Set uplink moving interval update plugin parameter
1476 The uplink moving interval update plugin parameter (in seconds)
1483 - true when an error is detected
1486 int setUplinkUpdateIntervalMoving(const char *value, void *data __attribute__ ((unused)),
1487 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1488 static const char * valueName = PUD_UPLINK_UPDATE_INTERVAL_MOVING_NAME;
1489 unsigned long long uplinkUpdateIntervalMovingNew;
1491 assert (value != NULL);
1493 if (!readULL(valueName, value, &uplinkUpdateIntervalMovingNew)) {
1497 if (uplinkUpdateIntervalMovingNew < 1) {
1498 pudError(false, "Configured %s must be at least 1", valueName);
1502 uplinkUpdateIntervalMoving = uplinkUpdateIntervalMovingNew;
1508 * movingSpeedThreshold
1511 /** The moving speed threshold plugin parameter (in kph) */
1512 static unsigned long long movingSpeedThreshold = PUD_MOVING_SPEED_THRESHOLD_DEFAULT;
1516 The moving speed threshold plugin parameter (in kph)
1518 unsigned long long getMovingSpeedThreshold(void) {
1519 return movingSpeedThreshold;
1523 Set moving speed threshold plugin parameter
1526 The moving speed threshold plugin parameter (in kph)
1533 - true when an error is detected
1536 int setMovingSpeedThreshold(const char *value, void *data __attribute__ ((unused)),
1537 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1538 static const char * valueName = PUD_MOVING_SPEED_THRESHOLD_NAME;
1539 unsigned long long movingSpeedThresholdNew;
1541 assert (value != NULL);
1543 if (!readULL(valueName, value, &movingSpeedThresholdNew)) {
1547 movingSpeedThreshold = movingSpeedThresholdNew;
1553 * movingDistanceThreshold
1556 /** The moving distance threshold plugin parameter (in meters) */
1557 static unsigned long long movingDistanceThreshold = PUD_MOVING_DISTANCE_THRESHOLD_DEFAULT;
1561 The moving distance threshold plugin parameter (in meters)
1563 unsigned long long getMovingDistanceThreshold(void) {
1564 return movingDistanceThreshold;
1568 Set moving distance threshold plugin parameter
1571 The moving distance threshold plugin parameter (in meter)
1578 - true when an error is detected
1581 int setMovingDistanceThreshold(const char *value, void *data __attribute__ ((unused)),
1582 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1583 static const char * valueName = PUD_MOVING_DISTANCE_THRESHOLD_NAME;
1584 unsigned long long movingDistanceThresholdNew;
1586 assert (value != NULL);
1588 if (!readULL(valueName, value, &movingDistanceThresholdNew)) {
1592 movingDistanceThreshold = movingDistanceThresholdNew;
1601 /* The DOP multiplier plugin parameter */
1602 static double dopMultiplier = PUD_DOP_MULTIPLIER_DEFAULT;
1606 The DOP multiplier plugin parameter
1608 double getDopMultiplier(void) {
1609 return dopMultiplier;
1613 Set DOP multiplier plugin parameter
1616 The DOP multiplier plugin parameter
1623 - true when an error is detected
1626 int setDopMultiplier(const char *value, void *data __attribute__ ((unused)),
1627 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1628 static const char * valueName = PUD_DOP_MULTIPLIER_NAME;
1629 double dopMultiplierNew;
1631 assert (value != NULL);
1633 if (!readDouble(valueName, value, &dopMultiplierNew)) {
1637 dopMultiplier = dopMultiplierNew;
1646 /** The default HDOP plugin parameter (in meters) */
1647 static unsigned long long defaultHdop = PUD_DEFAULT_HDOP_DEFAULT;
1651 The default HDOP plugin parameter (in meters)
1653 unsigned long long getDefaultHdop(void) {
1658 Set default HDOP plugin parameter
1661 The default HDOP plugin parameter (in meters)
1668 - true when an error is detected
1671 int setDefaultHdop(const char *value, void *data __attribute__ ((unused)),
1672 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1673 static const char * valueName = PUD_MOVING_DISTANCE_THRESHOLD_NAME;
1674 unsigned long long defaultHdopNew;
1676 assert (value != NULL);
1678 if (!readULL(valueName, value, &defaultHdopNew)) {
1682 defaultHdop = defaultHdopNew;
1691 /** The default VDOP plugin parameter (in meters) */
1692 static unsigned long long defaultVdop = PUD_DEFAULT_VDOP_DEFAULT;
1696 The default VDOP plugin parameter (in meters)
1698 unsigned long long getDefaultVdop(void) {
1703 Set default VDOP plugin parameter
1706 The default VDOP plugin parameter (in meters)
1713 - true when an error is detected
1716 int setDefaultVdop(const char *value, void *data __attribute__ ((unused)),
1717 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1718 static const char * valueName = PUD_MOVING_DISTANCE_THRESHOLD_NAME;
1719 unsigned long long defaultVdopNew;
1721 assert (value != NULL);
1723 if (!readULL(valueName, value, &defaultVdopNew)) {
1727 defaultVdop = defaultVdopNew;
1736 /** The depth of the average list */
1737 static unsigned long long averageDepth = PUD_AVERAGE_DEPTH_DEFAULT;
1741 The depth of the average list
1743 unsigned long long getAverageDepth(void) {
1744 return averageDepth;
1748 Set average depth plugin parameter
1751 The average depth plugin parameter
1758 - true when an error is detected
1761 int setAverageDepth(const char *value, void *data __attribute__ ((unused)),
1762 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1763 static const char * valueName = PUD_AVERAGE_DEPTH_NAME;
1764 unsigned long long averageDepthNew;
1766 assert (value != NULL);
1768 if (!readULL(valueName, value, &averageDepthNew)) {
1772 if (averageDepthNew < 1) {
1773 pudError(false, "Configured %s must be at least 1", valueName);
1777 averageDepth = averageDepthNew;
1783 * hysteresisCountToStationary
1786 /** The hysteresis count for changing state from moving to stationary */
1787 static unsigned long long hysteresisCountToStationary = PUD_HYSTERESIS_COUNT_2STAT_DEFAULT;
1791 The hysteresis count for changing state from moving to stationary
1793 unsigned long long getHysteresisCountToStationary(void) {
1794 return hysteresisCountToStationary;
1798 Set hysteresis count plugin parameter
1801 The hysteresis count plugin parameter
1808 - true when an error is detected
1811 int setHysteresisCountToStationary(const char *value, void *data __attribute__ ((unused)),
1812 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1813 static const char * valueName = PUD_HYSTERESIS_COUNT_2STAT_NAME;
1814 unsigned long long hysteresisCountNew;
1816 assert (value != NULL);
1818 if (!readULL(valueName, value, &hysteresisCountNew)) {
1822 hysteresisCountToStationary = hysteresisCountNew;
1828 * hysteresisCountToMoving
1831 /** The hysteresis count for changing state from stationary to moving */
1832 static unsigned long long hysteresisCountToMoving = PUD_HYSTERESIS_COUNT_2MOV_DEFAULT;
1836 The hysteresis count for changing state from stationary to moving
1838 unsigned long long getHysteresisCountToMoving(void) {
1839 return hysteresisCountToMoving;
1843 Set hysteresis count plugin parameter
1846 The hysteresis count plugin parameter
1853 - true when an error is detected
1856 int setHysteresisCountToMoving(const char *value, void *data __attribute__ ((unused)),
1857 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1858 static const char * valueName = PUD_HYSTERESIS_COUNT_2MOV_NAME;
1859 unsigned long long hysteresisCountNew;
1861 assert (value != NULL);
1863 if (!readULL(valueName, value, &hysteresisCountNew)) {
1867 hysteresisCountToMoving = hysteresisCountNew;
1876 /* when true then duplicate message detection is performed */
1877 static bool useDeDup = PUD_USE_DEDUP_DEFAULT;
1881 The duplicate message detection setting
1883 bool getUseDeDup(void) {
1888 Set duplicate message detection setting plugin parameter
1891 The duplicate message detection setting plugin parameter
1898 - true when an error is detected
1901 int setUseDeDup(const char *value, void *data __attribute__ ((unused)),
1902 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1903 static const char * valueName = PUD_USE_DEDUP_NAME;
1904 unsigned long long useDeDupNew;
1906 assert (value != NULL);
1908 if (!readULL(valueName, value, &useDeDupNew)) {
1912 if ((useDeDupNew != 0) && (useDeDupNew != 1)) {
1913 pudError(false, "Configured %s must be 0 (false) or 1 (true)",
1918 useDeDup = (useDeDupNew == 1);
1927 /** The hysteresis count for changing state from stationary to moving */
1928 static unsigned long long deDupDepth = PUD_DEDUP_DEPTH_DEFAULT;
1932 The hysteresis count for changing state from stationary to moving
1934 unsigned long long getDeDupDepth(void) {
1939 Set de-duplication depth plugin parameter
1942 The de-duplication depth plugin parameter
1949 - true when an error is detected
1952 int setDeDupDepth(const char *value, void *data __attribute__ ((unused)),
1953 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1954 static const char * valueName = PUD_DEDUP_DEPTH_NAME;
1955 unsigned long long deDupDepthNew;
1957 assert (value != NULL);
1959 if (!readULL(valueName, value, &deDupDepthNew)) {
1963 deDupDepth = deDupDepthNew;
1972 /* when true then loopback is performed */
1973 static bool useLoopback = PUD_USE_LOOPBACK_DEFAULT;
1977 The loopback usage setting
1979 bool getUseLoopback(void) {
1984 Set loopback usage plugin parameter
1987 The loopback usage plugin parameter
1994 - true when an error is detected
1997 int setUseLoopback(const char *value, void *data __attribute__ ((unused)),
1998 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1999 static const char * valueName = PUD_USE_LOOPBACK_NAME;
2000 unsigned long long useLoopbackNew;
2002 assert (value != NULL);
2004 if (!readULL(valueName, value, &useLoopbackNew)) {
2008 if ((useLoopbackNew != 0) && (useLoopbackNew != 1)) {
2009 pudError(false, "Configured %s must be 0 (false) or 1 (true)",
2014 useLoopback = (useLoopbackNew == 1);
2024 Check the configuration for consistency and validity.
2027 - true when the configuration is consistent and valid
2030 unsigned int checkConfig(void) {
2033 if (!olsr_cnf->smart_gw_active) {
2034 pudError(false, "Smart Gateway must be active");
2038 if (rxNonOlsrInterfaceCount == 0) {
2039 pudError(false, "No receive non-OLSR interfaces configured");
2043 if (txNonOlsrInterfaceCount == 0) {
2044 pudError(false, "No transmit non-OLSR interfaces configured");
2049 if (nodeIdType == PUD_NODEIDTYPE_DNS) {
2050 char name[PUD_NODEIDMAXLENGTH + 1];
2053 if (gethostname(&name[0], sizeof(name)) < 0) {
2054 pudError(true, "Could not get the host name");
2057 setNodeId(&name[0], NULL,
2058 (set_plugin_parameter_addon) {.pc = NULL});
2060 } else if ((nodeIdType != PUD_NODEIDTYPE_MAC) && (nodeIdType
2061 != PUD_NODEIDTYPE_IPV4) && (nodeIdType != PUD_NODEIDTYPE_IPV6)) {
2062 pudError(false, "No node ID set while one is required for"
2063 " node type %u", nodeIdType);
2068 if (!setupNodeIdBinaryAndValidate(nodeIdType)) {
2072 if (updateIntervalMoving > updateIntervalStationary) {
2073 pudError(false,"The update interval for moving situations must not be"
2074 " larger than that for stationary situations");
2078 if (uplinkUpdateIntervalMoving > uplinkUpdateIntervalStationary) {
2079 pudError(false,"The uplink update interval for moving situations must not be"
2080 " larger than that for stationary situations");
2084 if (getUplinkPort() == getDownlinkPort()) {
2085 pudError(false, "The uplink port and the downlink port must not be the same");
2093 Check the configuration for consistency and validity after everything has been
2097 - true when the configuration is consistent and valid
2100 unsigned int checkRunSetup(void) {
2104 /* any receive interface name that is configured but is not the name of an
2105 * actual receive interface is not a valid interface name */
2106 for (i = 0; i < rxNonOlsrInterfaceCount; i++) {
2107 unsigned char * nonOlsrInterfaceName = &rxNonOlsrInterfaceNames[i][0];
2109 TRxTxNetworkInterface * interfaceObject = getRxNetworkInterfaces();
2111 while (interfaceObject != NULL) {
2112 if (strncmp((char *) nonOlsrInterfaceName,
2113 (char *) &interfaceObject->name[0], IFNAMSIZ + 1) == 0) {
2117 interfaceObject = interfaceObject->next;
2120 pudError(false, "Configured receive non-OLSR interface %s is not"
2121 " a known interface name", nonOlsrInterfaceName);
2126 /* any transmit interface name that is configured but is not the name of an
2127 * actual transmit interface is not a valid interface name */
2128 for (i = 0; i < txNonOlsrInterfaceCount; i++) {
2129 unsigned char * nonOlsrInterfaceName = &txNonOlsrInterfaceNames[i][0];
2131 TRxTxNetworkInterface * interfaceObject = getTxNetworkInterfaces();
2133 while (interfaceObject != NULL) {
2134 if (strncmp((char *) nonOlsrInterfaceName,
2135 (char *) &interfaceObject->name[0], IFNAMSIZ + 1) == 0) {
2139 interfaceObject = interfaceObject->next;
2142 pudError(false, "Configured transmit non-OLSR interface %s is not"
2143 " a known interface name", nonOlsrInterfaceName);