From nobody@FreeBSD.org  Tue Sep 18 13:28:50 2012
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id C92FF106566C
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 18 Sep 2012 13:28:50 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 9B97D8FC0A
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 18 Sep 2012 13:28:50 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.5/8.14.5) with ESMTP id q8IDSoGj048867
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 18 Sep 2012 13:28:50 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.5/8.14.5/Submit) id q8IDSow0048866;
	Tue, 18 Sep 2012 13:28:50 GMT
	(envelope-from nobody)
Message-Id: <201209181328.q8IDSow0048866@red.freebsd.org>
Date: Tue, 18 Sep 2012 13:28:50 GMT
From: Stephen Workman <workman.stephen@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [PATCH] Fix wake command not sending proper WOL packet
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         171744
>Category:       bin
>Synopsis:       [PATCH] Fix wake(8) command not sending proper WOL packet
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    hiren
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Sep 18 13:30:10 UTC 2012
>Closed-Date:    
>Last-Modified:  Fri May 31 11:20:00 UTC 2013
>Originator:     Stephen Workman
>Release:        FreeBSD 9.0-RELEASE-p3
>Organization:
>Environment:
FreeBSD DarkTower 9.0-RELEASE-p3 FreeBSD 9.0-RELEASE-p3 #0: Tue Jun 12 02:52:29 UTC 2012     root@amd64-builder.daemonology.net:/usr/obj/usr/src/sys/GENERIC  amd64
>Description:
The current version of the wake command (/usr/sbin/wake) sends an improperly formatted WOL packet. It is "improper" due to the fact that it sends to the broadcast address of ff:ff:ff:ff:ff:ff instead of the address(es) specified on the command line. Because of this, the packet never makes it to the target host and thus, does not wake up the "sleeping" target.

I believe, in my case, the packet isn't even leaving the FreeBSD host.
>How-To-Repeat:
Run tcpdump on the target host: (tcpdump -i <IF> -nne not tcp and not udp and not icmp) - or use Wireshark on a Windows host.

Use "wake" to send a WOL packet to the target's MAC address (e.g.: wake xl0 00:11:22:33:44:55)

The packet will not be received on the target.
>Fix:
Send the packet to the target MAC address instead of the broadcast MAC. The patch I have attached makes this change. I have tested it, and it works as expected. 

Additionally, I have modified the ether_type value to use 0x0842 as this is recognized by tools such as Wireshark and is also used by some other WOL utilities. Also, emits a message to the screen when it sends a packet.

Patch attached with submission follows:

--- /usr/src/usr.sbin/wake/wake.c       2012-01-02 22:25:54.000000000 -0500
+++ wake.c      2012-09-18 08:23:32.000000000 -0400
@@ -160,8 +160,18 @@
        ssize_t len;
        int i;

-       (void)memset(pkt.hdr.ether_dhost, 0xff, sizeof(pkt.hdr.ether_dhost));
-       pkt.hdr.ether_type = htons(0);
+        /* Be useful */
+        printf("Sending magic packet to ");
+        for(i = 0; i < ETHER_ADDR_LEN - 1; i++)
+           printf("%.2X:", addr->octet[i]);
+        printf("%.2X\n", addr->octet[ETHER_ADDR_LEN-1]);
+
+       /* The packet MUST be sent to the target MAC address */
+        memcpy(pkt.hdr.ether_dhost, addr, ETHER_ADDR_LEN);
+
+        /* EtherType 0x0842 is at least semi-recognizable for WOL */
+       pkt.hdr.ether_type = htons(0x0842);
+
        (void)memset(pkt.data, 0xff, SYNC_LEN);
        for (p = pkt.data + SYNC_LEN, i = 0; i < DESTADDR_COUNT;
            p += ETHER_ADDR_LEN, i++)


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->hiren 
Responsible-Changed-By: hiren 
Responsible-Changed-When: Mon May 13 22:44:05 UTC 2013 
Responsible-Changed-Why:  
Grab. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=171744 

From: hiren panchasara <hiren@FreeBSD.org>
To: bug-followup@FreeBSD.org, workman.stephen@gmail.com
Cc:  
Subject: Re: bin/171744: [PATCH] Fix wake(8) command not sending proper WOL packet
Date: Mon, 13 May 2013 16:05:35 -0700

 Stephen,
 
 I just tried:
 wake <target_mac>
 wake <local_interface> <target_mac>
 
 and both worked just fine.
 
 Am I missing anything here? Are you experiencing any driver specific issues?
 
 cheers,
 Hiren

From: Stephen Workman <workman.stephen@gmail.com>
To: hiren panchasara <hiren@freebsd.org>
Cc: bug-followup@freebsd.org
Subject: Re: bin/171744: [PATCH] Fix wake(8) command not sending proper WOL packet
Date: Fri, 31 May 2013 07:10:40 -0400

 --047d7bd90c6c54a51904de01aa5a
 Content-Type: text/plain; charset=ISO-8859-1
 
 It's been awhile but, I don't believe it's a driver issue. Probably more of
 a WOL implementation issue since there are various interpretations of how
 it's supposed to work. I know Linux' implementation uses the destination
 MAC rather than broadcasting.
 
 I have a few Windows machines I've tried to wake using the original version
 of FreeBSD's "wake" and neither responds - but they do when their own MAC
 is in the destination field of the ethernet frame.
 
 Perhaps a command line switch to alter the behaviour of wake?
 
 wake -d interface lladdr ...
 
 On Mon, May 13, 2013 at 7:05 PM, hiren panchasara <hiren@freebsd.org> wrote:
 
 > Stephen,
 >
 > I just tried:
 > wake <target_mac>
 > wake <local_interface> <target_mac>
 >
 > and both worked just fine.
 >
 > Am I missing anything here? Are you experiencing any driver specific
 > issues?
 >
 > cheers,
 > Hiren
 >
 
 --047d7bd90c6c54a51904de01aa5a
 Content-Type: text/html; charset=ISO-8859-1
 Content-Transfer-Encoding: quoted-printable
 
 It&#39;s been awhile but, I don&#39;t believe it&#39;s a driver issue. Prob=
 ably more of a WOL implementation issue since there are various interpretat=
 ions of how it&#39;s supposed to work. I know Linux&#39; implementation use=
 s the destination MAC rather than broadcasting.<br>
 <br>I have a few Windows machines I&#39;ve tried to wake using the original=
  version of FreeBSD&#39;s &quot;wake&quot; and neither responds - but they =
 do when their own MAC is in the destination field of the ethernet frame.<br=
 >
 <br>Perhaps a command line switch to alter the behaviour of wake? <br><br>w=
 ake -d interface lladdr ...<br><br><div class=3D"gmail_quote">On Mon, May 1=
 3, 2013 at 7:05 PM, hiren panchasara <span dir=3D"ltr">&lt;<a href=3D"mailt=
 o:hiren@freebsd.org" target=3D"_blank">hiren@freebsd.org</a>&gt;</span> wro=
 te:<br>
 <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
 x #ccc solid;padding-left:1ex">Stephen,<br>
 <br>
 I just tried:<br>
 wake &lt;target_mac&gt;<br>
 wake &lt;local_interface&gt; &lt;target_mac&gt;<br>
 <br>
 and both worked just fine.<br>
 <br>
 Am I missing anything here? Are you experiencing any driver specific issues=
 ?<br>
 <br>
 cheers,<br>
 Hiren<br>
 </blockquote></div><br>
 
 --047d7bd90c6c54a51904de01aa5a--
>Unformatted:
