Reply
Thread Tools
Posts: 175 | Thanked: 210 times | Joined on Mar 2013
#1
Hello,

Does anybody know where I can find some info about udhcpc and dnsmasq functionality on maemo (N900), especially the part about how udhcpc transfers DNS servers obtained to dnsmasq, but any info about how these 2 work together would be appreciated.

Thanks.
 
Community Council | Posts: 677 | Thanked: 1,227 times | Joined on Sep 2010 @ Mbabane
#2
udhcpc does the requesting of IP address leases (I think you figured this part out), and dnsmasq takes care of name resolution.

As for how they work together:
dnsmasq settings look for a resolv.conf file in a number of places (see /etc/dnsmasq.conf).
if any of those files contains a valid name server, it gets used.

if you look in /etc/udhcpc/default.bound you will notice that udhcpc updates /var/run/resolv.conf once a successful IP assignment has taken place.

dnsmasq dynamically loads the resolv.conf files, so no restart or reload command is needed. That means as soon as udhcpc has chosen a nameserver, it is immediately available for use

Hope this helps

Any specific reason for asking?

Last edited by sicelo; 2017-02-07 at 07:23.
 

The Following 2 Users Say Thank You to sicelo For This Useful Post:
Posts: 175 | Thanked: 210 times | Joined on Mar 2013
#3
Hello sicelo,

Thanks for your response.

As I see it udhcpc doesn't directly update /var/run/resolv.conf, as in /etc/dnsmasq.conf there are multiple entries, one for each interface (/var/run.resolv.conf.wlan, /var/run.resolv.conf.gprs, /var/run.resolv.conf.lo and /var/run.resolv.conf.ppp0), and /var/run.resolv.conf is never created (at least when I was looking there). Each file (/var/run/resolv.conf.$interface) is created when connecting to that specific interface and contains the DNS server(s).

Now after digging a little more I've seen that there is a file /etc/udhcpc/libicd_network_ipv4.script that execute run-parts -a "$1" /etc/maemo-dhcp.d.
In /etc/maemo-dhcp.d/ there is only one file called 50_ipv4_network_setup which seem to be the one to create /var/run/resolv.conf.$interface. What I don't know is what calls the /etc/udhcpc/libicd_network_ipv4.script file in first place.
Any ideas?

Originally Posted by sicelo View Post
Any specific reason for asking?
I've setup an openvpn client on my N900 with some scripts to set a static mac address to its interface to get the same ip from the remote dhcp server (as in a consumer router, not from openvpn server itself), as I've seen the openvpn applet doesn't allow to set static mac address.
The scripts I've put in place seem to work and overall I'm satisfied with them but I feel like it could be better integrated if I could just call the scripts that udhcpc already calls with specific parameters to reach the same goal instead of using my own (maybe not so well written) scripts (at least for the ip and dns servers procurement).
Now what I look to achieve is better integrate the openvpn ip and dns servers request with the default udhcpc and dnsmasq way of working. The script I'm calling is /etc/openvpn/maemo-update-resolvconf which seem not to respect dnsmasq way on the N900 as it adds the dns server(s) obtained in /etc/resolv.conf (in which only the localhost ip should be) as this way dnsmasq is bypassed and the queries go directly to the upstream dns servers obtained without going through dnsmasq.

Hope the explaining was not to bad.
 
