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

📄 packet_in.c

📁 无线网络路有协议aodv的 linux的实现
💻 C
字号:
/***************************************************************************                          packet_in.c  -  description                             -------------------    begin                : Mon Jul 29 2002    copyright            : (C) 2002 by Luke Klein-Berndt    email                : kleinb@nist.gov ***************************************************************************/#include "packet_in.h"int valid_aodv_packet(int numbytes, int type, char *data){    rerr *tmp_rerr;    rreq *tmp_rreq;    rrep *tmp_rrep;    switch (type)    {        //RREQ    case 1:				tmp_rreq = (rreq *) data;        //If it is a normal route rreq				if (numbytes == sizeof(rreq))						return 1;         break;        //RREP    case 2:				tmp_rrep = (rrep *) data;				if (numbytes == sizeof(rrep))						return 1;								break;        //RERR    case 3:        // Normal RERR        tmp_rerr = (rerr *) data;        if (numbytes == (sizeof(rerr) + (sizeof(aodv_dst) * tmp_rerr->dst_count)))        {            return 1;        }        break;    case 4:                    //Normal RREP-ACK        if (numbytes == sizeof(rrep_ack))	        return 1;        break;    default:        break;    }    return 0;}int packet_in(struct sk_buff *packet){    struct net_device *dev;    struct iphdr *ip;    aodv_route *tmp_route;    aodv_neigh *tmp_neigh;    u_int32_t tmp_ip;    // Create aodv message types    u_int8_t aodv_type;    //The packets which come in still have their headers from the IP and UDP    int start_point = sizeof(struct udphdr) + sizeof(struct iphdr);    //get pointers to the important parts of the message    ip = packet->nh.iph;    dev = packet->dev; /*   if (strcmp(dev->name, "lo") == 0)    {        return NF_DROP;   }*/    //For all AODV packets the type is the first byte.    aodv_type = (int) packet->data[start_point];    if (!valid_aodv_packet(packet->len - start_point, aodv_type, packet->data + start_point))    {        printk(KERN_NOTICE               "AODV: Packet of type: %d and of size %u from: %s failed packet check!\n", aodv_type, packet->len - start_point, inet_ntoa(ip->saddr));        return NF_DROP;    }	/*	tmp_neigh = find_aodv_neigh_by_hw(&(packet->mac.ethernet->h_source));		if (tmp_neigh != NULL)		{	    delete_timer(tmp_neigh->ip, TASK_NEIGHBOR);  	  insert_timer(TASK_NEIGHBOR, HELLO_INTERVAL * (1 + ALLOWED_HELLO_LOSS) + 100, tmp_neigh->ip);    	update_timer_queue();    }*/     //place packet in the event queue!    insert_task(aodv_type, packet);    return NF_ACCEPT;}unsigned int input_handler(unsigned int hooknum, struct sk_buff **skb,                           const struct net_device *in, const struct net_device *out, int (*okfn) (struct sk_buff *)){    struct iphdr *ip = (*skb)->nh.iph;    struct iphdr *dev_ip = in->ip_ptr;    void *p = (uint32_t *) ip + ip->ihl;    struct udphdr *udp = p; //(struct udphdr *) ip + ip->ihl;    struct ethhdr *mac = (*skb)->mac.ethernet;  //Thanks to Randy Pitz for adding this extra check...            if ((*skb)->h.uh != NULL)    {        if ((udp->dest == htons(AODVPORT)) && (mac->h_proto == htons(ETH_P_IP)))        {                    if (dev_ip->saddr != ip->saddr)            {                return packet_in(*(skb));            } else            {            		printk("dropping packet from: %s\n",inet_ntoa(ip->saddr));            		return NF_DROP;            }        }    }    return NF_ACCEPT;}

⌨️ 快捷键说明

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