patchlwIP - A Lightweight TCP/IP stack - Patches: patch #9427, Add gethostbyname hook


You are not allowed to post comments on this tracker with your current authentication level.

patch #9427: Add gethostbyname hook

Submitted by:  Joel Cunningham <jcunningham>
Submitted on:  Fri 04 Aug 2017 08:45:19 PM UTC  
Category:  sockets/netconn Priority:  5 - Normal
Status:  Done Privacy:  Public
Assigned to:  Joel Cunningham <jcunningham> Open/Closed:  Closed
Planned Release:  2.1.0

( Jump to the original submission)

Mon 20 Nov 2017 05:22:04 PM UTC, comment #11: 

Hook submitted to lwip in 6af3b4accc7b05e4c0c52bc901c4d8b2af256f8e

Example hook with DNS-SD submitted to lwip-contrib in 01a91d3d6b7452f4e1478d9dd5f28eed41336ba1

Joel Cunningham <jcunningham>
Project MemberIn charge of this item.
Mon 20 Nov 2017 03:21:48 PM UTC, comment #10: 

> Yes. I've set this to 2.1.0 (which I'd be happy to get out this year).

I'll work on getting this submitted, thanks!

Joel Cunningham <jcunningham>
Project MemberIn charge of this item.
Sun 19 Nov 2017 08:42:05 PM UTC, comment #9: 

> Would LWIP_HOOK_NETCONN_EXTERNAL_RESOLVE be more appropriate?

Yes. I've set this to 2.1.0 (which I'd be happy to get out this year).

Simon Goldschmidt <goldsimon>
Project Administrator
Thu 19 Oct 2017 09:49:31 PM UTC, comment #8: 

I took a look at netdb and remembered that I placed the hook in netconn_gethostbyname rather than netdb because all the netdb functions end up calling netconn_gethostbyname.  This task name/wording in the patch doesn't mention netconn, so I could see how that caused some confusion of where the hook is.

The netconn layer seems appropriate to me so the hook isn't duplicated and any applications using netconn directly (rather than netdb) gets access to the hook.

Would LWIP_HOOK_NETCONN_EXTERNAL_RESOLVE be more appropriate?  That seems to make clear the hook is happening at the netconn layer

Joel Cunningham <jcunningham>
Project MemberIn charge of this item.
Thu 19 Oct 2017 07:07:15 PM UTC, comment #7: 

> Why don't you name it "LWIP_HOOK_NETDB_EXTERNAL_RESOLVE" and include it in gethostbyname_r() and getaddrinfo(), too?

Sounds good, I'll work on those changes and get it pushed!

Joel Cunningham <jcunningham>
Project MemberIn charge of this item.
Thu 19 Oct 2017 05:49:48 PM UTC, comment #6: 


I'm not sure this really helps to see it only works from API threads, not from callback apps calling dns_gethostbyname()...

Including "netdb" might help.

Thinking further, we're limited to API threads here, so callback APPs are left out. Bad enough. We still might want to include all sequential resolve APIs though. At least the ones in netdb.c.

Why don't you name it "LWIP_HOOK_NETDB_EXTERNAL_RESOLVE" and include it in gethostbyname_r() and getaddrinfo(), too?

Simon Goldschmidt <goldsimon>
Project Administrator
Mon 16 Oct 2017 08:56:37 PM UTC, comment #5: 

Great!  What do you think about changing the name to LWIP_HOOK_EXTERNAL_DNS_RESOLVER?

Joel Cunningham <jcunningham>
Project MemberIn charge of this item.
Mon 16 Oct 2017 07:00:44 PM UTC, comment #4: 

Thinking about this again, just go ahead and add the hook. If we find a decent way to make it accessible to the callback API, we can improve it later...

But please change the name of the hook and its documentation to make it clear that this is only usable from API threads!

Simon Goldschmidt <goldsimon>
Project Administrator
Mon 07 Aug 2017 02:00:16 PM UTC, comment #3: 

You're correct that dns_gethostbyname() would not have access to the hook, but then again the hook would have to be implemented in terms of only raw APIs if it were placed at that level.  That pretty much rules out hooking in any external DNS resolver since these are all going to use sockets API (I'm not aware of any external DNS libraries using LwIP's raw API)

The lack of parity between gethostbyname and dns_gethostbyname hasn't been an issue in my system since I don't use any of the raw applications, everything is calling netdb APIs for name resolution

FWIW, DNS resolver systems typically allow external hooks.  mDNSResponder ships with hooks for Glibc's GNU Name Switch Service and Winsock's Namepsace Service Provider

Joel Cunningham <jcunningham>
Project MemberIn charge of this item.
Sun 06 Aug 2017 07:45:04 PM UTC, comment #2: 

Hmm, adding a hook in gethostbyname in api_lib.c would mean that API applications would receive a different result to raw applications. I don't think that would be a good idea...

Simon Goldschmidt <goldsimon>
Project Administrator
Fri 04 Aug 2017 08:47:29 PM UTC, comment #1: 

0001-Add-DNS-SD-hook-for-LWIP_HOOK_GETHOSTBYNAME.patch is for lwip-contrib if that's not clear :)

Joel Cunningham <jcunningham>
Project MemberIn charge of this item.
Fri 04 Aug 2017 08:45:19 PM UTC, original submission:  

0001-Add-gethostbyname.patch: adds a new hook (LWIP_HOOK_GETHOSTBYNAME) which allows an external DNS resolver to be hooked into's LwIP gethostbyname/getaddrinfo implementation and DNS stack.  The hook can handle some or all of the queries

One use case for this hook is to run mDNSResponder in the same system as LwIP (mDNSResponder also uses LwIP's socekt APIs) and have it handle .local queries while LwIP stack handles unicast DNS queries

This allows applications to use LwIP's gethostbyname/getaddrinfo for all types of queries supported in the system and not have to worry about using a different API for each DNS resolver that actually handles the query

0001-Add-DNS-SD-hook-for-LWIP_HOOK_GETHOSTBYNAME.patch: This adds an implementation of LWIP_HOOK_GETHOSTBYNAME that uses the
DNS-SD API provided by mDNSResponder

I've been using these in my port, which uses mDNSResponder (ported to LwIP) only for MDNS queries (unicast queries use LwIP). This provides a unified DNS subsystem that applications can use via gethostbyname/getaddrinfo.  I know others have mDNSResponder in a system with LwIP, so I'd like to share this approach

Joel Cunningham <jcunningham>
Project MemberIn charge of this item.


Attached Files
file #41416:  0001-Add-gethostbyname-hook.patch added by jcunningham (3KiB - application/octet-stream)


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by goldsimon (Posted a comment)
  • -email is unavailable- added by jcunningham (Submitted the item)

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.




    Follow 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2017-11-20 jcunningham StatusNone => Done
        Open/ClosedOpen => Closed
    2017-11-17 goldsimon Planned ReleaseNone => 2.1.0
    2017-08-04 jcunningham Attached File- => Added 0001-Add-gethostbyname-hook.patch, #41416
        Attached File- => Added 0001-Add-DNS-SD-hook-for-LWIP_HOOK_GETHOSTBYNAME.patch, #41417

    Back to the top

    Powered by Savane 3.5