Community Council | Posts: 677 | Thanked: 1,227 times | Joined on Sep 2010 @ Mbabane
#4
Yes I was aware of the *.iface files. However, I do have /var/run/resolv.conf on my N900 ... which is populated by udhcpc when i connect to my work Wi-Fi (WPA-Enterprise .. where Maemo's wlancond fails)

In any case, dnsmasq looks in all /var/run/resolv.conf.*

That libicd script is probably called by icd2 when the connection has been successfully established ... i don't believe you will get anywhere with icd2 as it's closed-source (or i'm wrong?). icd2 is responsible for the network connections you select on the connection list (where your vpn will not be)

You can see the foregoing with 'ps ax | grep udhcpc' ... and that script is used as the config file ... nothing special involved there

can you not just call udhcpc yourself after your vpn connection has been established? that's what i do with wpa_supplicant for my scenario above
Code:
udhcpc -h N900 -i wlan0
Of course this honors dnsmasq as it doesn't touch /etc/resolv.conf

Last edited by sicelo; 2017-02-07 at 21:14.
 
Posts: 175 | Thanked: 210 times | Joined on Mar 2013
#5
Originally Posted by sicelo View Post
Yes I was aware of the *.iface files. However, I do have /var/run/resolv.conf on my N900 ... which is populated by udhcpc when i connect to my work Wi-Fi (WPA-Enterprise .. where Maemo's wlancond fails).
Weird, I am almost certain I have never seen /var/run/resolv.conf on my N900....

Originally Posted by sicelo View Post
can you not just call udhcpc yourself after your vpn connection has been established?
That's what I will do.

Thanks for the clarifications.
 
Posts: 175 | Thanked: 210 times | Joined on Mar 2013
#6
After some trials and trying to make things work I realized why /etc/openvpn/maemo-update-resolvconf bypasses dnsmasq and puts the DNS server(s) in /etc/resolv.conf.

What I've tried is to create the file /var/run/resolv.conf.tap0 which contains the DNS server of the remote network. Upon creation (from script), dnsmasq sees it has been created and uses the nameserver[1]. Afterwards it seems to query only that server for every request[2].
When disconnecting from the vpn, /var/run/resolv.conf.tap0 is deleted and dnsmasq is aware of it, but still tries to contact the vpn DNS server[3], which is obviously not reachable anymore. So DNS is broken and I can't connect to anywhere by name (it works if I specify directly the ip).

The problem seems to be that when dnsmasq becomes aware of a new /var/run/resolv.con.$interface file, it doesn't care anymore about the other one(s). In my case when /var/run/resolv.conf.tap0 is taken into account, /var/run/resolv.conf.gprs becomes like non existent for dnsmasq. So the question is how to make dnsmasq aware of this file again.

From the file /var/maemo-dhcp.d/50_ipv4_network_setup I can see that the command kill -SIGHUP `pidof dnsmasq` is used to "reload" dnsmasq, so I used the same command in my script but it doesn't seem to force dnsmasq to check the resolv-files (it only reloads /etc/hosts).
I could force restart dnsmasq but I would rather not to if I just could make it aware of the /var/run/resolv.conf.gprs file once /var/run/resolv.conf.tap0 is deleted.

[1]
Code:
reading /var/run/resolv.conf.tap0
using nameserver 192.168.120.1#53
read /etc/hosts - 1 addresses
[2]
Code:
query[A] domain.com from 127.0.0.1
forwarded domain.com to 192.168.120.1
reply domain.com is x.x.x.x
[3]
Code:
failed to access /var/run/resolv.conf.tap0: No such file or directory
query[A] anotherdomain.com from 127.0.0.1
forwarded anotherdomain.com to 192.168.120.1
query[A] anotherdomain.com from 127.0.0.1
forwarded anotherdomain.com to 192.168.120.1
 
Halftux's Avatar
Posts: 862 | Thanked: 2,511 times | Joined on Feb 2012 @ Germany
#7
Originally Posted by Malakai View Post
kill -SIGHUP `pidof dnsmasq`
When dnsmasq for example runs as dns server you have more than one pid.
In genwall I restarting dnsmasq with following code:

Code:
stop dnsmasq && start dnsmasq
 

The Following User Says Thank You to Halftux For This Useful Post:
Posts: 175 | Thanked: 210 times | Joined on Mar 2013
#8
Originally Posted by Halftux View Post
When dnsmasq for example runs as dns server you have more than one pid.
Really? I have never seen more than one instance of dnsmasq on my N900... or are you referring to dnsmasq as dns server and not dns forwarder (is it even possible).
I start to think that I have another Maemo version than you and sicelo, as you say you have more than one instance of dnsmasq and he says he has already seen a /var/run/resolv.conf file where I never had.

Code:
~ $ ps -ef | grep dnsmasq
 9289 nobody    2160 S    /usr/sbin/dnsmasq -k -i lo -a 127.0.0.1 -z
10187 user      2864 S    grep dnsmasq
~ $
Originally Posted by Halftux View Post
In genwall I restarting dnsmasq with following code:

Code:
stop dnsmasq && start dnsmasq
stop dnsmasq? Just like this? I don't have any stop or start command...

Code:
~ $ stop
-sh: stop: not found
~ $ start
-sh: start: not found
~ $
Or maybe you refer to /etc/init.d/dnsmasq stop and /etc/init.d/dnsmasq start which I've already seen on the forum, but sadly I don't have any /etc/init.d/dnsmasq file.

Code:
~ $ /etc/init.d/dnsmasq stop
-sh: /etc/init.d/dnsmasq: not found
~ $ ls -l /etc/init.d/ | grep dnsmasq
~ $
The only solution I have found for now is to stop dnsmasq from my script with kill `pidof dnsmasq` and it will restart by itself (I don't know how, maybe a watchdog that looks for dnsmasq and starts it if not found) so dnsmasq reads again it's configuration and looks for the /var/run/resolv.conf.$interface files. This way DNS seems to work (will have to use it more days to really tell).
 
Community Council | Posts: 677 | Thanked: 1,227 times | Joined on Sep 2010 @ Mbabane
#9
you have the same dnsmasq as all of us .. you're just using it differently from us ...

and yes, there is no /etc/init.d/dnsmasq ... on N900, dnsmasq is managed by upstart, so its start/stop script is in /etc/event.d/

you should just restart dnsmasq when changing your connections ... it's going to be hard to say how Maemo does it, because as mentioned before, icd2 is closed and not reverse-engineered yet (afaik). i don't even know what cleans out the resolv.conf.* files from that directory when the interfaces go down

maybe Nokia's dnsmasq was patched? you would have to look in the source

the dnsmasq man page says dnsmasq will only reload the resolv.conf.* files if the '--no-poll' argument is included, which is not the case on maemo. this is by dnsmasq design, http://lists.thekelleys.org.uk/piper...q4/000002.html

so simplest way - restart dnsmasq. works
 
Halftux's Avatar
Posts: 862 | Thanked: 2,511 times | Joined on Feb 2012 @ Germany
#10
Originally Posted by Malakai View Post

stop dnsmasq? Just like this? I don't have any stop or start command...

Code:
~ $ stop
-sh: stop: not found
~ $ start
-sh: start: not found
~ $
Yes like I described, as root of course!!!
 

The Following 2 Users Say Thank You to Halftux For This Useful Post:
Reply

Tags
dnsmasq, maemo, udhcpc

Thread Tools

 
Forum Jump


All times are GMT. The time now is 20:18.