Skip to content

Commit 869f37d

Browse files
kaberdavem330
authored andcommitted
[NETFILTER]: nf_conntrack/nf_nat: add IRC helper port
Add nf_conntrack port of the IRC conntrack/NAT helper. Since DCC doesn't support IPv6 yet, the helper is still IPv4 only. Signed-off-by: Patrick McHardy <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent f587de0 commit 869f37d

File tree

7 files changed

+419
-0
lines changed

7 files changed

+419
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#ifndef _NF_CONNTRACK_IRC_H
2+
#define _NF_CONNTRACK_IRC_H
3+
4+
#ifdef __KERNEL__
5+
6+
#define IRC_PORT 6667
7+
8+
extern unsigned int (*nf_nat_irc_hook)(struct sk_buff **pskb,
9+
enum ip_conntrack_info ctinfo,
10+
unsigned int matchoff,
11+
unsigned int matchlen,
12+
struct nf_conntrack_expect *exp);
13+
14+
#endif /* __KERNEL__ */
15+
#endif /* _NF_CONNTRACK_IRC_H */

net/ipv4/netfilter/Kconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,11 @@ config IP_NF_NAT_IRC
500500
default IP_NF_NAT if IP_NF_IRC=y
501501
default m if IP_NF_IRC=m
502502

503+
config NF_NAT_IRC
504+
tristate
505+
depends on IP_NF_IPTABLES && NF_CONNTRACK && NF_NAT
506+
default NF_NAT && NF_CONNTRACK_IRC
507+
503508
config IP_NF_NAT_TFTP
504509
tristate
505510
depends on IP_NF_IPTABLES!=n && IP_NF_CONNTRACK!=n && IP_NF_NAT!=n

net/ipv4/netfilter/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ obj-$(CONFIG_IP_NF_NAT_SIP) += ip_nat_sip.o
5353
obj-$(CONFIG_NF_NAT_AMANDA) += nf_nat_amanda.o
5454
obj-$(CONFIG_NF_NAT_FTP) += nf_nat_ftp.o
5555
obj-$(CONFIG_NF_NAT_H323) += nf_nat_h323.o
56+
obj-$(CONFIG_NF_NAT_IRC) += nf_nat_irc.o
5657

5758
# generic IP tables
5859
obj-$(CONFIG_IP_NF_IPTABLES) += ip_tables.o

