Main Page | Class List | File List | Class Members | File Members

inetpeer.h File Reference

#include <linux/types.h>
#include <linux/init.h>
#include <linux/sched.h>
#include <linux/spinlock.h>
#include <asm/atomic.h>

Go to the source code of this file.

Classes

struct  inet_peer

Functions

void inet_initpeers (void) __init
inet_peerinet_getpeer (__u32 daddr, int create)
void inet_putpeer (struct inet_peer *p)
__u16 inet_getid (struct inet_peer *p)

Variables

spinlock_t inet_peer_unused_lock
inet_peerinet_peer_unused_head
inet_peer ** inet_peer_unused_tailp
spinlock_t inet_peer_idlock


Function Documentation

__u16 inet_getid struct inet_peer p  )  [inline, static]
 

Definition at line 56 of file inetpeer.h.

References inet_peer_idlock, and inet_peer::ip_id_count.

Referenced by __ip_select_ident().

00057 { 00058 __u16 id; 00059 00060 spin_lock_bh(&inet_peer_idlock); 00061 id = p->ip_id_count++; 00062 spin_unlock_bh(&inet_peer_idlock); 00063 return id; 00064 }

struct inet_peer* inet_getpeer __u32  daddr,
int  create
 

Definition at line 371 of file inetpeer.c.

References cleanup_once(), inet_peer_threshold, link_to_pool, lookup, peer_avl_empty, peer_cachep, PEER_MAXDEPTH, peer_pool_lock, peer_total, and unlink_from_unused().

Referenced by rt_bind_peer(), tcp_v4_remember_stamp(), and tcp_v4_tw_remember_stamp().

00372 { 00373 struct inet_peer *p, *n; 00374 struct inet_peer **stack[PEER_MAXDEPTH], ***stackptr; 00375 00376 /* Look up for the address quickly. */ 00377 read_lock_bh(&peer_pool_lock); 00378 p = lookup(daddr); 00379 if (p != peer_avl_empty) 00380 atomic_inc(&p->refcnt); 00381 read_unlock_bh(&peer_pool_lock); 00382 00383 if (p != peer_avl_empty) { 00384 /* The existing node has been found. */ 00385 /* Remove the entry from unused list if it was there. */ 00386 unlink_from_unused(p); 00387 return p; 00388 } 00389 00390 if (!create) 00391 return NULL; 00392 00393 /* Allocate the space outside the locked region. */ 00394 n = kmem_cache_alloc(peer_cachep, GFP_ATOMIC); 00395 if (n == NULL) 00396 return NULL; 00397 n->v4daddr = daddr; 00398 atomic_set(&n->refcnt, 1); 00399 n->ip_id_count = secure_ip_id(daddr); 00400 n->tcp_ts_stamp = 0; 00401 00402 write_lock_bh(&peer_pool_lock); 00403 /* Check if an entry has suddenly appeared. */ 00404 p = lookup(daddr); 00405 if (p != peer_avl_empty) 00406 goto out_free; 00407 00408 /* Link the node. */ 00409 link_to_pool(n); 00410 n->unused_prevp = NULL; /* not on the list */ 00411 peer_total++; 00412 write_unlock_bh(&peer_pool_lock); 00413 00414 if (peer_total >= inet_peer_threshold) 00415 /* Remove one less-recently-used entry. */ 00416 cleanup_once(0); 00417 00418 return n; 00419 00420 out_free: 00421 /* The appropriate node is already in the pool. */ 00422 atomic_inc(&p->refcnt); 00423 write_unlock_bh(&peer_pool_lock); 00424 /* Remove the entry from unused list if it was there. */ 00425 unlink_from_unused(p); 00426 /* Free preallocated the preallocated node. */ 00427 kmem_cache_free(peer_cachep, n); 00428 return p; 00429 }

void inet_initpeers void   ) 
 

Definition at line 108 of file inetpeer.c.

References inet_peer_gc_maxtime, inet_peer_threshold, net_random(), peer_cachep, and peer_periodic_timer.

Referenced by ip_init().

00109 { 00110 struct sysinfo si; 00111 00112 /* Use the straight interface to information about memory. */ 00113 si_meminfo(&si); 00114 /* The values below were suggested by Alexey Kuznetsov 00115 * <kuznet@ms2.inr.ac.ru>. I don't have any opinion about the values 00116 * myself. --SAW 00117 */ 00118 if (si.totalram <= (32768*1024)/PAGE_SIZE) 00119 inet_peer_threshold >>= 1; /* max pool size about 1MB on IA32 */ 00120 if (si.totalram <= (16384*1024)/PAGE_SIZE) 00121 inet_peer_threshold >>= 1; /* about 512KB */ 00122 if (si.totalram <= (8192*1024)/PAGE_SIZE) 00123 inet_peer_threshold >>= 2; /* about 128KB */ 00124 00125 peer_cachep = kmem_cache_create("inet_peer_cache", 00126 sizeof(struct inet_peer), 00127 0, SLAB_HWCACHE_ALIGN, 00128 NULL, NULL); 00129 00130 /* All the timers, started at system startup tend 00131 to synchronize. Perturb it a bit. 00132 */ 00133 peer_periodic_timer.expires = jiffies 00134 + net_random() % inet_peer_gc_maxtime 00135 + inet_peer_gc_maxtime; 00136 add_timer(&peer_periodic_timer); 00137 }

void inet_putpeer struct inet_peer p  )  [inline, static]
 

Definition at line 41 of file inetpeer.h.

References inet_peer::dtime, inet_peer_unused_lock, inet_peer_unused_tailp, and inet_peer::unused_next.

Referenced by ipv4_dst_destroy(), rt_bind_peer(), tcp_v4_remember_stamp(), tcp_v4_tw_remember_stamp(), and unlink_from_pool().

00042 { 00043 spin_lock_bh(&inet_peer_unused_lock); 00044 if (atomic_dec_and_test(&p->refcnt)) { 00045 p->unused_prevp = inet_peer_unused_tailp; 00046 p->unused_next = NULL; 00047 *inet_peer_unused_tailp = p; 00048 inet_peer_unused_tailp = &p->unused_next; 00049 p->dtime = jiffies; 00050 } 00051 spin_unlock_bh(&inet_peer_unused_lock); 00052 }


Variable Documentation

spinlock_t inet_peer_idlock
 

Definition at line 71 of file inetpeer.c.

Referenced by inet_getid().

struct inet_peer* inet_peer_unused_head
 

Definition at line 94 of file inetpeer.c.

Referenced by cleanup_once().

spinlock_t inet_peer_unused_lock
 

Definition at line 96 of file inetpeer.c.

Referenced by cleanup_once(), inet_putpeer(), and unlink_from_unused().

struct inet_peer** inet_peer_unused_tailp
 

Definition at line 95 of file inetpeer.c.

Referenced by cleanup_once(), inet_putpeer(), and unlink_from_unused().


Generated on Wed Dec 1 21:25:35 2004 for Linux 2.4.23 Networking by doxygen 1.3.8