| 725 | } |
| 726 | |
| 727 | static int |
| 728 | UdpAliasIn(struct libalias *la, struct ip *pip) |
| 729 | { |
| 730 | struct udphdr *ud; |
| 731 | struct alias_link *lnk; |
| 732 | size_t dlen; |
| 733 | |
| 734 | LIBALIAS_LOCK_ASSERT(la); |
| 735 | |
| 736 | dlen = ntohs(pip->ip_len) - (pip->ip_hl << 2); |
| 737 | if (dlen < sizeof(struct udphdr)) |
| 738 | return (PKT_ALIAS_IGNORED); |
| 739 | |
| 740 | ud = (struct udphdr *)ip_next(pip); |
| 741 | if (dlen < ntohs(ud->uh_ulen)) |
| 742 | return (PKT_ALIAS_IGNORED); |
| 743 | |
| 744 | lnk = FindUdpTcpIn(la, pip->ip_src, pip->ip_dst, |
| 745 | ud->uh_sport, ud->uh_dport, |
| 746 | IPPROTO_UDP, !(la->packetAliasMode & PKT_ALIAS_PROXY_ONLY)); |
| 747 | if (lnk != NULL) { |
| 748 | struct in_addr alias_address; |
| 749 | struct in_addr original_address; |
| 750 | struct in_addr proxy_address; |
| 751 | u_short alias_port; |
| 752 | u_short proxy_port; |
| 753 | int accumulate; |
| 754 | int error; |
| 755 | struct alias_data ad = { |
| 756 | .lnk = lnk, |
| 757 | .oaddr = &original_address, |
| 758 | .aaddr = &alias_address, |
| 759 | .aport = &alias_port, |
| 760 | .sport = &ud->uh_sport, |
| 761 | .dport = &ud->uh_dport, |
| 762 | .maxpktsize = 0 |
| 763 | }; |
| 764 | |
| 765 | alias_address = GetAliasAddress(lnk); |
| 766 | original_address = GetOriginalAddress(lnk); |
| 767 | proxy_address = GetProxyAddress(lnk); |
| 768 | alias_port = ud->uh_dport; |
| 769 | ud->uh_dport = GetOriginalPort(lnk); |
| 770 | proxy_port = GetProxyPort(lnk); |
| 771 | |
| 772 | /* Walk out chain. */ |
| 773 | error = find_handler(IN, UDP, la, pip, &ad); |
| 774 | /* If we cannot figure out the packet, ignore it. */ |
| 775 | if (error < 0) |
| 776 | return (PKT_ALIAS_IGNORED); |
| 777 | |
| 778 | /* If UDP checksum is not zero, then adjust since destination port */ |
| 779 | /* is being unaliased and destination address is being altered. */ |
| 780 | if (ud->uh_sum != 0) { |
| 781 | accumulate = alias_port; |
| 782 | accumulate -= ud->uh_dport; |
| 783 | accumulate += twowords(&alias_address); |
| 784 | accumulate -= twowords(&original_address); |
no test coverage detected