Andrew Boyson / net

Dependents:   oldheating gps motorhome heating

Files at this revision

API Documentation at this revision

Comitter:
andrewboyson
Date:
Mon Jan 18 18:23:46 2021 +0000
Parent:
186:24198369b198
Child:
188:57f44b620d0e
Commit message:
Changed Ip4Address to Ip4Addr.; Moved Ip6AddrIsExternal from NdpNeedsToBeRouted.

Changed in this revision

arp/arp.c Show annotated file Show diff for this revision Revisions of this file
ip4/ip4.c Show annotated file Show diff for this revision Revisions of this file
ip4/ip4addr.c Show annotated file Show diff for this revision Revisions of this file
ip4/ip4addr.h Show annotated file Show diff for this revision Revisions of this file
ip4/udptcp4.c Show annotated file Show diff for this revision Revisions of this file
ip6/icmp/ndp/ndp.c Show annotated file Show diff for this revision Revisions of this file
ip6/icmp/ndp/ndp.h Show annotated file Show diff for this revision Revisions of this file
ip6/ip6.c Show annotated file Show diff for this revision Revisions of this file
ip6/ip6addr.c Show annotated file Show diff for this revision Revisions of this file
ip6/ip6addr.h Show annotated file Show diff for this revision Revisions of this file
resolve/ar4.c Show annotated file Show diff for this revision Revisions of this file
resolve/nr.c Show annotated file Show diff for this revision Revisions of this file
udp/dhcp/dhcp.c Show annotated file Show diff for this revision Revisions of this file
udp/dns/dnshdr.c Show annotated file Show diff for this revision Revisions of this file
udp/dns/dnsquery.c Show annotated file Show diff for this revision Revisions of this file
--- a/arp/arp.c	Sat Jan 16 18:34:32 2021 +0000
+++ b/arp/arp.c	Mon Jan 18 18:23:46 2021 +0000
@@ -34,18 +34,18 @@
         if      (ArpHdrGetOpCode(pPacket) == REQUEST)   Log ("  opCode                = REQUEST\r\n");
         else if (ArpHdrGetOpCode(pPacket) == REPLY  )   Log ("  opCode                = REPLY\r\n");
         else                                         LogF("  opCode                = %d\r\n", ArpHdrGetOpCode(pPacket));
-        Log("  senderHardwareAddress = ");               MacLog(ArpHdrPtrSenderHardwareAddr(pPacket)); Log("\r\n");
-        Log("  senderProtocolAddress = ");        Ip4AddressLog(ArpHdrGetSenderProtocolAddr(pPacket)); Log("\r\n");
-        Log("  targetHardwareAddress = ");               MacLog(ArpHdrPtrTargetHardwareAddr(pPacket)); Log("\r\n");
-        Log("  targetProtocolAddress = ");        Ip4AddressLog(ArpHdrGetTargetProtocolAddr(pPacket)); Log("\r\n");
+        Log("  senderHardwareAddress = ");          MacLog(ArpHdrPtrSenderHardwareAddr(pPacket)); Log("\r\n");
+        Log("  senderProtocolAddress = ");      Ip4AddrLog(ArpHdrGetSenderProtocolAddr(pPacket)); Log("\r\n");
+        Log("  targetHardwareAddress = ");          MacLog(ArpHdrPtrTargetHardwareAddr(pPacket)); Log("\r\n");
+        Log("  targetProtocolAddress = ");      Ip4AddrLog(ArpHdrGetTargetProtocolAddr(pPacket)); Log("\r\n");
     }
     else
     {
         Log("ARP header ");
-               MacLog(ArpHdrPtrSenderHardwareAddr(pPacket)); Log("==");
-        Ip4AddressLog(ArpHdrGetSenderProtocolAddr(pPacket)); Log(" >>> ");
-               MacLog(ArpHdrPtrTargetHardwareAddr(pPacket)); Log("==");
-        Ip4AddressLog(ArpHdrGetTargetProtocolAddr(pPacket)); Log("\r\n");
+            MacLog(ArpHdrPtrSenderHardwareAddr(pPacket)); Log("==");
+        Ip4AddrLog(ArpHdrGetSenderProtocolAddr(pPacket)); Log(" >>> ");
+            MacLog(ArpHdrPtrTargetHardwareAddr(pPacket)); Log("==");
+        Ip4AddrLog(ArpHdrGetTargetProtocolAddr(pPacket)); Log("\r\n");
         
     }
 }
