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

dst.c File Reference

#include <linux/bitops.h>
#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/mm.h>
#include <linux/string.h>
#include <linux/errno.h>
#include <linux/netdevice.h>
#include <linux/skbuff.h>
#include <linux/init.h>
#include <net/dst.h>

Go to the source code of this file.

Functions

void dst_run_gc (unsigned long)
int dst_discard (struct sk_buff *skb)
int dst_blackhole (struct sk_buff *skb)
void * dst_alloc (struct dst_ops *ops)
void __dst_free (struct dst_entry *dst)
void dst_destroy (struct dst_entry *dst)
int dst_dev_event (struct notifier_block *this, unsigned long event, void *ptr)
void __init dst_init (void)

Variables

dst_entrydst_garbage_list
spinlock_t dst_lock = SPIN_LOCK_UNLOCKED
unsigned long dst_gc_timer_expires
unsigned long dst_gc_timer_inc = DST_GC_MAX
timer_list dst_gc_timer
notifier_block dst_dev_notifier


Function Documentation

void __dst_free struct dst_entry dst  ) 
 

Definition at line 120 of file dst.c.

References dst_entry::dev, dst_blackhole(), dst_discard(), dst_garbage_list, DST_GC_INC, DST_GC_MIN, dst_gc_timer, dst_gc_timer_expires, dst_gc_timer_inc, dst_lock, net_device::flags, dst_entry::input, dst_entry::next, dst_entry::obsolete, and dst_entry::output.

Referenced by dst_free().

00121 { 00122 spin_lock_bh(&dst_lock); 00123 00124 /* The first case (dev==NULL) is required, when 00125 protocol module is unloaded. 00126 */ 00127 if (dst->dev == NULL || !(dst->dev->flags&IFF_UP)) { 00128 dst->input = dst_discard; 00129 dst->output = dst_blackhole; 00130 } 00131 dst->obsolete = 2; 00132 dst->next = dst_garbage_list; 00133 dst_garbage_list = dst; 00134 if (dst_gc_timer_inc > DST_GC_INC) { 00135 dst_gc_timer_inc = DST_GC_INC; 00136 dst_gc_timer_expires = DST_GC_MIN; 00137 mod_timer(&dst_gc_timer, jiffies + dst_gc_timer_expires); 00138 } 00139 00140 spin_unlock_bh(&dst_lock); 00141 }

void* dst_alloc struct dst_ops ops  ) 
 

Definition at line 96 of file dst.c.

References dst_blackhole(), dst_discard(), dst_ops::entries, dst_ops::entry_size, dst_ops::gc, dst_ops::gc_thresh, and dst_ops::kmem_cachep.

Referenced by ip_route_input_mc(), ip_route_input_slow(), ip_route_output_slow(), and ip_rt_redirect().

00097 { 00098 struct dst_entry * dst; 00099 00100 if (ops->gc && atomic_read(&ops->entries) > ops->gc_thresh) { 00101 if (ops->gc()) 00102 return NULL; 00103 } 00104 dst = kmem_cache_alloc(ops->kmem_cachep, SLAB_ATOMIC); 00105 if (!dst) 00106 return NULL; 00107 memset(dst, 0, ops->entry_size); 00108 atomic_set(&dst->__refcnt, 0); 00109 dst->ops = ops; 00110 dst->lastuse = jiffies; 00111 dst->input = dst_discard; 00112 dst->output = dst_blackhole; 00113 #if RT_CACHE_DEBUG >= 2 00114 atomic_inc(&dst_total); 00115 #endif 00116 atomic_inc(&ops->entries); 00117 return dst; 00118 }

int dst_blackhole struct sk_buff skb  )  [static]
 

Definition at line 90 of file dst.c.

References kfree_skb().

Referenced by __dst_free(), dst_alloc(), and dst_dev_event().

00091 { 00092 kfree_skb(skb); 00093 return 0; 00094 }

void dst_destroy struct dst_entry dst  ) 
 

Definition at line 143 of file dst.c.

References dst_ops::destroy, dst_entry::dev, dev_put(), dst_ops::entries, dst_entry::hh, dst_ops::kmem_cachep, neigh_release(), dst_entry::neighbour, and dst_entry::ops.

Referenced by dst_free(), and dst_run_gc().

