| 1550 | } |
| 1551 | |
| 1552 | int |
| 1553 | LibAliasUnaliasOut(struct libalias *la, void *ptr, /* valid IP packet */ |
| 1554 | int maxpacketsize /* for error checking */ |
| 1555 | ) |
| 1556 | { |
| 1557 | struct ip *pip; |
| 1558 | struct icmp *ic; |
| 1559 | struct udphdr *ud; |
| 1560 | struct tcphdr *tc; |
| 1561 | struct alias_link *lnk; |
| 1562 | int iresult = PKT_ALIAS_IGNORED; |
| 1563 | |
| 1564 | LIBALIAS_LOCK(la); |
| 1565 | pip = (struct ip *)ptr; |
| 1566 | |
| 1567 | /* Defense against mangled packets */ |
| 1568 | if (ntohs(pip->ip_len) > maxpacketsize |
| 1569 | || (pip->ip_hl << 2) > maxpacketsize) |
| 1570 | goto getout; |
| 1571 | |
| 1572 | ud = (struct udphdr *)ip_next(pip); |
| 1573 | tc = (struct tcphdr *)ip_next(pip); |
| 1574 | ic = (struct icmp *)ip_next(pip); |
| 1575 | |
| 1576 | /* Find a link */ |
| 1577 | if (pip->ip_p == IPPROTO_UDP) |
| 1578 | lnk = FindUdpTcpIn(la, pip->ip_dst, pip->ip_src, |
| 1579 | ud->uh_dport, ud->uh_sport, |
| 1580 | IPPROTO_UDP, 0); |
| 1581 | else if (pip->ip_p == IPPROTO_TCP) |
| 1582 | lnk = FindUdpTcpIn(la, pip->ip_dst, pip->ip_src, |
| 1583 | tc->th_dport, tc->th_sport, |
| 1584 | IPPROTO_TCP, 0); |
| 1585 | else if (pip->ip_p == IPPROTO_ICMP) |
| 1586 | lnk = FindIcmpIn(la, pip->ip_dst, pip->ip_src, ic->icmp_id, 0); |
| 1587 | else |
| 1588 | lnk = NULL; |
| 1589 | |
| 1590 | /* Change it from an aliased packet to an unaliased packet */ |
| 1591 | if (lnk != NULL) { |
| 1592 | if (pip->ip_p == IPPROTO_UDP || pip->ip_p == IPPROTO_TCP) { |
| 1593 | int accumulate; |
| 1594 | struct in_addr original_address; |
| 1595 | u_short original_port; |
| 1596 | |
| 1597 | original_address = GetOriginalAddress(lnk); |
| 1598 | original_port = GetOriginalPort(lnk); |
| 1599 | |
| 1600 | /* Adjust TCP/UDP checksum */ |
| 1601 | accumulate = twowords(&pip->ip_src); |
| 1602 | accumulate -= twowords(&original_address); |
| 1603 | |
| 1604 | if (pip->ip_p == IPPROTO_UDP) { |
| 1605 | accumulate += ud->uh_sport; |
| 1606 | accumulate -= original_port; |
| 1607 | ADJUST_CHECKSUM(accumulate, ud->uh_sum); |
| 1608 | } else { |
| 1609 | accumulate += tc->th_sport; |
nothing calls this directly
no test coverage detected