packet_out.c

説明を見る。
00001 /*
00002                Kernel AODV  v2.1
00003 National Institute of Standards and Technology
00004                Luke Klein-Berndt
00005 -----------------------------------------------------
00006   Version 2.1 new features:
00007      * Much more stable!
00008      * Added locks around important areas
00009      * Multihop Internet gatewaying now works
00010      * Multicast hack added
00011      * Many bug fixes!
00012 -----------------------------------------------------
00013 
00014 Originally based upon MadHoc code. I am not
00015 sure how much of it is left anymore, but MadHoc
00016 proved to be a great starting point.
00017 
00018 MadHoc was written by - Fredrik Lilieblad,
00019 Oskar Mattsson, Petra Nylund, Dan Ouchterlony
00020 and Anders Roxenhag Mail: mad-hoc@flyinglinux.net
00021 
00022 This software is Open Source under the GNU General Public Licence.
00023 
00024 */
00025 
00026 #include "packet_out.h"
00027 /****************************************************
00028 
00029    packet_out
00030 ----------------------------------------------------
00031 All packets going out of the computer get
00032 intercepted by netfilter and passed to this
00033 function.
00034 ****************************************************/
00035 
00036 extern struct route_table_entry *g_my_entry;
00037 extern u_int32_t        g_my_ip;
00038 extern u_int32_t  g_broadcast_ip;
00039 extern struct nf_hook_ops output_filter;
00040 
00041 #ifdef AODV_MULTICAST
00042 static u_int16_t temp_id=0;
00043 #endif
00044 
00045 /****************************************************
00046 
00047    output_handler
00048 ----------------------------------------------------
00049 Looks at all the packets leaving the computer
00050 ****************************************************/
00051 
00052 
00053 unsigned int output_handler(    unsigned int hooknum,struct sk_buff **skb,const struct net_device *in, const struct net_device *out, int (*okfn)(struct sk_buff *))
00054 {
00055     struct iphdr *ip;
00056     struct route_table_entry  *tmp_route;
00057     struct net_device *dev;
00058 
00059 
00060     // get some useful pointers
00061     ip  = (*skb)->nh.iph;
00062     dev = (*skb)->dev;
00063 
00064 #ifdef AODV_MULTICAST    
00065     if(hooknum==NF_IP_LOCAL_OUT)
00066       {
00067         if ( (multicast_test(ip->daddr)) && (ip->id==0) && (ip->ttl!=0))
00068           {
00069             temp_id++;
00070             ip->id=htons(temp_id);
00071             ip->check = 0;
00072 
00073 
00074             ip->check = ip_fast_csum((unsigned char *) ip, ip->ihl);
00075           }
00076       }
00077 #endif
00078     
00079 
00080 #ifdef AODV_MULTICAST
00081     if (multicast_test(ip->daddr) || (ip->daddr==g_broadcast_ip) )
00082 #else
00083     if  (ip->daddr==g_broadcast_ip)
00084 #endif
00085       {
00086         monitor.bytes=(*skb)->len + monitor.bytes;
00087         monitor.packets++;
00088         return NF_ACCEPT;
00089       }
00090     
00091     //Try to get a route to the destination
00092     tmp_route=find_route_table_entry(ip->daddr);    
00093 
00094     
00095 #ifdef AODV_GATEWAY
00096     if (adhoc_subnet_test(ip->daddr) &&( (tmp_route==NULL) || !(tmp_route->route_valid)))
00097 #else
00098       if ( (tmp_route==NULL) || !(tmp_route->route_valid))
00099 #endif
00100        {
00101          printk("Generating a RREQ for: %s\n",inet_ntoa(ip->daddr));
00102          gen_rreq(g_my_ip,ip->daddr);
00103          return NF_QUEUE;
00104        }
00105 
00106 if ((tmp_route!=NULL) && (tmp_route->route_valid))  //Found after an LONG search by Jon Anderson
00107      tmp_route->lifetime = MAX(tmp_route->lifetime,getcurrtime() + ACTIVE_ROUTE_TIMEOUT);
00108      
00109      monitor.bytes=(*skb)->len + monitor.bytes;
00110      monitor.packets++;
00111      return NF_ACCEPT;
00112 }
00113 

kernel_aodvmに対してThu Nov 10 18:53:11 2005に生成されました。  doxygen 1.4.5