Commit 46fb173b authored by Michael Graff's avatar Michael Graff
Browse files

add 'attributes' flags to lwres packets

parent c9373cc5
......@@ -43,6 +43,7 @@ struct lwres_lwpacket {
#define LWRES_LWPACKETFLAG_RESPONSE 0x0001U /* if set, pkt is a response */
#define LWRES_LWPACKETVERSION_0 0
/*
......
......@@ -123,6 +123,7 @@ struct lwres_addr {
typedef struct {
/* public */
lwres_uint32_t attributes;
lwres_uint32_t addrtypes;
lwres_uint16_t namelen;
char *name;
......@@ -130,6 +131,7 @@ typedef struct {
typedef struct {
/* public */
lwres_uint32_t attributes;
lwres_uint16_t naliases;
lwres_uint16_t naddrs;
char *realname;
......@@ -148,11 +150,13 @@ typedef struct {
#define LWRES_OPCODE_GETNAMEBYADDR 0x00010002U
typedef struct {
/* public */
lwres_uint32_t attributes;
lwres_addr_t addr;
} lwres_gnbarequest_t;
typedef struct {
/* public */
lwres_uint32_t attributes;
lwres_uint16_t naliases;
char *realname;
char **aliases;
......
......@@ -112,7 +112,7 @@ lwres_gabnrequest_render(lwres_context_t *ctx, lwres_gabnrequest_t *req,
datalen = strlen(req->name);
payload_length = 2 + req->namelen + 1 + 4;
payload_length = 4 + 4 + 2 + req->namelen + 1;
buflen = LWRES_LWPACKET_LENGTH + payload_length;
buf = CTXMALLOC(buflen);
......@@ -138,6 +138,11 @@ lwres_gabnrequest_render(lwres_context_t *ctx, lwres_gabnrequest_t *req,
INSIST(SPACE_OK(b, payload_length));
/*
* Attributes.
*/
lwres_buffer_putuint32(b, req->attributes);
/*
* Address types we'll accept.
*/
......@@ -174,7 +179,7 @@ lwres_gabnresponse_render(lwres_context_t *ctx, lwres_gabnresponse_t *req,
REQUIRE(b != NULL);
/* naliases, naddrs */
payload_length = 2 * 2;
payload_length = 4 + 2 + 2;
/* real name encoding */
payload_length += 2 + req->realnamelen + 1;
/* each alias */
......@@ -211,15 +216,20 @@ lwres_gabnresponse_render(lwres_context_t *ctx, lwres_gabnresponse_t *req,
return (ret);
}
/* encode naliases and naddrs */
/*
* Check space needed here.
*/
INSIST(SPACE_OK(b, payload_length));
INSIST(SPACE_OK(b, sizeof(lwres_uint16_t) * 2));
/* Attributes. */
lwres_buffer_putuint32(b, req->attributes);
/* encode naliases and naddrs */
lwres_buffer_putuint16(b, req->naliases);
lwres_buffer_putuint16(b, req->naddrs);
/* encode the real name */
datalen = req->realnamelen;
INSIST(SPACE_OK(b, (unsigned int)(datalen + 2 + 1)));
lwres_buffer_putuint16(b, datalen);
lwres_buffer_putmem(b, req->realname, datalen);
lwres_buffer_putuint8(b, 0);
......@@ -227,7 +237,6 @@ lwres_gabnresponse_render(lwres_context_t *ctx, lwres_gabnresponse_t *req,
/* encode the aliases */
for (x = 0 ; x < req->naliases ; x++) {
datalen = req->aliaslen[x];
INSIST(SPACE_OK(b, (unsigned int)(datalen + 2 + 1)));
lwres_buffer_putuint16(b, datalen);
lwres_buffer_putmem(b, req->aliases[x], datalen);
lwres_buffer_putuint8(b, 0);
......@@ -237,7 +246,6 @@ lwres_gabnresponse_render(lwres_context_t *ctx, lwres_gabnresponse_t *req,
addr = LWRES_LIST_HEAD(req->addrs);
while (addr != NULL) {
datalen = addr->length + 2 + 4;
INSIST(SPACE_OK(b, datalen));
lwres_buffer_putuint32(b, addr->family);
lwres_buffer_putuint16(b, addr->length);
lwres_buffer_putmem(b, addr->address, addr->length);
......@@ -258,6 +266,7 @@ lwres_gabnrequest_parse(lwres_context_t *ctx, lwres_buffer_t *b,
char *name;
lwres_gabnrequest_t *gabn;
lwres_uint32_t addrtypes;
lwres_uint32_t attributes;
lwres_uint16_t namelen;
REQUIRE(ctx != NULL);
......@@ -268,9 +277,10 @@ lwres_gabnrequest_parse(lwres_context_t *ctx, lwres_buffer_t *b,
if ((pkt->flags & LWRES_LWPACKETFLAG_RESPONSE) != 0)
return (LWRES_R_FAILURE);
if (!SPACE_REMAINING(b, 4))
if (!SPACE_REMAINING(b, 4 + 4))
return (LWRES_R_UNEXPECTEDEND);
attributes = lwres_buffer_getuint32(b);
addrtypes = lwres_buffer_getuint32(b);
/*
......@@ -287,6 +297,7 @@ lwres_gabnrequest_parse(lwres_context_t *ctx, lwres_buffer_t *b,
if (gabn == NULL)
return (LWRES_R_NOMEMORY);
gabn->attributes = attributes;
gabn->addrtypes = addrtypes;
gabn->name = name;
gabn->namelen = namelen;
......@@ -301,6 +312,7 @@ lwres_gabnresponse_parse(lwres_context_t *ctx, lwres_buffer_t *b,
{
lwres_result_t ret;
unsigned int x;
lwres_uint32_t attributes;
lwres_uint16_t naliases;
lwres_uint16_t naddrs;
lwres_gabnresponse_t *gabn;
......@@ -320,8 +332,9 @@ lwres_gabnresponse_parse(lwres_context_t *ctx, lwres_buffer_t *b,
/*
* Pull off the name itself
*/
if (!SPACE_REMAINING(b, sizeof(lwres_uint16_t) * 2))
if (!SPACE_REMAINING(b, 4 + 2 + 2))
return (LWRES_R_UNEXPECTEDEND);
attributes = lwres_buffer_getuint32(b);
naliases = lwres_buffer_getuint16(b);
naddrs = lwres_buffer_getuint16(b);
......@@ -333,6 +346,7 @@ lwres_gabnresponse_parse(lwres_context_t *ctx, lwres_buffer_t *b,
LWRES_LIST_INIT(gabn->addrs);
gabn->base = NULL;
gabn->attributes = attributes;
gabn->naliases = naliases;
gabn->naddrs = naddrs;
......
......@@ -46,8 +46,7 @@ lwres_gnbarequest_render(lwres_context_t *ctx, lwres_gnbarequest_t *req,
REQUIRE(pkt != NULL);
REQUIRE(b != NULL);
payload_length = sizeof(lwres_uint32_t) + sizeof(lwres_uint16_t)
+ req->addr.length;
payload_length = 4 + 4 + 2 + + req->addr.length;
buflen = LWRES_LWPACKET_LENGTH + payload_length;
buf = CTXMALLOC(buflen);
......@@ -76,6 +75,7 @@ lwres_gnbarequest_render(lwres_context_t *ctx, lwres_gnbarequest_t *req,
* Put the length and the data. We know this will fit because we
* just checked for it.
*/
lwres_buffer_putuint32(b, req->attributes);
lwres_buffer_putuint32(b, req->addr.family);
lwres_buffer_putuint16(b, req->addr.length);
lwres_buffer_putmem(b, req->addr.address, req->addr.length);
......@@ -101,12 +101,13 @@ lwres_gnbaresponse_render(lwres_context_t *ctx, lwres_gnbaresponse_t *req,
REQUIRE(pkt != NULL);
REQUIRE(b != NULL);
/* naliases */
payload_length = sizeof(lwres_uint16_t);
/* real name encoding */
payload_length += 2 + req->realnamelen + 1;
/* each alias */
for (x = 0 ; x < req->naliases ; x++)
/*
* Calculate packet size.
*/
payload_length = 4; /* attributes */
payload_length += 2; /* naliases */
payload_length += 2 + req->realnamelen + 1; /* real name encoding */
for (x = 0 ; x < req->naliases ; x++) /* each alias */
payload_length += 2 + req->aliaslen[x] + 1;
buflen = LWRES_LWPACKET_LENGTH + payload_length;
......@@ -129,13 +130,14 @@ lwres_gnbaresponse_render(lwres_context_t *ctx, lwres_gnbaresponse_t *req,
return (ret);
}
INSIST(SPACE_OK(b, payload_length));
lwres_buffer_putuint32(b, req->attributes);
/* encode naliases */
INSIST(SPACE_OK(b, sizeof(lwres_uint16_t) * 2));
lwres_buffer_putuint16(b, req->naliases);
/* encode the real name */
datalen = req->realnamelen;
INSIST(SPACE_OK(b, (unsigned int)(2 + req->realnamelen + 1)));
lwres_buffer_putuint16(b, datalen);
lwres_buffer_putmem(b, req->realname, datalen);
lwres_buffer_putuint8(b, 0);
......@@ -143,7 +145,6 @@ lwres_gnbaresponse_render(lwres_context_t *ctx, lwres_gnbaresponse_t *req,
/* encode the aliases */
for (x = 0 ; x < req->naliases ; x++) {
datalen = req->aliaslen[x];
INSIST(SPACE_OK(b, (unsigned int)(2 + req->aliaslen[x] + 1)));
lwres_buffer_putuint16(b, datalen);
lwres_buffer_putmem(b, req->aliases[x], datalen);
lwres_buffer_putuint8(b, 0);
......@@ -173,6 +174,11 @@ lwres_gnbarequest_parse(lwres_context_t *ctx, lwres_buffer_t *b,
if (gnba == NULL)
return (LWRES_R_NOMEMORY);
if (!SPACE_REMAINING(b, 4))
return (LWRES_R_UNEXPECTEDEND);
gnba->attributes = lwres_buffer_getuint32(b);
ret = lwres_addr_parse(b, &gnba->addr);
if (ret != LWRES_R_SUCCESS)
goto out;
......@@ -198,6 +204,7 @@ lwres_gnbaresponse_parse(lwres_context_t *ctx, lwres_buffer_t *b,
{
int ret;
unsigned int x;
lwres_uint32_t attributes;
lwres_uint16_t naliases;
lwres_gnbaresponse_t *gnba;
......@@ -214,8 +221,9 @@ lwres_gnbaresponse_parse(lwres_context_t *ctx, lwres_buffer_t *b,
/*
* Pull off the name itself
*/
if (!SPACE_REMAINING(b, sizeof(lwres_uint16_t)))
if (!SPACE_REMAINING(b, 4 + 2))
return (LWRES_R_UNEXPECTEDEND);
attributes = lwres_buffer_getuint32(b);
naliases = lwres_buffer_getuint16(b);
gnba = CTXMALLOC(sizeof(lwres_gnbaresponse_t));
......@@ -225,6 +233,7 @@ lwres_gnbaresponse_parse(lwres_context_t *ctx, lwres_buffer_t *b,
gnba->aliases = NULL;
gnba->aliaslen = NULL;
gnba->attributes = attributes;
gnba->naliases = naliases;
if (naliases > 0) {
......@@ -306,7 +315,8 @@ lwres_gnbaresponse_free(lwres_context_t *ctx, lwres_gnbaresponse_t **structp)
if (gnba->naliases > 0) {
CTXFREE(gnba->aliases, sizeof(char *) * gnba->naliases);
CTXFREE(gnba->aliaslen, sizeof(lwres_uint16_t) * gnba->naliases);
CTXFREE(gnba->aliaslen,
sizeof(lwres_uint16_t) * gnba->naliases);
}
if (gnba->base != NULL)
CTXFREE(gnba->base, gnba->baselen);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment