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

Function UdpAliasOut

freebsd/netinet/libalias/alias.c:821–928  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

819}
820
821static int
822UdpAliasOut(struct libalias *la, struct ip *pip, int maxpacketsize, int create)
823{
824 struct udphdr *ud;
825 struct alias_link *lnk;
826 struct in_addr dest_address;
827 struct in_addr proxy_server_address;
828 u_short dest_port;
829 u_short proxy_server_port;
830 int proxy_type;
831 int error;
832 size_t dlen;
833
834 LIBALIAS_LOCK_ASSERT(la);
835
836/* Return if proxy-only mode is enabled and not proxyrule found.*/
837 dlen = ntohs(pip->ip_len) - (pip->ip_hl << 2);
838 if (dlen < sizeof(struct udphdr))
839 return (PKT_ALIAS_IGNORED);
840
841 ud = (struct udphdr *)ip_next(pip);
842 if (dlen < ntohs(ud->uh_ulen))
843 return (PKT_ALIAS_IGNORED);
844
845 proxy_type = ProxyCheck(la, &proxy_server_address,
846 &proxy_server_port, pip->ip_src, pip->ip_dst,
847 ud->uh_dport, pip->ip_p);
848 if (proxy_type == 0 && (la->packetAliasMode & PKT_ALIAS_PROXY_ONLY))
849 return (PKT_ALIAS_OK);
850
851/* If this is a transparent proxy, save original destination,
852 * then alter the destination and adjust checksums */
853 dest_port = ud->uh_dport;
854 dest_address = pip->ip_dst;
855
856 if (proxy_type != 0) {
857 int accumulate;
858
859 accumulate = twowords(&pip->ip_dst);
860 accumulate -= twowords(&proxy_server_address);
861
862 ADJUST_CHECKSUM(accumulate, pip->ip_sum);
863
864 if (ud->uh_sum != 0) {
865 accumulate = twowords(&pip->ip_dst);
866 accumulate -= twowords(&proxy_server_address);
867 accumulate += ud->uh_dport;
868 accumulate -= proxy_server_port;
869 ADJUST_CHECKSUM(accumulate, ud->uh_sum);
870 }
871 pip->ip_dst = proxy_server_address;
872 ud->uh_dport = proxy_server_port;
873 }
874 lnk = FindUdpTcpOut(la, pip->ip_src, pip->ip_dst,
875 ud->uh_sport, ud->uh_dport,
876 IPPROTO_UDP, create);
877 if (lnk != NULL) {
878 u_short alias_port;

Callers 1

LibAliasOutLockedFunction · 0.85

Calls 11

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

Tested by

no test coverage detected