Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to exclude DNS features. #424

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/EtherCard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ uint8_t EtherCard::netmask[IP_LEN]; // subnet mask
uint8_t EtherCard::broadcastip[IP_LEN]; // broadcast address
uint8_t EtherCard::gwip[IP_LEN]; // gateway
uint8_t EtherCard::dhcpip[IP_LEN]; // dhcp server
#if ETHERCARD_DNS
uint8_t EtherCard::dnsip[IP_LEN]; // dns server
#endif
uint8_t EtherCard::hisip[IP_LEN]; // ip address of remote host
uint16_t EtherCard::hisport = HTTP_PORT; // tcp port to browse to
bool EtherCard::using_dhcp = false;
Expand Down
6 changes: 6 additions & 0 deletions src/EtherCard.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@
*/
#define ETHERCARD_DHCP 1

/** Enable DNS.
* Setting this to zero disables the use of DNS; if a program uses DNS it will
* not compile. Saves 6 bytes SRAM, 110 bytes flash, and some packet processing overhead.
*/
#define ETHERCARD_DNS 1

/** Enable client connections.
* Setting this to zero means that the program cannot issue TCP client requests
* anymore. Compilation will still work but the request will never be
Expand Down
2 changes: 2 additions & 0 deletions src/dns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//
// 2010-05-20 <[email protected]>

#if ETHERCARD_DNS
#include "EtherCard.h"
#include "net.h"

Expand Down Expand Up @@ -118,3 +119,4 @@ bool EtherCard::dnsLookup (const char* name, bool fromRam) {

return true;
}
#endif
8 changes: 8 additions & 0 deletions src/tcpip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ static const char *client_urlbuf_var; // Pointer to c-string filename part of HT
static const char *client_hoststr; // Pointer to c-string hostname of current HTTP request
static void (*icmp_cb)(uint8_t *ip); // Pointer to callback function for ICMP ECHO response handler (triggers when localhost receives ping response (pong))
static uint8_t destmacaddr[ETH_LEN]; // storing both dns server and destination mac addresses, but at different times because both are never needed at same time.
#if ETHERCARD_DNS
static boolean waiting_for_dns_mac = false; //might be better to use bit flags and bitmask operations for these conditions
static boolean has_dns_mac = false;
#endif
static boolean waiting_for_dest_mac = false;
static boolean has_dest_mac = false;
static uint8_t gwmacaddr[ETH_LEN]; // Hardware (MAC) address of gateway router
Expand Down Expand Up @@ -459,11 +461,13 @@ uint8_t EtherCard::clientWaitingGw () {
return !(waitgwmac & WGW_HAVE_GW_MAC);
}

#if ETHERCARD_DNS
uint8_t EtherCard::clientWaitingDns () {
if(is_lan(myip, dnsip))
return !has_dns_mac;
return !(waitgwmac & WGW_HAVE_GW_MAC);
}
#endif

static uint8_t client_store_mac(uint8_t *source_ip, uint8_t *mac) {
if (memcmp(gPB + ETH_ARP_SRC_IP_P, source_ip, IP_LEN) != 0)
Expand Down Expand Up @@ -697,11 +701,13 @@ uint16_t EtherCard::packetLoop (uint16_t plen) {
}
#endif

#if ETHERCARD_DNS
//!@todo this is trying to find mac only once. Need some timeout to make another call if first one doesn't succeed.
if(is_lan(myip, dnsip) && !has_dns_mac && !waiting_for_dns_mac) {
client_arp_whohas(dnsip);
waiting_for_dns_mac = true;
}
#endif

//!@todo this is trying to find mac only once. Need some timeout to make another call if first one doesn't succeed.
if(is_lan(myip, hisip) && !has_dest_mac && !waiting_for_dest_mac) {
Expand All @@ -718,10 +724,12 @@ uint16_t EtherCard::packetLoop (uint16_t plen) {
make_arp_answer_from_request();
if (waitgwmac & WGW_ACCEPT_ARP_REPLY && (gPB[ETH_ARP_OPCODE_L_P]==ETH_ARP_OPCODE_REPLY_L_V) && client_store_mac(gwip, gwmacaddr))
waitgwmac = WGW_HAVE_GW_MAC;
#if ETHERCARD_DNS
if (!has_dns_mac && waiting_for_dns_mac && client_store_mac(dnsip, destmacaddr)) {
has_dns_mac = true;
waiting_for_dns_mac = false;
}
#endif
if (!has_dest_mac && waiting_for_dest_mac && client_store_mac(hisip, destmacaddr)) {
has_dest_mac = true;
waiting_for_dest_mac = false;
Expand Down