1/* 2 * Copyright (C) 1993-2001, 2003 by Darren Reed. 3 * 4 * See the IPFILTER.LICENCE file for details on licencing. 5 */ 6#if defined(KERNEL) || defined(_KERNEL) 7# undef KERNEL 8# undef _KERNEL --- 39 unchanged lines hidden (view full) --- 48# endif 49# include <sys/stream.h> 50# include <sys/kmem.h> 51#endif 52#if defined(__FreeBSD_version) && (__FreeBSD_version >= 300000) 53# include <sys/malloc.h> 54#endif 55 |
56#if defined(SOLARIS2) && !defined(_KERNEL) 57# include "radix_ipf.h" 58#endif |
59#if defined(_KERNEL) && (defined(__osf__) || defined(AIX) || \ 60 defined(__hpux) || defined(__sgi)) 61# include "radix_ipf_local.h" 62# define _RADIX_H_ 63#endif 64#include <net/if.h> 65#include <netinet/in.h> 66 --- 6 unchanged lines hidden (view full) --- 73 !defined(__hpux) && !defined(__sgi)) 74static int rn_freenode __P((struct radix_node *, void *)); 75#endif 76 77/* END OF INCLUDES */ 78 79#if !defined(lint) 80static const char sccsid[] = "@(#)ip_fil.c 2.41 6/5/96 (C) 1993-2000 Darren Reed"; |
81static const char rcsid[] = "@(#)$Id: ip_pool.c,v 2.55.2.24 2007/10/10 09:45:37 darrenr Exp $"; |
82#endif 83 84#ifdef IPFILTER_LOOKUP 85 |
86# if !defined(RADIX_NODE_HEAD_LOCK) || !defined(RADIX_NODE_HEAD_UNLOCK) || \ 87 !defined(_KERNEL) 88# undef RADIX_NODE_HEAD_LOCK 89# undef RADIX_NODE_HEAD_UNLOCK |
90# define RADIX_NODE_HEAD_LOCK(x) ; |
91# define RADIX_NODE_HEAD_UNLOCK(x) ; 92# endif 93 94static void ip_pool_clearnodes __P((ip_pool_t *)); 95static void *ip_pool_exists __P((int, char *)); 96 97ip_pool_stat_t ipoolstat; 98ipfrwlock_t ip_poolrw; --- 164 unchanged lines hidden (view full) --- 263/* function for the radix tree that supports the pools. ip_pool_destroy() is*/ 264/* used to delete the pools one by one to ensure they're properly freed up. */ 265/* ------------------------------------------------------------------------ */ 266void ip_pool_fini() 267{ 268 ip_pool_t *p, *q; 269 int i; 270 |
271 for (i = 0; i <= IPL_LOGMAX; i++) { 272 for (q = ip_pool_list[i]; (p = q) != NULL; ) { 273 q = p->ipo_next; 274 (void) ip_pool_destroy(i, p->ipo_name); 275 } 276 } 277 278#if (!defined(_KERNEL) || (BSD < 199306)) --- 181 unchanged lines hidden (view full) --- 460int ip_pool_insert(ipo, addr, mask, info) 461ip_pool_t *ipo; 462i6addr_t *addr, *mask; 463int info; 464{ 465 struct radix_node *rn; 466 ip_pool_node_t *x; 467 |
468 KMALLOC(x, ip_pool_node_t *); 469 if (x == NULL) { 470 return ENOMEM; 471 } 472 473 bzero(x, sizeof(*x)); 474 475 x->ipn_info = info; --- 48 unchanged lines hidden (view full) --- 524/* ------------------------------------------------------------------------ */ 525int ip_pool_create(op) 526iplookupop_t *op; 527{ 528 char name[FR_GROUPLEN]; 529 int poolnum, unit; 530 ip_pool_t *h; 531 |
532 unit = op->iplo_unit; 533 |
534 if ((op->iplo_arg & LOOKUP_ANON) == 0) { |
535 h = ip_pool_exists(unit, op->iplo_name); |
536 if (h != NULL) { 537 if ((h->ipo_flags & IPOOL_DELETE) == 0) 538 return EEXIST; |
539 h->ipo_flags &= ~IPOOL_DELETE; 540 return 0; 541 } |
542 } |
543 |
544 KMALLOC(h, ip_pool_t *); 545 if (h == NULL) 546 return ENOMEM; 547 bzero(h, sizeof(*h)); 548 549 if (rn_inithead((void **)&h->ipo_head, 550 offsetof(addrfamily_t, adf_addr) << 3) == 0) { 551 KFREE(h); 552 return ENOMEM; |
553 } 554 555 if ((op->iplo_arg & LOOKUP_ANON) != 0) { 556 ip_pool_t *p; 557 558 h->ipo_flags |= IPOOL_ANON; 559 poolnum = LOOKUP_ANON; 560 --- 18 unchanged lines hidden (view full) --- 579 } 580 581 (void)strncpy(h->ipo_name, name, sizeof(h->ipo_name)); 582 (void)strncpy(op->iplo_name, name, sizeof(op->iplo_name)); 583 } else { 584 (void)strncpy(h->ipo_name, op->iplo_name, sizeof(h->ipo_name)); 585 } 586 |
587 h->ipo_ref = 1; 588 h->ipo_list = NULL; 589 h->ipo_unit = unit; 590 h->ipo_next = ip_pool_list[unit]; 591 if (ip_pool_list[unit] != NULL) 592 ip_pool_list[unit]->ipo_pnext = &h->ipo_next; 593 h->ipo_pnext = &ip_pool_list[unit]; 594 ip_pool_list[unit] = h; |
595 |
596 ipoolstat.ipls_pools++; |
597 598 return 0; 599} 600 601 602/* ------------------------------------------------------------------------ */ 603/* Function: ip_pool_remove */ 604/* Returns: int - 0 = success, else error */ 605/* Parameters: ipo(I) - pointer to the pool to remove the node from. */ 606/* ipe(I) - address being deleted as a node */ 607/* Locks: WRITE(ip_poolrw) */ 608/* */ 609/* Remove a node from the pool given by ipo. */ 610/* ------------------------------------------------------------------------ */ 611int ip_pool_remove(ipo, ipe) 612ip_pool_t *ipo; 613ip_pool_node_t *ipe; 614{ 615 |
616 if (ipe->ipn_pnext != NULL) 617 *ipe->ipn_pnext = ipe->ipn_next; 618 if (ipe->ipn_next != NULL) 619 ipe->ipn_next->ipn_pnext = ipe->ipn_pnext; 620 621 RADIX_NODE_HEAD_LOCK(ipo->ipo_head); 622 ipo->ipo_head->rnh_deladdr(&ipe->ipn_addr, &ipe->ipn_mask, 623 ipo->ipo_head); --- 151 unchanged lines hidden (view full) --- 775/* */ 776/* Drop the number of known references to this pool structure by one and if */ 777/* we arrive at zero known references, free it. */ 778/* ------------------------------------------------------------------------ */ 779void ip_pool_deref(ipo) 780ip_pool_t *ipo; 781{ 782 |
783 ipo->ipo_ref--; 784 785 if (ipo->ipo_ref == 0) 786 ip_pool_free(ipo); 787 788 else if ((ipo->ipo_ref == 1) && (ipo->ipo_flags & IPOOL_DELETE)) 789 ip_pool_destroy(ipo->ipo_unit, ipo->ipo_name); 790} --- 51 unchanged lines hidden (view full) --- 842 if (ipo == NULL) { 843 nextipo = ip_pool_list[(int)ilp->ili_unit]; 844 } else { 845 nextipo = ipo->ipo_next; 846 } 847 848 if (nextipo != NULL) { 849 ATOMIC_INC(nextipo->ipo_ref); |
850 token->ipt_data = nextipo; |
851 } else { 852 bzero((char *)&zp, sizeof(zp)); 853 nextipo = &zp; |
854 token->ipt_data = NULL; |
855 } 856 break; 857 858 case IPFLOOKUPITER_NODE : 859 node = token->ipt_data; 860 if (node == NULL) { 861 ipo = ip_pool_exists(ilp->ili_unit, ilp->ili_name); 862 if (ipo == NULL) 863 err = ESRCH; 864 else { 865 nextnode = ipo->ipo_list; 866 ipo = NULL; 867 } 868 } else { 869 nextnode = node->ipn_next; 870 } 871 872 if (nextnode != NULL) { 873 ATOMIC_INC(nextnode->ipn_ref); |
874 token->ipt_data = nextnode; |
875 } else { 876 bzero((char *)&zn, sizeof(zn)); 877 nextnode = &zn; |
878 token->ipt_data = NULL; |
879 } 880 break; 881 default : 882 err = EINVAL; 883 break; 884 } 885 886 RWLOCK_EXIT(&ip_poolrw); --- 4 unchanged lines hidden (view full) --- 891 switch (ilp->ili_otype) 892 { 893 case IPFLOOKUPITER_LIST : 894 if (ipo != NULL) { 895 WRITE_ENTER(&ip_poolrw); 896 ip_pool_deref(ipo); 897 RWLOCK_EXIT(&ip_poolrw); 898 } |
899 err = COPYOUT(nextipo, ilp->ili_data, sizeof(*nextipo)); 900 if (err != 0) 901 err = EFAULT; 902 break; 903 904 case IPFLOOKUPITER_NODE : 905 if (node != NULL) { 906 WRITE_ENTER(&ip_poolrw); 907 ip_pool_node_deref(node); 908 RWLOCK_EXIT(&ip_poolrw); 909 } |
910 err = COPYOUT(nextnode, ilp->ili_data, sizeof(*nextnode)); 911 if (err != 0) 912 err = EFAULT; 913 break; 914 } 915 916 return err; 917} --- 75 unchanged lines hidden --- |