X-Git-Url: https://git.llucax.com/z.facultad/75.74/practicos.git/blobdiff_plain/49f488eb5e757db401a81bc40a30a84d1abcaf88..46098de47811c686844e5cb8b1d8f1b59586e6b8:/practicas/pipi/src/ipin.cpp diff --git a/practicas/pipi/src/ipin.cpp b/practicas/pipi/src/ipin.cpp index 55bc856..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,28 +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()); - log << "\tdata (" << tmp.size() << ") = " << tmp << "\n"; + 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; } @@ -64,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; } @@ -82,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?)