/*
* 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 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <libilb.h>
#include <stddef.h>
#include <stdlib.h>
#include <strings.h>
#include <errno.h>
#include <assert.h>
#include <macros.h>
#include "libilb_impl.h"
#include "ilbd.h"
/*
* there is no lock for this since ilbd is single threaded. And we only care
* about the pointer value of client, not its type.
*
* The following variables store the current client making the request.
*/
static void *nat_cur_cli;
static void *sticky_cur_cli;
/*
* Clear the current requesting client. This will allow a new client
* to make a request.
*/
void
ilbd_show_nat_cleanup(void)
{
nat_cur_cli = NULL;
}
void
ilbd_show_sticky_cleanup(void)
{
}
/*
* To show the kernel NAT table.
*
* cli: the client pointer making the request.
* ic: the client request.
* rbuf: reply buffer to be filled in.
* rbufsz: reply buffer size.
*/
{
int i;
/* For new client request, start from the beginning of the table. */
if (nat_cur_cli == NULL) {
nat_cur_cli = cli;
} else if (cli == nat_cur_cli) {
/*
* Another request from client. If the client does not
* want to continue, reset the current client and reply OK.
*/
return (ILB_STATUS_OK);
}
} else {
/* A request is on-going, so reject a new client. */
return (ILB_STATUS_INPROGRESS);
}
tmp_rbufsz = *rbufsz;
/*
* Calculate the max number of ilb_nat_info_t can be fitted in the
* reply.
*/
*rbufsz += sizeof (ilb_show_info_t *);
tmp_rbufsz -= *rbufsz;
/*
* Calculate the exact number of entries we should request from kernel.
*/
logdebug("ilbd_show_nat: malloc(cmd)");
return (ILB_STATUS_ENOMEM);
}
logperror("ilbd_show_nat: ioctl(ILB_LIST_NAT_TABLE)");
return (ret);
}
/*
* It is the end of table, let the client know. And the transaction
* is done.
*/
nat_cur_cli = NULL;
} else {
/*
* ilbd_reply_ok() sets ic_flags to ILB_COMM_END by default.
* Need to clear it here.
*/
}
nat_ret++;
}
end:
return (ret);
}
/*
* To show the kernel sticky table.
*
* cli: the client pointer making the request.
* req_si: information about the show-persist request.
* rbuf: reply buffer to be filled in.
* rbufsz: reply buffer size.
*/
{
int i;
/* For new client request, start from the beginning of the table. */
if (sticky_cur_cli == NULL) {
} else if (cli == sticky_cur_cli) {
/*
* Another request from client. If the client does not
* want to continue, reset the current client and reply OK.
*/
return (ILB_STATUS_OK);
}
} else {
/* A request is on-going, so reject a new client. */
return (ILB_STATUS_INPROGRESS);
}
tmp_rbufsz = *rbufsz;
/*
* Calculate the max number of ilb_persist_info_t can be fitted in the
* reply.
*/
*rbufsz += sizeof (ilb_show_info_t *);
tmp_rbufsz -= *rbufsz;
/*
* Calculate the exact number of entries we should request from kernel.
*/
logdebug("ilbd_show_nat: malloc(cmd)");
return (ILB_STATUS_ENOMEM);
}
logperror("ilbd_show_nat: ioctl(ILB_LIST_STICKY_TABLE)");
return (ret);
}
} else {
/*
* ilbd_reply_ok() sets ic_flags to ILB_COMM_END by default.
* Need to clear it here.
*/
}
for (i = 0; i < kcmd->num_sticky; i++) {
st_ret++;
}
end:
return (ret);
}