MCPcopy Create free account
hub / github.com/F-Stack/f-stack / TcpAliasOut

Function TcpAliasOut

freebsd/netinet/libalias/alias.c:1057–1175  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1055}
1056
1057static int
1058TcpAliasOut(struct libalias *la, struct ip *pip, int maxpacketsize, int create)
1059{
1060 int proxy_type, error;
1061 u_short dest_port;
1062 u_short proxy_server_port;
1063 size_t dlen;
1064 struct in_addr dest_address;
1065 struct in_addr proxy_server_address;
1066 struct tcphdr *tc;
1067 struct alias_link *lnk;
1068
1069 LIBALIAS_LOCK_ASSERT(la);
1070
1071 dlen = ntohs(pip->ip_len) - (pip->ip_hl << 2);
1072 if (dlen < sizeof(struct tcphdr))
1073 return (PKT_ALIAS_IGNORED);
1074 tc = (struct tcphdr *)ip_next(pip);
1075
1076 if (create)
1077 proxy_type = ProxyCheck(la, &proxy_server_address,
1078 &proxy_server_port, pip->ip_src, pip->ip_dst,
1079 tc->th_dport, pip->ip_p);
1080 else
1081 proxy_type = 0;
1082
1083 if (proxy_type == 0 && (la->packetAliasMode & PKT_ALIAS_PROXY_ONLY))
1084 return (PKT_ALIAS_OK);
1085
1086/* If this is a transparent proxy, save original destination,
1087 then alter the destination and adjust checksums */
1088 dest_port = tc->th_dport;
1089 dest_address = pip->ip_dst;
1090 if (proxy_type != 0) {
1091 int accumulate;
1092
1093 accumulate = tc->th_dport;
1094 tc->th_dport = proxy_server_port;
1095 accumulate -= tc->th_dport;
1096 accumulate += twowords(&pip->ip_dst);
1097 accumulate -= twowords(&proxy_server_address);
1098 ADJUST_CHECKSUM(accumulate, tc->th_sum);
1099
1100 accumulate = twowords(&pip->ip_dst);
1101 pip->ip_dst = proxy_server_address;
1102 accumulate -= twowords(&pip->ip_dst);
1103 ADJUST_CHECKSUM(accumulate, pip->ip_sum);
1104 }
1105 lnk = FindUdpTcpOut(la, pip->ip_src, pip->ip_dst,
1106 tc->th_sport, tc->th_dport,
1107 IPPROTO_TCP, create);
1108 if (lnk == NULL)
1109 return (PKT_ALIAS_IGNORED);
1110 if (lnk != NULL) {
1111 u_short alias_port;
1112 struct in_addr alias_address;
1113 int accumulate;
1114 struct alias_data ad = {

Callers 1

LibAliasOutLockedFunction · 0.85

Calls 13

ip_nextFunction · 0.85
ProxyCheckFunction · 0.85
twowordsFunction · 0.85
FindUdpTcpOutFunction · 0.85
SetProxyPortFunction · 0.85
SetProxyAddressFunction · 0.85
ProxyModifyFunction · 0.85
GetAliasPortFunction · 0.85
GetAliasAddressFunction · 0.85
TcpMonitorOutFunction · 0.85
find_handlerFunction · 0.85
GetAckModifiedFunction · 0.85

Tested by

no test coverage detected