net/ipv4/netfilter/nf_nat_irc.c

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/* IRC extension for TCP NAT alteration.
2+
*
3+
* (C) 2000-2001 by Harald Welte <[email protected]>
4+
* (C) 2004 Rusty Russell <[email protected]> IBM Corporation
5+
* based on a copy of RR's ip_nat_ftp.c
6+
*
7+
* This program is free software; you can redistribute it and/or
8+
* modify it under the terms of the GNU General Public License
9+
* as published by the Free Software Foundation; either version
10+
* 2 of the License, or (at your option) any later version.
11+
*/
12+
13+
#include <linux/module.h>
14+
#include <linux/moduleparam.h>
15+
#include <linux/tcp.h>
16+
#include <linux/kernel.h>
17+
18+
#include <net/netfilter/nf_nat.h>
19+
#include <net/netfilter/nf_nat_helper.h>
20+
#include <net/netfilter/nf_nat_rule.h>
21+
#include <net/netfilter/nf_conntrack_helper.h>
22+
#include <net/netfilter/nf_conntrack_expect.h>
23+
#include <linux/netfilter/nf_conntrack_irc.h>
24+
25+
#if 0
26+
#define DEBUGP printk
27+
#else
28+
#define DEBUGP(format, args...)
29+
#endif
30+
31+
MODULE_AUTHOR("Harald Welte <[email protected]>");
32+
MODULE_DESCRIPTION("IRC (DCC) NAT helper");
33+
MODULE_LICENSE("GPL");
34+
MODULE_ALIAS("ip_nat_irc");
35+
36+
static unsigned int help(struct sk_buff **pskb,
37+
enum ip_conntrack_info ctinfo,
38+
unsigned int matchoff,
39+
unsigned int matchlen,
40+
struct nf_conntrack_expect *exp)
41+
{
42+
char buffer[sizeof("4294967296 65635")];
43+
u_int32_t ip;
44+
u_int16_t port;
45+
unsigned int ret;
46+
47+
DEBUGP("IRC_NAT: info (seq %u + %u) in %u\n",
48+
expect->seq, exp_irc_info->len, ntohl(tcph->seq));
49+
50+
/* Reply comes from server. */
51+
exp->saved_proto.tcp.port = exp->tuple.dst.u.tcp.port;
52+
exp->dir = IP_CT_DIR_REPLY;
53+
exp->expectfn = nf_nat_follow_master;
54+
55+
/* Try to get same port: if not, try to change it. */
56+
for (port = ntohs(exp->saved_proto.tcp.port); port != 0; port++) {
57+
exp->tuple.dst.u.tcp.port = htons(port);
58+
if (nf_conntrack_expect_related(exp) == 0)
59+
break;
60+
}
61+
62+
if (port == 0)
63+
return NF_DROP;
64+
65+
ip = ntohl(exp->master->tuplehash[IP_CT_DIR_REPLY].tuple.dst.u3.ip);
66+
sprintf(buffer, "%u %u", ip, port);
67+
DEBUGP("nf_nat_irc: inserting '%s' == %u.%u.%u.%u, port %u\n",
68+
buffer, NIPQUAD(ip), port);
69+
70+
ret = nf_nat_mangle_tcp_packet(pskb, exp->master, ctinfo,
71+
matchoff, matchlen, buffer,
72+
strlen(buffer));
73+
if (ret != NF_ACCEPT)
74+
nf_conntrack_unexpect_related(exp);
75+
return ret;
76+
}
77+
78+
static void __exit nf_nat_irc_fini(void)
79+
{
80+
rcu_assign_pointer(nf_nat_irc_hook, NULL);
81+
synchronize_rcu();
82+
}
83+
84+
static int __init nf_nat_irc_init(void)
85+
{
86+
BUG_ON(rcu_dereference(nf_nat_irc_hook));
87+
rcu_assign_pointer(nf_nat_irc_hook, help);
88+
return 0;
89+
}
90+
91+
/* Prior to 2.6.11, we had a ports param. No longer, but don't break users. */
92+
static int warn_set(const char *val, struct kernel_param *kp)
93+
{
94+
printk(KERN_INFO KBUILD_MODNAME
95+
": kernel >= 2.6.10 only uses 'ports' for conntrack modules\n");
96+
return 0;
97+
}
98+
module_param_call(ports, warn_set, NULL, NULL, 0);
99+
100+
module_init(nf_nat_irc_init);
101+
module_exit(nf_nat_irc_fini);

net/netfilter/Kconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,21 @@ config NF_CONNTRACK_H323
179179

180180
To compile it as a module, choose M here. If unsure, say N.
181181

182+
config NF_CONNTRACK_IRC
183+
tristate "IRC protocol support (EXPERIMENTAL)"
184+
depends on EXPERIMENTAL && NF_CONNTRACK
185+
help
186+
There is a commonly-used extension to IRC called
187+
Direct Client-to-Client Protocol (DCC). This enables users to send
188+
files to each other, and also chat to each other without the need
189+
of a server. DCC Sending is used anywhere you send files over IRC,
190+
and DCC Chat is most commonly used by Eggdrop bots. If you are
191+
using NAT, this extension will enable you to send files and initiate
192+
chats. Note that you do NOT need this extension to get files or
193+
have others initiate chats, or everything else in IRC.
194+
195+
To compile it as a module, choose M here. If unsure, say N.
196+
182197
config NF_CT_NETLINK
183198
tristate 'Connection tracking netlink interface (EXPERIMENTAL)'
184199
depends on EXPERIMENTAL && NF_CONNTRACK && NETFILTER_NETLINK

net/netfilter/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ nf_conntrack_h323-objs := nf_conntrack_h323_main.o nf_conntrack_h323_asn1.o
2525
obj-$(CONFIG_NF_CONNTRACK_AMANDA) += nf_conntrack_amanda.o
2626
obj-$(CONFIG_NF_CONNTRACK_FTP) += nf_conntrack_ftp.o
2727
obj-$(CONFIG_NF_CONNTRACK_H323) += nf_conntrack_h323.o
28+
obj-$(CONFIG_NF_CONNTRACK_IRC) += nf_conntrack_irc.o
2829

2930
# generic X tables
3031
obj-$(CONFIG_NETFILTER_XTABLES) += x_tables.o xt_tcpudp.o

0 commit comments

Comments
 (0)