From owner-p4-projects@FreeBSD.ORG Thu Feb 1 13:36:19 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 6A87016A409; Thu, 1 Feb 2007 13:36:19 +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 34FE616A405 for ; Thu, 1 Feb 2007 13:36:19 +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 188B413C481 for ; Thu, 1 Feb 2007 13:36:19 +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 l11DaI06099025 for ; Thu, 1 Feb 2007 13:36:18 GMT (envelope-from piso@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id l11DaIit098997 for perforce@freebsd.org; Thu, 1 Feb 2007 13:36:18 GMT (envelope-from piso@freebsd.org) Date: Thu, 1 Feb 2007 13:36:18 GMT Message-Id: <200702011336.l11DaIit098997@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 113829 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: Thu, 01 Feb 2007 13:36:19 -0000 http://perforce.freebsd.org/chv.cgi?CH=113829 Change 113829 by piso@piso_newluxor on 2007/02/01 13:35:36 Teach mbuf to IcmpAlias[In|Out]*(). Affected files ... .. //depot/projects/soc2005/libalias/sys/netinet/libalias/alias.c#50 edit Differences ... ==== //depot/projects/soc2005/libalias/sys/netinet/libalias/alias.c#50 (text+ko) ==== @@ -165,10 +165,29 @@ (pip) = mtod(m, struct ip *); \ } while (0) +#define PULLUP_ICMPHDR(pip, ptr) do { \ + struct mbuf *m; \ + pip = 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 = ptr #define PULLUP_UDPHDR(pip, ptr) pip = ptr #define PULLUP_TCPHDR(pip, ptr) pip = ptr +#define PULLUP_ICMPHDR(pip, ptr) pip = ptr +#define PULLUP_ICMPIP64(pip, ptr, ic) pip = ptr #endif static __inline int @@ -284,12 +303,12 @@ /* Local prototypes */ -static int IcmpAliasIn1(struct libalias *, void *); -static int IcmpAliasIn2(struct libalias *, void *); +static int IcmpAliasIn1(struct libalias *, struct ip *); +static int IcmpAliasIn2(struct libalias *, struct ip *); static int IcmpAliasIn(struct libalias *, void *); -static int IcmpAliasOut1(struct libalias *, void *, int create); -static int IcmpAliasOut2(struct libalias *, void *); +static int IcmpAliasOut1(struct libalias *, struct ip *, int create); +static int IcmpAliasOut2(struct libalias *, struct ip *); static int IcmpAliasOut(struct libalias *, void *, int create); static int ProtoAliasIn(struct libalias *, struct ip *); @@ -303,17 +322,10 @@ static int -IcmpAliasIn1(struct libalias *la, void *ptr) +IcmpAliasIn1(struct libalias *la, struct ip *pip) { struct alias_link *lnk; - struct ip *pip; struct icmp *ic; -#ifdef _KERNEL - // XXX - m_pullup() - pip = ptr; -#else - pip = ptr; -#endif LIBALIAS_LOCK_ASSERT(la); /* De-alias incoming echo and timestamp replies. @@ -354,25 +366,18 @@ } static int -IcmpAliasIn2(struct libalias *la, void *ptr) +IcmpAliasIn2(struct libalias *la, struct ip *pip) { /* Alias incoming ICMP error messages containing IP header and first 64 bits of datagram. */ - struct ip *ip, *pip; + struct ip *ip; struct icmp *ic, *ic2; struct udphdr *ud; struct tcphdr *tc; struct alias_link *lnk; -#ifdef _KERNEL - // XXX - m_pullup() - pip = ptr; -#else - pip = ptr; -#endif - LIBALIAS_LOCK_ASSERT(la); ic = (struct icmp *)ip_next(pip); ip = &ic->icmp_ip; @@ -467,37 +472,37 @@ int iresult; struct ip *pip; struct icmp *ic; -#ifdef _KERNEL - // XXX - m_pullup() - pip = ptr; -#else - pip = ptr; -#endif - + LIBALIAS_LOCK_ASSERT(la); /* Return if proxy-only mode is enabled */ if (la->packetAliasMode & PKT_ALIAS_PROXY_ONLY) return (PKT_ALIAS_OK); + iresult = PKT_ALIAS_IGNORED; + PULLUP_ICMPHDR(pip, ptr); + if (pip == NULL) + return (iresult); ic = (struct icmp *)ip_next(pip); - iresult = PKT_ALIAS_IGNORED; switch (ic->icmp_type) { case ICMP_ECHOREPLY: case ICMP_TSTAMPREPLY: if (ic->icmp_code == 0) { - iresult = IcmpAliasIn1(la, ptr); + iresult = IcmpAliasIn1(la, pip); } break; case ICMP_UNREACH: case ICMP_SOURCEQUENCH: case ICMP_TIMXCEED: case ICMP_PARAMPROB: - iresult = IcmpAliasIn2(la, ptr); + PULLUP_ICMPIP64(pip, ptr, ic); + if (pip == NULL) + return (iresult); + iresult = IcmpAliasIn2(la, pip); break; case ICMP_ECHO: case ICMP_TSTAMP: - iresult = IcmpAliasIn1(la, ptr); + iresult = IcmpAliasIn1(la, pip); break; } return (iresult); @@ -505,21 +510,14 @@ static int -IcmpAliasOut1(struct libalias *la, void *ptr, int create) +IcmpAliasOut1(struct libalias *la, struct ip *pip, int create) { /* Alias outgoing echo and timestamp requests. De-alias outgoing echo and timestamp replies. */ struct alias_link *lnk; - struct ip *pip; struct icmp *ic; -#ifdef _KERNEL - // XXX m_pullup() - pip = ptr; -#else - pip = ptr; -#endif LIBALIAS_LOCK_ASSERT(la); ic = (struct icmp *)ip_next(pip); @@ -557,23 +555,17 @@ static int -IcmpAliasOut2(struct libalias *la, void *ptr) +IcmpAliasOut2(struct libalias *la, struct ip *pip) { /* Alias outgoing ICMP error messages containing IP header and first 64 bits of datagram. */ - struct ip *ip, *pip; + struct ip *ip; struct icmp *ic, *ic2; struct udphdr *ud; struct tcphdr *tc; struct alias_link *lnk; -#ifdef _KERNEL - // XXX m_pullup() - pip = ptr; -#else - pip = ptr; -#endif LIBALIAS_LOCK_ASSERT(la); ic = (struct icmp *)ip_next(pip); @@ -669,12 +661,6 @@ int iresult; struct icmp *ic; struct ip *pip; -#ifdef _KERNEL - // XXX m_pullup() - pip = ptr; -#else - pip = ptr; -#endif LIBALIAS_LOCK_ASSERT(la); (void)create; @@ -683,25 +669,31 @@ if (la->packetAliasMode & PKT_ALIAS_PROXY_ONLY) return (PKT_ALIAS_OK); + iresult = PKT_ALIAS_IGNORED; + PULLUP_ICMPHDR(pip, ptr); + if (pip == NULL) + return (iresult); ic = (struct icmp *)ip_next(pip); - iresult = PKT_ALIAS_IGNORED; switch (ic->icmp_type) { case ICMP_ECHO: case ICMP_TSTAMP: if (ic->icmp_code == 0) { - iresult = IcmpAliasOut1(la, ptr, create); + iresult = IcmpAliasOut1(la, pip, create); } break; case ICMP_UNREACH: case ICMP_SOURCEQUENCH: case ICMP_TIMXCEED: case ICMP_PARAMPROB: - iresult = IcmpAliasOut2(la, ptr); + PULLUP_ICMPIP64(pip, ptr, ic); + if (pip == NULL) + return (iresult); + iresult = IcmpAliasOut2(la, pip); break; case ICMP_ECHOREPLY: case ICMP_TSTAMPREPLY: - iresult = IcmpAliasOut1(la, ptr, create); + iresult = IcmpAliasOut1(la, pip, create); } return (iresult); } @@ -1348,7 +1340,7 @@ if ((ntohs(pip->ip_off) & IP_OFFMASK) == 0) { switch (pip->ip_p) { case IPPROTO_ICMP: - iresult = IcmpAliasIn(la, pip); + iresult = IcmpAliasIn(la, ptr); break; case IPPROTO_UDP: iresult = UdpAliasIn(la, ptr); @@ -1499,7 +1491,7 @@ if ((ntohs(pip->ip_off) & IP_OFFMASK) == 0) { switch (pip->ip_p) { case IPPROTO_ICMP: - iresult = IcmpAliasOut(la, pip, create); + iresult = IcmpAliasOut(la, ptr, create); break; case IPPROTO_UDP: iresult = UdpAliasOut(la, ptr, create);