Date: Thu, 1 Feb 2007 13:36:18 GMT From: Paolo Pisati <piso@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 113829 for review Message-ID: <200702011336.l11DaIit098997@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
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);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200702011336.l11DaIit098997>