⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fromhost.hh

📁 Click is a modular router toolkit. To use it you ll need to know how to compile and install the sof
💻 HH
字号:
// -*- mode: c++; c-basic-offset: 4 -*-#ifndef CLICK_FROMHOST_HH#define CLICK_FROMHOST_HH#include <click/element.hh>#include <click/etheraddress.hh>#include <click/timer.hh>#include <click/notifier.hh>/*=cFromHost(DEVNAME [, PREFIX, I<KEYWORDS>])=s commreads packets from Linux=dCaptures packets orginating from the Linux kernel and pushes them on output 0.The type of packet depends on the TYPE keyword argument.  For TYPE ETHER,output packets have Ethernet headers; only the protocol field is interesting.For TYPE IP, output packets are IP packets.  TYPE ETHER is the default,although TYPE IP is probably more useful.Installs a fake interface called DEVNAME.  If PREFIX is given, changes therouting table so that every packet destined for PREFIX = ADDR/MASK is sentthrough that interface.  The packet then leaves on output 0. The device'snative address is ADDR.After the fake device is created, the effect of bringing up the interfaceand changing the routing table is analogous to:  % /sbin/ifconfig DEVNAME up  % /sbin/route add -net ADDR netmask MASK DEVNAMEThis element is only available in the Linux kernel module.Keyword arguments are:=over 8=item TYPESpecifies the device type.  Valid options are C<ETHER> and C<IP>.  Currentlydefaults to C<ETHER> with a warning.=item PREFIXSpecifies the fake device's IP address and netmask.=item ETHEREthernet address. Specifies the fake device's Ethernet address. Default is00-01-02-03-04-05.=item MTUInteger.  The maximum transmission unit reported to Linux for the device.Defaults to 1500.=item CAPACITYUnsigned.  Maximum length of the internal queue that collects packets fromLinux.  Defaults to 100.  If this queue overflows, packets will be silentlydropped.=item CLEAR_ANNOBoolean.  Sets whether or not to clear the user annotation area on packetsreceived from Linux.  This consists of the user annotations.If false, this area is left as it was received from Linux.(Note that the packet type, device, and header annotations are left as is.)Defaults to true.=back=nIf TYPE is IP, FromHost will set the packet's IP header and destination IPaddress annotations.  Packets with bad IP version or header length are droppedor emitted on output 1 if it exists.  Note that FromHost doesn't check IPchecksums or full packet lengths.If TYPE is ETHER, Linux will send ARP queries to the fake device. You mustrespond to these queries in order to receive any IP packets, but you canobviously respond with any Ethernet address you'd like. Here is one commonidiom:  FromHost(fake0, 192.0.0.1/8, TYPE ETHER)    -> fromhost_cl :: Classifier(12/0806, 12/0800);  fromhost_cl[0] -> ARPResponder(0.0.0.0/0 1-1-1-1-1-1) -> ToHost;  fromhost_cl[1] -> ... // IP packets=e  FromHost(fake0, 192.0.0.1/8) -> ...;=h length rReturn the current length of the internal queue.=h capacity rReturn the maximum length of the internal queue (the CAPACITY argument).=h drops rReturn the number of packets dropped off the internal queue so far.=a ToHost, FromDevice, PollDevice, ToDevice */#include <click/cxxprotect.h>CLICK_CXX_PROTECT#include <linux/netdevice.h>#include <linux/route.h>CLICK_CXX_UNPROTECT#include <click/cxxunprotect.h>#include <click/standard/storage.hh>#include "elements/linuxmodule/anydevice.hh"class EtherAddress;class FromHost : public AnyDevice, public Storage { public:    FromHost();    ~FromHost();    static void static_initialize();    const char *class_name() const	{ return "FromHost"; }    const char *port_count() const	{ return "0/1-2"; }    const char *processing() const	{ return PUSH; }    void *cast(const char *name);    net_device_stats *stats()		{ return &_stats; }    int configure_phase() const		{ return CONFIGURE_PHASE_FROMHOST; }    int configure(Vector<String> &, ErrorHandler *);    int initialize(ErrorHandler *);    void add_handlers();    void cleanup(CleanupStage);    int set_device_addresses(ErrorHandler *);    bool run_task(Task *);  private:    EtherAddress _macaddr;    IPAddress _destaddr;    IPAddress _destmask;    net_device_stats _stats;    Task _task;    Timer _wakeup_timer;    enum { smq_size = 4 };    union {	Packet *smq[smq_size + 1];	Packet **lgq;    } _q;    NotifierSignal _nonfull_signal;    int _mtu;    unsigned _drops;    unsigned _ninvalid;    net_device *new_device(const char *);    static int fl_tx(struct sk_buff *, net_device *);    enum { h_length };    static String read_handler(Element *e, void *thunk);};#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -