dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * CDDL HEADER START
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * The contents of this file are subject to the terms of the
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * Common Development and Distribution License (the "License").
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * You may not use this file except in compliance with the License.
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * or http://www.opensolaris.org/os/licensing.
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * See the License for the specific language governing permissions
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * and limitations under the License.
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * When distributing Covered Code, include this CDDL HEADER in each
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * If applicable, add the following below this CDDL HEADER, with the
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * fields enclosed by brackets "[]" replaced with your own identifying
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * information: Portions Copyright [yyyy] [name of copyright owner]
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * CDDL HEADER END
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * Use is subject to license terms.
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * We only allow one show nat/persist command running at any time. Note that
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * there is no lock for this since ilbd is single threaded. And we only care
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * about the pointer value of client, not its type.
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * The following variables store the current client making the request.
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra/* Maximum number of NAT/sticky entries to request from kernel. */
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * Clear the current requesting client. This will allow a new client
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * to make a request.
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * To show the kernel NAT table.
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * cli: the client pointer making the request.
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * ic: the client request.
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * rbuf: reply buffer to be filled in.
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * rbufsz: reply buffer size.
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misrailbd_show_nat(void *cli, const ilb_comm_t *ic, uint32_t *rbuf, size_t *rbufsz)
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra ilb_show_info_t *req_si = (ilb_show_info_t *)&ic->ic_data;
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra /* For new client request, start from the beginning of the table. */
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * Another request from client. If the client does not
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * want to continue, reset the current client and reply OK.
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra /* A request is on-going, so reject a new client. */
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra reply = (ilb_show_info_t *)&((ilb_comm_t *)rbuf)->ic_data;
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * Calculate the max number of ilb_nat_info_t can be fitted in the
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra max_num = tmp_rbufsz / sizeof (ilb_nat_info_t);
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * Calculate the exact number of entries we should request from kernel.
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra max_num = min(req_si->sn_num, min(NUM_ENTRIES, max_num));
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra kbufsz = max_num * sizeof (ilb_nat_entry_t) +
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra ilbd_reply_err(rbuf, rbufsz, ILB_STATUS_ENOMEM);
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra kcmd->flags = start ? ILB_LIST_BEGIN : ILB_LIST_CONT;
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra if ((ret = do_ioctl(kcmd, kbufsz)) != ILB_STATUS_OK) {
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra logperror("ilbd_show_nat: ioctl(ILB_LIST_NAT_TABLE)");
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra *rbufsz += reply->sn_num * sizeof (ilb_nat_info_t);
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * It is the end of table, let the client know. And the transaction
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * ilbd_reply_ok() sets ic_flags to ILB_COMM_END by default.
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * Need to clear it here.
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra nat_ret->nat_in_local_port = nat->in_local_port;
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra nat_ret->nat_in_global_port = nat->in_global_port;
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra nat_ret->nat_out_local_port = nat->out_local_port;
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra nat_ret->nat_out_global_port = nat->out_global_port;
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * To show the kernel sticky table.
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * cli: the client pointer making the request.
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * req_si: information about the show-persist request.
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * rbuf: reply buffer to be filled in.
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * rbufsz: reply buffer size.
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misrailbd_show_sticky(void *cli, const ilb_comm_t *ic, uint32_t *rbuf,
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra ilb_show_info_t *req_si = (ilb_show_info_t *)&ic->ic_data;
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra /* For new client request, start from the beginning of the table. */
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * Another request from client. If the client does not
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * want to continue, reset the current client and reply OK.
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra /* A request is on-going, so reject a new client. */
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra reply = (ilb_show_info_t *)&((ilb_comm_t *)rbuf)->ic_data;
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * Calculate the max number of ilb_persist_info_t can be fitted in the
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra max_num = tmp_rbufsz / sizeof (ilb_persist_info_t);
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * Calculate the exact number of entries we should request from kernel.
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra max_num = min(req_si->sn_num, min(NUM_ENTRIES, max_num));
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra kbufsz = max_num * sizeof (ilb_sticky_entry_t) +
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra ilbd_reply_err(rbuf, rbufsz, ILB_STATUS_ENOMEM);
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra kcmd->flags = start ? ILB_LIST_BEGIN : ILB_LIST_CONT;
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra if ((ret = do_ioctl(kcmd, kbufsz)) != ILB_STATUS_OK) {
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra logperror("ilbd_show_nat: ioctl(ILB_LIST_STICKY_TABLE)");
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra *rbufsz += reply->sn_num * sizeof (ilb_persist_info_t);
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * ilbd_reply_ok() sets ic_flags to ILB_COMM_END by default.
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * Need to clear it here.
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra st_ret = (ilb_persist_info_t *)&reply->sn_data;