Date: Sun, 23 Mar 2008 22:10:30 GMT From: Paolo Pisati <piso@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 138392 for review Message-ID: <200803232210.m2NMAU9n053767@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
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. */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200803232210.m2NMAU9n053767>