Print this page
inet_pton


   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 2008 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  */



  25 
  26 /*
  27  * NL7C (Network Layer 7 Cache) as part of SOCKFS provides an in-kernel
  28  * gateway cache for the request/response message based L7 protocol HTTP
  29  * (Hypertext Transfer Protocol, see HTTP/1.1 RFC2616) in a semantically
  30  * transparent manner.
  31  *
  32  * Neither the requesting user agent (client, e.g. web browser) nor the
  33  * origin server (e.g. webserver) that provided the response cached by
  34  * NL7C are impacted in any way.
  35  *
  36  * Note, currently NL7C only processes HTTP messages via the embedded
  37  * URI of scheme http (not https nor any other), additional scheme are
  38  * intended to be supported as is practical such that much of the NL7C
  39  * framework may appear more general purpose then would be needed just
  40  * for an HTTP gateway cache.
  41  *
  42  * NL7C replaces NCA (Network Cache and Accelerator) and in the future
  43  * NCAS (NCA/SSL).
  44  *
  45  * Further, NL7C uses all NCA configuration files, see "/etc/nca/", the
  46  * NCA socket API, "AF_NCA", and "ndd /dev/nca" for backwards compatibility.
  47  */
  48 
  49 #include <sys/systm.h>
  50 #include <sys/strsun.h>
  51 #include <sys/strsubr.h>
  52 #include <inet/common.h>
  53 #include <inet/led.h>
  54 #include <inet/mi.h>
  55 #include <netinet/in.h>
  56 #include <fs/sockfs/nl7c.h>
  57 #include <fs/sockfs/nl7curi.h>
  58 #include <fs/sockfs/socktpi.h>
  59 
  60 #include <inet/nca/ncadoorhdr.h>
  61 #include <inet/nca/ncalogd.h>
  62 #include <inet/nca/ncandd.h>

  63 
  64 #include <sys/promif.h>
  65 
  66 /*
  67  * NL7C, NCA, NL7C logger enabled:
  68  */
  69 
  70 boolean_t       nl7c_enabled = B_FALSE;
  71 
  72 boolean_t       nl7c_logd_enabled = B_FALSE;
  73 boolean_t       nl7c_logd_started = B_FALSE;
  74 boolean_t       nl7c_logd_cycle = B_TRUE;
  75 
  76 /*
  77  * Some externs:
  78  */
  79 
  80 extern int      inet_pton(int, char *, void *);
  81 
  82 extern void     nl7c_uri_init(void);
  83 extern boolean_t nl7c_logd_init(int, caddr_t *);
  84 extern void     nl7c_nca_init(void);
  85 
  86 /*
  87  * nl7c_addr_t - a singly linked grounded list, pointed to by *nl7caddrs,
  88  * constructed at init time by parsing "/etc/nca/ncaport.conf".
  89  *
  90  * This list is searched at bind(3SOCKET) time when an application doesn't
  91  * explicitly set AF_NCA but instead uses AF_INET, if a match is found then
  92  * the underlying socket is marked sti_nl7c_flags NL7C_ENABLED.
  93  */
  94 
  95 typedef struct nl7c_addr_s {
  96         struct nl7c_addr_s *next;       /* next entry */
  97         sa_family_t     family;         /* addr type, only INET and INET6 */
  98         uint16_t        port;           /* port */
  99         union {
 100                 ipaddr_t        v4;     /* IPv4 address */
 101                 in6_addr_t      v6;     /* IPv6 address */


 315         if (strcmp(s, "*") == 0) {
 316                 /* INADDR_ANY */
 317                 p->family = AF_INET;
 318                 return (0);
 319         }
 320         if (strcmp(s, "::") == 0) {
 321                 /* IN6ADDR_ANY */
 322                 p->family = AF_INET6;
 323                 return (0);
 324         }
 325         /* IPv4 address ? */
 326         if (inet_pton(AF_INET, s, &p->addr.v4) != 1) {
 327                 /* Nop, IPv6 address ? */
 328                 if (inet_pton(AF_INET6, s, &p->addr.v6) != 1) {
 329                         /* Nop, return error */
 330                         return (1);
 331                 }
 332                 p->family = AF_INET6;
 333         } else {
 334                 p->family = AF_INET;
 335                 p->addr.v4 = ntohl(p->addr.v4);
 336         }

 337         return (0);
 338 }
 339 
 340 /*
 341  * Open and read each line from "/etc/nca/ncaport.conf", the syntax of a
 342  * ncaport.conf file line is:
 343  *
 344  *      ncaport=IPaddr/Port[/Proxy]
 345  *
 346  * Where:
 347  *
 348  * ncaport - the only token recognized.
 349  *
 350  *  IPaddr - an IPv4 numeric dot address (e.g. 192.168.84.71) or '*' for
 351  *           INADDR_ANY, or an IPv6 numeric address or "::" for IN6ADDR_ANY.
 352  *
 353  *       / - IPaddr/Port separator.
 354  *
 355  *    Port - a TCP decimal port number.
 356  *




   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 2008 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 /*
  26  * Copyright 2012 Nexenta Systems, Inc. All rights reserved.
  27  */
  28 
  29 /*
  30  * NL7C (Network Layer 7 Cache) as part of SOCKFS provides an in-kernel
  31  * gateway cache for the request/response message based L7 protocol HTTP
  32  * (Hypertext Transfer Protocol, see HTTP/1.1 RFC2616) in a semantically
  33  * transparent manner.
  34  *
  35  * Neither the requesting user agent (client, e.g. web browser) nor the
  36  * origin server (e.g. webserver) that provided the response cached by
  37  * NL7C are impacted in any way.
  38  *
  39  * Note, currently NL7C only processes HTTP messages via the embedded
  40  * URI of scheme http (not https nor any other), additional scheme are
  41  * intended to be supported as is practical such that much of the NL7C
  42  * framework may appear more general purpose then would be needed just
  43  * for an HTTP gateway cache.
  44  *
  45  * NL7C replaces NCA (Network Cache and Accelerator) and in the future
  46  * NCAS (NCA/SSL).
  47  *
  48  * Further, NL7C uses all NCA configuration files, see "/etc/nca/", the
  49  * NCA socket API, "AF_NCA", and "ndd /dev/nca" for backwards compatibility.
  50  */
  51 
  52 #include <sys/systm.h>
  53 #include <sys/strsun.h>
  54 #include <sys/strsubr.h>
  55 #include <inet/common.h>
  56 #include <inet/led.h>
  57 #include <inet/mi.h>
  58 #include <netinet/in.h>
  59 #include <fs/sockfs/nl7c.h>
  60 #include <fs/sockfs/nl7curi.h>
  61 #include <fs/sockfs/socktpi.h>
  62 
  63 #include <inet/nca/ncadoorhdr.h>
  64 #include <inet/nca/ncalogd.h>
  65 #include <inet/nca/ncandd.h>
  66 #include <inet/ip.h>
  67 
  68 #include <sys/promif.h>
  69 
  70 /*
  71  * NL7C, NCA, NL7C logger enabled:
  72  */
  73 
  74 boolean_t       nl7c_enabled = B_FALSE;
  75 
  76 boolean_t       nl7c_logd_enabled = B_FALSE;
  77 boolean_t       nl7c_logd_started = B_FALSE;
  78 boolean_t       nl7c_logd_cycle = B_TRUE;
  79 
  80 /*
  81  * Some externs:
  82  */



  83 extern void     nl7c_uri_init(void);
  84 extern boolean_t nl7c_logd_init(int, caddr_t *);
  85 extern void     nl7c_nca_init(void);
  86 
  87 /*
  88  * nl7c_addr_t - a singly linked grounded list, pointed to by *nl7caddrs,
  89  * constructed at init time by parsing "/etc/nca/ncaport.conf".
  90  *
  91  * This list is searched at bind(3SOCKET) time when an application doesn't
  92  * explicitly set AF_NCA but instead uses AF_INET, if a match is found then
  93  * the underlying socket is marked sti_nl7c_flags NL7C_ENABLED.
  94  */
  95 
  96 typedef struct nl7c_addr_s {
  97         struct nl7c_addr_s *next;       /* next entry */
  98         sa_family_t     family;         /* addr type, only INET and INET6 */
  99         uint16_t        port;           /* port */
 100         union {
 101                 ipaddr_t        v4;     /* IPv4 address */
 102                 in6_addr_t      v6;     /* IPv6 address */


 316         if (strcmp(s, "*") == 0) {
 317                 /* INADDR_ANY */
 318                 p->family = AF_INET;
 319                 return (0);
 320         }
 321         if (strcmp(s, "::") == 0) {
 322                 /* IN6ADDR_ANY */
 323                 p->family = AF_INET6;
 324                 return (0);
 325         }
 326         /* IPv4 address ? */
 327         if (inet_pton(AF_INET, s, &p->addr.v4) != 1) {
 328                 /* Nop, IPv6 address ? */
 329                 if (inet_pton(AF_INET6, s, &p->addr.v6) != 1) {
 330                         /* Nop, return error */
 331                         return (1);
 332                 }
 333                 p->family = AF_INET6;
 334         } else {
 335                 p->family = AF_INET;

 336         }
 337 
 338         return (0);
 339 }
 340 
 341 /*
 342  * Open and read each line from "/etc/nca/ncaport.conf", the syntax of a
 343  * ncaport.conf file line is:
 344  *
 345  *      ncaport=IPaddr/Port[/Proxy]
 346  *
 347  * Where:
 348  *
 349  * ncaport - the only token recognized.
 350  *
 351  *  IPaddr - an IPv4 numeric dot address (e.g. 192.168.84.71) or '*' for
 352  *           INADDR_ANY, or an IPv6 numeric address or "::" for IN6ADDR_ANY.
 353  *
 354  *       / - IPaddr/Port separator.
 355  *
 356  *    Port - a TCP decimal port number.
 357  *