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
↓ 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>
↓ 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  
↓ 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          /*
↓ 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