Commit Graph

77 Commits

Author SHA1 Message Date
Vincent Batts 1b24dcf433 one patch, on grub-2.04 2020-10-29 15:48:21 -04:00
Andrei Borzenkov 5a4f9d5c04 net/dhcp: Actually send out DHCPv4 DISCOVER and REQUEST messages
Even though we were parsing some DHCP options sent by the server, so far
we are only using the BOOTP 2-way handshake, even when talking to a DHCP
server.

Change this by actually sending out DHCP DISCOVER packets instead of the
generic (mostly empty) BOOTP BOOTREQUEST packets.

A pure BOOTP server would ignore the extra DHCP options in the DISCOVER
packet and would just reply with a BOOTREPLY packet, which we also
handle in the code.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2019-03-12 20:04:07 +01:00
Andrei Borzenkov 5a365fed87 net/dhcp: Allow receiving DHCP OFFER and ACK packets
In respone to a BOOTREQUEST packet a BOOTP server would answer with a BOOTREPLY
packet, which ends the conversation for good. DHCP uses a 4-way handshake,
where the initial server respone is an OFFER, which has to be answered with
REQUEST by the client again, only to be completed by an ACKNOWLEDGE packet
from the server.

Teach the grub_net_process_dhcp() function to deal with OFFER packets,
and treat ACK packets the same es BOOTREPLY packets.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2019-03-12 20:04:07 +01:00
Andrei Borzenkov 93289dc67c net/dhcp: Use DHCP options for name and bootfile
The BOOTP RFC describes the boot file name and the server name as being part
of the integral BOOTP data structure, with some limits on the size of them.
DHCP extends this by allowing them to be separate DHCP options, which is more
flexible.

Teach the code dealing with those fields to check for those DHCP options first
and use this information, if provided. We fall back to using the BOOTP
information if those options are not used.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2019-03-12 20:04:07 +01:00
Andrei Borzenkov 12e1b6e604 net/dhcp: Introduce per-interface timeout
Currently we have a global timeout for all network cards in the BOOTP/DHCP
discovery process.

Make this timeout a per-interface one, so better accommodate the upcoming
4-way DHCP handshake and to also cover the lease time limit a DHCP offer
will come with.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2019-03-12 20:04:07 +01:00
Andrei Borzenkov 5459243465 net/dhcp: Make grub_net_process_dhcp() take an interface
Change the interface of the function dealing with incoming BOOTP packets
to take an interface instead of a card, to allow more fine per-interface
state (timeout, handshake state) later on.

Use the opportunity to clean up the code a bit.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2019-03-12 20:04:07 +01:00
Andrei Borzenkov bd21d6465e net/dhcp: Allow overloading legacy bootfile and name field
DHCP specifies a special dummy option OVERLOAD, to allow DHCP options to
spill over into the (legacy) BOOTFILE and SNAME fields.

Parse and handle this option properly.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2019-03-12 20:04:07 +01:00
Paulo Flabiano Smorigo d9f7de0ae3 Add Virtual LAN support.
This patch adds support for virtual LAN (VLAN) tagging. VLAN tagging allows
multiple VLANs in a bridged network to share the same physical network link
but maintain isolation:

http://en.wikipedia.org/wiki/IEEE_802.1Q

* grub-core/net/ethernet.c: Add check, get, and set vlan tag id.
* grub-core/net/drivers/ieee1275/ofnet.c: Get vlan tag id from bootargs.
* grub-core/net/arp.c: Add check.
* grub-core/net/ip.c: Likewise.
* include/grub/net/arp.h: Add vlantag attribute.
* include/grub/net/ip.h: Likewise.
2017-05-03 13:03:50 +02:00
Josef Bacik eb9f401fc1 net: fix ipv6 routing
ipv6 routing in grub2 is broken, we cannot talk to anything outside our local
network or anything that doesn't route in our global namespace.  This patch
fixes this by doing a couple of things

