/* Add a NetIO descriptor to a virtual ethernet switch */ int ethsw_add_netio(ethsw_table_t *t,char *nio_name) { netio_desc_t *nio; int i; ETHSW_LOCK(t); /* Try to find a free slot in the NIO array */ for(i=0;i<ETHSW_MAX_NIO;i++) if (t->nio[i] == NULL) break; /* No free slot found ... */ if (i == ETHSW_MAX_NIO) goto error; /* Acquire the NIO descriptor and increment its reference count */ if (!(nio = netio_acquire(nio_name))) goto error; /* By default, the port is an access port in VLAN 1 */ set_access_port(nio,1); t->nio[i] = nio; netio_rxl_add(nio,(netio_rx_handler_t)ethsw_recv_pkt,t,NULL); ETHSW_UNLOCK(t); return(0); error: ETHSW_UNLOCK(t); return(-1); }
/* Configure an ATM bridge */ int atm_bridge_configure(atm_bridge_t *t,char *eth_nio, char *atm_nio,u_int vpi,u_int vci) { netio_desc_t *e_nio,*a_nio; ATM_BRIDGE_LOCK(t); if (t->eth_nio || t->atm_nio) goto error; e_nio = netio_acquire(eth_nio); a_nio = netio_acquire(atm_nio); if (!e_nio || !a_nio) goto error; t->eth_nio = e_nio; t->atm_nio = a_nio; t->vpi = vpi; t->vci = vci; /* Add ATM RX listener */ if (netio_rxl_add(t->atm_nio,(netio_rx_handler_t)atm_bridge_recv_cell, t,NULL) == -1) goto error; /* Add Ethernet RX listener */ if (netio_rxl_add(t->eth_nio,(netio_rx_handler_t)atm_bridge_recv_pkt, t,NULL) == -1) goto error; ATM_BRIDGE_UNLOCK(t); return(0); error: ATM_BRIDGE_UNLOCK(t); return(-1); }
/* 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); }