56#include <sys/limits.h>
58#include <sys/kernel.h>
59#include <sys/module.h>
84#define IRC_CONTROL_PORT_NUMBER_1 6667
85#define IRC_CONTROL_PORT_NUMBER_2 6668
87#define PKTSIZE (IP_MAXPACKET + 1)
172 int hlen, tlen, dlen;
180 tc = (
struct tcphdr *)ip_next(pip);
181 hlen = (pip->
ip_hl + tc->th_off) << 2;
182 tlen = ntohs(pip->
ip_len);
189 if (dlen < (
int)
sizeof(
":A!a@n.n PRIVMSG A :aDCC 1 1a") - 1)
199 for (i = 0; i < dlen; i++) {
200 if (sptr[i] ==
'\001')
207 unsigned int copyat = i;
208 unsigned int iCopy = 0;
210 unsigned long org_addr;
211 unsigned short org_port;
215 if (i >= dlen || iCopy >=
PKTSIZE)
222 if (sptr[i + 0] !=
'D')
224 if (sptr[i + 1] !=
'C')
226 if (sptr[i + 2] !=
'C')
228 if (sptr[i + 3] !=
' ')
244 while (sptr[i] ==
' ') {
246 DBprintf((
"DCC packet terminated in just spaces\n"));
251 DBprintf((
"Transferring command...\n"));
252 while (sptr[i] !=
' ') {
254 if (++i >= dlen || iCopy >=
PKTSIZE) {
255 DBprintf((
"DCC packet terminated during command\n"));
260 if (i + 1 < dlen && iCopy <
PKTSIZE)
263 DBprintf((
"Done command - removing spaces\n"));
268 while (sptr[i] ==
' ') {
270 DBprintf((
"DCC packet terminated in just spaces (post-command)\n"));
275 DBprintf((
"Transferring filename...\n"));
276 while (sptr[i] !=
' ') {
278 if (++i >= dlen || iCopy >=
PKTSIZE) {
279 DBprintf((
"DCC packet terminated during filename\n"));
284 if (i + 1 < dlen && iCopy <
PKTSIZE)
287 DBprintf((
"Done filename - removing spaces\n"));
292 while (sptr[i] ==
' ') {
294 DBprintf((
"DCC packet terminated in just spaces (post-filename)\n"));
299 DBprintf((
"Fetching IP address\n"));
302 while (i < dlen && isdigit(sptr[i])) {
303 if (org_addr > ULONG_MAX / 10UL) {
304 DBprintf((
"DCC Address overflow (org_addr == 0x%08lx, next char %c\n", org_addr, sptr[i]));
308 org_addr += sptr[i++] -
'0';
311 if (i + 1 >= dlen || sptr[i] !=
' ') {
312 DBprintf((
"Overflow (%d >= %d) or bad character (%02x) terminating IP address\n", i + 1, dlen, sptr[i]));
320 while (sptr[i] ==
' ') {
322 DBprintf((
"Packet failure - space overflow.\n"));
326 DBprintf((
"Fetching port number\n"));
329 while (i < dlen && isdigit(sptr[i])) {
330 if (org_port > 6554) {
332 DBprintf((
"DCC: port number overflow\n"));
336 org_port += sptr[i++] -
'0';
339 if (i >= dlen || (sptr[i] !=
'\001' && sptr[i] !=
' ')) {
340 DBprintf((
"Bad port termination\n"));
343 DBprintf((
"Got IP %lu and port %u\n", org_addr, (
unsigned)org_port));
350 true_port = htons(org_port);
351 true_addr.
s_addr = htonl(org_addr);
355 if (!org_addr || !org_port ||
356 pip->ip_src.s_addr != true_addr.
s_addr ||
357 org_port < IPPORT_RESERVED)
383 "%lu ", (u_long) htonl(alias_address.
s_addr));
385 DBprintf((
"DCC packet construct failure.\n"));
390 DBprintf((
"DCC constructed packet overflow.\n"));
396 "%u", htons(alias_port));
398 DBprintf((
"DCC packet construct failure.\n"));
406 DBprintf((
"Aliased IP %lu and port %u\n", alias_address.
s_addr, (
unsigned)alias_port));
415 for (; i < dlen && iCopy <
PKTSIZE; i++, iCopy++) {
417 if (sptr[i] ==
'\001') {
424 for (; i < dlen && iCopy <
PKTSIZE; i++, iCopy++) {
426 if (sptr[i] ==
'\001') {
432 iCopy = iCopy > maxsize - copyat ? maxsize - copyat : iCopy;
440 tc = (
struct tcphdr *)ip_next(pip);
442 AddSeq(lnk, delta + copyat + iCopy - dlen, pip->
ip_hl,
443 pip->
ip_len, tc->th_seq, tc->th_off);
450 new_len = htons(hlen + iCopy + copyat);
463 tc->th_sum = TcpChecksum(pip);
u_short GetAliasPort(struct alias_link *lnk)
void PunchFWHole(struct alias_link *lnk)
struct in_addr GetAliasAddress(struct alias_link *lnk)
void SetAckModified(struct alias_link *lnk)
void AddSeq(struct alias_link *lnk, int delta, u_int ip_hl, u_short ip_len, u_long th_seq, u_int th_off)
int GetDeltaSeqOut(u_long seq, struct alias_link *lnk)
struct alias_link * FindUdpTcpOut(struct libalias *la, struct in_addr src_addr, struct in_addr dst_addr, u_short src_port, u_short dst_port, u_char proto, int create)
static int mod_handler(module_t mod, int type, void *data)
#define IRC_CONTROL_PORT_NUMBER_2
static int fingerprint(struct libalias *la, struct alias_data *ah)
static moduledata_t alias_mod
#define IRC_CONTROL_PORT_NUMBER_1
static void AliasHandleIrcOut(struct libalias *, struct ip *, struct alias_link *, int maxpacketsize)
static int protohandler(struct libalias *la, struct ip *pip, struct alias_data *ah)
struct proto_handler handlers[]
MODULE_DEPEND(alias_irc, libalias, 1, 1, 1)
MODULE_VERSION(alias_irc, 1)
DECLARE_MODULE(alias_irc, alias_mod, SI_SUB_DRIVERS, SI_ORDER_SECOND)
void DifferentialChecksum(u_short *_cksum, void *_new, void *_old, int _n)
int LibAliasAttachHandlers(struct proto_handler *p)
int LibAliasDetachHandlers(struct proto_handler *p)