Changeset 1010 in vbox
- Timestamp:
- Feb 21, 2007 2:40:16 PM (18 years ago)
- svn:sync-xref-src-repo-rev:
- 18860
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Network/slirp/udp.c
r184 r1010 38 38 * Changes and additions relating to SLiRP 39 39 * Copyright (c) 1995 Danny Gasparovski. 40 * 41 * Please read the file COPYRIGHT for the 40 * 41 * Please read the file COPYRIGHT for the 42 42 * terms and conditions of the copyright. 43 43 */ … … 67 67 udb.so_next = udb.so_prev = &udb; 68 68 } 69 /* m->m_data points at ip packet header 70 * m->m_len length ip packet 69 /* m->m_data points at ip packet header 70 * m->m_len length ip packet 71 71 * ip->ip_len length data (IPDU) 72 72 */ … … 80 80 /* struct mbuf *opts = 0;*/ 81 81 int len; 82 struct ip save_ip; 82 struct ip save_ip; 83 83 struct socket *so; 84 84 85 85 DEBUG_CALL("udp_input"); 86 86 DEBUG_ARG("m = %lx", (long)m); 87 87 DEBUG_ARG("iphlen = %d", iphlen); 88 88 89 89 udpstat.udps_ipackets++; 90 90 … … 120 120 ip->ip_len = len; 121 121 } 122 122 123 123 /* 124 124 * Save a copy of the IP header in case we want restore it 125 125 * for sending an ICMP error message in response. 126 126 */ 127 save_ip = *ip; 127 save_ip = *ip; 128 128 save_ip.ip_len+= iphlen; /* tcp_input subtracts this */ 129 129 … … 137 137 ((struct ipovly *)ip)->ih_len = uh->uh_ulen; 138 138 /* keep uh_sum for ICMP reply 139 * uh->uh_sum = cksum(m, len + sizeof (struct ip)); 140 * if (uh->uh_sum) { 139 * uh->uh_sum = cksum(m, len + sizeof (struct ip)); 140 * if (uh->uh_sum) { 141 141 */ 142 142 if(cksum(m, len + sizeof(struct ip))) { … … 154 154 } 155 155 156 #ifndef VBOX 157 /* Disable this for now (security leak, allows the guest to read any file 158 * from the current directory and the directories in it on the host). 159 * Reenable it after adding a way to optionally configure the tftp root 160 * directory (the existing tftp prefix setting is not sufficient). */ 156 161 /* 157 162 * handle TFTP … … 161 166 goto bad; 162 167 } 168 #endif /* !VBOX */ 163 169 164 170 /* … … 169 175 so->so_laddr.s_addr != ip->ip_src.s_addr) { 170 176 struct socket *tmp; 171 177 172 178 for (tmp = udb.so_next; tmp != &udb; tmp = tmp->so_next) { 173 179 if (tmp->so_lport == uh->uh_sport && … … 188 194 } 189 195 } 190 196 191 197 if (so == NULL) { 192 198 /* … … 196 202 if ((so = socreate()) == NULL) goto bad; 197 203 if(udp_attach(so) == -1) { 198 DEBUG_MISC((dfd," udp_attach errno = %d-%s\n", 204 DEBUG_MISC((dfd," udp_attach errno = %d-%s\n", 199 205 errno,strerror(errno))); 200 206 sofree(so); 201 207 goto bad; 202 208 } 203 209 204 210 /* 205 211 * Setup fields … … 208 214 so->so_laddr = ip->ip_src; 209 215 so->so_lport = uh->uh_sport; 210 216 211 217 if ((so->so_iptos = udp_tos(so)) == 0) 212 218 so->so_iptos = ip->ip_tos; 213 219 214 220 /* 215 221 * XXXXX Here, check if it's in udpexec_list, … … 236 242 *ip=save_ip; 237 243 DEBUG_MISC((dfd,"udp tx errno = %d-%s\n",errno,strerror(errno))); 238 icmp_error(m, ICMP_UNREACH,ICMP_UNREACH_NET, 0,strerror(errno)); 244 icmp_error(m, ICMP_UNREACH,ICMP_UNREACH_NET, 0,strerror(errno)); 239 245 } 240 246 … … 254 260 } 255 261 256 int udp_output2(struct socket *so, struct mbuf *m, 262 int udp_output2(struct socket *so, struct mbuf *m, 257 263 struct sockaddr_in *saddr, struct sockaddr_in *daddr, 258 264 int iptos) … … 272 278 m->m_data -= sizeof(struct udpiphdr); 273 279 m->m_len += sizeof(struct udpiphdr); 274 280 275 281 /* 276 282 * Fill in mbuf with extended UDP header … … 301 307 ((struct ip *)ui)->ip_ttl = ip_defttl; 302 308 ((struct ip *)ui)->ip_tos = iptos; 303 309 304 310 udpstat.udps_opackets++; 305 311 306 312 error = ip_output(so, m); 307 313 308 314 return (error); 309 315 } 310 316 311 int udp_output(struct socket *so, struct mbuf *m, 317 int udp_output(struct socket *so, struct mbuf *m, 312 318 struct sockaddr_in *addr) 313 319 … … 323 329 daddr.sin_addr = so->so_laddr; 324 330 daddr.sin_port = so->so_lport; 325 331 326 332 return udp_output2(so, m, &saddr, &daddr, so->so_iptos); 327 333 } … … 332 338 { 333 339 struct sockaddr_in addr; 334 340 335 341 if((so->s = socket(AF_INET,SOCK_DGRAM,0)) != -1) { 336 342 /* … … 387 393 { 388 394 int i = 0; 389 395 390 396 while(udptos[i].tos) { 391 397 if ((udptos[i].fport && ntohs(so->so_fport) == udptos[i].fport) || … … 396 402 i++; 397 403 } 398 404 399 405 return 0; 400 406 } … … 423 429 char buff[sizeof(CTL_MSG)]; 424 430 u_char type; 425 431 426 432 struct talk_request { 427 433 struct talk_request *next; … … 429 435 struct socket *tcp_so; 430 436 } *req; 431 432 static struct talk_request *req_tbl = 0; 433 437 438 static struct talk_request *req_tbl = 0; 439 434 440 #endif 435 441 436 442 struct cu_header { 437 443 uint16_t d_family; /* destination family */ … … 460 466 if (getsockname(so->s, (struct sockaddr *)&addr, &addrlen) < 0) 461 467 return; 462 468 463 469 #define IS_OLD (so->so_emu == EMU_TALK) 464 470 … … 483 489 OTOSIN(omsg, ctl_addr)->sin_addr = our_addr; 484 490 strncpy(omsg->l_name, getlogin(), NAME_SIZE_OLD); 485 } else { /* new talk */ 491 } else { /* new talk */ 486 492 omsg = (CTL_MSG_OLD *) buff; 487 493 nmsg = mtod(m, CTL_MSG *); … … 491 497 strncpy(nmsg->l_name, getlogin(), NAME_SIZE_OLD); 492 498 } 493 494 if (type == LOOK_UP) 499 500 if (type == LOOK_UP) 495 501 return; /* for LOOK_UP this is enough */ 496 502 497 503 if (IS_OLD) { /* make a copy of the message */ 498 504 COPY_MSG(nmsg, omsg); … … 513 519 * of the message, one in old talk and one in new talk 514 520 * format. 515 */ 521 */ 516 522 517 523 if (type == ANNOUNCE) { 518 524 int s; 519 525 u_short temp_port; 520 526 521 527 for(req = req_tbl; req; req = req->next) 522 528 if (so == req->udp_so) 523 529 break; /* found it */ 524 530 525 531 if (!req) { /* no entry for so, create new */ 526 532 req = (struct talk_request *) 527 533 malloc(sizeof(struct talk_request)); 528 534 req->udp_so = so; 529 req->tcp_so = solisten(0, 530 OTOSIN(omsg, addr)->sin_addr.s_addr, 535 req->tcp_so = solisten(0, 536 OTOSIN(omsg, addr)->sin_addr.s_addr, 531 537 OTOSIN(omsg, addr)->sin_port, 532 538 SS_FACCEPTONCE); 533 539 req->next = req_tbl; 534 540 req_tbl = req; 535 } 536 541 } 542 537 543 /* replace port number in addr field */ 538 544 addrlen = sizeof(addr); 539 getsockname(req->tcp_so->s, 545 getsockname(req->tcp_so->s, 540 546 (struct sockaddr *) &addr, 541 &addrlen); 547 &addrlen); 542 548 OTOSIN(omsg, addr)->sin_port = addr.sin_port; 543 549 OTOSIN(omsg, addr)->sin_addr = our_addr; 544 550 OTOSIN(nmsg, addr)->sin_port = addr.sin_port; 545 OTOSIN(nmsg, addr)->sin_addr = our_addr; 546 551 OTOSIN(nmsg, addr)->sin_addr = our_addr; 552 547 553 /* send LEAVE_INVITEs */ 548 554 temp_port = OTOSIN(omsg, ctl_addr)->sin_port; 549 555 OTOSIN(omsg, ctl_addr)->sin_port = 0; 550 556 OTOSIN(nmsg, ctl_addr)->sin_port = 0; 551 omsg->type = nmsg->type = LEAVE_INVITE; 552 557 omsg->type = nmsg->type = LEAVE_INVITE; 558 553 559 s = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP); 554 560 addr.sin_addr = our_addr; 555 561 addr.sin_family = AF_INET; 556 562 addr.sin_port = htons(517); 557 sendto(s, (char *)omsg, sizeof(*omsg), 0, 563 sendto(s, (char *)omsg, sizeof(*omsg), 0, 558 564 (struct sockaddr *)&addr, sizeof(addr)); 559 565 addr.sin_port = htons(518); … … 562 568 closesocket(s) ; 563 569 564 omsg->type = nmsg->type = ANNOUNCE; 570 omsg->type = nmsg->type = ANNOUNCE; 565 571 OTOSIN(omsg, ctl_addr)->sin_port = temp_port; 566 572 OTOSIN(nmsg, ctl_addr)->sin_port = temp_port; 567 573 } 568 569 /* 574 575 /* 570 576 * If it is a DELETE message, we send a copy to the 571 577 * local daemons. Then we delete the entry corresponding 572 578 * to our socket from the request table. 573 579 */ 574 580 575 581 if (type == DELETE) { 576 582 struct talk_request *temp_req, *req_next; 577 583 int s; 578 584 u_short temp_port; 579 585 580 586 temp_port = OTOSIN(omsg, ctl_addr)->sin_port; 581 587 OTOSIN(omsg, ctl_addr)->sin_port = 0; 582 588 OTOSIN(nmsg, ctl_addr)->sin_port = 0; 583 589 584 590 s = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP); 585 591 addr.sin_addr = our_addr; … … 592 598 (struct sockaddr *)&addr, sizeof(addr)); 593 599 closesocket(s); 594 600 595 601 OTOSIN(omsg, ctl_addr)->sin_port = temp_port; 596 602 OTOSIN(nmsg, ctl_addr)->sin_port = temp_port; … … 615 621 } 616 622 } 617 618 return; 623 624 return; 619 625 #endif 620 626 621 627 case EMU_CUSEEME: 622 628 623 629 /* 624 630 * Cu-SeeMe emulation. … … 626 632 * do any other tests, just replace the address and port 627 633 * fields. 628 */ 634 */ 629 635 if (m->m_len >= sizeof (*cu_head)) { 630 636 if (getsockname(so->s, (struct sockaddr *)&addr, &addrlen) < 0) … … 634 640 cu_head->so_addr = our_addr.s_addr; 635 641 } 636 642 637 643 return; 638 644 } … … 654 660 int opt = 1; 655 661 #endif /* VBOX */ 656 662 657 663 if ((so = socreate()) == NULL) { 658 664 free(so); … … 673 679 setsockopt(so->s,SOL_SOCKET,SO_REUSEADDR,(char *)&opt,sizeof(int)); 674 680 /* setsockopt(so->s,SOL_SOCKET,SO_OOBINLINE,(char *)&opt,sizeof(int)); */ 675 681 676 682 getsockname(so->s,(struct sockaddr *)&addr,&addrlen); 677 683 so->so_fport = addr.sin_port; … … 680 686 else 681 687 so->so_faddr = addr.sin_addr; 682 688 683 689 so->so_lport = lport; 684 690 so->so_laddr.s_addr = laddr; 685 691 if (flags != SS_FACCEPTONCE) 686 692 so->so_expire = 0; 687 693 688 694 so->so_state = SS_ISFCONNECTED; 689 695 690 696 return so; 691 697 }
Note:
See TracChangeset
for help on using the changeset viewer.