conflsn.c revision 1a69a1a78cfaa86f3b68bbc965232b7876d4da2a
0e9dcd548051a8ec34744bfa18b4e09fea742a39Andreas Gustafsson/*
d3498432822fb487e58f8f72bb5f880dd8307d7dMichael Sawyer * Copyright (C) 1999, 2000 Internet Software Consortium.
499b34cea04a46823d003d4c0520c8b03e8513cbBrian Wellington *
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * Permission to use, copy, modify, and distribute this software for any
d3498432822fb487e58f8f72bb5f880dd8307d7dMichael Sawyer * purpose with or without fee is hereby granted, provided that the above
d3498432822fb487e58f8f72bb5f880dd8307d7dMichael Sawyer * copyright notice and this permission notice appear in all copies.
d3498432822fb487e58f8f72bb5f880dd8307d7dMichael Sawyer *
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
15a44745412679c30a6d022733925af70a38b715David Lawrence * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
15a44745412679c30a6d022733925af70a38b715David Lawrence * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
15a44745412679c30a6d022733925af70a38b715David Lawrence * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
15a44745412679c30a6d022733925af70a38b715David Lawrence * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15a44745412679c30a6d022733925af70a38b715David Lawrence * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
15a44745412679c30a6d022733925af70a38b715David Lawrence * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
15a44745412679c30a6d022733925af70a38b715David Lawrence * SOFTWARE.
15a44745412679c30a6d022733925af70a38b715David Lawrence */
0e9dcd548051a8ec34744bfa18b4e09fea742a39Andreas Gustafsson
473ca0bf8c73e5fc3132df074b2d4e14be5eaa1eAndreas Gustafsson/* $Id: conflsn.c,v 1.13 2000/05/08 14:35:30 tale Exp $ */
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence
813d6c9781d1fb48bb5c1d6d3415e65f7be5eeb0Andreas Gustafsson#include <config.h>
813d6c9781d1fb48bb5c1d6d3415e65f7be5eeb0Andreas Gustafsson
813d6c9781d1fb48bb5c1d6d3415e65f7be5eeb0Andreas Gustafsson#include <isc/mem.h>
e6e0dadd30fc794b4b75f36ab8d1edb074fd5babMichael Sawyer#include <isc/util.h>
e6e0dadd30fc794b4b75f36ab8d1edb074fd5babMichael Sawyer
0e9dcd548051a8ec34744bfa18b4e09fea742a39Andreas Gustafsson#include <dns/conflsn.h>
0e9dcd548051a8ec34744bfa18b4e09fea742a39Andreas Gustafsson
0e9dcd548051a8ec34744bfa18b4e09fea742a39Andreas Gustafsson#include "confpvt.h"
0e9dcd548051a8ec34744bfa18b4e09fea742a39Andreas Gustafsson
81b172466cbf05a8ca1408c3865294832b12a136Brian Wellingtonisc_result_t
0e9dcd548051a8ec34744bfa18b4e09fea742a39Andreas Gustafssondns_c_lstnon_new(isc_mem_t *mem, dns_c_lstnon_t **listen) {
0e9dcd548051a8ec34744bfa18b4e09fea742a39Andreas Gustafsson dns_c_lstnon_t *ll;
0e9dcd548051a8ec34744bfa18b4e09fea742a39Andreas Gustafsson isc_result_t result;
0e9dcd548051a8ec34744bfa18b4e09fea742a39Andreas Gustafsson
0e9dcd548051a8ec34744bfa18b4e09fea742a39Andreas Gustafsson REQUIRE(listen != NULL);
02b4e9aef28c1e1d261f49f88a6cf389d117948bAndreas Gustafsson
473ca0bf8c73e5fc3132df074b2d4e14be5eaa1eAndreas Gustafsson *listen = NULL;
473ca0bf8c73e5fc3132df074b2d4e14be5eaa1eAndreas Gustafsson
473ca0bf8c73e5fc3132df074b2d4e14be5eaa1eAndreas Gustafsson ll = isc_mem_get(mem, sizeof *ll);
02b4e9aef28c1e1d261f49f88a6cf389d117948bAndreas Gustafsson ll->mem = mem;
473ca0bf8c73e5fc3132df074b2d4e14be5eaa1eAndreas Gustafsson ll->port = 0;
02b4e9aef28c1e1d261f49f88a6cf389d117948bAndreas Gustafsson ll->magic = DNS_C_LISTEN_MAGIC;
473ca0bf8c73e5fc3132df074b2d4e14be5eaa1eAndreas Gustafsson
473ca0bf8c73e5fc3132df074b2d4e14be5eaa1eAndreas Gustafsson result = dns_c_ipmatchlist_new(mem, &ll->iml);
473ca0bf8c73e5fc3132df074b2d4e14be5eaa1eAndreas Gustafsson if (result != ISC_R_SUCCESS) {
473ca0bf8c73e5fc3132df074b2d4e14be5eaa1eAndreas Gustafsson isc_mem_put(mem, ll, sizeof *ll);
d98372394fd6253336e9c9d580f48bd6ff9710f7Michael Sawyer return (result);
2c46670fb483b712181d4974199619bf98e61593Brian Wellington }
0e9dcd548051a8ec34744bfa18b4e09fea742a39Andreas Gustafsson
02b4e9aef28c1e1d261f49f88a6cf389d117948bAndreas Gustafsson ISC_LINK_INIT(ll, next);
0e9dcd548051a8ec34744bfa18b4e09fea742a39Andreas Gustafsson
2c46670fb483b712181d4974199619bf98e61593Brian Wellington *listen = ll;
0e9dcd548051a8ec34744bfa18b4e09fea742a39Andreas Gustafsson
5006de65318890450e5b7008d8805ce48525f58eBrian Wellington return (ISC_R_SUCCESS);
0e9dcd548051a8ec34744bfa18b4e09fea742a39Andreas Gustafsson}
5006de65318890450e5b7008d8805ce48525f58eBrian Wellington
5006de65318890450e5b7008d8805ce48525f58eBrian Wellingtonisc_result_t
5006de65318890450e5b7008d8805ce48525f58eBrian Wellingtondns_c_lstnon_delete(dns_c_lstnon_t **listen) {
5006de65318890450e5b7008d8805ce48525f58eBrian Wellington dns_c_lstnon_t *lo;
e6e0dadd30fc794b4b75f36ab8d1edb074fd5babMichael Sawyer isc_result_t r;
5006de65318890450e5b7008d8805ce48525f58eBrian Wellington
5006de65318890450e5b7008d8805ce48525f58eBrian Wellington REQUIRE(listen != NULL);
5006de65318890450e5b7008d8805ce48525f58eBrian Wellington REQUIRE(DNS_C_LISTEN_VALID(*listen));
2c46670fb483b712181d4974199619bf98e61593Brian Wellington
lo = *listen;
if (lo->iml != NULL) {
r = dns_c_ipmatchlist_detach(&lo->iml);
} else {
r = ISC_R_SUCCESS;
}
lo->magic = 0;
isc_mem_put(lo->mem, lo, sizeof *lo);
*listen = NULL;
return (r);
}
isc_result_t
dns_c_lstnon_setiml(dns_c_lstnon_t *listen,
dns_c_ipmatchlist_t *iml, isc_boolean_t deepcopy)
{
isc_result_t result;
REQUIRE(DNS_C_LISTEN_VALID(listen));
REQUIRE(DNS_C_IPMLIST_VALID(iml));
if (listen->iml != NULL) {
result = dns_c_ipmatchlist_detach(&listen->iml);
if (result != ISC_R_SUCCESS) {
return (result);
}
} else {
result = ISC_R_SUCCESS;
}
if (deepcopy) {
result = dns_c_ipmatchlist_copy(listen->mem,
&listen->iml, iml);
} else {
listen->iml = iml;
}
return (result);
}
isc_result_t
dns_c_lstnlist_new(isc_mem_t *mem, dns_c_lstnlist_t **llist) {
dns_c_lstnlist_t *ll;
REQUIRE(llist != NULL);
*llist = NULL;
ll = isc_mem_get(mem, sizeof *ll);
if (ll == NULL) {
/* XXXJAB logwrite */
return (ISC_R_NOMEMORY);
}
ll->mem = mem;
ll->magic = DNS_C_LLIST_MAGIC;
ISC_LIST_INIT(ll->elements);
*llist = ll;
return (ISC_R_SUCCESS);
}
isc_result_t
dns_c_lstnlist_delete(dns_c_lstnlist_t **llist) {
dns_c_lstnlist_t *ll;
dns_c_lstnon_t *lo, *lotmp;
isc_result_t r;
REQUIRE(llist != NULL);
REQUIRE(DNS_C_LISTENLIST_VALID(*llist));
ll = *llist;
lo = ISC_LIST_HEAD(ll->elements);
while (lo != NULL) {
lotmp = ISC_LIST_NEXT(lo, next);
ISC_LIST_UNLINK(ll->elements, lo, next);
r = dns_c_lstnon_delete(&lo);
if (r != ISC_R_SUCCESS) {
return (r);
}
lo = lotmp;
}
ll->magic = 0;
isc_mem_put(ll->mem, ll, sizeof *ll);
*llist = NULL;
return (ISC_R_SUCCESS);
}
isc_result_t
dns_c_lstnlist_print(FILE *fp, int indent, dns_c_lstnlist_t *ll) {
dns_c_lstnon_t *lo;
REQUIRE(DNS_C_LISTENLIST_VALID(ll));
lo = ISC_LIST_HEAD(ll->elements);
while (lo != NULL) {
dns_c_printtabs(fp, indent);
dns_c_lstnon_print(fp, indent, lo);
lo = ISC_LIST_NEXT(lo, next);
fprintf(fp, "\n");
}
return (ISC_R_SUCCESS);
}
isc_result_t
dns_c_lstnon_print(FILE *fp, int indent, dns_c_lstnon_t *lo) {
REQUIRE(lo != NULL);
REQUIRE(DNS_C_LISTEN_VALID(lo));
fprintf(fp, "listen-on ");
if (lo->port != DNS_C_DEFAULTPORT) {
fprintf(fp, "port %d ", lo->port);
}
dns_c_ipmatchlist_print(fp, indent + 1, lo->iml);
fprintf(fp, ";\n");
return (ISC_R_SUCCESS);
}