Annotation of embedaddon/strongswan/src/conftest/hooks/log_ts.c, revision 1.1
1.1 ! misho 1: /*
! 2: * Copyright (C) 2010 Martin Willi
! 3: * Copyright (C) 2010 revosec AG
! 4: *
! 5: * This program is free software; you can redistribute it and/or modify it
! 6: * under the terms of the GNU General Public License as published by the
! 7: * Free Software Foundation; either version 2 of the License, or (at your
! 8: * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
! 9: *
! 10: * This program is distributed in the hope that it will be useful, but
! 11: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
! 12: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
! 13: * for more details.
! 14: */
! 15:
! 16: #include "hook.h"
! 17:
! 18: #include <encoding/payloads/ts_payload.h>
! 19:
! 20: typedef struct private_log_ts_t private_log_ts_t;
! 21:
! 22: /**
! 23: * Private data of an log_ts_t object.
! 24: */
! 25: struct private_log_ts_t {
! 26:
! 27: /**
! 28: * Implements the hook_t interface.
! 29: */
! 30: hook_t hook;
! 31: };
! 32:
! 33: METHOD(listener_t, message, bool,
! 34: private_log_ts_t *this, ike_sa_t *ike_sa, message_t *message,
! 35: bool incoming, bool plain)
! 36: {
! 37: if (incoming && plain)
! 38: {
! 39: enumerator_t *enumerator;
! 40: payload_t *payload;
! 41: ts_payload_t *ts;
! 42:
! 43: enumerator = message->create_payload_enumerator(message);
! 44: while (enumerator->enumerate(enumerator, &payload))
! 45: {
! 46: if (payload->get_type(payload) == PLV2_TS_INITIATOR ||
! 47: payload->get_type(payload) == PLV2_TS_RESPONDER)
! 48: {
! 49: ts = (ts_payload_t*)payload;
! 50: host_t *from, *to;
! 51: linked_list_t *list;
! 52: enumerator_t *tsenum;
! 53: traffic_selector_t *selector;
! 54:
! 55: list = ts->get_traffic_selectors(ts);
! 56: tsenum = list->create_enumerator(list);
! 57: while (tsenum->enumerate(tsenum, &selector))
! 58: {
! 59: from = host_create_from_chunk(AF_UNSPEC,
! 60: selector->get_from_address(selector), 0);
! 61: to = host_create_from_chunk(AF_UNSPEC,
! 62: selector->get_to_address(selector), 0);
! 63:
! 64: DBG1(DBG_CFG, "received %N: %N %H-%H proto %u port %u-%u",
! 65: payload_type_short_names, payload->get_type(payload),
! 66: ts_type_name, selector->get_type(selector),
! 67: from, to, selector->get_protocol(selector),
! 68: selector->get_from_port(selector),
! 69: selector->get_to_port(selector));
! 70: }
! 71: tsenum->destroy(tsenum);
! 72:
! 73: list->destroy_offset(list, offsetof(traffic_selector_t, destroy));
! 74: }
! 75: }
! 76: enumerator->destroy(enumerator);
! 77: }
! 78: return TRUE;
! 79: }
! 80:
! 81: METHOD(hook_t, destroy, void,
! 82: private_log_ts_t *this)
! 83: {
! 84: free(this);
! 85: }
! 86:
! 87: /**
! 88: * Create the IKE_AUTH fill hook
! 89: */
! 90: hook_t *log_ts_hook_create(char *name)
! 91: {
! 92: private_log_ts_t *this;
! 93:
! 94: INIT(this,
! 95: .hook = {
! 96: .listener = {
! 97: .message = _message,
! 98: },
! 99: .destroy = _destroy,
! 100: },
! 101: );
! 102:
! 103: return &this->hook;
! 104: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>