Daemon News Ezine BSD News BSD Mall BSD Support Forum BSD Advocacy BSD Updates

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

fix for getipnodebyname(3)



getipnodebyname(3) as it stands in FreeBSD 4 and 5 has a problem
with nameserver timeouts or misconfiguration.

Symptom: getipnodebyname(3) lookups in unreachable/unconfigured
zones return h_errno=HOST_NOT_FOUND instead of h_errno=TRY_AGAIN.

It causes email to bounce at least with sendmail, which is quite
annoying.

Unless someone objects to it, I'd like to commit the following fix
to current later today. Since FreeBSD 4 is impacted too, the patch
will have to be adapted and MFC'd some day.

The only potential problem I see with my patch is that it accesses
h_errno, which is possibly not thread-safe. Could someone please
shed some light on this for me?

Pierre

--- name6.c.old	Wed Feb 25 23:27:17 2004
+++ name6.c	Mon Apr  5 14:19:31 2004
@@ -1565,7 +1565,8 @@
 					continue;
 				hp = _hpcopy(&hpbuf, errp);
 				hp0 = _hpmerge(hp0, hp, errp);
-			}
+			} else
+				*errp = h_errno;
 		}
 		if (hp0 != NULL) {
 			free(buf);
@@ -1604,7 +1605,8 @@
 						continue;
 					hp = _hpcopy(&hpbuf, errp);
 					hp0 = _hpmerge(hp0, hp, errp);
-				}
+				} else
+					*errp = h_errno;
 			}
 			if (hp0 != NULL) {
 				free(buf);
@@ -1677,7 +1679,8 @@
 					continue;
 				hp = _hpcopy(&hpbuf, errp);
 				hp0 = _hpmerge(hp0, hp, errp);
-			}
+			} else
+				*errp = h_errno;
 		}
 		if (hp0 != NULL) {
 			free(buf);
@@ -1739,7 +1742,12 @@
 	rtl = &rtl4;
 #endif
 	*(struct hostent **)rval = _res_search_multi(name, rtl, errp);
-	return (*(struct hostent **)rval != NULL) ? NS_SUCCESS : NS_NOTFOUND;
+	if (*(struct hostent **)rval != NULL)
+		return NS_SUCCESS;
+	else if (*errp == TRY_AGAIN)
+		return NS_TRYAGAIN;
+	else
+		return NS_NOTFOUND;
 }
 
 static int
-- 
Pierre Beyssac						pb@xxxxxxxxxxx