]>
git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blob - net/ipv4/netfilter/ip_nat_irc.c
1 /* IRC extension for TCP NAT alteration.
2 * (C) 2000-2001 by Harald Welte <laforge@gnumonks.org>
3 * (C) 2004 Rusty Russell <rusty@rustcorp.com.au> IBM Corporation
4 * based on a copy of RR's ip_nat_ftp.c
6 * ip_nat_irc.c,v 1.16 2001/12/06 07:42:10 laforge Exp
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version
11 * 2 of the License, or (at your option) any later version.
14 #include <linux/module.h>
15 #include <linux/netfilter_ipv4.h>
17 #include <linux/tcp.h>
18 #include <linux/kernel.h>
20 #include <linux/netfilter_ipv4/ip_nat.h>
21 #include <linux/netfilter_ipv4/ip_nat_helper.h>
22 #include <linux/netfilter_ipv4/ip_nat_rule.h>
23 #include <linux/netfilter_ipv4/ip_conntrack_irc.h>
24 #include <linux/netfilter_ipv4/ip_conntrack_helper.h>
25 #include <linux/moduleparam.h>
30 #define DEBUGP(format, args...)
33 MODULE_AUTHOR("Harald Welte <laforge@gnumonks.org>");
34 MODULE_DESCRIPTION("IRC (DCC) NAT helper");
35 MODULE_LICENSE("GPL");
37 static unsigned int help(struct sk_buff
**pskb
,
38 enum ip_conntrack_info ctinfo
,
39 unsigned int matchoff
,
40 unsigned int matchlen
,
41 struct ip_conntrack_expect
*exp
)
46 /* "4294967296 65635 " */
49 DEBUGP("IRC_NAT: info (seq %u + %u) in %u\n",
50 expect
->seq
, exp_irc_info
->len
,
53 /* Reply comes from server. */
54 exp
->saved_proto
.tcp
.port
= exp
->tuple
.dst
.u
.tcp
.port
;
55 exp
->dir
= IP_CT_DIR_REPLY
;
57 /* When you see the packet, we need to NAT it the same as the
59 exp
->expectfn
= ip_nat_follow_master
;
61 /* Try to get same port: if not, try to change it. */
62 for (port
= ntohs(exp
->saved_proto
.tcp
.port
); port
!= 0; port
++) {
63 exp
->tuple
.dst
.u
.tcp
.port
= htons(port
);
64 if (ip_conntrack_expect_related(exp
) == 0)
69 ip_conntrack_expect_free(exp
);
73 /* strlen("\1DCC CHAT chat AAAAAAAA P\1\n")=27
74 * strlen("\1DCC SCHAT chat AAAAAAAA P\1\n")=28
75 * strlen("\1DCC SEND F AAAAAAAA P S\1\n")=26
76 * strlen("\1DCC MOVE F AAAAAAAA P S\1\n")=26
77 * strlen("\1DCC TSEND F AAAAAAAA P S\1\n")=27
78 * AAAAAAAAA: bound addr (1.0.0.0==16777216, min 8 digits,
79 * 255.255.255.255==4294967296, 10 digits)
80 * P: bound port (min 1 d, max 5d (65635))
81 * F: filename (min 1 d )
83 * 0x01, \n: terminators
86 /* AAA = "us", ie. where server normally talks to. */
87 sprintf(buffer
, "%u %u",
88 ntohl(exp
->master
->tuplehash
[IP_CT_DIR_REPLY
].tuple
.dst
.ip
),
90 DEBUGP("ip_nat_irc: Inserting '%s' == %u.%u.%u.%u, port %u\n",
91 buffer
, NIPQUAD(exp
->tuple
.src
.ip
), port
);
93 ret
= ip_nat_mangle_tcp_packet(pskb
, exp
->master
, ctinfo
,
94 matchoff
, matchlen
, buffer
,
97 ip_conntrack_unexpect_related(exp
);
101 static void __exit
fini(void)
103 ip_nat_irc_hook
= NULL
;
104 /* Make sure noone calls it, meanwhile. */
108 static int __init
init(void)
110 BUG_ON(ip_nat_irc_hook
);
111 ip_nat_irc_hook
= help
;
115 /* Prior to 2.6.11, we had a ports param. No longer, but don't break users. */
116 static int warn_set(const char *val
, struct kernel_param
*kp
)
118 printk(KERN_INFO
__stringify(KBUILD_MODNAME
)
119 ": kernel >= 2.6.10 only uses 'ports' for conntrack modules\n");
122 module_param_call(ports
, warn_set
, NULL
, NULL
, 0);