VirtualBox

source: vbox/trunk/src/VBox/Devices/Network/slirp/udp.c@ 55192

Last change on this file since 55192 was 55003, checked in by vboxsync, 10 years ago

NAT: udp_input: force allocation of new socket for requests to the DNS
proxy since DNS proxy code is currently limited to tracking just one
request per socket.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 19.9 KB
Line 
1/* $Id: udp.c 55003 2015-03-30 02:21:45Z vboxsync $ */
2/** @file
3 * NAT - UDP protocol.
4 */
5
6/*
7 * Copyright (C) 2006-2012 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18/*
19 * This code is based on:
20 *
21 * Copyright (c) 1982, 1986, 1988, 1990, 1993
22 * The Regents of the University of California. All rights reserved.
23 *
24 * Redistribution and use in source and binary forms, with or without
25 * modification, are permitted provided that the following conditions
26 * are met:
27 * 1. Redistributions of source code must retain the above copyright
28 * notice, this list of conditions and the following disclaimer.
29 * 2. Redistributions in binary form must reproduce the above copyright
30 * notice, this list of conditions and the following disclaimer in the
31 * documentation and/or other materials provided with the distribution.
32 * 3. All advertising materials mentioning features or use of this software
33 * must display the following acknowledgement:
34 * This product includes software developed by the University of
35 * California, Berkeley and its contributors.
36 * 4. Neither the name of the University nor the names of its contributors
37 * may be used to endorse or promote products derived from this software
38 * without specific prior written permission.
39 *
40 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
41 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
44 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
49 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50 * SUCH DAMAGE.
51 *
52 * @(#)udp_usrreq.c 8.4 (Berkeley) 1/21/94
53 * udp_usrreq.c,v 1.4 1994/10/02 17:48:45 phk Exp
54 */
55
56/*
57 * Changes and additions relating to SLiRP
58 * Copyright (c) 1995 Danny Gasparovski.
59 *
60 * Please read the file COPYRIGHT for the
61 * terms and conditions of the copyright.
62 */
63
64#include <slirp.h>
65#include "ip_icmp.h"
66#include "ctl.h"
67
68
69/*
70 * UDP protocol implementation.
71 * Per RFC 768, August, 1980.
72 */
73#define udpcksum 1
74
75void
76udp_init(PNATState pData)
77{
78 udp_last_so = &udb;
79 udb.so_next = udb.so_prev = &udb;
80}
81
82/* m->m_data points at ip packet header
83 * m->m_len length ip packet
84 * ip->ip_len length data (IPDU)
85 */
86void
87udp_input(PNATState pData, register struct mbuf *m, int iphlen)
88{
89 register struct ip *ip;
90 register struct udphdr *uh;
91 int len;
92 struct ip save_ip;
93 struct socket *so;
94 int ret;
95 int ttl, tos;
96
97 LogFlowFunc(("ENTER: m = %p, iphlen = %d\n", m, iphlen));
98 ip = mtod(m, struct ip *);
99 Log2(("%RTnaipv4 iphlen = %d\n", ip->ip_dst, iphlen));
100
101 udpstat.udps_ipackets++;
102
103 /*
104 * Strip IP options, if any; should skip this,
105 * make available to user, and use on returned packets,
106 * but we don't yet have a way to check the checksum
107 * with options still present.
108 */
109 if (iphlen > sizeof(struct ip))
110 {
111 ip_stripoptions(m, (struct mbuf *)0);
112 iphlen = sizeof(struct ip);
113 }
114
115 /*
116 * Get IP and UDP header together in first mbuf.
117 */
118 ip = mtod(m, struct ip *);
119 uh = (struct udphdr *)((caddr_t)ip + iphlen);
120
121 /*
122 * Make mbuf data length reflect UDP length.
123 * If not enough data to reflect UDP length, drop.
124 */
125 len = RT_N2H_U16((u_int16_t)uh->uh_ulen);
126 Assert((ip->ip_len + iphlen == m_length(m, NULL)));
127
128 if (ip->ip_len != len)
129 {
130 if (len > ip->ip_len)
131 {
132 udpstat.udps_badlen++;
133 Log3(("NAT: IP(id: %hd) has bad size\n", ip->ip_id));
134 goto bad_free_mbuf;
135 }
136 m_adj(m, len - ip->ip_len);
137 ip->ip_len = len;
138 }
139
140 /*
141 * Save a copy of the IP header in case we want restore it
142 * for sending an ICMP error message in response.
143 */
144 save_ip = *ip;
145 save_ip.ip_len+= iphlen; /* tcp_input subtracts this */
146
147 /*
148 * Checksum extended UDP header and data.
149 */
150 if (udpcksum && uh->uh_sum)
151 {
152 memset(((struct ipovly *)ip)->ih_x1, 0, 9);
153 ((struct ipovly *)ip)->ih_len = uh->uh_ulen;
154#if 0
155 /* keep uh_sum for ICMP reply */
156 uh->uh_sum = cksum(m, len + sizeof (struct ip));
157 if (uh->uh_sum)
158 {
159
160#endif
161 if (cksum(m, len + iphlen))
162 {
163 udpstat.udps_badsum++;
164 Log3(("NAT: IP(id: %hd) has bad (udp) cksum\n", ip->ip_id));
165 goto bad_free_mbuf;
166 }
167 }
168#if 0
169 }
170#endif
171
172 /*
173 * handle DHCP/BOOTP
174 */
175 if (uh->uh_dport == RT_H2N_U16_C(BOOTP_SERVER))
176 {
177 bootp_input(pData, m);
178 goto done_free_mbuf;
179 }
180
181 LogFunc(("uh src: %RTnaipv4:%d, dst: %RTnaipv4:%d\n", ip->ip_src, RT_H2N_U16_C(uh->uh_sport), ip->ip_dst, RT_H2N_U16_C(uh->uh_dport)));
182 if ( pData->fUseHostResolver
183 && uh->uh_dport == RT_H2N_U16_C(53)
184 && CTL_CHECK(ip->ip_dst.s_addr, CTL_DNS))
185 {
186 struct sockaddr_in dst, src;
187 src.sin_addr.s_addr = ip->ip_dst.s_addr;
188 src.sin_port = uh->uh_dport;
189 dst.sin_addr.s_addr = ip->ip_src.s_addr;
190 dst.sin_port = uh->uh_sport;
191
192 slirpMbufTagService(pData, m, CTL_DNS);
193 /* udp_output2() expects a pointer to the body of UDP packet. */
194 m->m_data += sizeof(struct udpiphdr);
195 m->m_len -= sizeof(struct udpiphdr);
196 udp_output2(pData, NULL, m, &src, &dst, IPTOS_LOWDELAY);
197 LogFlowFuncLeave();
198 return;
199 }
200 /*
201 * handle TFTP
202 */
203 if ( uh->uh_dport == RT_H2N_U16_C(TFTP_SERVER)
204 && CTL_CHECK(ip->ip_dst.s_addr, CTL_TFTP))
205 {
206 if (pData->pvTftpSessions)
207 slirpTftpInput(pData, m);
208 goto done_free_mbuf;
209 }
210
211 /*
212 * XXX: DNS proxy currently relies on the fact that each socket
213 * only serves one request.
214 */
215 if ( pData->fUseDnsProxy
216 && CTL_CHECK(ip->ip_dst.s_addr, CTL_DNS)
217 && (uh->uh_dport == RT_H2N_U16_C(53)))
218 {
219 so = NULL;
220 goto new_socket;
221 }
222
223 /*
224 * Locate pcb for datagram.
225 */
226 so = udp_last_so;
227 if ( so->so_lport != uh->uh_sport
228 || so->so_laddr.s_addr != ip->ip_src.s_addr)
229 {
230 struct socket *tmp;
231
232 for (tmp = udb.so_next; tmp != &udb; tmp = tmp->so_next)
233 {
234 if ( tmp->so_lport == uh->uh_sport
235 && tmp->so_laddr.s_addr == ip->ip_src.s_addr)
236 {
237 so = tmp;
238 break;
239 }
240 }
241 if (tmp == &udb)
242 so = NULL;
243 else
244 {
245 udpstat.udpps_pcbcachemiss++;
246 udp_last_so = so;
247 }
248 }
249
250 new_socket:
251 if (so == NULL)
252 {
253 /*
254 * If there's no socket for this packet,
255 * create one
256 */
257 if ((so = socreate()) == NULL)
258 {
259 Log2(("NAT: IP(id: %hd) failed to create socket\n", ip->ip_id));
260 goto bad_free_mbuf;
261 }
262 if (udp_attach(pData, so) <= 0)
263 {
264 Log2(("NAT: IP(id: %hd) udp_attach errno = %d (%s)\n",
265 ip->ip_id, errno, strerror(errno)));
266 sofree(pData, so);
267 goto bad_free_mbuf;
268 }
269
270 /*
271 * Setup fields
272 */
273 /* udp_last_so = so; */
274 so->so_laddr = ip->ip_src;
275 so->so_lport = uh->uh_sport;
276
277 so->so_iptos = ip->ip_tos;
278
279 /*
280 * XXXXX Here, check if it's in udpexec_list,
281 * and if it is, do the fork_exec() etc.
282 */
283 }
284
285 so->so_faddr = ip->ip_dst; /* XXX */
286 so->so_fport = uh->uh_dport; /* XXX */
287 Assert(so->so_type == IPPROTO_UDP);
288
289 /*
290 * DNS proxy
291 */
292 if ( pData->fUseDnsProxy
293 && CTL_CHECK(ip->ip_dst.s_addr, CTL_DNS)
294 && (uh->uh_dport == RT_H2N_U16_C(53)))
295 {
296 dnsproxy_query(pData, so, m, iphlen);
297 goto done_free_mbuf;
298 }
299
300 iphlen += sizeof(struct udphdr);
301 m->m_len -= iphlen;
302 m->m_data += iphlen;
303
304 ttl = ip->ip_ttl = save_ip.ip_ttl;
305 if (ttl != so->so_sottl) {
306 ret = setsockopt(so->s, IPPROTO_IP, IP_TTL,
307 (char *)&ttl, sizeof(ttl));
308 if (RT_LIKELY(ret == 0))
309 so->so_sottl = ttl;
310 }
311
312 tos = save_ip.ip_tos;
313 if (tos != so->so_sotos) {
314 ret = setsockopt(so->s, IPPROTO_IP, IP_TOS,
315 (char *)&tos, sizeof(tos));
316 if (RT_LIKELY(ret == 0))
317 so->so_sotos = tos;
318 }
319
320 {
321 /*
322 * Different OSes have different socket options for DF. We
323 * can't use IP_HDRINCL here as it's only valid for SOCK_RAW.
324 */
325# define USE_DF_OPTION(_Optname) \
326 const int dfopt = _Optname; \
327 const char * const dfoptname = #_Optname;
328#if defined(IP_MTU_DISCOVER)
329 USE_DF_OPTION(IP_MTU_DISCOVER);
330#elif defined(IP_DONTFRAG) /* Solaris 11+, FreeBSD */
331 USE_DF_OPTION(IP_DONTFRAG);
332#elif defined(IP_DONTFRAGMENT) /* Windows */
333 USE_DF_OPTION(IP_DONTFRAGMENT);
334#else
335 USE_DF_OPTION(0);
336#endif
337 if (dfopt) {
338 int df = (save_ip.ip_off & IP_DF) != 0;
339#if defined(IP_MTU_DISCOVER)
340 df = df ? IP_PMTUDISC_DO : IP_PMTUDISC_DONT;
341#endif
342 if (df != so->so_sodf) {
343 ret = setsockopt(so->s, IPPROTO_IP, dfopt,
344 (char *)&df, sizeof(df));
345 if (RT_LIKELY(ret == 0))
346 so->so_sodf = df;
347 }
348 }
349 }
350
351 if ( sosendto(pData, so, m) == -1
352 && ( !soIgnorableErrorCode(errno)
353 && errno != ENOTCONN))
354 {
355 m->m_len += iphlen;
356 m->m_data -= iphlen;
357 *ip = save_ip;
358 Log2(("NAT: UDP tx errno = %d (%s) on sent to %RTnaipv4\n",
359 errno, strerror(errno), ip->ip_dst));
360 icmp_error(pData, m, ICMP_UNREACH, ICMP_UNREACH_NET, 0, strerror(errno));
361 so->so_m = NULL;
362 LogFlowFuncLeave();
363 return;
364 }
365
366 if (so->so_m)
367 m_freem(pData, so->so_m); /* used for ICMP if error on sorecvfrom */
368
369 /* restore the orig mbuf packet */
370 m->m_len += iphlen;
371 m->m_data -= iphlen;
372 *ip = save_ip;
373 so->so_m = m; /* ICMP backup */
374 LogFlowFuncLeave();
375 return;
376
377bad_free_mbuf:
378 Log2(("NAT: UDP(id: %hd) datagram to %RTnaipv4 with size(%d) claimed as bad\n",
379 ip->ip_id, &ip->ip_dst, ip->ip_len));
380
381done_free_mbuf:
382 /* some services like bootp(built-in), dns(buildt-in) and dhcp don't need sockets
383 * and create new m'buffers to send them to guest, so we'll free their incomming
384 * buffers here.
385 */
386 m_freem(pData, m);
387 LogFlowFuncLeave();
388 return;
389}
390
391/**
392 * Output a UDP packet.
393 *
394 * @note This function will finally free m!
395 */
396int udp_output2(PNATState pData, struct socket *so, struct mbuf *m,
397 struct sockaddr_in *saddr, struct sockaddr_in *daddr,
398 int iptos)
399{
400 register struct udpiphdr *ui;
401 int error;
402 int mlen = 0;
403
404 LogFlowFunc(("ENTER: so = %R[natsock], m = %p, saddr = %RTnaipv4, daddr = %RTnaipv4\n",
405 so, m, saddr->sin_addr.s_addr, daddr->sin_addr.s_addr));
406
407 /* in case of built-in service so might be NULL */
408 if (so) Assert(so->so_type == IPPROTO_UDP);
409
410 /*
411 * Adjust for header
412 */
413 m->m_data -= sizeof(struct udpiphdr);
414 m->m_len += sizeof(struct udpiphdr);
415 mlen = m_length(m, NULL);
416
417 /*
418 * Fill in mbuf with extended UDP header
419 * and addresses and length put into network format.
420 */
421 ui = mtod(m, struct udpiphdr *);
422 memset(ui->ui_x1, 0, 9);
423 ui->ui_pr = IPPROTO_UDP;
424 ui->ui_len = RT_H2N_U16(mlen - sizeof(struct ip));
425 /* XXXXX Check for from-one-location sockets, or from-any-location sockets */
426 ui->ui_src = saddr->sin_addr;
427 ui->ui_dst = daddr->sin_addr;
428 ui->ui_sport = saddr->sin_port;
429 ui->ui_dport = daddr->sin_port;
430 ui->ui_ulen = ui->ui_len;
431
432 /*
433 * Stuff checksum and output datagram.
434 */
435 ui->ui_sum = 0;
436 if (udpcksum)
437 {
438 if ((ui->ui_sum = cksum(m, /* sizeof (struct udpiphdr) + */ mlen)) == 0)
439 ui->ui_sum = 0xffff;
440 }
441 ((struct ip *)ui)->ip_len = mlen;
442 ((struct ip *)ui)->ip_ttl = ip_defttl;
443 ((struct ip *)ui)->ip_tos = iptos;
444
445 udpstat.udps_opackets++;
446
447 error = ip_output(pData, so, m);
448
449 return error;
450}
451
452/**
453 * @note This function will free m!
454 */
455int udp_output(PNATState pData, struct socket *so, struct mbuf *m,
456 struct sockaddr_in *addr)
457{
458 struct sockaddr_in saddr, daddr;
459#ifdef VBOX_WITH_NAT_UDP_SOCKET_CLONE
460 struct socket *pSocketClone = NULL;
461#endif
462 Assert(so->so_type == IPPROTO_UDP);
463 LogFlowFunc(("ENTER: so = %R[natsock], m = %p, saddr = %RTnaipv4\n",
464 so, (long)m, addr->sin_addr.s_addr));
465
466 saddr = *addr;
467 if ((so->so_faddr.s_addr & RT_H2N_U32(pData->netmask)) == pData->special_addr.s_addr)
468 {
469 saddr.sin_addr.s_addr = so->so_faddr.s_addr;
470 if (slirpIsWideCasting(pData, so->so_faddr.s_addr))
471 {
472 /**
473 * We haven't got real firewall but have got its submodule libalias.
474 */
475 m->m_flags |= M_SKIP_FIREWALL;
476 /**
477 * udp/137 port is Name Service in NetBIOS protocol. for some reasons Windows guest rejects
478 * accept data from non-aliased server.
479 */
480 if ( (so->so_fport == so->so_lport)
481 && (so->so_fport == RT_H2N_U16(137)))
482 saddr.sin_addr.s_addr = alias_addr.s_addr;
483 else
484 saddr.sin_addr.s_addr = addr->sin_addr.s_addr;
485 /* we shouldn't override initial socket */
486#ifdef VBOX_WITH_NAT_UDP_SOCKET_CLONE
487 if (so->so_cCloneCounter)
488 pSocketClone = soLookUpClonedUDPSocket(pData, so, addr->sin_addr.s_addr);
489 if (!pSocketClone)
490 pSocketClone = soCloneUDPSocketWithForegnAddr(pData, false, so, addr->sin_addr.s_addr);
491 Assert((pSocketClone));
492 so = pSocketClone;
493#else
494 so->so_faddr.s_addr = addr->sin_addr.s_addr;
495#endif
496 }
497 }
498
499 /* Any UDP packet to the loopback address must be translated to be from
500 * the forwarding address, i.e. 10.0.2.2. */
501 if ( (saddr.sin_addr.s_addr & RT_H2N_U32_C(IN_CLASSA_NET))
502 == RT_H2N_U32_C(INADDR_LOOPBACK & IN_CLASSA_NET))
503 saddr.sin_addr.s_addr = alias_addr.s_addr;
504
505 daddr.sin_addr = so->so_laddr;
506 daddr.sin_port = so->so_lport;
507
508 return udp_output2(pData, so, m, &saddr, &daddr, so->so_iptos);
509}
510
511int
512udp_attach(PNATState pData, struct socket *so)
513{
514 struct sockaddr_in *addr;
515 struct sockaddr sa_addr;
516 socklen_t socklen = sizeof(struct sockaddr);
517 int status;
518 int opt = 1;
519
520 /* We attaching some olready attched socket ??? */
521 Assert(so->so_type == 0);
522 if ((so->s = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
523 goto error;
524 so->so_sottl = 0;
525 so->so_sotos = 0;
526 so->so_sodf = -1;
527 /*
528 * Here, we bind() the socket. Although not really needed
529 * (sendto() on an unbound socket will bind it), it's done
530 * here so that emulation of ytalk etc. don't have to do it
531 */
532 memset(&sa_addr, 0, sizeof(struct sockaddr));
533 addr = (struct sockaddr_in *)&sa_addr;
534#ifdef RT_OS_DARWIN
535 addr->sin_len = sizeof(struct sockaddr_in);
536#endif
537 addr->sin_family = AF_INET;
538 addr->sin_addr.s_addr = pData->bindIP.s_addr;
539 fd_nonblock(so->s);
540 if (bind(so->s, &sa_addr, sizeof(struct sockaddr_in)) < 0)
541 {
542 int lasterrno = errno;
543 closesocket(so->s);
544 so->s = -1;
545#ifdef RT_OS_WINDOWS
546 WSASetLastError(lasterrno);
547#else
548 errno = lasterrno;
549#endif
550 goto error;
551 }
552 /* success, insert in queue */
553 so->so_expire = curtime + SO_EXPIRE;
554 /* enable broadcast for later use */
555 setsockopt(so->s, SOL_SOCKET, SO_BROADCAST, (const char *)&opt, sizeof(opt));
556 status = getsockname(so->s, &sa_addr, &socklen);
557 Assert(status == 0 && sa_addr.sa_family == AF_INET);
558 so->so_hlport = ((struct sockaddr_in *)&sa_addr)->sin_port;
559 so->so_hladdr.s_addr = ((struct sockaddr_in *)&sa_addr)->sin_addr.s_addr;
560
561 SOCKET_LOCK_CREATE(so);
562 QSOCKET_LOCK(udb);
563 insque(pData, so, &udb);
564 NSOCK_INC();
565 QSOCKET_UNLOCK(udb);
566 so->so_type = IPPROTO_UDP;
567 return so->s;
568error:
569 Log2(("NAT: can't create datagramm socket\n"));
570 return -1;
571}
572
573void
574udp_detach(PNATState pData, struct socket *so)
575{
576 if (so != &pData->icmp_socket)
577 {
578 Assert(so->so_type == IPPROTO_UDP);
579 QSOCKET_LOCK(udb);
580 SOCKET_LOCK(so);
581 QSOCKET_UNLOCK(udb);
582#ifdef VBOX_WITH_NAT_UDP_SOCKET_CLONE
583 if (so->so_cloneOf)
584 so->so_cloneOf->so_cCloneCounter--;
585 else if (so->so_cCloneCounter > 0)
586 {
587 /* we can't close socket yet */
588 SOCKET_UNLOCK(so);
589 return;
590 }
591#endif
592 closesocket(so->s);
593 sofree(pData, so);
594 SOCKET_UNLOCK(so);
595 }
596}
597
598struct socket *
599udp_listen(PNATState pData, u_int32_t bind_addr, u_int port, u_int32_t laddr, u_int lport, int flags)
600{
601 struct sockaddr_in addr;
602 struct socket *so;
603 socklen_t addrlen = sizeof(struct sockaddr_in);
604 int opt = 1;
605 LogFlowFunc(("ENTER: bind_addr:%RTnaipv4, port:%d, laddr:%RTnaipv4, lport:%d, flags:%x\n",
606 bind_addr, RT_N2H_U16(port), laddr, RT_N2H_U16(lport), flags));
607
608 if ((so = socreate()) == NULL)
609 {
610 LogFlowFunc(("LEAVE: NULL\n"));
611 return NULL;
612 }
613
614 so->s = socket(AF_INET, SOCK_DGRAM, 0);
615 if (so->s == -1)
616 {
617 LogRel(("NAT: can't create datagram socket\n"));
618 RTMemFree(so);
619 LogFlowFunc(("LEAVE: NULL\n"));
620 return NULL;
621 }
622 so->so_expire = curtime + SO_EXPIRE;
623 so->so_type = IPPROTO_UDP;
624 fd_nonblock(so->s);
625 so->so_sottl = 0;
626 so->so_sotos = 0;
627 so->so_sodf = -1;
628 SOCKET_LOCK_CREATE(so);
629 QSOCKET_LOCK(udb);
630 insque(pData, so, &udb);
631 NSOCK_INC();
632 QSOCKET_UNLOCK(udb);
633
634 memset(&addr, 0, sizeof(addr));
635#ifdef RT_OS_DARWIN
636 addr.sin_len = sizeof(addr);
637#endif
638 addr.sin_family = AF_INET;
639 addr.sin_addr.s_addr = bind_addr;
640 addr.sin_port = port;
641
642 if (bind(so->s,(struct sockaddr *)&addr, addrlen) < 0)
643 {
644 LogRel(("NAT: bind to %RTnaipv4 has been failed\n", addr.sin_addr));
645 udp_detach(pData, so);
646 LogFlowFunc(("LEAVE: NULL\n"));
647 return NULL;
648 }
649 setsockopt(so->s, SOL_SOCKET, SO_REUSEADDR,(char *)&opt, sizeof(int));
650/* setsockopt(so->s, SOL_SOCKET, SO_OOBINLINE,(char *)&opt, sizeof(int)); */
651
652 getsockname(so->s,(struct sockaddr *)&addr,&addrlen);
653 so->so_fport = addr.sin_port;
654 /* The original check was completely broken, as the commented out
655 * if statement was always true (INADDR_ANY=0). */
656 /* if (addr.sin_addr.s_addr == 0 || addr.sin_addr.s_addr == loopback_addr.s_addr) */
657 /* @todo: vvl - alias_addr should be set (if required)
658 * later by liabalias module.
659 */
660 if (1 == 0) /* always use the else part */
661 so->so_faddr = alias_addr;
662 else
663 so->so_faddr = addr.sin_addr;
664
665 so->so_lport = lport;
666 so->so_laddr.s_addr = laddr;
667 if (flags != SS_FACCEPTONCE)
668 so->so_expire = 0;
669
670 so->so_state = SS_ISFCONNECTED;
671
672 LogFlowFunc(("LEAVE: %R[natsock]\n", so));
673 return so;
674}
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette