Changeset 1083
- Timestamp:
- 08/16/07 23:10:47 (1 year ago)
- Files:
-
- trunk/pdns/pdns/nproxy.cc (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/pdns/pdns/nproxy.cc
r1082 r1083 40 40 nifs_t g_nifs; 41 41 42 void syslogFmt(const boost::format& fmt) 43 { 44 cerr<<"nproxy: "<<fmt<<endl; 45 syslog(LOG_WARNING, "%s", str(fmt).c_str()); 46 } 47 42 48 void handleOutsideUDPPacket(int fd, boost::any&) 43 49 try … … 61 67 nif.origID = mdp.d_header.id; 62 68 63 cerr<<"External notification received for: "<< nif.domain << endl; 69 64 70 65 71 if(mdp.d_header.opcode != Opcode::Notify || mdp.d_qtype != QType::SOA) { 66 cerr<<"Opcode: "<<mdp.d_header.opcode<<", != notify\n";72 syslogFmt(boost::format("Received non-notification packet for domain '%s' from external nameserver %s") % nif.domain % nif.source.toStringWithPort()); 67 73 return; 68 74 } 69 75 syslogFmt(boost::format("External notification received for domain '%s' from %s") % nif.domain % nif.source.toStringWithPort()); 70 76 vector<uint8_t> outpacket; 71 77 DNSPacketWriter pw(outpacket, mdp.d_qname, mdp.d_qtype, 1, Opcode::Notify); … … 83 89 catch(exception &e) 84 90 { 85 cerr<<"Error parsing incoming packet: "<<e.what()<<endl;91 syslogFmt(boost::format("Error parsing packet from external nameserver: %s") % e.what()); 86 92 } 87 93 … … 105 111 MOADNSParser mdp(packet); 106 112 107 cerr<<"Inside notification response for: "<<mdp.d_qname<<endl;113 // cerr<<"Inside notification response for: "<<mdp.d_qname<<endl; 108 114 109 115 if(!g_nifs.count(mdp.d_header.id)) { 110 cerr<<"Response from inner PowerDNS with unknown ID "<<mdp.d_header.id<<endl;116 syslogFmt(boost::format("Response from inner PowerDNS with unkown ID %1%") % (uint16_t)mdp.d_header.id); 111 117 return; 112 118 } … … 115 121 116 122 if(!iequals(nif.domain,mdp.d_qname)) { 117 cerr<<"Response from inner PowerDNS for different domain '"<<mdp.d_qname<<"' than original notification '"<<nif.domain<<"'"<<endl;123 syslogFmt(boost::format("Response from inner nameserver for different domain '%s' than original notification '%s'") % mdp.d_qname % nif.domain); 118 124 } else { 119 125 struct dnsheader dh; … … 122 128 123 129 if(sendto(nif.origSocket, buffer, len, 0, (sockaddr*) &nif.source, nif.source.getSocklen()) < 0) { 124 throw runtime_error("Unable to send notify to PowerDNS: "+stringerror());130 syslogFmt(boost::format("Unable to send notification response to external nameserver %s - %s") % nif.source.toStringWithPort() % stringerror()); 125 131 } 132 else 133 syslogFmt(boost::format("Sent notification response to external nameserver %s for domain '%s'") % nif.source.toStringWithPort() % nif.domain); 126 134 } 127 135 g_nifs.erase(mdp.d_header.id); … … 130 138 catch(exception &e) 131 139 { 132 cerr<<"Error parsing incoming packet: "<<e.what()<<endl;140 syslogFmt(boost::format("Error parsing packet from internal nameserver: %s") % e.what()); 133 141 } 134 142 … … 138 146 for(nifs_t::iterator iter = g_nifs.begin(); iter != g_nifs.end(); ) { 139 147 if(iter->second.resentTime < limit) { 140 cerr<<"Removing notification proxy entry for '"<<iter->second.domain<<"', expired"<<endl;148 syslogFmt(boost::format("Notification for domain '%s' was sent to inner nameserver, but no response within 10 seconds") % iter->second.domain); 141 149 g_nifs.erase(iter++); 142 150 } … … 151 159 try 152 160 { 161 openlog("nproxy", LOG_NDELAY | LOG_PID, LOG_DAEMON); 162 153 163 po::options_description desc("Allowed options"); 154 164 desc.add_options() 155 165 ("help,h", "produce help message") 156 166 ("powerdns-address", po::value<string>(), "IP address of PowerDNS server") 167 ("chroot", po::value<string>(), "chroot to this directory for additional security") 168 ("setuid", po::value<int>(), "setuid to this numerical user id") 169 ("setgid", po::value<int>(), "setgid to this numerical user id") 157 170 ("origin-address", po::value<string>()->default_value("::"), "Source address for notifications to PowerDNS") 158 171 ("listen-address", po::value<vector<string> >(), "IP addresses to listen on") … … 185 198 // create sockets to listen on 186 199 187 cerr<<"Binding sockets\n";200 syslogFmt(boost::format("Starting up")); 188 201 for(vector<string>::const_iterator address = addresses.begin(); address != addresses.end(); ++address) { 189 202 ComboAddress local(*address, 53); … … 196 209 197 210 g_fdm.addReadFD(sock, handleOutsideUDPPacket); // add to fdmultiplexer for each socket 211 syslogFmt(boost::format("Listening for external notifications on address %s") % local.toStringWithPort()); 198 212 } 199 213 … … 211 225 ComboAddress pdns(g_vm["powerdns-address"].as<string>(), 53); 212 226 if(connect(g_pdnssocket, (struct sockaddr*) &pdns, pdns.getSocklen()) < 0) 213 throw runtime_error("Failed to connect PowerDNS socket to address "+pdns.toString()+": "+stringerror()); 227 throw runtime_error("Failed to connect PowerDNS socket to address "+pdns.toStringWithPort()+": "+stringerror()); 228 229 syslogFmt(boost::format("Sending notifications to internal address %s") % pdns.toStringWithPort()); 214 230 215 231 g_fdm.addReadFD(g_pdnssocket, handleInsideUDPPacket); … … 218 234 if(chroot(g_vm["chroot"].as<string>().c_str()) < 0) 219 235 throw runtime_error("while chrooting to "+g_vm["chroot"].as<string>()); 236 syslogFmt(boost::format("Changed root to directory '%s'") % g_vm["chroot"].as<string>()); 237 } 238 239 if(g_vm.count("setuid")) { 240 if(setuid(g_vm["setuid"].as<int>()) < 0) 241 throw runtime_error("while changing uid to "+g_vm["setuid"].as<int>()); 242 syslogFmt(boost::format("Changed uid to %d") % g_vm["setuid"].as<int>()); 243 } 244 245 if(g_vm.count("setgid")) { 246 if(setuid(g_vm["setgid"].as<int>()) < 0) 247 throw runtime_error("while changing gid to "+g_vm["setgid"].as<int>()); 248 syslogFmt(boost::format("Changed gid to %d") % g_vm["setgid"].as<int>()); 220 249 } 221 250 222 251 if(g_vm["daemon"].as<bool>()) { 252 syslogFmt(boost::format("Daemonizing")); 223 253 daemonize(); 224 254 } 255 syslogFmt(boost::format("Program operational")); 225 256 226 257 … … 234 265 } 235 266 } 267 catch(boost::program_options::error& e) 268 { 269 syslogFmt(boost::format("Error parsing command line options: %s") % e.what()); 270 } 236 271 catch(exception& e) 237 272 { 238 cerr<<"Fatal: "<<e.what()<<endl;273 syslogFmt(boost::format("Fatal: %s") % e.what()); 239 274 } 240 275 catch(AhuException& e) 241 276 { 242 cerr<<"Fatal: "<<e.reason<<endl;277 syslogFmt(boost::format("Fatal: %s") % e.reason); 243 278 } 244 279