Print this page
195 Need replacement for nfs/lockd+klm
Reviewed by: Gordon Ross <gordon.ross@nexenta.com>
Reviewed by: Jeremy Jones <jeremy@delphix.com>
Reviewed by: Jeff Biseda <jbiseda@delphix.com>
   1 /*
   2  * CDDL HEADER START
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */

  21 /*
  22  * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
  23  */
  24 /*
  25  * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.

  26  */
  27 
  28 
  29 /*
  30  * nfs_tbind.c, common part for nfsd and lockd.
  31  */
  32 
  33 #include <tiuser.h>
  34 #include <fcntl.h>
  35 #include <netconfig.h>
  36 #include <stropts.h>
  37 #include <errno.h>
  38 #include <syslog.h>
  39 #include <rpc/rpc.h>
  40 #include <sys/time.h>
  41 #include <sys/resource.h>
  42 #include <signal.h>
  43 #include <netdir.h>
  44 #include <unistd.h>
  45 #include <string.h>


1681                 }
1682         }
1683         (void) endnetconfig(nc);
1684 
1685         syslog(LOG_ERR, "couldn't find netconfig entry for protocol %s",
1686             proto);
1687         return (-1);
1688 }
1689 
1690 #include <netinet/in.h>
1691 
1692 /*
1693  * Create an address mask appropriate for the transport.
1694  * The mask is used to obtain the host-specific part of
1695  * a network address when comparing addresses.
1696  * For an internet address the host-specific part is just
1697  * the 32 bit IP address and this part of the mask is set
1698  * to all-ones. The port number part of the mask is zeroes.
1699  */
1700 static int
1701 set_addrmask(fd, nconf, mask)
1702         struct netconfig *nconf;
1703         struct netbuf *mask;
1704 {
1705         struct t_info info;
1706 
1707         /*
1708          * Find the size of the address we need to mask.
1709          */
1710         if (t_getinfo(fd, &info) < 0) {
1711                 t_error("t_getinfo");
1712                 return (-1);
1713         }
1714         mask->len = mask->maxlen = info.addr;
1715         if (info.addr <= 0) {
1716                 /*
1717                  * loopback devices have infinite addr size
1718                  * (it is identified by -1 in addr field of t_info structure),
1719                  * so don't build the netmask for them. It's a special case
1720                  * that should be handled properly.
1721                  */
1722                 if ((info.addr == -1) &&
1723                     (0 == strcmp(nconf->nc_protofmly, NC_LOOPBACK))) {
1724                         memset(mask, 0, sizeof (*mask));
1725                         return (0);
1726                 }
1727 
1728                 syslog(LOG_ERR, "set_addrmask: address size: %ld",
1729                         info.addr);
1730                 return (-1);
1731         }
1732 
1733         mask->buf = (char *)malloc(mask->len);
1734         if (mask->buf == NULL) {
1735                 syslog(LOG_ERR, "set_addrmask: no memory");
1736                 return (-1);
1737         }
1738         (void) memset(mask->buf, 0, mask->len);   /* reset all mask bits */
1739 
1740         if (strcmp(nconf->nc_protofmly, NC_INET) == 0) {
1741                 /*
1742                  * Set the mask so that the port is ignored.
1743                  */
1744                 /* LINTED pointer alignment */
1745                 ((struct sockaddr_in *)mask->buf)->sin_addr.s_addr =
1746                                                                 (ulong_t)~0;
1747                 /* LINTED pointer alignment */
1748                 ((struct sockaddr_in *)mask->buf)->sin_family =
1749                                                                 (ushort_t)~0;


   1 /*
   2  * CDDL HEADER START
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.


  24  * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
  25  * Copyright (c) 2012 by Delphix. All rights reserved.
  26  */
  27 
  28 
  29 /*
  30  * nfs_tbind.c, common part for nfsd and lockd.
  31  */
  32 
  33 #include <tiuser.h>
  34 #include <fcntl.h>
  35 #include <netconfig.h>
  36 #include <stropts.h>
  37 #include <errno.h>
  38 #include <syslog.h>
  39 #include <rpc/rpc.h>
  40 #include <sys/time.h>
  41 #include <sys/resource.h>
  42 #include <signal.h>
  43 #include <netdir.h>
  44 #include <unistd.h>
  45 #include <string.h>


1681                 }
1682         }
1683         (void) endnetconfig(nc);
1684 
1685         syslog(LOG_ERR, "couldn't find netconfig entry for protocol %s",
1686             proto);
1687         return (-1);
1688 }
1689 
1690 #include <netinet/in.h>
1691 
1692 /*
1693  * Create an address mask appropriate for the transport.
1694  * The mask is used to obtain the host-specific part of
1695  * a network address when comparing addresses.
1696  * For an internet address the host-specific part is just
1697  * the 32 bit IP address and this part of the mask is set
1698  * to all-ones. The port number part of the mask is zeroes.
1699  */
1700 static int
1701 set_addrmask(int fd,
1702         struct netconfig *nconf,
1703         struct netbuf *mask)
1704 {
1705         struct t_info info;
1706 
1707         /*
1708          * Find the size of the address we need to mask.
1709          */
1710         if (t_getinfo(fd, &info) < 0) {
1711                 t_error("t_getinfo");
1712                 return (-1);
1713         }
1714         mask->len = mask->maxlen = info.addr;
1715         if (info.addr <= 0) {
1716                 /*
1717                  * loopback devices have infinite addr size
1718                  * (it is identified by -1 in addr field of t_info structure),
1719                  * so don't build the netmask for them. It's a special case
1720                  * that should be handled properly.
1721                  */
1722                 if ((info.addr == -1) &&
1723                     (0 == strcmp(nconf->nc_protofmly, NC_LOOPBACK))) {
1724                         memset(mask, 0, sizeof (*mask));
1725                         return (0);
1726                 }
1727 
1728                 syslog(LOG_ERR, "set_addrmask: address size: %ld", info.addr);

1729                 return (-1);
1730         }
1731 
1732         mask->buf = (char *)malloc(mask->len);
1733         if (mask->buf == NULL) {
1734                 syslog(LOG_ERR, "set_addrmask: no memory");
1735                 return (-1);
1736         }
1737         (void) memset(mask->buf, 0, mask->len);   /* reset all mask bits */
1738 
1739         if (strcmp(nconf->nc_protofmly, NC_INET) == 0) {
1740                 /*
1741                  * Set the mask so that the port is ignored.
1742                  */
1743                 /* LINTED pointer alignment */
1744                 ((struct sockaddr_in *)mask->buf)->sin_addr.s_addr =
1745                     (ulong_t)~0;
1746                 /* LINTED pointer alignment */
1747                 ((struct sockaddr_in *)mask->buf)->sin_family =
1748                     (ushort_t)~0;