?? mdb.c
字號(hào):
{ /* If there are statements to execute when the lease is released, execute them. */#if defined (NSUPDATE) ddns_removals (lease);#endif if (lease -> on_release) { execute_statements ((struct binding_value **)0, packet, lease, (struct client_state *)0, packet -> options, (struct option_state *)0, /* XXX */ &lease -> scope, lease -> on_release); if (lease -> on_release) executable_statement_dereference (&lease -> on_release, MDL); } /* We do either the on_release or the on_expiry events, but not both (it's possible that they could be the same, in any case). */ if (lease -> on_expiry) executable_statement_dereference (&lease -> on_expiry, MDL); if (lease -> binding_state != FTS_FREE && lease -> binding_state != FTS_BACKUP && lease -> binding_state != FTS_RELEASED && lease -> binding_state != FTS_EXPIRED && lease -> binding_state != FTS_RESET) { if (lease -> on_commit) executable_statement_dereference (&lease -> on_commit, MDL); /* Blow away any bindings. */ if (lease -> scope) binding_scope_dereference (&lease -> scope, MDL); lease -> ends = cur_time;#if defined (FAILOVER_PROTOCOL) if (lease -> pool && lease -> pool -> failover_peer) { lease -> next_binding_state = FTS_RELEASED; } else { lease -> next_binding_state = FTS_FREE; }#else lease -> next_binding_state = FTS_FREE;#endif supersede_lease (lease, (struct lease *)0, 1, 1, 1); }}/* Abandon the specified lease (set its timeout to infinity and its particulars to zero, and re-hash it as appropriate. */void abandon_lease (lease, message) struct lease *lease; const char *message;{ struct lease *lt = (struct lease *)0; if (!lease_copy (<, lease, MDL)) return; lt -> ends = cur_time; /* XXX */ lt -> next_binding_state = FTS_ABANDONED; log_error ("Abandoning IP address %s: %s", piaddr (lease -> ip_addr), message); lt -> hardware_addr.hlen = 0; if (lt -> uid && lt -> uid != lt -> uid_buf) dfree (lt -> uid, MDL); lt -> uid = (unsigned char *)0; lt -> uid_len = 0; lt -> uid_max = 0; supersede_lease (lease, lt, 1, 1, 1); lease_dereference (<, MDL);}/* Abandon the specified lease (set its timeout to infinity and its particulars to zero, and re-hash it as appropriate. */void dissociate_lease (lease) struct lease *lease;{ struct lease *lt = (struct lease *)0; if (!lease_copy (<, lease, MDL)) return;#if defined (FAILOVER_PROTOCOL) if (lease -> pool && lease -> pool -> failover_peer) { lt -> next_binding_state = FTS_RESET; } else { lt -> next_binding_state = FTS_FREE; }#else lt -> next_binding_state = FTS_FREE;#endif lt -> ends = cur_time; /* XXX */ lt -> hardware_addr.hlen = 0; if (lt -> uid && lt -> uid != lt -> uid_buf) dfree (lt -> uid, MDL); lt -> uid = (unsigned char *)0; lt -> uid_len = 0; lt -> uid_max = 0; supersede_lease (lease, lt, 1, 1, 1); lease_dereference (<, MDL);}/* Timer called when a lease in a particular pool expires. */void pool_timer (vpool) void *vpool;{ struct pool *pool; struct lease *lt = (struct lease *)0; struct lease *next = (struct lease *)0; struct lease *lease = (struct lease *)0; struct lease **lptr [5]; TIME next_expiry = MAX_TIME; int i; pool = (struct pool *)vpool;#define FREE_LEASES 0 lptr [FREE_LEASES] = &pool -> free;#define ACTIVE_LEASES 1 lptr [ACTIVE_LEASES] = &pool -> active;#define EXPIRED_LEASES 2 lptr [EXPIRED_LEASES] = &pool -> expired;#define ABANDONED_LEASES 3 lptr [ABANDONED_LEASES] = &pool -> abandoned;#define BACKUP_LEASES 4 lptr [BACKUP_LEASES] = &pool -> backup; for (i = FREE_LEASES; i <= BACKUP_LEASES; i++) { /* If there's nothing on the queue, skip it. */ if (!*(lptr [i])) continue;#if defined (FAILOVER_PROTOCOL) if (pool -> failover_peer && pool -> failover_peer -> me.state != partner_down) { /* The secondary can't remove a lease from the active state except in partner_down. */ if (i == ACTIVE_LEASES && pool -> failover_peer -> i_am == secondary) continue; /* Leases in an expired state don't move to free because of a timeout unless we're in partner_down. */ if (i == EXPIRED_LEASES) continue; }#endif lease_reference (&lease, *(lptr [i]), MDL); while (lease) { /* Remember the next lease in the list. */ if (next) lease_dereference (&next, MDL); if (lease -> next) lease_reference (&next, lease -> next, MDL); /* If we've run out of things to expire on this list, stop. */ if (lease -> sort_time > cur_time) { if (lease -> sort_time < next_expiry) next_expiry = lease -> sort_time; break; } /* If there is a pending state change, and this lease has gotten to the time when the state change should happen, just call supersede_lease on it to make the change happen. */ if (lease -> next_binding_state != lease -> binding_state) supersede_lease (lease, (struct lease *)0, 1, 1, 1); lease_dereference (&lease, MDL); if (next) lease_reference (&lease, next, MDL); } if (next) lease_dereference (&next, MDL); if (lease) lease_dereference (&lease, MDL); } if (next_expiry != MAX_TIME) { pool -> next_event_time = next_expiry; add_timeout (pool -> next_event_time, pool_timer, pool, (tvref_t)pool_reference, (tvunref_t)pool_dereference); } else pool -> next_event_time = MIN_TIME;}/* Locate the lease associated with a given IP address... */int find_lease_by_ip_addr (struct lease **lp, struct iaddr addr, const char *file, int line){ return lease_hash_lookup (lp, lease_ip_addr_hash, addr.iabuf, addr.len, file, line);}int find_lease_by_uid (struct lease **lp, const unsigned char *uid, unsigned len, const char *file, int line){ if (len == 0) return 0; return lease_hash_lookup (lp, lease_uid_hash, uid, len, file, line);}int find_lease_by_hw_addr (struct lease **lp, const unsigned char *hwaddr, unsigned hwlen, const char *file, int line){ if (hwlen == 0) return 0; return lease_hash_lookup (lp, lease_hw_addr_hash, hwaddr, hwlen, file, line);}/* Add the specified lease to the uid hash. */void uid_hash_add (lease) struct lease *lease;{ struct lease *head = (struct lease *)0; struct lease *next = (struct lease *)0; /* If it's not in the hash, just add it. */ if (!find_lease_by_uid (&head, lease -> uid, lease -> uid_len, MDL)) lease_hash_add (lease_uid_hash, lease -> uid, lease -> uid_len, lease, MDL); else { /* Otherwise, attach it to the end of the list. */ while (head -> n_uid) { lease_reference (&next, head -> n_uid, MDL); lease_dereference (&head, MDL); lease_reference (&head, next, MDL); lease_dereference (&next, MDL); } lease_reference (&head -> n_uid, lease, MDL); lease_dereference (&head, MDL); }}/* Delete the specified lease from the uid hash. */void uid_hash_delete (lease) struct lease *lease;{ struct lease *head = (struct lease *)0; struct lease *scan; /* If it's not in the hash, we have no work to do. */ if (!find_lease_by_uid (&head, lease -> uid, lease -> uid_len, MDL)) { if (lease -> n_uid) lease_dereference (&lease -> n_uid, MDL); return; } /* If the lease we're freeing is at the head of the list, remove the hash table entry and add a new one with the next lease on the list (if there is one). */ if (head == lease) { lease_hash_delete (lease_uid_hash, lease -> uid, lease -> uid_len, MDL); if (lease -> n_uid) { lease_hash_add (lease_uid_hash, lease -> n_uid -> uid, lease -> n_uid -> uid_len, lease -> n_uid, MDL); lease_dereference (&lease -> n_uid, MDL); } } else { /* Otherwise, look for the lease in the list of leases attached to the hash table entry, and remove it if we find it. */ for (scan = head; scan -> n_uid; scan = scan -> n_uid) { if (scan -> n_uid == lease) { lease_dereference (&scan -> n_uid, MDL); if (lease -> n_uid) { lease_reference (&scan -> n_uid, lease -> n_uid, MDL); lease_dereference (&lease -> n_uid, MDL); } break; } } } lease_dereference (&head, MDL);}/* Add the specified lease to the hardware address hash. */void hw_hash_add (lease) struct lease *lease;{ struct lease *head = (struct lease *)0; struct lease *next = (struct lease *)0; /* If it's not in the hash, just add it. */ if (!find_lease_by_hw_addr (&head, lease -> hardware_addr.hbuf, lease -> hardware_addr.hlen, MDL)) lease_hash_add (lease_hw_addr_hash, lease -> hardware_addr.hbuf, lease -> hardware_addr.hlen, lease, MDL); else { /* Otherwise, attach it to the end of the list. */ while (head -> n_hw) { lease_reference (&next, head -> n_hw, MDL); lease_dereference (&head, MDL); lease_reference (&head, next, MDL); lease_dereference (&next, MDL); } lease_reference (&head -> n_hw, lease, MDL); lease_dereference (&head, MDL); }}/* Delete the specified lease from the hardware address hash. */void hw_hash_delete (lease) struct lease *lease;{ struct lease *head = (struct lease *)0; struct lease *next = (struct lease *)0; /* If it's not in the hash, we have no work to do. */ if (!find_lease_by_hw_addr (&head, lease -> hardware_addr.hbuf, lease -> hardware_addr.hlen, MDL)) { if (lease -> n_hw) lease_dereference (&lease -> n_hw, MDL); return; } /* If the lease we're freeing is at the head of the list, remove the hash table entry and add a new one with the next lease on the list (if there is one). */ if (head == lease) { lease_hash_delete (lease_hw_addr_hash, lease -> hardware_addr.hbuf, lease -> hardware_addr.hlen, MDL); if (lease -> n_hw) { lease_hash_add (lease_hw_addr_hash, lease -> n_hw -> hardware_addr.hbuf, lease -> n_hw -> hardware_addr.hlen, lease -> n_hw, MDL); lease_dereference (&lease -> n_hw, MDL); } } else { /* Otherwise, look for the lease in the list of leases attached to the hash table entry, and remove it if we find it. */ while (head -> n_hw) { if (head -> n_hw == lease) { lease_dereference (&head -> n_hw, MDL); if (lease -> n_hw) { lease_reference (&head -> n_hw, lease -> n_hw, MDL); lease_dereference (&lease -> n_hw, MDL); } break; } lease_reference (&next, head -> n_hw, MDL); lease_dereference (&head, MDL); lease_reference (&head, next, MDL); lease_dereference (&next, MDL); } } if (head) lease_dereference (&head, MDL);}/* Write all interesting leases to permanent storage. */int write_leases (){ struct lease *l; struct shared_network *s; struct pool *p; struct host_decl *hp; struct group_object *gp; struct hash_bucket *hb; int i; int num_written; struct lease **lptr [5]; /* Write all the dynamically-created group declarations. */ if (group_name_hash) { num_written = 0; for (i = 0; i < group_name_hash -> hash_count; i++) { for (hb = group_name_hash -> buckets [i]; hb; hb = hb -> next) { gp = (struct group_object *)hb -> value; if ((gp -> flags & GROUP_OBJECT_DYNAMIC) || ((gp -> flags & GROUP_OBJECT_STATIC) && (gp -> flags & GROUP_OBJECT_DELETED))) { if (!write_group (gp)) return 0; ++num_written; } } } log_info ("Wrote %d group decls to leases file.", num_written); } /* Write all the deleted host declarations. */ if (host_name_hash) { num_written = 0; for (i = 0; i < host_name_hash -> hash_count; i++) { for (hb = host_name_hash -> buckets [i]; hb; hb = hb -> next) { hp = (struct host_decl *)hb -> value; if (((hp -> flags & HOST_DECL_STATIC) && (hp -> flags & HOST_DECL_DELETED))) { if (!write_host (hp)) return 0; ++num_written; } } } log_info ("Wrote %d deleted host decls to leases file.", num_written); } /* Write all the new, dynamic host declarations. */ if (host_name_hash) { num_written = 0; for (i = 0; i < host_name_hash -> hash_count; i++) { for (hb = host_name_hash -> buckets [i]; hb; hb = hb -> next) { hp = (struct host_decl *)hb -> value; if ((hp -> flags & HOST_DECL_DYNAMIC)) { if (!write_host (hp)) ++num_written; } } }
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -