2 * Transparent proxy support for Linux/iptables
4 * Copyright (c) 2006-2007 BalaBit IT Ltd.
5 * Author: Balazs Scheidler, Krisztian Kovacs
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
13 #include <linux/version.h>
14 #include <linux/module.h>
16 #include <linux/net.h>
18 #include <linux/netdevice.h>
20 #include <net/netfilter/nf_tproxy_core.h>
23 nf_tproxy_get_sock_v4(struct net *net, const u8 protocol,
24 const __be32 saddr, const __be32 daddr,
25 const __be16 sport, const __be16 dport,
26 const struct net_device *in, bool listening_only)
34 sk = __inet_lookup_listener(net, &tcp_hashinfo,
38 sk = __inet_lookup(net, &tcp_hashinfo,
39 saddr, sport, daddr, dport,
43 sk = udp4_lib_lookup(net, saddr, sport, daddr, dport,
51 pr_debug("tproxy socket lookup: proto %u %08x:%u -> %08x:%u, listener only: %d, sock %p\n",
52 protocol, ntohl(saddr), ntohs(sport), ntohl(daddr), ntohs(dport), listening_only, sk);
56 EXPORT_SYMBOL_GPL(nf_tproxy_get_sock_v4);
59 nf_tproxy_destructor(struct sk_buff *skb)
61 struct sock *sk = skb->sk;
64 skb->destructor = NULL;
67 nf_tproxy_put_sock(sk);
72 nf_tproxy_assign_sock(struct sk_buff *skb, struct sock *sk)
74 if (inet_sk(sk)->transparent) {
76 skb->destructor = nf_tproxy_destructor;
79 nf_tproxy_put_sock(sk);
83 EXPORT_SYMBOL_GPL(nf_tproxy_assign_sock);
85 static int __init nf_tproxy_init(void)
87 pr_info("NF_TPROXY: Transparent proxy support initialized, version 4.1.0\n");
88 pr_info("NF_TPROXY: Copyright (c) 2006-2007 BalaBit IT Ltd.\n");
92 module_init(nf_tproxy_init);
94 MODULE_LICENSE("GPL");
95 MODULE_AUTHOR("Krisztian Kovacs");
96 MODULE_DESCRIPTION("Transparent proxy support core routines");