alias.h revision 124621
174778Sbrian/* lint -save -library Flexelint comment for external headers */
226026Sbrian
374778Sbrian/*-
485964Sbrian * Copyright (c) 2001 Charles Mott <cm@linktel.net>
577701Sbrian * All rights reserved.
677701Sbrian *
777701Sbrian * Redistribution and use in source and binary forms, with or without
877701Sbrian * modification, are permitted provided that the following conditions
977701Sbrian * are met:
1077701Sbrian * 1. Redistributions of source code must retain the above copyright
1177701Sbrian *    notice, this list of conditions and the following disclaimer.
1277701Sbrian * 2. Redistributions in binary form must reproduce the above copyright
1377701Sbrian *    notice, this list of conditions and the following disclaimer in the
1477701Sbrian *    documentation and/or other materials provided with the distribution.
1577701Sbrian *
1677701Sbrian * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1777701Sbrian * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1877701Sbrian * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1977701Sbrian * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2077701Sbrian * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2177701Sbrian * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2277701Sbrian * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2377701Sbrian * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2477701Sbrian * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2577701Sbrian * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2677701Sbrian * SUCH DAMAGE.
2777701Sbrian *
2877701Sbrian * $FreeBSD: head/sys/netinet/libalias/alias.h 124621 2004-01-17 10:52:21Z phk $
2977701Sbrian */
3077701Sbrian
3177701Sbrian/*-
3274778Sbrian * Alias.h defines the outside world interfaces for the packet aliasing
3374778Sbrian * software.
3499207Sbrian *
3574778Sbrian * This software is placed into the public domain with no restrictions on its
3674778Sbrian * distribution.
3774778Sbrian */
3826026Sbrian
3926026Sbrian#ifndef _ALIAS_H_
4074778Sbrian#define	_ALIAS_H_
4126026Sbrian
42124621Sphk/*
43124621Sphk * The external interface to libalias, the packet aliasing engine.
44124621Sphk *
45124621Sphk * There are two sets of functions:
46124621Sphk *
47124621Sphk * PacketAlias*() the old API which doesn't take an instance pointer
48124621Sphk * and therefore can only have one packet engine at a time.
49124621Sphk *
50124621Sphk * LibAlias*() the new API which takes as first argument a pointer to
51124621Sphk * the instance of the packet aliasing engine.
52124621Sphk *
53124621Sphk * The functions otherwise correspond to each other one for one, except
54124621Sphk * for the LibAliasUnaliasOut()/PacketUnaliasOut() function which were
55124621Sphk * were misnamed in the old API.
56124621Sphk */
5726026Sbrian
58124621Sphk/*
59124621Sphk * The instance structure
60124621Sphk */
61124621Sphkstruct libalias;
62124621Sphk
63124621Sphk/*
64124621Sphk * An anonymous structure, a pointer to which is returned from
65124621Sphk * PacketAliasRedirectAddr(), PacketAliasRedirectPort() or
66124621Sphk * PacketAliasRedirectProto(), passed to PacketAliasAddServer(),
67124621Sphk * and freed by PacketAliasRedirectDelete().
68124621Sphk */
69124621Sphkstruct	alias_link;
70124621Sphk
71124621Sphk
72124621Sphk/* OLD API */
73124621Sphk
7474778Sbrian/* Initialization and control functions. */
7574778Sbrianvoid	 PacketAliasInit(void);
7674778Sbrianvoid	 PacketAliasSetAddress(struct in_addr _addr);
7774778Sbrianvoid	 PacketAliasSetFWBase(unsigned int _base, unsigned int _num);
78120372Smarcusvoid	 PacketAliasSetSkinnyPort(unsigned int _port);
7974778Sbrianunsigned int
8074778Sbrian	 PacketAliasSetMode(unsigned int _flags, unsigned int _mask);
8174778Sbrianvoid	 PacketAliasUninit(void);
8227864Sbrian
8374778Sbrian/* Packet Handling functions. */
8474778Sbrianint	 PacketAliasIn(char *_ptr, int _maxpacketsize);
8574778Sbrianint	 PacketAliasOut(char *_ptr, int _maxpacketsize);
8674778Sbrianint	 PacketUnaliasOut(char *_ptr, int _maxpacketsize);
8727864Sbrian
8874778Sbrian/* Port and address redirection functions. */
8932377Seivind
9027864Sbrian
9174778Sbrianint	 PacketAliasAddServer(struct alias_link *_link,
9274778Sbrian	    struct in_addr _addr, unsigned short _port);
9374778Sbrianstruct alias_link *
9474778Sbrian	 PacketAliasRedirectAddr(struct in_addr _src_addr,
9574778Sbrian	    struct in_addr _alias_addr);
96115650Sruint	 PacketAliasRedirectDynamic(struct alias_link *_link);
9774778Sbrianvoid	 PacketAliasRedirectDelete(struct alias_link *_link);
9874778Sbrianstruct alias_link *
9974778Sbrian	 PacketAliasRedirectPort(struct in_addr _src_addr,
10074778Sbrian	    unsigned short _src_port, struct in_addr _dst_addr,
10174778Sbrian	    unsigned short _dst_port, struct in_addr _alias_addr,
10274778Sbrian	    unsigned short _alias_port, unsigned char _proto);
10374778Sbrianstruct alias_link *
10474778Sbrian	 PacketAliasRedirectProto(struct in_addr _src_addr,
10574778Sbrian	    struct in_addr _dst_addr, struct in_addr _alias_addr,
10674778Sbrian	    unsigned char _proto);
10727864Sbrian
10874778Sbrian/* Fragment Handling functions. */
10974778Sbrianvoid	 PacketAliasFragmentIn(char *_ptr, char *_ptr_fragment);
11074778Sbrianchar	*PacketAliasGetFragment(char *_ptr);
11174778Sbrianint	 PacketAliasSaveFragment(char *_ptr);
11232377Seivind
11374778Sbrian/* Miscellaneous functions. */
11474778Sbrianint	 PacketAliasCheckNewLink(void);
11574778Sbrianunsigned short
11674778Sbrian	 PacketAliasInternetChecksum(unsigned short *_ptr, int _nbytes);
11774778Sbrianvoid	 PacketAliasSetTarget(struct in_addr _target_addr);
11827864Sbrian
11974778Sbrian/* Transparent proxying routines. */
12074778Sbrianint	 PacketAliasProxyRule(const char *_cmd);
12127864Sbrian
122124621Sphk/* NEW API */
123124621Sphk
124124621Sphk/* Initialization and control functions. */
125124621Sphkstruct libalias	*LibAliasInit(struct libalias *);
126124621Sphkvoid	 LibAliasSetAddress(struct libalias *, struct in_addr _addr);
127124621Sphkvoid	 LibAliasSetFWBase(struct libalias *, unsigned int _base, unsigned int _num);
128124621Sphkvoid	 LibAliasSetSkinnyPort(struct libalias *, unsigned int _port);
129124621Sphkunsigned int
130124621Sphk	 LibAliasSetMode(struct libalias *, unsigned int _flags, unsigned int _mask);
131124621Sphkvoid	 LibAliasUninit(struct libalias *);
132124621Sphk
133124621Sphk/* Packet Handling functions. */
134124621Sphkint	 LibAliasIn(struct libalias *, char *_ptr, int _maxpacketsize);
135124621Sphkint	 LibAliasOut(struct libalias *, char *_ptr, int _maxpacketsize);
136124621Sphkint	 LibAliasUnaliasOut(struct libalias *, char *_ptr, int _maxpacketsize);
137124621Sphk
138124621Sphk/* Port and address redirection functions. */
139124621Sphk
140124621Sphkint	 LibAliasAddServer(struct libalias *, struct alias_link *_link,
141124621Sphk	    struct in_addr _addr, unsigned short _port);
142124621Sphkstruct alias_link *
143124621Sphk	 LibAliasRedirectAddr(struct libalias *, struct in_addr _src_addr,
144124621Sphk	    struct in_addr _alias_addr);
145124621Sphkint	 LibAliasRedirectDynamic(struct libalias *, struct alias_link *_link);
146124621Sphkvoid	 LibAliasRedirectDelete(struct libalias *, struct alias_link *_link);
147124621Sphkstruct alias_link *
148124621Sphk	 LibAliasRedirectPort(struct libalias *, struct in_addr _src_addr,
149124621Sphk	    unsigned short _src_port, struct in_addr _dst_addr,
150124621Sphk	    unsigned short _dst_port, struct in_addr _alias_addr,
151124621Sphk	    unsigned short _alias_port, unsigned char _proto);
152124621Sphkstruct alias_link *
153124621Sphk	 LibAliasRedirectProto(struct libalias *, struct in_addr _src_addr,
154124621Sphk	    struct in_addr _dst_addr, struct in_addr _alias_addr,
155124621Sphk	    unsigned char _proto);
156124621Sphk
157124621Sphk/* Fragment Handling functions. */
158124621Sphkvoid	 LibAliasFragmentIn(struct libalias *, char *_ptr, char *_ptr_fragment);
159124621Sphkchar	*LibAliasGetFragment(struct libalias *, char *_ptr);
160124621Sphkint	 LibAliasSaveFragment(struct libalias *, char *_ptr);
161124621Sphk
162124621Sphk/* Miscellaneous functions. */
163124621Sphkint	 LibAliasCheckNewLink(struct libalias *);
164124621Sphkunsigned short
165124621Sphk	 LibAliasInternetChecksum(struct libalias *, unsigned short *_ptr, int _nbytes);
166124621Sphkvoid	 LibAliasSetTarget(struct libalias *, struct in_addr _target_addr);
167124621Sphk
168124621Sphk/* Transparent proxying routines. */
169124621Sphkint	 LibAliasProxyRule(struct libalias *, const char *_cmd);
170124621Sphk
171124621Sphk
172124621Sphk/*
173124621Sphk * Mode flags and other constants.
174124621Sphk */
175124621Sphk
176124621Sphk
17774778Sbrian/* Mode flags, set using PacketAliasSetMode() */
17863899Sarchie
17974778Sbrian/*
18074778Sbrian * If PKT_ALIAS_LOG is set, a message will be printed to /var/log/alias.log
18174778Sbrian * every time a link is created or deleted.  This is useful for debugging.
18274778Sbrian */
18374778Sbrian#define	PKT_ALIAS_LOG			0x01
18427864Sbrian
18574778Sbrian/*
18674778Sbrian * If PKT_ALIAS_DENY_INCOMING is set, then incoming connections (e.g. to ftp,
18774778Sbrian * telnet or web servers will be prevented by the aliasing mechanism.
18874778Sbrian */
18974778Sbrian#define	PKT_ALIAS_DENY_INCOMING		0x02
19059702Sru
19174778Sbrian/*
19274778Sbrian * If PKT_ALIAS_SAME_PORTS is set, packets will be attempted sent from the
19374778Sbrian * same port as they originated on.  This allows e.g. rsh to work *99% of the
19474778Sbrian * time*, but _not_ 100% (it will be slightly flakey instead of not working
19574778Sbrian * at all).  This mode bit is set by PacketAliasInit(), so it is a default
19674778Sbrian * mode of operation.
19774778Sbrian */
19874778Sbrian#define	PKT_ALIAS_SAME_PORTS		0x04
19944307Sbrian
20074778Sbrian/*
20174778Sbrian * If PKT_ALIAS_USE_SOCKETS is set, then when partially specified links (e.g.
20274778Sbrian * destination port and/or address is zero), the packet aliasing engine will
20374778Sbrian * attempt to allocate a socket for the aliasing port it chooses.  This will
20474778Sbrian * avoid interference with the host machine.  Fully specified links do not
20574778Sbrian * require this.  This bit is set after a call to PacketAliasInit(), so it is
20674778Sbrian * a default mode of operation.
20774778Sbrian */
20874778Sbrian#define	PKT_ALIAS_USE_SOCKETS		0x08
20927864Sbrian
21074778Sbrian/*-
21174778Sbrian * If PKT_ALIAS_UNREGISTERED_ONLY is set, then only packets with
21274778Sbrian * unregistered source addresses will be aliased.  Private
21374778Sbrian * addresses are those in the following ranges:
21474778Sbrian *
21574778Sbrian *		10.0.0.0     ->   10.255.255.255
21674778Sbrian *		172.16.0.0   ->   172.31.255.255
21774778Sbrian *		192.168.0.0  ->   192.168.255.255
21874778Sbrian */
21974778Sbrian#define	PKT_ALIAS_UNREGISTERED_ONLY	0x10
22027864Sbrian
22174778Sbrian/*
22274778Sbrian * If PKT_ALIAS_RESET_ON_ADDR_CHANGE is set, then the table of dynamic
22374778Sbrian * aliasing links will be reset whenever PacketAliasSetAddress() changes the
22474778Sbrian * default aliasing address.  If the default aliasing address is left
22574778Sbrian * unchanged by this function call, then the table of dynamic aliasing links
22674778Sbrian * will be left intact.  This bit is set after a call to PacketAliasInit().
22774778Sbrian */
22874778Sbrian#define	PKT_ALIAS_RESET_ON_ADDR_CHANGE	0x20
22927864Sbrian
23035314Sbrian#ifndef NO_FW_PUNCH
23174778Sbrian/*
23274778Sbrian * If PKT_ALIAS_PUNCH_FW is set, active FTP and IRC DCC connections will
23374778Sbrian * create a 'hole' in the firewall to allow the transfers to work.  The
23474778Sbrian * ipfw rule number that the hole is created with is controlled by
23574778Sbrian * PacketAliasSetFWBase().  The hole will be attached to that
23674778Sbrian * particular alias_link, so when the link goes away the hole is deleted.
23774778Sbrian */
23874778Sbrian#define	PKT_ALIAS_PUNCH_FW		0x100
23935314Sbrian#endif
24032377Seivind
24174778Sbrian/*
24274778Sbrian * If PKT_ALIAS_PROXY_ONLY is set, then NAT will be disabled and only
24374778Sbrian * transparent proxying is performed.
24474778Sbrian */
24574778Sbrian#define	PKT_ALIAS_PROXY_ONLY		0x40
24644307Sbrian
24774778Sbrian/*
24874778Sbrian * If PKT_ALIAS_REVERSE is set, the actions of PacketAliasIn() and
24974778Sbrian * PacketAliasOut() are reversed.
25074778Sbrian */
25174778Sbrian#define	PKT_ALIAS_REVERSE		0x80
25244307Sbrian
25374778Sbrian/* Function return codes. */
25474778Sbrian#define	PKT_ALIAS_ERROR			-1
25574778Sbrian#define	PKT_ALIAS_OK			1
25674778Sbrian#define	PKT_ALIAS_IGNORED		2
25774778Sbrian#define	PKT_ALIAS_UNRESOLVED_FRAGMENT	3
25874778Sbrian#define	PKT_ALIAS_FOUND_HEADER_FRAGMENT	4
25926026Sbrian
26074778Sbrian#endif /* !_ALIAS_H_ */
26174778Sbrian
26274778Sbrian/* lint -restore */
263