]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
Stop polling as soon as we have the packet we were waiting for.
authorVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Sat, 9 Jun 2012 09:06:55 +0000 (11:06 +0200)
committerVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Sat, 9 Jun 2012 09:06:55 +0000 (11:06 +0200)
* include/grub/net.h (grub_net_poll_cards): New argument stop_condition.
All users updated.
* grub-core/net/arp.c (have_pending): New var.
(pending_req): Likewise.
(grub_net_arp_send_request): Fill pending_req and use have_pending as
stop indicator.
(grub_net_arp_receive): Set have_pending.
* grub-core/net/dns.c (recv_data): New field stop.
(recv_hook): Set stop.
(grub_net_dns_lookup): Init stop and use as stop condition.
* grub-core/net/http.c (http_establish): Use headers_recv as stop
condition.
* grub-core/net/net.c (grub_net_poll_cards): New argument
stop_condition. Stop when it goes true.
* grub-core/net/tcp.c (grub_net_tcp_open): Use `established' as stop
indicator.
* grub-core/net/tftp.c (tftp_open): Use `have_oack' as stop indicator.

ChangeLog
grub-core/net/arp.c
grub-core/net/bootp.c
grub-core/net/dns.c
grub-core/net/http.c
grub-core/net/icmp6.c
grub-core/net/net.c
grub-core/net/tcp.c
grub-core/net/tftp.c
include/grub/net.h

index ad1da08cbb04c0bc15b91c272937d95c7130fda1..0d03c0932e884a8db03e9941ab298a99ef1eb10a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,25 @@
+2012-06-09  Vladimir Serbinenko  <phcoder@gmail.com>
+
+       Stop polling as soon as we have the packet we were waiting for.
+
+       * include/grub/net.h (grub_net_poll_cards): New argument stop_condition.
+       All users updated.
+       * grub-core/net/arp.c (have_pending): New var.
+       (pending_req): Likewise.
+       (grub_net_arp_send_request): Fill pending_req and use have_pending as
+       stop indicator.
+       (grub_net_arp_receive): Set have_pending.
+       * grub-core/net/dns.c (recv_data): New field stop.
+       (recv_hook): Set stop.
+       (grub_net_dns_lookup): Init stop and use as stop condition.
+       * grub-core/net/http.c (http_establish): Use headers_recv as stop
+       condition.
+       * grub-core/net/net.c (grub_net_poll_cards): New argument
+       stop_condition. Stop when it goes true.
+       * grub-core/net/tcp.c (grub_net_tcp_open): Use `established' as stop
+       indicator.
+       * grub-core/net/tftp.c (tftp_open): Use `have_oack' as stop indicator.
+
 2012-06-09  Vladimir Serbinenko  <phcoder@gmail.com>
 
        Keep TX and RX buffers on EFI rather than always allocate new ones.
index 3db852e74fc867e8d5d22f2316b6a0f17a3596ce..a34aecd0a8569427be3306963ba15ebe8d850f47 100644 (file)
@@ -45,6 +45,8 @@ struct arphdr {
   grub_uint16_t op;
 } __attribute__ ((packed));
 
