void test_session_tcp6(void) { lagopus_result_t ret; char cbuf[256] = {0}; char sbuf[256] = {0}; lagopus_session_t sesc, sess, sesa; struct addrunion dst, src; ret = session_create(SESSION_TCP6|SESSION_PASSIVE, &sess); TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, ret); addrunion_ipv6_set(&src, "::0"); ret = session_bind(sess, &src, 10023); TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, ret); ret = session_create(SESSION_TCP6|SESSION_ACTIVE, &sesc); TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, ret); addrunion_ipv6_set(&dst, "::1"); ret = session_connect(sesc, &dst, 10023, NULL, 0); if (ret == 0 || errno == EINPROGRESS) { TEST_ASSERT(true); } else { TEST_ASSERT(false); } ret = session_accept(sess, &sesa); TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, ret); TEST_ASSERT_NOT_NULL(sesa); TEST_ASSERT_TRUE(session_is_alive(sess)); TEST_ASSERT_TRUE(session_is_alive(sesc)); TEST_ASSERT_TRUE(session_is_alive(sesa)); snprintf(cbuf, sizeof(cbuf), "hogehoge\n"); ret = session_write(sesc, cbuf, strlen(cbuf)); TEST_ASSERT_EQUAL(ret, strlen(cbuf)); ret = session_read(sesa, sbuf, sizeof(sbuf)); TEST_ASSERT_EQUAL(ret, strlen(sbuf)); ret = session_write(sesa, sbuf, strlen(sbuf)); TEST_ASSERT_EQUAL(ret, strlen(sbuf)); ret = session_read(sesc, cbuf, sizeof(cbuf)); TEST_ASSERT_EQUAL(ret, strlen(cbuf)); session_destroy(sesc); session_destroy(sesa); session_destroy(sess); }
void test_session_create_and_fail(void) { lagopus_result_t ret; lagopus_session_t ses; ret = session_create(SESSION_ACTIVE|SESSION_TLS, &ses); TEST_ASSERT_EQUAL(LAGOPUS_RESULT_INVALID_ARGS, ret); ret = session_create(SESSION_TCP|SESSION_TLS, &ses); TEST_ASSERT_EQUAL(LAGOPUS_RESULT_INVALID_ARGS, ret); ret = session_create(SESSION_TLS|SESSION_PASSIVE, &ses); TEST_ASSERT_EQUAL(LAGOPUS_RESULT_INVALID_ARGS, ret); ret = session_create(SESSION_TCP|SESSION_ACTIVE, NULL); TEST_ASSERT_EQUAL(LAGOPUS_RESULT_INVALID_ARGS, ret); }
lagopus_result_t session_accept(lagopus_session_t s1, lagopus_session_t *s2) { int sock; struct sockaddr_storage ss = {0,0,{0}}; socklen_t ss_len = sizeof(ss); session_type_t t; lagopus_result_t ret; sock = accept(s1->sock, (struct sockaddr *) &ss, &ss_len); if (sock < 0) { lagopus_msg_warning("accept error.\n"); return LAGOPUS_RESULT_POSIX_API_ERROR; } t = ((s1->session_type & (unsigned int) ~(SESSION_PASSIVE|SESSION_ACTIVE)) | SESSION_ACCEPTED); ret = session_create(t, s2); if (*s2 == NULL) { close(sock); return ret; } (*s2)->sock = sock; if (s1->accept != NULL) { return s1->accept(s1, s2); } return LAGOPUS_RESULT_OK; }
static zx_status_t new_vc_cb(port_handler_t* ph, zx_signals_t signals, uint32_t evt) { zx_handle_t h; uint32_t dcount, hcount; if (zx_channel_read(ph->handle, 0, NULL, &h, 0, 1, &dcount, &hcount) < 0) { return ZX_OK; } if (hcount != 1) { return ZX_OK; } vc_t* vc; int fd; if (session_create(&vc, &fd, true, false) < 0) { zx_handle_close(h); return ZX_OK; } zx_handle_t handles[FDIO_MAX_HANDLES]; uint32_t types[FDIO_MAX_HANDLES]; zx_status_t r = fdio_transfer_fd(fd, FDIO_FLAG_USE_FOR_STDIO | 0, handles, types); if (zx_channel_write(h, 0, types, static_cast<uint32_t>(r * sizeof(uint32_t)), handles, r) != ZX_OK) { session_destroy(vc); } else { port_wait(&port, &vc->fh.ph); } zx_handle_close(h); return ZX_OK; }
inline NSAPIEnvironment::NSAPIEnvironment(const VirtualServer* vs, const char* uri) { // Break the thread's association with any HttpRequest. The existing // HttpRequest may refer to a different VS and will be using a different // Session (and therefore MALLOC pool). hrq = HttpRequest::CurrentRequest(); if (hrq) HttpRequest::SetCurrentRequest(NULL); else conf_get_thread_globals(threadHrq, threadVS); // Remember the caller's MALLOC pool if (keyPool == -1) keyPool = getThreadMallocKey(); poolCaller = (pool_handle_t*)systhread_getdata(keyPool); // Ensure session is allocated from the PERM_* pool so we can free it // correctly later if (poolCaller) systhread_setdata(keyPool, NULL); // Create a dummy Session. session_create() will create a pool for us. memset(&address, 0, sizeof(address)); address.sin_family = AF_INET; sn = session_create(PR_NewSink(), &address); // Create a dummy Request rq = request_restart_internal((char*)uri, NULL); // Get the VS's objset objset = vs ? vs->getObjset() : NULL; // Setup the thread-specific "globals" for this vs conf_set_thread_vs_globals(vs); }
struct session_entry *create_session_entry(int remote_id_4, int local_id_4, int local_id_6, int remote_id_6, struct bib_entry* bib, u_int8_t l4protocol, unsigned int dying_time) { struct ipv4_pair pair_4 = { .remote = addr4[remote_id_4], .local = addr4[local_id_4], }; struct ipv6_pair pair_6 = { .local = addr6[local_id_6], .remote = addr6[remote_id_6], }; struct session_entry* entry = session_create(&pair_4, &pair_6, l4protocol); if (!entry) return NULL; entry->dying_time = dying_time; if (bib) { entry->bib = bib; list_add(&entry->entries_from_bib, &bib->sessions); } return entry; }
static int create_session_handle(AMQP_CONNECTION_INSTANCE* instance) { int result; // Codes_SRS_IOTHUBTRANSPORT_AMQP_CONNECTION_09_024: [`instance->session_handle` shall be created using session_create(), passing `instance->connection_handle`] if ((instance->session_handle = session_create(instance->connection_handle, NULL, NULL)) == NULL) { // Codes_SRS_IOTHUBTRANSPORT_AMQP_CONNECTION_09_025: [If session_create() fails, amqp_connection_create() shall fail and return NULL] result = __FAILURE__; LogError("Failed creating the AMQP connection (connection_create2 failed)"); } else { // Codes_SRS_IOTHUBTRANSPORT_AMQP_CONNECTION_09_026: [The `instance->session_handle` incoming window size shall be set as UINT_MAX using session_set_incoming_window()] if (session_set_incoming_window(instance->session_handle, (uint32_t)DEFAULT_INCOMING_WINDOW_SIZE) != 0) { LogError("Failed to set the AMQP session incoming window size."); } // Codes_SRS_IOTHUBTRANSPORT_AMQP_CONNECTION_09_027: [The `instance->session_handle` outgoing window size shall be set as 100 using session_set_outgoing_window()] if (session_set_outgoing_window(instance->session_handle, DEFAULT_OUTGOING_WINDOW_SIZE) != 0) { LogError("Failed to set the AMQP session outgoing window size."); } result = RESULT_OK; } return result; }
/** * Acquire existing session from sotrage or create new one. * All session MUST be requested through this function. * @param[in] ip IPv4 address of client. * @param[in] existing_only Do only existing sssion search. * @return New client. */ struct zsession *session_acquire(uint32_t ip, bool existing_only) { struct zsession *sess = NULL; size_t sidx = STORAGE_IDX(ip); // search for existing session pthread_rwlock_rdlock(&zinst()->sessions_lock[sidx]); HASH_FIND(hh, zinst()->sessions[sidx], &ip, sizeof(ip), sess); if (NULL != sess) { __atomic_add_fetch(&sess->refcnt, 1, __ATOMIC_RELAXED); } pthread_rwlock_unlock(&zinst()->sessions_lock[sidx]); // or create new session if (!existing_only && NULL == sess) { pthread_rwlock_wrlock(&zinst()->sessions_lock[sidx]); HASH_FIND(hh, zinst()->sessions[sidx], &ip, sizeof(ip), sess); if (NULL != sess) { __atomic_add_fetch(&sess->refcnt, 1, __ATOMIC_RELAXED); } else { sess = session_create(); sess->ip = ip; __atomic_store_n(&sess->last_activity, ztime(false), __ATOMIC_RELAXED); __atomic_add_fetch(&sess->refcnt, 1, __ATOMIC_RELAXED); // sessions storage reference HASH_ADD(hh, zinst()->sessions[sidx], ip, sizeof(ip), sess); } pthread_rwlock_unlock(&zinst()->sessions_lock[sidx]); } return sess; }
static void read_confirm(struct rcontext* rcontext, const struct proto* proto) { char buf[1500]; ssize_t olength = 0; struct cipher_context *cipher; olength = xdecrypt(rcontext->config, rcontext->config->keyX, proto->rid.value, proto->rid.length, buf); if (olength < 0) { return; } cipher = verify_challenge(rcontext->config, &rcontext->from, &rcontext->endpoint->local, rcontext->session ? rcontext->session->rkey : 0, proto->rid.value, proto->rid.length); if (cipher == 0) { fprintf(stderr, "!! verify_challenge failed\n"); return; } /* update session*/ if (rcontext->rendpoint == 0) { rcontext->rendpoint = rendpoint_update(rcontext->config, &rcontext->from, 0); } if (rcontext->session == 0) { fprintf(stderr, "Confirm accepted. Creating new session\n"); rcontext->session = session_create(rcontext->config, rcontext->endpoint, rcontext->rendpoint); } else { fprintf(stderr, "confirm accepted\n"); } if (rcontext->session->rkey) { cipher_context_free(rcontext->session->rkey); } rcontext->session->rkey = cipher_context_create(rcontext->config->cipher, buf); write_accept(rcontext); }
session_t *session_create_exec(select_group_t *group, char *name, char *process) { session_t *session = session_create(name); session->driver = driver_create(DRIVER_TYPE_EXEC, driver_exec_create(group, process)); return session; }
session_t *session_create_console(select_group_t *group, char *name) { session_t *session = session_create(name); session->driver = driver_create(DRIVER_TYPE_CONSOLE, driver_console_create(group)); return session; }
void test_session_create_and_close(void) { lagopus_result_t ret; lagopus_session_t ses; ret = session_create(SESSION_TCP|SESSION_ACTIVE, &ses); TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, ret); session_destroy(ses); }
session_t *session_create_ping(select_group_t *group, char *name) { session_t *session = session_create(name); session->driver = driver_create(DRIVER_TYPE_PING, driver_ping_create(group)); session->is_ping = TRUE; return session; }
session_t *session_create_command(select_group_t *group, char *name) { session_t *session = session_create(name); session->driver = driver_create(DRIVER_TYPE_COMMAND, driver_command_create(group)); session->is_command = TRUE; return session; }
int main(int argc, char **argv) { /* * Standard command-line parsing. */ HASH_T *options = parse_cmdline(argc, argv, arg_opts); if(options == NULL || hash_get(options, "help") != NULL) { show_usage(argc, argv, arg_opts); return EXIT_FAILURE; } read_fortunes(hash_get(options, "fortune_file")); /* * Seed the random number generator. */ struct timeb t; ftime(&t); srandom((t.time * 1000 + t.millitm)); SESSION_T *session = NULL; char *url = hash_get(options, "url"); const char *principal = hash_get(options, "principal"); CREDENTIALS_T *credentials = NULL; const char *password = hash_get(options, "credentials"); if(password != NULL) { credentials = credentials_create_password(password); } char *topic = hash_get(options, "topic"); /* * A SESSION_LISTENER_T holds callbacks to inform the client * about changes to the state. Used here for informational * purposes only. */ SESSION_LISTENER_T session_listener = { 0 }; session_listener.on_state_changed = &on_session_state_changed; /* * Create a session with Diffusion. */ DIFFUSION_ERROR_T error = { 0 }; session = session_create(url, principal, credentials, &session_listener, NULL, &error); if(session == NULL) { fprintf(stderr, "TEST: Failed to create session\n"); fprintf(stderr, "ERR : %s\n", error.message); return EXIT_FAILURE; } /* * Add the "fortune" topic. */ TOPIC_DETAILS_T *details = create_topic_details_stateless(); add_topic(session, (ADD_TOPIC_PARAMS_T) { .topic_path = "fortune", .details = details });
void ast_ari_websocket_events_event_websocket_established(struct ast_ari_websocket_session *ws_session, struct ast_variable *headers, struct ast_ari_events_event_websocket_args *args) { RAII_VAR(struct event_session *, session, NULL, session_cleanup); struct ast_json *msg; int res; size_t i; int (* register_handler)(const char *, stasis_app_cb handler, void *data); ast_debug(3, "/events WebSocket connection\n"); session = session_create(ws_session); if (!session) { ast_ari_websocket_session_write(ws_session, ast_ari_oom_json()); return; } if (args->subscribe_all) { register_handler = &stasis_app_register_all; } else { register_handler = &stasis_app_register; } res = 0; for (i = 0; i < args->app_count; ++i) { if (ast_strlen_zero(args->app[i])) { continue; } res |= session_register_app(session, args->app[i], register_handler); } if (ao2_container_count(session->websocket_apps) == 0) { RAII_VAR(struct ast_json *, msg, NULL, ast_json_unref); msg = ast_json_pack("{s: s, s: [s]}", "type", "MissingParams", "params", "app"); if (!msg) { msg = ast_json_ref(ast_ari_oom_json()); } ast_ari_websocket_session_write(session->ws_session, msg); return; } if (res != 0) { ast_ari_websocket_session_write(ws_session, ast_ari_oom_json()); return; } /* We don't process any input, but we'll consume it waiting for EOF */ while ((msg = ast_ari_websocket_session_read(ws_session))) { ast_json_unref(msg); } }
int main(int argc, char* argv[]) { if (argc != 2) { fprintf(stderr, "usage: ./simple_client torrent-file\n"); return 1; } int ret = 0; void* ses = session_create(SES_LISTENPORT, 6881, SES_LISTENPORT_END, 6889, SES_ALERT_MASK, ~(cat_progress | cat_port_mapping | cat_debug | cat_performance_warning | cat_peer), TAG_END); void *t = session_add_torrent(ses, TOR_FILENAME, argv[1], TOR_SAVE_PATH, "./", TAG_END); if (t == 0) { fprintf(stderr, "Failed to add torrent\n"); ret = 1; goto exit; } struct torrent_status st; printf("press ctrl-C to stop\n"); signal(SIGINT, &stop); signal(SIGABRT, &stop); signal(SIGQUIT, &stop); while (quit == 0) { char const* message = ""; char const* state[] = { "queued", "checking", "downloading metadata", "downloading", "finished", "seeding", "allocating", "checking_resume_data" }; if (torrent_get_status(t, &st, sizeof(st)) < 0) break; printf("\r%3.f%% %d kB (%5.f kB/s) up: %d kB (%5.f kB/s) peers: %d '%s' %s ", (double) st.progress * 100., (int) (st.total_payload_download / 1000), (double) st.download_payload_rate / 1000., (int) (st.total_payload_upload / 1000), (double) st.upload_payload_rate / 1000., st.num_peers, state[st.state], message); if (strlen(st.error) > 0) { fprintf(stderr, "\nERROR: %s\n", st.error); break; } fflush(stdout); usleep(1000000); } printf("\nclosing\n"); exit: session_close(ses); return ret; }
static void login_finish(struct connection *conn) { switch (conn->session_type) { case SESSION_NORMAL: if (!conn->session) session_create(conn); conn->sid = conn->session->sid; break; case SESSION_DISCOVERY: /* set a dummy tsih value */ conn->sid.id.tsih = 1; break; } }
static struct session_entry *create_session_entry(int remote_id_4, int local_id_4, int local_id_6, int remote_id_6, l4_protocol l4_proto) { struct session_entry* entry = session_create(&addr6[remote_id_6], &addr6[local_id_6], &addr4[local_id_4], &addr4[remote_id_4], l4_proto, NULL); if (!entry) return NULL; log_debug(SESSION_PRINT_KEY, PRINT_SESSION(entry)); return entry; }
/** * Assumes that "tuple" and "bib"'s session doesn't exist, and creates it. Returns the resulting * entry in "session". * Assumes that "tuple" represents a IPv6 packet. */ static int create_session_ipv6(struct tuple *tuple6, struct bib_entry *bib, struct session_entry **session, enum session_timer_type timer_type, enum tcp_state state) { struct ipv6_prefix prefix; struct in_addr ipv4_dst; struct ipv4_transport_addr addr4; int error; /* Translate address from IPv6 to IPv4 */ error = pool6_get(&tuple6->dst.addr6.l3, &prefix); if (error) { log_debug("Errcode %d while obtaining %pI6c's prefix.", error, &tuple6->dst.addr6.l3); return error; } error = addr_6to4(&tuple6->dst.addr6.l3, &prefix, &ipv4_dst); if (error) { log_debug("Error code %d while translating the packet's address.", error); return error; } /* * Create the session entry. * * Fortunately, ICMP errors cannot reach this code because of the requirements in the header * of section 3.5, so we can use the tuple as shortcuts for the packet's fields. */ addr4.l3 = ipv4_dst; addr4.l4 = (tuple6->l4_proto != L4PROTO_ICMP) ? tuple6->dst.addr6.l4 : bib->ipv4.l4; *session = session_create(&tuple6->src.addr6, &tuple6->dst.addr6, &bib->ipv4, &addr4, tuple6->l4_proto, bib); if (!(*session)) { log_debug("Failed to allocate a session entry."); return -ENOMEM; } (*session)->state = state; apply_policies(); /* Add it to the table. */ error = sessiondb_add(*session, timer_type); if (error) { session_return(*session); log_debug("Error code %d while adding the session to the DB.", error); return error; } return 0; }
lagopus_result_t session_pair(session_type_t t, lagopus_session_t session[2]) { int ret0, sock[2]; lagopus_result_t ret; if (!(t & (SESSION_UNIX_STREAM|SESSION_UNIX_DGRAM))) { lagopus_msg_warning("illegal session type: 0x%x\n", t); return LAGOPUS_RESULT_INVALID_ARGS; } ret = session_create(t, &session[0]); if (ret != LAGOPUS_RESULT_OK) { lagopus_perror(ret); return ret; } ret = session_create(t, &session[1]); if (ret != LAGOPUS_RESULT_OK) { session_destroy(session[0]); lagopus_perror(ret); return ret; } ret0 = socketpair(session[0]->family, session[0]->type, 0, sock); if (ret0 != 0) { ret = LAGOPUS_RESULT_POSIX_API_ERROR; session_destroy(session[0]); session_destroy(session[1]); return ret; } session[0]->sock = sock[0]; session[1]->sock = sock[1]; return LAGOPUS_RESULT_OK; }
void session_initialize(sessions_t *sessions, char *session_name, uint32_t seq) { if(!session_get(sessions, session_name)) { session_t *session; fprintf(stderr, "Creating new session %s with sequence number %d\n", session_name, seq); session = session_create(sessions, session_name, seq); /* If we're in exec mode, attach the process. */ /* TODO: This is likely where I'll bind it to a socket. */ if(sessions->exec) { session_attach_process(sessions, session, sessions->exec); } } }
void session_setAttribute(const char *name, const char *value) { DBConnection dbc; char * encoded; session_tryload(); if (session_id == NULL) { session_create(); } Form_remove(session_attrs, name); if (value != NULL) { Form_add(session_attrs, name, value); } encoded = Form_encode(session_attrs); dbc = DBC_open(session_db); DBC_update(dbc, "sessions", "attributes", encoded, "id", session_id); free(encoded); DBC_close(dbc); }
struct channel * s_create_data_channel(void) { uint64_t dpid = 0x01; struct channel *channel; lagopus_session_t session; struct addrunion addr = {0,{{0}}}; addrunion_ipv4_set(&addr, "127.0.0.1"); channel = channel_alloc(&addr, dpid); (void) session_create(SESSION_TCP|SESSION_ACTIVE, &session); session_write_set(session, write_tcp); channel_version_set(channel, 0x04); channel_session_set(channel, session); channel_xid_set(channel, 0x10); return channel; }
static void read_challenge(struct rcontext* rcontext, const struct proto* proto) { struct cipher_context* key2; key2 = verify_challenge(rcontext->config, &rcontext->from, &rcontext->endpoint->local, rcontext->session ? rcontext->session->key1 : 0, proto->rid.value, proto->rid.length); if (key2) { if (rcontext->rendpoint == 0) { rcontext->rendpoint = rendpoint_update(rcontext->config, &rcontext->from, 0); } if (rcontext->session == 0) { fprintf(stderr, "Challenge accepted. Creating new session\n"); rcontext->session = session_create(rcontext->config, rcontext->endpoint, rcontext->rendpoint); } rcontext->session->key2 = key2; write_confirm(rcontext, proto->id.value, proto->id.length); } else { fprintf(stderr, "Challenge verify failed\n"); } }
Session *session_get_by_jid(const char *jid,Stream *stream,int delay_login){ Session *s; User *u; char *njid; GList *it; g_assert(sessions_jid!=NULL); debug(L_("Looking up session for '%s'"),jid); njid=jid_normalized(jid,0); if (njid==NULL){ g_message(L_("Bad JID: '%s'"),jid); return NULL; } debug(L_("Using '%s' as key"),njid); s=(Session *)g_hash_table_lookup(sessions_jid,(gpointer)njid); g_free(njid); if (s) return s; debug(L_("Session not found")); if (!stream) return NULL; u=user_get_by_jid(jid); if (!u) return NULL; debug(L_("User loaded, processing his subscriptions.")); for(it=g_list_first(u->contacts);it;it=g_list_next(it)){ Contact *c; char *c_jid; c=(Contact *)it->data; if (c->subscribe == SUB_UNDEFINED) { c_jid=jid_build(c->uin); presence_send_subscribe(stream,c_jid,u->jid); g_free(c_jid); } else if (c->subscribe == SUB_FROM || c->subscribe == SUB_BOTH){ c_jid=jid_build(c->uin); presence_send_probe(stream,c_jid,u->jid); g_free(c_jid); } } debug(L_("Creating new session")); return session_create(u,jid,NULL,NULL,stream,delay_login); }
static int create_session_ipv4(struct tuple *tuple4, struct bib_entry *bib, struct session_entry **session) { struct ipv6_prefix prefix; struct in6_addr ipv6_src; struct tuple tuple6; int error; error = pool6_peek(&prefix); if (error) return error; error = addr_4to6(&tuple4->src.addr4.l3, &prefix, &ipv6_src); if (error) { log_debug("Error code %d while translating the packet's address.", error); return error; } /* * Fortunately, ICMP errors cannot reach this code because of the requirements in the header * of section 3.5, so we can use the tuple as shortcuts for the packet's fields. */ if (bib) tuple6.src.addr6 = bib->ipv6; else memset(&tuple6.src.addr6, 0, sizeof(tuple6.src.addr6)); tuple6.dst.addr6.l3 = ipv6_src; tuple6.dst.addr6.l4 = tuple4->src.addr4.l4; *session = session_create(&tuple6.src.addr6, &tuple6.dst.addr6, &tuple4->dst.addr4, &tuple4->src.addr4, tuple4->l4_proto, bib); if (!(*session)) { log_debug("Failed to allocate a session entry."); return -ENOMEM; } apply_policies(); return 0; }
static int app_InitControlFD() { int ret_val = 0; int res; session_t *session = NULL; cfg_t *cfg = app_getCfg(); app_trace(TRACE_INFO, "App. Create control session: %s:%u", ip2str(cfg->local_ip, 0), cfg->local_port); session = session_create(FAX_SESSION_MODE_CTRL, FAX_CTRL_FD_IDX, FAX_SESSION_DIR_IN); if(!session) { app_trace(TRACE_ERR, "App. Control session creating failed"); ret_val = -1; goto _exit; } res = session_initCtrl(session); if(res) { app_trace(TRACE_ERR, "App. Control session init failed (%d)", res); session_destroy(session); ret_val = -2; goto _exit; } cfg->pfds[FAX_CTRL_FD_IDX].fd = session->fds; cfg->pfds[FAX_CTRL_FD_IDX].events = POLLIN; cfg->session[FAX_CTRL_FD_IDX] = session; cfg->session_cnt = 1; app_trace(TRACE_INFO, "App. Control session created: Session %04x fd = %d", session->ses_id, session->fds); _exit: return ret_val; }
static bool inject(unsigned int index, __u32 local4addr, __u16 local4id, __u32 remote4addr, __u16 remote4id) { struct ipv6_transport_addr remote6; struct ipv6_transport_addr local6; struct ipv4_transport_addr local4; struct ipv4_transport_addr remote4; int error; remote6.l3.s6_addr32[0] = cpu_to_be32(0x20010db8u); remote6.l3.s6_addr32[1] = 0; remote6.l3.s6_addr32[2] = 0; remote6.l3.s6_addr32[3] = cpu_to_be32(local4addr); remote6.l4 = local4id; local6.l3.s6_addr32[0] = cpu_to_be32(0x0064ff9bu); local6.l3.s6_addr32[1] = 0; local6.l3.s6_addr32[2] = 0; local6.l3.s6_addr32[3] = cpu_to_be32(0xc0000200u | remote4addr); local6.l4 = remote4id; local4.l3.s_addr = cpu_to_be32(0xcb007100u | local4addr); local4.l4 = local4id; remote4.l3.s_addr = cpu_to_be32(0xc0000200u | remote4addr); remote4.l4 = remote4id; entries[index] = session_create(&remote6, &local6, &local4, &remote4, L4PROTO_UDP, NULL); if (!entries[index]) return false; error = sessiontable_add(&table, entries[index], true); if (error) { log_err("Errcode %d on sessiontable_add.", error); return false; } return true; }
void test_channel_session_get_set(void) { struct channel *channel; lagopus_session_t session; lagopus_session_t ret_session; channel = s_create_data_channel(); (void) session_create(SESSION_TCP|SESSION_ACTIVE, &session); TEST_ASSERT_NOT_EQUAL_MESSAGE(session, channel_session_get(channel), "session error."); session_destroy(channel_session_get(channel)); /* Call func. */ channel_session_set(channel, session); ret_session = channel_session_get(channel); TEST_ASSERT_EQUAL_MESSAGE(ret_session, session, "session error."); session_destroy(channel_session_get(channel)); free(channel); }