cname_5.c revision 1ef8965366d91e02a4672c35a187d30aa4a4c72c
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley/*
279c6ec074be17dce62dd1b2c6ed7c2cc56a7b78David Lawrence * Copyright (C) 1998, 1999 Internet Software Consortium.
703e1c0bb66f3cd3d300358ca0c1fdf3cb5fb1c5Brian Wellington *
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * Permission to use, copy, modify, and 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 INTERNET SOFTWARE CONSORTIUM DISCLAIMS
a14613fce99dee3cad5bf842fd6be78f8e463582Brian Wellington * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
a14613fce99dee3cad5bf842fd6be78f8e463582Brian Wellington * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
a14613fce99dee3cad5bf842fd6be78f8e463582Brian Wellington * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
a14613fce99dee3cad5bf842fd6be78f8e463582Brian Wellington * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
a14613fce99dee3cad5bf842fd6be78f8e463582Brian Wellington * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
a14613fce99dee3cad5bf842fd6be78f8e463582Brian Wellington * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
a14613fce99dee3cad5bf842fd6be78f8e463582Brian Wellington * SOFTWARE.
a14613fce99dee3cad5bf842fd6be78f8e463582Brian Wellington */
279c6ec074be17dce62dd1b2c6ed7c2cc56a7b78David Lawrence
279c6ec074be17dce62dd1b2c6ed7c2cc56a7b78David Lawrence /* $Id: cname_5.c,v 1.11 1999/02/24 06:31:32 marka Exp $ */
703e1c0bb66f3cd3d300358ca0c1fdf3cb5fb1c5Brian Wellington
a14613fce99dee3cad5bf842fd6be78f8e463582Brian Wellington#ifndef RDATA_GENERIC_CNAME_5_H
279c6ec074be17dce62dd1b2c6ed7c2cc56a7b78David Lawrence#define RDATA_GENERIC_CNAME_5_H
279c6ec074be17dce62dd1b2c6ed7c2cc56a7b78David Lawrence
279c6ec074be17dce62dd1b2c6ed7c2cc56a7b78David Lawrencestatic dns_result_t
279c6ec074be17dce62dd1b2c6ed7c2cc56a7b78David Lawrencefromtext_cname(dns_rdataclass_t class, dns_rdatatype_t type,
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley isc_lex_t *lexer, dns_name_t *origin,
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley isc_boolean_t downcase, isc_buffer_t *target)
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley{
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley isc_token_t token;
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley dns_name_t name;
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley isc_buffer_t buffer;
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley REQUIRE(type == 5);
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley class = class; /*unused*/
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley RETERR(gettoken(lexer, &token, isc_tokentype_string, ISC_FALSE));
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley dns_name_init(&name, NULL);
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley buffer_fromregion(&buffer, &token.value.as_region,
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley ISC_BUFFERTYPE_TEXT);
90407942d3afe50f04ccea361de3b164a5a1702dMichael Graff origin = (origin != NULL) ? origin : dns_rootname;
90407942d3afe50f04ccea361de3b164a5a1702dMichael Graff return (dns_name_fromtext(&name, &buffer, origin, downcase, target));
90407942d3afe50f04ccea361de3b164a5a1702dMichael Graff}
90407942d3afe50f04ccea361de3b164a5a1702dMichael Graff
a30e7fc23415fd238d067a8a871607bca36068baMichael Graffstatic dns_result_t
a30e7fc23415fd238d067a8a871607bca36068baMichael Grafftotext_cname(dns_rdata_t *rdata, dns_name_t *origin, isc_buffer_t *target) {
a30e7fc23415fd238d067a8a871607bca36068baMichael Graff isc_region_t region;
8d4257cff01b3821abcb9a21f46c6c6a43bb1e72Bob Halley dns_name_t name;
8d4257cff01b3821abcb9a21f46c6c6a43bb1e72Bob Halley dns_name_t prefix;
8d4257cff01b3821abcb9a21f46c6c6a43bb1e72Bob Halley isc_boolean_t sub;
8d4257cff01b3821abcb9a21f46c6c6a43bb1e72Bob Halley
8d4257cff01b3821abcb9a21f46c6c6a43bb1e72Bob Halley REQUIRE(rdata->type == 5);
8d4257cff01b3821abcb9a21f46c6c6a43bb1e72Bob Halley
dc97fe4ed08488d314ab5bc8e99ed839542cf411David Lawrence dns_name_init(&name, NULL);
dc97fe4ed08488d314ab5bc8e99ed839542cf411David Lawrence dns_name_init(&prefix, NULL);
dc97fe4ed08488d314ab5bc8e99ed839542cf411David Lawrence
8d4257cff01b3821abcb9a21f46c6c6a43bb1e72Bob Halley dns_rdata_toregion(rdata, &region);
8d4257cff01b3821abcb9a21f46c6c6a43bb1e72Bob Halley dns_name_fromregion(&name, &region);
8d4257cff01b3821abcb9a21f46c6c6a43bb1e72Bob Halley
50453ad879d0d93854de5a3385776bd799e8f35cBob Halley sub = name_prefix(&name, origin, &prefix);
50453ad879d0d93854de5a3385776bd799e8f35cBob Halley
50453ad879d0d93854de5a3385776bd799e8f35cBob Halley return (dns_name_totext(&prefix, sub, target));
7005cfed8cd3296d356883dcb414979f22e06b13Brian Wellington}
7005cfed8cd3296d356883dcb414979f22e06b13Brian Wellington
7005cfed8cd3296d356883dcb414979f22e06b13Brian Wellingtonstatic dns_result_t
d8dcd6ad4617cc8d7df979bd62101fa9c4bac1bcBob Halleyfromwire_cname(dns_rdataclass_t class, dns_rdatatype_t type,
d8dcd6ad4617cc8d7df979bd62101fa9c4bac1bcBob Halley isc_buffer_t *source, dns_decompress_t *dctx,
d8dcd6ad4617cc8d7df979bd62101fa9c4bac1bcBob Halley isc_boolean_t downcase, isc_buffer_t *target)
194b6a25192581bbc8ec731e32e8989042b202a4Michael Graff{
a30e7fc23415fd238d067a8a871607bca36068baMichael Graff dns_name_t name;
a30e7fc23415fd238d067a8a871607bca36068baMichael Graff
5c00d1c90030a311d2700970fa7cffc8f828a48cBob Halley REQUIRE(type == 5);
5c00d1c90030a311d2700970fa7cffc8f828a48cBob Halley
194b6a25192581bbc8ec731e32e8989042b202a4Michael Graff class = class; /*unused*/
8313838954d67250d0ed7edf67fba5da0790d1a7Michael Graff
8313838954d67250d0ed7edf67fba5da0790d1a7Michael Graff if (dns_decompress_edns(dctx) >= 1 || !dns_decompress_strict(dctx))
8313838954d67250d0ed7edf67fba5da0790d1a7Michael Graff dns_decompress_setmethods(dctx, DNS_COMPRESS_ALL);
703e1c0bb66f3cd3d300358ca0c1fdf3cb5fb1c5Brian Wellington else
8313838954d67250d0ed7edf67fba5da0790d1a7Michael Graff dns_decompress_setmethods(dctx, DNS_COMPRESS_GLOBAL14);
8313838954d67250d0ed7edf67fba5da0790d1a7Michael Graff
703e1c0bb66f3cd3d300358ca0c1fdf3cb5fb1c5Brian Wellington dns_name_init(&name, NULL);
703e1c0bb66f3cd3d300358ca0c1fdf3cb5fb1c5Brian Wellington return(dns_name_fromwire(&name, source, dctx, downcase, target));
703e1c0bb66f3cd3d300358ca0c1fdf3cb5fb1c5Brian Wellington}
0eb2572d79822d02ea05448ce4e5f1759c73d171Michael Graff
0eb2572d79822d02ea05448ce4e5f1759c73d171Michael Graffstatic dns_result_t
0eb2572d79822d02ea05448ce4e5f1759c73d171Michael Grafftowire_cname(dns_rdata_t *rdata, dns_compress_t *cctx, isc_buffer_t *target) {
0eb2572d79822d02ea05448ce4e5f1759c73d171Michael Graff dns_name_t name;
0eb2572d79822d02ea05448ce4e5f1759c73d171Michael Graff isc_region_t region;
4108eed5092156cf0407a97a9bd8ab7775164694Brian Wellington
4108eed5092156cf0407a97a9bd8ab7775164694Brian Wellington REQUIRE(rdata->type == 5);
4108eed5092156cf0407a97a9bd8ab7775164694Brian Wellington
3f123dcc2fe5d2cd08ca91b732741d86a4036906Brian Wellington if (dns_compress_getedns(cctx) >= 1)
3f123dcc2fe5d2cd08ca91b732741d86a4036906Brian Wellington dns_compress_setmethods(cctx, DNS_COMPRESS_ALL);
3f123dcc2fe5d2cd08ca91b732741d86a4036906Brian Wellington else
17012a879742ceb6561dcc4ae3bcd4ff80dc9887David Lawrence dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14);
17012a879742ceb6561dcc4ae3bcd4ff80dc9887David Lawrence
17012a879742ceb6561dcc4ae3bcd4ff80dc9887David Lawrence dns_name_init(&name, NULL);
876753d5ce1be48f3218fb4875fac501f8adfd6cDavid Lawrence dns_rdata_toregion(rdata, &region);
876753d5ce1be48f3218fb4875fac501f8adfd6cDavid Lawrence dns_name_fromregion(&name, &region);
876753d5ce1be48f3218fb4875fac501f8adfd6cDavid Lawrence
876753d5ce1be48f3218fb4875fac501f8adfd6cDavid Lawrence return (dns_name_towire(&name, cctx, target));
876753d5ce1be48f3218fb4875fac501f8adfd6cDavid Lawrence}
876753d5ce1be48f3218fb4875fac501f8adfd6cDavid Lawrence
876753d5ce1be48f3218fb4875fac501f8adfd6cDavid Lawrencestatic int
ed71ea51c6ecb5d7d659b6e6a20f6b3f5c2678c6David Lawrencecompare_cname(dns_rdata_t *rdata1, dns_rdata_t *rdata2) {
ed71ea51c6ecb5d7d659b6e6a20f6b3f5c2678c6David Lawrence dns_name_t name1;
ed71ea51c6ecb5d7d659b6e6a20f6b3f5c2678c6David Lawrence dns_name_t name2;
ed71ea51c6ecb5d7d659b6e6a20f6b3f5c2678c6David Lawrence isc_region_t region1;
ed71ea51c6ecb5d7d659b6e6a20f6b3f5c2678c6David Lawrence isc_region_t region2;
ed71ea51c6ecb5d7d659b6e6a20f6b3f5c2678c6David Lawrence
49a2cf8f211213712d452287ae8e121cf59e3178David Lawrence REQUIRE(rdata1->type == rdata2->type);
49a2cf8f211213712d452287ae8e121cf59e3178David Lawrence REQUIRE(rdata1->class == rdata2->class);
49a2cf8f211213712d452287ae8e121cf59e3178David Lawrence REQUIRE(rdata1->type == 5);
49a2cf8f211213712d452287ae8e121cf59e3178David Lawrence
49a2cf8f211213712d452287ae8e121cf59e3178David Lawrence dns_name_init(&name1, NULL);
49a2cf8f211213712d452287ae8e121cf59e3178David Lawrence dns_name_init(&name2, NULL);
49a2cf8f211213712d452287ae8e121cf59e3178David Lawrence
49a2cf8f211213712d452287ae8e121cf59e3178David Lawrence dns_rdata_toregion(rdata1, &region1);
49a2cf8f211213712d452287ae8e121cf59e3178David Lawrence dns_rdata_toregion(rdata2, &region2);
49a2cf8f211213712d452287ae8e121cf59e3178David Lawrence
49a2cf8f211213712d452287ae8e121cf59e3178David Lawrence dns_name_fromregion(&name1, &region1);
49a2cf8f211213712d452287ae8e121cf59e3178David Lawrence dns_name_fromregion(&name2, &region2);
49a2cf8f211213712d452287ae8e121cf59e3178David Lawrence
49a2cf8f211213712d452287ae8e121cf59e3178David Lawrence return (dns_name_rdatacompare(&name1, &name2));
49a2cf8f211213712d452287ae8e121cf59e3178David Lawrence}
49a2cf8f211213712d452287ae8e121cf59e3178David Lawrence
49a2cf8f211213712d452287ae8e121cf59e3178David Lawrencestatic dns_result_t
49a2cf8f211213712d452287ae8e121cf59e3178David Lawrencefromstruct_cname(dns_rdataclass_t class, dns_rdatatype_t type, void *source,
a14613fce99dee3cad5bf842fd6be78f8e463582Brian Wellington isc_buffer_t *target)
529ff4b4959fb157194f985394951108ff5286e4Brian Wellington{
a14613fce99dee3cad5bf842fd6be78f8e463582Brian Wellington
489b76292622f5bc18bf1a18845f8166a73bd797Brian Wellington REQUIRE(type == 5);
489b76292622f5bc18bf1a18845f8166a73bd797Brian Wellington
489b76292622f5bc18bf1a18845f8166a73bd797Brian Wellington class = class; /*unused*/
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley source = source;
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley target = target;
5c00d1c90030a311d2700970fa7cffc8f828a48cBob Halley
5c00d1c90030a311d2700970fa7cffc8f828a48cBob Halley return (DNS_R_NOTIMPLEMENTED);
5c00d1c90030a311d2700970fa7cffc8f828a48cBob Halley}
134ba0e08a0ae9a564a8d8628fc633377d3fc239Bob Halley
134ba0e08a0ae9a564a8d8628fc633377d3fc239Bob Halleystatic dns_result_t
134ba0e08a0ae9a564a8d8628fc633377d3fc239Bob Halleytostruct_cname(dns_rdata_t *rdata, void *target) {
203596d27c225ea195e4faad4f19388c6e96ac80Bob Halley
203596d27c225ea195e4faad4f19388c6e96ac80Bob Halley REQUIRE(rdata->type == 5);
203596d27c225ea195e4faad4f19388c6e96ac80Bob Halley
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley target = target;
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley return (DNS_R_NOTIMPLEMENTED);
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley}
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley#endif /* RDATA_GENERIC_CNAME_5_H */
15bfd48fc5552ff1aae766021f42a250c001a098Michael Graff