summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLubos Slovak <lubos.slovak@nic.cz>2012-04-17 19:01:35 +0200
committerLubos Slovak <lubos.slovak@nic.cz>2012-04-17 19:02:37 +0200
commit76bb74b46bb78d1360edbcbca988aa5d7cdca7fd (patch)
tree2fb81ac119f4e55879a21023deb2852aa183ec50
parentFixed some debug messages and removed unused code. (diff)
downloadknot-76bb74b46bb78d1360edbcbca988aa5d7cdca7fd.tar.xz
knot-76bb74b46bb78d1360edbcbca988aa5d7cdca7fd.zip
Fix: EDNS should not apply for TCP queries.
refs #1828 @2h
-rw-r--r--src/knot/server/tcp-handler.c3
-rw-r--r--src/knot/server/udp-handler.c5
-rw-r--r--src/knot/server/zones.c7
-rw-r--r--src/knot/server/zones.h3
-rw-r--r--src/libknot/nameserver/name-server.c17
-rw-r--r--src/libknot/nameserver/name-server.h7
6 files changed, 28 insertions, 14 deletions
diff --git a/src/knot/server/tcp-handler.c b/src/knot/server/tcp-handler.c
index e53e28695..5f79096b5 100644
--- a/src/knot/server/tcp-handler.c
+++ b/src/knot/server/tcp-handler.c
@@ -207,7 +207,8 @@ static int tcp_handle(tcp_worker_t *w, int fd, uint8_t *qbuf, size_t qbuf_maxlen
case KNOT_QUERY_NORMAL:
//res = knot_ns_answer_normal(ns, packet, qbuf, &resp_len);
if (zones_normal_query_answer(ns, packet, &addr,
- qbuf, &resp_len) == KNOT_EOK) {
+ qbuf, &resp_len,
+ NS_TRANSPORT_TCP) == KNOT_EOK) {
res = KNOTD_EOK;
}
break;
diff --git a/src/knot/server/udp-handler.c b/src/knot/server/udp-handler.c
index 73c557d01..80bc011d7 100644
--- a/src/knot/server/udp-handler.c
+++ b/src/knot/server/udp-handler.c
@@ -122,7 +122,7 @@ int udp_handle(int fd, uint8_t *qbuf, size_t qbuflen, size_t *resp_len,
/* Query types. */
case KNOT_QUERY_NORMAL:
res = zones_normal_query_answer(ns, packet, addr, qbuf,
- resp_len);
+ resp_len, NS_TRANSPORT_UDP);
// res = knot_ns_answer_normal(ns, packet, qbuf,
// resp_len);
break;
@@ -144,7 +144,8 @@ int udp_handle(int fd, uint8_t *qbuf, size_t qbuflen, size_t *resp_len,
*/
knot_packet_set_qtype(packet, KNOT_RRTYPE_SOA);
res = zones_normal_query_answer(ns, packet, addr,
- qbuf, resp_len);
+ qbuf, resp_len,
+ NS_TRANSPORT_UDP);
// res = knot_ns_answer_normal(ns, packet, qbuf,
// resp_len);
break;
diff --git a/src/knot/server/zones.c b/src/knot/server/zones.c
index ba6340d10..8ef605d75 100644
--- a/src/knot/server/zones.c
+++ b/src/knot/server/zones.c
@@ -1978,7 +1978,8 @@ int zones_xfr_check_zone(knot_ns_xfr_t *xfr, knot_rcode_t *rcode)
int zones_normal_query_answer(knot_nameserver_t *nameserver,
knot_packet_t *query, const sockaddr_t *addr,
- uint8_t *resp_wire, size_t *rsize)
+ uint8_t *resp_wire, size_t *rsize,
+ knot_ns_transport_t transport)
{
rcu_read_lock();
@@ -1986,7 +1987,9 @@ int zones_normal_query_answer(knot_nameserver_t *nameserver,
const knot_zone_t *zone = NULL;
dbg_zones_verb("Preparing response structure.\n");
- int ret = knot_ns_prep_normal_response(nameserver, query, &resp, &zone);
+ int ret = knot_ns_prep_normal_response(nameserver, query, &resp, &zone,
+ (transport == NS_TRANSPORT_TCP)
+ ? *rsize : 0);
// check for TSIG in the query
if (knot_packet_additional_rrset_count(query) > 0) {
diff --git a/src/knot/server/zones.h b/src/knot/server/zones.h
index 08f9df6db..bb95b9340 100644
--- a/src/knot/server/zones.h
+++ b/src/knot/server/zones.h
@@ -151,7 +151,8 @@ int zones_xfr_check_zone(knot_ns_xfr_t *xfr, knot_rcode_t *rcode);
*/
int zones_normal_query_answer(knot_nameserver_t *nameserver,
knot_packet_t *query, const sockaddr_t *addr,
- uint8_t *response_wire, size_t *rsize);
+ uint8_t *response_wire, size_t *rsize,
+ knot_ns_transport_t transport);
/*!
* \brief Processes normal response packet.
diff --git a/src/libknot/nameserver/name-server.c b/src/libknot/nameserver/name-server.c
index e1ccdd4de..213534c38 100644
--- a/src/libknot/nameserver/name-server.c
+++ b/src/libknot/nameserver/name-server.c
@@ -2877,7 +2877,7 @@ void knot_ns_error_response_full(knot_nameserver_t *nameserver,
int knot_ns_prep_normal_response(knot_nameserver_t *nameserver,
knot_packet_t *query, knot_packet_t **resp,
- const knot_zone_t **zone)
+ const knot_zone_t **zone, size_t max_size)
{
dbg_ns("knot_ns_prep_normal_response()\n");
@@ -2894,8 +2894,8 @@ int knot_ns_prep_normal_response(knot_nameserver_t *nameserver,
ret = knot_packet_parse_rest(query);
if (ret != KNOT_EOK) {
- dbg_ns("Failed to parse rest of the query: "
- "%s.\n", knot_strerror(ret));
+ dbg_ns("Failed to parse rest of the query: %s.\n",
+ knot_strerror(ret));
return ret;
}
@@ -2917,11 +2917,14 @@ int knot_ns_prep_normal_response(knot_nameserver_t *nameserver,
size_t resp_max_size = 0;
- //assert(*rsize >= MAX_UDP_PAYLOAD);
-
knot_packet_dump(query);
-
- if (knot_query_edns_supported(query)) {
+
+ if (max_size > 0) {
+ // if TCP is used, buffer size is the only constraint
+ assert(max_size > 0);
+ resp_max_size = max_size;
+ } else if (knot_query_edns_supported(query)) {
+ assert(max_size == 0);
if (knot_edns_get_payload(&query->opt_rr) <
knot_edns_get_payload(nameserver->opt_rr)) {
resp_max_size = knot_edns_get_payload(&query->opt_rr);
diff --git a/src/libknot/nameserver/name-server.h b/src/libknot/nameserver/name-server.h
index 42fa0f260..d40a7d92c 100644
--- a/src/libknot/nameserver/name-server.h
+++ b/src/libknot/nameserver/name-server.h
@@ -157,6 +157,11 @@ enum knot_ns_xfr_flag_t {
XFR_FLAG_AXFR_FINISHED = 1 << 2
};
+typedef enum knot_ns_transport {
+ NS_TRANSPORT_UDP = 1 << 0,
+ NS_TRANSPORT_TCP = 1 << 1
+} knot_ns_transport_t;
+
/*!
* \brief XFR request types.
*/
@@ -235,7 +240,7 @@ void knot_ns_error_response_full(knot_nameserver_t *nameserver,
int knot_ns_prep_normal_response(knot_nameserver_t *nameserver,
knot_packet_t *query, knot_packet_t **resp,
- const knot_zone_t **zone);
+ const knot_zone_t **zone, size_t max_size);
/*!
* \brief Creates a response for the given normal query using the data of the