Browse code

core: Added more PROTO_WS and PROTO_WSS checks

Peter Dunkley authored on 30/06/2012 21:53:00
Showing 6 changed files
... ...
@@ -446,8 +446,10 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
446 446
 									u->proto);
447 447
 							ret=E_BAD_PROTO;
448 448
 							goto error_fwd_uri;
449
-						}
450
-						dst.proto=PROTO_TLS;
449
+						} else if (u->proto!=PROTO_WSS)
450
+							dst.proto=PROTO_TLS;
451
+						else
452
+							dst.proto=PROTO_WSS;
451 453
 					}
452 454
 #endif
453 455
 				}
... ...
@@ -136,6 +136,8 @@ int get_socket_list_from_proto(int **ipList, int protocol) {
136 136
 		return 0;
137 137
 	}
138 138
 #endif
139
+	if (protocol == PROTO_WS || protocol == PROTO_WSS)
140
+		return 0;
139 141
 
140 142
 	/* Retrieve the list of sockets with respect to the given protocol. */
141 143
 	list=get_sock_info_list(protocol);
... ...
@@ -409,6 +411,8 @@ int get_total_bytes_waiting(void)
409 411
 	numUDPSockets  = get_socket_list_from_proto(&UDPList,  PROTO_UDP);
410 412
 	numTCPSockets  = get_socket_list_from_proto(&TCPList,  PROTO_TCP);
411 413
 	numTLSSockets  = get_socket_list_from_proto(&TLSList,  PROTO_TLS);
414
+	/* Deliberately not looking at PROTO_WS or PROTO_WSS here as they are
415
+	   just upgraded TCP/TLS connections */
412 416
 
413 417
 	/* Find out the number of bytes waiting on our interface list over all
414 418
 	 * UDP and TCP transports. */
... ...
@@ -976,6 +976,8 @@ static int parse_proto(unsigned char* s, long len, int* proto)
976 976
 	}
977 977
 #endif /* USE_SCTP */
978 978
 	else
979
+	/* Deliberately leaving out PROTO_WS and PROTO_WSS as these are just
980
+	   upgraded TCP/TLS connections. */
979 981
 		return -1;
980 982
 	return 0;
981 983
 }
