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

Function UdpAliasIn

freebsd/netinet/libalias/alias.c:727–819  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

725}
726
727static int
728UdpAliasIn(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);

Callers 1

LibAliasInLockedFunction · 0.85

Calls 10

ip_nextFunction · 0.85
FindUdpTcpInFunction · 0.85
GetAliasAddressFunction · 0.85
GetOriginalAddressFunction · 0.85
GetProxyAddressFunction · 0.85
GetOriginalPortFunction · 0.85
GetProxyPortFunction · 0.85
find_handlerFunction · 0.85
twowordsFunction · 0.85
DifferentialChecksumFunction · 0.85

Tested by

no test coverage detected