sysdump: tftp: use lmalloc(), and set the gateway
authorH. Peter Anvin <hpa@linux.intel.com>
Sat, 19 Jun 2010 01:24:14 +0000 (18:24 -0700)
committerH. Peter Anvin <hpa@linux.intel.com>
Sat, 19 Jun 2010 01:24:14 +0000 (18:24 -0700)
Use lmalloc() rather than the fixed (obsolete) bounce buffer, and set
the gateway for PXE stacks that need it.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
com32/sysdump/be_tftp.c

index 07fdb08..8c92d4d 100644 (file)
@@ -21,23 +21,30 @@ enum tftp_opcode {
 struct tftp_state {
     uint32_t my_ip;
     uint32_t srv_ip;
+    uint32_t srv_gw;
     uint16_t my_port;
     uint16_t srv_port;
     uint16_t seq;
 };
 
+#define RCV_BUF        2048
+
 static int send_ack_packet(struct tftp_state *tftp,
                           const void *pkt, size_t len)
 {
     com32sys_t ireg, oreg;
-    t_PXENV_UDP_WRITE *uw = __com32.cs_bounce;
-    t_PXENV_UDP_READ  *ur = __com32.cs_bounce;
+    t_PXENV_UDP_WRITE *uw;
+    t_PXENV_UDP_READ  *ur;
     clock_t start;
     static const clock_t timeouts[] = {
        2, 2, 3, 3, 4, 5, 6, 7, 9, 10, 12, 15, 18, 21, 26, 31,
        37, 44, 53, 64, 77, 92, 110, 132, 159, 191, 229, 0
     };
     const clock_t *timeout;
+    int err = -1;
+
+    uw = lmalloc(sizeof *uw + len);
+    ur = lmalloc(sizeof *ur + RCV_BUF);
 
     memset(&ireg, 0, sizeof ireg);
     ireg.eax.w[0] = 0x0009;
@@ -46,6 +53,7 @@ static int send_ack_packet(struct tftp_state *tftp,
        memset(uw, 0, sizeof uw);
        memcpy(uw+1, pkt, len);
        uw->ip = tftp->srv_ip;
+       uw->gw = tftp->srv_gw;
        uw->src_port = tftp->my_port;
        uw->dst_port = tftp->srv_port ? tftp->srv_port : htons(69);
        uw->buffer_size = len;
@@ -65,7 +73,7 @@ static int send_ack_packet(struct tftp_state *tftp,
            ur->dest_ip = tftp->my_ip;
            ur->s_port = tftp->srv_port;
            ur->d_port = tftp->my_port;
-           ur->buffer_size = __com32.cs_bounce_size - sizeof *ur;
+           ur->buffer_size = RCV_BUF;
            ur->buffer = FAR_PTR(ur+1);
 
            ireg.ebx.w[0] = PXENV_UDP_READ;
@@ -82,15 +90,20 @@ static int send_ack_packet(struct tftp_state *tftp,
                if (ntohs(xb[0]) == TFTP_ACK &&
                    ntohs(xb[1]) == tftp->seq) {
                    tftp->srv_port = ur->s_port;
-                   return 0;           /* All good! */
+                   err = 0;            /* All good! */
+                   goto done;
                } else if (ntohs(xb[1]) == TFTP_ERROR) {
-                   return -1;          /* All bad! */
+                   goto done;
                }
            }
        } while ((clock_t)(times(NULL) - start) < *timeout);
     }
 
-    return -1;                 /* No success... */
+done:
+    lfree(ur);
+    lfree(uw);
+
+    return err;
 }
 
 static int be_tftp_write(struct backend *be)
@@ -108,6 +121,8 @@ static int be_tftp_write(struct backend *be)
     tftp.my_ip    = sdi->pxe.myip;
     tftp.my_port  = htons(local_port++);
     tftp.srv_ip   = pxe_dns(be->argv[1]);
+    tftp.srv_gw   = ((tftp.srv_ip ^ tftp.my_ip) & sdi->pxe.ipinfo->netmask)
+       ? sdi->pxe.ipinfo->gateway : 0;
     tftp.srv_port = 0;
     tftp.seq      = 0;