Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <linux/ip.h>
- #include <linux/netfilter/x_tables.h>
- #include <linux/netfilter/xt_TPROXY.h>
- struct xt_target * tproxy = NULL;
- static unsigned int simple_tproxy(void *priv,
- struct sk_buff *skb,
- const struct nf_hook_state *state)
- {
- struct xt_action_param par = {
- .state = state,
- .targinfo = (struct xt_tproxy_target_info_v1 []) {{
- /* --tproxy-mask=0/0 */
- .mark_value = 0,
- .mark_mask = 0,
- /* --on-ip=127.0.0.1 */
- .laddr = (union nf_inet_addr) { .ip = INADDR_LOOPBACK },
- /* --on-port=1234 */
- .lport = htons(1234),
- },},
- };
- /* -d 192.0.2.0/24 -p tcp */
- if ((ipv4_is_test_192(ip_hdr(skb)->daddr)
- && ip_hdr(skb)->protocol == IPPROTO_TCP))
- return tproxy->target(skb, &par);
- return NF_ACCEPT;
- }
- static struct nf_hook_ops tproxy_ops __read_mostly = {
- .hook = simple_tproxy,
- .pf = NFPROTO_IPV4,
- .hooknum = NF_INET_PRE_ROUTING,
- .priority = (NF_IP_PRI_MANGLE+1), /* after normal mangle matches */
- };
- static int __init simple_tproxy_init(void)
- {
- tproxy = xt_request_find_target(NFPROTO_IPV4, "TPROXY", 1);
- if (tproxy)
- return nf_register_hook(&tproxy_ops);
- return 0;
- }
- module_init(simple_tproxy_init);
Advertisement
Add Comment
Please, Sign In to add comment