1f987e1bdSBrian Somers /*-
2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause
3fe267a55SPedro F. Giffuni *
4e83aaae3SBrian Somers * Copyright (c) 2001 Charles Mott <cm@linktel.net>
5f987e1bdSBrian Somers * All rights reserved.
6f987e1bdSBrian Somers *
7f987e1bdSBrian Somers * Redistribution and use in source and binary forms, with or without
8f987e1bdSBrian Somers * modification, are permitted provided that the following conditions
9f987e1bdSBrian Somers * are met:
10f987e1bdSBrian Somers * 1. Redistributions of source code must retain the above copyright
11f987e1bdSBrian Somers * notice, this list of conditions and the following disclaimer.
12f987e1bdSBrian Somers * 2. Redistributions in binary form must reproduce the above copyright
13f987e1bdSBrian Somers * notice, this list of conditions and the following disclaimer in the
14f987e1bdSBrian Somers * documentation and/or other materials provided with the distribution.
15f987e1bdSBrian Somers *
16f987e1bdSBrian Somers * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17f987e1bdSBrian Somers * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18f987e1bdSBrian Somers * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19f987e1bdSBrian Somers * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20f987e1bdSBrian Somers * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21f987e1bdSBrian Somers * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22f987e1bdSBrian Somers * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23f987e1bdSBrian Somers * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24f987e1bdSBrian Somers * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25f987e1bdSBrian Somers * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26f987e1bdSBrian Somers * SUCH DAMAGE.
27f987e1bdSBrian Somers */
28f987e1bdSBrian Somers
2971593f95SBrian Somers /*
3071593f95SBrian Somers * Alias_local.h contains the function prototypes for alias.c,
3171593f95SBrian Somers * alias_db.c, alias_util.c and alias_ftp.c, alias_irc.c (as well
3271593f95SBrian Somers * as any future add-ons). It also includes macros, globals and
3371593f95SBrian Somers * struct definitions shared by more than one alias*.c file.
3471593f95SBrian Somers *
3571593f95SBrian Somers * This include file is intended to be used only within the aliasing
3671593f95SBrian Somers * software. Outside world interfaces are defined in alias.h
3771593f95SBrian Somers *
3871593f95SBrian Somers * This software is placed into the public domain with no restrictions
3971593f95SBrian Somers * on its distribution.
4071593f95SBrian Somers *
4171593f95SBrian Somers * Initial version: August, 1996 (cjm)
4271593f95SBrian Somers *
4371593f95SBrian Somers * <updated several times by original author and Eivind Eklund>
443b160b8bSBrian Somers */
453b160b8bSBrian Somers
4671593f95SBrian Somers #ifndef _ALIAS_LOCAL_H_
4771593f95SBrian Somers #define _ALIAS_LOCAL_H_
4871593f95SBrian Somers
49935fc93aSLutz Donnerhacke #include <sys/tree.h>
50be4f3cd0SPaolo Pisati #include <sys/types.h>
51be4f3cd0SPaolo Pisati #include <sys/sysctl.h>
525e289f9eSPoul-Henning Kamp
53c8564bffSGleb Smirnoff #ifdef _KERNEL
54be4f3cd0SPaolo Pisati #include <sys/malloc.h>
55ccd57eeaSPaolo Pisati #include <sys/param.h>
56be4f3cd0SPaolo Pisati #include <sys/lock.h>
57ccd57eeaSPaolo Pisati #include <sys/mutex.h>
58ccd57eeaSPaolo Pisati
59be4f3cd0SPaolo Pisati /* XXX: LibAliasSetTarget() uses this constant. */
60c8564bffSGleb Smirnoff #define INADDR_NONE 0xffffffff
6137ce2656SPaolo Pisati
6237ce2656SPaolo Pisati #include <netinet/libalias/alias_sctp.h>
6337ce2656SPaolo Pisati #else
6437ce2656SPaolo Pisati #include "alias_sctp.h"
65c8564bffSGleb Smirnoff #endif
66c8564bffSGleb Smirnoff
675e289f9eSPoul-Henning Kamp /* Sizes of input and output link tables */
6805116753SAndrey V. Elsukov #define GET_ALIAS_PORT -1
6905116753SAndrey V. Elsukov #define GET_ALIAS_ID GET_ALIAS_PORT
7005116753SAndrey V. Elsukov
718144690aSEric van Gyzen #ifdef _KERNEL
728144690aSEric van Gyzen #define INET_NTOA_BUF(buf) (buf)
738144690aSEric van Gyzen #else
748144690aSEric van Gyzen #define INET_NTOA_BUF(buf) (buf), sizeof(buf)
758144690aSEric van Gyzen #endif
768144690aSEric van Gyzen
775e289f9eSPoul-Henning Kamp struct proxy_entry;
785e289f9eSPoul-Henning Kamp
79492d3b71SLutz Donnerhacke struct group_in {
80492d3b71SLutz Donnerhacke struct in_addr alias_addr;
81492d3b71SLutz Donnerhacke u_short alias_port;
82492d3b71SLutz Donnerhacke int link_type;
83d261e57dSLutz Donnerhacke SPLAY_ENTRY(group_in) in;
84492d3b71SLutz Donnerhacke LIST_HEAD(, alias_link) full, partial;
85492d3b71SLutz Donnerhacke };
86492d3b71SLutz Donnerhacke
875e289f9eSPoul-Henning Kamp struct libalias {
885e289f9eSPoul-Henning Kamp LIST_ENTRY(libalias) instancelist;
89effc8e57SLutz Donnerhacke /* Mode flags documented in alias.h */
90effc8e57SLutz Donnerhacke int packetAliasMode;
91effc8e57SLutz Donnerhacke /* Address written onto source field of IP packet. */
92effc8e57SLutz Donnerhacke struct in_addr aliasAddress;
93effc8e57SLutz Donnerhacke /* IP address incoming packets are sent to
94effc8e57SLutz Donnerhacke * if no aliasing link already exists */
95effc8e57SLutz Donnerhacke struct in_addr targetAddress;
96effc8e57SLutz Donnerhacke /* Lookup table of pointers to chains of link records.
97effc8e57SLutz Donnerhacke * Each link record is doubly indexed into input and
98effc8e57SLutz Donnerhacke * output lookup tables. */
99935fc93aSLutz Donnerhacke SPLAY_HEAD(splay_out, alias_link) linkSplayOut;
100d261e57dSLutz Donnerhacke SPLAY_HEAD(splay_in, group_in) linkSplayIn;
1011178dda5SLutz Donnerhacke LIST_HEAD (, alias_link) pptpList;
102294799c6SLutz Donnerhacke /* HouseKeeping */
103294799c6SLutz Donnerhacke TAILQ_HEAD (, alias_link) checkExpire;
1045e289f9eSPoul-Henning Kamp /* Link statistics */
1053fd20a79SLutz Donnerhacke unsigned int icmpLinkCount;
1063fd20a79SLutz Donnerhacke unsigned int udpLinkCount;
1073fd20a79SLutz Donnerhacke unsigned int tcpLinkCount;
1083fd20a79SLutz Donnerhacke unsigned int pptpLinkCount;
1093fd20a79SLutz Donnerhacke unsigned int protoLinkCount;
1103fd20a79SLutz Donnerhacke unsigned int fragmentIdLinkCount;
1113fd20a79SLutz Donnerhacke unsigned int fragmentPtrLinkCount;
1123fd20a79SLutz Donnerhacke unsigned int sockCount;
113be4f3cd0SPaolo Pisati /* log descriptor */
114be4f3cd0SPaolo Pisati #ifdef _KERNEL
115be4f3cd0SPaolo Pisati char *logDesc;
116be4f3cd0SPaolo Pisati #else
117be4f3cd0SPaolo Pisati FILE *logDesc;
11840106c14SGleb Smirnoff #endif
1195e289f9eSPoul-Henning Kamp
1205e289f9eSPoul-Henning Kamp #ifndef NO_FW_PUNCH
121effc8e57SLutz Donnerhacke /* File descriptor to be able to control firewall.
122effc8e57SLutz Donnerhacke * Opened by PacketAliasSetMode on first setting
123effc8e57SLutz Donnerhacke * the PKT_ALIAS_PUNCH_FW flag. */
124effc8e57SLutz Donnerhacke int fireWallFD;
125effc8e57SLutz Donnerhacke /* The first firewall entry free for our use */
126effc8e57SLutz Donnerhacke int fireWallBaseNum;
127effc8e57SLutz Donnerhacke /* How many entries can we use? */
128effc8e57SLutz Donnerhacke int fireWallNumNums;
129effc8e57SLutz Donnerhacke /* Which entry did we last use? */
130effc8e57SLutz Donnerhacke int fireWallActiveNum;
131effc8e57SLutz Donnerhacke /* bool array for entries */
132effc8e57SLutz Donnerhacke char *fireWallField;
1335e289f9eSPoul-Henning Kamp #endif
134effc8e57SLutz Donnerhacke /* TCP port used by the Skinny protocol. */
135effc8e57SLutz Donnerhacke unsigned int skinnyPort;
1365e289f9eSPoul-Henning Kamp
1375e289f9eSPoul-Henning Kamp struct proxy_entry *proxyList;
1385e289f9eSPoul-Henning Kamp
1395e289f9eSPoul-Henning Kamp struct in_addr true_addr; /* in network byte order. */
1405e289f9eSPoul-Henning Kamp u_short true_port; /* in host byte order. */
14137ce2656SPaolo Pisati
142a08cdb6cSNeel Chauhan /* Port ranges for aliasing. */
143a08cdb6cSNeel Chauhan u_short aliasPortLower;
144a08cdb6cSNeel Chauhan u_short aliasPortLength;
145a08cdb6cSNeel Chauhan
14637ce2656SPaolo Pisati /*
14737ce2656SPaolo Pisati * sctp code support
14837ce2656SPaolo Pisati */
14937ce2656SPaolo Pisati
15037ce2656SPaolo Pisati /* counts associations that have progressed to UP and not yet removed */
15137ce2656SPaolo Pisati int sctpLinkCount;
152ccd57eeaSPaolo Pisati #ifdef _KERNEL
15337ce2656SPaolo Pisati /* timing queue for keeping track of association timeouts */
15437ce2656SPaolo Pisati struct sctp_nat_timer sctpNatTimer;
15537ce2656SPaolo Pisati /* size of hash table used in this instance */
15637ce2656SPaolo Pisati u_int sctpNatTableSize;
157effc8e57SLutz Donnerhacke /* local look up table sorted by l_vtag/l_port */
15837ce2656SPaolo Pisati LIST_HEAD(sctpNatTableL, sctp_nat_assoc) *sctpTableLocal;
159effc8e57SLutz Donnerhacke /* global look up table sorted by g_vtag/g_port */
16037ce2656SPaolo Pisati LIST_HEAD(sctpNatTableG, sctp_nat_assoc) *sctpTableGlobal;
16137ce2656SPaolo Pisati
162effc8e57SLutz Donnerhacke /* avoid races in libalias: every public function has to use it. */
163ccd57eeaSPaolo Pisati struct mtx mutex;
164ccd57eeaSPaolo Pisati #endif
1655e289f9eSPoul-Henning Kamp };
1665e289f9eSPoul-Henning Kamp
16771593f95SBrian Somers /* Macros */
1687d96f4efSBrian Somers
169ccd57eeaSPaolo Pisati #ifdef _KERNEL
170ccd57eeaSPaolo Pisati #define LIBALIAS_LOCK_INIT(l) \
171ccd57eeaSPaolo Pisati mtx_init(&l->mutex, "per-instance libalias mutex", NULL, MTX_DEF)
172ccd57eeaSPaolo Pisati #define LIBALIAS_LOCK_ASSERT(l) mtx_assert(&l->mutex, MA_OWNED)
173ccd57eeaSPaolo Pisati #define LIBALIAS_LOCK(l) mtx_lock(&l->mutex)
174ccd57eeaSPaolo Pisati #define LIBALIAS_UNLOCK(l) mtx_unlock(&l->mutex)
175ccd57eeaSPaolo Pisati #define LIBALIAS_LOCK_DESTROY(l) mtx_destroy(&l->mutex)
176ccd57eeaSPaolo Pisati #else
177ccd57eeaSPaolo Pisati #define LIBALIAS_LOCK_INIT(l)
178ccd57eeaSPaolo Pisati #define LIBALIAS_LOCK_ASSERT(l)
179ccd57eeaSPaolo Pisati #define LIBALIAS_LOCK(l)
180ccd57eeaSPaolo Pisati #define LIBALIAS_UNLOCK(l)
181ccd57eeaSPaolo Pisati #define LIBALIAS_LOCK_DESTROY(l)
182ccd57eeaSPaolo Pisati #endif
183ccd57eeaSPaolo Pisati
1847d96f4efSBrian Somers /*
18571593f95SBrian Somers * The following macro is used to update an
18671593f95SBrian Somers * internet checksum. "delta" is a 32-bit
18771593f95SBrian Somers * accumulation of all the changes to the
18871593f95SBrian Somers * checksum (adding in new 16-bit words and
18971593f95SBrian Somers * subtracting out old words), and "cksum"
19071593f95SBrian Somers * is the checksum value to be updated.
1917d96f4efSBrian Somers */
19271593f95SBrian Somers #define ADJUST_CHECKSUM(acc, cksum) \
19371593f95SBrian Somers do { \
1947d96f4efSBrian Somers acc += cksum; \
19571593f95SBrian Somers if (acc < 0) { \
1967d96f4efSBrian Somers acc = -acc; \
1977d96f4efSBrian Somers acc = (acc >> 16) + (acc & 0xffff); \
1987d96f4efSBrian Somers acc += acc >> 16; \
1997d96f4efSBrian Somers cksum = (u_short) ~acc; \
20071593f95SBrian Somers } else { \
2017d96f4efSBrian Somers acc = (acc >> 16) + (acc & 0xffff); \
2027d96f4efSBrian Somers acc += acc >> 16; \
2037d96f4efSBrian Somers cksum = (u_short) acc; \
2047d96f4efSBrian Somers } \
20571593f95SBrian Somers } while (0)
2063b160b8bSBrian Somers
20771593f95SBrian Somers /* Prototypes */
2083b160b8bSBrian Somers
209ef828d39SLutz Donnerhacke /* System time in seconds for current packet */
210ef828d39SLutz Donnerhacke extern int LibAliasTime;
211ef828d39SLutz Donnerhacke
21259dde15eSGleb Smirnoff /*
21337ce2656SPaolo Pisati * SctpFunction prototypes
21437ce2656SPaolo Pisati *
21537ce2656SPaolo Pisati */
21637ce2656SPaolo Pisati void AliasSctpInit(struct libalias *la);
21737ce2656SPaolo Pisati void AliasSctpTerm(struct libalias *la);
21837ce2656SPaolo Pisati int SctpAlias(struct libalias *la, struct ip *ip, int direction);
21937ce2656SPaolo Pisati
22037ce2656SPaolo Pisati /*
22159dde15eSGleb Smirnoff * We do not calculate TCP checksums when libalias is a kernel
22259dde15eSGleb Smirnoff * module, since it has no idea about checksum offloading.
22359dde15eSGleb Smirnoff * If TCP data has changed, then we just set checksum to zero,
22459dde15eSGleb Smirnoff * and caller must recalculate it himself.
22559dde15eSGleb Smirnoff * In case if libalias will edit UDP data, the same approach
22659dde15eSGleb Smirnoff * should be used.
22759dde15eSGleb Smirnoff */
22859dde15eSGleb Smirnoff #ifndef _KERNEL
22971593f95SBrian Somers u_short IpChecksum(struct ip *_pip);
23071593f95SBrian Somers u_short TcpChecksum(struct ip *_pip);
23159dde15eSGleb Smirnoff #endif
232f0f93429SDag-Erling Smørgrav void
2332871c501SDag-Erling Smørgrav DifferentialChecksum(u_short * _cksum, void * _new, void * _old, int _n);
2343b160b8bSBrian Somers
2353b160b8bSBrian Somers /* Internal data access */
2363b160b8bSBrian Somers struct alias_link *
23705116753SAndrey V. Elsukov AddLink(struct libalias *la, struct in_addr src_addr, struct in_addr dst_addr,
23805116753SAndrey V. Elsukov struct in_addr alias_addr, u_short src_port, u_short dst_port,
23905116753SAndrey V. Elsukov int alias_param, int link_type);
24005116753SAndrey V. Elsukov struct alias_link *
2415e289f9eSPoul-Henning Kamp FindIcmpIn(struct libalias *la, struct in_addr _dst_addr, struct in_addr _alias_addr,
24271593f95SBrian Somers u_short _id_alias, int _create);
2433b160b8bSBrian Somers struct alias_link *
2445e289f9eSPoul-Henning Kamp FindIcmpOut(struct libalias *la, struct in_addr _src_addr, struct in_addr _dst_addr,
24571593f95SBrian Somers u_short _id, int _create);
2463b160b8bSBrian Somers struct alias_link *
2475e289f9eSPoul-Henning Kamp FindFragmentIn1(struct libalias *la, struct in_addr _dst_addr, struct in_addr _alias_addr,
24871593f95SBrian Somers u_short _ip_id);
2493b160b8bSBrian Somers struct alias_link *
2505e289f9eSPoul-Henning Kamp FindFragmentIn2(struct libalias *la, struct in_addr _dst_addr, struct in_addr _alias_addr,
25171593f95SBrian Somers u_short _ip_id);
2523b160b8bSBrian Somers struct alias_link *
2535e289f9eSPoul-Henning Kamp AddFragmentPtrLink(struct libalias *la, struct in_addr _dst_addr, u_short _ip_id);
2543b160b8bSBrian Somers struct alias_link *
2555e289f9eSPoul-Henning Kamp FindFragmentPtr(struct libalias *la, struct in_addr _dst_addr, u_short _ip_id);
2563b160b8bSBrian Somers struct alias_link *
2575e289f9eSPoul-Henning Kamp FindProtoIn(struct libalias *la, struct in_addr _dst_addr, struct in_addr _alias_addr,
25871593f95SBrian Somers u_char _proto);
259483d2f22SRuslan Ermilov struct alias_link *
2605e289f9eSPoul-Henning Kamp FindProtoOut(struct libalias *la, struct in_addr _src_addr, struct in_addr _dst_addr,
26171593f95SBrian Somers u_char _proto);
262483d2f22SRuslan Ermilov struct alias_link *
2635e289f9eSPoul-Henning Kamp FindUdpTcpIn(struct libalias *la, struct in_addr _dst_addr, struct in_addr _alias_addr,
26471593f95SBrian Somers u_short _dst_port, u_short _alias_port, u_char _proto, int _create);
2653b160b8bSBrian Somers struct alias_link *
2665e289f9eSPoul-Henning Kamp FindUdpTcpOut(struct libalias *la, struct in_addr _src_addr, struct in_addr _dst_addr,
26771593f95SBrian Somers u_short _src_port, u_short _dst_port, u_char _proto, int _create);
26855a39fc5SRuslan Ermilov struct alias_link *
2695e289f9eSPoul-Henning Kamp AddPptp(struct libalias *la, struct in_addr _src_addr, struct in_addr _dst_addr,
27071593f95SBrian Somers struct in_addr _alias_addr, u_int16_t _src_call_id);
27155a39fc5SRuslan Ermilov struct alias_link *
2725e289f9eSPoul-Henning Kamp FindPptpOutByCallId(struct libalias *la, struct in_addr _src_addr,
27371593f95SBrian Somers struct in_addr _dst_addr, u_int16_t _src_call_id);
27403453c5eSRuslan Ermilov struct alias_link *
2755e289f9eSPoul-Henning Kamp FindPptpInByCallId(struct libalias *la, struct in_addr _dst_addr,
27671593f95SBrian Somers struct in_addr _alias_addr, u_int16_t _dst_call_id);
27703453c5eSRuslan Ermilov struct alias_link *
2785e289f9eSPoul-Henning Kamp FindPptpOutByPeerCallId(struct libalias *la, struct in_addr _src_addr,
27971593f95SBrian Somers struct in_addr _dst_addr, u_int16_t _dst_call_id);
28003453c5eSRuslan Ermilov struct alias_link *
2815e289f9eSPoul-Henning Kamp FindPptpInByPeerCallId(struct libalias *la, struct in_addr _dst_addr,
28271593f95SBrian Somers struct in_addr _alias_addr, u_int16_t _alias_call_id);
283642e43b3SArchie Cobbs struct alias_link *
2845e289f9eSPoul-Henning Kamp FindRtspOut(struct libalias *la, struct in_addr _src_addr, struct in_addr _dst_addr,
28571593f95SBrian Somers u_short _src_port, u_short _alias_port, u_char _proto);
2863b160b8bSBrian Somers struct in_addr
2875e289f9eSPoul-Henning Kamp FindOriginalAddress(struct libalias *la, struct in_addr _alias_addr);
2883b160b8bSBrian Somers struct in_addr
2895e289f9eSPoul-Henning Kamp FindAliasAddress(struct libalias *la, struct in_addr _original_addr);
29037ce2656SPaolo Pisati struct in_addr
29137ce2656SPaolo Pisati FindSctpRedirectAddress(struct libalias *la, struct sctp_nat_msg *sm);
2923b160b8bSBrian Somers
2933b160b8bSBrian Somers /* External data access/modification */
294effc8e57SLutz Donnerhacke int FindNewPortGroup(struct libalias *la, struct in_addr _dst_addr,
295effc8e57SLutz Donnerhacke struct in_addr _alias_addr, u_short _src_port,
296effc8e57SLutz Donnerhacke u_short _dst_port, u_short _port_count, u_char _proto,
297effc8e57SLutz Donnerhacke u_char _align);
298ed01a582SDag-Erling Smørgrav void GetFragmentAddr(struct alias_link *_lnk, struct in_addr *_src_addr);
299ed01a582SDag-Erling Smørgrav void SetFragmentAddr(struct alias_link *_lnk, struct in_addr _src_addr);
300bc596e56SAlex Richardson void GetFragmentPtr(struct alias_link *_lnk, void **_fptr);
301bc596e56SAlex Richardson void SetFragmentPtr(struct alias_link *_lnk, void *fptr);
302ed01a582SDag-Erling Smørgrav void SetStateIn(struct alias_link *_lnk, int _state);
303ed01a582SDag-Erling Smørgrav void SetStateOut(struct alias_link *_lnk, int _state);
304ed01a582SDag-Erling Smørgrav int GetStateIn (struct alias_link *_lnk);
305ed01a582SDag-Erling Smørgrav int GetStateOut(struct alias_link *_lnk);
306effc8e57SLutz Donnerhacke struct in_addr GetOriginalAddress(struct alias_link *_lnk);
307effc8e57SLutz Donnerhacke struct in_addr GetDestAddress(struct alias_link *_lnk);
308effc8e57SLutz Donnerhacke struct in_addr GetAliasAddress(struct alias_link *_lnk);
309effc8e57SLutz Donnerhacke struct in_addr GetDefaultAliasAddress(struct libalias *la);
3105e289f9eSPoul-Henning Kamp void SetDefaultAliasAddress(struct libalias *la, struct in_addr _alias_addr);
311ed01a582SDag-Erling Smørgrav u_short GetOriginalPort(struct alias_link *_lnk);
312ed01a582SDag-Erling Smørgrav u_short GetAliasPort(struct alias_link *_lnk);
313effc8e57SLutz Donnerhacke struct in_addr GetProxyAddress(struct alias_link *_lnk);
314ed01a582SDag-Erling Smørgrav void SetProxyAddress(struct alias_link *_lnk, struct in_addr _addr);
315ed01a582SDag-Erling Smørgrav u_short GetProxyPort(struct alias_link *_lnk);
316ed01a582SDag-Erling Smørgrav void SetProxyPort(struct alias_link *_lnk, u_short _port);
317ed01a582SDag-Erling Smørgrav void SetAckModified(struct alias_link *_lnk);
318ed01a582SDag-Erling Smørgrav int GetAckModified(struct alias_link *_lnk);
3194741f3a1SPaolo Pisati int GetDeltaAckIn(u_long, struct alias_link *_lnk);
3204741f3a1SPaolo Pisati int GetDeltaSeqOut(u_long, struct alias_link *lnk);
3214741f3a1SPaolo Pisati void AddSeq(struct alias_link *lnk, int delta, u_int ip_hl,
3224741f3a1SPaolo Pisati u_short ip_len, u_long th_seq, u_int th_off);
323ed01a582SDag-Erling Smørgrav void SetExpire (struct alias_link *_lnk, int _expire);
324ed01a582SDag-Erling Smørgrav void SetProtocolFlags(struct alias_link *_lnk, int _pflags);
325ed01a582SDag-Erling Smørgrav int GetProtocolFlags(struct alias_link *_lnk);
326ed01a582SDag-Erling Smørgrav void SetDestCallId(struct alias_link *_lnk, u_int16_t _cid);
327f0f93429SDag-Erling Smørgrav
328b5ce85feSBrian Somers #ifndef NO_FW_PUNCH
329ed01a582SDag-Erling Smørgrav void PunchFWHole(struct alias_link *_lnk);
330f0f93429SDag-Erling Smørgrav
331b5ce85feSBrian Somers #endif
3328ddc51bcSEivind Eklund
3333b160b8bSBrian Somers /* Housekeeping function */
3345e289f9eSPoul-Henning Kamp void HouseKeeping(struct libalias *);
3353b160b8bSBrian Somers
3367d96f4efSBrian Somers /* Transparent proxy routines */
337f0f93429SDag-Erling Smørgrav int
3384741f3a1SPaolo Pisati ProxyCheck(struct libalias *la, struct in_addr *proxy_server_addr,
3394741f3a1SPaolo Pisati u_short * proxy_server_port, struct in_addr src_addr,
3404741f3a1SPaolo Pisati struct in_addr dst_addr, u_short dst_port, u_char ip_p);
341f0f93429SDag-Erling Smørgrav void
342ed01a582SDag-Erling Smørgrav ProxyModify(struct libalias *la, struct alias_link *_lnk, struct ip *_pip,
34371593f95SBrian Somers int _maxpacketsize, int _proxy_type);
3443efa11bbSBrian Somers
345effc8e57SLutz Donnerhacke /* Tcp specific routines */
346effc8e57SLutz Donnerhacke /* lint -save -library Suppress flexelint warnings */
347effc8e57SLutz Donnerhacke
3488ddc51bcSEivind Eklund enum alias_tcp_state {
3498ddc51bcSEivind Eklund ALIAS_TCP_STATE_NOT_CONNECTED,
3508ddc51bcSEivind Eklund ALIAS_TCP_STATE_CONNECTED,
3518ddc51bcSEivind Eklund ALIAS_TCP_STATE_DISCONNECTED
3528ddc51bcSEivind Eklund };
35371593f95SBrian Somers
3549fa0fd26SDag-Erling Smørgrav #if defined(_NETINET_IP_H_)
3559fa0fd26SDag-Erling Smørgrav static __inline void *
ip_next(struct ip * iphdr)3569fa0fd26SDag-Erling Smørgrav ip_next(struct ip *iphdr)
3579fa0fd26SDag-Erling Smørgrav {
3589fa0fd26SDag-Erling Smørgrav char *p = (char *)iphdr;
3599fa0fd26SDag-Erling Smørgrav return (&p[iphdr->ip_hl * 4]);
3609fa0fd26SDag-Erling Smørgrav }
3619fa0fd26SDag-Erling Smørgrav #endif
3629fa0fd26SDag-Erling Smørgrav
3639fa0fd26SDag-Erling Smørgrav #if defined(_NETINET_TCP_H_)
3649fa0fd26SDag-Erling Smørgrav static __inline void *
tcp_next(struct tcphdr * tcphdr)3659fa0fd26SDag-Erling Smørgrav tcp_next(struct tcphdr *tcphdr)
3669fa0fd26SDag-Erling Smørgrav {
3679fa0fd26SDag-Erling Smørgrav char *p = (char *)tcphdr;
3689fa0fd26SDag-Erling Smørgrav return (&p[tcphdr->th_off * 4]);
3699fa0fd26SDag-Erling Smørgrav }
3709fa0fd26SDag-Erling Smørgrav #endif
3719fa0fd26SDag-Erling Smørgrav
3729fa0fd26SDag-Erling Smørgrav #if defined(_NETINET_UDP_H_)
3739fa0fd26SDag-Erling Smørgrav static __inline void *
udp_next(struct udphdr * udphdr)3749fa0fd26SDag-Erling Smørgrav udp_next(struct udphdr *udphdr)
3759fa0fd26SDag-Erling Smørgrav {
3769fa0fd26SDag-Erling Smørgrav return ((void *)(udphdr + 1));
3779fa0fd26SDag-Erling Smørgrav }
3789fa0fd26SDag-Erling Smørgrav #endif
3799fa0fd26SDag-Erling Smørgrav
38071593f95SBrian Somers #endif /* !_ALIAS_LOCAL_H_ */
381