confip.c revision 90adbb5f1cfeac900fecf654c9000d7f26c06b98
a7038d1a0513c8e804937ebc95fc9cb3a46c04f5Mark Andrews * Copyright (C) 1999 Internet Software Consortium.
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley * Permission to use, copy, modify, and distribute this software for any
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley * purpose with or without fee is hereby granted, provided that the above
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley * copyright notice and this permission notice appear in all copies.
15a44745412679c30a6d022733925af70a38b715David 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
8dfa9caeec8e68db0c937e347a3d6629e7627d54Bob Halley#define IPLIST_MAGIC 0x49706c73 /* Ipls */ /* dns_c_iplist */
54f959d12b5a1f9315fbf6a776c6d349316e9686Bob Halley#define IPMDIRECT_MAGIC 0x49506d64 /* IPmd */ /* dns_c_ipmatch_direct */
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley#define IPMINDIRECT_MAGIC 0x69506d69 /* iPmi */ /* dns_c_ipmatch_indirect */
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews#define IPMELEM_MAGIC 0x49704d65 /* IpMe */ /* dns_c_ipmatch_element */
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley#define IPMLIST_MAGIC 0x69706d6c /* ipml */ /* dns_c_ipmatchlist */
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley#define DNS_IPLIST_VALID(ipl) ISC_MAGIC_VALID(ipl,IPLIST_MAGIC)
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley#define DNS_IPDIRECT_VALID(ipmld) ISC_MAGIC_VALID(ipmld, IPMDIRECT_MAGIC)
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley#define DNS_IPINDIRECT_VALID(ipmlid) ISC_MAGIC_VALID(ipmlid, IPMINDIRECT_MAGIC)
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley#define DNS_IPMELEM_VALID(impe) ISC_MAGIC_VALID(impe, IPMELEM_MAGIC)
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley#define DNS_IPMLIST_VALID(ipml) ISC_MAGIC_VALID(ipml, IPMLIST_MAGIC)
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley/* Flag for dns_c_ipmatch_element */
078d49b63324f01d98301ee21671abee0c41fcdeBob Halley#define DNS_C_IPMATCH_NEGATE 0x01 /* match means deny access */
904a5734375869ffb504ed8cde6b68cafadb6d64Bob Halleystatic isc_result_t checkmask(isc_sockaddr_t *address, isc_uint32_t bits);
5619558151f1aa4249b3ead979e76876e29278b6Bob Halleystatic isc_result_t bits2v6mask(struct in6_addr *addr, isc_uint32_t bits);
b12f0228b32775ee688ed21ddbf3a116c1adfb43Michael Graff isc_mem_t *mem, dns_c_ipmatchelement_t **result)
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley return (ISC_TF((elem->flags & DNS_C_IPMATCH_NEGATE) ==
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley /* nothing */
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence dns_c_ipmatchlist_delete(lctx, &elem->u.indirect.list);
e02884167b7c969b56413f76c48c3802c4dca14dAndreas Gustafsson isc_log_write(lctx, DNS_LOGCATEGORY_CONFIG,
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff "dns_ipmath_none element type");
7837d146219db7a85a4b444a9cdf6602254a4f75Bob Halley result = dns_c_ipmatchelement_new(lctx, mem, &newel);
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley newel->u.aclname = isc_mem_strdup(mem, src->u.aclname);
7837d146219db7a85a4b444a9cdf6602254a4f75Bob Halley "ipmatch 'none' element type");
1c724c986de1449e3b2f1eeae4c724dc0d97603cBob Halleydns_c_ipmatchelement_equal(dns_c_ipmatchelement_t *e1,
1c724c986de1449e3b2f1eeae4c724dc0d97603cBob Halley if ((e1->type != e2->type) || (e1->flags != e2->flags))
1c724c986de1449e3b2f1eeae4c724dc0d97603cBob Halley return (isc_sockaddr_equal(&e1->u.direct.address,
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley return (dns_c_ipmatchlist_equal(e1->u.indirect.list,
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff return (ISC_TF(strcmp(e1->u.key, e2->u.key) == 0));
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley return (ISC_TF(strcmp(e1->u.aclname, e2->u.aclname) == 0));
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafssondns_c_ipmatchlocalnets_new(isc_log_t *lctx,
84185d19c7a9ef1ac23cc6236c8773697d4efeb1Brian Wellington res = dns_c_ipmatchelement_new(lctx, mem, &ime);
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley const char *name)
c3b708aaf1bb0a118e0e11befa1b732acfb1d079Bob Halley res = dns_c_ipmatchlist_copy(lctx, mem, &iml_copy, iml);
b2ca6fd3a8293440b4d263723525396059cf2400Brian Wellington ime->u.indirect.refname.length = strlen(name) + 1;
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley RUNTIME_CHECK(ime->u.indirect.refname.base != NULL);
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson res = dns_c_ipmatchelement_new(lctx, mem, &ime);
2dd99c098ca162f985b7ef3c8142a964ad8281aeMark Andrews res = dns_c_ipmatchelement_new(lctx, mem, &ipme);
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson res = dns_c_ipmatchelement_new(lctx, mem, &ipme);
2dd99c098ca162f985b7ef3c8142a964ad8281aeMark Andrews ipme->u.aclname = isc_mem_strdup(mem, aclname);
94a08e09db3dc844b6ee4841c368a2d7074a9c3fAndreas Gustafsson if ((ipe->flags & DNS_C_IPMATCH_NEGATE) == DNS_C_IPMATCH_NEGATE) {
03f91269f5453bcbd924910ef85a8f8496cf2661Mark Andrews res = dns_c_ipmatchelement_delete(lctx, ipml->mem, &ime);
84185d19c7a9ef1ac23cc6236c8773697d4efeb1Brian Wellingtondns_c_ipmatchlist_copy(isc_log_t *lctx, isc_mem_t *mem,
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson dns_c_ipmatchlist_t **dest, dns_c_ipmatchlist_t *src)
d981ca645597116d227a48bf37cc5edc061c854dBob Halley result = dns_c_ipmatchlist_new(lctx, mem, &newlist);
d981ca645597116d227a48bf37cc5edc061c854dBob Halley result = dns_c_ipmatchelement_copy(lctx, mem, &ptr, ime);
d981ca645597116d227a48bf37cc5edc061c854dBob Halleydns_c_ipmatchlist_equal(dns_c_ipmatchlist_t *l1, dns_c_ipmatchlist_t *l2) {
&ime_copy,
ime);
if (negate) {
return (result);
int bits;
case dns_c_ipmatch_pattern:
if (bits > 0) {
case dns_c_ipmatch_indirect:
case dns_c_ipmatch_key:
case dns_c_ipmatch_localhost:
case dns_c_ipmatch_localnets:
case dns_c_ipmatch_none:
return (ISC_R_FAILURE);
case dns_c_ipmatch_acl:
return (ISC_R_SUCCESS);
return (ISC_R_SUCCESS);
(void) lctx;
return (ISC_R_NOMEMORY);
return (ISC_R_NOMEMORY);
return (ISC_R_SUCCESS);
dns_c_iplist_t *l ;
(void) lctx;
l = *list;
if (l == NULL) {
return (ISC_R_SUCCESS);
l->refcount--;
if (l->refcount == 0) {
return (ISC_R_SUCCESS);
(void) lctx;
return (list);
isc_uint32_t i;
return (res);
return (ISC_R_SUCCESS);
isc_uint32_t i;
return (ISC_FALSE);
return (ISC_FALSE);
return (ISC_TRUE);
isc_uint32_t i;
isc_uint32_t i;
(void) lctx;
return (ISC_R_FAILURE);
return (ISC_R_NOMEMORY);
return (ISC_R_SUCCESS);
isc_uint32_t i;
(void) lctx;
return (ISC_R_FAILURE);
return (ISC_R_SUCCESS);
static isc_result_t
if (bits > 0) {
return (ISC_R_FAILURE);
unsigned char *maskp;
unsigned char *addrp;
return (ISC_R_FAILURE);
return (ISC_R_FAILURE);
return (ISC_R_SUCCESS);
static isc_result_t
} else if (bits > 0) {