⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mdb.c

📁 DHCP服务器源码
💻 C
📖 第 1 页 / 共 5 页
字号:
	    for (p = s -> pools; p; p = p -> next) {		lptr [FREE_LEASES] = &p -> free;		lptr [ACTIVE_LEASES] = &p -> active;		lptr [EXPIRED_LEASES] = &p -> expired;		lptr [ABANDONED_LEASES] = &p -> abandoned;		lptr [BACKUP_LEASES] = &p -> backup;		for (i = FREE_LEASES; i <= BACKUP_LEASES; i++) {		    for (l = *(lptr [i]); l; l = l -> next) {#if !defined (DEBUG_DUMP_ALL_LEASES)			if (l -> hardware_addr.hlen ||			    l -> uid_len ||			    (l -> binding_state != FTS_FREE))#endif			{			    if (!write_lease (l))				    return 0;			    num_written++;			}		    }		}	    }	}	log_info ("Wrote %d leases to leases file.", num_written);	if (!commit_leases ())		return 0;	return 1;}int lease_enqueue (struct lease *comp){	struct lease **lq, *prev, *lp;	/* No queue to put it on? */	if (!comp -> pool)		return 0;	/* Figure out which queue it's going to. */	switch (comp -> binding_state) {	      case FTS_FREE:		lq = &comp -> pool -> free;		comp -> pool -> free_leases++;		comp -> sort_time = comp -> ends;		break;	      case FTS_ACTIVE:		lq = &comp -> pool -> active;		comp -> sort_time = comp -> ends;		break;	      case FTS_EXPIRED:	      case FTS_RELEASED:	      case FTS_RESET:		lq = &comp -> pool -> expired;		comp -> sort_time = comp -> ends;		break;	      case FTS_ABANDONED:		lq = &comp -> pool -> abandoned;		comp -> sort_time = comp -> ends;		break;	      case FTS_BACKUP:		lq = &comp -> pool -> backup;		comp -> pool -> backup_leases++;		comp -> sort_time = comp -> ends;		break;	      default:		log_error ("Lease with bogus binding state: %d",			   comp -> binding_state);#if defined (BINDING_STATE_DEBUG)		abort ();#endif		return 0;	}	/* Insertion sort the lease onto the appropriate queue. */	prev = (struct lease *)0;	for (lp = *lq; lp; lp = lp -> next) {		if (lp -> sort_time >= comp -> sort_time)			break;		prev = lp;	}	if (prev) {		if (prev -> next) {			lease_reference (&comp -> next, prev -> next, MDL);			lease_dereference (&prev -> next, MDL);		}		lease_reference (&prev -> next, comp, MDL);	} else {		if (*lq) {			lease_reference (&comp -> next, *lq, MDL);			lease_dereference (lq, MDL);		}		lease_reference (lq, comp, MDL);	}	return 1;}/* For a given lease, sort it onto the right list in its pool and put it   in each appropriate hash, understanding that it's already by definition   in lease_ip_addr_hash. */void lease_instantiate (const unsigned char *val, unsigned len,			struct lease *lease){	struct class *class;	/* XXX If the lease doesn't have a pool at this point, it's an	   XXX orphan, which we *should* keep around until it expires,	   XXX but which right now we just forget. */	if (!lease -> pool) {		lease_hash_delete (lease_ip_addr_hash,				   lease -> ip_addr.iabuf,				   lease -> ip_addr.len, MDL);		return;	}			/* Put the lease on the right queue. */	lease_enqueue (lease);	/* Record the lease in the uid hash if possible. */	if (lease -> uid) {		uid_hash_add (lease);	}		/* Record it in the hardware address hash if possible. */	if (lease -> hardware_addr.hlen) {		hw_hash_add (lease);	}		/* If the lease has a billing class, set up the billing. */	if (lease -> billing_class) {		class = (struct class *)0;		class_reference (&class, lease -> billing_class, MDL);		class_dereference (&lease -> billing_class, MDL);		/* If the lease is available for allocation, the billing		   is invalid, so we don't keep it. */		if (lease -> binding_state == FTS_ACTIVE ||		    lease -> binding_state == FTS_EXPIRED ||		    lease -> binding_state == FTS_RELEASED ||		    lease -> binding_state == FTS_RESET)			bill_class (lease, class);		class_dereference (&class, MDL);	}	return;}/* Run expiry events on every pool.   This is called on startup so that   any expiry events that occurred after the server stopped and before it   was restarted can be run.   At the same time, if failover support is   compiled in, we compute the balance of leases for the pool. */void expire_all_pools (){	struct shared_network *s;	struct pool *p;	struct hash_bucket *hb;	int i;	struct lease *l;	struct lease **lptr [5];	/* First, go over the hash list and actually put all the leases	   on the appropriate lists. */	lease_hash_foreach (lease_ip_addr_hash, lease_instantiate);	/* Loop through each pool in each shared network and call the	   expiry routine on the pool. */	for (s = shared_networks; s; s = s -> next) {	    for (p = s -> pools; p; p = p -> next) {		pool_timer (p);		p -> lease_count = 0;		p -> free_leases = 0;		p -> backup_leases = 0;				lptr [FREE_LEASES] = &p -> free;		lptr [ACTIVE_LEASES] = &p -> active;		lptr [EXPIRED_LEASES] = &p -> expired;		lptr [ABANDONED_LEASES] = &p -> abandoned;		lptr [BACKUP_LEASES] = &p -> backup;		for (i = FREE_LEASES; i <= BACKUP_LEASES; i++) {		    for (l = *(lptr [i]); l; l = l -> next) {			p -> lease_count++;			if (l -> ends <= cur_time) {				if (l -> binding_state == FTS_FREE)					p -> free_leases++;				else if (l -> binding_state == FTS_BACKUP)					p -> backup_leases++;			}#if defined (FAILOVER_PROTOCOL)			if (p -> failover_peer &&			    l -> tstp > l -> tsfp &&			    !(l -> flags & ON_UPDATE_QUEUE)) {				l -> desired_binding_state = l -> binding_state;				dhcp_failover_queue_update (l, 1);			}#endif		    }		}	    }	}}void dump_subnets (){	struct lease *l;	struct shared_network *s;	struct subnet *n;	struct pool *p;	struct lease **lptr [5];	int i;	log_info ("Subnets:");	for (n = subnets; n; n = n -> next_subnet) {		log_debug ("  Subnet %s", piaddr (n -> net));		log_debug ("     netmask %s",		       piaddr (n -> netmask));	}	log_info ("Shared networks:");	for (s = shared_networks; s; s = s -> next) {	    log_info ("  %s", s -> name);	    for (p = s -> pools; p; p = p -> next) {		lptr [FREE_LEASES] = &p -> free;		lptr [ACTIVE_LEASES] = &p -> active;		lptr [EXPIRED_LEASES] = &p -> expired;		lptr [ABANDONED_LEASES] = &p -> abandoned;		lptr [BACKUP_LEASES] = &p -> backup;		for (i = FREE_LEASES; i <= BACKUP_LEASES; i++) {		    for (l = *(lptr [i]); l; l = l -> next) {			    print_lease (l);		    }		}	    }	}}HASH_FUNCTIONS (lease, const unsigned char *, struct lease, lease_hash_t,		lease_reference, lease_dereference)HASH_FUNCTIONS (host, const unsigned char *, struct host_decl, host_hash_t,		host_reference, host_dereference)HASH_FUNCTIONS (class, const char *, struct class, class_hash_t,		class_reference, class_dereference)#if defined (DEBUG_MEMORY_LEAKAGE) && \		defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)extern struct hash_table *dns_zone_hash;extern struct interface_info **interface_vector;extern int interface_count;dhcp_control_object_t *dhcp_control_object;extern struct hash_table *auth_key_hash;struct hash_table *universe_hash;struct universe **universes;int universe_count, universe_max;#if 0extern int end;#endif#if defined (COMPACT_LEASES)extern struct lease *lease_hunks;#endifvoid free_everything (){	struct subnet *sc = (struct subnet *)0, *sn = (struct subnet *)0;	struct shared_network *nc = (struct shared_network *)0,		*nn = (struct shared_network *)0;	struct pool *pc = (struct pool *)0, *pn = (struct pool *)0;	struct lease *lc = (struct lease *)0, *ln = (struct lease *)0;	struct interface_info *ic = (struct interface_info *)0,		*in = (struct interface_info *)0;	struct class *cc = (struct class *)0, *cn = (struct class *)0;	struct collection *lp;	void *st = (shared_networks		    ? (shared_networks -> next		       ? shared_networks -> next -> next : 0) : 0);	int i;	/* Get rid of all the hash tables. */	if (host_hw_addr_hash)		host_free_hash_table (&host_hw_addr_hash, MDL);	host_hw_addr_hash = 0;	if (host_uid_hash)		host_free_hash_table (&host_uid_hash, MDL);	host_uid_hash = 0;	if (lease_uid_hash)		lease_free_hash_table (&lease_uid_hash, MDL);	lease_uid_hash = 0;	if (lease_ip_addr_hash)		lease_free_hash_table (&lease_ip_addr_hash, MDL);	lease_ip_addr_hash = 0;	if (lease_hw_addr_hash)		lease_free_hash_table (&lease_hw_addr_hash, MDL);	lease_hw_addr_hash = 0;	if (host_name_hash)		host_free_hash_table (&host_name_hash, MDL);	host_name_hash = 0;	if (dns_zone_hash)		dns_zone_free_hash_table (&dns_zone_hash, MDL);	dns_zone_hash = 0;#if 0	if (auth_key_hash)		auth_key_free_hash_table (&auth_key_hash, MDL);#endif	auth_key_hash = 0;	omapi_object_dereference ((omapi_object_t **)&dhcp_control_object,				  MDL);	for (lp = collections; lp; lp = lp -> next) {	    if (lp -> classes) {		class_reference (&cn, lp -> classes, MDL);		do {		    if (cn) {			class_reference (&cc, cn, MDL);			class_dereference (&cn, MDL);		    }		    if (cc -> nic) {			class_reference (&cn, cc -> nic, MDL);			class_dereference (&cc -> nic, MDL);		    }		    group_dereference (&cc -> group, MDL);		    if (cc -> hash) {			    class_free_hash_table (&cc -> hash, MDL);			    cc -> hash = (struct hash_table *)0;		    }		    class_dereference (&cc, MDL);		} while (cn);		class_dereference (&lp -> classes, MDL);	    }	}	if (interface_vector) {	    for (i = 0; i < interface_count; i++) {		if (interface_vector [i])		    interface_dereference (&interface_vector [i], MDL);	    }	    dfree (interface_vector, MDL);	    interface_vector = 0;	}	if (interfaces) {	    interface_reference (&in, interfaces, MDL);	    do {		if (in) {		    interface_reference (&ic, in, MDL);		    interface_dereference (&in, MDL);		}		if (ic -> next) {		    interface_reference (&in, ic -> next, MDL);		    interface_dereference (&ic -> next, MDL);		}		omapi_unregister_io_object ((omapi_object_t *)ic);		if (ic -> shared_network) {		    if (ic -> shared_network -> interface)			interface_dereference				(&ic -> shared_network -> interface, MDL);		    shared_network_dereference (&ic -> shared_network, MDL);		}		interface_dereference (&ic, MDL);	    } while (in);	    interface_dereference (&interfaces, MDL);	}	/* Subnets are complicated because of the extra links. */	if (subnets) {	    subnet_reference (&sn, subnets, MDL);	    do {		if (sn) {		    subnet_reference (&sc, sn, MDL);		    subnet_dereference (&sn, MDL);		}		if (sc -> next_subnet) {		    subnet_reference (&sn, sc -> next_subnet, MDL);		    subnet_dereference (&sc -> next_subnet, MDL);		}		if (sc -> next_sibling)		    subnet_dereference (&sc -> next_sibling, MDL);		if (sc -> shared_network)		    shared_network_dereference (&sc -> shared_network, MDL);		group_dereference (&sc -> group, MDL);		if (sc -> interface)		    interface_dereference (&sc -> interface, MDL);		subnet_dereference (&sc, MDL);	    } while (sn);	    subnet_dereference (&subnets, MDL);	}	/* So are shared networks. */	if (shared_networks) {	    shared_network_reference (&nn, shared_networks, MDL);	    do {		if (nn) {		    shared_network_reference (&nc, nn, MDL);		    shared_network_dereference (&nn, MDL);		}		if (nc -> next) {		    shared_network_reference (&nn, nc -> next, MDL);		    shared_network_dereference (&nc -> next, MDL);		}		/* As are pools. */		if (nc -> pools) {		    pool_reference (&pn, nc -> pools, MDL);		    do {			struct lease **lptr [5];						if (pn) {			    pool_reference (&pc, pn, MDL);			    pool_dereference (&pn, MDL);			}			if (pc -> next) {			    pool_reference (&pn, pc -> next, MDL);			    pool_dereference (&pc -> next, MDL);			}						lptr [FREE_LEASES] = &pc -> free;			lptr [ACTIVE_LEASES] = &pc -> active;			lptr [EXPIRED_LEASES] = &pc -> expired;			lptr [ABANDONED_LEASES] = &pc -> abandoned;			lptr [BACKUP_LEASES] = &pc -> backup;			/* As (sigh) are leases. */			for (i = 0; i < 5; i++) {			    if (*lptr [i]) {				lease_reference (&ln, *lptr [i], MDL);				do {				    if (ln) {					lease_reference (&lc, ln, MDL);					lease_dereference (&ln, MDL);				    }				    if (lc -> next) {					lease_reference (&ln, lc -> next, MDL);					lease_dereference (&lc -> next, MDL);				    }				    if (lc -> billing_class)				       class_dereference (&lc -> billing_class,							  MDL);				    if (lc -> state)					free_lease_state (lc -> state, MDL);				    lc -> state = (struct lease_state *)0;				    if (lc -> n_hw)					lease_dereference (&lc -> n_hw, MDL);				    if (lc -> n_uid)					lease_dereference (&lc -> n_uid

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -