Not Quite [Solved] compiling dnsmasq with tftpd and logging

Post new topic   Reply to topic    DD-WRT Forum Index -> Generic Questions
Goto page 1, 2  Next
Author Message
MrFidget
DD-WRT User


Joined: 15 Jul 2010
Posts: 378

PostPosted: Wed Sep 21, 2011 4:32    Post subject: Not Quite [Solved] compiling dnsmasq with tftpd and logging Reply with quote
Hi all,

Should be straight forward enough Wink

I would Cool Love Cool Someone to put the tftp server functionality back into dnsmasq.

I understand that there is a version that is available with Optware, but, all the same I would love that feature to be available out of the box.

Simple interface
Service On / Off
Mount point for tftpboot directory
Option to log messages to syslog

An .cfg option as currently exists would be fine

Happy to have a go myself, but a little shy on time.

Speicifically for Netgear WNR3500L and Cisco E3000 hardware.

I know I am not the only person looking for this, but there are not very many posts in the forums and a short post in the Wiki saying that it has been removed from the DNSMasq compilation due to space.

As we now have 400MHz+ CPUs, 8Mb ROM and 64MB Ram with USB2 routers for less than AU$100.00 here in Australia, I think that this feature could be revisited. Would be more useful to me than some of the features currently on offer

Any comments, takers ??

Thanks
Chris

ps. I hope I have posted in the right place. I have looked through the stickys and Wikis and found nothing on posting feature requests other than request on the forums.

pps. Happy to donate "something" for the efforts of someone if they want to get involved.

ppps. Im also requesting through the "Professional Development" page too


Last edited by MrFidget on Tue Nov 01, 2011 11:42; edited 5 times in total
Sponsor
MrFidget
DD-WRT User


Joined: 15 Jul 2010
Posts: 378

PostPosted: Wed Sep 21, 2011 4:40    Post subject: Reply with quote
pppps: I still need OpenVPN and Milkfish to be running.

ppppps: I dont need wireless Shocked
MrFidget
DD-WRT User


Joined: 15 Jul 2010
Posts: 378

PostPosted: Wed Sep 21, 2011 4:52    Post subject: Reply with quote
ppppppppppppps: Does anyone know which release tftp was removed from DNSMasq ??

ppppppppppppppppppppps: for that matter, does anyone know where the release notes / changelogs are kept ?
<Kong>
DD-WRT Guru


Joined: 15 Dec 2010
Posts: 4339
Location: Germany

PostPosted: Wed Sep 21, 2011 9:01    Post subject: Reply with quote
Have you tried to add the tftp boot options to:

Additional DNSMasq Options

See:

http://svn.dd-wrt.com:8000/browser//src/router/dnsmasq/dnsmasq.conf.example

_________________
KONG PB's: http://www.desipro.de/ddwrt/
KONG Info: http://tips.desipro.de/
MrFidget
DD-WRT User


Joined: 15 Jul 2010
Posts: 378

PostPosted: Wed Sep 21, 2011 9:11    Post subject: Reply with quote
Yes I have
Code:
enable-tftp

in /tmp/dnsmasq.cfg
Stops DNSMasq from loading

Code:

# dnsmasq -t --conf-file=/tmp/dnsmasq
# echo $?
1
#

Quote:

EXIT CODES

0 - Dnsmasq successfully forked into the background, or terminated normally if backgrounding is not enabled.

1 - A problem with configuration was detected.

2 - A problem with network access occurred (address in use, attempt to use privileged ports without permission).

3 - A problem occurred with a filesystem operation (missing file/directory, permissions).

4 - Memory allocation failure.

5 - Other miscellaneous problem.

11 or greater - a non zero return code was received from the lease-script process "init" call. The exit code from dnsmasq is the script's exit code with 10 added.


Have a play and you'll see what I mean

Can you help ? I am trying to sdet up a build environment and knock up a new binary with TFTPD built in. I'll trash some hotspot stuff to make space

Any input is appreciated
Smile

/C
MrFidget
DD-WRT User


Joined: 15 Jul 2010
Posts: 378

PostPosted: Wed Sep 21, 2011 10:35    Post subject: Reply with quote
You've got me thinking, and looking.

I dumped the dnsmasq binary and found the following internal string:
Quote:
TFTP server not available: set HAVE_TFTP in src/config.h


There is a compiler directive in the source which sets whether to include tftpd or not.

This can either be turned off by the directive in config.h, or by a compiler flag

Code:

175   
176   /* Allow TFTP to be disabled with COPTS=-DNO_TFTP */
177   #ifdef NO_TFTP
178   #undef HAVE_TFTP
179   #endif


I can't find (don't know where to look for) the COPTS in the make files for dnsmasq

I am going to see if I can build a development environment. I am playing with the binary repackaging as I type.

Any help will be appreciated

Thanks in advance
/C
MrFidget
DD-WRT User


