Browse code

udp_server.c: logging: convert LOG to LM_*

Ovidiu Sas authored on 04/10/2014 03:08:46
Showing 1 changed files
... ...
@@ -101,7 +101,7 @@ static int dbg_msg_qa(char *buf, int len)
101 101
 
102 102
 	/* is there a zero character in there ? */	
103 103
 	if (memchr(buf, 0, len)) {
104
-		LOG(L_CRIT, "BUG: message with 0 in it\n");
104
+		LM_CRIT("message with 0 in it\n");
105 105
 		return 0;
106 106
 	}
107 107
 
... ...
@@ -115,8 +115,7 @@ static int dbg_msg_qa(char *buf, int len)
115 115
 			case ' ':	if (state==QA_SPACE) {
116 116
 							space_cnt++;
117 117
 							if (space_cnt==4) {
118
-								LOG(L_CRIT, "BUG(probably): DBG_MSG_QA: "
119
-									"too many spaces\n");
118
+								LM_CRIT("DBG_MSG_QA: too many spaces\n");
120 119
 								return 0;
121 120
 							}
122 121
 						} else space_cnt=0;
... ...
@@ -165,15 +164,15 @@ int probe_max_receive_buffer( int udp_sock )
165 165
 	if (getsockopt( udp_sock, SOL_SOCKET, SO_RCVBUF, (void*) &ioptval,
166 166
 		    &ioptvallen) == -1 )
167 167
 	{
168
-		LOG(L_ERR, "ERROR: udp_init: getsockopt: %s\n", strerror(errno));
168
+		LM_ERR("getsockopt: %s\n", strerror(errno));
169 169
 		return -1;
170 170
 	}
171 171
 	if ( ioptval==0 ) 
172 172
 	{
173
-		LOG(L_DBG, "DEBUG: udp_init: SO_RCVBUF initially set to 0; resetting to %d\n",
173
+		LM_DBG("SO_RCVBUF initially set to 0; resetting to %d\n",
174 174
 			BUFFER_INCREMENT );
175 175
 		ioptval=BUFFER_INCREMENT;
176
-	} else LOG(L_INFO, "INFO: udp_init: SO_RCVBUF is initially %d\n", ioptval );
176
+	} else LM_INFO("SO_RCVBUF is initially %d\n", ioptval );
177 177
 	for (optval=ioptval; ;  ) {
178 178
 		/* increase size; double in initial phase, add linearly later */
179 179
 		if (phase==0) optval <<= 1; else optval+=BUFFER_INCREMENT;
... ...
@@ -181,12 +180,11 @@ int probe_max_receive_buffer( int udp_sock )
181 181
 			if (phase==1) break; 
182 182
 			else { phase=1; optval >>=1; continue; }
183 183
 		}
184
-		LOG(L_DBG, "DEBUG: udp_init: trying SO_RCVBUF: %d\n", optval );
184
+		LM_DBG("trying SO_RCVBUF: %d\n", optval );
185 185
 		if (setsockopt( udp_sock, SOL_SOCKET, SO_RCVBUF,
186 186
 			(void*)&optval, sizeof(optval)) ==-1){
187 187
 			/* Solaris returns -1 if asked size too big; Linux ignores */
188
-			LOG(L_DBG, "DEBUG: udp_init: SOL_SOCKET failed"
189
-					" for %d, phase %d: %s\n", optval, phase, strerror(errno));
188
+			LM_DBG("SOL_SOCKET failed for %d, phase %d: %s\n", optval, phase, strerror(errno));
190 189
 			/* if setting buffer size failed and still in the aggressive
191 190
 			   phase, try less aggressively; otherwise give up 
192 191
 			*/
... ...
@@ -201,13 +199,13 @@ int probe_max_receive_buffer( int udp_sock )
201 201
 		if (getsockopt( udp_sock, SOL_SOCKET, SO_RCVBUF, (void*) &voptval,
202 202
 		    &voptvallen) == -1 )
203 203
 		{
204
-			LOG(L_ERR, "ERROR: udp_init: getsockopt: %s\n", strerror(errno));
204
+			LM_ERR("getsockopt: %s\n", strerror(errno));
205 205
 			return -1;
206 206
 		} else {
207
-			LOG(L_DBG, "DEBUG: setting SO_RCVBUF; set=%d,verify=%d\n", 
207
+			LM_DBG("setting SO_RCVBUF; set=%d,verify=%d\n", 
208 208
 				optval, voptval);
209 209
 			if (voptval<optval) {
210
-				LOG(L_DBG, "DEBUG: setting SO_RCVBUF has no effect\n");
210
+				LM_DBG("setting SO_RCVBUF has no effect\n");
211 211
 				/* if setting buffer size failed and still in the aggressive
212 212
 				phase, try less aggressively; otherwise give up 
213 213
 				*/
... ...
@@ -221,10 +219,10 @@ int probe_max_receive_buffer( int udp_sock )
221 221
 	if (getsockopt( udp_sock, SOL_SOCKET, SO_RCVBUF, (void*) &foptval,
222 222
 		    &foptvallen) == -1 )
223 223
 	{
224
-		LOG(L_ERR, "ERROR: udp_init: getsockopt: %s\n", strerror(errno));
224
+		LM_ERR("getsockopt: %s\n", strerror(errno));
225 225
 		return -1;
226 226
 	}
227
-	LOG(L_INFO, "INFO: udp_init: SO_RCVBUF is finally %d\n", foptval );
227
+	LM_INFO("SO_RCVBUF is finally %d\n", foptval );
228 228
 
229 229
 	return 0;
230 230
 
... ...
@@ -249,8 +247,7 @@ static int setup_mcast_rcvr(int sock, union sockaddr_union* addr)
249 249
 		
250 250
 		if (setsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP,&mreq,
251 251
 			       sizeof(mreq))==-1){
252
-			LOG(L_ERR, "ERROR: setup_mcast_rcvr: setsockopt: %s\n",
253
-			    strerror(errno));
252
+			LM_ERR("setsockopt: %s\n", strerror(errno));
254 253
 			return -1;
255 254
 		}
256 255
 		
... ...
@@ -264,13 +261,12 @@ static int setup_mcast_rcvr(int sock, union sockaddr_union* addr)
264 264
 		if (setsockopt(sock, IPPROTO_IPV6, IPV6_JOIN_GROUP, &mreq6,
265 265
 #endif
266 266
 			       sizeof(mreq6))==-1){
267
-			LOG(L_ERR, "ERROR: setup_mcast_rcvr: setsockopt:%s\n",
268
-			    strerror(errno));
267
+			LM_ERR("setsockopt:%s\n", strerror(errno));
269 268
 			return -1;
270 269
 		}
271 270
 		
272 271
 	} else {
273
-		LOG(L_ERR, "ERROR: setup_mcast_rcvr: Unsupported protocol family\n");
272
+		LM_ERR("setup_mcast_rcvr: Unsupported protocol family\n");
274 273
 		return -1;
275 274
 	}
276 275
 	return 0;
... ...
@@ -290,26 +286,26 @@ int udp_init(struct socket_info* sock_info)
290 290
 /*
291 291
 	addr=(union sockaddr_union*)pkg_malloc(sizeof(union sockaddr_union));
292 292
 	if (addr==0){
293
-		LOG(L_ERR, "ERROR: udp_init: out of memory\n");
293
+		LM_ERR("out of memory\n");
294 294
 		goto error;
295 295
 	}
296 296
 */
297 297
 	sock_info->proto=PROTO_UDP;
298 298
 	if (init_su(addr, &sock_info->address, sock_info->port_no)<0){
299
-		LOG(L_ERR, "ERROR: udp_init: could not init sockaddr_union\n");
299
+		LM_ERR("could not init sockaddr_union\n");
300 300
 		goto error;
301 301
 	}
302 302
 	
303 303
 	sock_info->socket = socket(AF2PF(addr->s.sa_family), SOCK_DGRAM, 0);
304 304
 	if (sock_info->socket==-1){
305
-		LOG(L_ERR, "ERROR: udp_init: socket: %s\n", strerror(errno));
305
+		LM_ERR("socket: %s\n", strerror(errno));
306 306
 		goto error;
307 307
 	}
308 308
 	/* set sock opts? */
309 309
 	optval=1;
310 310
 	if (setsockopt(sock_info->socket, SOL_SOCKET, SO_REUSEADDR ,
311 311
 					(void*)&optval, sizeof(optval)) ==-1){
312
-		LOG(L_ERR, "ERROR: udp_init: setsockopt: %s\n", strerror(errno));
312
+		LM_ERR("setsockopt: %s\n", strerror(errno));
313 313
 		goto error;
314 314
 	}
315 315
 	/* tos */
... ...
@@ -317,15 +313,13 @@ int udp_init(struct socket_info* sock_info)
317 317
 	if (addr->s.sa_family==AF_INET){
318 318
 		if (setsockopt(sock_info->socket, IPPROTO_IP, IP_TOS, (void*)&optval, 
319 319
 				sizeof(optval)) ==-1){
320
-			LOG(L_WARN, "WARNING: udp_init: setsockopt tos: %s\n",
321
-					strerror(errno));
320
+			LM_WARN("setsockopt tos: %s\n", strerror(errno));
322 321
 			/* continue since this is not critical */
323 322
 		}
324 323
 	} else if (addr->s.sa_family==AF_INET6){
325 324
 		if (setsockopt(sock_info->socket, IPPROTO_IPV6, IPV6_TCLASS,
326 325
 					(void*)&optval, sizeof(optval)) ==-1) {
327
-			LOG(L_WARN, "WARNING: udp_init: setsockopt v6 tos: %s\n",
328
-					strerror(errno));
326
+			LM_WARN("setsockopt v6 tos: %s\n", strerror(errno));
329 327
 			/* continue since this is not critical */
330 328
 		}
331 329
 	}
... ...
@@ -335,7 +329,7 @@ int udp_init(struct socket_info* sock_info)
335 335
 	/* enable error receiving on unconnected sockets */
336 336
 	if(setsockopt(sock_info->socket, SOL_IP, IP_RECVERR,
337 337
 					(void*)&optval, sizeof(optval)) ==-1){
338
-		LOG(L_ERR, "ERROR: udp_init: setsockopt: %s\n", strerror(errno));
338
+		LM_ERR("setsockopt: %s\n", strerror(errno));
339 339
 		goto error;
340 340
 	}
341 341
 #endif
... ...
@@ -345,7 +339,7 @@ int udp_init(struct socket_info* sock_info)
345 345
 	optval= (pmtu_discovery) ? IP_PMTUDISC_DO : IP_PMTUDISC_DONT;
346 346
 	if(setsockopt(sock_info->socket, IPPROTO_IP, IP_MTU_DISCOVER,
347 347
 			(void*)&optval, sizeof(optval)) ==-1){
348
-		LOG(L_ERR, "ERROR: udp_init: setsockopt: %s\n", strerror(errno));
348
+		LM_ERR("setsockopt: %s\n", strerror(errno));
349 349
 		goto error;
350 350
 	}
351 351
 #endif
... ...
@@ -360,8 +354,7 @@ int udp_init(struct socket_info* sock_info)
360 360
 		m_loop=mcast_loopback;
361 361
 		if (setsockopt(sock_info->socket, IPPROTO_IP, IP_MULTICAST_LOOP, 
362 362
 						&m_loop, sizeof(m_loop))==-1){
363
-			LOG(L_WARN, "WARNING: udp_init: setsockopt(IP_MULTICAST_LOOP):"
364
-						" %s\n", strerror(errno));
363
+			LM_WARN("setsockopt(IP_MULTICAST_LOOP): %s\n", strerror(errno));
365 364
 			/* it's only a warning because we might get this error if the
366 365
 			  network interface doesn't support multicasting -- andrei */
367 366
 		}
... ...
@@ -369,26 +362,22 @@ int udp_init(struct socket_info* sock_info)
369 369
 			m_ttl=mcast_ttl;
370 370
 			if (setsockopt(sock_info->socket, IPPROTO_IP, IP_MULTICAST_TTL,
371 371
 						&m_ttl, sizeof(m_ttl))==-1){
372
-				LOG(L_WARN, "WARNING: udp_init: setsockopt (IP_MULTICAST_TTL):"
373
-						" %s\n", strerror(errno));
372
+				LM_WARN("setsockopt (IP_MULTICAST_TTL): %s\n", strerror(errno));
374 373
 			}
375 374
 		}
376 375
 	} else if (addr->s.sa_family==AF_INET6){
377 376
 		if (setsockopt(sock_info->socket, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, 
378 377
 						&mcast_loopback, sizeof(mcast_loopback))==-1){
379
-			LOG(L_WARN, "WARNING: udp_init: setsockopt (IPV6_MULTICAST_LOOP):"
380
-					" %s\n", strerror(errno));
378
+			LM_WARN("setsockopt (IPV6_MULTICAST_LOOP): %s\n", strerror(errno));
381 379
 		}
382 380
 		if (mcast_ttl>=0){
383 381
 			if (setsockopt(sock_info->socket, IPPROTO_IP, IPV6_MULTICAST_HOPS,
384 382
 							&mcast_ttl, sizeof(mcast_ttl))==-1){
385
-				LOG(L_WARN, "WARNING: udp_init: setssckopt "
386
-						"(IPV6_MULTICAST_HOPS): %s\n", strerror(errno));
383
+				LM_WARN("setssckopt (IPV6_MULTICAST_HOPS): %s\n", strerror(errno));
387 384
 			}
388 385
 		}
389 386
 	} else {
390
-		LOG(L_ERR, "ERROR: udp_init: Unsupported protocol family %d\n",
391
-					addr->s.sa_family);
387
+		LM_ERR("Unsupported protocol family %d\n", addr->s.sa_family);
392 388
 		goto error;
393 389
 	}
