Line data Source code
1 : /**
2 : * Copyright (c) 2025 Huawei Technologies Co., Ltd.
3 : * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4 : * CANN Open Software License Agreement Version 2.0 (the "License").
5 : * Please refer to the License for details. You may not use this file except in compliance with the License.
6 : * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7 : * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8 : * See LICENSE in the root of the software repository for the full text of the License.
9 : */
10 :
11 : #include <stdlib.h>
12 : #include <errno.h>
13 : #include <sys/prctl.h>
14 : #include "securec.h"
15 : #include "user_log.h"
16 : #include "ra_comm.h"
17 : #include "ra_hdc_socket.h"
18 : #include "ra_rs_comm.h"
19 : #include "ra_rs_err.h"
20 : #include "rs.h"
21 : #include "ra_adp.h"
22 : #include "ra_adp_socket.h"
23 :
24 : struct RsSocketOps gSocketOps = {
25 : .socketBatchConnect = RsSocketBatchConnect,
26 : .socketBatchClose = RsSocketBatchClose,
27 : .socketBatchAbort = RsSocketBatchAbort,
28 : .socketListenStart = RsSocketListenStart,
29 : .socketListenStop = RsSocketListenStop,
30 : .getSockets = RsGetSockets,
31 : .socketSend = RsHdcSocketSend,
32 : .socketRecv = RsSocketRecv,
33 : .socketInit = RsSocketInit,
34 : .socketDeinit = RsSocketDeinit,
35 : .whiteListAdd = RsSocketWhiteListAdd,
36 : .whiteListDel = RsSocketWhiteListDel,
37 : .acceptCreditAdd = RsSocketAcceptCreditAdd,
38 : .getIfnum = RsGetIfnum,
39 : .getIfaddrs = RsGetIfaddrs,
40 : .getIfaddrsV2 = RsGetIfaddrsV2,
41 : .getVnicIp = RsGetVnicIp,
42 : .getVnicIpInfos = RsGetVnicIpInfos,
43 : };
44 :
45 4 : int RaRsSocketBatchConnect(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
46 : {
47 4 : union OpSocketConnectData *socketConnectData = (union OpSocketConnectData *)(inBuf + sizeof(struct MsgHead));
48 4 : unsigned int usePort = 0;
49 : unsigned int i;
50 :
51 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpSocketConnectData), sizeof(struct MsgHead), rcvBufLen, opResult);
52 :
53 : // clear resv bit 31 use_port, for compatibility issue
54 4 : usePort = socketConnectData->txData.num >> SOCKET_USE_PORT_BIT;
55 4 : socketConnectData->txData.num &= ~(1U << SOCKET_USE_PORT_BIT);
56 4 : HCCP_CHECK_PARAM_NUM(socketConnectData->txData.num, MAX_SOCKET_NUM);
57 :
58 5 : for (i = 0; i < (socketConnectData->txData).num; i++) {
59 : // use_port flag not specify, use default port for compatibility issue
60 2 : if (usePort == 0) {
61 1 : (socketConnectData->txData).conn[i].port = RS_SOCK_PORT_DEF;
62 1 : } else if ((socketConnectData->txData).conn[i].port > MAX_PORT_NUM) {
63 1 : hccp_err("[batch_connect]conn[%u].port=%u invalid", i, (socketConnectData->txData).conn[i].port);
64 1 : return -EINVAL;
65 : }
66 : }
67 :
68 3 : *opResult = gSocketOps.socketBatchConnect((socketConnectData->txData).conn, (socketConnectData->txData).num);
69 3 : if (*opResult != 0) {
70 1 : hccp_err("socket batch connect failed ret[%d].", *opResult);
71 : }
72 :
73 3 : return 0;
74 : }
75 :
76 1 : int RaRsSocketBatchClose(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
77 : {
78 1 : union OpSocketCloseData *socketCloseData = (union OpSocketCloseData *)(inBuf + sizeof(struct MsgHead));
79 1 : int disuseLinger = 0;
80 : unsigned int i;
81 :
82 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpSocketCloseData), sizeof(struct MsgHead), rcvBufLen, opResult);
83 :
84 : // clear resv bit 31 disuse_linger, for compatibility issue(0 by default)
85 1 : disuseLinger = socketCloseData->txData.num >> SOCKET_DISUSE_LINGER_BIT;
86 1 : socketCloseData->txData.num &= ~(1U << SOCKET_DISUSE_LINGER_BIT);
87 1 : HCCP_CHECK_PARAM_NUM(socketCloseData->txData.num, MAX_SOCKET_NUM);
88 :
89 1 : struct RsSocketCloseInfoT closeConn[MAX_SOCKET_NUM] = {0};
90 1 : for (i = 0; i < socketCloseData->txData.num; i++) {
91 0 : closeConn[i].fd = ((socketCloseData->txData).conn[i]).closeFd;
92 : }
93 1 : *opResult = gSocketOps.socketBatchClose(disuseLinger, closeConn, (socketCloseData->txData).num);
94 1 : if (*opResult != 0) {
95 0 : hccp_err("socket batch close failed ret[%d].", *opResult);
96 : }
97 :
98 1 : return 0;
99 : }
100 :
101 2 : int RaRsSocketBatchAbort(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
102 : {
103 2 : union OpSocketConnectData *socketConnectData = (union OpSocketConnectData *)(inBuf + sizeof(struct MsgHead));
104 :
105 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpSocketConnectData), sizeof(struct MsgHead), rcvBufLen, opResult);
106 2 : HCCP_CHECK_PARAM_NUM(socketConnectData->txData.num, MAX_SOCKET_NUM);
107 :
108 2 : *opResult = gSocketOps.socketBatchAbort((socketConnectData->txData).conn, (socketConnectData->txData).num);
109 2 : if (*opResult != 0) {
110 1 : hccp_err("socket batch abort failed ret[%d]", *opResult);
111 : }
112 :
113 2 : return 0;
114 : }
115 :
116 5 : int RaRsSocketListenStart(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
117 : {
118 5 : union OpSocketListenData *socketListenData = (union OpSocketListenData *)(inBuf + sizeof(struct MsgHead));
119 5 : union OpSocketListenData *socketListenDataOut = NULL;
120 5 : unsigned int usePort = 0;
121 : unsigned int i;
122 : int ret;
123 :
124 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpSocketListenData), sizeof(struct MsgHead), rcvBufLen, opResult);
125 :
126 : // clear resv bit 31 use_port, for compatibility issue
127 5 : usePort = socketListenData->txData.num >> SOCKET_USE_PORT_BIT;
128 5 : socketListenData->txData.num &= ~(1U << SOCKET_USE_PORT_BIT);
129 : HCCP_CHECK_PARAM_LEN_RET_HOST(socketListenData->txData.num, 0, MAX_SOCKET_NUM, opResult);
130 :
131 6 : for (i = 0; i < (socketListenData->txData).num; i++) {
132 : // use_port flag not specify, use default port for compatibility issue
133 2 : if (usePort == 0) {
134 1 : (socketListenData->txData).conn[i].port = RS_SOCK_PORT_DEF;
135 1 : } else if ((socketListenData->txData).conn[i].port > MAX_PORT_NUM) {
136 1 : hccp_err("[listen_start]conn[%u].port=%u invalid", i, (socketListenData->txData).conn[i].port);
137 1 : return -EINVAL;
138 : }
139 : }
140 4 : *opResult = gSocketOps.socketListenStart((socketListenData->txData).conn, (socketListenData->txData).num);
141 4 : if (*opResult == -EADDRINUSE) {
142 1 : hccp_warn("socket listen start unsuccessful ret[%d]", *opResult);
143 1 : return 0;
144 3 : } else if (*opResult != 0) {
145 1 : hccp_err("socket listen start failed ret[%d]", *opResult);
146 1 : return 0;
147 : }
148 :
149 2 : socketListenDataOut = (union OpSocketListenData *)(outBuf + sizeof(struct MsgHead));
150 2 : ret = memcpy_s((socketListenDataOut->rxData).conn, sizeof(struct SocketListenInfo) * MAX_SOCKET_NUM,
151 2 : (socketListenData->txData).conn, sizeof(struct SocketListenInfo) * (socketListenData->txData).num);
152 2 : CHK_PRT_RETURN(ret, hccp_err("memcpy_s socket_listen_info failed, ret[%d]", ret), -ESAFEFUNC);
153 2 : return 0;
154 : }
155 :
156 3 : int RaRsSocketListenStop(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
157 : {
158 3 : union OpSocketListenData *socketListenData = (union OpSocketListenData *)(inBuf + sizeof(struct MsgHead));
159 3 : unsigned int usePort = 0;
160 : unsigned int i;
161 :
162 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpSocketListenData), sizeof(struct MsgHead), rcvBufLen, opResult);
163 :
164 : // clear resv bit 31 use_port, for compatibility issue
165 3 : usePort = socketListenData->txData.num >> SOCKET_USE_PORT_BIT;
166 3 : socketListenData->txData.num &= ~(1U << SOCKET_USE_PORT_BIT);
167 : HCCP_CHECK_PARAM_LEN_RET_HOST(socketListenData->txData.num, 0, MAX_SOCKET_NUM, opResult);
168 :
169 5 : for (i = 0; i < (socketListenData->txData).num; i++) {
170 : // use_port flag not specify, use default port for compatibility issue
171 2 : if (usePort == 0) {
172 2 : (socketListenData->txData).conn[i].port = RS_SOCK_PORT_DEF;
173 0 : } else if ((socketListenData->txData).conn[i].port > MAX_PORT_NUM) {
174 0 : hccp_err("[listen_stop]conn[%u].port=%u invalid", i, (socketListenData->txData).conn[i].port);
175 0 : return -EINVAL;
176 : }
177 : }
178 :
179 3 : *opResult = gSocketOps.socketListenStop((socketListenData->txData).conn, (socketListenData->txData).num);
180 3 : if (*opResult != 0) {
181 0 : hccp_err("socket listen stop failed ret[%d].", *opResult);
182 : }
183 :
184 3 : return 0;
185 : }
186 :
187 2 : int RaRsGetSockets(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
188 : {
189 : int ret;
190 2 : union OpSocketInfoData *socketInfoDataOut = NULL;
191 2 : union OpSocketInfoData *socketInfoData = (union OpSocketInfoData *)(inBuf + sizeof(struct MsgHead));
192 :
193 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpSocketInfoData), sizeof(struct MsgHead), rcvBufLen, opResult);
194 : HCCP_CHECK_PARAM_LEN_RET_HOST(socketInfoData->txData.num, 0, MAX_SOCKET_NUM, opResult);
195 :
196 2 : *opResult = gSocketOps.getSockets(socketInfoData->txData.role, socketInfoData->txData.conn,
197 : socketInfoData->txData.num);
198 2 : if (*opResult < 0) {
199 1 : hccp_err("socket info get failed ret[%d].", *opResult);
200 1 : return 0;
201 : }
202 :
203 1 : socketInfoDataOut = (union OpSocketInfoData *)(outBuf + sizeof(struct MsgHead));
204 :
205 1 : (socketInfoDataOut->rxData).num = *opResult;
206 1 : ret = memcpy_s((socketInfoDataOut->rxData).conn, sizeof(struct SocketFdData) * MAX_SOCKET_NUM,
207 1 : (socketInfoData->txData).conn, sizeof(struct SocketFdData) * (socketInfoData->txData).num);
208 1 : CHK_PRT_RETURN(ret, hccp_err("ra_rs_get_sockets memcpy_s failed, ret[%d]. ", ret), -ESAFEFUNC);
209 :
210 1 : return 0;
211 : }
212 :
213 2 : int RaRsSocketSend(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
214 : {
215 : int sendLen;
216 2 : union OpSocketSendData *sendData = (union OpSocketSendData *)(inBuf + sizeof(struct MsgHead));
217 :
218 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpSocketSendData), sizeof(struct MsgHead), rcvBufLen, opResult);
219 : HCCP_CHECK_PARAM_LEN_RET_HOST(sendData->txData.sendSize, 0, SOCKET_SEND_MAXLEN, opResult);
220 :
221 2 : sendLen = gSocketOps.socketSend(sendData->txData.fd, sendData->txData.dataSend, sendData->txData.sendSize);
222 2 : if (sendLen <= 0) {
223 1 : if (sendLen == -EAGAIN) {
224 0 : hccp_dbg("socket send need retry, ret[%d]", sendLen);
225 : } else {
226 1 : hccp_warn("send unsuccessful, sendLen[%d] expect greater than 0.", sendLen);
227 : }
228 : }
229 :
230 2 : *opResult = sendLen;
231 2 : sendData = (union OpSocketSendData *)(outBuf + sizeof(struct MsgHead));
232 2 : sendData->rxData.realSendSize = sendLen;
233 :
234 2 : return 0;
235 : }
236 :
237 1 : int RaRsSocketRecv(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
238 : {
239 : int recvLen;
240 1 : union OpSocketRecvData *recvData = (union OpSocketRecvData *)(inBuf + sizeof(struct MsgHead));
241 :
242 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpSocketRecvData), sizeof(struct MsgHead), rcvBufLen, opResult);
243 1 : HCCP_CHECK_PARAM_LEN(sizeof(union OpSocketRecvData) + recvData->txData.recvSize, sizeof(struct MsgHead), rcvBufLen);
244 :
245 1 : recvLen = gSocketOps.socketRecv(recvData->txData.fd,
246 1 : outBuf + sizeof(struct MsgHead) + sizeof(union OpSocketRecvData), recvData->txData.recvSize);
247 1 : *opResult = recvLen;
248 :
249 1 : recvData = (union OpSocketRecvData *)(outBuf + sizeof(struct MsgHead));
250 1 : recvData->rxData.realRecvSize = recvLen;
251 :
252 1 : return 0;
253 : }
254 :
255 1 : int RaRsSocketInit(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
256 : {
257 1 : union OpSocketInitData *socketInitData = (union OpSocketInitData *)(inBuf + sizeof(struct MsgHead));
258 :
259 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpSocketInitData), sizeof(struct MsgHead), rcvBufLen, opResult);
260 :
261 1 : *opResult = gSocketOps.socketInit(socketInitData->txData.vnicIp, socketInitData->txData.num);
262 1 : if (*opResult != 0) {
263 0 : hccp_err("socket init failed ret[%d].", *opResult);
264 : }
265 :
266 1 : return 0;
267 : }
268 :
269 1 : int RaRsSocketDeinit(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
270 : {
271 1 : union OpSocketDeinitData *socketDeinitData = (union OpSocketDeinitData *)(inBuf + sizeof(struct MsgHead));
272 :
273 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpSocketDeinitData), sizeof(struct MsgHead), rcvBufLen, opResult);
274 :
275 1 : *opResult = gSocketOps.socketDeinit(socketDeinitData->txData.rdevInfo);
276 1 : if (*opResult != 0) {
277 0 : hccp_err("socket deinit failed ret[%d].", *opResult);
278 : }
279 :
280 1 : return 0;
281 : }
282 :
283 2 : int RaRsSocketWhiteListAdd(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
284 : {
285 2 : union OpWlistData *wlistData = (union OpWlistData *)(inBuf + sizeof(struct MsgHead));
286 :
287 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpWlistData), sizeof(struct MsgHead), rcvBufLen, opResult);
288 2 : HCCP_CHECK_PARAM_NUM(wlistData->txData.num, MAX_WLIST_NUM);
289 :
290 2 : *opResult = gSocketOps.whiteListAdd(wlistData->txData.rdevInfo, wlistData->txData.wlist, wlistData->txData.num);
291 2 : if (*opResult != 0) {
292 1 : hccp_err("white_list_add failed, ret[%d]", *opResult);
293 : }
294 2 : return 0;
295 : }
296 :
297 0 : int RaRsSocketWhiteListAddV2(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
298 : {
299 0 : union OpWlistDataV2 *wlistData = (union OpWlistDataV2 *)(inBuf + sizeof(struct MsgHead));
300 :
301 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpWlistDataV2), sizeof(struct MsgHead), rcvBufLen, opResult);
302 0 : HCCP_CHECK_PARAM_NUM(wlistData->txData.num, MAX_WLIST_NUM);
303 :
304 0 : *opResult = gSocketOps.whiteListAdd(wlistData->txData.rdevInfo, wlistData->txData.wlist, wlistData->txData.num);
305 0 : if (*opResult != 0) {
306 0 : hccp_err("white_list_add failed, ret[%d]", *opResult);
307 : }
308 0 : return 0;
309 : }
310 :
311 2 : int RaRsSocketWhiteListDel(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
312 : {
313 2 : union OpWlistData *wlistData = (union OpWlistData *)(inBuf + sizeof(struct MsgHead));
314 :
315 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpWlistData), sizeof(struct MsgHead), rcvBufLen, opResult);
316 2 : HCCP_CHECK_PARAM_NUM(wlistData->txData.num, MAX_WLIST_NUM);
317 :
318 2 : *opResult = gSocketOps.whiteListDel(wlistData->txData.rdevInfo, wlistData->txData.wlist, wlistData->txData.num);
319 2 : if (*opResult != 0) {
320 1 : hccp_err("white_list_del failed, ret[%d]", *opResult);
321 : }
322 2 : return 0;
323 : }
324 :
325 0 : int RaRsSocketWhiteListDelV2(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
326 : {
327 0 : union OpWlistDataV2 *wlistData = (union OpWlistDataV2 *)(inBuf + sizeof(struct MsgHead));
328 :
329 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpWlistDataV2), sizeof(struct MsgHead), rcvBufLen, opResult);
330 0 : HCCP_CHECK_PARAM_NUM(wlistData->txData.num, MAX_WLIST_NUM);
331 :
332 0 : *opResult = gSocketOps.whiteListDel(wlistData->txData.rdevInfo, wlistData->txData.wlist, wlistData->txData.num);
333 0 : if (*opResult != 0) {
334 0 : hccp_err("white_list_del failed, ret[%d]", *opResult);
335 : }
336 0 : return 0;
337 : }
338 :
339 0 : int RaRsSocketCreditAdd(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
340 : {
341 0 : union OpAcceptCreditData *opData = (union OpAcceptCreditData *)(inBuf + sizeof(struct MsgHead));
342 :
343 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpAcceptCreditData), sizeof(struct MsgHead), rcvBufLen, opResult);
344 0 : HCCP_CHECK_PARAM_NUM(opData->txData.num, MAX_SOCKET_NUM);
345 :
346 0 : *opResult = gSocketOps.acceptCreditAdd(opData->txData.conn, opData->txData.num, opData->txData.creditLimit);
347 0 : if (*opResult != 0) {
348 0 : hccp_err("accept_credit_add failed, ret[%d]", *opResult);
349 : }
350 0 : return 0;
351 : }
352 :
353 3 : int RaRsGetIfnum(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
354 : {
355 3 : union OpIfnumData *ifnumData = (union OpIfnumData *)(inBuf + sizeof(struct MsgHead));
356 3 : union OpIfnumData *ifnumDataOut = NULL;
357 3 : unsigned int num = 0;
358 3 : bool isAll = false;
359 :
360 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpIfnumData), sizeof(struct MsgHead), rcvBufLen, opResult);
361 : /* resv bit 31 for is_all for compatibility issue */
362 3 : if ((ifnumData->txData.num & RA_RS_GET_ALL_IP_BIT_MASK) != 0) {
363 0 : isAll = true;
364 : }
365 3 : *opResult = gSocketOps.getIfnum(ifnumData->txData.phyId, isAll, &num);
366 3 : if (*opResult != 0) {
367 0 : hccp_err("ra_rs_get_ifnum result ret[%d].", *opResult);
368 0 : return 0;
369 : }
370 :
371 3 : ifnumDataOut = (union OpIfnumData *)(outBuf + sizeof(struct MsgHead));
372 3 : (ifnumDataOut->rxData).num = num;
373 :
374 3 : return 0;
375 : }
376 :
377 2 : int RaRsGetIfaddrs(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
378 : {
379 : int ret;
380 2 : union OpIfaddrData *ifaddrDataOut = NULL;
381 2 : union OpIfaddrData *ifaddrData = (union OpIfaddrData *)(inBuf + sizeof(struct MsgHead));
382 :
383 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpIfaddrData), sizeof(struct MsgHead), rcvBufLen, opResult);
384 2 : CHK_PRT_RETURN(ifaddrData->txData.num > MAX_INTERFACE_NUM || ifaddrData->txData.num == 0,
385 : hccp_err("interface number is invalid, num[%u]", ifaddrData->txData.num), -EINVAL);
386 :
387 2 : *opResult = gSocketOps.getIfaddrs(ifaddrData->txData.ifaddrInfos, &(ifaddrData->txData.num),
388 : ifaddrData->txData.phyId);
389 2 : if (*opResult != 0) {
390 0 : hccp_err("ra_rs_get_ifaddrs result ret[%d].", *opResult);
391 0 : return 0;
392 : }
393 :
394 2 : ifaddrDataOut = (union OpIfaddrData *)(outBuf + sizeof(struct MsgHead));
395 :
396 2 : (ifaddrDataOut->rxData).num = ifaddrData->txData.num;
397 2 : ret = memcpy_s((ifaddrDataOut->rxData).ifaddrInfos, sizeof(struct IfaddrInfo) * MAX_INTERFACE_NUM,
398 2 : (ifaddrData->txData).ifaddrInfos, sizeof(struct IfaddrInfo) * (ifaddrData->txData).num);
399 2 : CHK_PRT_RETURN(ret, hccp_err("ra_rs_get_sockets memcpy_s failed, ret[%d]. ", ret), -ESAFEFUNC);
400 :
401 2 : return 0;
402 : }
403 :
404 2 : int RaRsGetIfaddrsV2(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
405 : {
406 2 : union OpIfaddrDataV2 *ifaddrData = (union OpIfaddrDataV2 *)(inBuf + sizeof(struct MsgHead));
407 2 : union OpIfaddrDataV2 *ifaddrDataOut = NULL;
408 2 : bool isAll = false;
409 : int ret;
410 :
411 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpIfaddrDataV2), sizeof(struct MsgHead), rcvBufLen, opResult);
412 :
413 : /* resv bit 31 for is_all for compatibility issue */
414 2 : if ((ifaddrData->txData.num & RA_RS_GET_ALL_IP_BIT_MASK) != 0) {
415 0 : isAll = true;
416 : }
417 2 : ifaddrData->txData.num = ifaddrData->txData.num & (~RA_RS_GET_ALL_IP_BIT_MASK);
418 2 : CHK_PRT_RETURN(ifaddrData->txData.num > MAX_INTERFACE_NUM || ifaddrData->txData.num == 0,
419 : hccp_err("interface number of op_ifaddr_data_v2 is invalid, num[%u]", ifaddrData->txData.num), -EINVAL);
420 :
421 1 : *opResult = gSocketOps.getIfaddrsV2(ifaddrData->txData.interfaceInfos, &(ifaddrData->txData.num),
422 : ifaddrData->txData.phyId, isAll);
423 1 : if (*opResult != 0) {
424 0 : hccp_err("ra_rs_get_ifaddrs_v2 result ret[%d].", *opResult);
425 0 : return 0;
426 : }
427 :
428 1 : ifaddrDataOut = (union OpIfaddrDataV2 *)(outBuf + sizeof(struct MsgHead));
429 :
430 1 : (ifaddrDataOut->rxData).num = ifaddrData->txData.num;
431 1 : ret = memcpy_s((ifaddrDataOut->rxData).interfaceInfos, sizeof(struct InterfaceInfo) * MAX_INTERFACE_NUM,
432 1 : (ifaddrData->txData).interfaceInfos, sizeof(struct InterfaceInfo) * (ifaddrData->txData).num);
433 1 : CHK_PRT_RETURN(ret, hccp_err("ra_rs_get_ifaddrs_v2 memcpy_s failed, ret[%d].", ret), -ESAFEFUNC);
434 :
435 1 : return 0;
436 : }
437 :
438 2 : int RaRsGetVnicIp(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
439 : {
440 2 : unsigned int vnicIp = 0;
441 2 : union OpGetVnicIpData *vnicIpDataRet = NULL;
442 2 : union OpGetVnicIpData *vnicIpData = (union OpGetVnicIpData *)(inBuf + sizeof(struct MsgHead));
443 :
444 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpGetVnicIpData), sizeof(struct MsgHead), rcvBufLen, opResult);
445 :
446 2 : *opResult = gSocketOps.getVnicIp(vnicIpData->txData.phyId, &vnicIp);
447 2 : if (*opResult != 0) {
448 1 : hccp_err("rs get vnic ip failed, phyId %d, ret %d", vnicIpData->txData.phyId, *opResult);
449 1 : return 0;
450 : }
451 :
452 1 : vnicIpDataRet = (union OpGetVnicIpData *)(outBuf + sizeof(struct MsgHead));
453 1 : hccp_info("rs get vnic_ip, phyId %d, vnicIp 0x%x", vnicIpData->txData.phyId, vnicIp);
454 1 : vnicIpDataRet->rxData.vnicIp = vnicIp;
455 1 : return 0;
456 : }
457 :
458 2 : int RaRsGetVnicIpInfosV1(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
459 : {
460 2 : union OpGetVnicIpInfosDataV1 *vnicIpData = (union OpGetVnicIpInfosDataV1 *)(inBuf + sizeof(struct MsgHead));
461 2 : union OpGetVnicIpInfosDataV1 *vnicIpOut = (union OpGetVnicIpInfosDataV1 *)(outBuf + sizeof(struct MsgHead));
462 :
463 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpGetVnicIpInfosDataV1), sizeof(struct MsgHead), rcvBufLen, opResult);
464 : HCCP_CHECK_PARAM_LEN_RET_HOST(vnicIpData->txData.num, 0, MAX_IP_INFO_NUM_V1, opResult);
465 :
466 4 : *opResult = gSocketOps.getVnicIpInfos(vnicIpData->txData.phyId, vnicIpData->txData.type, vnicIpData->txData.ids,
467 2 : vnicIpData->txData.num, vnicIpOut->rxData.infos);
468 :
469 2 : if (*opResult != 0) {
470 1 : hccp_err("rs get vnic ip infos failed, ret %d", *opResult);
471 : }
472 :
473 2 : return 0;
474 : }
475 :
476 2 : int RaRsGetVnicIpInfos(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
477 : {
478 2 : union OpGetVnicIpInfosData *vnicIpData = (union OpGetVnicIpInfosData *)(inBuf + sizeof(struct MsgHead));
479 2 : union OpGetVnicIpInfosData *vnicIpOut = (union OpGetVnicIpInfosData *)(outBuf + sizeof(struct MsgHead));
480 :
481 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpGetVnicIpInfosData), sizeof(struct MsgHead), rcvBufLen, opResult);
482 : HCCP_CHECK_PARAM_LEN_RET_HOST(vnicIpData->txData.num, 0, MAX_IP_INFO_NUM, opResult);
483 :
484 4 : *opResult = gSocketOps.getVnicIpInfos(vnicIpData->txData.phyId, vnicIpData->txData.type, vnicIpData->txData.ids,
485 2 : vnicIpData->txData.num, vnicIpOut->rxData.infos);
486 :
487 2 : if (*opResult != 0) {
488 1 : hccp_err("rs get vnic ip infos failed, ret %d", *opResult);
489 : }
490 :
491 2 : return 0;
492 : }
|