static void netio_canceled(void *arg) { pthread_netio_impl_t *nio = (pthread_netio_impl_t *) arg; /* free this thread's reference */ netio_release(&nio->iol); }
/* Release NIO used by an ATM bridge */ static void atm_bridge_clear_config(atm_bridge_t *t) { if (t != NULL) { /* release ethernet NIO */ if (t->eth_nio) { netio_rxl_remove(t->eth_nio); netio_release(t->eth_nio->name); } /* release ATM NIO */ if (t->atm_nio) { netio_rxl_remove(t->atm_nio); netio_release(t->atm_nio->name); } t->eth_nio = t->atm_nio = NULL; } }
/* Add a network IO binding */ int vm_slot_add_nio_binding(vm_instance_t *vm,u_int slot_id,u_int port_id, char *nio_name) { struct cisco_nio_binding *nb; struct cisco_card *card,*rc; u_int real_port_id; netio_desc_t *nio; if (!(card = vm_slot_get_card_ptr(vm,slot_id))) return(-1); /* Get the real card (in case this is a sub-slot) */ real_port_id = vm_slot_translate_port_id(vm,slot_id,port_id,&rc); if (rc == NULL) return(-1); /* check that a NIO is not already bound to this port */ if (cisco_card_find_nio_binding(rc,real_port_id) != NULL) { vm_error(vm,"a NIO already exists for interface %u/%u.\n", slot_id,port_id); return(-1); } /* acquire a reference on the NIO object */ if (!(nio = netio_acquire(nio_name))) { vm_error(vm,"unable to find NIO '%s'.\n",nio_name); return(-1); } /* create a new binding */ if (!(nb = malloc(sizeof(*nb)))) { vm_error(vm,"unable to create NIO binding for interface %u/%u.\n", slot_id,port_id); netio_release(nio_name); return(-1); } memset(nb,0,sizeof(*nb)); nb->nio = nio; nb->port_id = real_port_id; nb->orig_port_id = port_id; nb->next = rc->nio_list; if (nb->next) nb->next->prev = nb; rc->nio_list = nb; return(0); }
/* Remove all NIO bindings */ static void cisco_card_remove_all_nio_bindings(vm_instance_t *vm,struct cisco_card *card) { struct cisco_nio_binding *nb,*next; for(nb=card->nio_list;nb;nb=next) { next = nb->next; /* tell the slot driver to stop using this NIO */ if (card->driver) card->driver->card_unset_nio(vm,card,nb->port_id); /* unreference NIO object */ netio_release(nb->nio->name); free(nb); } card->nio_list = NULL; }
/* Remove a NIO binding */ int vm_slot_remove_nio_binding(vm_instance_t *vm,u_int slot_id,u_int port_id) { struct cisco_nio_binding *nb; struct cisco_card *card,*rc; u_int real_port_id; if (!(card = vm_slot_get_card_ptr(vm,slot_id))) return(-1); /* Get the real card (in case this is a sub-slot) */ real_port_id = vm_slot_translate_port_id(vm,slot_id,port_id,&rc); if (rc == NULL) return(-1); /* no nio binding for this slot/port ? */ if (!(nb = cisco_card_find_nio_binding(rc,real_port_id))) return(-1); /* tell the NM driver to stop using this NIO */ if (rc->driver) rc->driver->card_unset_nio(vm,rc,port_id); /* remove this entry from the double linked list */ if (nb->next) nb->next->prev = nb->prev; if (nb->prev) { nb->prev->next = nb->next; } else { rc->nio_list = nb->next; } /* unreference NIO object */ netio_release(nb->nio->name); free(nb); return(0); }
/* Create a new interface */ static int ethsw_cfg_create_if(ethsw_table_t *t,char **tokens,int count) { netio_desc_t *nio = NULL; int nio_type; nio_type = netio_get_type(tokens[2]); switch(nio_type) { case NETIO_TYPE_UNIX: if (count != 5) { fprintf(stderr,"ETHSW: invalid number of arguments " "for UNIX NIO\n"); break; } nio = netio_desc_create_unix(tokens[1],tokens[3],tokens[4]); break; case NETIO_TYPE_TAP: if (count != 4) { fprintf(stderr,"ETHSW: invalid number of arguments " "for TAP NIO\n"); break; } nio = netio_desc_create_tap(tokens[1],tokens[3]); break; case NETIO_TYPE_UDP: if (count != 6) { fprintf(stderr,"ETHSW: invalid number of arguments " "for UDP NIO\n"); break; } nio = netio_desc_create_udp(tokens[1],atoi(tokens[3]), tokens[4],atoi(tokens[5])); break; case NETIO_TYPE_MCAST: if (count != 5) { fprintf(stderr,"ETHSW: invalid number of arguments " "for Multicast NIO\n"); break; } nio = netio_desc_create_mcast(tokens[1],tokens[3],atoi(tokens[4])); break; case NETIO_TYPE_TCP_CLI: if (count != 5) { fprintf(stderr,"ETHSW: invalid number of arguments " "for TCP CLI NIO\n"); break; } nio = netio_desc_create_tcp_cli(tokens[1],tokens[3],tokens[4]); break; case NETIO_TYPE_TCP_SER: if (count != 4) { fprintf(stderr,"ETHSW: invalid number of arguments " "for TCP SER NIO\n"); break; } nio = netio_desc_create_tcp_ser(tokens[1],tokens[3]); break; #ifdef GEN_ETH case NETIO_TYPE_GEN_ETH: if (count != 4) { fprintf(stderr,"ETHSW: invalid number of arguments " "for Generic Ethernet NIO\n"); break; } nio = netio_desc_create_geneth(tokens[1],tokens[3]); break; #endif #ifdef LINUX_ETH case NETIO_TYPE_LINUX_ETH: if (count != 4) { fprintf(stderr,"ETHSW: invalid number of arguments " "for Linux Ethernet NIO\n"); break; } nio = netio_desc_create_lnxeth(tokens[1],tokens[3]); break; #endif default: fprintf(stderr,"ETHSW: unknown/invalid NETIO type '%s'\n", tokens[2]); } if (!nio) { fprintf(stderr,"ETHSW: unable to create NETIO descriptor\n"); return(-1); } if (ethsw_add_netio(t,tokens[1]) == -1) { fprintf(stderr,"ETHSW: unable to add NETIO descriptor.\n"); netio_release(nio->name); return(-1); } netio_release(nio->name); return(0); }
/* Free resources used by a NIO */ static void ethsw_free_nio(netio_desc_t *nio) { netio_rxl_remove(nio); netio_release(nio->name); }
/* Create a new interface */ int atm_bridge_cfg_create_if(atm_bridge_t *t,char **tokens,int count) { netio_desc_t *nio = NULL; int nio_type; /* at least: IF, interface name, NetIO type */ if (count < 3) { fprintf(stderr,"atmsw_cfg_create_if: invalid interface description\n"); return(-1); } nio_type = netio_get_type(tokens[2]); switch(nio_type) { case NETIO_TYPE_UNIX: if (count != 5) { fprintf(stderr,"ATMSW: invalid number of arguments " "for UNIX NIO '%s'\n",tokens[1]); break; } nio = netio_desc_create_unix(tokens[1],tokens[3],tokens[4]); break; case NETIO_TYPE_UDP: if (count != 6) { fprintf(stderr,"ATMSW: invalid number of arguments " "for UDP NIO '%s'\n",tokens[1]); break; } nio = netio_desc_create_udp(tokens[1],atoi(tokens[3]), tokens[4],atoi(tokens[5])); break; case NETIO_TYPE_MCAST: if (count != 5) { fprintf(stderr,"ATMSW: invalid number of arguments " "for Multicast NIO '%s'\n",tokens[1]); break; } nio = netio_desc_create_mcast(tokens[1],tokens[3],atoi(tokens[4])); break; case NETIO_TYPE_TCP_CLI: if (count != 5) { fprintf(stderr,"ATMSW: invalid number of arguments " "for TCP CLI NIO '%s'\n",tokens[1]); break; } nio = netio_desc_create_tcp_cli(tokens[1],tokens[3],tokens[4]); break; case NETIO_TYPE_TCP_SER: if (count != 4) { fprintf(stderr,"ATMSW: invalid number of arguments " "for TCP SER NIO '%s'\n",tokens[1]); break; } nio = netio_desc_create_tcp_ser(tokens[1],tokens[3]); break; default: fprintf(stderr,"ATMSW: unknown/invalid NETIO type '%s'\n", tokens[2]); } if (!nio) { fprintf(stderr,"ATMSW: unable to create NETIO descriptor of " "interface %s\n",tokens[1]); return(-1); } netio_release(nio->name); return(0); }
/* 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); }