Deleted Added
full compact
alias_db.c (65280) alias_db.c (67316)
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 65280 2000-08-31 12:47:57Z ru $
118 $FreeBSD: head/sys/netinet/libalias/alias_db.c 67316 2000-10-19 10:44:44Z ru $
119*/
120
121
122/* System include files */
123#include <errno.h>
124#include <stdlib.h>
125#include <stdio.h>
126#include <unistd.h>

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

926 case LINK_ICMP:
927 icmpLinkCount--;
928 break;
929 case LINK_UDP:
930 udpLinkCount--;
931 break;
932 case LINK_TCP:
933 tcpLinkCount--;
119*/
120
121
122/* System include files */
123#include <errno.h>
124#include <stdlib.h>
125#include <stdio.h>
126#include <unistd.h>

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

926 case LINK_ICMP:
927 icmpLinkCount--;
928 break;
929 case LINK_UDP:
930 udpLinkCount--;
931 break;
932 case LINK_TCP:
933 tcpLinkCount--;
934 if (link->data.tcp != NULL)
935 free(link->data.tcp);
934 free(link->data.tcp);
936 break;
937 case LINK_PPTP:
938 pptpLinkCount--;
939 break;
940 case LINK_FRAGMENT_ID:
941 fragmentIdLinkCount--;
942 break;
943 case LINK_FRAGMENT_PTR:

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

1028
1029 /* Determine alias port */
1030 if (GetNewPort(link, alias_port_param) != 0)
1031 {
1032 free(link);
1033 return(NULL);
1034 }
1035
935 break;
936 case LINK_PPTP:
937 pptpLinkCount--;
938 break;
939 case LINK_FRAGMENT_ID:
940 fragmentIdLinkCount--;
941 break;
942 case LINK_FRAGMENT_PTR:

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

1027
1028 /* Determine alias port */
1029 if (GetNewPort(link, alias_port_param) != 0)
1030 {
1031 free(link);
1032 return(NULL);
1033 }
1034
1036 /* Set up pointers for output lookup table */
1037 start_point = StartPointOut(src_addr, dst_addr,
1038 src_port, dst_port, link_type);
1039 LIST_INSERT_HEAD(&linkTableOut[start_point], link, list_out);
1040
1041 /* Set up pointers for input lookup table */
1042 start_point = StartPointIn(alias_addr, link->alias_port, link_type);
1043 LIST_INSERT_HEAD(&linkTableIn[start_point], link, list_in);
1044
1045 /* Link-type dependent initialization */
1046 switch(link_type)
1047 {
1048 struct tcp_dat *aux_tcp;
1049
1050 case LINK_ICMP:
1051 icmpLinkCount++;
1052 break;
1053 case LINK_UDP:
1054 udpLinkCount++;
1055 break;
1056 case LINK_TCP:
1057 aux_tcp = malloc(sizeof(struct tcp_dat));
1035 /* Link-type dependent initialization */
1036 switch(link_type)
1037 {
1038 struct tcp_dat *aux_tcp;
1039
1040 case LINK_ICMP:
1041 icmpLinkCount++;
1042 break;
1043 case LINK_UDP:
1044 udpLinkCount++;
1045 break;
1046 case LINK_TCP:
1047 aux_tcp = malloc(sizeof(struct tcp_dat));
1058 link->data.tcp = aux_tcp;
1059 if (aux_tcp != NULL)
1060 {
1061 int i;
1062
1063 tcpLinkCount++;
1064 aux_tcp->state.in = ALIAS_TCP_STATE_NOT_CONNECTED;
1065 aux_tcp->state.out = ALIAS_TCP_STATE_NOT_CONNECTED;
1066 aux_tcp->state.index = 0;
1067 aux_tcp->state.ack_modified = 0;
1068 for (i=0; i<N_LINK_TCP_DATA; i++)
1069 aux_tcp->ack[i].active = 0;
1070 aux_tcp->fwhole = -1;
1048 if (aux_tcp != NULL)
1049 {
1050 int i;
1051
1052 tcpLinkCount++;
1053 aux_tcp->state.in = ALIAS_TCP_STATE_NOT_CONNECTED;
1054 aux_tcp->state.out = ALIAS_TCP_STATE_NOT_CONNECTED;
1055 aux_tcp->state.index = 0;
1056 aux_tcp->state.ack_modified = 0;
1057 for (i=0; i<N_LINK_TCP_DATA; i++)
1058 aux_tcp->ack[i].active = 0;
1059 aux_tcp->fwhole = -1;
1060 link->data.tcp = aux_tcp;
1071 }
1072 else
1073 {
1074#ifdef DEBUG
1075 fprintf(stderr, "PacketAlias/AddLink: ");
1076 fprintf(stderr, " cannot allocate auxiliary TCP data\n");
1077#endif
1061 }
1062 else
1063 {
1064#ifdef DEBUG
1065 fprintf(stderr, "PacketAlias/AddLink: ");
1066 fprintf(stderr, " cannot allocate auxiliary TCP data\n");
1067#endif
1068 free(link);
1069 return (NULL);
1078 }
1079 break;
1080 case LINK_PPTP:
1081 pptpLinkCount++;
1082 break;
1083 case LINK_FRAGMENT_ID:
1084 fragmentIdLinkCount++;
1085 break;
1086 case LINK_FRAGMENT_PTR:
1087 fragmentPtrLinkCount++;
1088 break;
1089 case LINK_ADDR:
1090 break;
1091 default:
1092 protoLinkCount++;
1093 break;
1094 }
1070 }
1071 break;
1072 case LINK_PPTP:
1073 pptpLinkCount++;
1074 break;
1075 case LINK_FRAGMENT_ID:
1076 fragmentIdLinkCount++;
1077 break;
1078 case LINK_FRAGMENT_PTR:
1079 fragmentPtrLinkCount++;
1080 break;
1081 case LINK_ADDR:
1082 break;
1083 default:
1084 protoLinkCount++;
1085 break;
1086 }
1087
1088 /* Set up pointers for output lookup table */
1089 start_point = StartPointOut(src_addr, dst_addr,
1090 src_port, dst_port, link_type);
1091 LIST_INSERT_HEAD(&linkTableOut[start_point], link, list_out);
1092
1093 /* Set up pointers for input lookup table */
1094 start_point = StartPointIn(alias_addr, link->alias_port, link_type);
1095 LIST_INSERT_HEAD(&linkTableIn[start_point], link, list_in);
1095 }
1096 else
1097 {
1098#ifdef DEBUG
1099 fprintf(stderr, "PacketAlias/AddLink(): ");
1100 fprintf(stderr, "malloc() call failed.\n");
1101#endif
1102 }

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

1122 struct alias_link *new_link; /* zero, equal to alias port */
1123
1124 new_link = AddLink(src_addr, dst_addr, alias_addr,
1125 src_port, dst_port, alias_port_param,
1126 link_type);
1127#ifndef NO_FW_PUNCH
1128 if (new_link != NULL &&
1129 old_link->link_type == LINK_TCP &&
1096 }
1097 else
1098 {
1099#ifdef DEBUG
1100 fprintf(stderr, "PacketAlias/AddLink(): ");
1101 fprintf(stderr, "malloc() call failed.\n");
1102#endif
1103 }

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

1123 struct alias_link *new_link; /* zero, equal to alias port */
1124
1125 new_link = AddLink(src_addr, dst_addr, alias_addr,
1126 src_port, dst_port, alias_port_param,
1127 link_type);
1128#ifndef NO_FW_PUNCH
1129 if (new_link != NULL &&
1130 old_link->link_type == LINK_TCP &&
1130 old_link->data.tcp &&
1131 old_link->data.tcp->fwhole > 0) {
1132 PunchFWHole(new_link);
1133 }
1134#endif
1135 DeleteLink(old_link);
1136 return new_link;
1137}
1138

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

2674PunchFWHole(struct alias_link *link) {
2675 int r; /* Result code */
2676 struct ip_fw rule; /* On-the-fly built rule */
2677 int fwhole; /* Where to punch hole */
2678
2679/* Don't do anything unless we are asked to */
2680 if ( !(packetAliasMode & PKT_ALIAS_PUNCH_FW) ||
2681 fireWallFD < 0 ||
1131 old_link->data.tcp->fwhole > 0) {
1132 PunchFWHole(new_link);
1133 }
1134#endif
1135 DeleteLink(old_link);
1136 return new_link;
1137}
1138

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

2674PunchFWHole(struct alias_link *link) {
2675 int r; /* Result code */
2676 struct ip_fw rule; /* On-the-fly built rule */
2677 int fwhole; /* Where to punch hole */
2678
2679/* Don't do anything unless we are asked to */
2680 if ( !(packetAliasMode & PKT_ALIAS_PUNCH_FW) ||
2681 fireWallFD < 0 ||
2682 link->link_type != LINK_TCP ||
2683 !link->data.tcp)
2682 link->link_type != LINK_TCP)
2684 return;
2685
2686 memset(&rule, 0, sizeof rule);
2687
2688/** Build rule **/
2689
2690 /* Find empty slot */
2691 for (fwhole = fireWallActiveNum;

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

2750 link->data.tcp->fwhole = fwhole;
2751 fw_setfield(fireWallField, fwhole);
2752}
2753
2754/* Remove a hole in a firewall associated with a particular alias
2755 link. Calling this too often is harmless. */
2756static void
2757ClearFWHole(struct alias_link *link) {
2683 return;
2684
2685 memset(&rule, 0, sizeof rule);
2686
2687/** Build rule **/
2688
2689 /* Find empty slot */
2690 for (fwhole = fireWallActiveNum;

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

2749 link->data.tcp->fwhole = fwhole;
2750 fw_setfield(fireWallField, fwhole);
2751}
2752
2753/* Remove a hole in a firewall associated with a particular alias
2754 link. Calling this too often is harmless. */
2755static void
2756ClearFWHole(struct alias_link *link) {
2758 if (link->link_type == LINK_TCP && link->data.tcp) {
2757 if (link->link_type == LINK_TCP) {
2759 int fwhole = link->data.tcp->fwhole; /* Where is the firewall hole? */
2760 struct ip_fw rule;
2761
2762 if (fwhole < 0)
2763 return;
2764
2765 memset(&rule, 0, sizeof rule);
2766 rule.fw_number = fwhole;

--- 25 unchanged lines hidden ---
2758 int fwhole = link->data.tcp->fwhole; /* Where is the firewall hole? */
2759 struct ip_fw rule;
2760
2761 if (fwhole < 0)
2762 return;
2763
2764 memset(&rule, 0, sizeof rule);
2765 rule.fw_number = fwhole;

--- 25 unchanged lines hidden ---