+static int have_pending;
+static grub_uint32_t pending_req;
 
 grub_err_t
 grub_net_arp_send_request (struct grub_net_network_level_interface *inf,
@@ -106,7 +108,9 @@ grub_net_arp_send_request (struct grub_net_network_level_interface *inf,
     {
       if (grub_net_link_layer_resolve_check (inf, proto_addr))
        return GRUB_ERR_NONE;
-      grub_net_poll_cards (GRUB_NET_INTERVAL);
+      pending_req = proto_addr->ipv4;
+      have_pending = 0;
+      grub_net_poll_cards (GRUB_NET_INTERVAL, &have_pending);
       if (grub_net_link_layer_resolve_check (inf, proto_addr))
        return GRUB_ERR_NONE;
       nb.data = nbd;
@@ -140,6 +144,8 @@ grub_net_arp_receive (struct grub_net_buff *nb,
       target_addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4;
       grub_memcpy (&sender_addr.ipv4, sender_protocol_address, 4);
       grub_memcpy (&target_addr.ipv4, target_protocol_address, 4);
+      if (grub_memcmp (sender_protocol_address, &pending_req, 4) == 0)
+       have_pending = 1;
     }
   else
     return GRUB_ERR_NONE;
index d11fdb20dc0c3b1caddc0a2a9882d55e2292617a..a303bb19c665c754f877ff49ffcd34f1a9cab8f9 100644 (file)
@@ -541,7 +541,7 @@ grub_cmd_bootp (struct grub_command *cmd __attribute__ ((unused)),
        }
       if (!done)
        break;
-      grub_net_poll_cards (interval);
+      grub_net_poll_cards (interval, 0);
     }
 
   err = GRUB_ERR_NONE;
index ee3029e0bce3569804b929fad9f951e8102a2879..acf8557712d25b8f4c518119ec39d90f70cf67d3 100644 (file)
@@ -108,6 +108,7 @@ struct recv_data
   int dns_err;
   char *name;
   const char *oname;
+  int stop;
 };
 
 static inline int
@@ -339,6 +340,7 @@ recv_hook (grub_net_udp_socket_t sock __attribute__ ((unused)),
              grub_memcpy (&(*data->addresses)[*data->naddresses].ipv4,
                           ptr, 4);
              (*data->naddresses)++;
+             data->stop = 1;
              break;
            case DNS_CLASS_AAAA:
              if (length != 16)
@@ -348,6 +350,7 @@ recv_hook (grub_net_udp_socket_t sock __attribute__ ((unused)),
              grub_memcpy (&(*data->addresses)[*data->naddresses].ipv6,
                           ptr, 16);
              (*data->naddresses)++;
+             data->stop = 1;
              break;
            case DNS_CLASS_CNAME:
              if (!(redirect_cnt & (redirect_cnt - 1)))
@@ -425,7 +428,7 @@ grub_net_dns_lookup (const char *name,
   static grub_uint16_t id = 1;
   grub_err_t err = GRUB_ERR_NONE;
   struct recv_data data = {naddresses, addresses, cache,
-                          grub_cpu_to_be16 (id++), 0, 0, name};
+                          grub_cpu_to_be16 (id++), 0, 0, name, 0};
   grub_uint8_t *nbd;
   int have_server = 0;
 
@@ -573,7 +576,7 @@ grub_net_dns_lookup (const char *name,
          if (*data.naddresses)
            goto out;
        }
-      grub_net_poll_cards (200);
+      grub_net_poll_cards (200, &data.stop);
     }
  out:
   grub_free (data.name);
index 48b2ccf341e7cf378a41180ad1b3344689a94d89..be9dafacd8af9764fa87b0dec2cfc5e1504e243c 100644 (file)
@@ -390,7 +390,7 @@ http_establish (struct grub_file *file, grub_off_t offset, int initial)
   for (i = 0; !data->headers_recv && i < 100; i++)
     {
       grub_net_tcp_retransmit ();
-      grub_net_poll_cards (300);
+      grub_net_poll_cards (300, &data->headers_recv);
     }
 
   if (!data->headers_recv)
index 9a5f3cafe3a8e0509f0d3541f429da0caa87140b..4fc343d7292ffedfa8cb3c49111dfb93b347aff9 100644 (file)
@@ -513,7 +513,7 @@ grub_net_icmp6_send_request (struct grub_net_network_level_interface *inf,
     {
       if (grub_net_link_layer_resolve_check (inf, proto_addr))
        break;
-      grub_net_poll_cards (GRUB_NET_INTERVAL);
+      grub_net_poll_cards (GRUB_NET_INTERVAL, 0);
       if (grub_net_link_layer_resolve_check (inf, proto_addr))
        break;
       nb->data = nbd;
index 7e3ad7795895e3812cfe96559df1770d1207a502..9f1afd1e764928c7a247e676386e6b1f1ad9e03b 100644 (file)
@@ -339,7 +339,7 @@ grub_cmd_ipv6_autoconf (struct grub_command *cmd __attribute__ ((unused)),
        }
       if (done)
        break;
-      grub_net_poll_cards (interval);
+      grub_net_poll_cards (interval, 0);
     }
 
   err = GRUB_ERR_NONE;
@@ -1336,16 +1336,15 @@ receive_packets (struct grub_net_card *card)
 }
 
 void
-grub_net_poll_cards (unsigned time)
+grub_net_poll_cards (unsigned time, int *stop_condition)
 {
   struct grub_net_card *card;
   grub_uint64_t start_time;
-  FOR_NET_CARDS (card)
-    {
-      start_time = grub_get_time_ms ();
-      while ((grub_get_time_ms () - start_time) < time)        
-       receive_packets (card);
-    }
+  start_time = grub_get_time_ms ();
+  while ((grub_get_time_ms () - start_time) < time
+        && (!stop_condition || !*stop_condition))
+    FOR_NET_CARDS (card)
+      receive_packets (card);
   grub_net_tcp_retransmit ();
 }
 
@@ -1405,7 +1404,7 @@ grub_net_fs_read_real (grub_file_t file, char *buf, grub_size_t len)
       if (!net->eof)
        {
          try++;
-         grub_net_poll_cards (GRUB_NET_INTERVAL);
+         grub_net_poll_cards (GRUB_NET_INTERVAL, &net->eof);
        }
       else
        return total;
index ae86d2b864147042336bf7133b23894facae4063..57fdba97994dc1ccdbf407b7b2ad0926f205a98b 100644 (file)
@@ -649,7 +649,7 @@ grub_net_tcp_open (char *server,
        }
       for (j = 0; (j < TCP_SYN_RETRANSMISSION_TIMEOUT / 50 
                   && !socket->established); j++)
-       grub_net_poll_cards (50);
+       grub_net_poll_cards (50, &socket->established);
       if (socket->established)
        break;
     }
index 7cc89390d8fb97dd582e0ef223bf58cd1019d05b..abd5395d6a4e1a04df534142fa4d349fd955b54d 100644 (file)
@@ -376,7 +376,7 @@ tftp_open (struct grub_file *file, const char *filename)
          destroy_pq (data);
          return err;
        }
-      grub_net_poll_cards (GRUB_NET_INTERVAL);
+      grub_net_poll_cards (GRUB_NET_INTERVAL, &data->have_oack);
       if (data->have_oack)
        break;
     }
index bd6d87ae91e489818025a6fb8900d53ce139a4bf..d854ed2de35a3d571d846123727ee1cfcaf4d5ac 100644 (file)
@@ -458,7 +458,7 @@ void
 grub_net_hwaddr_to_str (const grub_net_link_level_address_t *addr, char *str);
 
 void
-grub_net_poll_cards (unsigned time);
+grub_net_poll_cards (unsigned time, int *stop_condition);
 
 void grub_bootp_init (void);
 void grub_bootp_fini (void);