|
@ -59,7 +59,6 @@ void NATRouter::onRecv() |
|
|
{ |
|
|
{ |
|
|
Packet p = this->recv(); |
|
|
Packet p = this->recv(); |
|
|
|
|
|
|
|
|
// TODO: jako ze router jest tez switchem, zaimplementowac wysylanie wiadomosci po sieci lokalnej
|
|
|
|
|
|
if (p.getSrcPort() != 0) |
|
|
if (p.getSrcPort() != 0) |
|
|
{ |
|
|
{ |
|
|
// jezeli pakiet idzie z jednego wezla do drugiego w danej possieci to odeslij mu "jak switch"
|
|
|
// jezeli pakiet idzie z jednego wezla do drugiego w danej possieci to odeslij mu "jak switch"
|
|
@ -85,11 +84,13 @@ void NATRouter::onRecv() |
|
|
void NATRouter::setWanIp(string wanIp) |
|
|
void NATRouter::setWanIp(string wanIp) |
|
|
{ |
|
|
{ |
|
|
this->netWanConf.ip = wanIp; |
|
|
this->netWanConf.ip = wanIp; |
|
|
|
|
|
this->setWanNetwork(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void NATRouter::setWanMask(string wanMask) |
|
|
void NATRouter::setWanMask(string wanMask) |
|
|
{ |
|
|
{ |
|
|
this->netWanConf.mask = wanMask; |
|
|
this->netWanConf.mask = wanMask; |
|
|
|
|
|
this->setWanNetwork(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void NATRouter::setWanGatewayIp(string wanGatewayIp) |
|
|
void NATRouter::setWanGatewayIp(string wanGatewayIp) |
|
@ -107,6 +108,14 @@ string NATRouter::getWanMask() |
|
|
return this->netWanConf.mask; |
|
|
return this->netWanConf.mask; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* funkcja SNAT zapisuje w tablicy NAT |
|
|
|
|
|
* numer portu zrodlowego komputera z LAN |
|
|
|
|
|
* oraz jego IP i przeksztalca pakiet, zmieniajac |
|
|
|
|
|
* zrodlowy IP na IP zewn. routera oraz wolny |
|
|
|
|
|
* port z tablicy NAT. Jezeli portu nie ma to funkcja |
|
|
|
|
|
* czeka, az sie zwolni |
|
|
|
|
|
*/ |
|
|
void NATRouter::sNAT(Packet *packet) |
|
|
void NATRouter::sNAT(Packet *packet) |
|
|
{ |
|
|
{ |
|
|
int port; |
|
|
int port; |
|
@ -133,6 +142,12 @@ void NATRouter::sNAT(Packet *packet) |
|
|
natItem = NULL; |
|
|
natItem = NULL; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* funkcja DNAT ma za zadanie znalezc w tablicy NAT |
|
|
|
|
|
* port i adres IP wezla na ktory ma wrocic odpowiedz |
|
|
|
|
|
* z sieci Internet (z zewnatrz), a takze zwolnic ten |
|
|
|
|
|
* port |
|
|
|
|
|
*/ |
|
|
void NATRouter::dNAT(Packet* packet) |
|
|
void NATRouter::dNAT(Packet* packet) |
|
|
{ |
|
|
{ |
|
|
NATItem *natItem = &this->natTable[packet->getDstPort()]; |
|
|
NATItem *natItem = &this->natTable[packet->getDstPort()]; |
|
@ -146,6 +161,16 @@ void NATRouter::dNAT(Packet* packet) |
|
|
natItem = NULL; |
|
|
natItem = NULL; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void NATRouter::setWanNetwork() |
|
|
|
|
|
{ |
|
|
|
|
|
this->netWanConf.network = this->calculateNetwork(this->getWanIp(), this->getWanMask()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
string NATRouter::getWanNetwork() |
|
|
|
|
|
{ |
|
|
|
|
|
return this->netWanConf.network; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
string NATRouter::getWanGatewayIp() |
|
|
string NATRouter::getWanGatewayIp() |
|
|
{ |
|
|
{ |
|
|
return this->netWanConf.gatewayIp; |
|
|
return this->netWanConf.gatewayIp; |
|
|