mx_15.c revision 52637f592f705ca93fadc218e403fd55e8ce4aea
1633838b8255282d10af15c5c84cee5a51466712Bob Halley/*
5fa46bc91672ef5737aee6f99763161511566c24Tinderbox User * Copyright (C) 1998, 1999 Internet Software Consortium.
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews *
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * Permission to use, copy, modify, and distribute this software for any
ec5347e2c775f027573ce5648b910361aa926c01Automatic Updater * purpose with or without fee is hereby granted, provided that the above
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * copyright notice and this permission notice appear in all copies.
1633838b8255282d10af15c5c84cee5a51466712Bob Halley *
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * SOFTWARE.
1633838b8255282d10af15c5c84cee5a51466712Bob Halley */
d25afd60ee2286cb171c4960a790f3d7041b6f85Bob Halley
28a8f5b0de57d269cf2845c69cb6abe18cbd3b3aMark Andrews /* $Id: mx_15.c,v 1.12 1999/02/22 07:24:01 marka Exp $ */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein#ifndef RDATA_GENERIC_MX_15_H
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence#define RDATA_GENERIC_MX_15_H
d25afd60ee2286cb171c4960a790f3d7041b6f85Bob Halley
d25afd60ee2286cb171c4960a790f3d7041b6f85Bob Halleystatic dns_result_t
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halleyfromtext_mx(dns_rdataclass_t class, dns_rdatatype_t type,
72bdbe3c70f415a717f59f72d04590d70acb380eMark Andrews isc_lex_t *lexer, dns_name_t *origin,
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley isc_boolean_t downcase, isc_buffer_t *target)
ddfe394c061049bbd71125ad41c3dd3092b2bbfdAndreas Gustafsson{
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews isc_token_t token;
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence dns_name_t name;
6cf369f528c4acd8182eada41ad83b8d97623db8Mark Andrews isc_buffer_t buffer;
fca5f81ad69098ea8abba130c7f841c951ef91c2Bob Halley
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence REQUIRE(type == 15);
6cf369f528c4acd8182eada41ad83b8d97623db8Mark Andrews
364a82f7c25b62967678027043425201a5e5171aBob Halley class = class; /*unused*/
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley
9192e92f7d0f4e78385a1d5f9b6607cc5bf0e42aBob Halley RETERR(gettoken(lexer, &token, isc_tokentype_number, ISC_FALSE));
3f8be559f0871022c78a229bad0eb09560b90909Evan Hunt
6d5032f9a23fe1197610114983c9938ac419b20cBrian Wellington RETERR(uint16_tobuffer(token.value.as_ulong, target));
6d5032f9a23fe1197610114983c9938ac419b20cBrian Wellington
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley RETERR(gettoken(lexer, &token, isc_tokentype_string, ISC_FALSE));
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley dns_name_init(&name, NULL);
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley buffer_fromregion(&buffer, &token.value.as_region,
95c86af1e92dae4ff837a39e7e2dcb7308dd9cceBob Halley ISC_BUFFERTYPE_TEXT);
95c86af1e92dae4ff837a39e7e2dcb7308dd9cceBob Halley origin = (origin != NULL) ? origin : dns_rootname;
95c86af1e92dae4ff837a39e7e2dcb7308dd9cceBob Halley return (dns_name_fromtext(&name, &buffer, origin, downcase, target));
95c86af1e92dae4ff837a39e7e2dcb7308dd9cceBob Halley}
95c86af1e92dae4ff837a39e7e2dcb7308dd9cceBob Halley
95c86af1e92dae4ff837a39e7e2dcb7308dd9cceBob Halleystatic dns_result_t
cee7525336d4710a64368875d92eb439d4d3efb1Mark Andrewstotext_mx(dns_rdata_t *rdata, dns_name_t *origin, isc_buffer_t *target) {
95c86af1e92dae4ff837a39e7e2dcb7308dd9cceBob Halley isc_region_t region;
95c86af1e92dae4ff837a39e7e2dcb7308dd9cceBob Halley dns_name_t name;
95c86af1e92dae4ff837a39e7e2dcb7308dd9cceBob Halley dns_name_t prefix;
95c86af1e92dae4ff837a39e7e2dcb7308dd9cceBob Halley isc_boolean_t sub;
95c86af1e92dae4ff837a39e7e2dcb7308dd9cceBob Halley char buf[sizeof "64000"];
95c86af1e92dae4ff837a39e7e2dcb7308dd9cceBob Halley unsigned short num;
ecb6c5782ea248307e86c4bceac6c371d27576a6David Lawrence
95c86af1e92dae4ff837a39e7e2dcb7308dd9cceBob Halley REQUIRE(rdata->type == 15);
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley dns_name_init(&name, NULL);
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley dns_name_init(&prefix, NULL);
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley dns_rdata_toregion(rdata, &region);
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley num = uint16_fromregion(&region);
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley isc_region_consume(&region, 2);
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley sprintf(buf, "%u", num);
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley RETERR(str_totext(buf, target));
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley RETERR(str_totext(" ", target));
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley dns_name_fromregion(&name, &region);
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley sub = name_prefix(&name, origin, &prefix);
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley return(dns_name_totext(&prefix, sub, target));
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley}
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halleystatic dns_result_t
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halleyfromwire_mx(dns_rdataclass_t class, dns_rdatatype_t type,
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley isc_buffer_t *source, dns_decompress_t *dctx,
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley isc_boolean_t downcase, isc_buffer_t *target)
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley{
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley dns_name_t name;
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley isc_region_t sregion;
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley isc_region_t tregion;
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley REQUIRE(type == 15);
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley class = class; /* unused */
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley dns_name_init(&name, NULL);
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley isc_buffer_active(source, &sregion);
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley isc_buffer_available(target, &tregion);
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley if (tregion.length < 2)
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley return (DNS_R_NOSPACE);
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley if (sregion.length < 2)
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley return (DNS_R_UNEXPECTEDEND);
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley memcpy(tregion.base, sregion.base, 2);
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley isc_buffer_forward(source, 2);
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley isc_buffer_add(target, 2);
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley return (dns_name_fromwire(&name, source, dctx, downcase, target));
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley}
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halleystatic dns_result_t
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halleytowire_mx(dns_rdata_t *rdata, dns_compress_t *cctx, isc_buffer_t *target) {
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley dns_name_t name;
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley isc_region_t region;
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley isc_region_t tr;
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley REQUIRE(rdata->type == 15);
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley if (dns_compress_getedns(cctx) >= 1)
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley dns_compress_setmethods(cctx, DNS_COMPRESS_ALL);
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley else
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14);
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley isc_buffer_available(target, &tr);
577179503f2eb7695ec668d8eeb41889a150e28fBob Halley dns_rdata_toregion(rdata, &region);
577179503f2eb7695ec668d8eeb41889a150e28fBob Halley if (tr.length < 2)
577179503f2eb7695ec668d8eeb41889a150e28fBob Halley return (DNS_R_NOSPACE);
86131d8d7aaf1bb8b8bfc7819985d05ea369b708Bob Halley memcpy(tr.base, region.base, 2);
86131d8d7aaf1bb8b8bfc7819985d05ea369b708Bob Halley isc_region_consume(&region, 2);
86131d8d7aaf1bb8b8bfc7819985d05ea369b708Bob Halley isc_buffer_add(target, 2);
86131d8d7aaf1bb8b8bfc7819985d05ea369b708Bob Halley
86131d8d7aaf1bb8b8bfc7819985d05ea369b708Bob Halley dns_name_init(&name, NULL);
86131d8d7aaf1bb8b8bfc7819985d05ea369b708Bob Halley dns_name_fromregion(&name, &region);
86131d8d7aaf1bb8b8bfc7819985d05ea369b708Bob Halley
86131d8d7aaf1bb8b8bfc7819985d05ea369b708Bob Halley return (dns_name_towire(&name, cctx, target));
86131d8d7aaf1bb8b8bfc7819985d05ea369b708Bob Halley}
86131d8d7aaf1bb8b8bfc7819985d05ea369b708Bob Halley
86131d8d7aaf1bb8b8bfc7819985d05ea369b708Bob Halleystatic int
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrencecompare_mx(dns_rdata_t *rdata1, dns_rdata_t *rdata2) {
86131d8d7aaf1bb8b8bfc7819985d05ea369b708Bob Halley dns_name_t name1;
86131d8d7aaf1bb8b8bfc7819985d05ea369b708Bob Halley dns_name_t name2;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein isc_region_t region1;
70fdfcd1fa7ebd059deffa9a2cecc29df96dfe52Bob Halley isc_region_t region2;
70fdfcd1fa7ebd059deffa9a2cecc29df96dfe52Bob Halley int result;
70fdfcd1fa7ebd059deffa9a2cecc29df96dfe52Bob Halley
70fdfcd1fa7ebd059deffa9a2cecc29df96dfe52Bob Halley REQUIRE(rdata1->type == rdata2->type);
70fdfcd1fa7ebd059deffa9a2cecc29df96dfe52Bob Halley REQUIRE(rdata1->class == rdata2->class);
70fdfcd1fa7ebd059deffa9a2cecc29df96dfe52Bob Halley REQUIRE(rdata1->type == 15);
70fdfcd1fa7ebd059deffa9a2cecc29df96dfe52Bob Halley
70fdfcd1fa7ebd059deffa9a2cecc29df96dfe52Bob Halley result = memcmp(rdata1->data, rdata2->data, 2);
70fdfcd1fa7ebd059deffa9a2cecc29df96dfe52Bob Halley if (result != 0)
70fdfcd1fa7ebd059deffa9a2cecc29df96dfe52Bob Halley return (result < 0 ? -1 : 1);
70fdfcd1fa7ebd059deffa9a2cecc29df96dfe52Bob Halley
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein dns_name_init(&name1, NULL);
08c8a934ceb2dfc6a5ebfd3be4ba5a1b3243bc73Bob Halley dns_name_init(&name2, NULL);
08c8a934ceb2dfc6a5ebfd3be4ba5a1b3243bc73Bob Halley
08c8a934ceb2dfc6a5ebfd3be4ba5a1b3243bc73Bob Halley dns_rdata_toregion(rdata1, &region1);
08c8a934ceb2dfc6a5ebfd3be4ba5a1b3243bc73Bob Halley dns_rdata_toregion(rdata2, &region2);
08c8a934ceb2dfc6a5ebfd3be4ba5a1b3243bc73Bob Halley
08c8a934ceb2dfc6a5ebfd3be4ba5a1b3243bc73Bob Halley isc_region_consume(&region1, 2);
08c8a934ceb2dfc6a5ebfd3be4ba5a1b3243bc73Bob Halley isc_region_consume(&region2, 2);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
4755b174df8221dff7e872f21d42b3572a74bf2fAndreas Gustafsson dns_name_fromregion(&name1, &region1);
4755b174df8221dff7e872f21d42b3572a74bf2fAndreas Gustafsson dns_name_fromregion(&name2, &region2);
4755b174df8221dff7e872f21d42b3572a74bf2fAndreas Gustafsson
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence return (dns_name_rdatacompare(&name1, &name2));
4755b174df8221dff7e872f21d42b3572a74bf2fAndreas Gustafsson}
4755b174df8221dff7e872f21d42b3572a74bf2fAndreas Gustafsson
4755b174df8221dff7e872f21d42b3572a74bf2fAndreas Gustafssonstatic dns_result_t
e672951ed28b2e9cc7a19c3d7fa4a258382f981cAutomatic Updaterfromstruct_mx(dns_rdataclass_t class, dns_rdatatype_t type, void *source,
4755b174df8221dff7e872f21d42b3572a74bf2fAndreas Gustafsson isc_buffer_t *target)
4755b174df8221dff7e872f21d42b3572a74bf2fAndreas Gustafsson{
4755b174df8221dff7e872f21d42b3572a74bf2fAndreas Gustafsson
4755b174df8221dff7e872f21d42b3572a74bf2fAndreas Gustafsson REQUIRE(type == 15);
4755b174df8221dff7e872f21d42b3572a74bf2fAndreas Gustafsson
4755b174df8221dff7e872f21d42b3572a74bf2fAndreas Gustafsson class = class; /*unused*/
4755b174df8221dff7e872f21d42b3572a74bf2fAndreas Gustafsson
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence source = source;
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley target = target;
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence
e61793f0865117ad87a19d6e245bea8f3b712d1bDanny Mayer return (DNS_R_NOTIMPLEMENTED);
4755b174df8221dff7e872f21d42b3572a74bf2fAndreas Gustafsson}
4755b174df8221dff7e872f21d42b3572a74bf2fAndreas Gustafsson
4755b174df8221dff7e872f21d42b3572a74bf2fAndreas Gustafssonstatic dns_result_t
4755b174df8221dff7e872f21d42b3572a74bf2fAndreas Gustafssontostruct_mx(dns_rdata_t *rdata, void *target) {
4755b174df8221dff7e872f21d42b3572a74bf2fAndreas Gustafsson
4755b174df8221dff7e872f21d42b3572a74bf2fAndreas Gustafsson REQUIRE(rdata->type == 15);
4755b174df8221dff7e872f21d42b3572a74bf2fAndreas Gustafsson
4755b174df8221dff7e872f21d42b3572a74bf2fAndreas Gustafsson target = target;
4755b174df8221dff7e872f21d42b3572a74bf2fAndreas Gustafsson
4755b174df8221dff7e872f21d42b3572a74bf2fAndreas Gustafsson return (DNS_R_NOTIMPLEMENTED);
4755b174df8221dff7e872f21d42b3572a74bf2fAndreas Gustafsson}
4755b174df8221dff7e872f21d42b3572a74bf2fAndreas Gustafsson#endif /* RDATA_GENERIC_MX_15_H */
5f120ce962b03e4dcf6f1974b9b896f0fa7cacb0Bob Halley