VirtualBox

Changeset 40621 in vbox for trunk/src


Ignore:
Timestamp:
Mar 26, 2012 1:18:08 AM (13 years ago)
Author:
vboxsync
Message:

NAT: libalias closes self sockets, and Slirp inform libalias in case it closes its socket.

Location:
trunk/src/VBox/Devices/Network/slirp
Files:
4 edited

Legend:

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

    r40583 r40621  
    345345     */
    346346    int     sockfd; /* socket descriptor                   */
     347#  else
     348    struct socket *pSo;
    347349# endif
    348350#endif
     
    570572static int  GetNewPort(struct libalias *, struct alias_link *, int);
    571573#ifndef NO_USE_SOCKETS
     574# ifdef VBOX
     575static u_short  GetSocket(struct libalias *, u_short, struct alias_link*, int);
     576# else
    572577static u_short  GetSocket(struct libalias *, u_short, int *, int);
     578# endif
    573579#endif
    574580static void CleanupAliasData(struct libalias *);
     
    688694                if (GetSocket(la, port_net, &lnk->sockfd, lnk->link_type)) {
    689695#else
    690                 if (GetSocket(la, port_net, NULL, lnk->link_type)) {
     696                if (GetSocket(la, port_net, lnk, lnk->link_type)) {
    691697#endif
    692698                    lnk->alias_port = port_net;
     
    716722#ifndef NO_USE_SOCKETS
    717723static      u_short
     724# ifndef VBOX
    718725GetSocket(struct libalias *la, u_short port_net, int *sockfd, int link_type)
     726# else
     727GetSocket(struct libalias *la, u_short port_net, struct alias_link *pLnk, int link_type)
     728# endif
    719729{
    720730    int err;
     
    727737    struct sockaddr sa_addr;
    728738    socklen_t socklen = sizeof(struct sockaddr);
    729     NOREF(sockfd);
    730739#endif
    731740
     
    816825        }
    817826        LogFunc(("bind called for socket: %R[natsock]\n", so));
     827        pLnk->pSo = so;
     828        so->so_pvLnk = pLnk;
    818829#else
    819830        *sockfd = sock;
     
    970981}
    971982
     983#ifdef VBOX
     984/**
     985 * when slirp delete the link we need inform libalias about it.
     986 */
     987void slirpDeleteLinkSocket(void *pvLnk)
     988{
     989        struct alias_link *lnk = (struct alias_link *)pvLnk;
     990        lnk->pSo = NULL;
     991}
     992#endif /* !VBOX */
     993
    972994static void
    973995DeleteLink(struct alias_link *lnk)
    974996{
    975997    struct libalias *la = lnk->la;
     998    LogFlowFunc(("ENTER: lnk->pSo:%R[natsock]\n", lnk->pSo));
    976999
    9771000    LIBALIAS_LOCK_ASSERT(la);
     
    10081031    }
    10091032# else
    1010     /* Slirp will close the socket in its own way */
     1033    if (lnk->pSo)
     1034    {
     1035        la->sockCount--;
     1036        /* should we be more smart, or it's enough to be
     1037         * narrow-minded and just do sofree here
     1038         */
     1039        sofree(la->pData, lnk->pSo);
     1040        lnk->pSo = NULL;
     1041    }
    10111042# endif
    10121043#endif
     
    10481079        ShowAliasStats(la);
    10491080    }
     1081    LogFlowFuncLeave();
    10501082}
    10511083
     
    10811113# ifndef VBOX
    10821114        lnk->sockfd = -1;
     1115# else
     1116        lnk->pSo = NULL;
    10831117# endif
    10841118#endif
  • trunk/src/VBox/Devices/Network/slirp/socket.c

    r40423 r40621  
    187187    else if (so == udp_last_so)
    188188        udp_last_so = &udb;
     189    /* libalias notification */
     190    if (so->so_pvLnk)
     191        slirpDeleteLinkSocket(so->so_pvLnk);
    189192
    190193    /* check if mbuf haven't been already freed  */
     
    12241227sofcantrcvmore(struct  socket *so)
    12251228{
     1229    LogFlowFunc(("ENTER: so:%R[natsock]\n", so));
    12261230    if ((so->so_state & SS_NOFDREF) == 0)
    12271231    {
     
    12341238    else
    12351239        so->so_state |= SS_FCANTRCVMORE;
     1240    LogFlowFuncLeave();
    12361241}
    12371242
     
    12391244sofcantsendmore(struct socket *so)
    12401245{
     1246    LogFlowFunc(("ENTER: so:%R[natsock]\n", so));
    12411247    if ((so->so_state & SS_NOFDREF) == 0)
    12421248        shutdown(so->s, 1);           /* send FIN to fhost */
     
    12471253    else
    12481254        so->so_state |= SS_FCANTSENDMORE;
     1255    LogFlowFuncLeave();
    12491256}
    12501257
  • trunk/src/VBox/Devices/Network/slirp/socket.h

    r39299 r40621  
    106106    /* required for port-forwarding */
    107107    struct libalias *so_la;
     108    /* libalias might attach the socket and we want to notify libalias we're freeing it */
     109    void *so_pvLnk;
    108110#ifdef VBOX_WITH_NAT_UDP_SOCKET_CLONE
    109111    struct socket *so_cloneOf; /* pointer to master instance */
     
    111113#endif
    112114};
     115
     116/* this function inform libalias about socket close */
     117void slirpDeleteLinkSocket(void *pvLnk);
    113118
    114119#ifdef VBOX_WITH_SLIRP_MT
  • trunk/src/VBox/Devices/Network/slirp/tcp_subr.c

    r40583 r40621  
    355355{
    356356    LogFlowFunc(("ENTER: tp = %R[tcpcb793]\n", tp));
     357    LogFunc(("tp->t_socket:%R[natsock]\n",tp->t_socket));
    357358
    358359    switch (tp->t_state)
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