-
Notifications
You must be signed in to change notification settings - Fork 82
/
tohost.hh
144 lines (132 loc) · 4.53 KB
/
tohost.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// -*- mode: c++; c-basic-offset: 4 -*-
#ifndef CLICK_TOHOST_HH
#define CLICK_TOHOST_HH
#include "elements/linuxmodule/anydevice.hh"
/*
* =c
*
* ToHost([DEVNAME, I<keywords>])
*
* =s comm
*
* sends packets to Linux
*
* =d
*
* Hands packets to the ordinary Linux protocol stack.
* You should probably give Linux IP packets addressed to
* the local machine (including broadcasts), and a copy
* of each ARP reply.
*
* If DEVNAME is present, packets without a preset device annotation are have
* their annotations set to that network device. (Linux requires a valid
* device annotation on each received packet.) As with ToDevice, DEVNAME can
* be an Ethernet address.
*
* If TYPE is ETHER, then expects packets with Ethernet headers; this is the
* default. If TYPE is IP, then expects packets with raw IP headers.
*
* This element is only available in the Linux kernel module.
*
* Keyword arguments are:
*
* =over 8
*
* =item SNIFFERS
*
* Boolean. If true, then ToHost will send packets to the kernel so that only
* tcpdump(1), and other sniffer programs on the host, will receive them.
* Default is false.
*
* =item TYPE
*
* Type of interface. Choices are ETHER and IP. Default is ETHER.
*
* =item QUIET
*
* Boolean. If true, then suppress device up/down messages. Default is false.
*
* =item ALLOW_NONEXISTENT
*
* Allow nonexistent devices. If true, and no device named DEVNAME exists when
* the router is initialized, then ToHost will report a warning (rather than
* an error). Later, while the router is running, if a device named DEVNAME
* appears, ToHost will seamlessly begin using it. Default is false.
*
* =item UP_CALL
*
* Write handler. If supplied, this handler is called when the device or link
* comes up.
*
* =item DOWN_CALL
*
* Write handler. If supplied, this handler is called when the device or link
* goes down.
*
* =back
*
* =n
*
* Linux expects packets to have valid device annotations and packet type
* annotations. ToHost will not pass packets with null device annotations to
* Linux! Use the `C<ToHost(eth0)>' syntax to supply a device annotation.
* Most packets generated by Click will have null device annotations -- for
* example, InfiniteSource makes packets with null device annotations.
* Exceptions include FromDevice and PollDevice.
*
* Linux depends on packet type annotations as well. It will generally only
* process packets with packet type annotation HOST. (Other packets, such as
* packets originally sent to some other host, are sent only to packet
* sniffers like tcpdump(1). Linux will handle some BROADCAST and MULTICAST
* packets.) By default, packets made by Click have HOST packet type
* annotations. However, if you modified a packet that you originally got from
* some device, that packet may have some other type. Use SetPacketType to
* reset the type appropriately.
*
* Finally, IPv4 packets should have a destination IP address corresponding
* to DEVNAME, and a routable source address. Otherwise Linux will silently
* drop the packets.
*
* =head2 Patchless Installations
*
* On patched installations, FromDevice intercepts packets before they are
* passed to packet sniffers like tcpdump. However, on patchless
* installations, packet sniffers receive incoming packets before FromDevice
* can intercept them. This means that in a configuration such as
*
* FromDevice(eth0) -> ToHost;
*
* packet sniffers will see eth0's packets twice, once before FromDevice runs
* and once when the packets are handed back to Linux via ToHost.
*
* =h drops read-only
*
* Reports the number of packets ToHost has dropped because they had a null
* device annotation.
*
* =a
*
* ToHostSniffers, FromHost, FromDevice, PollDevice, ToDevice,
* SetPacketType, InfiniteSource */
class ToHost : public AnyDevice { public:
ToHost() CLICK_COLD;
~ToHost() CLICK_COLD;
static void static_initialize();
static void static_cleanup();
const char *class_name() const override { return "ToHost"; }
const char *port_count() const override { return PORTS_1_0; }
const char *processing() const override { return PUSH; }
const char *flags() const { return "S2"; }
int configure_phase() const { return CONFIGURE_PHASE_TODEVICE; }
int configure(Vector<String> &, ErrorHandler *) CLICK_COLD;
int initialize(ErrorHandler *) CLICK_COLD;
void cleanup(CleanupStage) CLICK_COLD;
void add_handlers() CLICK_COLD;
void push(int port, Packet *);
private:
bool _sniffers;
int _drops;
int _type;
friend class ToHostSniffers;
};
#endif