1) Read the router information off of the router advertisement.  If we have a
router lifetime we need to take the source address and create a route from it.

2) Changes the routing stuff slightly to allow you to specify a gateway _and_ an
interface.  Since the router advertisements come in on the link local address we
need to associate it with the global address on the card.  So when we are
processing the router advertisement, either use the SLAAC interface we create
and add the route to that interface, or loop through the global addresses we
currently have on our interface and associate it with one of those addresses.
We need to have a special case here for the default route so that it gets used,
we do this by setting the masksize to 0 to mean it encompasses all networks.
The routing code will automatically select the best route so if there is a
closer match we will use that.

With this patch I can now talk to ipv6 addresses outside of my local network.
Thanks,

Signed-off-by: Josef Bacik <jbacik@fb.com>
2016-02-25 22:38:52 +03:00
Paulo Flabiano Smorigo e4dbf247b6 add grub_env_set_net_property function
* grub-core/net/bootp.c: Remove set_env_limn_ro.
* grub-core/net/net.c: Add grub_env_set_net_property.
* include/grub/net.h: Likewise.
2014-02-04 18:41:38 -02:00
Paulo Flabiano Smorigo 6f65e36cc4 increase network try interval gradually
* grub-core/net/arp.c (grub_net_arp_send_request): Increase network try
interval gradually.
* grub-core/net/icmp6.c (grub_net_icmp6_send_request): Likewise.
* grub-core/net/net.c (grub_net_fs_read_real): Likewise.
* grub-core/net/tftp.c (tftp_open): Likewise.
* include/grub/net.h (GRUB_NET_INTERVAL_ADDITION): New define.
2014-01-21 11:06:35 -02:00
Vladimir Serbinenko 7e47e27bd8 Add gcc_struct to all packed structures when compiling with mingw.
Just "packed" doesn't always pack the way we expect.
2013-12-15 14:14:30 +01:00
Gustavo Luiz Duarte 9e236169e9
issue separate DNS queries for ipv4 and ipv6
Adding multiple questions on a single DNS query is not supportted by
most DNS servers. This patch issues two separate DNS queries
sequentially for ipv4 and then for ipv6.

Fixes: https://savannah.gnu.org/bugs/?39710

 * grub-core/net/bootp.c (parse_dhcp_vendor): Add DNS option.
 * grub-core/net/dns.c (grub_dns_qtype_id): New enum.
 * (grub_net_dns_lookup): Now using separated dns packages.
 * (grub_cmd_nslookup): Add error condition.
 * (grub_cmd_list_dns): Print DNS option.
 * (grub_cmd_add_dns): Add four parameters: --only-ipv4,
 * --only-ipv6, --prefer-ipv4, and --prefer-ipv6.
 * include/grub/net.h (grub_dns_option_t): New enum.
 * (grub_net_network_level_address): option added.

