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

route.h File Reference

#include <linux/config.h>
#include <net/dst.h>
#include <net/inetpeer.h>
#include <linux/in_route.h>
#include <linux/rtnetlink.h>
#include <linux/route.h>
#include <linux/ip.h>
#include <linux/cache.h>

Go to the source code of this file.

Classes

struct  rt_key
struct  rtable
struct  ip_rt_acct
struct  rt_cache_stat

Defines

#define RTO_ONLINK   0x01
#define RTO_CONN   0
#define RT_CONN_FLAGS(sk)   (RT_TOS(sk->protinfo.af_inet.tos) | sk->localroute)
#define IPTOS_RT_MASK   (IPTOS_TOS_MASK & ~3)

Functions

void ip_rt_init (void)
void ip_rt_redirect (u32 old_gw, u32 dst, u32 new_gw, u32 src, u8 tos, struct net_device *dev)
void ip_rt_advice (struct rtable **rp, int advice)
void rt_cache_flush (int how)
int ip_route_output_key (struct rtable **, const struct rt_key *key)
int ip_route_input (struct sk_buff *, u32 dst, u32 src, u8 tos, struct net_device *devin)
unsigned short ip_rt_frag_needed (struct iphdr *iph, unsigned short new_mtu)
void ip_rt_update_pmtu (struct dst_entry *dst, unsigned mtu)
void ip_rt_send_redirect (struct sk_buff *skb)
unsigned inet_addr_type (u32 addr)
void ip_rt_multicast_event (struct in_device *)
int ip_rt_ioctl (unsigned int cmd, void *arg)
void ip_rt_get_source (u8 *src, struct rtable *rt)
int ip_rt_dump (struct sk_buff *skb, struct netlink_callback *cb)
int ip_route_output (struct rtable **rp, u32 daddr, u32 saddr, u32 tos, int oif)
void ip_rt_put (struct rtable *rt)
char rt_tos2priority (u8 tos)
int ip_route_connect (struct rtable **rp, u32 dst, u32 src, u32 tos, int oif)
void rt_bind_peer (struct rtable *rt, int create)
inet_peerrt_get_peer (struct rtable *rt)

Variables

rt_cache_stat ____cacheline_aligned_in_smp
ip_rt_acctip_rt_acct
__u8 ip_tos2prio [16]


Define Documentation

#define IPTOS_RT_MASK   (IPTOS_TOS_MASK & ~3)
 

Definition at line 157 of file route.h.

Referenced by ip_route_input(), ip_route_output_key(), ip_route_output_slow(), ip_rt_frag_needed(), and ip_rt_redirect().

#define RT_CONN_FLAGS sk   )     (RT_TOS(sk->protinfo.af_inet.tos) | sk->localroute)
 

Definition at line 46 of file route.h.

Referenced by cookie_v4_check(), ip_queue_xmit(), tcp_v4_connect(), tcp_v4_rebuild_header(), tcp_v4_route_req(), and udp_connect().

#define RTO_CONN   0
 

Definition at line 42 of file route.h.

Referenced by masquerade_target().

#define RTO_ONLINK   0x01
 

Definition at line 40 of file route.h.

Referenced by arp_req_delete(), arp_req_set(), ip_route_output_key(), ip_route_output_slow(), raw_sendmsg(), and udp_sendmsg().


Function Documentation

unsigned inet_addr_type u32  addr  ) 
 

Definition at line 171 of file fib_frontend.c.

References BADCLASS, fib_res_put(), local_table, MULTICAST, fib_table::tb_lookup, fib_result::type, and ZERONET.

Referenced by __ip_vs_update_dest(), arp_constructor(), arp_find(), arp_process(), arp_solicit(), fib_check_nh(), fib_convert_rtentry(), fib_create_info(), fib_del_ifaddr(), fib_rules_policy(), icmp_unreach(), inet_bind(), ip_options_compile(), ip_options_echo(), ip_route_me_harder(), ip_rt_redirect(), ip_vs_leave(), ip_vs_new_dest(), and raw_bind().

