/*
* 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
*
*/
/*
* IPMP query interfaces (see PSARC/2002/615 and PSARC/2007/272).
*/
#include <assert.h>
#include <errno.h>
#include <libinetutil.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include "ipmp_impl.h"
#include "ipmp_mpathd.h"
#include "ipmp_query_impl.h"
static void ipmp_freeiflist(ipmp_iflist_t *);
static void ipmp_freeaddrlist(ipmp_addrlist_t *);
struct sockaddr_storage *);
static int ipmp_querydone(ipmp_state_t *, int);
/*
* Using `statep', send a query request for `type' to in.mpathd, and if
* necessary wait until at least `endtp' for a response. Returns an IPMP
* error code. If successful, the caller may then read additional query
* information through ipmp_readinfo(), and must eventually call
* ipmp_querydone() to complete the query operation. Only one query may be
* outstanding on a given `statep' at a time.
*/
static int
{
int retval;
switch (type) {
case IPMP_ADDRINFO:
break;
case IPMP_GROUPINFO:
break;
case IPMP_IFINFO:
break;
case IPMP_GROUPLIST:
case IPMP_SNAP:
break;
default:
assert(0);
}
return (IPMP_FAILURE);
if (retval != IPMP_SUCCESS)
return (retval);
if (retval != IPMP_SUCCESS)
if (retval != IPMP_SUCCESS)
return (IPMP_SUCCESS);
}
/*
* Using `statep', read a query response of type `infotype' into a dynamically
* allocated buffer pointed to by `*infop', before the current time becomes
* `endtp'. Returns an IPMP error code.
*/
static int
{
int retval;
if (retval != IPMP_SUCCESS)
return (retval);
return (IPMP_EPROTO);
}
return (IPMP_SUCCESS);
}
/*
* Using `statep', read in the remaining IPMP group information TLVs from
* in.mpathd into `grinfop' before the current time becomes `endtp'. Returns
* an IPMP error code. On failure, `grinfop' will have its original contents.
*/
static int
{
int retval;
if (retval != IPMP_SUCCESS)
return (retval);
if (retval != IPMP_SUCCESS) {
return (retval);
}
return (IPMP_SUCCESS);
}
/*
* Using `statep', read in the remaining IPMP interface information TLVs from
* in.mpathd into `ifinfop' before the current time becomes `endtp'. Returns
* an IPMP error code. On failure, `ifinfop' will have its original contents.
*/
static int
{
int retval;
if (retval != IPMP_SUCCESS)
return (retval);
if (retval != IPMP_SUCCESS)
goto fail;
if (retval != IPMP_SUCCESS)
goto fail;
if (retval != IPMP_SUCCESS)
goto fail;
return (IPMP_SUCCESS);
fail:
return (retval);
}
/*
* Complete the query operation started in ipmp_sendquery(). The interface is
* designed to be easy to use in the `return' statement of a function, and
* thus returns the passed in `retval' and preserves `errno'.
*/
static int
{
return (retval);
}
/*
* Using `handle', get the group list and store the results in a dynamically
* allocated buffer pointed to by `*grlistpp'. Returns an IPMP error code.
*/
int
{
int retval;
}
if (retval != IPMP_SUCCESS)
return (retval);
}
/*
* Free the group list pointed to by `grlistp'.
*/
void
{
}
/*
* Using `handle', get the group information associated with group `name' and
* store the results in a dynamically allocated buffer pointed to by
* `*grinfopp'. Returns an IPMP error code.
*/
int
{
int retval;
return (IPMP_EUNKGROUP);
}
if (retval != IPMP_SUCCESS)
return (retval);
if (retval != IPMP_SUCCESS)
if (retval != IPMP_SUCCESS)
}
/*
* Free the group information pointed to by `grinfop'.
*/
void
{
}
/*
* Using `handle', get the interface information associated with interface
* `name' and store the results in a dynamically allocated buffer pointed to
* by `*ifinfopp'. Returns an IPMP error code.
*/
int
{
int retval;
return (IPMP_EUNKIF);
}
if (retval != IPMP_SUCCESS)
return (retval);
if (retval != IPMP_SUCCESS)
if (retval != IPMP_SUCCESS)
}
/*
* Free the interface information pointed to by `ifinfop'.
*/
void
{
}
/*
* Using `handle', get the address information associated with address `addrp'
* on group `grname' and store the results in a dynamically allocated buffer
* pointed to by `*adinfopp'. Returns an IPMP error code.
*/
int
{
int retval;
return (IPMP_EUNKADDR);
}
if (retval != IPMP_SUCCESS)
return (retval);
}
/*
* Free the address information pointed to by `adinfop'.
*/
void
{
}
/*
* Check if `buf' has a NUL byte in its first `bufsize' bytes.
*/
static boolean_t
{
while (bufsize-- > 0) {
return (B_TRUE);
}
return (B_FALSE);
}
/*
* Check that the TLV triplet named by `type', `len' and `value' is correctly
* formed.
*/
static boolean_t
{
unsigned int i;
switch (type) {
case IPMP_ADDRINFO:
if (len != sizeof (ipmp_addrinfo_t))
return (B_FALSE);
break;
case IPMP_ADDRLIST:
if (len < IPMP_ADDRLIST_SIZE(0) ||
return (B_FALSE);
break;
case IPMP_IFLIST:
if (len < IPMP_IFLIST_SIZE(0) ||
return (B_FALSE);
return (B_FALSE);
break;
case IPMP_IFINFO:
if (len != sizeof (ipmp_ifinfo_t))
return (B_FALSE);
return (B_FALSE);
break;
case IPMP_GROUPLIST:
if (len < IPMP_GROUPLIST_SIZE(0) ||
return (B_FALSE);
return (B_FALSE);
break;
case IPMP_GROUPINFO:
if (len != sizeof (ipmp_groupinfo_t))
return (B_FALSE);
return (B_FALSE);
break;
case IPMP_SNAP:
if (len != sizeof (ipmp_snap_t))
return (B_FALSE);
break;
default:
return (B_FALSE);
}
return (B_TRUE);
}
/*
* Create a group list; arguments match ipmp_grouplist_t fields. Returns a
* pointer to the new group list on success, or NULL on failure.
*/
char (*groups)[LIFGRNAMSIZ])
{
unsigned int i;
return (NULL);
for (i = 0; i < ngroup; i++)
return (grlistp);
}
/*
* Clone the group list named by `grlistp'. Returns a pointer to the clone on
* success, or NULL on failure.
*/
{
}
/*
* Create target information; arguments match ipmp_targinfo_t fields. Returns
* a pointer to the new target info on success, or NULL on failure.
*/
{
return (NULL);
return (NULL);
}
if (targmode == IPMP_TARG_TRANSITIVE) {
return (NULL);
}
}
return (targinfop);
}
/*
* Free the target information pointed to by `targinfop'.
*/
void
{
}
/*
* Create an interface list; arguments match ipmp_iflist_t fields. Returns a
* pointer to the new interface list on success, or NULL on failure.
*/
static ipmp_iflist_t *
{
unsigned int i;
return (NULL);
for (i = 0; i < nif; i++)
return (iflistp);
}
static ipmp_iflist_t *
{
return (NULL);
}
/*
* Free the interface list pointed to by `iflistp'.
*/
static void
{
}
/*
* Create an interface; arguments match ipmp_ifinfo_t fields. Returns a
* pointer to the new interface on success, or NULL on failure.
*/
{
return (NULL);
return (NULL);
}
return (ifinfop);
}
/*
* Clone the interface information named by `ifinfop'. Returns a pointer to
* the clone on success, or NULL on failure.
*/
{
&ifinfop->if_targinfo6));
}
/*
* Create a group; arguments match ipmp_groupinfo_t fields. Returns a pointer
* to the new group on success, or NULL on failure.
*/
{
return (NULL);
return (NULL);
}
return (grinfop);
}
/*
* Clone the group information named by `grinfop'. Returns a pointer to
* the clone on success, or NULL on failure.
*/
{
}
/*
* Create an address list; arguments match ipmp_addrlist_t fields. Returns
* a pointer to the new address list on success, or NULL on failure.
*/
static ipmp_addrlist_t *
{
unsigned int i;
return (NULL);
for (i = 0; i < naddr; i++)
return (adlistp);
}
/*
* Clone the address list named by `adlistp'. Returns a pointer to the clone
* on success, or NULL on failure.
*/
static ipmp_addrlist_t *
{
}
/*
* Free the address list pointed to by `adlistp'.
*/
static void
{
}
/*
* Create an address; arguments match ipmp_addrinfo_t fields. Returns a
* pointer to the new address on success, or NULL on failure.
*/
{
return (NULL);
return (adinfop);
}
/*
* Clone the address information named by `adinfop'. Returns a pointer to
* the clone on success, or NULL on failure.
*/
{
}
/*
* Set the query context associated with `handle' to `qcontext', which must be
* either IPMP_QCONTEXT_LIVE or IPMP_QCONTEXT_SNAP. Upon success, any
* previous snapshot associated with `handle' is discarded. Returns an IPMP
* error code.
*/
int
{
int retval;
switch (qcontext) {
case IPMP_QCONTEXT_LIVE:
break;
case IPMP_QCONTEXT_SNAP:
if (retval != IPMP_SUCCESS)
return (retval);
break;
default:
return (IPMP_EINVAL);
}
return (IPMP_SUCCESS);
}
/*
* Create an empty snapshot. Returns a pointer to the snapshot on success,
* or NULL on failure.
*/
ipmp_snap_create(void)
{
return (NULL);
return (snap);
}
/*
* Free all of the resources associated with snapshot `snap'.
*/
void
{
}
}
}
}
/*
* Add the group information in `grinfop' to the snapshot named by `snap'.
* Returns an IPMP error code.
*/
int
{
/*
* If the information for this group is already in the snapshot,
* in.mpathd is broken.
*/
return (IPMP_EPROTO);
return (IPMP_ENOMEM);
return (IPMP_SUCCESS);
}
/*
* Add the interface information in `ifinfop' to the snapshot named by `snap'.
* Returns an IPMP error code.
*/
int
{
/*
* If the information for this interface is already in the snapshot,
* in.mpathd is broken.
*/
return (IPMP_EPROTO);
return (IPMP_ENOMEM);
return (IPMP_SUCCESS);
}
/*
* Add the address information in `adinfop' to the snapshot named by `snap'.
* Returns an IPMP error code.
*/
int
{
/*
* Any duplicate addresses should've already been weeded by in.mpathd.
*/
return (IPMP_EPROTO);
return (IPMP_ENOMEM);
return (IPMP_SUCCESS);
}
/*
* Retrieve the information for the group `name' in snapshot `snap'.
* Returns a pointer to the group information on success, or NULL on failure.
*/
static ipmp_groupinfo_t *
{
break;
}
}
/*
* Retrieve the information for the interface `name' in snapshot `snap'.
* Returns a pointer to the interface information on success, or NULL on
* failure.
*/
static ipmp_ifinfo_t *
{
break;
}
}
/*
* Retrieve the information for the address `addrp' on group `grname' in
* snapshot `snap'. Returns a pointer to the address information on success,
* or NULL on failure.
*/
static ipmp_addrinfo_t *
struct sockaddr_storage *addrp)
{
break;
}
}
/*
* Using `statep', take a snapshot of the IPMP subsystem and if successful
* return it in a dynamically allocated snapshot pointed to by `*snapp'.
* Returns an IPMP error code.
*/
static int
{
int retval;
void *infop;
snap = ipmp_snap_create();
return (IPMP_ENOMEM);
if (retval != IPMP_SUCCESS) {
return (retval);
}
if (retval != IPMP_SUCCESS) {
}
/*
* Using the information in the `osnap' snapshot, build up our own
* snapshot. We know there will always be at least one TLV (for
* IPMP_GROUPLIST). If we receive anything illogical (e.g., more than
* the expected number of interfaces), then bail out. However, to a
* large extent we have to trust the information sent by in.mpathd.
*/
do {
if (retval != IPMP_SUCCESS)
goto fail;
goto fail;
}
switch (type) {
case IPMP_GROUPLIST:
break;
}
break;
case IPMP_IFINFO:
break;
}
/*
* Read in V4 and V6 targlist TLVs that follow.
*/
if (retval != IPMP_SUCCESS)
break;
if (retval != IPMP_SUCCESS) {
}
break;
case IPMP_ADDRINFO:
break;
}
/*
* NOTE: since we didn't call ipmp_read*info_lists(),
* no need to use ipmp_freeaddrinfo() on failure.
*/
break;
case IPMP_GROUPINFO:
break;
}
/*
* Read in IPMP groupinfo list TLVs that follow.
*/
if (retval != IPMP_SUCCESS)
break;
if (retval != IPMP_SUCCESS) {
}
break;
default:
break;
}
fail:
if (retval != IPMP_SUCCESS) {
}
}