Also-by: Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
Signed-off-by: Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
2013-11-05 17:41:16 -02:00
Vladimir 'phcoder' Serbinenko 2f1071d57e Resend a packet if we got the wrong buffer in status. 2013-03-17 13:33:16 +01:00
Vladimir 'phcoder' Serbinenko b27069e06d Implement flow control for tftp.
* grub-core/net/net.c (receive_packets): Decrease the stop to 10
	packets but stop only if stop condition is satisfied.
	(grub_net_fs_read_real): Call packets_pulled after real read. Use
	`stall' instead of `eof' as stop condition.
	* grub-core/net/http.c (parse_line): Set `stall' on EOF.
	(http_err): Likewise.
	* grub-core/net/tftp.c (ack): Replace the first argument with data
	instead of socket.
	(tftp_receive): Stall if too many packets are in wait queue.
	(tftp_packets_pulled): New function.
	(grub_tftp_protocol): Set packets_pulled.
	* include/grub/net.h (grub_net_packets): New field count.
	(grub_net_put_packet): Increment count.
	(grub_net_remove_packet): Likewise.
	(grub_net_app_protocol): New field `packets_pulled'.
	(grub_net): New field `stall'.
2012-06-22 14:17:46 +02:00
Vladimir 'phcoder' Serbinenko d6b7c7c986 Respect netmask from bootp/dhcp.
* grub-core/net/bootp.c (parse_dhcp_vendor): Parse mask.
	(grub_net_configure_by_dhcp_ack): Use mask and grub_net_add_ipv4_local.
	* grub-core/net/net.c (grub_net_add_addr): Split creating local route
	into ...
	(grub_net_add_ipv4_local): ... this.
	(grub_cmd_addaddr): Use grub_net_add_ipv4_local.
	* include/grub/net.h (GRUB_NET_BOOTP_NETMASK): New enum value.
	(grub_net_add_ipv4_local): New proto.
2012-06-20 23:46:50 +02:00
Vladimir 'phcoder' Serbinenko 0494408e7e * include/grub/net.h (grub_net_card): New member txbufsize.
* include/grub/ieee1275/ieee1275.h (grub_ieee1275_flag): New enum values
	GRUB_IEEE1275_FLAG_NO_OFNET_SUFFIX and
	GRUB_IEEE1275_FLAG_VIRT_TO_REAL_BROKEN.
	* grub-core/net/drivers/efi/efinet.c (grub_efinet_findcards): Use
	txbufsize.
	* grub-core/kern/ieee1275/cmain.c (grub_ieee1275_find_options): Use
	compatible property to check for macs. Set
	GRUB_IEEE1275_FLAG_NO_OFNET_SUFFIX and
	GRUB_IEEE1275_FLAG_VIRT_TO_REAL_BROKEN on macs.
	* grub-core/net/drivers/ieee1275/ofnet.c (card_open): Don't add suffix
	if GRUB_IEEE1275_FLAG_NO_OFNET_SUFFIX is set.
	(send_card_buffer): Use txbuf.
	(grub_ofnet_findcards): Allocate txbuf. Simplify code flow and move
	nested function out of the parent while on it.
2012-06-19 11:34:52 +02:00
Vladimir 'phcoder' Serbinenko 96f7e60eae 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 11:06:55 +02:00
Vladimir 'phcoder' Serbinenko 3e74723951 Keep TX and RX buffers on EFI rather than always allocate new ones.
* include/grub/net.h (grub_net_card_driver): Allow driver to modify
	card. All users updated.
	(grub_net_card): New members txbuf, rcvbuf, rcvbufsize and txbusy.
	* grub-core/net/drivers/efi/efinet.c (send_card_buffer): Reuse buffer.
	(get_card_packet): Likewise.
	(grub_efinet_findcards): Init new fields.
2012-06-09 11:00:18 +02:00
Vladimir 'phcoder' Serbinenko b2c0c4a6c6 * include/grub/net.h: Remove double declarations. 2012-02-09 22:44:28 +01:00
Vladimir 'phcoder' Serbinenko 87edb8940a Replace single-linked with double-linked lists. It results in more
compact and more efficient code.

	* grub-core/kern/list.c (grub_list_push): Moved from here ...
	* include/grub/list.h (grub_list_push): ... to here. Set prev.
	(grub_list_remove): Moved from here ...
	* include/grub/list.h (grub_list_remove): ... here. Use and set prev.
	(grub_prio_list_insert): Set prev.
	* include/grub/list.h (grub_list): Add prev. All users updated.
2012-01-24 13:31:12 +01:00
Vladimir 'phcoder' Serbinenko aa7d205236 Retrieve DNS names from DHCP/BOOTP 2011-12-16 17:37:47 +01:00
Vladimir 'phcoder' Serbinenko f0f4253cd2 Integrate DNS with address parsing 2011-12-16 17:12:01 +01:00
Vladimir 'phcoder' Serbinenko bd67ad0f70 merge mainline into net 2011-12-15 20:51:35 +01:00
Vladimir 'phcoder' Serbinenko d1c501ee94 * include/grub/net.h (grub_net_network_level_interfaces): Remove
redundant declaration.
	(FOR_NET_NETWORK_LEVEL_INTERFACES): Move to appropriate place.
2011-12-13 15:03:06 +01:00
Vladimir 'phcoder' Serbinenko bf3a385792 Add missing const qualifiers.
* grub-core/commands/i386/pc/sendkey.c (keysym): Add missing const.
	* grub-core/commands/lspci.c (grub_pci_classname): Likewise.
	* grub-core/commands/menuentry.c (hotkey_aliases): Likewise.
	* grub-core/disk/lvm.c (grub_lvm_getvalue): Likewise.
	(grub_lvm_check_flag): Likewise.
	* grub-core/efiemu/i386/coredetect.c
	(grub_efiemu_get_default_core_name): Likewise
	* grub-core/efiemu/main.c (grub_efiemu_autocore): Likewise.
	* grub-core/fs/hfsplus.c (grub_hfsplus_catkey_internal): Likewise.
	* grub-core/fs/ntfs.c (fixup): Likewise.
	* grub-core/fs/xfs.c (grub_xfs_iterate_dir): Likewise.
	* grub-core/fs/zfs/zfs.c (decomp_entry): Likewise.
	(fzap_lookup): Likewise.
	(zap_lookup): Likewise.
	* grub-core/gnulib/regcomp.c (init_dfa): Likewise.
	* grub-core/lib/legacy_parse.c (check_option): Likewise.
	* grub-core/lib/posix_wrap/langinfo.h (nl_langinfo): Likewise.
	* grub-core/loader/i386/bsd.c (grub_bsd_add_meta): Likewise.
	(grub_freebsd_add_meta_module): Likewise.
	(grub_cmd_freebsd_module): Likewise.
	* grub-core/loader/i386/xnu.c (tbl_alias): Likewise.
	* grub-core/loader/xnu.c (grub_xnu_register_memory): Likewise.
	(grub_xnu_writetree_get_size): Likewise.
	(grub_xnu_writetree_toheap_real): Likewise.
	(grub_xnu_find_key): Likewise.
	(grub_xnu_create_key): Likewise.
	(grub_xnu_create_value): Likewise.
	(grub_xnu_register_memory): Likewise.
	(grub_xnu_check_os_bundle_required): Likewise.
	(grub_xnu_scan_dir_for_kexts): Likewise.
	(grub_xnu_load_kext_from_dir): Likewise.
	* grub-core/normal/color.c (color_list): Likewise.
	* grub-core/normal/completion.c (current_word): Likewise.
	* grub-core/normal/menu_entry.c (insert_string): Likewise.
	* grub-core/term/serial.c (grub_serial_find): Likewise.
	* grub-core/term/tparm.c (grub_terminfo_tparm): Likewise.
	* include/grub/efiemu/efiemu.h (grub_efiemu_get_default_core_name):
	Likewise.
	* include/grub/i386/bsd.h (grub_bsd_add_meta): Likewise.
	(grub_freebsd_add_meta_module): Likewise.
	* include/grub/lib/arg.h (grub_arg_option): Likewise.
	* include/grub/net.h (grub_net_card_driver): Likewise.
	(grub_net_card): Likewise.
	(grub_net_app_protocol): Likewise.
	* include/grub/parttool.h (grub_parttool_argdesc): Likewise.
	* include/grub/serial.h (grub_serial_find): Likewise.
	* include/grub/tparm.h (grub_terminfo_tparm): Likewise.
	* include/grub/xnu.h (grub_xnu_create_key): Likewise.
	(grub_xnu_create_value): Likewise.
	(grub_xnu_find_key): Likewise.
	(grub_xnu_scan_dir_for_kexts): Likewise.
	(grub_xnu_load_kext_from_dir): Likewise.

	* include/grub/zfs/zio_checksum.h (zio_checksum_t): Moved from here ...
	* grub-core/fs/zfs/zfs.c (zio_checksum_t): ...here.
	* include/grub/zfs/zio_checksum.h (zio_checksum_info):
	Moved from here ...
	* grub-core/fs/zfs/zfs.c (zio_checksum_info): ... here. Added missing const.
2011-11-30 16:20:13 +01:00
Vladimir 'phcoder' Serbinenko 038ec56a31 nslookup implementation 2011-10-14 19:21:59 +02:00
Vladimir 'phcoder' Serbinenko da1b289afc IPv6. Apparently working. At least I could retrieve a file with http6 2011-10-13 01:22:56 +02:00
Vladimir 'phcoder' Serbinenko 7c006811f8 more ipv6 code. Now ipv6 ping succeeds 2011-10-12 23:15:02 +02:00
Vladimir 'phcoder' Serbinenko a53cf6534d some more ipv6 code 2011-10-12 10:20:55 +02:00
Vladimir 'phcoder' Serbinenko 9aad3cd91d IPv6 support. Several fixes and unifications 2011-10-05 22:15:30 +02:00
Vladimir 'phcoder' Serbinenko 4f71e077b9 HTTP seek support. Various bugfixes. 2011-10-05 17:39:13 +02:00
Vladimir 'phcoder' Serbinenko 80e722366d First attempt at http 2011-07-23 03:49:02 +02:00
Vladimir 'phcoder' Serbinenko 3a7af37260 basic tcp implementation 2011-07-10 08:46:48 +02:00
Vladimir 'phcoder' Serbinenko fecdbd6b17 support ip fragmentation 2011-07-09 00:27:27 +02:00
Vladimir 'phcoder' Serbinenko e2955971a3 move packet allocation to recv code to allow bigger buffers 2011-07-08 20:38:12 +02:00
Vladimir 'phcoder' Serbinenko 6a1af81a97 add mtu information 2011-07-08 18:49:35 +02:00
Vladimir 'phcoder' Serbinenko 1367c143dd several cleanups. Ping reply support 2011-07-08 14:41:52 +02:00
Vladimir 'phcoder' Serbinenko d1831ca48a Limit idle polling frequency 2011-07-06 18:21:07 +02:00
Vladimir 'phcoder' Serbinenko 138eeb3625 Move bootp into a separate file 2011-07-06 13:52:35 +02:00
Vladimir 'phcoder' Serbinenko b975df6348 Send TFTP_ERROR on tftp premature close. Several cleanups 2011-07-06 12:53:37 +02:00
Vladimir 'phcoder' Serbinenko 0bc2cd0f82 Reintroduce open/close of net cards. Clean up ofnet. 2011-07-05 16:37:14 +02:00
Vladimir 'phcoder' Serbinenko 671a78acb0 cleanup pxe and efi network release 2011-07-05 14:34:10 +02:00
Vladimir 'phcoder' Serbinenko 7e0c2d162a Restructurisations, cleanups and few bugfixes 2011-07-02 22:13:33 +02:00
Vladimir 'phcoder' Serbinenko c4d038f632 Don't react to adressed bootp packets unless in bootp transaction 2011-07-02 20:11:29 +02:00
Vladimir 'phcoder' Serbinenko 6708faafde Fix broken blksize negotiation, fix broken seek and change a way net device is filled n i386-pc 2011-07-02 17:58:23 +02:00
Vladimir 'phcoder' Serbinenko cae730b452 Automatically determine prefix when netbooted on EFI 2011-07-02 16:56:35 +02:00
Vladimir 'phcoder' Serbinenko d36f20db46 Don't do unaligned access when parsing DHCP packet 2011-06-26 22:37:19 +02:00
Vladimir 'phcoder' Serbinenko 80ca250565 Add backward compatibiulity with old (pxe) syntax. Several cleanups 2011-06-26 17:06:18 +02:00
Vladimir 'phcoder' Serbinenko a057797f18 merge mine and abranches' branches. Fix several issues 2011-06-24 21:51:57 +02:00