|
NETWORK ATTACKS FRAMEWORK
1.0.0
A NETwork Attacks framework. Making network attacks impact evaluation easier!
|
Go to the source code of this file.
Defines | |
| #define | GARBAGE_COLLECT |
| #define | ARP_DELAY 0.005 |
Functions | |
| void NS_CLASS | packet_queue_init (void) |
| void NS_CLASS | packet_queue_destroy (void) |
| int NS_CLASS | packet_queue_garbage_collect (void) |
| void NS_CLASS | packet_queue_add (cPacket *p, struct in_addr dest_addr) |
| int NS_CLASS | packet_queue_set_verdict (struct in_addr dest_addr, int verdict) |
| #define ARP_DELAY 0.005 |
| #define GARBAGE_COLLECT |
Definition at line 26 of file NA_packet_queue_omnet.cc.
| void NS_CLASS packet_queue_add | ( | cPacket * | p, |
| struct in_addr | dest_addr | ||
| ) |
Definition at line 324 of file NA_packet_queue_omnet.cc.
{
struct q_pkt *qp;
cPacket *dgram;
if (PQ.pkQueue.size() >= MAX_QUEUE_LENGTH)
{
DEBUG(LOG_DEBUG, 0, "MAX Queue length! Removing first packet.");
qp = PQ.pkQueue.front();
PQ.pkQueue.erase(PQ.pkQueue.begin());
dgram = qp->p;
sendICMP(dgram);
free(qp);
}
qp = (struct q_pkt *) malloc(sizeof(struct q_pkt));
if (qp == NULL)
{
fprintf(stderr, "Malloc failed!\n");
exit(-1);
}
qp->p = p;
qp->dest_addr = dest_addr;
gettimeofday(&qp->q_time, NULL);
PQ.pkQueue.push_back(qp);
DEBUG(LOG_INFO, 0, "buffered pkt to %s qlen=%u",
ip_to_str(dest_addr), PQ.length());
}
| void NS_CLASS packet_queue_destroy | ( | void | ) |
| int NS_CLASS packet_queue_garbage_collect | ( | void | ) |
Definition at line 293 of file NA_packet_queue_omnet.cc.
{
int count = 0;
struct timeval now;
gettimeofday(&now, NULL);
for (unsigned int i=0; i < PQ.pkQueue.size();)
{
struct q_pkt *qp = PQ.pkQueue[i];
if (timeval_diff(&now, &qp->q_time) > MAX_QUEUE_TIME)
{
PQ.pkQueue.erase(PQ.pkQueue.begin()+i);
sendICMP(qp->p);
free(qp);
count++;
}
else
i++;
}
if (count)
{
DEBUG(LOG_DEBUG, 0, "Removed %d packet(s)!", count);
}
return count;
}
| void NS_CLASS packet_queue_init | ( | void | ) |
Definition at line 266 of file NA_packet_queue_omnet.cc.
{
PQ.pkQueue.clear();
#ifdef GARBAGE_COLLECT
/* Set up garbage collector */
timer_init(&PQ.garbage_collect_timer, &NS_CLASS packet_queue_timeout, &PQ);
timer_set_timeout(&PQ.garbage_collect_timer, GARBAGE_COLLECT_TIME);
#endif
}
| int NS_CLASS packet_queue_set_verdict | ( | struct in_addr | dest_addr, |
| int | verdict | ||
| ) |
Definition at line 356 of file NA_packet_queue_omnet.cc.
{
int count = 0;
rt_table_t *rt, *next_hop_rt, *inet_rt = NULL;
struct in_addr gw_addr;
double delay = 0;
#define ARP_DELAY 0.005
if (verdict == PQ_ENC_SEND)
{
gw_addr.s_addr = ManetAddress(*gateWayAddress);
rt = rt_table_find(gw_addr);
}
else
rt = rt_table_find(dest_addr);
std::vector<ManetAddress> list;
if (isInMacLayer())
{
std::vector<MACAddress> listMac;
getApList(dest_addr.s_addr.getMAC(),listMac);
while (!listMac.empty())
{
list.push_back(ManetAddress(listMac.back()));
listMac.pop_back();
}
}
else
{
std::vector<IPv4Address> listIp;
getApListIp(dest_addr.s_addr.getIPv4(),listIp);
while (!listIp.empty())
{
list.push_back(ManetAddress(listIp.back()));
listIp.pop_back();
}
}
while (!list.empty())
{
struct in_addr dest_addr;
dest_addr.s_addr = list.back();
list.pop_back();
for (unsigned int i=0; i < PQ.pkQueue.size();)
{
struct q_pkt *qp = PQ.pkQueue[i];
if (qp->dest_addr.s_addr == dest_addr.s_addr)
{
PQ.pkQueue.erase(PQ.pkQueue.begin()+i);
switch (verdict)
{
case PQ_ENC_SEND:
if (dynamic_cast <IPv4Datagram *> (qp->p))
{
qp->p = pkt_encapsulate(dynamic_cast <IPv4Datagram *> (qp->p), *gateWayAddress);
// now Ip layer decremented again
/* Apparently, the link layer implementation can't handle a burst of packets. So to keep ARP happy, buffered
* packets are sent with ARP_DELAY seconds between sends. */
sendDelayed(qp->p, delay, "to_ip");
delay += ARP_DELAY;
}
else
{
sendICMP(qp->p);
}
break;
case PQ_SEND:
if (!rt)
return -1;
/* Apparently, the link layer implementation can't handle
* a burst of packets. So to keep ARP happy, buffered
* packets are sent with ARP_DELAY seconds between
* sends. */
// now Ip layer decremented again
sendDelayed(qp->p, delay, "to_ip");
delay += ARP_DELAY;
break;
case PQ_DROP:
sendICMP(qp->p);
break;
}
free(qp);
count++;
}
else
i++;
}
}
/* Update rt timeouts */
if (rt && rt->state == VALID &&
(verdict == PQ_SEND || verdict == PQ_ENC_SEND))
{
if (dest_addr.s_addr != DEV_IFINDEX(rt->ifindex).ipaddr.s_addr)
{
if (verdict == PQ_ENC_SEND && inet_rt)
rt_table_update_timeout(inet_rt, ACTIVE_ROUTE_TIMEOUT);
rt_table_update_timeout(rt, ACTIVE_ROUTE_TIMEOUT);
next_hop_rt = rt_table_find(rt->next_hop);
if (next_hop_rt && next_hop_rt->state == VALID &&
next_hop_rt->dest_addr.s_addr != rt->dest_addr.s_addr)
rt_table_update_timeout(next_hop_rt, ACTIVE_ROUTE_TIMEOUT);
}
DEBUG(LOG_INFO, 0, "SENT %d packets to %s qlen=%u",
count, ip_to_str(dest_addr), PQ.length());
}
else if (verdict == PQ_DROP)
{
DEBUG(LOG_INFO, 0, "DROPPED %d packets for %s!",
count, ip_to_str(dest_addr));
}
return count;
}