Project Alice
Loading...
Searching...
No Matches
pcp_client_db.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2014 by Cisco Systems, Inc.
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7
8 1. Redistributions of source code must retain the above copyright notice, this
9 list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright notice,
11 this list of conditions and the following disclaimer in the documentation
12 and/or other materials provided with the distribution.
13
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
18 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#ifndef PCP_CLIENT_DB_H_
27#define PCP_CLIENT_DB_H_
28
29#include <stdint.h>
30#include "pcp.h"
31#include "pcp_event_handler.h"
32#include "pcp_msg_structs.h"
33#ifdef WIN32
34#include "net/unp.h"
36#endif
37
38#ifdef __cplusplus
39extern "C" {
40#endif
41
42typedef enum {
43 optf_3rd_party=1 << 0, optf_flowp=1 << 1,
45
46#define PCP_INV_SERVER (~0u)
47
48#ifdef PCP_EXPERIMENTAL
49
50#ifndef MD_VAL_MAX_LEN
51#define MD_VAL_MAX_LEN 24
52#endif
53
54typedef struct {
55 uint16_t md_id;
56 uint16_t val_len;
57 uint8_t val_buf[MD_VAL_MAX_LEN];
58}md_val_t;
59#endif
60
61#define FLOW_HASH_BITS 5
62#define FLOW_HASH_SIZE (2<<FLOW_HASH_BITS)
63
66 struct in6_addr src_ip;
67 struct in6_addr pcp_server_ip;
69 //union {
70 struct mp_keydata {
72 uint16_t src_port;
73 struct in6_addr dst_ip;
74 uint16_t dst_port;
76 // };
77};
78
79typedef struct pcp_recv_msg {
83
84 //response data
85 struct in6_addr assigned_ext_ip;
93
94 //control data
96 struct sockaddr_storage rcvd_from_addr;
97 //msg buffer
101
102struct pcp_ctx_s {
107 size_t flow_cnt;
114};
115
117 // flow's data
118 struct pcp_ctx_s *ctx;
122
124 union {
125 struct {
126 struct in6_addr ext_ip;
127 uint16_t ext_port;
128 } map_peer;
129#ifdef PCP_SADSCP
130 struct {
131 uint8_t toler_fields;
132 uint8_t app_name_length;
133 uint8_t learned_dscp;
134 }sadscp;
135#endif
136 };
137#ifdef PCP_SADSCP
138 char *sadscp_app_name;
139#endif
140 //response data
143
144 //control data
145 struct pcp_flow_s *next; //next flow with same key bucket
146 struct pcp_flow_s *next_child; //next flow for MAP with 0.0.0.0 src ip
152 struct timeval timeout;
153
154#ifdef PCP_EXPERIMENTAL
155 //Userid
156 pcp_userid_option_t f_userid;
157
158 //Location
159 pcp_location_option_t f_location;
160
161 //DeviceID
162 pcp_deviceid_option_t f_deviceid;
163#endif
164
165#ifdef PCP_FLOW_PRIORITY
166 //FLOW Priority Option
167 uint8_t flowp_option_present;
168 uint8_t flowp_dscp_up;
169 uint8_t flowp_dscp_down;
170#endif
171
172 //PREFER FAILURE Option
174
175 //FILTER Option
178 uint16_t filter_port;
179 struct in6_addr filter_ip;
180
181 // THIRD_PARTY Option
183 struct in6_addr third_party_ip;
184
185#ifdef PCP_EXPERIMENTAL
186 //MD Option
187 uint32_t md_val_count;
188 md_val_t *md_vals;
189#endif
190
191 //msg buffer
195};
196
197/* structure holding PCP server specific data */
202 uint16_t pcp_port;
205 char pcp_server_paddr[INET6_ADDRSTRLEN];
206 struct sockaddr_storage pcp_server_saddr;
211 time_t cepoch;
217 struct timeval next_timeout;
219 void *app_data;
220};
221
222typedef int (*pcp_db_flow_iterate)(pcp_flow_t *f, void *data);
223
224typedef int (*pcp_db_server_iterate)(pcp_server_t *f, void *data);
225
227
229
231
233
235
237 void *data);
238
240
241#ifdef PCP_EXPERIMENTAL
242void pcp_db_add_md(pcp_flow_t *f, uint16_t md_id, void *val, size_t val_len);
243#endif
244
245int pcp_new_server(pcp_ctx_t *ctx, struct in6_addr *ip, uint16_t port, uint32_t scope_id);
246
248 void *data);
249
250pcp_server_t *get_pcp_server(pcp_ctx_t *ctx, int pcp_server_index);
251
252pcp_server_t *get_pcp_server_by_ip(pcp_ctx_t *ctx, struct in6_addr *ip);
253
255
257
258#ifdef __cplusplus
259}
260#endif
261
262#endif /* PCP_CLIENT_DB_H_ */
uint uint32_t
uchar uint8_t
void(* pcp_flow_change_notify)(pcp_flow_t *f, struct sockaddr *src_addr, struct sockaddr *ext_addr, pcp_fstate_e, void *cb_arg)
Definition: pcp.h:259
#define PCP_SOCKET
Definition: pcp.h:55
pcp_errno
Definition: pcp.h:65
pcp_errno pcp_db_foreach_flow(pcp_ctx_t *ctx, pcp_db_flow_iterate f, void *data)
pcp_server_t * get_pcp_server(pcp_ctx_t *ctx, int pcp_server_index)
#define FLOW_HASH_SIZE
Definition: pcp_client_db.h:62
opt_flags_e
Definition: pcp_client_db.h:42
@ optf_3rd_party
Definition: pcp_client_db.h:43
@ optf_flowp
Definition: pcp_client_db.h:43
void pcp_flow_clear_msg_buf(pcp_flow_t *f)
Definition: pcp_client_db.c:91
int(* pcp_db_flow_iterate)(pcp_flow_t *f, void *data)
pcp_errno pcp_db_add_flow(pcp_flow_t *f)
pcp_errno pcp_db_foreach_server(pcp_ctx_t *ctx, pcp_db_server_iterate f, void *data)
pcp_errno pcp_db_rem_flow(pcp_flow_t *f)
int(* pcp_db_server_iterate)(pcp_server_t *f, void *data)
pcp_errno pcp_free_flow(pcp_flow_t *f)
pcp_flow_t * pcp_create_flow(pcp_server_t *s, struct flow_key_data *fkd)
Definition: pcp_client_db.c:64
struct pcp_recv_msg pcp_recv_msg_t
void pcp_db_free_pcp_servers(pcp_ctx_t *ctx)
pcp_server_t * get_pcp_server_by_ip(pcp_ctx_t *ctx, struct in6_addr *ip)
pcp_flow_t * pcp_get_flow(struct flow_key_data *fkd, pcp_server_t *s)
int pcp_new_server(pcp_ctx_t *ctx, struct in6_addr *ip, uint16_t port, uint32_t scope_id)
pcp_errno pcp_delete_flow_intern(pcp_flow_t *f)
pcp_server_state_e
pcp_flow_state_e
#define PCP_MAX_LEN
struct in6_addr dst_ip
Definition: pcp_client_db.h:73
struct flow_key_data::mp_keydata map_peer
struct in6_addr src_ip
Definition: pcp_client_db.h:66
struct pcp_nonce nonce
Definition: pcp_client_db.h:68
struct in6_addr pcp_server_ip
Definition: pcp_client_db.h:67
uint8_t operation
Definition: pcp_client_db.h:65
pcp_server_t * pcp_servers
pcp_flow_t * flows[FLOW_HASH_SIZE]
pcp_recv_msg_t msg
void * flow_change_cb_arg
pcp_socket_vt_t * virt_socket_tb
pcp_flow_change_notify flow_change_cb_fun
PCP_SOCKET socket
struct pcp_ctx_s::pcp_client_db pcp_db
uint32_t pcp_server_indx
uint32_t pcp_msg_len
uint8_t third_party_option_present
uint16_t ext_port
uint8_t filter_option_present
opt_flags_e opt_flags
struct timeval timeout
uint32_t retry_count
uint8_t filter_prefix
uint16_t filter_port
struct pcp_ctx_s * ctx
struct flow_key_data kd
void * user_data
struct pcp_flow_s * next_child
struct pcp_flow_s * next
uint32_t lifetime
uint32_t key_bucket
struct in6_addr third_party_ip
char * pcp_msg_buffer
uint32_t recv_result
uint32_t to_send_count
struct in6_addr filter_ip
uint8_t pfailure_option_present
uint32_t resend_timeout
time_t recv_lifetime
pcp_flow_state_e state
time_t received_time
Definition: pcp_client_db.h:92
uint32_t pcp_msg_len
Definition: pcp_client_db.h:98
uint8_t recv_dscp
Definition: pcp_client_db.h:87
uint32_t recv_epoch
Definition: pcp_client_db.h:89
uint32_t recv_result
Definition: pcp_client_db.h:91
uint32_t key_bucket
Definition: pcp_client_db.h:82
struct flow_key_data kd
Definition: pcp_client_db.h:81
char pcp_msg_buffer[PCP_MAX_LEN]
Definition: pcp_client_db.h:99
uint32_t recv_version
Definition: pcp_client_db.h:88
struct sockaddr_storage rcvd_from_addr
Definition: pcp_client_db.h:96
uint16_t assigned_ext_port
Definition: pcp_client_db.h:86
uint32_t recv_lifetime
Definition: pcp_client_db.h:90
uint32_t pcp_server_indx
Definition: pcp_client_db.h:95
opt_flags_e opt_flags
Definition: pcp_client_db.h:80
struct in6_addr assigned_ext_ip
Definition: pcp_client_db.h:85
pcp_flow_t * restart_flow_msg
uint32_t index
uint16_t pcp_port
uint32_t natpmp_ext_addr
uint32_t pcp_ip[4]
pcp_flow_t * ping_flow_msg
struct timeval next_timeout
uint8_t pcp_version
struct sockaddr_storage pcp_server_saddr
void * app_data
pcp_server_state_e server_state
uint32_t ping_count
uint32_t af
uint32_t pcp_scope_id
char pcp_server_paddr[INET6_ADDRSTRLEN]
time_t cepoch
uint32_t epoch
uint32_t src_ip[4]
uint8_t next_version
pcp_ctx_t * ctx
struct pcp_nonce nonce