2001-06-04 14:52:17 +00:00
|
|
|
/*-
|
2017-11-27 15:23:17 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
|
|
|
*
|
1998-05-24 03:03:10 +00:00
|
|
|
* Written by Atsushi Murai <amurai@spec.co.jp>
|
2001-06-04 14:52:17 +00:00
|
|
|
* Copyright (c) 1998, System Planning and Engineering Co.
|
|
|
|
* All rights reserved.
|
1998-05-24 03:03:10 +00:00
|
|
|
*
|
2001-06-04 14:52:17 +00:00
|
|
|
* 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
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
1998-05-24 03:03:10 +00:00
|
|
|
*
|
2001-06-04 14:52:17 +00:00
|
|
|
* 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.
|
1998-05-24 03:03:10 +00:00
|
|
|
* TODO:
|
2002-07-01 11:19:40 +00:00
|
|
|
* oClean up.
|
1998-05-24 03:03:10 +00:00
|
|
|
* oConsidering for word alignment for other platform.
|
|
|
|
*/
|
2001-09-30 21:03:33 +00:00
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1998-05-24 03:03:10 +00:00
|
|
|
/*
|
|
|
|
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 */
|
2005-05-05 19:27:32 +00:00
|
|
|
#ifdef _KERNEL
|
|
|
|
#include <sys/param.h>
|
Summer of Code 2005: improve libalias - part 1 of 2
With the first part of my previous Summer of Code work, we get:
-made libalias modular:
-support for 'particular' protocols (like ftp/irc/etcetc) is no more
hardcoded inside libalias, but it's available through external
modules loadable at runtime
-modules are available both in kernel (/boot/kernel/alias_*.ko) and
user land (/lib/libalias_*)
-protocols/applications modularized are: cuseeme, ftp, irc, nbt, pptp,
skinny and smedia
-added logging support for kernel side
-cleanup
After a buildworld, do a 'mergemaster -i' to install the file libalias.conf
in /etc or manually copy it.
During startup (and after every HUP signal) user land applications running
the new libalias will try to read a file in /etc called libalias.conf:
that file contains the list of modules to load.
User land applications affected by this commit are ppp and natd:
if libalias.conf is present in /etc you won't notice any difference.
The only kernel land bit affected by this commit is ng_nat:
if you are using ng_nat, and it doesn't correctly handle
ftp/irc/etcetc sessions anymore, remember to kldload
the correspondent module (i.e. kldload alias_ftp).
General information and details about the inner working are available
in the libalias man page under the section 'MODULAR ARCHITECTURE
(AND ipfw(4) SUPPORT)'.
NOTA BENE: this commit affects _ONLY_ libalias, ipfw in-kernel nat
support will be part of the next libalias-related commit.
Approved by: glebius
Reviewed by: glebius, ru
2006-09-26 23:26:53 +00:00
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/module.h>
|
2005-05-05 19:27:32 +00:00
|
|
|
#else
|
Summer of Code 2005: improve libalias - part 1 of 2
With the first part of my previous Summer of Code work, we get:
-made libalias modular:
-support for 'particular' protocols (like ftp/irc/etcetc) is no more
hardcoded inside libalias, but it's available through external
modules loadable at runtime
-modules are available both in kernel (/boot/kernel/alias_*.ko) and
user land (/lib/libalias_*)
-protocols/applications modularized are: cuseeme, ftp, irc, nbt, pptp,
skinny and smedia
-added logging support for kernel side
-cleanup
After a buildworld, do a 'mergemaster -i' to install the file libalias.conf
in /etc or manually copy it.
During startup (and after every HUP signal) user land applications running
the new libalias will try to read a file in /etc called libalias.conf:
that file contains the list of modules to load.
User land applications affected by this commit are ppp and natd:
if libalias.conf is present in /etc you won't notice any difference.
The only kernel land bit affected by this commit is ng_nat:
if you are using ng_nat, and it doesn't correctly handle
ftp/irc/etcetc sessions anymore, remember to kldload
the correspondent module (i.e. kldload alias_ftp).
General information and details about the inner working are available
in the libalias man page under the section 'MODULAR ARCHITECTURE
(AND ipfw(4) SUPPORT)'.
NOTA BENE: this commit affects _ONLY_ libalias, ipfw in-kernel nat
support will be part of the next libalias-related commit.
Approved by: glebius
Reviewed by: glebius, ru
2006-09-26 23:26:53 +00:00
|
|
|
#include <errno.h>
|
2005-05-05 19:27:32 +00:00
|
|
|
#include <sys/types.h>
|
2002-07-01 11:19:40 +00:00
|
|
|
#include <stdio.h>
|
2009-01-15 19:35:23 +00:00
|
|
|
#include <strings.h>
|
2005-05-05 19:27:32 +00:00
|
|
|
#endif
|
|
|
|
|
1998-05-24 03:03:10 +00:00
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/ip.h>
|
|
|
|
#include <netinet/udp.h>
|
|
|
|
|
2005-05-05 19:27:32 +00:00
|
|
|
#ifdef _KERNEL
|
|
|
|
#include <netinet/libalias/alias_local.h>
|
Summer of Code 2005: improve libalias - part 1 of 2
With the first part of my previous Summer of Code work, we get:
-made libalias modular:
-support for 'particular' protocols (like ftp/irc/etcetc) is no more
hardcoded inside libalias, but it's available through external
modules loadable at runtime
-modules are available both in kernel (/boot/kernel/alias_*.ko) and
user land (/lib/libalias_*)
-protocols/applications modularized are: cuseeme, ftp, irc, nbt, pptp,
skinny and smedia
-added logging support for kernel side
-cleanup
After a buildworld, do a 'mergemaster -i' to install the file libalias.conf
in /etc or manually copy it.
During startup (and after every HUP signal) user land applications running
the new libalias will try to read a file in /etc called libalias.conf:
that file contains the list of modules to load.
User land applications affected by this commit are ppp and natd:
if libalias.conf is present in /etc you won't notice any difference.
The only kernel land bit affected by this commit is ng_nat:
if you are using ng_nat, and it doesn't correctly handle
ftp/irc/etcetc sessions anymore, remember to kldload
the correspondent module (i.e. kldload alias_ftp).
General information and details about the inner working are available
in the libalias man page under the section 'MODULAR ARCHITECTURE
(AND ipfw(4) SUPPORT)'.
NOTA BENE: this commit affects _ONLY_ libalias, ipfw in-kernel nat
support will be part of the next libalias-related commit.
Approved by: glebius
Reviewed by: glebius, ru
2006-09-26 23:26:53 +00:00
|
|
|
#include <netinet/libalias/alias_mod.h>
|
2005-05-05 19:27:32 +00:00
|
|
|
#else
|
1998-05-24 03:03:10 +00:00
|
|
|
#include "alias_local.h"
|
Summer of Code 2005: improve libalias - part 1 of 2
With the first part of my previous Summer of Code work, we get:
-made libalias modular:
-support for 'particular' protocols (like ftp/irc/etcetc) is no more
hardcoded inside libalias, but it's available through external
modules loadable at runtime
-modules are available both in kernel (/boot/kernel/alias_*.ko) and
user land (/lib/libalias_*)
-protocols/applications modularized are: cuseeme, ftp, irc, nbt, pptp,
skinny and smedia
-added logging support for kernel side
-cleanup
After a buildworld, do a 'mergemaster -i' to install the file libalias.conf
in /etc or manually copy it.
During startup (and after every HUP signal) user land applications running
the new libalias will try to read a file in /etc called libalias.conf:
that file contains the list of modules to load.
User land applications affected by this commit are ppp and natd:
if libalias.conf is present in /etc you won't notice any difference.
The only kernel land bit affected by this commit is ng_nat:
if you are using ng_nat, and it doesn't correctly handle
ftp/irc/etcetc sessions anymore, remember to kldload
the correspondent module (i.e. kldload alias_ftp).
General information and details about the inner working are available
in the libalias man page under the section 'MODULAR ARCHITECTURE
(AND ipfw(4) SUPPORT)'.
NOTA BENE: this commit affects _ONLY_ libalias, ipfw in-kernel nat
support will be part of the next libalias-related commit.
Approved by: glebius
Reviewed by: glebius, ru
2006-09-26 23:26:53 +00:00
|
|
|
#include "alias_mod.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define NETBIOS_NS_PORT_NUMBER 137
|
|
|
|
#define NETBIOS_DGM_PORT_NUMBER 138
|
|
|
|
|
|
|
|
static int
|
2013-12-25 02:06:57 +00:00
|
|
|
AliasHandleUdpNbt(struct libalias *, struct ip *, struct alias_link *,
|
Summer of Code 2005: improve libalias - part 1 of 2
With the first part of my previous Summer of Code work, we get:
-made libalias modular:
-support for 'particular' protocols (like ftp/irc/etcetc) is no more
hardcoded inside libalias, but it's available through external
modules loadable at runtime
-modules are available both in kernel (/boot/kernel/alias_*.ko) and
user land (/lib/libalias_*)
-protocols/applications modularized are: cuseeme, ftp, irc, nbt, pptp,
skinny and smedia
-added logging support for kernel side
-cleanup
After a buildworld, do a 'mergemaster -i' to install the file libalias.conf
in /etc or manually copy it.
During startup (and after every HUP signal) user land applications running
the new libalias will try to read a file in /etc called libalias.conf:
that file contains the list of modules to load.
User land applications affected by this commit are ppp and natd:
if libalias.conf is present in /etc you won't notice any difference.
The only kernel land bit affected by this commit is ng_nat:
if you are using ng_nat, and it doesn't correctly handle
ftp/irc/etcetc sessions anymore, remember to kldload
the correspondent module (i.e. kldload alias_ftp).
General information and details about the inner working are available
in the libalias man page under the section 'MODULAR ARCHITECTURE
(AND ipfw(4) SUPPORT)'.
NOTA BENE: this commit affects _ONLY_ libalias, ipfw in-kernel nat
support will be part of the next libalias-related commit.
Approved by: glebius
Reviewed by: glebius, ru
2006-09-26 23:26:53 +00:00
|
|
|
struct in_addr *, u_short);
|
|
|
|
|
|
|
|
static int
|
|
|
|
AliasHandleUdpNbtNS(struct libalias *, struct ip *, struct alias_link *,
|
|
|
|
struct in_addr *, u_short *, struct in_addr *, u_short *);
|
2013-12-25 02:06:57 +00:00
|
|
|
static int
|
2009-04-08 11:56:49 +00:00
|
|
|
fingerprint1(struct libalias *la, struct alias_data *ah)
|
Summer of Code 2005: improve libalias - part 1 of 2
With the first part of my previous Summer of Code work, we get:
-made libalias modular:
-support for 'particular' protocols (like ftp/irc/etcetc) is no more
hardcoded inside libalias, but it's available through external
modules loadable at runtime
-modules are available both in kernel (/boot/kernel/alias_*.ko) and
user land (/lib/libalias_*)
-protocols/applications modularized are: cuseeme, ftp, irc, nbt, pptp,
skinny and smedia
-added logging support for kernel side
-cleanup
After a buildworld, do a 'mergemaster -i' to install the file libalias.conf
in /etc or manually copy it.
During startup (and after every HUP signal) user land applications running
the new libalias will try to read a file in /etc called libalias.conf:
that file contains the list of modules to load.
User land applications affected by this commit are ppp and natd:
if libalias.conf is present in /etc you won't notice any difference.
The only kernel land bit affected by this commit is ng_nat:
if you are using ng_nat, and it doesn't correctly handle
ftp/irc/etcetc sessions anymore, remember to kldload
the correspondent module (i.e. kldload alias_ftp).
General information and details about the inner working are available
in the libalias man page under the section 'MODULAR ARCHITECTURE
(AND ipfw(4) SUPPORT)'.
NOTA BENE: this commit affects _ONLY_ libalias, ipfw in-kernel nat
support will be part of the next libalias-related commit.
Approved by: glebius
Reviewed by: glebius, ru
2006-09-26 23:26:53 +00:00
|
|
|
{
|
|
|
|
|
2013-12-25 02:06:57 +00:00
|
|
|
if (ah->dport == NULL || ah->sport == NULL || ah->lnk == NULL ||
|
Summer of Code 2005: improve libalias - part 1 of 2
With the first part of my previous Summer of Code work, we get:
-made libalias modular:
-support for 'particular' protocols (like ftp/irc/etcetc) is no more
hardcoded inside libalias, but it's available through external
modules loadable at runtime
-modules are available both in kernel (/boot/kernel/alias_*.ko) and
user land (/lib/libalias_*)
-protocols/applications modularized are: cuseeme, ftp, irc, nbt, pptp,
skinny and smedia
-added logging support for kernel side
-cleanup
After a buildworld, do a 'mergemaster -i' to install the file libalias.conf
in /etc or manually copy it.
During startup (and after every HUP signal) user land applications running
the new libalias will try to read a file in /etc called libalias.conf:
that file contains the list of modules to load.
User land applications affected by this commit are ppp and natd:
if libalias.conf is present in /etc you won't notice any difference.
The only kernel land bit affected by this commit is ng_nat:
if you are using ng_nat, and it doesn't correctly handle
ftp/irc/etcetc sessions anymore, remember to kldload
the correspondent module (i.e. kldload alias_ftp).
General information and details about the inner working are available
in the libalias man page under the section 'MODULAR ARCHITECTURE
(AND ipfw(4) SUPPORT)'.
NOTA BENE: this commit affects _ONLY_ libalias, ipfw in-kernel nat
support will be part of the next libalias-related commit.
Approved by: glebius
Reviewed by: glebius, ru
2006-09-26 23:26:53 +00:00
|
|
|
ah->aaddr == NULL || ah->aport == NULL)
|
|
|
|
return (-1);
|
|
|
|
if (ntohs(*ah->dport) == NETBIOS_DGM_PORT_NUMBER
|
|
|
|
|| ntohs(*ah->sport) == NETBIOS_DGM_PORT_NUMBER)
|
|
|
|
return (0);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
2013-12-25 02:06:57 +00:00
|
|
|
static int
|
Summer of Code 2005: improve libalias - part 1 of 2
With the first part of my previous Summer of Code work, we get:
-made libalias modular:
-support for 'particular' protocols (like ftp/irc/etcetc) is no more
hardcoded inside libalias, but it's available through external
modules loadable at runtime
-modules are available both in kernel (/boot/kernel/alias_*.ko) and
user land (/lib/libalias_*)
-protocols/applications modularized are: cuseeme, ftp, irc, nbt, pptp,
skinny and smedia
-added logging support for kernel side
-cleanup
After a buildworld, do a 'mergemaster -i' to install the file libalias.conf
in /etc or manually copy it.
During startup (and after every HUP signal) user land applications running
the new libalias will try to read a file in /etc called libalias.conf:
that file contains the list of modules to load.
User land applications affected by this commit are ppp and natd:
if libalias.conf is present in /etc you won't notice any difference.
The only kernel land bit affected by this commit is ng_nat:
if you are using ng_nat, and it doesn't correctly handle
ftp/irc/etcetc sessions anymore, remember to kldload
the correspondent module (i.e. kldload alias_ftp).
General information and details about the inner working are available
in the libalias man page under the section 'MODULAR ARCHITECTURE
(AND ipfw(4) SUPPORT)'.
NOTA BENE: this commit affects _ONLY_ libalias, ipfw in-kernel nat
support will be part of the next libalias-related commit.
Approved by: glebius
Reviewed by: glebius, ru
2006-09-26 23:26:53 +00:00
|
|
|
protohandler1(struct libalias *la, struct ip *pip, struct alias_data *ah)
|
|
|
|
{
|
|
|
|
|
2009-04-11 15:19:09 +00:00
|
|
|
return (AliasHandleUdpNbt(la, pip, ah->lnk, ah->aaddr, *ah->aport));
|
Summer of Code 2005: improve libalias - part 1 of 2
With the first part of my previous Summer of Code work, we get:
-made libalias modular:
-support for 'particular' protocols (like ftp/irc/etcetc) is no more
hardcoded inside libalias, but it's available through external
modules loadable at runtime
-modules are available both in kernel (/boot/kernel/alias_*.ko) and
user land (/lib/libalias_*)
-protocols/applications modularized are: cuseeme, ftp, irc, nbt, pptp,
skinny and smedia
-added logging support for kernel side
-cleanup
After a buildworld, do a 'mergemaster -i' to install the file libalias.conf
in /etc or manually copy it.
During startup (and after every HUP signal) user land applications running
the new libalias will try to read a file in /etc called libalias.conf:
that file contains the list of modules to load.
User land applications affected by this commit are ppp and natd:
if libalias.conf is present in /etc you won't notice any difference.
The only kernel land bit affected by this commit is ng_nat:
if you are using ng_nat, and it doesn't correctly handle
ftp/irc/etcetc sessions anymore, remember to kldload
the correspondent module (i.e. kldload alias_ftp).
General information and details about the inner working are available
in the libalias man page under the section 'MODULAR ARCHITECTURE
(AND ipfw(4) SUPPORT)'.
NOTA BENE: this commit affects _ONLY_ libalias, ipfw in-kernel nat
support will be part of the next libalias-related commit.
Approved by: glebius
Reviewed by: glebius, ru
2006-09-26 23:26:53 +00:00
|
|
|
}
|
|
|
|
|
2013-12-25 02:06:57 +00:00
|
|
|
static int
|
2009-04-08 11:56:49 +00:00
|
|
|
fingerprint2(struct libalias *la, struct alias_data *ah)
|
Summer of Code 2005: improve libalias - part 1 of 2
With the first part of my previous Summer of Code work, we get:
-made libalias modular:
-support for 'particular' protocols (like ftp/irc/etcetc) is no more
hardcoded inside libalias, but it's available through external
modules loadable at runtime
-modules are available both in kernel (/boot/kernel/alias_*.ko) and
user land (/lib/libalias_*)
-protocols/applications modularized are: cuseeme, ftp, irc, nbt, pptp,
skinny and smedia
-added logging support for kernel side
-cleanup
After a buildworld, do a 'mergemaster -i' to install the file libalias.conf
in /etc or manually copy it.
During startup (and after every HUP signal) user land applications running
the new libalias will try to read a file in /etc called libalias.conf:
that file contains the list of modules to load.
User land applications affected by this commit are ppp and natd:
if libalias.conf is present in /etc you won't notice any difference.
The only kernel land bit affected by this commit is ng_nat:
if you are using ng_nat, and it doesn't correctly handle
ftp/irc/etcetc sessions anymore, remember to kldload
the correspondent module (i.e. kldload alias_ftp).
General information and details about the inner working are available
in the libalias man page under the section 'MODULAR ARCHITECTURE
(AND ipfw(4) SUPPORT)'.
NOTA BENE: this commit affects _ONLY_ libalias, ipfw in-kernel nat
support will be part of the next libalias-related commit.
Approved by: glebius
Reviewed by: glebius, ru
2006-09-26 23:26:53 +00:00
|
|
|
{
|
|
|
|
|
2013-12-25 02:06:57 +00:00
|
|
|
if (ah->dport == NULL || ah->sport == NULL || ah->lnk == NULL ||
|
Summer of Code 2005: improve libalias - part 1 of 2
With the first part of my previous Summer of Code work, we get:
-made libalias modular:
-support for 'particular' protocols (like ftp/irc/etcetc) is no more
hardcoded inside libalias, but it's available through external
modules loadable at runtime
-modules are available both in kernel (/boot/kernel/alias_*.ko) and
user land (/lib/libalias_*)
-protocols/applications modularized are: cuseeme, ftp, irc, nbt, pptp,
skinny and smedia
-added logging support for kernel side
-cleanup
After a buildworld, do a 'mergemaster -i' to install the file libalias.conf
in /etc or manually copy it.
During startup (and after every HUP signal) user land applications running
the new libalias will try to read a file in /etc called libalias.conf:
that file contains the list of modules to load.
User land applications affected by this commit are ppp and natd:
if libalias.conf is present in /etc you won't notice any difference.
The only kernel land bit affected by this commit is ng_nat:
if you are using ng_nat, and it doesn't correctly handle
ftp/irc/etcetc sessions anymore, remember to kldload
the correspondent module (i.e. kldload alias_ftp).
General information and details about the inner working are available
in the libalias man page under the section 'MODULAR ARCHITECTURE
(AND ipfw(4) SUPPORT)'.
NOTA BENE: this commit affects _ONLY_ libalias, ipfw in-kernel nat
support will be part of the next libalias-related commit.
Approved by: glebius
Reviewed by: glebius, ru
2006-09-26 23:26:53 +00:00
|
|
|
ah->aaddr == NULL || ah->aport == NULL)
|
|
|
|
return (-1);
|
|
|
|
if (ntohs(*ah->dport) == NETBIOS_NS_PORT_NUMBER
|
|
|
|
|| ntohs(*ah->sport) == NETBIOS_NS_PORT_NUMBER)
|
|
|
|
return (0);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
2013-12-25 02:06:57 +00:00
|
|
|
static int
|
Summer of Code 2005: improve libalias - part 1 of 2
With the first part of my previous Summer of Code work, we get:
-made libalias modular:
-support for 'particular' protocols (like ftp/irc/etcetc) is no more
hardcoded inside libalias, but it's available through external
modules loadable at runtime
-modules are available both in kernel (/boot/kernel/alias_*.ko) and
user land (/lib/libalias_*)
-protocols/applications modularized are: cuseeme, ftp, irc, nbt, pptp,
skinny and smedia
-added logging support for kernel side
-cleanup
After a buildworld, do a 'mergemaster -i' to install the file libalias.conf
in /etc or manually copy it.
During startup (and after every HUP signal) user land applications running
the new libalias will try to read a file in /etc called libalias.conf:
that file contains the list of modules to load.
User land applications affected by this commit are ppp and natd:
if libalias.conf is present in /etc you won't notice any difference.
The only kernel land bit affected by this commit is ng_nat:
if you are using ng_nat, and it doesn't correctly handle
ftp/irc/etcetc sessions anymore, remember to kldload
the correspondent module (i.e. kldload alias_ftp).
General information and details about the inner working are available
in the libalias man page under the section 'MODULAR ARCHITECTURE
(AND ipfw(4) SUPPORT)'.
NOTA BENE: this commit affects _ONLY_ libalias, ipfw in-kernel nat
support will be part of the next libalias-related commit.
Approved by: glebius
Reviewed by: glebius, ru
2006-09-26 23:26:53 +00:00
|
|
|
protohandler2in(struct libalias *la, struct ip *pip, struct alias_data *ah)
|
|
|
|
{
|
|
|
|
|
|
|
|
AliasHandleUdpNbtNS(la, pip, ah->lnk, ah->aaddr, ah->aport,
|
|
|
|
ah->oaddr, ah->dport);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2013-12-25 02:06:57 +00:00
|
|
|
static int
|
Summer of Code 2005: improve libalias - part 1 of 2
With the first part of my previous Summer of Code work, we get:
-made libalias modular:
-support for 'particular' protocols (like ftp/irc/etcetc) is no more
hardcoded inside libalias, but it's available through external
modules loadable at runtime
-modules are available both in kernel (/boot/kernel/alias_*.ko) and
user land (/lib/libalias_*)
-protocols/applications modularized are: cuseeme, ftp, irc, nbt, pptp,
skinny and smedia
-added logging support for kernel side
-cleanup
After a buildworld, do a 'mergemaster -i' to install the file libalias.conf
in /etc or manually copy it.
During startup (and after every HUP signal) user land applications running
the new libalias will try to read a file in /etc called libalias.conf:
that file contains the list of modules to load.
User land applications affected by this commit are ppp and natd:
if libalias.conf is present in /etc you won't notice any difference.
The only kernel land bit affected by this commit is ng_nat:
if you are using ng_nat, and it doesn't correctly handle
ftp/irc/etcetc sessions anymore, remember to kldload
the correspondent module (i.e. kldload alias_ftp).
General information and details about the inner working are available
in the libalias man page under the section 'MODULAR ARCHITECTURE
(AND ipfw(4) SUPPORT)'.
NOTA BENE: this commit affects _ONLY_ libalias, ipfw in-kernel nat
support will be part of the next libalias-related commit.
Approved by: glebius
Reviewed by: glebius, ru
2006-09-26 23:26:53 +00:00
|
|
|
protohandler2out(struct libalias *la, struct ip *pip, struct alias_data *ah)
|
|
|
|
{
|
|
|
|
|
2009-04-11 15:19:09 +00:00
|
|
|
return (AliasHandleUdpNbtNS(la, pip, ah->lnk, &pip->ip_src, ah->sport,
|
|
|
|
ah->aaddr, ah->aport));
|
Summer of Code 2005: improve libalias - part 1 of 2
With the first part of my previous Summer of Code work, we get:
-made libalias modular:
-support for 'particular' protocols (like ftp/irc/etcetc) is no more
hardcoded inside libalias, but it's available through external
modules loadable at runtime
-modules are available both in kernel (/boot/kernel/alias_*.ko) and
user land (/lib/libalias_*)
-protocols/applications modularized are: cuseeme, ftp, irc, nbt, pptp,
skinny and smedia
-added logging support for kernel side
-cleanup
After a buildworld, do a 'mergemaster -i' to install the file libalias.conf
in /etc or manually copy it.
During startup (and after every HUP signal) user land applications running
the new libalias will try to read a file in /etc called libalias.conf:
that file contains the list of modules to load.
User land applications affected by this commit are ppp and natd:
if libalias.conf is present in /etc you won't notice any difference.
The only kernel land bit affected by this commit is ng_nat:
if you are using ng_nat, and it doesn't correctly handle
ftp/irc/etcetc sessions anymore, remember to kldload
the correspondent module (i.e. kldload alias_ftp).
General information and details about the inner working are available
in the libalias man page under the section 'MODULAR ARCHITECTURE
(AND ipfw(4) SUPPORT)'.
NOTA BENE: this commit affects _ONLY_ libalias, ipfw in-kernel nat
support will be part of the next libalias-related commit.
Approved by: glebius
Reviewed by: glebius, ru
2006-09-26 23:26:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Kernel module definition. */
|
|
|
|
struct proto_handler handlers[] = {
|
2013-12-25 02:06:57 +00:00
|
|
|
{
|
|
|
|
.pri = 130,
|
|
|
|
.dir = IN|OUT,
|
|
|
|
.proto = UDP,
|
|
|
|
.fingerprint = &fingerprint1,
|
Summer of Code 2005: improve libalias - part 1 of 2
With the first part of my previous Summer of Code work, we get:
-made libalias modular:
-support for 'particular' protocols (like ftp/irc/etcetc) is no more
hardcoded inside libalias, but it's available through external
modules loadable at runtime
-modules are available both in kernel (/boot/kernel/alias_*.ko) and
user land (/lib/libalias_*)
-protocols/applications modularized are: cuseeme, ftp, irc, nbt, pptp,
skinny and smedia
-added logging support for kernel side
-cleanup
After a buildworld, do a 'mergemaster -i' to install the file libalias.conf
in /etc or manually copy it.
During startup (and after every HUP signal) user land applications running
the new libalias will try to read a file in /etc called libalias.conf:
that file contains the list of modules to load.
User land applications affected by this commit are ppp and natd:
if libalias.conf is present in /etc you won't notice any difference.
The only kernel land bit affected by this commit is ng_nat:
if you are using ng_nat, and it doesn't correctly handle
ftp/irc/etcetc sessions anymore, remember to kldload
the correspondent module (i.e. kldload alias_ftp).
General information and details about the inner working are available
in the libalias man page under the section 'MODULAR ARCHITECTURE
(AND ipfw(4) SUPPORT)'.
NOTA BENE: this commit affects _ONLY_ libalias, ipfw in-kernel nat
support will be part of the next libalias-related commit.
Approved by: glebius
Reviewed by: glebius, ru
2006-09-26 23:26:53 +00:00
|
|
|
.protohandler = &protohandler1
|
2013-12-25 02:06:57 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.pri = 140,
|
|
|
|
.dir = IN,
|
|
|
|
.proto = UDP,
|
|
|
|
.fingerprint = &fingerprint2,
|
Summer of Code 2005: improve libalias - part 1 of 2
With the first part of my previous Summer of Code work, we get:
-made libalias modular:
-support for 'particular' protocols (like ftp/irc/etcetc) is no more
hardcoded inside libalias, but it's available through external
modules loadable at runtime
-modules are available both in kernel (/boot/kernel/alias_*.ko) and
user land (/lib/libalias_*)
-protocols/applications modularized are: cuseeme, ftp, irc, nbt, pptp,
skinny and smedia
-added logging support for kernel side
-cleanup
After a buildworld, do a 'mergemaster -i' to install the file libalias.conf
in /etc or manually copy it.
During startup (and after every HUP signal) user land applications running
the new libalias will try to read a file in /etc called libalias.conf:
that file contains the list of modules to load.
User land applications affected by this commit are ppp and natd:
if libalias.conf is present in /etc you won't notice any difference.
The only kernel land bit affected by this commit is ng_nat:
if you are using ng_nat, and it doesn't correctly handle
ftp/irc/etcetc sessions anymore, remember to kldload
the correspondent module (i.e. kldload alias_ftp).
General information and details about the inner working are available
in the libalias man page under the section 'MODULAR ARCHITECTURE
(AND ipfw(4) SUPPORT)'.
NOTA BENE: this commit affects _ONLY_ libalias, ipfw in-kernel nat
support will be part of the next libalias-related commit.
Approved by: glebius
Reviewed by: glebius, ru
2006-09-26 23:26:53 +00:00
|
|
|
.protohandler = &protohandler2in
|
2013-12-25 02:06:57 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.pri = 140,
|
|
|
|
.dir = OUT,
|
|
|
|
.proto = UDP,
|
|
|
|
.fingerprint = &fingerprint2,
|
Summer of Code 2005: improve libalias - part 1 of 2
With the first part of my previous Summer of Code work, we get:
-made libalias modular:
-support for 'particular' protocols (like ftp/irc/etcetc) is no more
hardcoded inside libalias, but it's available through external
modules loadable at runtime
-modules are available both in kernel (/boot/kernel/alias_*.ko) and
user land (/lib/libalias_*)
-protocols/applications modularized are: cuseeme, ftp, irc, nbt, pptp,
skinny and smedia
-added logging support for kernel side
-cleanup
After a buildworld, do a 'mergemaster -i' to install the file libalias.conf
in /etc or manually copy it.
During startup (and after every HUP signal) user land applications running
the new libalias will try to read a file in /etc called libalias.conf:
that file contains the list of modules to load.
User land applications affected by this commit are ppp and natd:
if libalias.conf is present in /etc you won't notice any difference.
The only kernel land bit affected by this commit is ng_nat:
if you are using ng_nat, and it doesn't correctly handle
ftp/irc/etcetc sessions anymore, remember to kldload
the correspondent module (i.e. kldload alias_ftp).
General information and details about the inner working are available
in the libalias man page under the section 'MODULAR ARCHITECTURE
(AND ipfw(4) SUPPORT)'.
NOTA BENE: this commit affects _ONLY_ libalias, ipfw in-kernel nat
support will be part of the next libalias-related commit.
Approved by: glebius
Reviewed by: glebius, ru
2006-09-26 23:26:53 +00:00
|
|
|
.protohandler = &protohandler2out
|
2013-12-25 02:06:57 +00:00
|
|
|
},
|
Summer of Code 2005: improve libalias - part 1 of 2
With the first part of my previous Summer of Code work, we get:
-made libalias modular:
-support for 'particular' protocols (like ftp/irc/etcetc) is no more
hardcoded inside libalias, but it's available through external
modules loadable at runtime
-modules are available both in kernel (/boot/kernel/alias_*.ko) and
user land (/lib/libalias_*)
-protocols/applications modularized are: cuseeme, ftp, irc, nbt, pptp,
skinny and smedia
-added logging support for kernel side
-cleanup
After a buildworld, do a 'mergemaster -i' to install the file libalias.conf
in /etc or manually copy it.
During startup (and after every HUP signal) user land applications running
the new libalias will try to read a file in /etc called libalias.conf:
that file contains the list of modules to load.
User land applications affected by this commit are ppp and natd:
if libalias.conf is present in /etc you won't notice any difference.
The only kernel land bit affected by this commit is ng_nat:
if you are using ng_nat, and it doesn't correctly handle
ftp/irc/etcetc sessions anymore, remember to kldload
the correspondent module (i.e. kldload alias_ftp).
General information and details about the inner working are available
in the libalias man page under the section 'MODULAR ARCHITECTURE
(AND ipfw(4) SUPPORT)'.
NOTA BENE: this commit affects _ONLY_ libalias, ipfw in-kernel nat
support will be part of the next libalias-related commit.
Approved by: glebius
Reviewed by: glebius, ru
2006-09-26 23:26:53 +00:00
|
|
|
{ EOH }
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
mod_handler(module_t mod, int type, void *data)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case MOD_LOAD:
|
|
|
|
error = 0;
|
|
|
|
LibAliasAttachHandlers(handlers);
|
|
|
|
break;
|
|
|
|
case MOD_UNLOAD:
|
|
|
|
error = 0;
|
|
|
|
LibAliasDetachHandlers(handlers);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef _KERNEL
|
2013-12-25 02:06:57 +00:00
|
|
|
static
|
Summer of Code 2005: improve libalias - part 1 of 2
With the first part of my previous Summer of Code work, we get:
-made libalias modular:
-support for 'particular' protocols (like ftp/irc/etcetc) is no more
hardcoded inside libalias, but it's available through external
modules loadable at runtime
-modules are available both in kernel (/boot/kernel/alias_*.ko) and
user land (/lib/libalias_*)
-protocols/applications modularized are: cuseeme, ftp, irc, nbt, pptp,
skinny and smedia
-added logging support for kernel side
-cleanup
After a buildworld, do a 'mergemaster -i' to install the file libalias.conf
in /etc or manually copy it.
During startup (and after every HUP signal) user land applications running
the new libalias will try to read a file in /etc called libalias.conf:
that file contains the list of modules to load.
User land applications affected by this commit are ppp and natd:
if libalias.conf is present in /etc you won't notice any difference.
The only kernel land bit affected by this commit is ng_nat:
if you are using ng_nat, and it doesn't correctly handle
ftp/irc/etcetc sessions anymore, remember to kldload
the correspondent module (i.e. kldload alias_ftp).
General information and details about the inner working are available
in the libalias man page under the section 'MODULAR ARCHITECTURE
(AND ipfw(4) SUPPORT)'.
NOTA BENE: this commit affects _ONLY_ libalias, ipfw in-kernel nat
support will be part of the next libalias-related commit.
Approved by: glebius
Reviewed by: glebius, ru
2006-09-26 23:26:53 +00:00
|
|
|
#endif
|
|
|
|
moduledata_t alias_mod = {
|
|
|
|
"alias_nbt", mod_handler, NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef _KERNEL
|
|
|
|
DECLARE_MODULE(alias_nbt, alias_mod, SI_SUB_DRIVERS, SI_ORDER_SECOND);
|
|
|
|
MODULE_VERSION(alias_nbt, 1);
|
|
|
|
MODULE_DEPEND(alias_nbt, libalias, 1, 1, 1);
|
2005-05-05 19:27:32 +00:00
|
|
|
#endif
|
1998-05-24 03:03:10 +00:00
|
|
|
|
|
|
|
typedef struct {
|
2004-03-16 21:30:41 +00:00
|
|
|
struct in_addr oldaddr;
|
|
|
|
u_short oldport;
|
|
|
|
struct in_addr newaddr;
|
|
|
|
u_short newport;
|
|
|
|
u_short *uh_sum;
|
|
|
|
} NBTArguments;
|
1998-05-24 03:03:10 +00:00
|
|
|
|
|
|
|
typedef struct {
|
2004-03-16 21:30:41 +00:00
|
|
|
unsigned char type;
|
|
|
|
unsigned char flags;
|
|
|
|
u_short id;
|
|
|
|
struct in_addr source_ip;
|
|
|
|
u_short source_port;
|
|
|
|
u_short len;
|
|
|
|
u_short offset;
|
|
|
|
} NbtDataHeader;
|
1998-05-24 03:03:10 +00:00
|
|
|
|
|
|
|
#define OpQuery 0
|
|
|
|
#define OpUnknown 4
|
|
|
|
#define OpRegist 5
|
|
|
|
#define OpRelease 6
|
|
|
|
#define OpWACK 7
|
|
|
|
#define OpRefresh 8
|
|
|
|
typedef struct {
|
2004-03-16 21:30:41 +00:00
|
|
|
u_short nametrid;
|
|
|
|
u_short dir: 1, opcode:4, nmflags:7, rcode:4;
|
|
|
|
u_short qdcount;
|
|
|
|
u_short ancount;
|
|
|
|
u_short nscount;
|
|
|
|
u_short arcount;
|
|
|
|
} NbtNSHeader;
|
1998-05-24 03:03:10 +00:00
|
|
|
|
|
|
|
#define FMT_ERR 0x1
|
|
|
|
#define SRV_ERR 0x2
|
|
|
|
#define IMP_ERR 0x4
|
|
|
|
#define RFS_ERR 0x5
|
|
|
|
#define ACT_ERR 0x6
|
|
|
|
#define CFT_ERR 0x7
|
|
|
|
|
|
|
|
|
2005-05-06 11:07:49 +00:00
|
|
|
#ifdef LIBALIAS_DEBUG
|
2004-03-16 21:30:41 +00:00
|
|
|
static void
|
|
|
|
PrintRcode(u_char rcode)
|
|
|
|
{
|
1998-05-24 03:03:10 +00:00
|
|
|
|
|
|
|
switch (rcode) {
|
|
|
|
case FMT_ERR:
|
2004-03-16 21:30:41 +00:00
|
|
|
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:
|
|
|
|
printf("\n?%c?=%0x\n", '?', rcode);
|
1998-05-24 03:03:10 +00:00
|
|
|
|
2002-07-01 11:19:40 +00:00
|
|
|
}
|
1998-05-24 03:03:10 +00:00
|
|
|
}
|
2004-03-16 21:30:41 +00:00
|
|
|
|
1999-03-09 23:44:00 +00:00
|
|
|
#endif
|
1998-05-24 03:03:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Handling Name field */
|
2004-03-16 21:30:41 +00:00
|
|
|
static u_char *
|
|
|
|
AliasHandleName(u_char * p, char *pmax)
|
|
|
|
{
|
1998-05-24 03:03:10 +00:00
|
|
|
|
|
|
|
u_char *s;
|
|
|
|
u_char c;
|
2004-03-16 21:30:41 +00:00
|
|
|
int compress;
|
1998-05-24 03:03:10 +00:00
|
|
|
|
|
|
|
/* Following length field */
|
1998-12-14 02:25:32 +00:00
|
|
|
|
|
|
|
if (p == NULL || (char *)p >= pmax)
|
2004-03-16 21:30:41 +00:00
|
|
|
return (NULL);
|
1998-12-14 02:25:32 +00:00
|
|
|
|
2004-03-16 21:30:41 +00:00
|
|
|
if (*p & 0xc0) {
|
1998-05-24 03:03:10 +00:00
|
|
|
p = p + 2;
|
1998-12-14 02:25:32 +00:00
|
|
|
if ((char *)p > pmax)
|
2004-03-16 21:30:41 +00:00
|
|
|
return (NULL);
|
|
|
|
return ((u_char *) p);
|
1998-05-24 03:03:10 +00:00
|
|
|
}
|
2004-03-16 21:30:41 +00:00
|
|
|
while ((*p & 0x3f) != 0x00) {
|
1998-05-24 03:03:10 +00:00
|
|
|
s = p + 1;
|
2004-03-16 21:30:41 +00:00
|
|
|
if (*p == 0x20)
|
1998-05-24 03:03:10 +00:00
|
|
|
compress = 1;
|
|
|
|
else
|
|
|
|
compress = 0;
|
2002-07-01 11:19:40 +00:00
|
|
|
|
2004-03-16 21:30:41 +00:00
|
|
|
/* Get next length field */
|
|
|
|
p = (u_char *) (p + (*p & 0x3f) + 1);
|
1998-12-14 02:25:32 +00:00
|
|
|
if ((char *)p > pmax) {
|
|
|
|
p = NULL;
|
|
|
|
break;
|
|
|
|
}
|
2005-05-06 11:07:49 +00:00
|
|
|
#ifdef LIBALIAS_DEBUG
|
1998-05-24 03:03:10 +00:00
|
|
|
printf(":");
|
|
|
|
#endif
|
|
|
|
while (s < p) {
|
2004-03-16 21:30:41 +00:00
|
|
|
if (compress == 1) {
|
|
|
|
c = (u_char) (((((*s & 0x0f) << 4) | (*(s + 1) & 0x0f)) - 0x11));
|
2005-05-06 11:07:49 +00:00
|
|
|
#ifdef LIBALIAS_DEBUG
|
2004-03-16 21:30:41 +00:00
|
|
|
if (isprint(c))
|
|
|
|
printf("%c", c);
|
1998-05-24 03:03:10 +00:00
|
|
|
else
|
2004-03-16 21:30:41 +00:00
|
|
|
printf("<0x%02x>", c);
|
1998-05-24 03:03:10 +00:00
|
|
|
#endif
|
2004-03-16 21:30:41 +00:00
|
|
|
s += 2;
|
1998-05-24 03:03:10 +00:00
|
|
|
} else {
|
2005-05-06 11:07:49 +00:00
|
|
|
#ifdef LIBALIAS_DEBUG
|
1998-05-24 03:03:10 +00:00
|
|
|
printf("%c", *s);
|
|
|
|
#endif
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
}
|
2005-05-06 11:07:49 +00:00
|
|
|
#ifdef LIBALIAS_DEBUG
|
1998-05-24 03:03:10 +00:00
|
|
|
printf(":");
|
|
|
|
fflush(stdout);
|
2005-05-05 21:07:34 +00:00
|
|
|
#endif
|
2004-03-16 21:30:41 +00:00
|
|
|
}
|
1998-05-24 03:03:10 +00:00
|
|
|
|
|
|
|
/* Set up to out of Name field */
|
1998-12-14 02:25:32 +00:00
|
|
|
if (p == NULL || (char *)p >= pmax)
|
2004-03-16 21:30:41 +00:00
|
|
|
p = NULL;
|
1998-12-14 02:25:32 +00:00
|
|
|
else
|
2004-03-16 21:30:41 +00:00
|
|
|
p++;
|
|
|
|
return ((u_char *) p);
|
1998-05-24 03:03:10 +00:00
|
|
|
}
|
|
|
|
|
2002-07-01 11:19:40 +00:00
|
|
|
/*
|
1998-05-24 03:03:10 +00:00
|
|
|
* NetBios Datagram Handler (IP/UDP)
|
|
|
|
*/
|
|
|
|
#define DGM_DIRECT_UNIQ 0x10
|
|
|
|
#define DGM_DIRECT_GROUP 0x11
|
|
|
|
#define DGM_BROADCAST 0x12
|
|
|
|
#define DGM_ERROR 0x13
|
|
|
|
#define DGM_QUERY 0x14
|
|
|
|
#define DGM_POSITIVE_RES 0x15
|
|
|
|
#define DGM_NEGATIVE_RES 0x16
|
|
|
|
|
Summer of Code 2005: improve libalias - part 1 of 2
With the first part of my previous Summer of Code work, we get:
-made libalias modular:
-support for 'particular' protocols (like ftp/irc/etcetc) is no more
hardcoded inside libalias, but it's available through external
modules loadable at runtime
-modules are available both in kernel (/boot/kernel/alias_*.ko) and
user land (/lib/libalias_*)
-protocols/applications modularized are: cuseeme, ftp, irc, nbt, pptp,
skinny and smedia
-added logging support for kernel side
-cleanup
After a buildworld, do a 'mergemaster -i' to install the file libalias.conf
in /etc or manually copy it.
During startup (and after every HUP signal) user land applications running
the new libalias will try to read a file in /etc called libalias.conf:
that file contains the list of modules to load.
User land applications affected by this commit are ppp and natd:
if libalias.conf is present in /etc you won't notice any difference.
The only kernel land bit affected by this commit is ng_nat:
if you are using ng_nat, and it doesn't correctly handle
ftp/irc/etcetc sessions anymore, remember to kldload
the correspondent module (i.e. kldload alias_ftp).
General information and details about the inner working are available
in the libalias man page under the section 'MODULAR ARCHITECTURE
(AND ipfw(4) SUPPORT)'.
NOTA BENE: this commit affects _ONLY_ libalias, ipfw in-kernel nat
support will be part of the next libalias-related commit.
Approved by: glebius
Reviewed by: glebius, ru
2006-09-26 23:26:53 +00:00
|
|
|
static int
|
2004-03-16 21:30:41 +00:00
|
|
|
AliasHandleUdpNbt(
|
|
|
|
struct libalias *la,
|
|
|
|
struct ip *pip, /* IP packet to examine/patch */
|
2004-07-05 11:10:57 +00:00
|
|
|
struct alias_link *lnk,
|
2004-03-16 21:30:41 +00:00
|
|
|
struct in_addr *alias_address,
|
|
|
|
u_short alias_port
|
|
|
|
)
|
|
|
|
{
|
|
|
|
struct udphdr *uh;
|
|
|
|
NbtDataHeader *ndh;
|
|
|
|
u_char *p = NULL;
|
|
|
|
char *pmax;
|
2017-02-16 20:47:41 +00:00
|
|
|
#ifdef LIBALIAS_DEBUG
|
|
|
|
char addrbuf[INET_ADDRSTRLEN];
|
|
|
|
#endif
|
2004-03-16 21:30:41 +00:00
|
|
|
|
2004-07-05 11:10:57 +00:00
|
|
|
(void)la;
|
|
|
|
(void)lnk;
|
|
|
|
|
2004-03-16 21:30:41 +00:00
|
|
|
/* Calculate data length of UDP packet */
|
2004-07-06 12:13:28 +00:00
|
|
|
uh = (struct udphdr *)ip_next(pip);
|
2004-03-16 21:30:41 +00:00
|
|
|
pmax = (char *)uh + ntohs(uh->uh_ulen);
|
|
|
|
|
2004-07-06 12:13:28 +00:00
|
|
|
ndh = (NbtDataHeader *)udp_next(uh);
|
2004-03-16 21:30:41 +00:00
|
|
|
if ((char *)(ndh + 1) > pmax)
|
|
|
|
return (-1);
|
2005-05-06 11:07:49 +00:00
|
|
|
#ifdef LIBALIAS_DEBUG
|
2004-03-16 21:30:41 +00:00
|
|
|
printf("\nType=%02x,", ndh->type);
|
1998-05-24 03:03:10 +00:00
|
|
|
#endif
|
2004-03-16 21:30:41 +00:00
|
|
|
switch (ndh->type) {
|
|
|
|
case DGM_DIRECT_UNIQ:
|
|
|
|
case DGM_DIRECT_GROUP:
|
|
|
|
case DGM_BROADCAST:
|
|
|
|
p = (u_char *) ndh + 14;
|
|
|
|
p = AliasHandleName(p, pmax); /* Source Name */
|
|
|
|
p = AliasHandleName(p, pmax); /* Destination Name */
|
|
|
|
break;
|
|
|
|
case DGM_ERROR:
|
|
|
|
p = (u_char *) ndh + 11;
|
|
|
|
break;
|
|
|
|
case DGM_QUERY:
|
|
|
|
case DGM_POSITIVE_RES:
|
|
|
|
case DGM_NEGATIVE_RES:
|
|
|
|
p = (u_char *) ndh + 10;
|
|
|
|
p = AliasHandleName(p, pmax); /* Destination Name */
|
|
|
|
break;
|
1998-05-24 03:03:10 +00:00
|
|
|
}
|
2004-03-16 21:30:41 +00:00
|
|
|
if (p == NULL || (char *)p > pmax)
|
|
|
|
p = NULL;
|
2005-05-06 11:07:49 +00:00
|
|
|
#ifdef LIBALIAS_DEBUG
|
2017-02-16 20:47:41 +00:00
|
|
|
printf("%s:%d-->", inet_ntoa_r(ndh->source_ip, INET_NTOA_BUF(addrbuf)),
|
|
|
|
ntohs(ndh->source_port));
|
1998-05-24 03:03:10 +00:00
|
|
|
#endif
|
2003-01-01 18:49:04 +00:00
|
|
|
/* Doing an IP address and Port number Translation */
|
2004-03-16 21:30:41 +00:00
|
|
|
if (uh->uh_sum != 0) {
|
|
|
|
int acc;
|
|
|
|
u_short *sptr;
|
|
|
|
|
|
|
|
acc = ndh->source_port;
|
1998-05-24 03:03:10 +00:00
|
|
|
acc -= alias_port;
|
2004-03-16 21:30:41 +00:00
|
|
|
sptr = (u_short *) & (ndh->source_ip);
|
1998-05-24 03:03:10 +00:00
|
|
|
acc += *sptr++;
|
|
|
|
acc += *sptr;
|
|
|
|
sptr = (u_short *) alias_address;
|
|
|
|
acc -= *sptr++;
|
|
|
|
acc -= *sptr;
|
2001-03-25 12:05:10 +00:00
|
|
|
ADJUST_CHECKSUM(acc, uh->uh_sum);
|
1998-05-24 03:03:10 +00:00
|
|
|
}
|
2004-03-16 21:30:41 +00:00
|
|
|
ndh->source_ip = *alias_address;
|
|
|
|
ndh->source_port = alias_port;
|
2005-05-06 11:07:49 +00:00
|
|
|
#ifdef LIBALIAS_DEBUG
|
2017-02-16 20:47:41 +00:00
|
|
|
printf("%s:%d\n", inet_ntoa_r(ndh->source_ip, INET_NTOA_BUF(addrbuf)),
|
|
|
|
ntohs(ndh->source_port));
|
1998-05-24 03:03:10 +00:00
|
|
|
fflush(stdout);
|
|
|
|
#endif
|
2004-03-16 21:30:41 +00:00
|
|
|
return ((p == NULL) ? -1 : 0);
|
1998-05-24 03:03:10 +00:00
|
|
|
}
|
2004-03-16 21:30:41 +00:00
|
|
|
|
1998-05-24 03:03:10 +00:00
|
|
|
/* Question Section */
|
|
|
|
#define QS_TYPE_NB 0x0020
|
|
|
|
#define QS_TYPE_NBSTAT 0x0021
|
|
|
|
#define QS_CLAS_IN 0x0001
|
|
|
|
typedef struct {
|
2004-03-16 21:30:41 +00:00
|
|
|
u_short type; /* The type of Request */
|
|
|
|
u_short class; /* The class of Request */
|
|
|
|
} NBTNsQuestion;
|
1998-05-24 03:03:10 +00:00
|
|
|
|
2004-03-16 21:30:41 +00:00
|
|
|
static u_char *
|
1998-12-14 02:25:32 +00:00
|
|
|
AliasHandleQuestion(
|
|
|
|
u_short count,
|
2004-03-16 21:30:41 +00:00
|
|
|
NBTNsQuestion * q,
|
1998-12-14 02:25:32 +00:00
|
|
|
char *pmax,
|
2004-03-16 21:30:41 +00:00
|
|
|
NBTArguments * nbtarg)
|
1998-05-24 03:03:10 +00:00
|
|
|
{
|
|
|
|
|
2004-07-05 11:10:57 +00:00
|
|
|
(void)nbtarg;
|
|
|
|
|
2004-03-16 21:30:41 +00:00
|
|
|
while (count != 0) {
|
1998-05-24 03:03:10 +00:00
|
|
|
/* Name Filed */
|
2004-03-16 21:30:41 +00:00
|
|
|
q = (NBTNsQuestion *) AliasHandleName((u_char *) q, pmax);
|
1998-12-14 02:25:32 +00:00
|
|
|
|
|
|
|
if (q == NULL || (char *)(q + 1) > pmax) {
|
|
|
|
q = NULL;
|
|
|
|
break;
|
|
|
|
}
|
1998-05-24 03:03:10 +00:00
|
|
|
/* Type and Class filed */
|
2004-03-16 21:30:41 +00:00
|
|
|
switch (ntohs(q->type)) {
|
|
|
|
case QS_TYPE_NB:
|
|
|
|
case QS_TYPE_NBSTAT:
|
|
|
|
q = q + 1;
|
1998-05-24 03:03:10 +00:00
|
|
|
break;
|
2004-03-16 21:30:41 +00:00
|
|
|
default:
|
2005-05-06 11:07:49 +00:00
|
|
|
#ifdef LIBALIAS_DEBUG
|
2004-03-16 21:30:41 +00:00
|
|
|
printf("\nUnknown Type on Question %0x\n", ntohs(q->type));
|
1999-03-09 23:44:00 +00:00
|
|
|
#endif
|
1998-05-24 03:03:10 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
count--;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set up to out of Question Section */
|
2004-03-16 21:30:41 +00:00
|
|
|
return ((u_char *) q);
|
1998-05-24 03:03:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Resource Record */
|
|
|
|
#define RR_TYPE_A 0x0001
|
|
|
|
#define RR_TYPE_NS 0x0002
|
|
|
|
#define RR_TYPE_NULL 0x000a
|
|
|
|
#define RR_TYPE_NB 0x0020
|
|
|
|
#define RR_TYPE_NBSTAT 0x0021
|
|
|
|
#define RR_CLAS_IN 0x0001
|
|
|
|
#define SizeOfNsResource 8
|
|
|
|
typedef struct {
|
2004-03-16 21:30:41 +00:00
|
|
|
u_short type;
|
|
|
|
u_short class;
|
|
|
|
unsigned int ttl;
|
|
|
|
u_short rdlen;
|
|
|
|
} NBTNsResource;
|
1998-05-24 03:03:10 +00:00
|
|
|
|
|
|
|
#define SizeOfNsRNB 6
|
|
|
|
typedef struct {
|
2004-03-16 21:30:41 +00:00
|
|
|
u_short g: 1 , ont:2, resv:13;
|
|
|
|
struct in_addr addr;
|
|
|
|
} NBTNsRNB;
|
1998-05-24 03:03:10 +00:00
|
|
|
|
2004-03-16 21:30:41 +00:00
|
|
|
static u_char *
|
2002-07-01 11:19:40 +00:00
|
|
|
AliasHandleResourceNB(
|
2004-03-16 21:30:41 +00:00
|
|
|
NBTNsResource * q,
|
2002-07-01 11:19:40 +00:00
|
|
|
char *pmax,
|
2004-03-16 21:30:41 +00:00
|
|
|
NBTArguments * nbtarg)
|
1998-05-24 03:03:10 +00:00
|
|
|
{
|
2004-03-16 21:30:41 +00:00
|
|
|
NBTNsRNB *nb;
|
1998-05-24 03:03:10 +00:00
|
|
|
u_short bcount;
|
2017-02-16 20:47:41 +00:00
|
|
|
#ifdef LIBALIAS_DEBUG
|
|
|
|
char oldbuf[INET_ADDRSTRLEN];
|
|
|
|
char newbuf[INET_ADDRSTRLEN];
|
|
|
|
#endif
|
1998-05-24 03:03:10 +00:00
|
|
|
|
1998-12-14 02:25:32 +00:00
|
|
|
if (q == NULL || (char *)(q + 1) > pmax)
|
2004-03-16 21:30:41 +00:00
|
|
|
return (NULL);
|
1998-05-24 03:03:10 +00:00
|
|
|
/* Check out a length */
|
|
|
|
bcount = ntohs(q->rdlen);
|
|
|
|
|
|
|
|
/* Forward to Resource NB position */
|
2004-03-16 21:30:41 +00:00
|
|
|
nb = (NBTNsRNB *) ((u_char *) q + SizeOfNsResource);
|
1998-05-24 03:03:10 +00:00
|
|
|
|
|
|
|
/* Processing all in_addr array */
|
2005-05-06 11:07:49 +00:00
|
|
|
#ifdef LIBALIAS_DEBUG
|
2017-02-16 20:47:41 +00:00
|
|
|
printf("NB rec[%s->%s, %dbytes] ",
|
|
|
|
inet_ntoa_r(nbtarg->oldaddr, INET_NTOA_BUF(oldbuf)),
|
|
|
|
inet_ntoa_r(nbtarg->newaddr, INET_NTOA_BUF(newbuf)),
|
|
|
|
bcount);
|
1998-05-24 03:03:10 +00:00
|
|
|
#endif
|
2004-03-16 21:30:41 +00:00
|
|
|
while (nb != NULL && bcount != 0) {
|
1998-12-14 02:25:32 +00:00
|
|
|
if ((char *)(nb + 1) > pmax) {
|
|
|
|
nb = NULL;
|
|
|
|
break;
|
|
|
|
}
|
2005-05-06 11:07:49 +00:00
|
|
|
#ifdef LIBALIAS_DEBUG
|
2017-02-16 20:47:41 +00:00
|
|
|
printf("<%s>", inet_ntoa_r(nb->addr, INET_NTOA_BUF(newbuf)));
|
1998-05-24 03:03:10 +00:00
|
|
|
#endif
|
2004-03-16 21:30:41 +00:00
|
|
|
if (!bcmp(&nbtarg->oldaddr, &nb->addr, sizeof(struct in_addr))) {
|
|
|
|
if (*nbtarg->uh_sum != 0) {
|
|
|
|
int acc;
|
|
|
|
u_short *sptr;
|
|
|
|
|
|
|
|
sptr = (u_short *) & (nb->addr);
|
|
|
|
acc = *sptr++;
|
|
|
|
acc += *sptr;
|
|
|
|
sptr = (u_short *) & (nbtarg->newaddr);
|
|
|
|
acc -= *sptr++;
|
|
|
|
acc -= *sptr;
|
|
|
|
ADJUST_CHECKSUM(acc, *nbtarg->uh_sum);
|
1998-05-24 03:03:10 +00:00
|
|
|
}
|
|
|
|
nb->addr = nbtarg->newaddr;
|
2005-05-06 11:07:49 +00:00
|
|
|
#ifdef LIBALIAS_DEBUG
|
1998-05-24 03:03:10 +00:00
|
|
|
printf("O");
|
|
|
|
#endif
|
|
|
|
}
|
2005-05-06 11:07:49 +00:00
|
|
|
#ifdef LIBALIAS_DEBUG
|
2004-03-16 21:30:41 +00:00
|
|
|
else {
|
1998-05-24 03:03:10 +00:00
|
|
|
printf(".");
|
|
|
|
}
|
|
|
|
#endif
|
2004-03-16 21:30:41 +00:00
|
|
|
nb = (NBTNsRNB *) ((u_char *) nb + SizeOfNsRNB);
|
|
|
|
bcount -= SizeOfNsRNB;
|
1998-05-24 03:03:10 +00:00
|
|
|
}
|
1998-12-14 02:25:32 +00:00
|
|
|
if (nb == NULL || (char *)(nb + 1) > pmax) {
|
|
|
|
nb = NULL;
|
|
|
|
}
|
2004-03-16 21:30:41 +00:00
|
|
|
return ((u_char *) nb);
|
1998-05-24 03:03:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define SizeOfResourceA 6
|
|
|
|
typedef struct {
|
2004-03-16 21:30:41 +00:00
|
|
|
struct in_addr addr;
|
|
|
|
} NBTNsResourceA;
|
1998-05-24 03:03:10 +00:00
|
|
|
|
2004-03-16 21:30:41 +00:00
|
|
|
static u_char *
|
2002-07-01 11:19:40 +00:00
|
|
|
AliasHandleResourceA(
|
2004-03-16 21:30:41 +00:00
|
|
|
NBTNsResource * q,
|
1998-12-14 02:25:32 +00:00
|
|
|
char *pmax,
|
2004-03-16 21:30:41 +00:00
|
|
|
NBTArguments * nbtarg)
|
1998-05-24 03:03:10 +00:00
|
|
|
{
|
2004-03-16 21:30:41 +00:00
|
|
|
NBTNsResourceA *a;
|
1998-05-24 03:03:10 +00:00
|
|
|
u_short bcount;
|
2017-02-16 20:47:41 +00:00
|
|
|
#ifdef LIBALIAS_DEBUG
|
|
|
|
char oldbuf[INET_ADDRSTRLEN];
|
|
|
|
char newbuf[INET_ADDRSTRLEN];
|
|
|
|
#endif
|
1998-05-24 03:03:10 +00:00
|
|
|
|
1998-12-14 02:25:32 +00:00
|
|
|
if (q == NULL || (char *)(q + 1) > pmax)
|
2004-03-16 21:30:41 +00:00
|
|
|
return (NULL);
|
1998-12-14 02:25:32 +00:00
|
|
|
|
1998-05-24 03:03:10 +00:00
|
|
|
/* Forward to Resource A position */
|
2004-03-16 21:30:41 +00:00
|
|
|
a = (NBTNsResourceA *) ((u_char *) q + sizeof(NBTNsResource));
|
1998-05-24 03:03:10 +00:00
|
|
|
|
|
|
|
/* Check out of length */
|
|
|
|
bcount = ntohs(q->rdlen);
|
|
|
|
|
|
|
|
/* Processing all in_addr array */
|
2005-05-06 11:07:49 +00:00
|
|
|
#ifdef LIBALIAS_DEBUG
|
2017-02-16 20:47:41 +00:00
|
|
|
printf("Arec [%s->%s]",
|
|
|
|
inet_ntoa_r(nbtarg->oldaddr, INET_NTOA_BUF(oldbuf)),
|
|
|
|
inet_ntoa_r(nbtarg->newaddr, INET_NTOA_BUF(newbuf)));
|
1998-05-24 03:03:10 +00:00
|
|
|
#endif
|
2004-03-16 21:30:41 +00:00
|
|
|
while (bcount != 0) {
|
1998-12-14 02:25:32 +00:00
|
|
|
if (a == NULL || (char *)(a + 1) > pmax)
|
2004-03-16 21:30:41 +00:00
|
|
|
return (NULL);
|
2005-05-06 11:07:49 +00:00
|
|
|
#ifdef LIBALIAS_DEBUG
|
2017-02-16 20:47:41 +00:00
|
|
|
printf("..%s", inet_ntoa_r(a->addr, INET_NTOA_BUF(newbuf)));
|
1998-05-24 03:03:10 +00:00
|
|
|
#endif
|
2004-03-16 21:30:41 +00:00
|
|
|
if (!bcmp(&nbtarg->oldaddr, &a->addr, sizeof(struct in_addr))) {
|
|
|
|
if (*nbtarg->uh_sum != 0) {
|
|
|
|
int acc;
|
|
|
|
u_short *sptr;
|
|
|
|
|
|
|
|
sptr = (u_short *) & (a->addr); /* Old */
|
|
|
|
acc = *sptr++;
|
|
|
|
acc += *sptr;
|
|
|
|
sptr = (u_short *) & nbtarg->newaddr; /* New */
|
|
|
|
acc -= *sptr++;
|
|
|
|
acc -= *sptr;
|
|
|
|
ADJUST_CHECKSUM(acc, *nbtarg->uh_sum);
|
1998-05-24 03:03:10 +00:00
|
|
|
}
|
|
|
|
a->addr = nbtarg->newaddr;
|
|
|
|
}
|
2004-03-16 21:30:41 +00:00
|
|
|
a++; /* XXXX */
|
1998-05-24 03:03:10 +00:00
|
|
|
bcount -= SizeOfResourceA;
|
|
|
|
}
|
1998-12-14 02:25:32 +00:00
|
|
|
if (a == NULL || (char *)(a + 1) > pmax)
|
2004-03-16 21:30:41 +00:00
|
|
|
a = NULL;
|
|
|
|
return ((u_char *) a);
|
1998-05-24 03:03:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct {
|
2004-03-16 21:30:41 +00:00
|
|
|
u_short opcode:4, flags:8, resv:4;
|
|
|
|
} NBTNsResourceNULL;
|
1998-05-24 03:03:10 +00:00
|
|
|
|
2004-03-16 21:30:41 +00:00
|
|
|
static u_char *
|
2002-07-01 11:19:40 +00:00
|
|
|
AliasHandleResourceNULL(
|
2004-03-16 21:30:41 +00:00
|
|
|
NBTNsResource * q,
|
1998-12-14 02:25:32 +00:00
|
|
|
char *pmax,
|
2004-03-16 21:30:41 +00:00
|
|
|
NBTArguments * nbtarg)
|
1998-05-24 03:03:10 +00:00
|
|
|
{
|
2004-03-16 21:30:41 +00:00
|
|
|
NBTNsResourceNULL *n;
|
1998-05-24 03:03:10 +00:00
|
|
|
u_short bcount;
|
|
|
|
|
2004-07-05 11:10:57 +00:00
|
|
|
(void)nbtarg;
|
|
|
|
|
1998-12-14 02:25:32 +00:00
|
|
|
if (q == NULL || (char *)(q + 1) > pmax)
|
2004-03-16 21:30:41 +00:00
|
|
|
return (NULL);
|
1998-12-14 02:25:32 +00:00
|
|
|
|
1998-05-24 03:03:10 +00:00
|
|
|
/* Forward to Resource NULL position */
|
2004-03-16 21:30:41 +00:00
|
|
|
n = (NBTNsResourceNULL *) ((u_char *) q + sizeof(NBTNsResource));
|
1998-05-24 03:03:10 +00:00
|
|
|
|
|
|
|
/* Check out of length */
|
|
|
|
bcount = ntohs(q->rdlen);
|
|
|
|
|
|
|
|
/* Processing all in_addr array */
|
2004-03-16 21:30:41 +00:00
|
|
|
while (bcount != 0) {
|
1998-12-14 02:25:32 +00:00
|
|
|
if ((char *)(n + 1) > pmax) {
|
|
|
|
n = NULL;
|
|
|
|
break;
|
|
|
|
}
|
1998-05-24 03:03:10 +00:00
|
|
|
n++;
|
|
|
|
bcount -= sizeof(NBTNsResourceNULL);
|
|
|
|
}
|
1998-12-14 02:25:32 +00:00
|
|
|
if ((char *)(n + 1) > pmax)
|
|
|
|
n = NULL;
|
1998-05-24 03:03:10 +00:00
|
|
|
|
2004-03-16 21:30:41 +00:00
|
|
|
return ((u_char *) n);
|
1998-05-24 03:03:10 +00:00
|
|
|
}
|
|
|
|
|
2004-03-16 21:30:41 +00:00
|
|
|
static u_char *
|
2002-07-01 11:19:40 +00:00
|
|
|
AliasHandleResourceNS(
|
2004-03-16 21:30:41 +00:00
|
|
|
NBTNsResource * q,
|
1998-12-14 02:25:32 +00:00
|
|
|
char *pmax,
|
2004-03-16 21:30:41 +00:00
|
|
|
NBTArguments * nbtarg)
|
1998-05-24 03:03:10 +00:00
|
|
|
{
|
2004-03-16 21:30:41 +00:00
|
|
|
NBTNsResourceNULL *n;
|
1998-05-24 03:03:10 +00:00
|
|
|
u_short bcount;
|
|
|
|
|
2004-07-05 11:10:57 +00:00
|
|
|
(void)nbtarg;
|
|
|
|
|
1998-12-14 02:25:32 +00:00
|
|
|
if (q == NULL || (char *)(q + 1) > pmax)
|
2004-03-16 21:30:41 +00:00
|
|
|
return (NULL);
|
1998-12-14 02:25:32 +00:00
|
|
|
|
1998-05-24 03:03:10 +00:00
|
|
|
/* Forward to Resource NULL position */
|
2004-03-16 21:30:41 +00:00
|
|
|
n = (NBTNsResourceNULL *) ((u_char *) q + sizeof(NBTNsResource));
|
1998-05-24 03:03:10 +00:00
|
|
|
|
|
|
|
/* Check out of length */
|
|
|
|
bcount = ntohs(q->rdlen);
|
|
|
|
|
|
|
|
/* Resource Record Name Filed */
|
2004-03-16 21:30:41 +00:00
|
|
|
q = (NBTNsResource *) AliasHandleName((u_char *) n, pmax); /* XXX */
|
1998-05-24 03:03:10 +00:00
|
|
|
|
2004-03-16 21:30:41 +00:00
|
|
|
if (q == NULL || (char *)((u_char *) n + bcount) > pmax)
|
|
|
|
return (NULL);
|
1998-12-14 02:25:32 +00:00
|
|
|
else
|
2004-03-16 21:30:41 +00:00
|
|
|
return ((u_char *) n + bcount);
|
1998-05-24 03:03:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct {
|
2004-03-16 21:30:41 +00:00
|
|
|
u_short numnames;
|
|
|
|
} NBTNsResourceNBSTAT;
|
1998-05-24 03:03:10 +00:00
|
|
|
|
2004-03-16 21:30:41 +00:00
|
|
|
static u_char *
|
1998-12-14 02:25:32 +00:00
|
|
|
AliasHandleResourceNBSTAT(
|
2004-03-16 21:30:41 +00:00
|
|
|
NBTNsResource * q,
|
1998-12-14 02:25:32 +00:00
|
|
|
char *pmax,
|
2004-03-16 21:30:41 +00:00
|
|
|
NBTArguments * nbtarg)
|
1998-05-24 03:03:10 +00:00
|
|
|
{
|
2004-03-16 21:30:41 +00:00
|
|
|
NBTNsResourceNBSTAT *n;
|
1998-05-24 03:03:10 +00:00
|
|
|
u_short bcount;
|
|
|
|
|
2004-07-05 11:10:57 +00:00
|
|
|
(void)nbtarg;
|
|
|
|
|
1998-12-14 02:25:32 +00:00
|
|
|
if (q == NULL || (char *)(q + 1) > pmax)
|
2004-03-16 21:30:41 +00:00
|
|
|
return (NULL);
|
1998-12-14 02:25:32 +00:00
|
|
|
|
1998-05-24 03:03:10 +00:00
|
|
|
/* Forward to Resource NBSTAT position */
|
2004-03-16 21:30:41 +00:00
|
|
|
n = (NBTNsResourceNBSTAT *) ((u_char *) q + sizeof(NBTNsResource));
|
1998-05-24 03:03:10 +00:00
|
|
|
|
|
|
|
/* Check out of length */
|
|
|
|
bcount = ntohs(q->rdlen);
|
|
|
|
|
2004-03-16 21:30:41 +00:00
|
|
|
if (q == NULL || (char *)((u_char *) n + bcount) > pmax)
|
|
|
|
return (NULL);
|
1998-12-14 02:25:32 +00:00
|
|
|
else
|
2004-03-16 21:30:41 +00:00
|
|
|
return ((u_char *) n + bcount);
|
1998-05-24 03:03:10 +00:00
|
|
|
}
|
|
|
|
|
2004-03-16 21:30:41 +00:00
|
|
|
static u_char *
|
1998-12-14 02:25:32 +00:00
|
|
|
AliasHandleResource(
|
2002-07-01 11:19:40 +00:00
|
|
|
u_short count,
|
2004-03-16 21:30:41 +00:00
|
|
|
NBTNsResource * q,
|
1998-12-14 02:25:32 +00:00
|
|
|
char *pmax,
|
2002-07-01 11:19:40 +00:00
|
|
|
NBTArguments
|
2004-03-16 21:30:41 +00:00
|
|
|
* nbtarg)
|
1998-05-24 03:03:10 +00:00
|
|
|
{
|
2004-03-16 21:30:41 +00:00
|
|
|
while (count != 0) {
|
1998-05-24 03:03:10 +00:00
|
|
|
/* Resource Record Name Filed */
|
2004-03-16 21:30:41 +00:00
|
|
|
q = (NBTNsResource *) AliasHandleName((u_char *) q, pmax);
|
1998-12-14 02:25:32 +00:00
|
|
|
|
|
|
|
if (q == NULL || (char *)(q + 1) > pmax)
|
|
|
|
break;
|
2005-05-06 11:07:49 +00:00
|
|
|
#ifdef LIBALIAS_DEBUG
|
2004-03-16 21:30:41 +00:00
|
|
|
printf("type=%02x, count=%d\n", ntohs(q->type), count);
|
1998-05-24 03:03:10 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Type and Class filed */
|
2004-03-16 21:30:41 +00:00
|
|
|
switch (ntohs(q->type)) {
|
|
|
|
case RR_TYPE_NB:
|
|
|
|
q = (NBTNsResource *) AliasHandleResourceNB(
|
|
|
|
q,
|
|
|
|
pmax,
|
|
|
|
nbtarg
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case RR_TYPE_A:
|
|
|
|
q = (NBTNsResource *) AliasHandleResourceA(
|
|
|
|
q,
|
|
|
|
pmax,
|
|
|
|
nbtarg
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case RR_TYPE_NS:
|
|
|
|
q = (NBTNsResource *) AliasHandleResourceNS(
|
|
|
|
q,
|
|
|
|
pmax,
|
|
|
|
nbtarg
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case RR_TYPE_NULL:
|
|
|
|
q = (NBTNsResource *) AliasHandleResourceNULL(
|
|
|
|
q,
|
|
|
|
pmax,
|
|
|
|
nbtarg
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case RR_TYPE_NBSTAT:
|
|
|
|
q = (NBTNsResource *) AliasHandleResourceNBSTAT(
|
|
|
|
q,
|
|
|
|
pmax,
|
|
|
|
nbtarg
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
default:
|
2005-05-06 11:07:49 +00:00
|
|
|
#ifdef LIBALIAS_DEBUG
|
2004-03-16 21:30:41 +00:00
|
|
|
printf(
|
|
|
|
"\nUnknown Type of Resource %0x\n",
|
|
|
|
ntohs(q->type)
|
|
|
|
);
|
2005-05-05 21:07:34 +00:00
|
|
|
fflush(stdout);
|
1999-03-09 23:44:00 +00:00
|
|
|
#endif
|
2004-03-16 21:30:41 +00:00
|
|
|
break;
|
1998-05-24 03:03:10 +00:00
|
|
|
}
|
|
|
|
count--;
|
|
|
|
}
|
2004-03-16 21:30:41 +00:00
|
|
|
return ((u_char *) q);
|
1998-05-24 03:03:10 +00:00
|
|
|
}
|
|
|
|
|
Summer of Code 2005: improve libalias - part 1 of 2
With the first part of my previous Summer of Code work, we get:
-made libalias modular:
-support for 'particular' protocols (like ftp/irc/etcetc) is no more
hardcoded inside libalias, but it's available through external
modules loadable at runtime
-modules are available both in kernel (/boot/kernel/alias_*.ko) and
user land (/lib/libalias_*)
-protocols/applications modularized are: cuseeme, ftp, irc, nbt, pptp,
skinny and smedia
-added logging support for kernel side
-cleanup
After a buildworld, do a 'mergemaster -i' to install the file libalias.conf
in /etc or manually copy it.
During startup (and after every HUP signal) user land applications running
the new libalias will try to read a file in /etc called libalias.conf:
that file contains the list of modules to load.
User land applications affected by this commit are ppp and natd:
if libalias.conf is present in /etc you won't notice any difference.
The only kernel land bit affected by this commit is ng_nat:
if you are using ng_nat, and it doesn't correctly handle
ftp/irc/etcetc sessions anymore, remember to kldload
the correspondent module (i.e. kldload alias_ftp).
General information and details about the inner working are available
in the libalias man page under the section 'MODULAR ARCHITECTURE
(AND ipfw(4) SUPPORT)'.
NOTA BENE: this commit affects _ONLY_ libalias, ipfw in-kernel nat
support will be part of the next libalias-related commit.
Approved by: glebius
Reviewed by: glebius, ru
2006-09-26 23:26:53 +00:00
|
|
|
static int
|
2004-03-16 21:30:41 +00:00
|
|
|
AliasHandleUdpNbtNS(
|
|
|
|
struct libalias *la,
|
|
|
|
struct ip *pip, /* IP packet to examine/patch */
|
2004-07-05 11:10:57 +00:00
|
|
|
struct alias_link *lnk,
|
2004-03-16 21:30:41 +00:00
|
|
|
struct in_addr *alias_address,
|
|
|
|
u_short * alias_port,
|
|
|
|
struct in_addr *original_address,
|
|
|
|
u_short * original_port)
|
1998-05-24 03:03:10 +00:00
|
|
|
{
|
2004-03-16 21:30:41 +00:00
|
|
|
struct udphdr *uh;
|
|
|
|
NbtNSHeader *nsh;
|
|
|
|
u_char *p;
|
|
|
|
char *pmax;
|
|
|
|
NBTArguments nbtarg;
|
1998-05-24 03:03:10 +00:00
|
|
|
|
2004-07-05 11:10:57 +00:00
|
|
|
(void)la;
|
|
|
|
(void)lnk;
|
|
|
|
|
2002-07-01 11:19:40 +00:00
|
|
|
/* Set up Common Parameter */
|
2004-03-16 21:30:41 +00:00
|
|
|
nbtarg.oldaddr = *alias_address;
|
|
|
|
nbtarg.oldport = *alias_port;
|
|
|
|
nbtarg.newaddr = *original_address;
|
|
|
|
nbtarg.newport = *original_port;
|
1998-05-24 03:03:10 +00:00
|
|
|
|
2004-03-16 21:30:41 +00:00
|
|
|
/* Calculate data length of UDP packet */
|
2004-07-06 12:13:28 +00:00
|
|
|
uh = (struct udphdr *)ip_next(pip);
|
2004-03-16 21:30:41 +00:00
|
|
|
nbtarg.uh_sum = &(uh->uh_sum);
|
2004-07-06 12:13:28 +00:00
|
|
|
nsh = (NbtNSHeader *)udp_next(uh);
|
2004-03-16 21:30:41 +00:00
|
|
|
p = (u_char *) (nsh + 1);
|
|
|
|
pmax = (char *)uh + ntohs(uh->uh_ulen);
|
1998-12-14 02:25:32 +00:00
|
|
|
|
2004-03-16 21:30:41 +00:00
|
|
|
if ((char *)(nsh + 1) > pmax)
|
|
|
|
return (-1);
|
1998-05-24 03:03:10 +00:00
|
|
|
|
2005-05-06 11:07:49 +00:00
|
|
|
#ifdef LIBALIAS_DEBUG
|
2004-03-16 21:30:41 +00:00
|
|
|
printf(" [%s] ID=%02x, op=%01x, flag=%02x, rcode=%01x, qd=%04x"
|
|
|
|
", an=%04x, ns=%04x, ar=%04x, [%d]-->",
|
|
|
|
nsh->dir ? "Response" : "Request",
|
|
|
|
nsh->nametrid,
|
|
|
|
nsh->opcode,
|
|
|
|
nsh->nmflags,
|
|
|
|
nsh->rcode,
|
|
|
|
ntohs(nsh->qdcount),
|
|
|
|
ntohs(nsh->ancount),
|
|
|
|
ntohs(nsh->nscount),
|
|
|
|
ntohs(nsh->arcount),
|
|
|
|
(u_char *) p - (u_char *) nsh
|
|
|
|
);
|
1998-05-24 03:03:10 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Question Entries */
|
2004-03-16 21:30:41 +00:00
|
|
|
if (ntohs(nsh->qdcount) != 0) {
|
|
|
|
p = AliasHandleQuestion(
|
|
|
|
ntohs(nsh->qdcount),
|
|
|
|
(NBTNsQuestion *) p,
|
|
|
|
pmax,
|
|
|
|
&nbtarg
|
|
|
|
);
|
1998-05-24 03:03:10 +00:00
|
|
|
}
|
|
|
|
/* Answer Resource Records */
|
2004-03-16 21:30:41 +00:00
|
|
|
if (ntohs(nsh->ancount) != 0) {
|
|
|
|
p = AliasHandleResource(
|
|
|
|
ntohs(nsh->ancount),
|
|
|
|
(NBTNsResource *) p,
|
|
|
|
pmax,
|
|
|
|
&nbtarg
|
|
|
|
);
|
1998-05-24 03:03:10 +00:00
|
|
|
}
|
|
|
|
/* Authority Resource Recodrs */
|
2004-03-16 21:30:41 +00:00
|
|
|
if (ntohs(nsh->nscount) != 0) {
|
|
|
|
p = AliasHandleResource(
|
|
|
|
ntohs(nsh->nscount),
|
|
|
|
(NBTNsResource *) p,
|
|
|
|
pmax,
|
|
|
|
&nbtarg
|
|
|
|
);
|
1998-05-24 03:03:10 +00:00
|
|
|
}
|
|
|
|
/* Additional Resource Recodrs */
|
2004-03-16 21:30:41 +00:00
|
|
|
if (ntohs(nsh->arcount) != 0) {
|
|
|
|
p = AliasHandleResource(
|
|
|
|
ntohs(nsh->arcount),
|
|
|
|
(NBTNsResource *) p,
|
|
|
|
pmax,
|
|
|
|
&nbtarg
|
|
|
|
);
|
1998-05-24 03:03:10 +00:00
|
|
|
}
|
2005-05-06 11:07:49 +00:00
|
|
|
#ifdef LIBALIAS_DEBUG
|
2004-03-16 21:30:41 +00:00
|
|
|
PrintRcode(nsh->rcode);
|
1998-05-24 03:03:10 +00:00
|
|
|
#endif
|
2004-03-16 21:30:41 +00:00
|
|
|
return ((p == NULL) ? -1 : 0);
|
1998-05-24 03:03:10 +00:00
|
|
|
}
|