Deleted Added
full compact
alias_db.c (67316) alias_db.c (67966)
1/* -*- mode: c; tab-width: 8; c-basic-indent: 4; -*-
2 Alias_db.c encapsulates all data structures used for storing
3 packet aliasing data. Other parts of the aliasing software
4 access data through functions provided in this file.
5
6 Data storage is based on the notion of a "link", which is
7 established for ICMP echo/reply packets, UDP datagrams and
8 TCP stream connections. A link stores the original source

--- 101 unchanged lines hidden (view full) ---

110 link but not actually add one.
111
112 Added FindRtspOut, which is closely derived from FindUdpTcpOut,
113 except that the alias port (from FindNewPortGroup) is provided
114 as input.
115
116 See HISTORY file for additional revisions.
117
1/* -*- mode: c; tab-width: 8; c-basic-indent: 4; -*-
2 Alias_db.c encapsulates all data structures used for storing
3 packet aliasing data. Other parts of the aliasing software
4 access data through functions provided in this file.
5
6 Data storage is based on the notion of a "link", which is
7 established for ICMP echo/reply packets, UDP datagrams and
8 TCP stream connections. A link stores the original source

--- 101 unchanged lines hidden (view full) ---

110 link but not actually add one.
111
112 Added FindRtspOut, which is closely derived from FindUdpTcpOut,
113 except that the alias port (from FindNewPortGroup) is provided
114 as input.
115
116 See HISTORY file for additional revisions.
117
118 $FreeBSD: head/sys/netinet/libalias/alias_db.c 67316 2000-10-19 10:44:44Z ru $
118 $FreeBSD: head/sys/netinet/libalias/alias_db.c 67966 2000-10-30 12:39:41Z ru $
119*/
120
121
122/* System include files */
123#include <errno.h>
124#include <stdlib.h>
125#include <stdio.h>
126#include <unistd.h>

--- 26 unchanged lines hidden (view full) ---

153
154/* Parameters used for cleanup of expired links */
155#define ALIAS_CLEANUP_INTERVAL_SECS 60
156#define ALIAS_CLEANUP_MAX_SPOKES 30
157
158/* Timeouts (in seconds) for different link types */
159#define ICMP_EXPIRE_TIME 60
160#define UDP_EXPIRE_TIME 60
119*/
120
121
122/* System include files */
123#include <errno.h>
124#include <stdlib.h>
125#include <stdio.h>
126#include <unistd.h>

--- 26 unchanged lines hidden (view full) ---

153
154/* Parameters used for cleanup of expired links */
155#define ALIAS_CLEANUP_INTERVAL_SECS 60
156#define ALIAS_CLEANUP_MAX_SPOKES 30
157
158/* Timeouts (in seconds) for different link types */
159#define ICMP_EXPIRE_TIME 60
160#define UDP_EXPIRE_TIME 60
161#define PPTP_EXPIRE_TIME 60
162#define PROTO_EXPIRE_TIME 60
163#define FRAGMENT_ID_EXPIRE_TIME 10
164#define FRAGMENT_PTR_EXPIRE_TIME 30
165
166/* TCP link expire time for different cases */
167/* When the link has been used and closed - minimal grace time to
168 allow ACKs and potential re-connect in FTP (XXX - is this allowed?) */
169#ifndef TCP_EXPIRE_DEAD

--- 247 unchanged lines hidden (view full) ---

