|
Click
|
Manages Click name databases. More...
Public Types | |
| enum | DBType { T_NONE = 0 , T_SCHEDULEINFO = 0x00000001 , T_ANNOTATION = 0x00000002 , T_SCRIPT_INSN = 0x00000003 , T_SIGNO = 0x00000004 , T_SPINLOCK = 0x00000005 , T_ETHERNET_ADDR = 0x01000001 , T_IP_ADDR = 0x04000001 , T_IP_PREFIX = 0x04000002 , T_IP_PROTO = 0x04000003 , T_IPFILTER_TYPE = 0x04000004 , T_TCP_OPT = 0x04000005 , T_IPREWRITER_PATTERN = 0x04000006 , T_ICMP_TYPE = 0x04010000 , T_ICMP_CODE = 0x04010100 , T_IP_PORT = 0x04020000 , T_TCP_PORT = 0x04020006 , T_UDP_PORT = 0x04020011 , T_IP_FIELDNAME = 0x04030000 , T_ICMP_FIELDNAME = 0x04030001 , T_TCP_FIELDNAME = 0x04030006 , T_UDP_FIELDNAME = 0x04030011 , T_IP6_ADDR = 0x06000001 , T_IP6_PREFIX = 0x06000002 } |
| Known name database types. More... | |
Public Member Functions | |
| NameInfo () | |
| Construct a NameInfo element. | |
| ~NameInfo () | |
| Destroy a NameInfo object. | |
Static Public Member Functions | |
| static void | static_initialize () |
| Static initialization for NameInfo. | |
| static void | static_cleanup () |
| Static cleanup for NameInfo. | |
| static NameDB * | getdb (uint32_t type, const Element *context, size_t value_size, bool create) |
| Find or create a name database. | |
| static void | installdb (NameDB *db, const Element *context) |
| Install a name database. | |
| static void | uninstalldb (NameDB *db) |
| Uninstall a name database. | |
| static bool | query (uint32_t type, const Element *context, const String &name, void *value_store, size_t value_size) |
| Query installed databases for name. | |
| static bool | query_int (uint32_t type, const Element *context, const String &name, int32_t *value_store) |
| Query installed databases for name, returning a 32-bit integer value. | |
| static bool | query_int (uint32_t type, const Element *context, const String &name, uint32_t *value_store) |
| static String | revquery (uint32_t type, const Element *context, const void *value, size_t value_size) |
| Query installed databases for value. | |
| static String | revquery_int (uint32_t type, const Element *context, int32_t value) |
| Query installed databases for a 32-bit integer value. | |
| static bool | define (uint32_t type, const Element *context, const String &name, const void *value, size_t value_size) |
| Define name to equal value in the installed databases. | |
| static bool | define_int (uint32_t type, const Element *context, const String &name, int32_t value) |
| Define name to equal 32-bit integer value in the installed databases. | |
Manages Click name databases.
NameInfo is the user interface to Click's name databases, a general mechanism for mapping names to values. NameInfo and NameDB implement generally useful properties like names local to a compound element context.
Every name database maps names, which are nonempty strings, to values, which are sequences of bytes. A database is identified by its type, which indicates the kind of name stored in the database, and, optionally, its compound element context, which is a pair of router and element name prefix. The database is used for queries that take place in the given context. A query bubbles up through the databases, starting with the most specific context and getting more general, until it succeeds. A database stores values with a fixed size; it is an error to query a database with the wrong size.
Many common types are defined in the NameDB::DBType enumeration, but NameInfo allows arbitrary other types to be added at run time.
Here's an example of how to query NameInfo:
Many elements also add their own databases to NameInfo; see, for example, the IPNameInfo or IPFilter elements for examples.
| enum NameInfo::DBType |
Known name database types.
| Enumerator | |
|---|---|
| T_NONE | Nonexistent names database. |
| T_SCHEDULEINFO | ScheduleInfo database. |
| T_ANNOTATION | Packet annotation database. |
| T_SCRIPT_INSN | Script instruction names database. |
| T_SIGNO | User-level signal names database. |
| T_SPINLOCK | Spinlock names database. |
| T_ETHERNET_ADDR | Ethernet address names database. |
| T_IP_ADDR | IP address names database. |
| T_IP_PREFIX | IP prefix names database. |
| T_IP_PROTO | IP protocol names database. |
| T_IPFILTER_TYPE | IPFilter instruction names database. |
| T_TCP_OPT | TCP option names database. |
| T_IPREWRITER_PATTERN | IPRewriterPattern database. |
| T_ICMP_TYPE | ICMP type names database. |
| T_ICMP_CODE | ICMP code names database. |
| T_IP_PORT | Starting point for IP per-protocol port names databases. |
| T_TCP_PORT | TCP port names database. |
| T_UDP_PORT | UDP port names database. |
| T_IP_FIELDNAME | Starting point for IP per-protocol field names databases. |
| T_ICMP_FIELDNAME | ICMP field names database. |
| T_TCP_FIELDNAME | TCP field names database. |
| T_UDP_FIELDNAME | UDP field names database. |
| T_IP6_ADDR | IPv6 address names database. |
| T_IP6_PREFIX | IPv6 prefix names database. |
| NameInfo::NameInfo | ( | ) |
Construct a NameInfo element.
Users never need to call this.
| NameInfo::~NameInfo | ( | ) |
|
static |
|
static |
|
static |
Find or create a name database.
| type | database type |
| context | compound element context |
| value_size | size of values stored in database |
| create | whether to create a DynamicNameDB if no database exists |
Returns an installed name database matching type and context. (If context is non-null, then the database matches the implied router and compound element context. Otherwise, the database is the unique global database for the given type.) If create is true, and no database exists exactly matching type and context, then a DynamicNameDB is created and installed with that type, context, and value_size. Otherwise, the search bubbles up through the prefixes of context until an installed database is found.
Returns null if no installed database is found. value_size must match the value size in the returned database.
Most users will use query() and define() directly, not call getdb().
Install a name database.
| db | name database |
| context | compound element context |
Installs the given name database for the compound element context implied by context. (If context is non-null, then the database is installed for the implied router and compound element context. If it is null, the database is installed globally.) The query() and define() operations apply only to installed databases.
It is an error to install a database that has already been installed. It is also an error to install a database for a compound element context that already has a different database installed. An installed NameDB is automatically destroyed when its containing NameInfo is destroyed (for example, when context's router is destroyed).
|
static |
Uninstall a name database.
| db | name database |
Undoes the effects of installdb(). The given database will no longer be used for query() and define() operations.
|
static |
Query installed databases for name.
| type | database type |
| context | compound element context |
| name | name to look up |
| value_store | value storage |
| value_size | size of value storage |
Queries all installed type databases that apply to the compound element context, returning the most specific value matching name. The value is stored in value_store. The installed databases must have the given value_size.
|
static |
Query installed databases for name, returning a 32-bit integer value.
| type | database type |
| context | compound element context |
| name | name to look up |
| value_store | value storage |
Queries all installed type databases that apply to the compound element context, returning the most specific value matching name. The value is stored in value_store. The installed databases must have a value size of 4.
If no matching name is found, query_int checks whether name unparses into a 32-bit integer value (for example, "30"). If so, *value_store is set to the corresponding integer and true is returned. Otherwise, false is returned.
|
static |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
static |
Query installed databases for value.
| type | database type |
| context | compound element context |
| value | points to value to look up |
| value_size | size of value |
Queries all installed type databases that apply to the compound element context, returning the name in the most specific database whose value matches value, or the empty string if the relevant databases don't support reverse queries or no such value exists. The installed databases must have the given value_size.
|
inlinestatic |
Query installed databases for a 32-bit integer value.
| type | database type |
| context | compound element context |
| value | value to look up |
Queries all installed type databases that apply to the compound element context, returning the name in the most specific database whose value matches value, or the empty string if the relevant databases don't support reverse queries or no such value exists. The installed databases must have value size 4.
|
inlinestatic |
Define name to equal value in the installed databases.
| type | database type |
| context | compound element context |
| name | name to define |
| value | points to defined value |
| value_size | size of value |
Defines the given name to value in the installed type database with compound element context. If no database exists exactly matching that type and context, a new DynamicNameDB is created and installed with those values (and the given value_size). A name might not be defined if the existing database for that type and context doesn't support definitions, or if no new database can be created. If any database exists, it must match the given value_size.
|
inlinestatic |
Define name to equal 32-bit integer value in the installed databases.
| type | database type |
| context | compound element context |
| name | name to define |
| value | defined value |
Defines the given name to value in the installed type database with compound element context. If no database exists exactly matching that type and context, a new DynamicNameDB is created and installed with those values (and value size 4). A name might not be defined if the existing database for that type and context doesn't support definitions, or if no new database can be created. If any database exists, it must have value size 4.