PUBLIC time_t get_time() { if (!curr_time) { static message mess; mess.m_type= GET_UPTIME; if (sendrec (CLOCK, &mess) < 0) ip_panic(("unable to sendrec")); if (mess.m_type != OK) ip_panic(("can't read clock")); curr_time= mess.NEW_TIME; } return curr_time; }
PUBLIC void main() { mq_t *mq; int result; nw_init(); while (TRUE) { mq= mq_get(); if (!mq) ip_panic(("out of messages")); result= receive (ANY, &mq->mq_mess); if (result<0) { ip_panic(("unable to receive: %d", result)); } reset_time(); #if DEBUG & 256 { where(); printf("got message from %d, type %d\n", mq->mq_mess.m_source, mq->mq_mess.m_type); } #endif switch (mq->mq_mess.m_source) { case FS_PROC_NR: #if DEBUG & 256 { where(); printf("got message from fs, type %d\n", mq->mq_mess.m_type); } #endif sr_rec(mq); break; case DL_ETH: #if DEBUG & 256 { where(); printf("calling eth_rec\n"); } #endif eth_rec(&mq->mq_mess); mq_free(mq); break; case SYN_ALRM_TASK: clck_tick (&mq->mq_mess); mq_free(mq); break; default: ip_panic(("message from unknown source: %d", mq->mq_mess.m_source)); } } ip_panic(("task is not allowed to terminate")); }
PRIVATE void tcpip_chmod() { static long cols[NROOTCOLUMNS] = {0xFF & ~(SP_DELRGT | SP_MODRGT)}; if (dirchmod(TCPIP_DIRNAME, NROOTCOLUMNS, cols)) ip_panic(( "tcpip_chmod: can't chmod directory" )); }
PRIVATE void tcpip_dirinit() { extern capset _sp_rootdir; static char *colnames[] = { "owner", "group", "other", 0 }; static long cols[NROOTCOLUMNS] = {0xFF & ~(SP_DELRGT)}; capset psdir; /* ** Create an internal soap directory and append it to the root. */ if (sp_create(&_sp_rootdir, colnames, &psdir) != STD_OK) ip_panic(( "tcpip_dirinit: can't create directory" )); if (sp_append(&_sp_rootdir, TCPIP_DIRNAME, &psdir, NROOTCOLUMNS, cols) != STD_OK) ip_panic(( "tcpip_dirinit: can't append directory" )); }
time_t get_time() { if (!curr_time) { if (getticks(&curr_time) != OK) ip_panic(("can't read clock")); assert(curr_time >= prev_time); } return curr_time; }
PUBLIC void bf_init() { int i; size_t size; size_t buf_s; bf_buf_gran= BUF_S; buf_s= 0; #if USE_MALLOCS printf("buf.c: malloc %d 32K-buffers (%dK)\n", BUF32K_NR, sizeof(*buffers32K) * BUF32K_NR / 1024); buffers32K= malloc(sizeof(*buffers32K) * BUF32K_NR); if (!buffers32K) ip_panic(( "unable to alloc 32K-buffers" )); printf("buf.c: malloc %d 2K-buffers (%dK)\n", BUF2K_NR, sizeof(*buffers2K) * BUF2K_NR / 1024); buffers2K= malloc(sizeof(*buffers2K) * BUF2K_NR); if (!buffers2K) ip_panic(( "unable to alloc 2K-buffers" )); printf("buf.c: malloc %d 512-buffers (%dK)\n", BUF512_NR, sizeof(*buffers512) * BUF512_NR / 1024); buffers512= malloc(sizeof(*buffers512) * BUF512_NR); if (!buffers512) ip_panic(( "unable to alloc 512-buffers" )); printf("buf.c: malloc %d accessors (%dK)\n", ACC_NR, sizeof(*accessors) * ACC_NR / 1024); accessors= malloc(sizeof(*accessors) * ACC_NR); if (!accessors) ip_panic(( "unable to alloc accessors" )); #endif for (i=0;i<BUF512_NR;i++) { buffers512[i].buf_header.buf_linkC= 0; buffers512[i].buf_header.buf_next= &buffers512[i+1]; buffers512[i].buf_header.buf_free= bf_512free; buffers512[i].buf_header.buf_size= sizeof(buffers512[i]. buf_data); buffers512[i].buf_header.buf_data_p= buffers512[i].buf_data; } buffers512[i-1].buf_header.buf_next= 0; buf512_free= &buffers512[0]; if (sizeof(buffers512[0].buf_data) < bf_buf_gran) bf_buf_gran= sizeof(buffers512[0].buf_data); if (sizeof(buffers512[0].buf_data) > buf_s) buf_s= sizeof(buffers512[0].buf_data); for (i=0;i<ACC_NR;i++) { accessors[i].acc_linkC= 0; accessors[i].acc_next= &accessors[i+1]; } acc_free_list= accessors; accessors[i-1].acc_next= 0; for (i=0;i<CLIENT_NR;i++) freereq[i]=0; assert (buf_s == BUF_S); }
PUBLIC void main() { mq_t *mq; int r; int source, timerand, fd; struct fssignon device; #ifdef __minix_vmd struct systaskinfo info; #endif u8_t randbits[32]; struct timeval tv; #if DEBUG printf("Starting inet...\n"); printf("%s\n", version); #endif /* Read configuration. */ nw_conf(); /* Get a random number */ timerand= 1; fd= open(RANDOM_DEV_NAME, O_RDONLY | O_NONBLOCK); if (fd != -1) { r= read(fd, randbits, sizeof(randbits)); if (r == sizeof(randbits)) timerand= 0; else { printf("unable to read random data from %s: %s\n", RANDOM_DEV_NAME, r == -1 ? strerror(errno) : r == 0 ? "EOF" : "not enough data"); } close(fd); } else { printf("unable to open random device %s: %s\n", RANDOM_DEV_NAME, strerror(errno)); } if (timerand) { printf("using current time for random-number seed\n"); #ifdef __minix_vmd r= sysutime(UTIME_TIMEOFDAY, &tv); #else /* Minix 3 */ r= gettimeofday(&tv, NULL); #endif if (r == -1) { printf("sysutime failed: %s\n", strerror(errno)); exit(1); } memcpy(randbits, &tv, sizeof(tv)); } init_rand256(randbits); #ifdef __minix_vmd if (svrctl(SYSSIGNON, (void *) &info) == -1) pause(); /* Our new identity as a server. */ this_proc = info.proc_nr; #else /* Minix 3 */ /* Our new identity as a server. */ if ((this_proc = getprocnr()) < 0) ip_panic(( "unable to get own process nr\n")); #endif /* Register the device group. */ device.dev= ip_dev; device.style= STYLE_CLONE; if (svrctl(FSSIGNON, (void *) &device) == -1) { printf("inet: error %d on registering ethernet devices\n", errno); pause(); } #ifdef BUF_CONSISTENCY_CHECK inet_buf_debug= (getenv("inetbufdebug") && (strcmp(getenv("inetbufdebug"), "on") == 0)); inet_buf_debug= 100; if (inet_buf_debug) { ip_warning(( "buffer consistency check enabled" )); } #endif if (getenv("killerinet")) { ip_warning(( "killer inet active" )); killer_inet= 1; } #ifdef __minix_vmd r= sys_findproc(SYN_AL_NAME, &synal_tasknr, 0); if (r != OK) ip_panic(( "unable to find synchronous alarm task: %d\n", r )); #endif nw_init(); while (TRUE) { #ifdef BUF_CONSISTENCY_CHECK if (inet_buf_debug) { static int buf_debug_count= 0; if (++buf_debug_count >= inet_buf_debug) { buf_debug_count= 0; if (!bf_consistency_check()) break; } } #endif if (ev_head) { ev_process(); continue; } if (clck_call_expire) { clck_expire_timers(); continue; } mq= mq_get(); if (!mq) ip_panic(("out of messages")); r= receive (ANY, &mq->mq_mess); if (r<0) { ip_panic(("unable to receive: %d", r)); } reset_time(); source= mq->mq_mess.m_source; if (source == FS_PROC_NR) { sr_rec(mq); } #ifdef __minix_vmd else if (source == synal_tasknr) { clck_tick (&mq->mq_mess); mq_free(mq); } #else /* Minix 3 */ else if (mq->mq_mess.m_type == SYN_ALARM) { clck_tick(&mq->mq_mess); mq_free(mq); } else if (mq->mq_mess.m_type == SYS_SIG) { /* signaled */ /* probably SIGTERM */ mq_free(mq); } else if (mq->mq_mess.m_type & NOTIFY_MESSAGE) { /* A driver is (re)started. */ eth_check_drivers(&mq->mq_mess); mq_free(mq); } #endif else { compare(mq->mq_mess.m_type, ==, DL_TASK_REPLY); eth_rec(&mq->mq_mess); mq_free(mq); } } ip_panic(("task is not allowed to terminate")); }
void main(void) { mq_t *mq; int r; int source, m_type, timerand, fd; u32_t tasknr; struct fssignon device; u8_t randbits[32]; struct timeval tv; #if DEBUG printk("Starting inet...\n"); printk("%s\n", version); #endif #if HZ_DYNAMIC system_hz = sys_hz(); #endif /* Read configuration. */ nw_conf(); /* Get a random number */ timerand= 1; fd= open(RANDOM_DEV_NAME, O_RDONLY | O_NONBLOCK); if (fd != -1) { r= read(fd, randbits, sizeof(randbits)); if (r == sizeof(randbits)) timerand= 0; else { printk("inet: unable to read random data from %s: %s\n", RANDOM_DEV_NAME, r == -1 ? strerror(errno) : r == 0 ? "EOF" : "not enough data"); } close(fd); } else { printk("inet: unable to open random device %s: %s\n", RANDOM_DEV_NAME, strerror(errno)); } if (timerand) { printk("inet: using current time for random-number seed\n"); r= gettimeofday(&tv, NULL); if (r == -1) { printk("sysutime failed: %s\n", strerror(errno)); exit(1); } memcpy(randbits, &tv, sizeof(tv)); } init_rand256(randbits); /* Our new identity as a server. */ r= ds_retrieve_u32("inet", &tasknr); if (r != 0) ip_panic(("inet: ds_retrieve_u32 failed for 'inet': %d", r)); this_proc= tasknr; /* Register the device group. */ device.dev= ip_dev; device.style= STYLE_CLONE; if (svrctl(FSSIGNON, (void *) &device) == -1) { printk("inet: error %d on registering ethernet devices\n", errno); pause(); } #ifdef BUF_CONSISTENCY_CHECK inet_buf_debug= (getenv("inetbufdebug") && (strcmp(getenv("inetbufdebug"), "on") == 0)); inet_buf_debug= 100; if (inet_buf_debug) { ip_warning(( "buffer consistency check enabled" )); } #endif if (getenv("killerinet")) { ip_warning(( "killer inet active" )); killer_inet= 1; } nw_init(); while (TRUE) { #ifdef BUF_CONSISTENCY_CHECK if (inet_buf_debug) { static int buf_debug_count= 0; if (++buf_debug_count >= inet_buf_debug) { buf_debug_count= 0; if (!bf_consistency_check()) break; } } #endif if (ev_head) { ev_process(); continue; } if (clck_call_expire) { clck_expire_timers(); continue; } mq= mq_get(); if (!mq) ip_panic(("out of messages")); r = kipc_module_call(KIPC_RECEIVE, 0, ENDPT_ANY, &mq->mq_mess); if (r<0) { ip_panic(("unable to receive: %d", r)); } reset_time(); source= mq->mq_mess.m_source; m_type= mq->mq_mess.m_type; if (source == VFS_PROC_NR) { sr_rec(mq); } else if (is_notify(m_type)) { if (_ENDPOINT_P(source) == CLOCK) { clck_tick(&mq->mq_mess); mq_free(mq); } else if (_ENDPOINT_P(source) == PM_PROC_NR) { /* signaled */ /* probably SIGTERM */ mq_free(mq); } else { /* A driver is (re)started. */ eth_check_drivers(&mq->mq_mess); mq_free(mq); } } else if (m_type == DL_CONF_REPLY || m_type == DL_TASK_REPLY || m_type == DL_NAME_REPLY || m_type == DL_STAT_REPLY) { eth_rec(&mq->mq_mess); mq_free(mq); } else { printk("inet: got bad message type 0x%x from %d\n", mq->mq_mess.m_type, mq->mq_mess.m_source); mq_free(mq); } } ip_panic(("task is not allowed to terminate")); }
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); } }
PUBLIC int main(int argc, char *argv[]) { mq_t *mq; int ipc_status; int r; endpoint_t source; int m_type; /* SEF local startup. */ sef_local_startup(); while (TRUE) { #ifdef BUF_CONSISTENCY_CHECK if (inet_buf_debug) { static int buf_debug_count= 0; if (++buf_debug_count >= inet_buf_debug) { buf_debug_count= 0; if (!bf_consistency_check()) break; } } #endif if (ev_head) { ev_process(); continue; } if (clck_call_expire) { clck_expire_timers(); continue; } mq= mq_get(); if (!mq) ip_panic(("out of messages")); r= sef_receive_status(ANY, &mq->mq_mess, &ipc_status); if (r<0) { ip_panic(("unable to receive: %d", r)); } reset_time(); source= mq->mq_mess.m_source; m_type= mq->mq_mess.m_type; if (source == VFS_PROC_NR) { sr_rec(mq); } else if (is_ipc_notify(ipc_status)) { if (source == CLOCK) { clck_tick(&mq->mq_mess); mq_free(mq); } else if (source == PM_PROC_NR) { /* signaled */ /* probably SIGTERM */ mq_free(mq); } else if (source == DS_PROC_NR) { /* DS notifies us of an event. */ ds_event(); mq_free(mq); } else { printf("inet: got unexpected notify from %d\n", mq->mq_mess.m_source); mq_free(mq); } } else if (m_type == DL_CONF_REPLY || m_type == DL_TASK_REPLY || m_type == DL_STAT_REPLY) { eth_rec(&mq->mq_mess); mq_free(mq); } else { printf("inet: got bad message type 0x%x from %d\n", mq->mq_mess.m_type, mq->mq_mess.m_source); mq_free(mq); } } ip_panic(("task is not allowed to terminate")); return 1; }
/*===========================================================================* * sef_cb_init_fresh * *===========================================================================*/ PRIVATE int sef_cb_init_fresh(int type, sef_init_info_t *info) { /* Initialize the inet server. */ int r; int timerand, fd; u8_t randbits[32]; struct timeval tv; struct passwd *pw; #if DEBUG printf("Starting inet...\n"); printf("%s\n", version); #endif #if HZ_DYNAMIC system_hz = sys_hz(); #endif /* Read configuration. */ nw_conf(); /* Get a random number */ timerand= 1; fd= open(RANDOM_DEV_NAME, O_RDONLY | O_NONBLOCK); if (fd != -1) { r= read(fd, randbits, sizeof(randbits)); if (r == sizeof(randbits)) timerand= 0; else { printf("inet: unable to read random data from %s: %s\n", RANDOM_DEV_NAME, r == -1 ? strerror(errno) : r == 0 ? "EOF" : "not enough data"); } close(fd); } else { printf("inet: unable to open random device %s: %s\n", RANDOM_DEV_NAME, strerror(errno)); } if (timerand) { printf("inet: using current time for random-number seed\n"); r= gettimeofday(&tv, NULL); if (r == -1) { printf("sysutime failed: %s\n", strerror(errno)); exit(1); } memcpy(randbits, &tv, sizeof(tv)); } init_rand256(randbits); /* Our new identity as a server. */ this_proc= info->endpoint; #ifdef BUF_CONSISTENCY_CHECK inet_buf_debug= (getenv("inetbufdebug") && (strcmp(getenv("inetbufdebug"), "on") == 0)); inet_buf_debug= 100; if (inet_buf_debug) { ip_warning(( "buffer consistency check enabled" )); } #endif if (getenv("killerinet")) { ip_warning(( "killer inet active" )); killer_inet= 1; } nw_init(); /* Subscribe to driver events for network drivers. */ r = ds_subscribe("drv\\.net\\..*", DSF_INITIAL | DSF_OVERWRITE); if(r != OK) { ip_panic(("inet: can't subscribe to driver events")); } /* Drop root privileges */ if ((pw = getpwnam(SERVICE_LOGIN)) == NULL) { printf("inet: unable to retrieve uid of SERVICE_LOGIN, " "still running as root"); } else if (setuid(pw->pw_uid) != 0) { ip_panic(("inet: unable to drop privileges")); } /* Announce we are up. INET announces its presence to VFS just like * any other character driver. */ chardriver_announce(); return(OK); }