📄 checkipheader.hh
字号:
#ifndef CLICK_CHECKIPHEADER_HH#define CLICK_CHECKIPHEADER_HH#include <click/element.hh>#include <click/atomic.hh>#include <click/ipaddresslist.hh>CLICK_DECLS/*=cCheckIPHeader([OFFSET, I<keywords> OFFSET, INTERFACES, BADSRC, GOODDST, CHECKSUM, VERBOSE, DETAILS])=s IP, checkingchecks IP header=dInput packets should have IP headers starting OFFSET bytes in. Default OFFSETis zero. Checks that the packet's length is reasonable, and that the IPversion, header length, length, and checksum fields are valid. Checks that theIP source address is a legal unicast address, or that the packet is destinedfor one of this machine's addresses (see below). Shortens packets to the IPlength, if the IP length is shorter than the nominal packet length (due toEthernet padding, for example). Also sets the destination IP addressannotation to the actual destination IP address.CheckIPHeader emits valid packets on output 0. Invalid packets are pushed outon output 1, unless output 1 was unused; if so, drops invalid packets.CheckIPHeader checks packets' source addresses for validity if one or more ofthe INTERFACES, BADSRC, and GOODDST keyword arguments are supplied (RFC18125.3.7).CheckIPHeader prints a message to the console the first time it encounters anincorrect IP packet (but see VERBOSE below).Keyword arguments are:=over 5=item CHECKSUMBoolean. If true, then check each packet's checksum for validity; if false, donot check the checksum. Default is true.=item OFFSETUnsigned integer. Byte position at which the IP header begins. Default is 0.=item BADSRCSpace-separated list of IP addresses. CheckIPHeader will drop packets whosesource address is on this list (but see GOODDST below). Default is empty.=item GOODDSTSpace-separated list of IP addresses. CheckIPHeader exempts packets whosedestination address is on this list from BADSRC processing. Default is empty.=item INTERFACESSpace-separated list of IP addresses with network prefixes, meant to representthis router's interface addresses. This argument specifies both BADSRC andGOODDST. Specifically, the argument "INTERFACES 18.26.4.9/24 18.32.9.44/28"acts like a BADSRC of "18.26.4.255 18.32.9.47 0.0.0.0 255.255.255.255" -- theset of broadcast addresses for this router -- and a GOODDST of "18.26.4.918.32.9.44". Default is not given.=item VERBOSEBoolean. If it is true, then a message will be printed for every erroneouspacket, rather than just the first. False by default.=item DETAILSBoolean. If it is true, then CheckIPHeader will maintain detailed counts ofhow many packets were dropped for each possible reason, accessible through theC<drop_details> handler. False by default.=back=nCheckIPHeader supports an old configuration syntax:CheckIPHeader([BADSRC2, OFFSET, I<keywords>])The BADSRC2 argument behaves like the BADSRC keyword, except that if you usethis syntax, 0.0.0.0 and 255.255.255.255 considered bad addresses in additionto those explicitly in the list. This syntax is deprecated and should not beused in new configurations.=h drops read-onlyReturns the number of incorrect packets CheckIPHeader has seen.=h drop_details read-onlyReturns a text file showing how many erroneous packets CheckIPHeader has seen,subdivided by error. Only available if the DETAILS keyword argument was true.=a CheckIPHeader2, MarkIPHeader, SetIPChecksum, StripIPHeader,CheckTCPHeader, CheckUDPHeader, CheckICMPHeader */class CheckIPHeader : public Element { public: CheckIPHeader(); ~CheckIPHeader(); static void static_initialize(); static void static_cleanup(); const char *class_name() const { return "CheckIPHeader"; } const char *processing() const { return "a/ah"; } void notify_noutputs(int); int configure(Vector<String> &, ErrorHandler *); void add_handlers(); Packet *simple_action(Packet *); private: unsigned _offset; IPAddressList _bad_src; // array of illegal IP src addresses bool _checksum;#if HAVE_FAST_CHECKSUM && FAST_CHECKSUM_ALIGNED bool _aligned : 1;#endif bool _verbose : 1; IPAddressList _good_dst; // array of IP dst addrs for which _bad_src // does not apply atomic_uint32_t _drops; atomic_uint32_t *_reason_drops; enum Reason { MINISCULE_PACKET, BAD_VERSION, BAD_HLEN, BAD_IP_LEN, BAD_CHECKSUM, BAD_SADDR, NREASONS }; static const char * const reason_texts[NREASONS]; Packet *drop(Reason, Packet *); static String read_handler(Element *, void *); friend class CheckIPHeader2; };CLICK_ENDDECLS#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -