diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 3827227b8..2b4c22e01 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -1598,6 +1598,7 @@ module = { module = { name = net; common = net/net.c; + common = net/dns.c; common = net/bootp.c; common = net/ip.c; common = net/udp.c; diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c index 0c060fe19..b83b343c8 100644 --- a/grub-core/net/bootp.c +++ b/grub-core/net/bootp.c @@ -541,7 +541,7 @@ grub_cmd_bootp (struct grub_command *cmd __attribute__ ((unused)), return err; } -static grub_command_t cmd_dhcp, cmd_getdhcp, cmd_bootp; +static grub_command_t cmd_getdhcp, cmd_bootp; void grub_bootp_init (void) @@ -549,9 +549,6 @@ grub_bootp_init (void) cmd_bootp = grub_register_command ("net_bootp", grub_cmd_bootp, "[CARD]", N_("perform a bootp autoconfiguration")); - cmd_dhcp = grub_register_command ("net_dhcp", grub_cmd_bootp, - "[CARD]", - N_("perform a bootp autoconfiguration")); cmd_getdhcp = grub_register_command ("net_get_dhcp_option", grub_cmd_dhcpopt, N_("VAR INTERFACE NUMBER DESCRIPTION"), N_("retrieve DHCP option and save it into VAR. If VAR is - then print the value.")); @@ -561,6 +558,5 @@ void grub_bootp_fini (void) { grub_unregister_command (cmd_getdhcp); - grub_unregister_command (cmd_dhcp); grub_unregister_command (cmd_bootp); } diff --git a/grub-core/net/net.c b/grub-core/net/net.c index fe713f05c..269786fd8 100644 --- a/grub-core/net/net.c +++ b/grub-core/net/net.c @@ -1491,6 +1491,7 @@ GRUB_MOD_INIT(net) cmd_lsaddr = grub_register_command ("net_ls_addr", grub_cmd_listaddrs, "", N_("list network addresses")); grub_bootp_init (); + grub_dns_init (); grub_fs_register (&grub_net_fs); grub_net_open = grub_net_open_real; @@ -1503,6 +1504,7 @@ GRUB_MOD_INIT(net) GRUB_MOD_FINI(net) { grub_bootp_fini (); + grub_dns_fini (); grub_unregister_command (cmd_addaddr); grub_unregister_command (cmd_deladdr); grub_unregister_command (cmd_addroute); diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c index 9be7294e8..9accdf5d2 100644 --- a/grub-core/net/tftp.c +++ b/grub-core/net/tftp.c @@ -279,6 +279,7 @@ tftp_open (struct grub_file *file, const char *filename) tftp_data_t data; grub_err_t err; grub_uint8_t *nbd; + grub_net_network_level_address_t addr; data = grub_zalloc (sizeof (*data)); if (!data) @@ -335,7 +336,14 @@ tftp_open (struct grub_file *file, const char *filename) if (!data->pq) return grub_errno; - data->sock = grub_net_udp_open (file->device->net->server, + err = grub_net_resolve_address (file->device->net->server, &addr); + if (err) + { + destroy_pq (data); + return err; + } + + data->sock = grub_net_udp_open (addr, TFTP_SERVER_PORT, tftp_receive, file); if (!data->sock) diff --git a/grub-core/net/udp.c b/grub-core/net/udp.c index 739541097..e26608e36 100644 --- a/grub-core/net/udp.c +++ b/grub-core/net/udp.c @@ -59,7 +59,7 @@ grub_net_udp_close (grub_net_udp_socket_t sock) } grub_net_udp_socket_t -grub_net_udp_open (char *server, +grub_net_udp_open (grub_net_network_level_address_t addr, grub_uint16_t out_port, grub_err_t (*recv_hook) (grub_net_udp_socket_t sock, struct grub_net_buff *nb, @@ -67,17 +67,12 @@ grub_net_udp_open (char *server, void *recv_hook_data) { grub_err_t err; - grub_net_network_level_address_t addr; struct grub_net_network_level_interface *inf; grub_net_network_level_address_t gateway; grub_net_udp_socket_t socket; static int in_port = 25300; grub_net_link_level_address_t ll_target_addr; - err = grub_net_resolve_address (server, &addr); - if (err) - return NULL; - if (addr.type != GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4 && addr.type != GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV6) { diff --git a/include/grub/err.h b/include/grub/err.h index d13f2c9ce..3a75f5698 100644 --- a/include/grub/err.h +++ b/include/grub/err.h @@ -65,7 +65,8 @@ typedef enum GRUB_ERR_NET_PORT_CLOSED, GRUB_ERR_NET_INVALID_RESPONSE, GRUB_ERR_NET_UNKNOWN_ERROR, - GRUB_ERR_NET_PACKET_TOO_BIG + GRUB_ERR_NET_PACKET_TOO_BIG, + GRUB_ERR_NET_NO_DOMAIN } grub_err_t; diff --git a/include/grub/net.h b/include/grub/net.h index b3adb74f9..f39c9d70b 100644 --- a/include/grub/net.h +++ b/include/grub/net.h @@ -446,6 +446,9 @@ grub_net_poll_cards (unsigned time); void grub_bootp_init (void); void grub_bootp_fini (void); +void grub_dns_init (void); +void grub_dns_fini (void); + static inline void grub_net_network_level_interface_unregister (struct grub_net_network_level_interface *inter) { @@ -472,6 +475,13 @@ grub_err_t grub_net_link_layer_resolve (struct grub_net_network_level_interface *inf, const grub_net_network_level_address_t *proto_addr, grub_net_link_level_address_t *hw_addr); +grub_err_t +grub_net_dns_lookup (const char *name, + const struct grub_net_network_level_address *servers, + grub_size_t n_servers, + grub_size_t *naddresses, + struct grub_net_network_level_address **addresses, + int cache); extern char *grub_net_default_server; diff --git a/include/grub/net/udp.h b/include/grub/net/udp.h index fca94ba47..1a7efa777 100644 --- a/include/grub/net/udp.h +++ b/include/grub/net/udp.h @@ -33,7 +33,7 @@ struct grub_net_udp_socket; typedef struct grub_net_udp_socket *grub_net_udp_socket_t; grub_net_udp_socket_t -grub_net_udp_open (char *server, +grub_net_udp_open (grub_net_network_level_address_t addr, grub_uint16_t out_port, grub_err_t (*recv_hook) (grub_net_udp_socket_t sock, struct grub_net_buff *nb,