alias.c (35314) | alias.c (36321) |
---|---|
1/* -*- mode: c; tab-width: 8; c-basic-indent: 4; -*- */ 2/* 3 Alias.c provides supervisory control for the functions of the 4 packet aliasing software. It consists of routines to monitor 5 TCP connection state, protocol-specific aliasing routines, 6 fragment handling and the following outside world functional 7 interfaces: SaveFragmentPtr, GetFragmentPtr, FragmentAliasIn, 8 PacketAliasIn and PacketAliasOut. --- 79 unchanged lines hidden (view full) --- 88#include <netinet/ip.h> 89#include <netinet/ip_icmp.h> 90#include <netinet/tcp.h> 91#include <netinet/udp.h> 92 93#include "alias_local.h" 94#include "alias.h" 95 | 1/* -*- mode: c; tab-width: 8; c-basic-indent: 4; -*- */ 2/* 3 Alias.c provides supervisory control for the functions of the 4 packet aliasing software. It consists of routines to monitor 5 TCP connection state, protocol-specific aliasing routines, 6 fragment handling and the following outside world functional 7 interfaces: SaveFragmentPtr, GetFragmentPtr, FragmentAliasIn, 8 PacketAliasIn and PacketAliasOut. --- 79 unchanged lines hidden (view full) --- 88#include <netinet/ip.h> 89#include <netinet/ip_icmp.h> 90#include <netinet/tcp.h> 91#include <netinet/udp.h> 92 93#include "alias_local.h" 94#include "alias.h" 95 |
96#define NETBIOS_NS_PORT_NUMBER 137 97#define NETBIOS_DGM_PORT_NUMBER 138 |
|
96#define FTP_CONTROL_PORT_NUMBER 21 | 98#define FTP_CONTROL_PORT_NUMBER 21 |
99#define FTP_CONTROL_PORT_NUMBER 21 |
|
97#define IRC_CONTROL_PORT_NUMBER_1 6667 98#define IRC_CONTROL_PORT_NUMBER_2 6668 99 100/* 101 The following macro is used to update an 102 internet checksum. "delta" is a 32-bit 103 accumulation of all the changes to the 104 checksum (adding in new 16-bit words and --- 208 unchanged lines hidden (view full) --- 313 if (ip->ip_p == IPPROTO_UDP) 314 link = FindUdpTcpIn(ip->ip_dst, ip->ip_src, 315 ud->uh_dport, ud->uh_sport, 316 IPPROTO_UDP); 317 else if (ip->ip_p == IPPROTO_TCP) 318 link = FindUdpTcpIn(ip->ip_dst, ip->ip_src, 319 tc->th_dport, tc->th_sport, 320 IPPROTO_TCP); | 100#define IRC_CONTROL_PORT_NUMBER_1 6667 101#define IRC_CONTROL_PORT_NUMBER_2 6668 102 103/* 104 The following macro is used to update an 105 internet checksum. "delta" is a 32-bit 106 accumulation of all the changes to the 107 checksum (adding in new 16-bit words and --- 208 unchanged lines hidden (view full) --- 316 if (ip->ip_p == IPPROTO_UDP) 317 link = FindUdpTcpIn(ip->ip_dst, ip->ip_src, 318 ud->uh_dport, ud->uh_sport, 319 IPPROTO_UDP); 320 else if (ip->ip_p == IPPROTO_TCP) 321 link = FindUdpTcpIn(ip->ip_dst, ip->ip_src, 322 tc->th_dport, tc->th_sport, 323 IPPROTO_TCP); |
321 else if (ip->ip_p == IPPROTO_ICMP) { | 324 else if (ip->ip_p == IPPROTO_ICMP) |
322 if (ic2->icmp_type == ICMP_ECHO || ic2->icmp_type == ICMP_TSTAMP) 323 link = FindIcmpIn(ip->ip_dst, ip->ip_src, ic2->icmp_id); 324 else 325 link = NULL; | 325 if (ic2->icmp_type == ICMP_ECHO || ic2->icmp_type == ICMP_TSTAMP) 326 link = FindIcmpIn(ip->ip_dst, ip->ip_src, ic2->icmp_id); 327 else 328 link = NULL; |
326 } else | 329 else |
327 link = NULL; 328 329 if (link != NULL) 330 { 331 if (ip->ip_p == IPPROTO_UDP || ip->ip_p == IPPROTO_TCP) 332 { 333 u_short *sptr; 334 int accumulate; --- 265 unchanged lines hidden (view full) --- 600 int accumulate; 601 u_short *sptr; 602 603 alias_address = GetAliasAddress(link); 604 original_address = GetOriginalAddress(link); 605 alias_port = ud->uh_dport; 606 ud->uh_dport = GetOriginalPort(link); 607 | 330 link = NULL; 331 332 if (link != NULL) 333 { 334 if (ip->ip_p == IPPROTO_UDP || ip->ip_p == IPPROTO_TCP) 335 { 336 u_short *sptr; 337 int accumulate; --- 265 unchanged lines hidden (view full) --- 603 int accumulate; 604 u_short *sptr; 605 606 alias_address = GetAliasAddress(link); 607 original_address = GetOriginalAddress(link); 608 alias_port = ud->uh_dport; 609 ud->uh_dport = GetOriginalPort(link); 610 |
611/* If NETBIOS Datagram, It should be alias address in UDP Data, too */ 612 if (ntohs(ud->uh_dport) == NETBIOS_DGM_PORT_NUMBER 613 || ntohs(ud->uh_sport) == NETBIOS_DGM_PORT_NUMBER ) 614 { 615 AliasHandleUdpNbt(pip, link, &original_address, ud->uh_dport); 616 } else if (ntohs(ud->uh_dport) == NETBIOS_NS_PORT_NUMBER 617 || ntohs(ud->uh_sport) == NETBIOS_NS_PORT_NUMBER ) 618 { 619 AliasHandleUdpNbtNS(pip, link, 620 &alias_address, 621 &alias_port, 622 &original_address, 623 &ud->uh_dport ); 624 } 625 |
|
608/* If UDP checksum is not zero, then adjust since destination port */ 609/* is being unaliased and destination port is being altered. */ 610 if (ud->uh_sum != 0) 611 { 612 accumulate = alias_port; 613 accumulate -= ud->uh_dport; 614 sptr = (u_short *) &alias_address; 615 accumulate += *sptr++; --- 29 unchanged lines hidden (view full) --- 645 if (link != NULL) 646 { 647 u_short alias_port; 648 struct in_addr alias_address; 649 650 alias_address = GetAliasAddress(link); 651 alias_port = GetAliasPort(link); 652 | 626/* If UDP checksum is not zero, then adjust since destination port */ 627/* is being unaliased and destination port is being altered. */ 628 if (ud->uh_sum != 0) 629 { 630 accumulate = alias_port; 631 accumulate -= ud->uh_dport; 632 sptr = (u_short *) &alias_address; 633 accumulate += *sptr++; --- 29 unchanged lines hidden (view full) --- 663 if (link != NULL) 664 { 665 u_short alias_port; 666 struct in_addr alias_address; 667 668 alias_address = GetAliasAddress(link); 669 alias_port = GetAliasPort(link); 670 |
671/* If NETBIOS Datagram, It should be alias address in UDP Data, too */ 672 if (ntohs(ud->uh_dport) == NETBIOS_DGM_PORT_NUMBER 673 || ntohs(ud->uh_sport) == NETBIOS_DGM_PORT_NUMBER ) 674 { 675 AliasHandleUdpNbt(pip, link, &alias_address, alias_port); 676 } else if (ntohs(ud->uh_dport) == NETBIOS_NS_PORT_NUMBER 677 || ntohs(ud->uh_sport) == NETBIOS_NS_PORT_NUMBER ) 678 { 679 AliasHandleUdpNbtNS(pip, link, 680 &pip->ip_src, 681 &ud->uh_sport, 682 &alias_address, 683 &alias_port); 684 } 685 |
|
653/* If UDP checksum is not zero, adjust since source port is */ 654/* being aliased and source address is being altered */ 655 if (ud->uh_sum != 0) 656 { 657 int accumulate; 658 u_short *sptr; 659 660 accumulate = ud->uh_sport; 661 accumulate -= alias_port; 662 sptr = (u_short *) &(pip->ip_src); 663 accumulate += *sptr++; 664 accumulate += *sptr; 665 sptr = (u_short *) &alias_address; 666 accumulate -= *sptr++; 667 accumulate -= *sptr; 668 ADJUST_CHECKSUM(accumulate, ud->uh_sum) 669 } 670 | 686/* If UDP checksum is not zero, adjust since source port is */ 687/* being aliased and source address is being altered */ 688 if (ud->uh_sum != 0) 689 { 690 int accumulate; 691 u_short *sptr; 692 693 accumulate = ud->uh_sport; 694 accumulate -= alias_port; 695 sptr = (u_short *) &(pip->ip_src); 696 accumulate += *sptr++; 697 accumulate += *sptr; 698 sptr = (u_short *) &alias_address; 699 accumulate -= *sptr++; 700 accumulate -= *sptr; 701 ADJUST_CHECKSUM(accumulate, ud->uh_sum) 702 } 703 |
671/* Put alias port in TCP header */ | 704/* Put alias port in UDP header */ |
672 ud->uh_sport = alias_port; 673 674/* Change source address */ 675 DifferentialChecksum(&pip->ip_sum, 676 (u_short *) &alias_address, 677 (u_short *) &pip->ip_src, 678 2); 679 pip->ip_src = alias_address; --- 435 unchanged lines hidden --- | 705 ud->uh_sport = alias_port; 706 707/* Change source address */ 708 DifferentialChecksum(&pip->ip_sum, 709 (u_short *) &alias_address, 710 (u_short *) &pip->ip_src, 711 2); 712 pip->ip_src = alias_address; --- 435 unchanged lines hidden --- |