aboutsummaryrefslogtreecommitdiffstats
path: root/hicn-light/src/hicn/core/connection.h
blob: b6513ea1aa4050be1249358f76ca1dfaff5ffe37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/*
 * Copyright (c) 2017-2019 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * @file connection.h
 * @brief Wrapper for different types of connections
 *
 * A connection wraps a specific set of {@link IoOperations}.  Those operations
 * allow for input and output.  Connections get stored in the Connection Table.
 *
 */

#ifndef connection_h
#define connection_h
#include <hicn/hicn-light/config.h>
#include <hicn/core/connectionState.h>
#include <hicn/io/ioOperations.h>
#include <hicn/utils/address.h>

#ifdef WITH_MAPME
typedef enum {
  CONNECTION_EVENT_CREATE,
  CONNECTION_EVENT_DELETE,
  CONNECTION_EVENT_UPDATE,
  CONNECTION_EVENT_SET_UP,
  CONNECTION_EVENT_SET_DOWN,
  CONNECTION_EVENT_PRIORITY_CHANGED,
  CONNECTION_EVENT_TAGS_CHANGED,
} connection_event_t;

#endif /* WITH_MAPME */

#ifdef WITH_POLICY
#include <hicn/policy.h>
#endif /* WITH_POLICY */

struct connection;
typedef struct connection Connection;

/**
 * Creates a connection object.
 */
Connection *connection_Create(IoOperations *ops);

/**
 * @function connection_Release
 * @abstract Releases a reference count, destroying on last release
 * @discussion
 *   Only frees the memory on the final reference count.  The pointer will
 *   always be NULL'd.
 */
void connection_Release(Connection **connectionPtr);

/**
 * @function connection_Acquire
 * @abstract A reference counted copy.
 * @discussion
 *   A shallow copy, they share the same memory.
 */
Connection *connection_Acquire(Connection *connection);

/**
 * @function connection_Send
 * @abstract Sends the message on the connection
 * @return true if message sent, false if connection not up
 */
bool connection_Send(const Connection *conn, Message *message);

/**
 * @function connection_SendIOVBuffer
 * @abstract Sends an IOV buffer
 */
bool connection_SendIOVBuffer(const Connection *conn, struct iovec *msg,
    size_t size);

/**
 * @function connection_SendBuffer
 * @abstract Sends a buffer
 */
bool connection_SendBuffer(const Connection *conn, u8 * buffer, size_t length);

/**
 * Return the `IoOperations` instance associated with the specified `Connection`
 * instance.
 * @param [in] connection The allocated connection
 * @return a pointer to the IoOperations instance associated by th specified
 * connection.
 */
IoOperations *connection_GetIoOperations(const Connection *conn);

/**
 * Returns the unique identifier of the connection
 * Calls the underlying IoOperations to fetch the connection id
 * @param [in] connection The allocated connection
 * @return unsigned The unique connection id
 */
unsigned connection_GetConnectionId(const Connection *conn);

/**
 * Returns the (remote, local) address pair that describes the connection
 * @param [in] connection The allocated connection
 * @return non-null The connection's remote and local address
 * @return null Should never return NULL
 */
const AddressPair *connection_GetAddressPair(const Connection *conn);

/**
 * Checks if the connection is in the "up" state
 * @param [in] connection The allocated connection
 * @return true The connection is in the "up" state
 * @return false The connection is not in the "up" state
 */
bool connection_IsUp(const Connection *conn);

/**
 * Checks if the connection is to a Local/Loopback address
 *
 * A local connection is PF_LOCAL (PF_UNIX) and a loopback connection is
 * 127.0.0.0/8 or ::1 for IPv6.
 *
 * @param [in] connection The allocated connection
 *
 * @retval true The connection is local or loopback
 * @retval false The connection is not local or loopback
 */
bool connection_IsLocal(const Connection *conn);

/**
 * Returns an opaque pointer representing the class of the Io Operations
 *
 * Returns an opaque pointer that an implementation can use to detect if
 * the connection is based on that class.
 *
 * @param [in] conn The Connection to analyze
 *
 * @return non-null An opaque pointer for each concrete implementation
 */
const void *connection_Class(const Connection *conn);

bool connection_ReSend(const Connection *conn, Message *message,
                       bool notification);

void connection_Probe(Connection *conn, uint8_t *probe);

void connection_HandleProbe(Connection *conn, uint8_t *message);

void connection_AllowWldrAutoStart(Connection *conn, bool allow);

void connection_EnableWldr(Connection *conn);

void connection_DisableWldr(Connection *conn);

bool connection_HasWldr(const Connection *conn);

bool connection_WldrAutoStartAllowed(const Connection *conn);

void connection_DetectLosses(Connection *conn, Message *message);

void connection_HandleWldrNotification(Connection *conn, Message *message);

connection_state_t connection_GetState(const Connection *conn);

void connection_SetState(Connection *conn, connection_state_t state);

connection_state_t connection_GetAdminState(const Connection *conn);

void connection_SetAdminState(Connection *conn, connection_state_t admin_state);

#ifdef WITH_POLICY
uint32_t connection_GetPriority(const Connection *conn);

void connection_SetPriority(Connection *conn, uint32_t priority);
#endif /* WITH_POLICY */

const char * connection_GetInterfaceName(const Connection * conn);

#ifdef WITH_POLICY
void connection_AddTag(Connection *conn, policy_tag_t tag);
void connection_RemoveTag(Connection *conn, policy_tag_t tag);
policy_tags_t connection_GetTags(const Connection *conn);
void connection_SetTags(Connection *conn, policy_tags_t tags);
void connection_ClearTags(Connection *conn);
int connection_HasTag(const Connection *conn, policy_tag_t tag);
#endif /* WITH_POLICY */

#endif  // connection_h