PUD: also setup MAC address in cache
authorFerry Huberts <ferry.huberts@pelagic.nl>
Thu, 2 Feb 2012 11:39:08 +0000 (12:39 +0100)
committerFerry Huberts <ferry.huberts@pelagic.nl>
Tue, 14 Feb 2012 13:32:58 +0000 (14:32 +0100)
Signed-off-by: Ferry Huberts <f.huberts@mindef.nl>
lib/pud/src/configuration.c

index d2e2a5f..80df175 100644 (file)
@@ -199,6 +199,7 @@ typedef union _nodeIdBinaryType {
                unsigned long long longValue;
                unsigned char stringValue[PUD_NODEIDMAXLENGTH + 1];
                union olsr_ip_addr ip;
+               unsigned char mac[PUD_NODEIDTYPE_MAC_BYTES];
 } nodeIdBinaryType;
 
 /** The nodeId buffer */
@@ -285,6 +286,31 @@ int setNodeId(const char *value, void *data __attribute__ ((unused)), set_plugin
  * nodeId Validation
  */
 
+/**
+ Validate whether the configured nodeId is valid w.r.t. the configured
+ nodeIdType, for types that are MAC addresses
+
+ @return
+ - true when ok
+ - false on failure
+ */
+static bool setupNodeIdBinaryMAC(void) {
+       unsigned char * mac = getMainIpMacAddress();
+       if (!mac) {
+               return false;
+       }
+
+       memcpy(&nodeIdBinary.mac, mac, PUD_NODEIDTYPE_MAC_BYTES);
+       nodeIdBinarySet = true;
+
+       if (setupNodeIdBinaryBufferForOlsrCache(mac, PUD_NODEIDTYPE_MAC_BYTES)) {
+               return true;
+       }
+
+       pudError(false, "%s value \"MAC address\" could not be setup", PUD_NODE_ID_NAME);
+       return false;
+}
+
 /**
  Validate whether the configured nodeId is valid w.r.t. the configured
  nodeIdType, for types that fit in an unsigned long long (64 bits)
@@ -373,8 +399,7 @@ static bool setupNodeIdBinaryString(void) {
 static bool setupNodeIdBinaryAndValidate(NodeIdType nodeIdTypeNumber) {
        switch (nodeIdTypeNumber) {
                case PUD_NODEIDTYPE_MAC: /* hardware address */
-                       /* explicit return: configured nodeId is not relevant */
-                       return true;
+                       return setupNodeIdBinaryMAC();
 
                case PUD_NODEIDTYPE_MSISDN: /* an MSISDN number */
                        return setupNodeIdBinaryLongLong(0LL, 999999999999999LL,