X-Git-Url: https://git.llucax.com/z.facultad/75.74/practicos.git/blobdiff_plain/6758589f5ff68b1775d5a83b01d7ac49f1b612ef..659563a75d668130df84664e7e6b1220667cbc28:/practicas/pipi/src/ipin.cpp diff --git a/practicas/pipi/src/ipin.cpp b/practicas/pipi/src/ipin.cpp index c191b90..c8ea64e 100644 --- a/practicas/pipi/src/ipin.cpp +++ b/practicas/pipi/src/ipin.cpp @@ -16,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 @@ -33,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 - std::cout << "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; } @@ -67,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; } @@ -85,7 +99,8 @@ std::string IPIn::recv(uint8_t proto, IPAddr& src, IPAddr& dst) throw (std::runt data += i->second; } #ifdef DEBUG - std::cout << "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?)