[PATCH] Make link-local addresses resolvable via running avahi-daemon.

Mike Frysinger vapier at gentoo.org
Sun Nov 27 01:03:07 UTC 2011


On Wednesday 23 November 2011 08:31:33 Nikolaus Voss wrote:
> nss-mdns is an extension to glibc to support resolution of link-local
> (.local) addresses via GNU Name Service Switch (NSS) which redirects
> the queries to a running avahi-daemon, which in turn does the resolution
> via multicast DNS (mdns).
> 
> However, this does not work for uClibc, as it does not support NSS.

since we don't support NSS (or any similar approach), this is unfortunately 
the only way to handle things.  if we get more requests, perhaps we can look 
at adding an array of callbacks which the resolv code would walk ...

> --- /dev/null
> +++ b/libc/inet/avahi.c
>
> +int __avahi_resolve_name(int af, const char* name, void* data)
> attribute_hidden;
> +int __avahi_resolve_address(int af, const void *data, char* name,
> +			    size_t name_len) attribute_hidden;

once you have a local header, you can delete this

> +static int set_cloexec(int fd)
> +static FILE *open_socket(void)

please add "avahi" prefixes to these (yes, even though they're static)

> +static int set_cloexec(int fd)
> +{
> +	int n;
> +
> +	assert(fd >= 0);
> +
> +	if ((n = fcntl(fd, F_GETFD)) < 0)
> +		return -1;
> +
> +	if (n & FD_CLOEXEC)
> +		return 0;
> +
> +	return fcntl(fd, F_SETFD, n|FD_CLOEXEC);
> +}

delete this func ...

> +static FILE *open_socket(void)
> +{
> +	int fd = -1;
> +	struct sockaddr_un sa;
> +	FILE *f = NULL;
> +
> +	if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
> +		goto fail;

add SOCK_CLOEXEC to the type field

> +	set_cloexec(fd);

add __ASSUME_SOCK_CLOEXEC to sysdeps/linux/common/bits/kernel-features.h (see 
the file in glibc).  then use:
#ifndef __ASSUME_SOCK_CLOEXEC
	fcntl_not_cancel(fd, F_SETFD, FD_CLOEXEC);
#endif

i don't think there's any actual flags we need to worry about here ?

> +	if (!(f = fdopen(fd, "r+")))
> +		goto fail;

i wonder if we really need to use the stdio layer here.  we currently always 
build dprintf(), and that seems to be the only real reason for it ...

> +	fprintf(f, "RESOLVE-HOSTNAME%s %s\n", af == AF_INET ? "-IPV4" : "-IPV6",
> name);

might as well trim this slightly:
	fprintf(f, "RESOLVE-HOSTNAME-IPV%c %s\n", af == AF_INET ? 4 : 6, name);

> +	if (!(fgets(ln, sizeof(ln), f)))

don't need the paren around fgets here

> +	/* Cut off end of line */
> +	*(p + strcspn(p, "\n\r\t ")) = 0;

p[strcspn(p, "\n\r\t ")] = 0;

> --- a/libc/inet/resolv.c
> +++ b/libc/inet/resolv.c
>
> +#ifdef __UCLIBC_HAS_AVAHI_RES__
> +extern int __avahi_resolve_name(int af, const char* name,
> +				void* data) attribute_hidden;
> +
> +extern int __avahi_resolve_address(int af, const void *data, char* name,
> +				   size_t name_len) attribute_hidden;
> +#endif

please add a local header file for this.  most of the local extern's in this 
file are due to the multiplexed nature (all the L_xxx), so the extern's are in 
the same file as both the definition and the users.  but that doesn't apply to 
the avahi code.

> @@ -1963,7 +1971,6 @@
>  libc_hidden_def(getnameinfo)
>  #endif
> 
> -
>  #ifdef L_gethostbyname_r
> 
>  /* Bug 671 says:

please don't add unrelated whitespace changes

> -		if (inet_aton(name, in)) {
> +#ifdef __UCLIBC_HAS_AVAHI_RES__
> +		if (!__avahi_resolve_name(AF_INET, name, in) ||
> +#else
> +		if (
> +#endif

in the local header, you can do:
#ifdef __UCLIBC_HAS_AVAHI_RES__
extern ...;
#else
static inline int ...{ return 1; }
#endif

then we can drop the #ifdef's in this file
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.busybox.net/pipermail/uclibc/attachments/20111126/6164c7b7/attachment.asc>


More information about the uClibc mailing list