| 819 | } |
| 820 | |
| 821 | static int |
| 822 | UdpAliasOut(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; |
no test coverage detected