1*613a2f6bSGordon Ross /* 2*613a2f6bSGordon Ross * CDDL HEADER START 3*613a2f6bSGordon Ross * 4*613a2f6bSGordon Ross * The contents of this file are subject to the terms of the 5*613a2f6bSGordon Ross * Common Development and Distribution License (the "License"). 6*613a2f6bSGordon Ross * You may not use this file except in compliance with the License. 7*613a2f6bSGordon Ross * 8*613a2f6bSGordon Ross * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*613a2f6bSGordon Ross * or http://www.opensolaris.org/os/licensing. 10*613a2f6bSGordon Ross * See the License for the specific language governing permissions 11*613a2f6bSGordon Ross * and limitations under the License. 12*613a2f6bSGordon Ross * 13*613a2f6bSGordon Ross * When distributing Covered Code, include this CDDL HEADER in each 14*613a2f6bSGordon Ross * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*613a2f6bSGordon Ross * If applicable, add the following below this CDDL HEADER, with the 16*613a2f6bSGordon Ross * fields enclosed by brackets "[]" replaced with your own identifying 17*613a2f6bSGordon Ross * information: Portions Copyright [yyyy] [name of copyright owner] 18*613a2f6bSGordon Ross * 19*613a2f6bSGordon Ross * CDDL HEADER END 20*613a2f6bSGordon Ross */ 21*613a2f6bSGordon Ross 22*613a2f6bSGordon Ross /* 23*613a2f6bSGordon Ross * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 24*613a2f6bSGordon Ross * Use is subject to license terms. 25*613a2f6bSGordon Ross */ 26*613a2f6bSGordon Ross 27*613a2f6bSGordon Ross /* 28*613a2f6bSGordon Ross * Create a new VC given a list of addresses. 29*613a2f6bSGordon Ross */ 30*613a2f6bSGordon Ross 31*613a2f6bSGordon Ross #include <errno.h> 32*613a2f6bSGordon Ross #include <stdio.h> 33*613a2f6bSGordon Ross #include <string.h> 34*613a2f6bSGordon Ross #include <strings.h> 35*613a2f6bSGordon Ross #include <stdlib.h> 36*613a2f6bSGordon Ross #include <unistd.h> 37*613a2f6bSGordon Ross #include <netdb.h> 38*613a2f6bSGordon Ross #include <libintl.h> 39*613a2f6bSGordon Ross #include <xti.h> 40*613a2f6bSGordon Ross #include <assert.h> 41*613a2f6bSGordon Ross 42*613a2f6bSGordon Ross #include <sys/types.h> 43*613a2f6bSGordon Ross #include <sys/time.h> 44*613a2f6bSGordon Ross #include <sys/byteorder.h> 45*613a2f6bSGordon Ross #include <sys/socket.h> 46*613a2f6bSGordon Ross #include <sys/fcntl.h> 47*613a2f6bSGordon Ross 48*613a2f6bSGordon Ross #include <netinet/in.h> 49*613a2f6bSGordon Ross #include <netinet/tcp.h> 50*613a2f6bSGordon Ross #include <arpa/inet.h> 51*613a2f6bSGordon Ross 52*613a2f6bSGordon Ross #include <netsmb/smb.h> 53*613a2f6bSGordon Ross #include <netsmb/smb_lib.h> 54*613a2f6bSGordon Ross #include <netsmb/netbios.h> 55*613a2f6bSGordon Ross #include <netsmb/nb_lib.h> 56*613a2f6bSGordon Ross #include <netsmb/smb_dev.h> 57*613a2f6bSGordon Ross 58*613a2f6bSGordon Ross #include "charsets.h" 59*613a2f6bSGordon Ross #include "private.h" 60*613a2f6bSGordon Ross 61*613a2f6bSGordon Ross /* 62*613a2f6bSGordon Ross * Ask the IOD to create a VC with this IP address. 63*613a2f6bSGordon Ross */ 64*613a2f6bSGordon Ross static int 65*613a2f6bSGordon Ross newvc(struct smb_ctx *ctx, struct addrinfo *ai) 66*613a2f6bSGordon Ross { 67*613a2f6bSGordon Ross smbioc_ossn_t *ssn = &ctx->ct_ssn; 68*613a2f6bSGordon Ross 69*613a2f6bSGordon Ross /* 70*613a2f6bSGordon Ross * Copy the passed address into ssn_srvaddr, 71*613a2f6bSGordon Ross * but first sanity-check lengths. Also, 72*613a2f6bSGordon Ross * zero it first to avoid trailing junk. 73*613a2f6bSGordon Ross */ 74*613a2f6bSGordon Ross if (ai->ai_addrlen > sizeof (ssn->ssn_srvaddr)) 75*613a2f6bSGordon Ross return (EINVAL); 76*613a2f6bSGordon Ross bzero(&ssn->ssn_srvaddr, sizeof (ssn->ssn_srvaddr)); 77*613a2f6bSGordon Ross bcopy(ai->ai_addr, &ssn->ssn_srvaddr, ai->ai_addrlen); 78*613a2f6bSGordon Ross 79*613a2f6bSGordon Ross return (smb_iod_cl_newvc(ctx)); 80*613a2f6bSGordon Ross } 81*613a2f6bSGordon Ross 82*613a2f6bSGordon Ross /* 83*613a2f6bSGordon Ross * Setup a new VC via the IOD. 84*613a2f6bSGordon Ross * Similar to findvc.c 85*613a2f6bSGordon Ross */ 86*613a2f6bSGordon Ross int 87*613a2f6bSGordon Ross smb_ctx_newvc(struct smb_ctx *ctx) 88*613a2f6bSGordon Ross { 89*613a2f6bSGordon Ross struct addrinfo *ai; 90*613a2f6bSGordon Ross int err = ENOENT; 91*613a2f6bSGordon Ross 92*613a2f6bSGordon Ross /* Should already have the address list. */ 93*613a2f6bSGordon Ross if ((ctx->ct_flags & SMBCF_RESOLVED) == 0) 94*613a2f6bSGordon Ross return (EINVAL); 95*613a2f6bSGordon Ross 96*613a2f6bSGordon Ross for (ai = ctx->ct_addrinfo; ai; ai = ai->ai_next) { 97*613a2f6bSGordon Ross 98*613a2f6bSGordon Ross switch (ai->ai_family) { 99*613a2f6bSGordon Ross 100*613a2f6bSGordon Ross case AF_INET: 101*613a2f6bSGordon Ross case AF_INET6: 102*613a2f6bSGordon Ross case AF_NETBIOS: 103*613a2f6bSGordon Ross err = newvc(ctx, ai); 104*613a2f6bSGordon Ross break; 105*613a2f6bSGordon Ross 106*613a2f6bSGordon Ross default: 107*613a2f6bSGordon Ross DPRINT("skipped family %d", ai->ai_family); 108*613a2f6bSGordon Ross break; 109*613a2f6bSGordon Ross } 110*613a2f6bSGordon Ross 111*613a2f6bSGordon Ross if (err == 0) { 112*613a2f6bSGordon Ross ctx->ct_flags |= SMBCF_SSNACTIVE; 113*613a2f6bSGordon Ross return (0); 114*613a2f6bSGordon Ross } 115*613a2f6bSGordon Ross } 116*613a2f6bSGordon Ross 117*613a2f6bSGordon Ross return (err); 118*613a2f6bSGordon Ross } 119