Date: Sat, 9 Dec 2006 21:01:39 GMT From: Paolo Pisati <piso@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 111341 for review Message-ID: <200612092101.kB9L1dW1078125@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=111341 Change 111341 by piso@piso_newluxor on 2006/12/09 21:01:37 Introduce LibAliasInLocked() & LibAliasOutLocked() for the PKT_ALIAS_REVERSE case: using these functions we avoid a dangerous drop and reacquire of the lock around a call to LibAliasIn*()/LibAliasOut*(). Suggested by: glebius Affected files ... .. //depot/projects/soc2005/libalias/sys/netinet/libalias/alias.c#26 edit Differences ... ==== //depot/projects/soc2005/libalias/sys/netinet/libalias/alias.c#26 (text+ko) ==== @@ -1211,20 +1211,35 @@ LIBALIAS_UNLOCK(la); } +/* Local prototypes */ +static int +LibAliasOutLocked(struct libalias *la, char *ptr, + int maxpacketsize); +static int +LibAliasInLocked(struct libalias *la, char *ptr, + int maxpacketsize); int LibAliasIn(struct libalias *la, char *ptr, int maxpacketsize) { + int res; + + LIBALIAS_LOCK(la); + res = LibAliasInLocked(la, ptr, maxpacketsize); + LIBALIAS_LOCK(la); + return (res); +} + +static int +LibAliasInLocked(struct libalias *la, char *ptr, int maxpacketsize) +{ struct in_addr alias_addr; struct ip *pip; int iresult; - - LIBALIAS_LOCK(la); + if (la->packetAliasMode & PKT_ALIAS_REVERSE) { la->packetAliasMode &= ~PKT_ALIAS_REVERSE; - LIBALIAS_UNLOCK(la); - iresult = LibAliasOut(la, ptr, maxpacketsize); - LIBALIAS_LOCK(la); + iresult = LibAliasOutLocked(la, ptr, maxpacketsize); la->packetAliasMode |= PKT_ALIAS_REVERSE; goto getout; } @@ -1293,7 +1308,6 @@ } getout: - LIBALIAS_UNLOCK(la); return (iresult); } @@ -1314,31 +1328,31 @@ #define UNREG_ADDR_C_UPPER 0xc0a8ffff int -LibAliasOut(struct libalias *la, char *ptr, /* valid IP packet */ - int maxpacketsize /* How much the packet data may grow (FTP - * and IRC inline changes) */ -) +LibAliasOut(struct libalias *la, char *ptr, int maxpacketsize) { - return (LibAliasOutTry(la, ptr, maxpacketsize, 1)); + int res; + + LIBALIAS_LOCK(la); + res = LibAliasOutLocked(la, ptr, maxpacketsize); + LIBALIAS_UNLOCK(la); + return (res); } -int -LibAliasOutTry(struct libalias *la, char *ptr, /* valid IP packet */ - int maxpacketsize, /* How much the packet data may grow (FTP +static int +LibAliasOutLocked(struct libalias *la, char *ptr, /* valid IP packet */ + int maxpacketsize /* How much the packet data may grow (FTP * and IRC inline changes) */ - int create /* Create new entries ? */ ) { int iresult; + int create; /* Create new entries ? */ struct in_addr addr_save; struct ip *pip; - LIBALIAS_LOCK(la); + create = 1; if (la->packetAliasMode & PKT_ALIAS_REVERSE) { la->packetAliasMode &= ~PKT_ALIAS_REVERSE; - LIBALIAS_UNLOCK(la); - iresult = LibAliasIn(la, ptr, maxpacketsize); - LIBALIAS_LOCK(la); + iresult = LibAliasInLocked(la, ptr, maxpacketsize); la->packetAliasMode |= PKT_ALIAS_REVERSE; goto getout; } @@ -1414,7 +1428,6 @@ SetDefaultAliasAddress(la, addr_save); getout: - LIBALIAS_UNLOCK(la); return (iresult); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200612092101.kB9L1dW1078125>