/*-
* Written by Atsushi Murai <amurai@spec.co.jp>
* Copyright (c) 1998, System Planning and Engineering Co.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* TODO:
* oClean up.
* oConsidering for word alignment for other platform.
*/
#ifndef VBOX
__FBSDID("$FreeBSD: src/sys/netinet/libalias/alias_nbt.c,v 1.20.8.1 2009/04/15 03:14:26 kensmith Exp $");
/*
alias_nbt.c performs special processing for NetBios over TCP/IP
sessions by UDP.
Initial version: May, 1998 (Atsushi Murai <amurai@spec.co.jp>)
See HISTORY file for record of revisions.
*/
/* Includes */
#ifdef _KERNEL
#else
#include <errno.h>
#include <stdio.h>
#endif
#include <netinet/in_systm.h>
#ifdef _KERNEL
#else
#include "alias_local.h"
#include "alias_mod.h"
#endif
#else /* VBOX */
# include <slirp.h>
# include "alias_local.h"
# include "alias_mod.h"
#endif /* VBOX */
static int
static int
static int
{
#ifdef VBOX
#endif
return (-1);
return (0);
return (-1);
}
static int
{
return (0);
}
static int
{
#ifdef VBOX
#endif
return (-1);
return (0);
return (-1);
}
static int
{
return (0);
}
static int
{
return (0);
}
/* Kernel module definition. */
#ifndef VBOX
{
.pri = 130,
.fingerprint = &fingerprint1,
},
{
.pri = 140,
.fingerprint = &fingerprint2,
},
{
.pri = 140,
.fingerprint = &fingerprint2,
},
{ EOH }
};
#else /* VBOX */
#endif /* VBOX */
#ifndef VBOX
static int
#else /* VBOX */
int
{
}
int
{
}
static int
#endif /* VBOX */
{
int error;
#ifdef VBOX
#endif /* VBOX */
switch (type) {
case MOD_LOAD:
error = 0;
#ifdef VBOX
#else
#endif
break;
case MOD_UNLOAD:
error = 0;
#ifdef VBOX
#else
#endif
break;
default:
}
return (error);
}
#ifndef VBOX
#ifdef _KERNEL
static
#endif
};
#endif /* !VBOX */
#ifdef _KERNEL
#endif
typedef struct {
} NBTArguments;
typedef struct {
unsigned char type;
unsigned char flags;
#define OpQuery 0
typedef struct {
#ifndef VBOX
#else
unsigned nametrid:16;
#endif
} NbtNSHeader;
#ifdef LIBALIAS_DEBUG
static void
{
switch (rcode) {
case FMT_ERR:
printf("\nFormat Error.");
case SRV_ERR:
printf("\nSever failure.");
case IMP_ERR:
printf("\nUnsupported request error.\n");
case RFS_ERR:
printf("\nRefused error.\n");
case ACT_ERR:
printf("\nActive error.\n");
case CFT_ERR:
printf("\nName in conflict error.\n");
default:
}
}
#endif
/* Handling Name field */
static u_char *
{
u_char *s;
#ifdef LIBALIAS_DEBUG
u_char c;
#endif
int compress;
/* Following length field */
return (NULL);
if (*p & 0xc0) {
p = p + 2;
if ((char *)p > pmax)
return (NULL);
return ((u_char *) p);
}
while ((*p & 0x3f) != 0x00) {
s = p + 1;
if (*p == 0x20)
compress = 1;
else
compress = 0;
/* Get next length field */
if ((char *)p > pmax) {
p = NULL;
break;
}
#ifdef LIBALIAS_DEBUG
printf(":");
#endif
while (s < p) {
if (compress == 1) {
#ifdef LIBALIAS_DEBUG
if (isprint(c))
printf("%c", c);
else
printf("<0x%02x>", c);
#endif
s += 2;
} else {
#ifdef LIBALIAS_DEBUG
printf("%c", *s);
#endif
s++;
}
}
#ifdef LIBALIAS_DEBUG
printf(":");
#endif
}
/* Set up to out of Name field */
p = NULL;
else
p++;
return ((u_char *) p);
}
/*
*/
static int
struct alias_link *lnk,
struct in_addr *alias_address,
)
{
char *pmax;
(void)la;
(void)lnk;
/* Calculate data length of UDP packet */
return (-1);
#ifdef LIBALIAS_DEBUG
#endif
case DGM_DIRECT_UNIQ:
case DGM_DIRECT_GROUP:
case DGM_BROADCAST:
break;
case DGM_ERROR:
break;
case DGM_QUERY:
case DGM_POSITIVE_RES:
case DGM_NEGATIVE_RES:
break;
}
p = NULL;
#ifdef LIBALIAS_DEBUG
#endif
/* Doing an IP address and Port number Translation */
int acc;
acc -= alias_port;
}
#ifdef LIBALIAS_DEBUG
#endif
return ((p == NULL) ? -1 : 0);
}
/* Question Section */
typedef struct {
static u_char *
NBTNsQuestion * q,
char *pmax,
{
(void)nbtarg;
while (count != 0) {
/* Name Filed */
q = NULL;
break;
}
/* Type and Class filed */
case QS_TYPE_NB:
case QS_TYPE_NBSTAT:
q = q + 1;
break;
default:
#ifdef LIBALIAS_DEBUG
#endif
break;
}
count--;
}
/* Set up to out of Question Section */
return ((u_char *) q);
}
/* Resource Record */
typedef struct {
unsigned int ttl;
typedef struct {
#ifndef VBOX
#else
#endif
} NBTNsRNB;
static u_char *
NBTNsResource * q,
char *pmax,
{
return (NULL);
/* Check out a length */
/* Forward to Resource NB position */
/* Processing all in_addr array */
#ifdef LIBALIAS_DEBUG
#endif
break;
}
#ifdef LIBALIAS_DEBUG
#endif
int acc;
}
#ifdef LIBALIAS_DEBUG
printf("O");
#endif
}
#ifdef LIBALIAS_DEBUG
else {
printf(".");
}
#endif
bcount -= SizeOfNsRNB;
}
}
}
typedef struct {
static u_char *
NBTNsResource * q,
char *pmax,
{
NBTNsResourceA *a;
return (NULL);
/* Forward to Resource A position */
/* Check out of length */
/* Processing all in_addr array */
#ifdef LIBALIAS_DEBUG
#endif
while (bcount != 0) {
return (NULL);
#ifdef LIBALIAS_DEBUG
#endif
int acc;
}
}
a++; /* XXXX */
}
a = NULL;
return ((u_char *) a);
}
typedef struct {
#ifndef VBOX
#else
#endif
static u_char *
NBTNsResource * q,
char *pmax,
{
(void)nbtarg;
return (NULL);
/* Forward to Resource NULL position */
/* Check out of length */
/* Processing all in_addr array */
while (bcount != 0) {
if ((char *)(n + 1) > pmax) {
n = NULL;
break;
}
n++;
bcount -= sizeof(NBTNsResourceNULL);
}
if ((char *)(n + 1) > pmax)
n = NULL;
return ((u_char *) n);
}
static u_char *
NBTNsResource * q,
char *pmax,
{
(void)nbtarg;
return (NULL);
/* Forward to Resource NULL position */
/* Check out of length */
/* Resource Record Name Filed */
return (NULL);
else
}
typedef struct {
static u_char *
NBTNsResource * q,
char *pmax,
{
(void)nbtarg;
return (NULL);
/* Forward to Resource NBSTAT position */
/* Check out of length */
return (NULL);
else
}
static u_char *
NBTNsResource * q,
char *pmax,
* nbtarg)
{
while (count != 0) {
/* Resource Record Name Filed */
break;
#ifdef LIBALIAS_DEBUG
#endif
/* Type and Class filed */
case RR_TYPE_NB:
q = (NBTNsResource *) AliasHandleResourceNB(
q,
pmax,
);
break;
case RR_TYPE_A:
q = (NBTNsResource *) AliasHandleResourceA(
q,
pmax,
);
break;
case RR_TYPE_NS:
q = (NBTNsResource *) AliasHandleResourceNS(
q,
pmax,
);
break;
case RR_TYPE_NULL:
q = (NBTNsResource *) AliasHandleResourceNULL(
q,
pmax,
);
break;
case RR_TYPE_NBSTAT:
q = (NBTNsResource *) AliasHandleResourceNBSTAT(
q,
pmax,
);
break;
default:
#ifdef LIBALIAS_DEBUG
"\nUnknown Type of Resource %0x\n",
);
#endif
break;
}
count--;
}
return ((u_char *) q);
}
static int
struct alias_link *lnk,
struct in_addr *alias_address,
struct in_addr *original_address,
{
u_char *p;
char *pmax;
(void)la;
(void)lnk;
/* Set up Common Parameter */
/* Calculate data length of UDP packet */
return (-1);
#ifdef LIBALIAS_DEBUG
printf(" [%s] ID=%02x, op=%01x, flag=%02x, rcode=%01x, qd=%04x"
", an=%04x, ns=%04x, ar=%04x, [%d]-->",
);
#endif
/* Question Entries */
p = AliasHandleQuestion(
(NBTNsQuestion *) p,
pmax,
);
}
/* Answer Resource Records */
p = AliasHandleResource(
(NBTNsResource *) p,
pmax,
);
}
/* Authority Resource Recodrs */
p = AliasHandleResource(
(NBTNsResource *) p,
pmax,
);
}
/* Additional Resource Recodrs */
p = AliasHandleResource(
(NBTNsResource *) p,
pmax,
);
}
#ifdef LIBALIAS_DEBUG
#endif
return ((p == NULL) ? -1 : 0);
}