⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 module.c

📁 一种AODV实现方法
💻 C
字号:
/*               Kernel AODV  v2.0National Institute of Standards and Technology               Luke Klein-Berndt-----------------------------------------------------  Version 2.0 new features:     * Updated to AODV draft version 11     * Managed internet gatewaying     * Monitor wireles signal strength     * Many bug fixes!-----------------------------------------------------Originally based upon MadHoc code. I am notsure how much of it is left anymore, but MadHocproved to be a great starting point.MadHoc was written by - Fredrik Lilieblad,Oskar Mattsson, Petra Nylund, Dan Ouchterlonyand Anders Roxenhag Mail: mad-hoc@flyinglinux.netThis software is Open Source under the GNU General Public Licence.*/#include "module.h"#ifdef ARM#define EXPORT_SYMBOL_ALIAS ( __do_softirq, do_softirq);#endif/****************************************************   module----------------------------------------------------These are the two functions which are used tostart things up and shut things down.****************************************************/static struct nf_hook_ops input_filter;struct nf_hook_ops output_filter;struct route_table_entry *g_my_entry;  // a pointer to my route entry in the tableu_int32_t        g_my_ip;  // my IP number, set on the command lineu_int32_t g_broadcast_ip;  // the broadcast address to use.u_int8_t	use_lo;  //variable for command line optionschar *block_dev;char *aodv_dev;char *aodv_subnet;//entries for our different PROC filesstatic struct proc_dir_entry *aodv_dir, *route_table_proc, *rreq_id_proc, *timer_queue_proc, *monitor_proc;MODULE_PARM(use_lo,"i");MODULE_PARM(block_dev, "s");MODULE_PARM(aodv_dev,"s");MODULE_PARM(aodv_subnet,"s");/****************************************************	init_module----------------------------------------------------This is called by insmod when things getstarted up!****************************************************/int init_module(void){    int result;    if (use_lo==0)        USE_LO=0;    else        USE_LO=1;    if (block_dev==NULL)        strcpy(g_block_dev,"");    else        strcpy(g_block_dev,block_dev);    if (aodv_dev==NULL)        strcpy(g_aodv_dev,"");    else        strcpy(g_aodv_dev,aodv_dev);    if (aodv_subnet==NULL)        g_aodv_subnet=0;    else    {        inet_aton(aodv_subnet, &g_aodv_subnet);    }    inet_aton("255.255.255.255",&g_broadcast_ip);    printk("\n-=: Kernel AODV v1.5 :=-\nLuke Klein-Berndt\nWireless Communications Technologies Group\nNational Institue of Standards and Technology\n");    printk("---------------------------------------------\n");    //netfilter stuff    init_packet_queue();    /* input hook */    input_filter.list.next = NULL;    input_filter.list.prev = NULL;    input_filter.hook = input_handler;    input_filter.pf = PF_INET; // IPv4    input_filter.hooknum = NF_IP_LOCAL_IN;    /* output hook */    output_filter.list.next = NULL;    output_filter.list.prev = NULL;    output_filter.hook = output_handler;    output_filter.pf = PF_INET; // IPv4    output_filter.hooknum = NF_IP_LOCAL_OUT;    init_timer_queue();    init_rreq_id_queue();    init_event_queue();    init_route_table();    init_iw_sock();    init_interface_list();    init_neighbor_list();    startup_aodv();    /* hooks registration */    result = nf_register_hook(&input_filter);    if (result)        goto hook_failed;#ifdef TRACE    printk("Kernel_AODV: Input filter registered!\n");#endif    result = nf_register_hook(&output_filter);    if (result)        goto hook_failed;#ifdef TRACE    printk("Kernel_AODV: Output filter registered!\n");#endif#ifdef MESSAGES    printk("Kernel_AODV: Principal IP address - %s\n",inet_ntoa(g_my_ip));#endif    insert_timer_queue_entry(getcurrtime() + ACTIVE_ROUTE_TIMEOUT, NULL,0,g_my_ip,0,0, EVENT_CLEANUP);    update_timer_queue();    //setup the proc file system    aodv_dir=proc_mkdir("aodv",NULL);    aodv_dir->owner=THIS_MODULE;    route_table_proc=create_proc_read_entry("aodv/route_table", 0, NULL, read_route_table_proc, NULL);    route_table_proc->owner=THIS_MODULE;    rreq_id_proc=create_proc_read_entry("aodv/rreq_id_queue", 0, NULL, read_rreq_id_proc, NULL);    rreq_id_proc->owner=THIS_MODULE;    timer_queue_proc=create_proc_read_entry("aodv/timer_queue", 0, NULL, read_timer_queue_proc, NULL);    timer_queue_proc->owner=THIS_MODULE;    monitor_proc=create_proc_read_entry("aodv/monitor", 0, NULL, read_monitor_proc, NULL);    monitor_proc->owner=THIS_MODULE;    //starts aodv thread    return 0;hook_failed:#ifndef NO_ERROR    printk(KERN_INFO "Kernel_AODV: error registering hook (%d)", result);#endif    return 1;}/****************************************************   cleanup_module----------------------------------------------------cleans up the module. called by rmmod****************************************************/void cleanup_module(void){    //get rid of all our proc files    remove_proc_entry("aodv/monitor",NULL);    remove_proc_entry("aodv/route_table",NULL);    remove_proc_entry("aodv/rreq_id_queue", NULL);    remove_proc_entry("aodv/timer_queue", NULL);    remove_proc_entry("aodv", NULL);    /* unregister hooks */#ifdef MESSAGES    printk("Kernel_AODV: Shutting down...\n");#endif    nf_unregister_hook(&input_filter);    nf_unregister_hook(&output_filter);#ifdef MESSAGES    printk("Kernel_AODV: Unregistered NetFilter hooks...\n");#endif    cleanup_packet_queue();    cleanup_event_queue();    cleanup_rreq_id_queue();#ifdef MESSAGES    printk("Kernel_AODV: Cleaned up AODV Queues...\n");#endif    kill_aodv();#ifdef MESSAGES    printk("Kernel_AODV: Killed router thread...\n");#endif    del_timer(&aodv_timer);#ifdef MESSAGES    printk("Kernel_AODV: Removed timer...\n");#endif    cleanup_route_table();#ifdef MESSAGES    printk("Kernel_AODV: Cleaned up Route Table...\n");#endif    close_sock();    close_iw_sock();#ifdef MESSAGES    printk("Kernel_AODV: Closed sockets...\n");#endif#ifdef MESSAGES    printk("Kernel_AODV: Shutdown complete!\n");#endif}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -