~ubuntu-branches/ubuntu/oneiric/open-iscsi/oneiric

« back to all changes in this revision

Viewing changes to usr/netlink.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Zobel-Helas
  • Date: 2006-12-03 16:54:21 UTC
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20061203165421-udgd6i05ugt1byrh
Tags: upstream-2.0.730
ImportĀ upstreamĀ versionĀ 2.0.730

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
#include "iscsid.h"
35
35
#include "log.h"
36
36
#include "iscsi_ipc.h"
 
37
#include "initiator.h"
 
38
#include "iscsi_sysfs.h"
37
39
 
38
40
static int ctrl_fd;
39
41
static struct sockaddr_nl src_addr, dest_addr;
44
46
static void *nlm_sendbuf;
45
47
static void *nlm_recvbuf;
46
48
static void *pdu_sendbuf;
 
49
static void *setparam_buf;
47
50
 
48
51
static int ctldev_handle(void);
49
52
 
54
57
#define PDU_SENDBUF_DEFAULT_MAX \
55
58
        (DEFAULT_MAX_RECV_DATA_SEGMENT_LENGTH + sizeof(struct iscsi_hdr))
56
59
 
57
 
 
58
 
#define ISCSI_TRANSPORT_DIR "/sys/class/iscsi_transport"
 
60
#define NLM_SETPARAM_DEFAULT_MAX \
 
61
        (NI_MAXHOST + 1 + sizeof(struct iscsi_uevent))
59
62
 
60
63
static int
61
64
kread(char *data, int count)
301
304
 
302
305
static int
303
306
kcreate_session(uint64_t transport_handle, uint32_t initial_cmdsn,
304
 
                uint64_t *out_handle, uint32_t *out_sid)
 
307
                uint32_t *out_sid, uint32_t *out_hostno)
305
308
{
306
309
        int rc;
307
310
        struct iscsi_uevent ev;
317
320
        if ((rc = __kipc_call(&ev, sizeof(ev))) < 0) {
318
321
                return rc;
319
322
        }
320
 
        if (!ev.r.c_session_ret.session_handle || ev.r.c_session_ret.sid < 0)
321
 
                return -EIO;
322
323
 
323
 
        *out_handle = ev.r.c_session_ret.session_handle;
 
324
        *out_hostno = ev.r.c_session_ret.host_no;
324
325
        *out_sid = ev.r.c_session_ret.sid;
325
326
 
326
327
        return 0;
327
328
}
328
329
 
329
330
static int
330
 
kdestroy_session(uint64_t transport_handle, uint64_t sessionh, uint32_t sid)
 
