NETWORK ATTACKS FRAMEWORK
1.0.0
A NETwork Attacks framework. Making network attacks impact evaluation easier!
|
Go to the source code of this file.
Classes | |
struct | q_pkt |
struct | packet_queue |
Defines | |
#define | MAX_QUEUE_LENGTH 512 |
#define | MAX_QUEUE_TIME 10000 /* Maximum time packets can be queued (ms) */ |
#define | GARBAGE_COLLECT_TIME |
Enumerations | |
enum | { PQ_DROP = 0, PQ_SEND = 1, PQ_ENC_SEND = 2 } |
Functions | |
void | packet_queue_add (cPacket *p, struct in_addr dest_addr) |
void | packet_queue_init () |
void | packet_queue_destroy () |
int | packet_queue_set_verdict (struct in_addr dest_addr, int verdict) |
int | packet_queue_garbage_collect (void) |
Variables | |
struct packet_queue | PQ |
#define GARBAGE_COLLECT_TIME |
1000 /* Interval between running the * garbage collector (ms) */
Definition at line 29 of file NA_packet_queue_omnet.h.
#define MAX_QUEUE_LENGTH 512 |
Definition at line 27 of file NA_packet_queue_omnet.h.
#define MAX_QUEUE_TIME 10000 /* Maximum time packets can be queued (ms) */ |
Definition at line 28 of file NA_packet_queue_omnet.h.
anonymous enum |
Definition at line 34 of file NA_packet_queue_omnet.h.
{ PQ_DROP = 0, PQ_SEND = 1, PQ_ENC_SEND = 2
void 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 packet_queue_destroy | ( | ) |
int 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 packet_queue_init | ( | ) |
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 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; }
struct packet_queue PQ |
Definition at line 76 of file NA_packet_queue_omnet.h.