[BACK]Return to res_private.h CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / lib / libc / resolv

File: [cvs.NetBSD.org] / src / lib / libc / resolv / res_private.h (download)

Revision 1.3.48.1, Tue Oct 5 11:06:58 2021 UTC (2 years, 6 months ago) by martin
Branch: netbsd-9
CVS Tags: netbsd-9-3-RELEASE
Changes since 1.3: +2 -1 lines

Pull up following revision(s) (requested by christos in ticket #1356):

	lib/libc/resolv/res_init.c: revision 1.32
	lib/libc/resolv/res_private.h: revision 1.4

kqueue(2) file descriptors are not inherited across fork(2). A
process that that calls getaddrinfo(3) will end up cacheing the
kqueue(2) file descriptor in its res_state structure. If that
process fork(2)s and calls getaddrinfo(3) again might end up closing
that cached file descriptor which can end up pointing to a different
file object than the kqueue(2) original one. To fix this, associate
the kqueue(2) file descriptor with the process id that created it,
and don't close(2) it if it is being closed from a different process.

An alternative fix would be to attach the resolver to a fork(2) hook
to cleanup the res_state, but handling it internally in the resolver
is less intrusive. This was discovered by Dima Veselov when using
the FreeRADIUS package.

/*	$NetBSD: res_private.h,v 1.3.48.1 2021/10/05 11:06:58 martin Exp $	*/

#ifndef res_private_h
#define res_private_h

struct __res_state_ext {
	union res_sockaddr_union nsaddrs[MAXNS];
	struct sort_list {
		int     af;
		union {
			struct in_addr  ina;
			struct in6_addr in6a;
		} addr, mask;
	} sort_list[MAXRESOLVSORT];
	char nsuffix[64];
	char nsuffix2[64];
	struct timespec res_conf_time;
	int kq, resfd;
	pid_t kqpid;
};

extern int res_ourserver_p(const res_state, const struct sockaddr *);
extern int __res_vinit(res_state, int);

#endif

/*! \file */