#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef CONFIG_NETFILTER #include #include #endif #include #include struct sock *igmp_delete_sk = NULL; struct test_struct { char data[30]; }; static int try_mac(const char *data, char array[], int array_size, char sep) { uint32 i; memset(array, 0, sizeof(array[0])*array_size); /* Keep data pointing at next char. */ for (i = 0; i < array_size; data++) { if (*data >= '0' && *data <= '9') { array[i] = array[i]*16 + *data - '0'; } else if(*data >='a' && *data <='f') { array[i] = array[i]*16 + *data - 'a'+10; } else if(*data >='A' && *data <='F') { array[i] = array[i]*16 + *data - 'A'+10; } else if (*data == sep) i++; else { /* Unexpected character; true if it's the terminator and we're finished. */ if (i == array_size - 1) return 1; printk("Char %u '%c' unexpected\n",\ i, *data); return 0; } } return 0; } extern int32 rtl_delIgmpRecordByMacAddr(uint8 *macAddr); void igmp_delete (struct sk_buff *__skb) { int pid; struct test_struct send_data,recv_data; uint8 mac[6]; char *ptr; pid=rtk_nlrecvmsg(__skb,sizeof(struct test_struct),&recv_data); //printk("igmp_delete data:%s\n", recv_data.data); memset(mac, 0, 6); ptr = recv_data.data; if(try_mac(recv_data.data, mac, 6, ':')) { rtl_delIgmpRecordByMacAddr(mac); //printk("filter mac: %02x:%02x:%02x:%02x:%02x:%02x\n", mac[0],mac[1],mac[2],mac[3],mac[4],mac[5]); sprintf(send_data.data,"clear igmp cache ok\n"); } else { printk("clear igmp cache of bad format mac:%s\n", recv_data.data); sprintf(send_data.data,"please input like 00:23:e8:79:99:32\n"); } rtk_nlsendmsg(pid, igmp_delete_sk, sizeof(struct test_struct), &send_data); return; } int igmp_delete_init_netlink(void) { igmp_delete_sk = netlink_kernel_create(&init_net, NETLINK_MULTICAST_DELETE, 0, igmp_delete, NULL, THIS_MODULE); if (!igmp_delete_sk) { printk(KERN_ERR "Netlink[Kernel] Cannot create netlink socket for igmp delete.\n"); return -EIO; } printk("Netlink[Kernel] create socket for igmp ok.\n"); return 0; }