?? uip.lst
字號(hào):
428 2 UIP_STAT(++uip_stat.ip.chkerr);
429 2 UIP_LOG("ip: bad checksum.");
430 2 goto drop;
431 2 }
432 1
433 1 if(BUF->proto == IP_PROTO_TCP) /* Check for TCP packet. If so, jump
434 1 to the tcp_input label. */
435 1 goto tcp_input;
436 1
437 1 if(BUF->proto != IP_PROTO_ICMP) { /* We only allow ICMP packets from
438 2 here. */
439 2 UIP_STAT(++uip_stat.ip.drop);
440 2 UIP_STAT(++uip_stat.ip.protoerr);
441 2 UIP_LOG("ip: neither tcp nor icmp.");
442 2 goto drop;
443 2 }
444 1
445 1 UIP_STAT(++uip_stat.icmp.recv);
446 1
447 1 /* ICMP echo (i.e., ping) processing. This is simple, we only change
448 1 the ICMP type from ECHO to ECHO_REPLY and adjust the ICMP
449 1 checksum before we return the packet. */
450 1 if(ICMPBUF->type != ICMP_ECHO) {
451 2 UIP_STAT(++uip_stat.icmp.drop);
452 2 UIP_STAT(++uip_stat.icmp.typeerr);
453 2 UIP_LOG("icmp: not icmp echo.");
454 2 goto drop;
455 2 }
456 1
457 1 ICMPBUF->type = ICMP_ECHO_REPLY;
458 1
459 1 if(ICMPBUF->icmpchksum >= htons(0xffff - (ICMP_ECHO << 8))) {
460 2 ICMPBUF->icmpchksum += htons(ICMP_ECHO << 8) + 1;
461 2 } else {
462 2 ICMPBUF->icmpchksum += htons(ICMP_ECHO << 8);
463 2 }
464 1
465 1 /* Swap IP addresses. */
466 1 tmpport = BUF->destipaddr[0];
467 1 BUF->destipaddr[0] = BUF->srcipaddr[0];
468 1 BUF->srcipaddr[0] = tmpport;
469 1 tmpport = BUF->destipaddr[1];
470 1 BUF->destipaddr[1] = BUF->srcipaddr[1];
471 1 BUF->srcipaddr[1] = tmpport;
472 1
473 1 UIP_STAT(++uip_stat.icmp.sent);
474 1 goto send;
475 1
476 1 /* TCP input processing. */
477 1 tcp_input:
478 1
479 1 UIP_STAT(++uip_stat.tcp.recv);
480 1
481 1 if(uip_tcpchksum() != 0xffff) { /* Compute and check the TCP
482 2 checksum. */
483 2 UIP_STAT(++uip_stat.tcp.drop);
484 2 UIP_STAT(++uip_stat.tcp.chkerr);
485 2 UIP_LOG("tcp: bad checksum.");
486 2 goto drop;
487 2 }
488 1
489 1 /* Demultiplex this segment. */
C51 COMPILER V7.08 UIP 12/26/2003 07:27:14 PAGE 9
490 1 /* First check any active connections. */
491 1 for(uip_conn = &uip_conns[0]; uip_conn < &uip_conns[UIP_CONNS]; ++uip_conn)
492 1 {
493 2 if(uip_conn->tcpstateflags != CLOSED &&
494 2 BUF->srcipaddr[0] == uip_conn->ripaddr[0] &&
495 2 BUF->srcipaddr[1] == uip_conn->ripaddr[1] &&
496 2 BUF->destport == uip_conn->lport &&
497 2 BUF->srcport == uip_conn->rport)
498 2 goto found;
499 2 }
500 1
501 1 /* If we didn't find and active connection that expected the packet,
502 1 either this packet is an old duplicate, or this is a SYN packet
503 1 destined for a connection in LISTEN. If the SYN flag isn't set,
504 1 it is an old packet and we send a RST. */
505 1 if(BUF->flags != TCP_SYN)
506 1 goto reset;
507 1
508 1 tmpport = BUF->destport;
509 1 /* Next, check listening connections. */
510 1 for(c = 0; c < UIP_LISTENPORTS && uip_listenports[c] != 0; ++c)
511 1 {
512 2 if(tmpport == uip_listenports[c])
513 2 goto found_listen;
514 2 }
515 1
516 1 /* No matching connection found, so we send a RST packet. */
517 1 UIP_STAT(++uip_stat.tcp.synrst);
518 1 reset:
519 1
520 1 /* We do not send resets in response to resets. */
521 1 if(BUF->flags & TCP_RST)
522 1 goto drop;
523 1
524 1 UIP_STAT(++uip_stat.tcp.rst);
525 1
526 1 BUF->flags = TCP_RST | TCP_ACK;
527 1 uip_len = 40;
528 1 BUF->tcpoffset = 5 << 4;
529 1
530 1 /* Flip the seqno and ackno fields in the TCP header. */
531 1 c = BUF->seqno[3];
532 1 BUF->seqno[3] = BUF->ackno[3];
533 1 BUF->ackno[3] = c;
534 1
535 1 c = BUF->seqno[2];
536 1 BUF->seqno[2] = BUF->ackno[2];
537 1 BUF->ackno[2] = c;
538 1
539 1 c = BUF->seqno[1];
540 1 BUF->seqno[1] = BUF->ackno[1];
541 1 BUF->ackno[1] = c;
542 1
543 1 c = BUF->seqno[0];
544 1 BUF->seqno[0] = BUF->ackno[0];
545 1 BUF->ackno[0] = c;
546 1
547 1 /* We also have to increase the sequence number we are
548 1 acknowledging. If the least significant byte overflowed, we need
549 1 to propagate the carry to the other bytes as well. */
550 1 if(++BUF->ackno[3] == 0) {
551 2 if(++BUF->ackno[2] == 0) {
C51 COMPILER V7.08 UIP 12/26/2003 07:27:14 PAGE 10
552 3 if(++BUF->ackno[1] == 0) {
553 4 ++BUF->ackno[0];
554 4 }
555 3 }
556 2 }
557 1
558 1 /* Swap port numbers. */
559 1 tmpport = BUF->srcport;
560 1 BUF->srcport = BUF->destport;
561 1 BUF->destport = tmpport;
562 1
563 1 /* Swap IP addresses. */
564 1 tmpport = BUF->destipaddr[0];
565 1 BUF->destipaddr[0] = BUF->srcipaddr[0];
566 1 BUF->srcipaddr[0] = tmpport;
567 1 tmpport = BUF->destipaddr[1];
568 1 BUF->destipaddr[1] = BUF->srcipaddr[1];
569 1 BUF->srcipaddr[1] = tmpport;
570 1
571 1 /* And send out the RST packet! */
572 1 goto tcp_send_noconn;
573 1
574 1 /* This label will be jumped to if we matched the incoming packet
575 1 with a connection in LISTEN. In that case, we should create a new
576 1 connection and send a SYNACK in return. */
577 1 found_listen:
578 1 /* First we check if there are any connections avaliable. Unused
579 1 connections are kept in the same table as used connections, but
580 1 unused ones have the tcpstate set to CLOSED. */
581 1 for(c = 0; c < UIP_CONNS; ++c)
582 1 {
583 2 if(uip_conns[c].tcpstateflags == CLOSED)
584 2 goto found_unused_connection;
585 2 }
586 1 for(c = 0; c < UIP_CONNS; ++c)
587 1 {
588 2 if(uip_conns[c].tcpstateflags == TIME_WAIT)
589 2 goto found_unused_connection;
590 2 }
591 1 /* All connections are used already, we drop packet and hope that
592 1 the remote end will retransmit the packet at a time when we have
593 1 more spare connections. */
594 1 UIP_STAT(++uip_stat.tcp.syndrop);
595 1 UIP_LOG("tcp: found no unused connections.");
596 1 goto drop;
597 1
598 1 /* This label will be jumped to if we have found an unused
599 1 connection that we can use. */
600 1 found_unused_connection:
601 1 uip_conn = &uip_conns[c];
602 1
603 1 /* Fill in the necessary fields for the new connection. */
604 1 uip_conn->timer = UIP_RTO;
605 1 uip_conn->nrtx = 0;
606 1 uip_conn->lport = BUF->destport;
607 1 uip_conn->rport = BUF->srcport;
608 1 uip_conn->ripaddr[0] = BUF->srcipaddr[0];
609 1 uip_conn->ripaddr[1] = BUF->srcipaddr[1];
610 1 uip_conn->tcpstateflags = SYN_RCVD | UIP_OUTSTANDING;
611 1
612 1 uip_conn->snd_nxt[0] = uip_conn->ack_nxt[0] = iss[0];
613 1 uip_conn->snd_nxt[1] = uip_conn->ack_nxt[1] = iss[1];
C51 COMPILER V7.08 UIP 12/26/2003 07:27:14 PAGE 11
614 1 uip_conn->snd_nxt[2] = uip_conn->ack_nxt[2] = iss[2];
615 1 uip_conn->snd_nxt[3] = uip_conn->ack_nxt[3] = iss[3];
616 1 uip_add_ack_nxt(1);
617 1
618 1 /* rcv_nxt should be the seqno from the incoming packet + 1. */
619 1 uip_conn->rcv_nxt[3] = BUF->seqno[3];
620 1 uip_conn->rcv_nxt[2] = BUF->seqno[2];
621 1 uip_conn->rcv_nxt[1] = BUF->seqno[1];
622 1 uip_conn->rcv_nxt[0] = BUF->seqno[0];
623 1 uip_add_rcv_nxt(1);
624 1
625 1 /* Parse the TCP MSS option, if present. */
626 1 if((BUF->tcpoffset & 0xf0) > 0x50)
627 1 {
628 2 for(c = 0; c < ((BUF->tcpoffset >> 4) - 5) << 2 ;)
629 2 {
630 3 opt = uip_buf[40 + UIP_LLH_LEN + c];
631 3 if(opt == 0x00)
632 3 {
633 4 /* End of options. */
634 4 break;
635 4 } else if(opt == 0x01)
636 3 {
637 4 ++c;
638 4 /* NOP option. */
639 4 } else if(opt == 0x02 &&
640 3 uip_buf[40 + UIP_LLH_LEN + c + 1] == 0x04)
641 3 {
642 4 /* An MSS option with the right option length. */
643 4 tmpport = (uip_buf[40 + UIP_LLH_LEN + c + 2] << 8) |
644 4 uip_buf[40 + UIP_LLH_LEN + c + 3];
645 4 uip_conn->mss = tmpport > UIP_TCP_MSS? UIP_TCP_MSS: tmpport;
646 4
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -