📄 uip.lst
字号:
528 6
529 6 /* We also send a reset packet to the remote host. */
530 6 BUF->flags = TCP_RST | TCP_ACK;
531 6 goto tcp_send_nodata;
532 6 }
533 5
534 5 /* Exponential backoff. */
535 5 uip_connr->timer = UIP_RTO << (uip_connr->nrtx > 4?
536 5 4:
537 5 uip_connr->nrtx);
538 5 ++(uip_connr->nrtx);
539 5
540 5 /* Ok, so we need to retransmit. We do this differently
541 5 depending on which state we are in. In ESTABLISHED, we
542 5 call upon the application so that it may prepare the
543 5 data for the retransmit. In SYN_RCVD, we resend the
544 5 SYNACK that we sent earlier and in LAST_ACK we have to
545 5 retransmit our FINACK. */
546 5 UIP_STAT(++uip_stat.tcp.rexmit);
547 5 switch(uip_connr->tcpstateflags & TS_MASK) {
548 6 case SYN_RCVD:
549 6 /* In the SYN_RCVD state, we should retransmit our
C51 COMPILER V8.16 UIP 03/16/2009 23:18:13 PAGE 10
550 6 SYNACK. */
551 6 goto tcp_send_synack;
552 6
553 6 #if UIP_ACTIVE_OPEN
case SYN_SENT:
/* In the SYN_SENT state, we retransmit out SYN. */
BUF->flags = 0;
goto tcp_send_syn;
#endif /* UIP_ACTIVE_OPEN */
559 6
560 6 case ESTABLISHED:
561 6 /* In the ESTABLISHED state, we call upon the application
562 6 to do the actual retransmit after which we jump into
563 6 the code for sending out the packet (the apprexmit
564 6 label). */
565 6 uip_len = 0;
566 6 uip_slen = 0;
567 6 uip_flags = UIP_REXMIT;
568 6 UIP_APPCALL();
569 6 goto apprexmit;
570 6
571 6 case FIN_WAIT_1:
572 6 case CLOSING:
573 6 case LAST_ACK:
574 6 /* In all these states we should retransmit a FINACK. */
575 6 goto tcp_send_finack;
576 6
577 6 }
578 5 }
579 4 } else if((uip_connr->tcpstateflags & TS_MASK) == ESTABLISHED) {
580 4 /* If there was no need for a retransmission, we poll the
581 4 application for new data. */
582 4 uip_len = 0;
583 4 uip_slen = 0;
584 4 uip_flags = UIP_POLL;
585 4 UIP_APPCALL();
586 4 goto appsend;
587 4 }
588 3 }
589 2 goto drop;
590 2 }
591 1 #if UIP_UDP
if(flag == UIP_UDP_TIMER) {
if(uip_udp_conn->lport != 0) {
uip_appdata = &uip_buf[UIP_LLH_LEN + 28];
uip_len = uip_slen = 0;
uip_flags = UIP_POLL;
UIP_UDP_APPCALL();
goto udp_send;
} else {
goto drop;
}
}
#endif
604 1
605 1 /* This is where the input processing starts. */
606 1 UIP_STAT(++uip_stat.ip.recv);
607 1
608 1
609 1 /* Start of IPv4 input header processing code. */
610 1
611 1 /* Check validity of the IP header. */
C51 COMPILER V8.16 UIP 03/16/2009 23:18:13 PAGE 11
612 1 if(BUF->vhl != 0x45) { /* IP version and header length. */
613 2 UIP_STAT(++uip_stat.ip.drop);
614 2 UIP_STAT(++uip_stat.ip.vhlerr);
615 2 Printf_String("\r\n[MSG:] ip: invalid version or header length.");
616 2 goto drop;
617 2 }
618 1
619 1 /* Check the size of the packet. If the size reported to us in
620 1 uip_len doesn't match the size reported in the IP header, there
621 1 has been a transmission error and we drop the packet. */
622 1
623 1 if(BUF->len[0] != (uip_len >> 8)) { /* IP length, high byte. */
624 2 uip_len = (uip_len & 0xff) | (BUF->len[0] << 8);
625 2 }
626 1 if(BUF->len[1] != (uip_len & 0xff)) { /* IP length, low byte. */
627 2 uip_len = (uip_len & 0xff00) | BUF->len[1];
628 2 }
629 1
630 1 /* Check the fragment flag. */
631 1 if((BUF->ipoffset[0] & 0x3f) != 0 ||
632 1 BUF->ipoffset[1] != 0) {
633 2 #if UIP_REASSEMBLY
uip_len = uip_reass();
if(uip_len == 0) {
goto drop;
}
#else
639 2 UIP_STAT(++uip_stat.ip.drop);
640 2 UIP_STAT(++uip_stat.ip.fragerr);
641 2 Printf_String("\r\n[MSG:] ip: fragment dropped.");
642 2 goto drop;
643 2 #endif /* UIP_REASSEMBLY */
644 2 }
645 1
646 1 /* If we are configured to use ping IP address configuration and
647 1 hasn't been assigned an IP address yet, we accept all ICMP
648 1 packets. */
649 1 #if UIP_PINGADDRCONF
if((uip_hostaddr[0] | uip_hostaddr[1]) == 0) {
if(BUF->proto == UIP_PROTO_ICMP) {
Printf_String("\r\n[MSG:] ip: possible ping config packet received.");
goto icmp_input;
} else {
Printf_String("\r\n[MSG:] ip: packet dropped since no address assigned.");
goto drop;
}
}
#endif /* UIP_PINGADDRCONF */
660 1
661 1 /* Check if the packet is destined for our IP address. */
662 1 if(BUF->destipaddr[0] != uip_hostaddr[0]) {
663 2 UIP_STAT(++uip_stat.ip.drop);
664 2 // Printf_String("\r\n ->ip: packet not for us.");
665 2 goto drop;
666 2 }
667 1 if(BUF->destipaddr[1] != uip_hostaddr[1]) {
668 2 UIP_STAT(++uip_stat.ip.drop);
669 2 // Printf_String("\r\n ->ip: packet not for us.");
670 2 goto drop;
671 2 }
672 1
673 1 if(uip_ipchksum() != 0xffff) { /* Compute and check the IP header
C51 COMPILER V8.16 UIP 03/16/2009 23:18:13 PAGE 12
674 2 checksum. */
675 2 UIP_STAT(++uip_stat.ip.drop);
676 2 UIP_STAT(++uip_stat.ip.chkerr);
677 2 Printf_String("\r\n[MSG:] ip: bad checksum.");
678 2 goto drop;
679 2 }
680 1
681 1 if(BUF->proto == UIP_PROTO_TCP) /* Check for TCP packet. If so, jump
682 1 to the tcp_input label. */
683 1 goto tcp_input;
684 1
685 1 #if UIP_UDP
if(BUF->proto == UIP_PROTO_UDP)
goto udp_input;
#endif /* UIP_UDP */
689 1
690 1 if(BUF->proto != UIP_PROTO_ICMP) { /* We only allow ICMP packets from
691 2 here. */
692 2 UIP_STAT(++uip_stat.ip.drop);
693 2 UIP_STAT(++uip_stat.ip.protoerr);
694 2 Printf_String("\r\n[MSG:] ip: neither tcp nor icmp.");
695 2 goto drop;
696 2 }
697 1
698 1 icmp_input:
699 1 UIP_STAT(++uip_stat.icmp.recv);
700 1
701 1 /* ICMP echo (i.e., ping) processing. This is simple, we only change
702 1 the ICMP type from ECHO to ECHO_REPLY and adjust the ICMP
703 1 checksum before we return the packet. */
704 1 if(ICMPBUF->type != ICMP_ECHO) {
705 2 UIP_STAT(++uip_stat.icmp.drop);
706 2 UIP_STAT(++uip_stat.icmp.typeerr);
707 2 Printf_String("\r\n[MSG:] icmp: not icmp echo.");
708 2 goto drop;
709 2 }
710 1
711 1 /* If we are configured to use ping IP address assignment, we use
712 1 the destination IP address of this ping packet and assign it to
713 1 ourself. */
714 1 #if UIP_PINGADDRCONF
if((uip_hostaddr[0] | uip_hostaddr[1]) == 0) {
uip_hostaddr[0] = BUF->destipaddr[0];
uip_hostaddr[1] = BUF->destipaddr[1];
}
#endif /* UIP_PINGADDRCONF */
720 1
721 1 ICMPBUF->type = ICMP_ECHO_REPLY;
722 1
723 1 if(ICMPBUF->icmpchksum >= HTONS(0xffff - (ICMP_ECHO << 8))) {
724 2 ICMPBUF->icmpchksum += HTONS(ICMP_ECHO << 8) + 1;
725 2 } else {
726 2 ICMPBUF->icmpchksum += HTONS(ICMP_ECHO << 8);
727 2 }
728 1
729 1 /* Swap IP addresses. */
730 1 tmp16 = BUF->destipaddr[0];
731 1 BUF->destipaddr[0] = BUF->srcipaddr[0];
732 1 BUF->srcipaddr[0] = tmp16;
733 1 tmp16 = BUF->destipaddr[1];
734 1 BUF->destipaddr[1] = BUF->srcipaddr[1];
735 1 BUF->srcipaddr[1] = tmp16;
C51 COMPILER V8.16 UIP 03/16/2009 23:18:13 PAGE 13
736 1
737 1 UIP_STAT(++uip_stat.icmp.sent);
738 1
739 1
740 1 /*@test by jerkoh ping debug@*/
741 1 gjk_iptemp=BUF->srcipaddr[0]>>8;
742 1
743 1 Printf_String("\r\n[MSG:] Reply from ");
744 1
745 1 Printf_Str(gjk_iptemp);
746 1 Printf_String(".");
747 1 Printf_Str(BUF->srcipaddr[0]);
748 1 Printf_String(".");
749 1 gjk_iptemp=BUF->srcipaddr[1]>>8;
750 1
751 1 Printf_Str(gjk_iptemp);
752 1 Printf_String(".");
753 1 Printf_Str(BUF->srcipaddr[1]);
754 1
755 1 Printf_String(": byte=32 time<37ms TTL=64 ");
756 1
757 1 /*@test by jerkoh ping debug@*/
758 1
759 1
760 1
761 1 goto send;
762 1
763 1 /* End of IPv4 input header processing code. */
764 1
765 1
766 1 #if UIP_UDP
/* UDP input processing. */
udp_input:
/* UDP processing is really just a hack. We don't do anything to the
UDP/IP headers, but let the UDP application do all the hard
work. If the application sets uip_slen, it has a packet to
send. */
#if UIP_UDP_CHECKSUMS
if(uip_udpchksum() != 0xffff) {
UIP_STAT(++uip_stat.udp.drop);
UIP_STAT(++uip_stat.udp.chkerr);
Printf_String("\r\n[MSG:] udp: bad checksum.");
goto drop;
}
#endif /* UIP_UDP_CHECKSUMS */
/* Demultiplex this UDP packet between the UDP "connections". */
for(uip_udp_conn = &uip_udp_conns[0];
uip_udp_conn < &uip_udp_conns[UIP_UDP_CONNS];
++uip_udp_conn) {
if(uip_udp_conn->lport != 0 &&
UDPBUF->destport == uip_udp_conn->lport &&
(uip_udp_conn->rport == 0 ||
UDPBUF->srcport == uip_udp_conn->rport) &&
BUF->srcipaddr[0] == uip_udp_conn->ripaddr[0] &&
BUF->srcipaddr[1] == uip_udp_conn->ripaddr[1]) {
goto udp_found;
}
}
goto drop;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -