diff options
Diffstat (limited to 'src/libstrongswan/selectors/traffic_selector.c')
-rw-r--r-- | src/libstrongswan/selectors/traffic_selector.c | 47 |
1 files changed, 41 insertions, 6 deletions
diff --git a/src/libstrongswan/selectors/traffic_selector.c b/src/libstrongswan/selectors/traffic_selector.c index 75a8717dd..b9d9b6556 100644 --- a/src/libstrongswan/selectors/traffic_selector.c +++ b/src/libstrongswan/selectors/traffic_selector.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007-2009 Tobias Brunner + * Copyright (C) 2007-2013 Tobias Brunner * Copyright (C) 2005-2007 Martin Willi * Copyright (C) 2005 Jan Hutter * Hochschule fuer Technik Rapperswil @@ -194,6 +194,22 @@ static bool is_any(private_traffic_selector_t *this) } /** + * Print ICMP/ICMPv6 type and code + */ +static int print_icmp(printf_hook_data_t *data, u_int16_t port) +{ + u_int8_t type, code; + + type = traffic_selector_icmp_type(port); + code = traffic_selector_icmp_code(port); + if (code) + { + return print_in_hook(data, "%d(%d)", type, code); + } + return print_in_hook(data, "%d", type); +} + +/** * Described in header. */ int traffic_selector_printf_hook(printf_hook_data_t *data, @@ -302,20 +318,35 @@ int traffic_selector_printf_hook(printf_hook_data_t *data, { struct servent *serv; - serv = getservbyport(htons(this->from_port), serv_proto); - if (serv) + if (this->protocol == IPPROTO_ICMP || + this->protocol == IPPROTO_ICMPV6) { - written += print_in_hook(data, "%s", serv->s_name); + written += print_icmp(data, this->from_port); } else { - written += print_in_hook(data, "%d", this->from_port); + serv = getservbyport(htons(this->from_port), serv_proto); + if (serv) + { + written += print_in_hook(data, "%s", serv->s_name); + } + else + { + written += print_in_hook(data, "%d", this->from_port); + } } } else if (is_opaque(this)) { written += print_in_hook(data, "OPAQUE"); } + else if (this->protocol == IPPROTO_ICMP || + this->protocol == IPPROTO_ICMPV6) + { + written += print_icmp(data, this->from_port); + written += print_in_hook(data, "-"); + written += print_icmp(data, this->to_port); + } else { written += print_in_hook(data, "%d-%d", @@ -910,6 +941,10 @@ static private_traffic_selector_t *traffic_selector_create(u_int8_t protocol, .protocol = protocol, .type = type, ); - + if (protocol == IPPROTO_ICMP || protocol == IPPROTO_ICMPV6) + { + this->from_port = from_port < 256 ? from_port << 8 : from_port; + this->to_port = to_port < 256 ? to_port << 8 : to_port; + } return this; } |