linux-man.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Michael Kerrisk (man-pages)" <mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: Graham Shaw <gdshaw-1YjpMCWsJptAfugRpC6u6w@public.gmane.org>
Cc: mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org,
	linux-man-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: packet(7) omits sll_protocol from required field list for outbound packets
Date: Wed, 06 May 2015 15:06:02 +0200	[thread overview]
Message-ID: <554A11BA.4060101@gmail.com> (raw)
In-Reply-To: <4FCFCB49.20504-1YjpMCWsJptAfugRpC6u6w@public.gmane.org>

Graham,

On 06/06/2012 11:27 PM, Graham Shaw wrote:
> The manpage packet(7) currently states that:
> 
> "When you send packets it is enough to specify sll_family, sll_addr, 
> sll_halen, sll_ifindex."
> 
> This is incorrect: you also need to specify sll_protocol.
> 
> (The protocol specified when the socket is created is used for filtering 
> inbound packets, but not for constructing outbound packets.)
> 
> I encountered this while researching a page for my website:
> 
> http://www.microhowto.info/howto/send_an_arbitrary_ethernet_frame_using_an_af_packet_socket_in_c.html
> 
> To empirically verify the behaviour I took my test code from the above 
> page then changed it to use different values for the third argument to 
> socket() and the sll_protocol field:
> 
> - socket created with ETH_P_ARP, packet sent with ETH_P_ARP:
>      packet sent with EtherType of ETH_P_ARP
> - socket created with ETH_P_ARP, sll_protocol==0:
>      packet sent with EtherType of 0
> - socket created with 0x88b5, sll_protocol==htons(ETH_P_ARP):
>      packet sent with EtherType of ETH_P_ARP
> - socket created with ETH_P_ARP, sll_protocol==htons(0x88b5):
>      packet sent with EtherType of 0x88b5
> 
> This shows that leaving sll_protocol set to zero does not have the 
> desired effect and that it needs to be set to the desired link-layer 
> protocol.
> 
> There is code in the relevant kernel source file 
> (net/packet/af_packet.c) which appears to inspect the value of the 
> sll_protocol field and use it as the link-layer protocol number, however 
> I am not sufficiently familiar with this subsystem to be fully confident 
> of what is happening. The line in question is:
> 
>      proto   = saddr->sll_protocol;
> 
> In version 3.4 of the kernel this can be found in the functions 
> packet_snd and tpacket_snd. In version 2.6.26 it is in packet_sendmsg.
> 
> Below is a patch that adds sll_protocol to the list of required fields. 
> This may not be the whole truth, since it is not clear what role if any 
> sll_protocol, sll_halen or sll_addr would play when the socket type is 
> SOCK_RAW, however I'm confident it is more accurate than the page as it 
> stands at present:
> 
> diff --git a/man7/packet.7 b/man7/packet.7
> index 374f6da..fb09f15 100644
> --- a/man7/packet.7
> +++ b/man7/packet.7
> @@ -160,7 +160,9 @@ When you send packets it is enough to specify
>   .IR sll_family ,
>   .IR sll_addr ,
>   .IR sll_halen ,
> -.IR sll_ifindex .
> +.IR sll_ifindex
> +and
> +.IR sll_protocol .
>   The other fields should be 0.
>   .I sll_hatype
>   and

Sorry for the very long delay in dealing with this patch.
My light reading of the kernel source suggests your analysis 
is correct, and I've applied the patch.

Thanks,

Michael

-- 
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

      parent reply	other threads:[~2015-05-06 13:06 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-06 21:27 packet(7) omits sll_protocol from required field list for outbound packets Graham Shaw
     [not found] ` <4FCFCB49.20504-1YjpMCWsJptAfugRpC6u6w@public.gmane.org>
2015-05-06 13:06   ` Michael Kerrisk (man-pages) [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=554A11BA.4060101@gmail.com \
    --to=mtk.manpages-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=gdshaw-1YjpMCWsJptAfugRpC6u6w@public.gmane.org \
    --cc=linux-man-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).