Joined: 15 Jul 2010
Posts: 378

PostPosted: Fri Sep 23, 2011 22:11    Post subject: Reply with quote
Here is where it is in the build options (found here:http://svn.dd-wrt.com:8000/browser//src/router/rules/dnsmasq.mk

Code:
dnsmasq:
6           $(MAKE) -C dnsmasq clean
7   ifeq ($(CONFIG_DNSMASQ_TFTP),y)
8           $(MAKE) -j 4 -C dnsmasq COPTS=-DHAVE_BROKEN_RTC CFLAGS="$(COPTS) -DNO_LOG -ffunction-sections -fdata-sections -Wl,--gc-sections"
9   else
10   ifeq ($(CONFIG_DIST),"micro")
11           $(MAKE) -j 4 -C dnsmasq "COPTS=-DHAVE_BROKEN_RTC [b]-DNO_TFTP[/b]" CFLAGS="$(COPTS) -DNO_LOG $(DNSMASQ_MAKEFLAGS) -ffunction-sections -fdata-sections -Wl,--gc-sections"
12   else
13   ifeq ($(CONFIG_DIST),"micro-special")
14           $(MAKE) -j 4 -C dnsmasq "COPTS=-DHAVE_BROKEN_RTC [b]-DNO_TFTP[/b]" CFLAGS="$(COPTS) -DNO_LOG $(DNSMASQ_MAKEFLAGS) -ffunction-sections -fdata-sections -Wl,--gc-sections"
15   else
16           $(MAKE) -j 4 -C dnsmasq "COPTS=-DHAVE_BROKEN_RTC [b]-DNO_TFTP[/b]" CFLAGS="$(COPTS) $(DNSMASQ_MAKEFLAGS) -ffunction-sections -fdata-sections -Wl,--gc-sections"
17   endif


I've managed to get the package to compile from source. I have integrated the binary into a firmware image using the repackager.

I can now see that it is listening on UDP port 69 and I can get a client to talk....however....

I am now getting permissions errors when I try to download a file. Selected root user. Set perms as 0755 Confused

I have also tried the tftp-secure option . No love. Sad

I left it at that at 1:30am last night, early, I know but I had been up since 6:00am. Such is family life with Felix our 2 year old son Very Happy

I'll look into the C code and try some debugging to see whats going on. See if I can work out what stopping things.

Will keep you all posted

/C


Last edited by MrFidget on Sun Sep 25, 2011 8:52; edited 1 time in total
MrFidget
DD-WRT User


Joined: 15 Jul 2010
Posts: 378

PostPosted: Sun Sep 25, 2011 0:08    Post subject: Reply with quote
Further information...

It is failling on file permissions within the tftp.c

Code:

if (uid == 0)
{
  if (!(statbuf.st_mode & S_IROTH))
  {
    goto perm;
  }
}


statbuf.st_mode == 0 which implies no access Sad

uid == 0 therefore the process is running as root so there shouldnt be a reason for no access.

The file is 0777 on an efs2 partition and no other processes are accessing it.

if I ignore the check and force it to continue, the program cant read the file.

Reading the file is done with read and open, not a buffered fread and fopen.

This is statrting to strech my C coding. Can anyone throw me some suggestions ?

When I get back home later today, I was going to try to see if I could read the file using another method. I have created some debugging messages, not shown here that can write to a file using fopen, fprintf and fflush, therefore I am thinking that there is some implimentation issue with using system calls from fcntl.h instead of stdio.h

Anyone with any experience who can shed some light on this would be met with grattitude and beer money via paypal.

Thanks all in advance

/C
MrFidget
DD-WRT User


Joined: 15 Jul 2010
Posts: 378

PostPosted: Sun Sep 25, 2011 8:47    Post subject: Reply with quote
open() & read() dont work
fopen() and fread() do

Can anyone shed any light on this ?

Thanks
/C
MrFidget
DD-WRT User


Joined: 15 Jul 2010
Posts: 378

PostPosted: Sun Oct 23, 2011 8:21    Post subject: Reply with quote
Fixed:

1. Make sure you are compiling with the right toolchain.
In my case, for a Netgear WNR3500L and v15962 source (K26) use the toolchain-mipsel_gcc4.1.2
2. Make sure your development libraries are all there and up to date. There was some libc6 stuff that wasnt there or wrong. Not sure. It works now though Smile

AFAIK the stdio.h functions will work under most circumstances, however with lower level system calls, you have to have your libraries set up correctly.

Compiling dnsmasq with TFTP and logging

Have a look at /src/router/rules/dnsmasq.mk

Code:

5   dnsmasq:
6           $(MAKE) -C dnsmasq clean
7   ifeq ($(CONFIG_DNSMASQ_TFTP),y)
8           $(MAKE) -j 4 -C dnsmasq COPTS=-DHAVE_BROKEN_RTC CFLAGS="$(COPTS) -DNO_LOG -ffunction-sections -fdata-sections -Wl,--gc-sections"


Remove the -DNO_LOG and from the shell before you run make:
Code:

set CONFIG_DNSMASQ_TFTP=y
export CONFIG_DNSMASQ_TFTP


To build, from the ./src/router directory
Code:

make clean
make dnsmasq


The dnsmasq binary will now be found in ./src/router/dnsmasq/src directory.

Use the firmware mod tool to extract a binary
Copy that file on its own to ./rootfs/usr/sbin
Repackage the binary
Copy to your router

You will now get useful messages about leases and tftp transfers in your /var/log/messages

You will also have a working tftp server.

To make the TFTP server work

1. Format a USB key on a machine either FAT32, or efs2 if you wish, and make a directory on it /tftpboot. If you use efs2, make sure its set world readable / executable (755)

2. Enable USB storage services. Services -> USB -> USB Support
Code:

Core USB Support: Enable
USB 2.0 Support: Enable
USB Storage Support: Enable
Automatic Drive Mount: Enable
Disk Mount Point: /mnt


To make this active, in your Services -> Services -> DNSMasq -> Additional DNSMasq Options add the following lines:

Code:
enable-tftp
tftp-root=/mnt/tftpboot
dhcp-option=66,"192.168.1.1"


This will provide a TFTP server on the local router.

To set the router as the default TFTP boot server you need to set option 66 in DHCP. Change the IP address accordlingly.

I hope that this is of use to someone else but me. I have spent hours working on this over the past few weeks during downtime

Cheers all
Chris
MrFidget
DD-WRT User


Joined: 15 Jul 2010
Posts: 378

PostPosted: Wed Oct 26, 2011 19:54    Post subject: Reply with quote
Hmmmm.....not so fast.....

Repeated the process, now I have a segfault starting dnsmasq...

will keep you all posted

/C
MrFidget
DD-WRT User


Joined: 15 Jul 2010
Posts: 378

PostPosted: Tue Nov 01, 2011 11:45    Post subject: Reply with quote
dnsmasq will segfault unless:

1. I have USB storage enabled
2. I have a USB key plugged in

Go figure Confused

/C
MrFidget
DD-WRT User


Joined: 15 Jul 2010
Posts: 378

PostPosted: Tue Nov 01, 2011 12:36    Post subject: Reply with quote
....Debug code in one of the files pointing to the usb key... Rolling Eyes

Works OK but does not start unless syslog is turned on...any suggestions ?

My thoughts are:
Change the defaults and have syslogd run all the time
or
Fix the code to check before starting...

Hmm....

A quick hack of /etc/defaults.bin with a hex editor didn't brick my router. Smile
I also put the code back together properly and it kills the logging Sad

I'll keep working on it

/C
DGoncz
DD-WRT Novice


Joined: 18 Oct 2012
Posts: 1

PostPosted: Thu Oct 18, 2012 3:42    Post subject: No, Really.... Reply with quote
Very good work!

but....


Why boot off your router?
Do you have a store mounted?
Can you boot off the store?

In my case, having been doing this since looong before there was even an ARPANET (since 1973), I'd consider reviewing...


Network Working Group Bill Croft (Stanford University)
Request for Comments: 951 John Gilmore (Sun Microsystems)
September 1985

BOOTSTRAP PROTOCOL (BOOTP)

and joining me as I try to boot Scientific Linux (onto my Compaq EVO D510 SFF desktop PC)....

from my *phone*. Wirelessly.

No, really...read it. It could happen.

In other words, I'll put up with your sh!t and help you with your project, if you'll put up with my sh!t and help me with my project. I am saying this because at the root of it, I think we're pretty much working on the same project.

See Also:

http://www.h-online.com/open/news/item/Multi-booting-over-the-internet-743175.html

which include today this text:

"It is also possible to store custom configurations at netboot.me and use chainload URLs to start them with the netboot.me boot loader. To do this, a user just needs to simply submit the URLs of kernel and initrd together with any required parameters. Those who have built a boot configuration that is interesting for a wider audience are asked to inform the operators so they can include it in the boot menu and make it accessible to all."


Doug
MrFidget
DD-WRT User


Joined: 15 Jul 2010
Posts: 378

PostPosted: Sun Sep 29, 2013 8:24    Post subject: Reply with quote
Hi Doug

Been a while, but I'm back here needing a TFTP server....still..I just got disctracted with more pressing work....like a job tracking system, and a CDR billing system...but I'm back

I am using the TFTP to boot / provision IP phones.

I think I have a solution which may work for me. I'm going to try it out and if it works, I'll post my results
Goto page 1, 2  Next Display posts from previous:    Page 1 of 2
Post new topic   Reply to topic    DD-WRT Forum Index -> Generic Questions All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum