mirror of
https://github.com/NLnetLabs/unbound.git
synced 2024-09-21 14:47:09 +00:00
- Reformat pythonmod/pythonmod_utils.{c,h}.
This commit is contained in:
parent
7d5050c729
commit
a13d935153
@ -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.
|
||||||
|
@ -56,15 +56,18 @@
|
|||||||
#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,
|
||||||
|
"Authoritative answer can't be stored");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,7 +76,8 @@ int storeQueryInCache(struct module_qstate* qstate, struct query_info* qinfo, st
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* 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;
|
hashvalue_type h;
|
||||||
struct lruhash_entry* e;
|
struct lruhash_entry* e;
|
||||||
@ -81,15 +85,12 @@ void invalidateQueryInCache(struct module_qstate* qstate, struct query_info* qin
|
|||||||
size_t i, j;
|
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;
|
r->ttl = 0;
|
||||||
if(rrset_array_lock(r->ref, r->rrset_count, *qstate->env->now)) {
|
if(rrset_array_lock(r->ref, r->rrset_count, *qstate->env->now)) {
|
||||||
for(i=0; i< r->rrset_count; i++)
|
for(i=0; i< r->rrset_count; i++) {
|
||||||
{
|
|
||||||
struct packed_rrset_data* data =
|
struct packed_rrset_data* data =
|
||||||
(struct packed_rrset_data*) r->ref[i].key->entry.data;
|
(struct packed_rrset_data*) r->ref[i].key->entry.data;
|
||||||
if(i>0 && r->ref[i].key == r->ref[i-1].key)
|
if(i>0 && r->ref[i].key == r->ref[i-1].key)
|
||||||
@ -115,9 +116,10 @@ int createResponse(struct module_qstate* qstate, sldns_buffer* pkt)
|
|||||||
struct edns_data edns;
|
struct edns_data edns;
|
||||||
|
|
||||||
/* parse message */
|
/* parse message */
|
||||||
prs = (struct msg_parse*) regional_alloc(qstate->env->scratch, sizeof(struct msg_parse));
|
prs = (struct msg_parse*) regional_alloc(qstate->env->scratch,
|
||||||
|
sizeof(struct msg_parse));
|
||||||
if(!prs) {
|
if(!prs) {
|
||||||
log_err("storeResponse: out of memory on incoming message");
|
log_err("createResponse: out of memory on incoming message");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,7 +128,7 @@ int createResponse(struct module_qstate* qstate, sldns_buffer* pkt)
|
|||||||
|
|
||||||
sldns_buffer_set_position(pkt, 0);
|
sldns_buffer_set_position(pkt, 0);
|
||||||
if(parse_packet(pkt, prs, qstate->env->scratch) != LDNS_RCODE_NOERROR) {
|
if(parse_packet(pkt, prs, qstate->env->scratch) != LDNS_RCODE_NOERROR) {
|
||||||
verbose(VERB_ALGO, "storeResponse: parse error on reply packet");
|
verbose(VERB_ALGO, "createResponse: parse error on reply packet");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* edns is not examined, but removed from message to help cache */
|
/* edns is not examined, but removed from message to help cache */
|
||||||
@ -138,13 +140,15 @@ int createResponse(struct module_qstate* qstate, sldns_buffer* pkt)
|
|||||||
prs->flags &= ~BIT_CD;
|
prs->flags &= ~BIT_CD;
|
||||||
|
|
||||||
/* allocate response dns_msg in region */
|
/* allocate response dns_msg in region */
|
||||||
qstate->return_msg = (struct dns_msg*)regional_alloc(qstate->region, sizeof(struct dns_msg));
|
qstate->return_msg = (struct dns_msg*) regional_alloc(qstate->region,
|
||||||
|
sizeof(struct dns_msg));
|
||||||
if(!qstate->return_msg)
|
if(!qstate->return_msg)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
memset(qstate->return_msg, 0, sizeof(*qstate->return_msg));
|
memset(qstate->return_msg, 0, sizeof(*qstate->return_msg));
|
||||||
if(!parse_create_msg(pkt, prs, NULL, &(qstate->return_msg)->qinfo, &(qstate->return_msg)->rep, qstate->region)) {
|
if(!parse_create_msg(pkt, prs, NULL, &(qstate->return_msg)->qinfo,
|
||||||
log_err("storeResponse: malloc failure: allocating incoming dns_msg");
|
&(qstate->return_msg)->rep, qstate->region)) {
|
||||||
|
log_err("createResponse: malloc failure: allocating incoming dns_msg");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,7 +164,8 @@ int createResponse(struct module_qstate* qstate, sldns_buffer* pkt)
|
|||||||
/*qstate->return_msg->rep->flags |= BIT_QR; */
|
/*qstate->return_msg->rep->flags |= BIT_QR; */
|
||||||
|
|
||||||
if(verbosity >= VERB_ALGO)
|
if(verbosity >= VERB_ALGO)
|
||||||
log_dns_msg("storeResponse: packet:", &qstate->return_msg->qinfo, qstate->return_msg->rep);
|
log_dns_msg("createResponse: packet:", &qstate->return_msg->qinfo,
|
||||||
|
qstate->return_msg->rep);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,8 @@ 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.
|
||||||
@ -56,21 +57,24 @@ struct sldns_buffer;
|
|||||||
* 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
|
||||||
*
|
*
|
||||||
@ -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 New Issue
Block a user