From owner-p4-projects@FreeBSD.ORG Sun Mar 23 22:10:31 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 0165C1065671; Sun, 23 Mar 2008 22:10:31 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B4561106566B for ; Sun, 23 Mar 2008 22:10:30 +0000 (UTC) (envelope-from piso@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 9E7C08FC1F for ; Sun, 23 Mar 2008 22:10:30 +0000 (UTC) (envelope-from piso@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id m2NMAUJn053769 for ; Sun, 23 Mar 2008 22:10:30 GMT (envelope-from piso@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id m2NMAU9n053767 for perforce@freebsd.org; Sun, 23 Mar 2008 22:10:30 GMT (envelope-from piso@freebsd.org) Date: Sun, 23 Mar 2008 22:10:30 GMT Message-Id: <200803232210.m2NMAU9n053767@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 138392 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, 23 Mar 2008 22:10:31 -0000 http://perforce.freebsd.org/chv.cgi?CH=138392 Change 138392 by piso@piso_newluxor on 2008/03/23 22:09:41 Modify kernel side of LibUnaliasOut to use mbuf. Affected files ... .. //depot/projects/soc2005/libalias/sys/netinet/libalias/alias.c#72 edit .. //depot/projects/soc2005/libalias/sys/netinet/libalias/alias.h#20 edit Differences ... ==== //depot/projects/soc2005/libalias/sys/netinet/libalias/alias.c#72 (text+ko) ==== @@ -1455,7 +1455,7 @@ } int -LibAliasUnaliasOut(struct libalias *la, char *ptr, /* valid IP packet */ +LibAliasUnaliasOut(struct libalias *la, pkt_t ptr, /* valid IP packet */ int maxpacketsize /* for error checking */ ) { @@ -1464,32 +1464,38 @@ struct udphdr *ud; struct tcphdr *tc; struct alias_link *lnk; - int iresult = PKT_ALIAS_IGNORED; + int iresult; LIBALIAS_LOCK(la); - pip = (struct ip *)ptr; + iresult = PKT_ALIAS_IGNORED; + ic = NULL; + ud = NULL; + tc = NULL; + PULLUP_IPHDR(pip, ptr); /* Defense against mangled packets */ if (ntohs(pip->ip_len) > maxpacketsize || (pip->ip_hl << 2) > maxpacketsize) goto getout; - ud = (struct udphdr *)ip_next(pip); - tc = (struct tcphdr *)ip_next(pip); - ic = (struct icmp *)ip_next(pip); - /* Find a link */ - if (pip->ip_p == IPPROTO_UDP) + if (pip->ip_p == IPPROTO_UDP) { + PULLUP_UDPHDR(pip, ptr); + ud = (struct udphdr *)ip_next(pip); lnk = FindUdpTcpIn(la, pip->ip_dst, pip->ip_src, ud->uh_dport, ud->uh_sport, IPPROTO_UDP, 0); - else if (pip->ip_p == IPPROTO_TCP) + } else if (pip->ip_p == IPPROTO_TCP) { + PULLUP_TCPHDR(pip, ptr); + tc = (struct tcphdr *)ip_next(pip); lnk = FindUdpTcpIn(la, pip->ip_dst, pip->ip_src, tc->th_dport, tc->th_sport, IPPROTO_TCP, 0); - else if (pip->ip_p == IPPROTO_ICMP) + } else if (pip->ip_p == IPPROTO_ICMP) { + PULLUP_ICMPHDR(pip, ptr); + ic = (struct icmp *)ip_next(pip); lnk = FindIcmpIn(la, pip->ip_dst, pip->ip_src, ic->icmp_id, 0); - else + } else lnk = NULL; /* Change it from an aliased packet to an unaliased packet */ ==== //depot/projects/soc2005/libalias/sys/netinet/libalias/alias.h#20 (text+ko) ==== @@ -96,10 +96,35 @@ if (pip != NULL && ((pip->ip_hl << 2) > sizeof(struct ip))) \ PULLUP_SIZE(pip, ptr, (pip->ip_hl << 2)); \ } while (0) + +#define PULLUP_UDPHDR(pip, ptr) do { \ + pip = mtod(*ptr, struct ip *); \ + PULLUP_SIZE(pip, ptr, (pip->ip_hl << 2) + sizeof(struct udphdr)); \ + } while (0) + +#define PULLUP_TCPHDR(pip, ptr) do { \ + struct tcphdr *th; \ + pip = mtod(*ptr, struct ip *); \ + PULLUP_SIZE(pip, ptr, (pip->ip_hl << 2) + sizeof(struct tcphdr)); \ + if (pip != NULL) { \ + th = (struct tcphdr *)&(((char *)pip)[pip->ip_hl << 2]); \ + if ((th->th_off << 2) > sizeof(struct tcphdr)) \ + PULLUP_SIZE(pip, ptr, ((pip->ip_hl + th->th_off) << \ + 2)); \ + } \ +} while (0) + +#define PULLUP_ICMPHDR(pip, ptr) do { \ + pip = mtod(*ptr, struct ip *); \ + PULLUP_SIZE(pip, ptr, (pip->ip_hl << 2) + sizeof(struct icmp)); \ +} while (0) #else typedef char * pkt_t; #define PULLUP_IPHDR(pip, ptr) pip = (struct ip *)ptr +#define PULLUP_UDPHDR(pip, ptr) +#define PULLUP_TCPHDR(pip, ptr) +#define PULLUP_ICMPHDR(pip, ptr) #endif /* Initialization and control functions. */ @@ -115,7 +140,12 @@ int LibAliasIn (struct libalias *, char *_ptr, int _maxpacketsize); int LibAliasOut(struct libalias *, char *_ptr, int _maxpacketsize); int LibAliasOutTry(struct libalias *, char *_ptr, int _maxpacketsize, int _create); +#ifdef _KERNEL +int LibAliasUnaliasOut(struct libalias *, struct mbuf **_ptr, + int _maxpacketsize); +#else int LibAliasUnaliasOut(struct libalias *, char *_ptr, int _maxpacketsize); +#endif /* Port and address redirection functions. */