/* initialize a new endpoint */ struct endpoint *setup_ep(int portno, int fd_ctl, int fd_data, uid_t user, struct mod_support *modfun) { struct port *port; struct endpoint *ep; if ((portno = alloc_port(portno)) >= 0) { port=portv[portno]; if (port->ep == NULL && checkport_ac(port,user)==0) port->curuser=user; if (port->curuser == user && (ep=malloc(sizeof(struct endpoint))) != NULL) { DBGOUT(DBGEPNEW,"Port %02d FD %2d", portno,fd_ctl); EVENTOUT(DBGEPNEW,portno,fd_ctl); port->ms=modfun; port->sender=modfun->sender; ep->port=portno; ep->fd_ctl=fd_ctl; ep->fd_data=fd_data; ep->descr=NULL; #ifdef VDE_PQ2 ep->vdepq=NULL; ep->vdepq_count=0; ep->vdepq_max=stdqlen; #endif if(port->ep == NULL) {/* WAS INACTIVE */ register int i; /* copy all the vlan defs to the active vlan defs */ ep->next=port->ep; port->ep=ep; bac_FORALL(validvlan,NUMOFVLAN, ({if (ba_check(vlant[i].table,portno)) { ba_set(vlant[i].bctag,portno); #ifdef FSTP fstaddport(i,portno,(i!=port->vlanuntag)); #endif } }),i); if (port->vlanuntag != NOVLAN) { ba_set(vlant[port->vlanuntag].bcuntag,portno); ba_clr(vlant[port->vlanuntag].bctag,portno); } ba_clr(vlant[port->vlanuntag].notlearning,portno); } else {
/* * msg_port() * Create a new port with the given global ID * * If port_name is 0, we generate one for them. */ port_t msg_port(port_name arg_port, port_name *arg_portp) { struct port *port; struct proc *p = curthread->t_proc; int slot; /* * Get new port */ port = alloc_port(); /* * Lock the process and see if we have a free slot */ p_sema(&p->p_sema, PRIHI); for (slot = 0; slot < PROCPORTS; ++slot) { if (p->p_ports[slot] == 0) break; } if (slot >= PROCPORTS) { v_sema(&p->p_sema); FREE(port, MT_PORT); return(err(ENOSPC)); } /* * On first open for this process, allocate the portref * hash. */ if (!p->p_prefs) { p->p_prefs = hash_alloc(NPROC/4); } /* * If needed, pick a new number */ p_sema(&name_sema, PRIHI); if (arg_port == 0) { while (hash_lookup(portnames, rotor)) { ++rotor; if (rotor == 0) { rotor = START_ROTOR; } } arg_port = rotor++; } else { /* * Otherwise verify that it doesn't already * exist. */ if (hash_lookup(portnames, arg_port)) { v_sema(&name_sema); v_sema(&p->p_sema); FREE(port, MT_PORT); return(err(EBUSY)); } } /* * Insert our entry, then release the name interlock */ hash_insert(portnames, arg_port, port); v_sema(&name_sema); port->p_name = arg_port; /* * Fill in our proc entry, return success */ p->p_ports[slot] = port; v_sema(&p->p_sema); /* * If non-NULL second argument, return name to caller */ if (arg_portp) { (void)copyout(arg_portp, &arg_port, sizeof(arg_port)); } return(slot+PROCOPENS); }