417static u_int
418StartPointIn(struct in_addr alias_addr,
419 u_short alias_port,
420 int link_type)
421{
422 u_int n;
423
424 n = alias_addr.s_addr;
161#define PROTO_EXPIRE_TIME 60
162#define FRAGMENT_ID_EXPIRE_TIME 10
163#define FRAGMENT_PTR_EXPIRE_TIME 30
164
165/* TCP link expire time for different cases */
166/* When the link has been used and closed - minimal grace time to
167 allow ACKs and potential re-connect in FTP (XXX - is this allowed?) */
168#ifndef TCP_EXPIRE_DEAD

--- 247 unchanged lines hidden (view full) ---

416static u_int
417StartPointIn(struct in_addr alias_addr,
418 u_short alias_port,
419 int link_type)
420{
421 u_int n;
422
423 n = alias_addr.s_addr;
425 n += alias_port;
424 if (link_type != LINK_PPTP)
425 n += alias_port;
426 n += link_type;
427 return(n % LINK_TABLE_IN_SIZE);
428}
429
430
431static u_int
432StartPointOut(struct in_addr src_addr, struct in_addr dst_addr,
433 u_short src_port, u_short dst_port, int link_type)
434{
435 u_int n;
436
437 n = src_addr.s_addr;
438 n += dst_addr.s_addr;
426 n += link_type;
427 return(n % LINK_TABLE_IN_SIZE);
428}
429
430
431static u_int
432StartPointOut(struct in_addr src_addr, struct in_addr dst_addr,
433 u_short src_port, u_short dst_port, int link_type)
434{
435 u_int n;
436
437 n = src_addr.s_addr;
438 n += dst_addr.s_addr;
439 n += src_port;
440 n += dst_port;
439 if (link_type != LINK_PPTP) {
440 n += src_port;
441 n += dst_port;
442 }
441 n += link_type;
442
443 return(n % LINK_TABLE_OUT_SIZE);
444}
445
446
447static int
448SeqDiff(u_long x, u_long y)

--- 550 unchanged lines hidden (view full) ---

999 break;
1000 case LINK_UDP:
1001 link->expire_time = UDP_EXPIRE_TIME;
1002 break;
1003 case LINK_TCP:
1004 link->expire_time = TCP_EXPIRE_INITIAL;
1005 break;
1006 case LINK_PPTP:
443 n += link_type;
444
445 return(n % LINK_TABLE_OUT_SIZE);
446}
447
448
449static int
450SeqDiff(u_long x, u_long y)

--- 550 unchanged lines hidden (view full) ---

1001 break;
1002 case LINK_UDP:
1003 link->expire_time = UDP_EXPIRE_TIME;
1004 break;
1005 case LINK_TCP:
1006 link->expire_time = TCP_EXPIRE_INITIAL;
1007 break;
1008 case LINK_PPTP:
1007 link->expire_time = PPTP_EXPIRE_TIME;
1009 link->flags |= LINK_PERMANENT; /* no timeout. */
1008 break;
1009 case LINK_FRAGMENT_ID:
1010 link->expire_time = FRAGMENT_ID_EXPIRE_TIME;
1011 break;
1012 case LINK_FRAGMENT_PTR:
1013 link->expire_time = FRAGMENT_PTR_EXPIRE_TIME;
1014 break;
1015 case LINK_ADDR:

--- 368 unchanged lines hidden (view full) ---

1384
1385-- "external" means outside alias_db.c, but within alias*.c --
1386
1387 FindIcmpIn(), FindIcmpOut()
1388 FindFragmentIn1(), FindFragmentIn2()
1389 AddFragmentPtrLink(), FindFragmentPtr()
1390 FindProtoIn(), FindProtoOut()
1391 FindUdpTcpIn(), FindUdpTcpOut()
1010 break;
1011 case LINK_FRAGMENT_ID:
1012 link->expire_time = FRAGMENT_ID_EXPIRE_TIME;
1013 break;
1014 case LINK_FRAGMENT_PTR:
1015 link->expire_time = FRAGMENT_PTR_EXPIRE_TIME;
1016 break;
1017 case LINK_ADDR:

--- 368 unchanged lines hidden (view full) ---