394 390
 #endif /* USE_MCAST */
... ...
@@ -396,14 +385,13 @@ int udp_init(struct socket_info* sock_info)
396 396
 	if ( probe_max_receive_buffer(sock_info->socket)==-1) goto error;
397 397
 	
398 398
 	if (bind(sock_info->socket,  &addr->s, sockaddru_len(*addr))==-1){
399
-		LOG(L_ERR, "ERROR: udp_init: bind(%x, %p, %d) on %s: %s\n",
399
+		LM_ERR("bind(%x, %p, %d) on %s: %s\n",
400 400
 				sock_info->socket, &addr->s, 
401 401
 				(unsigned)sockaddru_len(*addr),
402 402
 				sock_info->address_str.s,
403 403
 				strerror(errno));
404 404
 		if (addr->s.sa_family==AF_INET6)
405
-			LOG(L_ERR, "ERROR: udp_init: might be caused by using a link "
406
-					" local address, try site local or global\n");
405
+			LM_ERR("might be caused by using a link local address, try site local or global\n");
407 406
 		goto error;
408 407
 	}
409 408
 
... ...
@@ -433,7 +421,7 @@ int udp_rcv_loop()
433 433
 
434 434
 	from=(union sockaddr_union*) pkg_malloc(sizeof(union sockaddr_union));
435 435
 	if (from==0){
436
-		LOG(L_ERR, "ERROR: udp_rcv_loop: out of memory\n");
436
+		LM_ERR("out of memory\n");
437 437
 		goto error;
438 438
 	}
439 439
 	memset(from, 0 , sizeof(union sockaddr_union));
... ...
@@ -450,8 +438,7 @@ int udp_rcv_loop()
450 450
 #ifdef DYN_BUF
451 451
 		buf=pkg_malloc(BUF_SIZE+1);
452 452
 		if (buf==0){
453
-			LOG(L_ERR, "ERROR: udp_rcv_loop: could not allocate receive"
454
-					 " buffer\n");
453
+			LM_ERR("could not allocate receive buffer\n");
455 454
 			goto error;
456 455
 		}
457 456
 #endif
... ...
@@ -463,8 +450,7 @@ int udp_rcv_loop()
463 463
 				DBG("udp_rcv_loop: packet with bad checksum received\n");
464 464
 				continue;
465 465
 			}
