diff options
author | Jozsef Kadlecsik <kadlec@blackhole.kfki.hu> | 2010-10-24 21:42:48 +0200 |
---|---|---|
committer | Jozsef Kadlecsik <kadlec@blackhole.kfki.hu> | 2010-10-24 21:42:48 +0200 |
commit | 0d32c5c070f817229110f92d7b31df9a3e4eeec5 (patch) | |
tree | 5ee04a9e03de32d2029ad0d708811e382ca922d1 /lib/icmpv6.c | |
parent | 62a3d29539aa109fed1c8a20d63ef95948b13842 (diff) |
Fixes, cleanups, commentsv5.0-pre8
- More comments added to the code
- ICMP and ICMPv6 support added to the hash:ip,port, hash:ip,port,ip
and hash:ip,port,net types
- hash:net and hash:ip,port,net types are reworked
- hash:net,port type added
- Wrong direction parameters fixed in hash:ip,port
- Helps and manpage are updated
- More tests added
- Ugly macros are rewritten to functions in parse.c
(Holger Eitzenberger)
- resize related bug in hash types fixed (Holger Eitzenberger)
- autoreconf patches by Jan Engelhardt applied
- netlink patch minimalized: dumping can be initialized by a second
parsing of the message (thanks to David and Patrick for the suggestion)
- IPv4/IPv6 address attributes are introduced in order to fix the context
(suggested by David)
Diffstat (limited to 'lib/icmpv6.c')
-rw-r--r-- | lib/icmpv6.c | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/lib/icmpv6.c b/lib/icmpv6.c new file mode 100644 index 0000000..c32a6a4 --- /dev/null +++ b/lib/icmpv6.c @@ -0,0 +1,66 @@ +/* Copyright 2007-2010 Jozsef Kadlecsik (kadlec@blackhole.kfki.hu) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ +#include <libipset/utils.h> /* STRNEQ */ +#include <libipset/icmpv6.h> /* prototypes */ + +struct icmpv6_names { + const char *name; + uint8_t type, code; +}; + +static const struct icmpv6_names icmpv6_typecodes[] = { + { "no-route", 1, 0 }, + { "communication-prohibited", 1, 1 }, + { "address-unreachable", 1, 3 }, + { "port-unreachable", 1, 4 }, + { "packet-too-big", 2, 0 }, + { "ttl-zero-during-transit", 3, 0 }, + { "ttl-zero-during-reassembly", 3, 1 }, + { "bad-header", 4, 0 }, + { "unknown-header-type", 4, 1 }, + { "unknown-option", 4, 2 }, + { "echo-request", 128, 0 }, + { "ping", 128, 0 }, + { "echo-reply", 129, 0 }, + { "pong", 129, 0 }, + { "router-solicitation", 133, 0 }, + { "router-advertisement", 134, 0 }, + { "neighbour-solicitation", 135, 0 }, + { "neigbour-solicitation", 135, 0 }, + { "neighbour-advertisement", 136, 0 }, + { "neigbour-advertisement", 136, 0 }, + { "redirect", 137, 0 }, +}; + +const char * id_to_icmpv6(uint8_t id) +{ + return id < ARRAY_SIZE(icmpv6_typecodes) ? icmpv6_typecodes[id].name : NULL; +} + +const char * icmpv6_to_name(uint8_t type, uint8_t code) +{ + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(icmpv6_typecodes); i++) + if (icmpv6_typecodes[i].type == type && icmpv6_typecodes[i].code == code) + return icmpv6_typecodes[i].name; + + return NULL; +} + +int name_to_icmpv6(const char *str, uint16_t *typecode) +{ + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(icmpv6_typecodes); i++) + if (STRNEQ(icmpv6_typecodes[i].name, str, strlen(str))) { + *typecode = (icmpv6_typecodes[i].type << 8) | icmpv6_typecodes[i].code; + return 0; + } + + return -1; +} |