Netdev Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] packet.7: Describe SOCK_PACKET netif name length issues and workarounds.
@ 2021-07-27  8:53 Ralf Baechle
  2021-07-28 20:52 ` Alejandro Colomar (man-pages)
  0 siblings, 1 reply; 3+ messages in thread
From: Ralf Baechle @ 2021-07-27  8:53 UTC (permalink / raw)
  To: linux-man, Michael Kerrisk, Alejandro Colomar
  Cc: netdev, linux-hams, Thomas Osterried

Describe the issues with SOCK_PACKET possibly truncating network interface
names in results, solutions and possible workarounds.

While the issue is know for a long time it appears to have never been
documented properly and is has started to bite software antiques badly since
the introduction of Predictable Network Interface Names.  So let's document
it.

Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
---
 man7/packet.7 | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/man7/packet.7 b/man7/packet.7
index 706efbb54..7697bbdeb 100644
--- a/man7/packet.7
+++ b/man7/packet.7
@@ -627,6 +627,34 @@ extension is an ugly hack and should be replaced by a control message.
 There is currently no way to get the original destination address of
 packets via
 .BR SOCK_DGRAM .
+.PP
+The
+.I spkt_device
+field of
+.I sockaddr_pkt
+has a size of 14 bytes which is less than the constant
+.B IFNAMSIZ
+defined in
+.I <net/if.h>
+which is 16 bytes and describes the system limit for a network interface
+name.  This means the names of network devices longer than 14 bytes will be
+truncated to fit into
+.I spkt_device .
+All these lengths include the terminating null byte (\(aq\e0\(aq)).
+.PP
+Issues from this with old code typically show up with very long interface
+names used by the
+.B Predictable Network Interface Names
+feature enabled by default in many modern Linux distributions.
+.PP
+The preferred solution is to rewrite code to avoid
+.BR SOCK_PACKET .
+Possible user solutions are to disable
+.B Predictable Network Interface Names
+or to rename the interface to a name of at most 13 bytes, for example using
+the
+.BR IP (8)
+tool.
 .\" .SH CREDITS
 .\" This man page was written by Andi Kleen with help from Matthew Wilcox.
 .\" AF_PACKET in Linux 2.2 was implemented
@@ -637,7 +665,8 @@ packets via
 .BR capabilities (7),
 .BR ip (7),
 .BR raw (7),
-.BR socket (7)
+.BR socket (7),
+.BR ip (8),
 .PP
 RFC\ 894 for the standard IP Ethernet encapsulation.
 RFC\ 1700 for the IEEE 802.3 IP encapsulation.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] packet.7: Describe SOCK_PACKET netif name length issues and workarounds.
  2021-07-27  8:53 [PATCH] packet.7: Describe SOCK_PACKET netif name length issues and workarounds Ralf Baechle
@ 2021-07-28 20:52 ` Alejandro Colomar (man-pages)
  2021-07-29  6:05   ` Ralf Baechle DL5RB
  0 siblings, 1 reply; 3+ messages in thread
From: Alejandro Colomar (man-pages) @ 2021-07-28 20:52 UTC (permalink / raw)
  To: Ralf Baechle
  Cc: netdev, linux-hams, Thomas Osterried, Michael Kerrisk, linux-man

Hello Ralf,

On 7/27/21 10:53 AM, Ralf Baechle wrote:
> Describe the issues with SOCK_PACKET possibly truncating network interface
> names in results, solutions and possible workarounds.
> 
> While the issue is know for a long time it appears to have never been
> documented properly and is has started to bite software antiques badly since
> the introduction of Predictable Network Interface Names.  So let's document
> it.
> 
> Signed-off-by: Ralf Baechle <ralf@linux-mips.org>

Thanks for the patch!
Please see a few comments below.

Thanks,

Alex

> ---
>   man7/packet.7 | 31 ++++++++++++++++++++++++++++++-
>   1 file changed, 30 insertions(+), 1 deletion(-)
> 
> diff --git a/man7/packet.7 b/man7/packet.7
> index 706efbb54..7697bbdeb 100644
> --- a/man7/packet.7
> +++ b/man7/packet.7
> @@ -627,6 +627,34 @@ extension is an ugly hack and should be replaced by a control message.
>   There is currently no way to get the original destination address of
>   packets via
>   .BR SOCK_DGRAM .

Since the bug spreads across multiple paragraphs, maybe consider adding 
a subsection of BUGS to keep it organized?

> +.PP
> +The
> +.I spkt_device
> +field of
> +.I sockaddr_pkt
> +has a size of 14 bytes which is less than the constant
> +.B IFNAMSIZ
> +defined in
> +.I <net/if.h>
> +which is 16 bytes and describes the system limit for a network interface


See the following extract from man-pages(7):

$ man 7 man-pages | sed -n '/Use semantic newlines/,/^$/p';
    Use semantic newlines
        In the source of a manual page,  new  sentences  should  be
        started  on new lines, and long sentences should split into
        lines at clause breaks (commas, semicolons, colons, and  so
        on).   This  convention,  sometimes known as "semantic new‐
        lines", makes it easier to see the effect of patches, which
        often  operate at the level of individual sentences or sen‐
        tence clauses.


> +name.  This means the names of network devices longer than 14 bytes will be
> +truncated to fit into
> +.I spkt_device .
> +All these lengths include the terminating null byte (\(aq\e0\(aq)).
> +.PP
> +Issues from this with old code typically show up with very long interface
> +names used by the
> +.B Predictable Network Interface Names
> +feature enabled by default in many modern Linux distributions.
> +.PP
> +The preferred solution is to rewrite code to avoid
> +.BR SOCK_PACKET .
> +Possible user solutions are to disable
> +.B Predictable Network Interface Names
> +or to rename the interface to a name of at most 13 bytes, for example using
> +the
> +.BR IP (8)

You probably meant s/IP/ip/

> +tool.
>   .\" .SH CREDITS
>   .\" This man page was written by Andi Kleen with help from Matthew Wilcox.
>   .\" AF_PACKET in Linux 2.2 was implemented
> @@ -637,7 +665,8 @@ packets via
>   .BR capabilities (7),
>   .BR ip (7),
>   .BR raw (7),
> -.BR socket (7)
> +.BR socket (7),
> +.BR ip (8),
>   .PP
>   RFC\ 894 for the standard IP Ethernet encapsulation.
>   RFC\ 1700 for the IEEE 802.3 IP encapsulation.
> 


-- 
Alejandro Colomar
Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] packet.7: Describe SOCK_PACKET netif name length issues and workarounds.
  2021-07-28 20:52 ` Alejandro Colomar (man-pages)
