// vim:foldmethod=marker:syntax=lpc:noexpandtab // $Id: udp.c,v 1.32 2008/03/29 20:36:44 lynx Exp $ // #include #include #include #include #include // SECURITY CONCERN: // originating udp host and port numbers can rather easily be spoofed // and currently many routers/gateways won't bother delivering a packet which // couldn't possibly have come from that direction. UDP may generally // need to be considered not trustworthy, even if it apparently comes // from localhost. okay, hopefully our kernel is smart enough not to // believe an incoming packet to be from localhost. it's his job! #ifdef __PIKE__ import net.psyc.common; #else inherit PSYC_PATH "common"; #endif // network location of remote server (hostname or hostname:port) volatile mapping namecache = ([]); // volatile int timeoutPending; // TODO? should keep caches of host:port per remote target somewhat like tcp #ifdef FORK # include "routerparse.i" #else # include "parse.i" #endif object load() { return ME; } // avoid a find_object call in obj/master parseUDP2(host, ip, port, msg) { string *m; int i, l #ifdef FORK , parsed #endif ; unless (stringp(host)) host = ip; P3(( "parseUDP(%O,%O): %O\n", ip,port,msg )) pvars = ([ ]); // this call is a performance killer // should UDP get used heavily.. TODO // needs hash-based host matching, not linear unless (hostCheck(ip, port, 1)) { log_file("PSYCBLOCK", "UDP from "+ip +" ignored » "+msg+" «\n"); // netloc = "psyc://"+ip+":"+port; // sendmsg(netloc, "_error_illegal_source", // "Sorry, my configuration does not permit to talk to you.\n"); return; } //netloc = "psyc://"+ip; peeraddr = peerhost = host; if (port != PSYC_SERVICE) { peerport = port; peeraddr += ":"+port+"d"; // this is a UDP peerport } // else: we presume a UDP 4404 also listens on TCP #ifdef PRO_PATH P1(("./psyc/udp.c: restart. why?\n")) restart(); // leading . does that anyway #endif #if 1 //def NOT_EXPERIMENTAL pvars["_INTERNAL_source"] = "psyc://"+peeraddr+"/"; #endif // m = regexplode(msg, "\r?\n"); ? m = explode(msg, "\n"); for (l=0; l