331
kdestroy_session(uint64_t transport_handle, uint32_t sid)
331
332
{
332
333
        int rc;
333
334
        struct iscsi_uevent ev;
338
339
 
339
340
        ev.type = ISCSI_UEVENT_DESTROY_SESSION;
340
341
        ev.transport_handle = transport_handle;
341
 
        ev.u.d_session.session_handle = sessionh;
342
342
        ev.u.d_session.sid = sid;
343
343
 
344
344
        if ((rc = __kipc_call(&ev, sizeof(ev))) < 0) {
349
349
}
350
350
 
351
351
static int
352
 
kcreate_conn(uint64_t transport_handle, uint64_t sessionh, uint32_t sid,
353
 
            uint32_t cid, uint64_t *out_handle)
 
352
kcreate_conn(uint64_t transport_handle, uint32_t sid,
 
353
            uint32_t cid, uint32_t *out_cid)
354
354
{
355
355
        int rc;
356
356
        struct iscsi_uevent ev;
361
361
 
362
362
        ev.type = ISCSI_UEVENT_CREATE_CONN;
363
363
        ev.transport_handle = transport_handle;
364
 
        ev.u.c_conn.session_handle = sessionh;
365
364
        ev.u.c_conn.cid = cid;
366
365
        ev.u.c_conn.sid = sid;
367
366
 
368
367
        if ((rc = __kipc_call(&ev, sizeof(ev))) < 0) {
 
368
                log_debug(7, "returned %d", rc);
369
369
                return rc;
370
370
        }
371
 
        if (!ev.r.handle)
 
371
 
 
372
        if ((int)ev.r.c_conn_ret.cid == -1)
372
373
                return -EIO;
373
374
 
374
 
        *out_handle = ev.r.handle;
 
375
        *out_cid = ev.r.c_conn_ret.cid;
375
376
        return 0;
376
377
}
377
378
 
378
379
static int
379
 
kdestroy_conn(uint64_t transport_handle, uint64_t connh, int cid)
 
380
kdestroy_conn(uint64_t transport_handle, uint32_t sid, uint32_t cid)
380
381
{
381
382
        int rc;
382
383
        struct iscsi_uevent ev;
387
388
 
388
389
        ev.type = ISCSI_UEVENT_DESTROY_CONN;
389
390
        ev.transport_handle = transport_handle;
390
 
        ev.u.d_conn.conn_handle = connh;
 
391
        ev.u.d_conn.sid = sid;
391
392
        ev.u.d_conn.cid = cid;
392
393
 
393
394
        if ((rc = __kipc_call(&ev, sizeof(ev))) < 0) {
398
399
}
399
400
 
400
401
static int
401
 
kbind_conn(uint64_t transport_handle, uint64_t sessionh, uint64_t connh,
402
 
          uint32_t transport_fd, int is_leading, int *retcode)
 
402
kbind_conn(uint64_t transport_handle, uint32_t sid, uint32_t cid,
 
403
          uint64_t transport_eph, int is_leading, int *retcode)
403
404
{
404
405
        int rc;
405
406
        struct iscsi_uevent ev;
410
411
 
411
412
        ev.type = ISCSI_UEVENT_BIND_CONN;
412
413
        ev.transport_handle = transport_handle;
413
 
        ev.u.b_conn.session_handle = sessionh;
414
 
        ev.u.b_conn.conn_handle = connh;
415
 
        ev.u.b_conn.transport_fd = transport_fd;
 
414
        ev.u.b_conn.sid = sid;
 
415
        ev.u.b_conn.cid = cid;
 
416
        ev.u.b_conn.transport_eph = transport_eph;
416
417
        ev.u.b_conn.is_leading = is_leading;
417
418
 
418
419
        if ((rc = __kipc_call(&ev, sizeof(ev))) < 0) {
425
426
}
426
427
 
427
428
static void
428
 
ksend_pdu_begin(uint64_t transport_handle, uint64_t connh,
 
429
ksend_pdu_begin(uint64_t transport_handle, uint32_t sid, uint32_t cid,
429
430
                        int hdr_size, int data_size)
430
431
{
431
432
        struct iscsi_uevent *ev;
444
445
        memset(ev, 0, sizeof(*ev));
445
446
        ev->type = ISCSI_UEVENT_SEND_PDU;
446
447
        ev->transport_handle = transport_handle;
447
 
        ev->u.send_pdu.conn_handle = connh;
 
448
        ev->u.send_pdu.sid = sid;
 
449
        ev->u.send_pdu.cid = cid;
448
450
        ev->u.send_pdu.hdr_size = hdr_size;
449
451
        ev->u.send_pdu.data_size = data_size;
450
452
 
453
455
}
454
456
 
455
457
static int
456
 
ksend_pdu_end(uint64_t transport_handle, uint64_t connh, int *retcode)
 
458
ksend_pdu_end(uint64_t transport_handle, uint32_t sid, uint32_t cid,
 
459
              int *retcode)
457
460
{
458
461
        int rc;
459
462
        struct iscsi_uevent *ev;
466
469
                exit(-EIO);
467
470
        }
468
471
        ev = xmitbuf;
469
 
        if (ev->u.send_pdu.conn_handle != connh) {
 
472
        if (ev->u.send_pdu.sid != sid || ev->u.send_pdu.cid != cid) {
470
473
                log_error("send's end state machine corruption?");
471
474
                exit(-EIO);
472
475
        }
485
488
                exit(-EIO);
486
489
        }
487
490
 
488
 
        log_debug(3, "send PDU finished for conn (handle %p)", iscsi_ptr(connh));
 
491
        log_debug(3, "send PDU finished for conn %d:%d", 
 
492
                  sid, cid);
489
493
 
490
494
        xmitbuf = NULL;
491
495
        return 0;
497
501
}
498
502
 
499
503
static int
500
 
kset_param(uint64_t transport_handle, uint64_t connh,
501
 
               enum iscsi_param param, uint32_t value, int *retcode)
 
504
kset_param(uint64_t transport_handle, uint32_t sid, uint32_t cid,
 
505
           enum iscsi_param param, void *value, int type)
502
506
{
503
 
        int rc;
504
 
        struct iscsi_uevent ev;
 
507
        struct iscsi_uevent *ev;
 
508
        char *param_str;
 
509
        int rc, len;
505
510
 
506
511
        log_debug(7, "in %s", __FUNCTION__);
507
512
 
508
 
        memset(&ev, 0, sizeof(struct iscsi_uevent));
509
 
 
510
 
        ev.type = ISCSI_UEVENT_SET_PARAM;
511
 
        ev.transport_handle = transport_handle;
512
 
        ev.u.set_param.conn_handle = connh;
513
 
        ev.u.set_param.param = param;
514
 
        ev.u.set_param.value = value;
515
 
 
516
 
        if ((rc = __kipc_call(&ev, sizeof(ev))) < 0) {
 
513
        memset(setparam_buf, 0, NLM_SETPARAM_DEFAULT_MAX);
 
514
        ev = (struct iscsi_uevent *)setparam_buf;
 
515
        ev->type = ISCSI_UEVENT_SET_PARAM;
 
516
        ev->transport_handle = transport_handle;
 
517
        ev->u.set_param.sid = sid;
 
518
        ev->u.set_param.cid = cid;
 
519
        ev->u.set_param.param = param;
 
520
 
 
521
        param_str = setparam_buf + sizeof(*ev);
 
522
        switch (type) {
 
523
        case ISCSI_INT:
 
524
                sprintf(param_str, "%d", *((int *)value));
 
525
                break;
 
526
        case ISCSI_STRING:
 
527
                sprintf(param_str, "%s", (char *)value);
 
528
                break;
 
529
        default:
 
530
                log_error("invalid type %d\n", type);
 
531
                return -EINVAL;
 
532
        }
 
533
        ev->u.set_param.len = len = strlen(param_str) + 1;
 
534
 
 
535
        if ((rc = __kipc_call(ev, sizeof(*ev) + len)) < 0) {
517
536
                return rc;
518
537
        }
519
538
 
520
 
        *retcode = ev.r.retcode;
521
 
 
522
539
        return 0;
523
540
}
524
541
 
525
542
static int
526
 
kstop_conn(uint64_t transport_handle, uint64_t connh, int flag)
 
543
kstop_conn(uint64_t transport_handle, uint32_t sid, uint32_t cid, int flag)
527
544
{
528
545
        int rc;
529
546
        struct iscsi_uevent ev;
534
551
 
535
552
        ev.type = ISCSI_UEVENT_STOP_CONN;
536
553
        ev.transport_handle = transport_handle;
537
 
        ev.u.stop_conn.conn_handle = connh;
 
554
        ev.u.stop_conn.sid = sid;
 
555
        ev.u.stop_conn.cid = cid;
538
556
        ev.u.stop_conn.flag = flag;
539
557
 
540
558
        if ((rc = __kipc_call(&ev, sizeof(ev))) < 0) {
545
563
}
546
564
 
547
565
static int
548
 
kstart_conn(uint64_t transport_handle, uint64_t connh, int *retcode)
 
566
kstart_conn(uint64_t transport_handle, uint32_t sid, uint32_t cid,
 
567
            int *retcode)
549
568
{
550
569
        int rc;
551
570
        struct iscsi_uevent ev;
556
575
 
557
576
        ev.type = ISCSI_UEVENT_START_CONN;
558
577
        ev.transport_handle = transport_handle;
559
 
        ev.u.start_conn.conn_handle = connh;
 
578
        ev.u.start_conn.sid = sid;
 
579
        ev.u.start_conn.cid = cid;
560
580
 
561
581
        if ((rc = __kipc_call(&ev, sizeof(ev))) < 0) {
562
582
                return rc;
567
587
}
568
588
 
569
589
static int
570
 
krecv_pdu_begin(uint64_t transport_handle, uint64_t connh,
571
 
                uintptr_t recv_handle, uintptr_t *pdu_handle, int *pdu_size)
 
590
krecv_pdu_begin(uint64_t transport_handle, uintptr_t recv_handle,
 
591
                uintptr_t *pdu_handle, int *pdu_size)
572
592
{
573
593
        log_debug(7, "in %s", __FUNCTION__);
574
594
 
605
625
        return 0;
606
626
}
607
627
 
608
 
static int
609
 
read_transport_file(char *filename, void *value, char *format)
610
 
{
611
 
        FILE *file;
612
 
        char buffer[32], *line;
613
 
        int err = 0;
614
 
 
615
 
        file = fopen(filename, "r");
616
 
        if (file) {
617
 
                line = fgets(buffer, sizeof(buffer), file);
618
 
                if (line)
619
 
                        sscanf(buffer, format, value);
620
 
                else {
621
 
                        log_error("Could not read %s.\n", filename);
622
 
                        err = -EIO;
623
 
                }
624
 
                fclose(file);
625
 
        } else {
626
 
                log_error("Could not open %s.\n", filename);
627
 
                err = -EIO;
628
 
        }
629
 
        return err;
630
 
}
631
 
 
632
 
static int
633
 
trans_filter(const struct dirent *dir)
634
 
{
635
 
        return strcmp(dir->d_name, ".") && strcmp(dir->d_name, "..");
636
 
}
637
 
 
638
 
static int
639
 
ktrans_list(void)
640
 
{
641
 
        struct dirent **namelist;
642
 
        char filename[64];
643
 
        int i, n, err = 0;
644
 
 
645
 
        log_debug(7, "in %s", __FUNCTION__);
646
 
 
647
 
        n = scandir(ISCSI_TRANSPORT_DIR, &namelist, trans_filter,
648
 
                    alphasort);
649
 
        if (n < 0) {
650
 
                log_error("Could not scan %s.", ISCSI_TRANSPORT_DIR);
651
 
                return n;
652
 
        }
653
 
 
654
 
        if (n > num_providers) {
655
 
                iscsi_provider_t *provider_arr;
656
 
 
657
 
                provider_arr = calloc(n,sizeof(iscsi_provider_t));
658
 
                if (provider_arr == NULL) {
659
 
                        log_error("Failed to alloc %d poviders.", n);
660
 
                        return -ENOMEM;
661
 
                }
662
 
                if (num_providers > 0) {
663
 
                        free(provider);
664
 
                }
665
 
                provider = provider_arr;
666
 
                num_providers = n;
667
 
        }
668
 
 
669
 
        for (i = 0; i < n; i++) {
670
 
                strncpy(provider[i].name, namelist[i]->d_name,
671
 
                        ISCSI_TRANSPORT_NAME_MAXLEN);
672
 
                free(namelist[i]);
673
 
 
674
 
                sprintf(filename, ISCSI_TRANSPORT_DIR"/%s/handle",
675
 
                        provider[i].name);
676
 
                err = read_transport_file(filename, &provider[i].handle,
677
 
                                          "%llu");
678
 
                if (err)
679
 
                        break;
680
 
 
681
 
                sprintf(filename, ISCSI_TRANSPORT_DIR"/%s/caps",
682
 
                        provider[i].name);
683
 
                err = read_transport_file(filename, &provider[i].caps,
684
 
                                          "0x%x");
685
 
                if (err)
686
 
                        break;
687
 
        }
688
 
 
689
 
        for (i++; i < n; i++)
690
 
                free(namelist[i]);
691
 
        free(namelist);
692
 
 
693
 
        return err;
694
 
}
695
 
 
696
 
static int
697
 
kget_stats(uint64_t transport_handle, uint64_t connh, char *statsbuf,
698
 
        int statsbuf_max)
 
628
int
 
629
ktransport_ep_connect(iscsi_conn_t *conn, int non_blocking)
 
630
{
 
631
        int rc, addrlen;
 
632
        struct iscsi_uevent *ev;
 
633
        struct sockaddr *dst_addr = (struct sockaddr *)&conn->saddr;
 
634
 
 
635
        log_debug(7, "in %s", __FUNCTION__);
 
636
 
 
637
        memset(setparam_buf, 0, NLM_SETPARAM_DEFAULT_MAX);
 
638
        ev = (struct iscsi_uevent *)setparam_buf;
 
639
        ev->type = ISCSI_UEVENT_TRANSPORT_EP_CONNECT;
 
640
        ev->transport_handle = conn->session->transport_handle;
 
641
 
 
642
        if (dst_addr->sa_family == PF_INET)
 
643
                addrlen = sizeof(struct sockaddr_in);
 
644
        else if (dst_addr->sa_family == PF_INET6)
 
645
                addrlen = sizeof(struct sockaddr_in6);
 
646
        else {
 
647
                log_error("%s unknown addr family %d\n",
 
648
                         __FUNCTION__, dst_addr->sa_family);
 
649
                return -EINVAL;
 
650
        }
 
651
        memcpy(setparam_buf + sizeof(*ev), dst_addr, addrlen);
 
652
        ev->u.ep_connect.non_blocking = non_blocking;
 
653
 
 
654
        if ((rc = __kipc_call(ev, sizeof(*ev) + addrlen)) < 0)
 
655
                return rc;
 
656
 
 
657
        if (!ev->r.ep_connect_ret.handle)
 
658
                return -EIO;
 
659
 
 
660
        conn->transport_ep_handle = ev->r.ep_connect_ret.handle;
 
661
 
 
662
        log_debug(6, "%s got handle %llx",
 
663
                __FUNCTION__, (unsigned long long)conn->transport_ep_handle);
 
664
        return 0;
 
665
}
 
666
 
 
667
int
 
668
ktransport_ep_poll(iscsi_conn_t *conn, int timeout_ms)
 
669
{
 
670
        int rc;
 
671
        struct iscsi_uevent ev;
 
672
 
 
673
        log_debug(7, "in %s", __FUNCTION__);
 
674
 
 
675
        memset(&ev, 0, sizeof(struct iscsi_uevent));
 
676
 
 
677
        ev.type = ISCSI_UEVENT_TRANSPORT_EP_POLL;
 
678
        ev.transport_handle = conn->session->transport_handle;
 
679
        ev.u.ep_poll.ep_handle  = conn->transport_ep_handle;
 
680
        ev.u.ep_poll.timeout_ms = timeout_ms;
 
681
 
 
682
        if ((rc = __kipc_call(&ev, sizeof(ev))) < 0)
 
683
                return rc;
 
684
 
 
685
        return ev.r.retcode;
 
686
}
 
687
 
 
688
void
 
689
ktransport_ep_disconnect(iscsi_conn_t *conn)
 
690
{
 
691
        int rc;
 
692
        struct iscsi_uevent ev;
 
693
 
 
694
        log_debug(7, "in %s", __FUNCTION__);
 
695
 
 
696
        if (conn->transport_ep_handle < 0)
 
697
                return;
 
698
 
 
699
        memset(&ev, 0, sizeof(struct iscsi_uevent));
 
700
 
 
701
        ev.type = ISCSI_UEVENT_TRANSPORT_EP_DISCONNECT;
 
702
        ev.transport_handle = conn->session->transport_handle;
 
703
        ev.u.ep_disconnect.ep_handle = conn->transport_ep_handle;
 
704
 
 
705
        if ((rc = __kipc_call(&ev, sizeof(ev))) < 0) {
 
706
                log_error("conn %p session %p transport disconnect failed %d\n",
 
707
                          conn, conn->session, rc);
 
708
        } else
 
709
                conn->transport_ep_handle = -1;
 
710
}
 
711
 
 
712
static int
 
713
kget_stats(uint64_t transport_handle, uint32_t sid, uint32_t cid,
 
714
           char *statsbuf, int statsbuf_max)
699
715
{
700
716
        int rc;
701
717
        int ev_size;
709
725
 
710
726
        ev.type = ISCSI_UEVENT_GET_STATS;
711
727
        ev.transport_handle = transport_handle;
712
 
        ev.u.get_stats.conn_handle = connh;
 
728
        ev.u.get_stats.sid = sid;
 
729
        ev.u.get_stats.cid = cid;
713
730
 
714
731
        if ((rc = __kipc_call(&ev, sizeof(ev))) < 0) {
715
732
                return rc;
744
761
{
745
762
        int rc;
746
763
        struct iscsi_uevent *ev;
747
 
        struct qelem *item;
 
764
        struct qelem *item, *pitem;
 
765
        iscsi_provider_t *p;
748
766
        iscsi_session_t *session = NULL;
749
767
        iscsi_conn_t *conn = NULL;
750
768
        uintptr_t recv_handle;
751
769
        char nlm_ev[NLMSG_SPACE(sizeof(struct iscsi_uevent))];
752
770
        struct nlmsghdr *nlh;
753
771
        int ev_size;
754
 
        int k;
755
772
 
756
773
        log_debug(7, "in %s", __FUNCTION__);
757
774
 
764
781
        ev = (struct iscsi_uevent *)NLMSG_DATA(nlm_ev);
765
782
 
766
783
        /* verify connection */
767
 
        for (k = 0; k < num_providers; k++) {
768
 
                item = provider[k].sessions.q_forw;
769
 
                while (item != &provider[k].sessions) {
 
784
        pitem = providers.q_forw;
 
785
        while (pitem != &providers) {
 
786
                p = (iscsi_provider_t *)pitem;
 
787
 
 
788
                item = p->sessions.q_forw;
 
789
                while (item != &p->sessions) {
770
790
                        int i;
771
791
                        session = (iscsi_session_t *)item;
772
792
                        for (i=0; i<ISCSI_CONN_MAX; i++) {
773
793
                                if (ev->type == ISCSI_KEVENT_RECV_PDU &&
774
 
                                    ev->r.recv_req.conn_handle &&
775
 
                                    session->conn[i].handle ==
776
 
                                                ev->r.recv_req.conn_handle) {
 
794
                                    session->id == ev->r.recv_req.sid &&
 
795
                                    session->conn[i].id == ev->r.recv_req.cid) {
777
796
                                        conn = &session->conn[i];
778
 
                                        break;
 
797
                                        goto verify_conn;
779
798
                                }
780
799
                                if (ev->type == ISCSI_KEVENT_CONN_ERROR &&
781
 
                                    ev->r.connerror.conn_handle &&
782
 
                                    session->conn[i].handle ==
783
 
                                                ev->r.connerror.conn_handle) {
 
800
                                    session->id == ev->r.connerror.sid &&
 
801
                                    session->conn[i].id == ev->r.connerror.cid) {
784
802
                                        conn = &session->conn[i];
785
 
                                        break;
 
803
                                        goto verify_conn;
786
804
                                }
787
805
                        }
788
806
                        item = item->q_forw;
789
807
                }
 
808
                pitem = pitem->q_forw;
790
809
        }
 
810
 
 
811
verify_conn:
791
812
        if (conn == NULL) {
792
 
                log_error("could not verify connection 0x%p ", conn);
 
813
                log_error("could not verify connection %d:%d", 
 
814
                          ev->r.recv_req.sid, ev->r.recv_req.cid);
793
815
                return -ENXIO;
794
816
        }
795
817
 
843
865
 
844
866
        nlm_recvbuf = calloc(1, NLM_BUF_DEFAULT_MAX);
845
867
        if (!nlm_recvbuf) {
846
 
                free(nlm_sendbuf);
847
868
                log_error("can not allocate nlm_recvbuf");
848
 
                return -1;
 
869
                goto free_nlm_sendbuf;
849
870
        }
850
871
 
851
872
        pdu_sendbuf = calloc(1, PDU_SENDBUF_DEFAULT_MAX);
852
873
        if (!pdu_sendbuf) {
853
 
                free(nlm_recvbuf);
854
 
                free(nlm_sendbuf);
855
874
                log_error("can not allocate nlm_sendbuf");
856
 
                return -1;
 
875
                goto free_nlm_recvbuf;
 
876
        }
 
877
 
 
878
        setparam_buf = calloc(1, NLM_SETPARAM_DEFAULT_MAX);
 
879
        if (!setparam_buf) {
 
880
                log_error("can not allocate setparam_buf");
 
881
                goto free_pdu_sendbuf;
857
882
        }
858
883
 
859
884
        ctrl_fd = socket(PF_NETLINK, SOCK_RAW, NETLINK_ISCSI);
860
885
        if (!ctrl_fd) {
861
886
                log_error("can not create NETLINK_ISCSI socket");
862
 
                return -1;
 
887
                goto free_setparam_buf;
863
888
        }
864
889
 
865
890
        memset(&src_addr, 0, sizeof(src_addr));
866
891
        src_addr.nl_family = AF_NETLINK;
867
892
        src_addr.nl_pid = getpid();
868
 
        src_addr.nl_groups = 0; /* not in mcast groups */
 
893
        src_addr.nl_groups = 1;
869
894
        if (bind(ctrl_fd, (struct sockaddr *)&src_addr, sizeof(src_addr))) {
870
895
                log_error("can not bind NETLINK_ISCSI socket");
871
 
                return -1;
 
896
                goto close_socket;
872
897
        }
873
898
 
874
899
        memset(&dest_addr, 0, sizeof(dest_addr));
879
904
        log_debug(7, "created NETLINK_ISCSI socket...");
880
905
 
881
906
        return ctrl_fd;
 
907
 
 
908
close_socket:
 
909
        close(ctrl_fd);
 
910
free_setparam_buf:
 
911
        free(setparam_buf);
 
912
free_pdu_sendbuf:
 
913
        free(pdu_sendbuf);
 
914
free_nlm_recvbuf:
 
915
        free(nlm_recvbuf);
 
916
free_nlm_sendbuf:
 
917
        free(nlm_sendbuf);
 
918
        return -1;
882
919
}
883
920
 
884
921
static void
886
923
{
887
924
        log_debug(7, "in %s", __FUNCTION__);
888
925
 
 
926
        free(setparam_buf);
889
927
        free(pdu_sendbuf);
890
928
        free(nlm_recvbuf);
891
929
        free(nlm_sendbuf);
898
936
        .ctldev_open            = ctldev_open,
899
937
        .ctldev_close           = ctldev_close,
900
938
        .ctldev_handle          = ctldev_handle,
901
 
        .trans_list             = ktrans_list,
902
939
        .create_session         = kcreate_session,
903
940
        .destroy_session        = kdestroy_session,
904
941
        .create_conn            = kcreate_conn,