Пример #1
0
/*------------------------------------------------------------------------
 * udp_in - handle an incoming UDP packet
 *------------------------------------------------------------------------
 */
void	udp_in(void) {			/* currpkt points to the packet	*/

	intmask	mask;			/* saved interrupt mask		*/
	int32	i;			/* index into udptab		*/
	struct	udpentry *udptr;	/* pointer to udptab entry	*/

	/* Insure only one process can access the UDP table at a time */

	mask = disable();

	/* Convert IP and UDP header fields to host byte order */

	udp_ntoh(currpkt);

	for (i=0; i<UDP_SLOTS; i++) {
	    udptr = &udptab[i];
	    if ( (udptr->udstate != UDP_FREE) &&
		 (currpkt->net_udpdport == udptr->udlocport)  &&
		    ((udptr->udremport == 0) ||
			(currpkt->net_udpsport == udptr->udremport)) &&
		 (  ((udptr->udremip==0)     ||
			(currpkt->net_ipsrc == udptr->udremip)))    ) {

		/* Entry matches incoming packet */

		if (udptr->udcount < UDP_QSIZ) {
			udptr->udcount++;
			udptr->udqueue[udptr->udtail++] = currpkt;
			if (udptr->udtail >= UDP_QSIZ) {
				udptr->udtail = 0;
			}
			currpkt = (struct netpacket *)getbuf(netbufpool);
			if (udptr->udstate == UDP_RECV) {
				udptr->udstate = UDP_USED;
				send (udptr->udpid, OK);
			}
			restore(mask);
			return;
		}
	    }
	}

	/* No match - simply discard packet */

	restore(mask);
	return;
}
Пример #2
0
/*------------------------------------------------------------------------
 * udp_in - handle an incoming UDP packet
 *------------------------------------------------------------------------
 */
void	udp_in(void) {			/* currpkt points to the packet	*/

    intmask	mask;			/* saved interrupt mask		*/
    int32	i;			/* index into udptab		*/
    struct	udpentry *udptr;	/* pointer to udptab entry	*/
    struct  ipv4_packet *ippkt = (struct ipv4_packet *)(currpkt->net_ethdata);
    struct  udp_packet * udppkt = (struct udp_packet *)(ippkt->net_ipdata);

    /* Insure only one process can access the UDP table at a time */

    mask = disable();

    //kprintf("Inside udp_in\r\n");
    /* Convert IP and UDP header fields to host byte order */

    udp_ntoh(udppkt);



    /*
    if (ippkt->net_ipproto == IP_UDP) {
            kprintf("proto UDP (%d), length %d",
                            ippkt->net_ipproto, ntohs(ippkt->net_iplen));
            kprintf(")\n");
            kprintf("\t%d.%d.%d.%d > ",
                            ((ippkt->net_ipsrc)>>24)&0xff,
                            ((ippkt->net_ipsrc)>>16)&0xff,
                            ((ippkt->net_ipsrc)>>8)&0xff,
                            ((ippkt->net_ipsrc)&0xff));
            kprintf("%d.%d.%d.%d: ",
                            ((ippkt->net_ipdst)>>24)&0xff,
                            ((ippkt->net_ipdst)>>16)&0xff,
                            ((ippkt->net_ipdst)>>8)&0xff,
                            ((ippkt->net_ipdst)&0xff));
            //kprintf("PDUMP Check 9\r\n");
            kprintf("[udp checksum none] ");
            kprintf("UDP, src port %d, dst port %d, length %d\n",
                            (udppkt->net_udpsport),
                            (udppkt->net_udpdport),
                            (udppkt->net_udplen) - UDP_HDR_LEN);
    }
    */


    for (i=0; i<UDP_SLOTS; i++) {
        udptr = &udptab[i];
        if ( (udptr->udstate != UDP_FREE) &&
                (udppkt->net_udpdport == udptr->udlocport)  &&
                ((udptr->udremport == 0) ||
                 (udppkt->net_udpsport == udptr->udremport)) &&
                (  ((udptr->udremip==0)     ||
                    (ippkt->net_ipsrc == udptr->udremip)))    ) {

            /* Entry matches incoming packet */

            if (udptr->udcount < UDP_QSIZ) {
                udptr->udcount++;
                udptr->udqueue[udptr->udtail++] = (struct eth_packet *)currpkt;
                if (udptr->udtail >= UDP_QSIZ) {
                    udptr->udtail = 0;
                }
                currpkt = (struct eth_packet *)getbuf(netbufpool);
                if (udptr->udstate == UDP_RECV) {
                    udptr->udstate = UDP_USED;
                    send (udptr->udpid, OK);
                }
                restore(mask);
                return;
            }
        }
    }

    /* No match - simply discard packet */
    //kprintf("Done with udp_in\r\n");
    restore(mask);
    return;
}