static int BootpCheckPkt(uchar *pkt, unsigned dest, unsigned src, unsigned len){ Bootp_t *bp = (Bootp_t *) pkt; int retval = 0; if(dest != PORT_BOOTPC || src != PORT_BOOTPS){ retval = -1; } else if(len < sizeof (Bootp_t) - OPT_SIZE){ retval = -2; } else if(bp->bp_op != OP_BOOTREQUEST && bp->bp_op != OP_BOOTREPLY && bp->bp_op != DHCP_OFFER && bp->bp_op != DHCP_ACK && bp->bp_op != DHCP_NAK){ retval = -3; } else if(bp->bp_htype != HWT_ETHER){ retval = -4; } else if(bp->bp_hlen != HWL_ETHER){ retval = -5; } else if(NetReadLong((ulong*)&bp->bp_id) != BootpID){ retval = -6; } #ifdef DEBUG printf("Filtering pkt = %d\n", retval); #endif return(retval); }
static int BootpCheckPkt(uchar *pkt, unsigned dest, unsigned src, unsigned len) { struct Bootp_t *bp = (struct Bootp_t *) pkt; int retval = 0; if (dest != PORT_BOOTPC || src != PORT_BOOTPS) retval = -1; else if (len < sizeof(struct Bootp_t) - OPT_FIELD_SIZE) retval = -2; else if (bp->bp_op != OP_BOOTREQUEST && bp->bp_op != OP_BOOTREPLY && bp->bp_op != DHCP_OFFER && bp->bp_op != DHCP_ACK && bp->bp_op != DHCP_NAK) retval = -3; else if (bp->bp_htype != HWT_ETHER) retval = -4; else if (bp->bp_hlen != HWL_ETHER) retval = -5; else if (!bootp_match_id(NetReadLong((uint *)&bp->bp_id))) retval = -6; debug("Filtering pkt = %d\n", retval); return retval; }
/* * Handle a BOOTP received packet. */ static void BootpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src, unsigned len) { struct Bootp_t *bp; debug("got BOOTP packet (src=%d, dst=%d, len=%d want_len=%zu)\n", src, dest, len, sizeof(struct Bootp_t)); bp = (struct Bootp_t *)pkt; /* Filter out pkts we don't want */ if (BootpCheckPkt(pkt, dest, src, len)) return; /* * Got a good BOOTP reply. Copy the data into our variables. */ #ifdef CONFIG_STATUS_LED status_led_set(STATUS_LED_BOOT, STATUS_LED_OFF); #endif BootpCopyNetParams(bp); /* Store net parameters from reply */ /* Retrieve extended information (we must parse the vendor area) */ if (NetReadLong((uint *)&bp->bp_vend[0]) == htonl(BOOTP_VENDOR_MAGIC)) BootpVendorProcess((uchar *)&bp->bp_vend[4], len); NetSetTimeout(0, (thand_f *)0); bootstage_mark_name(BOOTSTAGE_ID_BOOTP_STOP, "bootp_stop"); debug("Got good BOOTP\n"); net_auto_load(); }
/* * Handle a BOOTP received packet. */ static void BootpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len) { Bootp_t *bp; char *s; debug("got BOOTP packet (src=%d, dst=%d, len=%d want_len=%zu)\n", src, dest, len, sizeof (Bootp_t)); bp = (Bootp_t *)pkt; if (BootpCheckPkt(pkt, dest, src, len)) /* Filter out pkts we don't want */ return; /* * Got a good BOOTP reply. Copy the data into our variables. */ #ifdef CONFIG_STATUS_LED status_led_set (STATUS_LED_BOOT, STATUS_LED_OFF); #endif BootpCopyNetParams(bp); /* Store net parameters from reply */ /* Retrieve extended information (we must parse the vendor area) */ if (NetReadLong((ulong*)&bp->bp_vend[0]) == htonl(BOOTP_VENDOR_MAGIC)) BootpVendorProcess((uchar *)&bp->bp_vend[4], len); NetSetTimeout(0, (thand_f *)0); debug("Got good BOOTP\n"); if ((s = getenv("autoload")) != NULL) { if (*s == 'n') { /* * Just use BOOTP to configure system; * Do not use TFTP to load the bootfile. */ NetState = NETLOOP_SUCCESS; return; #if defined(CONFIG_CMD_NFS) } else if (strcmp(s, "NFS") == 0) { /* * Use NFS to load the bootfile. */ NfsStart(); return; #endif } } struct NetTask tftp_task; BootpDeriveTaskTftp(&tftp_task, bp); TftpStart(&tftp_task); }