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 (setupNodeIdNumberForOlsrCache(nodeIdBinary.longValue, min, max,
313 pudError(false, "%s value %llu is out of range [%llu,%llu]",
314 PUD_NODE_ID_NAME, nodeIdBinary.longValue, min, max);
319 Validate whether the configured nodeId is valid w.r.t. the configured
320 nodeIdType, for types that are strings
322 static bool setupNodeIdBinaryString(void) {
326 char * nodeid = (char *)getNodeIdWithLength(&nodeidlength);
328 invalidChars = nmea_string_has_invalid_chars(nodeid,
329 PUD_NODE_ID_NAME, &report[0], sizeof(report));
331 pudError(false, &report[0]);
335 if (nodeidlength > PUD_NODEIDMAXLENGTH) {
336 pudError(false, "%s value \"%s\" is too long", PUD_NODE_ID_NAME, &nodeid[0]);
340 /* including trailing \0 */
341 memcpy(&nodeIdBinary.stringValue[0], &nodeid[0], nodeidlength + 1);
342 nodeIdBinarySet = true;
344 /* including trailing \0 */
345 if (setupNodeIdBinaryBufferForOlsrCache(&nodeid[0], nodeidlength + 1)) {
349 pudError(false, "%s value \"%s\" is too long", PUD_NODE_ID_NAME, &nodeid[0]);
354 Validate whether the configured nodeId is valid w.r.t. the configured
361 static bool setupNodeIdBinaryAndValidate(NodeIdType nodeIdTypeNumber) {
362 switch (nodeIdTypeNumber) {
363 case PUD_NODEIDTYPE_IPV4: /* IPv4 address */
364 case PUD_NODEIDTYPE_IPV6: /* IPv6 address */
365 case PUD_NODEIDTYPE_MAC: /* hardware address */
366 /* explicit return: configured nodeId is not relevant */
369 case PUD_NODEIDTYPE_MSISDN: /* an MSISDN number */
370 return setupNodeIdBinaryLongLong(0LL, 999999999999999LL,
371 PUD_NODEIDTYPE_MSISDN_BYTES);
373 case PUD_NODEIDTYPE_TETRA: /* a Tetra number */
374 return setupNodeIdBinaryLongLong(0LL, 99999999999999999LL,
375 PUD_NODEIDTYPE_TETRA_BYTES);
377 case PUD_NODEIDTYPE_DNS: /* DNS name */
378 return setupNodeIdBinaryString();
380 case PUD_NODEIDTYPE_MMSI: /* an AIS MMSI number */
381 return setupNodeIdBinaryLongLong(0LL, 999999999LL,
382 PUD_NODEIDTYPE_MMSI_BYTES);
384 case PUD_NODEIDTYPE_URN: /* a URN number */
385 return setupNodeIdBinaryLongLong(0LL, 16777215LL,
386 PUD_NODEIDTYPE_URN_BYTES);
388 case PUD_NODEIDTYPE_192:
389 return setupNodeIdBinaryLongLong(0LL, 9999999LL,
390 PUD_NODEIDTYPE_192_BYTES);
392 case PUD_NODEIDTYPE_193:
393 return setupNodeIdBinaryLongLong(0LL, 999999LL,
394 PUD_NODEIDTYPE_193_BYTES);
396 case PUD_NODEIDTYPE_194:
397 return setupNodeIdBinaryLongLong(1LL, 8191LL, PUD_NODEIDTYPE_194_BYTES);
399 default: /* unsupported */
400 /* explicit return: configured nodeId is not relevant, will
401 * fallback to IP addresses */
412 /** The maximum number of RX non-OLSR interfaces */
413 #define PUD_RX_NON_OLSR_IF_MAX 32
415 /** Array with RX non-OLSR interface names */
416 static unsigned char rxNonOlsrInterfaceNames[PUD_RX_NON_OLSR_IF_MAX][IFNAMSIZ + 1];
418 /** The number of RX non-OLSR interface names in the array */
419 static unsigned int rxNonOlsrInterfaceCount = 0;
422 Determine whether a give interface name is configured as a receive non-OLSR
426 The interface name to check
429 - true when the given interface name is configured as a receive non-OLSR
433 bool isRxNonOlsrInterface(const char *ifName) {
436 assert (ifName != NULL);
438 for (i = 0; i < rxNonOlsrInterfaceCount; i++) {
439 if (strncmp((char *) &rxNonOlsrInterfaceNames[i][0], ifName, IFNAMSIZ
449 Add a receive non-OLSR interface
452 The name of the non-OLSR interface to add
459 - true when an error is detected
462 int addRxNonOlsrInterface(const char *value, void *data __attribute__ ((unused)),
463 set_plugin_parameter_addon addon __attribute__ ((unused))) {
464 unsigned long valueLength;
466 assert (value != NULL);
468 valueLength = strlen(value);
469 if (valueLength > IFNAMSIZ) {
470 pudError(false, "Configured %s (%s) is too long,"
471 " maximum length is %u, current length is %lu",
472 PUD_RX_NON_OLSR_IF_NAME, value, IFNAMSIZ, valueLength);
476 if (!isRxNonOlsrInterface(value)) {
477 if (rxNonOlsrInterfaceCount >= PUD_RX_NON_OLSR_IF_MAX) {
478 pudError(false, "Can't configure more than %u receive interfaces",
479 PUD_RX_NON_OLSR_IF_MAX);
483 strcpy((char *) &rxNonOlsrInterfaceNames[rxNonOlsrInterfaceCount][0],
485 rxNonOlsrInterfaceCount++;
492 * rxAllowedSourceIpAddress
495 /** The maximum number of RX allowed source IP addresses */
496 #define PUD_RX_ALLOWED_SOURCE_IP_MAX 32
498 /** Array with RX allowed source IP addresses */
499 static struct sockaddr rxAllowedSourceIpAddresses[PUD_RX_ALLOWED_SOURCE_IP_MAX];
501 /** The number of RX allowed source IP addresses in the array */
502 static unsigned int rxAllowedSourceIpAddressesCount = 0;
505 Determine whether a give IP address is configured as an allowed source IP
509 The IP address to check
512 - true when the given IP address is configured as an allowed source IP
516 bool isRxAllowedSourceIpAddress(struct sockaddr * sender) {
518 unsigned int addrSize;
521 if (rxAllowedSourceIpAddressesCount == 0) {
525 if (sender == NULL) {
529 if (sender->sa_family == AF_INET) {
530 addr = (void *) (&((struct sockaddr_in *) sender)->sin_addr);
531 addrSize = sizeof(struct in_addr);
533 addr = (void *) (&((struct sockaddr_in6 *) sender)->sin6_addr);
534 addrSize = sizeof(struct in6_addr);
537 for (i = 0; i < rxAllowedSourceIpAddressesCount; i++) {
538 if ((rxAllowedSourceIpAddresses[i].sa_family == sender->sa_family)
539 && (memcmp(&rxAllowedSourceIpAddresses[i].sa_data, addr,
549 Set the RX allowed source IP addresses.
552 The RX allowed source IP address (in string representation)
559 - true when an error is detected
562 int addRxAllowedSourceIpAddress(const char *value, void *data __attribute__ ((unused)),
563 set_plugin_parameter_addon addon __attribute__ ((unused))) {
564 static const char * valueName = PUD_RX_ALLOWED_SOURCE_IP_NAME;
565 const char * valueInternal = value;
567 struct sockaddr addr;
569 assert (value != NULL);
571 memset(&addr, 0, sizeof(addr));
573 addr.sa_family = olsr_cnf->ip_version;
574 conversion = inet_pton(olsr_cnf->ip_version, valueInternal, &addr.sa_data);
575 if (conversion != 1) {
576 pudError((conversion == -1) ? true : false,
577 "Configured %s (%s) is not an IP address", valueName,
582 if ((rxAllowedSourceIpAddressesCount == 0) || !isRxAllowedSourceIpAddress(&addr)) {
583 if (rxAllowedSourceIpAddressesCount >= PUD_RX_ALLOWED_SOURCE_IP_MAX) {
584 pudError(false, "Can't configure more than %u allowed source IP"
585 " addresses", PUD_RX_ALLOWED_SOURCE_IP_MAX);
589 memcpy(&rxAllowedSourceIpAddresses[rxAllowedSourceIpAddressesCount],
590 &addr, sizeof(addr));
591 rxAllowedSourceIpAddressesCount++;
601 /** The rx multicast address */
602 static union olsr_sockaddr rxMcAddr;
604 /** True when the rx multicast address is set */
605 static bool rxMcAddrSet = false;
609 The receive multicast address (in network byte order). Sets both the address
610 and the port to their default values when the address was not yet set.
612 union olsr_sockaddr * getRxMcAddr(void) {
614 setRxMcAddr(NULL, NULL, ((set_plugin_parameter_addon) {.pc = NULL}));
620 Set the receive multicast address. Sets the address to its default value when
621 the value is NULL. Also sets the port to its default value when the address
625 The receive multicast address (in string representation)
632 - true when an error is detected
635 int setRxMcAddr(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))) {
636 static const char * valueName = PUD_RX_MC_ADDR_NAME;
639 const char * valueInternal = value;
642 getOlsrSockAddrAndPortAddresses(olsr_cnf->ip_version, &rxMcAddr, &ipAddress,
644 if (olsr_cnf->ip_version == AF_INET) {
645 rxMcAddr.in4.sin_family = olsr_cnf->ip_version;
646 if (valueInternal == NULL) {
647 valueInternal = PUD_RX_MC_ADDR_4_DEFAULT;
650 rxMcAddr.in6.sin6_family = olsr_cnf->ip_version;
651 if (valueInternal == NULL) {
652 valueInternal = PUD_RX_MC_ADDR_6_DEFAULT;
657 *port = htons(PUD_RX_MC_PORT_DEFAULT);
660 conversion = inet_pton(olsr_cnf->ip_version, valueInternal, ipAddress);
661 if (conversion != 1) {
662 pudError((conversion == -1) ? true : false,
663 "Configured %s (%s) is not an IP address", valueName,
668 if (!isMulticast(olsr_cnf->ip_version, &rxMcAddr)) {
669 pudError(false, "Configured %s (%s) is not a multicast address",
670 valueName, valueInternal);
684 The receive multicast port (in network byte order)
686 unsigned short getRxMcPort(void) {
688 getOlsrSockaddrPortAddress(olsr_cnf->ip_version, getRxMcAddr(), &port);
693 Set the receive multicast port
696 The receive multicast port (a number in string representation)
703 - true when an error is detected
706 int setRxMcPort(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))) {
707 static const char * valueName = PUD_RX_MC_PORT_NAME;
708 unsigned long long rxMcPortNew;
710 union olsr_sockaddr * addr = getRxMcAddr();
712 assert (value != NULL);
714 if (!readULL(valueName, value, &rxMcPortNew)) {
718 if ((rxMcPortNew < 1) || (rxMcPortNew > 65535)) {
719 pudError(false, "Configured %s (%llu) is outside of"
720 " valid range 1-65535", valueName, rxMcPortNew);
724 getOlsrSockaddrPortAddress(olsr_cnf->ip_version, addr, &port);
725 *port = htons((uint16_t) rxMcPortNew);
734 /** The maximum number of rx non-olsr interfaces */
735 #define PUD_TX_NON_OLSR_IF_MAX 32
737 /** Array with tx non-olsr interface names */
738 static unsigned char txNonOlsrInterfaceNames[PUD_TX_NON_OLSR_IF_MAX][IFNAMSIZ + 1];
740 /** The number of tx interface names in the array */
741 static unsigned int txNonOlsrInterfaceCount = 0;
744 Determine whether a give interface name is configured as a transmit non-OLSR
748 The interface to check
751 - true when the given interface name is configured as a transmit non-OLSR
755 bool isTxNonOlsrInterface(const char *ifName) {
758 assert (ifName != NULL);
760 for (i = 0; i < txNonOlsrInterfaceCount; i++) {
761 if (strncmp((char *) &txNonOlsrInterfaceNames[i][0], ifName, IFNAMSIZ
771 Add a transmit non-OLSR interface
774 The name of the non-OLSR interface to add
781 - true when an error is detected
784 int addTxNonOlsrInterface(const char *value, void *data __attribute__ ((unused)),
785 set_plugin_parameter_addon addon __attribute__ ((unused))) {
786 unsigned long valueLength;
788 assert (value != NULL);
790 valueLength = strlen(value);
791 if (valueLength > IFNAMSIZ) {
792 pudError(false, "Configured %s (%s) is too long,"
793 " maximum length is %u, current length is %lu",
794 PUD_TX_NON_OLSR_IF_NAME, value, IFNAMSIZ, valueLength);
798 if (!isTxNonOlsrInterface(value)) {
799 if (txNonOlsrInterfaceCount >= PUD_TX_NON_OLSR_IF_MAX) {
800 pudError(false, "Can not configure more than %u transmit"
801 " interfaces", PUD_TX_NON_OLSR_IF_MAX);
805 strcpy((char *) &txNonOlsrInterfaceNames[txNonOlsrInterfaceCount][0],
807 txNonOlsrInterfaceCount++;
817 /** The tx multicast address */
818 static union olsr_sockaddr txMcAddr;
820 /** True when the tx multicast address is set */
821 static bool txMcAddrSet = false;
825 The transmit multicast address (in network byte order). Sets both the address
826 and the port to their default values when the address was not yet set.
828 union olsr_sockaddr * getTxMcAddr(void) {
830 setTxMcAddr(NULL, NULL, ((set_plugin_parameter_addon) {.pc = NULL}));
836 Set the transmit multicast address. Sets the address to its default value when
837 the value is NULL. Also sets the port to its default value when the address
841 The transmit multicast address (in string representation)
848 - true when an error is detected
851 int setTxMcAddr(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))) {
852 static const char * valueName = PUD_TX_MC_ADDR_NAME;
855 const char * valueInternal = value;
858 getOlsrSockAddrAndPortAddresses(olsr_cnf->ip_version, &txMcAddr, &ipAddress,
860 if (olsr_cnf->ip_version == AF_INET) {
861 txMcAddr.in4.sin_family = olsr_cnf->ip_version;
862 if (valueInternal == NULL) {
863 valueInternal = PUD_TX_MC_ADDR_4_DEFAULT;
866 txMcAddr.in6.sin6_family = olsr_cnf->ip_version;
867 if (valueInternal == NULL) {
868 valueInternal = PUD_TX_MC_ADDR_6_DEFAULT;
873 *port = htons(PUD_TX_MC_PORT_DEFAULT);
876 conversion = inet_pton(olsr_cnf->ip_version, valueInternal, ipAddress);
877 if (conversion != 1) {
878 pudError((conversion == -1) ? true : false,
879 "Configured %s (%s) is not an IP address", valueName,
884 if (!isMulticast(olsr_cnf->ip_version, &txMcAddr)) {
885 pudError(false, "Configured %s (%s) is not a multicast address",
886 valueName, valueInternal);
900 The transmit multicast port (in network byte order)
902 unsigned short getTxMcPort(void) {
904 getOlsrSockaddrPortAddress(olsr_cnf->ip_version, getTxMcAddr(), &port);
909 Set the transmit multicast port
912 The transmit multicast port (a number in string representation)
919 - true when an error is detected
922 int setTxMcPort(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))) {
923 static const char * valueName = PUD_TX_MC_PORT_NAME;
924 unsigned long long txMcPortNew;
926 union olsr_sockaddr * addr = getTxMcAddr();
928 assert (value != NULL);
930 if (!readULL(valueName, value, &txMcPortNew)) {
934 if ((txMcPortNew < 1) || (txMcPortNew > 65535)) {
935 pudError(false, "Configured %s (%llu) is outside of"
936 " valid range 1-65535", valueName, txMcPortNew);
940 getOlsrSockaddrPortAddress(olsr_cnf->ip_version, addr, &port);
941 *port = htons((uint16_t) txMcPortNew);
950 /** The uplink address */
951 static union olsr_sockaddr uplinkAddr;
953 /** True when the uplink address is set */
954 static bool uplinkAddrSet = false;
956 /** True when the uplink address is set */
957 static bool uplinkPortSet = false;
961 - true when the uplink address is set
964 bool isUplinkAddrSet(void) {
965 return uplinkAddrSet;
970 The uplink address (in network byte order). Sets both the address
971 and the port to their default values when the address was not yet set.
973 union olsr_sockaddr * getUplinkAddr(void) {
974 if (!uplinkAddrSet) {
975 setUplinkAddr(NULL, NULL, ((set_plugin_parameter_addon) {.pc = NULL}));
981 Set the uplink address. Sets the address to its default value when
982 the value is NULL. Also sets the port to its default value when the address
986 The uplink address (in string representation)
993 - true when an error is detected
996 int setUplinkAddr(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))) {
997 static const char * valueName = PUD_UPLINK_ADDR_NAME;
1000 const char * valueInternal = value;
1002 bool defaultValue = false;
1004 getOlsrSockAddrAndPortAddresses(olsr_cnf->ip_version, &uplinkAddr,
1006 if (olsr_cnf->ip_version == AF_INET) {
1007 uplinkAddr.in4.sin_family = olsr_cnf->ip_version;
1008 if (valueInternal == NULL) {
1009 valueInternal = PUD_UPLINK_ADDR_4_DEFAULT;
1010 defaultValue = true;
1013 uplinkAddr.in6.sin6_family = olsr_cnf->ip_version;
1014 if (valueInternal == NULL) {
1015 valueInternal = PUD_UPLINK_ADDR_6_DEFAULT;
1016 defaultValue = true;
1020 if (!uplinkPortSet) {
1021 *port = htons(PUD_UPLINK_PORT_DEFAULT);
1022 uplinkPortSet = true;
1025 conversion = inet_pton(olsr_cnf->ip_version, valueInternal, ipAddress);
1026 if (conversion != 1) {
1027 pudError((conversion == -1) ? true : false,
1028 "Configured %s (%s) is not an IP address", valueName,
1033 if (!defaultValue) {
1034 uplinkAddrSet = true;
1046 The uplink port (in network byte order)
1048 unsigned short getUplinkPort(void) {
1050 getOlsrSockaddrPortAddress(olsr_cnf->ip_version, getUplinkAddr(), &port);
1058 The uplink port (a number in string representation)
1065 - true when an error is detected
1068 int setUplinkPort(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))) {
1069 static const char * valueName = PUD_UPLINK_PORT_NAME;
1070 unsigned long long uplinkPortNew;
1072 union olsr_sockaddr * addr = getUplinkAddr();
1074 assert (value != NULL);
1076 if (!readULL(valueName, value, &uplinkPortNew)) {
1080 if ((uplinkPortNew < 1) || (uplinkPortNew > 65535)) {
1081 pudError(false, "Configured %s (%llu) is outside of"
1082 " valid range 1-65535", valueName, uplinkPortNew);
1086 getOlsrSockaddrPortAddress(olsr_cnf->ip_version, addr, &port);
1087 *port = htons((uint16_t) uplinkPortNew);
1088 uplinkPortSet = true;
1098 /** the downlink port */
1099 unsigned short downlinkPort = 0;
1101 /** true when the downlinkPort is set */
1102 bool downlinkPortSet = false;
1106 The downlink port (in network byte order)
1108 unsigned short getDownlinkPort(void) {
1109 if (!downlinkPortSet) {
1110 downlinkPort = htons(PUD_DOWNLINK_PORT_DEFAULT);
1111 downlinkPortSet = true;
1114 return downlinkPort;
1118 Set the downlink port
1121 The downlink port (a number in string representation)
1128 - true when an error is detected
1131 int setDownlinkPort(const char *value, void *data __attribute__ ((unused)),
1132 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1133 static const char * valueName = PUD_DOWNLINK_PORT_NAME;
1134 unsigned long long downlinkPortNew;
1136 assert(value != NULL);
1138 if (!readULL(valueName, value, &downlinkPortNew)) {
1142 if ((downlinkPortNew < 1) || (downlinkPortNew > 65535)) {
1143 pudError(false, "Configured %s (%llu) is outside of"
1144 " valid range 1-65535", valueName, downlinkPortNew);
1148 downlinkPort = htons(downlinkPortNew);
1149 downlinkPortSet = true;
1159 static unsigned char txTtl = PUD_TX_TTL_DEFAULT;
1163 The transmit multicast IP packet time-to-live
1165 unsigned char getTxTtl(void) {
1170 Set the transmit multicast IP packet time-to-live
1173 The transmit multicast IP packet time-to-live (a number in string representation)
1180 - true when an error is detected
1183 int setTxTtl(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))) {
1184 static const char * valueName = PUD_TX_TTL_NAME;
1185 unsigned long long txTtlNew;
1187 assert (value != NULL);
1189 if (!readULL(valueName, value, &txTtlNew)) {
1193 if ((txTtlNew < 1) || (txTtlNew > MAX_TTL)) {
1194 pudError(false, "Configured %s (%llu) is outside of"
1195 " valid range 1-%u", valueName, txTtlNew, MAX_TTL);
1205 * txNmeaMessagePrefix
1208 /** The exact length of the tx NMEA message prefix */
1209 #define PUD_TXNMEAMESSAGEPREFIXLENGTH 4
1211 /** The tx NMEA message prefix buffer */
1212 static unsigned char txNmeaMessagePrefix[PUD_TXNMEAMESSAGEPREFIXLENGTH + 1];
1214 /** True when the tx NMEA message prefix is set */
1215 static bool txNmeaMessagePrefixSet = false;
1219 The transmit multicast NMEA message prefix
1221 unsigned char * getTxNmeaMessagePrefix(void) {
1222 if (!txNmeaMessagePrefixSet) {
1223 setTxNmeaMessagePrefix(PUD_TX_NMEAMESSAGEPREFIX_DEFAULT, NULL,
1224 (set_plugin_parameter_addon) {.pc = NULL});
1226 return &txNmeaMessagePrefix[0];
1230 Set the transmit multicast NMEA message prefix
1233 The transmit multicast NMEA message prefix (in string representation)
1240 - true when an error is detected
1243 int setTxNmeaMessagePrefix(const char *value, void *data __attribute__ ((unused)),
1244 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1245 static const char * valueName = PUD_TX_NMEAMESSAGEPREFIX_NAME;
1250 assert (value != NULL);
1252 valueLength = strlen(value);
1253 if (valueLength != PUD_TXNMEAMESSAGEPREFIXLENGTH) {
1254 pudError(false, "Configured %s (%s) must be %u exactly characters",
1255 valueName, value, PUD_TXNMEAMESSAGEPREFIXLENGTH);
1259 invalidChars = nmea_string_has_invalid_chars(value, valueName, &report[0],
1262 pudError(false, &report[0]);
1266 if ((strchr(value, ' ') != NULL) || (strchr(value, '\t') != NULL)) {
1267 pudError(false, "Configured %s (%s) can not contain whitespace",
1272 strcpy((char *) &txNmeaMessagePrefix[0], value);
1273 txNmeaMessagePrefixSet = true;
1282 static unsigned char olsrTtl = PUD_OLSR_TTL_DEFAULT;
1286 The OLSR multicast IP packet time-to-live
1288 unsigned char getOlsrTtl(void) {
1293 Set the OLSR multicast IP packet time-to-live
1296 The OLSR multicast IP packet time-to-live (a number in string representation)
1303 - true when an error is detected
1306 int setOlsrTtl(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))) {
1307 static const char * valueName = PUD_OLSR_TTL_NAME;
1308 unsigned long long olsrTtlNew;
1310 assert (value != NULL);
1312 if (!readULL(valueName, value, &olsrTtlNew)) {
1316 if ((olsrTtlNew < 1) || (olsrTtlNew > MAX_TTL)) {
1317 pudError(false, "Configured %s (%llu) is outside of valid range 1-%u",
1318 valueName, olsrTtlNew, MAX_TTL);
1322 olsrTtl = olsrTtlNew;
1328 * updateIntervalStationary
1331 /** The stationary interval update plugin parameter (in seconds) */
1332 static unsigned long long updateIntervalStationary = PUD_UPDATE_INTERVAL_STATIONARY_DEFAULT;
1336 The stationary interval update plugin parameter (in seconds)
1338 unsigned long long getUpdateIntervalStationary(void) {
1339 return updateIntervalStationary;
1343 Set stationary interval update plugin parameter
1346 The stationary interval update plugin parameter (in seconds)
1353 - true when an error is detected
1356 int setUpdateIntervalStationary(const char *value, void *data __attribute__ ((unused)),
1357 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1358 static const char * valueName = PUD_UPDATE_INTERVAL_STATIONARY_NAME;
1359 unsigned long long updateIntervalStationaryNew;
1361 assert (value != NULL);
1363 if (!readULL(valueName, value, &updateIntervalStationaryNew)) {
1367 if (updateIntervalStationaryNew < 1) {
1368 pudError(false, "Configured %s must be at least 1", valueName);
1372 updateIntervalStationary = updateIntervalStationaryNew;
1378 * updateIntervalMoving
1381 /** The moving interval update plugin parameter (in seconds) */
1382 static unsigned long long updateIntervalMoving = PUD_UPDATE_INTERVAL_MOVING_DEFAULT;
1386 The moving interval update plugin parameter (in seconds)
1388 unsigned long long getUpdateIntervalMoving(void) {
1389 return updateIntervalMoving;
1393 Set moving interval update plugin parameter
1396 The moving interval update plugin parameter (in seconds)
1403 - true when an error is detected
1406 int setUpdateIntervalMoving(const char *value, void *data __attribute__ ((unused)),
1407 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1408 static const char * valueName = PUD_UPDATE_INTERVAL_MOVING_NAME;
1409 unsigned long long updateIntervalMovingNew;
1411 assert (value != NULL);
1413 if (!readULL(valueName, value, &updateIntervalMovingNew)) {
1417 if (updateIntervalMovingNew < 1) {
1418 pudError(false, "Configured %s must be at least 1", valueName);
1422 updateIntervalMoving = updateIntervalMovingNew;
1428 * uplinkUpdateIntervalStationary
1431 /** The uplink stationary interval update plugin parameter (in seconds) */
1432 static unsigned long long uplinkUpdateIntervalStationary = PUD_UPLINK_UPDATE_INTERVAL_STATIONARY_DEFAULT;
1436 The uplink stationary interval update plugin parameter (in seconds)
1438 unsigned long long getUplinkUpdateIntervalStationary(void) {
1439 return uplinkUpdateIntervalStationary;
1443 Set uplink stationary interval update plugin parameter
1446 The uplink stationary interval update plugin parameter (in seconds)
1453 - true when an error is detected
1456 int setUplinkUpdateIntervalStationary(const char *value, void *data __attribute__ ((unused)),
1457 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1458 static const char * valueName = PUD_UPLINK_UPDATE_INTERVAL_STATIONARY_NAME;
1459 unsigned long long uplinkUpdateIntervalStationaryNew;
1461 assert (value != NULL);
1463 if (!readULL(valueName, value, &uplinkUpdateIntervalStationaryNew)) {
1467 if (uplinkUpdateIntervalStationaryNew < 1) {
1468 pudError(false, "Configured %s must be at least 1", valueName);
1472 uplinkUpdateIntervalStationary = uplinkUpdateIntervalStationaryNew;
1478 * uplinkUpdateIntervalMoving
1481 /** The uplink moving interval update plugin parameter (in seconds) */
1482 static unsigned long long uplinkUpdateIntervalMoving = PUD_UPLINK_UPDATE_INTERVAL_MOVING_DEFAULT;
1486 The uplink moving interval update plugin parameter (in seconds)
1488 unsigned long long getUplinkUpdateIntervalMoving(void) {
1489 return uplinkUpdateIntervalMoving;
1493 Set uplink moving interval update plugin parameter
1496 The uplink moving interval update plugin parameter (in seconds)
1503 - true when an error is detected
1506 int setUplinkUpdateIntervalMoving(const char *value, void *data __attribute__ ((unused)),
1507 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1508 static const char * valueName = PUD_UPLINK_UPDATE_INTERVAL_MOVING_NAME;
1509 unsigned long long uplinkUpdateIntervalMovingNew;
1511 assert (value != NULL);
1513 if (!readULL(valueName, value, &uplinkUpdateIntervalMovingNew)) {
1517 if (uplinkUpdateIntervalMovingNew < 1) {
1518 pudError(false, "Configured %s must be at least 1", valueName);
1522 uplinkUpdateIntervalMoving = uplinkUpdateIntervalMovingNew;
1528 * movingSpeedThreshold
1531 /** The moving speed threshold plugin parameter (in kph) */
1532 static unsigned long long movingSpeedThreshold = PUD_MOVING_SPEED_THRESHOLD_DEFAULT;
1536 The moving speed threshold plugin parameter (in kph)
1538 unsigned long long getMovingSpeedThreshold(void) {
1539 return movingSpeedThreshold;
1543 Set moving speed threshold plugin parameter
1546 The moving speed threshold plugin parameter (in kph)
1553 - true when an error is detected
1556 int setMovingSpeedThreshold(const char *value, void *data __attribute__ ((unused)),
1557 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1558 static const char * valueName = PUD_MOVING_SPEED_THRESHOLD_NAME;
1559 unsigned long long movingSpeedThresholdNew;
1561 assert (value != NULL);
1563 if (!readULL(valueName, value, &movingSpeedThresholdNew)) {
1567 movingSpeedThreshold = movingSpeedThresholdNew;
1573 * movingDistanceThreshold
1576 /** The moving distance threshold plugin parameter (in meters) */
1577 static unsigned long long movingDistanceThreshold = PUD_MOVING_DISTANCE_THRESHOLD_DEFAULT;
1581 The moving distance threshold plugin parameter (in meters)
1583 unsigned long long getMovingDistanceThreshold(void) {
1584 return movingDistanceThreshold;
1588 Set moving distance threshold plugin parameter
1591 The moving distance threshold plugin parameter (in meter)
1598 - true when an error is detected
1601 int setMovingDistanceThreshold(const char *value, void *data __attribute__ ((unused)),
1602 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1603 static const char * valueName = PUD_MOVING_DISTANCE_THRESHOLD_NAME;
1604 unsigned long long movingDistanceThresholdNew;
1606 assert (value != NULL);
1608 if (!readULL(valueName, value, &movingDistanceThresholdNew)) {
1612 movingDistanceThreshold = movingDistanceThresholdNew;
1621 /* The DOP multiplier plugin parameter */
1622 static double dopMultiplier = PUD_DOP_MULTIPLIER_DEFAULT;
1626 The DOP multiplier plugin parameter
1628 double getDopMultiplier(void) {
1629 return dopMultiplier;
1633 Set DOP multiplier plugin parameter
1636 The DOP multiplier plugin parameter
1643 - true when an error is detected
1646 int setDopMultiplier(const char *value, void *data __attribute__ ((unused)),
1647 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1648 static const char * valueName = PUD_DOP_MULTIPLIER_NAME;
1649 double dopMultiplierNew;
1651 assert (value != NULL);
1653 if (!readDouble(valueName, value, &dopMultiplierNew)) {
1657 dopMultiplier = dopMultiplierNew;
1666 /** The default HDOP plugin parameter (in meters) */
1667 static unsigned long long defaultHdop = PUD_DEFAULT_HDOP_DEFAULT;
1671 The default HDOP plugin parameter (in meters)
1673 unsigned long long getDefaultHdop(void) {
1678 Set default HDOP plugin parameter
1681 The default HDOP plugin parameter (in meters)
1688 - true when an error is detected
1691 int setDefaultHdop(const char *value, void *data __attribute__ ((unused)),
1692 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1693 static const char * valueName = PUD_MOVING_DISTANCE_THRESHOLD_NAME;
1694 unsigned long long defaultHdopNew;
1696 assert (value != NULL);
1698 if (!readULL(valueName, value, &defaultHdopNew)) {
1702 defaultHdop = defaultHdopNew;
1711 /** The default VDOP plugin parameter (in meters) */
1712 static unsigned long long defaultVdop = PUD_DEFAULT_VDOP_DEFAULT;
1716 The default VDOP plugin parameter (in meters)
1718 unsigned long long getDefaultVdop(void) {
1723 Set default VDOP plugin parameter
1726 The default VDOP plugin parameter (in meters)
1733 - true when an error is detected
1736 int setDefaultVdop(const char *value, void *data __attribute__ ((unused)),
1737 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1738 static const char * valueName = PUD_MOVING_DISTANCE_THRESHOLD_NAME;
1739 unsigned long long defaultVdopNew;
1741 assert (value != NULL);
1743 if (!readULL(valueName, value, &defaultVdopNew)) {
1747 defaultVdop = defaultVdopNew;
1756 /** The depth of the average list */
1757 static unsigned long long averageDepth = PUD_AVERAGE_DEPTH_DEFAULT;
1761 The depth of the average list
1763 unsigned long long getAverageDepth(void) {
1764 return averageDepth;
1768 Set average depth plugin parameter
1771 The average depth plugin parameter
1778 - true when an error is detected
1781 int setAverageDepth(const char *value, void *data __attribute__ ((unused)),
1782 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1783 static const char * valueName = PUD_AVERAGE_DEPTH_NAME;
1784 unsigned long long averageDepthNew;
1786 assert (value != NULL);
1788 if (!readULL(valueName, value, &averageDepthNew)) {
1792 if (averageDepthNew < 1) {
1793 pudError(false, "Configured %s must be at least 1", valueName);
1797 averageDepth = averageDepthNew;
1803 * hysteresisCountToStationary
1806 /** The hysteresis count for changing state from moving to stationary */
1807 static unsigned long long hysteresisCountToStationary = PUD_HYSTERESIS_COUNT_2STAT_DEFAULT;
1811 The hysteresis count for changing state from moving to stationary
1813 unsigned long long getHysteresisCountToStationary(void) {
1814 return hysteresisCountToStationary;
1818 Set hysteresis count plugin parameter
1821 The hysteresis count plugin parameter
1828 - true when an error is detected
1831 int setHysteresisCountToStationary(const char *value, void *data __attribute__ ((unused)),
1832 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1833 static const char * valueName = PUD_HYSTERESIS_COUNT_2STAT_NAME;
1834 unsigned long long hysteresisCountNew;
1836 assert (value != NULL);
1838 if (!readULL(valueName, value, &hysteresisCountNew)) {
1842 hysteresisCountToStationary = hysteresisCountNew;
1848 * hysteresisCountToMoving
1851 /** The hysteresis count for changing state from stationary to moving */
1852 static unsigned long long hysteresisCountToMoving = PUD_HYSTERESIS_COUNT_2MOV_DEFAULT;
1856 The hysteresis count for changing state from stationary to moving
1858 unsigned long long getHysteresisCountToMoving(void) {
1859 return hysteresisCountToMoving;
1863 Set hysteresis count plugin parameter
1866 The hysteresis count plugin parameter
1873 - true when an error is detected
1876 int setHysteresisCountToMoving(const char *value, void *data __attribute__ ((unused)),
1877 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1878 static const char * valueName = PUD_HYSTERESIS_COUNT_2MOV_NAME;
1879 unsigned long long hysteresisCountNew;
1881 assert (value != NULL);
1883 if (!readULL(valueName, value, &hysteresisCountNew)) {
1887 hysteresisCountToMoving = hysteresisCountNew;
1896 /* when true then duplicate message detection is performed */
1897 static bool useDeDup = PUD_USE_DEDUP_DEFAULT;
1901 The duplicate message detection setting
1903 bool getUseDeDup(void) {
1908 Set duplicate message detection setting plugin parameter
1911 The duplicate message detection setting plugin parameter
1918 - true when an error is detected
1921 int setUseDeDup(const char *value, void *data __attribute__ ((unused)),
1922 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1923 static const char * valueName = PUD_USE_DEDUP_NAME;
1924 unsigned long long useDeDupNew;
1926 assert (value != NULL);
1928 if (!readULL(valueName, value, &useDeDupNew)) {
1932 if ((useDeDupNew != 0) && (useDeDupNew != 1)) {
1933 pudError(false, "Configured %s must be 0 (false) or 1 (true)",
1938 useDeDup = (useDeDupNew == 1);
1947 /** The hysteresis count for changing state from stationary to moving */
1948 static unsigned long long deDupDepth = PUD_DEDUP_DEPTH_DEFAULT;
1952 The hysteresis count for changing state from stationary to moving
1954 unsigned long long getDeDupDepth(void) {
1959 Set de-duplication depth plugin parameter
1962 The de-duplication depth plugin parameter
1969 - true when an error is detected
1972 int setDeDupDepth(const char *value, void *data __attribute__ ((unused)),
1973 set_plugin_parameter_addon addon __attribute__ ((unused))) {
1974 static const char * valueName = PUD_DEDUP_DEPTH_NAME;
1975 unsigned long long deDupDepthNew;
1977 assert (value != NULL);
1979 if (!readULL(valueName, value, &deDupDepthNew)) {
1983 deDupDepth = deDupDepthNew;
1992 /* when true then loopback is performed */
1993 static bool useLoopback = PUD_USE_LOOPBACK_DEFAULT;
1997 The loopback usage setting
1999 bool getUseLoopback(void) {
2004 Set loopback usage plugin parameter
2007 The loopback usage plugin parameter
2014 - true when an error is detected
2017 int setUseLoopback(const char *value, void *data __attribute__ ((unused)),
2018 set_plugin_parameter_addon addon __attribute__ ((unused))) {
2019 static const char * valueName = PUD_USE_LOOPBACK_NAME;
2020 unsigned long long useLoopbackNew;
2022 assert (value != NULL);
2024 if (!readULL(valueName, value, &useLoopbackNew)) {
2028 if ((useLoopbackNew != 0) && (useLoopbackNew != 1)) {
2029 pudError(false, "Configured %s must be 0 (false) or 1 (true)",
2034 useLoopback = (useLoopbackNew == 1);
2044 Check the configuration for consistency and validity.
2047 - true when the configuration is consistent and valid
2050 unsigned int checkConfig(void) {
2053 if (!olsr_cnf->smart_gw_active) {
2054 pudError(false, "Smart Gateway must be active");
2058 if (rxNonOlsrInterfaceCount == 0) {
2059 pudError(false, "No receive non-OLSR interfaces configured");
2063 if (txNonOlsrInterfaceCount == 0) {
2064 pudError(false, "No transmit non-OLSR interfaces configured");
2069 if (nodeIdType == PUD_NODEIDTYPE_DNS) {
2070 char name[PUD_NODEIDMAXLENGTH + 1];
2073 if (gethostname(&name[0], sizeof(name)) < 0) {
2074 pudError(true, "Could not get the host name");
2077 setNodeId(&name[0], NULL,
2078 (set_plugin_parameter_addon) {.pc = NULL});
2080 } else if ((nodeIdType != PUD_NODEIDTYPE_MAC) && (nodeIdType
2081 != PUD_NODEIDTYPE_IPV4) && (nodeIdType != PUD_NODEIDTYPE_IPV6)) {
2082 pudError(false, "No node ID set while one is required for"
2083 " node type %u", nodeIdType);
2088 if (!setupNodeIdBinaryAndValidate(nodeIdType)) {
2092 if (updateIntervalMoving > updateIntervalStationary) {
2093 pudError(false,"The update interval for moving situations must not be"
2094 " larger than that for stationary situations");
2098 if (uplinkUpdateIntervalMoving > uplinkUpdateIntervalStationary) {
2099 pudError(false,"The uplink update interval for moving situations must not be"
2100 " larger than that for stationary situations");
2104 if (getUplinkPort() == getDownlinkPort()) {
2105 pudError(false, "The uplink port and the downlink port must not be the same");
2113 Check the configuration for consistency and validity after everything has been
2117 - true when the configuration is consistent and valid
2120 unsigned int checkRunSetup(void) {
2124 /* any receive interface name that is configured but is not the name of an
2125 * actual receive interface is not a valid interface name */
2126 for (i = 0; i < rxNonOlsrInterfaceCount; i++) {
2127 unsigned char * nonOlsrInterfaceName = &rxNonOlsrInterfaceNames[i][0];
2129 TRxTxNetworkInterface * interfaceObject = getRxNetworkInterfaces();
2131 while (interfaceObject != NULL) {
2132 if (strncmp((char *) nonOlsrInterfaceName,
2133 (char *) &interfaceObject->name[0], IFNAMSIZ + 1) == 0) {
2137 interfaceObject = interfaceObject->next;
2140 pudError(false, "Configured receive non-OLSR interface %s is not"
2141 " a known interface name", nonOlsrInterfaceName);
2146 /* any transmit interface name that is configured but is not the name of an
2147 * actual transmit interface is not a valid interface name */
2148 for (i = 0; i < txNonOlsrInterfaceCount; i++) {
2149 unsigned char * nonOlsrInterfaceName = &txNonOlsrInterfaceNames[i][0];
2151 TRxTxNetworkInterface * interfaceObject = getTxNetworkInterfaces();
2153 while (interfaceObject != NULL) {
2154 if (strncmp((char *) nonOlsrInterfaceName,
2155 (char *) &interfaceObject->name[0], IFNAMSIZ + 1) == 0) {
2159 interfaceObject = interfaceObject->next;
2162 pudError(false, "Configured transmit non-OLSR interface %s is not"
2163 " a known interface name", nonOlsrInterfaceName);