@ 2021-07-29  6:05   ` Ralf Baechle DL5RB
  0 siblings, 0 replies; 3+ messages in thread
From: Ralf Baechle DL5RB @ 2021-07-29  6:05 UTC (permalink / raw)
  To: Alejandro Colomar (man-pages)
  Cc: netdev, linux-hams, Thomas Osterried, Michael Kerrisk, linux-man

On Wed, Jul 28, 2021 at 10:52:15PM +0200, Alejandro Colomar (man-pages) wrote:

> Hello Ralf,
> 
> On 7/27/21 10:53 AM, Ralf Baechle wrote:
> > Describe the issues with SOCK_PACKET possibly truncating network interface
> > names in results, solutions and possible workarounds.
> > 
> > While the issue is know for a long time it appears to have never been
> > documented properly and is has started to bite software antiques badly since
> > the introduction of Predictable Network Interface Names.  So let's document
> > it.
> > 
> > Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
> 
> Thanks for the patch!
> Please see a few comments below.

I'll make an updated version in a week or so.  Until then I'm goning to be
offline on civil defence duty in German's flood disaster region ...

  Ralf

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-07-29  6:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-27  8:53 [PATCH] packet.7: Describe SOCK_PACKET netif name length issues and workarounds Ralf Baechle
2021-07-28 20:52 ` Alejandro Colomar (man-pages)
2021-07-29  6:05   ` Ralf Baechle DL5RB

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).