Deleted Added
full compact
alias.c (51125) alias.c (59047)
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.
9
10 The other C program files are briefly described. The data
11 structure framework which holds information needed to translate
12 packets is encapsulated in alias_db.c. Data is accessed by
13 function calls, so other segments of the program need not know
14 about the underlying data structures. Alias_ftp.c contains
15 special code for modifying the ftp PORT command used to establish
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.
9
10 The other C program files are briefly described. The data
11 structure framework which holds information needed to translate
12 packets is encapsulated in alias_db.c. Data is accessed by
13 function calls, so other segments of the program need not know
14 about the underlying data structures. Alias_ftp.c contains
15 special code for modifying the ftp PORT command used to establish
16 data connections, while alias_irc.c do the same for IRC
16 data connections, while alias_irc.c does the same for IRC
17 DCC. Alias_util.c contains a few utility routines.
18
19 This software is placed into the public domain with no restrictions
20 on its distribution.
21
22 Version 1.0 August, 1996 (cjm)
23
24 Version 1.1 August 20, 1996 (cjm)

--- 48 unchanged lines hidden (view full) ---

73 - Eliminated PacketAliasIn2() and
74 PacketAliasOut2() as poorly conceived.
75
76 Version 2.3 Dec 1998 (dillon)
77 - Major bounds checking additions, see FreeBSD/CVS
78
79 See HISTORY file for additional revisions.
80
17 DCC. Alias_util.c contains a few utility routines.
18
19 This software is placed into the public domain with no restrictions
20 on its distribution.
21
22 Version 1.0 August, 1996 (cjm)
23
24 Version 1.1 August 20, 1996 (cjm)

--- 48 unchanged lines hidden (view full) ---

73 - Eliminated PacketAliasIn2() and
74 PacketAliasOut2() as poorly conceived.
75
76 Version 2.3 Dec 1998 (dillon)
77 - Major bounds checking additions, see FreeBSD/CVS
78
79 See HISTORY file for additional revisions.
80
81 $FreeBSD: head/sys/netinet/libalias/alias.c 51125 1999-09-10 15:27:34Z ru $
81 $FreeBSD: head/sys/netinet/libalias/alias.c 59047 2000-04-05 14:27:34Z ru $
82*/
83
82*/
83
84#include <stdio.h>
85#include <unistd.h>
86
87#include <sys/param.h>
88#include <sys/types.h>
89
90#include <netinet/in_systm.h>
91#include <netinet/in.h>
92#include <netinet/ip.h>
93#include <netinet/ip_icmp.h>
94#include <netinet/tcp.h>
95#include <netinet/udp.h>

--- 210 unchanged lines hidden (view full) ---

306 IPPROTO_UDP);
307 else if (ip->ip_p == IPPROTO_TCP)
308 link = FindUdpTcpIn(ip->ip_dst, ip->ip_src,
309 tc->th_dport, tc->th_sport,
310 IPPROTO_TCP);
311 else if (ip->ip_p == IPPROTO_ICMP) {
312 if (ic2->icmp_type == ICMP_ECHO || ic2->icmp_type == ICMP_TSTAMP)
313 link = FindIcmpIn(ip->ip_dst, ip->ip_src, ic2->icmp_id);
84#include <sys/types.h>
85
86#include <netinet/in_systm.h>
87#include <netinet/in.h>
88#include <netinet/ip.h>
89#include <netinet/ip_icmp.h>
90#include <netinet/tcp.h>
91#include <netinet/udp.h>

--- 210 unchanged lines hidden (view full) ---

302 IPPROTO_UDP);
303 else if (ip->ip_p == IPPROTO_TCP)
304 link = FindUdpTcpIn(ip->ip_dst, ip->ip_src,
305 tc->th_dport, tc->th_sport,
306 IPPROTO_TCP);
307 else if (ip->ip_p == IPPROTO_ICMP) {
308 if (ic2->icmp_type == ICMP_ECHO || ic2->icmp_type == ICMP_TSTAMP)
309 link = FindIcmpIn(ip->ip_dst, ip->ip_src, ic2->icmp_id);
314 else
310 else
315 link = NULL;
316 } else
317 link = NULL;
318
319 if (link != NULL)
320 {
321 if (ip->ip_p == IPPROTO_UDP || ip->ip_p == IPPROTO_TCP)
322 {

--- 51 unchanged lines hidden (view full) ---

374
375/* Un-alias address in IP header */
376 DifferentialChecksum(&pip->ip_sum,
377 (u_short *) &original_address,
378 (u_short *) &pip->ip_dst,
379 2);
380 pip->ip_dst = original_address;
381
311 link = NULL;
312 } else
313 link = NULL;
314
315 if (link != NULL)
316 {
317 if (ip->ip_p == IPPROTO_UDP || ip->ip_p == IPPROTO_TCP)
318 {

--- 51 unchanged lines hidden (view full) ---

370
371/* Un-alias address in IP header */
372 DifferentialChecksum(&pip->ip_sum,
373 (u_short *) &original_address,
374 (u_short *) &pip->ip_dst,
375 2);
376 pip->ip_dst = original_address;
377
382/* Un-alias address of original IP packet and seqence number of
383 embedded icmp datagram */
378/* Un-alias address of original IP packet and sequence number of
379 embedded ICMP datagram */
384 ip->ip_src = original_address;
385 ic2->icmp_id = original_id;
386 }
387 return(PKT_ALIAS_OK);
388 }
389 return(PKT_ALIAS_IGNORED);
390}
391

--- 98 unchanged lines hidden (view full) ---

