alias_dns.c revision 8249645203450de75a21975d1acd4dbadac56897
/* $Id$ */
/** @file
* libalias helper for using the host resolver instead of dnsproxy.
*/
/*
* Copyright (C) 2009 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
#ifndef RT_OS_WINDOWS
# include <netdb.h>
#endif
#include <slirp.h>
#include "alias.h"
#include "alias_local.h"
#include "alias_mod.h"
#define DNS_CONTROL_PORT_NUMBER 53
/* see RFC 1035(4.1.1) */
union dnsmsg_header
{
struct
{
unsigned id:16;
unsigned rd:1;
unsigned tc:1;
unsigned aa:1;
unsigned opcode:4;
unsigned qr:1;
unsigned rcode:4;
unsigned Z:3;
unsigned ra:1;
} X;
};
struct dns_meta_data
{
};
struct dnsmsg_answer
{
struct dns_meta_data meta;
};
/* see RFC 1035(4.1) */
#endif
static int
{
return -1;
Log(("NAT:%s: ah(dport: %hd, sport: %hd) oaddr:%RTnaipv4 aaddr:%RTnaipv4\n",
return 0;
return -1;
}
static void doanswer(union dnsmsg_header *pHdr, struct dns_meta_data *pReqMeta, char *pszQname, struct ip *pIp, struct hostent *pHostent)
{
int i;
if (!pHostent)
{
}
else
{
char *query;
char *answers;
char **cstr;
char *c;
uint16_t packet_len = 0;
struct dns_meta_data *meta;
#if 0
/* here is no compressed names+answers + new query */
m_inc(m, pHostent->h_length * sizeof(struct dnsmsg_answer) + strlen(pszQname) + 2 * sizeof(uint16_t));
#endif
+ sizeof(struct udphdr)
+ sizeof(union dnsmsg_header)
+ sizeof(struct dns_meta_data); /* ip + udp + header + query */
/* class & type informations lay right after symbolic inforamtion. */
/* answers zone lays after query in response packet */
/* add aliases */
{
}
/* add addresses */
{
}
/* don't forget update m_len */
}
}
static int
{
int i;
/* Parse dns request */
char pszCname[255];
int cname_len = 0;
struct dns_meta_data *meta;
return 0; /* this is respose */
{
static bool fMultiWarn;
if (!fMultiWarn)
{
LogRel(("NAT:alias_dns: multiple quieries isn't supported\n"));
fMultiWarn = true;
}
return 1;
}
{
Log(("pszQname:%s qtype:%hd qclass:%hd\n",
/* Some guests like win-xp adds _dot_ after host name
* and after domain name (not passed with host resolver)
* that confuses host resolver.
*/
if ( cname_len > 2
{
}
if ( pHostent
#endif
}
/*
* We have changed the size and the content of udp, to avoid double csum calculation
* will assign to zero
*/
return 0;
}
/*
* qstr is z-string with -dot- replaced with \count to next -dot-
* e.g. ya.ru is \02ya\02ru
* Note: it's assumed that caller allocates buffer for cstr
*/
{
const char *q;
char *c;
{
if ( isalpha(*q)
|| isdigit(*q)
|| *q == '-'
|| *q == '_')
{
*c = *q;
c++;
}
else if (c != &pszStr[0])
{
*c = '.';
c++;
}
}
*c = '\0';
}
/*
*
*/
{
const char *c;
const char *pc;
char *q;
{
/* at the begining or at -dot- position */
{
if (c != pcszStr)
c++;
}
else
{
*q = *c;
c++;
}
}
*q = '\0';
}
int
{
}
int
{
}
static int
{
int error;
if (!handlers)
switch (type)
{
case MOD_LOAD:
error = 0;
break;
case MOD_UNLOAD:
error = 0;
break;
default:
}
return error;
}
static bool isDnsMappingEntryMatchOrEqual2Str(const PDNSMAPPINGENTRY pDNSMapingEntry, const char *pcszString)
{
return ( ( pDNSMapingEntry->pszCName
|| ( pDNSMapingEntry->pszPattern
&& RTStrSimplePatternMultiMatch(pDNSMapingEntry->pszPattern, RTSTR_MAX, pcszString, RTSTR_MAX, NULL)));
}
{
bool fMatch = false;
{
{
fMatch = true;
break;
}
{
{
fMatch = true;
if (!pDnsMapping)
{
LogFunc(("Can't allocate DNSMAPPINGENTRY\n"));
return;
}
if (!pDnsMapping->pszCName)
{
return;
}
LogRel(("NAT: user-defined mapping %s: %RTnaipv4 is registered\n",
}
}
if (fMatch)
break;
}
/* h_lenght is lenght of h_addr_list in bytes, so we check that we have enough space for IPv4 address */
if ( fMatch
&& pDNSMapingEntry)
{
}
}
#endif