// start_download(tracker_task, filename) // Return a TASK_DOWNLOAD task for downloading 'filename' from peers. // Contacts the tracker for a list of peers that have 'filename', // and returns a task containing that peer list. task_t *start_download(task_t *tracker_task, const char *filename) { char *s1, *s2; task_t *t = NULL; peer_t *p; size_t messagepos; assert(tracker_task->type == TASK_TRACKER); message("* Finding peers for '%s'\n", filename); osp2p_writef(tracker_task->peer_fd, "WANT %s\n", filename); messagepos = read_tracker_response(tracker_task); if (tracker_task->buf[messagepos] != '2') { error("* Tracker error message while requesting '%s':\n%s", filename, &tracker_task->buf[messagepos]); goto exit; } if (!(t = task_new(TASK_DOWNLOAD))) { error("* Error while allocating task"); goto exit; } // EXERCISE 2A: FILENAME BUFFER OVERRUN // Avoid downloading a file with a name that is too long // The max number of bytes to copy is FILENAMESIZ, so use strncpy to // limit how much we copy, and add a null terminator at the end. strncpy(t->filename, filename, FILENAMESIZ); t->filename[FILENAMESIZ - 1] = '\0'; // add peers s1 = tracker_task->buf; while ((s2 = memchr(s1, '\n', (tracker_task->buf + messagepos) - s1))) { if (!(p = parse_peer(s1, s2 - s1))) die("osptracker responded to WANT command with unexpected format!\n"); p->next = t->peer_list; t->peer_list = p; s1 = s2 + 1; } if (s1 != tracker_task->buf + messagepos) die("osptracker's response to WANT has unexpected format!\n"); exit: return t; }
// start_download(tracker_task, filename) // Return a TASK_DOWNLOAD task for downloading 'filename' from peers. // Contacts the tracker for a list of peers that have 'filename', // and returns a task containing that peer list. task_t *start_download(task_t *tracker_task, const char *filename) { char *s1, *s2; task_t *t = NULL; peer_t *p; size_t messagepos; assert(tracker_task->type == TASK_TRACKER); message("* Finding peers for '%s'\n", filename); osp2p_writef(tracker_task->peer_fd, "WANT %s\n", filename); messagepos = read_tracker_response(tracker_task); if (tracker_task->buf[messagepos] != '2') { error("* Tracker error message while requesting '%s':\n%s", filename, &tracker_task->buf[messagepos]); goto exit; } if (!(t = task_new(TASK_DOWNLOAD))) { error("* Error while allocating task"); goto exit; } // Case where the filename is too large. if (strlen(filename) > FILENAMESIZ) error("Filename specified is larger than max filename size."); strcpy(t->filename, filename); // add peers s1 = tracker_task->buf; while ((s2 = memchr(s1, '\n', (tracker_task->buf + messagepos) - s1))) { if (!(p = parse_peer(s1, s2 - s1))) die("osptracker responded to WANT command with unexpected format!\n"); p->next = t->peer_list; t->peer_list = p; s1 = s2 + 1; } if (s1 != tracker_task->buf + messagepos) die("osptracker's response to WANT has unexpected format!\n"); exit: return t; }
/*---------------------------------------------------------------------------*/ usys kbd_init (void) { usys stat ; /* Initialize the stdio interface structure */ memset (&kbd_link, 0, sizeof (link_t)) ; /* Create the Keyboard Task */ stat = task_new (1, 0, 1024, 0,0, kbd_task, 0,0,0, "kbd_task", &task_id) ; if (stat != GOOD) { printf ("ERR: Creating kbd_task. Stat = %d\n", stat) ; return BAD ; } return GOOD ; } /* End of function kbd_init() */
static L4_ThreadId_t launch(L4_BootRec_t *br) { AddrSpace_t *as = task_new(mman_tid); if (!as) { debug("launch: can't create address space for %s\n", L4_Module_Cmdline(br)); return L4_nilthread; } /* we have to explicitly grab these from sigma0 */ L4_Word_t mi; for (mi = 0; mi < L4_Module_Size(br); mi += 4096) { L4_Sigma0_GetPage(L4_nilthread, L4_Fpage(L4_Module_Start(br) + mi, 4096)); } L4_Word_t start = elf_load32(as, L4_Module_Start(br), L4_Module_Size(br)); thread_start(as->tid, start, L4_Module_Cmdline(br), n_paths, dir_paths, dir_caps); printf(" %s\n", L4_Module_Cmdline(br)); return as->tid; }
task_mgr = task_new(vmatrixr_md->mod_mgr, TASK_PRIO_NORMAL, TASK_NEED_RSP_FLAG, TASK_NEED_ALL_RSP); VMATRIX_ROW_COL_BLOCKS_LOOP_NEXT(matrix, block_row_idx, block_col_idx) { VMM_NODE *matrix_block_vmm; //vmm_alloc(vmatrixr_md->vmm_md_id, MD_VMATRIXR, MOD_NODE_MODI(recv_mod_node), MM_VMM_NODE, &vmm_node); alloc_static_mem(MD_VMATRIXR, vmatrixr_md_id, MM_VMM_NODE, &matrix_block_vmm, LOC_VMATRIXR_0007); cvector_push((CVECTOR *)blocks, (void *)matrix_block_vmm); task_inc(task_mgr, &ret, FI_vmatrix_r_alloc_block, ERR_MODULE_ID, matrix_block_vmm);/*alloc matrix block from virtual memory*/ } task_wait(task_mgr, TASK_ALWAYS_LIVE, TASK_NOT_NEED_RESCHEDULE_FLAG, NULL_PTR); /*adjust row num of last row header and its blocks if necessary*/ task_mgr = task_new(vmatrixr_md->mod_mgr, TASK_PRIO_NORMAL, TASK_NEED_RSP_FLAG, TASK_NEED_ALL_RSP); sub_row_num = (row_num % MATRIX_VECTOR_WIDTH); if( 0 < sub_row_num ) { block_row_idx = (blocks_row_num - 1); VMATRIX_BLOCK_COL_LOOP_NEXT(blocks_col_num, block_col_idx) { VMM_NODE *matrix_block_vmm; MOD_NODE *recv_mod_node; UINT32 ret; matrix_block_vmm = (VMM_NODE *)MATRIX_GET_BLOCK(matrix, block_row_idx, block_col_idx); recv_mod_node = VMM_NODE_MOD_NODE(matrix_block_vmm); //vmatrix_r_block_set_row_num(vmatrixr_md_id, sub_row_num, vmm_node); task_super_inc(task_mgr, send_mod_node, recv_mod_node, &ret, FI_vmatrix_r_block_set_row_num, VMM_NODE_MODI(matrix_block_vmm), sub_row_num, matrix_block_vmm);
/*---------------------------------------------------------------------------*/ usys os_init (usys mem_start, usys mem_size) { usys stat ; /* Disable all Interrupts */ cpu_disable_ints() ; /* The global kernel data structre is statically allocated by */ /* the linker. This prevent the need for it to get allocated by */ /* the Memory Unit which is itself not initialized. */ memset (&kernel, 0, sizeof (kernel_t)) ; /* Initialize the Memory Unit */ if (mem_init (mem_start, mem_size) != GOOD) { printf ("ERR: In os_init(): mem_init() Failed !!!\n") ; return BAD ; } /* Initialize the Task Unit */ if (task_init () != GOOD) { printf ("ERR: In os_init(): task_init () Failed !!!\n") ; return BAD ; } /* The memory and task units are now initialized. The kernel */ /* task and the interrupt task can now be created. They are */ /* created with the highest priority. */ kernel.int_mode = YES ; /* Fix this HACK <-- */ printf ("Akalon: Creating Idle Task\n") ; stat = task_new (0, 0, 1024,0,0, task_idle, 0,0,0, "idle_task", (usys *) (void *) &kernel.task_idle) ; if (stat != GOOD) { printf ("ERR: In os_init(): Creating Idle Task. Stat = %d\n", stat) ; return BAD ; } /* Initialize the Interrupt Unit */ if (int_init () != GOOD) { printf ("ERR: In os_init(): int_init () Failed !!!\n") ; return BAD ; } /* Initialize the Semaphore Unit */ if (sem_init () != GOOD) { printf ("ERR: In os_init(): sem_init() Failed !!!\n") ; return BAD ; } /* Initialize the Timer Unit */ if (timer_init () != GOOD) { printf ("ERR: In os_init(): timer_init() Failed !!!\n") ; return BAD ; } /* Now, run the Idle Task. Except in the case of */ /* an Error, this call will never return back. */ kernel.task_idle->state = TASK_RUNNING ; cpu_task_first (kernel.task_idle->stack_ptr) ; /* We did return back...something has gone wrong. */ printf ("ERR: os_init(). Cannot Run Idle Task !!!\n") ; return BAD ; } /* End of function os_init() */
/*---------------------------------------------------------------------------*/ usys stdio_init (void) { usys stat ; usys id ; /*********/ /* Input */ /*********/ /* Create an empty counting semaphore of buffer size for the receiver */ stat = sem_new (BUF_SIZE, 0, "STDIO: rx_sem", &rx_sem) ; if (stat != GOOD) { printf ("ERR: (STDIO) Creating rx_sem. Stat = %d\n", stat) ; /* Graceful Exit <-- DO */ return BAD ; } rx_p = rx_c = 0 ; /**********/ /* Output */ /**********/ /* STD-Output Task */ stat = task_new (2, 0, 1024, 0,0, stdout_task, 0,0,0, "stdout_task", &id) ; if (stat != GOOD) { printf ("ERR: (STDIO) Creating stdout_task. Stat = %d\n", stat) ; /* Graceful Exit <-- DO */ return BAD ; } /* Create a full binary semaphore for putchar() */ stat = sem_new (1, 1, "STDIO: out_free_sem", &putchar_sem) ; if (stat != GOOD) { printf ("ERR: (STDIO) Creating putchar_sem. Stat = %d\n", stat) ; /* Graceful Exit <-- DO */ return BAD ; } /* Create a empty binary semaphore to wake-up the stdout_task() */ stat = sem_new (BUF_SIZE, 0, "STDIO: tx_task_sem", &tx_task_sem) ; if (stat != GOOD) { printf ("ERR: Cannot Create STDIO: tx_task_sem. Stat = %d\n", stat) ; /* Graceful Exit <-- DO */ return BAD ; } /* Create a full counting semaphore of buffer size for the transmitter */ stat = sem_new (BUF_SIZE, BUF_SIZE, "STDIO: tx_buf_sem", &tx_buf_sem) ; if (stat != GOOD) { printf ("ERR: (STDIO) Creating out_buf_sem. Stat = %d\n", stat) ; /* Graceful Exit <-- DO */ return BAD ; } tx_p = tx_c = 0 ; /*********/ /* Misc. */ /*********/ /* Initialize the stdio interface structure */ memset (&stdio_link, 0, sizeof (link_t)) ; stdio_link.rx_func = rx_func ; return GOOD ; } /* End of function stdio_init() */
/*check replica files*/ EC_BOOL test_case_85_crfs_check_file_content(const char *home, const UINT32 crfs_tcid, const UINT32 crfs_rank, const UINT32 crfs_modi, const UINT32 max_test_data_files, UINT32 *counter) { MOD_MGR *mod_mgr; TASK_MGR *task_mgr; UINT32 index; CSTRING *path[CRFS_TEST_READ_MAX_FILES]; EC_BOOL ret[CRFS_TEST_READ_MAX_FILES]; EC_BOOL continue_flag; for(index = 0; index < CRFS_TEST_READ_MAX_FILES; index ++) { path[ index ] = NULL_PTR; ret[ index ] = EC_FALSE; } mod_mgr = mod_mgr_new(CMPI_ERROR_MODI, LOAD_BALANCING_LOOP); mod_mgr_incl(crfs_tcid, CMPI_ANY_COMM, crfs_rank, crfs_modi, mod_mgr); sys_log(LOGSTDOUT, "test_case_85_crfs_check_file_content: npp mod mgr is\n"); mod_mgr_print(LOGSTDOUT, crfs_get_npp_mod_mgr(crfs_modi)); sys_log(LOGSTDOUT, "test_case_85_crfs_check_file_content: dn mod mgr is\n"); mod_mgr_print(LOGSTDOUT, crfs_get_dn_mod_mgr(crfs_modi)); task_mgr = task_new(mod_mgr, TASK_PRIO_NORMAL, TASK_NEED_RSP_FLAG, TASK_NEED_ALL_RSP); for(index = 0; index < CRFS_TEST_READ_MAX_FILES; index ++, (*counter) ++) { CBYTES *cbytes_des; cbytes_des = __test_crfs_fetch_g_cbytes(max_test_data_files, ((*counter) % max_test_data_files)); path[ index ] = cstring_new(NULL_PTR, 0); cstring_format(path[ index ], "%s/%ld.dat", home, (*counter)); ret[ index ] = EC_FALSE; task_inc(task_mgr, &(ret[ index ]), FI_crfs_check_file_is, ERR_MODULE_ID, path[ index ], cbytes_des); } task_wait(task_mgr, TASK_DEFAULT_LIVE, TASK_NEED_RESCHEDULE_FLAG, NULL_PTR); continue_flag = EC_TRUE; for(index = 0; index < CRFS_TEST_READ_MAX_FILES; index ++) { if(EC_TRUE == ret[ index ]) { sys_log(LOGSTDOUT, "[SUCC] path: %s\n", (char *)cstring_get_str(path[ index ])); } else { continue_flag = EC_FALSE; sys_log(LOGCONSOLE, "[FAIL] path: %s\n", (char *)cstring_get_str(path[ index ])); } if(NULL_PTR != path[ index ]) { cstring_free(path[ index ]); path[ index ] = NULL_PTR; } if(NULL_PTR != path[ index ]) { cstring_free(path[ index ]); path[ index ] = NULL_PTR; } } mod_mgr_free(mod_mgr); return (continue_flag); }
/* This function is called from the protocol layer accept() in order to * instanciate a new session on behalf of a given listener and frontend. It * returns a positive value upon success, 0 if the connection can be ignored, * or a negative value upon critical failure. The accepted file descriptor is * closed if we return <= 0. If no handshake is needed, it immediately tries * to instanciate a new stream. The created connection's owner points to the * new session until the upper layers are created. */ int session_accept_fd(struct listener *l, int cfd, struct sockaddr_storage *addr) { struct connection *cli_conn; struct proxy *p = l->bind_conf->frontend; struct session *sess; int ret; ret = -1; /* assume unrecoverable error by default */ if (unlikely((cli_conn = conn_new()) == NULL)) goto out_close; conn_prepare(cli_conn, l->proto, l->bind_conf->xprt); cli_conn->handle.fd = cfd; cli_conn->addr.from = *addr; cli_conn->flags |= CO_FL_ADDR_FROM_SET; cli_conn->target = &l->obj_type; cli_conn->proxy_netns = l->netns; conn_ctrl_init(cli_conn); /* wait for a PROXY protocol header */ if (l->options & LI_O_ACC_PROXY) { cli_conn->flags |= CO_FL_ACCEPT_PROXY; conn_sock_want_recv(cli_conn); } /* wait for a NetScaler client IP insertion protocol header */ if (l->options & LI_O_ACC_CIP) { cli_conn->flags |= CO_FL_ACCEPT_CIP; conn_sock_want_recv(cli_conn); } conn_xprt_want_recv(cli_conn); if (conn_xprt_init(cli_conn) < 0) goto out_free_conn; sess = session_new(p, l, &cli_conn->obj_type); if (!sess) goto out_free_conn; conn_set_owner(cli_conn, sess, NULL); /* now evaluate the tcp-request layer4 rules. We only need a session * and no stream for these rules. */ if ((l->options & LI_O_TCP_L4_RULES) && !tcp_exec_l4_rules(sess)) { /* let's do a no-linger now to close with a single RST. */ setsockopt(cfd, SOL_SOCKET, SO_LINGER, (struct linger *) &nolinger, sizeof(struct linger)); ret = 0; /* successful termination */ goto out_free_sess; } /* monitor-net and health mode are processed immediately after TCP * connection rules. This way it's possible to block them, but they * never use the lower data layers, they send directly over the socket, * as they were designed for. We first flush the socket receive buffer * in order to avoid emission of an RST by the system. We ignore any * error. */ if (unlikely((p->mode == PR_MODE_HEALTH) || ((l->options & LI_O_CHK_MONNET) && addr->ss_family == AF_INET && (((struct sockaddr_in *)addr)->sin_addr.s_addr & p->mon_mask.s_addr) == p->mon_net.s_addr))) { /* we have 4 possibilities here : * - HTTP mode, from monitoring address => send "HTTP/1.0 200 OK" * - HEALTH mode with HTTP check => send "HTTP/1.0 200 OK" * - HEALTH mode without HTTP check => just send "OK" * - TCP mode from monitoring address => just close */ if (l->proto->drain) l->proto->drain(cfd); if (p->mode == PR_MODE_HTTP || (p->mode == PR_MODE_HEALTH && (p->options2 & PR_O2_CHK_ANY) == PR_O2_HTTP_CHK)) send(cfd, "HTTP/1.0 200 OK\r\n\r\n", 19, MSG_DONTWAIT|MSG_NOSIGNAL|MSG_MORE); else if (p->mode == PR_MODE_HEALTH) send(cfd, "OK\n", 3, MSG_DONTWAIT|MSG_NOSIGNAL|MSG_MORE); ret = 0; goto out_free_sess; } /* Adjust some socket options */ if (l->addr.ss_family == AF_INET || l->addr.ss_family == AF_INET6) { setsockopt(cfd, IPPROTO_TCP, TCP_NODELAY, (char *) &one, sizeof(one)); if (p->options & PR_O_TCP_CLI_KA) setsockopt(cfd, SOL_SOCKET, SO_KEEPALIVE, (char *) &one, sizeof(one)); if (p->options & PR_O_TCP_NOLING) fdtab[cfd].linger_risk = 1; #if defined(TCP_MAXSEG) if (l->maxseg < 0) { /* we just want to reduce the current MSS by that value */ int mss; socklen_t mss_len = sizeof(mss); if (getsockopt(cfd, IPPROTO_TCP, TCP_MAXSEG, &mss, &mss_len) == 0) { mss += l->maxseg; /* remember, it's < 0 */ setsockopt(cfd, IPPROTO_TCP, TCP_MAXSEG, &mss, sizeof(mss)); } } #endif } if (global.tune.client_sndbuf) setsockopt(cfd, SOL_SOCKET, SO_SNDBUF, &global.tune.client_sndbuf, sizeof(global.tune.client_sndbuf)); if (global.tune.client_rcvbuf) setsockopt(cfd, SOL_SOCKET, SO_RCVBUF, &global.tune.client_rcvbuf, sizeof(global.tune.client_rcvbuf)); /* OK, now either we have a pending handshake to execute with and then * we must return to the I/O layer, or we can proceed with the end of * the stream initialization. In case of handshake, we also set the I/O * timeout to the frontend's client timeout and register a task in the * session for this purpose. The connection's owner is left to the * session during this period. * * At this point we set the relation between sess/task/conn this way : * * +----------------- task * | | * orig -- sess <-- context | * | ^ | | * v | | | * conn -- owner ---> task <-----+ */ if (cli_conn->flags & (CO_FL_HANDSHAKE | CO_FL_EARLY_SSL_HS)) { if (unlikely((sess->task = task_new(tid_bit)) == NULL)) goto out_free_sess; conn_set_xprt_done_cb(cli_conn, conn_complete_session); sess->task->context = sess; sess->task->nice = l->nice; sess->task->process = session_expire_embryonic; sess->task->expire = tick_add_ifset(now_ms, p->timeout.client); task_queue(sess->task); return 1; } /* OK let's complete stream initialization since there is no handshake */ if (conn_complete_session(cli_conn) >= 0) return 1; /* error unrolling */ out_free_sess: /* prevent call to listener_release during session_free. It will be * done below, for all errors. */ sess->listener = NULL; session_free(sess); out_free_conn: conn_stop_tracking(cli_conn); conn_xprt_close(cli_conn); conn_free(cli_conn); out_close: listener_release(l); if (ret < 0 && l->bind_conf->xprt == xprt_get(XPRT_RAW) && p->mode == PR_MODE_HTTP) { /* critical error, no more memory, try to emit a 500 response */ struct chunk *err_msg = &p->errmsg[HTTP_ERR_500]; if (!err_msg->str) err_msg = &http_err_chunks[HTTP_ERR_500]; send(cfd, err_msg->str, err_msg->len, MSG_DONTWAIT|MSG_NOSIGNAL); } if (fdtab[cfd].owner) fd_delete(cfd); else close(cfd); return ret; }
/* This function is called from the protocol layer accept() in order to * instanciate a new session on behalf of a given listener and frontend. It * returns a positive value upon success, 0 if the connection can be ignored, * or a negative value upon critical failure. The accepted file descriptor is * closed if we return <= 0. If no handshake is needed, it immediately tries * to instanciate a new stream. */ int session_accept_fd(struct listener *l, int cfd, struct sockaddr_storage *addr) { struct connection *cli_conn; struct proxy *p = l->frontend; struct session *sess; struct stream *strm; struct task *t; int ret; ret = -1; /* assume unrecoverable error by default */ if (unlikely((cli_conn = conn_new()) == NULL)) goto out_close; conn_prepare(cli_conn, l->proto, l->xprt); cli_conn->t.sock.fd = cfd; cli_conn->addr.from = *addr; cli_conn->flags |= CO_FL_ADDR_FROM_SET; cli_conn->target = &l->obj_type; cli_conn->proxy_netns = l->netns; conn_ctrl_init(cli_conn); /* wait for a PROXY protocol header */ if (l->options & LI_O_ACC_PROXY) { cli_conn->flags |= CO_FL_ACCEPT_PROXY; conn_sock_want_recv(cli_conn); } conn_data_want_recv(cli_conn); if (conn_xprt_init(cli_conn) < 0) goto out_free_conn; sess = session_new(p, l, &cli_conn->obj_type); if (!sess) goto out_free_conn; p->feconn++; /* This session was accepted, count it now */ if (p->feconn > p->fe_counters.conn_max) p->fe_counters.conn_max = p->feconn; proxy_inc_fe_conn_ctr(l, p); /* now evaluate the tcp-request layer4 rules. We only need a session * and no stream for these rules. */ if ((l->options & LI_O_TCP_RULES) && !tcp_exec_req_rules(sess)) { /* let's do a no-linger now to close with a single RST. */ setsockopt(cfd, SOL_SOCKET, SO_LINGER, (struct linger *) &nolinger, sizeof(struct linger)); ret = 0; /* successful termination */ goto out_free_sess; } /* monitor-net and health mode are processed immediately after TCP * connection rules. This way it's possible to block them, but they * never use the lower data layers, they send directly over the socket, * as they were designed for. We first flush the socket receive buffer * in order to avoid emission of an RST by the system. We ignore any * error. */ if (unlikely((p->mode == PR_MODE_HEALTH) || ((l->options & LI_O_CHK_MONNET) && addr->ss_family == AF_INET && (((struct sockaddr_in *)addr)->sin_addr.s_addr & p->mon_mask.s_addr) == p->mon_net.s_addr))) { /* we have 4 possibilities here : * - HTTP mode, from monitoring address => send "HTTP/1.0 200 OK" * - HEALTH mode with HTTP check => send "HTTP/1.0 200 OK" * - HEALTH mode without HTTP check => just send "OK" * - TCP mode from monitoring address => just close */ if (l->proto->drain) l->proto->drain(cfd); if (p->mode == PR_MODE_HTTP || (p->mode == PR_MODE_HEALTH && (p->options2 & PR_O2_CHK_ANY) == PR_O2_HTTP_CHK)) send(cfd, "HTTP/1.0 200 OK\r\n\r\n", 19, MSG_DONTWAIT|MSG_NOSIGNAL|MSG_MORE); else if (p->mode == PR_MODE_HEALTH) send(cfd, "OK\n", 3, MSG_DONTWAIT|MSG_NOSIGNAL|MSG_MORE); ret = 0; goto out_free_sess; } /* Adjust some socket options */ if (l->addr.ss_family == AF_INET || l->addr.ss_family == AF_INET6) { setsockopt(cfd, IPPROTO_TCP, TCP_NODELAY, (char *) &one, sizeof(one)); if (p->options & PR_O_TCP_CLI_KA) setsockopt(cfd, SOL_SOCKET, SO_KEEPALIVE, (char *) &one, sizeof(one)); if (p->options & PR_O_TCP_NOLING) fdtab[cfd].linger_risk = 1; #if defined(TCP_MAXSEG) if (l->maxseg < 0) { /* we just want to reduce the current MSS by that value */ int mss; socklen_t mss_len = sizeof(mss); if (getsockopt(cfd, IPPROTO_TCP, TCP_MAXSEG, &mss, &mss_len) == 0) { mss += l->maxseg; /* remember, it's < 0 */ setsockopt(cfd, IPPROTO_TCP, TCP_MAXSEG, &mss, sizeof(mss)); } } #endif } if (global.tune.client_sndbuf) setsockopt(cfd, SOL_SOCKET, SO_SNDBUF, &global.tune.client_sndbuf, sizeof(global.tune.client_sndbuf)); if (global.tune.client_rcvbuf) setsockopt(cfd, SOL_SOCKET, SO_RCVBUF, &global.tune.client_rcvbuf, sizeof(global.tune.client_rcvbuf)); if (unlikely((t = task_new()) == NULL)) goto out_free_sess; t->context = sess; t->nice = l->nice; /* OK, now either we have a pending handshake to execute with and * then we must return to the I/O layer, or we can proceed with the * end of the stream initialization. In case of handshake, we also * set the I/O timeout to the frontend's client timeout. * * At this point we set the relation between sess/task/conn this way : * * orig -- sess <-- context * | | * v | * conn -- owner ---> task */ if (cli_conn->flags & CO_FL_HANDSHAKE) { conn_attach(cli_conn, t, &sess_conn_cb); t->process = session_expire_embryonic; t->expire = tick_add_ifset(now_ms, p->timeout.client); task_queue(t); cli_conn->flags |= CO_FL_INIT_DATA | CO_FL_WAKE_DATA; return 1; } /* OK let's complete stream initialization since there is no handshake */ cli_conn->flags |= CO_FL_CONNECTED; /* we want the connection handler to notify the stream interface about updates. */ cli_conn->flags |= CO_FL_WAKE_DATA; /* if logs require transport layer information, note it on the connection */ if (sess->fe->to_log & LW_XPRT) cli_conn->flags |= CO_FL_XPRT_TRACKED; session_count_new(sess); strm = stream_new(sess, t, &cli_conn->obj_type); if (!strm) goto out_free_task; strm->target = sess->listener->default_target; strm->req.analysers = sess->listener->analysers; return 1; out_free_task: task_free(t); out_free_sess: p->feconn--; session_free(sess); out_free_conn: cli_conn->flags &= ~CO_FL_XPRT_TRACKED; conn_xprt_close(cli_conn); conn_free(cli_conn); out_close: if (ret < 0 && l->xprt == &raw_sock && p->mode == PR_MODE_HTTP) { /* critical error, no more memory, try to emit a 500 response */ struct chunk *err_msg = &p->errmsg[HTTP_ERR_500]; if (!err_msg->str) err_msg = &http_err_chunks[HTTP_ERR_500]; send(cfd, err_msg->str, err_msg->len, MSG_DONTWAIT|MSG_NOSIGNAL); } if (fdtab[cfd].owner) fd_delete(cfd); else close(cfd); return ret; }
/* * Create a new peer session in assigned state (connect will start automatically) */ static struct stream *peer_session_create(struct peer *peer, struct peer_session *ps) { struct listener *l = LIST_NEXT(&peer->peers->peers_fe->conf.listeners, struct listener *, by_fe); struct proxy *p = (struct proxy *)l->frontend; /* attached frontend */ struct appctx *appctx; struct session *sess; struct stream *s; struct task *t; struct connection *conn; ps->reconnect = tick_add(now_ms, MS_TO_TICKS(5000)); ps->statuscode = PEER_SESS_SC_CONNECTCODE; s = NULL; appctx = appctx_new(&peer_applet); if (!appctx) goto out_close; appctx->st0 = PEER_SESS_ST_CONNECT; appctx->ctx.peers.ptr = (void *)ps; sess = session_new(p, l, &appctx->obj_type); if (!sess) { Alert("out of memory in peer_session_create().\n"); goto out_free_appctx; } if ((t = task_new()) == NULL) { Alert("out of memory in peer_session_create().\n"); goto out_free_sess; } t->nice = l->nice; if ((s = stream_new(sess, t, &appctx->obj_type)) == NULL) { Alert("Failed to initialize stream in peer_session_create().\n"); goto out_free_task; } /* The tasks below are normally what is supposed to be done by * fe->accept(). */ s->flags = SF_ASSIGNED|SF_ADDR_SET; /* applet is waiting for data */ si_applet_cant_get(&s->si[0]); appctx_wakeup(appctx); /* initiate an outgoing connection */ si_set_state(&s->si[1], SI_ST_ASS); /* automatically prepare the stream interface to connect to the * pre-initialized connection in si->conn. */ if (unlikely((conn = conn_new()) == NULL)) goto out_free_strm; conn_prepare(conn, peer->proto, peer->xprt); si_attach_conn(&s->si[1], conn); conn->target = s->target = &s->be->obj_type; memcpy(&conn->addr.to, &peer->addr, sizeof(conn->addr.to)); s->do_log = NULL; s->uniq_id = 0; s->res.flags |= CF_READ_DONTWAIT; l->nbconn++; /* warning! right now, it's up to the handler to decrease this */ p->feconn++;/* beconn will be increased later */ jobs++; if (!(s->sess->listener->options & LI_O_UNLIMITED)) actconn++; totalconn++; ps->appctx = appctx; ps->stream = s; return s; /* Error unrolling */ out_free_strm: LIST_DEL(&s->list); pool_free2(pool2_stream, s); out_free_task: task_free(t); out_free_sess: session_free(sess); out_free_appctx: appctx_free(appctx); out_close: return s; }
static void manager_thread(node *n, endpoint *endpt, void *arg) { int done = 0; while (!done) { message *msg = endpoint_receive(endpt,-1); switch (msg->tag) { case MSG_NEWTASK: { newtask_msg *ntmsg; endpointid epid; array *args = array_new(sizeof(char*),0); char *str; char *start; if (sizeof(newtask_msg) > msg->size) fatal("NEWTASK: invalid message size"); ntmsg = (newtask_msg*)msg->data; if (sizeof(newtask_msg)+ntmsg->bcsize > msg->size) fatal("NEWTASK: invalid bytecode size"); str = ((char*)msg->data)+sizeof(newtask_msg)+ntmsg->bcsize; start = str; while (str < ((char*)msg->data)+msg->size) { if ('\0' == *str) { array_append(args,&start,sizeof(char*)); start = str+1; } str++; } assert(array_count(args) == ntmsg->argc); node_log(n,LOG_INFO,"NEWTASK pid = %d, groupsize = %d, bcsize = %d", ntmsg->tid,ntmsg->groupsize,ntmsg->bcsize); task_new(ntmsg->tid,ntmsg->groupsize,ntmsg->bcdata,ntmsg->bcsize,args,n, ntmsg->out_sockid,&epid); endpoint_send(endpt,msg->source,MSG_NEWTASKRESP, &epid.localid,sizeof(int)); array_free(args); break; } case MSG_START_CHORD: { start_chord_msg *m = (start_chord_msg*)msg->data; assert(sizeof(start_chord_msg) == msg->size); start_chord(n,0,m->initial,m->caller,m->stabilize_delay); break; } case MSG_STARTGC: assert(sizeof(startgc_msg) <= msg->size); manager_startgc(n,endpt,(startgc_msg*)msg->data,msg->source); break; case MSG_GET_TASKS: assert(sizeof(get_tasks_msg) == msg->size); manager_get_tasks(n,endpt,(get_tasks_msg*)msg->data); break; case MSG_KILL: node_log(n,LOG_INFO,"Manager received KILL"); done = 1; break; default: fatal("manager: unexpected message %d",msg->tag); break; } message_free(msg); } }
void hx_connect (struct htlc_conn *htlc, const char *serverstr, u_int16_t port, const char *name, u_int16_t icon, const char *login, const char *pass, int secure) { int s; struct SOCKADDR_IN saddr; char abuf[HOSTLEN+1]; #if !defined(__WIN32__) if (serverstr[0] == '|' && serverstr[1]) { int pfds[2]; int r; if (htlc->fd) hx_htlc_close(htlc); r = fd_popen(pfds, serverstr+1); if (r < 0) { hx_printf_prefix(htlc, 0, INFOPREFIX, "fd_popen(%s): %s\n", serverstr+1, strerror(errno)); return; } hx_printf_prefix(htlc, 0, INFOPREFIX, "connecting through pipe %s\n", serverstr+1); htlc->fd = pfds[0]; htlc->wfd = pfds[1]; s = htlc->fd; fd_blocking(s, 0); fd_closeonexec(s, 1); hxd_files[s].ready_write = 0; hxd_files[s].ready_read = htlc_read; hxd_files[s].conn.htlc = htlc; hxd_fd_add(s); hxd_fd_set(s, FDR); if (high_fd < s) high_fd = s; s = htlc->wfd; fd_blocking(s, 0); fd_closeonexec(s, 1); hxd_files[s].ready_read = 0; hxd_files[s].ready_write = htlc_write; hxd_files[s].conn.htlc = htlc; hxd_fd_add(s); hxd_fd_set(s, FDW); if (high_fd < s) high_fd = s; goto is_pipe; } #endif #if defined(CONFIG_UNIXSOCKETS) else if (serverstr[0] == '!' && serverstr[1]) { struct sockaddr_un usaddr; s = socket(AF_UNIX, SOCK_STREAM, 0); if (s < 0) { hx_printf_prefix(htlc, 0, INFOPREFIX, "socket: %s\n", strerror(errno)); return; } usaddr.sun_family = AF_UNIX; snprintf(usaddr.sun_path, sizeof(usaddr.sun_path), "%s", serverstr+1); if (htlc->fd) hx_htlc_close(htlc); if (connect(s, (struct sockaddr *)&usaddr, sizeof(usaddr))) { switch (errno) { case EINPROGRESS: break; default: hx_printf_prefix(htlc, 0, INFOPREFIX, "connect: %s\n", strerror(errno)); socket_close(s); return; } } htlc->usockaddr = usaddr; socket_blocking(s, 0); fd_closeonexec(s, 1); goto is_unix; } #endif s = socket(AFINET, SOCK_STREAM, IPPROTO_TCP); if (s < 0) { hx_printf_prefix(htlc, 0, INFOPREFIX, "socket: %s\n", strerror(errno)); return; } if (s >= hxd_open_max) { hx_printf_prefix(htlc, 0, INFOPREFIX, "%s:%d: %d >= hxd_open_max (%d)", __FILE__, __LINE__, s, hxd_open_max); close(s); return; } socket_blocking(s, 0); fd_closeonexec(s, 1); if (hx_hostname[0]) { #ifdef CONFIG_IPV6 if (!inet_pton(AFINET, hx_hostname, &saddr.SIN_ADDR)) { #else if (!inet_aton(hx_hostname, &saddr.SIN_ADDR)) { #endif struct hostent *he; if ((he = gethostbyname(hx_hostname))) { size_t len = (unsigned int)he->h_length > sizeof(struct IN_ADDR) ? sizeof(struct IN_ADDR) : (unsigned int)he->h_length; memcpy(&saddr.SIN_ADDR, he->h_addr, len); } else { #ifndef HAVE_HSTRERROR hx_printf_prefix(htlc, 0, INFOPREFIX, "DNS lookup for %s failed\n", hx_hostname); #else hx_printf_prefix(htlc, 0, INFOPREFIX, "DNS lookup for %s failed: %s\n", hx_hostname, hstrerror(h_errno)); #endif socket_close(s); return; } } saddr.SIN_PORT = 0; saddr.SIN_FAMILY = AFINET; if (bind(s, (struct sockaddr *)&saddr, sizeof(saddr)) < 0) { inaddr2str(abuf, &saddr); hx_printf_prefix(htlc, 0, INFOPREFIX, "bind %s (%s): %s\n", hx_hostname, abuf, strerror(errno)); socket_close(s); return; } } #ifdef CONFIG_IPV6 if (!inet_pton(AFINET, serverstr, &saddr.SIN_ADDR)) { #else if (!inet_aton(serverstr, &saddr.SIN_ADDR)) { #endif struct hostent *he; if ((he = gethostbyname(serverstr))) { size_t len = (unsigned int)he->h_length > sizeof(struct IN_ADDR) ? sizeof(struct IN_ADDR) : (unsigned int)he->h_length; memcpy(&saddr.SIN_ADDR, he->h_addr, len); } else { #ifndef HAVE_HSTRERROR hx_printf_prefix(htlc, 0, INFOPREFIX, "DNS lookup for %s failed\n", serverstr); #else hx_printf_prefix(htlc, 0, INFOPREFIX, "DNS lookup for %s failed: %s\n", serverstr, hstrerror(h_errno)); #endif socket_close(s); return; } } saddr.SIN_PORT = htons(port); saddr.SIN_FAMILY = AFINET; if (htlc->fd) hx_htlc_close(htlc); if (connect(s, (struct sockaddr *)&saddr, sizeof(saddr))) { #if !defined(__WIN32__) switch (errno) { case EINPROGRESS: break; default: hx_printf_prefix(htlc, 0, INFOPREFIX, "connect: %s\n", strerror(errno)); socket_close(s); return; } #else int wsaerr; wsaerr = WSAGetLastError(); if (wsaerr != WSAEWOULDBLOCK) { hx_printf_prefix(htlc, 0, INFOPREFIX, "connect: WSA error %d\n", wsaerr); socket_close(s); return; } #endif } htlc->sockaddr = saddr; inaddr2str(abuf, &saddr); hx_printf_prefix(htlc, 0, INFOPREFIX, "connecting to %s:%u\n", abuf, ntohs(saddr.SIN_PORT)); is_unix: hxd_files[s].ready_read = htlc_read; hxd_files[s].ready_write = htlc_write_connect; hxd_files[s].conn.htlc = htlc; hxd_fd_add(s); hxd_fd_set(s, FDR|FDW); htlc->fd = s; is_pipe: hx_output.status(); if (name) strlcpy(htlc->name, name, sizeof(htlc->name)); if (icon) htlc->icon = icon; if (login) strlcpy(htlc->login, login, sizeof(htlc->login)); if (pass) strlcpy(htlc->password, pass, sizeof(htlc->password)); else htlc->password[0] = 0; htlc->secure = secure; htlc->flags.in_login = 1; htlc->rcv = hx_rcv_magic; htlc->trans = 1; memset(&htlc->in, 0, sizeof(struct qbuf)); memset(&htlc->out, 0, sizeof(struct qbuf)); qbuf_set(&htlc->in, 0, HTLS_MAGIC_LEN); qbuf_add(&htlc->out, HTLC_MAGIC, HTLC_MAGIC_LEN); } void hx_connect_finish (struct htlc_conn *htlc) { char enclogin[64], encpass[64]; char abuf[HOSTLEN+1]; u_int16_t icon16; u_int16_t llen, plen; int secure; u_int8_t *login, *pass; secure = htlc->secure; login = htlc->login; pass = htlc->password; inaddr2str(abuf, &htlc->sockaddr); #ifdef CONFIG_HOPE if (secure) { #ifdef CONFIG_CIPHER u_int8_t cipheralglist[64]; u_int16_t cipheralglistlen; u_int8_t cipherlen; #endif #ifdef CONFIG_COMPRESS u_int8_t compressalglist[64]; u_int16_t compressalglistlen; u_int8_t compresslen; #endif u_int16_t hc; u_int8_t macalglist[64]; u_int16_t macalglistlen; abuf[0] = 0; task_new(htlc, rcv_task_login, htlc, 0, "login"); strcpy(htlc->macalg, "HMAC-SHA1"); S16HTON(2, macalglist); macalglistlen = 2; macalglist[macalglistlen] = 9; macalglistlen++; memcpy(macalglist+macalglistlen, htlc->macalg, 9); macalglistlen += 9; macalglist[macalglistlen] = 8; macalglistlen++; memcpy(macalglist+macalglistlen, "HMAC-MD5", 8); macalglistlen += 8; hc = 4; #ifdef CONFIG_COMPRESS if (htlc->compressalg[0]) { compresslen = strlen(htlc->compressalg); S16HTON(1, compressalglist); compressalglistlen = 2; compressalglist[compressalglistlen] = compresslen; compressalglistlen++; memcpy(compressalglist+compressalglistlen, htlc->compressalg, compresslen); compressalglistlen += compresslen; hc++; } else compressalglistlen = 0; #endif #ifdef CONFIG_CIPHER if (htlc->cipheralg[0]) { cipherlen = strlen(htlc->cipheralg); S16HTON(1, cipheralglist); cipheralglistlen = 2; cipheralglist[cipheralglistlen] = cipherlen; cipheralglistlen++; memcpy(cipheralglist+cipheralglistlen, htlc->cipheralg, cipherlen); cipheralglistlen += cipherlen; hc++; } else cipheralglistlen = 0; #endif hlwrite(htlc, HTLC_HDR_LOGIN, 0, hc, HTLC_DATA_LOGIN, 1, abuf, HTLC_DATA_PASSWORD, 1, abuf, HTLC_DATA_MAC_ALG, macalglistlen, macalglist, #ifdef CONFIG_CIPHER HTLC_DATA_CIPHER_ALG, cipheralglistlen, cipheralglist, #endif #ifdef CONFIG_COMPRESS HTLC_DATA_COMPRESS_ALG, compressalglistlen, compressalglist, #endif HTLC_DATA_SESSIONKEY, 0, 0); return; } #endif /* HOPE */ task_new(htlc, rcv_task_login, 0, 0, "login"); icon16 = htons(htlc->icon); if (login) { llen = strlen(login); if (llen > 32) llen = 32; hl_encode(enclogin, login, llen); } else llen = 0; htlc->clientversion = g_clientversion; if (htlc->clientversion >= 150) { if (pass) { u_int16_t cv = htons(185); plen = strlen(pass); if (plen > 32) plen = 32; hl_encode(encpass, pass, plen); hlwrite(htlc, HTLC_HDR_LOGIN, 0, 3, HTLC_DATA_LOGIN, llen, enclogin, HTLC_DATA_PASSWORD, plen, encpass, HTLC_DATA_CLIENTVERSION, 2, &cv); } else { u_int16_t cv = htons(185); hlwrite(htlc, HTLC_HDR_LOGIN, 0, 2, HTLC_DATA_LOGIN, llen, enclogin, HTLC_DATA_CLIENTVERSION, 2, &cv); } } else { /* 123 */ if (pass) { plen = strlen(pass); if (plen > 32) plen = 32; hl_encode(encpass, pass, plen); hlwrite(htlc, HTLC_HDR_LOGIN, 0, 4, HTLC_DATA_ICON, 2, &icon16, HTLC_DATA_LOGIN, llen, enclogin, HTLC_DATA_PASSWORD, plen, encpass, HTLC_DATA_NAME, strlen(htlc->name), htlc->name); } else { hlwrite(htlc, HTLC_HDR_LOGIN, 0, 3, HTLC_DATA_ICON, 2, &icon16, HTLC_DATA_LOGIN, llen, enclogin, HTLC_DATA_NAME, strlen(htlc->name), htlc->name); } } memset(htlc->password, 0, sizeof(htlc->password)); }
static void rcv_task_login (struct htlc_conn *htlc, void *secure) { char abuf[HOSTLEN+1]; u_int32_t uid; u_int16_t icon16; #ifdef CONFIG_HOPE u_int16_t hc; u_int8_t *p, *mal = 0; u_int16_t mal_len = 0; u_int16_t sklen = 0, macalglen = 0, secure_login = 0, secure_password = 0; u_int8_t password_mac[20]; u_int8_t login[32]; u_int16_t llen, pmaclen; #ifdef CONFIG_CIPHER u_int8_t *s_cipher_al = 0, *c_cipher_al = 0; u_int16_t s_cipher_al_len = 0, c_cipher_al_len = 0; u_int8_t s_cipheralg[32], c_cipheralg[32]; u_int16_t s_cipheralglen = 0, c_cipheralglen = 0; u_int8_t cipheralglist[64]; u_int16_t cipheralglistlen; #endif #ifdef CONFIG_COMPRESS u_int8_t *s_compress_al = 0, *c_compress_al = 0; u_int16_t s_compress_al_len = 0, c_compress_al_len = 0; u_int8_t s_compressalg[32], c_compressalg[32]; u_int16_t s_compressalglen = 0, c_compressalglen = 0; u_int8_t compressalglist[64]; u_int16_t compressalglistlen; #endif if (secure) { dh_start(htlc) switch (dh_type) { case HTLS_DATA_LOGIN: if (dh_len && dh_len == strlen(htlc->macalg) && !memcmp(htlc->macalg, dh_data, dh_len)) secure_login = 1; break; case HTLS_DATA_PASSWORD: if (dh_len && dh_len == strlen(htlc->macalg) && !memcmp(htlc->macalg, dh_data, dh_len)) secure_password = 1; break; case HTLS_DATA_MAC_ALG: mal_len = dh_len; mal = dh_data; break; #ifdef CONFIG_CIPHER case HTLS_DATA_CIPHER_ALG: s_cipher_al_len = dh_len; s_cipher_al = dh_data; break; case HTLC_DATA_CIPHER_ALG: c_cipher_al_len = dh_len; c_cipher_al = dh_data; break; case HTLS_DATA_CIPHER_MODE: break; case HTLC_DATA_CIPHER_MODE: break; case HTLS_DATA_CIPHER_IVEC: break; case HTLC_DATA_CIPHER_IVEC: break; #endif #if defined(CONFIG_COMPRESS) case HTLS_DATA_COMPRESS_ALG: s_compress_al_len = dh_len; s_compress_al = dh_data; break; case HTLC_DATA_COMPRESS_ALG: c_compress_al_len = dh_len; c_compress_al = dh_data; break; #endif case HTLS_DATA_CHECKSUM_ALG: break; case HTLC_DATA_CHECKSUM_ALG: break; case HTLS_DATA_SESSIONKEY: sklen = dh_len > sizeof(htlc->sessionkey) ? sizeof(htlc->sessionkey) : dh_len; memcpy(htlc->sessionkey, dh_data, sklen); htlc->sklen = sklen; break; } dh_end() if (!mal_len) { no_mal: hx_printf_prefix(htlc, 0, INFOPREFIX, "No macalg from server\n"); hx_htlc_close(htlc); memset(htlc->password, 0, sizeof(htlc->password)); return; } p = list_n(mal, mal_len, 0); if (!p || !*p) goto no_mal; macalglen = *p >= sizeof(htlc->macalg) ? sizeof(htlc->macalg)-1 : *p; memcpy(htlc->macalg, p+1, macalglen); htlc->macalg[macalglen] = 0; if (sklen < 32) { hx_printf_prefix(htlc, 0, INFOPREFIX, "sessionkey length (%u) not big enough\n", sklen); hx_htlc_close(htlc); memset(htlc->password, 0, sizeof(htlc->password)); return; } #ifdef CONFIG_IPV6 if (memcmp(htlc->sessionkey, &htlc->sockaddr.SIN_ADDR.S_ADDR, 16) || *((u_int16_t *)(htlc->sessionkey + 16)) != htlc->sockaddr.SIN_PORT) { #else if (*((u_int32_t *)(htlc->sessionkey)) != htlc->sockaddr.SIN_ADDR.S_ADDR || *((u_int16_t *)(htlc->sessionkey + 4)) != htlc->sockaddr.SIN_PORT) { #endif char fakeabuf[HOSTLEN+1], realabuf[HOSTLEN+1]; struct IN_ADDR fakeinaddr; #ifdef CONFIG_IPV6 memcpy(&fakeinaddr.S_ADDR, htlc->sessionkey, 16); inet_ntop(AFINET, (char *)&fakeinaddr, fakeabuf, sizeof(fakeabuf)); inet_ntop(AFINET, (char *)&htlc->sockaddr.SIN_ADDR, realabuf, sizeof(realabuf)); #else fakeinaddr.S_ADDR = *((u_int32_t *)(htlc->sessionkey)); inet_ntoa_r(fakeinaddr, fakeabuf, sizeof(fakeabuf)); inet_ntoa_r(htlc->sockaddr.SIN_ADDR, realabuf, sizeof(realabuf)); #endif hx_printf_prefix(htlc, 0, INFOPREFIX, "Server gave wrong address: %s:%u != %s:%u\n", fakeabuf, ntohs(*((u_int16_t *)(htlc->sessionkey + 4))), realabuf, ntohs(htlc->sockaddr.SIN_PORT)); /* XXX HACK XXX */ if (htlc->secure == 2) { hx_printf_prefix(htlc, 0, INFOPREFIX, "Possible man-in-the-middle attack! Connecting anyway.\n"); } else { hx_printf_prefix(htlc, 0, INFOPREFIX, "Possible man-in-the-middle attack! Closing connection. Use -f to force connect.\n"); hx_htlc_close(htlc); memset(htlc->password, 0, sizeof(htlc->password)); return; } } if (task_inerror(htlc)) { hx_htlc_close(htlc); memset(htlc->password, 0, sizeof(htlc->password)); return; } task_new(htlc, rcv_task_login, 0, 0, "login"); icon16 = htons(htlc->icon); if (secure_login) { llen = hmac_xxx(login, htlc->login, strlen(htlc->login), htlc->sessionkey, sklen, htlc->macalg); if (!llen) { hx_printf_prefix(htlc, 0, INFOPREFIX, "bad HMAC algorithm %s\n", htlc->macalg); hx_htlc_close(htlc); memset(htlc->password, 0, sizeof(htlc->password)); return; } } else { llen = strlen(htlc->login); hl_encode(login, htlc->login, llen); login[llen] = 0; } pmaclen = hmac_xxx(password_mac, htlc->password, strlen(htlc->password), htlc->sessionkey, sklen, htlc->macalg); if (!pmaclen) { hx_printf_prefix(htlc, 0, INFOPREFIX, "bad HMAC algorithm %s\n", htlc->macalg); hx_htlc_close(htlc); return; } hc = 4; #ifdef CONFIG_COMPRESS if (!htlc->compressalg[0] || !strcmp(htlc->compressalg, "NONE")) { hx_printf_prefix(htlc, 0, INFOPREFIX, "WARNING: this connection is not compressed\n"); compressalglistlen = 0; goto no_compress; } if (!c_compress_al_len || !s_compress_al_len) { no_compress_al: hx_printf_prefix(htlc, 0, INFOPREFIX, "No compress algorithm from server\n"); hx_htlc_close(htlc); return; } p = list_n(s_compress_al, s_compress_al_len, 0); if (!p || !*p) goto no_compress_al; s_compressalglen = *p >= sizeof(s_compressalg) ? sizeof(s_compressalg)-1 : *p; memcpy(s_compressalg, p+1, s_compressalglen); s_compressalg[s_compressalglen] = 0; p = list_n(c_compress_al, c_compress_al_len, 0); if (!p || !*p) goto no_compress_al; c_compressalglen = *p >= sizeof(c_compressalg) ? sizeof(c_compressalg)-1 : *p; memcpy(c_compressalg, p+1, c_compressalglen); c_compressalg[c_compressalglen] = 0; if (!valid_compress(c_compressalg)) { hx_printf_prefix(htlc, 0, INFOPREFIX, "Bad client compress algorithm %s\n", c_compressalg); goto ret_badcompress_a; } else if (!valid_compress(s_compressalg)) { hx_printf_prefix(htlc, 0, INFOPREFIX, "Bad server compress algorithm %s\n", s_compressalg); ret_badcompress_a: compressalglistlen = 0; hx_htlc_close(htlc); return; } else { S16HTON(1, compressalglist); compressalglistlen = 2; compressalglist[compressalglistlen] = s_compressalglen; compressalglistlen++; memcpy(compressalglist+compressalglistlen, s_compressalg, s_compressalglen); compressalglistlen += s_compressalglen; } no_compress: hc++; #endif #ifdef CONFIG_CIPHER if (!htlc->cipheralg[0] || !strcmp(htlc->cipheralg, "NONE")) { hx_printf_prefix(htlc, 0, INFOPREFIX, "WARNING: this connection is not encrypted\n"); cipheralglistlen = 0; goto no_cipher; } if (!c_cipher_al_len || !s_cipher_al_len) { no_cal: hx_printf_prefix(htlc, 0, INFOPREFIX, "No cipher algorithm from server\n"); hx_htlc_close(htlc); return; } p = list_n(s_cipher_al, s_cipher_al_len, 0); if (!p || !*p) goto no_cal; s_cipheralglen = *p >= sizeof(s_cipheralg) ? sizeof(s_cipheralg)-1 : *p; memcpy(s_cipheralg, p+1, s_cipheralglen); s_cipheralg[s_cipheralglen] = 0; p = list_n(c_cipher_al, c_cipher_al_len, 0); if (!p || !*p) goto no_cal; c_cipheralglen = *p >= sizeof(c_cipheralg) ? sizeof(c_cipheralg)-1 : *p; memcpy(c_cipheralg, p+1, c_cipheralglen); c_cipheralg[c_cipheralglen] = 0; if (!valid_cipher(c_cipheralg)) { hx_printf_prefix(htlc, 0, INFOPREFIX, "Bad client cipher algorithm %s\n", c_cipheralg); goto ret_badca; } else if (!valid_cipher(s_cipheralg)) { hx_printf_prefix(htlc, 0, INFOPREFIX, "Bad server cipher algorithm %s\n", s_cipheralg); ret_badca: cipheralglistlen = 0; hx_htlc_close(htlc); return; } else { S16HTON(1, cipheralglist); cipheralglistlen = 2; cipheralglist[cipheralglistlen] = s_cipheralglen; cipheralglistlen++; memcpy(cipheralglist+cipheralglistlen, s_cipheralg, s_cipheralglen); cipheralglistlen += s_cipheralglen; } /* server key first */ pmaclen = hmac_xxx(htlc->cipher_decode_key, htlc->password, strlen(htlc->password), password_mac, pmaclen, htlc->macalg); htlc->cipher_decode_keylen = pmaclen; pmaclen = hmac_xxx(htlc->cipher_encode_key, htlc->password, strlen(htlc->password), htlc->cipher_decode_key, pmaclen, htlc->macalg); htlc->cipher_encode_keylen = pmaclen; no_cipher: hc++; #endif memset(htlc->password, 0, sizeof(htlc->password)); hlwrite(htlc, HTLC_HDR_LOGIN, 0, hc, HTLC_DATA_LOGIN, llen, login, HTLC_DATA_PASSWORD, pmaclen, password_mac, #ifdef CONFIG_CIPHER HTLS_DATA_CIPHER_ALG, cipheralglistlen, cipheralglist, #endif #ifdef CONFIG_COMPRESS HTLS_DATA_COMPRESS_ALG, compressalglistlen, compressalglist, #endif HTLC_DATA_NAME, strlen(htlc->name), htlc->name, HTLC_DATA_ICON, 2, &icon16); #ifdef CONFIG_COMPRESS if (compressalglistlen) { hx_printf_prefix(htlc, 0, INFOPREFIX, "compress: server %s client %s\n", c_compressalg, s_compressalg); if (c_compress_al_len) { htlc->compress_encode_type = COMPRESS_GZIP; compress_encode_init(htlc); } if (s_compress_al_len) { htlc->compress_decode_type = COMPRESS_GZIP; compress_decode_init(htlc); } } #endif #ifdef CONFIG_CIPHER if (cipheralglistlen) { hx_printf_prefix(htlc, 0, INFOPREFIX, "cipher: server %s client %s\n", c_cipheralg, s_cipheralg); if (!strcmp(s_cipheralg, "RC4")) htlc->cipher_decode_type = CIPHER_RC4; else if (!strcmp(s_cipheralg, "BLOWFISH")) htlc->cipher_decode_type = CIPHER_BLOWFISH; else if (!strcmp(s_cipheralg, "IDEA")) htlc->cipher_decode_type = CIPHER_IDEA; if (!strcmp(c_cipheralg, "RC4")) htlc->cipher_encode_type = CIPHER_RC4; else if (!strcmp(c_cipheralg, "BLOWFISH")) htlc->cipher_encode_type = CIPHER_BLOWFISH; else if (!strcmp(c_cipheralg, "IDEA")) htlc->cipher_encode_type = CIPHER_IDEA; cipher_encode_init(htlc); cipher_decode_init(htlc); } #endif } else { #endif /* CONFIG_HOPE */ inaddr2str(abuf, &htlc->sockaddr); hx_printf_prefix(htlc, 0, INFOPREFIX, "%s:%u: login %s\n", abuf, ntohs(htlc->sockaddr.SIN_PORT), task_inerror(htlc) ? "failed?" : "successful"); if (!task_inerror(htlc)) { hx_chat_new(htlc, 0); play_sound(snd_login); dh_start(htlc) switch (dh_type) { case HTLS_DATA_UID: dh_getint(uid); htlc->uid = uid; break; case HTLS_DATA_SERVERVERSION: dh_getint(htlc->serverversion); break; case HTLS_DATA_BANNERID: break; case HTLS_DATA_SERVERNAME: hx_printf_prefix(htlc, 0, INFOPREFIX, "servername: %.*s\n", dh_len, dh_data); break; } dh_end() if (htlc->clientversion >= 150 && htlc->serverversion < 150) { icon16 = htons(htlc->icon); hlwrite(htlc, HTLC_HDR_USER_CHANGE, 0, 2, HTLC_DATA_NAME, strlen(htlc->name), htlc->name, HTLC_DATA_ICON, 2, &icon16); } hx_output.on_connect(htlc); } #ifdef CONFIG_HOPE } #endif }
UINT32 vmatrix_r_new_matrix_skeleton(const UINT32 vmatrixr_md_id, const UINT32 row_num, const UINT32 col_num, MATRIX *matrix) { VMATRIXR_MD *vmatrixr_md; UINT32 blocks_row_num; UINT32 blocks_col_num; UINT32 block_row_idx; UINT32 block_col_idx; UINT32 sub_row_num; UINT32 sub_col_num; //VMATRIX_BLOCK *vmatrix_block; CVECTOR *blocks; TASK_MGR *task_mgr; MOD_NODE *send_mod_node; UINT32 ret; #if ( SWITCH_ON == MATRIX_DEBUG_SWITCH ) if ( VMATRIXR_MD_ID_CHECK_INVALID(vmatrixr_md_id) ) { sys_log(LOGSTDOUT, "error:vmatrix_r_new_matrix_skeleton: matrixr module #0x%lx not started.\n", vmatrixr_md_id); dbg_exit(MD_VMATRIXR, vmatrixr_md_id); } #endif/*MATRIX_DEBUG_SWITCH*/ if( NULL_PTR == matrix ) { sys_log(LOGSTDERR,"error:vmatrix_r_new_matrix_skeleton: matrix is null pointer\n"); return ((UINT32)(-1)); } vmatrixr_md = VMATRIXR_MD_GET(vmatrixr_md_id); send_mod_node = &(vmatrixr_md->local_mod_node); /*set rotated_flag to default 0*/ MATRIX_SET_ROTATED_FLAG(matrix, 0); /*set row num and col num to matrix. not sure if it is suitable or not here*/ MATRIX_SET_ROW_NUM(matrix, row_num); MATRIX_SET_COL_NUM(matrix, col_num); blocks_row_num = MATRIX_GET_ROW_BLOCKS_NUM(matrix); blocks_col_num = MATRIX_GET_COL_BLOCKS_NUM(matrix); /*create matrix header*/ blocks = cvector_new(blocks_row_num * blocks_col_num, MM_VMM_NODE, LOC_VMATRIXR_0006); MATRIX_SET_BLOCKS(matrix, blocks); task_mgr = task_new(vmatrixr_md->mod_mgr, TASK_PRIO_NORMAL, TASK_NEED_RSP_FLAG, TASK_NEED_ALL_RSP); VMATRIX_ROW_COL_BLOCKS_LOOP_NEXT(matrix, block_row_idx, block_col_idx) { VMM_NODE *matrix_block_vmm; //vmm_alloc(vmatrixr_md->vmm_md_id, MD_VMATRIXR, MOD_NODE_MODI(recv_mod_node), MM_VMM_NODE, &vmm_node); alloc_static_mem(MD_VMATRIXR, vmatrixr_md_id, MM_VMM_NODE, &matrix_block_vmm, LOC_VMATRIXR_0007); cvector_push((CVECTOR *)blocks, (void *)matrix_block_vmm); task_inc(task_mgr, &ret, FI_vmatrix_r_alloc_block, ERR_MODULE_ID, matrix_block_vmm);/*alloc matrix block from virtual memory*/ }
void test_normal() { gen g_uni[] = {builtin, devurandom, kalkulator, mersenne, #if N <= (1 << 12) randorg, #endif 0}; test t[] = {chisq, kolsmir, 0}; task* prob = task_new(0, g_uni, t, 0 ); gsl_histogram* h = gsl_histogram_alloc(B); gsl_histogram_set_ranges_uniform(h, 0, 1); gsl_histogram_shift(h, AVG); prob->density = h; gsl_histogram2d* hd = gsl_histogram2d_alloc(B2, B2); gsl_histogram2d_set_ranges_uniform(hd, 0, 1, 0, 1); gsl_histogram2d_shift(hd, AVG2/2); prob->density2d = hd; prob->min = 0; prob->max = 1; task_perform(prob); task_free(prob); gen g_gauss[] = {gauss_bm, gauss_zig, gauss_ratio, 0}; prob = task_new(2, g_gauss, t, 0); prob->max = 3; prob->min = -prob->max; h = gsl_histogram_alloc(B); gsl_histogram_set_ranges_uniform(h, prob->min, prob->max); int j; for (j=0; j<B; ++j) { double min, max; gsl_histogram_get_range(h, j, &min, &max); double x = (max + min)/2; gsl_histogram_accumulate(h, x, N*gsl_ran_ugaussian_pdf(x) / B * (prob->max - prob->min)); } hd = gsl_histogram2d_alloc(B2, B2); gsl_histogram2d_set_ranges_uniform(hd, prob->min, prob->max, prob->min, prob->max); int k; for (j=0; j < B2; ++j) for (k=0; k<B2; ++k) { double min, max; gsl_histogram2d_get_xrange(hd, j, &min, &max); double x = (max + min)/2; gsl_histogram2d_get_yrange(hd, k, &min, &max); double y = (max + min)/2; gsl_histogram2d_accumulate(hd, x, y, gsl_ran_ugaussian_pdf(x) * gsl_ran_ugaussian_pdf(y)); } gsl_histogram2d_scale( hd, N/2/gsl_histogram2d_sum(hd) ); prob->density = h; prob->density2d = hd; task_perform(prob); task_free(prob); }
void test_case_cbgt_delete_group_p(const UINT32 cbgt_md_id, const char *table_name, const UINT32 row_tag) { UINT32 row_idx; UINT32 colf_idx; UINT32 colq_idx; CBYTES table_name_bytes; void *mod_mgr; EC_BOOL continue_flag; ASSERT(mod_mgr = mod_mgr_new(cbgt_md_id, LOAD_BALANCING_OBJ)); mod_mgr_incl(CMPI_LOCAL_TCID, CMPI_LOCAL_COMM, CMPI_LOCAL_RANK, cbgt_md_id, mod_mgr); mod_mgr_print(LOGCONSOLE, mod_mgr); cbytes_mount(&table_name_bytes, strlen(table_name), (UINT8 *)table_name); continue_flag = EC_TRUE; for(row_idx = 0; row_idx < CBGT_TEST_ROW_NUM && EC_TRUE == continue_flag; row_idx ++) { char *row; CBYTES *row_bytes; ASSERT(row = (char *)safe_malloc(CBGT_STR_MAX_LEN, 0)); snprintf(row, CBGT_STR_MAX_LEN, "row-%08ld-%08ld", row_tag, row_idx); ASSERT(row_bytes = cbytes_new(0)); cbytes_mount(row_bytes , strlen(row) , (UINT8 *)row ); //cvector_push(bytes_vec, (void *)row_bytes); for(colf_idx = 0; colf_idx < CBGT_TEST_COLF_NUM && EC_TRUE == continue_flag; colf_idx ++) { char *colf; CBYTES *colf_bytes; void *task_mgr; void *bytes_vec; EC_BOOL ret[CBGT_TEST_COLQ_NUM]; ASSERT(bytes_vec = cvector_new(0, MM_CBYTES, 0)); ASSERT(colf = (char *)safe_malloc(CBGT_STR_MAX_LEN, 0)); snprintf(colf, CBGT_STR_MAX_LEN, "colf-%ld", colf_idx); ASSERT(colf_bytes = cbytes_new(0)); cbytes_mount(colf_bytes , strlen(colf) , (UINT8 *)colf ); task_mgr = task_new(mod_mgr, TASK_PRIO_NORMAL, TASK_NEED_RSP_FLAG, TASK_NEED_ALL_RSP); for(colq_idx = 0; colq_idx < CBGT_TEST_COLQ_NUM && EC_TRUE == continue_flag; colq_idx ++) { char *colq; CBYTES *colq_bytes; ASSERT(colq = (char *)safe_malloc(CBGT_STR_MAX_LEN, 0)); snprintf(colq, CBGT_STR_MAX_LEN, "colq-%08ld-%08ld-%08ld", row_idx, colf_idx, colq_idx); ASSERT(colq_bytes = cbytes_new(0)); cbytes_mount(colq_bytes , strlen(colq) , (UINT8 *)colq ); cvector_push(bytes_vec, (void *)colq_bytes); ret[ colq_idx ] = EC_FALSE; task_inc(task_mgr, &(ret[ colq_idx ]), FI_cbgt_delete, ERR_MODULE_ID, &table_name_bytes, row_bytes, colf_bytes, colq_bytes); } task_wait(task_mgr, TASK_DEFAULT_LIVE, TASK_NEED_RESCHEDULE_FLAG, NULL_PTR); for(colq_idx = 0; colq_idx < CBGT_TEST_COLQ_NUM; colq_idx ++) { if(EC_TRUE == ret[ colq_idx ]) { sys_log(LOGSTDNULL, "[DEBUG] test_case_cbgt_delete_group_p: [SUCC] delete %s %s:%s:colq-%08ld-%08ld-%08ld\n", table_name, row, colf, row_idx, colf_idx, colq_idx); } else { //continue_flag = EC_FALSE; sys_log(LOGCONSOLE, "[DEBUG] test_case_cbgt_delete_group_p: [FAIL] delete %s %s:%s:colq-%08ld-%08ld-%08ld\n", table_name, row, colf, row_idx, colf_idx, colq_idx); } } cbytes_free(colf_bytes, 0); cvector_clean_with_location(bytes_vec, (CVECTOR_DATA_LOCATION_CLEANER)cbytes_free, 0); cvector_free(bytes_vec, 0); } cbytes_free(row_bytes, 0); if(EC_TRUE == continue_flag) { sys_log(LOGCONSOLE, "[DEBUG] test_case_cbgt_delete_group_p: [SUCC] row tag %ld, row no. %ld\n", row_tag, row_idx); } else { sys_log(LOGCONSOLE, "[DEBUG] test_case_cbgt_delete_group_p: [FAIL] row tag %ld, row no. %ld\n", row_tag, row_idx); } } sys_log(LOGCONSOLE, "[DEBUG] test_case_cbgt_delete_group_p: row tag %ld end\n", row_tag); return; }
EC_BOOL test_case_82_crfs_read(const char *home, const UINT32 crfs_tcid, const UINT32 crfs_rank, const UINT32 crfs_modi, const UINT32 max_test_data_files, UINT32 *counter) { void *mod_mgr; void *task_mgr; UINT32 index; CSTRING *path[CRFS_TEST_READ_MAX_FILES]; CBYTES *cbytes[CRFS_TEST_READ_MAX_FILES];/*read from dn*/ CBYTES *cbytes_des[CRFS_TEST_READ_MAX_FILES];/*benchmark*/ EC_BOOL ret[CRFS_TEST_READ_MAX_FILES]; EC_BOOL continue_flag; for(index = 0; index < CRFS_TEST_READ_MAX_FILES; index ++) { path[ index ] = NULL_PTR; cbytes[ index ] = NULL_PTR; cbytes_des[ index ] = NULL_PTR; ret[ index ] = EC_FALSE; } mod_mgr = mod_mgr_new(CMPI_ERROR_MODI, LOAD_BALANCING_LOOP); mod_mgr_incl(crfs_tcid, CMPI_ANY_COMM, crfs_rank, crfs_modi, mod_mgr); #if 0 sys_log(LOGSTDOUT, "test_case_82_crfs_read: npp mod mgr is\n"); mod_mgr_print(LOGSTDOUT, crfs_get_npp_mod_mgr(crfs_modi)); sys_log(LOGSTDOUT, "test_case_82_crfs_read: dn mod mgr is\n"); mod_mgr_print(LOGSTDOUT, crfs_get_dn_mod_mgr(crfs_modi)); #endif task_mgr = task_new(mod_mgr, TASK_PRIO_NORMAL, TASK_NEED_RSP_FLAG, TASK_NEED_ALL_RSP); for(index = 0; index < CRFS_TEST_READ_MAX_FILES; index ++, (*counter) ++) { path[ index ] = cstring_new(NULL_PTR, 0); cstring_format(path[ index ], "%s/%ld.dat", home, (*counter)); cbytes[ index ] = cbytes_new(0); cbytes_des[ index ] = __test_crfs_fetch_g_cbytes(max_test_data_files, ((*counter) % max_test_data_files)); ret[ index ] = EC_FALSE; task_inc(task_mgr, &(ret[ index ]), FI_crfs_read, ERR_MODULE_ID, path[ index ], cbytes[ index ]); } task_wait(task_mgr, TASK_DEFAULT_LIVE, TASK_NEED_RESCHEDULE_FLAG, NULL_PTR); continue_flag = EC_TRUE; for(index = 0; index < CRFS_TEST_READ_MAX_FILES; index ++) { if(NULL_PTR != cbytes[ index ]) { if(EC_TRUE == cbytes_ncmp(cbytes[ index ], cbytes_des[ index ], 16)) { sys_log(LOGSTDOUT, "[SUCC] path: %s, len = %ld ", (char *)cstring_get_str(path[ index ]), cbytes_len(cbytes[ index ])); sys_print(LOGSTDOUT, "text = %.*s\n", cbytes_len(cbytes[ index ]) > 16 ? 16 : cbytes_len(cbytes[ index ]), /*output up to 16 chars*/ (char *)cbytes_buf(cbytes[ index ])); } else { continue_flag = EC_FALSE; sys_log(LOGCONSOLE, "[FAIL] path: %s, read len = %ld ", (char *)cstring_get_str(path[ index ]), cbytes_len(cbytes[ index ])); sys_print(LOGCONSOLE, "text = %.*s <--> ", cbytes_len(cbytes[ index ]) > 16 ? 16 : cbytes_len(cbytes[ index ]), /*output up to 16 chars*/ (char *)cbytes_buf(cbytes[ index ])); sys_print(LOGCONSOLE, "expect len = %ld ", cbytes_len(cbytes_des[ index ])); sys_print(LOGCONSOLE, "text = %.*s\n", cbytes_len(cbytes_des[ index ]) > 16 ? 16 : cbytes_len(cbytes_des[ index ]), (char *)cbytes_buf(cbytes_des[ index ])); } } if(NULL_PTR != path[ index ]) { cstring_free(path[ index ]); path[ index ] = NULL_PTR; } if(NULL_PTR != cbytes[ index ]) { cbytes_free(cbytes[ index ], 0); cbytes[ index ] = NULL_PTR; } if(NULL_PTR != cbytes_des[ index ]) { cbytes_des[ index ] = NULL_PTR; } } mod_mgr_free(mod_mgr); return (continue_flag); }
EC_BOOL test_case_83_crfs_write(const char *home, const UINT32 crfs_tcid, const UINT32 crfs_rank, const UINT32 crfs_modi, const UINT32 max_test_data_files, UINT32 *counter) { void *mod_mgr; void *task_mgr; UINT32 index; EC_BOOL continue_flag; CSTRING *path[CRFS_TEST_WRITE_MAX_FILES]; EC_BOOL ret[CRFS_TEST_WRITE_MAX_FILES]; for(index = 0; index < CRFS_TEST_WRITE_MAX_FILES; index ++) { path[ index ] = NULL_PTR; ret[ index ] = EC_FALSE; } mod_mgr = mod_mgr_new(CMPI_ERROR_MODI, LOAD_BALANCING_LOOP); mod_mgr_incl(crfs_tcid, CMPI_ANY_COMM, crfs_rank, crfs_modi, mod_mgr); #if 0 sys_log(LOGSTDOUT, "test_case_83_crfs_write: npp mod mgr is\n"); mod_mgr_print(LOGSTDOUT, crfs_get_npp_mod_mgr(crfs_modi)); sys_log(LOGSTDOUT, "test_case_83_crfs_write: dn mod mgr is\n"); mod_mgr_print(LOGSTDOUT, crfs_get_dn_mod_mgr(crfs_modi)); #endif task_mgr = task_new(mod_mgr, TASK_PRIO_NORMAL, TASK_NEED_RSP_FLAG, TASK_NEED_ALL_RSP); for(index = 0; index < CRFS_TEST_WRITE_MAX_FILES; index ++, (*counter) ++) { void *cbytes; path[ index ] = cstring_new(NULL_PTR, 0); cstring_format(path[ index ], "%s/%ld.dat", home, (*counter)); ret[ index ] = EC_FALSE; cbytes = __test_crfs_fetch_g_cbytes(max_test_data_files, ((*counter) % max_test_data_files)); if(NULL_PTR == cbytes) { sys_log(LOGSTDOUT, "error:test_case_83_crfs_write: crfs buff is null where index = %ld, max_test_data_files = %ld\n", index, max_test_data_files); cstring_free(path[ index ]); path[ index ] = NULL_PTR; break; } task_inc(task_mgr, &(ret[ index ]), FI_crfs_write, ERR_MODULE_ID, path[ index ], cbytes); } task_wait(task_mgr, TASK_DEFAULT_LIVE, TASK_NOT_NEED_RESCHEDULE_FLAG, NULL_PTR); continue_flag = EC_TRUE; for(index = 0; index < CRFS_TEST_WRITE_MAX_FILES; index ++) { if(EC_FALSE == ret[ index ] && NULL_PTR != path[ index ]) { continue_flag = EC_FALSE; sys_log(LOGCONSOLE, "test_case_83_crfs_write: [FAIL] %s\n", (char *)cstring_get_str(path[ index ])); } if(NULL_PTR != path[ index ]) { cstring_free(path[ index ]); path[ index ] = NULL_PTR; } } mod_mgr_free(mod_mgr); return (continue_flag); }
/* * Create a new peer session in assigned state (connect will start automatically) */ static struct session *peer_session_create(struct peer *peer, struct peer_session *ps) { struct listener *l = ((struct proxy *)peer->peers->peers_fe)->listen; struct proxy *p = (struct proxy *)l->frontend; /* attached frontend */ struct session *s; struct http_txn *txn; struct task *t; if ((s = pool_alloc2(pool2_session)) == NULL) { /* disable this proxy for a while */ Alert("out of memory in event_accept().\n"); goto out_close; } LIST_ADDQ(&sessions, &s->list); LIST_INIT(&s->back_refs); s->flags = SN_ASSIGNED|SN_ADDR_SET; s->term_trace = 0; /* if this session comes from a known monitoring system, we want to ignore * it as soon as possible, which means closing it immediately for TCP. */ if ((t = task_new()) == NULL) { /* disable this proxy for a while */ Alert("out of memory in event_accept().\n"); goto out_free_session; } ps->reconnect = tick_add(now_ms, MS_TO_TICKS(5000)); ps->statuscode = PEER_SESSION_CONNECTCODE; t->process = l->handler; t->context = s; t->nice = l->nice; memcpy(&s->si[1].conn.addr.to, &peer->addr, sizeof(s->si[1].conn.addr.to)); s->task = t; s->listener = l; /* Note: initially, the session's backend points to the frontend. * This changes later when switching rules are executed or * when the default backend is assigned. */ s->be = s->fe = p; s->req = s->rep = NULL; /* will be allocated later */ s->si[0].conn.t.sock.fd = -1; s->si[0].conn.flags = CO_FL_NONE; s->si[0].owner = t; s->si[0].state = s->si[0].prev_state = SI_ST_EST; s->si[0].err_type = SI_ET_NONE; s->si[0].err_loc = NULL; s->si[0].release = NULL; s->si[0].send_proxy_ofs = 0; set_target_client(&s->si[0].conn.target, l); s->si[0].exp = TICK_ETERNITY; s->si[0].flags = SI_FL_NONE; if (s->fe->options2 & PR_O2_INDEPSTR) s->si[0].flags |= SI_FL_INDEP_STR; stream_int_register_handler(&s->si[0], &peer_applet); s->si[0].applet.st0 = PEER_SESSION_CONNECT; s->si[0].conn.data_ctx = (void *)ps; s->si[1].conn.t.sock.fd = -1; /* just to help with debugging */ s->si[1].conn.flags = CO_FL_NONE; s->si[1].owner = t; s->si[1].state = s->si[1].prev_state = SI_ST_ASS; s->si[1].conn_retries = p->conn_retries; s->si[1].err_type = SI_ET_NONE; s->si[1].err_loc = NULL; s->si[1].release = NULL; s->si[1].send_proxy_ofs = 0; set_target_proxy(&s->si[1].conn.target, s->be); si_prepare_conn(&s->si[1], peer->proto, peer->data); s->si[1].exp = TICK_ETERNITY; s->si[1].flags = SI_FL_NONE; if (s->be->options2 & PR_O2_INDEPSTR) s->si[1].flags |= SI_FL_INDEP_STR; session_init_srv_conn(s); set_target_proxy(&s->target, s->be); s->pend_pos = NULL; /* init store persistence */ s->store_count = 0; s->stkctr1_entry = NULL; s->stkctr2_entry = NULL; /* FIXME: the logs are horribly complicated now, because they are * defined in <p>, <p>, and later <be> and <be>. */ s->logs.logwait = 0; s->do_log = NULL; /* default error reporting function, may be changed by analysers */ s->srv_error = default_srv_error; s->uniq_id = 0; s->unique_id = NULL; txn = &s->txn; /* Those variables will be checked and freed if non-NULL in * session.c:session_free(). It is important that they are * properly initialized. */ txn->sessid = NULL; txn->srv_cookie = NULL; txn->cli_cookie = NULL; txn->uri = NULL; txn->req.cap = NULL; txn->rsp.cap = NULL; txn->hdr_idx.v = NULL; txn->hdr_idx.size = txn->hdr_idx.used = 0; if ((s->req = pool_alloc2(pool2_channel)) == NULL) goto out_fail_req; /* no memory */ s->req->buf.size = global.tune.bufsize; channel_init(s->req); s->req->prod = &s->si[0]; s->req->cons = &s->si[1]; s->si[0].ib = s->si[1].ob = s->req; s->req->flags |= CF_READ_ATTACHED; /* the producer is already connected */ /* activate default analysers enabled for this listener */ s->req->analysers = l->analysers; /* note: this should not happen anymore since there's always at least the switching rules */ if (!s->req->analysers) { channel_auto_connect(s->req);/* don't wait to establish connection */ channel_auto_close(s->req);/* let the producer forward close requests */ } s->req->rto = s->fe->timeout.client; s->req->wto = s->be->timeout.server; if ((s->rep = pool_alloc2(pool2_channel)) == NULL) goto out_fail_rep; /* no memory */ s->rep->buf.size = global.tune.bufsize; channel_init(s->rep); s->rep->prod = &s->si[1]; s->rep->cons = &s->si[0]; s->si[0].ob = s->si[1].ib = s->rep; s->rep->rto = s->be->timeout.server; s->rep->wto = s->fe->timeout.client; s->req->rex = TICK_ETERNITY; s->req->wex = TICK_ETERNITY; s->req->analyse_exp = TICK_ETERNITY; s->rep->rex = TICK_ETERNITY; s->rep->wex = TICK_ETERNITY; s->rep->analyse_exp = TICK_ETERNITY; t->expire = TICK_ETERNITY; s->rep->flags |= CF_READ_DONTWAIT; /* it is important not to call the wakeup function directly but to * pass through task_wakeup(), because this one knows how to apply * priorities to tasks. */ task_wakeup(t, TASK_WOKEN_INIT); l->nbconn++; /* warning! right now, it's up to the handler to decrease this */ p->feconn++;/* beconn will be increased later */ jobs++; if (!(s->listener->options & LI_O_UNLIMITED)) actconn++; totalconn++; return s; /* Error unrolling */ out_fail_rep: pool_free2(pool2_channel, s->req); out_fail_req: task_free(t); out_free_session: LIST_DEL(&s->list); pool_free2(pool2_session, s); out_close: return s; }
/*check replica files*/ EC_BOOL test_case_85_cdfs_check_file_content(const char *home, const UINT32 cdfs_md_id, const UINT32 max_test_data_files, UINT32 *counter) { void *cdfsnpp_mod_mgr; void *task_mgr; UINT32 index; CSTRING *path[CDFS_TEST_READ_MAX_FILES]; CSTRING *file_content_cstr[CDFS_TEST_READ_MAX_FILES]; EC_BOOL ret[CDFS_TEST_READ_MAX_FILES]; EC_BOOL continue_flag; for(index = 0; index < CDFS_TEST_READ_MAX_FILES; index ++) { path[ index ] = NULL_PTR; file_content_cstr[ index ] = NULL_PTR; ret[ index ] = EC_FALSE; } cdfsnpp_mod_mgr = cdfs_get_npp_mod_mgr(cdfs_md_id); dbg_log(SEC_0137_DEMO, 5)(LOGSTDOUT, "test_case_85_cdfs_check_file_content: cdfsnpp mod mgr is\n"); mod_mgr_print(LOGSTDOUT, cdfsnpp_mod_mgr); task_mgr = task_new(cdfsnpp_mod_mgr, TASK_PRIO_NORMAL, TASK_NEED_RSP_FLAG, TASK_NEED_ALL_RSP); for(index = 0; index < CDFS_TEST_READ_MAX_FILES; index ++, (*counter) ++) { CBYTES *cbytes_des; cbytes_des = fetch_g_cbytes(cdfs_md_id, max_test_data_files, ((*counter) % max_test_data_files)); path[ index ] = cstring_new(NULL_PTR, 0); cstring_format(path[ index ], "%s/%ld.dat", home, (*counter)); file_content_cstr[ index ] = cstring_new(NULL_PTR, 0); cstring_append_chars(file_content_cstr[ index ], 16, cbytes_buf(cbytes_des)); ret[ index ] = EC_FALSE; task_inc(task_mgr, &(ret[ index ]), FI_cdfs_check_replica_files_content, ERR_MODULE_ID, path[ index ], cbytes_len(cbytes_des), file_content_cstr[ index ]); } task_wait(task_mgr, TASK_DEFAULT_LIVE, TASK_NEED_RESCHEDULE_FLAG, NULL_PTR); continue_flag = EC_TRUE; for(index = 0; index < CDFS_TEST_READ_MAX_FILES; index ++) { if(EC_TRUE == ret[ index ]) { dbg_log(SEC_0137_DEMO, 5)(LOGSTDOUT, "[SUCC] path: %s\n", (char *)cstring_get_str(path[ index ])); } else { continue_flag = EC_FALSE; dbg_log(SEC_0137_DEMO, 0)(LOGCONSOLE, "[FAIL] path: %s\n", (char *)cstring_get_str(path[ index ])); } if(NULL_PTR != path[ index ]) { cstring_free(path[ index ]); path[ index ] = NULL_PTR; } if(NULL_PTR != path[ index ]) { cstring_free(path[ index ]); path[ index ] = NULL_PTR; } if(NULL_PTR != file_content_cstr[ index ]) { cstring_free(file_content_cstr[ index ]); file_content_cstr[ index ] = NULL_PTR; } } return (continue_flag); }