VirtualBox

Ignore:
Timestamp:
Nov 6, 2015 1:43:02 AM (9 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
103951
Message:

lwip: Use different callback for proxy accept that is triggered by
receiving a SYN. Pass the SYN pbuf as a separate argument, so that we
can do it for normal listening pcbs too (they do use callback arg
unlike proxy). Adapt pxtcp to the change.

Location:
trunk/src/VBox/Devices/Network/lwip-new/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Network/lwip-new/src/core/tcp.c

    r58581 r58592  
    543543#endif /* LWIP_CALLBACK_API */
    544544
     545#if LWIP_CONNECTION_PROXY
     546/**
     547 * Default proxy accept syn callback if no accept callback is specified by the user.
     548 */
     549err_t
     550tcp_accept_syn_null(void *arg, struct tcp_pcb *newpcb, struct pbuf *syn)
     551{
     552  LWIP_UNUSED_ARG(arg);
     553  LWIP_UNUSED_ARG(syn);
     554
     555  tcp_abort(newpcb);
     556  return ERR_ABRT;
     557}
     558#endif /* LWIP_CONNECTION_PROXY */
     559
    545560/**
    546561 * Set the state of the connection to be LISTEN, which means that it
     
    15591574 */
    15601575void
    1561 tcp_proxy_accept(tcp_accept_fn accept)
    1562 {
    1563   tcp_proxy_accept_callback = accept;
     1576tcp_proxy_accept(tcp_accept_syn_fn accept_syn)
     1577{
     1578  tcp_proxy_accept_callback = accept_syn;
    15641579}
    15651580
     
    15711586 */
    15721587void
    1573 tcp_accept_syn(struct tcp_pcb *pcb, tcp_accept_fn accept)
     1588tcp_accept_syn(struct tcp_pcb *pcb, tcp_accept_syn_fn accept_syn)
    15741589{
    15751590  struct tcp_pcb_listen *lpcb;
     
    15781593  lpcb = (struct tcp_pcb_listen *)pcb;
    15791594
    1580   lpcb->accept = accept;
     1595  lpcb->accept = (tcp_accept_fn)accept_syn;
    15811596  lpcb->accept_on_syn = 1;
    15821597}
  • trunk/src/VBox/Devices/Network/lwip-new/src/core/tcp_in.c

    r58589 r58592  
    6464
    6565#if LWIP_CONNECTION_PROXY
    66 tcp_accept_fn tcp_proxy_accept_callback = tcp_accept_null;
     66tcp_accept_syn_fn tcp_proxy_accept_callback = tcp_accept_syn_null;
    6767#endif
    6868
     
    9090static void tcp_parseopt(struct tcp_pcb *pcb);
    9191
    92 static err_t tcp_listen_input(struct tcp_pcb_listen *pcb);
     92static err_t tcp_listen_input(struct tcp_pcb_listen *pcb, struct pbuf *syn);
    9393static err_t tcp_timewait_input(struct tcp_pcb *pcb);
    9494
    9595#if LWIP_CONNECTION_PROXY
    96 static err_t tcp_proxy_listen_input(struct pbuf *p);
     96static err_t tcp_proxy_listen_input(struct pbuf *syn);
    9797static void tcp_restore_pbuf(struct pbuf *p);
    9898
     
    314314   
    315315      LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_input: packed for LISTENing connection.\n"));
    316       tcp_listen_input(lpcb);
     316      tcp_listen_input(lpcb, p);
    317317      pbuf_free(p);
    318318      return;
     
    498498 */
    499499static err_t
    500 tcp_listen_input(struct tcp_pcb_listen *pcb)
     500tcp_listen_input(struct tcp_pcb_listen *pcb, struct pbuf *syn)
    501501{
    502502  struct tcp_pcb *npcb;
     
    572572    /* Early accept on SYN, like we do in tcp_proxy_listen_input() */
    573573    if (pcb->accept_on_syn) {
     574      tcp_accept_syn_fn accept_syn;
    574575      err_t err;
    575576
     
    578579
    579580      /*
    580        * XXX: TODO: how to pass syn pbuf?  Need to be consistent with
    581        * proxy version, but can't abuse callback_arg here since it's
    582        * actually used in this case.
     581       * Call the accept syn function.  Note, that it comes from the
     582       * listening pcb and we reset the normal accept callback of the
     583       * new pcb.  The latter should be set by the client along with
     584       * other callbacks if necessary.
    583585       */
    584       /* Call the accept function. */
    585       TCP_EVENT_ACCEPT(npcb, ERR_OK, err);
     586      accept_syn = (tcp_accept_syn_fn)npcb->accept;
     587      npcb->accept = tcp_accept_null;
     588
     589      /* TCP_EVENT_ACCEPT_SYN */
     590      if (accept_syn != NULL)
     591        err = (*accept_syn)(npcb->callback_arg, npcb, syn);
     592      else
     593        err = ERR_ARG;
     594
    586595      if (err != ERR_OK) {
    587596        /* If the accept function returns with an error, we abort
     
    645654 */
    646655static err_t
    647 tcp_proxy_listen_input(struct pbuf *p)
     656tcp_proxy_listen_input(struct pbuf *syn)
    648657{
    649658  struct tcp_pcb *npcb;
     
    700709    npcb->callback_arg = /* pcb->callback_arg */ NULL;
    701710#if LWIP_CALLBACK_API
    702     npcb->accept = /* pcb->accept */ tcp_proxy_accept_callback;
     711    npcb->accept = /* pcb->accept */ tcp_accept_null;
    703712#endif /* LWIP_CALLBACK_API */
    704713    /* inherit socket options */
     
    733742     */
    734743
    735     tcp_restore_pbuf(p);
    736     npcb->callback_arg = (void *)p;
    737  
    738     /* Call the accept function. */
    739     TCP_EVENT_ACCEPT(npcb, ERR_OK, err);
     744    tcp_restore_pbuf(syn);
     745
     746    /* TCP_EVENT_ACCEPT_SYN */
     747    if (tcp_proxy_accept_callback != NULL)
     748      err = (*tcp_proxy_accept_callback)(NULL, npcb, syn);
     749    else
     750      err = ERR_ARG;
     751
    740752    if (err != ERR_OK) {
    741753        /* If the accept function returns with an error, we abort
  • trunk/src/VBox/Devices/Network/lwip-new/src/include/lwip/tcp.h

    r58555 r58592  
    6161 */
    6262typedef err_t (*tcp_accept_fn)(void *arg, struct tcp_pcb *newpcb, err_t err);
     63
     64#if LWIP_CONNECTION_PROXY
     65/** Function prototype for tcp accept callback functions. Called when
     66 * a new connection is about to be accepted by the proxy or on a
     67 * listening pcb that requested proxy-like accept on syn.
     68 *
     69 * @param arg Additional argument to pass to the callback function (@see tcp_arg())
     70 * @param newpcb The new connection pcb
     71 * @param syn The pbuf with the SYN segment (may be used to reply with ICMP).
     72 */
     73typedef err_t (*tcp_accept_syn_fn)(void *arg, struct tcp_pcb *newpcb, struct pbuf *syn);
     74#endif /* LWIP_CONNECTION_PROXY */
    6375
    6476/** Function prototype for tcp receive callback functions. Called when data has
     
    333345/* when proxied connection is accepted there's no listening pcb */
    334346void             tcp_proxy_arg(void *arg);
    335 void             tcp_proxy_accept(tcp_accept_fn accept);
     347void             tcp_proxy_accept(tcp_accept_syn_fn accept);
    336348/* but we also provide proxy-like early accept for listening pcbs */
    337 void             tcp_accept_syn(struct tcp_pcb *lpcb, tcp_accept_fn accept);
     349void             tcp_accept_syn(struct tcp_pcb *lpcb, tcp_accept_syn_fn accept);
    338350#endif
    339351void             tcp_recv    (struct tcp_pcb *pcb, tcp_recv_fn recv);
  • trunk/src/VBox/Devices/Network/lwip-new/src/include/lwip/tcp_impl.h

    r58581 r58592  
    314314
    315315#if LWIP_CONNECTION_PROXY
    316 extern tcp_accept_fn tcp_proxy_accept_callback;
     316extern tcp_accept_syn_fn tcp_proxy_accept_callback;
    317317#endif
    318318
     
    489489#endif /* LWIP_CALLBACK_API */
    490490
     491#if LWIP_CONNECTION_PROXY
     492err_t tcp_accept_syn_null(void *arg, struct tcp_pcb *newpcb, struct pbuf *syn);
     493#endif /* LWIP_CONNECTION_PROXY */
     494
    491495#if TCP_DEBUG || TCP_INPUT_DEBUG || TCP_OUTPUT_DEBUG
    492496void tcp_debug_print(struct tcp_hdr *tcphdr);
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