Deleted Added
full compact
alias_proxy.c (169149) alias_proxy.c (176884)
1/*-
2 * Copyright (c) 2001 Charles Mott <cm@linktel.net>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

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

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2001 Charles Mott <cm@linktel.net>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

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

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/sys/netinet/libalias/alias_proxy.c 169149 2007-04-30 20:26:11Z maxim $");
28__FBSDID("$FreeBSD: head/sys/netinet/libalias/alias_proxy.c 176884 2008-03-06 21:50:41Z piso $");
29
30/* file: alias_proxy.c
31
32 This file encapsulates special operations related to transparent
33 proxy redirection. This is where packets with a particular destination,
34 usually tcp port 80, are redirected to a proxy server.
35
36 When packets are proxied, the destination address and port are

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

448 memcpy(p, buffer, slen);
449 }
450
451/* Save information about modfied sequence number */
452 {
453 int delta;
454
455 SetAckModified(lnk);
29
30/* file: alias_proxy.c
31
32 This file encapsulates special operations related to transparent
33 proxy redirection. This is where packets with a particular destination,
34 usually tcp port 80, are redirected to a proxy server.
35
36 When packets are proxied, the destination address and port are

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

448 memcpy(p, buffer, slen);
449 }
450
451/* Save information about modfied sequence number */
452 {
453 int delta;
454
455 SetAckModified(lnk);
456 delta = GetDeltaSeqOut(pip, lnk);
457 AddSeq(pip, lnk, delta + slen);
456 tc = (struct tcphdr *)ip_next(pip);
457 delta = GetDeltaSeqOut(tc->th_seq, lnk);
458 AddSeq(lnk, delta + slen, pip->ip_hl, pip->ip_len, tc->th_seq,
459 tc->th_off);
458 }
459
460/* Update IP header packet length and checksum */
461 {
462 int accumulate;
463
464 accumulate = pip->ip_len;
465 pip->ip_len = htons(ntohs(pip->ip_len) + slen);

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

556 ProxyCheck() -- Checks whether an outgoing packet should
557 be proxied.
558 ProxyModify() -- Encodes the original destination address/port
559 for a packet which is to be redirected to
560 a proxy server.
561*/
562
563int
460 }
461
462/* Update IP header packet length and checksum */
463 {
464 int accumulate;
465
466 accumulate = pip->ip_len;
467 pip->ip_len = htons(ntohs(pip->ip_len) + slen);

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

558 ProxyCheck() -- Checks whether an outgoing packet should
559 be proxied.
560 ProxyModify() -- Encodes the original destination address/port
561 for a packet which is to be redirected to
562 a proxy server.
563*/
564
565int
564ProxyCheck(struct libalias *la, struct ip *pip,
565 struct in_addr *proxy_server_addr,
566 u_short * proxy_server_port)
566ProxyCheck(struct libalias *la, struct in_addr *proxy_server_addr,
567 u_short * proxy_server_port, struct in_addr src_addr,
568 struct in_addr dst_addr, u_short dst_port, u_char ip_p)
567{
569{
568 u_short dst_port;
569 struct in_addr src_addr;
570 struct in_addr dst_addr;
571 struct proxy_entry *ptr;
572
573 LIBALIAS_LOCK_ASSERT(la);
570 struct proxy_entry *ptr;
571
572 LIBALIAS_LOCK_ASSERT(la);
574 src_addr = pip->ip_src;
575 dst_addr = pip->ip_dst;
576 dst_port = ((struct tcphdr *)ip_next(pip))
577 ->th_dport;
578
579 ptr = la->proxyList;
580 while (ptr != NULL) {
581 u_short proxy_port;
582
583 proxy_port = ptr->proxy_port;
584 if ((dst_port == proxy_port || proxy_port == 0)
573
574 ptr = la->proxyList;
575 while (ptr != NULL) {
576 u_short proxy_port;
577
578 proxy_port = ptr->proxy_port;
579 if ((dst_port == proxy_port || proxy_port == 0)
585 && pip->ip_p == ptr->proto
580 && ip_p == ptr->proto
586 && src_addr.s_addr != ptr->server_addr.s_addr) {
587 struct in_addr src_addr_masked;
588 struct in_addr dst_addr_masked;
589
590 src_addr_masked.s_addr = src_addr.s_addr & ptr->src_mask.s_addr;
591 dst_addr_masked.s_addr = dst_addr.s_addr & ptr->dst_mask.s_addr;
592
593 if ((src_addr_masked.s_addr == ptr->src_addr.s_addr)

--- 384 unchanged lines hidden ---
581 && src_addr.s_addr != ptr->server_addr.s_addr) {
582 struct in_addr src_addr_masked;
583 struct in_addr dst_addr_masked;
584
585 src_addr_masked.s_addr = src_addr.s_addr & ptr->src_mask.s_addr;
586 dst_addr_masked.s_addr = dst_addr.s_addr & ptr->dst_mask.s_addr;
587
588 if ((src_addr_masked.s_addr == ptr->src_addr.s_addr)

--- 384 unchanged lines hidden ---