wks_11.c revision 34416a7954da96c5a5f5803fe02f059cb94bf6fd
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews/*
279c6ec074be17dce62dd1b2c6ed7c2cc56a7b78David Lawrence * Copyright (C) 2004, 2007, 2009, 2011, 2012 Internet Systems Consortium, Inc. ("ISC")
281bfa2a98f1d1721538086e1b550185559f1d8bMark Andrews * Copyright (C) 1999-2002 Internet Software Consortium.
281bfa2a98f1d1721538086e1b550185559f1d8bMark Andrews *
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * Permission to use, copy, modify, and/or distribute this software for any
279c6ec074be17dce62dd1b2c6ed7c2cc56a7b78David Lawrence * purpose with or without fee is hereby granted, provided that the above
279c6ec074be17dce62dd1b2c6ed7c2cc56a7b78David Lawrence * copyright notice and this permission notice appear in all copies.
279c6ec074be17dce62dd1b2c6ed7c2cc56a7b78David Lawrence *
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
281bfa2a98f1d1721538086e1b550185559f1d8bMark Andrews * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
281bfa2a98f1d1721538086e1b550185559f1d8bMark Andrews * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
281bfa2a98f1d1721538086e1b550185559f1d8bMark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
281bfa2a98f1d1721538086e1b550185559f1d8bMark Andrews * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
281bfa2a98f1d1721538086e1b550185559f1d8bMark Andrews * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
281bfa2a98f1d1721538086e1b550185559f1d8bMark Andrews * PERFORMANCE OF THIS SOFTWARE.
281bfa2a98f1d1721538086e1b550185559f1d8bMark Andrews */
279c6ec074be17dce62dd1b2c6ed7c2cc56a7b78David Lawrence
279c6ec074be17dce62dd1b2c6ed7c2cc56a7b78David Lawrence/* $Id$ */
43fe2897fc80bbec2115310ca79d432a252f3ea4Mark Andrews
a14613fce99dee3cad5bf842fd6be78f8e463582Brian Wellington/* Reviewed: Fri Mar 17 15:01:49 PST 2000 by explorer */
279c6ec074be17dce62dd1b2c6ed7c2cc56a7b78David Lawrence
279c6ec074be17dce62dd1b2c6ed7c2cc56a7b78David Lawrence#ifndef RDATA_IN_1_WKS_11_C
279c6ec074be17dce62dd1b2c6ed7c2cc56a7b78David Lawrence#define RDATA_IN_1_WKS_11_C
279c6ec074be17dce62dd1b2c6ed7c2cc56a7b78David Lawrence
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley#include <limits.h>
fd837244be31850a764863688bce11df9ce972f4Andreas Gustafsson#include <stdlib.h>
fd837244be31850a764863688bce11df9ce972f4Andreas Gustafsson
fd837244be31850a764863688bce11df9ce972f4Andreas Gustafsson#include <isc/net.h>
a30e7fc23415fd238d067a8a871607bca36068baMichael Graff#include <isc/netdb.h>
a30e7fc23415fd238d067a8a871607bca36068baMichael Graff#include <isc/once.h>
a30e7fc23415fd238d067a8a871607bca36068baMichael Graff
8d4257cff01b3821abcb9a21f46c6c6a43bb1e72Bob Halley#define RRTYPE_WKS_ATTRIBUTES (0)
8d4257cff01b3821abcb9a21f46c6c6a43bb1e72Bob Halley
8d4257cff01b3821abcb9a21f46c6c6a43bb1e72Bob Halleystatic isc_mutex_t wks_lock;
8d4257cff01b3821abcb9a21f46c6c6a43bb1e72Bob Halley
8d4257cff01b3821abcb9a21f46c6c6a43bb1e72Bob Halleystatic void init_lock(void) {
8d4257cff01b3821abcb9a21f46c6c6a43bb1e72Bob Halley RUNTIME_CHECK(isc_mutex_init(&wks_lock) == ISC_R_SUCCESS);
dc97fe4ed08488d314ab5bc8e99ed839542cf411David Lawrence}
dc97fe4ed08488d314ab5bc8e99ed839542cf411David Lawrence
dc97fe4ed08488d314ab5bc8e99ed839542cf411David Lawrencestatic isc_boolean_t
8d4257cff01b3821abcb9a21f46c6c6a43bb1e72Bob Halleymygetprotobyname(const char *name, long *proto) {
8d4257cff01b3821abcb9a21f46c6c6a43bb1e72Bob Halley struct protoent *pe;
8d4257cff01b3821abcb9a21f46c6c6a43bb1e72Bob Halley
50453ad879d0d93854de5a3385776bd799e8f35cBob Halley LOCK(&wks_lock);
50453ad879d0d93854de5a3385776bd799e8f35cBob Halley pe = getprotobyname(name);
50453ad879d0d93854de5a3385776bd799e8f35cBob Halley if (pe != NULL)
7005cfed8cd3296d356883dcb414979f22e06b13Brian Wellington *proto = pe->p_proto;
7005cfed8cd3296d356883dcb414979f22e06b13Brian Wellington UNLOCK(&wks_lock);
7005cfed8cd3296d356883dcb414979f22e06b13Brian Wellington return (ISC_TF(pe != NULL));
6f7660093e70d3a7c80738b681ac0f5c1b661c00Mark Andrews}
6f7660093e70d3a7c80738b681ac0f5c1b661c00Mark Andrews
6f7660093e70d3a7c80738b681ac0f5c1b661c00Mark Andrewsstatic isc_boolean_t
d8dcd6ad4617cc8d7df979bd62101fa9c4bac1bcBob Halleymygetservbyname(const char *name, const char *proto, long *port) {
d8dcd6ad4617cc8d7df979bd62101fa9c4bac1bcBob Halley struct servent *se;
d8dcd6ad4617cc8d7df979bd62101fa9c4bac1bcBob Halley
baf7c7e589f313f10b29d9119811fc4d36c2e4bcMark Andrews LOCK(&wks_lock);
baf7c7e589f313f10b29d9119811fc4d36c2e4bcMark Andrews se = getservbyname(name, proto);
baf7c7e589f313f10b29d9119811fc4d36c2e4bcMark Andrews if (se != NULL)
d2a97368971414ffd71907e404fe02591dc5ed83Mark Andrews *port = ntohs(se->s_port);
a30e7fc23415fd238d067a8a871607bca36068baMichael Graff UNLOCK(&wks_lock);
a30e7fc23415fd238d067a8a871607bca36068baMichael Graff return (ISC_TF(se != NULL));
5c00d1c90030a311d2700970fa7cffc8f828a48cBob Halley}
5c00d1c90030a311d2700970fa7cffc8f828a48cBob Halley
194b6a25192581bbc8ec731e32e8989042b202a4Michael Graffstatic inline isc_result_t
6286983c506433d642b23e64845c50be30f2a7f6Mark Andrewsfromtext_in_wks(ARGS_FROMTEXT) {
6286983c506433d642b23e64845c50be30f2a7f6Mark Andrews static isc_once_t once = ISC_ONCE_INIT;
6286983c506433d642b23e64845c50be30f2a7f6Mark Andrews isc_token_t token;
8313838954d67250d0ed7edf67fba5da0790d1a7Michael Graff isc_region_t region;
8313838954d67250d0ed7edf67fba5da0790d1a7Michael Graff struct in_addr addr;
8313838954d67250d0ed7edf67fba5da0790d1a7Michael Graff char *e;
703e1c0bb66f3cd3d300358ca0c1fdf3cb5fb1c5Brian Wellington long proto;
8313838954d67250d0ed7edf67fba5da0790d1a7Michael Graff unsigned char bm[8*1024]; /* 64k bits */
8313838954d67250d0ed7edf67fba5da0790d1a7Michael Graff long port;
703e1c0bb66f3cd3d300358ca0c1fdf3cb5fb1c5Brian Wellington long maxport = -1;
703e1c0bb66f3cd3d300358ca0c1fdf3cb5fb1c5Brian Wellington const char *ps = NULL;
703e1c0bb66f3cd3d300358ca0c1fdf3cb5fb1c5Brian Wellington unsigned int n;
b15c543f7957fbb4284f0fc20b3278f2a411d272Mark Andrews char service[32];
b15c543f7957fbb4284f0fc20b3278f2a411d272Mark Andrews int i;
b15c543f7957fbb4284f0fc20b3278f2a411d272Mark Andrews
0eb2572d79822d02ea05448ce4e5f1759c73d171Michael Graff REQUIRE(type == 11);
0eb2572d79822d02ea05448ce4e5f1759c73d171Michael Graff REQUIRE(rdclass == 1);
0eb2572d79822d02ea05448ce4e5f1759c73d171Michael Graff
0eb2572d79822d02ea05448ce4e5f1759c73d171Michael Graff UNUSED(type);
0eb2572d79822d02ea05448ce4e5f1759c73d171Michael Graff UNUSED(origin);
4108eed5092156cf0407a97a9bd8ab7775164694Brian Wellington UNUSED(options);
4108eed5092156cf0407a97a9bd8ab7775164694Brian Wellington UNUSED(rdclass);
4108eed5092156cf0407a97a9bd8ab7775164694Brian Wellington
3f123dcc2fe5d2cd08ca91b732741d86a4036906Brian Wellington RUNTIME_CHECK(isc_once_do(&once, init_lock) == ISC_R_SUCCESS);
3f123dcc2fe5d2cd08ca91b732741d86a4036906Brian Wellington
3f123dcc2fe5d2cd08ca91b732741d86a4036906Brian Wellington /*
64b92523f9333ba053f4b2860335583be455b0b3Brian Wellington * IPv4 dotted quad.
64b92523f9333ba053f4b2860335583be455b0b3Brian Wellington */
64b92523f9333ba053f4b2860335583be455b0b3Brian Wellington RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
876753d5ce1be48f3218fb4875fac501f8adfd6cDavid Lawrence ISC_FALSE));
876753d5ce1be48f3218fb4875fac501f8adfd6cDavid Lawrence
876753d5ce1be48f3218fb4875fac501f8adfd6cDavid Lawrence isc_buffer_availableregion(target, &region);
876753d5ce1be48f3218fb4875fac501f8adfd6cDavid Lawrence if (getquad(DNS_AS_STR(token), &addr, lexer, callbacks) != 1)
876753d5ce1be48f3218fb4875fac501f8adfd6cDavid Lawrence RETTOK(DNS_R_BADDOTTEDQUAD);
876753d5ce1be48f3218fb4875fac501f8adfd6cDavid Lawrence if (region.length < 4)
876753d5ce1be48f3218fb4875fac501f8adfd6cDavid Lawrence return (ISC_R_NOSPACE);
ed71ea51c6ecb5d7d659b6e6a20f6b3f5c2678c6David Lawrence memcpy(region.base, &addr, 4);
ed71ea51c6ecb5d7d659b6e6a20f6b3f5c2678c6David Lawrence isc_buffer_add(target, 4);
ed71ea51c6ecb5d7d659b6e6a20f6b3f5c2678c6David Lawrence
ed71ea51c6ecb5d7d659b6e6a20f6b3f5c2678c6David Lawrence /*
ed71ea51c6ecb5d7d659b6e6a20f6b3f5c2678c6David Lawrence * Protocol.
ed71ea51c6ecb5d7d659b6e6a20f6b3f5c2678c6David Lawrence */
49a2cf8f211213712d452287ae8e121cf59e3178David Lawrence RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
49a2cf8f211213712d452287ae8e121cf59e3178David Lawrence ISC_FALSE));
49a2cf8f211213712d452287ae8e121cf59e3178David Lawrence
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews proto = strtol(DNS_AS_STR(token), &e, 10);
49a2cf8f211213712d452287ae8e121cf59e3178David Lawrence if (*e == 0)
49a2cf8f211213712d452287ae8e121cf59e3178David Lawrence ;
49a2cf8f211213712d452287ae8e121cf59e3178David Lawrence else if (!mygetprotobyname(DNS_AS_STR(token), &proto))
49a2cf8f211213712d452287ae8e121cf59e3178David Lawrence RETTOK(DNS_R_UNKNOWNPROTO);
49a2cf8f211213712d452287ae8e121cf59e3178David Lawrence
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews if (proto < 0 || proto > 0xff)
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews RETTOK(ISC_R_RANGE);
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews if (proto == IPPROTO_TCP)
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews ps = "tcp";
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews else if (proto == IPPROTO_UDP)
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews ps = "udp";
49a2cf8f211213712d452287ae8e121cf59e3178David Lawrence
49a2cf8f211213712d452287ae8e121cf59e3178David Lawrence RETERR(uint8_tobuffer(proto, target));
a14613fce99dee3cad5bf842fd6be78f8e463582Brian Wellington
529ff4b4959fb157194f985394951108ff5286e4Brian Wellington memset(bm, 0, sizeof(bm));
a14613fce99dee3cad5bf842fd6be78f8e463582Brian Wellington do {
489b76292622f5bc18bf1a18845f8166a73bd797Brian Wellington RETERR(isc_lex_getmastertoken(lexer, &token,
489b76292622f5bc18bf1a18845f8166a73bd797Brian Wellington isc_tokentype_string, ISC_TRUE));
489b76292622f5bc18bf1a18845f8166a73bd797Brian Wellington if (token.type != isc_tokentype_string)
bff8ac12a8c099257bdbf7d0c55d2d5b77591926Mark Andrews break;
bff8ac12a8c099257bdbf7d0c55d2d5b77591926Mark Andrews
bff8ac12a8c099257bdbf7d0c55d2d5b77591926Mark Andrews /*
fd837244be31850a764863688bce11df9ce972f4Andreas Gustafsson * Lowercase the service string as some getservbyname() are
fd837244be31850a764863688bce11df9ce972f4Andreas Gustafsson * case sensitive and the database is usually in lowercase.
fd837244be31850a764863688bce11df9ce972f4Andreas Gustafsson */
43fe2897fc80bbec2115310ca79d432a252f3ea4Mark Andrews strncpy(service, DNS_AS_STR(token), sizeof(service));
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews service[sizeof(service)-1] = '\0';
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews for (i = strlen(service) - 1; i >= 0; i--)
cffc2e06f906dd048af4cc27d487deb157f5a082Mark Andrews if (isupper(service[i]&0xff))
cffc2e06f906dd048af4cc27d487deb157f5a082Mark Andrews service[i] = tolower(service[i]&0xff);
cffc2e06f906dd048af4cc27d487deb157f5a082Mark Andrews
43fe2897fc80bbec2115310ca79d432a252f3ea4Mark Andrews port = strtol(DNS_AS_STR(token), &e, 10);
43fe2897fc80bbec2115310ca79d432a252f3ea4Mark Andrews if (*e == 0)
43fe2897fc80bbec2115310ca79d432a252f3ea4Mark Andrews ;
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews else if (!mygetservbyname(service, ps, &port) &&
64b92523f9333ba053f4b2860335583be455b0b3Brian Wellington !mygetservbyname(DNS_AS_STR(token), ps, &port))
64b92523f9333ba053f4b2860335583be455b0b3Brian Wellington RETTOK(DNS_R_UNKNOWNSERVICE);
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews if (port < 0 || port > 0xffff)
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley RETTOK(ISC_R_RANGE);
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley if (port > maxport)
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews maxport = port;
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews bm[port / 8] |= (0x80 >> (port % 8));
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews } while (1);
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews /*
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews * Let upper layer handle eol/eof.
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews */
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews isc_lex_ungettoken(lexer, &token);
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews n = (maxport + 8) / 8;
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews return (mem_tobuffer(target, bm, n));
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews}
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrewsstatic inline isc_result_t
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrewstotext_in_wks(ARGS_TOTEXT) {
23ac30603a7639bea1d331537634b079b046b122Mark Andrews isc_region_t sr;
23ac30603a7639bea1d331537634b079b046b122Mark Andrews unsigned short proto;
23ac30603a7639bea1d331537634b079b046b122Mark Andrews char buf[sizeof("65535")];
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews unsigned int i, j;
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews UNUSED(tctx);
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews
5c00d1c90030a311d2700970fa7cffc8f828a48cBob Halley REQUIRE(rdata->type == 11);
5c00d1c90030a311d2700970fa7cffc8f828a48cBob Halley REQUIRE(rdata->rdclass == 1);
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews REQUIRE(rdata->length >= 5);
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews dns_rdata_toregion(rdata, &sr);
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews RETERR(inet_totext(AF_INET, &sr, target));
fd837244be31850a764863688bce11df9ce972f4Andreas Gustafsson isc_region_consume(&sr, 4);
fd837244be31850a764863688bce11df9ce972f4Andreas Gustafsson
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews proto = uint8_fromregion(&sr);
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews sprintf(buf, "%u", proto);
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews RETERR(str_totext(" ", target));
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews RETERR(str_totext(buf, target));
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews isc_region_consume(&sr, 1);
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews INSIST(sr.length <= 8*1024);
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews for (i = 0; i < sr.length; i++) {
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews if (sr.base[i] != 0)
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews for (j = 0; j < 8; j++)
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews if ((sr.base[i] & (0x80 >> j)) != 0) {
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews sprintf(buf, "%u", i * 8 + j);
2b50e0d877db0d668f363d50914232f82ad8c454Mark Andrews RETERR(str_totext(" ", target));
2b50e0d877db0d668f363d50914232f82ad8c454Mark Andrews RETERR(str_totext(buf, target));
2b50e0d877db0d668f363d50914232f82ad8c454Mark Andrews }
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews }
f8727bd90366af835f551da1b5e1fdfcd2d3d01fBrian Wellington
f8727bd90366af835f551da1b5e1fdfcd2d3d01fBrian Wellington return (ISC_R_SUCCESS);
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews}
f8727bd90366af835f551da1b5e1fdfcd2d3d01fBrian Wellington
134ba0e08a0ae9a564a8d8628fc633377d3fc239Bob Halleystatic inline isc_result_t
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrewsfromwire_in_wks(ARGS_FROMWIRE) {
203596d27c225ea195e4faad4f19388c6e96ac80Bob Halley isc_region_t sr;
203596d27c225ea195e4faad4f19388c6e96ac80Bob Halley isc_region_t tr;
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews REQUIRE(type == 11);
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews REQUIRE(rdclass == 1);
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews
fd837244be31850a764863688bce11df9ce972f4Andreas Gustafsson UNUSED(type);
fd837244be31850a764863688bce11df9ce972f4Andreas Gustafsson UNUSED(dctx);
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews UNUSED(options);
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley UNUSED(rdclass);
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews isc_buffer_activeregion(source, &sr);
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews isc_buffer_availableregion(target, &tr);
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews if (sr.length < 5)
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews return (ISC_R_UNEXPECTEDEND);
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews if (sr.length > 8 * 1024 + 5)
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews return (DNS_R_EXTRADATA);
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley if (tr.length < sr.length)
15bfd48fc5552ff1aae766021f42a250c001a098Michael Graff return (ISC_R_NOSPACE);
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews memcpy(tr.base, sr.base, sr.length);
882350d11c90de9de6fc1cead25690c8114b0b95Michael Graff isc_buffer_add(target, sr.length);
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews isc_buffer_forward(source, sr.length);
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews
15bfd48fc5552ff1aae766021f42a250c001a098Michael Graff return (ISC_R_SUCCESS);
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews}
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrewsstatic inline isc_result_t
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrewstowire_in_wks(ARGS_TOWIRE) {
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews isc_region_t sr;
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews UNUSED(cctx);
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews REQUIRE(rdata->type == 11);
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews REQUIRE(rdata->rdclass == 1);
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews REQUIRE(rdata->length != 0);
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews dns_rdata_toregion(rdata, &sr);
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews return (mem_tobuffer(target, sr.base, sr.length));
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews}
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrewsstatic inline int
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrewscompare_in_wks(ARGS_COMPARE) {
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews isc_region_t r1;
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews isc_region_t r2;
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews REQUIRE(rdata1->type == rdata2->type);
281bfa2a98f1d1721538086e1b550185559f1d8bMark Andrews REQUIRE(rdata1->rdclass == rdata2->rdclass);
281bfa2a98f1d1721538086e1b550185559f1d8bMark Andrews REQUIRE(rdata1->type == 11);
281bfa2a98f1d1721538086e1b550185559f1d8bMark Andrews REQUIRE(rdata1->rdclass == 1);
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews REQUIRE(rdata1->length != 0);
281bfa2a98f1d1721538086e1b550185559f1d8bMark Andrews REQUIRE(rdata2->length != 0);
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews dns_rdata_toregion(rdata1, &r1);
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews dns_rdata_toregion(rdata2, &r2);
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews return (isc_region_compare(&r1, &r2));
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews}
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews
static inline isc_result_t
fromstruct_in_wks(ARGS_FROMSTRUCT) {
dns_rdata_in_wks_t *wks = source;
isc_uint32_t a;
REQUIRE(type == 11);
REQUIRE(rdclass == 1);
REQUIRE(source != NULL);
REQUIRE(wks->common.rdtype == type);
REQUIRE(wks->common.rdclass == rdclass);
REQUIRE((wks->map != NULL && wks->map_len <= 8*1024) ||
wks->map_len == 0);
UNUSED(type);
UNUSED(rdclass);
a = ntohl(wks->in_addr.s_addr);
RETERR(uint32_tobuffer(a, target));
RETERR(uint8_tobuffer(wks->protocol, target));
return (mem_tobuffer(target, wks->map, wks->map_len));
}
static inline isc_result_t
tostruct_in_wks(ARGS_TOSTRUCT) {
dns_rdata_in_wks_t *wks = target;
isc_uint32_t n;
isc_region_t region;
REQUIRE(rdata->type == 11);
REQUIRE(rdata->rdclass == 1);
REQUIRE(rdata->length != 0);
wks->common.rdclass = rdata->rdclass;
wks->common.rdtype = rdata->type;
ISC_LINK_INIT(&wks->common, link);
dns_rdata_toregion(rdata, &region);
n = uint32_fromregion(&region);
wks->in_addr.s_addr = htonl(n);
isc_region_consume(&region, 4);
wks->protocol = uint8_fromregion(&region);
isc_region_consume(&region, 1);
wks->map_len = region.length;
wks->map = mem_maybedup(mctx, region.base, region.length);
if (wks->map == NULL)
return (ISC_R_NOMEMORY);
wks->mctx = mctx;
return (ISC_R_SUCCESS);
}
static inline void
freestruct_in_wks(ARGS_FREESTRUCT) {
dns_rdata_in_wks_t *wks = source;
REQUIRE(source != NULL);
REQUIRE(wks->common.rdtype == 11);
REQUIRE(wks->common.rdclass == 1);
if (wks->mctx == NULL)
return;
if (wks->map != NULL)
isc_mem_free(wks->mctx, wks->map);
wks->mctx = NULL;
}
static inline isc_result_t
additionaldata_in_wks(ARGS_ADDLDATA) {
UNUSED(rdata);
UNUSED(add);
UNUSED(arg);
REQUIRE(rdata->type == 11);
REQUIRE(rdata->rdclass == 1);
return (ISC_R_SUCCESS);
}
static inline isc_result_t
digest_in_wks(ARGS_DIGEST) {
isc_region_t r;
REQUIRE(rdata->type == 11);
REQUIRE(rdata->rdclass == 1);
dns_rdata_toregion(rdata, &r);
return ((digest)(arg, &r));
}
static inline isc_boolean_t
checkowner_in_wks(ARGS_CHECKOWNER) {
REQUIRE(type == 11);
REQUIRE(rdclass == 1);
UNUSED(type);
UNUSED(rdclass);
return (dns_name_ishostname(name, wildcard));
}
static inline isc_boolean_t
checknames_in_wks(ARGS_CHECKNAMES) {
REQUIRE(rdata->type == 11);
REQUIRE(rdata->rdclass == 1);
UNUSED(rdata);
UNUSED(owner);
UNUSED(bad);
return (ISC_TRUE);
}
static inline int
casecompare_in_wks(ARGS_COMPARE) {
return (compare_in_wks(rdata1, rdata2));
}
#endif /* RDATA_IN_1_WKS_11_C */