/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2015 Nexenta Systems, Inc. All rights reserved.
*/
#include <sys/sysmacros.h>
#include <sys/socketvar.h>
/*
* Socket Parameters
*
* Socket parameter (struct sockparams) entries represent the socket types
* available on the system.
*
* Flags (sp_flags):
*
* SOCKPARAMS_EPHEMERAL: A temporary sockparams entry that will be deleted
* as soon as its' ref count drops to zero. In addition, ephemeral entries will
* never be hooked onto the global sockparams list. Ephemeral entries are
* created when application requests to create a socket using an application
* supplied device path, or when a socket is falling back to TPI.
*
* Lock order:
* The lock order is sockconf_lock -> sp_lock.
*/
extern int kobj_path_exists(char *, int);
static int sockparams_sdev_init(struct sockparams *, char *, int);
static void sockparams_sdev_fini(struct sockparams *);
/*
* Global sockparams list (populated via soconfig(1M)).
*/
/*
* List of ephemeral sockparams.
*/
/* Global kstats for sockparams */
typedef struct sockparams_g_stats {
void
sockparams_init(void)
{
if (sp_g_kstat == NULL)
return;
}
static int
{
if (rw == KSTAT_WRITE)
return (EACCES);
return (0);
}
/*
* Setup kstats for the given sockparams entry.
*/
static void
{
sizeof (sockparams_stats_t) / sizeof (kstat_named_t),
return;
}
static void
{
}
}
/*
* sockparams_create(int family, int type, int protocol, char *modname,
* char *devpath, int devpathlen, int flags, int kmflags, int *errorp)
*
* Create a new sockparams entry.
*
* Arguments:
* family, type, protocol: specifies the socket type
* modname: Name of the module associated with the socket type. The
* module can be NULL if a device path is given, in which
* case the TPI module is used.
* devpath: Path to the STREAMS device. Must be NULL for non-STREAMS
* based transports.
* devpathlen: Length of the devpath string. The argument can be 0,
* indicating that devpath was allocated statically, and should
* not be freed when the sockparams entry is destroyed.
*
* flags : SOCKPARAMS_EPHEMERAL is the only flag that is allowed.
* kmflags: KM_{NO,}SLEEP
* errorp : Value-return argument, set when an error occurs.
*
* Returns:
* On success a new sockparams entry is returned, and *errorp is set
* to 0. On failure NULL is returned and *errorp is set to indicate the
* type of error that occured.
*
* Notes:
* devpath and modname are freed upon failure.
*/
struct sockparams *
{
if (flags & ~SOCKPARAMS_EPHEMERAL) {
goto error;
}
/* either a module or device must be given, but not both */
goto error;
}
goto error;
}
/*
* Track how many ephemeral entries we have created.
*/
} else {
goto error;
}
}
/* Set up the device entry. */
if (*errorp != 0)
goto error;
}
*errorp = 0;
return (sp);
if (devpathlen != 0)
return (NULL);
}
/*
* Initialize the STREAMS device aspect of the sockparams entry.
*/
static int
{
int error;
dprint(0, ("sockparams_sdev_init: vp %s failed with %d\n",
return (error);
}
return (0);
}
/*
* sockparams_destroy(struct sockparams *sp)
*
* Releases all the resources associated with the sockparams entry,
* and frees the sockparams entry.
*
* Arguments:
* sp: the sockparams entry to destroy.
*
* Returns:
* Nothing.
*
* Locking:
* The sp_lock of the entry can not be held.
*/
void
{
}
/*
* Clean up the STREAMS device part of the sockparams entry.
*/
static void
{
/*
* if the entry does not have a STREAMS device, then there
* is nothing to do.
*/
if (!SOCKPARAMS_HAS_DEVICE(sp))
return;
if (sd.sd_devpathlen != 0)
}
/*
* Look for a matching sockparams entry on the given list.
* The caller must hold the associated list lock.
*/
static struct sockparams *
{
break;
else if (by_devpath &&
name) == 0)
break;
break;
}
}
}
return (sp);
}
/*
* sockparams_hold_ephemeral()
*
* Returns an ephemeral sockparams entry of the requested family, type and
* protocol. The entry is returned held, and the caller is responsible for
* dropping the reference using SOCKPARAMS_DEC_REF() once done.
*
* All ephemeral entries are on list (sp_ephem_list). If there is an
* entry on the list that match the search criteria, then a reference is
* placed on that entry. Otherwise, a new entry is created and inserted
* in the list. The entry is removed from the list when the last reference
* is dropped.
*
* The tpi flag is used to determine whether name refers to a device or
* module name.
*/
static struct sockparams *
{
*errorp = 0;
/*
* First look for an existing entry
*/
by_devpath, name);
return (sp);
} else {
int namelen = 0;
return (NULL);
}
if (by_devpath) {
} else {
}
return (NULL);
}
/*
* Time to load the socket module.
*/
/* Failed to load */
return (NULL);
}
/*
* The sockparams entry was created, now try to add it
* to the list. We need to hold the lock as a WRITER.
*/
by_devpath, name);
/*
* Someone has requested a matching entry, so just
* place a hold on it and release the entry we alloc'ed.
*/
} else {
if (*errorp != 0) {
return (NULL);
}
}
return (sp);
}
}
struct sockparams *
{
}
struct sockparams *
{
}
/*
* Called when the last socket using the ephemeral entry is dropping
* its' reference. To maintain lock order we must drop the sockparams
* lock before calling this function. As a result, a new reference
* might be placed on the entry, in which case there is nothing to
* do. However, if ref count goes to zero, we delete the entry.
*/
void
{
} else {
}
}
/*
* sockparams_add(struct sockparams *sp)
*
* Tries to add the given sockparams entry to the global list.
*
* Arguments:
* sp: the sockparms entry to add
*
* Returns:
* On success 0, but if an entry already exists, then EEXIST
* is returned.
*
* Locking:
* The caller can not be holding sockconf_lock.
*/
int
{
int error;
return (EEXIST);
} else {
/*
* Unique sockparams entry, so init the kstats.
*/
/*
* Before making the socket type available we must make
* sure that interested socket filters are aware of it.
*/
if (error != 0) {
return (error);
}
return (0);
}
}
/*
* sockparams_delete(int family, int type, int protocol)
*
* Marks the sockparams entry for a specific family, type and protocol
* for deletion. The entry is removed from the list and destroyed
* if no one is holding a reference to it.
*
* Arguments:
* family, type, protocol: the socket type that should be removed.
*
* Returns:
* On success 0, otherwise ENXIO.
*
* Locking:
* Caller can not be holding sockconf_lock or the sp_lock of
* any sockparams entry.
*/
int
{
/*
* If no one is holding a reference to the entry, then
* we go ahead and remove it from the list and then
* destroy it.
*/
return (EBUSY);
}
/* Delete the sockparams entry. */
return (0);
} else {
return (ENXIO);
}
}
/*
* solookup(int family, int type, int protocol, struct sockparams **spp)
*
* Lookup an entry in the sockparams list based on the triple. The returned
* entry either exactly match the given tuple, or it is the 'default' entry
* for the given <family, type>. A default entry is on with a protocol
* value of zero.
*
* Arguments:
* family, type, protocol: tuple to search for
* spp: Value-return argument
*
* Returns:
* If an entry is found, 0 is returned and *spp is set to point to the
* entry. In case an entry is not found, *spp is set to NULL, and an
* error code is returned. The errors are (in decreasing precedence):
* EAFNOSUPPORT - address family not in list
* EPROTONOSUPPORT - address family supported but not protocol.
* EPROTOTYPE - address family and protocol supported but not socket type.
*
* TODO: should use ddi_modopen()/ddi_modclose()
*/
int
{
int error = 0;
/*
* Search the sockparams list for an appropiate entry.
* Hopefully we find an entry that match the exact family,
* type and protocol specified by the user, in which case
* we return that entry. However, we also keep track of
* the default entry for a specific family and type, the
* entry of which would have a protocol value of 0.
*/
int found = 0;
/* Determine correct error code */
found = 1;
found = 2;
}
switch (found) {
case 0:
break;
case 1:
break;
case 2:
error = EPROTOTYPE;
break;
}
return (error);
}
/*
* An entry was found.
*
* We put a hold on the entry early on, so if the
* sockmod is not loaded, and we have to exit
* sockconf_lock to call modload(), we know that the
* sockparams entry wont go away. That way we don't
* have to look up the entry once we come back from
* modload().
*/
/*
* We put a hold on the sockparams entry
* earlier, hoping everything would work out.
* That obviously did not happen, so release
* the hold here.
*/
/*
* We should probably mark the sockparams as
* "bad", and redo the lookup skipping the
* "bad" entries. I.e., sp->sp_mod_state |= BAD,
* return (solookup(...))
*/
return (ENXIO);
}
/*
* Another thread might have already looked up the socket
* module for this entry. In that case we need to drop our
* reference to `smod' to ensure that the sockparams entry
* only holds one reference.
*/
else
}
/*
* Alright, we have a valid sockparams entry.
*/
return (0);
}
/*
* Called when filter entry `ent' is going away. All sockparams remove
* their references to `ent'.
*/
static void
{
break;
}
}
}
}
void
{
}
/*
* New filter is being added; walk the list of sockparams to see if
* the filter is interested in any of the sockparams.
*/
static int
{
int err;
return (err);
}
}
return (0);
}
int
{
int error;
return (error);
return (error);
}
/*
* Setup and return socket configuration table.
*/
int
{
uint_t i = 0;
int ret = 0;
STRUCT_SIZE(st), 0) != 0)
return (EFAULT);
/*
* If the output buffer is size zero, just copy out the count.
*/
if (count == 0) {
count++;
}
STRUCT_SIZE(st), 0) != 0)
return (EFAULT);
return (0);
}
KM_SLEEP);
if (i >= count) {
/*
* Return if the number of entries has changed.
*/
count * sizeof (sockconfig_socktable_entry_t));
return (EAGAIN);
}
i++;
}
i * sizeof (sockconfig_socktable_entry_t), 0) != 0)
STRUCT_SIZE(st), 0) != 0)
return (ret);
}