obgm / libcoap

A CoAP (RFC 7252) implementation in C
Other
777 stars 421 forks source link

Name Service Switch interface integration of Coap-RD #1445

Open dgtlrift opened 2 weeks ago

dgtlrift commented 2 weeks ago

Problem Statement: Adoption of Coap-RD into legacy applications utilizing getaddrinfo(), getnameinfo(), gethostbyname(), gethostbyaddr(), getservbyname(), or getservbyport() requires refactoring of legacy code base of those applications.

Description of suggested solution: Creation of a libnss_coaprd.so.2 library with implementations of:

enum nss_status _nss_coaprd_gethostbyname_r (const char *name,
                                            struct hostent *result_buf,
                                            char *buf, size_t buflen,
                                            int *errnop, int *h_errnop);
enum nss_status _nss_coaprd_gethostbyaddr_r(const void* addr, int len, int af,
                                          struct hostent* result, char* buffer,
                                          size_t buflen, int* errnop,
                                          int* h_errnop);
enum nss_status _nss_coaprd_getservbyname_r (const char *, const char *,
                                             struct servent *, char *, size_t,
                                             int *);

and

enum nss_status _nss_coaprd_getservbyport_r (int, const char *,
                                             struct servent *, char *, size_t,
                                             int *);

as documented in https://www.gnu.org/software/libc/manual/html_node/NSS-Modules-Interface.html and there is also reference implementation of this concept with mDNS/SD via the Avahi project https://github.com/avahi/nss-mdns

This would allow any legacy applications to utilize coap-rd without any modification to their code base. The administrator would reconfigure the /etc/nsswitch.conf file to something like the following:

hosts:      files coaprd dns
services:   db files coaprd

which would allow the names services switch to utilize the implemented functions above contained within the installed libnss_coaprd.so.2 library to provide querying the hosts and services database services via coaprd.

mrdeep1 commented 1 week ago

@dgtlrift A good idea and I have used this NSS concept elsewhere (not for name resolution though). Someone needs to create this as a project, a part of which needs to specify how the information is stored / accessed / updated in coap-rd so that the NSS modules know how to access this data and return the appropriate information.