00144 { 00145 struct neighbour *neigh = dst->neighbour; 00146 struct hh_cache *hh = dst->hh; 00147 00148 dst->hh = NULL; 00149 if (hh && atomic_dec_and_test(&hh->hh_refcnt)) 00150 kfree(hh); 00151 00152 if (neigh) { 00153 dst->neighbour = NULL; 00154 neigh_release(neigh); 00155 } 00156 00157 atomic_dec(&dst->ops->entries); 00158 00159 if (dst->ops->destroy) 00160 dst->ops->destroy(dst); 00161 if (dst->dev) 00162 dev_put(dst->dev); 00163 #if RT_CACHE_DEBUG >= 2 00164 atomic_dec(&dst_total); 00165 #endif 00166 kmem_cache_free(dst->ops->kmem_cachep, dst); 00167 }

int dst_dev_event struct notifier_block *  this,
unsigned long  event,
void *  ptr
[static]
 

Definition at line 169 of file dst.c.

References dev_hold, dev_put(), dst_blackhole(), dst_discard(), dst_garbage_list, dst_lock, loopback_dev, NETIF_F_DYNALLOC, and dst_entry::next.

00170 { 00171 struct net_device *dev = ptr; 00172 struct dst_entry *dst; 00173 00174 switch (event) { 00175 case NETDEV_UNREGISTER: 00176 case NETDEV_DOWN: 00177 spin_lock_bh(&dst_lock); 00178 for (dst = dst_garbage_list; dst; dst = dst->next) { 00179 if (dst->dev == dev) { 00180 /* Dirty hack. We did it in 2.2 (in __dst_free), 00181 we have _very_ good reasons not to repeat 00182 this mistake in 2.3, but we have no choice 00183 now. _It_ _is_ _explicit_ _deliberate_ 00184 _race_ _condition_. 00185 */ 00186 if (event!=NETDEV_DOWN && 00187 !(dev->features & NETIF_F_DYNALLOC) && 00188 dst->output == dst_blackhole) { 00189 dst->dev = &loopback_dev; 00190 dev_put(dev); 00191 dev_hold(&loopback_dev); 00192 dst->output = dst_discard; 00193 if (dst->neighbour && dst->neighbour->dev == dev) { 00194 dst->neighbour->dev = &loopback_dev; 00195 dev_put(dev); 00196 dev_hold(&loopback_dev); 00197 } 00198 } else { 00199 dst->input = dst_discard; 00200 dst->output = dst_blackhole; 00201 } 00202 } 00203 } 00204 spin_unlock_bh(&dst_lock); 00205 break; 00206 } 00207 return NOTIFY_DONE; 00208 }

int dst_discard struct sk_buff skb  )  [static]
 

Definition at line 84 of file dst.c.

References kfree_skb().

Referenced by __dst_free(), dst_alloc(), and dst_dev_event().

00085 { 00086 kfree_skb(skb); 00087 return 0; 00088 }

void __init dst_init void   ) 
 

Definition at line 216 of file dst.c.

References dst_dev_notifier, and register_netdevice_notifier().

Referenced by net_dev_init().

00217 { 00218 register_netdevice_notifier(&dst_dev_notifier); 00219 }

void dst_run_gc unsigned  long  )  [static]
 

Definition at line 44 of file dst.c.

References dst_destroy(), dst_garbage_list, DST_GC_INC, DST_GC_MAX, dst_gc_timer, dst_gc_timer_expires, dst_gc_timer_inc, dst_lock, and dst_entry::next.

00045 { 00046 int delayed = 0; 00047 struct dst_entry * dst, **dstp; 00048 00049 if (!spin_trylock(&dst_lock)) { 00050 mod_timer(&dst_gc_timer, jiffies + HZ/10); 00051 return; 00052 } 00053 00054 00055 del_timer(&dst_gc_timer); 00056 dstp = &dst_garbage_list; 00057 while ((dst = *dstp) != NULL) { 00058 if (atomic_read(&dst->__refcnt)) { 00059 dstp = &dst->next; 00060 delayed++; 00061 continue; 00062 } 00063 *dstp = dst->next; 00064 dst_destroy(dst); 00065 } 00066 if (!dst_garbage_list) { 00067 dst_gc_timer_inc = DST_GC_MAX; 00068 goto out; 00069 } 00070 if ((dst_gc_timer_expires += dst_gc_timer_inc) > DST_GC_MAX) 00071 dst_gc_timer_expires = DST_GC_MAX; 00072 dst_gc_timer_inc += DST_GC_INC; 00073 dst_gc_timer.expires = jiffies + dst_gc_timer_expires; 00074 #if RT_CACHE_DEBUG >= 2 00075 printk("dst_total: %d/%d %ld\n", 00076 atomic_read(&dst_total), delayed, dst_gc_timer_expires); 00077 #endif 00078 add_timer(&dst_gc_timer); 00079 00080 out: 00081 spin_unlock(&dst_lock); 00082 }


Variable Documentation

struct notifier_block dst_dev_notifier
 

Initial value:

{ dst_dev_event, NULL, 0 }
Definition at line 210 of file dst.c.

Referenced by dst_init().

struct dst_entry* dst_garbage_list [static]
 

Definition at line 30 of file dst.c.

Referenced by __dst_free(), dst_dev_event(), and dst_run_gc().

struct timer_list dst_gc_timer [static]
 

Initial value:

{ data: DST_GC_MIN, function: dst_run_gc }
Definition at line 40 of file dst.c.

Referenced by __dst_free(), and dst_run_gc().

unsigned long dst_gc_timer_expires [static]
 

Definition at line 36 of file dst.c.

Referenced by __dst_free(), and dst_run_gc().

unsigned long dst_gc_timer_inc = DST_GC_MAX [static]
 

Definition at line 37 of file dst.c.

Referenced by __dst_free(), and dst_run_gc().

spinlock_t dst_lock = SPIN_LOCK_UNLOCKED [static]
 

Definition at line 34 of file dst.c.

Referenced by __dst_free(), dst_dev_event(), and dst_run_gc().


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