00001 00002 /* 00003 * The olsr.org Optimized Link-State Routing daemon(olsrd) 00004 * Copyright (c) 2004-2009, the olsr.org team - see HISTORY file 00005 * All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions 00009 * are met: 00010 * 00011 * * Redistributions of source code must retain the above copyright 00012 * notice, this list of conditions and the following disclaimer. 00013 * * Redistributions in binary form must reproduce the above copyright 00014 * notice, this list of conditions and the following disclaimer in 00015 * the documentation and/or other materials provided with the 00016 * distribution. 00017 * * Neither the name of olsr.org, olsrd nor the names of its 00018 * contributors may be used to endorse or promote products derived 00019 * from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00022 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00023 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00024 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00025 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00026 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00027 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00028 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00029 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00030 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00031 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00032 * POSSIBILITY OF SUCH DAMAGE. 00033 * 00034 * Visit http://www.olsr.org for more information. 00035 * 00036 * If you find this software useful feel free to make a donation 00037 * to the project. For more information see the website or contact 00038 * the copyright holders. 00039 * 00040 */ 00041 00042 #include "ipcalc.h" 00043 #include "olsr_ip_prefix_list.h" 00044 #include "olsr_ip_acl.h" 00045 00046 void 00047 ip_acl_init(struct ip_acl *acl) 00048 { 00049 list_init_head(&acl->accept); 00050 list_init_head(&acl->reject); 00051 acl->default_accept = false; 00052 acl->first_accept = false; 00053 } 00054 00055 void 00056 ip_acl_flush(struct ip_acl *acl) 00057 { 00058 ip_prefix_list_flush(&acl->accept); 00059 ip_prefix_list_flush(&acl->reject); 00060 } 00061 00062 void 00063 ip_acl_add(struct ip_acl *acl, const union olsr_ip_addr *net, uint8_t prefix_len, bool reject) 00064 { 00065 ip_prefix_list_add(reject ? &acl->reject : &acl->accept, net, prefix_len); 00066 } 00067 00068 void 00069 ip_acl_remove(struct ip_acl *acl, const union olsr_ip_addr *net, uint8_t prefix_len, bool reject, int ip_version) 00070 { 00071 ip_prefix_list_remove(reject ? &acl->reject : &acl->accept, net, prefix_len, ip_version); 00072 } 00073 00074 bool 00075 ip_acl_acceptable(struct ip_acl *acl, const union olsr_ip_addr *ip, int ip_version) 00076 { 00077 struct list_entity *first, *second; 00078 struct ip_prefix_entry *entry, *iterator; 00079 00080 first = acl->first_accept ? &acl->accept : &acl->reject; 00081 second = acl->first_accept ? &acl->reject : &acl->accept; 00082 00083 /* first run */ 00084 OLSR_FOR_ALL_IPPREFIX_ENTRIES(first, entry, iterator) { 00085 if (ip_in_net(ip, &entry->net, ip_version)) { 00086 return acl->first_accept; 00087 } 00088 } 00089 00090 /* second run */ 00091 OLSR_FOR_ALL_IPPREFIX_ENTRIES(second, entry, iterator) { 00092 if (ip_in_net(ip, &entry->net, ip_version)) { 00093 return !acl->first_accept; 00094 } 00095 } 00096 00097 /* just use default */ 00098 return acl->default_accept; 00099 } 00100 00101 /* 00102 * Local Variables: 00103 * mode: c 00104 * style: linux 00105 * c-basic-offset: 4 00106 * indent-tabs-mode: nil 00107 * End: 00108 */
1.6.3