mirror of
https://github.com/isc-projects/bind9.git
synced 2026-02-26 19:41:04 -05:00
noop packets are now fully functional.
This commit is contained in:
parent
617361c2c3
commit
658db10162
4 changed files with 102 additions and 48 deletions
|
|
@ -23,5 +23,6 @@
|
|||
#define INSIST(x) assert(x)
|
||||
|
||||
#define SPACE_OK(b, s) (LWRES_BUFFER_AVAILABLECOUNT(b) >= s)
|
||||
#define SPACE_REMAINING(b, s) (LWRES_BUFFER_REMAINING(b) >= s)
|
||||
|
||||
#endif /* LWRES_ASSERT_P_H */
|
||||
|
|
|
|||
|
|
@ -131,6 +131,8 @@ ISC_LANG_BEGINDECLS
|
|||
*/
|
||||
#define LWRES_BUFFER_AVAILABLECOUNT(b) ((b)->length - (b)->used)
|
||||
|
||||
#define LWRES_BUFFER_REMAINING(b) ((b)->used - (b)->current)
|
||||
|
||||
/*
|
||||
* Note that the buffer structure is public. This is principally so buffer
|
||||
* operations can be implemented using macros. Applications are strongly
|
||||
|
|
|
|||
|
|
@ -91,8 +91,6 @@
|
|||
#define LWRES_OPCODE_NOOP 0x00000000U
|
||||
|
||||
typedef struct {
|
||||
/* header info */
|
||||
isc_uint32_t serial;
|
||||
/* public */
|
||||
isc_uint16_t datalength;
|
||||
unsigned char *data;
|
||||
|
|
@ -102,9 +100,6 @@ typedef struct {
|
|||
} lwres_nooprequest_t;
|
||||
|
||||
typedef struct {
|
||||
/* header info */
|
||||
isc_uint32_t serial;
|
||||
isc_uint32_t result;
|
||||
/* public */
|
||||
isc_uint16_t datalength;
|
||||
unsigned char *data;
|
||||
|
|
@ -184,13 +179,11 @@ typedef struct {
|
|||
ISC_LANG_BEGINDECLS
|
||||
|
||||
int
|
||||
lwres_gabnrequest_render(lwres_context_t *ctx,
|
||||
lwres_gabnrequest_t *req,
|
||||
lwres_gabnrequest_render(lwres_context_t *ctx, lwres_gabnrequest_t *req,
|
||||
isc_uint32_t maxrecv, lwres_buffer_t *b);
|
||||
|
||||
int
|
||||
lwres_gabnresponse_render(lwres_context_t *ctx,
|
||||
lwres_gabnresponse_t *req,
|
||||
lwres_gabnresponse_render(lwres_context_t *ctx, lwres_gabnresponse_t *req,
|
||||
isc_uint32_t maxrecv, lwres_buffer_t *b);
|
||||
|
||||
int
|
||||
|
|
@ -294,7 +287,7 @@ lwres_gnbaresponse_free(lwres_context_t *ctx, lwres_gnbaresponse_t **structp);
|
|||
|
||||
int
|
||||
lwres_nooprequest_render(lwres_context_t *ctx, lwres_nooprequest_t *req,
|
||||
isc_uint32_t maxrecv, lwres_buffer_t *b);
|
||||
lwres_lwpacket_t *pkt, lwres_buffer_t *b);
|
||||
/*
|
||||
* Allocate space and render into wire format a noop request packet.
|
||||
*
|
||||
|
|
@ -306,6 +299,9 @@ lwres_nooprequest_render(lwres_context_t *ctx, lwres_nooprequest_t *req,
|
|||
* buffer structure will be initialized to contain the wire-format
|
||||
* noop request packet.
|
||||
*
|
||||
* Caller needs to fill in parts of "pkt" before calling:
|
||||
* serial, maxrecv, result.
|
||||
*
|
||||
* Returns:
|
||||
*
|
||||
* Returns 0 on success, non-zero on failure.
|
||||
|
|
@ -316,14 +312,23 @@ lwres_nooprequest_render(lwres_context_t *ctx, lwres_nooprequest_t *req,
|
|||
|
||||
int
|
||||
lwres_noopresponse_render(lwres_context_t *ctx, lwres_noopresponse_t *req,
|
||||
isc_uint32_t maxrecv, lwres_buffer_t *b);
|
||||
lwres_lwpacket_t *pkt, lwres_buffer_t *b);
|
||||
|
||||
int
|
||||
lwres_nooprequest_parse(lwres_context_t *ctx, lwres_buffer_t *b,
|
||||
lwres_nooprequest_t **structp);
|
||||
lwres_lwpacket_t *pkt, lwres_nooprequest_t **structp);
|
||||
/*
|
||||
* Parse a noop request. Note that to get here, the lwpacket must have
|
||||
* already been parsed and removed by the caller, otherwise it would be
|
||||
* pretty hard for it to know this is the right function to call.
|
||||
*
|
||||
* The function verifies bits of the header, but does not modify it.
|
||||
*/
|
||||
|
||||
int
|
||||
lwres_noopresponse_parse(lwres_context_t *ctx, lwres_noopresponse_t **structp);
|
||||
lwres_noopresponse_parse(lwres_context_t *ctx, lwres_buffer_t *b,
|
||||
lwres_lwpacket_t *pkt,
|
||||
lwres_noopresponse_t **structp);
|
||||
|
||||
void
|
||||
lwres_nooprequest_free(lwres_context_t *ctx, lwres_nooprequest_t **structp);
|
||||
|
|
|
|||
|
|
@ -31,9 +31,8 @@
|
|||
|
||||
int
|
||||
lwres_nooprequest_render(lwres_context_t *ctx, lwres_nooprequest_t *req,
|
||||
isc_uint32_t maxrecv, lwres_buffer_t *b)
|
||||
lwres_lwpacket_t *pkt, lwres_buffer_t *b)
|
||||
{
|
||||
lwres_lwpacket_t pkt;
|
||||
unsigned char *buf;
|
||||
size_t buflen;
|
||||
int ret;
|
||||
|
|
@ -53,17 +52,15 @@ lwres_nooprequest_render(lwres_context_t *ctx, lwres_nooprequest_t *req,
|
|||
}
|
||||
lwres_buffer_init(b, buf, buflen);
|
||||
|
||||
pkt.length = buflen;
|
||||
pkt.version = LWRES_LWPACKETVERSION_0;
|
||||
pkt.flags = 0;
|
||||
pkt.serial = req->serial;
|
||||
pkt.opcode = LWRES_OPCODE_NOOP;
|
||||
pkt.result = 0;
|
||||
pkt.recvlength = maxrecv;
|
||||
pkt.authtype = 0;
|
||||
pkt.authlength = 0;
|
||||
pkt->length = buflen;
|
||||
pkt->version = LWRES_LWPACKETVERSION_0;
|
||||
pkt->flags = 0;
|
||||
pkt->opcode = LWRES_OPCODE_NOOP;
|
||||
pkt->result = 0;
|
||||
pkt->authtype = 0;
|
||||
pkt->authlength = 0;
|
||||
|
||||
ret = lwres_lwpacket_renderheader(b, &pkt);
|
||||
ret = lwres_lwpacket_renderheader(b, pkt);
|
||||
if (ret != 0) {
|
||||
lwres_buffer_invalidate(b);
|
||||
CTXFREE(buf, buflen);
|
||||
|
|
@ -86,9 +83,8 @@ lwres_nooprequest_render(lwres_context_t *ctx, lwres_nooprequest_t *req,
|
|||
|
||||
int
|
||||
lwres_noopresponse_render(lwres_context_t *ctx, lwres_noopresponse_t *req,
|
||||
isc_uint32_t maxrecv, lwres_buffer_t *b)
|
||||
lwres_lwpacket_t *pkt, lwres_buffer_t *b)
|
||||
{
|
||||
lwres_lwpacket_t pkt;
|
||||
unsigned char *buf;
|
||||
size_t buflen;
|
||||
int ret;
|
||||
|
|
@ -108,17 +104,14 @@ lwres_noopresponse_render(lwres_context_t *ctx, lwres_noopresponse_t *req,
|
|||
}
|
||||
lwres_buffer_init(b, buf, buflen);
|
||||
|
||||
pkt.length = buflen;
|
||||
pkt.version = LWRES_LWPACKETVERSION_0;
|
||||
pkt.flags = LWRES_LWPACKETFLAG_RESPONSE;
|
||||
pkt.serial = req->serial;
|
||||
pkt.opcode = LWRES_OPCODE_NOOP;
|
||||
pkt.result = req->result;
|
||||
pkt.recvlength = maxrecv;
|
||||
pkt.authtype = 0;
|
||||
pkt.authlength = 0;
|
||||
pkt->length = buflen;
|
||||
pkt->version = LWRES_LWPACKETVERSION_0;
|
||||
pkt->flags |= LWRES_LWPACKETFLAG_RESPONSE;
|
||||
pkt->opcode = LWRES_OPCODE_NOOP;
|
||||
pkt->authtype = 0;
|
||||
pkt->authlength = 0;
|
||||
|
||||
ret = lwres_lwpacket_renderheader(b, &pkt);
|
||||
ret = lwres_lwpacket_renderheader(b, pkt);
|
||||
if (ret != 0) {
|
||||
lwres_buffer_invalidate(b);
|
||||
CTXFREE(buf, buflen);
|
||||
|
|
@ -141,31 +134,84 @@ lwres_noopresponse_render(lwres_context_t *ctx, lwres_noopresponse_t *req,
|
|||
|
||||
int
|
||||
lwres_nooprequest_parse(lwres_context_t *ctx, lwres_buffer_t *b,
|
||||
lwres_nooprequest_t **structp)
|
||||
lwres_lwpacket_t *pkt, lwres_nooprequest_t **structp)
|
||||
{
|
||||
lwres_lwpacket_t pkt;
|
||||
int ret;
|
||||
lwres_nooprequest_t *req;
|
||||
|
||||
REQUIRE(ctx != NULL);
|
||||
REQUIRE(structp != NULL && *structp == NULL);
|
||||
REQUIRE(b != NULL);
|
||||
REQUIRE(pkt != NULL);
|
||||
REQUIRE(structp != NULL && *structp == NULL);
|
||||
|
||||
/*
|
||||
* First, parse out the header.
|
||||
*/
|
||||
ret = lwres_lwpacket_parseheader(&pkt, b);
|
||||
if (ret != 0)
|
||||
return (ret);
|
||||
if ((pkt->flags & LWRES_LWPACKETFLAG_RESPONSE) != 0)
|
||||
return (-1);
|
||||
|
||||
|
||||
req = CTXMALLOC(sizeof(lwres_nooprequest_t));
|
||||
if (req == NULL)
|
||||
return (-1);
|
||||
|
||||
if (!SPACE_REMAINING(b, sizeof(isc_uint16_t))) {
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
req->datalength = lwres_buffer_getuint16(b);
|
||||
|
||||
if (!SPACE_REMAINING(b, req->datalength)) {
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
req->data = b->base + b->current;
|
||||
|
||||
/* success! */
|
||||
*structp = req;
|
||||
return (0);
|
||||
|
||||
/* Error return */
|
||||
out:
|
||||
CTXFREE(req, sizeof(lwres_nooprequest_t));
|
||||
return (ret);
|
||||
}
|
||||
|
||||
int
|
||||
lwres_noopresponse_parse(lwres_context_t *ctx, lwres_noopresponse_t **structp)
|
||||
lwres_noopresponse_parse(lwres_context_t *ctx, lwres_buffer_t *b,
|
||||
lwres_lwpacket_t *pkt, lwres_noopresponse_t **structp)
|
||||
{
|
||||
int ret;
|
||||
lwres_noopresponse_t *req;
|
||||
|
||||
REQUIRE(ctx != NULL);
|
||||
REQUIRE(b != NULL);
|
||||
REQUIRE(pkt != NULL);
|
||||
REQUIRE(structp != NULL && *structp == NULL);
|
||||
|
||||
if ((pkt->flags & LWRES_LWPACKETFLAG_RESPONSE) == 0)
|
||||
return (-1);
|
||||
|
||||
req = CTXMALLOC(sizeof(lwres_noopresponse_t));
|
||||
if (req == NULL)
|
||||
return (-1);
|
||||
|
||||
if (!SPACE_REMAINING(b, sizeof(isc_uint16_t))) {
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
req->datalength = lwres_buffer_getuint16(b);
|
||||
|
||||
if (!SPACE_REMAINING(b, req->datalength)) {
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
req->data = b->base + b->current;
|
||||
|
||||
/* success! */
|
||||
*structp = req;
|
||||
return (0);
|
||||
|
||||
/* Error return */
|
||||
out:
|
||||
CTXFREE(req, sizeof(lwres_noopresponse_t));
|
||||
return (ret);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
|||
Loading…
Reference in a new issue