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 2007 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 #ifndef _INETSVC_H 27 #define _INETSVC_H 28 29 #pragma ident "%Z%%M% %I% %E% SMI" 30 31 #include <libscf.h> 32 #include <sys/socket.h> 33 #include <libuutil.h> 34 #include <rpc/rpc.h> 35 36 /* 37 * Interfaces shared by usr.lib/inetd and its administrative commands. 38 */ 39 40 #ifdef __cplusplus 41 extern "C" { 42 #endif 43 44 #define PROTO_DELIMITERS " ," 45 46 #define INETD_UDS_PATH "/var/run/.inetd.uds" 47 #define INETD_INSTANCE_FMRI "svc:/network/inetd:default" 48 49 #define PG_NAME_SERVICE_CONFIG "inetd" 50 #define PG_NAME_SERVICE_DEFAULTS "defaults" 51 #define PG_NAME_INETCONV "inetconv" 52 53 #define PR_SVC_NAME_NAME "name" 54 #define PR_SOCK_TYPE_NAME "endpoint_type" 55 #define PR_PROTO_NAME "proto" 56 #define PR_ISRPC_NAME "isrpc" 57 #define PR_RPC_LW_VER_NAME "rpc_low_version" 58 #define PR_RPC_HI_VER_NAME "rpc_high_version" 59 #define PR_ISWAIT_NAME "wait" 60 #define PR_CON_RATE_MAX_NAME "max_con_rate" 61 #define PR_CON_RATE_OFFLINE_NAME "con_rate_offline" 62 #define PR_BIND_ADDR_NAME "bind_addr" 63 #define PR_BIND_FAIL_MAX_NAME "bind_fail_max" 64 #define PR_BIND_FAIL_INTVL_NAME "bind_fail_interval" 65 #define PR_MAX_COPIES_NAME "max_copies" 66 #define PR_MAX_FAIL_RATE_CNT_NAME "failrate_cnt" 67 #define PR_MAX_FAIL_RATE_INTVL_NAME "failrate_interval" 68 #define PR_INHERIT_ENV_NAME "inherit_env" 69 #define PR_DO_TCP_WRAPPERS_NAME "tcp_wrappers" 70 #define PR_DO_TCP_TRACE_NAME "tcp_trace" 71 #define PR_AUTO_CONVERTED_NAME "converted" 72 #define PR_VERSION_NAME "version" 73 #define PR_SOURCE_LINE_NAME "source_line" 74 #define PR_CONNECTION_BACKLOG_NAME "connection_backlog" 75 76 /* 77 * Provide index values for inetd property locations in the property table, for 78 * convenience. If the array is modified, these values MUST be updated. 79 */ 80 #define PT_SVC_NAME_INDEX 0 81 #define PT_SOCK_TYPE_INDEX 1 82 #define PT_PROTO_INDEX 2 83 #define PT_ISRPC_INDEX 3 84 #define PT_RPC_LW_VER_INDEX 4 85 #define PT_RPC_HI_VER_INDEX 5 86 #define PT_ISWAIT_INDEX 6 87 #define PT_EXEC_INDEX 7 88 #define PT_ARG0_INDEX 8 89 #define PT_USER_INDEX 9 90 #define PT_BIND_ADDR_INDEX 10 91 #define PT_BIND_FAIL_MAX_INDEX 11 92 #define PT_BIND_FAIL_INTVL_INDEX 12 93 #define PT_CON_RATE_MAX_INDEX 13 94 #define PT_MAX_COPIES_INDEX 14 95 #define PT_CON_RATE_OFFLINE_INDEX 15 96 #define PT_MAX_FAIL_RATE_CNT_INDEX 16 97 #define PT_MAX_FAIL_RATE_INTVL_INDEX 17 98 #define PT_INHERIT_ENV_INDEX 18 99 #define PT_DO_TCP_TRACE_INDEX 19 100 #define PT_DO_TCP_WRAPPERS_INDEX 20 101 #define PT_CONNECTION_BACKLOG_INDEX 21 102 103 /* 104 * Names of method properties. 105 */ 106 #define PR_EXEC_NAME "exec" 107 #define PR_ARG0_NAME "arg0" 108 #define PR_USER_NAME "user" 109 110 /* 111 * Method property group names. 112 */ 113 #define START_METHOD_NAME "inetd_start" 114 #define OFFLINE_METHOD_NAME "inetd_offline" 115 #define ONLINE_METHOD_NAME "inetd_online" 116 #define DISABLE_METHOD_NAME "inetd_disable" 117 #define REFRESH_METHOD_NAME "inetd_refresh" 118 119 /* 120 * Valid socket type values. 121 */ 122 #define SOCKTYPE_STREAM_STR "stream" 123 #define SOCKTYPE_DGRAM_STR "dgram" 124 #define SOCKTYPE_RAW_STR "raw" 125 #define SOCKTYPE_SEQPKT_STR "seqpacket" 126 #define SOCKTYPE_TLI_STR "tli" 127 #define SOCKTYPE_XTI_STR "xti" 128 129 /* 130 * Valid socket based service protocols. 131 */ 132 #define SOCKET_PROTO_SCTP6 "sctp6" 133 #define SOCKET_PROTO_SCTP6_ONLY "sctp6only" 134 #define SOCKET_PROTO_SCTP "sctp" 135 #define SOCKET_PROTO_TCP6 "tcp6" 136 #define SOCKET_PROTO_TCP6_ONLY "tcp6only" 137 #define SOCKET_PROTO_TCP "tcp" 138 #define SOCKET_PROTO_UDP6 "udp6" 139 #define SOCKET_PROTO_UDP6_ONLY "udp6only" 140 #define SOCKET_PROTO_UDP "udp" 141 142 /* 143 * Return codes for the methods of inetd managed services. 144 */ 145 #define IMRET_SUCCESS 0 146 /* 147 * Set this value above the range used by unix commands so theres minimal chance 148 * of a non-GL cognizant command accidentally returning this code. 149 */ 150 #define IMRET_FAILURE 100 151 152 /* 153 * Macros for differentiating between sockaddr_in & sockaddr_in6 when 154 * dealing with the contents of a sockaddr_storage structure. 155 * These differentiate based on the contents of ss_family (either AF_INET 156 * or AF_INET6). 157 */ 158 #define SS_ADDRLEN(s) ((s).ss_family == AF_INET ? \ 159 sizeof (struct sockaddr_in) : sizeof (struct sockaddr_in6)) 160 #define SS_PORT(s) ((s).ss_family == AF_INET ? \ 161 ((struct sockaddr_in *)&(s))->sin_port : \ 162 ((struct sockaddr_in6 *)&(s))->sin6_port) 163 #define SS_SETPORT(s, port) ((s).ss_family == AF_INET ? \ 164 (((struct sockaddr_in *)&(s))->sin_port = port) : \ 165 (((struct sockaddr_in6 *)&(s))->sin6_port = port)) 166 #define SS_SINADDR(s) ((s).ss_family == AF_INET ? \ 167 ((void *) &(((struct sockaddr_in *)&(s))->sin_addr)) : \ 168 ((void *) &(((struct sockaddr_in6 *)&(s))->sin6_addr))) 169 170 /* Collection of information pertaining to rpc based services. */ 171 typedef struct { 172 struct netbuf netbuf; 173 int prognum; 174 int lowver; 175 int highver; 176 char *netid; 177 boolean_t is_loopback; 178 } rpc_info_t; 179 180 /* 181 * Structure containing the common elements of both the socket_info_t and the 182 * tlx_info_t structures. 183 */ 184 typedef struct { 185 /* proto string causing this entry */ 186 char *proto; 187 188 /* network fd we're listening on; -1 if not listening */ 189 int listen_fd; 190 191 /* associate RPC info structure, if any (NULL if none). */ 192 rpc_info_t *ri; 193 194 uu_list_node_t link; 195 196 /* should this fd have the v6 socket option set? */ 197 boolean_t v6only; 198 } proto_info_t; 199 200 201 /* TLI/XTI connection indication list construct. */ 202 typedef struct { 203 struct t_call *call; 204 uu_list_node_t link; 205 } tlx_conn_ind_t; 206 207 /* Collection of information pertaining to tli/xti based services. */ 208 typedef struct { 209 /* protocol information common to tlx and socket based services */ 210 proto_info_t pr_info; 211 212 /* address we're bound to */ 213 struct netbuf local_addr; 214 215 /* device name supplied to t_open() */ 216 char *dev_name; 217 218 /* queue of pending connection indications */ 219 uu_list_t *conn_ind_queue; 220 } tlx_info_t; 221 222 /* Collection of information pertaining to socket based services. */ 223 typedef struct { 224 /* protocol information common to tlx and socket based services */ 225 proto_info_t pr_info; 226 227 /* address we're bound to */ 228 struct sockaddr_storage local_addr; 229 230 /* SOCK_STREAM/SOCK_DGRAM/SOCK_RAW/SOCK_SEQPACKET */ 231 int type; 232 233 int protocol; 234 } socket_info_t; 235 236 /* Basic configuration properties for an instance. */ 237 typedef struct { 238 /* getservbyname() recognized service name */ 239 char *svc_name; 240 241 /* TLI/XTI type service ? */ 242 boolean_t istlx; 243 244 /* list of protocols and associated info */ 245 uu_list_t *proto_list; 246 247 /* wait type service ? */ 248 boolean_t iswait; 249 250 /* 251 * Properties from here onwards all have default values in the inetd 252 * service instance. 253 */ 254 255 boolean_t do_tcp_wrappers; 256 boolean_t do_tcp_trace; 257 258 /* inherit inetd's environment, or take an empty one */ 259 boolean_t inherit_env; 260 261 /* failure rate configuration */ 262 int64_t wait_fail_cnt; 263 int wait_fail_interval; 264 265 /* maximum concurrent copies limit */ 266 int64_t max_copies; 267 268 /* connection rate configuration */ 269 int conn_rate_offline; 270 int64_t conn_rate_max; 271 272 /* bind failure retries configuration */ 273 int bind_fail_interval; 274 int64_t bind_fail_max; 275 276 /* specific address to bind instance to */ 277 char *bind_addr; 278 279 /* connection backlog queue size */ 280 int64_t conn_backlog; 281 } basic_cfg_t; 282 283 typedef enum uds_request { 284 UR_REFRESH_INETD, 285 UR_STOP_INETD 286 } uds_request_t; 287 288 typedef union { 289 int64_t iv_int; 290 uint64_t iv_cnt; 291 boolean_t iv_boolean; 292 char *iv_string; 293 char **iv_string_list; 294 } inetd_value_t; 295 296 typedef enum { 297 IVE_VALID, 298 IVE_UNSET, 299 IVE_INVALID 300 } iv_error_t; 301 302 /* 303 * Operations on these types (like valid_default_prop()) need to be modified 304 * when this list is changed. 305 */ 306 typedef enum { 307 INET_TYPE_INVALID = 0, 308 309 INET_TYPE_BOOLEAN, 310 INET_TYPE_COUNT, 311 INET_TYPE_INTEGER, 312 INET_TYPE_STRING, 313 INET_TYPE_STRING_LIST 314 } inet_type_t; 315 316 typedef struct { 317 const char *ip_name; 318 const char *ip_pg; 319 inet_type_t ip_type; 320 boolean_t ip_default; 321 iv_error_t ip_error; 322 inetd_value_t ip_value; 323 boolean_t from_inetd; 324 } inetd_prop_t; 325 326 inetd_prop_t *get_prop_table(size_t *); 327 inetd_prop_t *find_prop(const inetd_prop_t *, const char *, inet_type_t); 328 int64_t get_prop_value_int(const inetd_prop_t *, const char *); 329 uint64_t get_prop_value_count(const inetd_prop_t *, const char *); 330 boolean_t get_prop_value_boolean(const inetd_prop_t *, const char *); 331 const char *get_prop_value_string(const inetd_prop_t *, const char *); 332 const char **get_prop_value_string_list(const inetd_prop_t *, const char *); 333 void put_prop_value_int(inetd_prop_t *, const char *, int64_t); 334 void put_prop_value_count(inetd_prop_t *, const char *, uint64_t); 335 void put_prop_value_boolean(inetd_prop_t *, const char *, boolean_t); 336 boolean_t put_prop_value_string(inetd_prop_t *, const char *, const char *); 337 void put_prop_value_string_list(inetd_prop_t *, const char *, char **); 338 boolean_t valid_props(inetd_prop_t *, const char *fmri, basic_cfg_t **, 339 uu_list_pool_t *, uu_list_pool_t *); 340 void destroy_basic_cfg(basic_cfg_t *); 341 void destroy_proto_list(basic_cfg_t *); 342 boolean_t valid_default_prop(const char *, const void *); 343 scf_error_t read_prop(scf_handle_t *, inetd_prop_t *, int, const char *, 344 const char *); 345 inetd_prop_t *read_instance_props(scf_handle_t *, const char *, size_t *, 346 scf_error_t *); 347 inetd_prop_t *read_default_props(scf_handle_t *, size_t *, scf_error_t *); 348 void free_instance_props(inetd_prop_t *); 349 int connect_to_inetd(void); 350 int refresh_inetd(void); 351 int get_sock_type_id(const char *); 352 int get_rpc_prognum(const char *); 353 int calculate_hash(const char *, char **); 354 scf_error_t retrieve_inetd_hash(char **); 355 scf_error_t store_inetd_hash(const char *); 356 const char *inet_ntop_native(int, const void *, char *, size_t); 357 void setproctitle(const char *, int, char **); 358 void dg_template( 359 void (*)(int, const struct sockaddr *, int, const void *, size_t), int, 360 void *, size_t); 361 int safe_write(int, const void *, size_t); 362 int safe_sendto(int, const void *, size_t, int, const struct sockaddr *, int); 363 char **get_protos(const char *); 364 char **get_netids(char *); 365 void destroy_strings(char **); 366 367 #ifdef __cplusplus 368 } 369 #endif 370 371 #endif /* _INETSVC_H */ 372