--- a/ip4/ip4.c	Sat Jan 16 18:34:32 2021 +0000
+++ b/ip4/ip4.c	Mon Jan 18 18:23:46 2021 +0000
@@ -43,17 +43,17 @@
         LogF("  Protocol          "); IpProtocolLog(Ip4HdrGetProtocol(pPacket)); Log("\r\n");
         LogF("  Checksum (hex)    %04hX\r\n", Ip4HdrGetChecksum(pPacket));
         LogF("  Calculated (hex)  %04hX\r\n",  CheckSum(headerLength, pPacket));
-        LogF("  Source IP         "); Ip4AddressLog(Ip4HdrGetSrc(pPacket)); Log("\r\n");
-        LogF("  Destination IP    "); Ip4AddressLog(Ip4HdrGetDst(pPacket)); Log("\r\n");
+        LogF("  Source IP         "); Ip4AddrLog(Ip4HdrGetSrc(pPacket)); Log("\r\n");
+        LogF("  Destination IP    "); Ip4AddrLog(Ip4HdrGetDst(pPacket)); Log("\r\n");
     }
     else
     {
         Log ("IP4   header ");
         IpProtocolLog(Ip4HdrGetProtocol(pPacket));
         Log(" ");
-        Ip4AddressLog(Ip4HdrGetSrc(pPacket));
+        Ip4AddrLog(Ip4HdrGetSrc(pPacket));
         Log(" >>> ");
-        Ip4AddressLog(Ip4HdrGetDst(pPacket));
+        Ip4AddrLog(Ip4HdrGetDst(pPacket));
         Log("\r\n");
     }
 }
