Date: Fri, 16 Feb 2007 20:39:29 GMT From: Paolo Pisati <piso@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 114641 for review Message-ID: <200702162039.l1GKdT28092998@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=114641 Change 114641 by piso@piso_newluxor on 2007/02/16 20:39:23 Introduce a per-instance of libalias buffer of memory that will be used to temporary hold the entire mbuf-chain in a 'flat' format (like a contiguous chunk of memory): used only for irc, nbt and smedia modules cause fixing these modules to grok mbuf was too much of a pain without a complete rewrite. Affected files ... .. //depot/projects/soc2005/libalias/sys/netinet/libalias/alias_db.c#24 edit .. //depot/projects/soc2005/libalias/sys/netinet/libalias/alias_irc.c#20 edit .. //depot/projects/soc2005/libalias/sys/netinet/libalias/alias_local.h#26 edit .. //depot/projects/soc2005/libalias/sys/netinet/libalias/alias_nbt.c#15 edit .. //depot/projects/soc2005/libalias/sys/netinet/libalias/alias_smedia.c#19 edit Differences ... ==== //depot/projects/soc2005/libalias/sys/netinet/libalias/alias_db.c#24 (text+ko) ==== @@ -2538,6 +2538,11 @@ #ifdef _KERNEL la->timeStamp = time_uptime; la->lastCleanupTime = time_uptime; + la->buff = malloc(PKT_BUFF); + if (la->buff == NULL) { + free (la); + return (NULL); + } #else gettimeofday(&tv, &tz); la->timeStamp = tv.tv_sec; @@ -2602,6 +2607,9 @@ LIST_REMOVE(la, instancelist); LIBALIAS_UNLOCK(la); LIBALIAS_LOCK_DESTROY(la); +#ifdef _KERNEL + free(la->buff); +#endif free(la); } ==== //depot/projects/soc2005/libalias/sys/netinet/libalias/alias_irc.c#20 (text+ko) ==== @@ -170,9 +170,6 @@ struct ip *pip; struct tcphdr *tc; int i; /* Iterator through the source */ -#ifdef _KERNEL - char mpkt[65536]; -#endif /* Calculate data length of TCP packet */ PULLUP_TCPHDR(pip, ptr); @@ -205,16 +202,16 @@ * o 2k < pkt < 4k: use a 4k mbuf cluster (jumbo) * o 4k < pkt < 9k: use a 9k mbuf cluster (jumbo9) * o 9k < pkt < 16k: use a 16k mbuf cluster (jumbo16) - * o pkt > 16k: use mpkt buffer (worst case) + * o pkt > 16k: use la->buff buffer (worst case) * * WATCH OUT: pkt could grow, so beware of boundaries in case * an mbuf/mbuf cluster is used, check maxsize. */ // XXX so far only the worst case is implemented... - m_copydata(*ptr, hlen, m_length(*ptr, NULL), mpkt); - sptr = mpkt; - maxsize = 65536; /* size of mpkt */ + m_copydata(*ptr, hlen, m_length(*ptr, NULL), la->buff); + sptr = la->buff; + maxsize = PKT_BUFF; /* size of packet buffer */ #else sptr = (char *)pip; sptr += hlen; ==== //depot/projects/soc2005/libalias/sys/netinet/libalias/alias_local.h#26 (text+ko) ==== @@ -156,6 +156,18 @@ * avoid races in libalias: every public function has to use it. */ struct mtx mutex; + /* + * some modules (irc, nbt and smedia) need a contiguos buffer of + * memory to work properly, so copy the entire mbuf chain here + * and pass this buffer to them. + * On return, copy back the data from this buffer to an mbuf + * chain. + * XXX this is supposed to be a stop gap solution until a brave soul + * (NdPiso me?) rewrite these modules to properly handle an mbuf + * chain. + */ +#define PKT_BUFF 65536 + char *buff; #endif }; ==== //depot/projects/soc2005/libalias/sys/netinet/libalias/alias_nbt.c#15 (text+ko) ==== @@ -350,18 +350,24 @@ NbtDataHeader *ndh; u_char *p = NULL; char *pmax; +#ifdef _KERNEL + int size; +#endif (void)la; (void)lnk; /* Calculate data length of UDP packet */ - PULLUP_UDPHDR(pip ,ptr); - if (pip == NULL) - return (-1); +#ifdef _KERNEL + size = m_length(*ptr, NULL); + m_copydata(*ptr, 0, m_length(*ptr, NULL), la->buff); + pip = (struct ip *)la->buff; +#else + pip = (struct ip *)ptr; +#endif uh = (struct udphdr *)ip_next(pip); pmax = (char *)uh + ntohs(uh->uh_ulen); - // XXX broken ndh = (NbtDataHeader *)udp_next(uh); if ((char *)(ndh + 1) > pmax) return (-1); @@ -412,6 +418,9 @@ printf("%s:%d\n", inet_ntoa(ndh->source_ip), ntohs(ndh->source_port)); fflush(stdout); #endif +#ifdef _KERNEL + m_copyback(*ptr, 0, size, la->buff); +#endif return ((p == NULL) ? -1 : 0); } @@ -785,6 +794,9 @@ u_char *p; char *pmax; NBTArguments nbtarg; +#ifdef _KERNEL + int size; +#endif (void)la; (void)lnk; @@ -802,9 +814,13 @@ alias_address = NULL; /* Calculate data length of UDP packet */ - PULLUP_UDPHDR(pip, ptr); - if (pip == NULL) - return (-1); +#ifdef _KERNEL + size = m_length(*ptr, NULL); + m_copydata(*ptr, 0, m_length(*ptr, NULL), la->buff); + pip = (struct ip *)la->buff; +#else + pip = (struct ip *)ptr; +#endif uh = (struct udphdr *)ip_next(pip); nbtarg.uh_sum = &(uh->uh_sum); nsh = (NbtNSHeader *)udp_next(uh); @@ -869,5 +885,8 @@ #ifdef LIBALIAS_DEBUG PrintRcode(nsh->rcode); #endif +#ifdef _KERNEL + m_copyback(*ptr, 0, size, la->buff); +#endif return ((p == NULL) ? -1 : 0); } ==== //depot/projects/soc2005/libalias/sys/netinet/libalias/alias_smedia.c#19 (text+ko) ==== @@ -489,16 +489,19 @@ const char *okstr = "OK", *client_port_str = "client_port"; const char *server_port_str = "server_port"; int i, parseOk; +#ifdef _KERNEL + int size; - PULLUP_TCPHDR(pip, ptr); - if (pip == NULL) - return; + size = m_length(*ptr, NULL); + m_copydata(*ptr, 0, m_length(*ptr, NULL), la->buff); + pip = (struct ip *)la->buff; +#else + pip = (struct ip *)ptr; +#endif tc = (struct tcphdr *)ip_next(pip); hlen = (pip->ip_hl + tc->th_off) << 2; tlen = ntohs(pip->ip_len); dlen = tlen - hlen; - - // XXX broken data = (char *)pip; data += hlen; @@ -549,4 +552,7 @@ } } } +#ifdef _KERNEL + m_copyback(*ptr, 0, size, la->buff); +#endif }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200702162039.l1GKdT28092998>