Skip to content

Commit

Permalink
Allow partial cache as as answer
Browse files Browse the repository at this point in the history
When `CacheParallel` is on, there could be too many, exceeding buffer size.
  • Loading branch information
lifenjoiner committed Sep 23, 2024
1 parent 154aa66 commit 2c5beac
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 15 deletions.
24 changes: 9 additions & 15 deletions dnscache.c
Original file line number Diff line number Diff line change
Expand Up @@ -690,11 +690,10 @@ static int DNSCache_GetRawRecordsFromCache(__in const char *Name,
break;
}

Ret = 0;

if( Node->TTL != 0 )
{
char *CacheItr;
int iRet;

/* TTL*/
if( IgnoreTTL == TRUE )
Expand All @@ -708,24 +707,19 @@ static int DNSCache_GetRawRecordsFromCache(__in const char *Name,
CacheItr = MapStart + Node->Offset + 1 + KeyLength + 1;

/* Now the data position */
switch( Type )
iRet = g->Generate(g, Name, Type, Klass, CacheItr,
MapStart + Node->Offset + Node->UsedLength - CacheItr,
NewTTL
);
if( iRet != 0 )
{
case DNS_TYPE_CNAME:
if( g->CName(g, Name, CacheItr, NewTTL) != 0 )
{
return -1;
}
break;

default:
if( g->RawData(g, Name, Type, Klass, CacheItr,
Node->UsedLength - 1 - KeyLength - 1,
NewTTL) != 0 )
if( Ret == 0 )
{
return -256;
INFO("Partial cache used for: %s\n", Name_Type_Class);
}
break;
}
Ret = iRet;
}
} while ( TRUE );

Expand Down
31 changes: 31 additions & 0 deletions dnsgenerator.c
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,36 @@ static int StripedLength(const char *Origin, int OriginLength)
}
}

static int DnsGenerator_Generate(DnsGenerator *g,
const char *Name,
DNSRecordType Type,
DNSRecordClass Klass,
const char *Data,
int DataLength,
int Ttl
)
{
int Ret = -256;

switch( Type )
{
case DNS_TYPE_CNAME:
Ret = g->CName(g, Name, Data, Ttl);
break;

case DNS_TYPE_A:
case DNS_TYPE_AAAA:
case DNS_TYPE_HTTPS:
Ret = g->RawData(g, Name, Type, Klass, Data, DataLength, Ttl);
break;

default:
break;
}

return Ret;
}

int DnsGenerator_Init(DnsGenerator *g,
char *Buffer, /* generate to here */
int BufferLength,
Expand Down Expand Up @@ -861,6 +891,7 @@ int DnsGenerator_Init(DnsGenerator *g,
g->AAAA = DnsGenerator_AAAA;
g->EDns = DnsGenerator_EDns;
g->RawData = DnsGenerator_RawData;
g->Generate = DnsGenerator_Generate;

return 0;
}
9 changes: 9 additions & 0 deletions dnsgenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ struct _DnsGenerator {
int DataLength,
int Ttl
);

int (*Generate)(DnsGenerator *g,
const char *Name,
DNSRecordType Type,
DNSRecordClass Klass,
const char *Data,
int DataLength,
int Ttl
);
};

int DnsGenerator_Init(DnsGenerator *g,
Expand Down

0 comments on commit 2c5beac

Please sign in to comment.