2
* Plain file-based configuration file code.
4
* (C) 2005 FUJITA Tomonori <tomof@acm.org>
5
* This code is licenced under the GPL.
2
* plain.c - ietd plain file-based configuration
4
* Copyright (C) 2004-2005 FUJITA Tomonori <tomof at acm dot org>
5
* Copyright (C) 2004-2010 VMware, Inc. All Rights Reserved.
6
* Copyright (C) 2007-2010 Ross Walker <rswwalker at gmail dot com>
8
* This file is part of iSCSI Enterprise Target software.
10
* Released under the terms of the GNU GPL v2.0.
12
* This program is free software; you can redistribute it and/or
13
* modify it under the terms of the GNU General Public License as
14
* published by the Free Software Foundation; either version 2 of the
15
* License, or (at your option) any later version.
17
* This program is distributed in the hope that it will be useful, but
18
* WITHOUT ANY WARRANTY; without even the implied warranty of
19
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20
* General Public License for more details.
22
* You should have received a copy of the GNU General Public License
23
* along with this program; if not, write to the Free Software
24
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
66
int is_addr_valid(char *addr)
70
char tmp[NI_MAXHOST + 1], *p = tmp, *q;
72
snprintf(tmp, sizeof(tmp), "%s", addr);
74
if (inet_pton(AF_INET, p, &ia) == 1)
79
q = p + strlen(p) - 1;
85
if (inet_pton(AF_INET6, p, &ia6) == 1)
46
91
/* this is the orignal Ardis code. */
47
92
static char *target_sep_string(char **pp)
476
521
* Main configuration code
524
static int __plain_target_redirect(u32 tid, char *dest, u8 type, int update)
526
struct target *target;
527
char *a = dest, *p = dest + strlen(dest);
529
if (!tid || !dest || !type)
532
if (type != ISCSI_STATUS_TGT_MOVED_TEMP &&
533
type != ISCSI_STATUS_TGT_MOVED_PERM)
536
target = target_find_by_id(tid);
538
log_error("can't find target: %d", tid);
546
while(isspace(*(--p)))
549
if ((p = strrchr(a, ']')))
550
p = strchrnul(p, ':');
552
p = strchrnul(a, ':');
560
if (!is_addr_valid(a))
563
log_warning("target %s %s redirected to %s:%s", target->name,
564
(type == ISCSI_STATUS_TGT_MOVED_TEMP) ? "temporarily" :
566
a, strlen(p) ? p : "3260");
568
log_warning("target redirection for %s cleared", target->name);
570
target->redirect.type = type;
572
snprintf(target->redirect.addr, sizeof(target->redirect.addr), "%s", a);
573
snprintf(target->redirect.port, sizeof(target->redirect.port), "%s", p);
578
static int plain_target_redirect(u32 tid, char *dest, u8 type)
580
return __plain_target_redirect(tid, dest, type, 1);
479
583
static int __plain_target_create(u32 *tid, char *name, int update)
516
if ((err = ki->lunit_create(tid, lun, args)) < 0)
620
err = ki->lunit_create(tid, lun, args);
622
log_error("unable to create logical unit %u in target %u: %d",
530
638
static int plain_lunit_destroy(u32 tid, u32 lun)
532
return ki->lunit_destroy(tid, lun);
642
err = ki->lunit_destroy(tid, lun);
644
log_error("unable to delete logical unit %u in target %u: %d",
535
650
static int __plain_param_set(u32 tid, u64 sid, int type,
540
if ((err = ki->param_set(tid, sid, type, partial, param)) < 0)
655
err = ki->param_set(tid, sid, type, partial, param);
657
log_error ("unable to set parameter (%d:%u) of session %#" PRIx64 " in target %u: %d",
658
type, partial, sid, tid, errno);
735
854
.account_list = plain_account_list,
736
855
.initiator_allow = plain_initiator_allow,
737
856
.target_allow = plain_target_allow,
857
.target_redirect = plain_target_redirect,