mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-30 05:57:52 +00:00
Clean up and refactor dns_adb_getcookie()
The dns_adb_getcookie() doesn't use the 'adb' parameter, remove it. Refactor the dns_adb_getcookie() function to just return the size of the cookie when the caller passes 'NULL' as the 'cookie' argument.
This commit is contained in:
parent
5266444e35
commit
03442d922b
@ -3465,21 +3465,26 @@ dns_adb_setcookie(dns_adb_t *adb, dns_adbaddrinfo_t *addr,
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
dns_adb_getcookie(dns_adb_t *adb, dns_adbaddrinfo_t *addr,
|
dns_adb_getcookie(dns_adbaddrinfo_t *addr, unsigned char *cookie, size_t len) {
|
||||||
unsigned char *cookie, size_t len) {
|
|
||||||
REQUIRE(DNS_ADB_VALID(adb));
|
|
||||||
REQUIRE(DNS_ADBADDRINFO_VALID(addr));
|
REQUIRE(DNS_ADBADDRINFO_VALID(addr));
|
||||||
|
|
||||||
dns_adbentry_t *entry = addr->entry;
|
dns_adbentry_t *entry = addr->entry;
|
||||||
|
|
||||||
LOCK(&entry->lock);
|
LOCK(&entry->lock);
|
||||||
if (cookie != NULL && entry->cookie != NULL && len >= entry->cookielen)
|
if (entry->cookie == NULL) {
|
||||||
{
|
|
||||||
memmove(cookie, entry->cookie, entry->cookielen);
|
|
||||||
len = entry->cookielen;
|
|
||||||
} else {
|
|
||||||
len = 0;
|
len = 0;
|
||||||
|
goto unlock;
|
||||||
}
|
}
|
||||||
|
if (cookie != NULL) {
|
||||||
|
if (len < entry->cookielen) {
|
||||||
|
len = 0;
|
||||||
|
goto unlock;
|
||||||
|
}
|
||||||
|
memmove(cookie, entry->cookie, entry->cookielen);
|
||||||
|
}
|
||||||
|
len = entry->cookielen;
|
||||||
|
|
||||||
|
unlock:
|
||||||
UNLOCK(&entry->lock);
|
UNLOCK(&entry->lock);
|
||||||
|
|
||||||
return (len);
|
return (len);
|
||||||
|
@ -671,19 +671,17 @@ dns_adb_setcookie(dns_adb_t *adb, dns_adbaddrinfo_t *addr,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
dns_adb_getcookie(dns_adb_t *adb, dns_adbaddrinfo_t *addr,
|
dns_adb_getcookie(dns_adbaddrinfo_t *addr, unsigned char *cookie, size_t len);
|
||||||
unsigned char *cookie, size_t len);
|
|
||||||
/*
|
/*
|
||||||
* Retrieve the saved COOKIE value and store it in 'cookie' which has
|
* If 'cookie' is not NULL, then retrieve the saved COOKIE value and store it
|
||||||
* size 'len'.
|
* in 'cookie' which has size 'len'.
|
||||||
*
|
*
|
||||||
* Requires:
|
* Requires:
|
||||||
*\li 'adb' is valid.
|
|
||||||
*\li 'addr' is valid.
|
*\li 'addr' is valid.
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* The size of the cookie or zero if it doesn't fit in the buffer
|
* The size of the cookie or zero if it doesn't exist, or when 'cookie' is
|
||||||
* or it doesn't exist.
|
* not NULL and it doesn't fit in the buffer.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -2744,8 +2744,8 @@ resquery_send(resquery_t *query) {
|
|||||||
ednsopts[ednsopt].code = DNS_OPT_COOKIE;
|
ednsopts[ednsopt].code = DNS_OPT_COOKIE;
|
||||||
ednsopts[ednsopt].length =
|
ednsopts[ednsopt].length =
|
||||||
(uint16_t)dns_adb_getcookie(
|
(uint16_t)dns_adb_getcookie(
|
||||||
fctx->adb, query->addrinfo,
|
query->addrinfo, cookie,
|
||||||
cookie, sizeof(cookie));
|
sizeof(cookie));
|
||||||
if (ednsopts[ednsopt].length != 0) {
|
if (ednsopts[ednsopt].length != 0) {
|
||||||
ednsopts[ednsopt].value = cookie;
|
ednsopts[ednsopt].value = cookie;
|
||||||
inc_stats(
|
inc_stats(
|
||||||
@ -7658,9 +7658,8 @@ resquery_response(isc_result_t eresult, isc_region_t *region, void *arg) {
|
|||||||
!query->rmessage->cc_ok && !query->rmessage->cc_bad &&
|
!query->rmessage->cc_ok && !query->rmessage->cc_bad &&
|
||||||
(rctx.retryopts & DNS_FETCHOPT_TCP) == 0)
|
(rctx.retryopts & DNS_FETCHOPT_TCP) == 0)
|
||||||
{
|
{
|
||||||
unsigned char cookie[COOKIE_BUFFER_SIZE];
|
if (dns_adb_getcookie(query->addrinfo, NULL, 0) >
|
||||||
if (dns_adb_getcookie(fctx->adb, query->addrinfo, cookie,
|
CLIENT_COOKIE_SIZE)
|
||||||
sizeof(cookie)) > CLIENT_COOKIE_SIZE)
|
|
||||||
{
|
{
|
||||||
if (isc_log_wouldlog(dns_lctx, ISC_LOG_INFO)) {
|
if (isc_log_wouldlog(dns_lctx, ISC_LOG_INFO)) {
|
||||||
char addrbuf[ISC_SOCKADDR_FORMATSIZE];
|
char addrbuf[ISC_SOCKADDR_FORMATSIZE];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user