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.
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.
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]
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
31 #include <sys/types.h>
32 #include <sys/socket.h>
34 #include "libilb_impl.h"
41 /* The common function to show kernel info. */
42 static ilb_status_t
ilb_show_info(ilb_handle_t
, char *, size_t *, boolean_t
*,
46 * To get the ILB NAT table.
48 * buf: The buffer to return the NAT table entries.
49 * num: The caller sets it to the number of ilb_nat_info_t entries buf can
50 * hold. On return, it contains the actual number of entries put in buf.
51 * end: The caller sets it to B_TRUE if it only wants at most num entries to
52 * be returned. The transaction to ilbd will be termianted when this
54 * The caller sets it to B_FALSE if it intends to get the whole table.
55 * If the whole table has more than num entries, the caller can call
56 * this function again to retrieve the rest of the table.
57 * On return, end is set to B_TRUE if end of table is reached; B_FALSE
58 * if there are still remaining entries.
61 ilb_show_nat(ilb_handle_t h
, ilb_nat_info_t buf
[], size_t *num
,
64 return (ilb_show_info(h
, (char *)buf
, num
, end
, show_nat
));
68 * To get the ILB persistent entry table.
70 * buf: The buffer to return the persistent table entries.
71 * num: The caller sets it to the number of ilb_persist_info_t entries buf can
72 * hold. On return, it contains the actual number of entries put in buf.
73 * end: The caller sets it to B_TRUE if it only wants at most num entries to
74 * be returned. The transaction to ilbd will be termianted when this
76 * The caller sets it to B_FALSE if it intends to get the whole table.
77 * If the whole table has more than num entries, the caller can call
78 * this function again to retrieve the rest of the table.
79 * On return, end is set to B_TRUE if end of table is reached; B_FALSE
80 * if there are still remaining entries.
83 ilb_show_persist(ilb_handle_t h
, ilb_persist_info_t buf
[], size_t *num
,
86 return (ilb_show_info(h
, (char *)buf
, num
, end
, show_persist
));
90 * The function doing the work... The tbl parameter determines whith table
94 ilb_show_info(ilb_handle_t h
, char *buf
, size_t *num
, boolean_t
*end
,
97 ilb_comm_t
*req
, *rbuf
;
98 ilb_show_info_t
*req_si
, *tmp_si
;
99 size_t reqsz
, rbufsz
, tmp_rbufsz
, cur_num
;
104 return (ILB_STATUS_EINVAL
);
106 reqsz
= sizeof (ilb_comm_t
) + sizeof (ilb_show_info_t
);
107 if ((req
= malloc(reqsz
)) == NULL
)
108 return (ILB_STATUS_ENOMEM
);
109 req_si
= (ilb_show_info_t
*)&req
->ic_data
;
112 * Need to allocate a receive buffer and then copy the buffer
113 * content to the passed in buf. The reason is that the
114 * communication to ilbd is message based and the protocol
115 * includes a header in the reply. We need to remove this header
116 * from the message, hence the copying...
119 entry_sz
= sizeof (ilb_nat_info_t
);
121 entry_sz
= sizeof (ilb_persist_info_t
);
122 rbufsz
= *num
* entry_sz
+ sizeof (ilb_comm_t
) +
123 sizeof (ilb_show_info_t
);
124 if ((rbuf
= malloc(rbufsz
)) == NULL
) {
126 return (ILB_STATUS_ENOMEM
);
130 req
->ic_cmd
= ILBD_SHOW_NAT
;
132 req
->ic_cmd
= ILBD_SHOW_PERSIST
;
134 req_si
->sn_num
= *num
;
139 rc
= i_ilb_do_comm(h
, req
, reqsz
, rbuf
, &tmp_rbufsz
);
140 if (rc
!= ILB_STATUS_OK
)
142 if (rbuf
->ic_cmd
!= ILBD_CMD_OK
) {
143 rc
= *(ilb_status_t
*)&rbuf
->ic_data
;
147 tmp_si
= (ilb_show_info_t
*)&rbuf
->ic_data
;
149 cur_num
+= tmp_si
->sn_num
;
150 bcopy(&tmp_si
->sn_data
, buf
, tmp_si
->sn_num
* entry_sz
);
151 buf
+= tmp_si
->sn_num
* entry_sz
;
154 * Buffer is filled, regardless of this is the end of table or
155 * not, we need to stop.
159 /* Try to fill in the rest. */
160 req_si
->sn_num
= *num
- cur_num
;
161 } while (!(rbuf
->ic_flags
& ILB_COMM_END
));
165 /* End of transaction, let the caller know. */
166 if (rbuf
->ic_flags
& ILB_COMM_END
) {
169 /* The user wants to terminate the transaction */
171 req
->ic_flags
= ILB_COMM_END
;
173 rc
= i_ilb_do_comm(h
, req
, reqsz
, rbuf
, &tmp_rbufsz
);