Print this page
OS-5007 support SO_ATTACH_FILTER on ICMP sockets
Reviewed by: Cody Mello <melloc@joyent.com>
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Approved by: Jerry Jelinek <jerry.jelinek@joyent.com>


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

  24  */
  25 
  26 #include <sys/types.h>
  27 #include <sys/stream.h>
  28 #define _SUN_TPI_VERSION 2
  29 #include <sys/tihdr.h>
  30 #include <sys/socket.h>
  31 #include <sys/xti_xtiopt.h>
  32 #include <sys/xti_inet.h>
  33 
  34 #include <netinet/in.h>
  35 #include <netinet/icmp6.h>
  36 #include <inet/common.h>
  37 #include <netinet/ip6.h>
  38 #include <inet/ip.h>
  39 
  40 #include <netinet/tcp.h>
  41 #include <netinet/ip_mroute.h>
  42 #include <inet/optcom.h>
  43 #include <inet/rawip_impl.h>

  44 
  45 /*
  46  * Table of all known options handled on a ICMP protocol stack.
  47  *
  48  * Note: This table contains options processed by both ICMP and IP levels
  49  *       and is the superset of options that can be performed on a ICMP over IP
  50  *       stack.
  51  */
  52 opdes_t icmp_opt_arr[] = {
  53 
  54 { SO_DEBUG,     SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
  55 { SO_DONTROUTE, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
  56 { SO_USELOOPBACK, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0
  57         },
  58 { SO_BROADCAST, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
  59 { SO_REUSEADDR, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
  60 
  61 #ifdef  SO_PROTOTYPE
  62         /*
  63          * icmp will only allow IPPROTO_ICMP for non-privileged streams


  69 { SO_TYPE,      SOL_SOCKET, OA_R, OA_R, OP_NP, 0, sizeof (int), 0 },
  70 { SO_SNDBUF,    SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
  71 { SO_RCVBUF,    SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
  72 { SO_SNDTIMEO,  SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0,
  73         sizeof (struct timeval), 0 },
  74 { SO_RCVTIMEO,  SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0,
  75         sizeof (struct timeval), 0 },
  76 { SO_DGRAM_ERRIND, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int),
  77         0 },
  78 { SO_TIMESTAMP, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0
  79         },
  80 { SO_MAC_EXEMPT, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int),
  81         0 },
  82 { SO_MAC_IMPLICIT, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int),
  83         0 },
  84 
  85 { SO_ALLZONES, SOL_SOCKET, OA_R, OA_RW, OP_CONFIG, 0, sizeof (int),
  86         0 },
  87 { SO_DOMAIN,    SOL_SOCKET, OA_R, OA_R, OP_NP, 0, sizeof (int), 0 },
  88 




  89 { IP_OPTIONS,   IPPROTO_IP, OA_RW, OA_RW, OP_NP,
  90         (OP_VARLEN|OP_NODEFAULT),
  91         IP_MAX_OPT_LENGTH + IP_ADDR_LEN, -1 /* not initialized */ },
  92 { T_IP_OPTIONS, IPPROTO_IP, OA_RW, OA_RW, OP_NP,
  93         (OP_VARLEN|OP_NODEFAULT),
  94         IP_MAX_OPT_LENGTH + IP_ADDR_LEN, -1 /* not initialized */ },
  95 
  96 { IP_HDRINCL,   IPPROTO_IP, OA_R,  OA_RW, OP_RAW, 0,
  97         sizeof (int), 0 },
  98 { IP_TOS,       IPPROTO_IP, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
  99 { T_IP_TOS,     IPPROTO_IP, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
 100 { IP_TTL,       IPPROTO_IP, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
 101 
 102 { IP_MULTICAST_IF, IPPROTO_IP, OA_RW, OA_RW, OP_NP, 0,
 103         sizeof (struct in_addr), 0 /* INADDR_ANY */ },
 104 
 105 { IP_MULTICAST_LOOP, IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_DEF_FN,
 106         sizeof (uchar_t), -1 /* not initialized */},
 107 
 108 { IP_MULTICAST_TTL, IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_DEF_FN,




   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 2009 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  * Copyright 2016 Joyent, Inc.
  25  */
  26 
  27 #include <sys/types.h>
  28 #include <sys/stream.h>
  29 #define _SUN_TPI_VERSION 2
  30 #include <sys/tihdr.h>
  31 #include <sys/socket.h>
  32 #include <sys/xti_xtiopt.h>
  33 #include <sys/xti_inet.h>
  34 
  35 #include <netinet/in.h>
  36 #include <netinet/icmp6.h>
  37 #include <inet/common.h>
  38 #include <netinet/ip6.h>
  39 #include <inet/ip.h>
  40 
  41 #include <netinet/tcp.h>
  42 #include <netinet/ip_mroute.h>
  43 #include <inet/optcom.h>
  44 #include <inet/rawip_impl.h>
  45 #include <net/bpf.h>
  46 
  47 /*
  48  * Table of all known options handled on a ICMP protocol stack.
  49  *
  50  * Note: This table contains options processed by both ICMP and IP levels
  51  *       and is the superset of options that can be performed on a ICMP over IP
  52  *       stack.
  53  */
  54 opdes_t icmp_opt_arr[] = {
  55 
  56 { SO_DEBUG,     SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
  57 { SO_DONTROUTE, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
  58 { SO_USELOOPBACK, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0
  59         },
  60 { SO_BROADCAST, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
  61 { SO_REUSEADDR, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
  62 
  63 #ifdef  SO_PROTOTYPE
  64         /*
  65          * icmp will only allow IPPROTO_ICMP for non-privileged streams


  71 { SO_TYPE,      SOL_SOCKET, OA_R, OA_R, OP_NP, 0, sizeof (int), 0 },
  72 { SO_SNDBUF,    SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
  73 { SO_RCVBUF,    SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
  74 { SO_SNDTIMEO,  SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0,
  75         sizeof (struct timeval), 0 },
  76 { SO_RCVTIMEO,  SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0,
  77         sizeof (struct timeval), 0 },
  78 { SO_DGRAM_ERRIND, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int),
  79         0 },
  80 { SO_TIMESTAMP, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0
  81         },
  82 { SO_MAC_EXEMPT, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int),
  83         0 },
  84 { SO_MAC_IMPLICIT, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int),
  85         0 },
  86 
  87 { SO_ALLZONES, SOL_SOCKET, OA_R, OA_RW, OP_CONFIG, 0, sizeof (int),
  88         0 },
  89 { SO_DOMAIN,    SOL_SOCKET, OA_R, OA_R, OP_NP, 0, sizeof (int), 0 },
  90 
  91 { SO_ATTACH_FILTER,     SOL_SOCKET, OA_W, OA_W, OP_NP, 0,
  92         sizeof (struct bpf_program), 0 },
  93 { SO_DETACH_FILTER,     SOL_SOCKET, OA_W, OA_W, OP_NP, 0, 0, 0 },
  94 
  95 { IP_OPTIONS,   IPPROTO_IP, OA_RW, OA_RW, OP_NP,
  96         (OP_VARLEN|OP_NODEFAULT),
  97         IP_MAX_OPT_LENGTH + IP_ADDR_LEN, -1 /* not initialized */ },
  98 { T_IP_OPTIONS, IPPROTO_IP, OA_RW, OA_RW, OP_NP,
  99         (OP_VARLEN|OP_NODEFAULT),
 100         IP_MAX_OPT_LENGTH + IP_ADDR_LEN, -1 /* not initialized */ },
 101 
 102 { IP_HDRINCL,   IPPROTO_IP, OA_R,  OA_RW, OP_RAW, 0,
 103         sizeof (int), 0 },
 104 { IP_TOS,       IPPROTO_IP, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
 105 { T_IP_TOS,     IPPROTO_IP, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
 106 { IP_TTL,       IPPROTO_IP, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
 107 
 108 { IP_MULTICAST_IF, IPPROTO_IP, OA_RW, OA_RW, OP_NP, 0,
 109         sizeof (struct in_addr), 0 /* INADDR_ANY */ },
 110 
 111 { IP_MULTICAST_LOOP, IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_DEF_FN,
 112         sizeof (uchar_t), -1 /* not initialized */},
 113 
 114 { IP_MULTICAST_TTL, IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_DEF_FN,