📄 packet_input.c
字号:
DEBUG(LOG_INFO, 0, "packet_input: pkt to %s", ip6_to_str(dest_addr)); printf("ZJH:packet_input: pkt to %s\n", ip6_to_str(dest_addr));#else DEBUG(LOG_INFO, 0, "packet_input: pkt to %s", ip_to_str(dest_addr));#endif /* _IPV6 */#endif /* DEBUG_PACKET */ if (dev_name){ ifindex = name2index(dev_name);// printf("ZJH:dev_name:%s if_index:%d\n",dev_name,ifindex); } else ifindex = 0;#endif /* NS_PORT */ /* If the packet is not interesting we just let it go through... */ //PL:#ifdef _IPV6 if ((memcmp(&dest_addr, &ipv6_multicast_addr, sizeof(struct in6_addr)) == 0) || /*(memcmp(&dest_addr, &(DEV_IFINDEX(ifindex).ipaddr), sizeof(struct in6_addr)) == 0) ||*/ to_my_address(dest_addr)|| (memcmp(&dest_addr, &(DEV_IFINDEX(ifindex).multicast), sizeof(struct in6_addr)) == 0) || (dest_addr.s6_addr[0]==256) /*multicast address*/ /* PL: Not sure about this, we don't have netmask || ((internet_gw_mode && this_host.gateway_mode) && ((dest_addr & DEV_IFINDEX(ifindex).netmask) != DEV_IFINDEX(ifindex).broadcast)) */ ) { //PL: debug printf("**** dest_addr = %s, src_addr = %s *****\n", ip6_to_str(dest_addr), ip6_to_str(src_addr)); printf("goto accept\n"); goto accept; }#else if ((dest_addr == AODV_BROADCAST) || (dest_addr == DEV_IFINDEX(ifindex).ipaddr) || (dest_addr == DEV_IFINDEX(ifindex).broadcast) || ((internet_gw_mode && this_host.gateway_mode) && ((dest_addr & DEV_IFINDEX(ifindex).netmask) != DEV_IFINDEX(ifindex).broadcast))) goto accept;#endif /* _IPV6 */ /* Find the entry of the neighboring node and the destination (if any). */ rev_rt = rt_table_find_active(src_addr); fwd_rt = rt_table_find_active(dest_addr); //PL: debug /* printf("dest_addr = %s, src_addr = %s\n", ip6_to_str(dest_addr), ip6_to_str(src_addr)); if(rev_rt != NULL) printf("rev_rt != NULL\n"); else printf("rev_rt == NULL\n"); if(fwd_rt != NULL) printf("fwd_rt != NULL\n"); else printf("fwd_rt == NULL\n"); */ /* If a packet is received on the NF_IP_PRE_ROUTING hook, i.e. inbound on the interface and we don't have a route to the destination, we should send an RERR to the source and then drop the package... */ /* NF_IP_PRE_ROUTING = 0 */#ifdef NS_PORT#define PACKET_IS_INBOUND ch->direction() == hdr_cmn::UP#else#define PACKET_IS_INBOUND pkt->hook == 0#endif //PL:#ifdef _IPV6 //if ((memcmp(&dest_addr, &(DEV_IFINDEX(ifindex).ipaddr), sizeof(dest_addr)) != 0) if(!to_my_address(dest_addr) && (!fwd_rt && PACKET_IS_INBOUND))#else if ((dest_addr != DEV_IFINDEX(ifindex).ipaddr) && (!fwd_rt && PACKET_IS_INBOUND))#endif /* _IPV6 */ { rt_table_t *rt_entry; RERR *rerr; //PL:#ifdef _IPV6 struct in6_addr rerr_dest; DEBUG(LOG_DEBUG, 0, "packet_input: Sending RERR for unknown dest %s", ip6_to_str(dest_addr));#else u_int32_t rerr_dest; DEBUG(LOG_DEBUG, 0, "packet_input: Sending RERR for unknown dest %s", ip_to_str(dest_addr));#endif /* _IPV6 */ /* There is an expired entry in the routing table we want to send along the seqno in the RERR... */ rt_entry = rt_table_find(dest_addr); if (rt_entry) { rerr = rerr_create(0, rt_entry->dest_addr, rt_entry->dest_seqno); rt_table_update_timeout(rt_entry, DELETE_PERIOD); } else rerr = rerr_create(0, dest_addr, 0); /* Unicast the RERR to the source of the data transmission if * possible, otherwise we broadcast it. */ //PL:#ifdef _IPV6 if (rev_rt) memcpy(&rerr_dest, &rev_rt->next_hop, sizeof(struct in6_addr)); else memcpy(&rerr_dest, &ipv6_multicast_addr, sizeof(struct in6_addr));#else if (rev_rt) rerr_dest = rev_rt->next_hop; else rerr_dest = AODV_BROADCAST;#endif /* _IPV6 */ aodv_socket_send((AODV_msg *) rerr, rerr_dest, RERR_CALC_SIZE(rerr), 1, &DEV_IFINDEX(ifindex)); if (wait_on_reboot) { DEBUG(LOG_DEBUG, 0, "packet_input: Wait on reboot timer reset."); timer_add_msec(&worb_timer, DELETE_PERIOD); }#ifdef NS_PORT drop(p, DROP_RTR_NO_ROUTE);#else status = ipq_set_verdict(h, pkt->packet_id, NF_DROP, 0, NULL); if (status < 0) die(h);#endif return; } /* Check if the route is currently in repair. In that case just buffer the packet */ repair_rt = rt_table_find(dest_addr); if (repair_rt && (repair_rt->flags & LREPAIR)) {#ifdef NS_PORT packet_queue_add(p, dest_addr);#else packet_queue_add(pkt->packet_id, dest_addr);#endif return; } /* update_timers: */ /* When forwarding a packet, we update the lifetime of the destination's routing table entry, as well as the entry for the next hop neighbor (if not the same). AODV draft 10, section 6.2. */ //PL:#ifdef _IPV6 if (fwd_rt && //(memcmp(&dest_addr, &(DEV_IFINDEX(ifindex).ipaddr), sizeof(struct in6_addr)) != 0)) !to_my_address(dest_addr))#else if (fwd_rt && dest_addr != DEV_IFINDEX(ifindex).ipaddr)#endif /* _IPV6 */ { rt_table_update_timeout(fwd_rt, ACTIVE_ROUTE_TIMEOUT); next_hop_rt = rt_table_find_active(fwd_rt->next_hop); //PL:#ifdef _IPV6 if (next_hop_rt && (memcmp(&(next_hop_rt->dest_addr), &(fwd_rt->dest_addr), sizeof(struct in6_addr)) != 0))#else if (next_hop_rt && next_hop_rt->dest_addr != fwd_rt->dest_addr)#endif /* _IPV6 */ { //PL: /* printf("packet_input: rt_table_update_timeout\n"); */ rt_table_update_timeout(next_hop_rt, ACTIVE_ROUTE_TIMEOUT); } } /* Also update the reverse route and reverse next hop along the path back, since routes between originators and the destination are expected to be symmetric. */ if (rev_rt) { rt_table_update_timeout(rev_rt, ACTIVE_ROUTE_TIMEOUT); next_hop_rt = rt_table_find_active(rev_rt->next_hop); //PL:#ifdef _IPV6 if (next_hop_rt && (memcmp(&(next_hop_rt->dest_addr), &(fwd_rt->dest_addr), sizeof(struct in6_addr)) != 0))#else if (next_hop_rt && next_hop_rt->dest_addr != fwd_rt->dest_addr)#endif /* _IPV6 */ rt_table_update_timeout(next_hop_rt, ACTIVE_ROUTE_TIMEOUT); }#ifdef DEBUG_PACKET //PL:#ifdef _IPV6 DEBUG(LOG_INFO, 0, "packet_input: d=%s s=%s", ip6_to_str(dest_addr), ip6_to_str(src_addr));#else DEBUG(LOG_INFO, 0, "packet_input: d=%s s=%s", ip_to_str(dest_addr), ip_to_str(src_addr));#endif /* _IPV6 */#endif /* DEBUG_PACKET */ if (!fwd_rt || (fwd_rt->hcnt == 1 && (fwd_rt->flags & UNIDIR))) { /* Buffer packets... Packets are queued by the ip_queue_aodv.o module already. We only need to save the handle id, and return the proper verdict when we know what to do... */#ifdef NS_PORT packet_queue_add(p, dest_addr);#else seek_entry=seek_list_find(dest_addr); /*if (seek_entry&&seek_entry->to_internet) { //DEBUG(LOG_INFO, 0, "rreq_route_discovery: Already seeking %s",ip_to_str(dest_addr)); packet_queue_add(pkt->packet_id,dest_addr,1); }else{ packet_queue_add(pkt->packet_id, dest_addr,0); */ if(seek_entry){ packet_queue_add(pkt->packet_id,dest_addr); }else{ packet_queue_add(pkt->packet_id,dest_addr); /* If the request is generated locally by an application, we save the IP header + 64 bits of data for sending an ICMP Destination Host Unreachable in case we don't find a route... */ //PL:#ifdef _IPV6 //if (memcmp(&src_addr, &(DEV_IFINDEX(ifindex).ipaddr),sizeof(struct in6_addr)) == 0) if(to_my_address(src_addr))#else if (src_addr == DEV_IFINDEX(ifindex).ipaddr)#endif /* _IPV6 */ { ipd = (struct ip_data *) malloc(sizeof(struct ip_data)); if (ipd < 0) { perror("Malloc for IP data failed!"); exit(-1); } //PL:#ifdef _IPV6 //PL: No idea at all, just guessing here.... ipd->len = 40 + 8;#else ipd->len = (ip->ihl << 2) + 8; /* IP header + 64 bits data (8 bytes) */#endif /* _IPV6 */ memcpy(ipd->data, ip, ipd->len); } else ipd = NULL;#endif /* Whether need gateway or not */ if((internet_gw_mode==0)|| (memcmp(&(new_ip6addr_head->ip6_in6addr),&dest_addr,(int)((new_ip6addr_head->plen)/8))==0)){ gw_find_flag=GW_FIND_NO_NEED; printf("no need gateway!\n"); } else{ gw_find_flag=GW_FIND_NEED; printf("need gateway!\n"); } rreq_route_discovery(dest_addr, rreq_flags, ipd); } return; } accept:#ifdef NS_PORT if (fwd_rt) sendPacket(p, fwd_rt->next_hop, 0.0); else drop(p, DROP_RTR_NO_ROUTE);#else status = ipq_set_verdict(h, pkt->packet_id, NF_ACCEPT, 0, NULL); if (status < 0) die(h);#endif return;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -