d236c95d9b9b661bf7a6d39786a371d7b24f56d8
[strongswan.git] / src / charon / encoding / payloads / endpoint_notify.h
1 /*
2 * Copyright (C) 2007 Tobias Brunner
3 * 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 * $Id$
16 */
17
18 /**
19 * @defgroup endpoint_notify endpoint_notify
20 * @{ @ingroup payloads
21 */
22
23 #ifndef ENDPOINT_NOTIFY_H_
24 #define ENDPOINT_NOTIFY_H_
25
26 #define ME_PRIO_HOST 255
27 #define ME_PRIO_PEER 128
28 #define ME_PRIO_SERVER 64
29 #define ME_PRIO_RELAY 0
30
31 typedef enum me_endpoint_family_t me_endpoint_family_t;
32 typedef enum me_endpoint_type_t me_endpoint_type_t;
33 typedef struct endpoint_notify_t endpoint_notify_t;
34
35 #include <encoding/payloads/notify_payload.h>
36
37 /**
38 * ME endpoint families.
39 */
40 enum me_endpoint_family_t {
41
42 NO_FAMILY = 0,
43
44 IPv4 = 1,
45
46 IPv6 = 2,
47
48 MAX_FAMILY = 3
49
50 };
51
52 /**
53 * ME endpoint types.
54 */
55 enum me_endpoint_type_t {
56
57 NO_TYPE = 0,
58
59 HOST = 1,
60
61 PEER_REFLEXIVE = 2,
62
63 SERVER_REFLEXIVE = 3,
64
65 RELAYED = 4,
66
67 MAX_TYPE = 5
68
69 };
70
71 /**
72 * enum name for me_endpoint_type_t.
73 */
74 extern enum_name_t *me_endpoint_type_names;
75
76 /**
77 * Class representing a ME_ENDPOINT Notify payload. In fact it's not
78 * the notify per se, but the notification data of that notify that is
79 * handled with this class.
80 */
81 struct endpoint_notify_t {
82 /**
83 * Returns the priority of this endpoint.
84 *
85 * @return priority
86 */
87 u_int32_t (*get_priority) (endpoint_notify_t *this);
88
89 /**
90 * Sets the priority of this endpoint.
91 *
92 * @param priority priority
93 */
94 void (*set_priority) (endpoint_notify_t *this, u_int32_t priority);
95
96 /**
97 * Returns the endpoint type of this endpoint.
98 *
99 * @return endpoint type
100 */
101 me_endpoint_type_t (*get_type) (endpoint_notify_t *this);
102
103 /**
104 * Returns the endpoint family of this endpoint.
105 *
106 * @return endpoint family
107 */
108 me_endpoint_family_t (*get_family) (endpoint_notify_t *this);
109
110 /**
111 * Returns the host of this endpoint.
112 *
113 * @return host
114 */
115 host_t *(*get_host) (endpoint_notify_t *this);
116
117 /**
118 * Returns the base of this endpoint.
119 *
120 * If this is not a SERVER_REFLEXIVE endpoint, the returned host is the same
121 * as the one returned by get_host.
122 *
123 * @return host
124 */
125 host_t *(*get_base) (endpoint_notify_t *this);
126
127 /**
128 * Generates a notification payload from this endpoint.
129 *
130 * @return built notify_payload_t
131 */
132 notify_payload_t *(*build_notify) (endpoint_notify_t *this);
133
134 /**
135 * Clones an endpoint_notify_t object.
136 *
137 * @return cloned object
138 */
139 endpoint_notify_t *(*clone) (endpoint_notify_t *this);
140
141 /**
142 * Destroys an endpoint_notify_t object.
143 */
144 void (*destroy) (endpoint_notify_t *this);
145 };
146
147 /**
148 * Creates an empty endpoint_notify_t object.
149 *
150 * @return created endpoint_notify_t object
151 */
152 endpoint_notify_t *endpoint_notify_create(void);
153
154
155 /**
156 * Creates an endpoint_notify_t object from a host.
157 *
158 * @param type the endpoint type
159 * @param host host to base the notify on (gets cloned)
160 * @param base base of the endpoint, applies only to reflexive endpoints (gets cloned)
161 * @return created endpoint_notify_t object
162 */
163 endpoint_notify_t *endpoint_notify_create_from_host(me_endpoint_type_t type,
164 host_t *host, host_t *base);
165
166 /**
167 * Creates an endpoint_notify_t object from a notify payload.
168 *
169 * @param notify the notify payload
170 * @return - created endpoint_notify_t object
171 * - NULL if invalid payload
172 */
173 endpoint_notify_t *endpoint_notify_create_from_payload(notify_payload_t *notify);
174
175 #endif /*ENDPOINT_NOTIFY_H_ @} */