예제 #1
0
파일: io.c 프로젝트: grevian/open-iscsi
static int bind_conn_to_iface(iscsi_conn_t *conn, struct iface_rec *iface)
{
	struct iscsi_session *session = conn->session;

	if (strcmp(iface->transport_name, DEFAULT_TRANSPORT))
		return 0;

	memset(session->netdev, 0, IFNAMSIZ);
	if (iface_is_bound_by_hwaddr(iface)) {
		if (net_get_netdev_from_hwaddress(iface->hwaddress,
						  session->netdev)) {
			log_error("Cannot match %s to net/scsi interface.",
				  iface->hwaddress);
			return -1;
		}
	} else if (iface_is_bound_by_netdev(iface)) {
		strcpy(session->netdev, iface->netdev);
	} else if (iface_is_bound_by_ipaddr(iface)) {
		/*
		 * we never supported this but now with offload having to
		 * set the ip address in the iface, useris may forget to
		 * set the offload's transport type and we end up here by
		 * accident.
		 */
		log_error("Cannot bind %s to net/scsi interface. This is not "
			  "supported with software iSCSI (iscsi_tcp).",
			   iface->ipaddress);
		return -1;
	}

	if (strlen(session->netdev)) {
		struct ifreq ifr;

		log_debug(4, "Binding session %d to %s", session->id,
			  session->netdev);
		memset(&ifr, 0, sizeof(ifr));
		strlcpy(ifr.ifr_name, session->netdev, IFNAMSIZ);

		if (setsockopt(conn->socket_fd, SOL_SOCKET, SO_BINDTODEVICE,
			       session->netdev,
			       strlen(session->netdev) + 1) < 0) {
			log_error("Could not bind connection %d to %s\n",
				  conn->id, session->netdev);
			return -1;
		}
	}

	return 0;
}
예제 #2
0
/*
 * Routines to fill in the context values.
 */
static int fill_nic_context(char *subsys, char *id,
			    struct boot_context *context)
{
	int rc;

	rc = sysfs_get_int(id, subsys, "flags", &context->nic_flags);
	/*
	 * Per spec we would need to check against Bit 0
	 * (Block Valid Flag), but some firmware only
	 * sets Bit 1 (Firmware Booting Selected).
	 * So any setting is deemed okay.
	 */
	if (!rc && (context->nic_flags == 0))
		rc = ENODEV;
	if (rc)
		return rc;

	rc = sysfs_get_str(id, subsys, "mac", context->mac,
			   sizeof(context->mac));
	if (rc)
		return rc;

	/*
	 * Some offload cards like bnx2i use different MACs for the net and
	 * iscsi functions, so we have to follow the sysfs links.
	 *
	 * Other ibft implementations may not be tied to a pci function,
	 * so there will not be any device/net link, so we drop down to
	 * the MAC matching.
	 *
	 * And finally, some cards like be2iscsi and qla4xxx do not have
	 * any linux network subsys representation. These hosts will
	 * not have the ibft subsys. Instead the subsys is the scsi host
	 * number.
	 */
	if (!strcmp(IBFT_SUBSYS, subsys)) {
		rc = get_iface_from_device(id, context);
		if (rc) {
			rc = net_get_netdev_from_hwaddress(context->mac,
							   context->iface);
			if (rc)
				return rc;
		}
	} else
		strlcpy(context->scsi_host_name, subsys,
			sizeof(context->scsi_host_name));

	memset(&context->boot_nic, 0, sizeof(context->boot_nic));
	snprintf(context->boot_nic, sizeof(context->boot_nic), "%s", id);

	sysfs_get_str(id, subsys, "ip-addr", context->ipaddr,
		      sizeof(context->ipaddr));
	sysfs_get_str(id, subsys, "vlan", context->vlan,
		      sizeof(context->vlan));
	sysfs_get_str(id, subsys, "subnet-mask", context->mask,
		      sizeof(context->mask));
	sysfs_get_str(id, subsys, "gateway", context->gateway,
		      sizeof(context->gateway));
	sysfs_get_str(id, subsys, "primary-dns", context->primary_dns,
		      sizeof(context->primary_dns));
	sysfs_get_str(id, subsys, "secondary-dns", context->secondary_dns,
		      sizeof(context->secondary_dns));
	sysfs_get_str(id, subsys, "dhcp", context->dhcp,
		      sizeof(context->dhcp));
	sysfs_get_int(id, subsys, "origin", (int *)&context->origin);
	return 0;
}