Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: oldheating gps motorhome heating
Revision 15:6ca6778168b1, committed 2017-05-09
- Comitter:
- andrewboyson
- Date:
- Tue May 09 15:39:03 2017 +0000
- Parent:
- 14:e75a59c1123d
- Child:
- 16:f416ef583c89
- Commit message:
- Tidied up dns debug output
Changed in this revision
--- a/eth/eth.h Fri May 05 17:44:16 2017 +0000 +++ b/eth/eth.h Tue May 09 15:39:03 2017 +0000 @@ -1,3 +1,5 @@ +#include "mbed.h" + extern uint16_t EthProtocol; extern void EthProtocolToString(uint16_t protocol, int size, char* text); extern int EthHandlePacket (void* pPacket, int* pSize);
--- a/ip4/ip4.cpp Fri May 05 17:44:16 2017 +0000
+++ b/ip4/ip4.cpp Tue May 09 15:39:03 2017 +0000
@@ -150,10 +150,23 @@
readHeader(pHeader);
bool isMe = Ip4Dst == DhcpLocalIp;
+ bool isLocalBroadcast = Ip4Dst == DhcpLocalIp | 0xFF000000;
bool isBroadcast = Ip4Dst == IP4_BROADCAST_ADDRESS;
bool isMulticast = (Ip4Dst & 0xE0) == 0xE0; //224.x.x.x == 1110 0000 == E0.xx.xx.xx == xx.xx.xx.E0 in little endian
- if (!isMe && !isBroadcast && !isMulticast) return DO_NOTHING;
+ bool doIt = isMe || isLocalBroadcast || isBroadcast || isMulticast;
+ if (!doIt)
+ {
+ if (DEBUG)
+ {
+ char text[20];
+ Ip4AddressToString(Ip4Dst, sizeof(text), text);
+ LogTimeF("IP4 filtered out ip %s ", text);
+ Ip4AddressToString(Ip4Src, sizeof(text), text);
+ LogF("from %s \r\n", text);
+ }
+ return DO_NOTHING;
+ }
ArAdd4(pSrcMac, Ip4Src);
--- a/ip4/udptcp4.cpp Fri May 05 17:44:16 2017 +0000 +++ b/ip4/udptcp4.cpp Tue May 09 15:39:03 2017 +0000 @@ -2,6 +2,8 @@ #include "log.h" #include "net.h" #include "dhcp.h" +#include "eth.h" +#include "ip.h" #include "ip4.h" #include "tcp.h" #include "udp.h"
--- a/ip6/ip6.cpp Fri May 05 17:44:16 2017 +0000
+++ b/ip6/ip6.cpp Tue May 09 15:39:03 2017 +0000
@@ -167,7 +167,7 @@
struct header * pHeader = (header*)pPacket;
readHeader(pHeader);
- bool isMe = getIsSame(Ip6Dst, SlaacLinkLocalIp);
+ bool isMe = getIsSame(Ip6Dst, SlaacLinkLocalIp) || getIsSame(Ip6Dst, SlaacGlobalIp);
bool isMulticast = Ip6Dst[0] == 0xFF;
bool isSolicited = getIsSolicited(Ip6Dst);
bool isGroup = isSolicited && getIsSameGroup(Ip6Dst, SlaacLinkLocalIp);
@@ -176,9 +176,14 @@
if (!doIt)
{
- char text[100];
- Ip6AddressToString(Ip6Dst, sizeof(text), text);
- LogTimeF("IP6 filtered out ip %s \r\n", text);
+ if (DEBUG)
+ {
+ char text[100];
+ Ip6AddressToString(Ip6Dst, sizeof(text), text);
+ LogTimeF("IP6 filtered out ip %s ", text);
+ Ip6AddressToString(Ip6Src, sizeof(text), text);
+ LogF("from %s \r\n", text);
+ }
return DO_NOTHING;
}
--- a/ip6/ndp.cpp Fri May 05 17:44:16 2017 +0000
+++ b/ip6/ndp.cpp Tue May 09 15:39:03 2017 +0000
@@ -1,8 +1,9 @@
-#include "mbed.h"
-#include "log.h"
-#include "net.h"
-#include "ip6.h"
-#include "mac.h"
+#include "mbed.h"
+#include "log.h"
+#include "net.h"
+#include "ip6.h"
+#include "mac.h"
+#include "slaac.h"
#define DEBUG_RA false
#define DEBUG_NS false
@@ -54,6 +55,7 @@
p += 4; //Skip gracefully past the Reserved2 field
memcpy(NdpPrefix, p, 16);
+ SlaacMakeGlobal(NdpPrefix);
if (DEBUG_OP)
@@ -61,7 +63,7 @@
char text[100];
LogF(" Prefix length %d\r\n", NdpPrefixLength);
LogF(" Prefix LA %X\r\n", prefixLA);
- NetIp6AddressToString(NdpPrefix, sizeof(text), text);
+ Ip6AddressToString(NdpPrefix, sizeof(text), text);
LogF(" Prefix %s\r\n", text);
}
}
@@ -76,7 +78,7 @@
if (DEBUG_OP)
{
char text[100];
- NetMacToString(srcMAC, sizeof(text), text);
+ MacToString(srcMAC, sizeof(text), text);
LogF(" Src MAC %s\r\n", text);
}
break;
@@ -85,7 +87,7 @@
if (DEBUG_OP)
{
char text[100];
- NetMacToString(dstMAC, sizeof(text), text);
+ MacToString(dstMAC, sizeof(text), text);
LogF(" Dst MAC %s\r\n", text);
}
break;
@@ -116,7 +118,7 @@
{
LogF(" DNS lifetime %u\r\n", dnsLifetime);
char text[100];
- NetIp6AddressToString(NdpDnsServer, sizeof(text), text);
+ Ip6AddressToString(NdpDnsServer, sizeof(text), text);
LogF(" DNS Server %s\r\n", text);
}
break;
@@ -178,7 +180,7 @@
char text[100];
LogTimeF("NDP neighbour solicit\r\n");
LogF(" Size %d\r\n", *pSize);
- NetIp6AddressToString(pHeader->target, sizeof(text), text);
+ Ip6AddressToString(pHeader->target, sizeof(text), text);
LogF(" Target %s\r\n", text);
}
char* p = pData;
@@ -214,6 +216,7 @@
if (DEBUG_RA) LogTimeF("Router advertisement has expired\r\n");
routerAdvertisementLifetime = 0;
memset(NdpPrefix , 0, 16);
+ SlaacMakeGlobal(NdpPrefix);
memset(NdpDnsServer, 0, 16);
}
--- a/ip6/slaac.cpp Fri May 05 17:44:16 2017 +0000
+++ b/ip6/slaac.cpp Tue May 09 15:39:03 2017 +0000
@@ -1,7 +1,23 @@
-#include "mac.h"
+#include "mbed.h"
+#include "mac.h"
char SlaacLinkLocalIp[16];
+char SlaacGlobalIp[16];
+void SlaacMakeGlobal(char* pPrefix)
+{
+ memcpy(SlaacGlobalIp, pPrefix, 8);
+ char* p = SlaacGlobalIp + 8;
+ *p++ = MacLocal[0] | 0x02; //Modified EUI-64
+ *p++ = MacLocal[1];
+ *p++ = MacLocal[2];
+ *p++ = 0xFF;
+ *p++ = 0xFE;
+ *p++ = MacLocal[3];
+ *p++ = MacLocal[4];
+ *p++ = MacLocal[5];
+
+}
void SlaacInit()
{
char* p = SlaacLinkLocalIp;
--- a/ip6/slaac.h Fri May 05 17:44:16 2017 +0000 +++ b/ip6/slaac.h Tue May 09 15:39:03 2017 +0000 @@ -1,3 +1,5 @@ extern char SlaacLinkLocalIp[]; +extern char SlaacGlobalIp[]; +extern void SlaacMakeGlobal(char* pPrefix); extern void SlaacInit(); \ No newline at end of file
--- a/net.h Fri May 05 17:44:16 2017 +0000
+++ b/net.h Tue May 09 15:39:03 2017 +0000
@@ -1,3 +1,5 @@
+#pragma once
+#include "mbed.h"
extern int16_t NetToHost16(int16_t n);
extern int32_t NetToHost32(int32_t n);
@@ -10,6 +12,29 @@
extern char* NetName;
+struct NetAction
+{
+ char dst; //none, reply, specified, dns, dhcp, all nodes, all routers, mdns, llmnr,
+ char cst; //none, unicast, multicast, broadcast, solicited
+ char pro; //none, IPv4 or IPv6
+ char dbg; //false or true
+};
+
+#define NET_DO_NOTHING 0
+#define NET_REPLY 1
+#define NET_SPECIFIED 2
+#define NET_ALL_NODES 3
+#define NET_ALL_ROUTERS 4
+#define NET_DNS 5
+#define NET_MDNS 6
+#define NET_LLMNR 7
+#define NET_DHCP 8
+
+#define NET_UNICAST 1
+#define NET_MULTICAST 2
+#define NET_SOLICITED 3
+#define NET_BROADCAST 4
+
#define DO_NOTHING 0
#define UNICAST 1
--- a/udp/dns/dns.cpp Fri May 05 17:44:16 2017 +0000
+++ b/udp/dns/dns.cpp Tue May 09 15:39:03 2017 +0000
@@ -23,6 +23,8 @@
case DNS_RECORD_A: strncpy (text, "A", size); break;
case DNS_RECORD_AAAA: strncpy (text, "AAAA", size); break;
case DNS_RECORD_PTR: strncpy (text, "PTR", size); break;
+ case DNS_RECORD_TXT: strncpy (text, "TXT", size); break;
+ case DNS_RECORD_SRV: strncpy (text, "SRV", size); break;
default: snprintf(text, size, "%d", recordtype); break;
}
}
@@ -39,15 +41,11 @@
int action;
if (DnsHdrIsReply)
{
- Led1 = 1;
action = DnsReplyHandle(dnsProtocol, pSize);
- Led1 = 0;
}
else
{
- Led2 = 1;
action = DnsServerHandleQuery(dnsProtocol, pSize);
- Led2 = 0;
}
return action;
}
--- a/udp/dns/dns.h Fri May 05 17:44:16 2017 +0000 +++ b/udp/dns/dns.h Tue May 09 15:39:03 2017 +0000 @@ -22,3 +22,5 @@ #define DNS_RECORD_A 1 #define DNS_RECORD_PTR 12 #define DNS_RECORD_AAAA 28 +#define DNS_RECORD_TXT 16 +#define DNS_RECORD_SRV 33
--- a/udp/dns/dnshdr.cpp Fri May 05 17:44:16 2017 +0000
+++ b/udp/dns/dnshdr.cpp Tue May 09 15:39:03 2017 +0000
@@ -81,37 +81,38 @@
void DnsHdrLog(char* title, int protocol)
{
char text[100];
- LogTimeF("DNS %s\r\n", title);
+ DnsProtocolToString(protocol, sizeof(text), text);
+ LogTimeF("%s %s\r\n", text, title);
if (EthProtocol == IPV6)
{
Ip6AddressToString(Ip6Src, sizeof(text), text);
- LogF(" Src IP %s\r\n", text);
+ LogF(" IP: src %s;", text);
Ip6AddressToString(Ip6Dst, sizeof(text), text);
- LogF(" Dst IP %s\r\n", text);
+ LogF(" dst %s\r\n", text);
}
else if (EthProtocol == IPV4)
{
Ip4AddressToString(Ip4Src, sizeof(text), text);
- LogF(" Src port %s\r\n", text);
+ LogF(" IP: src %s;", text);
Ip4AddressToString(Ip4Dst, sizeof(text), text);
- LogF(" Dst port %s\r\n", text);
+ LogF(" dst %s\r\n", text);
}
else
{
LogF(" Unknown eth protocol %04hX\r\n", EthProtocol);
}
- LogF(" Source %hu\r\n", UdpSrcPort);
- LogF(" Dest %hu\r\n", UdpDstPort);
-
- DnsProtocolToString(protocol, sizeof(text), text);
- LogF(" Protocol %s\r\n", text);
+ LogF(" Port: src %5hu; dst %5hu\r\n", UdpSrcPort, UdpDstPort);
LogF(" Ident %hd\r\n", DnsHdrId);
- if (DnsHdrIsReply) LogF(" Is reply\r\n");
- else LogF(" Is request\r\n");
- if (DnsHdrIsAuthoritative) LogF(" Is authoritative reply\r\n");
- else LogF(" Is not authoritative reply\r\n");
- if (DnsHdrIsRecursiveQuery) LogF(" Is recursive query\r\n");
- else LogF(" Is non recursive query\r\n");
+ if (DnsHdrIsReply)
+ {
+ if (DnsHdrIsAuthoritative) LogF(" Authoritative reply\r\n");
+ else LogF(" Non authoritative reply\r\n");
+ }
+ else
+ {
+ if (DnsHdrIsRecursiveQuery) LogF(" Recursive query\r\n");
+ else LogF(" Non recursive query\r\n");
+ }
LogF(" qd, an, ns, ar %hu, %hu, %hu, %hu\r\n", DnsHdrQdcount, DnsHdrAncount, DnsHdrNscount, DnsHdrArcount);
}
--- a/udp/dns/dnshdr.h Fri May 05 17:44:16 2017 +0000 +++ b/udp/dns/dnshdr.h Tue May 09 15:39:03 2017 +0000 @@ -17,4 +17,4 @@ extern void DnsHdrSetup(void* pPacket); extern void DnsHdrRead (); extern void DnsHdrWrite(); -extern void DnsHdrLog (char* title, int protocol); +extern void DnsHdrLog (char* title, int ipProtocol);
--- a/udp/dns/dnsquery.cpp Fri May 05 17:44:16 2017 +0000
+++ b/udp/dns/dnsquery.cpp Tue May 09 15:39:03 2017 +0000
@@ -118,13 +118,10 @@
if (DEBUG)
{
char text[20];
+ DnsProtocolToString(DnsQueryProtocol, sizeof(text), text);
+ LogTimeF("%s sent request for ", text);
Ip4AddressToString(DnsQueryIp4, sizeof(text), text);
- switch (DnsQueryProtocol)
- {
- case DNS_PROTOCOL_UDNS: LogTimeF("DNS sent DNS reverse request for %s\r\n", text); break;
- case DNS_PROTOCOL_MDNS: LogTimeF("DNS sent MDNS reverse request for %s\r\n", text); break;
- case DNS_PROTOCOL_LLMNR: LogTimeF("DNS sent LLMNR reverse request for %s\r\n", text); break;
- }
+ LogF("%s\r\n", text);
}
DnsNameEncodeIp4(DnsQueryIp4, &p);
*p++ = 0;
@@ -135,13 +132,10 @@
if (DEBUG)
{
char text[60];
+ DnsProtocolToString(DnsQueryProtocol, sizeof(text), text);
+ LogTimeF("%s sent request for ", text);
Ip6AddressToString(DnsQueryIp6, sizeof(text), text);
- switch (DnsQueryProtocol)
- {
- case DNS_PROTOCOL_UDNS: LogTimeF("DNS sent DNS reverse request for %s\r\n", text); break;
- case DNS_PROTOCOL_MDNS: LogTimeF("DNS sent MDNS reverse request for %s\r\n", text); break;
- case DNS_PROTOCOL_LLMNR: LogTimeF("DNS sent LLMNR reverse request for %s\r\n", text); break;
- }
+ LogF("%s\r\n", text);
}
DnsNameEncodeIp6(DnsQueryIp6, &p);
*p++ = 0;
--- a/udp/dns/dnsreply.cpp Fri May 05 17:44:16 2017 +0000
+++ b/udp/dns/dnsreply.cpp Tue May 09 15:39:03 2017 +0000
@@ -83,33 +83,18 @@
case DNS_RECORD_A:
case DNS_RECORD_AAAA:
case DNS_RECORD_PTR:
+ case DNS_RECORD_SRV:
+ case DNS_RECORD_TXT:
break;
default:
LogTimeF("DnsReply readAnswer unrecognised record type %d\r\n", recordType);
- return; }
+ return;
+ }
DnsNameDecode (recordNameOffset, sizeof(DnsReplyRecordName), DnsReplyRecordName);
DnsNameDecodeIp4(recordNameOffset, &DnsReplyRecordNameAsIp4);
DnsNameDecodeIp6(recordNameOffset, DnsReplyRecordNameAsIp6);
- if (DEBUG)
- {
- LogF(" record name as string %s\r\n", DnsReplyRecordName);
- char text[100];
- if (DnsReplyRecordNameAsIp4)
- {
- Ip4AddressToString(DnsReplyRecordNameAsIp4, sizeof(text), text);
- LogF(" record name as ip4 %s\r\n", text);
- }
- if (DnsReplyRecordNameAsIp6[0])
- {
- Ip6AddressToString(DnsReplyRecordNameAsIp6, sizeof(text), text);
- LogF(" record name as ip6 %s\r\n", text);
- }
- DnsRecordTypeToString(recordType, sizeof(text), text);
- LogF(" record type %s\r\n", text);
- LogF(" record data length %d bytes\r\n", recordDataLength);
- }
-
+
switch (recordType)
{
case DNS_RECORD_A:
@@ -137,21 +122,38 @@
DnsNameDecode(DnsNameIndexFromPointer(pRecordData), sizeof(DnsReplyName), DnsReplyName);
break;
}
+
if (DEBUG)
{
+ LogF(" answer: %s", DnsReplyRecordName);
char text[100];
+ if (DnsReplyRecordNameAsIp4)
+ {
+ Ip4AddressToString(DnsReplyRecordNameAsIp4, sizeof(text), text);
+ LogF(" (%s)", text);
+ }
+ if (DnsReplyRecordNameAsIp6[0])
+ {
+ Ip6AddressToString(DnsReplyRecordNameAsIp6, sizeof(text), text);
+ LogF(" (%s)", text);
+ }
+ LogF(" == ");
switch (recordType)
{
case DNS_RECORD_A:
Ip4AddressToString(DnsReplyIp4, sizeof(text), text);
- LogF(" ip4 %s\r\n", text);
+ LogF("%s\r\n", text);
break;
case DNS_RECORD_AAAA:
Ip6AddressToString(DnsReplyIp6, sizeof(text), text);
- LogF(" ip6 %s\r\n", text);
+ LogF("%s\r\n", text);
break;
case DNS_RECORD_PTR:
- LogF(" ptr %s\r\n", DnsReplyName);
+ LogF("%s\r\n", DnsReplyName);
+ break;
+ default:
+ DnsRecordTypeToString(recordType, sizeof(text), text);
+ LogF("%d bytes of %s\r\n", recordDataLength, text);
break;
}
}
--- a/udp/udp.cpp Fri May 05 17:44:16 2017 +0000
+++ b/udp/udp.cpp Tue May 09 15:39:03 2017 +0000
@@ -5,13 +5,14 @@
#include "ntp.h"
#include "dhcp.h"
#include "dns.h"
+#include "eth.h"
#include "ip4.h"
#include "ip6.h"
#include "slaac.h"
#include "ndp.h"
#include "io.h"
-#define UNKNOWN false
+#define UNKNOWN true
#define HEADER_SIZE 8
__packed struct header
@@ -35,12 +36,17 @@
case NTP_PORT: return NtpHandleRequest ( pDataLength, pData); // 123
case DNS_UNICAST_CLIENT_PORT: return DnsHandlePacketReceived(DNS_PROTOCOL_UDNS, pDataLength, pData); //53053
case DNS_MDNS_PORT: return DnsHandlePacketReceived(DNS_PROTOCOL_MDNS, pDataLength, pData); // 5353
- case DNS_LLMNR_CLIENT_PORT: return DnsHandlePacketReceived(DNS_PROTOCOL_LLMNR, pDataLength, pData); // 5355
+ case DNS_LLMNR_CLIENT_PORT: return DnsHandlePacketReceived(DNS_PROTOCOL_LLMNR, pDataLength, pData); //53055
+ case DNS_LLMNR_SERVER_PORT: return DnsHandlePacketReceived(DNS_PROTOCOL_LLMNR, pDataLength, pData); // 5355
//Quietly drop these
case DHCP_SERVER_PORT: //67
+ case 137: //NETBIOS name service
+ case 138: //NETBIOS datagram service
+ case 139: //NETBIOS session service
case 1900: //SSDP Simple Service Discovery Protocol (uPnP)
case 3076: //Call of Duty - Xbox
+ case 9956: //Alljoyn part af Allseen IoT services
case 9997: //VLC
case 9998: //VLC
case 9999: //VLC