Lines Matching +defs:p +defs:c

1 /*	$OpenBSD: initiator.c,v 1.21 2025/01/28 20:41:44 claudio Exp $ */
4 * Copyright (c) 2009 Claudio Jeker <claudio@openbsd.org>
40 struct connection *c;
47 struct connection *c;
193 initiator_login(struct connection *c)
196 struct pdu *p;
200 conn_fail(c);
203 tl->c = c;
206 if (!(p = initiator_login_build(c, tl))) {
209 conn_fail(c);
213 task_init(&tl->task, c->session, 1, tl, initiator_login_cb, NULL);
214 task_pdu_add(&tl->task, p);
215 conn_task_issue(c, &tl->task);
222 struct pdu *p;
230 /* XXX sess_fail(c); */
234 if (!(p = initiator_text_build(t, s, kvp))) {
237 /* XXX sess_fail(c); */
242 task_pdu_add(t, p);
247 initiator_logout(struct session *s, struct connection *c, u_int8_t reason)
250 struct pdu *p;
258 tl->c = c;
261 if (!(p = pdu_new())) {
267 if (!(loreq = pdu_gethdr(p))) {
270 pdu_free(p);
278 loreq->cid = c->cid;
281 task_pdu_add(&tl->task, p);
282 if (c && (c->state & CONN_RUNNING))
283 conn_task_issue(c, &tl->task);
289 initiator_nop_in_imm(struct connection *c, struct pdu *p)
295 nopin = pdu_getbuf(p, NULL, PDU_HEADER);
302 pdu_free(p);
306 task_init(t, c->session, 1, NULL, NULL, NULL);
308 task_pdu_add(t, p);
309 conn_task_issue(c, t);
313 conn_is_leading(struct connection *c)
315 return c == TAILQ_FIRST(&c->session->connections);
318 #define MINE_NOT_DEFAULT(c, k) ((c)->mine.k != iscsi_conn_defaults.k)
321 initiator_login_kvp(struct connection *c, u_int8_t stage)
335 const char **p, **q;
339 if (c->session->config.SessionType == SESSION_TYPE_DISCOVERY) {
348 for (p = q; *p != NULL; i++, p++)
349 if (kvp_set_from_mine(&kvp[i], *p, c))
354 if (conn_is_leading(c))
356 if (MINE_NOT_DEFAULT(c, MaxRecvDataSegmentLength))
360 for (p = opneg_always; *p != NULL; i++, p++)
361 if (kvp_set_from_mine(&kvp[i], *p, c))
363 if (conn_is_leading(c))
364 for (p = leading_only; *p != NULL; i++, p++)
365 if (kvp_set_from_mine(&kvp[i], *p, c))
367 if (MINE_NOT_DEFAULT(c, MaxRecvDataSegmentLength) &&
368 kvp_set_from_mine(&kvp[i], "MaxRecvDataSegmentLength", c))
383 initiator_login_build(struct connection *c, struct task_login *tl)
385 struct pdu *p;
390 if (!(p = pdu_new()))
392 if (!(lreq = pdu_gethdr(p))) {
393 pdu_free(p);
407 lreq->isid_base = htonl(tl->c->session->isid_base);
408 lreq->isid_qual = htons(tl->c->session->isid_qual);
410 lreq->cid = htons(tl->c->cid);
411 lreq->expstatsn = htonl(tl->c->expstatsn);
413 if (!(kvp = initiator_login_kvp(c, tl->stage))) {
417 if ((n = text_to_pdu(kvp, p)) == -1) {
425 pdu_free(p);
432 return p;
438 struct pdu *p;
442 if (!(p = pdu_new()))
444 if (!(lreq = pdu_gethdr(p)))
451 if ((n = text_to_pdu(kvp, p)) == -1)
456 return p;
460 initiator_login_cb(struct connection *c, void *arg, struct pdu *p)
468 lresp = pdu_getbuf(p, NULL, PDU_HEADER);
473 conn_fail(c);
479 conn_fail(c);
485 buf = pdu_getbuf(p, &n, PDU_DATA);
488 conn_fail(c);
495 conn_fail(c);
499 if (conn_parse_kvp(c, kvp) == -1) {
501 conn_fail(c);
515 pdu_free(p);
516 p = initiator_login_build(c, tl);
517 if (p == NULL) {
518 conn_fail(c);
523 conn_fsm(c, CONN_EV_LOGGED_IN);
524 conn_task_cleanup(c, &tl->task);
529 conn_fail(c);
532 conn_task_cleanup(c, &tl->task);
534 task_pdu_add(&tl->task, p);
535 conn_task_issue(c, &tl->task);
538 if (p)
539 pdu_free(p);
543 initiator_discovery_cb(struct connection *c, void *arg, struct pdu *p)
551 lresp = pdu_getbuf(p, NULL, PDU_HEADER);
558 session_shutdown(c->session);
561 buf = pdu_getbuf(p, &n, PDU_DATA);
572 session_shutdown(c->session);
578 conn_fail(c);
579 pdu_free(p);
582 conn_task_cleanup(c, t);
584 pdu_free(p);
588 initiator_logout_cb(struct connection *c, void *arg, struct pdu *p)
593 loresp = pdu_getbuf(p, NULL, PDU_HEADER);
602 conn_fsm(c, CONN_EV_LOGGED_OUT);
603 session_fsm(&c->session->sev, SESS_EV_CLOSED, 0);
605 conn_fsm(tl->c, CONN_EV_LOGGED_OUT);
606 session_fsm(&tl->c->sev, SESS_EV_CONN_CLOSED, 0);
612 tl->c->session->config.SessionName,
613 tl->c->cid);
614 conn_fsm(tl->c, CONN_EV_FREE);
620 conn_fail(tl->c);
621 pdu_free(p);
625 conn_task_cleanup(c, &tl->task);
627 pdu_free(p);