📄 arpquerier.hh
字号:
#ifndef CLICK_ARPQUERIER_HH#define CLICK_ARPQUERIER_HH#include <click/element.hh>#include <click/etheraddress.hh>#include <click/ipaddress.hh>#include <click/sync.hh>#include <click/timer.hh>#include "arptable.hh"CLICK_DECLS/*=cARPQuerier(IP, ETH, I<keywords>)ARPQuerier(NAME, I<keywords>)=s arpencapsulates IP packets in Ethernet headers found via ARP=dHandles most of the ARP protocol. Argument IP should bethis host's IP address, and ETH should be this host'sEthernet address. (Inthe one-argument form, NAME should be shorthand forboth an IP and an Ethernet address; see AddressInfo(n).)Packets arriving on input 0 should be IP packets, and must have theirdestination address annotations set.If an Ethernet address is already knownfor the destination, the IP packet is wrapped in an Ethernetheader and sent to output 0. Otherwise the IP packet is saved andan ARP query is sent instead. If an ARP response arriveson input 1 for an IP address that we need, the mapping isrecorded and any saved IP packets are sent.The ARP reply packets on input 1 should include the Ethernet header.ARPQuerier may have one or two outputs. If it has two, then ARP queriesare sent to the second output.ARPQuerier implements special behavior for 0.0.0.0, 255.255.255.255, multicastaddresses, and, if specified, any BROADCAST address. Packets addressed to0.0.0.0 are dropped. Packets for broadcast addresses are forwarded withdestination Ethernet address FF-FF-FF-FF-FF-FF. Multicast IP addresses areforwarded to 01-00-5E-xx-yy-zz, where xx-yy-zz are the lower 23 bits of themulticast IP address, as specified in RFC1112.Keyword arguments are:=over 8=item TABLEElement. Names an ARPTable element that holds this element's correspondingARP state. By default ARPQuerier creates its own internal ARPTable and usesthat. If TABLE is specified, CAPACITY, ENTRY_CAPACITY, and TIMEOUT areignored.=item CAPACITYUnsigned integer. The maximum number of saved IP packets the table willhold at a time. Default is 2048.=item ENTRY_CAPACITYUnsigned integer. The maximum number of ARP entries the table will holdat a time. Default is 0, which means unlimited.=item TIMEOUTTime in seconds. Amount of time before an ARP entry expires. Defaults to1 minute.=item BROADCASTIP address. Local broadcast IP address. Packets sent to this address will beforwarded to Ethernet address FF-FF-FF-FF-FF-FF. Defaults to the localbroadcast address that can be extracted from the IP address's correspondingprefix, if any.=back=e c :: Classifier(12/0806 20/0002, 12/0800, ...); a :: ARPQuerier(18.26.4.24, 00:00:C0:AE:67:EF); c[0] -> a[1]; c[1] -> ... -> a[0]; a[0] -> ... -> ToDevice(eth0);=nIf a host has multiple interfaces, it will need multipleinstances of ARPQuerier.ARPQuerier uses packets' destination IP address annotations, and can destroytheir next packet annotations.ARPQuerier will send at most 10 queries a second for any IP address.=h ipaddr read/writeReturns or sets the ARPQuerier's source IP address.=h broadcast read-onlyReturns the ARPQuerier's IP broadcast address.=h table read-onlyReturns a textual representation of the ARP table. See ARPTable's tablehandler.=h stats read-onlyReturns textual statistics (queries and drops).=h queries read-onlyReturns the number of queries sent.=h responses read-onlyReturns the number of responses received.=h drops read-onlyReturns the number of packets dropped.=h insert wAdd an entry to the ARP table. The input string should have the form "IP ETH".=h delete wDelete an entry from the ARP table. The input string should be an IP address.=h clear wClear the ARP table.=aARPTable, ARPResponder, ARPFaker, AddressInfo*/class ARPQuerier : public Element { public: ARPQuerier(); ~ARPQuerier(); const char *class_name() const { return "ARPQuerier"; } const char *port_count() const { return "2/1-2"; } const char *processing() const { return PUSH; } const char *flow_code() const { return "xy/x"; } void *cast(const char *name); int configure(Vector<String> &, ErrorHandler *); int live_reconfigure(Vector<String> &, ErrorHandler *); bool can_live_reconfigure() const { return true; } int initialize(ErrorHandler *errh); void add_handlers(); void cleanup(CleanupStage stage); void take_state(Element *e, ErrorHandler *errh); void push(int port, Packet *p); private: ARPTable *_arpt; EtherAddress _my_en; IPAddress _my_ip; IPAddress _my_bcast_ip; // statistics atomic_uint32_t _arp_queries; atomic_uint32_t _drops; atomic_uint32_t _arp_responses; atomic_uint32_t _broadcasts; bool _my_arpt; void send_query_for(Packet *p); void handle_ip(Packet *p, bool response); void handle_response(Packet *p); static void expire_hook(Timer *, void *); static String read_table(Element *, void *); static String read_table_xml(Element *, void *); static String read_handler(Element *, void *); static int write_handler(const String &, Element *, void *, ErrorHandler *); enum { h_table, h_table_xml, h_stats, h_insert, h_delete, h_clear };};CLICK_ENDDECLS#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -