2 * Simple netbios-dgm transparent proxy for in-kernel use.
3 * For use with the NAT code.
4 * $Id: ip_netbios_pxy.c,v 1.1.2.3 2002/01/09 09:28:37 darrenr Exp $
5 * $FreeBSD: src/sys/contrib/ipfilter/netinet/ip_netbios_pxy.c,v 1.1.1.1.2.1 2002/04/27 17:37:12 darrenr Exp $
6 * $DragonFly: src/sys/contrib/ipfilter/netinet/ip_netbios_pxy.c,v 1.3 2003/08/27 11:02:14 rob Exp $
10 * Copyright (c) 2002 Paul J. Ledbetter III
11 * All rights reserved.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * $Id: ip_netbios_pxy.c,v 1.1.2.3 2002/01/09 09:28:37 darrenr Exp $
37 #define IPF_NETBIOS_PROXY
39 int ippr_netbios_init (void);
40 int ippr_netbios_out (fr_info_t *, ip_t *, ap_session_t *, nat_t *);
42 static frentry_t netbiosfr;
45 * Initialize local structures.
47 int ippr_netbios_init()
49 bzero((char *)&netbiosfr, sizeof(netbiosfr));
51 netbiosfr.fr_flags = FR_INQUE|FR_PASS|FR_QUICK|FR_KEEPSTATE;
55 int ippr_netbios_out(fin, ip, aps, nat)
67 m = *(mb_t **)fin->fin_mp;
68 off = fin->fin_hlen + sizeof(udphdr_t);
72 dlen = mbufchainlen(m);
77 * no net bios datagram could possibly be shorter than this
82 udp = (udphdr_t *)fin->fin_dp;
88 * 4 bytes into the net bios dgm header.
89 * According to rfc1002, this should be the exact location of
90 * the source address/port
94 /* Copy NATed source Address/port*/
95 dgmbuf[0] = (char)((ip->ip_src.s_addr ) &0xFF);
96 dgmbuf[1] = (char)((ip->ip_src.s_addr >> 8) &0xFF);
97 dgmbuf[2] = (char)((ip->ip_src.s_addr >> 16)&0xFF);
98 dgmbuf[3] = (char)((ip->ip_src.s_addr >> 24)&0xFF);
100 dgmbuf[4] = (char)((udp->uh_sport )&0xFF);
101 dgmbuf[5] = (char)((udp->uh_sport >> 8)&0xFF);
103 /* replace data in packet */
105 copyin_mblk(m, off, sizeof(dgmbuf), dgmbuf);
107 m_copyback(m, off, sizeof(dgmbuf), dgmbuf);