Print this page
NEX-16824 SMB client connection setup rework
NEX-17232 SMB client reconnect failures
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Matt Barden <matt.barden@nexenta.com>
and: (improve debug)
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/lib/libsmbfs/smb/getaddr.c
+++ new/usr/src/lib/libsmbfs/smb/getaddr.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
|
↓ open down ↓ |
13 lines elided |
↑ open up ↑ |
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
24 + * Copyright 2018 Nexenta Systems, Inc. All rights reserved.
24 25 */
25 26
26 27 /*
27 28 * Functions to get list of addresses (TCP and/or NetBIOS)
28 29 */
29 30
30 31 #include <errno.h>
31 32 #include <stdio.h>
32 33 #include <stdlib.h>
33 34 #include <string.h>
34 35 #include <strings.h>
35 36 #include <unistd.h>
36 37 #include <netdb.h>
37 38 #include <libintl.h>
38 39 #include <xti.h>
39 40 #include <assert.h>
40 41
41 42 #include <sys/types.h>
42 43 #include <sys/time.h>
43 44 #include <sys/byteorder.h>
44 45 #include <sys/socket.h>
45 46 #include <sys/fcntl.h>
46 47
47 48 #include <netinet/in.h>
48 49 #include <netinet/tcp.h>
49 50 #include <arpa/inet.h>
|
↓ open down ↓ |
16 lines elided |
↑ open up ↑ |
50 51
51 52 #include <netsmb/smb.h>
52 53 #include <netsmb/smb_lib.h>
53 54 #include <netsmb/netbios.h>
54 55 #include <netsmb/nb_lib.h>
55 56 #include <netsmb/smb_dev.h>
56 57
57 58 #include "charsets.h"
58 59 #include "private.h"
59 60
61 +static char smb_port[16] = "445";
62 +
60 63 void
61 64 dump_addrinfo(struct addrinfo *ai)
62 65 {
63 66 int i;
64 67
65 68 if (ai == NULL) {
66 69 printf("ai==NULL\n");
67 70 return;
68 71 }
69 72
70 73 for (i = 0; ai; i++, ai = ai->ai_next) {
71 74 printf("ai[%d]: af=%d, len=%d", i,
72 75 ai->ai_family, ai->ai_addrlen);
73 76 dump_sockaddr(ai->ai_addr);
74 77 if (ai->ai_canonname) {
75 78 printf("ai[%d]: cname=\"%s\"\n",
76 79 i, ai->ai_canonname);
77 80 }
78 81 }
79 82 }
80 83
81 84 void
82 85 dump_sockaddr(struct sockaddr *sa)
83 86 {
84 87 char paddrbuf[INET6_ADDRSTRLEN];
85 88 struct sockaddr_in *sin;
86 89 struct sockaddr_in6 *sin6;
87 90 int af = sa->sa_family;
88 91 const char *ip;
89 92
90 93 printf(" saf=%d,", af);
91 94 switch (af) {
92 95 case AF_NETBIOS: /* see nbns_rq.c */
93 96 case AF_INET:
94 97 sin = (void *)sa;
95 98 ip = inet_ntop(AF_INET, &sin->sin_addr,
96 99 paddrbuf, sizeof (paddrbuf));
97 100 break;
98 101 case AF_INET6:
99 102 sin6 = (void *)sa;
100 103 ip = inet_ntop(AF_INET6, &sin6->sin6_addr,
101 104 paddrbuf, sizeof (paddrbuf));
102 105 break;
103 106 default:
104 107 ip = "?";
105 108 break;
106 109 }
107 110 printf(" IP=%s\n", ip);
108 111 }
109 112
110 113
|
↓ open down ↓ |
41 lines elided |
↑ open up ↑ |
111 114 /*
112 115 * SMB client name resolution - normal, and/or NetBIOS.
113 116 * Returns an EAI_xxx error number like getaddrinfo(3)
114 117 */
115 118 int
116 119 smb_ctx_getaddr(struct smb_ctx *ctx)
117 120 {
118 121 struct nb_ctx *nbc = ctx->ct_nb;
119 122 struct addrinfo hints, *res;
120 123 char *srvaddr_str;
121 - int gaierr, gaierr2;
124 + int gaierr;
122 125
123 126 if (ctx->ct_fullserver == NULL || ctx->ct_fullserver[0] == '\0')
124 127 return (EAI_NONAME);
125 128
126 129 if (ctx->ct_addrinfo != NULL) {
127 130 freeaddrinfo(ctx->ct_addrinfo);
128 131 ctx->ct_addrinfo = NULL;
129 132 }
130 133
131 134 /*
132 135 * If the user specified an address, use it,
133 136 * and don't do NetBIOS lookup.
134 137 */
135 138 if (ctx->ct_srvaddr_s) {
136 139 srvaddr_str = ctx->ct_srvaddr_s;
137 140 nbc->nb_flags &= ~NBCF_NS_ENABLE;
138 141 } else
139 142 srvaddr_str = ctx->ct_fullserver;
140 143
141 144 /*
142 145 * Default the server name we'll use in the
143 146 * protocol (i.e. NTLM, tree connect).
144 147 */
145 148 strlcpy(ctx->ct_srvname, ctx->ct_fullserver,
146 149 sizeof (ctx->ct_srvname));
|
↓ open down ↓ |
15 lines elided |
↑ open up ↑ |
147 150
148 151 /*
149 152 * Try to lookup the host address using the
150 153 * normal name-to-IP address mechanisms.
151 154 * If that fails, we MAY try NetBIOS.
152 155 */
153 156 memset(&hints, 0, sizeof (hints));
154 157 hints.ai_flags = AI_CANONNAME;
155 158 hints.ai_family = PF_UNSPEC;
156 159 hints.ai_socktype = SOCK_STREAM;
157 - gaierr = getaddrinfo(srvaddr_str, NULL, &hints, &res);
160 + gaierr = getaddrinfo(srvaddr_str, smb_port, &hints, &res);
158 161 if (gaierr == 0) {
159 162 ctx->ct_addrinfo = res;
160 163 return (0);
161 164 }
162 165
163 166 /*
167 + * If we really want to support NetBIOS, we should add
168 + * an AF_NETBIOS entry to the address list here.
169 + * For now, let's just skip NetBIOS.
170 + * (Can we just kill NetBIOS? Please? :)
171 + */
172 +#if 0 /* XXX Just kill NetBIOS? */
173 + /*
164 174 * If regular IP name lookup failed, try NetBIOS,
165 175 * but only if given a valid NetBIOS name and if
166 176 * NetBIOS name lookup is enabled.
167 177 */
168 178 if (nbc->nb_flags & NBCF_NS_ENABLE) {
169 - gaierr2 = nbns_getaddrinfo(ctx->ct_fullserver, nbc, &res);
179 + int gaierr2 = nbns_getaddrinfo(ctx->ct_fullserver, nbc, &res);
170 180 if (gaierr2 == 0) {
171 181 if (res->ai_canonname)
172 182 strlcpy(ctx->ct_srvname,
173 183 res->ai_canonname,
174 184 sizeof (ctx->ct_srvname));
175 185 ctx->ct_addrinfo = res;
176 186 return (0);
177 187 }
178 188 }
189 +#endif
179 190
180 191 /*
181 192 * Return the original error from getaddrinfo
182 193 */
183 194 if (smb_verbose) {
184 195 smb_error(dgettext(TEXT_DOMAIN,
185 196 "getaddrinfo: %s: %s"), 0,
186 197 ctx->ct_fullserver,
187 198 gai_strerror(gaierr));
188 199 }
189 200 return (gaierr);
190 201 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX