📄 tcpdemux.cc
字号:
/* * tcpdemux.{cc,hh} -- demultiplexes tcp flows * Benjie Chen * * Copyright (c) 2001 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 <clicknet/ip.h>#include <clicknet/tcp.h>#include <click/elemfilter.hh>#include <click/router.hh>#include <click/error.hh>#include "tcpdemux.hh"CLICK_DECLSTCPDemux::TCPDemux() : Element(1, 1){}TCPDemux::~TCPDemux(){}intTCPDemux::configure(Vector<String> &, ErrorHandler *){ return 0;}intTCPDemux::find_flow(Packet *p){ const click_ip *iph = p->ip_header(); const click_tcp *tcph = p->tcp_header(); // match (sa,sp,da,dp) IPFlowID fid(p); int *iptr = _flows.findp(fid.rev()); if (iptr) return *iptr; // match (0,0,da,dp) fid = IPFlowID(0, 0, iph->ip_dst, tcph->th_dport); iptr = _flows.findp(fid.rev()); if (iptr) return *iptr; // match (0,0,0,dp) fid = IPFlowID(0, 0, 0, tcph->th_dport); iptr = _flows.findp(fid.rev()); if (iptr) return *iptr; // match (0,0,da,0) fid = IPFlowID(0, 0, iph->ip_dst, 0); iptr = _flows.findp(fid.rev()); if (iptr) return *iptr; // match (0,0,0,0) fid = IPFlowID(0, 0, 0, 0); iptr = _flows.findp(fid); if (iptr) return *iptr; return -1;}voidTCPDemux::push(int, Packet *p){ int port = find_flow(p); if (port < 0 || port > noutputs()) { click_chatter("reject packet from unknown flow"); p->kill(); } else output(port).push(p);}boolTCPDemux::add_flow(IPAddress sa, unsigned short sp, IPAddress da, unsigned short dp, unsigned port){ if (_flows.findp(IPFlowID(sa, sp, da, dp))) return false; else return _flows.insert(IPFlowID(sa, sp, da, dp), port);}boolTCPDemux::remove_flow(IPAddress sa, unsigned short sp, IPAddress da, unsigned short dp){ return _flows.remove(IPFlowID(sa, sp, da, dp));}EXPORT_ELEMENT(TCPDemux)#include <click/bighashmap.cc>CLICK_ENDDECLS
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -