/* Create a Network Module (command line) */ int vm_slot_cmd_create(vm_instance_t *vm,char *str) { char *tokens[SLOT_DESC_MAX_TOKENS]; int i,count,res; u_int slot_id,port_id; /* A port adapter description is like "1:0:NM-1FE" */ count = m_strsplit(str,':',tokens,SLOT_DESC_MAX_TOKENS); if ((count < 2) || (count > 3)) { vm_error(vm,"unable to parse slot description '%s'.\n",str); return(-1); } /* Parse the slot id */ slot_id = atoi(tokens[0]); /* Parse the sub-slot id */ if (count == 3) port_id = atoi(tokens[1]); else port_id = 0; /* Add this new slot to the current slot list */ res = vm_slot_add_binding(vm,tokens[count-1],slot_id,port_id); /* The complete array was cleaned by strsplit */ for(i=0;i<SLOT_DESC_MAX_TOKENS;i++) free(tokens[i]); return(res); }
/* Handle an ATMSW configuration line */ int atm_bridge_handle_cfg_line(atm_bridge_t *t,char *str) { char *tokens[ATM_BRIDGE_MAX_TOKENS]; int count; if ((count = m_strsplit(str,':',tokens,ATM_BRIDGE_MAX_TOKENS)) <= 1) return(-1); if (!strcmp(tokens[0],"IF")) return(atm_bridge_cfg_create_if(t,tokens,count)); else if (!strcmp(tokens[0],"BRIDGE")) return(atm_bridge_cfg_setup(t,tokens,count)); fprintf(stderr,"ATM Bridge: " "Unknown statement \"%s\" (allowed: IF,BRIDGE)\n", tokens[0]); return(-1); }
/* Handle a ETHSW configuration line */ static int ethsw_handle_cfg_line(ethsw_table_t *t,char *str) { char *tokens[ETHSW_MAX_TOKENS]; int count; if ((count = m_strsplit(str,':',tokens,ETHSW_MAX_TOKENS)) <= 1) return(-1); if (!strcmp(tokens[0],"IF")) return(ethsw_cfg_create_if(t,tokens,count)); else if (!strcmp(tokens[0],"ACCESS")) return(ethsw_cfg_set_access_port(t,tokens,count)); else if (!strcmp(tokens[0],"DOT1Q")) return(ethsw_cfg_set_dot1q_port(t,tokens,count)); else if (!strcmp(tokens[0],"QINQ")) return(ethsw_cfg_set_qinq_port(t,tokens,count)); fprintf(stderr, "ETHSW: Unknown statement \"%s\" (allowed: IF,ACCESS,TRUNK)\n", tokens[0]); return(-1); }
/* Add a Network IO descriptor binding (command line) */ int vm_slot_cmd_add_nio(vm_instance_t *vm,char *str) { char *tokens[SLOT_DESC_MAX_TOKENS]; int i,count,nio_type,res=-1; u_int slot_id,port_id; netio_desc_t *nio; char nio_name[128]; /* A NIO binding description is like "1:3:tap:tap0" */ if ((count = m_strsplit(str,':',tokens,SLOT_DESC_MAX_TOKENS)) < 3) { vm_error(vm,"unable to parse NIO description '%s'.\n",str); return(-1); } /* Parse the slot id */ slot_id = atoi(tokens[0]); /* Parse the port id */ port_id = atoi(tokens[1]); /* Autogenerate a NIO name */ snprintf(nio_name,sizeof(nio_name),"%s-i%u/%u/%u", vm_get_type(vm),vm->instance_id,slot_id,port_id); /* Create the Network IO descriptor */ nio = NULL; nio_type = netio_get_type(tokens[2]); switch(nio_type) { case NETIO_TYPE_UNIX: if (count != 5) { vm_error(vm,"invalid number of arguments for UNIX NIO '%s'\n",str); goto done; } nio = netio_desc_create_unix(nio_name,tokens[3],tokens[4]); break; case NETIO_TYPE_VDE: if (count != 5) { vm_error(vm,"invalid number of arguments for VDE NIO '%s'\n",str); goto done; } nio = netio_desc_create_vde(nio_name,tokens[3],tokens[4]); break; case NETIO_TYPE_TAP: if (count != 4) { vm_error(vm,"invalid number of arguments for TAP NIO '%s'\n",str); goto done; } nio = netio_desc_create_tap(nio_name,tokens[3]); break; case NETIO_TYPE_UDP: if (count != 6) { vm_error(vm,"invalid number of arguments for UDP NIO '%s'\n",str); goto done; } nio = netio_desc_create_udp(nio_name,atoi(tokens[3]), tokens[4],atoi(tokens[5])); break; case NETIO_TYPE_TCP_CLI: if (count != 5) { vm_error(vm,"invalid number of arguments for TCP CLI NIO '%s'\n", str); goto done; } nio = netio_desc_create_tcp_cli(nio_name,tokens[3],tokens[4]); break; case NETIO_TYPE_TCP_SER: if (count != 4) { vm_error(vm,"invalid number of arguments for TCP SER NIO '%s'\n", str); goto done; } nio = netio_desc_create_tcp_ser(nio_name,tokens[3]); break; case NETIO_TYPE_NULL: nio = netio_desc_create_null(nio_name); break; #ifdef LINUX_ETH case NETIO_TYPE_LINUX_ETH: if (count != 4) { vm_error(vm,"invalid number of arguments for Linux Eth NIO '%s'\n", str); goto done; } nio = netio_desc_create_lnxeth(nio_name,tokens[3]); break; #endif #ifdef GEN_ETH case NETIO_TYPE_GEN_ETH: if (count != 4) { vm_error(vm, "invalid number of arguments for Generic Eth NIO '%s'\n", str); goto done; } nio = netio_desc_create_geneth(nio_name,tokens[3]); break; #endif default: vm_error(vm,"unknown NETIO type '%s'\n",tokens[2]); goto done; } if (!nio) { vm_error(vm,"unable to create NETIO descriptor for slot %u\n",slot_id); goto done; } if (vm_slot_add_nio_binding(vm,slot_id,port_id,nio_name) == -1) { vm_error(vm,"unable to add NETIO binding for slot %u\n",slot_id); netio_release(nio_name); netio_delete(nio_name); goto done; } netio_release(nio_name); res = 0; done: /* The complete array was cleaned by strsplit */ for(i=0;i<SLOT_DESC_MAX_TOKENS;i++) free(tokens[i]); return(res); }