490
491static int
492IcmpAliasOut2(struct ip *pip)
493{
494/*
495 Alias outgoing ICMP error messages containing
496 IP header and first 64 bits of datagram.
497*/
380 ip->ip_src = original_address;
381 ic2->icmp_id = original_id;
382 }
383 return(PKT_ALIAS_OK);
384 }
385 return(PKT_ALIAS_IGNORED);
386}
387

--- 98 unchanged lines hidden (view full) ---

486
487static int
488IcmpAliasOut2(struct ip *pip)
489{
490/*
491 Alias outgoing ICMP error messages containing
492 IP header and first 64 bits of datagram.
493*/
498 struct in_addr alias_addr;
499 struct ip *ip;
494 struct ip *ip;
500 struct icmp *ic;
495 struct icmp *ic, *ic2;
496 struct udphdr *ud;
497 struct tcphdr *tc;
498 struct alias_link *link;
501
502 ic = (struct icmp *) ((char *) pip + (pip->ip_hl << 2));
503 ip = (struct ip *) ic->icmp_data;
504
499
500 ic = (struct icmp *) ((char *) pip + (pip->ip_hl << 2));
501 ip = (struct ip *) ic->icmp_data;
502
505 alias_addr = FindAliasAddress(ip->ip_src);
503 ud = (struct udphdr *) ((char *) ip + (ip->ip_hl <<2));
504 tc = (struct tcphdr *) ud;
505 ic2 = (struct icmp *) ud;
506
506
507/* Alias destination address in IP fragment */
508 DifferentialChecksum(&ic->icmp_cksum,
509 (u_short *) &alias_addr,
510 (u_short *) &ip->ip_dst,
511 2);
512 ip->ip_dst = alias_addr;
507 if (ip->ip_p == IPPROTO_UDP)
508 link = FindUdpTcpOut(ip->ip_dst, ip->ip_src,
509 ud->uh_dport, ud->uh_sport,
510 IPPROTO_UDP);
511 else if (ip->ip_p == IPPROTO_TCP)
512 link = FindUdpTcpOut(ip->ip_dst, ip->ip_src,
513 tc->th_dport, tc->th_sport,
514 IPPROTO_TCP);
515 else if (ip->ip_p == IPPROTO_ICMP) {
516 if (ic2->icmp_type == ICMP_ECHO || ic2->icmp_type == ICMP_TSTAMP)
517 link = FindIcmpOut(ip->ip_dst, ip->ip_src, ic2->icmp_id);
518 else
519 link = NULL;
520 } else
521 link = NULL;
513
522
514/* alias source address in IP header */
515 DifferentialChecksum(&pip->ip_sum,
516 (u_short *) &alias_addr,
517 (u_short *) &pip->ip_src,
518 2);
519 pip->ip_src = alias_addr;
523 if (link != NULL)
524 {
525 if (ip->ip_p == IPPROTO_UDP || ip->ip_p == IPPROTO_TCP)
526 {
527 u_short *sptr;
528 int accumulate;
529 struct in_addr alias_address;
530 u_short alias_port;
520
531
521 return PKT_ALIAS_OK;
532 alias_address = GetAliasAddress(link);
533 alias_port = GetAliasPort(link);
534
535/* Adjust ICMP checksum */
536 sptr = (u_short *) &(ip->ip_dst);
537 accumulate = *sptr++;
538 accumulate += *sptr;
539 sptr = (u_short *) &alias_address;
540 accumulate -= *sptr++;
541 accumulate -= *sptr;
542 accumulate += ud->uh_dport;
543 accumulate -= alias_port;
544 ADJUST_CHECKSUM(accumulate, ic->icmp_cksum)
545
546/* Alias address in IP header */
547 DifferentialChecksum(&pip->ip_sum,
548 (u_short *) &alias_address,
549 (u_short *) &pip->ip_src,
550 2);
551 pip->ip_src = alias_address;
552
553/* Alias address and port number of original IP packet
554fragment contained in ICMP data section */
555 ip->ip_dst = alias_address;
556 ud->uh_dport = alias_port;
557 }
558 else if (pip->ip_p == IPPROTO_ICMP)
559 {
560 u_short *sptr;
561 int accumulate;
562 struct in_addr alias_address;
563 u_short alias_id;
564
565 alias_address = GetAliasAddress(link);
566 alias_id = GetAliasPort(link);
567
568/* Adjust ICMP checksum */
569 sptr = (u_short *) &(ip->ip_dst);
570 accumulate = *sptr++;
571 accumulate += *sptr;
572 sptr = (u_short *) &alias_address;
573 accumulate -= *sptr++;
574 accumulate -= *sptr;
575 accumulate += ic2->icmp_id;
576 accumulate -= alias_id;
577 ADJUST_CHECKSUM(accumulate, ic->icmp_cksum)
578
579/* Alias address in IP header */
580 DifferentialChecksum(&pip->ip_sum,
581 (u_short *) &alias_address,
582 (u_short *) &pip->ip_src,
583 2);
584 pip->ip_src = alias_address;
585
586/* Alias address of original IP packet and sequence number of
587 embedded ICMP datagram */
588 ip->ip_dst = alias_address;
589 ic2->icmp_id = alias_id;
590 }
591 return(PKT_ALIAS_OK);
592 }
593 return(PKT_ALIAS_IGNORED);
522}
523
524
525static int
526IcmpAliasOut3(struct ip *pip)
527{
528/*
529 Handle outgoing echo and timestamp replies. The

--- 806 unchanged lines hidden ---
594}
595
596
597static int
598IcmpAliasOut3(struct ip *pip)
599{
600/*
601 Handle outgoing echo and timestamp replies. The

--- 806 unchanged lines hidden ---