PUBLIC void udp_init() { udp_fd_t *udp_fd; udp_port_t *udp_port; int i, result; assert (BUF_S >= sizeof(struct nwio_ipopt)); assert (BUF_S >= sizeof(struct nwio_ipconf)); assert (BUF_S >= sizeof(struct nwio_udpopt)); assert (BUF_S >= sizeof(struct udp_io_hdr)); assert (UDP_HDR_SIZE == sizeof(udp_hdr_t)); assert (UDP_IO_HDR_SIZE == sizeof(udp_io_hdr_t)); for (i= 0, udp_fd= udp_fd_table; i<UDP_FD_NR; i++, udp_fd++) { udp_fd->uf_flags= UFF_EMPTY; udp_fd->uf_rdbuf_head= NULL; } #ifndef BUF_CONSISTENCY_CHECK bf_logon(udp_buffree); #else bf_logon(udp_buffree, udp_bufcheck); #endif for (i= 0, udp_port= udp_port_table; i<UDP_PORT_NR; i++, udp_port++) { if (i == udp_conf_nr) { printf("udp_init: more ports than configurations\n"); break; } udp_port->up_minor= udp_conf[i].uc_minor; udp_port->up_ipdev= udp_conf[i].uc_port; udp_port->up_flags= UPF_EMPTY; udp_port->up_state= UPS_EMPTY; udp_port->up_next_fd= udp_fd_table; udp_port->up_write_fd= NULL; result= sr_add_minor (udp_port->up_minor, udp_port-udp_port_table, udp_open, udp_close, udp_read, udp_write, udp_ioctl, udp_cancel); assert (result >= 0); udp_main(udp_port); } }
void udp_init() { udp_fd_t *udp_fd; udp_port_t *udp_port; int i, j, ifno; assert (BUF_S >= sizeof(struct nwio_ipopt)); assert (BUF_S >= sizeof(struct nwio_ipconf)); assert (BUF_S >= sizeof(struct nwio_udpopt)); assert (BUF_S >= sizeof(struct udp_io_hdr)); assert (UDP_HDR_SIZE == sizeof(udp_hdr_t)); assert (UDP_IO_HDR_SIZE == sizeof(udp_io_hdr_t)); for (i= 0, udp_fd= udp_fd_table; i<UDP_FD_NR; i++, udp_fd++) { udp_fd->uf_flags= UFF_EMPTY; udp_fd->uf_rdbuf_head= NULL; } #ifndef BUF_CONSISTENCY_CHECK bf_logon(udp_buffree); #else bf_logon(udp_buffree, udp_bufcheck); #endif for (i= 0, udp_port= udp_port_table; i<udp_conf_nr; i++, udp_port++) { udp_port->up_ipdev= udp_conf[i].uc_port; udp_port->up_flags= UPF_EMPTY; udp_port->up_state= UPS_EMPTY; udp_port->up_next_fd= udp_fd_table; udp_port->up_write_fd= NULL; udp_port->up_wr_pack= NULL; udp_port->up_port_any= NULL; for (j= 0; j<UDP_PORT_HASH_NR; j++) udp_port->up_port_hash[j]= NULL; ifno= ip_conf[udp_port->up_ipdev].ic_ifno; sr_add_minor(if2minor(ifno, UDP_DEV_OFF), i, udp_open, udp_close, udp_read, udp_write, udp_ioctl, udp_cancel, udp_select); udp_main(udp_port); } }
PUBLIC void udp_init() { udp_fd_t *udp_fd; udp_port_t *udp_port; int i, result; assert (BUF_S >= sizeof(struct nwio_ipopt)); assert (BUF_S >= sizeof(struct nwio_ipconf)); assert (BUF_S >= sizeof(struct nwio_udpopt)); assert (BUF_S >= sizeof(struct udp_io_hdr)); assert (UDP_HDR_SIZE == sizeof(udp_hdr_t)); assert (UDP_IO_HDR_SIZE == sizeof(udp_io_hdr_t)); udp_port_table[0].up_minor= UDP_DEV0; udp_port_table[0].up_ipdev= IP0; for (i= 0, udp_fd= udp_fd_table; i<UDP_FD_NR; i++, udp_fd++) { udp_fd->uf_flags= UFF_EMPTY; } bf_logon(udp_buffree); for (i= 0, udp_port= udp_port_table; i<UDP_PORT_NR; i++, udp_port++) { udp_port->up_flags= UPF_EMPTY; udp_port->up_state= UPS_EMPTY; udp_port->up_next_fd= udp_fd_table; udp_port->up_write_fd= NULL; result= sr_add_minor (udp_port->up_minor, udp_port-udp_port_table, udp_open, udp_close, udp_read, udp_write, udp_ioctl, udp_cancel); assert (result >= 0); udp_main(udp_port); } }
PUBLIC void ip_init() { int i, j, result; ip_ass_t *ip_ass; ip_fd_t *ip_fd; ip_port_t *ip_port; struct ip_conf *icp; assert (BUF_S >= sizeof(struct nwio_ethopt)); assert (BUF_S >= IP_MAX_HDR_SIZE + ETH_HDR_SIZE); assert (BUF_S >= sizeof(nwio_ipopt_t)); assert (BUF_S >= sizeof(nwio_route_t)); for (i=0, ip_ass= ip_ass_table; i<IP_ASS_NR; i++, ip_ass++) { ip_ass->ia_frags= 0; ip_ass->ia_first_time= 0; ip_ass->ia_port= 0; } for (i=0, ip_fd= ip_fd_table; i<IP_FD_NR; i++, ip_fd++) { ip_fd->if_flags= IFF_EMPTY; ip_fd->if_rdbuf_head= 0; } for (i=0, ip_port= ip_port_table, icp= ip_conf; i<ip_conf_nr; i++, ip_port++, icp++) { ip_port->ip_port= i; ip_port->ip_flags= IPF_EMPTY; ip_port->ip_dev_main= (ip_dev_t)ip_bad_callback; ip_port->ip_dev_set_ipaddr= (ip_dev_t)ip_bad_callback; ip_port->ip_dev_send= (ip_dev_send_t)ip_bad_callback; ip_port->ip_dl_type= icp->ic_devtype; ip_port->ip_mtu= IP_DEF_MTU; ip_port->ip_mtu_max= IP_MAX_PACKSIZE; switch(ip_port->ip_dl_type) { case IPDL_ETH: ip_port->ip_dl.dl_eth.de_port= icp->ic_port; result= ipeth_init(ip_port); if (result == -1) continue; assert(result == NW_OK); break; case IPDL_PSIP: ip_port->ip_dl.dl_ps.ps_port= icp->ic_port; result= ipps_init(ip_port); if (result == -1) continue; assert(result == NW_OK); break; default: ip_panic(( "unknown ip_dl_type %d", ip_port->ip_dl_type )); break; } ip_port->ip_loopb_head= NULL; ip_port->ip_loopb_tail= NULL; ev_init(&ip_port->ip_loopb_event); ip_port->ip_routeq_head= NULL; ip_port->ip_routeq_tail= NULL; ev_init(&ip_port->ip_routeq_event); ip_port->ip_flags |= IPF_CONFIGURED; ip_port->ip_proto_any= NULL; for (j= 0; j<IP_PROTO_HASH_NR; j++) ip_port->ip_proto[j]= NULL; } #ifndef BUF_CONSISTENCY_CHECK bf_logon(ip_buffree); #else bf_logon(ip_buffree, ip_bufcheck); #endif icmp_init(); ipr_init(); for (i=0, ip_port= ip_port_table; i<ip_conf_nr; i++, ip_port++) { if (!(ip_port->ip_flags & IPF_CONFIGURED)) continue; ip_port->ip_frame_id= (u16_t)get_time(); sr_add_minor(if2minor(ip_conf[i].ic_ifno, IP_DEV_OFF), i, ip_open, ip_close, ip_read, ip_write, ip_ioctl, ip_cancel, ip_select); (*ip_port->ip_dev_main)(ip_port); } }
PUBLIC void osdep_eth_init() { int i, r, tasknr; struct eth_conf *ecp; eth_port_t *eth_port; message mess, repl_mess; for (i= 0, eth_port= eth_port_table, ecp= eth_conf; i<eth_conf_nr; i++, eth_port++, ecp++) { r= sys_findproc(ecp->ec_task, &tasknr, 0); if (r != OK) { ip_panic(( "unable to find task %s: %d\n", ecp->ec_task, r )); } eth_port->etp_osdep.etp_port= ecp->ec_port; eth_port->etp_osdep.etp_task= tasknr; ev_init(ð_port->etp_osdep.etp_recvev); mess.m_type= DL_INIT; mess.DL_PORT= eth_port->etp_osdep.etp_port; mess.DL_PROC= this_proc; mess.DL_MODE= DL_NOMODE; r= send(eth_port->etp_osdep.etp_task, &mess); if (r<0) { #if !CRAMPED printf( "osdep_eth_init: unable to send to ethernet task, error= %d\n", r); #endif continue; } if (receive(eth_port->etp_osdep.etp_task, &mess)<0) ip_panic(("unable to receive")); if (mess.m3_i1 == ENXIO) { #if !CRAMPED printf( "osdep_eth_init: no ethernet device at task=%d,port=%d\n", eth_port->etp_osdep.etp_task, eth_port->etp_osdep.etp_port); #endif continue; } if (mess.m3_i1 != eth_port->etp_osdep.etp_port) ip_panic(("osdep_eth_init: DL_INIT error or wrong port: %d\n", mess.m3_i1)); eth_port->etp_ethaddr= *(ether_addr_t *)mess.m3_ca1; sr_add_minor(if2minor(ecp->ec_ifno, ETH_DEV_OFF), i, eth_open, eth_close, eth_read, eth_write, eth_ioctl, eth_cancel); eth_port->etp_flags |= EPF_ENABLED; eth_port->etp_wr_pack= 0; eth_port->etp_rd_pack= 0; setup_read (eth_port); eth_port++; } }
PUBLIC void osdep_eth_init() { int i, r, tasknr, rport; struct eth_conf *ecp; eth_port_t *eth_port, *rep; message mess; /* First initialize normal ethernet interfaces */ for (i= 0, ecp= eth_conf, eth_port= eth_port_table; i<eth_conf_nr; i++, ecp++, eth_port++) { if (eth_is_vlan(ecp)) continue; #ifdef __minix_vmd r= sys_findproc(ecp->ec_task, &tasknr, 0); #else /* Minix 3 */ r = findproc(ecp->ec_task, &tasknr); #endif if (r != OK) { printf("eth%d: unable to find task %s: %d\n", i, ecp->ec_task, r); continue; } eth_port->etp_osdep.etp_port= ecp->ec_port; eth_port->etp_osdep.etp_task= tasknr; ev_init(ð_port->etp_osdep.etp_recvev); mess.m_type= DL_INIT; mess.DL_PORT= eth_port->etp_osdep.etp_port; mess.DL_PROC= this_proc; mess.DL_MODE= DL_NOMODE; r= send(eth_port->etp_osdep.etp_task, &mess); if (r<0) { printf( "osdep_eth_init: unable to send to ethernet task, error= %d\n", r); continue; } if (receive(eth_port->etp_osdep.etp_task, &mess)<0) ip_panic(("unable to receive")); if (mess.m3_i1 == ENXIO) { printf( "osdep_eth_init: no ethernet device at task=%d,port=%d\n", eth_port->etp_osdep.etp_task, eth_port->etp_osdep.etp_port); continue; } if (mess.m3_i1 < 0) ip_panic(("osdep_eth_init: DL_INIT returned error %d\n", mess.m3_i1)); if (mess.m3_i1 != eth_port->etp_osdep.etp_port) { ip_panic(( "osdep_eth_init: got reply for wrong port (got %d, expected %d)\n", mess.m3_i1, eth_port->etp_osdep.etp_port)); } eth_port->etp_ethaddr= *(ether_addr_t *)mess.m3_ca1; sr_add_minor(if2minor(ecp->ec_ifno, ETH_DEV_OFF), i, eth_open, eth_close, eth_read, eth_write, eth_ioctl, eth_cancel, eth_select); eth_port->etp_flags |= EPF_ENABLED; eth_port->etp_vlan= 0; eth_port->etp_vlan_port= NULL; eth_port->etp_wr_pack= 0; eth_port->etp_rd_pack= 0; setup_read (eth_port); } /* And now come the VLANs */ for (i= 0, ecp= eth_conf, eth_port= eth_port_table; i<eth_conf_nr; i++, ecp++, eth_port++) { if (!eth_is_vlan(ecp)) continue; eth_port->etp_osdep.etp_port= ecp->ec_port; eth_port->etp_osdep.etp_task= ANY; ev_init(ð_port->etp_osdep.etp_recvev); rport= eth_port->etp_osdep.etp_port; assert(rport >= 0 && rport < eth_conf_nr); rep= ð_port_table[rport]; if (!(rep->etp_flags & EPF_ENABLED)) { printf( "eth%d: underlying ethernet device %d not enabled", i, rport); continue; } if (rep->etp_vlan != 0) { printf( "eth%d: underlying ethernet device %d is a VLAN", i, rport); continue; } eth_port->etp_ethaddr= rep->etp_ethaddr; sr_add_minor(if2minor(ecp->ec_ifno, ETH_DEV_OFF), i, eth_open, eth_close, eth_read, eth_write, eth_ioctl, eth_cancel, eth_select); eth_port->etp_flags |= EPF_ENABLED; eth_port->etp_vlan= ecp->ec_vlan; eth_port->etp_vlan_port= rep; assert(eth_port->etp_vlan != 0); eth_port->etp_wr_pack= 0; eth_port->etp_rd_pack= 0; eth_reg_vlan(rep, eth_port); } }
PUBLIC void eth_init0() { int result; eth_port_t *eth_port; static message mess, repl_mess; eth_port= ð_port_table[0]; eth_port->etp_osdep.etp_port= 0; eth_port->etp_osdep.etp_task= DL_ETH; eth_port->etp_osdep.etp_minor= ETH_DEV; #if XXX mess.m_type= DL_STOP; mess.DL_PORT= eth_port->etp_osdep.etp_port; #if DEBUG & 256 { where(); printf("sending DL_STOP\n"); } #endif assert (eth_port->etp_osdep.etp_task != MM_PROC_NR); result= send(eth_port->etp_osdep.etp_task, &mess); if (result < 0) { printf("send failed with error %d\n",result); printf("eth_init0: unable to stop ethernet task\n"); return; } #endif #if DEBUG & 256 { where(); printf("sending DL_INIT\n"); } #endif mess.m_type= DL_INIT; mess.DL_PORT= eth_port->etp_osdep.etp_port; mess.DL_PROC= THIS_PROC; mess.DL_MODE= DL_NOMODE; assert (eth_port->etp_osdep.etp_task != MM_PROC_NR); result= send(eth_port->etp_osdep.etp_task, &mess); if (result<0) { printf( "eth_init0: unable to send to ethernet task, error= %d\n", result); return; } if (receive(eth_port->etp_osdep.etp_task, &mess)<0) ip_panic(("unable to receive")); if (mess.m3_i1 != eth_port->etp_osdep.etp_port) { printf("eth_init0: got reply for wrong port\n"); return; } eth_port->etp_ethaddr= *(ether_addr_t *)mess.m3_ca1; if (sr_add_minor (eth_port->etp_osdep.etp_minor, eth_port- eth_port_table, eth_open, eth_close, eth_read, eth_write, eth_ioctl, eth_cancel)<0) ip_panic(("can't sr_init")); eth_port->etp_flags |= EPF_ENABLED; eth_port->etp_wr_pack= 0; eth_port->etp_rd_pack= 0; setup_read (eth_port); }
PUBLIC void osdep_eth_init() { int i, j, rport; struct eth_conf *ecp; eth_port_t *eth_port, *rep; cp_grant_id_t gid; /* First initialize normal ethernet interfaces */ for (i= 0, ecp= eth_conf, eth_port= eth_port_table; i<eth_conf_nr; i++, ecp++, eth_port++) { /* Set all grants to invalid */ for (j= 0; j<IOVEC_NR; j++) eth_port->etp_osdep.etp_wr_iovec[j].iov_grant= -1; eth_port->etp_osdep.etp_wr_vec_grant= -1; for (j= 0; j<RD_IOVEC; j++) eth_port->etp_osdep.etp_rd_iovec[j].iov_grant= -1; eth_port->etp_osdep.etp_rd_vec_grant= -1; eth_port->etp_osdep.etp_state= OEPS_INIT; eth_port->etp_osdep.etp_flags= OEPF_EMPTY; eth_port->etp_osdep.etp_stat_gid= -1; eth_port->etp_osdep.etp_stat_buf= NULL; if (eth_is_vlan(ecp)) continue; /* Allocate grants */ for (j= 0; j<IOVEC_NR; j++) { if (cpf_getgrants(&gid, 1) != 1) { ip_panic(( "osdep_eth_init: cpf_getgrants failed: %d\n", errno)); } eth_port->etp_osdep.etp_wr_iovec[j].iov_grant= gid; } if (cpf_getgrants(&gid, 1) != 1) { ip_panic(( "osdep_eth_init: cpf_getgrants failed: %d\n", errno)); } eth_port->etp_osdep.etp_wr_vec_grant= gid; for (j= 0; j<RD_IOVEC; j++) { if (cpf_getgrants(&gid, 1) != 1) { ip_panic(( "osdep_eth_init: cpf_getgrants failed: %d\n", errno)); } eth_port->etp_osdep.etp_rd_iovec[j].iov_grant= gid; } if (cpf_getgrants(&gid, 1) != 1) { ip_panic(( "osdep_eth_init: cpf_getgrants failed: %d\n", errno)); } eth_port->etp_osdep.etp_rd_vec_grant= gid; eth_port->etp_osdep.etp_task= NONE; eth_port->etp_osdep.etp_recvconf= 0; ev_init(ð_port->etp_osdep.etp_recvev); sr_add_minor(if2minor(ecp->ec_ifno, ETH_DEV_OFF), i, eth_open, eth_close, eth_read, eth_write, eth_ioctl, eth_cancel, eth_select); eth_port->etp_flags |= EPF_ENABLED; eth_port->etp_vlan= 0; eth_port->etp_vlan_port= NULL; eth_port->etp_wr_pack= 0; eth_port->etp_rd_pack= 0; } /* And now come the VLANs */ for (i= 0, ecp= eth_conf, eth_port= eth_port_table; i<eth_conf_nr; i++, ecp++, eth_port++) { if (!eth_is_vlan(ecp)) continue; eth_port->etp_osdep.etp_task= NONE; ev_init(ð_port->etp_osdep.etp_recvev); rport= ecp->ec_port; assert(rport >= 0 && rport < eth_conf_nr); rep= ð_port_table[rport]; if (!(rep->etp_flags & EPF_ENABLED)) { printf( "eth%d: underlying ethernet device %d not enabled", i, rport); continue; } if (rep->etp_vlan != 0) { printf( "eth%d: underlying ethernet device %d is a VLAN", i, rport); continue; } if (rep->etp_flags & EPF_GOT_ADDR) { eth_port->etp_ethaddr= rep->etp_ethaddr; printf("osdep_eth_init: setting EPF_GOT_ADDR\n"); eth_port->etp_flags |= EPF_GOT_ADDR; } sr_add_minor(if2minor(ecp->ec_ifno, ETH_DEV_OFF), i, eth_open, eth_close, eth_read, eth_write, eth_ioctl, eth_cancel, eth_select); eth_port->etp_flags |= EPF_ENABLED; eth_port->etp_vlan= ecp->ec_vlan; eth_port->etp_vlan_port= rep; assert(eth_port->etp_vlan != 0); eth_port->etp_wr_pack= 0; eth_port->etp_rd_pack= 0; eth_reg_vlan(rep, eth_port); } }