1386
1387-- "external" means outside alias_db.c, but within alias*.c --
1388
1389 FindIcmpIn(), FindIcmpOut()
1390 FindFragmentIn1(), FindFragmentIn2()
1391 AddFragmentPtrLink(), FindFragmentPtr()
1392 FindProtoIn(), FindProtoOut()
1393 FindUdpTcpIn(), FindUdpTcpOut()
1392 FindPptpIn(), FindPptpOut()
1394 AddPptp(), FindPptpOutByCallId(), FindPptpInByCallId(),
1395 FindPptpOutByPeerCallId(), FindPptpInByPeerCallId()
1393 FindOriginalAddress(), FindAliasAddress()
1394
1395(prototypes in alias_local.h)
1396*/
1397
1398
1399struct alias_link *
1400FindIcmpIn(struct in_addr dst_addr,

--- 224 unchanged lines hidden (view full) ---

1625 link_type);
1626 }
1627
1628 return(link);
1629}
1630
1631
1632struct alias_link *
1396 FindOriginalAddress(), FindAliasAddress()
1397
1398(prototypes in alias_local.h)
1399*/
1400
1401
1402struct alias_link *
1403FindIcmpIn(struct in_addr dst_addr,

--- 224 unchanged lines hidden (view full) ---

1628 link_type);
1629 }
1630
1631 return(link);
1632}
1633
1634
1635struct alias_link *
1633FindPptpIn(struct in_addr dst_addr,
1634 struct in_addr alias_addr,
1635 u_short call_id)
1636{
1637 struct alias_link *link;
1638
1639 link = FindLinkIn(dst_addr, alias_addr,
1640 NO_DEST_PORT, call_id,
1641 LINK_PPTP, 1);
1642
1643 if (link == NULL && !(packetAliasMode & PKT_ALIAS_DENY_INCOMING))
1644 {
1645 struct in_addr target_addr;
1646
1647 target_addr = FindOriginalAddress(alias_addr);
1648 link = AddLink(target_addr, dst_addr, alias_addr,
1649 call_id, NO_DEST_PORT, call_id,
1650 LINK_PPTP);
1651 }
1652
1653 return(link);
1654}
1655
1656
1657struct alias_link *
1658FindPptpOut(struct in_addr src_addr,
1659 struct in_addr dst_addr,
1660 u_short call_id)
1661{
1662 struct alias_link *link;
1663
1664 link = FindLinkOut(src_addr, dst_addr,
1665 call_id, NO_DEST_PORT,
1666 LINK_PPTP, 1);
1667
1668 if (link == NULL)
1669 {
1670 struct in_addr alias_addr;
1671
1672 alias_addr = FindAliasAddress(src_addr);
1673 link = AddLink(src_addr, dst_addr, alias_addr,
1674 call_id, NO_DEST_PORT, GET_ALIAS_PORT,
1675 LINK_PPTP);
1676 }
1677
1678 return(link);
1679}
1680
1681
1682struct alias_link *
1683QueryUdpTcpIn(struct in_addr dst_addr,
1684 struct in_addr alias_addr,
1685 u_short dst_port,
1686 u_short alias_port,
1687 u_char proto)
1688{
1689 int link_type;
1690 struct alias_link *link;

--- 44 unchanged lines hidden (view full) ---

1735
1736 link = FindLinkOut(src_addr, dst_addr,
1737 src_port, dst_port,
1738 link_type, 0);
1739
1740 return(link);
1741}
1742
1636QueryUdpTcpIn(struct in_addr dst_addr,
1637 struct in_addr alias_addr,
1638 u_short dst_port,
1639 u_short alias_port,
1640 u_char proto)
1641{
1642 int link_type;
1643 struct alias_link *link;

--- 44 unchanged lines hidden (view full) ---

1688
1689 link = FindLinkOut(src_addr, dst_addr,
1690 src_port, dst_port,
1691 link_type, 0);
1692
1693 return(link);
1694}
1695
1696struct alias_link *
1697AddPptp(struct in_addr src_addr,
1698 struct in_addr dst_addr,
1699 struct in_addr alias_addr,
1700 u_int16_t src_call_id)
1701{
1702 struct alias_link *link;
1743
1703
1704 link = AddLink(src_addr, dst_addr, alias_addr,
1705 src_call_id, 0, GET_ALIAS_PORT,
1706 LINK_PPTP);
1707
1708 return (link);
1709}
1710
1711
1712struct alias_link *
1713FindPptpOutByCallId(struct in_addr src_addr,
1714 struct in_addr dst_addr,
1715 u_int16_t src_call_id)
1716{
1717 u_int i;
1718 struct alias_link *link;
1719
1720 i = StartPointOut(src_addr, dst_addr, 0, 0, LINK_PPTP);
1721 LIST_FOREACH(link, &linkTableOut[i], list_out)
1722 if (link->link_type == LINK_PPTP &&
1723 link->src_addr.s_addr == src_addr.s_addr &&
1724 link->dst_addr.s_addr == dst_addr.s_addr &&
1725 link->src_port == src_call_id)
1726 break;
1727
1728 return (link);
1729}
1730
1731
1732struct alias_link *
1733FindPptpOutByPeerCallId(struct in_addr src_addr,
1734 struct in_addr dst_addr,
1735 u_int16_t dst_call_id)
1736{
1737 u_int i;
1738 struct alias_link *link;
1739
1740 i = StartPointOut(src_addr, dst_addr, 0, 0, LINK_PPTP);
1741 LIST_FOREACH(link, &linkTableOut[i], list_out)
1742 if (link->link_type == LINK_PPTP &&
1743 link->src_addr.s_addr == src_addr.s_addr &&
1744 link->dst_addr.s_addr == dst_addr.s_addr &&
1745 link->dst_port == dst_call_id)
1746 break;
1747
1748 return (link);
1749}
1750
1751
1752struct alias_link *
1753FindPptpInByCallId(struct in_addr dst_addr,
1754 struct in_addr alias_addr,
1755 u_int16_t dst_call_id)
1756{
1757 u_int i;
1758 struct alias_link *link;
1759
1760 i = StartPointIn(alias_addr, 0, LINK_PPTP);
1761 LIST_FOREACH(link, &linkTableIn[i], list_in)
1762 if (link->link_type == LINK_PPTP &&
1763 link->dst_addr.s_addr == dst_addr.s_addr &&
1764 link->alias_addr.s_addr == alias_addr.s_addr &&
1765 link->dst_port == dst_call_id)
1766 break;
1767
1768 return (link);
1769}
1770
1771
1772struct alias_link *
1773FindPptpInByPeerCallId(struct in_addr dst_addr,
1774 struct in_addr alias_addr,
1775 u_int16_t alias_call_id)
1776{
1777 struct alias_link *link;
1778
1779 link = FindLinkIn(dst_addr, alias_addr,
1780 0/* any */, alias_call_id,
1781 LINK_PPTP, 0);
1782
1783
1784 return (link);
1785}
1786
1787
1744struct alias_link *
1745FindRtspOut(struct in_addr src_addr,
1746 struct in_addr dst_addr,
1747 u_short src_port,
1748 u_short alias_port,
1749 u_char proto)
1750{
1751 int link_type;

--- 88 unchanged lines hidden (view full) ---

1840 SetFragmentData(), GetFragmentData()
1841 SetFragmentPtr(), GetFragmentPtr()
1842 SetStateIn(), SetStateOut(), GetStateIn(), GetStateOut()
1843 GetOriginalAddress(), GetDestAddress(), GetAliasAddress()
1844 GetOriginalPort(), GetAliasPort()
1845 SetAckModified(), GetAckModified()
1846 GetDeltaAckIn(), GetDeltaSeqOut(), AddSeq()
1847 SetLastLineCrlfTermed(), GetLastLineCrlfTermed()
1788struct alias_link *
1789FindRtspOut(struct in_addr src_addr,
1790 struct in_addr dst_addr,
1791 u_short src_port,
1792 u_short alias_port,
1793 u_char proto)
1794{
1795 int link_type;

--- 88 unchanged lines hidden (view full) ---

1884 SetFragmentData(), GetFragmentData()
1885 SetFragmentPtr(), GetFragmentPtr()
1886 SetStateIn(), SetStateOut(), GetStateIn(), GetStateOut()
1887 GetOriginalAddress(), GetDestAddress(), GetAliasAddress()
1888 GetOriginalPort(), GetAliasPort()
1889 SetAckModified(), GetAckModified()
1890 GetDeltaAckIn(), GetDeltaSeqOut(), AddSeq()
1891 SetLastLineCrlfTermed(), GetLastLineCrlfTermed()
1892 SetDestCallId()
1848*/
1849
1850
1851void
1852SetFragmentAddr(struct alias_link *link, struct in_addr src_addr)
1853{
1854 link->data.frag_addr = src_addr;
1855}

--- 366 unchanged lines hidden (view full) ---

2222
2223int
2224GetLastLineCrlfTermed(struct alias_link *link)
2225{
2226
2227 return (link->flags & LINK_LAST_LINE_CRLF_TERMED);
2228}
2229
1893*/
1894
1895
1896void
1897SetFragmentAddr(struct alias_link *link, struct in_addr src_addr)
1898{
1899 link->data.frag_addr = src_addr;
1900}

--- 366 unchanged lines hidden (view full) ---

2267
2268int
2269GetLastLineCrlfTermed(struct alias_link *link)
2270{
2271
2272 return (link->flags & LINK_LAST_LINE_CRLF_TERMED);
2273}
2274
2275void
2276SetDestCallId(struct alias_link *link, u_int16_t cid)
2277{
2230
2278
2279 deleteAllLinks = 1;
2280 link = ReLink(link, link->src_addr, link->dst_addr, link->alias_addr,
2281 link->src_port, cid, link->alias_port, link->link_type);
2282 deleteAllLinks = 0;
2283}
2284
2285
2231/* Miscellaneous Functions
2232
2233 HouseKeeping()
2234 InitPacketAliasLog()
2235 UninitPacketAliasLog()
2236*/
2237
2238/*

--- 552 unchanged lines hidden ---
2286/* Miscellaneous Functions
2287
2288 HouseKeeping()
2289 InitPacketAliasLog()
2290 UninitPacketAliasLog()
2291*/
2292
2293/*

--- 552 unchanged lines hidden ---