Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Knot DNS
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
22
Issues
22
List
Boards
Labels
Service Desk
Milestones
Merge Requests
17
Merge Requests
17
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Knot projects
Knot DNS
Commits
0a29865a
Commit
0a29865a
authored
Nov 14, 2013
by
Marek Vavrusa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ported libknot to new pkt API.
parent
e3b85192
Changes
22
Hide whitespace changes
Inline
Side-by-side
Showing
22 changed files
with
676 additions
and
1009 deletions
+676
-1009
src/libknot/consts.h
src/libknot/consts.h
+21
-11
src/libknot/dname.c
src/libknot/dname.c
+1
-1
src/libknot/dnssec/sig0.c
src/libknot/dnssec/sig0.c
+1
-1
src/libknot/edns.c
src/libknot/edns.c
+1
-1
src/libknot/edns.h
src/libknot/edns.h
+10
-0
src/libknot/libknot.h
src/libknot/libknot.h
+4
-4
src/libknot/nameserver/chaos.c
src/libknot/nameserver/chaos.c
+8
-10
src/libknot/nameserver/chaos.h
src/libknot/nameserver/chaos.h
+2
-2
src/libknot/nameserver/name-server.c
src/libknot/nameserver/name-server.c
+374
-596
src/libknot/nameserver/name-server.h
src/libknot/nameserver/name-server.h
+15
-20
src/libknot/packet/pkt.c
src/libknot/packet/pkt.c
+3
-3
src/libknot/packet/pkt.h
src/libknot/packet/pkt.h
+1
-1
src/libknot/rrset.c
src/libknot/rrset.c
+52
-56
src/libknot/rrset.h
src/libknot/rrset.h
+4
-2
src/libknot/tsig-op.c
src/libknot/tsig-op.c
+1
-1
src/libknot/tsig.c
src/libknot/tsig.c
+4
-0
src/libknot/updates/ddns.c
src/libknot/updates/ddns.c
+17
-16
src/libknot/updates/ddns.h
src/libknot/updates/ddns.h
+4
-4
src/libknot/updates/xfr-in.c
src/libknot/updates/xfr-in.c
+146
-264
src/libknot/updates/xfr-in.h
src/libknot/updates/xfr-in.h
+5
-14
src/libknot/zone/zone-contents.c
src/libknot/zone/zone-contents.c
+1
-1
src/libknot/zone/zonedb.c
src/libknot/zone/zonedb.c
+1
-1
No files found.
src/libknot/consts.h
View file @
0a29865a
...
...
@@ -89,19 +89,29 @@ typedef enum {
* OPCODE and the QTYPE.
*/
typedef
enum
{
KNOT_QUERY_INVALID
,
/*!< Invalid query. */
KNOT_QUERY_NORMAL
,
/*!< Normal query. */
KNOT_QUERY_AXFR
,
/*!< Request for AXFR transfer. */
KNOT_QUERY_IXFR
,
/*!< Request for IXFR transfer. */
KNOT_QUERY_NOTIFY
,
/*!< NOTIFY query. */
KNOT_QUERY_UPDATE
,
/*!< Dynamic update. */
KNOT_RESPONSE_NORMAL
,
/*!< Normal response. */
KNOT_RESPONSE_AXFR
,
/*!< AXFR transfer response. */
KNOT_RESPONSE_IXFR
,
/*!< IXFR transfer response. */
KNOT_RESPONSE_NOTIFY
,
/*!< NOTIFY response. */
KNOT_RESPONSE_UPDATE
/*!< Dynamic update response. */
KNOT_QUERY_INVALID
=
1
<<
1
,
/*!< Invalid query. */
KNOT_QUERY_NORMAL
=
1
<<
2
,
/*!< Normal query. */
KNOT_QUERY_AXFR
=
1
<<
3
,
/*!< Request for AXFR transfer. */
KNOT_QUERY_IXFR
=
1
<<
4
,
/*!< Request for IXFR transfer. */
KNOT_QUERY_NOTIFY
=
1
<<
5
,
/*!< NOTIFY query. */
KNOT_QUERY_UPDATE
=
1
<<
6
,
/*!< Dynamic update. */
KNOT_RESPONSE
=
1
<<
0
,
/*!< Is response. */
KNOT_RESPONSE_NORMAL
=
KNOT_RESPONSE
|
KNOT_QUERY_NORMAL
,
/*!< Normal response. */
KNOT_RESPONSE_AXFR
=
KNOT_RESPONSE
|
KNOT_QUERY_AXFR
,
/*!< AXFR transfer response. */
KNOT_RESPONSE_IXFR
=
KNOT_RESPONSE
|
KNOT_QUERY_IXFR
,
/*!< IXFR transfer response. */
KNOT_RESPONSE_NOTIFY
=
KNOT_RESPONSE
|
KNOT_QUERY_NOTIFY
,
/*!< NOTIFY response. */
KNOT_RESPONSE_UPDATE
=
KNOT_RESPONSE
|
KNOT_QUERY_UPDATE
/*!< Dynamic update response. */
}
knot_packet_type_t
;
/*!
* \brief DNS packet section identifiers.
*/
typedef
enum
{
KNOT_ANSWER
=
0
,
KNOT_AUTHORITY
=
1
,
KNOT_ADDITIONAL
=
2
}
knot_section_t
;
/*!
* \brief TSIG algorithm numbers.
*
...
...
src/libknot/dname.c
View file @
0a29865a
...
...
@@ -29,7 +29,7 @@
#include "libknot/util/tolower.h"
#include "libknot/util/debug.h"
#include "libknot/util/utils.h"
#include "libknot/
util
/wire.h"
#include "libknot/
packet
/wire.h"
/*----------------------------------------------------------------------------*/
...
...
src/libknot/dnssec/sig0.c
View file @
0a29865a
...
...
@@ -21,7 +21,7 @@
#include "libknot/dnssec/rrset-sign.h"
#include "libknot/dnssec/sig0.h"
#include "libknot/dnssec/sign.h"
#include "libknot/
util
/wire.h"
#include "libknot/
packet
/wire.h"
/*!
* \brief Lifetime fudge of the SIG(0) packets in seconds.
...
...
src/libknot/edns.c
View file @
0a29865a
...
...
@@ -274,7 +274,7 @@ short knot_edns_to_wire(const knot_opt_rr_t *opt_rr, uint8_t *wire,
assert
(
EDNS_MIN_SIZE
<=
(
int
)
max_size
);
if
((
int
)
max_size
<
opt_rr
->
size
)
{
dbg_edns
(
"Not enough place for OPT RR wire format.
\n
"
);
printf
(
"Not enough place for OPT RR wire format.
\n
"
);
return
KNOT_ESPACE
;
}
...
...
src/libknot/edns.h
View file @
0a29865a
...
...
@@ -32,6 +32,8 @@
#include "libknot/util/utils.h"
#include "libknot/rrset.h"
struct
knot_packet
;
/*----------------------------------------------------------------------------*/
/*! \brief Structure representing one OPT RR Option. */
struct
knot_opt_option
{
...
...
@@ -80,6 +82,13 @@ enum knot_edns_const {
EDNS_MIN_SIZE
=
11
/*!< Minimum size of EDNS OPT RR in wire format. */
};
enum
{
KNOT_PKT_EDNS_PAYLOAD
=
0
,
KNOT_PKT_EDNS_VERSION
=
1
,
KNOT_PKT_EDNS_RCODE
=
2
,
KNOT_PKT_EDNS_NSID
=
3
};
/*----------------------------------------------------------------------------*/
/*!
* \brief Creates new empty OPT RR structure for holding EDNS parameters.
...
...
@@ -230,6 +239,7 @@ int knot_edns_add_option(knot_opt_rr_t *opt_rr, uint16_t code,
*/
int
knot_edns_has_option
(
const
knot_opt_rr_t
*
opt_rr
,
uint16_t
code
);
/*!
* \brief Converts the given OPT RR into wire format.
*
...
...
src/libknot/libknot.h
View file @
0a29865a
...
...
@@ -30,16 +30,16 @@
#include "libknot/consts.h"
#include "libknot/dname.h"
#include "libknot/edns.h"
#include "libknot/packet/
packet
.h"
#include "libknot/packet/
query
.h"
#include "libknot/packet/
response
.h"
#include "libknot/packet/
wire
.h"
#include "libknot/packet/
compr
.h"
#include "libknot/packet/
pkt
.h"
#include "libknot/rrset.h"
#include "libknot/rrset-dump.h"
#include "libknot/tsig.h"
#include "libknot/tsig-op.h"
#include "libknot/util/tolower.h"
#include "libknot/util/utils.h"
#include "libknot/util/wire.h"
#include "libknot/zone/node.h"
#include "libknot/zone/zone.h"
#include "libknot/zone/zonedb.h"
...
...
src/libknot/nameserver/chaos.c
View file @
0a29865a
...
...
@@ -19,8 +19,7 @@
#include "libknot/nameserver/chaos.h"
#include "common/descriptor.h"
#include "libknot/packet/packet.h"
#include "libknot/packet/response.h"
#include "libknot/packet/pkt.h"
/*!
* \brief Get a string result for a given TXT query.
...
...
@@ -89,10 +88,10 @@ static knot_rrset_t *create_txt_rrset(const knot_dname_t *owner,
* \param return KNOT_RCODE_NOERROR if the response was succesfully created,
* otherwise an RCODE representing the failure.
*/
static
int
answer_txt
(
knot_nameserver_t
*
nameserver
,
knot_p
acke
t_t
*
response
,
static
int
answer_txt
(
knot_nameserver_t
*
nameserver
,
knot_p
k
t_t
*
response
,
uint8_t
*
response_wire
,
size_t
*
response_size
)
{
const
knot_dname_t
*
qname
=
knot_p
acke
t_qname
(
response
);
const
knot_dname_t
*
qname
=
knot_p
k
t_qname
(
response
);
const
char
*
response_str
=
get_txt_response_string
(
nameserver
,
qname
);
if
(
response_str
==
NULL
||
response_str
[
0
]
==
'\0'
)
return
KNOT_RCODE_REFUSED
;
...
...
@@ -101,7 +100,8 @@ static int answer_txt(knot_nameserver_t *nameserver, knot_packet_t *response,
if
(
!
rrset
)
return
KNOT_RCODE_SERVFAIL
;
int
result
=
knot_response_add_rrset_answer
(
response
,
rrset
,
0
);
assert
(
KNOT_PKT_IN_AN
(
response
))
/* #10 */
;
int
result
=
knot_pkt_put
(
response
,
0
,
rrset
,
KNOT_PF_FREE
);
if
(
result
!=
KNOT_EOK
)
{
knot_rrset_deep_free
(
&
rrset
,
1
);
return
KNOT_RCODE_SERVFAIL
;
...
...
@@ -109,12 +109,10 @@ static int answer_txt(knot_nameserver_t *nameserver, knot_packet_t *response,
result
=
ns_response_to_wire
(
response
,
response_wire
,
response_size
);
if
(
result
!=
KNOT_EOK
)
{
knot_rrset_deep_free
(
&
rrset
,
1
);
return
KNOT_RCODE_SERVFAIL
;
}
knot_rrset_deep_free
(
&
rrset
,
1
);
knot_response_set_rcode
(
response
,
KNOT_RCODE_NOERROR
);
knot_wire_set_rcode
(
response
->
wire
,
KNOT_RCODE_NOERROR
);
return
KNOT_RCODE_NOERROR
;
}
...
...
@@ -122,12 +120,12 @@ static int answer_txt(knot_nameserver_t *nameserver, knot_packet_t *response,
/*!
* \brief Create a response for a given query in the CHAOS class.
*/
int
knot_ns_answer_chaos
(
knot_nameserver_t
*
nameserver
,
knot_p
acke
t_t
*
resp
,
int
knot_ns_answer_chaos
(
knot_nameserver_t
*
nameserver
,
knot_p
k
t_t
*
resp
,
uint8_t
*
resp_wire
,
size_t
*
resp_size
)
{
int
rcode
=
KNOT_RCODE_REFUSED
;
if
(
knot_p
acke
t_qtype
(
resp
)
==
KNOT_RRTYPE_TXT
)
{
if
(
knot_p
k
t_qtype
(
resp
)
==
KNOT_RRTYPE_TXT
)
{
rcode
=
answer_txt
(
nameserver
,
resp
,
resp_wire
,
resp_size
);
}
...
...
src/libknot/nameserver/chaos.h
View file @
0a29865a
...
...
@@ -30,7 +30,7 @@
#include <stdint.h>
#include "libknot/nameserver/name-server.h"
#include "libknot/packet/p
acke
t.h"
#include "libknot/packet/p
k
t.h"
/*!
* \brief Create a response for a given query in the CHAOS class.
...
...
@@ -42,7 +42,7 @@
*
* \return Always KNOT_EOK.
*/
int
knot_ns_answer_chaos
(
knot_nameserver_t
*
nameserver
,
knot_p
acke
t_t
*
response
,
int
knot_ns_answer_chaos
(
knot_nameserver_t
*
nameserver
,
knot_p
k
t_t
*
response
,
uint8_t
*
response_wire
,
size_t
*
response_size
);
#endif // _KNOT_CHAOS_H_
...
...
src/libknot/nameserver/name-server.c
View file @
0a29865a
...
...
@@ -29,9 +29,7 @@
#include "libknot/common.h"
#include "common/lists.h"
#include "libknot/util/debug.h"
#include "libknot/packet/packet.h"
#include "libknot/packet/response.h"
#include "libknot/packet/query.h"
#include "libknot/packet/pkt.h"
#include "libknot/consts.h"
#include "common/descriptor.h"
#include "libknot/updates/changesets.h"
...
...
@@ -136,7 +134,7 @@ static knot_rrset_t *ns_synth_from_wildcard(
* temporary RRSet).
* \param rrset RRSet to check (and possibly replace).
*/
static
int
ns_check_wildcard
(
const
knot_dname_t
*
name
,
knot_p
acke
t_t
*
resp
,
static
int
ns_check_wildcard
(
const
knot_dname_t
*
name
,
knot_p
k
t_t
*
resp
,
knot_rrset_t
**
rrset
)
{
assert
(
name
!=
NULL
);
...
...
@@ -158,13 +156,8 @@ dbg_ns_exec_verb(
knot_rrset_dump
(
synth_rrset
);
);
int
ret
=
knot_packet_add_tmp_rrset
(
resp
,
synth_rrset
);
if
(
ret
!=
KNOT_EOK
)
{
dbg_ns
(
"Failed to add sythetized RRSet to tmp list.
\n
"
);
knot_rrset_deep_free
(
&
synth_rrset
,
1
);
return
ret
;
}
*
rrset
=
synth_rrset
;
/* #10 update flags somehow, will leak */
}
return
KNOT_EOK
;
...
...
@@ -191,11 +184,8 @@ dbg_ns_exec_verb(
* \return KNOT_ENOMEM
* \return KNOT_ESPACE
*/
static
int
ns_add_rrsigs
(
knot_rrset_t
*
rrset
,
knot_p
acke
t_t
*
resp
,
static
int
ns_add_rrsigs
(
knot_rrset_t
*
rrset
,
knot_p
k
t_t
*
resp
,
const
knot_dname_t
*
name
,
int
(
*
add_rrset_to_resp
)(
knot_packet_t
*
,
knot_rrset_t
*
,
uint32_t
),
uint32_t
flags
)
{
knot_rrset_t
*
rrsigs
;
...
...
@@ -203,15 +193,14 @@ static int ns_add_rrsigs(knot_rrset_t *rrset, knot_packet_t *resp,
dbg_ns_verb
(
"Adding RRSIGs for RRSet, type: %u.
\n
"
,
knot_rrset_type
(
rrset
));
assert
(
resp
!=
NULL
);
assert
(
add_rrset_to_resp
!=
NULL
);
dbg_ns_detail
(
"DNSSEC requested: %d
\n
"
,
knot_
query_dnssec_requested
(
knot_packet_query
(
resp
)
));
knot_
pkt_have_dnssec
(
resp
->
query
));
dbg_ns_detail
(
"RRSIGS: %p
\n
"
,
knot_rrset_rrsigs
(
rrset
));
if
(
DNSSEC_ENABLED
&&
(
knot_
query_dnssec_requested
(
knot_packet_query
(
resp
)
)
||
knot_p
acke
t_qtype
(
resp
)
==
KNOT_RRTYPE_ANY
)
&&
(
knot_
pkt_have_dnssec
(
resp
->
query
)
||
knot_p
k
t_qtype
(
resp
)
==
KNOT_RRTYPE_ANY
)
&&
(
rrsigs
=
knot_rrset_get_rrsigs
(
rrset
))
!=
NULL
)
{
if
(
name
!=
NULL
)
{
int
ret
=
ns_check_wildcard
(
name
,
resp
,
&
rrsigs
);
...
...
@@ -220,8 +209,9 @@ static int ns_add_rrsigs(knot_rrset_t *rrset, knot_packet_t *resp,
knot_strerror
(
ret
));
return
ret
;
}
/* #10 will leak if synthetized new */
}
return
add_rrset_to_resp
(
resp
,
rrsigs
,
flags
|
KNOT_PF_CHECKDUP
);
return
knot_pkt_put
(
resp
,
0
,
rrsigs
,
flags
|
KNOT_PF_CHECKDUP
);
}
return
KNOT_EOK
;
...
...
@@ -282,10 +272,7 @@ static void cname_chain_free(list_t *chain)
*/
static
int
ns_follow_cname
(
const
knot_node_t
**
node
,
const
knot_dname_t
**
qname
,
knot_packet_t
*
resp
,
int
(
*
add_rrset_to_resp
)(
knot_packet_t
*
,
knot_rrset_t
*
,
uint32_t
flags
),
knot_pkt_t
*
resp
,
int
flags
)
{
dbg_ns_verb
(
"Resolving CNAME chain...
\n
"
);
...
...
@@ -343,17 +330,7 @@ static int ns_follow_cname(const knot_node_t **node,
return
KNOT_ERROR
;
/*! \todo Better error. */
}
ret
=
knot_packet_add_tmp_rrset
(
resp
,
rrset
);
if
(
ret
!=
KNOT_EOK
)
{
dbg_ns
(
"Failed to add synthetized RRSet (CNAME "
"follow) to the tmp RRSets in response."
"
\n
"
);
knot_rrset_deep_free
(
&
rrset
,
1
);
cname_chain_free
(
&
cname_chain
);
return
ret
;
}
ret
=
add_rrset_to_resp
(
resp
,
rrset
,
flags
);
ret
=
knot_pkt_put
(
resp
,
0
,
rrset
,
flags
|
KNOT_PF_FREE
);
if
(
ret
!=
KNOT_EOK
)
{
dbg_ns
(
"Failed to add synthetized RRSet (CNAME "
"follow) to the response.
\n
"
);
...
...
@@ -361,8 +338,7 @@ static int ns_follow_cname(const knot_node_t **node,
return
ret
;
}
ret
=
ns_add_rrsigs
(
cname_rrset
,
resp
,
*
qname
,
add_rrset_to_resp
,
flags
);
ret
=
ns_add_rrsigs
(
cname_rrset
,
resp
,
*
qname
,
flags
);
if
(
ret
!=
KNOT_EOK
)
{
dbg_ns
(
"Failed to add RRSIG for the synthetized"
"RRSet (CNAME follow) to the response."
...
...
@@ -371,7 +347,7 @@ static int ns_follow_cname(const knot_node_t **node,
return
ret
;
}
int
ret
=
knot_
response
_add_wildcard_node
(
int
ret
=
knot_
pkt
_add_wildcard_node
(
resp
,
*
node
,
*
qname
);
if
(
ret
!=
KNOT_EOK
)
{
dbg_ns
(
"Failed to add wildcard node for later "
...
...
@@ -380,7 +356,7 @@ static int ns_follow_cname(const knot_node_t **node,
return
ret
;
}
}
else
{
ret
=
add_rrset_to_resp
(
resp
,
rrset
,
flags
);
ret
=
knot_pkt_put
(
resp
,
0
,
rrset
,
flags
);
if
(
ret
!=
KNOT_EOK
)
{
dbg_ns
(
"Failed to add followed RRSet into"
...
...
@@ -389,8 +365,7 @@ static int ns_follow_cname(const knot_node_t **node,
return
ret
;
}
ret
=
ns_add_rrsigs
(
rrset
,
resp
,
*
qname
,
add_rrset_to_resp
,
flags
);
ret
=
ns_add_rrsigs
(
rrset
,
resp
,
*
qname
,
flags
);
if
(
ret
!=
KNOT_EOK
)
{
dbg_ns
(
"Failed to add RRSIG for followed RRSet "
...
...
@@ -464,7 +439,7 @@ dbg_ns_exec_verb(
static
int
ns_put_answer
(
const
knot_node_t
*
node
,
const
knot_zone_contents_t
*
zone
,
const
knot_dname_t
*
name
,
uint16_t
type
,
knot_p
acke
t_t
*
resp
,
int
*
added
,
uint16_t
type
,
knot_p
k
t_t
*
resp
,
int
*
added
,
int
check_any
)
{
*
added
=
0
;
...
...
@@ -482,7 +457,7 @@ dbg_ns_exec_verb(
// if ANY not allowed, set TC bit
if
(
check_any
&&
knot_zone_contents_any_disabled
(
zone
))
{
knot_
response_set_tc
(
resp
);
knot_
wire_set_tc
(
resp
->
wire
);
break
;
}
...
...
@@ -507,8 +482,8 @@ dbg_ns_exec_verb(
break
;
}
ret
=
knot_response_add_rrset_answer
(
resp
,
rrset
,
0
);
assert
(
KNOT_PKT_IN_AN
(
resp
));
ret
=
knot_pkt_put
(
resp
,
0
,
rrset
,
0
);
if
(
ret
!=
KNOT_EOK
)
{
dbg_ns
(
"Failed add Answer RRSet: %s
\n
"
,
knot_strerror
(
ret
));
...
...
@@ -518,8 +493,8 @@ dbg_ns_exec_verb(
*
added
+=
1
;
}
ret
=
ns_add_rrsigs
(
rrset
,
resp
,
name
,
knot_response_add_rrset_answer
,
1
);
assert
(
KNOT_PKT_IN_AN
(
resp
));
ret
=
ns_add_rrsigs
(
rrset
,
resp
,
name
,
1
);
if
(
ret
!=
KNOT_EOK
)
{
dbg_ns
(
"Failed add RRSIGs for Answer RRSet: %s"
"
\n
"
,
knot_strerror
(
ret
));
...
...
@@ -557,7 +532,8 @@ dbg_ns_exec_verb(
break
;
}
ret
=
knot_response_add_rrset_answer
(
resp
,
rrset
,
0
);
assert
(
KNOT_PKT_IN_AN
(
resp
));
ret
=
knot_pkt_put
(
resp
,
0
,
rrset
,
0
);
if
(
ret
!=
KNOT_EOK
)
{
dbg_ns
(
"Failed add Answer RRSet: %s
\n
"
,
knot_strerror
(
ret
));
...
...
@@ -583,7 +559,8 @@ dbg_ns_exec_verb(
break
;
}
ret
=
knot_response_add_rrset_answer
(
resp
,
rrset2
,
0
);
assert
(
KNOT_PKT_IN_AN
(
resp
));
ret
=
knot_pkt_put
(
resp
,
0
,
rrset2
,
0
);
if
(
ret
!=
KNOT_EOK
)
{
dbg_ns
(
"Failed add Answer RRSet: %s
\n
"
,
knot_strerror
(
ret
));
...
...
@@ -592,8 +569,8 @@ dbg_ns_exec_verb(
*
added
+=
1
;
ret
=
ns_add_rrsigs
(
rrset
,
resp
,
name
,
knot_response_add_rrset_answer
,
1
);
assert
(
KNOT_PKT_IN_AN
(
resp
));
ret
=
ns_add_rrsigs
(
rrset
,
resp
,
name
,
1
);
if
(
ret
!=
KNOT_EOK
)
{
dbg_ns
(
"Failed add RRSIGs for Answer RRSet: %s"
...
...
@@ -627,9 +604,12 @@ dbg_ns_exec_verb(
* \param resp Response where to add the Additional data.
* \param rrset RRSet to get the Additional data for.
*/
static
int
ns_put_additional_for_rrset
(
knot_packet_t
*
resp
,
const
knot_rrset_t
*
rrset
)
static
int
ns_put_additional_for_rrset
(
knot_pkt_t
*
resp
,
uint16_t
rr_id
)
{
assert
(
KNOT_PKT_IN_AR
(
resp
));
assert
(
rr_id
<
resp
->
rrset_count
);
const
knot_rrset_t
*
rrset
=
resp
->
rr
[
rr_id
];
knot_rrinfo_t
*
rrinfo
=
&
resp
->
rr_info
[
rr_id
];
const
knot_node_t
*
node
=
NULL
,
*
encloser
=
NULL
,
*
prev
=
NULL
;
int
ret
=
0
;
...
...
@@ -639,6 +619,7 @@ static int ns_put_additional_for_rrset(knot_packet_t *resp,
for
(
uint16_t
i
=
0
;
i
<
knot_rrset_rdata_rr_count
(
rrset
);
i
++
)
{
dbg_ns_verb
(
"Getting name from RDATA, type %u..
\n
"
,
knot_rrset_type
(
rrset
));
uint16_t
compr_hint
=
knot_pkt_compr_hint
(
rrinfo
,
COMPR_HINT_RDATA
+
i
);
const
knot_dname_t
*
dname
=
knot_rdata_name
(
rrset
,
i
);
assert
(
dname
);
dbg_ns_exec_detail
(
...
...
@@ -670,8 +651,8 @@ dbg_ns_exec(
dbg_ns_detail
(
"Found CNAME in node.
\n
"
);
const
knot_dname_t
*
dname
=
knot_node_owner
(
node
);
ret
=
ns_follow_cname
(
&
node
,
&
dname
,
resp
,
knot_response_add_rrset_additional
,
0
);
assert
(
KNOT_PKT_IN_AR
(
resp
));
ret
=
ns_follow_cname
(
&
node
,
&
dname
,
resp
,
0
);
if
(
ret
!=
KNOT_EOK
)
{
dbg_ns
(
"Failed to follow CNAME.
\n
"
);
return
ret
;
...
...
@@ -693,8 +674,9 @@ dbg_ns_exec(
return
ret
;
}
ret
=
knot_response_add_rrset_additional
(
resp
,
rrset_add2
,
KNOT_PF_NOTRUNC
|
KNOT_PF_CHECKDUP
);
assert
(
KNOT_PKT_IN_AR
(
resp
));
ret
=
knot_pkt_put
(
resp
,
compr_hint
,
rrset_add2
,
KNOT_PF_NOTRUNC
|
KNOT_PF_CHECKDUP
);
if
(
ret
!=
KNOT_EOK
)
{
dbg_ns
(
"Failed to add A RRSet to "
...
...
@@ -703,8 +685,8 @@ dbg_ns_exec(
return
ret
;
}
ret
=
ns_add_rrsigs
(
rrset_add
,
resp
,
dname
,
knot_response_add_rrset_additional
,
0
);
assert
(
KNOT_PKT_IN_AR
(
resp
));
ret
=
ns_add_rrsigs
(
rrset_add
,
resp
,
dname
,
0
);
if
(
ret
!=
KNOT_EOK
)
{
dbg_ns
(
"Failed to add RRSIGs for A RR"
...
...
@@ -729,8 +711,9 @@ dbg_ns_exec(
return
ret
;
}
ret
=
knot_response_add_rrset_additional
(
resp
,
rrset_add2
,
KNOT_PF_NOTRUNC
|
KNOT_PF_CHECKDUP
);
assert
(
KNOT_PKT_IN_AR
(
resp
));
ret
=
knot_pkt_put
(
resp
,
compr_hint
,
rrset_add2
,
KNOT_PF_NOTRUNC
|
KNOT_PF_CHECKDUP
);
if
(
ret
!=
KNOT_EOK
)
{
dbg_ns
(
"Failed to add AAAA RRSet to "
...
...
@@ -738,8 +721,8 @@ dbg_ns_exec(
return
ret
;
}
ret
=
ns_add_rrsigs
(
rrset_add
,
resp
,
dname
,
knot_response_add_rrset_additional
,
0
);
assert
(
KNOT_PKT_IN_AR
(
resp
));
ret
=
ns_add_rrsigs
(
rrset_add
,
resp
,
dname
,
0
);
if
(
ret
!=
KNOT_EOK
)
{
dbg_ns
(
"Failed to add RRSIG for AAAA RR"
...
...
@@ -783,37 +766,27 @@ static int ns_additional_needed(uint16_t qtype)
*
* \param resp Response to process.
*/
static
int
ns_put_additional
(
knot_p
acke
t_t
*
resp
)
static
int
ns_put_additional
(
knot_p
k
t_t
*
resp
)
{
dbg_ns_verb
(
"ADDITIONAL SECTION PROCESSING
\n
"
);
const
knot_rrset_t
*
rrset
=
NULL
;
int
ret
=
0
;
for
(
int
i
=
0
;
i
<
knot_packet_answer_rrset_count
(
resp
);
++
i
)
{
rrset
=
knot_packet_answer_rrset
(
resp
,
i
);
assert
(
rrset
!=
NULL
);
if
(
ns_additional_needed
(
knot_rrset_type
(
rrset
)))
{
ret
=
ns_put_additional_for_rrset
(
resp
,
rrset
);
if
(
ret
!=
KNOT_EOK
)
{
// if error, do not try to add other RRSets
return
ret
;
}
}
}
for
(
int
i
=
0
;
i
<
knot_packet_authority_rrset_count
(
resp
);
++
i
)
{
rrset
=
knot_packet_authority_rrset
(
resp
,
i
);
if
(
ns_additional_needed
(
knot_rrset_type
(
rrset
)))
{
ret
=
ns_put_additional_for_rrset
(
resp
,
rrset
);
/* Begin AR section. */
int
ret
=
KNOT_EOK
;
knot_pkt_begin
(
resp
,
KNOT_ADDITIONAL
);
knot_pkt_put_opt
(
resp
);
/* Scan all RRs in AN+NS. */
uint16_t
rr_count
=
resp
->
rrset_count
;
for
(
uint16_t
i
=
0
;
i
<
rr_count
;
++
i
)
{
if
(
ns_additional_needed
(
knot_rrset_type
(
resp
->
rr
[
i
])))
{
ret
=
ns_put_additional_for_rrset
(
resp
,
i
);
if
(
ret
!=
KNOT_EOK
)
{
// if error, do not try to add other RRSets
return
ret
;
break
;
}
}
}
return
KNOT_EOK
;
return
ret
;
}
/*----------------------------------------------------------------------------*/
...
...
@@ -824,15 +797,16 @@ static int ns_put_additional(knot_packet_t *resp)
* \param resp Response where to add the RRSet.
*/
static
int
ns_put_authority_ns
(
const
knot_zone_contents_t
*
zone
,
knot_p
acke
t_t
*
resp
)
knot_p
k
t_t
*
resp
)
{
dbg_ns_verb
(
"PUTTING AUTHORITY NS
\n
"
);
assert
(
KNOT_PKT_IN_NS
(
resp
));
knot_rrset_t
*
ns_rrset
=
knot_node_get_rrset
(
knot_zone_contents_apex
(
zone
),
KNOT_RRTYPE_NS
);
if
(
ns_rrset
!=
NULL
)
{
int
ret
=
knot_
response_add_rrset_authority
(
resp
,
ns_rrset
,
KNOT_PF_NOTRUNC
|
KNOT_PF_CHECKDUP
);
int
ret
=
knot_
pkt_put
(
resp
,
0
,
ns_rrset
,
KNOT_PF_NOTRUNC
|
KNOT_PF_CHECKDUP
);
if
(
ret
!=
KNOT_EOK
)
{
dbg_ns
(
"Failed to add Authority NSs to response.
\n
"
);
...
...
@@ -842,8 +816,7 @@ static int ns_put_authority_ns(const knot_zone_contents_t *zone,
/*! \bug This is strange, it should either fit both NS+RRSIG or
* nothing. This would leave the last NS without RRSIG. */
ret
=
ns_add_rrsigs
(
ns_rrset
,
resp
,
knot_node_owner
(
knot_zone_contents_apex
(
zone
)),
knot_response_add_rrset_authority
,
0
);
knot_zone_contents_apex
(
zone
)),
0
);
if
(
ret
!=
KNOT_EOK
)
{
dbg_ns
(
"Failed to add RRSIGs for Authority NSs to "
...
...
@@ -863,8 +836,9 @@ static int ns_put_authority_ns(const knot_zone_contents_t *zone,
* \param resp Response where to add the RRSet.
*/
static
int
ns_put_authority_soa
(
const
knot_zone_contents_t
*
zone
,
knot_p
acke
t_t
*
resp
)
knot_p
k
t_t
*
resp
)
{
assert
(
KNOT_PKT_IN_NS
(
resp
));
dbg_ns_verb
(
"PUTTING AUTHORITY SOA
\n
"
);
int
ret
;
...
...
@@ -875,6 +849,7 @@ static int ns_put_authority_soa(const knot_zone_contents_t *zone,
// if SOA's TTL is larger than MINIMUM, copy the RRSet and set
// MINIMUM as TTL
uint32_t
flags
=
KNOT_PF_NOTRUNC
;
uint32_t
min
=
knot_rdata_soa_minimum
(
soa_rrset
);
if
(
min
<
knot_rrset_ttl
(
soa_rrset
))
{
knot_rrset_t
*
soa_copy
=
NULL
;
...
...
@@ -889,23 +864,19 @@ static int ns_put_authority_soa(const knot_zone_contents_t *zone,
knot_rrset_set_ttl
(
soa_copy
,
min
);
soa_rrset
=
soa_copy
;
/* Need to add it as temporary, so it get's freed. */
ret
=
knot_packet_add_tmp_rrset
(
resp
,
soa_copy
);
if
(
ret
!=
KNOT_EOK
)
{
knot_rrset_deep_free
(
&
soa_copy
,
1
);
return
ret
;
}
flags
|=
KNOT_PF_FREE
;
}
assert
(
soa_rrset
!=
NULL
);
ret
=
knot_
response_add_rrset_authority
(
resp
,
soa_rrset
,
KNOT_PF_NOTRUNC
);
assert
(
KNOT_PKT_IN_NS
(
resp
));
ret
=
knot_
pkt_put
(
resp
,
0
,
soa_rrset
,
flags
);
if
(
ret
!=
KNOT_EOK
)
{
return
ret
;
}
ret
=
ns_add_rrsigs
(
soa_rrset
,
resp
,
knot_node_owner
(
knot_zone_contents_apex
(
zone
)),
knot_response_add_rrset_authority
,
0
);
0
);
return
ret
;
}
...
...
@@ -951,10 +922,10 @@ static knot_dname_t *ns_next_closer(const knot_dname_t *closest_encloser,
* \param resp Response where to add the RRSets.
*/
static
int
ns_put_nsec3_from_node
(
const
knot_node_t
*
node
,
knot_p
acke
t_t
*
resp
)
knot_p
k
t_t
*
resp
)
{
assert
(
DNSSEC_ENABLED
&&
knot_
query_dnssec_requested
(
knot_packet_query
(
resp
)
));
&&
knot_
pkt_have_dnssec
(
resp
->
query
));
knot_rrset_t
*
rrset
=
knot_node_get_rrset
(
node
,
KNOT_RRTYPE_NSEC3
);
//assert(rrset != NULL);
...
...
@@ -966,12 +937,14 @@ static int ns_put_nsec3_from_node(const knot_node_t *node,
int
res
=
KNOT_EOK
;
if
(
knot_rrset_rdata_rr_count
(
rrset
))
{
res
=
knot_response_add_rrset_authority
(
resp
,
rrset
,
KNOT_PF_CHECKDUP
);
assert
(
KNOT_PKT_IN_NS
(
resp
));
res
=
knot_pkt_put
(
resp
,
0
,
rrset
,
KNOT_PF_CHECKDUP
);
}
// add RRSIG for the RRSet
if
(
res
==
KNOT_EOK
&&
(
rrset
=
knot_rrset_get_rrsigs
(
rrset
))
!=
NULL
&&
knot_rrset_rdata_rr_count
(
rrset
))
{
res
=
knot_response_add_rrset_authority
(
resp
,
rrset
,
0
);
assert
(
KNOT_PKT_IN_NS
(
resp
));
res
=
knot_pkt_put
(
resp
,
0
,
rrset
,
0
);