LCOV - code coverage report
Current view: top level - base_comm/resources/hccp/rdma_agent/adapter - ra_adp_socket.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 83.4 % 229 191
Test Date: 2026-07-28 12:11:00 Functions: 85.7 % 21 18

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

Generated by: LCOV version 2.0-1