From owner-p4-projects@FreeBSD.ORG Sun Feb 4 13:44:16 2007 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 48FDB16A403; Sun, 4 Feb 2007 13:44:16 +0000 (UTC) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id E71EC16A400 for ; Sun, 4 Feb 2007 13:44:15 +0000 (UTC) (envelope-from piso@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [69.147.83.41]) by mx1.freebsd.org (Postfix) with ESMTP id D809913C4B4 for ; Sun, 4 Feb 2007 13:44:15 +0000 (UTC) (envelope-from piso@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.6/8.13.6) with ESMTP id l14DiFq0003526 for ; Sun, 4 Feb 2007 13:44:15 GMT (envelope-from piso@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id l14DiFRx003523 for perforce@freebsd.org; Sun, 4 Feb 2007 13:44:15 GMT (envelope-from piso@freebsd.org) Date: Sun, 4 Feb 2007 13:44:15 GMT Message-Id: <200702041344.l14DiFRx003523@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to piso@freebsd.org using -f From: Paolo Pisati To: Perforce Change Reviews Cc: Subject: PERFORCE change 113996 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 04 Feb 2007 13:44:16 -0000 http://perforce.freebsd.org/chv.cgi?CH=113996 Change 113996 by piso@piso_newluxor on 2007/02/04 13:43:51 o move the PULLUP* macros to alias_local.h (so they can be used anywhere in libalias) o teach mbuf to ProxyEncodeIpHeader() Affected files ... .. //depot/projects/soc2005/libalias/sys/netinet/libalias/alias.c#53 edit .. //depot/projects/soc2005/libalias/sys/netinet/libalias/alias_local.h#18 edit .. //depot/projects/soc2005/libalias/sys/netinet/libalias/alias_proxy.c#18 edit Differences ... ==== //depot/projects/soc2005/libalias/sys/netinet/libalias/alias.c#53 (text+ko) ==== @@ -143,53 +143,6 @@ #include "alias_mod.h" #endif -#ifdef _KERNEL - -#define PULLUP_IPHDR(pip, ptr) do { \ - struct mbuf *m; \ - m = m_pullup((ptr), sizeof(struct ip)); \ - (pip) = mtod(m, struct ip *); \ -} while (0) - -#define PULLUP_UDPHDR(pip, ptr) do { \ - struct mbuf *m; \ - pip = ptr; \ - m = m_pullup((ptr), (pip->ip_hl << 2) + sizeof(struct udphdr)); \ - (pip) = mtod(m, struct ip *); \ -} while (0) - -#define PULLUP_TCPHDR(pip, ptr) do { \ - struct mbuf *m; \ - pip = ptr; \ - m = m_pullup((ptr), (pip->ip_hl << 2) + sizeof(struct tcphdr)); \ - (pip) = mtod(m, struct ip *); \ -} while (0) - -#define PULLUP_ICMPHDR(pip, ptr) do { \ - struct mbuf *m; \ - pip = (struct ip *)ptr; \ - m = m_pullup((ptr), (pip->ip_hl << 2) + sizeof(struct icmp)); \ - (pip) = mtod(m, struct ip *); \ -} while (0) - -#define PULLUP_ICMPIP64(pip, ptr, ic) do { \ - struct mbuf *m; \ - int s; \ - pip = ptr; \ - s = (pip->ip_hl << 2) + sizeof(struct icmp) + \ - (ic->icmp_ip.ip_hl << 2) - sizeof(struct ip) + 8; \ - m = m_pullup((ptr), s); \ - (pip) = mtod(m, struct ip *); \ -} while (0) - -#else -#define PULLUP_IPHDR(pip, ptr) pip = (struct ip *)ptr -#define PULLUP_UDPHDR(pip, ptr) pip = ptr -#define PULLUP_TCPHDR(pip, ptr) pip = ptr -#define PULLUP_ICMPHDR(pip, ptr) pip = (struct ip *)ptr -#define PULLUP_ICMPIP64(pip, ptr, ic) pip = ptr -#endif - static __inline int twowords(void *p) { @@ -1102,7 +1055,7 @@ SetProxyPort(lnk, dest_port); SetProxyAddress(lnk, dest_address); // XXX broken - ProxyModify(la, lnk, pip, maxpacketsize, proxy_type, + ProxyModify(la, lnk, ptr, maxpacketsize, proxy_type, src_port); // XXX m_pullup() tc = (struct tcphdr *)ip_next(pip); ==== //depot/projects/soc2005/libalias/sys/netinet/libalias/alias_local.h#18 (text+ko) ==== @@ -54,6 +54,8 @@ #include #include #include +#include +#include /* XXX: LibAliasSetTarget() uses this constant. */ #define INADDR_NONE 0xffffffff @@ -174,6 +176,53 @@ #define LIBALIAS_LOCK_DESTROY(l) #endif +#ifdef _KERNEL + +#define PULLUP_IPHDR(pip, ptr) do { \ + struct mbuf *m; \ + m = m_pullup((ptr), sizeof(struct ip)); \ + (pip) = mtod(m, struct ip *); \ +} while (0) + +#define PULLUP_UDPHDR(pip, ptr) do { \ + struct mbuf *m; \ + pip = ptr; \ + m = m_pullup((ptr), (pip->ip_hl << 2) + sizeof(struct udphdr)); \ + (pip) = mtod(m, struct ip *); \ +} while (0) + +#define PULLUP_TCPHDR(pip, ptr) do { \ + struct mbuf *m; \ + pip = ptr; \ + m = m_pullup((ptr), (pip->ip_hl << 2) + sizeof(struct tcphdr)); \ + (pip) = mtod(m, struct ip *); \ +} while (0) + +#define PULLUP_ICMPHDR(pip, ptr) do { \ + struct mbuf *m; \ + pip = (struct ip *)ptr; \ + m = m_pullup((ptr), (pip->ip_hl << 2) + sizeof(struct icmp)); \ + (pip) = mtod(m, struct ip *); \ +} while (0) + +#define PULLUP_ICMPIP64(pip, ptr, ic) do { \ + struct mbuf *m; \ + int s; \ + pip = ptr; \ + s = (pip->ip_hl << 2) + sizeof(struct icmp) + \ + (ic->icmp_ip.ip_hl << 2) - sizeof(struct ip) + 8; \ + m = m_pullup((ptr), s); \ + (pip) = mtod(m, struct ip *); \ +} while (0) + +#else +#define PULLUP_IPHDR(pip, ptr) pip = (struct ip *)ptr +#define PULLUP_UDPHDR(pip, ptr) pip = ptr +#define PULLUP_TCPHDR(pip, ptr) pip = ptr +#define PULLUP_ICMPHDR(pip, ptr) pip = (struct ip *)ptr +#define PULLUP_ICMPIP64(pip, ptr, ic) pip = ptr +#endif + /* * The following macro is used to update an * internet checksum. "delta" is a 32-bit @@ -329,7 +378,7 @@ ProxyCheck(struct libalias *la, struct ip *_pip, struct in_addr *_proxy_server_addr, u_short * _proxy_server_port, u_short dst_port); void -ProxyModify(struct libalias *la, struct alias_link *_lnk, struct ip *_pip, +ProxyModify(struct libalias *la, struct alias_link *_lnk, void *_pip, int _maxpacketsize, int _proxy_type, u_short src_port); enum alias_tcp_state { ==== //depot/projects/soc2005/libalias/sys/netinet/libalias/alias_proxy.c#18 (text+ko) ==== @@ -147,7 +147,7 @@ static void RuleDelete(struct proxy_entry *); static int RuleNumberDelete(struct libalias *la, int); static void ProxyEncodeTcpStream(struct alias_link *, struct ip *, int); -static void ProxyEncodeIpHeader(struct ip *, u_short sport); +static void ProxyEncodeIpHeader(void *, u_short sport); #ifdef _KERNEL static int @@ -480,13 +480,18 @@ } static void -ProxyEncodeIpHeader(struct ip *pip, u_short sport) +ProxyEncodeIpHeader(void *_ptr, u_short sport) { + struct ip *pip; #define OPTION_LEN_BYTES 8 #define OPTION_LEN_INT16 4 #define OPTION_LEN_INT32 2 u_char option[OPTION_LEN_BYTES]; + PULLUP_IPHDR(pip, _ptr); + if (pip == NULL) + return; + #ifdef LIBALIAS_DEBUG fprintf(stdout, " ip cksum 1 = %x\n", (u_int) IpChecksum(pip)); fprintf(stdout, "tcp cksum 1 = %x\n", (u_int) TcpChecksum(pip)); @@ -498,11 +503,15 @@ /* Build option and copy into packet */ { +#ifdef _KERNEL + struct mbuf *m; +#else u_char *ptr; ptr = (u_char *) pip; ptr += 20; memcpy(ptr + OPTION_LEN_BYTES, ptr, ntohs(pip->ip_len) - 20); +#endif option[0] = 0x64; /* class: 3 (reserved), option 4 */ option[1] = OPTION_LEN_BYTES; @@ -511,7 +520,17 @@ memcpy(&option[6], (u_char *) & sport, 2); +#ifdef _KERNEL + // XXX - here i assume after an m_split() there's always enough + // XXX - space to append option[] to _ptr + m = m_split(_ptr, 20, M_TRYWAIT); + if (m == NULL) + return; + m_copyback(_ptr, 20, 8, option); + m_cat(_ptr, m); +#else memcpy(ptr, option, 8); +#endif } /* Update checksum, header length and packet length */ @@ -520,12 +539,19 @@ int accumulate; u_short *sptr; + PULLUP_IPHDR(pip, _ptr); + if (pip == NULL) + return; + sptr = (u_short *) option; accumulate = 0; for (i = 0; i < OPTION_LEN_INT16; i++) accumulate -= *(sptr++); - +#ifdef _KERNEL + sptr = mtod((struct mbuf *)_ptr, u_short *); +#else sptr = (u_short *) pip; +#endif accumulate += *sptr; pip->ip_hl += OPTION_LEN_INT32; accumulate -= *sptr; @@ -597,19 +623,21 @@ } void -ProxyModify(struct libalias *la, struct alias_link *lnk, struct ip *pip, +ProxyModify(struct libalias *la, struct alias_link *lnk, void *ptr, int maxpacketsize, int proxy_type, u_short src_port) { + struct ip *pip; LIBALIAS_LOCK_ASSERT(la); (void)la; switch (proxy_type) { case PROXY_TYPE_ENCODE_IPHDR: - ProxyEncodeIpHeader(pip, src_port); + ProxyEncodeIpHeader(ptr, src_port); break; case PROXY_TYPE_ENCODE_TCPSTREAM: + PULLUP_IPHDR(pip, ptr); ProxyEncodeTcpStream(lnk, pip, maxpacketsize); break; }