-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcc_secure_channel_send.c
189 lines (151 loc) · 4.07 KB
/
cc_secure_channel_send.c
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
/*
* cc_secure_channel_send functions.
*
* Author: qiang wang <[email protected]>
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2, as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "cc_secure_channel_send.h"
FUNC_CB_S
cc_select_send_func(uint16_t type)
{
int ret;
FUNC_CB_S func_cb;
switch(type){
// Immutable messages.
case OFPAPP_HELLO:
func_cb = cc_send_hello;
break;
case OFPAPP_ERROR:
func_cb = cc_send_error_msg;
break;
case OFPAPP_ECHO_REQUEST:
func_cb = cc_send_echo_request;
break;
case OFPAPP_ECHO_REPLY:
func_cb = cc_send_echo_reply;
break;
case OFPAPP_FEATURE_REQUEST:
func_cb = cc_send_features_request;
break;
// Asynchronous messages.
case OFPAPP_FLOW_MOD:
func_cb = cc_send_flow_mod;
break;
case OFPAPP_PORT_MOD:
func_cb = cc_send_port_mod;
break;
// Statistics messages.
case OFPAPP_STATS_REQUEST:
func_cb = cc_send_stats_request;
break;
// Queue Configuration messages.
case OFPAPP_QUEUE_STATS_REQUEST:
func_cb = cc_send_queue_stats_request;
break;
case OFPAPP_TABLE_STATS_REQUEST:
func_cb = cc_send_table_stats_request;
break;
case OFPAPP_VENDOR_STATS_REQUEST:
func_cb = cc_send_vendor_stats_request;
break;
case OFPAPP_AGGREGATE_STATS_REQUEST:
func_cb = cc_send_aggregate_stats_request;
break;
case OFPAPP_FLOW_STATS_REQUEST:
func_cb = cc_send_flow_stats_request;
break;
case OFPAPP_SET_CONFIG:
func_cb = cc_send_set_config;
break;
case OFPAPP_GET_CONFIG_REQUEST:
func_cb = cc_send_get_config_request;
break;
case OFPAPP_GET_DESC_STATS_REQUEST:
func_cb = cc_send_get_desc_stats;
break;
case OFPAPP_PACKET_OUT:
func_cb = cc_send_packet_out;
break;
default:
func_cb = NULL;
break;
}
return func_cb;
}
static int
cc_send_to_secure_channel(sw_info* cc_sw_info,buffer* buf)
{
int ret;
buffer* msg;
if( sw_info->send_queue == NULL )
sw_info->send_queue = create_message_queue();
ret = enqueue_message(cc_sw_info->send_queue, buf);
return ret;
}
static int
cc_send_to_secure_channel_app(sw_info* cc_sw_info,buffer* buf)
{
int ret;
buffer* msg;
if( cc_sw_info->app_send_queue == NULL )
cc_sw_info->app_send_queue = create_message_queue();
ret = enqueue_message(cc_sw_info->send_queue, buf);
return ret;
}
static int
cc_flush_to_secure_channel(sw_info* cc_sw_info)
{
buffer* msg;
int count = 0;
while(( msg = dequeue_message(cc_sw_info->recv_queue, msg)) != NULL && count < 50)
{
ssize_t write_length = write( cc_sw_info->cc_switch->cc_socket->fd, msg->data, CC_BUFFER_SIZE);
if( write_length < 0 )
{
if ( errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK )
{
return CC_ERROR;
}
perror("fail to write a message to secure channel");
return CC_ERROR;
}else if( (size_t)write_length > 0 && (size_t)write_length < msg->length ) {
log_err_for_cc("write msg to secure channel error!");
//write( cc_sw_info->cc_switch->cc_socket->fd,msg,sizeof(msg));
continue;
}
free_buffer(msg);
count++;
}
return CC_SUCCESS;
}
#if 0
/*send to secure channel through socket*/
int
cc_secure_channel_write(sw_info *cc_sw_info, buffer* buf)
{
int ret;
if(cc_sw_info->send_queue->length > 0)
{
if(cc_send_to_secure_channel(cc_sw_info) < 0)
{
log_err_for_cc();
return CC_ERROR;
}
}else{
return CC_ERROR;
}
return CC_SUCCESS;
}