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;
192 /** The maximum length of a nodeId */
193 #define PUD_NODEIDMAXLENGTH 255
196 The type that is used to store the nodeId as a binary representation
198 typedef union _nodeIdBinaryType {
199 unsigned long long longValue;
200 unsigned char stringValue[PUD_NODEIDMAXLENGTH + 1];
203 /** The nodeId buffer */
204 static unsigned char nodeId[PUD_NODEIDMAXLENGTH + 1];
206 /** The length of the string in the nodeId buffer */
207 static size_t nodeIdLength = 0;
209 /** True when the nodeId is set */
210 static bool nodeIdSet = false;
212 /** The nodeId as a binary representation */
213 static nodeIdBinaryType nodeIdBinary;
215 /** True when the nodeIdBinary is set */
216 static bool nodeIdBinarySet = false;
222 unsigned char * getNodeId(void) {
223 return getNodeIdWithLength(NULL);
227 Get the nodeId and its length
230 a pointer to the variable in which to store the nodeId length (allowed to be
231 NULL, in which case the length is not stored)
236 unsigned char * getNodeIdWithLength(size_t *length) {
238 setNodeId("", NULL, (set_plugin_parameter_addon) {.pc = NULL});
241 if (length != NULL) {
242 *length = nodeIdLength;
252 The value of the node ID to set (in string representation)
259 - true when an error is detected
262 int setNodeId(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))) {
263 static const char * valueName = PUD_NODE_ID_NAME;
266 assert (value != NULL);
268 valueLength = strlen(value);
269 if (valueLength > PUD_NODEIDMAXLENGTH) {
270 pudError(false, "Configured %s is too long, maximum length is"
271 " %u, current length is %lu", valueName, PUD_NODEIDMAXLENGTH,
272 (unsigned long) valueLength);
276 strcpy((char *) &nodeId[0], value);
277 nodeIdLength = valueLength;
288 Validate whether the configured nodeId is valid w.r.t. the configured
289 nodeIdType, for types that fit in an unsigned long long (64 bits)
296 the number of bytes in the buffer
298 static bool setupNodeIdBinaryLongLong(unsigned long long min,
299 unsigned long long max, unsigned int bytes) {
300 if (!nodeIdBinarySet) {
301 if (!readULL(PUD_NODE_ID_NAME, (char *) &nodeId[0],
302 &nodeIdBinary.longValue)) {
305 nodeIdBinarySet = true;
308 if ((nodeIdBinary.longValue < min) || (nodeIdBinary.longValue > max)) {
309 pudError(false, "%s value %llu is out of range [%llu,%llu]",
310 PUD_NODE_ID_NAME, nodeIdBinary.longValue, min, max);
314 if (setupNodeIdNumberForOlsrCache(nodeIdBinary.longValue, bytes)) {
322 Validate whether the configured nodeId is valid w.r.t. the configured
323 nodeIdType, for types that are strings
325 static bool setupNodeIdBinaryString(void) {
329 char * nodeid = (char *)getNodeIdWithLength(&nodeidlength);
331 invalidChars = nmea_string_has_invalid_chars(nodeid,
332 PUD_NODE_ID_NAME, &report[0], sizeof(report));
334 pudError(false, &report[0]);
338 if (nodeidlength > PUD_NODEIDMAXLENGTH) {
339 pudError(false, "%s value \"%s\" is too long", PUD_NODE_ID_NAME, &nodeid[0]);
343 /* including trailing \0 */
344 memcpy(&nodeIdBinary.stringValue[0], &nodeid[0], nodeidlength + 1);
345 nodeIdBinarySet = true;
347 /* including trailing \0 */
348 if (setupNodeIdBinaryBufferForOlsrCache(&nodeid[0], nodeidlength + 1)) {
352 pudError(false, "%s value \"%s\" is too long", PUD_NODE_ID_NAME, &nodeid[0]);
357 Validate whether the configured nodeId is valid w.r.t. the configured
364 static bool setupNodeIdBinaryAndValidate(NodeIdType nodeIdTypeNumber) {
365 switch (nodeIdTypeNumber) {
366 case PUD_NODEIDTYPE_IPV4: /* IPv4 address */
367 case PUD_NODEIDTYPE_IPV6: /* IPv6 address */
368 case PUD_NODEIDTYPE_MAC: /* hardware address */
369 /* explicit return: configured nodeId is not relevant */
372 case PUD_NODEIDTYPE_MSISDN: /* an MSISDN number */
373 return setupNodeIdBinaryLongLong(0LL, 999999999999999LL,
374 PUD_NODEIDTYPE_MSISDN_BYTES);
376 case PUD_NODEIDTYPE_TETRA: /* a Tetra number */
377 return setupNodeIdBinaryLongLong(0LL, 99999999999999999LL,
378 PUD_NODEIDTYPE_TETRA_BYTES);
380 case PUD_NODEIDTYPE_DNS: /* DNS name */
381 return setupNodeIdBinaryString();
383 case PUD_NODEIDTYPE_MMSI: /* an AIS MMSI number */
384 return setupNodeIdBinaryLongLong(0LL, 999999999LL,
385 PUD_NODEIDTYPE_MMSI_BYTES);
387 case PUD_NODEIDTYPE_URN: /* a URN number */
388 return setupNodeIdBinaryLongLong(0LL, 16777215LL,
389 PUD_NODEIDTYPE_URN_BYTES);
391 case PUD_NODEIDTYPE_192:
392 return setupNodeIdBinaryLongLong(0LL, 9999999LL,
393 PUD_NODEIDTYPE_192_BYTES);
395 case PUD_NODEIDTYPE_193:
396 return setupNodeIdBinaryLongLong(0LL, 999999LL,
397 PUD_NODEIDTYPE_193_BYTES);
399 case PUD_NODEIDTYPE_194:
400 return setupNodeIdBinaryLongLong(1LL, 8191LL, PUD_NODEIDTYPE_194_BYTES);
402 default: /* unsupported */
403 /* explicit return: configured nodeId is not relevant, will
404 * fallback to IP addresses */
415 /** The maximum number of RX non-OLSR interfaces */
416 #define PUD_RX_NON_OLSR_IF_MAX 32
418 /** Array with RX non-OLSR interface names */
419 static unsigned char rxNonOlsrInterfaceNames[PUD_RX_NON_OLSR_IF_MAX][IFNAMSIZ + 1];
421 /** The number of RX non-OLSR interface names in the array */
422 static unsigned int rxNonOlsrInterfaceCount = 0;
425 Determine whether a give interface name is configured as a receive non-OLSR
429 The interface name to check
432 - true when the given interface name is configured as a receive non-OLSR
436 bool isRxNonOlsrInterface(const char *ifName) {
439 assert (ifName != NULL);
441 for (i = 0; i < rxNonOlsrInterfaceCount; i++) {
442 if (strncmp((char *) &rxNonOlsrInterfaceNames[i][0], ifName, IFNAMSIZ
452 Add a receive non-OLSR interface
455 The name of the non-OLSR interface to add
462 - true when an error is detected
465 int addRxNonOlsrInterface(const char *value, void *data __attribute__ ((unused)),
466 set_plugin_parameter_addon addon __attribute__ ((unused))) {
467 unsigned long valueLength;
469 assert (value != NULL);
471 valueLength = strlen(value);
472 if (valueLength > IFNAMSIZ) {
473 pudError(false, "Configured %s (%s) is too long,"
474 " maximum length is %u, current length is %lu",
475 PUD_RX_NON_OLSR_IF_NAME, value, IFNAMSIZ, valueLength);
479 if (!isRxNonOlsrInterface(value)) {
480 if (rxNonOlsrInterfaceCount >= PUD_RX_NON_OLSR_IF_MAX) {
481 pudError(false, "Can't configure more than %u receive interfaces",
482 PUD_RX_NON_OLSR_IF_MAX);
486 strcpy((char *) &rxNonOlsrInterfaceNames[rxNonOlsrInterfaceCount][0],
488 rxNonOlsrInterfaceCount++;
495 * rxAllowedSourceIpAddress
498 /** The maximum number of RX allowed source IP addresses */
499 #define PUD_RX_ALLOWED_SOURCE_IP_MAX 32
501 /** Array with RX allowed source IP addresses */
502 static struct sockaddr rxAllowedSourceIpAddresses[PUD_RX_ALLOWED_SOURCE_IP_MAX];
504 /** The number of RX allowed source IP addresses in the array */
505 static unsigned int rxAllowedSourceIpAddressesCount = 0;
508 Determine whether a give IP address is configured as an allowed source IP
512 The IP address to check
515 - true when the given IP address is configured as an allowed source IP
519 bool isRxAllowedSourceIpAddress(struct sockaddr * sender) {
521 unsigned int addrSize;
524 if (rxAllowedSourceIpAddressesCount == 0) {
528 if (sender == NULL) {
532 if (sender->sa_family == AF_INET) {
533 addr = (void *) (&((struct sockaddr_in *) sender)->sin_addr);
534 addrSize = sizeof(struct in_addr);
536 addr = (void *) (&((struct sockaddr_in6 *) sender)->sin6_addr);
537 addrSize = sizeof(struct in6_addr);
540 for (i = 0; i < rxAllowedSourceIpAddressesCount; i++) {
541 if ((rxAllowedSourceIpAddresses[i].sa_family == sender->sa_family)
542 && (memcmp(&rxAllowedSourceIpAddresses[i].sa_data, addr,
552 Set the RX allowed source IP addresses.
555 The RX allowed source IP address (in string representation)
562 - true when an error is detected
565 int addRxAllowedSourceIpAddress(const char *value, void *data __attribute__ ((unused)),
566 set_plugin_parameter_addon addon __attribute__ ((unused))) {
567 static const char * valueName = PUD_RX_ALLOWED_SOURCE_IP_NAME;
568 const char * valueInternal = value;
570 struct sockaddr addr;
572 assert (value != NULL);
574 memset(&addr, 0, sizeof(addr));
576 addr.sa_family = olsr_cnf->ip_version;
577 conversion = inet_pton(olsr_cnf->ip_version, valueInternal, &addr.sa_data);
578 if (conversion != 1) {
579 pudError((conversion == -1) ? true : false,
580 "Configured %s (%s) is not an IP address", valueName,
585 if ((rxAllowedSourceIpAddressesCount == 0) || !isRxAllowedSourceIpAddress(&addr)) {
586 if (rxAllowedSourceIpAddressesCount >= PUD_RX_ALLOWED_SOURCE_IP_MAX) {
587 pudError(false, "Can't configure more than %u allowed source IP"
588 " addresses", PUD_RX_ALLOWED_SOURCE_IP_MAX);
592 memcpy(&rxAllowedSourceIpAddresses[rxAllowedSourceIpAddressesCount],
593 &addr, sizeof(addr));
594 rxAllowedSourceIpAddressesCount++;
604 /** The rx multicast address */
605 static union olsr_sockaddr rxMcAddr;
607 /** True when the rx multicast address is set */
608 static bool rxMcAddrSet = false;
612 The receive multicast address (in network byte order). Sets both the address
613 and the port to their default values when the address was not yet set.
615 union olsr_sockaddr * getRxMcAddr(void) {
617 setRxMcAddr(NULL, NULL, ((set_plugin_parameter_addon) {.pc = NULL}));
623 Set the receive multicast address. Sets the address to its default value when
624 the value is NULL. Also sets the port to its default value when the address
628 The receive multicast address (in string representation)
635 - true when an error is detected
638 int setRxMcAddr(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))) {
639 static const char * valueName = PUD_RX_MC_ADDR_NAME;
642 const char * valueInternal = value;
645 getOlsrSockAddrAndPortAddresses(olsr_cnf->ip_version, &rxMcAddr, &ipAddress,
647 if (olsr_cnf->ip_version == AF_INET) {
648 rxMcAddr.in4.sin_family = olsr_cnf->ip_version;
649 if (valueInternal == NULL) {
650 valueInternal = PUD_RX_MC_ADDR_4_DEFAULT;
653 rxMcAddr.in6.sin6_family = olsr_cnf->ip_version;
654 if (valueInternal == NULL) {
655 valueInternal = PUD_RX_MC_ADDR_6_DEFAULT;
660 *port = htons(PUD_RX_MC_PORT_DEFAULT);
663 conversion = inet_pton(olsr_cnf->ip_version, valueInternal, ipAddress);
664 if (conversion != 1) {
665 pudError((conversion == -1) ? true : false,
666 "Configured %s (%s) is not an IP address", valueName,
671 if (!isMulticast(olsr_cnf->ip_version, &rxMcAddr)) {
672 pudError(false, "Configured %s (%s) is not a multicast address",
673 valueName, valueInternal);
687 The receive multicast port (in network byte order)
689 unsigned short getRxMcPort(void) {
691 getOlsrSockaddrPortAddress(olsr_cnf->ip_version, getRxMcAddr(), &port);
696 Set the receive multicast port
699 The receive multicast port (a number in string representation)
706 - true when an error is detected
709 int setRxMcPort(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))) {
710 static const char * valueName = PUD_RX_MC_PORT_NAME;
711 unsigned long long rxMcPortNew;
713 union olsr_sockaddr * addr = getRxMcAddr();
715 assert (value != NULL);
717 if (!readULL(valueName, value, &rxMcPortNew)) {
721 if ((rxMcPortNew < 1) || (rxMcPortNew > 65535)) {
722 pudError(false, "Configured %s (%llu) is outside of"
723 " valid range 1-65535", valueName, rxMcPortNew);
727 getOlsrSockaddrPortAddress(olsr_cnf->ip_version, addr, &port);
728 *port = htons((uint16_t) rxMcPortNew);
737 /** The maximum number of rx non-olsr interfaces */
738 #define PUD_TX_NON_OLSR_IF_MAX 32
740 /** Array with tx non-olsr interface names */
741 static unsigned char txNonOlsrInterfaceNames[PUD_TX_NON_OLSR_IF_MAX][IFNAMSIZ + 1];
743 /** The number of tx interface names in the array */
744 static unsigned int txNonOlsrInterfaceCount = 0;
747 Determine whether a give interface name is configured as a transmit non-OLSR
751 The interface to check
754 - true when the given interface name is configured as a transmit non-OLSR
758 bool isTxNonOlsrInterface(const char *ifName) {
761 assert (ifName != NULL);
763 for (i = 0; i < txNonOlsrInterfaceCount; i++) {
764 if (strncmp((char *) &txNonOlsrInterfaceNames[i][0], ifName, IFNAMSIZ
774 Add a transmit non-OLSR interface
777 The name of the non-OLSR interface to add
784 - true when an error is detected
787 int addTxNonOlsrInterface(const char *value, void *data __attribute__ ((unused)),
788 set_plugin_parameter_addon addon __attribute__ ((unused))) {
789 unsigned long valueLength;
791 assert (value != NULL);
793 valueLength = strlen(value);
794 if (valueLength > IFNAMSIZ) {
795 pudError(false, "Configured %s (%s) is too long,"
796 " maximum length is %u, current length is %lu",
797 PUD_TX_NON_OLSR_IF_NAME, value, IFNAMSIZ, valueLength);
801 if (!isTxNonOlsrInterface(value)) {
802 if (txNonOlsrInterfaceCount >= PUD_TX_NON_OLSR_IF_MAX) {
803 pudError(false, "Can not configure more than %u transmit"
804 " interfaces", PUD_TX_NON_OLSR_IF_MAX);
808 strcpy((char *) &txNonOlsrInterfaceNames[txNonOlsrInterfaceCount][0],
810 txNonOlsrInterfaceCount++;
820 /** The tx multicast address */
821 static union olsr_sockaddr txMcAddr;
823 /** True when the tx multicast address is set */
824 static bool txMcAddrSet = false;
828 The transmit multicast address (in network byte order). Sets both the address
829 and the port to their default values when the address was not yet set.
831 union olsr_sockaddr * getTxMcAddr(void) {
833 setTxMcAddr(NULL, NULL, ((set_plugin_parameter_addon) {.pc = NULL}));
839 Set the transmit multicast address. Sets the address to its default value when
840 the value is NULL. Also sets the port to its default value when the address
844 The transmit multicast address (in string representation)
851 - true when an error is detected
854 int setTxMcAddr(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))) {
855 static const char * valueName = PUD_TX_MC_ADDR_NAME;
858 const char * valueInternal = value;
861 getOlsrSockAddrAndPortAddresses(olsr_cnf->ip_version, &txMcAddr, &ipAddress,
863 if (olsr_cnf->ip_version == AF_INET) {
864 txMcAddr.in4.sin_family = olsr_cnf->ip_version;
865 if (valueInternal == NULL) {
866 valueInternal = PUD_TX_MC_ADDR_4_DEFAULT;
869 txMcAddr.in6.sin6_family = olsr_cnf->ip_version;
870 if (valueInternal == NULL) {
871 valueInternal = PUD_TX_MC_ADDR_6_DEFAULT;
876 *port = htons(PUD_TX_MC_PORT_DEFAULT);
879 conversion = inet_pton(olsr_cnf->ip_version, valueInternal, ipAddress);
880 if (conversion != 1) {
881 pudError((conversion == -1) ? true : false,
882 "Configured %s (%s) is not an IP address", valueName,
887 if (!isMulticast(olsr_cnf->ip_version, &txMcAddr)) {
888 pudError(false, "Configured %s (%s) is not a multicast address",
889 valueName, valueInternal);
903 The transmit multicast port (in network byte order)
905 unsigned short getTxMcPort(void) {
907 getOlsrSockaddrPortAddress(olsr_cnf->ip_version, getTxMcAddr(), &port);
912 Set the transmit multicast port
915 The transmit multicast port (a number in string representation)
922 - true when an error is detected
925 int setTxMcPort(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))) {
926 static const char * valueName = PUD_TX_MC_PORT_NAME;
927 unsigned long long txMcPortNew;
929 union olsr_sockaddr * addr = getTxMcAddr();
931 assert (value != NULL);
933 if (!readULL(valueName, value, &txMcPortNew)) {
937 if ((txMcPortNew < 1) || (txMcPortNew > 65535)) {
938 pudError(false, "Configured %s (%llu) is outside of"
939 " valid range 1-65535", valueName, txMcPortNew);
943 getOlsrSockaddrPortAddress(olsr_cnf->ip_version, addr, &port);
944 *port = htons((uint16_t) txMcPortNew);
953 /** The uplink address */
954 static union olsr_sockaddr uplinkAddr;
956 /** True when the uplink address is set */
957 static bool uplinkAddrSet = false;
959 /** True when the uplink address is set */
960 static bool uplinkPortSet = false;
964 - true when the uplink address is set
967 bool isUplinkAddrSet(void) {
968 return uplinkAddrSet;
973 The uplink address (in network byte order). Sets both the address
974 and the port to their default values when the address was not yet set.
976 union olsr_sockaddr * getUplinkAddr(void) {
977 if (!uplinkAddrSet) {
978 setUplinkAddr(NULL, NULL, ((set_plugin_parameter_addon) {.pc = NULL}));
984 Set the uplink address. Sets the address to its default value when
985 the value is NULL. Also sets the port to its default value when the address
989 The uplink address (in string representation)
996 - true when an error is detected
999 int setUplinkAddr(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))) {
1000 static const char * valueName = PUD_UPLINK_ADDR_NAME;
1003 const char * valueInternal = value;
1005 bool defaultValue = false;
1007 getOlsrSockAddrAndPortAddresses(olsr_cnf->ip_version, &uplinkAddr,
1009 if (olsr_cnf->ip_version == AF_INET) {
1010 uplinkAddr.in4.sin_family = olsr_cnf->ip_version;
1011 if (valueInternal == NULL) {
1012 valueInternal = PUD_UPLINK_ADDR_4_DEFAULT;
1013 defaultValue = true;
1016 uplinkAddr.in6.sin6_family = olsr_cnf->ip_version;
1017 if (valueInternal == NULL) {
1018 valueInternal = PUD_UPLINK_ADDR_6_DEFAULT;
1019 defaultValue = true;
1023 if (!uplinkPortSet) {
1024 *port = htons(PUD_UPLINK_PORT_DEFAULT);
1025 uplinkPortSet = true;
1028 conversion = inet_pton(olsr_cnf->ip_version, valueInternal, ipAddress);
1029 if (conversion != 1) {
1030 pudError((conversion == -1) ? true : false,
1031 "Configured %s (%s) is not an IP address", valueName,
1036 if (!defaultValue) {
1037 uplinkAddrSet = true;
1049 The uplink port (in network byte order)
1051 unsigned short getUplinkPort(void) {
1053 getOlsrSockaddrPortAddress(olsr_cnf->ip_version, getUplinkAddr(), &port);
1061 The uplink port (a number in string representation)
1068 - true when an error is detected
1071 int setUplinkPort(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))) {
1072 static const char * valueName = PUD_UPLINK_PORT_NAME;
1073 unsigned long long uplinkPortNew;
1075 union olsr_sockaddr * addr = getUplinkAddr();
1077 assert (value != NULL);
1079 if (!readULL(valueName, value, &uplinkPortNew)) {
1083 if ((uplinkPortNew < 1) || (uplinkPortNew > 65535)) {
1084 pudError(false, "Configured %s (%llu) is outside of"
1085 " valid range 1-65535", valueName, uplinkPortNew);
1089 getOlsrSockaddrPortAddress(olsr_cnf->ip_version, addr, &port);
1090 *port = htons((uint16_t) uplinkPortNew);
1091 uplinkPortSet = true;
1101 /** the downlink port */
1102 unsigned short downlinkPort = 0;
1104 /** true when the downlinkPort is set */
1105 bool downlinkPortSet = false;
1109 The downlink port (in network byte order)
1111 unsigned short getDownlinkPort(void) {
1112 if (!downlinkPortSet) {
1113 downlinkPort = htons(PUD_DOWNLINK_PORT_DEFAULT);
1114 downlinkPortSet = true;
1117 return downlinkPort;
1121 Set the downlink port
1124 The downlink port (a number in string representation)
1131 - true when an error is detected
1134 int setDownlinkPort(const char *value, void *data __attribute__ ((unused)),
1135 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1136 static const char * valueName = PUD_DOWNLINK_PORT_NAME;
1137 unsigned long long downlinkPortNew;
1139 assert(value != NULL);
1141 if (!readULL(valueName, value, &downlinkPortNew)) {
1145 if ((downlinkPortNew < 1) || (downlinkPortNew > 65535)) {
1146 pudError(false, "Configured %s (%llu) is outside of"
1147 " valid range 1-65535", valueName, downlinkPortNew);
1151 downlinkPort = htons(downlinkPortNew);
1152 downlinkPortSet = true;
1162 static unsigned char txTtl = PUD_TX_TTL_DEFAULT;
1166 The transmit multicast IP packet time-to-live
1168 unsigned char getTxTtl(void) {
1173 Set the transmit multicast IP packet time-to-live
1176 The transmit multicast IP packet time-to-live (a number in string representation)
1183 - true when an error is detected
1186 int setTxTtl(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))) {
1187 static const char * valueName = PUD_TX_TTL_NAME;
1188 unsigned long long txTtlNew;
1190 assert (value != NULL);
1192 if (!readULL(valueName, value, &txTtlNew)) {
1196 if ((txTtlNew < 1) || (txTtlNew > MAX_TTL)) {
1197 pudError(false, "Configured %s (%llu) is outside of"
1198 " valid range 1-%u", valueName, txTtlNew, MAX_TTL);
1208 * txNmeaMessagePrefix
1211 /** The exact length of the tx NMEA message prefix */
1212 #define PUD_TXNMEAMESSAGEPREFIXLENGTH 4
1214 /** The tx NMEA message prefix buffer */
1215 static unsigned char txNmeaMessagePrefix[PUD_TXNMEAMESSAGEPREFIXLENGTH + 1];
1217 /** True when the tx NMEA message prefix is set */
1218 static bool txNmeaMessagePrefixSet = false;
1222 The transmit multicast NMEA message prefix
1224 unsigned char * getTxNmeaMessagePrefix(void) {
1225 if (!txNmeaMessagePrefixSet) {
1226 setTxNmeaMessagePrefix(PUD_TX_NMEAMESSAGEPREFIX_DEFAULT, NULL,
1227 (set_plugin_parameter_addon) {.pc = NULL});
1229 return &txNmeaMessagePrefix[0];
1233 Set the transmit multicast NMEA message prefix
1236 The transmit multicast NMEA message prefix (in string representation)
1243 - true when an error is detected
1246 int setTxNmeaMessagePrefix(const char *value, void *data __attribute__ ((unused)),
1247 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1248 static const char * valueName = PUD_TX_NMEAMESSAGEPREFIX_NAME;
1253 assert (value != NULL);
1255 valueLength = strlen(value);
1256 if (valueLength != PUD_TXNMEAMESSAGEPREFIXLENGTH) {
1257 pudError(false, "Configured %s (%s) must be %u exactly characters",
1258 valueName, value, PUD_TXNMEAMESSAGEPREFIXLENGTH);
1262 invalidChars = nmea_string_has_invalid_chars(value, valueName, &report[0],
1265 pudError(false, &report[0]);
1269 if ((strchr(value, ' ') != NULL) || (strchr(value, '\t') != NULL)) {
1270 pudError(false, "Configured %s (%s) can not contain whitespace",
1275 strcpy((char *) &txNmeaMessagePrefix[0], value);
1276 txNmeaMessagePrefixSet = true;
1285 static unsigned char olsrTtl = PUD_OLSR_TTL_DEFAULT;
1289 The OLSR multicast IP packet time-to-live
1291 unsigned char getOlsrTtl(void) {
1296 Set the OLSR multicast IP packet time-to-live
1299 The OLSR multicast IP packet time-to-live (a number in string representation)
1306 - true when an error is detected
1309 int setOlsrTtl(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))) {
1310 static const char * valueName = PUD_OLSR_TTL_NAME;
1311 unsigned long long olsrTtlNew;
1313 assert (value != NULL);
1315 if (!readULL(valueName, value, &olsrTtlNew)) {
1319 if ((olsrTtlNew < 1) || (olsrTtlNew > MAX_TTL)) {
1320 pudError(false, "Configured %s (%llu) is outside of valid range 1-%u",
1321 valueName, olsrTtlNew, MAX_TTL);
1325 olsrTtl = olsrTtlNew;
1331 * updateIntervalStationary
1334 /** The stationary interval update plugin parameter (in seconds) */
1335 static unsigned long long updateIntervalStationary = PUD_UPDATE_INTERVAL_STATIONARY_DEFAULT;
1339 The stationary interval update plugin parameter (in seconds)
1341 unsigned long long getUpdateIntervalStationary(void) {
1342 return updateIntervalStationary;
1346 Set stationary interval update plugin parameter
1349 The stationary interval update plugin parameter (in seconds)
1356 - true when an error is detected
1359 int setUpdateIntervalStationary(const char *value, void *data __attribute__ ((unused)),
1360 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1361 static const char * valueName = PUD_UPDATE_INTERVAL_STATIONARY_NAME;
1362 unsigned long long updateIntervalStationaryNew;
1364 assert (value != NULL);
1366 if (!readULL(valueName, value, &updateIntervalStationaryNew)) {
1370 if (updateIntervalStationaryNew < 1) {
1371 pudError(false, "Configured %s must be at least 1", valueName);
1375 updateIntervalStationary = updateIntervalStationaryNew;
1381 * updateIntervalMoving
1384 /** The moving interval update plugin parameter (in seconds) */
1385 static unsigned long long updateIntervalMoving = PUD_UPDATE_INTERVAL_MOVING_DEFAULT;
1389 The moving interval update plugin parameter (in seconds)
1391 unsigned long long getUpdateIntervalMoving(void) {
1392 return updateIntervalMoving;
1396 Set moving interval update plugin parameter
1399 The moving interval update plugin parameter (in seconds)
1406 - true when an error is detected
1409 int setUpdateIntervalMoving(const char *value, void *data __attribute__ ((unused)),
1410 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1411 static const char * valueName = PUD_UPDATE_INTERVAL_MOVING_NAME;
1412 unsigned long long updateIntervalMovingNew;
1414 assert (value != NULL);
1416 if (!readULL(valueName, value, &updateIntervalMovingNew)) {
1420 if (updateIntervalMovingNew < 1) {
1421 pudError(false, "Configured %s must be at least 1", valueName);
1425 updateIntervalMoving = updateIntervalMovingNew;
1431 * uplinkUpdateIntervalStationary
1434 /** The uplink stationary interval update plugin parameter (in seconds) */
1435 static unsigned long long uplinkUpdateIntervalStationary = PUD_UPLINK_UPDATE_INTERVAL_STATIONARY_DEFAULT;
1439 The uplink stationary interval update plugin parameter (in seconds)
1441 unsigned long long getUplinkUpdateIntervalStationary(void) {
1442 return uplinkUpdateIntervalStationary;
1446 Set uplink stationary interval update plugin parameter
1449 The uplink stationary interval update plugin parameter (in seconds)
1456 - true when an error is detected
1459 int setUplinkUpdateIntervalStationary(const char *value, void *data __attribute__ ((unused)),
1460 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1461 static const char * valueName = PUD_UPLINK_UPDATE_INTERVAL_STATIONARY_NAME;
1462 unsigned long long uplinkUpdateIntervalStationaryNew;
1464 assert (value != NULL);
1466 if (!readULL(valueName, value, &uplinkUpdateIntervalStationaryNew)) {
1470 if (uplinkUpdateIntervalStationaryNew < 1) {
1471 pudError(false, "Configured %s must be at least 1", valueName);
1475 uplinkUpdateIntervalStationary = uplinkUpdateIntervalStationaryNew;
1481 * uplinkUpdateIntervalMoving
1484 /** The uplink moving interval update plugin parameter (in seconds) */
1485 static unsigned long long uplinkUpdateIntervalMoving = PUD_UPLINK_UPDATE_INTERVAL_MOVING_DEFAULT;
1489 The uplink moving interval update plugin parameter (in seconds)
1491 unsigned long long getUplinkUpdateIntervalMoving(void) {
1492 return uplinkUpdateIntervalMoving;
1496 Set uplink moving interval update plugin parameter
1499 The uplink moving interval update plugin parameter (in seconds)
1506 - true when an error is detected
1509 int setUplinkUpdateIntervalMoving(const char *value, void *data __attribute__ ((unused)),
1510 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1511 static const char * valueName = PUD_UPLINK_UPDATE_INTERVAL_MOVING_NAME;
1512 unsigned long long uplinkUpdateIntervalMovingNew;
1514 assert (value != NULL);
1516 if (!readULL(valueName, value, &uplinkUpdateIntervalMovingNew)) {
1520 if (uplinkUpdateIntervalMovingNew < 1) {
1521 pudError(false, "Configured %s must be at least 1", valueName);
1525 uplinkUpdateIntervalMoving = uplinkUpdateIntervalMovingNew;
1531 * movingSpeedThreshold
1534 /** The moving speed threshold plugin parameter (in kph) */
1535 static unsigned long long movingSpeedThreshold = PUD_MOVING_SPEED_THRESHOLD_DEFAULT;
1539 The moving speed threshold plugin parameter (in kph)
1541 unsigned long long getMovingSpeedThreshold(void) {
1542 return movingSpeedThreshold;
1546 Set moving speed threshold plugin parameter
1549 The moving speed threshold plugin parameter (in kph)
1556 - true when an error is detected
1559 int setMovingSpeedThreshold(const char *value, void *data __attribute__ ((unused)),
1560 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1561 static const char * valueName = PUD_MOVING_SPEED_THRESHOLD_NAME;
1562 unsigned long long movingSpeedThresholdNew;
1564 assert (value != NULL);
1566 if (!readULL(valueName, value, &movingSpeedThresholdNew)) {
1570 movingSpeedThreshold = movingSpeedThresholdNew;
1576 * movingDistanceThreshold
1579 /** The moving distance threshold plugin parameter (in meters) */
1580 static unsigned long long movingDistanceThreshold = PUD_MOVING_DISTANCE_THRESHOLD_DEFAULT;
1584 The moving distance threshold plugin parameter (in meters)
1586 unsigned long long getMovingDistanceThreshold(void) {
1587 return movingDistanceThreshold;
1591 Set moving distance threshold plugin parameter
1594 The moving distance threshold plugin parameter (in meter)
1601 - true when an error is detected
1604 int setMovingDistanceThreshold(const char *value, void *data __attribute__ ((unused)),
1605 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1606 static const char * valueName = PUD_MOVING_DISTANCE_THRESHOLD_NAME;
1607 unsigned long long movingDistanceThresholdNew;
1609 assert (value != NULL);
1611 if (!readULL(valueName, value, &movingDistanceThresholdNew)) {
1615 movingDistanceThreshold = movingDistanceThresholdNew;
1624 /* The DOP multiplier plugin parameter */
1625 static double dopMultiplier = PUD_DOP_MULTIPLIER_DEFAULT;
1629 The DOP multiplier plugin parameter
1631 double getDopMultiplier(void) {
1632 return dopMultiplier;
1636 Set DOP multiplier plugin parameter
1639 The DOP multiplier plugin parameter
1646 - true when an error is detected
1649 int setDopMultiplier(const char *value, void *data __attribute__ ((unused)),
1650 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1651 static const char * valueName = PUD_DOP_MULTIPLIER_NAME;
1652 double dopMultiplierNew;
1654 assert (value != NULL);
1656 if (!readDouble(valueName, value, &dopMultiplierNew)) {
1660 dopMultiplier = dopMultiplierNew;
1669 /** The default HDOP plugin parameter (in meters) */
1670 static unsigned long long defaultHdop = PUD_DEFAULT_HDOP_DEFAULT;
1674 The default HDOP plugin parameter (in meters)
1676 unsigned long long getDefaultHdop(void) {
1681 Set default HDOP plugin parameter
1684 The default HDOP plugin parameter (in meters)
1691 - true when an error is detected
1694 int setDefaultHdop(const char *value, void *data __attribute__ ((unused)),
1695 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1696 static const char * valueName = PUD_MOVING_DISTANCE_THRESHOLD_NAME;
1697 unsigned long long defaultHdopNew;
1699 assert (value != NULL);
1701 if (!readULL(valueName, value, &defaultHdopNew)) {
1705 defaultHdop = defaultHdopNew;
1714 /** The default VDOP plugin parameter (in meters) */
1715 static unsigned long long defaultVdop = PUD_DEFAULT_VDOP_DEFAULT;
1719 The default VDOP plugin parameter (in meters)
1721 unsigned long long getDefaultVdop(void) {
1726 Set default VDOP plugin parameter
1729 The default VDOP plugin parameter (in meters)
1736 - true when an error is detected
1739 int setDefaultVdop(const char *value, void *data __attribute__ ((unused)),
1740 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1741 static const char * valueName = PUD_MOVING_DISTANCE_THRESHOLD_NAME;
1742 unsigned long long defaultVdopNew;
1744 assert (value != NULL);
1746 if (!readULL(valueName, value, &defaultVdopNew)) {
1750 defaultVdop = defaultVdopNew;
1759 /** The depth of the average list */
1760 static unsigned long long averageDepth = PUD_AVERAGE_DEPTH_DEFAULT;
1764 The depth of the average list
1766 unsigned long long getAverageDepth(void) {
1767 return averageDepth;
1771 Set average depth plugin parameter
1774 The average depth plugin parameter
1781 - true when an error is detected
1784 int setAverageDepth(const char *value, void *data __attribute__ ((unused)),
1785 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1786 static const char * valueName = PUD_AVERAGE_DEPTH_NAME;
1787 unsigned long long averageDepthNew;
1789 assert (value != NULL);
1791 if (!readULL(valueName, value, &averageDepthNew)) {
1795 if (averageDepthNew < 1) {
1796 pudError(false, "Configured %s must be at least 1", valueName);
1800 averageDepth = averageDepthNew;
1806 * hysteresisCountToStationary
1809 /** The hysteresis count for changing state from moving to stationary */
1810 static unsigned long long hysteresisCountToStationary = PUD_HYSTERESIS_COUNT_2STAT_DEFAULT;
1814 The hysteresis count for changing state from moving to stationary
1816 unsigned long long getHysteresisCountToStationary(void) {
1817 return hysteresisCountToStationary;
1821 Set hysteresis count plugin parameter
1824 The hysteresis count plugin parameter
1831 - true when an error is detected
1834 int setHysteresisCountToStationary(const char *value, void *data __attribute__ ((unused)),
1835 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1836 static const char * valueName = PUD_HYSTERESIS_COUNT_2STAT_NAME;
1837 unsigned long long hysteresisCountNew;
1839 assert (value != NULL);
1841 if (!readULL(valueName, value, &hysteresisCountNew)) {
1845 hysteresisCountToStationary = hysteresisCountNew;
1851 * hysteresisCountToMoving
1854 /** The hysteresis count for changing state from stationary to moving */
1855 static unsigned long long hysteresisCountToMoving = PUD_HYSTERESIS_COUNT_2MOV_DEFAULT;
1859 The hysteresis count for changing state from stationary to moving
1861 unsigned long long getHysteresisCountToMoving(void) {
1862 return hysteresisCountToMoving;
1866 Set hysteresis count plugin parameter
1869 The hysteresis count plugin parameter
1876 - true when an error is detected
1879 int setHysteresisCountToMoving(const char *value, void *data __attribute__ ((unused)),
1880 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1881 static const char * valueName = PUD_HYSTERESIS_COUNT_2MOV_NAME;
1882 unsigned long long hysteresisCountNew;
1884 assert (value != NULL);
1886 if (!readULL(valueName, value, &hysteresisCountNew)) {
1890 hysteresisCountToMoving = hysteresisCountNew;
1899 /* when true then duplicate message detection is performed */
1900 static bool useDeDup = PUD_USE_DEDUP_DEFAULT;
1904 The duplicate message detection setting
1906 bool getUseDeDup(void) {
1911 Set duplicate message detection setting plugin parameter
1914 The duplicate message detection setting plugin parameter
1921 - true when an error is detected
1924 int setUseDeDup(const char *value, void *data __attribute__ ((unused)),
1925 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1926 static const char * valueName = PUD_USE_DEDUP_NAME;
1927 unsigned long long useDeDupNew;
1929 assert (value != NULL);
1931 if (!readULL(valueName, value, &useDeDupNew)) {
1935 if ((useDeDupNew != 0) && (useDeDupNew != 1)) {
1936 pudError(false, "Configured %s must be 0 (false) or 1 (true)",
1941 useDeDup = (useDeDupNew == 1);
1950 /** The hysteresis count for changing state from stationary to moving */
1951 static unsigned long long deDupDepth = PUD_DEDUP_DEPTH_DEFAULT;
1955 The hysteresis count for changing state from stationary to moving
1957 unsigned long long getDeDupDepth(void) {
1962 Set de-duplication depth plugin parameter
1965 The de-duplication depth plugin parameter
1972 - true when an error is detected
1975 int setDeDupDepth(const char *value, void *data __attribute__ ((unused)),
1976 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1977 static const char * valueName = PUD_DEDUP_DEPTH_NAME;
1978 unsigned long long deDupDepthNew;
1980 assert (value != NULL);
1982 if (!readULL(valueName, value, &deDupDepthNew)) {
1986 deDupDepth = deDupDepthNew;
1995 /* when true then loopback is performed */
1996 static bool useLoopback = PUD_USE_LOOPBACK_DEFAULT;
2000 The loopback usage setting
2002 bool getUseLoopback(void) {
2007 Set loopback usage plugin parameter
2010 The loopback usage plugin parameter
2017 - true when an error is detected
2020 int setUseLoopback(const char *value, void *data __attribute__ ((unused)),
2021 set_plugin_parameter_addon addon __attribute__ ((unused))) {
2022 static const char * valueName = PUD_USE_LOOPBACK_NAME;
2023 unsigned long long useLoopbackNew;
2025 assert (value != NULL);
2027 if (!readULL(valueName, value, &useLoopbackNew)) {
2031 if ((useLoopbackNew != 0) && (useLoopbackNew != 1)) {
2032 pudError(false, "Configured %s must be 0 (false) or 1 (true)",
2037 useLoopback = (useLoopbackNew == 1);
2047 Check the configuration for consistency and validity.
2050 - true when the configuration is consistent and valid
2053 unsigned int checkConfig(void) {
2056 if (!olsr_cnf->smart_gw_active) {
2057 pudError(false, "Smart Gateway must be active");
2061 if (rxNonOlsrInterfaceCount == 0) {
2062 pudError(false, "No receive non-OLSR interfaces configured");
2066 if (txNonOlsrInterfaceCount == 0) {
2067 pudError(false, "No transmit non-OLSR interfaces configured");
2072 if (nodeIdType == PUD_NODEIDTYPE_DNS) {
2073 char name[PUD_NODEIDMAXLENGTH + 1];
2076 if (gethostname(&name[0], sizeof(name)) < 0) {
2077 pudError(true, "Could not get the host name");
2080 setNodeId(&name[0], NULL,
2081 (set_plugin_parameter_addon) {.pc = NULL});
2083 } else if ((nodeIdType != PUD_NODEIDTYPE_MAC) && (nodeIdType
2084 != PUD_NODEIDTYPE_IPV4) && (nodeIdType != PUD_NODEIDTYPE_IPV6)) {
2085 pudError(false, "No node ID set while one is required for"
2086 " node type %u", nodeIdType);
2091 if (!setupNodeIdBinaryAndValidate(nodeIdType)) {
2095 if (updateIntervalMoving > updateIntervalStationary) {
2096 pudError(false,"The update interval for moving situations must not be"
2097 " larger than that for stationary situations");
2101 if (uplinkUpdateIntervalMoving > uplinkUpdateIntervalStationary) {
2102 pudError(false,"The uplink update interval for moving situations must not be"
2103 " larger than that for stationary situations");
2107 if (getUplinkPort() == getDownlinkPort()) {
2108 pudError(false, "The uplink port and the downlink port must not be the same");
2116 Check the configuration for consistency and validity after everything has been
2120 - true when the configuration is consistent and valid
2123 unsigned int checkRunSetup(void) {
2127 /* any receive interface name that is configured but is not the name of an
2128 * actual receive interface is not a valid interface name */
2129 for (i = 0; i < rxNonOlsrInterfaceCount; i++) {
2130 unsigned char * nonOlsrInterfaceName = &rxNonOlsrInterfaceNames[i][0];
2132 TRxTxNetworkInterface * interfaceObject = getRxNetworkInterfaces();
2134 while (interfaceObject != NULL) {
2135 if (strncmp((char *) nonOlsrInterfaceName,
2136 (char *) &interfaceObject->name[0], IFNAMSIZ + 1) == 0) {
2140 interfaceObject = interfaceObject->next;
2143 pudError(false, "Configured receive non-OLSR interface %s is not"
2144 " a known interface name", nonOlsrInterfaceName);
2149 /* any transmit interface name that is configured but is not the name of an
2150 * actual transmit interface is not a valid interface name */
2151 for (i = 0; i < txNonOlsrInterfaceCount; i++) {
2152 unsigned char * nonOlsrInterfaceName = &txNonOlsrInterfaceNames[i][0];
2154 TRxTxNetworkInterface * interfaceObject = getTxNetworkInterfaces();
2156 while (interfaceObject != NULL) {
2157 if (strncmp((char *) nonOlsrInterfaceName,
2158 (char *) &interfaceObject->name[0], IFNAMSIZ + 1) == 0) {
2162 interfaceObject = interfaceObject->next;
2165 pudError(false, "Configured transmit non-OLSR interface %s is not"
2166 " a known interface name", nonOlsrInterfaceName);