466
-			LOG(L_ERR, "ERROR: udp_rcv_loop:recvfrom:[%d] %s\n",
467
-						errno, strerror(errno));
466
+			LM_ERR("recvfrom:[%d] %s\n", errno, strerror(errno));
468 467
 			if ((errno==EINTR)||(errno==EWOULDBLOCK)|| (errno==ECONNREFUSED))
469 468
 				continue; /* goto skip;*/
470 469
 			else goto error;
... ...
@@ -504,8 +490,7 @@ int udp_rcv_loop()
504 504
 #ifdef TRASH_ZEROTERMINATED_PACKETS
505 505
 		if (buf[len-1]==0) {
506 506
 			tmp=ip_addr2a(&ri.src_ip);
507
-			LOG(L_WARN, "WARNING: udp_rcv_loop: "
508
-					"upstream bug - 0-terminated packet from %s %d\n",
507
+			LM_WARN("upstream bug - 0-terminated packet from %s %d\n",
509 508
 					tmp, htons(ri.src_port));
510 509
 			len--;
511 510
 		}
... ...
@@ -513,14 +498,14 @@ int udp_rcv_loop()
513 513
 #endif
514 514
 #ifdef DBG_MSG_QA
515 515
 		if (!dbg_msg_qa(buf, len)) {
516
-			LOG(L_WARN, "WARNING: an incoming message didn't pass test,"
516
+			LM_WARN("an incoming message didn't pass test,"
517 517
 						"  drop it: %.*s\n", len, buf );
518 518
 			continue;
519 519
 		}
520 520
 #endif
521 521
 		if (ri.src_port==0){
522 522
 			tmp=ip_addr2a(&ri.src_ip);
523
-			LOG(L_INFO, "udp_rcv_loop: dropping 0 port packet from %s\n", tmp);
523
+			LM_INFO("dropping 0 port packet from %s\n", tmp);
524 524
 			continue;
525 525
 		}
526 526
 		
... ...
@@ -568,7 +553,7 @@ int udp_send(struct dest_info* dst, char *buf, unsigned len)
568 568
 #ifdef DBG_MSG_QA
569 569
 	/* aborts on error, does nothing otherwise */
570 570
 	if (!dbg_msg_qa( buf, len )) {
571
-		LOG(L_ERR, "ERROR: udp_send: dbg_msg_qa failed\n");
571
+		LM_ERR("dbg_msg_qa failed\n");
572 572
 		abort();
573 573
 	}
574 574
 #endif
... ...
@@ -582,16 +567,16 @@ int udp_send(struct dest_info* dst, char *buf, unsigned len)
582 582
 again:
583 583
 		n=sendto(dst->send_sock->socket, buf, len, 0, &dst->to.s, tolen);
584 584
 #ifdef XL_DEBUG
585
-		LOG(L_INFO, "INFO: send status: %d\n", n);
585
+		LM_INFO("send status: %d\n", n);
586 586
 #endif
587 587
 		if (unlikely(n==-1)){
588 588
 			su2ip_addr(&ip, &dst->to);
589
-			LOG(L_ERR, "ERROR: udp_send: sendto(sock,%p,%u,0,%s:%d,%d):"
590
-					" %s(%d)\n", buf,len, ip_addr2a(&ip),
589
+			LM_ERR("sendto(sock,%p,%u,0,%s:%d,%d): %s(%d)\n",
590
+					buf,len, ip_addr2a(&ip),
591 591
 					su_getport(&dst->to), tolen, strerror(errno), errno);
592 592
 			if (errno==EINTR) goto again;
593 593
 			if (errno==EINVAL) {
594
-				LOG(L_CRIT,"CRITICAL: invalid sendtoparameters\n"
594
+				LM_CRIT("invalid sendtoparameters\n"
595 595
 				"one possible reason is the server is bound to localhost and\n"
596 596
 				"attempts to send to the net\n");
597 597
 			}
... ...
@@ -607,8 +592,8 @@ raw_again:
607 607
 								mtu);
608 608
 		if (unlikely(n==-1)){
609 609
 			su2ip_addr(&ip, &dst->to);
610
-			LOG(L_ERR, "ERROR: raw_iphdr_udp4_send(%d,%p,%u,...,%s:%d,%d):"
611
-					" %s(%d)\n", raw_udp4_send_sock, buf,len, ip_addr2a(&ip),
610
+			LM_ERR("raw_iphdr_udp4_send(%d,%p,%u,...,%s:%d,%d): %s(%d)\n",
611
+					raw_udp4_send_sock, buf,len, ip_addr2a(&ip),
612 612
 					su_getport(&dst->to), mtu, strerror(errno), errno);
613 613
 			if (errno==EINTR) goto raw_again;
614 614
 		}