Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:Evergreen:11.2:Test
smpppd
smpppd-add-support-for-netconfig-bnc-449518.diff
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File smpppd-add-support-for-netconfig-bnc-449518.diff of Package smpppd
From 889b3db9c26416f5b227d1d4ded11798010a3f2b Mon Sep 17 00:00:00 2001 From: lnussel <lnussel@bd8e1831-0645-0410-9286-e9bb2349ee90> Date: Fri, 28 Nov 2008 13:35:19 +0000 Subject: [PATCH] add support for netconfig (bnc#449518) needs some help from ip-up too git-svn-id: https://forgesvn1.novell.com/svn/smpppd/trunk@33 bd8e1831-0645-0410-9286-e9bb2349ee90 --- smpppd/connection.cc | 106 +++++++++++++++++++++++++++++++++++++++++--------- smpppd/connection.h | 6 ++- smpppd/dsl.cc | 2 +- smpppd/isdn.cc | 2 +- smpppd/modem.cc | 7 ++- 5 files changed, 99 insertions(+), 24 deletions(-) diff --git a/smpppd/connection.cc b/smpppd/connection.cc index 3d0391a..bbb70e5 100644 --- a/smpppd/connection.cc +++ b/smpppd/connection.cc @@ -61,6 +61,16 @@ Connection::Connection (const ConnectionConfig* config, string user, reconnect_time = (time_t)(-1); stop_requested = false; + + have_netconfig = false; + have_modify_resolv_conf = false; + if (access("/sbin/netconfig", X_OK) == 0) { + have_netconfig = true; + } else if (access("/sbin/modify_resolvconf", X_OK) == 0) { + have_modify_resolv_conf = true; + } else { + logit (true, "error: no tool found to modify /etc/resolv.conf. DNS may not work"); + } } @@ -393,8 +403,9 @@ Connection::weexit () } + void -Connection::dns_modify (const string& dns1, const string& dns2) +Connection::dns_modify_resolv_conf() { Process resolv; resolv << "/sbin/modify_resolvconf" << "modify"; @@ -402,7 +413,7 @@ Connection::dns_modify (const string& dns1, const string& dns2) << "--script" << _PATH_SMPPPD_IFCFG << "--process" << _SMPPPD_IFCFG << "--pid" << getpid (); - resolv << "--nameservers" << dns1 + " " + dns2; + resolv << "--nameservers" << config->dns1 + " " + config->dns2; resolv << "--text" << "If you do not want the smpppd to change your nameserver settings\n" @@ -417,20 +428,51 @@ Connection::dns_modify (const string& dns1, const string& dns2) resolv.wait_for_dead (); } - void -Connection::dns_keep () +Connection::dns_modify_netconfig() { - Process resolv; - resolv << "/sbin/modify_resolvconf" << "restore"; - resolv << "--service" << _PPPD - << "--process" << _PPPD; - resolv << "--keep"; + // we use service pppd here so we can use dummy DNS servers for + // DoD and have them replaced with real ones in ip-up + const char cmd[] = "/sbin/netconfig modify --service pppd"; + + string cfg; + cfg += "INTERFACE='" + config->ifcfg_filename.substr (6, string::npos) + "'\n"; + cfg += "DNSSERVERS='" + config->dns1 + " " + config->dns2 + "'\n"; + + FILE* pp = popen (cmd, "w"); + if(pp) { + fwrite (cfg.c_str (), cfg.length (), 1, pp); + pclose (pp); + dns_changed = true; + } +} - if (!resolv.start ()) - return; +void +Connection::dns_modify () +{ + if (have_netconfig) { + dns_modify_netconfig(); + } else if (have_modify_resolv_conf) { + dns_modify_resolv_conf(); + } +} - resolv.wait_for_dead (); +void +Connection::dns_keep () +{ + // nothing to do for netconfig + if (have_modify_resolv_conf) { + Process resolv; + resolv << "/sbin/modify_resolvconf" << "restore"; + resolv << "--service" << _PPPD + << "--process" << _PPPD; + resolv << "--keep"; + + if (!resolv.start ()) + return; + + resolv.wait_for_dead (); + } } @@ -440,16 +482,30 @@ Connection::dns_restore () if (!dns_changed) return; - Process resolv; - resolv << "/sbin/modify_resolvconf" << "restore"; - resolv << "--service" << _SMPPPD_IFCFG; + if (have_netconfig){ + Process resolv; + resolv << "/sbin/netconfig" << "remove"; + resolv << "--service" << "pppd" + << "--interface" << config->ifcfg_filename.substr (6, string::npos); - if (!resolv.start ()) - return; + if (!resolv.start ()) + return; - dns_changed = false; + dns_changed = false; - resolv.wait_for_dead (); + resolv.wait_for_dead (); + } else if (have_modify_resolv_conf) { + Process resolv; + resolv << "/sbin/modify_resolvconf" << "restore"; + resolv << "--service" << _SMPPPD_IFCFG; + + if (!resolv.start ()) + return; + + dns_changed = false; + + resolv.wait_for_dead (); + } } @@ -582,6 +638,18 @@ Connection::analyse_pppd_output (const string& line) if (startswith (line, "Using interface ")) { pppd_ifname = line.substr (16, string::npos); status_callback (); + + // XXX: we've set the DNS servers before pppd was started ie + // before the interface was available. Netconfig doesn't + // modify /etc/resolv.conf in that case. So let's tell it to + // do that now. + if (config->modify_dns && have_netconfig + && (config->demand || !config->auto_dns)) { + Process netconfig; + netconfig << "/sbin/netconfig" << "update"; + if (netconfig.start ()) + netconfig.wait_for_dead (); + } return; } } diff --git a/smpppd/connection.h b/smpppd/connection.h index 62099ca..ad2e2b6 100644 --- a/smpppd/connection.h +++ b/smpppd/connection.h @@ -86,11 +86,13 @@ protected: /* dns stuff */ bool dns_changed; + bool have_netconfig; + bool have_modify_resolv_conf; int reconnect_time; bool stop_requested; - void dns_modify (const string&, const string&); + void dns_modify (); void dns_keep (); void dns_restore (); @@ -152,6 +154,8 @@ private: Connection (const Connection&); // disallow Connection& operator = (const Connection&); // disallow + void dns_modify_netconfig (); + void dns_modify_resolv_conf (); }; diff --git a/smpppd/dsl.cc b/smpppd/dsl.cc index c9dc056..bb69f04 100644 --- a/smpppd/dsl.cc +++ b/smpppd/dsl.cc @@ -183,7 +183,7 @@ DSL::start () return false; if (dslconfig->modify_dns && (dslconfig->demand || !dslconfig->auto_dns)) { - dns_modify (dslconfig->dns1, dslconfig->dns2); + dns_modify(); } else { dns_changed = false; } diff --git a/smpppd/isdn.cc b/smpppd/isdn.cc index f155de8..14a726a 100644 --- a/smpppd/isdn.cc +++ b/smpppd/isdn.cc @@ -108,7 +108,7 @@ ISDN::start () return false; if (isdnconfig->modify_dns && (isdnconfig->demand || !isdnconfig->auto_dns)) { - dns_modify (isdnconfig->dns1, isdnconfig->dns2); + dns_modify(); } else { dns_changed = false; } diff --git a/smpppd/modem.cc b/smpppd/modem.cc index a0f13ee..cfd056a 100644 --- a/smpppd/modem.cc +++ b/smpppd/modem.cc @@ -236,8 +236,11 @@ Modem::start () if (!add_user_pass_options (&pppd)) return false; - if (modemconfig->modify_dns && (modemconfig->demand || !modemconfig->auto_dns)) - dns_modify (modemconfig->dns1, modemconfig->dns2); + if (modemconfig->modify_dns && (modemconfig->demand || !modemconfig->auto_dns)) { + dns_modify(); + } else { + dns_changed = false; + } if (!add_debug_options (&pppd)) return false; -- 1.6.0.2
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor