mirror of
https://github.com/mollyim/unbound.git
synced 2025-05-19 16:47:54 +01:00
- Reformat pythonmod/pythonmod_utils.{c,h}.
This commit is contained in:
parent
7d5050c729
commit
a13d935153
3 changed files with 129 additions and 113 deletions
|
@ -1,6 +1,7 @@
|
||||||
22 March 2021: George
|
22 March 2021: George
|
||||||
- Fix unused-function warning when compiling with --enable-dnscrypt.
|
- Fix unused-function warning when compiling with --enable-dnscrypt.
|
||||||
- Fix for #367: fix memory leak when cannot bind to listening port.
|
- Fix for #367: fix memory leak when cannot bind to listening port.
|
||||||
|
- Reformat pythonmod/pythonmod_utils.{c,h}.
|
||||||
|
|
||||||
22 March 2021: Wouter
|
22 March 2021: Wouter
|
||||||
- Merge #449 from orbea: build: Add missing linker flags.
|
- Merge #449 from orbea: build: Add missing linker flags.
|
||||||
|
|
|
@ -5,18 +5,18 @@
|
||||||
* Marek Vavrusa (xvavru00 AT stud.fit.vutbr.cz)
|
* Marek Vavrusa (xvavru00 AT stud.fit.vutbr.cz)
|
||||||
*
|
*
|
||||||
* This software is open source.
|
* This software is open source.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
* are met:
|
* are met:
|
||||||
*
|
*
|
||||||
* * Redistributions of source code must retain the above copyright notice,
|
* * Redistributions of source code must retain the above copyright notice,
|
||||||
* this list of conditions and the following disclaimer.
|
* this list of conditions and the following disclaimer.
|
||||||
*
|
*
|
||||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
* and/or other materials provided with the distribution.
|
* and/or other materials provided with the distribution.
|
||||||
*
|
*
|
||||||
* * Neither the name of the organization nor the names of its
|
* * Neither the name of the organization nor the names of its
|
||||||
* contributors may be used to endorse or promote products derived from this
|
* contributors may be used to endorse or promote products derived from this
|
||||||
* software without specific prior written permission.
|
* software without specific prior written permission.
|
||||||
|
@ -56,113 +56,118 @@
|
||||||
#undef _XOPEN_SOURCE
|
#undef _XOPEN_SOURCE
|
||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
|
|
||||||
/* Store the reply_info and query_info pair in message cache (qstate->msg_cache) */
|
/* Store the reply_info and query_info pair in message cache
|
||||||
int storeQueryInCache(struct module_qstate* qstate, struct query_info* qinfo, struct reply_info* msgrep, int is_referral)
|
* (qstate->msg_cache) */
|
||||||
|
int storeQueryInCache(struct module_qstate* qstate, struct query_info* qinfo,
|
||||||
|
struct reply_info* msgrep, int is_referral)
|
||||||
{
|
{
|
||||||
if (!msgrep)
|
if (!msgrep)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (msgrep->authoritative) /*authoritative answer can't be stored in cache*/
|
/* authoritative answer can't be stored in cache */
|
||||||
{
|
if (msgrep->authoritative) {
|
||||||
PyErr_SetString(PyExc_ValueError, "Authoritative answer can't be stored");
|
PyErr_SetString(PyExc_ValueError,
|
||||||
return 0;
|
"Authoritative answer can't be stored");
|
||||||
}
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
return dns_cache_store(qstate->env, qinfo, msgrep, is_referral,
|
return dns_cache_store(qstate->env, qinfo, msgrep, is_referral,
|
||||||
qstate->prefetch_leeway, 0, NULL, qstate->query_flags);
|
qstate->prefetch_leeway, 0, NULL, qstate->query_flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Invalidate the message associated with query_info stored in message cache */
|
/* Invalidate the message associated with query_info stored in message cache */
|
||||||
void invalidateQueryInCache(struct module_qstate* qstate, struct query_info* qinfo)
|
void invalidateQueryInCache(struct module_qstate* qstate,
|
||||||
{
|
struct query_info* qinfo)
|
||||||
hashvalue_type h;
|
{
|
||||||
struct lruhash_entry* e;
|
hashvalue_type h;
|
||||||
struct reply_info *r;
|
struct lruhash_entry* e;
|
||||||
size_t i, j;
|
struct reply_info *r;
|
||||||
|
size_t i, j;
|
||||||
|
|
||||||
h = query_info_hash(qinfo, qstate->query_flags);
|
h = query_info_hash(qinfo, qstate->query_flags);
|
||||||
if ((e=slabhash_lookup(qstate->env->msg_cache, h, qinfo, 0)))
|
if ((e=slabhash_lookup(qstate->env->msg_cache, h, qinfo, 0))) {
|
||||||
{
|
r = (struct reply_info*)(e->data);
|
||||||
r = (struct reply_info*)(e->data);
|
if (r) {
|
||||||
if (r)
|
r->ttl = 0;
|
||||||
{
|
if(rrset_array_lock(r->ref, r->rrset_count, *qstate->env->now)) {
|
||||||
r->ttl = 0;
|
for(i=0; i< r->rrset_count; i++) {
|
||||||
if(rrset_array_lock(r->ref, r->rrset_count, *qstate->env->now)) {
|
struct packed_rrset_data* data =
|
||||||
for(i=0; i< r->rrset_count; i++)
|
(struct packed_rrset_data*) r->ref[i].key->entry.data;
|
||||||
{
|
if(i>0 && r->ref[i].key == r->ref[i-1].key)
|
||||||
struct packed_rrset_data* data =
|
continue;
|
||||||
(struct packed_rrset_data*) r->ref[i].key->entry.data;
|
|
||||||
if(i>0 && r->ref[i].key == r->ref[i-1].key)
|
data->ttl = r->ttl;
|
||||||
continue;
|
for(j=0; j<data->count + data->rrsig_count; j++)
|
||||||
|
data->rr_ttl[j] = r->ttl;
|
||||||
data->ttl = r->ttl;
|
}
|
||||||
for(j=0; j<data->count + data->rrsig_count; j++)
|
rrset_array_unlock(r->ref, r->rrset_count);
|
||||||
data->rr_ttl[j] = r->ttl;
|
}
|
||||||
}
|
}
|
||||||
rrset_array_unlock(r->ref, r->rrset_count);
|
lock_rw_unlock(&e->lock);
|
||||||
}
|
} else {
|
||||||
|
log_info("invalidateQueryInCache: qinfo is not in cache");
|
||||||
}
|
}
|
||||||
lock_rw_unlock(&e->lock);
|
|
||||||
} else {
|
|
||||||
log_info("invalidateQueryInCache: qinfo is not in cache");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create response according to the ldns packet content */
|
/* Create response according to the ldns packet content */
|
||||||
int createResponse(struct module_qstate* qstate, sldns_buffer* pkt)
|
int createResponse(struct module_qstate* qstate, sldns_buffer* pkt)
|
||||||
{
|
{
|
||||||
struct msg_parse* prs;
|
struct msg_parse* prs;
|
||||||
struct edns_data edns;
|
struct edns_data edns;
|
||||||
|
|
||||||
/* parse message */
|
|
||||||
prs = (struct msg_parse*) regional_alloc(qstate->env->scratch, sizeof(struct msg_parse));
|
|
||||||
if (!prs) {
|
|
||||||
log_err("storeResponse: out of memory on incoming message");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
memset(prs, 0, sizeof(*prs));
|
/* parse message */
|
||||||
memset(&edns, 0, sizeof(edns));
|
prs = (struct msg_parse*) regional_alloc(qstate->env->scratch,
|
||||||
|
sizeof(struct msg_parse));
|
||||||
|
if(!prs) {
|
||||||
|
log_err("createResponse: out of memory on incoming message");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
sldns_buffer_set_position(pkt, 0);
|
memset(prs, 0, sizeof(*prs));
|
||||||
if (parse_packet(pkt, prs, qstate->env->scratch) != LDNS_RCODE_NOERROR) {
|
memset(&edns, 0, sizeof(edns));
|
||||||
verbose(VERB_ALGO, "storeResponse: parse error on reply packet");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
/* edns is not examined, but removed from message to help cache */
|
|
||||||
if(parse_extract_edns(prs, &edns, qstate->env->scratch) !=
|
|
||||||
LDNS_RCODE_NOERROR)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
/* remove CD-bit, we asked for in case we handle validation ourself */
|
sldns_buffer_set_position(pkt, 0);
|
||||||
prs->flags &= ~BIT_CD;
|
if(parse_packet(pkt, prs, qstate->env->scratch) != LDNS_RCODE_NOERROR) {
|
||||||
|
verbose(VERB_ALGO, "createResponse: parse error on reply packet");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/* edns is not examined, but removed from message to help cache */
|
||||||
|
if(parse_extract_edns(prs, &edns, qstate->env->scratch) !=
|
||||||
|
LDNS_RCODE_NOERROR)
|
||||||
|
return 0;
|
||||||
|
|
||||||
/* allocate response dns_msg in region */
|
/* remove CD-bit, we asked for in case we handle validation ourself */
|
||||||
qstate->return_msg = (struct dns_msg*)regional_alloc(qstate->region, sizeof(struct dns_msg));
|
prs->flags &= ~BIT_CD;
|
||||||
if (!qstate->return_msg)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
memset(qstate->return_msg, 0, sizeof(*qstate->return_msg));
|
/* allocate response dns_msg in region */
|
||||||
if(!parse_create_msg(pkt, prs, NULL, &(qstate->return_msg)->qinfo, &(qstate->return_msg)->rep, qstate->region)) {
|
qstate->return_msg = (struct dns_msg*) regional_alloc(qstate->region,
|
||||||
log_err("storeResponse: malloc failure: allocating incoming dns_msg");
|
sizeof(struct dns_msg));
|
||||||
return 0;
|
if(!qstate->return_msg)
|
||||||
}
|
return 0;
|
||||||
|
|
||||||
/* Make sure that the RA flag is set (since the presence of
|
|
||||||
* this module means that recursion is available) */
|
|
||||||
/* qstate->return_msg->rep->flags |= BIT_RA; */
|
|
||||||
|
|
||||||
/* Clear the AA flag */
|
memset(qstate->return_msg, 0, sizeof(*qstate->return_msg));
|
||||||
/* FIXME: does this action go here or in some other module? */
|
if(!parse_create_msg(pkt, prs, NULL, &(qstate->return_msg)->qinfo,
|
||||||
/*qstate->return_msg->rep->flags &= ~BIT_AA; */
|
&(qstate->return_msg)->rep, qstate->region)) {
|
||||||
|
log_err("createResponse: malloc failure: allocating incoming dns_msg");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* make sure QR flag is on */
|
/* Make sure that the RA flag is set (since the presence of
|
||||||
/*qstate->return_msg->rep->flags |= BIT_QR; */
|
* this module means that recursion is available) */
|
||||||
|
/* qstate->return_msg->rep->flags |= BIT_RA; */
|
||||||
|
|
||||||
if(verbosity >= VERB_ALGO)
|
/* Clear the AA flag */
|
||||||
log_dns_msg("storeResponse: packet:", &qstate->return_msg->qinfo, qstate->return_msg->rep);
|
/* FIXME: does this action go here or in some other module? */
|
||||||
|
/*qstate->return_msg->rep->flags &= ~BIT_AA; */
|
||||||
|
|
||||||
return 1;
|
/* make sure QR flag is on */
|
||||||
|
/*qstate->return_msg->rep->flags |= BIT_QR; */
|
||||||
|
|
||||||
|
if(verbosity >= VERB_ALGO)
|
||||||
|
log_dns_msg("createResponse: packet:", &qstate->return_msg->qinfo,
|
||||||
|
qstate->return_msg->rep);
|
||||||
|
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -176,7 +181,7 @@ void reply_addr2str(struct comm_reply* reply, char* dest, int maxlen)
|
||||||
sinaddr = &((struct sockaddr_in6*)&(reply->addr))->sin6_addr;
|
sinaddr = &((struct sockaddr_in6*)&(reply->addr))->sin6_addr;
|
||||||
dest[0] = 0;
|
dest[0] = 0;
|
||||||
if (inet_ntop(af, sinaddr, dest, (socklen_t)maxlen) == 0)
|
if (inet_ntop(af, sinaddr, dest, (socklen_t)maxlen) == 0)
|
||||||
return;
|
return;
|
||||||
dest[maxlen-1] = 0;
|
dest[maxlen-1] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,6 +195,6 @@ void delegpt_addr_addr2str(struct delegpt_addr* target, char *dest, int maxlen)
|
||||||
sinaddr = &((struct sockaddr_in6*)&(target->addr))->sin6_addr;
|
sinaddr = &((struct sockaddr_in6*)&(target->addr))->sin6_addr;
|
||||||
dest[0] = 0;
|
dest[0] = 0;
|
||||||
if (inet_ntop(af, sinaddr, dest, (socklen_t)maxlen) == 0)
|
if (inet_ntop(af, sinaddr, dest, (socklen_t)maxlen) == 0)
|
||||||
return;
|
return;
|
||||||
dest[maxlen-1] = 0;
|
dest[maxlen-1] = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,22 +1,22 @@
|
||||||
/*
|
/*
|
||||||
* pythonmod_utils.h: utils header file
|
* pythonmod_utils.h: utils header file
|
||||||
*
|
*
|
||||||
* Copyright (c) 2009, Zdenek Vasicek (vasicek AT fit.vutbr.cz)
|
* Copyright (c) 2009, Zdenek Vasicek (vasicek AT fit.vutbr.cz)
|
||||||
* Marek Vavrusa (xvavru00 AT stud.fit.vutbr.cz)
|
* Marek Vavrusa (xvavru00 AT stud.fit.vutbr.cz)
|
||||||
*
|
*
|
||||||
* This software is open source.
|
* This software is open source.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
* are met:
|
* are met:
|
||||||
*
|
*
|
||||||
* * Redistributions of source code must retain the above copyright notice,
|
* * Redistributions of source code must retain the above copyright notice,
|
||||||
* this list of conditions and the following disclaimer.
|
* this list of conditions and the following disclaimer.
|
||||||
*
|
*
|
||||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
* and/or other materials provided with the distribution.
|
* and/or other materials provided with the distribution.
|
||||||
*
|
*
|
||||||
* * Neither the name of the organization nor the names of its
|
* * Neither the name of the organization nor the names of its
|
||||||
* contributors may be used to endorse or promote products derived from this
|
* contributors may be used to endorse or promote products derived from this
|
||||||
* software without specific prior written permission.
|
* software without specific prior written permission.
|
||||||
|
@ -46,34 +46,38 @@ struct delegpt_addr;
|
||||||
struct sldns_buffer;
|
struct sldns_buffer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store the reply_info and query_info pair in message cache (qstate->msg_cache)
|
* Store the reply_info and query_info pair in message cache
|
||||||
|
* (qstate->msg_cache).
|
||||||
*
|
*
|
||||||
* @param qstate: module environment
|
* @param qstate: module environment
|
||||||
* @param qinfo: query info, the query for which answer is stored.
|
* @param qinfo: query info, the query for which answer is stored.
|
||||||
* @param msgrep: reply in dns_msg
|
* @param msgrep: reply in dns_msg
|
||||||
* @param is_referral: If true, then the given message to be stored is a
|
* @param is_referral: If true, then the given message to be stored is a
|
||||||
* referral. The cache implementation may use this as a hint.
|
* referral. The cache implementation may use this as a hint.
|
||||||
* It will store only the RRsets, not the message.
|
* It will store only the RRsets, not the message.
|
||||||
* @return 0 on alloc error (out of memory).
|
* @return 0 on alloc error (out of memory).
|
||||||
*/
|
*/
|
||||||
int storeQueryInCache(struct module_qstate* qstate, struct query_info* qinfo, struct reply_info* msgrep, int is_referral);
|
int storeQueryInCache(struct module_qstate* qstate, struct query_info* qinfo,
|
||||||
|
struct reply_info* msgrep, int is_referral);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invalidate the message associated with query_info stored in message cache.
|
* Invalidate the message associated with query_info stored in message cache.
|
||||||
*
|
*
|
||||||
* This function invalidates the record in message cache associated with the given query only if such a record exists.
|
* This function invalidates the record in message cache associated with the
|
||||||
|
* given query only if such a record exists.
|
||||||
*
|
*
|
||||||
* @param qstate: module environment
|
* @param qstate: module environment
|
||||||
* @param qinfo: query info, the query for which answer is stored.
|
* @param qinfo: query info, the query for which answer is stored.
|
||||||
*/
|
*/
|
||||||
void invalidateQueryInCache(struct module_qstate* qstate, struct query_info* qinfo);
|
void invalidateQueryInCache(struct module_qstate* qstate,
|
||||||
|
struct query_info* qinfo);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create response according to the ldns packet content
|
* Create response according to the ldns packet content.
|
||||||
|
*
|
||||||
|
* This function fills qstate.return_msg up with data of a given packet
|
||||||
*
|
*
|
||||||
* This function fills qstate.return_msg up with data of a given packet
|
|
||||||
*
|
|
||||||
* @param qstate: module environment
|
* @param qstate: module environment
|
||||||
* @param pkt: a sldns_buffer which contains sldns_packet data
|
* @param pkt: a sldns_buffer which contains sldns_packet data
|
||||||
* @return 0 on failure, out of memory or parse error.
|
* @return 0 on failure, out of memory or parse error.
|
||||||
|
@ -81,14 +85,20 @@ void invalidateQueryInCache(struct module_qstate* qstate, struct query_info* qin
|
||||||
int createResponse(struct module_qstate* qstate, struct sldns_buffer* pkt);
|
int createResponse(struct module_qstate* qstate, struct sldns_buffer* pkt);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert reply->addr to string
|
* Convert reply->addr to string.
|
||||||
* @param reply: comm reply with address in it.
|
* @param reply: comm reply with address in it.
|
||||||
* @param dest: destination string.
|
* @param dest: destination string.
|
||||||
* @param maxlen: length of string buffer.
|
* @param maxlen: length of string buffer.
|
||||||
*/
|
*/
|
||||||
void reply_addr2str(struct comm_reply* reply, char* dest, int maxlen);
|
void reply_addr2str(struct comm_reply* reply, char* dest, int maxlen);
|
||||||
|
|
||||||
/* Convert target->addr to string */
|
/**
|
||||||
void delegpt_addr_addr2str(struct delegpt_addr* target, char *dest, int maxlen);
|
* Convert target->addr to string.
|
||||||
|
* @param target: delegpt_addr with address in it.
|
||||||
|
* @param dest: destination string.
|
||||||
|
* @param maxlen: length of string buffer.
|
||||||
|
*/
|
||||||
|
void delegpt_addr_addr2str(struct delegpt_addr* target, char *dest,
|
||||||
|
int maxlen);
|
||||||
|
|
||||||
#endif /* PYTHONMOD_UTILS_H */
|
#endif /* PYTHONMOD_UTILS_H */
|
||||||
|
|
Loading…
Reference in a new issue