static unsigned int arp_in(unsigned int hook, struct sk_buff **pskb, const struct net_device *in, const struct net_device *out, int (*okfn) (struct sk_buff *)) { struct arphdr *arp = NULL; uint8_t *sip; uint8_t *dip; uint8_t *smac; uint8_t *dmac; arp = (*pskb)->nh.arph; smac = ((uint8_t *) arp) + ARP_HEADER_LEN; //if (ntohs(arp->ar_op) == ARPOP_REQUEST) { if (ntohs(arp->ar_op) == ARPOP_REPLY) { aos_header_t athr_header; memcpy( &athr_header, (*pskb)->head, sizeof(aos_header_t)); //if(athr_header.type != AOS_HEADER_TYPE_ARP) return NF_ACCEPT; //printk("header type:%x port:%d vid:%x\n", athr_header.type, athr_header.sport, athr_header.vid); fal_host_entry_t arp_entry; memset(&arp_entry,0,sizeof(arp_entry)); sip = smac + MAC_LEN; dmac = sip + IP_LEN; dip = dmac + MAC_LEN; //if_mac_entry_add();//debug uint32_t mac_index = if_mac_entry.entry_id; uint32_t vid_low = if_mac_entry.vid_low; uint32_t vid_offset = athr_header.vid - vid_low; uint32_t intf_id = (vid_offset<<3)| (mac_index&0x7); memcpy(&arp_entry.ip4_addr, sip, 4); memcpy(arp_entry.mac_addr.uc, smac, 6); arp_entry.port_id = athr_header.sport; arp_entry.intf_id = intf_id; arp_entry.flags = FAL_IP_IP4_ADDR; arp_entry.status = ARP_AGE; arp_entry.counter_en = 1; arp_entry.counter_id = debug_counter; if(++debug_counter == 8) debug_counter = 0; int rv = isis_ip_host_add(0,&arp_entry); if(rv==0) printk("##(port:%d)##isis_ip_host_add #%d##\n", athr_header.sport, rv); } return NF_ACCEPT; }
void host_check_aging(void) { fal_host_entry_t *host_entry_p, host_entry= {0}; sw_error_t rv; int cnt = 0; unsigned long flags; fal_napt_entry_t src_napt = {0}, pub_napt = {0}; host_entry_p = &host_entry; host_entry_p->entry_id = FAL_NEXT_ENTRY_FIRST_ID; local_irq_save(flags); while (1) { host_entry_p->status = HOST_AGEOUT_STATUS; /* FIXME: now device id is set to 0. */ rv = isis_ip_host_next (0, FAL_IP_ENTRY_STATUS_EN, host_entry_p); // rv = isis_ip_host_next (0, 0, host_entry_p); if (SW_OK != rv) break; if (cnt >= ARP_ENTRY_MAX) // arp entry number break; if (ARP_AGE_NEVER == host_entry_p->status) continue; if ((S17_WAN_PORT == host_entry_p->port_id) && (host_entry_p->counter_en)) { if (0 != host_entry_p->packet) { // arp entry is using, update it. host_entry.status = ARP_AGE; printk("Update WAN port hostentry!\n"); isis_ip_host_add(0, host_entry_p); } else { printk("Del WAN port hostentry!\n"); isis_ip_host_del(0, FAL_IP_ENTRY_IPADDR_EN, host_entry_p); } continue; } src_napt.entry_id = FAL_NEXT_ENTRY_FIRST_ID; memcpy(&src_napt.src_addr, &host_entry_p->ip4_addr, sizeof(fal_ip4_addr_t)); pub_napt.entry_id = FAL_NEXT_ENTRY_FIRST_ID; memcpy(&pub_napt.trans_addr, &host_entry_p->ip4_addr, sizeof(fal_ip4_addr_t)); if((isis_napt_next(0, FAL_NAT_ENTRY_SOURCE_IP_EN ,&src_napt) !=0) && \ (isis_napt_next(0, FAL_NAT_ENTRY_PUBLIC_IP_EN ,&pub_napt) != 0)) { /* Cannot find naptentry */ printk("ARP id 0x%x: Cannot find NAPT entry!\n", host_entry_p->entry_id); isis_ip_host_del(0, FAL_IP_ENTRY_IPADDR_EN, host_entry_p); continue; } // arp entry is using, update it. host_entry_p->status = ARP_AGE; isis_ip_host_add(0, host_entry_p); printk("update entry 0x%x port %d\n", host_entry_p->entry_id, host_entry_p->port_id); cnt++; } local_irq_restore(flags); }