static int suni_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg) { switch (cmd) { case SONET_GETSTATZ: case SONET_GETSTAT: return fetch_stats(dev, arg, cmd == SONET_GETSTATZ); case SONET_SETDIAG: return change_diag(dev,arg,1); case SONET_CLRDIAG: return change_diag(dev,arg,0); case SONET_GETDIAG: return get_diag(dev,arg); case SONET_SETFRAMING: if (!capable(CAP_NET_ADMIN)) return -EPERM; return set_framing(dev, arg); case SONET_GETFRAMING: return get_framing(dev, arg); case SONET_GETFRSENSE: return -EINVAL; case ATM_SETLOOP: if (!capable(CAP_NET_ADMIN)) return -EPERM; return set_loopback(dev,(int)(unsigned long)arg); case ATM_GETLOOP: return put_user(PRIV(dev)->loop_mode,(int __user *)arg) ? -EFAULT : 0; case ATM_QUERYLOOP: return put_user(ATM_LM_LOC_PHY | ATM_LM_RMT_PHY, (int __user *) arg) ? -EFAULT : 0; default: return -ENOIOCTLCMD; } }
static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg) { switch (cmd) { case SONET_GETSTATZ: case SONET_GETSTAT: return fetch_stats(dev,arg, cmd == SONET_GETSTATZ); case SONET_SETFRAMING: return set_framing(dev, (int)(unsigned long)arg); case SONET_GETFRAMING: return put_user(PRIV(dev)->framing,(int __user *)arg) ? -EFAULT : 0; case SONET_GETFRSENSE: return get_sense(dev,arg); case ATM_SETLOOP: return set_loopback(dev, (int)(unsigned long)arg); case ATM_GETLOOP: return put_user(PRIV(dev)->loop_mode,(int __user *)arg) ? -EFAULT : 0; case ATM_QUERYLOOP: return put_user(ATM_LM_LOC_PHY | ATM_LM_LOC_ATM | ATM_LM_RMT_PHY,(int __user *)arg) ? -EFAULT : 0; default: return -ENOIOCTLCMD; } }
static int suni_ioctl(struct atm_dev *dev,unsigned int cmd,void *arg) { switch (cmd) { case SONET_GETSTATZ: case SONET_GETSTAT: return fetch_stats(dev,(struct sonet_stats *) arg, cmd == SONET_GETSTATZ); case SONET_SETDIAG: return change_diag(dev,arg,1); case SONET_CLRDIAG: return change_diag(dev,arg,0); case SONET_GETDIAG: return get_diag(dev,arg); case SONET_SETFRAMING: if (arg != SONET_FRAME_SONET) return -EINVAL; return 0; case SONET_GETFRAMING: return put_user(SONET_FRAME_SONET,(int *) arg) ? -EFAULT : 0; case SONET_GETFRSENSE: return -EINVAL; case ATM_SETLOOP: return set_loopback(dev,(int) (long) arg); case ATM_GETLOOP: return put_user(PRIV(dev)->loop_mode,(int *) arg) ? -EFAULT : 0; case ATM_QUERYLOOP: return put_user(ATM_LM_LOC_PHY | ATM_LM_RMT_PHY, (int *) arg) ? -EFAULT : 0; default: return -ENOIOCTLCMD; } }
static int idt77105_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg) { #ifdef CONFIG_DEBUG_PRINTK printk(KERN_NOTICE "%s(%d) idt77105_ioctl() called\n",dev->type,dev->number); #else ; #endif switch (cmd) { case IDT77105_GETSTATZ: if (!capable(CAP_NET_ADMIN)) return -EPERM; /* fall through */ case IDT77105_GETSTAT: return fetch_stats(dev, arg, cmd == IDT77105_GETSTATZ); case ATM_SETLOOP: return set_loopback(dev,(int)(unsigned long) arg); case ATM_GETLOOP: return put_user(PRIV(dev)->loop_mode,(int __user *)arg) ? -EFAULT : 0; case ATM_QUERYLOOP: return put_user(ATM_LM_LOC_ATM | ATM_LM_RMT_ATM, (int __user *) arg) ? -EFAULT : 0; default: return -ENOIOCTLCMD; } }
int main() { //###################################################################### //TODO get this from config file eventually //host interface my_host_mac_addr = 0x080027445566ull; my_host_ip_addr = IP4_ADR_P2H(192,168,1,20); my_host_mask = IP4_ADR_P2H(255,255,255,0); //loopback interface loopback_ip_addr = IP4_ADR_P2H(127,0,0,1); loopback_mask = IP4_ADR_P2H(255,0,0,0); //any any_ip_addr = IP4_ADR_P2H(0,0,0,0); //###################################################################### sem_init(&control_serial_sem, 0, 1); //TODO remove after gen_control_serial_num() converted to RNG signal(SIGINT, termination_handler); //register termination handler // Start the driving thread of each module PRINT_DEBUG("Initialize Modules"); switch_init(); //should always be first daemon_init(); //TODO improve how sets mac/ip interface_init(); arp_init(); arp_register_interface(my_host_mac_addr, my_host_ip_addr); ipv4_init(); set_interface(my_host_ip_addr, my_host_mask); set_loopback(loopback_ip_addr, loopback_mask); icmp_init(); tcp_init(); udp_init(); //rtm_init(); //TODO when updated/fully implemented pthread_attr_t fins_pthread_attr; pthread_attr_init(&fins_pthread_attr); PRINT_DEBUG("Run/start Modules"); switch_run(&fins_pthread_attr); daemon_run(&fins_pthread_attr); interface_run(&fins_pthread_attr); arp_run(&fins_pthread_attr); ipv4_run(&fins_pthread_attr); icmp_run(&fins_pthread_attr); tcp_run(&fins_pthread_attr); udp_run(&fins_pthread_attr); //rtm_run(&fins_pthread_attr); //############################# //TODO custom test, remove later /* if (0) { char recv_data[4000]; while (1) { gets(recv_data); PRINT_DEBUG("Sending ARP req"); metadata *params_req = (metadata *) malloc(sizeof(metadata)); if (params_req == NULL) { PRINT_ERROR("metadata alloc fail"); exit(-1); } metadata_create(params_req); uint32_t dst_ip = IP4_ADR_P2H(192, 168, 1, 11); //uint32_t dst_ip = IP4_ADR_P2H(172, 31, 50, 152); uint32_t src_ip = IP4_ADR_P2H(192, 168, 1, 20); //uint32_t src_ip = IP4_ADR_P2H(172, 31, 50, 160); metadata_writeToElement(params_req, "dst_ip", &dst_ip, META_TYPE_INT32); metadata_writeToElement(params_req, "src_ip", &src_ip, META_TYPE_INT32); struct finsFrame *ff_req = (struct finsFrame*) malloc(sizeof(struct finsFrame)); if (ff_req == NULL) { PRINT_ERROR("todo error"); //metadata_destroy(params_req); exit(-1); } ff_req->dataOrCtrl = CONTROL; ff_req->destinationID.id = ARP_ID; ff_req->destinationID.next = NULL; ff_req->metaData = params_req; ff_req->ctrlFrame.senderID = IP_ID; ff_req->ctrlFrame.serial_num = gen_control_serial_num(); ff_req->ctrlFrame.opcode = CTRL_EXEC; ff_req->ctrlFrame.param_id = EXEC_ARP_GET_ADDR; ff_req->ctrlFrame.data_len = 0; ff_req->ctrlFrame.data = NULL; arp_to_switch(ff_req); //doesn't matter which queue } } //############################# */ while (1) ; return (1); }