cdp_avp: added README file
[sip-router] / udp_server.c
1 /*
2  * $Id$
3  *
4  * Copyright (C) 2001-2003 FhG Fokus
5  *
6  * This file is part of ser, a free SIP server.
7  *
8  * ser is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version
12  *
13  * For a license to use the ser software under conditions
14  * other than those described here, or to purchase support for this
15  * software, please contact iptel.org by e-mail at the following addresses:
16  *    info@iptel.org
17  *
18  * ser is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License 
24  * along with this program; if not, write to the Free Software 
25  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26  *
27  * History
28  * --------
29  *  2003-01-28  packet zero-termination moved to receive_msg (jiri)
30  *  2003-02-10  undoed the above changes (andrei)
31  *  2003-03-19  replaced all the mallocs/frees w/ pkg_malloc/pkg_free (andrei)
32  *  2003-04-14  set sockopts to TOS low delay (andrei)
33  *  2004-05-03  applied multicast support patch from janakj
34  *              added set multicast ttl support (andrei)
35  *  2004-07-05  udp_rcv_loop: drop packets with 0 src port + error msg.
36  *              cleanups (andrei)
37  *  2005-03-10  multicast options are now set for all the udp sockets (andrei)
38  *  2005-06-26  failure to set mcast options is not an error anymore (andrei)
39  *  2006-04-12  udp_send() switched to struct dest_info (andrei)
40  *  2006-10-13  added STUN support (vlada)
41  *  2007-08-28  disable/set MTU discover option for the udp sockets
42  *               (in linux it's enabled by default which produces udp packets
43  *                with the DF flag ser) (patch from hscholz)
44  *  2010-06-15  support for using raw sockets for sending (andrei)
45  */
46
47
48 /** udp send and loop-receive functions.
49  * @file udp_server.c
50  * @ingroup core
51  * Module: @ref core
52  */
53
54 #include <stdlib.h>
55 #include <string.h>
56 #include <sys/types.h>
57 #include <sys/socket.h>
58 #include <netinet/in.h>
59 #include <netinet/in_systm.h>
60 #include <netinet/ip.h>
61 #include <errno.h>
62 #include <arpa/inet.h>
63 #ifdef __linux__
64         #include <linux/types.h>
65         #include <linux/errqueue.h>
66 #endif
67
68
69 #include "udp_server.h"
70 #include "compiler_opt.h"
71 #include "globals.h"
72 #include "config.h"
73 #include "dprint.h"
74 #include "receive.h"
75 #include "mem/mem.h"
76 #include "ip_addr.h"
77 #include "cfg/cfg_struct.h"
78 #include "events.h"
79 #ifdef USE_RAW_SOCKS
80 #include "raw_sock.h"
81 #endif /* USE_RAW_SOCKS */
82
83
84 #ifdef USE_STUN
85   #include "ser_stun.h"
86 #endif
87
88 #ifdef DBG_MSG_QA
89 /* message quality assurance -- frequently, bugs in ser have
90    been indicated by zero characters or long whitespaces
91    in generated messages; this debugging option aborts if
92    any such message is sighted
93 */
94 static int dbg_msg_qa(char *buf, int len)
95 {
96 #define _DBG_WS_LEN 3
97 #define _DBG_WS "   "
98
99         char *scan;
100         int my_len;
101         int space_cnt;
102         enum { QA_ANY, QA_SPACE, QA_EOL1 } state;
103
104
105         /* is there a zero character in there ? */      
106         if (memchr(buf, 0, len)) {
107                 LOG(L_CRIT, "BUG: message with 0 in it\n");
108                 return 0;
109         }
110
111         my_len=len;
112         scan=buf;
113         state=QA_ANY;
114         space_cnt=0;
115
116         while(my_len) {
117                 switch(*scan) {
118                         case ' ':       if (state==QA_SPACE) {
119                                                         space_cnt++;
120                                                         if (space_cnt==4) {
121                                                                 LOG(L_CRIT, "BUG(probably): DBG_MSG_QA: "
122                                                                         "too many spaces\n");
123                                                                 return 0;
124                                                         }
125                                                 } else space_cnt=0;
126                                                 state=QA_SPACE; 
127                                                 break;
128
129                         case '\r':      /* ignore */
130                                                 space_cnt=0;
131                                                 break;
132
133                         case '\n': /* don't proceed to body on EoH */
134                                                 if (state==QA_EOL1) goto qa_passed;
135                                                 space_cnt=0;
136                                                 state=QA_EOL1;
137                                                 break;
138
139                         default:        space_cnt=0;
140                                                 state=QA_ANY;
141                                                 break;
142                 }
143                 scan++;
144                 my_len--;
145         }
146
147
148 qa_passed:
149         return 1;
150 }
151
152 #endif
153
154
155 int probe_max_receive_buffer( int udp_sock )
156 {
157         int optval;
158         int ioptval;
159         unsigned int ioptvallen;
160         int foptval;
161         unsigned int foptvallen;
162         int voptval;
163         unsigned int voptvallen;
164         int phase=0;
165
166         /* jku: try to increase buffer size as much as we can */
167         ioptvallen=sizeof(ioptval);
168         if (getsockopt( udp_sock, SOL_SOCKET, SO_RCVBUF, (void*) &ioptval,
169                     &ioptvallen) == -1 )
170         {
171                 LOG(L_ERR, "ERROR: udp_init: getsockopt: %s\n", strerror(errno));
172                 return -1;
173         }
174         if ( ioptval==0 ) 
175         {
176                 LOG(L_DBG, "DEBUG: udp_init: SO_RCVBUF initially set to 0; resetting to %d\n",
177                         BUFFER_INCREMENT );
178                 ioptval=BUFFER_INCREMENT;
179         } else LOG(L_INFO, "INFO: udp_init: SO_RCVBUF is initially %d\n", ioptval );
180         for (optval=ioptval; ;  ) {
181                 /* increase size; double in initial phase, add linearly later */
182                 if (phase==0) optval <<= 1; else optval+=BUFFER_INCREMENT;
183                 if (optval > maxbuffer){
184                         if (phase==1) break; 
185                         else { phase=1; optval >>=1; continue; }
186                 }
187                 LOG(L_DBG, "DEBUG: udp_init: trying SO_RCVBUF: %d\n", optval );
188                 if (setsockopt( udp_sock, SOL_SOCKET, SO_RCVBUF,
189                         (void*)&optval, sizeof(optval)) ==-1){
190                         /* Solaris returns -1 if asked size too big; Linux ignores */
191                         LOG(L_DBG, "DEBUG: udp_init: SOL_SOCKET failed"
192                                         " for %d, phase %d: %s\n", optval, phase, strerror(errno));
193                         /* if setting buffer size failed and still in the aggressive
194                            phase, try less aggressively; otherwise give up 
195                         */
196                         if (phase==0) { phase=1; optval >>=1 ; continue; } 
197                         else break;
198                 } 
199                 /* verify if change has taken effect */
200                 /* Linux note -- otherwise I would never know that; funny thing: Linux
201                    doubles size for which we asked in setsockopt
202                 */
203                 voptvallen=sizeof(voptval);
204                 if (getsockopt( udp_sock, SOL_SOCKET, SO_RCVBUF, (void*) &voptval,
205                     &voptvallen) == -1 )
206                 {
207                         LOG(L_ERR, "ERROR: udp_init: getsockopt: %s\n", strerror(errno));
208                         return -1;
209                 } else {
210                         LOG(L_DBG, "DEBUG: setting SO_RCVBUF; set=%d,verify=%d\n", 
211                                 optval, voptval);
212                         if (voptval<optval) {
213                                 LOG(L_DBG, "DEBUG: setting SO_RCVBUF has no effect\n");
214                                 /* if setting buffer size failed and still in the aggressive
215                                 phase, try less aggressively; otherwise give up 
216                                 */
217                                 if (phase==0) { phase=1; optval >>=1 ; continue; } 
218                                 else break;
219                         } 
220                 }
221         
222         } /* for ... */
223         foptvallen=sizeof(foptval);
224         if (getsockopt( udp_sock, SOL_SOCKET, SO_RCVBUF, (void*) &foptval,
225                     &foptvallen) == -1 )
226         {
227                 LOG(L_ERR, "ERROR: udp_init: getsockopt: %s\n", strerror(errno));
228                 return -1;
229         }
230         LOG(L_INFO, "INFO: udp_init: SO_RCVBUF is finally %d\n", foptval );
231
232         return 0;
233
234         /* EoJKU */
235 }
236
237
238 #ifdef USE_MCAST
239
240 /*
241  * Setup multicast receiver
242  */
243 static int setup_mcast_rcvr(int sock, union sockaddr_union* addr)
244 {
245         struct ip_mreq mreq;
246 #ifdef USE_IPV6
247         struct ipv6_mreq mreq6;
248 #endif /* USE_IPV6 */
249         
250         if (addr->s.sa_family==AF_INET){
251                 memcpy(&mreq.imr_multiaddr, &addr->sin.sin_addr, 
252                        sizeof(struct in_addr));
253                 mreq.imr_interface.s_addr = htonl(INADDR_ANY);
254                 
255                 if (setsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP,&mreq,
256                                sizeof(mreq))==-1){
257                         LOG(L_ERR, "ERROR: setup_mcast_rcvr: setsockopt: %s\n",
258                             strerror(errno));
259                         return -1;
260                 }
261                 
262 #ifdef USE_IPV6
263         } else if (addr->s.sa_family==AF_INET6){
264                 memcpy(&mreq6.ipv6mr_multiaddr, &addr->sin6.sin6_addr, 
265                        sizeof(struct in6_addr));
266                 mreq6.ipv6mr_interface = 0;
267 #ifdef __OS_linux
268                 if (setsockopt(sock, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, &mreq6,
269 #else
270                 if (setsockopt(sock, IPPROTO_IPV6, IPV6_JOIN_GROUP, &mreq6,
271 #endif
272                                sizeof(mreq6))==-1){
273                         LOG(L_ERR, "ERROR: setup_mcast_rcvr: setsockopt:%s\n",
274                             strerror(errno));
275                         return -1;
276                 }
277                 
278 #endif /* USE_IPV6 */
279         } else {
280                 LOG(L_ERR, "ERROR: setup_mcast_rcvr: Unsupported protocol family\n");
281                 return -1;
282         }
283         return 0;
284 }
285
286 #endif /* USE_MCAST */
287
288
289 int udp_init(struct socket_info* sock_info)
290 {
291         union sockaddr_union* addr;
292         int optval;
293 #ifdef USE_MCAST
294         unsigned char m_ttl, m_loop;
295 #endif
296         addr=&sock_info->su;
297 /*
298         addr=(union sockaddr_union*)pkg_malloc(sizeof(union sockaddr_union));
299         if (addr==0){
300                 LOG(L_ERR, "ERROR: udp_init: out of memory\n");
301                 goto error;
302         }
303 */
304         sock_info->proto=PROTO_UDP;
305         if (init_su(addr, &sock_info->address, sock_info->port_no)<0){
306                 LOG(L_ERR, "ERROR: udp_init: could not init sockaddr_union\n");
307                 goto error;
308         }
309         
310         sock_info->socket = socket(AF2PF(addr->s.sa_family), SOCK_DGRAM, 0);
311         if (sock_info->socket==-1){
312                 LOG(L_ERR, "ERROR: udp_init: socket: %s\n", strerror(errno));
313                 goto error;
314         }
315         /* set sock opts? */
316         optval=1;
317         if (setsockopt(sock_info->socket, SOL_SOCKET, SO_REUSEADDR ,
318                                         (void*)&optval, sizeof(optval)) ==-1){
319                 LOG(L_ERR, "ERROR: udp_init: setsockopt: %s\n", strerror(errno));
320                 goto error;
321         }
322         /* tos */
323         optval = tos;
324         if (setsockopt(sock_info->socket, IPPROTO_IP, IP_TOS, (void*)&optval, 
325                         sizeof(optval)) ==-1){
326                 LOG(L_WARN, "WARNING: udp_init: setsockopt tos: %s\n", strerror(errno));
327                 /* continue since this is not critical */
328         }
329 #if defined (__OS_linux) && defined(UDP_ERRORS)
330         optval=1;
331         /* enable error receiving on unconnected sockets */
332         if(setsockopt(sock_info->socket, SOL_IP, IP_RECVERR,
333                                         (void*)&optval, sizeof(optval)) ==-1){
334                 LOG(L_ERR, "ERROR: udp_init: setsockopt: %s\n", strerror(errno));
335                 goto error;
336         }
337 #endif
338 #if defined (__OS_linux)
339         /* if pmtu_discovery=1 then set DF bit and do Path MTU discovery
340          * disabled by default */
341         optval= (pmtu_discovery) ? IP_PMTUDISC_DO : IP_PMTUDISC_DONT;
342         if(setsockopt(sock_info->socket, IPPROTO_IP, IP_MTU_DISCOVER,
343                         (void*)&optval, sizeof(optval)) ==-1){
344                 LOG(L_ERR, "ERROR: udp_init: setsockopt: %s\n", strerror(errno));
345                 goto error;
346         }
347 #endif
348
349 #ifdef USE_MCAST
350         if ((sock_info->flags & SI_IS_MCAST) 
351             && (setup_mcast_rcvr(sock_info->socket, addr)<0)){
352                         goto error;
353         }
354         /* set the multicast options */
355         if (addr->s.sa_family==AF_INET){
356                 m_loop=mcast_loopback;
357                 if (setsockopt(sock_info->socket, IPPROTO_IP, IP_MULTICAST_LOOP, 
358                                                 &m_loop, sizeof(m_loop))==-1){
359                         LOG(L_WARN, "WARNING: udp_init: setsockopt(IP_MULTICAST_LOOP):"
360                                                 " %s\n", strerror(errno));
361                         /* it's only a warning because we might get this error if the
362                           network interface doesn't support multicasting -- andrei */
363                 }
364                 if (mcast_ttl>=0){
365                         m_ttl=mcast_ttl;
366                         if (setsockopt(sock_info->socket, IPPROTO_IP, IP_MULTICAST_TTL,
367                                                 &m_ttl, sizeof(m_ttl))==-1){
368                                 LOG(L_WARN, "WARNING: udp_init: setsockopt (IP_MULTICAST_TTL):"
369                                                 " %s\n", strerror(errno));
370                         }
371                 }
372 #ifdef USE_IPV6
373         } else if (addr->s.sa_family==AF_INET6){
374                 if (setsockopt(sock_info->socket, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, 
375                                                 &mcast_loopback, sizeof(mcast_loopback))==-1){
376                         LOG(L_WARN, "WARNING: udp_init: setsockopt (IPV6_MULTICAST_LOOP):"
377                                         " %s\n", strerror(errno));
378                 }
379                 if (mcast_ttl>=0){
380                         if (setsockopt(sock_info->socket, IPPROTO_IP, IPV6_MULTICAST_HOPS,
381                                                         &mcast_ttl, sizeof(mcast_ttl))==-1){
382                                 LOG(L_WARN, "WARNING: udp_init: setssckopt "
383                                                 "(IPV6_MULTICAST_HOPS): %s\n", strerror(errno));
384                         }
385                 }
386 #endif /* USE_IPV6*/
387         } else {
388                 LOG(L_ERR, "ERROR: udp_init: Unsupported protocol family %d\n",
389                                         addr->s.sa_family);
390                 goto error;
391         }
392 #endif /* USE_MCAST */
393
394         if ( probe_max_receive_buffer(sock_info->socket)==-1) goto error;
395         
396         if (bind(sock_info->socket,  &addr->s, sockaddru_len(*addr))==-1){
397                 LOG(L_ERR, "ERROR: udp_init: bind(%x, %p, %d) on %s: %s\n",
398                                 sock_info->socket, &addr->s, 
399                                 (unsigned)sockaddru_len(*addr),
400                                 sock_info->address_str.s,
401                                 strerror(errno));
402         #ifdef USE_IPV6
403                 if (addr->s.sa_family==AF_INET6)
404                         LOG(L_ERR, "ERROR: udp_init: might be caused by using a link "
405                                         " local address, try site local or global\n");
406         #endif
407                 goto error;
408         }
409
410 /*      pkg_free(addr);*/
411         return 0;
412
413 error:
414 /*      if (addr) pkg_free(addr);*/
415         return -1;
416 }
417
418
419
420 int udp_rcv_loop()
421 {
422         unsigned len;
423 #ifdef DYN_BUF
424         char* buf;
425 #else
426         static char buf [BUF_SIZE+1];
427 #endif
428         char *tmp;
429         union sockaddr_union* from;
430         unsigned int fromlen;
431         struct receive_info ri;
432
433
434         from=(union sockaddr_union*) pkg_malloc(sizeof(union sockaddr_union));
435         if (from==0){
436                 LOG(L_ERR, "ERROR: udp_rcv_loop: out of memory\n");
437                 goto error;
438         }
439         memset(from, 0 , sizeof(union sockaddr_union));
440         ri.bind_address=bind_address; /* this will not change, we do it only once*/
441         ri.dst_port=bind_address->port_no;
442         ri.dst_ip=bind_address->address;
443         ri.proto=PROTO_UDP;
444         ri.proto_reserved1=ri.proto_reserved2=0;
445
446         /* initialize the config framework */
447         if (cfg_child_init()) goto error;
448
449         for(;;){
450 #ifdef DYN_BUF
451                 buf=pkg_malloc(BUF_SIZE+1);
452                 if (buf==0){
453                         LOG(L_ERR, "ERROR: udp_rcv_loop: could not allocate receive"
454                                          " buffer\n");
455                         goto error;
456                 }
457 #endif
458                 fromlen=sockaddru_len(bind_address->su);
459                 len=recvfrom(bind_address->socket, buf, BUF_SIZE, 0, &from->s,
460                                                                                         &fromlen);
461                 if (len==-1){
462                         if (errno==EAGAIN){
463                                 DBG("udp_rcv_loop: packet with bad checksum received\n");
464                                 continue;
465                         }
466                         LOG(L_ERR, "ERROR: udp_rcv_loop:recvfrom:[%d] %s\n",
467                                                 errno, strerror(errno));
468                         if ((errno==EINTR)||(errno==EWOULDBLOCK)|| (errno==ECONNREFUSED))
469                                 continue; /* goto skip;*/
470                         else goto error;
471                 }
472                 /* we must 0-term the messages, receive_msg expects it */
473                 buf[len]=0; /* no need to save the previous char */
474
475                 ri.src_su=*from;
476                 su2ip_addr(&ri.src_ip, from);
477                 ri.src_port=su_getport(from);
478
479                 if(unlikely(sr_event_enabled(SREV_NET_DGRAM_IN)))
480                 {
481                         void *sredp[3];
482                         sredp[0] = (void*)buf;
483                         sredp[1] = (void*)(&len);
484                         sredp[2] = (void*)(&ri);
485                         if(sr_event_exec(SREV_NET_DGRAM_IN, (void*)sredp)<0) {
486                                 /* data handled by callback - continue to next packet */
487                                 continue;
488                         }
489                 }
490 #ifndef NO_ZERO_CHECKS
491 #ifdef USE_STUN
492                 /* STUN support can be switched off even if it's compiled */
493                 if (stun_allow_stun == 0 || (unsigned char)*buf != 0x00) {
494 #endif
495                   if (len<MIN_UDP_PACKET) {
496                           tmp=ip_addr2a(&ri.src_ip);
497                           DBG("udp_rcv_loop: probing packet received from %s %d\n",
498                                         tmp, htons(ri.src_port));
499                           continue;
500                   }
501 #ifdef USE_STUN
502                 }
503 #endif
504 /* historically, zero-terminated packets indicated a bug in clients
505  * that calculated wrongly packet length and included string-terminating
506  * zero; today clients exist with legitimate binary payloads and we
507  * shall not check for zero-terminated payloads
508  */
509 #ifdef TRASH_ZEROTERMINATED_PACKETS
510                 if (buf[len-1]==0) {
511                         tmp=ip_addr2a(&ri.src_ip);
512                         LOG(L_WARN, "WARNING: udp_rcv_loop: "
513                                         "upstream bug - 0-terminated packet from %s %d\n",
514                                         tmp, htons(ri.src_port));
515                         len--;
516                 }
517 #endif
518 #endif
519 #ifdef DBG_MSG_QA
520                 if (!dbg_msg_qa(buf, len)) {
521                         LOG(L_WARN, "WARNING: an incoming message didn't pass test,"
522                                                 "  drop it: %.*s\n", len, buf );
523                         continue;
524                 }
525 #endif
526                 if (ri.src_port==0){
527                         tmp=ip_addr2a(&ri.src_ip);
528                         LOG(L_INFO, "udp_rcv_loop: dropping 0 port packet from %s\n", tmp);
529                         continue;
530                 }
531                 
532                 /* update the local config */
533                 cfg_update();
534 #ifdef USE_STUN
535                         /* STUN support can be switched off even if it's compiled */
536                         if (stun_allow_stun && (unsigned char)*buf == 0x00) {
537                             /* stun_process_msg releases buf memory if necessary */
538                                 if ((stun_process_msg(buf, len, &ri)) != 0) {
539                                         continue; /* some error occurred */
540                                 }
541                         } else
542 #endif
543                 /* receive_msg must free buf too!*/
544                 receive_msg(buf, len, &ri);
545                 
546         /* skip: do other stuff */
547                 
548         }
549         /*
550         if (from) pkg_free(from);
551         return 0;
552         */
553         
554 error:
555         if (from) pkg_free(from);
556         return -1;
557 }
558
559
560
561
562 /* send buf:len over udp to dst (uses only the to and send_sock dst members)
563  * returns the numbers of bytes sent on success (>=0) and -1 on error
564  */
565 int udp_send(struct dest_info* dst, char *buf, unsigned len)
566 {
567
568         int n;
569         int tolen;
570         struct ip_addr ip; /* used only on error, for debugging */
571 #ifdef USE_RAW_SOCKS
572         int mtu;
573 #endif /* USE_RAW_SOCKS */
574
575 #ifdef DBG_MSG_QA
576         /* aborts on error, does nothing otherwise */
577         if (!dbg_msg_qa( buf, len )) {
578                 LOG(L_ERR, "ERROR: udp_send: dbg_msg_qa failed\n");
579                 abort();
580         }
581 #endif
582 #ifdef USE_RAW_SOCKS
583         if (likely( ! (raw_udp4_send_sock >= 0 &&
584                                         cfg_get(core, core_cfg, udp4_raw) &&
585                                         dst->send_sock->address.af == AF_INET) )) {
586 #endif /* USE_RAW_SOCKS */
587                 /* normal send over udp socket */
588                 tolen=sockaddru_len(dst->to);
589 again:
590                 n=sendto(dst->send_sock->socket, buf, len, 0, &dst->to.s, tolen);
591 #ifdef XL_DEBUG
592                 LOG(L_INFO, "INFO: send status: %d\n", n);
593 #endif
594                 if (unlikely(n==-1)){
595                         su2ip_addr(&ip, &dst->to);
596                         LOG(L_ERR, "ERROR: udp_send: sendto(sock,%p,%u,0,%s:%d,%d):"
597                                         " %s(%d)\n", buf,len, ip_addr2a(&ip),
598                                         su_getport(&dst->to), tolen, strerror(errno), errno);
599                         if (errno==EINTR) goto again;
600                         if (errno==EINVAL) {
601                                 LOG(L_CRIT,"CRITICAL: invalid sendtoparameters\n"
602                                 "one possible reason is the server is bound to localhost and\n"
603                                 "attempts to send to the net\n");
604                         }
605                 }
606 #ifdef USE_RAW_SOCKS
607         } else {
608                 /* send over a raw socket */
609                 mtu = cfg_get(core, core_cfg, udp4_raw_mtu);
610 raw_again:
611                 n=raw_iphdr_udp4_send(raw_udp4_send_sock, buf, len,
612                                                                 &dst->send_sock->su,
613                                                                 &dst->to,
614                                                                 mtu);
615                 if (unlikely(n==-1)){
616                         su2ip_addr(&ip, &dst->to);
617                         LOG(L_ERR, "ERROR: raw_iphdr_udp4_send(%d,%p,%u,...,%s:%d,%d):"
618                                         " %s(%d)\n", raw_udp4_send_sock, buf,len, ip_addr2a(&ip),
619                                         su_getport(&dst->to), mtu, strerror(errno), errno);
620                         if (errno==EINTR) goto raw_again;
621                 }
622         }
623 #endif /* USE_RAW_SOCKS */
624         return n;
625 }