static struct avctp *avctp_get_internal(const bdaddr_t *src, const bdaddr_t *dst) { struct avctp_server *server; struct avctp *session; assert(src != NULL); assert(dst != NULL); server = find_server(servers, src); if (server == NULL) return NULL; session = find_session(server->sessions, dst); if (session) return session; session = g_new0(struct avctp, 1); session->server = server; bacpy(&session->dst, dst); session->state = AVCTP_STATE_DISCONNECTED; server->sessions = g_slist_append(server->sessions, session); return session; }
static DBusMessage *remove_session(DBusConnection *connection, DBusMessage *message, void *user_data) { struct obc_session *session; const char *sender, *path; if (dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID) == FALSE) return g_dbus_create_error(message, ERROR_INTERFACE ".InvalidArguments", NULL); session = find_session(path); if (session == NULL) return g_dbus_create_error(message, ERROR_INTERFACE ".InvalidArguments", NULL); sender = dbus_message_get_sender(message); if (g_str_equal(sender, obc_session_get_owner(session)) == FALSE) return g_dbus_create_error(message, ERROR_INTERFACE ".NotAuthorized", "Not Authorized"); release_session(session); return dbus_message_new_method_return(message); }
uint32_t remove_connection(iscsid_remove_connection_req_t * req) { iscsi_remove_parameters_t removep; session_t *sess; connection_t *conn; int ret; LOCK_SESSIONS; sess = find_session(&req->session_id); if (sess == NULL) { UNLOCK_SESSIONS; return ISCSID_STATUS_INVALID_SESSION_ID; } conn = find_connection(sess, &req->connection_id); if (conn == NULL) { UNLOCK_SESSIONS; return ISCSID_STATUS_INVALID_CONNECTION_ID; } removep.session_id = sess->entry.sid.id; removep.connection_id = conn->entry.sid.id; UNLOCK_SESSIONS; ret = ioctl(driver, ISCSI_REMOVE_CONNECTION, &removep); DEB(9, ("Remove Connection returns %d, status=%d\n", ret, removep.status)); return removep.status; }
/** * Queue a request from a client for transmission to a particular peer. * * @param car request to queue; this handle is then shared between * the caller (CLIENTS subsystem) and SESSIONS and must not * be released by either until either #GSC_SESSIONS_dequeue(), * #GSC_SESSIONS_transmit() or #GSC_CLIENTS_failed() * have been invoked on it */ void GSC_SESSIONS_queue_request (struct GSC_ClientActiveRequest *car) { struct Session *session; session = find_session (&car->target); if (NULL == session) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Dropped client request for transmission (am disconnected)\n"); GNUNET_break (0); /* should have been rejected earlier */ GSC_CLIENTS_reject_request (car, GNUNET_NO); return; } if (car->msize > GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) { GNUNET_break (0); GSC_CLIENTS_reject_request (car, GNUNET_YES); return; } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received client transmission request. queueing\n"); GNUNET_CONTAINER_DLL_insert (session->active_client_request_head, session->active_client_request_tail, car); try_transmission (session); }
/** * Traffic is being solicited for the given peer. This means that the * message queue on the transport-level (NEIGHBOURS subsystem) is now * empty and it is now OK to transmit another (non-control) message. * * @param pid identity of peer ready to receive data */ void GSC_SESSIONS_solicit (const struct GNUNET_PeerIdentity *pid) { struct Session *session; session = find_session (pid); if (NULL == session) return; session->ready_to_transmit = GNUNET_YES; try_transmission (session); }
/** * End the session with the given peer (we are no longer * connected). * * @param pid identity of peer to kill session with */ void GSC_SESSIONS_end (const struct GNUNET_PeerIdentity *pid) { struct Session *session; struct GSC_ClientActiveRequest *car; struct SessionMessageEntry *sme; session = find_session (pid); if (NULL == session) return; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Destroying session for peer `%4s'\n", GNUNET_i2s (&session->peer)); if (NULL != session->cork_task) { GNUNET_SCHEDULER_cancel (session->cork_task); session->cork_task = NULL; } while (NULL != (car = session->active_client_request_head)) { GNUNET_CONTAINER_DLL_remove (session->active_client_request_head, session->active_client_request_tail, car); GSC_CLIENTS_reject_request (car, GNUNET_NO); } while (NULL != (sme = session->sme_head)) { GNUNET_CONTAINER_DLL_remove (session->sme_head, session->sme_tail, sme); GNUNET_free (sme); } if (NULL != session->typemap_task) { GNUNET_SCHEDULER_cancel (session->typemap_task); session->typemap_task = NULL; } GSC_CLIENTS_notify_clients_about_neighbour (&session->peer, session->tmap, NULL); GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multipeermap_remove (sessions, &session->peer, session)); GNUNET_STATISTICS_set (GSC_stats, gettext_noop ("# peers connected"), GNUNET_CONTAINER_multipeermap_size (sessions), GNUNET_NO); GSC_TYPEMAP_destroy (session->tmap); session->tmap = NULL; GNUNET_free (session); }
void setup_dmapi() { char *cp; if (dm_init_service(&cp) == -1) { fprintf(stderr,"Can't init dmapi\n"); exit(1); } if (strcmp(cp, DM_VER_STR_CONTENTS)) { fprintf(stderr,"Compiled for a different version\n"); exit(1); } find_session(); }
/** * The other peer has indicated that he 'lost' the session * (KX down), reinitialize the session on our end, in particular * this means to restart the typemap transmission. * * @param peer peer that is now connected */ void GSC_SESSIONS_reinit (const struct GNUNET_PeerIdentity *peer) { struct Session *session; session = find_session (peer); if (NULL == session) { /* KX/session is new for both sides; thus no need to restart what has not yet begun */ return; } start_typemap_task (session); }
void add_connection(iscsid_login_req_t * req, iscsid_response_t * res) { session_t *sess; LOCK_SESSIONS; sess = find_session(&req->session_id); if (sess == NULL) { UNLOCK_SESSIONS; res->status = ISCSID_STATUS_INVALID_SESSION_ID; return; } make_connection(sess, req, res, 0); UNLOCK_SESSIONS; }
struct session *parse_tintin_command(struct session *ses, char *input) { char line[BUFFER_SIZE]; struct session *sesptr; input = get_arg_stop_spaces(ses, input, line, 0); substitute(ses, line, line, SUB_VAR|SUB_FUN); if (is_number(line)) { int cnt = atoi(line); input = get_arg_in_braces(ses, input, line, TRUE); while (cnt-- > 0) { ses = script_driver(ses, LIST_COMMAND, line); } return ses; } sesptr = find_session(line); if (sesptr) { if (*input) { input = get_arg_in_braces(ses, input, line, TRUE); substitute(ses, line, line, SUB_VAR|SUB_FUN); script_driver(sesptr, LIST_COMMAND, line); return ses; } else { return activate_session(sesptr); } } tintin_printf(ses, "#ERROR: #UNKNOWN TINTIN-COMMAND '%s'.", line); return ses; }
/** * Dequeue a request from a client from transmission to a particular peer. * * @param car request to dequeue; this handle will then be 'owned' by * the caller (CLIENTS sysbsystem) */ void GSC_SESSIONS_dequeue_request (struct GSC_ClientActiveRequest *car) { struct Session *session; if (0 == memcmp (&car->target, &GSC_my_identity, sizeof (struct GNUNET_PeerIdentity))) return; session = find_session (&car->target); GNUNET_assert (NULL != session); GNUNET_CONTAINER_DLL_remove (session->active_client_request_head, session->active_client_request_tail, car); /* dequeueing of 'high' priority messages may unblock transmission for lower-priority messages, so we also need to try in this case. */ try_transmission (session); }
/** * The given peer send a message of the specified type. Make sure the * respective bit is set in its type-map and that clients are notified * about the session. * * @param peer peer this is about * @param type type of the message */ void GSC_SESSIONS_add_to_typemap (const struct GNUNET_PeerIdentity *peer, uint16_t type) { struct Session *session; struct GSC_TypeMap *nmap; if (0 == memcmp (peer, &GSC_my_identity, sizeof (struct GNUNET_PeerIdentity))) return; session = find_session (peer); GNUNET_assert (NULL != session); if (GNUNET_YES == GSC_TYPEMAP_test_match (session->tmap, &type, 1)) return; /* already in it */ nmap = GSC_TYPEMAP_extend (session->tmap, &type, 1); GSC_CLIENTS_notify_clients_about_neighbour (peer, session->tmap, nmap); GSC_TYPEMAP_destroy (session->tmap); session->tmap = nmap; }
/** * The other peer has confirmed receiving our type map, * check if it is current and if so, stop retransmitting it. * * @param peer peer that confirmed the type map * @param msg confirmation message we received */ void GSC_SESSIONS_confirm_typemap (const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *msg) { const struct TypeMapConfirmationMessage *cmsg; struct Session *session; session = find_session (peer); if (NULL == session) { GNUNET_break (0); return; } if (ntohs (msg->size) != sizeof (struct TypeMapConfirmationMessage)) { GNUNET_break_op (0); return; } cmsg = (const struct TypeMapConfirmationMessage *) msg; if (GNUNET_YES != GSC_TYPEMAP_check_hash (&cmsg->tm_hash)) { /* our typemap has changed in the meantime, do not accept confirmation */ GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# outdated typemap confirmations received"), 1, GNUNET_NO); return; } if (NULL != session->typemap_task) { GNUNET_SCHEDULER_cancel (session->typemap_task); session->typemap_task = NULL; } GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# valid typemap confirmations received"), 1, GNUNET_NO); }
/** * We have received a typemap message from a peer, update ours. * Notifies clients about the session. * * @param peer peer this is about * @param msg typemap update message */ void GSC_SESSIONS_set_typemap (const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *msg) { struct Session *session; struct GSC_TypeMap *nmap; struct SessionMessageEntry *sme; struct TypeMapConfirmationMessage *tmc; nmap = GSC_TYPEMAP_get_from_message (msg); if (NULL == nmap) return; /* malformed */ session = find_session (peer); if (NULL == session) { GNUNET_break (0); return; } sme = GNUNET_malloc (sizeof (struct SessionMessageEntry) + sizeof (struct TypeMapConfirmationMessage)); sme->deadline = GNUNET_TIME_absolute_get (); sme->size = sizeof (struct TypeMapConfirmationMessage); sme->priority = GNUNET_CORE_PRIO_CRITICAL_CONTROL; tmc = (struct TypeMapConfirmationMessage *) &sme[1]; tmc->header.size = htons (sizeof (struct TypeMapConfirmationMessage)); tmc->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_CONFIRM_TYPE_MAP); tmc->reserved = htonl (0); GSC_TYPEMAP_hash (nmap, &tmc->tm_hash); GNUNET_CONTAINER_DLL_insert (session->sme_head, session->sme_tail, sme); try_transmission (session); GSC_CLIENTS_notify_clients_about_neighbour (peer, session->tmap, nmap); GSC_TYPEMAP_destroy (session->tmap); session->tmap = nmap; }
static void bnep_watchdog_cb(GIOChannel *chan, GIOCondition cond, gpointer data) { struct network_server *ns = data; struct network_session *session; char address[18]; const char *paddr = address; session = find_session(ns->sessions, chan); if (!connection || !session) return; ba2str(&session->dst, address); g_dbus_emit_signal(connection, adapter_get_path(ns->na->adapter), ns->iface, "DeviceDisconnected", DBUS_TYPE_STRING, &paddr, DBUS_TYPE_INVALID); g_io_channel_shutdown(chan, TRUE, NULL); g_io_channel_unref(session->io); session->io = NULL; session_free(session); }
static struct avctp *avctp_get(const bdaddr_t *src, const bdaddr_t *dst) { struct avctp *session; assert(src != NULL); assert(dst != NULL); session = find_session(src, dst); if (session) return session; session = g_new0(struct avctp, 1); session->uinput = -1; session->sock = -1; bacpy(&session->src, src); bacpy(&session->dst, dst); sessions = g_slist_append(sessions, session); return session; }
uint32_t logout(iscsid_sym_id_t * req) { iscsi_logout_parameters_t logoutp; session_t *sess; int ret; (void) memset(&logoutp, 0x0, sizeof(logoutp)); LOCK_SESSIONS; sess = find_session(req); if (sess == NULL) { UNLOCK_SESSIONS; return ISCSID_STATUS_INVALID_SESSION_ID; } logoutp.session_id = sess->entry.sid.id; UNLOCK_SESSIONS; ret = ioctl(driver, ISCSI_LOGOUT, &logoutp); DEB(9, ("Logout returns %d, status = %d\n", ret, logoutp.status)); return logoutp.status; }
/** * Transmit a message to a particular peer. * * @param car original request that was queued and then solicited; * this handle will now be 'owned' by the SESSIONS subsystem * @param msg message to transmit * @param cork is corking allowed? * @param priority how important is this message */ void GSC_SESSIONS_transmit (struct GSC_ClientActiveRequest *car, const struct GNUNET_MessageHeader *msg, int cork, enum GNUNET_CORE_Priority priority) { struct Session *session; struct SessionMessageEntry *sme; struct SessionMessageEntry *pos; size_t msize; session = find_session (&car->target); if (NULL == session) return; msize = ntohs (msg->size); sme = GNUNET_malloc (sizeof (struct SessionMessageEntry) + msize); memcpy (&sme[1], msg, msize); sme->size = msize; sme->priority = priority; if (GNUNET_YES == cork) sme->deadline = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_MAX_CORK_DELAY); pos = session->sme_head; while ( (NULL != pos) && (pos->priority >= sme->priority) ) pos = pos->next; if (NULL == pos) GNUNET_CONTAINER_DLL_insert_tail (session->sme_head, session->sme_tail, sme); else GNUNET_CONTAINER_DLL_insert_after (session->sme_head, session->sme_tail, pos->prev, sme); try_transmission (session); }
static struct avctp *avctp_get_internal(struct btd_device *device) { struct avctp_server *server; struct avctp *session; server = find_server(servers, device_get_adapter(device)); if (server == NULL) return NULL; session = find_session(server->sessions, device); if (session) return session; session = g_new0(struct avctp, 1); session->server = server; session->device = btd_device_ref(device); session->state = AVCTP_STATE_DISCONNECTED; session->uinput = -1; server->sessions = g_slist_append(server->sessions, session); return session; }
/* Reinitialize outgoing request after 401/407 response is received. * The purpose of this function is: * - to add a Authorization/Proxy-Authorization header. * - to put the newly created Authorization/Proxy-Authorization header * in cached_list. */ PJ_DEF(pjsip_tx_data*) pjsip_auth_reinit_req( pjsip_endpoint *endpt, pj_pool_t *ses_pool, pjsip_auth_session *sess_list, int cred_count, const pjsip_cred_info cred_info[], pjsip_tx_data *tdata, const pjsip_rx_data *rdata) { const pjsip_hdr *hdr; pjsip_via_hdr *via; PJ_UNUSED_ARG(endpt) pj_assert(rdata->msg->type == PJSIP_RESPONSE_MSG); pj_assert(rdata->msg->line.status.code == 401 || rdata->msg->line.status.code == 407 ); /* * Respond to each authentication challenge. */ hdr = rdata->msg->hdr.next; while (hdr != &rdata->msg->hdr) { pjsip_auth_session *sess; const pjsip_www_authenticate_hdr *hchal; pjsip_authorization_hdr *hauth; /* Find WWW-Authenticate or Proxy-Authenticate header. */ while (hdr->type != PJSIP_H_WWW_AUTHENTICATE && hdr->type != PJSIP_H_PROXY_AUTHENTICATE && hdr != &rdata->msg->hdr) { hdr = hdr->next; } if (hdr == &rdata->msg->hdr) break; hchal = (const pjsip_www_authenticate_hdr*) hdr; /* Find authentication session for this realm, create a new one * if not present. */ sess = find_session(sess_list, &hchal->challenge.common.realm ); if (!sess) { sess = pj_pool_calloc( ses_pool, 1, sizeof(*sess)); pj_strdup( ses_pool, &sess->realm, &hchal->challenge.common.realm); sess->is_proxy = (hchal->type == PJSIP_H_PROXY_AUTHENTICATE); # if (PJSIP_AUTH_HEADER_CACHING) { pj_list_init(&sess->cached_hdr); } # endif pj_list_insert_before( sess_list, sess ); } /* Create authorization header for this challenge, and update * authorization session. */ hauth = process_auth( tdata->pool, hchal, tdata->msg->line.req.uri, tdata, cred_count, cred_info, ses_pool, sess ); if (!hauth) return NULL; /* Add to the message. */ pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)hauth); /* Process next header. */ hdr = hdr->next; } /* Remove branch param in Via header. */ via = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_VIA, NULL); if (via) via->branch_param.slen = 0; /* Increment reference counter. */ pjsip_tx_data_add_ref(tdata); /* Done. */ return tdata; }
/** * Type of a function to call when we receive a address suggestion * message from the service. * * @param cls the `struct GNUNET_ATS_SchedulingHandle` * @param msg message received, NULL on timeout or fatal error */ static void process_ats_address_suggestion_message (void *cls, const struct GNUNET_MessageHeader *msg) { struct GNUNET_ATS_SchedulingHandle *sh = cls; const struct AddressSuggestionMessage *m; struct GNUNET_ATS_AddressRecord *ar; uint32_t session_id; m = (const struct AddressSuggestionMessage *) msg; session_id = ntohl (m->session_id); if (0 == session_id) { GNUNET_break (0); force_reconnect (sh); return; } ar = find_session (sh, session_id, &m->peer); if (NULL == ar) { GNUNET_break (0); force_reconnect (sh); return; } if (NULL == sh->suggest_cb) return; if (GNUNET_YES == ar->in_destroy) { /* ignore suggestion, as this address is dying, unless BW is 0, in that case signal 'disconnect' via BW 0 */ if ( (0 == ntohl (m->bandwidth_out.value__)) && (0 == ntohl (m->bandwidth_in.value__)) ) { LOG (GNUNET_ERROR_TYPE_DEBUG, "ATS suggests disconnect from peer `%s' with BW %u/%u\n", GNUNET_i2s (&ar->address->peer), (unsigned int) ntohl (m->bandwidth_out.value__), (unsigned int) ntohl (m->bandwidth_in.value__)); sh->suggest_cb (sh->suggest_cb_cls, &m->peer, NULL, NULL, m->bandwidth_out, m->bandwidth_in); } return; } if ( (NULL == ar->session) && (GNUNET_HELLO_address_check_option (ar->address, GNUNET_HELLO_ADDRESS_INFO_INBOUND)) ) { GNUNET_break (0); return; } sh->backoff = GNUNET_TIME_UNIT_ZERO; LOG (GNUNET_ERROR_TYPE_DEBUG, "ATS suggests address slot %u for peer `%s' using plugin %s\n", ar->slot, GNUNET_i2s (&ar->address->peer), ar->address->transport_name); sh->suggest_cb (sh->suggest_cb_cls, &m->peer, ar->address, ar->session, m->bandwidth_out, m->bandwidth_in); }
uint state_process_packet() { session_t *this_session; enum sm_Status smStatus; #ifdef __DEBUG__ IF_TRACED((TRC_STATE|TRC_PACKET)) printf("state_process_packet: Entered with event %s",smEvent_names[g_this_event.evtType]); if (g_this_event.evtType==evtPacketRcvd) { printf(" (%s)\n",Topo_opcode_names[g_opcode]); } else { puts(""); } END_TRACE #endif g_this_event.isInternalEvt = FALSE; // It's a real event, not internally generated /* First, look this RealSrc up in the session table, to * locate any association with an established session. * * If there is no matching session, create a new one, iff the * packet is a valid Discover of either topo- or quick- TOS ... */ g_this_event.isNewSession = FALSE; if ((this_session = find_session(&g_base_hdr->tbh_realsrc)) == NULL) { /* Not found: Check for a Discovery packet (validated in packetio.c) */ if (g_opcode == Opcode_Discover) { /* Create a new session for this association */ if ((this_session = new_session()) == NULL) { /* No room in the table: drop the packet and whine. */ warn("state_process_packet: no room to create new session. Packet dropped.\n"); return UINT_MAX; } g_this_event.isNewSession = TRUE; /* Fill in the newly valid session table entry with info from the packet */ this_session->ssn_XID = g_sequencenum; this_session->ssn_mapper_real = g_base_hdr->tbh_realsrc; this_session->ssn_mapper_current = g_ethernet_hdr->eh_src; this_session->ssn_TypeOfSvc = g_base_hdr->tbh_tos; #ifdef __DEBUG__ IF_TRACED(TRC_STATE) printf("New Session:\n\tXID = %X\n\treal address: " ETHERADDR_FMT \ "\n",this_session->ssn_XID, \ ETHERADDR_PRINT(&this_session->ssn_mapper_real) ); printf("\tcurrent address: " ETHERADDR_FMT "\n\tToS: %s\n", ETHERADDR_PRINT(&this_session->ssn_mapper_current), Lld2_tos_names[this_session->ssn_TypeOfSvc] ); END_TRACE #endif g_this_event.ssn = this_session; } /*** end of if (g_opcode == Opcode_Discover) ***/ /* Probes are forced to associate with the mapping session, if there is one. */ if (g_opcode == Opcode_Probe) { if (g_topo_session != NULL && g_topo_session->ssn_is_valid) { this_session = g_topo_session; } } } /*** endo of if (find_session()==NULL) ***/ /* We have associated whatever session that we can with this packet - pass to state machines */ g_this_event.ssn = this_session; smStatus = smS_process_event( &g_this_event ); if (smStatus != PROCESSING_ABORTED) { smStatus = smE_process_event( &g_this_event ); } if (smStatus != PROCESSING_ABORTED) { smStatus = smT_process_event( &g_this_event ); } /* Remove any "new-session" marking */ g_this_event.isNewSession = FALSE; #ifdef __DEBUG__ IF_TRACED(TRC_PACKET) printf("state_process_packet: Leaving - done with event %s\n",smEvent_names[g_this_event.evtType]); END_TRACE #endif return 0; /* Success! */ }
int mlx4_en_rx_frags(struct mlx4_en_priv *priv, struct mlx4_en_rx_ring *ring, struct sk_buff *skb, struct mlx4_cqe *cqe) { struct mlx4_en_ipfrag *session; struct iphdr *iph; u16 ip_len; u16 ip_hlen; int data_len; u16 offset; skb_reset_network_header(skb); skb_reset_transport_header(skb); iph = ip_hdr(skb); ip_len = ntohs(iph->tot_len); ip_hlen = iph->ihl * 4; data_len = ip_len - ip_hlen; offset = ntohs(iph->frag_off); offset &= IP_OFFSET; offset <<= 3; session = find_session(ring, iph); if (unlikely(ip_fast_csum((u8 *)iph, iph->ihl))) { if (session) flush_session(priv, session, IP_MF); return -EINVAL; } if (session) { if (unlikely(session->offset + session->total_len != offset + ip_hlen)) { flush_session(priv, session, IP_MF); goto new_session; } /* Packets smaller then 60 bytes are padded to that size * Need to fix len field of the skb to fit the actual data size * Since ethernet header already removed, the IP total length * is exactly the data size (the skb is linear) */ skb->len = ip_len; frag_append(priv, session, skb, data_len); } else { new_session: session = start_session(ring, iph); if (unlikely(!session)) return -ENOSPC; session->fragments = skb; session->daddr = iph->daddr; session->saddr = iph->saddr; session->id = iph->id; session->protocol = iph->protocol; session->total_len = ip_len; session->offset = offset; session->vlan = (priv->vlgrp && (be32_to_cpu(cqe->vlan_my_qpn) & MLX4_CQE_VLAN_PRESENT_MASK)) ? 1 : 0; session->sl_vid = cqe->sl_vid; } if (!(ntohs(iph->frag_off) & IP_MF)) flush_session(priv, session, 0); else if (session->fragments->len + priv->dev->mtu > 65536) flush_session(priv, session, IP_MF); return 0; }
void test_define(iscsi_test_define_parameters_t *par) { test_pars_t *tp; session_t *sess = NULL; connection_t *conn = NULL; if (!par->test_id) { par->status = ISCSI_STATUS_INVALID_ID; return; } if (find_test_id(par->test_id) != NULL) { par->status = ISCSI_STATUS_DUPLICATE_ID; return; } if (par->session_id && (sess = find_session(par->session_id)) == NULL) { par->status = ISCSI_STATUS_INVALID_SESSION_ID; return; } if (sess != NULL) { if (par->connection_id && (conn = find_connection(sess, par->connection_id)) == NULL) { par->status = ISCSI_STATUS_INVALID_CONNECTION_ID; return; } else if (!par->connection_id) { conn = TAILQ_FIRST(&sess->conn_list); } if (conn->test_pars != NULL) { par->status = ISCSI_STATUS_TEST_ALREADY_ASSIGNED; return; } } if ((tp = malloc(sizeof(*tp), M_TEMP, M_WAITOK | M_ZERO)) == NULL) { par->status = ISCSI_STATUS_NO_RESOURCES; return; } TAILQ_INIT(&tp->negs); TAILQ_INIT(&tp->mods); if (par->neg_descriptor_size && (par->status = add_neg(tp, par->neg_descriptor_ptr, par->neg_descriptor_size)) != 0) { free(tp, M_TEMP); return; } tp->test_id = par->test_id; tp->options = par->options; tp->lose_random[CNT_RX] = par->lose_random_rx; tp->lose_random[CNT_TX] = par->lose_random_tx; tp->connection = conn; tp->firstburst_val = par->firstburst_val; tp->maxburst_val = par->maxburst_val; tp->r2t_val = par->r2t_val; DEB(1, ("TestDefine: id=%d, opt=%x, negsize=%d, conn=%x\n", tp->test_id, tp->options, par->neg_descriptor_size, (int)conn)); TAILQ_INSERT_TAIL(&test_list, tp, link); if (conn != NULL) { tp->connection = conn; conn->test_pars = tp; DEB(1, ("Assigning session %d, connection %d to test %d\n", conn->session->id, conn->id, tp->test_id)); } par->status = ISCSI_STATUS_SUCCESS; }
int main(int argc, char **argv, char **environ) { int c; char *p = (char *) 0; char sysconfdir[BUFSIZ]; struct dirent *dirp; DIR *dp; session *scan; session *last; progname = argv[0]; if ((p = (char *) strrchr(progname, '/')) != (char *) 0) progname = p + 1; snprintf(sysconfdir, BUFSIZ - 1, "%s/sudosh.conf", SYSCONFDIR); parse(&config_option, sysconfdir); snprintf(match, BUFSIZ - 1, "%%32[^%c]%c%%32[^%c]%c%%32[^%c]%c%%ld%c%%64[A-Za-z0-9]", config_option.fdl, config_option.fdl, config_option.fdl, config_option.fdl, config_option.fdl, config_option.fdl, config_option.fdl); while (1) { c = getopt(argc, argv, "d:hVv"); if (c == EOF) break; switch (c) { case 'V': case 'v': fprintf(stdout, "%s version %s\n", progname, VERSION); exit(EXIT_SUCCESS); break; case 'h': fprintf(stdout, "Usage: %s ID [MULTIPLIER] [MAXWAIT]\n", progname); fprintf(stdout, "Replay %s sessions as they were originally recorded.\n\n", progname); fprintf(stdout, "-d Specify alternate LOGDIR where sessions are stored.\n"); fprintf(stdout, "-h Show help synopsis.\n"); fprintf(stdout, "-v,-V Show version.\n\n"); fprintf(stdout, "ID\n The session id of which you wish to view. The format is user-id\n"); fprintf(stdout, " You may obtain a list of ids by just running %s\n\n", progname); fprintf(stdout, "MULTIPLIER\n"); fprintf(stdout, " This is optional. If you wish to \"speed up\" the playback of the\n"); fprintf(stdout, " session, specify a rate to increase it. For example if you used\n"); fprintf(stdout, " a multiplier of \"2\" it would playback the session 2x the original\n"); fprintf(stdout, " recording speed.\n\n"); fprintf(stdout, "MAXWAIT\n"); fprintf(stdout, " This is optional. If you do not want to wait during any long pauses\n"); fprintf(stdout, " use this option to specify a maximum wait time. For example a MAXWAIT\n"); fprintf(stdout, " of 2 would wait a maximum of 2 seconds then continue.\n\n"); fprintf(stdout, "Example: how to get a list of sessions to replay.\n"); fprintf(stdout, "# %s\n\n", progname); fprintf(stdout, "Example: how to replay a session as it was recorded.\n"); fprintf(stdout, "# %s ID\n", progname); fprintf(stdout, "Example: how to replay a session, but just echo the contains to the screen.\n"); fprintf(stdout, "# %s ID 0\n\n", progname); fprintf(stdout, "This is %s version %s\n", progname, VERSION); fprintf(stdout, "Report bugs to <%s>\n", PACKAGE_BUGREPORT); exit(EXIT_SUCCESS); break; case 'd': strncpy(config_option.logdir, optarg, BUFSIZ - 1); break; default: fprintf(stderr, "%s: unrecognized option `%c'\n", progname, c); fprintf(stderr, "Try `%s -h' for more information.\n", progname); exit(EXIT_FAILURE); break; } } argc -= optind; argv += optind; if ((dp = opendir(config_option.logdir)) == (DIR *) 0) { LL(); fprintf(stderr, "%s: can't opendir(%s): %s (%i)\n", progname, config_option.logdir, strerror(errno), errno); exit(EXIT_FAILURE); } while ((dirp = readdir(dp)) != (struct dirent *) 0) { session *s; char from[BUFSIZ]; char to[BUFSIZ]; char type[BUFSIZ]; char randstr[BUFSIZ]; time_t e; if (strcmp(dirp->d_name, ".") == 0 || strcmp(dirp->d_name, "..") == 0) continue; if (sscanf(dirp->d_name, match, from, to, type, &e, randstr) != 5) { LL(); fprintf(stderr, "[warning]: invalid file: %s\n", dirp->d_name); continue; } if (strcmp(type, "script") && strcmp(type, "time") && strcmp(type, "interactive") && strcmp(type,"input")) { fprintf(stderr, "[warning]: invalid type (%s): %s\n", type, dirp->d_name); continue; } if(!strcmp(type, "interactive")) { char *ptr; FILE *f; s = session_malloc(); s->secs = 0; s->e = e; snprintf(s->script.str, BUFSIZ - 1, "%s/%s", config_option.logdir, dirp->d_name); f = fopen(s->script.str, "r"); if(f == (FILE *) 0) { fprintf(stderr, "%.100s: %.100s (%i)\n", s->script.str, strerror(errno), errno); exit(EXIT_FAILURE); } if (fgets(s->id, BUFSIZ - 1, f)==NULL) fprintf(stderr,"Bad header in %s\n",s->script.str); else { ptr = strchr(s->id, '\n'); if(ptr != (char *) 0) *ptr++ = '\0'; strncpy(s->from, from, BUFSIZ - 1); strncpy(s->to, to, BUFSIZ - 1); strncpy(s->type, type, BUFSIZ - 1); strncpy(s->randstr, randstr, BUFSIZ - 1); strftime(s->date, 20, "%m/%d/%Y %H:%M:%S", localtime(&s->e)); link_session(s); } fclose(f); continue; } s = find_session(from, to, e, randstr); if (s == (session *) 0) { s = session_malloc(); s->secs = 0; if (!strcmp(type, "script")) snprintf(s->script.str, BUFSIZ - 1, "%s/%s", config_option.logdir, dirp->d_name); if (!strcmp(type, "time")) { snprintf(s->time.str, BUFSIZ - 1, "%s/%s", config_option.logdir, dirp->d_name); count_dur(s); } s->e = e; strncpy(s->from, from, BUFSIZ - 1); strncpy(s->to, to, BUFSIZ - 1); strncpy(s->type, type, BUFSIZ - 1); strncpy(s->randstr, randstr, BUFSIZ - 1); strftime(s->date, 20, "%m/%d/%Y %H:%M:%S", localtime(&s->e)); snprintf(s->id, BUFSIZ - 1, "%s%c%s%c%ld%c%s", s->from, config_option.fdl, s->to, config_option.fdl, s->e, config_option.fdl, s->randstr); link_session(s); } else { if (!strcmp(type, "script")) snprintf(s->script.str, BUFSIZ - 1, "%s/%s", config_option.logdir, dirp->d_name); if (!strcmp(type, "time")) { snprintf(s->time.str, BUFSIZ - 1, "%s/%s", config_option.logdir, dirp->d_name); count_dur(s); } } } if (closedir(dp) < 0) { LL(); fprintf(stderr, "%s: can't closedir(%s): %s (%i) .. But teally this isn't fatal, it just wasn't expected.\n", progname, config_option.logdir, strerror(errno), errno); // exit(EXIT_FAILURE); } if (argc) { char from[BUFSIZ]; char to[BUFSIZ]; char randstr[BUFSIZ]; time_t e; int div, maxwait; session *s; snprintf(match, BUFSIZ - 1, "%%32[^%c]%c%%32[^%c]%c%%ld%c%%64[A-Za-z0-9]", config_option.fdl, config_option.fdl, config_option.fdl, config_option.fdl, config_option.fdl); if (sscanf(argv[0], match, from, to, &e, randstr) != 4) { LL(); fprintf(stderr, "%s: invalid format: %s\n", progname, argv[0]); fprintf(stderr, "%s: the appropiate format is %s\n", progname, match); exit(EXIT_FAILURE); } s = find_session(from, to, e, randstr); if (s == (session *) 0) { LL(); fprintf(stderr, "%s: no such session: %s\n", progname, argv[0]); exit(EXIT_FAILURE); } div = 1; maxwait = 1; if (argc > 1) div = atoi(argv[1]); if (argc > 2) maxwait = atoi(argv[2]); if (div == 0) { FILE *f_script = fopen(s->script.str, "r"); char buffer[BUFSIZ]; if (f_script == (FILE *) 0) { LL(); fprintf(stderr, "%s: %s: %s (%i)\n", progname, s->script.str, strerror(errno), errno); exit(EXIT_FAILURE); } while (fread(&buffer, 1, BUFSIZ, f_script)) fputs(buffer, stdout); fclose(f_script); } else replay(s->time.str, s->script.str, div, maxwait); exit(EXIT_SUCCESS); } if (!s_top) { fprintf(stderr, "No sessions are logged in %s\n", config_option.logdir); exit(EXIT_SUCCESS); } fprintf(stderr, "%-19s %-8s %-12s %-12s %s\n", "Date", "Duration", "From", "To", "ID"); fprintf(stderr, "%-19s %-8s %-12s %-12s %s\n", "====", "========", "====", "==", "=="); s_top = sort_list(s_top); last = s_top; for (scan = s_top; scan; scan = scan->next) { if ((scan->script.fd = open(scan->script.str, O_RDONLY)) == -1) { LL(); fprintf(stderr, "[error]: session %s is missing script information.\n", scan->id); continue; } close(scan->script.fd); if(!strcmp(scan->type, "interactive")) fprintf(stdout, "%-19s %-8s %-12s %-12s %s\n", scan->date, "-c arg", scan->from, scan->to, scan->id); else fprintf(stdout, "%-19s %-8s %-12s %-12s %s\n", scan->date, int2smalltime(scan->secs), scan->from, scan->to, scan->id); last = scan; } if (s_top && last) fprintf(stderr, "\nUsage: %s ID [MULTIPLIER] [MAXWAIT]\n" "See '%s -h' for more help.\n" "Example: %s %s 1 2\n", progname, progname, progname, last->id); else fprintf(stderr, "\nUsage: %s ID [MULTIPLIER] [MAXWAIT]\n" "See '%s -h' for more help.\n", progname, progname); exit(EXIT_SUCCESS); }