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 409
 	numUDPSockets  = get_socket_list_from_proto(&UDPList,  PROTO_UDP);
410 410
 	numTCPSockets  = get_socket_list_from_proto(&TCPList,  PROTO_TCP);
411 411
 	numTLSSockets  = get_socket_list_from_proto(&TLSList,  PROTO_TLS);
412
+	/* Deliberately not looking at PROTO_WS or PROTO_WSS here as they are
413
+	   just upgraded TCP/TLS connections */
412 414
 
413 415
 	/* Find out the number of bytes waiting on our interface list over all
414 416
 	 * 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 688
 						case PROTO_SCTP: \
689 689
 								new_len+=TRANSPORT_PARAM_LEN+4; \
690 690
 								break; \
691
+						case PROTO_WS: \
692
+						case PROTO_WSS: \
693
+								new_len+=TRANSPORT_PARAM_LEN+2; \
694
+								break; \
691 695
 						default: \
692 696
 						LOG(L_CRIT, "BUG: lumps_len: unknown proto %d\n", \
693 697
 								msg->rcv.bind_address->proto); \
... ...
@@ -729,6 +737,10 @@ static inline int lumps_len(struct sip_msg* msg, struct lump* lumps,
729 729
 						case PROTO_SCTP: \
730 730
 								new_len+=4; \
731 731
 								break; \
732
+						case PROTO_WS: \
733
+						case PROTO_WSS: \
734
+								new_len+=2; \
735
+								break; \
732 736
 						default: \
733 737
 						LOG(L_CRIT, "BUG: lumps_len: unknown proto %d\n", \
734 738
 								send_sock->proto); \
... ...
@@ -761,6 +773,10 @@ static inline int lumps_len(struct sip_msg* msg, struct lump* lumps,
761 761
 						case PROTO_SCTP: \
762 762
 								new_len+=TRANSPORT_PARAM_LEN+4; \
763 763
 								break; \
764
+						case PROTO_WS: \
765
+						case PROTO_WSS: \
766
+								new_len+=TRANSPORT_PARAM_LEN+2; \
767
+								break; \
764 768
 						default: \
765 769
 						LOG(L_CRIT, "BUG: lumps_len: unknown proto %d\n", \
766 770
 								send_sock->proto); \
... ...
@@ -1051,6 +1067,14 @@ static inline void process_lumps(	struct sip_msg* msg,
1051 1051
 						memcpy(new_buf+offset, "sctp", 4); \
1052 1052
 						offset+=4; \
1053 1053
 						break; \
1054
+					case PROTO_WS: \
1055
+					case PROTO_WSS: \
1056
+						memcpy(new_buf+offset, TRANSPORT_PARAM, \
1057
+								TRANSPORT_PARAM_LEN); \
1058
+						offset+=TRANSPORT_PARAM_LEN; \
1059
+						memcpy(new_buf+offset, "ws", 2); \
1060
+						offset+=2; \
1061
+						break; \
1054 1062
 					default: \
1055 1063
 						LOG(L_CRIT, "BUG: process_lumps: unknown proto %d\n", \
1056 1064
 								msg->rcv.bind_address->proto); \
... ...
@@ -1138,6 +1162,14 @@ static inline void process_lumps(	struct sip_msg* msg,
1138 1138
 						memcpy(new_buf+offset, "sctp", 4); \
1139 1139
 						offset+=4; \
1140 1140
 						break; \
1141
+					case PROTO_WS: \
1142
+					case PROTO_WSS: \
1143
+						memcpy(new_buf+offset, TRANSPORT_PARAM, \
1144
+								TRANSPORT_PARAM_LEN); \
1145
+						offset+=TRANSPORT_PARAM_LEN; \
1146
+						memcpy(new_buf+offset, "ws", 2); \
1147
+						offset+=2; \
1148
+						break; \
1141 1149
 					default: \
1142 1150
 						LOG(L_CRIT, "BUG: process_lumps: unknown proto %d\n", \
1143 1151
 								send_sock->proto); \
... ...
@@ -1168,6 +1200,11 @@ static inline void process_lumps(	struct sip_msg* msg,
1168 1168
 						memcpy(new_buf+offset, "sctp", 4); \
1169 1169
 						offset+=4; \
1170 1170
 						break; \
1171
+					case PROTO_WS: \
1172
+					case PROTO_WSS: \
1173
+						memcpy(new_buf+offset, "ws", 2); \
1174
+						offset+=2; \
1175
+						break; \
1171 1176
 					default: \
1172 1177
 						LOG(L_CRIT, "BUG: process_lumps: unknown proto %d\n", \
1173 1178
 								msg->rcv.bind_address->proto); \
... ...
@@ -1198,6 +1235,11 @@ static inline void process_lumps(	struct sip_msg* msg,
1198 1198
 						memcpy(new_buf+offset, "sctp", 4); \
1199 1199
 						offset+=4; \
1200 1200
 						break; \
1201
+					case PROTO_WS: \
1202
+					case PROTO_WSS: \
1203
+						memcpy(new_buf+offset, "ws", 2); \
1204
+						offset+=4; \
1205
+						break; \
1201 1206
 					default: \
1202 1207
 						LOG(L_CRIT, "BUG: process_lumps: unknown proto %d\n", \
1203 1208
 								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
 		}