LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Dialing only when there is data to send via PPP (https://www.linuxquestions.org/questions/linux-software-2/dialing-only-when-there-is-data-to-send-via-ppp-89729/)

ruchika 09-05-2003 07:58 PM

Dialing only when there is data to send via PPP
 
Hi,

If PPPd is invoked with the demand option, as described in pppd man pages, the pppd deamon starts running but chat script is not executed and there is no attempt to establish connection with the PPP server. Thats good. But now coming to the real question ... does demand option mean that when there is data to send out, pppd will try to establish connection with the PPP server on its own? What will happen if pppd is not able to establish connection .. how will my function know that PPP connection couldn't be established? I am not running PPP with updetach option, hence it runs detached from the controlling terminal from the get go. Is there a way to find out if PPP connection got established successfully and the data went thru in this case? The intent is to not hold the calling process while we r trying to establish the PPP connection, thats the reason pppd is invoked without the updetach option.
Since connection is established only when there is data to send, this wouldn't cost more than when nodemand option is specified. Is that right?

Is there a way of making sure that only one PPPd and PPP connection is alive/active at any time?

Any pointers will be highly appreciated.

Thanks,
Ruchika

lyle_s 09-06-2003 12:53 PM

Sorry you're not getting too many replies to your posts. It's just that your questions are a bit unstructured, but that's okay because that's just the stage you're at. I hope you'll forgive me if my suggestions are also unstructured.

It seems to me that your program shouldn't be written to be so PPP specific. What if the situation should change and the client and server need to be on the same LAN, over the Internet, or on the same machine? You would have to change your program for it to work. I can't think of any client or server program that I use that is aware if I'm using PPP or not.

So, your client program shouldn't worry about whether or not pppd connected successfully--only that the call to connect was successful. But before that, it has to worry about if the call to gethostbyname was successful. This is how to know what IP address to specify in the connect call. Your client program should accept a hostname to connect to. You could add a line in /etc/hosts to provide an IP address to the other end of the PPP connection. You can find out the IP address of the other end of the PPP link by running ifconfig while the PPP link is up; as far as I know, it stays the same.

There's an article at http://www.linuxjournal.com/article....rder=0&thold=0 that deals with some of this material.

In order to deal with the slow connection times associated with a PPP connection coming up or other errors, your client could use a back off algorithm for the gethostbyname and connect calls. For example, if the call to gethostbyname fails, it could wait 2 seconds and try again. If that fails wait 4 seconds then try, if that fails wait 6 seconds, and on and on to a configurable number of tries or amount of time to keep trying.

pppd runs some scripts, namely ip-up and ip-down when a PPP connection comes up and goes down respectively. You can do whatever you want in these scripts, and pppd passes a bunch of environment variables you can use in these scripts. See man pppd and the PPP HOWTO at http://www.tldp.org/HOWTO/PPP-HOWTO/index.html

Lyle

ruchika 09-08-2003 09:39 PM

Thank you for the reply lyle_s.

Excuse me if my questions may have been unstructured. I'll try to be more clear about things.

As mentioned by you, it makes sense not to make the client PPP aware. Someone else is working on a module that allows the client and server on the same LAN to talk to each other over the Internet. My job is to provide plugins for an alternate route (instead of LAN, a CDMA modem that can establish PPP connection). We are already using socket interface. So once the PPP connection has been established, we can use the same socket interface for data transfer.

I have the PPP connection established. But I am not able to browse the internet. I think the problem is because the default route is ethernet on my machine. I know that by changing the default route using /sbin/route del default I can fix this. Is there an alternate way of fixing this problem? Maybe by specifying something in the options file?

Also, I want to support demand dial. Do I need to specify/change some settings inorder to support this? My current settings are

persist idle debug lock modem crtscts defaultroute noauth bsdcomp 0 deflate 0 asyncmap 0 kdebug 0 connect $DIALER SCRIPT

Thanks,
Ruchika

lyle_s 09-08-2003 10:41 PM

You can get dial on demand working by placing "demand" in the options file. Use the "idle" option to specify how many seconds of inactivity on the ppp interface you want before pppd terminates the connection.

You can have pppd add a default route to the ppp interface by adding "defaultroute" to the options file.

This is what my options file looks like:
root@europa:~# cat /etc/ppp/options.demand
# General configuration options for PPPD:
lock
defaultroute
noipdefault
modem
/dev/modem
115200
crtscts
# Uncomment the line below for more verbose error reporting:
#debug
# If you have a default route already, pppd may require the other side
# to authenticate itself, which most ISPs will not do. To work around this,
# uncomment the line below. Note that this may have negative side effects
# on system security if you allow PPP dialins. See the docs in /usr/doc/ppp*
# for more information.
#noauth
passive
asyncmap 0
name "username corresponding to username in pap-secrets"
ipcp-accept-local
ipcp-accept-remote
0.0.0.0:10.10.10.10
demand
idle 180
maxfail 100
connect "/usr/sbin/chat -v -f /etc/ppp/pppscript"
# End general configuration options for PPPD

pppd is started like this:

root@europa:~# pppd file "/etc/ppp/options.demand"

Hope this helps,
Lyle

ruchika 09-09-2003 04:12 PM

Thanks lyle_s.

You had mentioned that the client program shouldn't worry about whether or not pppd connected successfully--only that the call to connect was successful. I call connect on a non-blocking socket, and also select the socket for completion of connection before writing, what should I look for inorder to know that the connection could not be established? Does select still indicate writablilty if connection fails? Can a timeout be specified on connect?

In some cases, the application may want to know the reason why the connection could not be established. For eg, if the modem is not connected, if there is no carrier etc. I am thinking of creating a thread that establishes PPP connection with the updetach option inorder to catch the errors returned by pppd/chat and not block the main process. Is this the standard way to catch errors and know the connection state or is there another way?

Thanks,
Ruchika

lyle_s 09-09-2003 11:50 PM

Sorry, you've gone a bit out of my area of expertise (which isn't that large in the first place). I've never used select or non-blocking sockets; I've just done a "hello network world" sort of thing.

Wish I could help more.

Lyle

ruchika 09-10-2003 11:30 AM

No problem Lyle. Thanks for you help.

Ruchika


All times are GMT -5. The time now is 12:58 AM.