X-Git-Url: https://git.llucax.com/z.facultad/75.74/practicos.git/blobdiff_plain/093ef819f410add240cf97b72f9e7dcab5abd16c..c1b28b595a388df043997c87faf75c06959405d0:/practicas/pipi/src/ipin.cpp diff --git a/practicas/pipi/src/ipin.cpp b/practicas/pipi/src/ipin.cpp index a9029c6..c8ea64e 100644 --- a/practicas/pipi/src/ipin.cpp +++ b/practicas/pipi/src/ipin.cpp @@ -1,6 +1,9 @@ #include "ipin.h" #include "ipheader.h" +#ifdef DEBUG +#include +#endif /// Constructor IPIn::IPIn(const IPAddr& ip, Dev& dev, Dev& forward_que, bool router, @@ -13,12 +16,14 @@ IPIn::IPIn(const IPAddr& ip, Dev& dev, Dev& forward_que, bool router, void IPIn::drop(const std::string& msg, const std::string& buf) { - log << "IPIn::drop: " << msg << "\n\tBuffer: " << buf << "\n"; + log << "IPIn::drop (" << ip << "): " << msg << "\n\tBuffer: " << buf + << "\n"; } void IPIn::drop(const std::string& msg, const IPHeader& iph) { - log << "IPIn::drop: " << msg << "\n\tIPHeader: " << iph << "\n"; + log << "IPIn::drop (" << ip << "): " << msg << "\n\tIPHeader: " << iph + << "\n"; } /// Recibe un paquete IP @@ -30,26 +35,39 @@ std::string IPIn::recv(uint8_t proto, IPAddr& src, IPAddr& dst) throw (std::runt // No es siquiera IP if (buf.size() < IPHeader::header_len()) { + // Silencioso drop("Cabecera incompleta o no es IP", buf); continue; } IPHeader iph(buf); #ifdef DEBUG - log << "IPIn::recv: IPHeader: " << iph << "\n"; + std::cout << "IPIn::recv (" << ip << "): IPHeader: " << iph << "\n"; + std::string tmp = buf.substr(iph.header_len()); + std::cout << "\tdata (" << tmp.size() << ") = " << tmp << "\n"; #endif if (iph.version != 4) { + // Silencioso drop("Versión IP incorrecta", iph); continue; } if (!iph.check_checksum()) { + // Silencioso drop("Mal checksum", iph); continue; } + // Si el TTL se va a 0 + if (!--iph.ttl) + { + // ICMP + drop("TTL == 0 -> ICMP", iph); + continue; + } // No es para nosotros y no forwardeamos if (iph.dst != ip && !forward) { + // Silencioso drop("No es para nosotros y no hacemos forward", iph); continue; } @@ -62,6 +80,7 @@ std::string IPIn::recv(uint8_t proto, IPAddr& src, IPAddr& dst) throw (std::runt // Es para nosotros pero somos router else if (router) { + // Silencioso drop("Es para nosotros pero somos un router", iph); continue; } @@ -80,7 +99,8 @@ std::string IPIn::recv(uint8_t proto, IPAddr& src, IPAddr& dst) throw (std::runt data += i->second; } #ifdef DEBUG - log << "IPIn::recv: Paquete completo: data = '" << data << "'\n"; + std::cout << "IPIn::recv (" << ip << "): Paquete completo: data = '" + << data << "'\n"; #endif buffer.erase(iph); //TODO faltaría limpiar fragmentos viejos cada tanto (timer?)