... ...
@@ -657,7 +657,11 @@ static inline int lumps_len(struct sip_msg* msg, struct lump* lumps,
657 657
 								break; \
658 658
 						case PROTO_SCTP: \
659 659
 								new_len+=4; \
660
-								break; \
660
+							break; \
661
+						case PROTO_WS: \
662
+						case PROTO_WSS: \
663
+							new_len+=2; \
664
+							break; \
661 665
 						default: \
662 666
 						LOG(L_CRIT, "BUG: lumps_len: unknown proto %d\n", \
663 667
 								msg->rcv.bind_address->proto); \
... ...
@@ -688,6 +692,10 @@ static inline int lumps_len(struct sip_msg* msg, struct lump* lumps,
688 692
 						case PROTO_SCTP: \
689 693
 								new_len+=TRANSPORT_PARAM_LEN+4; \
690 694
 								break; \
695
+						case PROTO_WS: \
696
+						case PROTO_WSS: \
697
+								new_len+=TRANSPORT_PARAM_LEN+2; \
698
+								break; \
691 699
 						default: \
692 700
 						LOG(L_CRIT, "BUG: lumps_len: unknown proto %d\n", \
693 701
 								msg->rcv.bind_address->proto); \
... ...
@@ -729,6 +737,10 @@ static inline int lumps_len(struct sip_msg* msg, struct lump* lumps,
729 737
 						case PROTO_SCTP: \
730 738
 								new_len+=4; \
731 739
 								break; \
740
+						case PROTO_WS: \
741
+						case PROTO_WSS: \
742
+								new_len+=2; \
743
+								break; \
732 744
 						default: \
733 745
 						LOG(L_CRIT, "BUG: lumps_len: unknown proto %d\n", \
734 746
 								send_sock->proto); \
... ...
@@ -761,6 +773,10 @@ static inline int lumps_len(struct sip_msg* msg, struct lump* lumps,
761 773
 						case PROTO_SCTP: \
762 774
 								new_len+=TRANSPORT_PARAM_LEN+4; \
763 775
 								break; \
776
+						case PROTO_WS: \
777
+						case PROTO_WSS: \
778
+								new_len+=TRANSPORT_PARAM_LEN+2; \
779
+								break; \
764 780
 						default: \
765 781
 						LOG(L_CRIT, "BUG: lumps_len: unknown proto %d\n", \
766 782
 								send_sock->proto); \
... ...
@@ -1051,6 +1067,14 @@ static inline void process_lumps(	struct sip_msg* msg,
1051 1067
 						memcpy(new_buf+offset, "sctp", 4); \
1052 1068
 						offset+=4; \
1053 1069
 						break; \
1070
+					case PROTO_WS: \
1071
+					case PROTO_WSS: \
1072
+						memcpy(new_buf+offset, TRANSPORT_PARAM, \
1073
+								TRANSPORT_PARAM_LEN); \
1074
+						offset+=TRANSPORT_PARAM_LEN; \
1075
+						memcpy(new_buf+offset, "ws", 2); \
1076
+						offset+=2; \
1077
+						break; \
1054 1078
 					default: \
1055 1079
 						LOG(L_CRIT, "BUG: process_lumps: unknown proto %d\n", \
1056 1080
 								msg->rcv.bind_address->proto); \
... ...
@@ -1138,6 +1162,14 @@ static inline void process_lumps(	struct sip_msg* msg,
1138 1162
 						memcpy(new_buf+offset, "sctp", 4); \
1139 1163
 						offset+=4; \
1140 1164
 						break; \
1165
+					case PROTO_WS: \
1166
+					case PROTO_WSS: \
1167
+						memcpy(new_buf+offset, TRANSPORT_PARAM, \
1168
+								TRANSPORT_PARAM_LEN); \
1169
+						offset+=TRANSPORT_PARAM_LEN; \
1170
+						memcpy(new_buf+offset, "ws", 2); \
1171
+						offset+=2; \
1172
+						break; \
1141 1173
 					default: \
1142 1174
 						LOG(L_CRIT, "BUG: process_lumps: unknown proto %d\n", \
1143 1175
 								send_sock->proto); \
... ...
@@ -1168,6 +1200,11 @@ static inline void process_lumps(	struct sip_msg* msg,
1168 1200
 						memcpy(new_buf+offset, "sctp", 4); \
1169 1201
 						offset+=4; \
1170 1202
 						break; \
1203
+					case PROTO_WS: \
1204
+					case PROTO_WSS: \
1205
+						memcpy(new_buf+offset, "ws", 2); \
1206
+						offset+=2; \
1207
+						break; \
1171 1208
 					default: \
1172 1209
 						LOG(L_CRIT, "BUG: process_lumps: unknown proto %d\n", \
1173 1210
 								msg->rcv.bind_address->proto); \
... ...
@@ -1198,6 +1235,11 @@ static inline void process_lumps(	struct sip_msg* msg,
1198 1235
 						memcpy(new_buf+offset, "sctp", 4); \
1199 1236
 						offset+=4; \
1200 1237
 						break; \
1238
+					case PROTO_WS: \
1239
+					case PROTO_WSS: \
1240
+						memcpy(new_buf+offset, "ws", 2); \
1241
+						offset+=4; \
1242
+						break; \
1201 1243
 					default: \
1202 1244
 						LOG(L_CRIT, "BUG: process_lumps: unknown proto %d\n", \
1203 1245
 								send_sock->proto); \
... ...
@@ -140,6 +140,8 @@ inline static void addr_info_list_ins_lst(struct addr_info* lst,
140 140
 /* protocol order, filled by init_proto_order() */
141 141
 enum sip_protos nxt_proto[PROTO_LAST+1]=
142 142
 { PROTO_UDP, PROTO_TCP, PROTO_TLS, PROTO_SCTP, 0 };
143
+/* Deliberately left PROTO_WS and PROTO_WSS out of this as they are just
144
+   upgraded TCP and TLS connections */
143 145
 
144 146
 
145 147
 
... ...
@@ -1427,7 +1427,7 @@ static inline void _tcpconn_free(struct tcp_connection* c)
1427 1427
 #endif
1428 1428
 	lock_destroy(&c->write_lock);
1429 1429
 #ifdef USE_TLS
1430
-	if (unlikely(c->type==PROTO_TLS)) tls_tcpconn_clean(c);
1430
+	if (unlikely(c->type==PROTO_TLS || c->type==PROTO_WSS)) tls_tcpconn_clean(c);
1431 1431
 #endif
1432 1432
 	shm_free(c);
1433 1433
 }
... ...
@@ -1456,7 +1456,7 @@ void tcpconn_rm(struct tcp_connection* c)
1456 1456
 	TCPCONN_UNLOCK;
1457 1457
 	lock_destroy(&c->write_lock);
1458 1458
 #ifdef USE_TLS
1459
-	if ((c->type==PROTO_TLS)&&(c->extra_data)) tls_tcpconn_clean(c);
1459
+	if ((c->type==PROTO_TLS || c->type==PROTO_WSS)&&(c->extra_data)) tls_tcpconn_clean(c);
1460 1460
 #endif
1461 1461
 	shm_free(c);
1462 1462
 }
... ...
@@ -2270,7 +2270,7 @@ static int tcpconn_send_put(struct tcp_connection* c, const char* buf,
2270 2270
 				{
2271 2271
 					do_close_fd=0;
2272 2272
 #ifdef USE_TLS
2273
-					if (unlikely(c->type==PROTO_TLS)) {
2273
+					if (unlikely(c->type==PROTO_TLS || c->type==PROTO_WSS)) {
2274 2274
 						t_buf = buf;
2275 2275
 						t_len = len;
2276 2276
 						do {
... ...
@@ -2372,7 +2372,7 @@ static int tcpconn_send_put(struct tcp_connection* c, const char* buf,
2372 2372
 		}
2373 2373
 	
2374 2374
 #ifdef USE_TLS
2375
-		if (unlikely(c->type==PROTO_TLS)) {
2375
+		if (unlikely(c->type==PROTO_TLS || c->type==PROTO_WSS)) {
2376 2376
 			/* for TLS the TLS processing and the send must happen
2377 2377
 			   atomically w/ respect to other sends on the same connection
2378 2378
 			   (otherwise reordering might occur which would break TLS) =>
... ...
@@ -2958,7 +2958,7 @@ inline static void tcpconn_close_main_fd(struct tcp_connection* tcpconn)
2958 2958
 	
2959 2959
 	fd=tcpconn->s;
2960 2960
 #ifdef USE_TLS
2961
-	if (tcpconn->type==PROTO_TLS)
2961
+	if (tcpconn->type==PROTO_TLS || tcpconn->type==PROTO_WSS)
2962 2962
 		tls_close(tcpconn, fd);
2963 2963
 #endif
2964 2964
 #ifdef TCP_FD_CACHE
... ...
@@ -3025,7 +3025,7 @@ inline static void tcpconn_destroy(struct tcp_connection* tcpconn)
3025 3025
 			tcpconn_close_main_fd(tcpconn);
3026 3026
 			tcpconn->flags|=F_CONN_FD_CLOSED;
3027 3027
 			(*tcp_connections_no)--;
3028
-			if (unlikely(tcpconn->type==PROTO_TLS))
3028
+			if (unlikely(tcpconn->type==PROTO_TLS || tcpconn->type==PROTO_WSS))
3029 3029
 				(*tls_connections_no)--;
3030 3030
 		}
3031 3031
 		_tcpconn_free(tcpconn); /* destroys also the wbuf_q if still present*/
... ...
@@ -3073,7 +3073,7 @@ inline static int tcpconn_put_destroy(struct tcp_connection* tcpconn)
3073 3073
 		tcpconn_close_main_fd(tcpconn);
3074 3074
 		tcpconn->flags|=F_CONN_FD_CLOSED;
3075 3075
 		(*tcp_connections_no)--;
3076
-		if (unlikely(tcpconn->type==PROTO_TLS))
3076
+		if (unlikely(tcpconn->type==PROTO_TLS || tcpconn->type==PROTO_WSS))
3077 3077
 				(*tls_connections_no)--;
3078 3078
 	}
3079 3079
 	/* all the flags / ops on the tcpconn must be done prior to decrementing
... ...
@@ -4509,7 +4509,7 @@ static inline void tcpconn_destroy_all(void)
4509 4509
 					fd=-1;
4510 4510
 				}
4511 4511
 #ifdef USE_TLS
4512
-				if (fd>0 && c->type==PROTO_TLS)
4512
+				if (fd>0 && (c->type==PROTO_TLS || c->type==PROTO_WSS))
4513 4513
 					tls_close(c, fd);
4514 4514
 #endif
4515 4515
 				_tcpconn_rm(c);
... ...
@@ -4522,7 +4522,7 @@ static inline void tcpconn_destroy_all(void)
4522 4522
 					tcp_safe_close(fd);
4523 4523
 				}
4524 4524
 				(*tcp_connections_no)--;
4525
-				if (unlikely(c->type==PROTO_TLS))
4525
+				if (unlikely(c->type==PROTO_TLS || c->type==PROTO_WSS))
4526 4526
 					(*tls_connections_no)--;
4527 4527
 			c=next;
4528 4528
 		}