VirtualBox

Changeset 64585 in vbox


Ignore:
Timestamp:
Nov 4, 2016 8:52:10 PM (8 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
111774
Message:

slirp/tftp: LogRel for TFTP requests.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Network/slirp/tftp.c

    r63621 r64585  
    259259    int fWithArg = 0;
    260260    int idxOptionArg = 0;
     261
    261262    AssertPtrReturn(pTftpSession, VERR_INVALID_PARAMETER);
    262263    AssertPtrReturn(pcTftpIpHeader, VERR_INVALID_PARAMETER);
    263264    AssertReturn(RT_N2H_U16(pcTftpIpHeader->u16TftpOpType) == TFTP_RRQ, VERR_INVALID_PARAMETER);
    264265    LogFlowFunc(("pTftpSession:%p, pcTftpIpHeader:%p\n", pTftpSession, pcTftpIpHeader));
     266
    265267    pszTftpRRQRaw = (char *)&pcTftpIpHeader->Core;
    266268    cbTftpRRQRaw = RT_H2N_U16(pcTftpIpHeader->UdpHdr.uh_ulen) + sizeof(struct ip) - RT_OFFSETOF(TFTPIPHDR, Core);
     
    400402}
    401403
    402 DECLINLINE(int) pftpSessionOpenFile(PNATState pData, PTFTPSESSION pTftpSession, PRTFILE pSessionFile)
    403 {
    404     char aszSessionFileName[TFTP_FILENAME_MAX];
    405     size_t cbSessionFileName;
    406     int rc = VINF_SUCCESS;
     404DECLINLINE(int) pftpSessionOpenFile(PNATState pData, PTFTPSESSION pTftpSession, bool fVerbose, PRTFILE pSessionFile)
     405{
     406    char szSessionFilename[TFTP_FILENAME_MAX];
     407    ssize_t cchSessionFilename;
     408    int rc;
    407409    LogFlowFuncEnter();
    408     cbSessionFileName = RTStrPrintf(aszSessionFileName, TFTP_FILENAME_MAX, "%s/%s",
    409                     tftp_prefix, pTftpSession->pszFilename);
    410     if (cbSessionFileName >= TFTP_FILENAME_MAX)
    411     {
    412         LogFlowFuncLeaveRC(VERR_INTERNAL_ERROR);
    413         return VERR_INTERNAL_ERROR;
    414     }
    415     LogFunc(("aszSessionFileName: %s\n", aszSessionFileName));
    416 
    417     if (!RTFileExists(aszSessionFileName))
    418     {
    419         LogFlowFuncLeaveRC(VERR_FILE_NOT_FOUND);
    420         return VERR_FILE_NOT_FOUND;
    421     }
    422 
    423     rc = RTFileOpen(pSessionFile, aszSessionFileName, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE);
     410
     411    cchSessionFilename = RTStrPrintf2(szSessionFilename, TFTP_FILENAME_MAX, "%s/%s", tftp_prefix, pTftpSession->pszFilename);
     412    if (cchSessionFilename > 0)
     413    {
     414        LogFunc(("szSessionFilename: %s\n", szSessionFilename));
     415        if (RTFileExists(szSessionFilename))
     416        {
     417            rc = RTFileOpen(pSessionFile, szSessionFilename, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE);
     418        }
     419        else
     420            rc = VERR_FILE_NOT_FOUND;
     421    }
     422    else
     423        rc = VERR_FILENAME_TOO_LONG;
     424    if (fVerbose)
     425        LogRel(("NAT TFTP: %s/%s -> %Rrc\n", tftp_prefix, pTftpSession->pszFilename, rc));
    424426    LogFlowFuncLeaveRC(rc);
    425427    return rc;
     
    428430DECLINLINE(int) tftpSessionEvaluateOptions(PNATState pData, PTFTPSESSION pTftpSession)
    429431{
    430     int rc = VINF_SUCCESS;
     432    int rc;
    431433    RTFILE hSessionFile;
    432434    uint64_t cbSessionFile = 0;
    433435    LogFlowFunc(("pTftpSession:%p\n", pTftpSession));
    434436
    435     rc = pftpSessionOpenFile(pData, pTftpSession, &hSessionFile);
     437    rc = pftpSessionOpenFile(pData, pTftpSession, true /*fVerbose*/, &hSessionFile);
    436438    if (RT_FAILURE(rc))
    437439    {
     
    482484    return rc;
    483485}
    484 DECLINLINE(int) tftpSendError(PNATState pData, PTFTPSESSION pTftpSession, uint16_t errorcode, const char *msg, PCTFTPIPHDR pcTftpIpHeaderRecv);
     486
     487
     488DECLINLINE(int) tftpSendError(PNATState pData, PTFTPSESSION pTftpSession, uint16_t errorcode,
     489                              const char *msg, PCTFTPIPHDR pcTftpIpHeaderRecv); /* gee wiz */
    485490
    486491DECLINLINE(int) tftpReadDataBlock(PNATState pData,
     
    503508
    504509    u16BlkSize = (uint16_t)pcTftpSession->OptionBlkSize.u64Value;
    505     rc = pftpSessionOpenFile(pData, pcTftpSession, &hSessionFile);
     510    rc = pftpSessionOpenFile(pData, pcTftpSession, false /*fVerbose*/, &hSessionFile);
    506511    if (RT_FAILURE(rc))
    507512    {
     
    542547DECLINLINE(int) tftpAddOptionToOACK(PNATState pData, struct mbuf *pMBuf, const char *pszOptName, uint64_t u64OptValue)
    543548{
    544     char aszOptionBuffer[256];
     549    char szOptionBuffer[256];
    545550    size_t iOptLength;
    546551    int rc = VINF_SUCCESS;
     
    550555    AssertPtrReturn(pszOptName, VERR_INVALID_PARAMETER);
    551556
    552     RT_ZERO(aszOptionBuffer);
    553     iOptLength  = RTStrPrintf(aszOptionBuffer, 256 , "%s", pszOptName) + 1;
    554     iOptLength += RTStrPrintf(aszOptionBuffer + iOptLength, 256 - iOptLength , "%llu", u64OptValue) + 1;
     557    RT_ZERO(szOptionBuffer);
     558    iOptLength  = RTStrPrintf(szOptionBuffer, 256 , "%s", pszOptName) + 1;
     559    iOptLength += RTStrPrintf(szOptionBuffer + iOptLength, 256 - iOptLength , "%llu", u64OptValue) + 1;
    555560    if (iOptLength > M_TRAILINGSPACE(pMBuf))
    556561        rc = VERR_BUFFER_OVERFLOW; /* buffer too small */
     
    558563    {
    559564        pMBuf->m_len += (int)iOptLength;
    560         m_copyback(pData, pMBuf, cbMBufCurrent, (int)iOptLength, aszOptionBuffer);
     565        m_copyback(pData, pMBuf, cbMBufCurrent, (int)iOptLength, szOptionBuffer);
    561566    }
    562567    LogFlowFuncLeaveRC(rc);
     
    565570
    566571DECLINLINE(int) tftpSendOACK(PNATState pData,
    567                           PTFTPSESSION pTftpSession,
    568                           PCTFTPIPHDR pcTftpIpHeaderRecv)
     572                             PTFTPSESSION pTftpSession,
     573                             PCTFTPIPHDR pcTftpIpHeaderRecv)
    569574{
    570575    struct mbuf *m;
    571576    PTFTPIPHDR pTftpIpHeader;
    572     int rc = VINF_SUCCESS;
     577    int rc;
    573578
    574579    rc = tftpSessionEvaluateOptions(pData, pTftpSession);
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette