PERFORCE change 114362 for review
Paolo Pisati
piso at FreeBSD.org
Sat Feb 10 19:18:36 UTC 2007
http://perforce.freebsd.org/chv.cgi?CH=114362
Change 114362 by piso at piso_newluxor on 2007/02/10 19:18:07
Teach mbuf to ftp libalias module.
Affected files ...
.. //depot/projects/soc2005/libalias/sys/netinet/libalias/alias_ftp.c#17 edit
Differences ...
==== //depot/projects/soc2005/libalias/sys/netinet/libalias/alias_ftp.c#17 (text+ko) ====
@@ -184,7 +184,7 @@
static int ParseFtpEprtCommand(struct libalias *la, char *, int);
static int ParseFtp227Reply(struct libalias *la, char *, int);
static int ParseFtp229Reply(struct libalias *la, char *, int);
-static void NewFtpMessage(struct libalias *la, struct ip *, struct alias_link *, int, int);
+static void NewFtpMessage(struct libalias *la, pkt_t, struct alias_link *, int, int);
static void
AliasHandleFtpOut(
@@ -199,6 +199,11 @@
struct ip *pip;
struct tcphdr *tc;
int ftp_message_type;
+ u_short dport;
+ in_addr_t s_addr;
+#ifdef _KERNEL
+ struct mbuf *m;
+#endif
/* Calculate data length of TCP packet */
PULLUP_TCPHDR(pip, ptr);
@@ -210,9 +215,8 @@
dlen = tlen - hlen;
/* Place string pointer and beginning of data */
- // XXX broken
- sptr = (char *)pip;
- sptr += hlen;
+ dport = ntohs(tc->th_dport);
+ s_addr = pip->ip_src.s_addr;
/*
* Check that data length is not too long and previous message was
@@ -222,7 +226,22 @@
if (dlen <= MAX_MESSAGE_SIZE && !(pflags & WAIT_CRLF)) {
ftp_message_type = FTP_UNKNOWN_MESSAGE;
- if (ntohs(tc->th_dport) == FTP_CONTROL_PORT_NUMBER) {
+#ifdef _KERNEL
+ if (tlen <= MHLEN) {
+ m = m_split(*ptr, hlen, M_TRYWAIT);
+ if (m == NULL)
+ return;
+ m = m_pullup(m, dlen);
+ } else
+ m = m_pullup(*ptr, tlen);
+ if (m == NULL)
+ return;
+ sptr = mtod(m, char *);
+#else
+ sptr = (char *)pip;
+ sptr += hlen;
+#endif
+ if (dport == FTP_CONTROL_PORT_NUMBER) {
/*
* When aliasing a client, check for the PORT/EPRT command.
*/
@@ -238,24 +257,41 @@
ftp_message_type = FTP_227_REPLY;
else if (ParseFtp229Reply(la, sptr, dlen)) {
ftp_message_type = FTP_229_REPLY;
- la->true_addr.s_addr = pip->ip_src.s_addr;
+ la->true_addr.s_addr = s_addr;
}
}
+#ifdef _KERNEL
+ if (tlen <= MHLEN)
+ m_cat(*ptr, m);
+#endif
if (ftp_message_type != FTP_UNKNOWN_MESSAGE)
- NewFtpMessage(la, pip, lnk, maxpacketsize, ftp_message_type);
+ NewFtpMessage(la, ptr, lnk, maxpacketsize, ftp_message_type);
}
/* Track the msgs which are CRLF term'd for PORT/PASV FW breach */
if (dlen) { /* only if there's data */
- sptr = (char *)pip; /* start over at beginning */
+ PULLUP_IPHDR(pip, ptr);
+ if (pip == NULL)
+ return;
tlen = ntohs(pip->ip_len); /* recalc tlen, pkt may
* have grown */
- if (sptr[tlen - 2] == '\r' && sptr[tlen - 1] == '\n')
+#ifdef _KERNEL
+ m = m_split(*ptr, tlen - 2, M_TRYWAIT);
+ m = m_pullup(m, 2);
+ sptr = mtod(m, char *);
+#else
+ sptr = (char *)pip; /* start over at beginning */
+ sptr += tlen - 2;
+#endif
+ if (sptr[0] == '\r' && sptr[1] == '\n')
pflags &= ~WAIT_CRLF;
else
pflags |= WAIT_CRLF;
SetProtocolFlags(lnk, pflags);
+#ifdef _KERNEL
+ m_cat(*ptr, m);
+#endif
}
}
@@ -641,12 +677,23 @@
}
static void
-NewFtpMessage(struct libalias *la, struct ip *pip,
+NewFtpMessage(struct libalias *la, pkt_t _ptr,
struct alias_link *lnk,
int maxpacketsize,
int ftp_message_type)
{
struct alias_link *ftp_lnk;
+ struct ip *pip;
+#ifdef _KERNEL
+ struct mbuf *m;
+#endif
+
+ PULLUP_IPHDR(pip, _ptr);
+ if (pip == NULL)
+ return;
+ PULLUP_TCPHDR(pip, _ptr);
+ if (pip == NULL)
+ return;
/* Security checks. */
if (pip->ip_src.s_addr != la->true_addr.s_addr)
@@ -677,7 +724,9 @@
/* Create new FTP message. */
{
char stemp[MAX_MESSAGE_SIZE + 1];
+#ifndef _KERNEL
char *sptr;
+#endif
u_short alias_port;
u_char *ptr;
int a1, a2, a3, a4, p1, p2;
@@ -728,10 +777,20 @@
slen = strlen(stemp);
/* Copy modified buffer into IP packet. */
+#ifdef _KERNEL
+ if (maxpacketsize == 0)
+ maxpacketsize = slen;
+ m = m_split(*_ptr, hlen, M_TRYWAIT);
+ m_copyback(*_ptr, 0, maxpacketsize, stemp);
+ m_cat(*_ptr, m);
+#else
sptr = (char *)pip;
sptr += hlen;
strncpy(sptr, stemp, maxpacketsize - hlen);
+#endif
}
+ PULLUP_IPHDR(pip, _ptr);
+ PULLUP_TCPHDR(pip, _ptr);
/* Save information regarding modified seq and ack numbers */
{
More information about the p4-projects
mailing list