Annotation of embedaddon/strongswan/src/libcharon/plugins/p_cscf/p_cscf_handler.c, revision 1.1.1.1
1.1 misho 1: /*
2: * Copyright (C) 2016 Tobias Brunner
3: * HSR Hochschule fuer Technik Rapperswil
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 "p_cscf_handler.h"
17:
18: #include <networking/host.h>
19: #include <utils/debug.h>
20:
21: typedef struct private_p_cscf_handler_t private_p_cscf_handler_t;
22:
23: /**
24: * Private data
25: */
26: struct private_p_cscf_handler_t {
27:
28: /**
29: * Public interface
30: */
31: p_cscf_handler_t public;
32: };
33:
34: METHOD(attribute_handler_t, handle, bool,
35: private_p_cscf_handler_t *this, ike_sa_t *ike_sa,
36: configuration_attribute_type_t type, chunk_t data)
37: {
38: host_t *server;
39: int family = AF_INET6;
40:
41: switch (type)
42: {
43: case P_CSCF_IP4_ADDRESS:
44: family = AF_INET;
45: /* fall-through */
46: case P_CSCF_IP6_ADDRESS:
47: server = host_create_from_chunk(family, data, 0);
48: if (!server)
49: {
50: DBG1(DBG_CFG, "received invalid P-CSCF server IP");
51: return FALSE;
52: }
53: DBG1(DBG_CFG, "received P-CSCF server IP %H", server);
54: server->destroy(server);
55: return TRUE;
56: default:
57: return FALSE;
58: }
59: }
60:
61: METHOD(attribute_handler_t, release, void,
62: private_p_cscf_handler_t *this, ike_sa_t *ike_sa,
63: configuration_attribute_type_t type, chunk_t data)
64: {
65: switch (type)
66: {
67: case P_CSCF_IP4_ADDRESS:
68: case P_CSCF_IP6_ADDRESS:
69: /* nothing to do as we only log the server IPs */
70: break;
71: default:
72: break;
73: }
74: }
75:
76: /**
77: * Data for attribute enumerator
78: */
79: typedef struct {
80: enumerator_t public;
81: bool request_ipv4;
82: bool request_ipv6;
83: } attr_enumerator_t;
84:
85: METHOD(enumerator_t, enumerate_attrs, bool,
86: attr_enumerator_t *this, va_list args)
87: {
88: configuration_attribute_type_t *type;
89: chunk_t *data;
90:
91: VA_ARGS_VGET(args, type, data);
92: if (this->request_ipv4)
93: {
94: *type = P_CSCF_IP4_ADDRESS;
95: *data = chunk_empty;
96: this->request_ipv4 = FALSE;
97: return TRUE;
98: }
99: if (this->request_ipv6)
100: {
101: *type = P_CSCF_IP6_ADDRESS;
102: *data = chunk_empty;
103: this->request_ipv6 = FALSE;
104: return TRUE;
105: }
106: return FALSE;
107: }
108:
109: CALLBACK(is_family, bool,
110: host_t *host, va_list args)
111: {
112: int family;
113:
114: VA_ARGS_VGET(args, family);
115: return host->get_family(host) == family;
116: }
117:
118: /**
119: * Check if a list has a host of a given family
120: */
121: static bool has_host_family(linked_list_t *list, int family)
122: {
123: return list->find_first(list, is_family, NULL, family);
124: }
125:
126: METHOD(attribute_handler_t, create_attribute_enumerator, enumerator_t *,
127: private_p_cscf_handler_t *this, ike_sa_t *ike_sa,
128: linked_list_t *vips)
129: {
130: attr_enumerator_t *enumerator;
131:
132: if (ike_sa->get_version(ike_sa) == IKEV1)
133: {
134: return enumerator_create_empty();
135: }
136:
137: INIT(enumerator,
138: .public = {
139: .enumerate = enumerator_enumerate_default,
140: .venumerate = _enumerate_attrs,
141: .destroy = (void*)free,
142: },
143: );
144: if (lib->settings->get_bool(lib->settings, "%s.plugins.p-cscf.enable.%s",
145: FALSE, lib->ns, ike_sa->get_name(ike_sa)))
146: {
147: enumerator->request_ipv4 = has_host_family(vips, AF_INET);
148: enumerator->request_ipv6 = has_host_family(vips, AF_INET6);
149: }
150: return &enumerator->public;
151: }
152:
153: METHOD(p_cscf_handler_t, destroy, void,
154: private_p_cscf_handler_t *this)
155: {
156: free(this);
157: }
158:
159: /**
160: * See header
161: */
162: p_cscf_handler_t *p_cscf_handler_create()
163: {
164: private_p_cscf_handler_t *this;
165:
166: INIT(this,
167: .public = {
168: .handler = {
169: .handle = _handle,
170: .release = _release,
171: .create_attribute_enumerator = _create_attribute_enumerator,
172: },
173: .destroy = _destroy,
174: },
175: );
176:
177: return &this->public;
178: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>