Click
Loading...
Searching...
No Matches
addressinfo.hh
1// -*- related-file-name: "../../../elements/standard/addressinfo.cc" -*-
2#ifndef CLICK_ADDRESSINFO_HH
3#define CLICK_ADDRESSINFO_HH
4#include <click/element.hh>
5CLICK_DECLS
6
7/*
8=c
9
10AddressInfo(NAME ADDRESS [ADDRESS...], ...)
11
12=s information
13
14specifies address information
15
16=io
17
18None
19
20=d
21
22Lets you use mnemonic names for IPv4 and IPv6 addresses, IPv4 and IPv6
23address prefixes, and Ethernet addresses. Each argument has the form `NAME
24ADDRESS [ADDRESS...]', which associates the given ADDRESSes with NAME. For
25example, if a configuration contains this AddressInfo element,
26
27 AddressInfo(mauer 10.0.0.1, mazu 10.0.0.10);
28
29then other configuration strings can use C<mauer> and C<mazu> as mnemonics
30for the IP addresses 10.0.0.1 and 10.0.0.10, respectively.
31
32The mnemonic names introduced by AddressInfo elements are local with
33respect to compound elements. That is, names created inside a compound
34element apply only within that compound element and its subelements. For
35example:
36
37 AddressInfo(mauer 10.0.0.1);
38 compound :: {
39 AddressInfo(mazu 10.0.0.10);
40 ... -> IPEncap(6, mauer, mazu) -> ... // OK
41 };
42 ... -> IPEncap(6, mauer, mazu) -> ... // error: `mazu' undefined
43
44Any name can be simultaneously associated with an IP address, an IP network
45address, and an Ethernet address. The kind of address that is returned is
46generally determined from context. For example:
47
48 AddressInfo(mauer 10.0.0.1 00-50-BA-85-84-A9);
49 ... -> IPEncap(6, mauer, ...) // as IP address
50 -> EtherEncap(0x0800, mauer, ...) -> ... // as Ethernet address
51 ... -> ARPResponder(mauer) -> ... // as IP address and Ethernet address!
52
53An optional suffix makes the context unambiguous. C<NAME> is an ambiguous
54reference to some address, but C<NAME:ip> is always an IPv4 address,
55C<NAME:ipnet> is always an IPv4 network address (IPv4 address prefix),
56C<NAME:ip6> is always an IPv6 address, C<NAME:ip6net> is always an IPv6
57network address, and C<NAME:eth> is always an Ethernet address.
58
59Names with both address and prefix definitions are preferentially parsed as
60addresses. For example:
61
62 AddressInfo(boojum 10.0.0.1/24); // defines address and prefix
63 a1 :: ARPResponder(boojum 00-01-02-03-04-05);
64 // a1 will have the same configuration as:
65 a2 :: ARPResponder(10.0.0.1/32 00-01-02-03-04-05);
66
67To prefer the network prefix, use C<NAME:ipnet>.
68
69If C<NAME:ipnet> is a valid IPv4 network address, then C<NAME:bcast> is a
70valid IPv4 address equaling the broadcast address for that network. This is
71obtained by setting all the host bits in the address prefix to 1.
72
73C<NAME:gw> usually equals the default gateway address for network
74C<NAME>. If C<NAME> is a device, then C<NAME:gw> can sometimes be
75looked up explicitly; otherwise, C<NAME:gw> is calculated from
76C<NAME:ipnet> by setting the lowest-order bit in the network address.
77
78=head1 DEFAULT ADDRESSES
79
80If you do not define an address for a given NAME, AddressInfo will use the
81default, if any. Defaults are as follows:
82
83=over 2
84
85=item *
86
87For Ethernet addresses, Click checks for an Ethernet device named NAME, and
88uses its address. (At userlevel, this works only on BSD and Linux.)
89
90=item *
91
92For IPv4 addresses, Click checks for a network device named NAME, and uses
93its primary IPv4 address.
94
95=item *
96
97For C<NAME:gw>, Click checks for a network device named NAME, and uses its
98default gateway.
99
100=back
101
102These defaults are not available on all platforms.
103
104=a
105
106PortInfo */
107
108class AddressInfo : public Element { public:
109
110 AddressInfo();
111
112 const char *class_name() const override { return "AddressInfo"; }
113
114 int configure_phase() const { return CONFIGURE_PHASE_FIRST; }
115 int configure(Vector<String> &conf, ErrorHandler *errh);
116
117 enum {
118 f_nodevice = 1
119 };
120 static bool query_ip(const String &s, unsigned char *store, const Element *context, int flags = 0);
121 static bool query_ip_prefix(String s, unsigned char *store_addr, unsigned char *store_mask, const Element *context, int flags = 0);
122#if HAVE_IP6
123 static bool query_ip6(String s, unsigned char *store, const Element *context, int flags = 0);
124 static bool query_ip6_prefix(String s, unsigned char *store_addr, int *store_prefixlen, const Element *context, int flags = 0);
125#endif
126 static bool query_ethernet(String s, unsigned char *store, const Element *context, int flags = 0);
127
128 private:
129
130 static bool query_netdevice(const String &name, unsigned char *store, int type, int len, const Element *context, int flags);
131
132};
133
134CLICK_ENDDECLS
135#endif
Base class for Click elements.
Definition element.hh:42
String name() const
Return the element's name.
Definition element.cc:555
virtual int configure_phase() const
Return the element's configure phase, which determines the order in which elements are configured and...
Definition element.cc:1308
virtual const char * flags() const
Return the element's flags.
Definition element.cc:1234
virtual int configure(Vector< String > &conf, ErrorHandler *errh)
Parse the element's configuration arguments.
Definition element.cc:1372
virtual const char * class_name() const =0
Return the element's class name.
Error reporting class.
Definition error.hh:90
A string of characters.
Definition string.hh:22
Vector template.
Definition vector.hh:111
Click's Element class.