📄 ackfilter.cc
字号:
/* * ackfilter.{cc,hh} -- Picks up ack header for encoded packets * Wenjun Hu * * Copyright (c) 2005 University of Cambridge * Copyright (c) 2005 Massachusetts Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, subject to the conditions * listed in the Click LICENSE file. These conditions include: you must * preserve this copyright notice, and you cannot mention the copyright * holders in advertising related to the Software without their permission. * The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This * notice is a summary of the Click LICENSE file; the license in that file is * legally binding. */#include <click/config.h>#include <click/confparse.hh>#include <click/error.hh>#include <click/glue.hh>#include <click/etheraddress.hh>#include <clicknet/ether.h>#include <click/straccum.hh>#include <click/timestamp.hh>#include <click/string.hh>#include "ackheader.hh"#include "ackfilter.hh"#include "../sr/srpacket.hh"#include <click/ipaddress.hh>#include <click/timestamp.hh>#include <click/straccum.hh>#include <click/packet_anno.hh>CLICK_DECLSAckFilter::AckFilter() : Element(1, 2), _et(0), _et_nothing(0){}AckFilter::~AckFilter(){}intAckFilter::configure(Vector<String> &conf, ErrorHandler *errh){ int ret = cp_va_parse(conf, this, errh, cpKeywords, "ETHTYPE", cpUnsigned, "Ethernet Ack encapsulation type", &_et, "NOTHINGETHTYPE", cpUnsigned, "Nothing Ethernet Encapsulation type", &_et_nothing, cpEnd); if (!_et) return errh->error("ETHTYPE not specified"); if (!_et_nothing) return errh->error("NOTHINGETHTYPE not specified"); return ret;}voidAckFilter::push(int port, Packet *p){ click_ether *eh = (click_ether *) p->data(); EtherAddress src = EtherAddress(eh->ether_shost); EtherAddress dst = EtherAddress(eh->ether_dhost); uint16_t ethtype = eh->ether_type; click_chatter("%s packet length %d", id().cc(), p->length()); if (ethtype != htons(_et)) { if (ntohs(ethtype) == 0x0943) { WritablePacket *pw = p->uniqueify(); struct srpacket *pk = (struct srpacket *)(eh+1); int extra = pk->hlen_wo_data() + sizeof(click_ether); const click_ip *i = reinterpret_cast<const click_ip *>(pw->data()+extra); pw->set_ip_header(i, i->ip_hl << 2); StringAccum sa; sa << EtherAddress(eh->ether_shost) << " " << IPAddress(i->ip_src) << " " << ntohs(i->ip_id) << " " << IPAddress(i->ip_dst); click_chatter("%s ackfilter %s", id().cc(), sa.c_str()); } output(0).push(p); return; } click_chatter("ackfilter received a packet with ackheader and ethtype %04x at %u", ntohs(ethtype), Timestamp::now().msec1()); // has an ack header, try to separate that into another packet struct click_enc_ack *ackh = (struct click_enc_ack *)(eh + 1); uint8_t hlen = ackh->get_hlen(ackh->nentries()); ackh = (struct click_enc_ack*) malloc(hlen); memcpy(ackh, (struct click_enc_ack*)(eh+1), hlen); int acklen = sizeof(click_ether) + hlen; WritablePacket *ackpkt = Packet::make(acklen); if (!ackpkt) return; StringAccum sa; sa << "push() separating ack packet from ea " << EtherAddress(src); click_chatter("%s %s", id().cc(), sa.c_str()); memcpy(ackpkt->data(), p->data(), acklen); output(1).push(ackpkt); if (ackh->_et_next == htons(_et_nothing)) return; // a pure ack packet click_chatter("%s : pushing the data packet", id().cc()); // sort out the original packet too WritablePacket *wp = p->uniqueify(); wp->pull(acklen); // not sure about this offset...*** wp = wp->push(sizeof(click_ether)); click_ether *oeth = (click_ether *)wp->data(); memcpy(oeth->ether_dhost, dst.data(), 6); memcpy(oeth->ether_shost, src.data(), 6); oeth->ether_type = ackh->_et_next; sa.clear(); sa << "Source EA " << src << " Dst EA " << dst; click_chatter("%s data packet %s %#x", id().cc(), sa.c_str(), ntohs(ackh->_et_next)); output(0).push(wp);}CLICK_ENDDECLSEXPORT_ELEMENT(AckFilter)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -