VirtualBox

Changeset 58613 in vbox for trunk/src/VBox/NetworkServices


Ignore:
Timestamp:
Nov 9, 2015 2:45:26 AM (9 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
103987
Message:

NAT/Net: Export pxtcp_pcb_accept_outbound() and use it to provide DNS
TCP proxy. For now we only try to connect to the first resolver,
since we simply hand off connection to pxtcp and there are currently
no hooks for us to retry connection to a different server.

Location:
trunk/src/VBox/NetworkServices/NAT
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/NetworkServices/NAT/pxdns.c

    r56300 r58613  
    4343#include "proxy.h"
    4444#include "proxy_pollmgr.h"
     45#include "pxtcp.h"
    4546
    4647#include "lwip/sys.h"
    4748#include "lwip/tcpip.h"
     49#include "lwip/ip_addr.h"
    4850#include "lwip/udp.h"
     51#include "lwip/tcp.h"
    4952
    5053#ifndef RT_OS_WINDOWS
     
    8487    struct udp_pcb *pcb6;
    8588
     89    struct tcp_pcb *ltcp;
     90
    8691    size_t generation;
    8792    size_t nresolvers;
     
    177182static void pxdns_create_resolver_sockaddrs(struct pxdns *pxdns,
    178183                                            const char **nameservers);
     184
     185static err_t pxdns_accept_syn(void *arg, struct tcp_pcb *newpcb, struct pbuf *syn);
    179186
    180187static void pxdns_recv4(void *arg, struct udp_pcb *pcb, struct pbuf *p,
     
    211218    LWIP_UNUSED_ARG(proxy_netif);
    212219
     220    pxdns->ltcp = tcp_new();
     221    if (pxdns->ltcp != NULL) {
     222        tcp_bind_ip6(pxdns->ltcp, IP6_ADDR_ANY, 53);
     223        pxdns->ltcp = tcp_listen_dual(pxdns->ltcp);
     224        if (pxdns->ltcp != NULL) {
     225            tcp_arg(pxdns->ltcp, pxdns);
     226            tcp_accept_syn(pxdns->ltcp, pxdns_accept_syn);
     227        }
     228    }
     229
    213230    pxdns->pmhdl4.callback = pxdns_pmgr_pump;
    214231    pxdns->pmhdl4.data = (void *)pxdns;
     
    863880    pxdns_request_free(req);
    864881}
     882
     883
     884/**
     885 * TCP DNS proxy.  This kicks in for large replies that don't fit into
     886 * 512 bytes of UDP payload.  Client will retry with TCP to get
     887 * complete reply.
     888 */
     889static err_t
     890pxdns_accept_syn(void *arg, struct tcp_pcb *newpcb, struct pbuf *syn)
     891{
     892    struct pxdns *pxdns = (struct pxdns *)arg;
     893    union sockaddr_inet *si;
     894    ipX_addr_t *dst;
     895    u16_t dst_port;
     896
     897    tcp_accepted(pxdns->ltcp);
     898
     899    if (pxdns->nresolvers == 0) {
     900        return ERR_CONN;
     901    }
     902
     903    si = &pxdns->resolvers[0];
     904
     905    if (si->sa.sa_family == AF_INET6) {
     906        dst = (ipX_addr_t *)&si->sin6.sin6_addr;
     907        dst_port = ntohs(si->sin6.sin6_port);
     908    }
     909    else {
     910        dst = (ipX_addr_t *)&si->sin.sin_addr;
     911        dst_port = ntohs(si->sin.sin_port);
     912    }
     913
     914    /*
     915     * XXX: TODO: need to implement protocol hooks.  E.g. here if
     916     * connect fails, we should try connecting to a different server.
     917     */
     918    return pxtcp_pcb_accept_outbound(newpcb, syn,
     919               si->sa.sa_family == AF_INET6, dst, dst_port);
     920}
  • trunk/src/VBox/NetworkServices/NAT/pxtcp.c

    r58592 r58613  
    276276static void pxtcp_pcb_err(void *, err_t);
    277277
    278 static err_t pxtcp_pcb_accept_outbound(struct tcp_pcb *, struct pbuf *, int, ipX_addr_t *, u16_t);
    279 
    280278static err_t pxtcp_pcb_forward_outbound(struct pxtcp *, struct pbuf *);
    281279static void pxtcp_pcb_forward_outbound_close(struct pxtcp *);
     
    10121010
    10131011
    1014 static err_t
     1012err_t
    10151013pxtcp_pcb_accept_outbound(struct tcp_pcb *newpcb, struct pbuf *p,
    10161014                          int is_ipv6, ipX_addr_t *dst_addr, u16_t dst_port)
  • trunk/src/VBox/NetworkServices/NAT/pxtcp.h

    r56300 r58613  
    1919#define _pxtcp_h_
    2020
     21#include "lwip/err.h"
     22#include "lwip/ip_addr.h"
     23
     24struct pbuf;
     25struct tcp_pcb;
    2126struct pxtcp;
    2227struct fwspec;
     28
     29err_t pxtcp_pcb_accept_outbound(struct tcp_pcb *, struct pbuf *, int, ipX_addr_t *, u16_t);
    2330
    2431struct pxtcp *pxtcp_create_forwarded(SOCKET);
Note: See TracChangeset for help on using the changeset viewer.

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