Changeset 1103:d8591b1c56cd in freeDiameter for libfdcore/server.c
- Timestamp:
- May 10, 2013, 7:48:57 PM (11 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libfdcore/server.c
r1093 r1103 134 134 struct client * c = arg; 135 135 struct server * s = NULL; 136 uint8_t * buf = NULL;137 s ize_t bufsz;136 struct fd_cnx_rcvdata rcv_data; 137 struct fd_msg_pmdl * pmdl = NULL; 138 138 struct msg * msg = NULL; 139 139 struct msg_hdr *hdr = NULL; 140 struct fd_pei pei; 140 141 141 142 TRACE_ENTRY("%p", c); … … 152 153 int ret = fd_cnx_handshake(c->conn, GNUTLS_SERVER, NULL, NULL); 153 154 if (ret != 0) { 154 if (TRACE_BOOL(INFO)) { 155 fd_log_debug("TLS handshake failed for client '%s', connection aborted.", fd_cnx_getid(c->conn)); 156 } 155 char buf[1024]; 156 snprintf(buf, sizeof(buf), "TLS handshake failed for client '%s', connection aborted.", fd_cnx_getid(c->conn)); 157 158 fd_hook_call(HOOK_PEER_CONNECT_FAILED, NULL, NULL, buf, NULL); 159 157 160 goto cleanup; 158 161 } … … 166 169 167 170 /* Receive the first Diameter message on the connection -- cleanup in case of timeout */ 168 CHECK_FCT_DO( fd_cnx_receive(c->conn, &c->ts, &buf, &bufsz), goto cleanup ); 169 170 TRACE_DEBUG(FULL, "Received %zdb from new client '%s'", bufsz, fd_cnx_getid(c->conn)); 171 CHECK_FCT_DO( fd_cnx_receive(c->conn, &c->ts, &rcv_data.buffer, &rcv_data.length), 172 { 173 char buf[1024]; 174 175 switch (__ret__) { 176 case ETIMEDOUT: 177 snprintf(buf, sizeof(buf), "Client '%s' did not send CER within %ds, connection aborted.", fd_cnx_getid(c->conn), INCNX_TIMEOUT); 178 fd_hook_call(HOOK_PEER_CONNECT_FAILED, NULL, NULL, buf, NULL); 179 break; 180 181 case ENOTCONN: 182 snprintf(buf, sizeof(buf), "Connection from '%s' in error before CER was received.", fd_cnx_getid(c->conn)); 183 fd_hook_call(HOOK_PEER_CONNECT_FAILED, NULL, NULL, buf, NULL); 184 break; 185 186 default: 187 snprintf(buf, sizeof(buf), "Connection from '%s': unspecified error, connection aborted.", fd_cnx_getid(c->conn)); 188 fd_hook_call(HOOK_PEER_CONNECT_FAILED, NULL, NULL, buf, NULL); 189 } 190 goto cleanup; 191 } ); 192 193 TRACE_DEBUG(FULL, "Received %zdb from new client '%s'", rcv_data.length, fd_cnx_getid(c->conn)); 194 195 pmdl = fd_msg_pmdl_get_inbuf(rcv_data.buffer, rcv_data.length); 171 196 172 197 /* Try parsing this message */ 173 CHECK_FCT_DO( fd_msg_parse_buffer( &buf, bufsz, &msg ), /* Parsing failed */ goto cleanup ); 198 CHECK_FCT_DO( fd_msg_parse_buffer( &rcv_data.buffer, rcv_data.length, &msg ), 199 { /* Parsing failed */ 200 fd_hook_call(HOOK_MESSAGE_PARSING_ERROR, NULL, NULL, &rcv_data, pmdl ); 201 goto cleanup; 202 } ); 174 203 175 204 /* Log incoming message */ 176 //fd_msg_log( FD_MSG_LOG_RECEIVED, msg, "Received %zdb from new client '%s'", bufsz, fd_cnx_getid(c->conn) ); 205 fd_hook_associate(msg, pmdl); 206 fd_hook_call(HOOK_MESSAGE_RECEIVED, msg, NULL, fd_cnx_getid(c->conn), fd_msg_pmdl_get(msg)); 177 207 178 208 /* We expect a CER, it must parse with our dictionary and rules */ 179 CHECK_FCT_DO( fd_msg_parse_rules( msg, fd_g_config->cnf_dict, NULL ), /* Parsing failed -- trace details ? */ goto cleanup ); 209 CHECK_FCT_DO( fd_msg_parse_rules( msg, fd_g_config->cnf_dict, &pei ), 210 { /* Parsing failed -- trace details */ 211 char buf[1024]; 212 213 fd_hook_call(HOOK_MESSAGE_PARSING_ERROR, msg, NULL, pei.pei_message ?: pei.pei_errcode, fd_msg_pmdl_get(msg)); 214 215 snprintf(buf, sizeof(buf), "Error parsing CER from '%s', connection aborted.", fd_cnx_getid(c->conn)); 216 fd_hook_call(HOOK_PEER_CONNECT_FAILED, NULL, NULL, buf, NULL); 217 218 goto cleanup; 219 } ); 180 220 181 221 /* Now check we received a CER */ 182 222 CHECK_FCT_DO( fd_msg_hdr ( msg, &hdr ), goto fatal_error ); 183 223 CHECK_PARAMS_DO( (hdr->msg_appl == 0) && (hdr->msg_flags & CMD_FLAG_REQUEST) && (hdr->msg_code == CC_CAPABILITIES_EXCHANGE), 184 { fd_log_debug("Connection '%s', expecting CER, received something else, closing...", fd_cnx_getid(c->conn)); goto cleanup; } ); 224 { /* Parsing failed -- trace details */ 225 char buf[1024]; 226 snprintf(buf, sizeof(buf), "Expected CER from '%s', received a different message, connection aborted.", fd_cnx_getid(c->conn)); 227 fd_hook_call(HOOK_PEER_CONNECT_FAILED, msg, NULL, buf, NULL); 228 goto cleanup; 229 } ); 185 230 186 231 /* Finally, pass the information to the peers module which will handle it next */ … … 200 245 /* Cleanup the parsed message if any */ 201 246 if (msg) { 202 //fd_msg_log( FD_MSG_LOG_DROPPED, msg, "Received invalid/unexpected message from connecting client '%s'", fd_cnx_getid(c->conn) );203 247 CHECK_FCT_DO( fd_msg_free(msg), /* continue */); 204 248 } … … 209 253 210 254 /* Cleanup the received buffer if any */ 211 free( buf);255 free(rcv_data.buffer); 212 256 213 257 /* Detach the thread, cleanup the client structure */ … … 239 283 /* Wait for a new client or cancel */ 240 284 CHECK_MALLOC_DO( conn = fd_cnx_serv_accept(s->conn), goto error ); 241 242 TRACE_DEBUG(FULL, "New connection accepted");243 285 244 286 /* Create a client structure */ … … 261 303 if (s) 262 304 set_status(s, TERMINATED); 263 /* Send error signal to the daemon */ 264 TRACE_DEBUG(INFO, "An error occurred in server module! Thread is terminating..."); 305 306 /* Send error signal to the core */ 307 LOG_F( "An error occurred in server module! Thread is terminating..."); 265 308 CHECK_FCT_DO(fd_event_send(fd_g_config->cnf_main_ev, FDEV_TERMINATE, 0, NULL), ); 266 309
Note: See TracChangeset
for help on using the changeset viewer.