00172 { 00173 struct rt_key key; 00174 struct fib_result res; 00175 unsigned ret = RTN_BROADCAST; 00176 00177 if (ZERONET(addr) || BADCLASS(addr)) 00178 return RTN_BROADCAST; 00179 if (MULTICAST(addr)) 00180 return RTN_MULTICAST; 00181 00182 memset(&key, 0, sizeof(key)); 00183 key.dst = addr; 00184 #ifdef CONFIG_IP_MULTIPLE_TABLES 00185 res.r = NULL; 00186 #endif 00187 00188 if (local_table) { 00189 ret = RTN_UNICAST; 00190 if (local_table->tb_lookup(local_table, &key, &res) == 0) { 00191 ret = res.type; 00192 fib_res_put(&res); 00193 } 00194 } 00195 return ret; 00196 }

int ip_route_connect struct rtable **  rp,
u32  dst,
u32  src,
u32  tos,
int  oif
[inline, static]
 

Definition at line 166 of file route.h.

References ip_route_output(), and ip_rt_put().

Referenced by tcp_v4_connect(), tcp_v4_reselect_saddr(), and udp_connect().

00167 { 00168 int err; 00169 err = ip_route_output(rp, dst, src, tos, oif); 00170 if (err || (dst && src)) 00171 return err; 00172 dst = (*rp)->rt_dst; 00173 src = (*rp)->rt_src; 00174 ip_rt_put(*rp); 00175 *rp = NULL; 00176 return ip_route_output(rp, dst, src, tos, oif); 00177 }

int ip_route_input struct sk_buff skb,
u32  daddr,
u32  saddr,
u8  tos,
struct net_device dev
 

As a side effect, skb->dst (of type struct dst_entry) is assigned the retrieved routing table entry. Because the first part of a routing table entry (struct rtable) is actually struct dst_entry, a routing table entry can be cast to a dst_entry.
Definition at line 1712 of file route.c.

References __in_dev_get(), rt_hash_bucket::chain, sk_buff::dst, dst_hold(), net_device::ifindex, IN_DEV_MFORWARD, rt_cache_stat::in_hit, rt_cache_stat::in_hlist_search, inetdev_lock, ip_check_mc(), ip_route_input_mc(), ip_route_input_slow(), IPTOS_RT_MASK, LOCAL_MCAST, MULTICAST, rt_cache_stat, rt_hash_code(), rt_hash_table, and rtable::u.

Referenced by arp_process(), fw_in(), inet_rtm_getroute(), ip_options_rcv_srr(), ip_rcv_finish(), ip_route_me_harder(), ipgre_err(), ipip_err(), route_mirror(), and route_reverse().

01714 { 01715 struct rtable * rth; 01716 unsigned hash; 01717 int iif = dev->ifindex; 01718 01719 tos &= IPTOS_RT_MASK; 01720 hash = rt_hash_code(daddr, saddr ^ (iif << 5), tos); 01721 01722 read_lock(&rt_hash_table[hash].lock); 01723 for (rth = rt_hash_table[hash].chain; rth; rth = rth->u.rt_next) { 01724 if (rth->key.dst == daddr && 01725 rth->key.src == saddr && 01726 rth->key.iif == iif && 01727 rth->key.oif == 0 && 01728 #ifdef CONFIG_IP_ROUTE_FWMARK 01729 rth->key.fwmark == skb->nfmark && 01730 #endif 01731 rth->key.tos == tos) { 01732 rth->u.dst.lastuse = jiffies; 01733 dst_hold(&rth->u.dst); 01734 rth->u.dst.__use++; 01735 rt_cache_stat[smp_processor_id()].in_hit++; 01736 read_unlock(&rt_hash_table[hash].lock); 01737 skb->dst = (struct dst_entry*)rth; 01738 return 0; 01739 } 01740 rt_cache_stat[smp_processor_id()].in_hlist_search++; 01741 } 01742 read_unlock(&rt_hash_table[hash].lock); 01743 01744 /* Multicast recognition logic is moved from route cache to here. 01745 The problem was that too many Ethernet cards have broken/missing 01746 hardware multicast filters :-( As result the host on multicasting 01747 network acquires a lot of useless route cache entries, sort of 01748 SDR messages from all the world. Now we try to get rid of them. 01749 Really, provided software IP multicast filter is organized 01750 reasonably (at least, hashed), it does not result in a slowdown 01751 comparing with route cache reject entries. 01752 Note, that multicast routers are not affected, because 01753 route cache entry is created eventually. 01754 */ 01755 if (MULTICAST(daddr)) { 01756 struct in_device *in_dev; 01757 01758 read_lock(&inetdev_lock); 01759 if ((in_dev = __in_dev_get(dev)) != NULL) { 01760 int our = ip_check_mc(in_dev, daddr, saddr); 01761 if (our 01762 #ifdef CONFIG_IP_MROUTE 01763 || (!LOCAL_MCAST(daddr) && IN_DEV_MFORWARD(in_dev)) 01764 #endif 01765 ) { 01766 read_unlock(&inetdev_lock); 01767 return ip_route_input_mc(skb, daddr, saddr, 01768 tos, dev, our); 01769 } 01770 } 01771 read_unlock(&inetdev_lock); 01772 return -EINVAL; 01773 } 01774 return ip_route_input_slow(skb, daddr, saddr, tos, dev); 01775 }

int ip_route_output struct rtable **  rp,
u32  daddr,
u32  saddr,
u32  tos,
int  oif
[inline, static]
 

Definition at line 142 of file route.h.

References ip_route_output_key().

Referenced by __ip_vs_get_out_rt(), arp_filter(), arp_req_delete(), arp_req_set(), cookie_v4_check(), do_masquerade(), icmp_reply(), icmp_send(), inet_rtm_getroute(), ip_mc_find_dev(), ip_queue_xmit(), ip_route_connect(), ip_send_reply(), ip_vs_bypass_xmit(), ipgre_err(), ipgre_tunnel_init(), ipgre_tunnel_xmit(), ipip_err(), ipip_tunnel_init(), ipip_tunnel_xmit(), ipmr_queue_xmit(), raw_sendmsg(), send_unreach(), tcp_v4_rebuild_header(), tcp_v4_route_req(), and udp_sendmsg().

00144 { 00145 struct rt_key key = { dst:daddr, src:saddr, oif:oif, tos:tos }; 00146 00147 return ip_route_output_key(rp, &key); 00148 }

int ip_route_output_key struct rtable **  ,
const struct rt_key key
 

Definition at line 2111 of file route.c.

References rt_hash_bucket::chain, rt_key::dst, dst_hold(), ip_route_output_slow(), IPTOS_RT_MASK, rt_key::oif, rt_cache_stat::out_hit, rt_cache_stat::out_hlist_search, rt_cache_stat, rt_hash_code(), rt_hash_table, RTO_ONLINK, rt_key::src, rt_key::tos, and rtable::u.

Referenced by ip_route_me_harder(), ip_route_output(), masquerade_target(), route_mirror(), and route_reverse().

02112 { 02113 unsigned hash; 02114 struct rtable *rth; 02115 02116 hash = rt_hash_code(key->dst, key->src ^ (key->oif << 5), key->tos); 02117 02118 read_lock_bh(&rt_hash_table[hash].lock); 02119 for (rth = rt_hash_table[hash].chain; rth; rth = rth->u.rt_next) { 02120 if (rth->key.dst == key->dst && 02121 rth->key.src == key->src && 02122 rth->key.iif == 0 && 02123 rth->key.oif == key->oif && 02124 #ifdef CONFIG_IP_ROUTE_FWMARK 02125 rth->key.fwmark == key->fwmark && 02126 #endif 02127 !((rth->key.tos ^ key->tos) & 02128 (IPTOS_RT_MASK | RTO_ONLINK))) { 02129 rth->u.dst.lastuse = jiffies; 02130 dst_hold(&rth->u.dst); 02131 rth->u.dst.__use++; 02132 rt_cache_stat[smp_processor_id()].out_hit++; 02133 read_unlock_bh(&rt_hash_table[hash].lock); 02134 *rp = rth; 02135 return 0; 02136 } 02137 rt_cache_stat[smp_processor_id()].out_hlist_search++; 02138 } 02139 read_unlock_bh(&rt_hash_table[hash].lock); 02140 02141 return ip_route_output_slow(rp, key); 02142 }

void ip_rt_advice struct rtable **  rp,
int  advice
 

int ip_rt_dump struct sk_buff skb,
struct netlink_callback cb
 

Definition at line 2315 of file route.c.

References netlink_callback::args, rt_hash_bucket::chain, sk_buff::dst, dst_clone(), dst_release(), sk_buff::len, NETLINK_CB, netlink_callback::nlh, nlmsghdr::nlmsg_seq, rt_fill_info(), rt_hash_mask, rt_hash_table, netlink_callback::skb, and rtable::u.

Referenced by inet_dump_fib().

02316 { 02317 struct rtable *rt; 02318 int h, s_h; 02319 int idx, s_idx; 02320 02321 s_h = cb->args[0]; 02322 s_idx = idx = cb->args[1]; 02323 for (h = 0; h <= rt_hash_mask; h++) { 02324 if (h < s_h) continue; 02325 if (h > s_h) 02326 s_idx = 0; 02327 read_lock_bh(&rt_hash_table[h].lock); 02328 for (rt = rt_hash_table[h].chain, idx = 0; rt; 02329 rt = rt->u.rt_next, idx++) { 02330 if (idx < s_idx) 02331 continue; 02332 skb->dst = dst_clone(&rt->u.dst); 02333 if (rt_fill_info(skb, NETLINK_CB(cb->skb).pid, 02334 cb->nlh->nlmsg_seq, 02335 RTM_NEWROUTE, 1) <= 0) { 02336 dst_release(xchg(&skb->dst, NULL)); 02337 read_unlock_bh(&rt_hash_table[h].lock); 02338 goto done; 02339 } 02340 dst_release(xchg(&skb->dst, NULL)); 02341 } 02342 read_unlock_bh(&rt_hash_table[h].lock); 02343 } 02344 02345 done: 02346 cb->args[0] = h; 02347 cb->args[1] = idx; 02348 return skb->len; 02349 }

unsigned short ip_rt_frag_needed struct iphdr iph,
unsigned short  new_mtu
 

Definition at line 1108 of file route.c.

References rt_hash_bucket::chain, iphdr::daddr, dst_confirm(), dst_set_expires(), guess_mtu(), ip_rt_min_pmtu, ip_rt_mtu_expires, IPTOS_RT_MASK, rt_hash_code(), rt_hash_table, iphdr::saddr, iphdr::tos, iphdr::tot_len, and rtable::u.

Referenced by icmp_unreach().

01109 { 01110 int i; 01111 unsigned short old_mtu = ntohs(iph->tot_len); 01112 struct rtable *rth; 01113 u32 skeys[2] = { iph->saddr, 0, }; 01114 u32 daddr = iph->daddr; 01115 u8 tos = iph->tos & IPTOS_RT_MASK; 01116 unsigned short est_mtu = 0; 01117 01118 if (ipv4_config.no_pmtu_disc) 01119 return 0; 01120 01121 for (i = 0; i < 2; i++) { 01122 unsigned hash = rt_hash_code(daddr, skeys[i], tos); 01123 01124 read_lock(&rt_hash_table[hash].lock); 01125 for (rth = rt_hash_table[hash].chain; rth; 01126 rth = rth->u.rt_next) { 01127 if (rth->key.dst == daddr && 01128 rth->key.src == skeys[i] && 01129 rth->rt_dst == daddr && 01130 rth->rt_src == iph->saddr && 01131 rth->key.tos == tos && 01132 rth->key.iif == 0 && 01133 !(rth->u.dst.mxlock & (1 << RTAX_MTU))) { 01134 unsigned short mtu = new_mtu; 01135 01136 if (new_mtu < 68 || new_mtu >= old_mtu) { 01137 01138 /* BSD 4.2 compatibility hack :-( */ 01139 if (mtu == 0 && 01140 old_mtu >= rth->u.dst.pmtu && 01141 old_mtu >= 68 + (iph->ihl << 2)) 01142 old_mtu -= iph->ihl << 2; 01143 01144 mtu = guess_mtu(old_mtu); 01145 } 01146 if (mtu <= rth->u.dst.pmtu) { 01147 if (mtu < rth->u.dst.pmtu) { 01148 dst_confirm(&rth->u.dst); 01149 if (mtu < ip_rt_min_pmtu) { 01150 mtu = ip_rt_min_pmtu; 01151 rth->u.dst.mxlock |= 01152 (1 << RTAX_MTU); 01153 } 01154 rth->u.dst.pmtu = mtu; 01155 dst_set_expires(&rth->u.dst, 01156 ip_rt_mtu_expires); 01157 } 01158 est_mtu = mtu; 01159 } 01160 } 01161 } 01162 read_unlock(&rt_hash_table[hash].lock); 01163 } 01164 return est_mtu ? : new_mtu; 01165 }

void ip_rt_get_source u8 *  src,
struct rtable rt
 

Definition at line 1232 of file route.c.

References fib_lookup(), FIB_RES_PREFSRC, fib_res_put(), rt_key::iif, inet_select_addr(), rtable::key, rtable::rt_gateway, rtable::rt_src, fib_result::type, and rtable::u.

Referenced by ip_forward_options(), and ip_options_build().

01233 { 01234 u32 src; 01235 struct fib_result res; 01236 01237 if (rt->key.iif == 0) 01238 src = rt->rt_src; 01239 else if (fib_lookup(&rt->key, &res) == 0) { 01240 #ifdef CONFIG_IP_ROUTE_NAT 01241 if (res.type == RTN_NAT) 01242 src = inet_select_addr(rt->u.dst.dev, rt->rt_gateway, 01243 RT_SCOPE_UNIVERSE); 01244 else 01245 #endif 01246 src = FIB_RES_PREFSRC(res); 01247 fib_res_put(&res); 01248 } else 01249 src = inet_select_addr(rt->u.dst.dev, rt->rt_gateway, 01250 RT_SCOPE_UNIVERSE); 01251 memcpy(addr, &src, 4); 01252 }

void ip_rt_init void   ) 
 

Definition at line 2593 of file route.c.

References rt_hash_bucket::chain, devinet_init(), dst_ops::gc_thresh, ip_fib_init(), ip_rt_gc_interval, ip_rt_max_size, ip_rt_secret_interval, ipv4_dst_ops, dst_ops::kmem_cachep, rt_hash_bucket::lock, net_random(), rt_cache_get_info(), rt_cache_stat_get_info(), rt_check_expire, rt_flush_timer, rt_hash_log, rt_hash_mask, rt_hash_rnd, rt_hash_table, rt_periodic_timer, rt_run_flush, rt_secret_rebuild(), and rt_secret_timer.

Referenced by ip_init().

02594 { 02595 int i, order, goal; 02596 02597 rt_hash_rnd = (int) ((num_physpages ^ (num_physpages>>8)) ^ 02598 (jiffies ^ (jiffies >> 7))); 02599 02600 #ifdef CONFIG_NET_CLS_ROUTE 02601 for (order = 0; 02602 (PAGE_SIZE << order) < 256 * sizeof(struct ip_rt_acct) * NR_CPUS; order++) 02603 /* NOTHING */; 02604 ip_rt_acct = (struct ip_rt_acct *)__get_free_pages(GFP_KERNEL, order); 02605 if (!ip_rt_acct) 02606 panic("IP: failed to allocate ip_rt_acct\n"); 02607 memset(ip_rt_acct, 0, PAGE_SIZE << order); 02608 #endif 02609 02610 ipv4_dst_ops.kmem_cachep = kmem_cache_create("ip_dst_cache", 02611 sizeof(struct rtable), 02612 0, SLAB_HWCACHE_ALIGN, 02613 NULL, NULL); 02614 02615 if (!ipv4_dst_ops.kmem_cachep) 02616 panic("IP: failed to allocate ip_dst_cache\n"); 02617 02618 goal = num_physpages >> (26 - PAGE_SHIFT); 02619 02620 for (order = 0; (1UL << order) < goal; order++) 02621 /* NOTHING */; 02622 02623 do { 02624 rt_hash_mask = (1UL << order) * PAGE_SIZE / 02625 sizeof(struct rt_hash_bucket); 02626 while (rt_hash_mask & (rt_hash_mask - 1)) 02627 rt_hash_mask--; 02628 rt_hash_table = (struct rt_hash_bucket *) 02629 __get_free_pages(GFP_ATOMIC, order); 02630 } while (rt_hash_table == NULL && --order > 0); 02631 02632 if (!rt_hash_table) 02633 panic("Failed to allocate IP route cache hash table\n"); 02634 02635 printk(KERN_INFO "IP: routing cache hash table of %u buckets, %ldKbytes\n", 02636 rt_hash_mask, 02637 (long) (rt_hash_mask * sizeof(struct rt_hash_bucket)) / 1024); 02638 02639 for (rt_hash_log = 0; (1 << rt_hash_log) != rt_hash_mask; rt_hash_log++) 02640 /* NOTHING */; 02641 02642 rt_hash_mask--; 02643 for (i = 0; i <= rt_hash_mask; i++) { 02644 rt_hash_table[i].lock = RW_LOCK_UNLOCKED; 02645 rt_hash_table[i].chain = NULL; 02646 } 02647 02648 ipv4_dst_ops.gc_thresh = (rt_hash_mask + 1); 02649 ip_rt_max_size = (rt_hash_mask + 1) * 16; 02650 02651 devinet_init(); 02652 ip_fib_init(); 02653 02654 rt_flush_timer.function = rt_run_flush; 02655 rt_periodic_timer.function = rt_check_expire; 02656 rt_secret_timer.function = rt_secret_rebuild; 02657 02658 /* All the timers, started at system startup tend 02659 to synchronize. Perturb it a bit. 02660 */ 02661 rt_periodic_timer.expires = jiffies + net_random() % ip_rt_gc_interval + 02662 ip_rt_gc_interval; 02663 add_timer(&rt_periodic_timer); 02664 02665 rt_secret_timer.expires = jiffies + net_random() % ip_rt_secret_interval + 02666 ip_rt_secret_interval; 02667 add_timer(&rt_secret_timer); 02668 02669 proc_net_create ("rt_cache", 0, rt_cache_get_info); 02670 proc_net_create ("rt_cache_stat", 0, rt_cache_stat_get_info); 02671 #ifdef CONFIG_NET_CLS_ROUTE 02672 create_proc_read_entry("net/rt_acct", 0, 0, ip_rt_acct_read, NULL); 02673 #endif 02674 }

int ip_rt_ioctl unsigned int  cmd,
void *  arg
 

Definition at line 292 of file fib_frontend.c.

References fib_convert_rtentry(), fib_get_table(), fib_new_table(), kern_rta::rta_mx, rtnl_lock(), and rtnl_unlock().

Referenced by ic_route_ioctl(), and inet_ioctl().

00293 { 00294 int err; 00295 struct kern_rta rta; 00296 struct rtentry r; 00297 struct { 00298 struct nlmsghdr nlh; 00299 struct rtmsg rtm; 00300 } req; 00301 00302 switch (cmd) { 00303 case SIOCADDRT: /* Add a route */ 00304 case SIOCDELRT: /* Delete a route */ 00305 if (!capable(CAP_NET_ADMIN)) 00306 return -EPERM; 00307 if (copy_from_user(&r, arg, sizeof(struct rtentry))) 00308 return -EFAULT; 00309 rtnl_lock(); 00310 err = fib_convert_rtentry(cmd, &req.nlh, &req.rtm, &rta, &r); 00311 if (err == 0) { 00312 if (cmd == SIOCDELRT) { 00313 struct fib_table *tb = fib_get_table(req.rtm.rtm_table); 00314 err = -ESRCH; 00315 if (tb) 00316 err = tb->tb_delete(tb, &req.rtm, &rta, &req.nlh, NULL); 00317 } else { 00318 struct fib_table *tb = fib_new_table(req.rtm.rtm_table); 00319 err = -ENOBUFS; 00320 if (tb) 00321 err = tb->tb_insert(tb, &req.rtm, &rta, &req.nlh, NULL); 00322 } 00323 if (rta.rta_mx) 00324 kfree(rta.rta_mx); 00325 } 00326 rtnl_unlock(); 00327 return err; 00328 } 00329 return -EINVAL; 00330 }

void ip_rt_multicast_event struct in_device  ) 
 

Definition at line 2351 of file route.c.

References rt_cache_flush().

Referenced by ip_mc_add1_src(), ip_mc_dec_group(), ip_mc_del1_src(), ip_mc_inc_group(), vif_add(), and vif_delete().

02352 { 02353 rt_cache_flush(0); 02354 }

void ip_rt_put struct rtable rt  )  [inline, static]
 

Definition at line 151 of file route.h.

References dst_release(), and rtable::u.

Referenced by arp_filter(), arp_req_delete(), arp_req_set(), do_masquerade(), icmp_reply(), icmp_send(), ip_mc_find_dev(), ip_options_rcv_srr(), ip_route_connect(), ip_rt_redirect(), ip_send_reply(), ip_vs_bypass_xmit(), ip_vs_dr_xmit(), ip_vs_in_icmp(), ip_vs_nat_xmit(), ip_vs_tunnel_xmit(), ipgre_err(), ipgre_tunnel_init(), ipgre_tunnel_xmit(), ipip_err(), ipip_tunnel_init(), ipip_tunnel_xmit(), ipmr_queue_xmit(), ipv4_negative_advice(), masquerade_target(), raw_sendmsg(), rt_del(), rt_drop(), send_unreach(), tcp_v4_connect(), tcp_v4_route_req(), udp_connect(), and udp_sendmsg().

00152 { 00153 if (rt) 00154 dst_release(&rt->u.dst); 00155 }

void ip_rt_redirect u32  old_gw,
u32  dst,
u32  new_gw,
u32  src,
u8  tos,
struct net_device dev
 

Definition at line 840 of file route.c.

References arp_bind_neighbour(), BADCLASS, rt_hash_bucket::chain, dev_hold, dst_alloc(), dst_confirm(), dst_hold(), net_device::ifindex, in_dev_get(), IN_DEV_LOG_MARTIANS, in_dev_put(), IN_DEV_RX_REDIRECTS, IN_DEV_SEC_REDIRECTS, IN_DEV_SHARED_MEDIA, inet_addr_onlink(), inet_addr_type(), ip_fib_check_default(), ip_rt_put(), IPTOS_RT_MASK, ipv4_dst_ops, MULTICAST, net_device::name, neigh_event_send(), net_ratelimit(), NUD_VALID, rt_del(), rt_drop(), rt_hash_code(), rt_hash_table, rt_intern_hash(), and ZERONET.

Referenced by icmp_redirect().

00842 { 00843 int i, k; 00844 struct in_device *in_dev = in_dev_get(dev); 00845 struct rtable *rth, **rthp; 00846 u32 skeys[2] = { saddr, 0 }; 00847 int ikeys[2] = { dev->ifindex, 0 }; 00848 00849 tos &= IPTOS_RT_MASK; 00850 00851 if (!in_dev) 00852 return; 00853 00854 if (new_gw == old_gw || !IN_DEV_RX_REDIRECTS(in_dev) 00855 || MULTICAST(new_gw) || BADCLASS(new_gw) || ZERONET(new_gw)) 00856 goto reject_redirect; 00857 00858 if (!IN_DEV_SHARED_MEDIA(in_dev)) { 00859 if (!inet_addr_onlink(in_dev, new_gw, old_gw)) 00860 goto reject_redirect; 00861 if (IN_DEV_SEC_REDIRECTS(in_dev) && ip_fib_check_default(new_gw, dev)) 00862 goto reject_redirect; 00863 } else { 00864 if (inet_addr_type(new_gw) != RTN_UNICAST) 00865 goto reject_redirect; 00866 } 00867 00868 for (i = 0; i < 2; i++) { 00869 for (k = 0; k < 2; k++) { 00870 unsigned hash = rt_hash_code(daddr, 00871 skeys[i] ^ (ikeys[k] << 5), 00872 tos); 00873 00874 rthp=&rt_hash_table[hash].chain; 00875 00876 read_lock(&rt_hash_table[hash].lock); 00877 while ((rth = *rthp) != NULL) { 00878 struct rtable *rt; 00879 00880 if (rth->key.dst != daddr || 00881 rth->key.src != skeys[i] || 00882 rth->key.tos != tos || 00883 rth->key.oif != ikeys[k] || 00884 rth->key.iif != 0) { 00885 rthp = &rth->u.rt_next; 00886 continue; 00887 } 00888 00889 if (rth->rt_dst != daddr || 00890 rth->rt_src != saddr || 00891 rth->u.dst.error || 00892 rth->rt_gateway != old_gw || 00893 rth->u.dst.dev != dev) 00894 break; 00895 00896 dst_hold(&rth->u.dst); 00897 read_unlock(&rt_hash_table[hash].lock); 00898 00899 rt = dst_alloc(&ipv4_dst_ops); 00900 if (rt == NULL) { 00901 ip_rt_put(rth); 00902 in_dev_put(in_dev); 00903 return; 00904 } 00905 00906 /* Copy all the information. */ 00907 *rt = *rth; 00908 rt->u.dst.__use = 1; 00909 atomic_set(&rt->u.dst.__refcnt, 1); 00910 if (rt->u.dst.dev) 00911 dev_hold(rt->u.dst.dev); 00912 rt->u.dst.lastuse = jiffies; 00913 rt->u.dst.neighbour = NULL; 00914 rt->u.dst.hh = NULL; 00915 rt->u.dst.obsolete = 0; 00916 00917 rt->rt_flags |= RTCF_REDIRECTED; 00918 00919 /* Gateway is different ... */ 00920 rt->rt_gateway = new_gw; 00921 00922 /* Redirect received -> path was valid */ 00923 dst_confirm(&rth->u.dst); 00924 00925 if (rt->peer) 00926 atomic_inc(&rt->peer->refcnt); 00927 00928 if (arp_bind_neighbour(&rt->u.dst) || 00929 !(rt->u.dst.neighbour->nud_state & 00930 NUD_VALID)) { 00931 if (rt->u.dst.neighbour) 00932 neigh_event_send(rt->u.dst.neighbour, NULL); 00933 ip_rt_put(rth); 00934 rt_drop(rt); 00935 goto do_next; 00936 } 00937 00938 rt_del(hash, rth); 00939 if (!rt_intern_hash(hash, rt, &rt)) 00940 ip_rt_put(rt); 00941 goto do_next; 00942 } 00943 read_unlock(&rt_hash_table[hash].lock); 00944 do_next: 00945 ; 00946 } 00947 } 00948 in_dev_put(in_dev); 00949 return; 00950 00951 reject_redirect: 00952 #ifdef CONFIG_IP_ROUTE_VERBOSE 00953 if (IN_DEV_LOG_MARTIANS(in_dev) && net_ratelimit()) 00954 printk(KERN_INFO "Redirect from %u.%u.%u.%u on %s about " 00955 "%u.%u.%u.%u ignored.\n" 00956 " Advised path = %u.%u.%u.%u -> %u.%u.%u.%u, " 00957 "tos %02x\n", 00958 NIPQUAD(old_gw), dev->name, NIPQUAD(new_gw), 00959 NIPQUAD(saddr), NIPQUAD(daddr), tos); 00960 #endif 00961 in_dev_put(in_dev); 00962 }

void ip_rt_send_redirect struct sk_buff skb  ) 
 

Definition at line 1007 of file route.c.

References sk_buff::dst, icmp_send(), in_dev_get(), IN_DEV_LOG_MARTIANS, in_dev_put(), IN_DEV_TX_REDIRECTS, ip_rt_redirect_load, ip_rt_redirect_number, ip_rt_redirect_silence, and net_ratelimit().

Referenced by ip_forward().

01008 { 01009 struct rtable *rt = (struct rtable*)skb->dst; 01010 struct in_device *in_dev = in_dev_get(rt->u.dst.dev); 01011 01012 if (!in_dev) 01013 return; 01014 01015 if (!IN_DEV_TX_REDIRECTS(in_dev)) 01016 goto out; 01017 01018 /* No redirected packets during ip_rt_redirect_silence; 01019 * reset the algorithm. 01020 */ 01021 if (time_after(jiffies, rt->u.dst.rate_last + ip_rt_redirect_silence)) 01022 rt->u.dst.rate_tokens = 0; 01023 01024 /* Too many ignored redirects; do not send anything 01025 * set u.dst.rate_last to the last seen redirected packet. 01026 */ 01027 if (rt->u.dst.rate_tokens >= ip_rt_redirect_number) { 01028 rt->u.dst.rate_last = jiffies; 01029 goto out; 01030 } 01031 01032 /* Check for load limit; set rate_last to the latest sent 01033 * redirect. 01034 */ 01035 if (time_after(jiffies, 01036 (rt->u.dst.rate_last + 01037 (ip_rt_redirect_load << rt->u.dst.rate_tokens)))) { 01038 icmp_send(skb, ICMP_REDIRECT, ICMP_REDIR_HOST, rt->rt_gateway); 01039 rt->u.dst.rate_last = jiffies; 01040 ++rt->u.dst.rate_tokens; 01041 #ifdef CONFIG_IP_ROUTE_VERBOSE 01042 if (IN_DEV_LOG_MARTIANS(in_dev) && 01043 rt->u.dst.rate_tokens == ip_rt_redirect_number && 01044 net_ratelimit()) 01045 printk(KERN_WARNING "host %u.%u.%u.%u/if%d ignores " 01046 "redirects for %u.%u.%u.%u to %u.%u.%u.%u.\n", 01047 NIPQUAD(rt->rt_src), rt->rt_iif, 01048 NIPQUAD(rt->rt_dst), NIPQUAD(rt->rt_gateway)); 01049 #endif 01050 } 01051 out: 01052 in_dev_put(in_dev); 01053 }

void ip_rt_update_pmtu struct dst_entry dst,
unsigned  mtu
 

Definition at line 1167 of file route.c.

References dst_set_expires(), ip_rt_min_pmtu, ip_rt_mtu_expires, dst_entry::mxlock, and dst_entry::pmtu.

Referenced by do_pmtu_discovery().

01168 { 01169 if (dst->pmtu > mtu && mtu >= 68 && 01170 !(dst->mxlock & (1 << RTAX_MTU))) { 01171 if (mtu < ip_rt_min_pmtu) { 01172 mtu = ip_rt_min_pmtu; 01173 dst->mxlock |= (1 << RTAX_MTU); 01174 } 01175 dst->pmtu = mtu; 01176 dst_set_expires(dst, ip_rt_mtu_expires); 01177 } 01178 }

void rt_bind_peer struct rtable rt,
int  create
 

Definition at line 766 of file route.c.

References inet_getpeer(), inet_putpeer(), rtable::peer, and rtable::rt_dst.

Referenced by __ip_select_ident(), rt_get_peer(), and tcp_v4_remember_stamp().

00767 { 00768 static spinlock_t rt_peer_lock = SPIN_LOCK_UNLOCKED; 00769 struct inet_peer *peer; 00770 00771 peer = inet_getpeer(rt->rt_dst, create); 00772 00773 spin_lock_bh(&rt_peer_lock); 00774 if (rt->peer == NULL) { 00775 rt->peer = peer; 00776 peer = NULL; 00777 } 00778 spin_unlock_bh(&rt_peer_lock); 00779 if (peer) 00780 inet_putpeer(peer); 00781 }

void rt_cache_flush int  how  ) 
 

Definition at line 468 of file route.c.

References ip_rt_max_delay, ip_rt_min_delay, rt_deadline, rt_flush_lock, rt_flush_timer, and rt_run_flush.

Referenced by arp_netdev_event(), fib_disable_ip(), fib_flush(), fib_inetaddr_event(), fib_netdev_event(), fn_hash_delete(), fn_hash_insert(), ip_rt_multicast_event(), and rt_secret_rebuild().

00469 { 00470 unsigned long now = jiffies; 00471 int user_mode = !in_softirq(); 00472 00473 if (delay < 0) 00474 delay = ip_rt_min_delay; 00475 00476 spin_lock_bh(&rt_flush_lock); 00477 00478 if (del_timer(&rt_flush_timer) && delay > 0 && rt_deadline) { 00479 long tmo = (long)(rt_deadline - now); 00480 00481 /* If flush timer is already running 00482 and flush request is not immediate (delay > 0): 00483 00484 if deadline is not achieved, prolongate timer to "delay", 00485 otherwise fire it at deadline time. 00486 */ 00487 00488 if (user_mode && tmo < ip_rt_max_delay-ip_rt_min_delay) 00489 tmo = 0; 00490 00491 if (delay > tmo) 00492 delay = tmo; 00493 } 00494 00495 if (delay <= 0) { 00496 spin_unlock_bh(&rt_flush_lock); 00497 SMP_TIMER_NAME(rt_run_flush)(0); 00498 return; 00499 } 00500 00501 if (rt_deadline == 0) 00502 rt_deadline = now + ip_rt_max_delay; 00503 00504 mod_timer(&rt_flush_timer, now+delay); 00505 spin_unlock_bh(&rt_flush_lock); 00506 }

struct inet_peer* rt_get_peer struct rtable rt  )  [inline, static]
 

Definition at line 181 of file route.h.

References rtable::peer, and rt_bind_peer().

Referenced by tcp_v4_conn_request(), and tcp_v4_connect().

00182 { 00183 if (rt->peer) 00184 return rt->peer; 00185 00186 rt_bind_peer(rt, 0); 00187 return rt->peer; 00188 }

char rt_tos2priority u8  tos  )  [inline, static]
 

Definition at line 161 of file route.h.

References ip_tos2prio, and IPTOS_TOS.

Referenced by ip_forward(), and ip_setsockopt().

00162 { 00163 return ip_tos2prio[IPTOS_TOS(tos)>>1]; 00164 }


Variable Documentation

struct rt_cache_stat ____cacheline_aligned_in_smp
 

struct ip_rt_acct* ip_rt_acct
 

__u8 ip_tos2prio[16]
 

Definition at line 157 of file route.c.

Referenced by rt_tos2priority().


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