@@ -113,9 +113,9 @@
     {
         if (Ip4Trace)
         {
-            LogTimeF("IP4 filtered out ip "); Ip4AddressLog(dstIp);
+            LogTimeF("IP4 filtered out ip "); Ip4AddrLog(dstIp);
             Log(" from ");
-            Ip4AddressLog(srcIp);
+            Ip4AddrLog(srcIp);
             Log("\r\n");
         }
         RestartPoint = lastRestartPoint;
--- a/ip4/ip4addr.c	Sat Jan 16 18:34:32 2021 +0000
+++ b/ip4/ip4addr.c	Mon Jan 18 18:23:46 2021 +0000
@@ -9,7 +9,7 @@
 #include "ntpclient.h"
 #include "tftp.h"
 
-int Ip4AddressToString(const uint32_t ip, const int size, char* text)
+int Ip4AddrToString(const uint32_t ip, const int size, char* text)
 {
     int a0 = (ip & 0xFF000000) >> 24;
     int a1 = (ip & 0x00FF0000) >> 16;
@@ -17,7 +17,7 @@
     int a3 = (ip & 0x000000FF);
     return snprintf(text, size, "%d.%d.%d.%d", a3, a2, a1, a0); 
 }
-int Ip4AddressLog(const uint32_t ip)
+int Ip4AddrLog(const uint32_t ip)
 {
     int a0 = (ip & 0xFF000000) >> 24;
     int a1 = (ip & 0x00FF0000) >> 16;
@@ -25,7 +25,7 @@
     int a3 = (ip & 0x000000FF);
     return LogF("%d.%d.%d.%d", a3, a2, a1, a0); 
 }
-int Ip4AddressHttp(const uint32_t ip)
+int Ip4AddrHttp(const uint32_t ip)
 {
     int a0 = (ip & 0xFF000000) >> 24;
     int a1 = (ip & 0x00FF0000) >> 16;
@@ -34,14 +34,14 @@
     return HttpAddF("%d.%d.%d.%d", a3, a2, a1, a0); 
 }
 
-uint32_t Ip4AddressParse(const char* text)
+uint32_t Ip4AddrParse(const char* text)
 {
     int ints[4];
     sscanf(text, "%d.%d.%d.%d", &ints[3], &ints[2], &ints[1], &ints[0]);
     return (ints[0] << 24) + (ints[1] << 16) + (ints[2] << 8) + ints[3];
 }
 
-void Ip4AddressFromDest(const int dest, uint32_t* pDstIp)
+void Ip4AddrFromDest(const int dest, uint32_t* pDstIp)
 {
     switch (dest)
     {
@@ -61,7 +61,8 @@
             break;
     }
 }
-bool Ip4AddrIsRoutable(uint32_t ip)
+bool Ip4AddrIsExternal(uint32_t ip)
+//Logic is if it isn't local and it isn't one of the three types of broadcast then it must be external.
 {
     if ((ip & DhcpSubnetMask) == (DhcpLocalIp & DhcpSubnetMask)) return false; // Ip is same as local ip in the unmasked area
     if ( ip == (DhcpLocalIp | 0xFF000000)                      ) return false; // Ip == 192.168.0.255; '|' is lower precendence than '=='
--- a/ip4/ip4addr.h	Sat Jan 16 18:34:32 2021 +0000
+++ b/ip4/ip4addr.h	Mon Jan 18 18:23:46 2021 +0000
@@ -1,11 +1,11 @@
-extern int      Ip4AddressToString(const uint32_t ip, int size, char* text);
-extern int      Ip4AddressLog     (const uint32_t ip);
-extern int      Ip4AddressHttp    (const uint32_t ip);
-extern uint32_t Ip4AddressParse   (const char* text);
+extern int      Ip4AddrToString  (const uint32_t ip, int size, char* text);
+extern int      Ip4AddrLog       (const uint32_t ip);
+extern int      Ip4AddrHttp      (const uint32_t ip);
+extern uint32_t Ip4AddrParse     (const char* text);
 
-extern void     Ip4AddressFromDest(const int dest, uint32_t* pDstIp);
+extern void     Ip4AddrFromDest  (const int dest, uint32_t* pDstIp);
 
-extern bool     Ip4AddrIsRoutable(uint32_t ip);
+extern bool     Ip4AddrIsExternal(uint32_t ip);
 
 #define IP4_BROADCAST_ADDRESS       0xFFFFFFFF
 #define IP4_MULTICAST_ALL_HOSTS     0x010000E0
--- a/ip4/udptcp4.c	Sat Jan 16 18:34:32 2021 +0000
+++ b/ip4/udptcp4.c	Mon Jan 18 18:23:46 2021 +0000
@@ -31,7 +31,7 @@
 {    
     if (!action) return;
     
-    Ip4AddressFromDest(ActionGetDestPart(action), pDstIp);
+    Ip4AddrFromDest(ActionGetDestPart(action), pDstIp);
     *pSrcIp = DhcpLocalIp;
     
     switch (pro)
--- a/ip6/icmp/ndp/ndp.c	Sat Jan 16 18:34:32 2021 +0000
+++ b/ip6/icmp/ndp/ndp.c	Mon Jan 18 18:23:46 2021 +0000
@@ -72,17 +72,6 @@
     return false;
 }
 
-bool NdpIpNeedsToBeRouted(char* ip)
-{
-    //Check address is assigned to internet
-    if (!Ip6AddrIsGlobal(ip)) return false;
-
-    //Check it is not our own prefix
-    if (memcmp(ip, NdpGlobalPrefix, 8) == 0) return false;
-
-    return true;
-}
-
 static uint32_t decodeUint32(char* p)
 {
     uint32_t     value  = *p++;
--- a/ip6/icmp/ndp/ndp.h	Sat Jan 16 18:34:32 2021 +0000
+++ b/ip6/icmp/ndp/ndp.h	Mon Jan 18 18:23:46 2021 +0000
@@ -40,5 +40,3 @@
 extern void NdpDecodeOptions    (char* pData, int dataLength, char* srcMac, char* dstMac);
 extern void NdpLogOptionsVerbose(char* pData, int dataLength);
 extern void NdpLogOptionsQuiet  (char* pData, int dataLength);
-
-extern bool NdpIpNeedsToBeRouted(char* ip);
--- a/ip6/ip6.c	Sat Jan 16 18:34:32 2021 +0000
+++ b/ip6/ip6.c	Mon Jan 18 18:23:46 2021 +0000
@@ -110,7 +110,7 @@
     if (!action) return DO_NOTHING;
     
     int hoplimit;
-    if (NdpIpNeedsToBeRouted(dstIp))
+    if (Ip6AddrIsExternal(dstIp))
     {
         MacCopy(macRemote, NdpRouterMac); //Send to the router MAC
         hoplimit = NdpHopLimit;
@@ -158,7 +158,7 @@
         case UNICAST_DHCP:
         case UNICAST_NTP:
         case UNICAST_TFTP:
-            if (NdpIpNeedsToBeRouted(dstIp))
+            if (Ip6AddrIsExternal(dstIp))
             {
                 MacCopy(pDstMac, NdpRouterMac); //Send to the router MAC
                 hoplimit = NdpHopLimit;
--- a/ip6/ip6addr.c	Sat Jan 16 18:34:32 2021 +0000
+++ b/ip6/ip6addr.c	Mon Jan 18 18:23:46 2021 +0000
@@ -149,7 +149,15 @@
     //The top byte AND 0b11100000 (0xE0)must be 0x20
     return (p[0] & 0xE0) == 0x20;
 }
-
+bool Ip6AddrIsExternal(const char* p)
+{
+    //Logic is address must be global and not have the global prefix
+    if (!Ip6AddrIsGlobal(p)) return false;
+    if (!NdpGlobalPrefixLength) return false;
+    if (memcmp(NdpGlobalPrefix, p, NdpGlobalPrefixLength) != 0) return false; //Only 0 if the same
+    return true;
+    
+}
 bool Ip6AddrIsSolicited(const char* p)
 {
     if (*p++ != 0xff) return false;
--- a/ip6/ip6addr.h	Sat Jan 16 18:34:32 2021 +0000
+++ b/ip6/ip6addr.h	Mon Jan 18 18:23:46 2021 +0000
@@ -13,6 +13,7 @@
 extern bool Ip6AddrIsLinkLocal  (const char* p);
 extern bool Ip6AddrIsUniqueLocal(const char* p);
 extern bool Ip6AddrIsGlobal     (const char* p);
+extern bool Ip6AddrIsExternal   (const char* p);
 extern bool Ip6AddrIsSolicited  (const char* p);
 extern bool Ip6AddrIsMulticast  (const char *p);
 extern bool Ip6AddrIsSameGroup  (const char* pA, const char* pB);
--- a/resolve/ar4.c	Sat Jan 16 18:34:32 2021 +0000
+++ b/resolve/ar4.c	Mon Jan 18 18:23:46 2021 +0000
@@ -68,7 +68,7 @@
         if (Ar4Trace)
         {
             LogTimeF("AR4 Updated request for MAC of ");
-            Ip4AddressLog(ip);
+            Ip4AddrLog(ip);
             Log("\r\n");
         }
         records[i].state    = STATE_WANT;
@@ -81,7 +81,7 @@
     if (Ar4Trace)
     {
         LogTimeF("AR4 Made request for MAC of ");
-        Ip4AddressLog(ip);
+        Ip4AddrLog(ip);
         Log("\r\n");
     }
     i = getOldest();
@@ -164,7 +164,7 @@
         {
             HttpAddF("%4u ", (MsTimerCount - records[i].elapsed) / 1000 / 60);
             
-            int ipLen = Ip4AddressHttp(records[i].ip);
+            int ipLen = Ip4AddrHttp(records[i].ip);
             HttpAddFillChar(' ', 40 - ipLen);
             
             MacHttp(records[i].mac);
@@ -224,7 +224,7 @@
             if (Ar4Trace)
             {
                 LogTimeF("AR4 Send request for MAC from IP4 ");
-                Ip4AddressLog(pr->ip);
+                Ip4AddrLog(pr->ip);
                 Log("\r\n");
             }
             ArpAddressToResolve = pr->ip;
--- a/resolve/nr.c	Sat Jan 16 18:34:32 2021 +0000
+++ b/resolve/nr.c	Mon Jan 18 18:23:46 2021 +0000
@@ -83,7 +83,7 @@
 {
     switch (addrType)
     {
-        case ADDR_TYPE_A   : return Ip4AddressLog(*(uint32_t*)ip);
+        case ADDR_TYPE_A   : return Ip4AddrLog(*(uint32_t*)ip);
         case ADDR_TYPE_AAAA: return Ip6AddrLog(ip);
         default:             return LogTimeF("NR - addrLog - Unknown addrType %d\r\n", addrType);
     }
@@ -498,11 +498,11 @@
             
             if (pr->addrType == ADDR_TYPE_AAAA)
             {
-                return Ip6AddrIsGlobal((char*)pr->AAAA);
+                return Ip6AddrIsExternal((char*)pr->AAAA);
             }
             else
             {
-                return Ip4AddrIsRoutable(pr->A);
+                return Ip4AddrIsExternal(pr->A);
             }
         case TODO_ADDRESS_FROM_NAME:
             return DnsLabelIsExternal(pr->name);
--- a/udp/dhcp/dhcp.c	Sat Jan 16 18:34:32 2021 +0000
+++ b/udp/dhcp/dhcp.c	Mon Jan 18 18:23:46 2021 +0000
@@ -300,12 +300,12 @@
             {
                 _offeredIp = yiaddr;
                 readOptionServerId(sizeRx - DHCP_HEADER_LENGTH, pOptions);
-                if (DhcpTrace) { LogTime("DHCP <- offer  "); Ip4AddressLog(_offeredIp); Log(" from server "); Ip4AddressLog(_serverId); Log("\r\n"); }
+                if (DhcpTrace) { LogTime("DHCP <- offer  "); Ip4AddrLog(_offeredIp); Log(" from server "); Ip4AddrLog(_serverId); Log("\r\n"); }
                 _awaitingResponse = false;
             }
             else
             {
-                if (DhcpTrace) { LogTime("DHCP <- offer  "); Ip4AddressLog(_offeredIp); Log(" from server "); Ip4AddressLog(_serverId); Log(" ignored\r\n"); }
+                if (DhcpTrace) { LogTime("DHCP <- offer  "); Ip4AddrLog(_offeredIp); Log(" from server "); Ip4AddrLog(_serverId); Log(" ignored\r\n"); }
             }
             break;
         case DHCPACK:
@@ -314,26 +314,26 @@
                 DhcpLocalIp = yiaddr;
                 readOptions(sizeRx - DHCP_HEADER_LENGTH, pOptions);
                 DhcpServerIp = _serverId;
-                if (DhcpTrace) { LogTime("DHCP <- ack    ");   Ip4AddressLog(DhcpLocalIp); Log(" from server "); Ip4AddressLog(_serverId); Log("\r\n"); }
+                if (DhcpTrace) { LogTime("DHCP <- ack    ");   Ip4AddrLog(DhcpLocalIp); Log(" from server "); Ip4AddrLog(_serverId); Log("\r\n"); }
                 _elapsedLifeMsTimer = MsTimerCount;  //Start the life timer
                 _awaitingResponse = false;
             }
             else
             {
-                if (DhcpTrace) { LogTime("DHCP <- ack    ");   Ip4AddressLog(DhcpLocalIp); Log(" from server "); Ip4AddressLog(_serverId); Log(" ignored\r\n"); }
+                if (DhcpTrace) { LogTime("DHCP <- ack    ");   Ip4AddrLog(DhcpLocalIp); Log(" from server "); Ip4AddrLog(_serverId); Log(" ignored\r\n"); }
             }
             break;
         case DHCPNAK:
             if (_state == STATE_SELECT || _state == STATE_RENEW || _state == STATE_REBIND)
             {
                 readOptionServerId(sizeRx - DHCP_HEADER_LENGTH, pOptions);
-                if (DhcpTrace) { LogTime("DHCP <- nack   ");  Ip4AddressLog(yiaddr); Log(" from server "); Ip4AddressLog(_serverId); Log("\r\n"); }
+                if (DhcpTrace) { LogTime("DHCP <- nack   ");  Ip4AddrLog(yiaddr); Log(" from server "); Ip4AddrLog(_serverId); Log("\r\n"); }
                 clearAll();
                 _awaitingResponse = false;
             }
             else
             {
-                if (DhcpTrace) { LogTime("DHCP <- nack   ");  Ip4AddressLog(yiaddr); Log(" from server "); Ip4AddressLog(_serverId); Log(" ignored\r\n"); }
+                if (DhcpTrace) { LogTime("DHCP <- nack   ");  Ip4AddrLog(yiaddr); Log(" from server "); Ip4AddrLog(_serverId); Log(" ignored\r\n"); }
             }
             break;
         default:
@@ -425,7 +425,7 @@
             break;
             
         case STATE_SELECT:
-            if (DhcpTrace) { LogTimeF("DHCP -> select "); Ip4AddressLog(_offeredIp); Log(" from server "); Ip4AddressLog(_serverId); Log("\r\n"); }
+            if (DhcpTrace) { LogTimeF("DHCP -> select "); Ip4AddrLog(_offeredIp); Log(" from server "); Ip4AddrLog(_serverId); Log("\r\n"); }
             type = DHCPREQUEST;
             ciaddr = 0;
             requestedIp = _offeredIp;
@@ -434,11 +434,11 @@
             break;
             
         case STATE_BOUND:
-            if (DhcpTrace) { LogTimeF("DHCP -- bound  "); Ip4AddressLog(DhcpLocalIp); Log("\r\n"); }
+            if (DhcpTrace) { LogTimeF("DHCP -- bound  "); Ip4AddrLog(DhcpLocalIp); Log("\r\n"); }
             return DO_NOTHING;
             
         case STATE_RENEW:
-            if (DhcpTrace) { LogTimeF("DHCP -> renew (T1) "); Ip4AddressLog(DhcpLocalIp); Log("\r\n"); }
+            if (DhcpTrace) { LogTimeF("DHCP -> renew (T1) "); Ip4AddrLog(DhcpLocalIp); Log("\r\n"); }
             type = DHCPREQUEST;
             ciaddr = DhcpLocalIp;
             requestedIp = 0;
@@ -447,7 +447,7 @@
             break;
             
         case STATE_REBIND:
-            if (DhcpTrace) { LogTimeF("DHCP -> rebind (T2) "); Ip4AddressLog(DhcpLocalIp); Log("\r\n"); }
+            if (DhcpTrace) { LogTimeF("DHCP -> rebind (T2) "); Ip4AddrLog(DhcpLocalIp); Log("\r\n"); }
             type = DHCPREQUEST;
             ciaddr = DhcpLocalIp;
             requestedIp = 0;
@@ -456,7 +456,7 @@
             break;
             
         case STATE_EXPIRED:
-            if (DhcpTrace) { LogTimeF("DHCP -- expired "); Ip4AddressLog(DhcpLocalIp); Log("\r\n"); }
+            if (DhcpTrace) { LogTimeF("DHCP -- expired "); Ip4AddrLog(DhcpLocalIp); Log("\r\n"); }
             clearAll();
             return DO_NOTHING;
             
--- a/udp/dns/dnshdr.c	Sat Jan 16 18:34:32 2021 +0000
+++ b/udp/dns/dnshdr.c	Mon Jan 18 18:23:46 2021 +0000
@@ -84,7 +84,7 @@
 }
 static void logRecordA(int len, char* p)
 {
-    if (len == 4) Ip4AddressLog(*(uint32_t*)p);
+    if (len == 4) Ip4AddrLog(*(uint32_t*)p);
     else          LogF("expected 4 bytes but had %d", len);
 }
 static void logRecordAAAA(int len, char* p)
--- a/udp/dns/dnsquery.c	Sat Jan 16 18:34:32 2021 +0000
+++ b/udp/dns/dnsquery.c	Mon Jan 18 18:23:46 2021 +0000
@@ -41,8 +41,8 @@
         LogTimeF("DnsQuery reaped ongoing request for record type ");
         DnsRecordTypeLog(_RecordType);
         if (DnsQueryName[0]) { LogF(" name '%s'", DnsQueryName); }
-        if (DnsQueryIp4)     { Log(" address "); Ip4AddressLog(DnsQueryIp4); }
-        if (DnsQueryIp6[0])  { Log(" address "); Ip6AddrLog   (DnsQueryIp6); }
+        if (DnsQueryIp4)     { Log(" address "); Ip4AddrLog(DnsQueryIp4); }
+        if (DnsQueryIp6[0])  { Log(" address "); Ip6AddrLog(DnsQueryIp6); }
         Log(" using ");
         DnsProtocolLog(_DnsProtocol);
         Log(" over ");
@@ -137,7 +137,7 @@
     Log(" ");
     if (DnsQueryIp4) //Reverse
     {
-        Ip4AddressLog(DnsQueryIp4);
+        Ip4AddrLog(DnsQueryIp4);
     }
     else if (DnsQueryIp6[0])
     {