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 : (void)outBuf;
48 : (void)outLen;
49 4 : union OpSocketConnectData *socketConnectData = (union OpSocketConnectData *)(inBuf + sizeof(struct MsgHead));
50 4 : unsigned int usePort = 0;
51 : unsigned int i;
52 :
53 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpSocketConnectData), sizeof(struct MsgHead), rcvBufLen, opResult);
54 :
55 : // clear resv bit 31 use_port, for compatibility issue
56 4 : usePort = socketConnectData->txData.num >> SOCKET_USE_PORT_BIT;
57 4 : socketConnectData->txData.num &= ~(1U << SOCKET_USE_PORT_BIT);
58 4 : HCCP_CHECK_PARAM_NUM(socketConnectData->txData.num, MAX_SOCKET_NUM);
59 :
60 5 : for (i = 0; i < (socketConnectData->txData).num; i++) {
61 : // use_port flag not specify, use default port for compatibility issue
62 2 : if (usePort == 0) {
63 1 : (socketConnectData->txData).conn[i].port = RS_SOCK_PORT_DEF;
64 1 : } else if ((socketConnectData->txData).conn[i].port > MAX_PORT_NUM) {
65 1 : hccp_err("[batch_connect]conn[%u].port=%u invalid", i, (socketConnectData->txData).conn[i].port);
66 1 : return -EINVAL;
67 : }
68 : }
69 :
70 3 : *opResult = gSocketOps.socketBatchConnect((socketConnectData->txData).conn, (socketConnectData->txData).num);
71 3 : if (*opResult != 0) {
72 1 : hccp_err("socket batch connect failed ret[%d].", *opResult);
73 : }
74 :
75 3 : return 0;
76 : }
77 :
78 1 : int RaRsSocketBatchClose(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
79 : {
80 : (void)outBuf;
81 : (void)outLen;
82 1 : union OpSocketCloseData *socketCloseData = (union OpSocketCloseData *)(inBuf + sizeof(struct MsgHead));
83 1 : int disuseLinger = 0;
84 : unsigned int i;
85 :
86 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpSocketCloseData), sizeof(struct MsgHead), rcvBufLen, opResult);
87 :
88 : // clear resv bit 31 disuse_linger, for compatibility issue(0 by default)
89 1 : disuseLinger = socketCloseData->txData.num >> SOCKET_DISUSE_LINGER_BIT;
90 1 : socketCloseData->txData.num &= ~(1U << SOCKET_DISUSE_LINGER_BIT);
91 1 : HCCP_CHECK_PARAM_NUM(socketCloseData->txData.num, MAX_SOCKET_NUM);
92 :
93 1 : struct RsSocketCloseInfoT closeConn[MAX_SOCKET_NUM] = {0};
94 1 : for (i = 0; i < socketCloseData->txData.num; i++) {
95 0 : closeConn[i].fd = ((socketCloseData->txData).conn[i]).closeFd;
96 : }
97 1 : *opResult = gSocketOps.socketBatchClose(disuseLinger, closeConn, (socketCloseData->txData).num);
98 1 : if (*opResult != 0) {
99 0 : hccp_err("socket batch close failed ret[%d].", *opResult);
100 : }
101 :
102 1 : return 0;
103 : }
104 :
105 2 : int RaRsSocketBatchAbort(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
106 : {
107 : (void)outBuf;
108 : (void)outLen;
109 2 : union OpSocketConnectData *socketConnectData = (union OpSocketConnectData *)(inBuf + sizeof(struct MsgHead));
110 :
111 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpSocketConnectData), sizeof(struct MsgHead), rcvBufLen, opResult);
112 2 : HCCP_CHECK_PARAM_NUM(socketConnectData->txData.num, MAX_SOCKET_NUM);
113 :
114 2 : *opResult = gSocketOps.socketBatchAbort((socketConnectData->txData).conn, (socketConnectData->txData).num);
115 2 : if (*opResult != 0) {
116 1 : hccp_err("socket batch abort failed ret[%d]", *opResult);
117 : }
118 :
119 2 : return 0;
120 : }
121 :
122 5 : int RaRsSocketListenStart(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
123 : {
124 : (void)outLen;
125 5 : union OpSocketListenData *socketListenData = (union OpSocketListenData *)(inBuf + sizeof(struct MsgHead));
126 5 : union OpSocketListenData *socketListenDataOut = NULL;
127 5 : unsigned int usePort = 0;
128 : unsigned int i;
129 : int ret;
130 :
131 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpSocketListenData), sizeof(struct MsgHead), rcvBufLen, opResult);
132 :
133 : // clear resv bit 31 use_port, for compatibility issue
134 5 : usePort = socketListenData->txData.num >> SOCKET_USE_PORT_BIT;
135 5 : socketListenData->txData.num &= ~(1U << SOCKET_USE_PORT_BIT);
136 : HCCP_CHECK_PARAM_LEN_RET_HOST(socketListenData->txData.num, 0, MAX_SOCKET_NUM, opResult);
137 :
138 6 : for (i = 0; i < (socketListenData->txData).num; i++) {
139 : // use_port flag not specify, use default port for compatibility issue
140 2 : if (usePort == 0) {
141 1 : (socketListenData->txData).conn[i].port = RS_SOCK_PORT_DEF;
142 1 : } else if ((socketListenData->txData).conn[i].port > MAX_PORT_NUM) {
143 1 : hccp_err("[listen_start]conn[%u].port=%u invalid", i, (socketListenData->txData).conn[i].port);
144 1 : return -EINVAL;
145 : }
146 : }
147 4 : *opResult = gSocketOps.socketListenStart((socketListenData->txData).conn, (socketListenData->txData).num);
148 4 : if (*opResult == -EADDRINUSE) {
149 1 : hccp_warn("socket listen start unsuccessful ret[%d]", *opResult);
150 1 : return 0;
151 3 : } else if (*opResult != 0) {
152 1 : hccp_err("socket listen start failed ret[%d]", *opResult);
153 1 : return 0;
154 : }
155 :
156 2 : socketListenDataOut = (union OpSocketListenData *)(outBuf + sizeof(struct MsgHead));
157 2 : ret = memcpy_s((socketListenDataOut->rxData).conn, sizeof(struct SocketListenInfo) * MAX_SOCKET_NUM,
158 2 : (socketListenData->txData).conn, sizeof(struct SocketListenInfo) * (socketListenData->txData).num);
159 2 : CHK_PRT_RETURN(ret, hccp_err("memcpy_s socket_listen_info failed, ret[%d]", ret), -ESAFEFUNC);
160 2 : return 0;
161 : }
162 :
163 3 : int RaRsSocketListenStop(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
164 : {
165 : (void)outBuf;
166 : (void)outLen;
167 3 : union OpSocketListenData *socketListenData = (union OpSocketListenData *)(inBuf + sizeof(struct MsgHead));
168 3 : unsigned int usePort = 0;
169 : unsigned int i;
170 :
171 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpSocketListenData), sizeof(struct MsgHead), rcvBufLen, opResult);
172 :
173 : // clear resv bit 31 use_port, for compatibility issue
174 3 : usePort = socketListenData->txData.num >> SOCKET_USE_PORT_BIT;
175 3 : socketListenData->txData.num &= ~(1U << SOCKET_USE_PORT_BIT);
176 : HCCP_CHECK_PARAM_LEN_RET_HOST(socketListenData->txData.num, 0, MAX_SOCKET_NUM, opResult);
177 :
178 5 : for (i = 0; i < (socketListenData->txData).num; i++) {
179 : // use_port flag not specify, use default port for compatibility issue
180 2 : if (usePort == 0) {
181 2 : (socketListenData->txData).conn[i].port = RS_SOCK_PORT_DEF;
182 0 : } else if ((socketListenData->txData).conn[i].port > MAX_PORT_NUM) {
183 0 : hccp_err("[listen_stop]conn[%u].port=%u invalid", i, (socketListenData->txData).conn[i].port);
184 0 : return -EINVAL;
185 : }
186 : }
187 :
188 3 : *opResult = gSocketOps.socketListenStop((socketListenData->txData).conn, (socketListenData->txData).num);
189 3 : if (*opResult != 0) {
190 0 : hccp_err("socket listen stop failed ret[%d].", *opResult);
191 : }
192 :
193 3 : return 0;
194 : }
195 :
196 2 : int RaRsGetSockets(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
197 : {
198 : (void)outLen;
199 : int ret;
200 2 : union OpSocketInfoData *socketInfoDataOut = NULL;
201 2 : union OpSocketInfoData *socketInfoData = (union OpSocketInfoData *)(inBuf + sizeof(struct MsgHead));
202 :
203 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpSocketInfoData), sizeof(struct MsgHead), rcvBufLen, opResult);
204 : HCCP_CHECK_PARAM_LEN_RET_HOST(socketInfoData->txData.num, 0, MAX_SOCKET_NUM, opResult);
205 :
206 2 : *opResult = gSocketOps.getSockets(socketInfoData->txData.role, socketInfoData->txData.conn,
207 : socketInfoData->txData.num);
208 2 : if (*opResult < 0) {
209 1 : hccp_err("socket info get failed ret[%d].", *opResult);
210 1 : return 0;
211 : }
212 :
213 1 : socketInfoDataOut = (union OpSocketInfoData *)(outBuf + sizeof(struct MsgHead));
214 :
215 1 : (socketInfoDataOut->rxData).num = *opResult;
216 1 : ret = memcpy_s((socketInfoDataOut->rxData).conn, sizeof(struct SocketFdData) * MAX_SOCKET_NUM,
217 1 : (socketInfoData->txData).conn, sizeof(struct SocketFdData) * (socketInfoData->txData).num);
218 1 : CHK_PRT_RETURN(ret, hccp_err("ra_rs_get_sockets memcpy_s failed, ret[%d]. ", ret), -ESAFEFUNC);
219 :
220 1 : return 0;
221 : }
222 :
223 2 : int RaRsSocketSend(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
224 : {
225 : (void)outLen;
226 : int sendLen;
227 2 : union OpSocketSendData *sendData = (union OpSocketSendData *)(inBuf + sizeof(struct MsgHead));
228 :
229 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpSocketSendData), sizeof(struct MsgHead), rcvBufLen, opResult);
230 : HCCP_CHECK_PARAM_LEN_RET_HOST(sendData->txData.sendSize, 0, SOCKET_SEND_MAXLEN, opResult);
231 :
232 2 : sendLen = gSocketOps.socketSend(sendData->txData.fd, sendData->txData.dataSend, sendData->txData.sendSize);
233 2 : if (sendLen <= 0) {
234 1 : if (sendLen == -EAGAIN) {
235 0 : hccp_dbg("socket send need retry, ret[%d]", sendLen);
236 : } else {
237 1 : hccp_warn("send unsuccessful, sendLen[%d] expect greater than 0.", sendLen);
238 : }
239 : }
240 :
241 2 : *opResult = sendLen;
242 2 : sendData = (union OpSocketSendData *)(outBuf + sizeof(struct MsgHead));
243 2 : sendData->rxData.realSendSize = sendLen;
244 :
245 2 : return 0;
246 : }
247 :
248 1 : int RaRsSocketRecv(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
249 : {
250 : (void)outLen;
251 : int recvLen;
252 1 : union OpSocketRecvData *recvData = (union OpSocketRecvData *)(inBuf + sizeof(struct MsgHead));
253 :
254 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpSocketRecvData), sizeof(struct MsgHead), rcvBufLen, opResult);
255 1 : HCCP_CHECK_PARAM_LEN(sizeof(union OpSocketRecvData) + recvData->txData.recvSize, sizeof(struct MsgHead), rcvBufLen);
256 :
257 1 : recvLen = gSocketOps.socketRecv(recvData->txData.fd,
258 1 : outBuf + sizeof(struct MsgHead) + sizeof(union OpSocketRecvData), recvData->txData.recvSize);
259 1 : *opResult = recvLen;
260 :
261 1 : recvData = (union OpSocketRecvData *)(outBuf + sizeof(struct MsgHead));
262 1 : recvData->rxData.realRecvSize = recvLen;
263 :
264 1 : return 0;
265 : }
266 :
267 1 : int RaRsSocketInit(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
268 : {
269 : (void)outBuf;
270 : (void)outLen;
271 1 : union OpSocketInitData *socketInitData = (union OpSocketInitData *)(inBuf + sizeof(struct MsgHead));
272 :
273 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpSocketInitData), sizeof(struct MsgHead), rcvBufLen, opResult);
274 :
275 1 : *opResult = gSocketOps.socketInit(socketInitData->txData.vnicIp, socketInitData->txData.num);
276 1 : if (*opResult != 0) {
277 0 : hccp_err("socket init failed ret[%d].", *opResult);
278 : }
279 :
280 1 : return 0;
281 : }
282 :
283 1 : int RaRsSocketDeinit(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
284 : {
285 : (void)outBuf;
286 : (void)outLen;
287 1 : union OpSocketDeinitData *socketDeinitData = (union OpSocketDeinitData *)(inBuf + sizeof(struct MsgHead));
288 :
289 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpSocketDeinitData), sizeof(struct MsgHead), rcvBufLen, opResult);
290 :
291 1 : *opResult = gSocketOps.socketDeinit(socketDeinitData->txData.rdevInfo);
292 1 : if (*opResult != 0) {
293 0 : hccp_err("socket deinit failed ret[%d].", *opResult);
294 : }
295 :
296 1 : return 0;
297 : }
298 :
299 2 : int RaRsSocketWhiteListAdd(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
300 : {
301 : (void)outBuf;
302 : (void)outLen;
303 2 : union OpWlistData *wlistData = (union OpWlistData *)(inBuf + sizeof(struct MsgHead));
304 :
305 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpWlistData), sizeof(struct MsgHead), rcvBufLen, opResult);
306 2 : HCCP_CHECK_PARAM_NUM(wlistData->txData.num, MAX_WLIST_NUM);
307 :
308 2 : *opResult = gSocketOps.whiteListAdd(wlistData->txData.rdevInfo, wlistData->txData.wlist, wlistData->txData.num);
309 2 : if (*opResult != 0) {
310 1 : hccp_err("white_list_add failed, ret[%d]", *opResult);
311 : }
312 2 : return 0;
313 : }
314 :
315 0 : int RaRsSocketWhiteListAddV2(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
316 : {
317 : (void)outBuf;
318 : (void)outLen;
319 0 : union OpWlistDataV2 *wlistData = (union OpWlistDataV2 *)(inBuf + sizeof(struct MsgHead));
320 :
321 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpWlistDataV2), sizeof(struct MsgHead), rcvBufLen, opResult);
322 0 : HCCP_CHECK_PARAM_NUM(wlistData->txData.num, MAX_WLIST_NUM);
323 :
324 0 : *opResult = gSocketOps.whiteListAdd(wlistData->txData.rdevInfo, wlistData->txData.wlist, wlistData->txData.num);
325 0 : if (*opResult != 0) {
326 0 : hccp_err("white_list_add failed, ret[%d]", *opResult);
327 : }
328 0 : return 0;
329 : }
330 :
331 2 : int RaRsSocketWhiteListDel(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
332 : {
333 : (void)outBuf;
334 : (void)outLen;
335 2 : union OpWlistData *wlistData = (union OpWlistData *)(inBuf + sizeof(struct MsgHead));
336 :
337 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpWlistData), sizeof(struct MsgHead), rcvBufLen, opResult);
338 2 : HCCP_CHECK_PARAM_NUM(wlistData->txData.num, MAX_WLIST_NUM);
339 :
340 2 : *opResult = gSocketOps.whiteListDel(wlistData->txData.rdevInfo, wlistData->txData.wlist, wlistData->txData.num);
341 2 : if (*opResult != 0) {
342 1 : hccp_err("white_list_del failed, ret[%d]", *opResult);
343 : }
344 2 : return 0;
345 : }
346 :
347 0 : int RaRsSocketWhiteListDelV2(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
348 : {
349 : (void)outBuf;
350 : (void)outLen;
351 0 : union OpWlistDataV2 *wlistData = (union OpWlistDataV2 *)(inBuf + sizeof(struct MsgHead));
352 :
353 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpWlistDataV2), sizeof(struct MsgHead), rcvBufLen, opResult);
354 0 : HCCP_CHECK_PARAM_NUM(wlistData->txData.num, MAX_WLIST_NUM);
355 :
356 0 : *opResult = gSocketOps.whiteListDel(wlistData->txData.rdevInfo, wlistData->txData.wlist, wlistData->txData.num);
357 0 : if (*opResult != 0) {
358 0 : hccp_err("white_list_del failed, ret[%d]", *opResult);
359 : }
360 0 : return 0;
361 : }
362 :
363 0 : int RaRsSocketCreditAdd(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
364 : {
365 : (void)outBuf;
366 : (void)outLen;
367 0 : union OpAcceptCreditData *opData = (union OpAcceptCreditData *)(inBuf + sizeof(struct MsgHead));
368 :
369 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpAcceptCreditData), sizeof(struct MsgHead), rcvBufLen, opResult);
370 0 : HCCP_CHECK_PARAM_NUM(opData->txData.num, MAX_SOCKET_NUM);
371 :
372 0 : *opResult = gSocketOps.acceptCreditAdd(opData->txData.conn, opData->txData.num, opData->txData.creditLimit);
373 0 : if (*opResult != 0) {
374 0 : hccp_err("accept_credit_add failed, ret[%d]", *opResult);
375 : }
376 0 : return 0;
377 : }
378 :
379 3 : int RaRsGetIfnum(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
380 : {
381 : (void)outLen;
382 3 : union OpIfnumData *ifnumData = (union OpIfnumData *)(inBuf + sizeof(struct MsgHead));
383 3 : union OpIfnumData *ifnumDataOut = NULL;
384 3 : unsigned int num = 0;
385 3 : bool isAll = false;
386 :
387 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpIfnumData), sizeof(struct MsgHead), rcvBufLen, opResult);
388 : /* resv bit 31 for is_all for compatibility issue */
389 3 : if ((ifnumData->txData.num & RA_RS_GET_ALL_IP_BIT_MASK) != 0) {
390 0 : isAll = true;
391 : }
392 3 : *opResult = gSocketOps.getIfnum(ifnumData->txData.phyId, isAll, &num);
393 3 : if (*opResult != 0) {
394 0 : hccp_err("ra_rs_get_ifnum result ret[%d].", *opResult);
395 0 : return 0;
396 : }
397 :
398 3 : ifnumDataOut = (union OpIfnumData *)(outBuf + sizeof(struct MsgHead));
399 3 : (ifnumDataOut->rxData).num = num;
400 :
401 3 : return 0;
402 : }
403 :
404 2 : int RaRsGetIfaddrs(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
405 : {
406 : (void)outLen;
407 : int ret;
408 2 : union OpIfaddrData *ifaddrDataOut = NULL;
409 2 : union OpIfaddrData *ifaddrData = (union OpIfaddrData *)(inBuf + sizeof(struct MsgHead));
410 :
411 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpIfaddrData), sizeof(struct MsgHead), rcvBufLen, opResult);
412 2 : CHK_PRT_RETURN(ifaddrData->txData.num > MAX_INTERFACE_NUM || ifaddrData->txData.num == 0,
413 : hccp_err("interface number is invalid, num[%u]", ifaddrData->txData.num), -EINVAL);
414 :
415 2 : *opResult = gSocketOps.getIfaddrs(ifaddrData->txData.ifaddrInfos, &(ifaddrData->txData.num),
416 : ifaddrData->txData.phyId);
417 2 : if (*opResult != 0) {
418 0 : hccp_err("ra_rs_get_ifaddrs result ret[%d].", *opResult);
419 0 : return 0;
420 : }
421 :
422 2 : ifaddrDataOut = (union OpIfaddrData *)(outBuf + sizeof(struct MsgHead));
423 :
424 2 : (ifaddrDataOut->rxData).num = ifaddrData->txData.num;
425 2 : ret = memcpy_s((ifaddrDataOut->rxData).ifaddrInfos, sizeof(struct IfaddrInfo) * MAX_INTERFACE_NUM,
426 2 : (ifaddrData->txData).ifaddrInfos, sizeof(struct IfaddrInfo) * (ifaddrData->txData).num);
427 2 : CHK_PRT_RETURN(ret, hccp_err("ra_rs_get_sockets memcpy_s failed, ret[%d]. ", ret), -ESAFEFUNC);
428 :
429 2 : return 0;
430 : }
431 :
432 2 : int RaRsGetIfaddrsV2(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
433 : {
434 : (void)outLen;
435 2 : union OpIfaddrDataV2 *ifaddrData = (union OpIfaddrDataV2 *)(inBuf + sizeof(struct MsgHead));
436 2 : union OpIfaddrDataV2 *ifaddrDataOut = NULL;
437 2 : bool isAll = false;
438 : int ret;
439 :
440 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpIfaddrDataV2), sizeof(struct MsgHead), rcvBufLen, opResult);
441 :
442 : /* resv bit 31 for is_all for compatibility issue */
443 2 : if ((ifaddrData->txData.num & RA_RS_GET_ALL_IP_BIT_MASK) != 0) {
444 0 : isAll = true;
445 : }
446 2 : ifaddrData->txData.num = ifaddrData->txData.num & (~RA_RS_GET_ALL_IP_BIT_MASK);
447 2 : CHK_PRT_RETURN(ifaddrData->txData.num > MAX_INTERFACE_NUM || ifaddrData->txData.num == 0,
448 : hccp_err("interface number of op_ifaddr_data_v2 is invalid, num[%u]", ifaddrData->txData.num), -EINVAL);
449 :
450 1 : *opResult = gSocketOps.getIfaddrsV2(ifaddrData->txData.interfaceInfos, &(ifaddrData->txData.num),
451 : ifaddrData->txData.phyId, isAll);
452 1 : if (*opResult != 0) {
453 0 : hccp_err("ra_rs_get_ifaddrs_v2 result ret[%d].", *opResult);
454 0 : return 0;
455 : }
456 :
457 1 : ifaddrDataOut = (union OpIfaddrDataV2 *)(outBuf + sizeof(struct MsgHead));
458 :
459 1 : (ifaddrDataOut->rxData).num = ifaddrData->txData.num;
460 1 : ret = memcpy_s((ifaddrDataOut->rxData).interfaceInfos, sizeof(struct InterfaceInfo) * MAX_INTERFACE_NUM,
461 1 : (ifaddrData->txData).interfaceInfos, sizeof(struct InterfaceInfo) * (ifaddrData->txData).num);
462 1 : CHK_PRT_RETURN(ret, hccp_err("ra_rs_get_ifaddrs_v2 memcpy_s failed, ret[%d].", ret), -ESAFEFUNC);
463 :
464 1 : return 0;
465 : }
466 :
467 2 : int RaRsGetVnicIp(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
468 : {
469 : (void)outLen;
470 2 : unsigned int vnicIp = 0;
471 2 : union OpGetVnicIpData *vnicIpDataRet = NULL;
472 2 : union OpGetVnicIpData *vnicIpData = (union OpGetVnicIpData *)(inBuf + sizeof(struct MsgHead));
473 :
474 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpGetVnicIpData), sizeof(struct MsgHead), rcvBufLen, opResult);
475 :
476 2 : *opResult = gSocketOps.getVnicIp(vnicIpData->txData.phyId, &vnicIp);
477 2 : if (*opResult != 0) {
478 1 : hccp_err("rs get vnic ip failed, phyId %d, ret %d", vnicIpData->txData.phyId, *opResult);
479 1 : return 0;
480 : }
481 :
482 1 : vnicIpDataRet = (union OpGetVnicIpData *)(outBuf + sizeof(struct MsgHead));
483 1 : hccp_info("rs get vnic_ip, phyId %d, vnicIp 0x%x", vnicIpData->txData.phyId, vnicIp);
484 1 : vnicIpDataRet->rxData.vnicIp = vnicIp;
485 1 : return 0;
486 : }
487 :
488 2 : int RaRsGetVnicIpInfosV1(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
489 : {
490 : (void)outLen;
491 2 : union OpGetVnicIpInfosDataV1 *vnicIpData = (union OpGetVnicIpInfosDataV1 *)(inBuf + sizeof(struct MsgHead));
492 2 : union OpGetVnicIpInfosDataV1 *vnicIpOut = (union OpGetVnicIpInfosDataV1 *)(outBuf + sizeof(struct MsgHead));
493 :
494 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpGetVnicIpInfosDataV1), sizeof(struct MsgHead), rcvBufLen, opResult);
495 : HCCP_CHECK_PARAM_LEN_RET_HOST(vnicIpData->txData.num, 0, MAX_IP_INFO_NUM_V1, opResult);
496 :
497 4 : *opResult = gSocketOps.getVnicIpInfos(vnicIpData->txData.phyId, vnicIpData->txData.type, vnicIpData->txData.ids,
498 2 : vnicIpData->txData.num, vnicIpOut->rxData.infos);
499 :
500 2 : if (*opResult != 0) {
501 1 : hccp_err("rs get vnic ip infos failed, ret %d", *opResult);
502 : }
503 :
504 2 : return 0;
505 : }
506 :
507 2 : int RaRsGetVnicIpInfos(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
508 : {
509 : (void)outLen;
510 2 : union OpGetVnicIpInfosData *vnicIpData = (union OpGetVnicIpInfosData *)(inBuf + sizeof(struct MsgHead));
511 2 : union OpGetVnicIpInfosData *vnicIpOut = (union OpGetVnicIpInfosData *)(outBuf + sizeof(struct MsgHead));
512 :
513 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpGetVnicIpInfosData), sizeof(struct MsgHead), rcvBufLen, opResult);
514 : HCCP_CHECK_PARAM_LEN_RET_HOST(vnicIpData->txData.num, 0, MAX_IP_INFO_NUM, opResult);
515 :
516 4 : *opResult = gSocketOps.getVnicIpInfos(vnicIpData->txData.phyId, vnicIpData->txData.type, vnicIpData->txData.ids,
517 2 : vnicIpData->txData.num, vnicIpOut->rxData.infos);
518 :
519 2 : if (*opResult != 0) {
520 1 : hccp_err("rs get vnic ip infos failed, ret %d", *opResult);
521 : }
522 :
523 2 : return 0;
524 : }
|