All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* [BUG] "$ ss -a" incorrectly displays raw sockets as udp sockets
@ 2015-07-09 14:13 Miha Marolt
  2015-07-09 14:50 ` Nikolay Aleksandrov
  2015-07-09 15:14 ` [BUG] "$ ss -a" incorrectly displays raw sockets as udp sockets Eric Dumazet
  0 siblings, 2 replies; 15+ messages in thread
From: Miha Marolt @ 2015-07-09 14:13 UTC (permalink / raw
  To: netdev

Hi!

I hope this is the right place to reports bugs. I apologize if it isn't.

I have written a C program (see below for source code) that opens a raw 
socket on CentOS 7.1 Linux and binds it to some address (it doesn't use 
the port that I supplied, but that is not the point here). The "netstat" 
program correctly recognizes the socket as "raw", while "ss" program 
says it is "udp". Here are the relevant lines from the ss and netstat 
commands:

$ netstat -an
raw        0      0 127.0.0.1:6             0.0.0.0:* 7

$ ./ss -an
udp    UNCONN     21569  0      127.0.0.1:6 *:*

Here is the version information

$ netstat --version  # From CentOS 7.1.
net-tools 2.10-alpha

$ ./ss --version  # Built from git.
ss utility, iproute2-ss150626


C source follows. If you store it in "main.c", then compile it with "$ 
gcc main.c -o main" and then run it by executing "$ sudo ./main".

#include <arpa/inet.h>
#include <assert.h>
#include <sys/socket.h>
#include <stdio.h>
#include <unistd.h>


int main(void)
{
     // Create a raw socket.
     int sock = socket(AF_INET, SOCK_RAW, IPPROTO_TCP);
     if (sock == -1) { perror(NULL); goto exc_cleanup; }

     // Bind socket to an address.
     struct sockaddr_in addr;
     addr.sin_family = AF_INET;
     inet_pton(AF_INET, "127.0.0.1", &addr.sin_addr);
     addr.sin_port = htons(27183);

     int rc = bind(sock, (struct sockaddr*)&addr, sizeof(addr));
     if (rc != 0) { perror(NULL); goto exc_cleanup; }

     // Wait until user presses <ENTER>.
     printf("\nPress <ENTER> to quit the program.\n");
     getchar();

exc_cleanup:
     assert(!close(sock));
}


Best regards,
Miha

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

* Re: [BUG] "$ ss -a" incorrectly displays raw sockets as udp sockets
  2015-07-09 14:13 [BUG] "$ ss -a" incorrectly displays raw sockets as udp sockets Miha Marolt
@ 2015-07-09 14:50 ` Nikolay Aleksandrov
  2015-07-09 14:55   ` Vadim Kochan
  2015-07-09 15:14 ` [BUG] "$ ss -a" incorrectly displays raw sockets as udp sockets Eric Dumazet
  1 sibling, 1 reply; 15+ messages in thread
From: Nikolay Aleksandrov @ 2015-07-09 14:50 UTC (permalink / raw
  To: Miha Marolt, netdev, vadim4j

[-- Attachment #1: Type: text/plain, Size: 2057 bytes --]

On 07/09/2015 04:13 PM, Miha Marolt wrote:
> Hi!
> 
> I hope this is the right place to reports bugs. I apologize if it isn't.
> 
> I have written a C program (see below for source code) that opens a raw socket on CentOS 7.1 Linux and binds it to some address (it doesn't use the port that I supplied, but that is not the point here). The "netstat" program correctly recognizes the socket as "raw", while "ss" program says it is "udp". Here are the relevant lines from the ss and netstat commands:
> 
> $ netstat -an
> raw        0      0 127.0.0.1:6             0.0.0.0:* 7
> 
> $ ./ss -an
> udp    UNCONN     21569  0      127.0.0.1:6 *:*
> 
> Here is the version information
> 
> $ netstat --version  # From CentOS 7.1.
> net-tools 2.10-alpha
> 
> $ ./ss --version  # Built from git.
> ss utility, iproute2-ss150626
> 
> 
> C source follows. If you store it in "main.c", then compile it with "$ gcc main.c -o main" and then run it by executing "$ sudo ./main".
> 
> #include <arpa/inet.h>
> #include <assert.h>
> #include <sys/socket.h>
> #include <stdio.h>
> #include <unistd.h>
> 
> 
> int main(void)
> {
>     // Create a raw socket.
>     int sock = socket(AF_INET, SOCK_RAW, IPPROTO_TCP);
>     if (sock == -1) { perror(NULL); goto exc_cleanup; }
> 
>     // Bind socket to an address.
>     struct sockaddr_in addr;
>     addr.sin_family = AF_INET;
>     inet_pton(AF_INET, "127.0.0.1", &addr.sin_addr);
>     addr.sin_port = htons(27183);
> 
>     int rc = bind(sock, (struct sockaddr*)&addr, sizeof(addr));
>     if (rc != 0) { perror(NULL); goto exc_cleanup; }
> 
>     // Wait until user presses <ENTER>.
>     printf("\nPress <ENTER> to quit the program.\n");
>     getchar();
> 
> exc_cleanup:
>     assert(!close(sock));
> }
> 
> 
> Best regards,
> Miha


Hi,
I think this was changed by commit:
8250bc9ff4e5 ("ss: Unify inet sockets output")
Because dgram_show_line() is used for both UDP and RAW sockets
IPPROTO_UDP is used for both now and proto_name() returns "udp".
CCed the patch author and attached a possible solution.

Cheers,
 Nik

[-- Attachment #2: ss-raw.patch --]
[-- Type: text/x-patch, Size: 594 bytes --]

diff --git a/misc/ss.c b/misc/ss.c
index 870cad185341..4de77e92c319 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -1554,6 +1554,8 @@ out:
 static char *proto_name(int protocol)
 {
 	switch (protocol) {
+	case IPPROTO_RAW:
+		return "raw";
 	case IPPROTO_UDP:
 		return "udp";
 	case IPPROTO_TCP:
@@ -2398,7 +2400,7 @@ static int dgram_show_line(char *line, const struct filter *f, int family)
 	if (n < 9)
 		opt[0] = 0;
 
-	inet_stats_print(&s, IPPROTO_UDP);
+	inet_stats_print(&s, dg_proto == UDP_PROTO ? IPPROTO_UDP : IPPROTO_RAW);
 
 	if (show_details && opt[0])
 		printf(" opt:\"%s\"", opt);

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

* Re: [BUG] "$ ss -a" incorrectly displays raw sockets as udp sockets
  2015-07-09 14:50 ` Nikolay Aleksandrov
@ 2015-07-09 14:55   ` Vadim Kochan
  2015-07-09 14:57     ` Nikolay Aleksandrov
  0 siblings, 1 reply; 15+ messages in thread
From: Vadim Kochan @ 2015-07-09 14:55 UTC (permalink / raw
  To: Nikolay Aleksandrov; +Cc: Miha Marolt, netdev, vadim4j

On Thu, Jul 09, 2015 at 04:50:06PM +0200, Nikolay Aleksandrov wrote:
> On 07/09/2015 04:13 PM, Miha Marolt wrote:
> > Hi!
> > 
> > I hope this is the right place to reports bugs. I apologize if it isn't.
> > 
> > I have written a C program (see below for source code) that opens a raw socket on CentOS 7.1 Linux and binds it to some address (it doesn't use the port that I supplied, but that is not the point here). The "netstat" program correctly recognizes the socket as "raw", while "ss" program says it is "udp". Here are the relevant lines from the ss and netstat commands:
> > 
> > $ netstat -an
> > raw        0      0 127.0.0.1:6             0.0.0.0:* 7
> > 
> > $ ./ss -an
> > udp    UNCONN     21569  0      127.0.0.1:6 *:*
> > 
> > Here is the version information
> > 
> > $ netstat --version  # From CentOS 7.1.
> > net-tools 2.10-alpha
> > 
> > $ ./ss --version  # Built from git.
> > ss utility, iproute2-ss150626
> > 
> > 
> > C source follows. If you store it in "main.c", then compile it with "$ gcc main.c -o main" and then run it by executing "$ sudo ./main".
> > 
> > #include <arpa/inet.h>
> > #include <assert.h>
> > #include <sys/socket.h>
> > #include <stdio.h>
> > #include <unistd.h>
> > 
> > 
> > int main(void)
> > {
> >     // Create a raw socket.
> >     int sock = socket(AF_INET, SOCK_RAW, IPPROTO_TCP);
> >     if (sock == -1) { perror(NULL); goto exc_cleanup; }
> > 
> >     // Bind socket to an address.
> >     struct sockaddr_in addr;
> >     addr.sin_family = AF_INET;
> >     inet_pton(AF_INET, "127.0.0.1", &addr.sin_addr);
> >     addr.sin_port = htons(27183);
> > 
> >     int rc = bind(sock, (struct sockaddr*)&addr, sizeof(addr));
> >     if (rc != 0) { perror(NULL); goto exc_cleanup; }
> > 
> >     // Wait until user presses <ENTER>.
> >     printf("\nPress <ENTER> to quit the program.\n");
> >     getchar();
> > 
> > exc_cleanup:
> >     assert(!close(sock));
> > }
> > 
> > 
> > Best regards,
> > Miha
> 
> 
> Hi,
> I think this was changed by commit:
> 8250bc9ff4e5 ("ss: Unify inet sockets output")
> Because dgram_show_line() is used for both UDP and RAW sockets
> IPPROTO_UDP is used for both now and proto_name() returns "udp".
> CCed the patch author and attached a possible solution.
> 
> Cheers,
>  Nik

> diff --git a/misc/ss.c b/misc/ss.c
> index 870cad185341..4de77e92c319 100644
> --- a/misc/ss.c
> +++ b/misc/ss.c
> @@ -1554,6 +1554,8 @@ out:
>  static char *proto_name(int protocol)
>  {
>  	switch (protocol) {
> +	case IPPROTO_RAW:
> +		return "raw";
>  	case IPPROTO_UDP:
>  		return "udp";
>  	case IPPROTO_TCP:
> @@ -2398,7 +2400,7 @@ static int dgram_show_line(char *line, const struct filter *f, int family)
>  	if (n < 9)
>  		opt[0] = 0;
>  
> -	inet_stats_print(&s, IPPROTO_UDP);
> +	inet_stats_print(&s, dg_proto == UDP_PROTO ? IPPROTO_UDP : IPPROTO_RAW);
>  
>  	if (show_details && opt[0])
>  		printf(" opt:\"%s\"", opt);

Yeah, it fixed the issue, just tested the fix.

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

* Re: [BUG] "$ ss -a" incorrectly displays raw sockets as udp sockets
  2015-07-09 14:55   ` Vadim Kochan
@ 2015-07-09 14:57     ` Nikolay Aleksandrov
  2015-07-09 15:09       ` Miha Marolt
  0 siblings, 1 reply; 15+ messages in thread
From: Nikolay Aleksandrov @ 2015-07-09 14:57 UTC (permalink / raw
  To: Vadim Kochan; +Cc: Miha Marolt, netdev

On 07/09/2015 04:55 PM, Vadim Kochan wrote:
> On Thu, Jul 09, 2015 at 04:50:06PM +0200, Nikolay Aleksandrov wrote:
>> On 07/09/2015 04:13 PM, Miha Marolt wrote:
>>> Hi!
>>>
>>> I hope this is the right place to reports bugs. I apologize if it isn't.
>>>
>>> I have written a C program (see below for source code) that opens a raw socket on CentOS 7.1 Linux and binds it to some address (it doesn't use the port that I supplied, but that is not the point here). The "netstat" program correctly recognizes the socket as "raw", while "ss" program says it is "udp". Here are the relevant lines from the ss and netstat commands:
>>>
>>> $ netstat -an
>>> raw        0      0 127.0.0.1:6             0.0.0.0:* 7
>>>
>>> $ ./ss -an
>>> udp    UNCONN     21569  0      127.0.0.1:6 *:*
>>>
>>> Here is the version information
>>>
>>> $ netstat --version  # From CentOS 7.1.
>>> net-tools 2.10-alpha
>>>
>>> $ ./ss --version  # Built from git.
>>> ss utility, iproute2-ss150626
>>>
>>>
>>> C source follows. If you store it in "main.c", then compile it with "$ gcc main.c -o main" and then run it by executing "$ sudo ./main".
>>>
>>> #include <arpa/inet.h>
>>> #include <assert.h>
>>> #include <sys/socket.h>
>>> #include <stdio.h>
>>> #include <unistd.h>
>>>
>>>
>>> int main(void)
>>> {
>>>     // Create a raw socket.
>>>     int sock = socket(AF_INET, SOCK_RAW, IPPROTO_TCP);
>>>     if (sock == -1) { perror(NULL); goto exc_cleanup; }
>>>
>>>     // Bind socket to an address.
>>>     struct sockaddr_in addr;
>>>     addr.sin_family = AF_INET;
>>>     inet_pton(AF_INET, "127.0.0.1", &addr.sin_addr);
>>>     addr.sin_port = htons(27183);
>>>
>>>     int rc = bind(sock, (struct sockaddr*)&addr, sizeof(addr));
>>>     if (rc != 0) { perror(NULL); goto exc_cleanup; }
>>>
>>>     // Wait until user presses <ENTER>.
>>>     printf("\nPress <ENTER> to quit the program.\n");
>>>     getchar();
>>>
>>> exc_cleanup:
>>>     assert(!close(sock));
>>> }
>>>
>>>
>>> Best regards,
>>> Miha
>>
>>
>> Hi,
>> I think this was changed by commit:
>> 8250bc9ff4e5 ("ss: Unify inet sockets output")
>> Because dgram_show_line() is used for both UDP and RAW sockets
>> IPPROTO_UDP is used for both now and proto_name() returns "udp".
>> CCed the patch author and attached a possible solution.
>>
>> Cheers,
>>  Nik
> 
>> diff --git a/misc/ss.c b/misc/ss.c
>> index 870cad185341..4de77e92c319 100644
>> --- a/misc/ss.c
>> +++ b/misc/ss.c
>> @@ -1554,6 +1554,8 @@ out:
>>  static char *proto_name(int protocol)
>>  {
>>  	switch (protocol) {
>> +	case IPPROTO_RAW:
>> +		return "raw";
>>  	case IPPROTO_UDP:
>>  		return "udp";
>>  	case IPPROTO_TCP:
>> @@ -2398,7 +2400,7 @@ static int dgram_show_line(char *line, const struct filter *f, int family)
>>  	if (n < 9)
>>  		opt[0] = 0;
>>  
>> -	inet_stats_print(&s, IPPROTO_UDP);
>> +	inet_stats_print(&s, dg_proto == UDP_PROTO ? IPPROTO_UDP : IPPROTO_RAW);
>>  
>>  	if (show_details && opt[0])
>>  		printf(" opt:\"%s\"", opt);
> 
> Yeah, it fixed the issue, just tested the fix.
> 

Great, I'll submit it in a minute.
Thanks for testing!

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

* Re: [BUG] "$ ss -a" incorrectly displays raw sockets as udp sockets
  2015-07-09 14:57     ` Nikolay Aleksandrov
@ 2015-07-09 15:09       ` Miha Marolt
  2015-07-09 15:15         ` Vadim Kochan
  0 siblings, 1 reply; 15+ messages in thread
From: Miha Marolt @ 2015-07-09 15:09 UTC (permalink / raw
  To: Nikolay Aleksandrov, Vadim Kochan; +Cc: netdev



On 07/09/2015 04:57 PM, Nikolay Aleksandrov wrote:
> On 07/09/2015 04:55 PM, Vadim Kochan wrote:
>> On Thu, Jul 09, 2015 at 04:50:06PM +0200, Nikolay Aleksandrov wrote:
>>> On 07/09/2015 04:13 PM, Miha Marolt wrote:
>>>> Hi!
>>>>
>>>> I hope this is the right place to reports bugs. I apologize if it isn't.
>>>>
>>>> I have written a C program (see below for source code) that opens a raw socket on CentOS 7.1 Linux and binds it to some address (it doesn't use the port that I supplied, but that is not the point here). The "netstat" program correctly recognizes the socket as "raw", while "ss" program says it is "udp". Here are the relevant lines from the ss and netstat commands:
>>>>
>>>> $ netstat -an
>>>> raw        0      0 127.0.0.1:6             0.0.0.0:* 7
>>>>
>>>> $ ./ss -an
>>>> udp    UNCONN     21569  0      127.0.0.1:6 *:*
>>>>
>>>> Here is the version information
>>>>
>>>> $ netstat --version  # From CentOS 7.1.
>>>> net-tools 2.10-alpha
>>>>
>>>> $ ./ss --version  # Built from git.
>>>> ss utility, iproute2-ss150626
>>>>
>>>>
>>>> C source follows. If you store it in "main.c", then compile it with "$ gcc main.c -o main" and then run it by executing "$ sudo ./main".
>>>>
>>>> #include <arpa/inet.h>
>>>> #include <assert.h>
>>>> #include <sys/socket.h>
>>>> #include <stdio.h>
>>>> #include <unistd.h>
>>>>
>>>>
>>>> int main(void)
>>>> {
>>>>      // Create a raw socket.
>>>>      int sock = socket(AF_INET, SOCK_RAW, IPPROTO_TCP);
>>>>      if (sock == -1) { perror(NULL); goto exc_cleanup; }
>>>>
>>>>      // Bind socket to an address.
>>>>      struct sockaddr_in addr;
>>>>      addr.sin_family = AF_INET;
>>>>      inet_pton(AF_INET, "127.0.0.1", &addr.sin_addr);
>>>>      addr.sin_port = htons(27183);
>>>>
>>>>      int rc = bind(sock, (struct sockaddr*)&addr, sizeof(addr));
>>>>      if (rc != 0) { perror(NULL); goto exc_cleanup; }
>>>>
>>>>      // Wait until user presses <ENTER>.
>>>>      printf("\nPress <ENTER> to quit the program.\n");
>>>>      getchar();
>>>>
>>>> exc_cleanup:
>>>>      assert(!close(sock));
>>>> }
>>>>
>>>>
>>>> Best regards,
>>>> Miha
>>>
>>> Hi,
>>> I think this was changed by commit:
>>> 8250bc9ff4e5 ("ss: Unify inet sockets output")
>>> Because dgram_show_line() is used for both UDP and RAW sockets
>>> IPPROTO_UDP is used for both now and proto_name() returns "udp".
>>> CCed the patch author and attached a possible solution.
>>>
>>> Cheers,
>>>   Nik
>>> diff --git a/misc/ss.c b/misc/ss.c
>>> index 870cad185341..4de77e92c319 100644
>>> --- a/misc/ss.c
>>> +++ b/misc/ss.c
>>> @@ -1554,6 +1554,8 @@ out:
>>>   static char *proto_name(int protocol)
>>>   {
>>>   	switch (protocol) {
>>> +	case IPPROTO_RAW:
>>> +		return "raw";
>>>   	case IPPROTO_UDP:
>>>   		return "udp";
>>>   	case IPPROTO_TCP:
>>> @@ -2398,7 +2400,7 @@ static int dgram_show_line(char *line, const struct filter *f, int family)
>>>   	if (n < 9)
>>>   		opt[0] = 0;
>>>   
>>> -	inet_stats_print(&s, IPPROTO_UDP);
>>> +	inet_stats_print(&s, dg_proto == UDP_PROTO ? IPPROTO_UDP : IPPROTO_RAW);
>>>   
>>>   	if (show_details && opt[0])
>>>   		printf(" opt:\"%s\"", opt);
>> Yeah, it fixed the issue, just tested the fix.
>>
> Great, I'll submit it in a minute.
> Thanks for testing!

Thank you very much for the fast fix!

I've found another bug: command "$ ss" doesn't display only tcp sockets 
as the man page ss(8) says (file man/man8/ss.8 in iproute2 git repo). It 
also displays e.g. unix sockets. The man page says "When no option is 
used ss displays a list of open non-listening TCP sockets that have 
established connection.".


Regards,
Miha

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

* Re: [BUG] "$ ss -a" incorrectly displays raw sockets as udp sockets
  2015-07-09 14:13 [BUG] "$ ss -a" incorrectly displays raw sockets as udp sockets Miha Marolt
  2015-07-09 14:50 ` Nikolay Aleksandrov
@ 2015-07-09 15:14 ` Eric Dumazet
  2015-07-09 15:21   ` Eric Dumazet
  1 sibling, 1 reply; 15+ messages in thread
From: Eric Dumazet @ 2015-07-09 15:14 UTC (permalink / raw
  To: Miha Marolt; +Cc: netdev, Vadim Kochan

On Thu, 2015-07-09 at 16:13 +0200, Miha Marolt wrote:
> Hi!
> 
> I hope this is the right place to reports bugs. I apologize if it isn't.
> 
> I have written a C program (see below for source code) that opens a raw 
> socket on CentOS 7.1 Linux and binds it to some address (it doesn't use 
> the port that I supplied, but that is not the point here). The "netstat" 
> program correctly recognizes the socket as "raw", while "ss" program 
> says it is "udp". Here are the relevant lines from the ss and netstat 
> commands:
> 
> $ netstat -an
> raw        0      0 127.0.0.1:6             0.0.0.0:* 7
> 
> $ ./ss -an
> udp    UNCONN     21569  0      127.0.0.1:6 *:*
> 
> Here is the version information
> 
> $ netstat --version  # From CentOS 7.1.
> net-tools 2.10-alpha
> 
> $ ./ss --version  # Built from git.
> ss utility, iproute2-ss150626
> 
> 
> C source follows. If you store it in "main.c", then compile it with "$ 
> gcc main.c -o main" and then run it by executing "$ sudo ./main".
> 
> #include <arpa/inet.h>
> #include <assert.h>
> #include <sys/socket.h>
> #include <stdio.h>
> #include <unistd.h>
> 
> 
> int main(void)
> {
>      // Create a raw socket.
>      int sock = socket(AF_INET, SOCK_RAW, IPPROTO_TCP);
>      if (sock == -1) { perror(NULL); goto exc_cleanup; }
> 
>      // Bind socket to an address.
>      struct sockaddr_in addr;
>      addr.sin_family = AF_INET;
>      inet_pton(AF_INET, "127.0.0.1", &addr.sin_addr);
>      addr.sin_port = htons(27183);
> 
>      int rc = bind(sock, (struct sockaddr*)&addr, sizeof(addr));
>      if (rc != 0) { perror(NULL); goto exc_cleanup; }
> 
>      // Wait until user presses <ENTER>.
>      printf("\nPress <ENTER> to quit the program.\n");
>      getchar();
> 
> exc_cleanup:
>      assert(!close(sock));
> }

It is indeed a raw socket on proto TCP.

Note sure if commit 8250bc9ff4e55a3ef397ed8c7612f1392d164295
was really good...


diff --git a/misc/ss.c b/misc/ss.c
index 03f92fa69270..dc61aaa79bca 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -2416,7 +2416,7 @@ static int dgram_show_line(char *line, const
struct filter *f, int family)
        if (n < 9)
                opt[0] = 0;
 
-       inet_stats_print(&s, IPPROTO_UDP);
+       inet_stats_print(&s, atoi(line));
 
        if (show_details && opt[0])
                printf(" opt:\"%s\"", opt);

-> 
# ./ss -an | grep 127.0.0.1
tcp    UNCONN     213486 0      127.0.0.1:6                     *:*                  



If I checkout iproute2 tree to db08bdb816d337102c5486744008db9c9faa43bf
(before buggy commit) we indeed had this result :

# ./ss -an | grep 127.0.0.1
raw    UNCONN     213486 0      127.0.0.1:6                     *:*                  

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

* Re: [BUG] "$ ss -a" incorrectly displays raw sockets as udp sockets
  2015-07-09 15:09       ` Miha Marolt
@ 2015-07-09 15:15         ` Vadim Kochan
  2015-07-10  7:09           ` Miha Marolt
  0 siblings, 1 reply; 15+ messages in thread
From: Vadim Kochan @ 2015-07-09 15:15 UTC (permalink / raw
  To: Miha Marolt; +Cc: Nikolay Aleksandrov, Vadim Kochan, netdev

On Thu, Jul 09, 2015 at 05:09:27PM +0200, Miha Marolt wrote:
> 
> 
> On 07/09/2015 04:57 PM, Nikolay Aleksandrov wrote:
> >On 07/09/2015 04:55 PM, Vadim Kochan wrote:
> >>On Thu, Jul 09, 2015 at 04:50:06PM +0200, Nikolay Aleksandrov wrote:
> >>>On 07/09/2015 04:13 PM, Miha Marolt wrote:
> >>>>Hi!
> >>>>
> >>>>I hope this is the right place to reports bugs. I apologize if it isn't.
> >>>>
> >>>>I have written a C program (see below for source code) that opens a raw socket on CentOS 7.1 Linux and binds it to some address (it doesn't use the port that I supplied, but that is not the point here). The "netstat" program correctly recognizes the socket as "raw", while "ss" program says it is "udp". Here are the relevant lines from the ss and netstat commands:
> >>>>
> >>>>$ netstat -an
> >>>>raw        0      0 127.0.0.1:6             0.0.0.0:* 7
> >>>>
> >>>>$ ./ss -an
> >>>>udp    UNCONN     21569  0      127.0.0.1:6 *:*
> >>>>
> >>>>Here is the version information
> >>>>
> >>>>$ netstat --version  # From CentOS 7.1.
> >>>>net-tools 2.10-alpha
> >>>>
> >>>>$ ./ss --version  # Built from git.
> >>>>ss utility, iproute2-ss150626
> >>>>
> >>>>
> >>>>C source follows. If you store it in "main.c", then compile it with "$ gcc main.c -o main" and then run it by executing "$ sudo ./main".
> >>>>
> >>>>#include <arpa/inet.h>
> >>>>#include <assert.h>
> >>>>#include <sys/socket.h>
> >>>>#include <stdio.h>
> >>>>#include <unistd.h>
> >>>>
> >>>>
> >>>>int main(void)
> >>>>{
> >>>>     // Create a raw socket.
> >>>>     int sock = socket(AF_INET, SOCK_RAW, IPPROTO_TCP);
> >>>>     if (sock == -1) { perror(NULL); goto exc_cleanup; }
> >>>>
> >>>>     // Bind socket to an address.
> >>>>     struct sockaddr_in addr;
> >>>>     addr.sin_family = AF_INET;
> >>>>     inet_pton(AF_INET, "127.0.0.1", &addr.sin_addr);
> >>>>     addr.sin_port = htons(27183);
> >>>>
> >>>>     int rc = bind(sock, (struct sockaddr*)&addr, sizeof(addr));
> >>>>     if (rc != 0) { perror(NULL); goto exc_cleanup; }
> >>>>
> >>>>     // Wait until user presses <ENTER>.
> >>>>     printf("\nPress <ENTER> to quit the program.\n");
> >>>>     getchar();
> >>>>
> >>>>exc_cleanup:
> >>>>     assert(!close(sock));
> >>>>}
> >>>>
> >>>>
> >>>>Best regards,
> >>>>Miha
> >>>
> >>>Hi,
> >>>I think this was changed by commit:
> >>>8250bc9ff4e5 ("ss: Unify inet sockets output")
> >>>Because dgram_show_line() is used for both UDP and RAW sockets
> >>>IPPROTO_UDP is used for both now and proto_name() returns "udp".
> >>>CCed the patch author and attached a possible solution.
> >>>
> >>>Cheers,
> >>>  Nik
> >>>diff --git a/misc/ss.c b/misc/ss.c
> >>>index 870cad185341..4de77e92c319 100644
> >>>--- a/misc/ss.c
> >>>+++ b/misc/ss.c
> >>>@@ -1554,6 +1554,8 @@ out:
> >>>  static char *proto_name(int protocol)
> >>>  {
> >>>  	switch (protocol) {
> >>>+	case IPPROTO_RAW:
> >>>+		return "raw";
> >>>  	case IPPROTO_UDP:
> >>>  		return "udp";
> >>>  	case IPPROTO_TCP:
> >>>@@ -2398,7 +2400,7 @@ static int dgram_show_line(char *line, const struct filter *f, int family)
> >>>  	if (n < 9)
> >>>  		opt[0] = 0;
> >>>-	inet_stats_print(&s, IPPROTO_UDP);
> >>>+	inet_stats_print(&s, dg_proto == UDP_PROTO ? IPPROTO_UDP : IPPROTO_RAW);
> >>>  	if (show_details && opt[0])
> >>>  		printf(" opt:\"%s\"", opt);
> >>Yeah, it fixed the issue, just tested the fix.
> >>
> >Great, I'll submit it in a minute.
> >Thanks for testing!
> 
> Thank you very much for the fast fix!
> 
> I've found another bug: command "$ ss" doesn't display only tcp sockets as
> the man page ss(8) says (file man/man8/ss.8 in iproute2 git repo). It also
> displays e.g. unix sockets. The man page says "When no option is used ss
> displays a list of open non-listening TCP sockets that have established
> connection.".
> 
> 
> Regards,
> Miha

That seems OK, I see that unix stream sockets are displayed which are
connection oriented, and UDP can also have established state.

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

* Re: [BUG] "$ ss -a" incorrectly displays raw sockets as udp sockets
  2015-07-09 15:14 ` [BUG] "$ ss -a" incorrectly displays raw sockets as udp sockets Eric Dumazet
@ 2015-07-09 15:21   ` Eric Dumazet
  2015-07-09 15:28     ` Vadim Kochan
  0 siblings, 1 reply; 15+ messages in thread
From: Eric Dumazet @ 2015-07-09 15:21 UTC (permalink / raw
  To: Miha Marolt; +Cc: netdev, Vadim Kochan

On Thu, 2015-07-09 at 17:14 +0200, Eric Dumazet wrote:

> 
> If I checkout iproute2 tree to db08bdb816d337102c5486744008db9c9faa43bf
> (before buggy commit) we indeed had this result :
> 
> # ./ss -an | grep 127.0.0.1
> raw    UNCONN     213486 0      127.0.0.1:6                     *:*                  

Maybe following patch would fix the issue.

diff --git a/misc/ss.c b/misc/ss.c
index 03f92fa69270..9b7dad00290c 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -1552,6 +1552,8 @@ out:
 static char *proto_name(int protocol)
 {
 	switch (protocol) {
+	case 0:
+		return "raw";
 	case IPPROTO_UDP:
 		return "udp";
 	case IPPROTO_TCP:
@@ -2416,7 +2418,7 @@ static int dgram_show_line(char *line, const struct filter *f, int family)
 	if (n < 9)
 		opt[0] = 0;
 
-	inet_stats_print(&s, IPPROTO_UDP);
+	inet_stats_print(&s, 0);
 
 	if (show_details && opt[0])
 		printf(" opt:\"%s\"", opt);

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

* Re: [BUG] "$ ss -a" incorrectly displays raw sockets as udp sockets
  2015-07-09 15:21   ` Eric Dumazet
@ 2015-07-09 15:28     ` Vadim Kochan
  2015-07-09 15:30       ` Nikolay Aleksandrov
  0 siblings, 1 reply; 15+ messages in thread
From: Vadim Kochan @ 2015-07-09 15:28 UTC (permalink / raw
  To: Eric Dumazet; +Cc: Miha Marolt, netdev, Vadim Kochan

On Thu, Jul 09, 2015 at 05:21:10PM +0200, Eric Dumazet wrote:
> On Thu, 2015-07-09 at 17:14 +0200, Eric Dumazet wrote:
> 
> > 
> > If I checkout iproute2 tree to db08bdb816d337102c5486744008db9c9faa43bf
> > (before buggy commit) we indeed had this result :
> > 
> > # ./ss -an | grep 127.0.0.1
> > raw    UNCONN     213486 0      127.0.0.1:6                     *:*                  
> 
> Maybe following patch would fix the issue.
> 
> diff --git a/misc/ss.c b/misc/ss.c
> index 03f92fa69270..9b7dad00290c 100644
> --- a/misc/ss.c
> +++ b/misc/ss.c
> @@ -1552,6 +1552,8 @@ out:
>  static char *proto_name(int protocol)
>  {
>  	switch (protocol) {
> +	case 0:
> +		return "raw";
>  	case IPPROTO_UDP:
>  		return "udp";
>  	case IPPROTO_TCP:
> @@ -2416,7 +2418,7 @@ static int dgram_show_line(char *line, const struct filter *f, int family)
>  	if (n < 9)
>  		opt[0] = 0;
>  
> -	inet_stats_print(&s, IPPROTO_UDP);
> +	inet_stats_print(&s, 0);
>  
>  	if (show_details && opt[0])
>  		printf(" opt:\"%s\"", opt);
> 
> 

Yes, it fixes the issue too.

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

* Re: [BUG] "$ ss -a" incorrectly displays raw sockets as udp sockets
  2015-07-09 15:28     ` Vadim Kochan
@ 2015-07-09 15:30       ` Nikolay Aleksandrov
  0 siblings, 0 replies; 15+ messages in thread
From: Nikolay Aleksandrov @ 2015-07-09 15:30 UTC (permalink / raw
  To: Vadim Kochan, Eric Dumazet; +Cc: Miha Marolt, netdev

On 07/09/2015 05:28 PM, Vadim Kochan wrote:
> On Thu, Jul 09, 2015 at 05:21:10PM +0200, Eric Dumazet wrote:
>> On Thu, 2015-07-09 at 17:14 +0200, Eric Dumazet wrote:
>>
>>>
>>> If I checkout iproute2 tree to db08bdb816d337102c5486744008db9c9faa43bf
>>> (before buggy commit) we indeed had this result :
>>>
>>> # ./ss -an | grep 127.0.0.1
>>> raw    UNCONN     213486 0      127.0.0.1:6                     *:*                  
>>
>> Maybe following patch would fix the issue.
>>
>> diff --git a/misc/ss.c b/misc/ss.c
>> index 03f92fa69270..9b7dad00290c 100644
>> --- a/misc/ss.c
>> +++ b/misc/ss.c
>> @@ -1552,6 +1552,8 @@ out:
>>  static char *proto_name(int protocol)
>>  {
>>  	switch (protocol) {
>> +	case 0:
>> +		return "raw";
>>  	case IPPROTO_UDP:
>>  		return "udp";
>>  	case IPPROTO_TCP:
>> @@ -2416,7 +2418,7 @@ static int dgram_show_line(char *line, const struct filter *f, int family)
>>  	if (n < 9)
>>  		opt[0] = 0;
>>  
>> -	inet_stats_print(&s, IPPROTO_UDP);
>> +	inet_stats_print(&s, 0);
>>  
>>  	if (show_details && opt[0])
>>  		printf(" opt:\"%s\"", opt);
>>
>>
> 
> Yes, it fixes the issue too.

Yeah, I think this is better than my solution because it's not really
IPPROTO_RAW protocol, so I'll drop my submission.

Thanks,
 Nik

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

* Re: [BUG] "$ ss -a" incorrectly displays raw sockets as udp sockets
  2015-07-09 15:15         ` Vadim Kochan
@ 2015-07-10  7:09           ` Miha Marolt
  2015-07-10  7:16             ` Vadim Kochan
  0 siblings, 1 reply; 15+ messages in thread
From: Miha Marolt @ 2015-07-10  7:09 UTC (permalink / raw
  To: Vadim Kochan; +Cc: Nikolay Aleksandrov, netdev



On 07/09/2015 05:15 PM, Vadim Kochan wrote:
> On Thu, Jul 09, 2015 at 05:09:27PM +0200, Miha Marolt wrote:
>>
>> On 07/09/2015 04:57 PM, Nikolay Aleksandrov wrote:
>>> On 07/09/2015 04:55 PM, Vadim Kochan wrote:
>>>> On Thu, Jul 09, 2015 at 04:50:06PM +0200, Nikolay Aleksandrov wrote:
>>>>> On 07/09/2015 04:13 PM, Miha Marolt wrote:
>>>>>> Hi!
>>>>>>
>>>>>> I hope this is the right place to reports bugs. I apologize if it isn't.
>>>>>>
>>>>>> I have written a C program (see below for source code) that opens a raw socket on CentOS 7.1 Linux and binds it to some address (it doesn't use the port that I supplied, but that is not the point here). The "netstat" program correctly recognizes the socket as "raw", while "ss" program says it is "udp". Here are the relevant lines from the ss and netstat commands:
>>>>>>
>>>>>> $ netstat -an
>>>>>> raw        0      0 127.0.0.1:6             0.0.0.0:* 7
>>>>>>
>>>>>> $ ./ss -an
>>>>>> udp    UNCONN     21569  0      127.0.0.1:6 *:*
>>>>>>
>>>>>> Here is the version information
>>>>>>
>>>>>> $ netstat --version  # From CentOS 7.1.
>>>>>> net-tools 2.10-alpha
>>>>>>
>>>>>> $ ./ss --version  # Built from git.
>>>>>> ss utility, iproute2-ss150626
>>>>>>
>>>>>>
>>>>>> C source follows. If you store it in "main.c", then compile it with "$ gcc main.c -o main" and then run it by executing "$ sudo ./main".
>>>>>>
>>>>>> #include <arpa/inet.h>
>>>>>> #include <assert.h>
>>>>>> #include <sys/socket.h>
>>>>>> #include <stdio.h>
>>>>>> #include <unistd.h>
>>>>>>
>>>>>>
>>>>>> int main(void)
>>>>>> {
>>>>>>      // Create a raw socket.
>>>>>>      int sock = socket(AF_INET, SOCK_RAW, IPPROTO_TCP);
>>>>>>      if (sock == -1) { perror(NULL); goto exc_cleanup; }
>>>>>>
>>>>>>      // Bind socket to an address.
>>>>>>      struct sockaddr_in addr;
>>>>>>      addr.sin_family = AF_INET;
>>>>>>      inet_pton(AF_INET, "127.0.0.1", &addr.sin_addr);
>>>>>>      addr.sin_port = htons(27183);
>>>>>>
>>>>>>      int rc = bind(sock, (struct sockaddr*)&addr, sizeof(addr));
>>>>>>      if (rc != 0) { perror(NULL); goto exc_cleanup; }
>>>>>>
>>>>>>      // Wait until user presses <ENTER>.
>>>>>>      printf("\nPress <ENTER> to quit the program.\n");
>>>>>>      getchar();
>>>>>>
>>>>>> exc_cleanup:
>>>>>>      assert(!close(sock));
>>>>>> }
>>>>>>
>>>>>>
>>>>>> Best regards,
>>>>>> Miha
>>>>> Hi,
>>>>> I think this was changed by commit:
>>>>> 8250bc9ff4e5 ("ss: Unify inet sockets output")
>>>>> Because dgram_show_line() is used for both UDP and RAW sockets
>>>>> IPPROTO_UDP is used for both now and proto_name() returns "udp".
>>>>> CCed the patch author and attached a possible solution.
>>>>>
>>>>> Cheers,
>>>>>   Nik
>>>>> diff --git a/misc/ss.c b/misc/ss.c
>>>>> index 870cad185341..4de77e92c319 100644
>>>>> --- a/misc/ss.c
>>>>> +++ b/misc/ss.c
>>>>> @@ -1554,6 +1554,8 @@ out:
>>>>>   static char *proto_name(int protocol)
>>>>>   {
>>>>>   	switch (protocol) {
>>>>> +	case IPPROTO_RAW:
>>>>> +		return "raw";
>>>>>   	case IPPROTO_UDP:
>>>>>   		return "udp";
>>>>>   	case IPPROTO_TCP:
>>>>> @@ -2398,7 +2400,7 @@ static int dgram_show_line(char *line, const struct filter *f, int family)
>>>>>   	if (n < 9)
>>>>>   		opt[0] = 0;
>>>>> -	inet_stats_print(&s, IPPROTO_UDP);
>>>>> +	inet_stats_print(&s, dg_proto == UDP_PROTO ? IPPROTO_UDP : IPPROTO_RAW);
>>>>>   	if (show_details && opt[0])
>>>>>   		printf(" opt:\"%s\"", opt);
>>>> Yeah, it fixed the issue, just tested the fix.
>>>>
>>> Great, I'll submit it in a minute.
>>> Thanks for testing!
>> Thank you very much for the fast fix!
>>
>> I've found another bug: command "$ ss" doesn't display only tcp sockets as
>> the man page ss(8) says (file man/man8/ss.8 in iproute2 git repo). It also
>> displays e.g. unix sockets. The man page says "When no option is used ss
>> displays a list of open non-listening TCP sockets that have established
>> connection.".
>>
>>
>> Regards,
>> Miha
> That seems OK, I see that unix stream sockets are displayed which are
> connection oriented, and UDP can also have established state.

According to the man page, **only** TCP sockets should be listed by "$ 
ss". In reality, also Unix and UDP sockets are listed, so there is a 
discrepancy between what man page says and what actually happens.

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

* Re: [BUG] "$ ss -a" incorrectly displays raw sockets as udp sockets
  2015-07-10  7:09           ` Miha Marolt
@ 2015-07-10  7:16             ` Vadim Kochan
  2015-07-15 12:10               ` Miha Marolt
  0 siblings, 1 reply; 15+ messages in thread
From: Vadim Kochan @ 2015-07-10  7:16 UTC (permalink / raw
  To: Miha Marolt; +Cc: Vadim Kochan, Nikolay Aleksandrov, netdev

On Fri, Jul 10, 2015 at 09:09:46AM +0200, Miha Marolt wrote:
> 
> 
> On 07/09/2015 05:15 PM, Vadim Kochan wrote:
> >On Thu, Jul 09, 2015 at 05:09:27PM +0200, Miha Marolt wrote:
> >>
> >>On 07/09/2015 04:57 PM, Nikolay Aleksandrov wrote:
> >>>On 07/09/2015 04:55 PM, Vadim Kochan wrote:
> >>>>On Thu, Jul 09, 2015 at 04:50:06PM +0200, Nikolay Aleksandrov wrote:
> >>>>>On 07/09/2015 04:13 PM, Miha Marolt wrote:
> >>>>>>Hi!
> >>>>>>
> >>>>>>I hope this is the right place to reports bugs. I apologize if it isn't.
> >>>>>>
> >>>>>>I have written a C program (see below for source code) that opens a raw socket on CentOS 7.1 Linux and binds it to some address (it doesn't use the port that I supplied, but that is not the point here). The "netstat" program correctly recognizes the socket as "raw", while "ss" program says it is "udp". Here are the relevant lines from the ss and netstat commands:
> >>>>>>
> >>>>>>$ netstat -an
> >>>>>>raw        0      0 127.0.0.1:6             0.0.0.0:* 7
> >>>>>>
> >>>>>>$ ./ss -an
> >>>>>>udp    UNCONN     21569  0      127.0.0.1:6 *:*
> >>>>>>
> >>>>>>Here is the version information
> >>>>>>
> >>>>>>$ netstat --version  # From CentOS 7.1.
> >>>>>>net-tools 2.10-alpha
> >>>>>>
> >>>>>>$ ./ss --version  # Built from git.
> >>>>>>ss utility, iproute2-ss150626
> >>>>>>
> >>>>>>
> >>>>>>C source follows. If you store it in "main.c", then compile it with "$ gcc main.c -o main" and then run it by executing "$ sudo ./main".
> >>>>>>
> >>>>>>#include <arpa/inet.h>
> >>>>>>#include <assert.h>
> >>>>>>#include <sys/socket.h>
> >>>>>>#include <stdio.h>
> >>>>>>#include <unistd.h>
> >>>>>>
> >>>>>>
> >>>>>>int main(void)
> >>>>>>{
> >>>>>>     // Create a raw socket.
> >>>>>>     int sock = socket(AF_INET, SOCK_RAW, IPPROTO_TCP);
> >>>>>>     if (sock == -1) { perror(NULL); goto exc_cleanup; }
> >>>>>>
> >>>>>>     // Bind socket to an address.
> >>>>>>     struct sockaddr_in addr;
> >>>>>>     addr.sin_family = AF_INET;
> >>>>>>     inet_pton(AF_INET, "127.0.0.1", &addr.sin_addr);
> >>>>>>     addr.sin_port = htons(27183);
> >>>>>>
> >>>>>>     int rc = bind(sock, (struct sockaddr*)&addr, sizeof(addr));
> >>>>>>     if (rc != 0) { perror(NULL); goto exc_cleanup; }
> >>>>>>
> >>>>>>     // Wait until user presses <ENTER>.
> >>>>>>     printf("\nPress <ENTER> to quit the program.\n");
> >>>>>>     getchar();
> >>>>>>
> >>>>>>exc_cleanup:
> >>>>>>     assert(!close(sock));
> >>>>>>}
> >>>>>>
> >>>>>>
> >>>>>>Best regards,
> >>>>>>Miha
> >>>>>Hi,
> >>>>>I think this was changed by commit:
> >>>>>8250bc9ff4e5 ("ss: Unify inet sockets output")
> >>>>>Because dgram_show_line() is used for both UDP and RAW sockets
> >>>>>IPPROTO_UDP is used for both now and proto_name() returns "udp".
> >>>>>CCed the patch author and attached a possible solution.
> >>>>>
> >>>>>Cheers,
> >>>>>  Nik
> >>>>>diff --git a/misc/ss.c b/misc/ss.c
> >>>>>index 870cad185341..4de77e92c319 100644
> >>>>>--- a/misc/ss.c
> >>>>>+++ b/misc/ss.c
> >>>>>@@ -1554,6 +1554,8 @@ out:
> >>>>>  static char *proto_name(int protocol)
> >>>>>  {
> >>>>>  	switch (protocol) {
> >>>>>+	case IPPROTO_RAW:
> >>>>>+		return "raw";
> >>>>>  	case IPPROTO_UDP:
> >>>>>  		return "udp";
> >>>>>  	case IPPROTO_TCP:
> >>>>>@@ -2398,7 +2400,7 @@ static int dgram_show_line(char *line, const struct filter *f, int family)
> >>>>>  	if (n < 9)
> >>>>>  		opt[0] = 0;
> >>>>>-	inet_stats_print(&s, IPPROTO_UDP);
> >>>>>+	inet_stats_print(&s, dg_proto == UDP_PROTO ? IPPROTO_UDP : IPPROTO_RAW);
> >>>>>  	if (show_details && opt[0])
> >>>>>  		printf(" opt:\"%s\"", opt);
> >>>>Yeah, it fixed the issue, just tested the fix.
> >>>>
> >>>Great, I'll submit it in a minute.
> >>>Thanks for testing!
> >>Thank you very much for the fast fix!
> >>
> >>I've found another bug: command "$ ss" doesn't display only tcp sockets as
> >>the man page ss(8) says (file man/man8/ss.8 in iproute2 git repo). It also
> >>displays e.g. unix sockets. The man page says "When no option is used ss
> >>displays a list of open non-listening TCP sockets that have established
> >>connection.".
> >>
> >>
> >>Regards,
> >>Miha
> >That seems OK, I see that unix stream sockets are displayed which are
> >connection oriented, and UDP can also have established state.
> 

> According to the man page, **only** TCP sockets should be listed by "$ ss".
> In reality, also Unix and UDP sockets are listed, so there is a discrepancy
> between what man page says and what actually happens.

Yes, you are right man page says so, but seems such behaviour is for a
long time and may be it is better to change man page rather than change
the default behaviour.

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

* Re: [BUG] "$ ss -a" incorrectly displays raw sockets as udp sockets
  2015-07-10  7:16             ` Vadim Kochan
@ 2015-07-15 12:10               ` Miha Marolt
  2015-07-15 12:50                 ` [PATCH iproute2] ss: fix display of raw sockets Nikolay Aleksandrov
  0 siblings, 1 reply; 15+ messages in thread
From: Miha Marolt @ 2015-07-15 12:10 UTC (permalink / raw
  To: Vadim Kochan; +Cc: Nikolay Aleksandrov, netdev

On 07/10/2015 09:16 AM, Vadim Kochan wrote:
> On Fri, Jul 10, 2015 at 09:09:46AM +0200, Miha Marolt wrote:
>>
>> On 07/09/2015 05:15 PM, Vadim Kochan wrote:
>>> On Thu, Jul 09, 2015 at 05:09:27PM +0200, Miha Marolt wrote:
>>>> On 07/09/2015 04:57 PM, Nikolay Aleksandrov wrote:
>>>>> On 07/09/2015 04:55 PM, Vadim Kochan wrote:
>>>>>> On Thu, Jul 09, 2015 at 04:50:06PM +0200, Nikolay Aleksandrov wrote:
>>>>>>> On 07/09/2015 04:13 PM, Miha Marolt wrote:
>>>>>>>> Hi!
>>>>>>>>
>>>>>>>> I hope this is the right place to reports bugs. I apologize if it isn't.
>>>>>>>>
>>>>>>>> I have written a C program (see below for source code) that opens a raw socket on CentOS 7.1 Linux and binds it to some address (it doesn't use the port that I supplied, but that is not the point here). The "netstat" program correctly recognizes the socket as "raw", while "ss" program says it is "udp". Here are the relevant lines from the ss and netstat commands:
>>>>>>>>
>>>>>>>> $ netstat -an
>>>>>>>> raw        0      0 127.0.0.1:6             0.0.0.0:* 7
>>>>>>>>
>>>>>>>> $ ./ss -an
>>>>>>>> udp    UNCONN     21569  0      127.0.0.1:6 *:*
>>>>>>>>
>>>>>>>> Here is the version information
>>>>>>>>
>>>>>>>> $ netstat --version  # From CentOS 7.1.
>>>>>>>> net-tools 2.10-alpha
>>>>>>>>
>>>>>>>> $ ./ss --version  # Built from git.
>>>>>>>> ss utility, iproute2-ss150626
>>>>>>>>
>>>>>>>>
>>>>>>>> C source follows. If you store it in "main.c", then compile it with "$ gcc main.c -o main" and then run it by executing "$ sudo ./main".
>>>>>>>>
>>>>>>>> #include <arpa/inet.h>
>>>>>>>> #include <assert.h>
>>>>>>>> #include <sys/socket.h>
>>>>>>>> #include <stdio.h>
>>>>>>>> #include <unistd.h>
>>>>>>>>
>>>>>>>>
>>>>>>>> int main(void)
>>>>>>>> {
>>>>>>>>      // Create a raw socket.
>>>>>>>>      int sock = socket(AF_INET, SOCK_RAW, IPPROTO_TCP);
>>>>>>>>      if (sock == -1) { perror(NULL); goto exc_cleanup; }
>>>>>>>>
>>>>>>>>      // Bind socket to an address.
>>>>>>>>      struct sockaddr_in addr;
>>>>>>>>      addr.sin_family = AF_INET;
>>>>>>>>      inet_pton(AF_INET, "127.0.0.1", &addr.sin_addr);
>>>>>>>>      addr.sin_port = htons(27183);
>>>>>>>>
>>>>>>>>      int rc = bind(sock, (struct sockaddr*)&addr, sizeof(addr));
>>>>>>>>      if (rc != 0) { perror(NULL); goto exc_cleanup; }
>>>>>>>>
>>>>>>>>      // Wait until user presses <ENTER>.
>>>>>>>>      printf("\nPress <ENTER> to quit the program.\n");
>>>>>>>>      getchar();
>>>>>>>>
>>>>>>>> exc_cleanup:
>>>>>>>>      assert(!close(sock));
>>>>>>>> }
>>>>>>>>
>>>>>>>>
>>>>>>>> Best regards,
>>>>>>>> Miha
>>>>>>> Hi,
>>>>>>> I think this was changed by commit:
>>>>>>> 8250bc9ff4e5 ("ss: Unify inet sockets output")
>>>>>>> Because dgram_show_line() is used for both UDP and RAW sockets
>>>>>>> IPPROTO_UDP is used for both now and proto_name() returns "udp".
>>>>>>> CCed the patch author and attached a possible solution.
>>>>>>>
>>>>>>> Cheers,
>>>>>>>   Nik
>>>>>>> diff --git a/misc/ss.c b/misc/ss.c
>>>>>>> index 870cad185341..4de77e92c319 100644
>>>>>>> --- a/misc/ss.c
>>>>>>> +++ b/misc/ss.c
>>>>>>> @@ -1554,6 +1554,8 @@ out:
>>>>>>>   static char *proto_name(int protocol)
>>>>>>>   {
>>>>>>>   	switch (protocol) {
>>>>>>> +	case IPPROTO_RAW:
>>>>>>> +		return "raw";
>>>>>>>   	case IPPROTO_UDP:
>>>>>>>   		return "udp";
>>>>>>>   	case IPPROTO_TCP:
>>>>>>> @@ -2398,7 +2400,7 @@ static int dgram_show_line(char *line, const struct filter *f, int family)
>>>>>>>   	if (n < 9)
>>>>>>>   		opt[0] = 0;
>>>>>>> -	inet_stats_print(&s, IPPROTO_UDP);
>>>>>>> +	inet_stats_print(&s, dg_proto == UDP_PROTO ? IPPROTO_UDP : IPPROTO_RAW);
>>>>>>>   	if (show_details && opt[0])
>>>>>>>   		printf(" opt:\"%s\"", opt);
>>>>>> Yeah, it fixed the issue, just tested the fix.
>>>>>>
>>>>> Great, I'll submit it in a minute.
>>>>> Thanks for testing!
>>>> Thank you very much for the fast fix!
>>>>
>>>> I've found another bug: command "$ ss" doesn't display only tcp sockets as
>>>> the man page ss(8) says (file man/man8/ss.8 in iproute2 git repo). It also
>>>> displays e.g. unix sockets. The man page says "When no option is used ss
>>>> displays a list of open non-listening TCP sockets that have established
>>>> connection.".
>>>>
>>>>
>>>> Regards,
>>>> Miha
>>> That seems OK, I see that unix stream sockets are displayed which are
>>> connection oriented, and UDP can also have established state.
>> According to the man page, **only** TCP sockets should be listed by "$ ss".
>> In reality, also Unix and UDP sockets are listed, so there is a discrepancy
>> between what man page says and what actually happens.
> Yes, you are right man page says so, but seems such behaviour is for a
> long time and may be it is better to change man page rather than change
> the default behaviour.

Hi again!

What is the status of these two bugs (raw sockets wrongly being 
displayed as udp sockets and wrong description in the man page)?

According to the git web client [1], fixes haven't been commited yet.

How and where can I follow the progress?


[1] 
https://git.kernel.org/cgit/linux/kernel/git/shemminger/iproute2.git/log/


Regards,
Miha

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

* [PATCH iproute2] ss: fix display of raw sockets
  2015-07-15 12:10               ` Miha Marolt
@ 2015-07-15 12:50                 ` Nikolay Aleksandrov
  2015-07-20 21:58                   ` Stephen Hemminger
  0 siblings, 1 reply; 15+ messages in thread
From: Nikolay Aleksandrov @ 2015-07-15 12:50 UTC (permalink / raw
  To: netdev; +Cc: eric.dumazet, miham, vadim4j, davem, stephen, Nikolay Aleksandrov

After commit 8250bc9ff4e5 ("ss: Unify inet sockets output") raw sockets
are displayed as udp because dgram_show_line() is used for both and
thus IPPROTO_UDP is used for both so proto_name() returns "udp".
Fix this by checking dg_proto which is set according to the caller of
dgram_show_line().

Reported-by: Miha Marolt <miham@beyondsemi.com>
Signed-off-by: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
---
note: use 0 instead of IPPROTO_RAW like Eric suggested

 misc/ss.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/misc/ss.c b/misc/ss.c
index 03f92fa69270..6abd1d1206b3 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -1552,6 +1552,8 @@ out:
 static char *proto_name(int protocol)
 {
 	switch (protocol) {
+	case 0:
+		return "raw";
 	case IPPROTO_UDP:
 		return "udp";
 	case IPPROTO_TCP:
@@ -2416,7 +2418,7 @@ static int dgram_show_line(char *line, const struct filter *f, int family)
 	if (n < 9)
 		opt[0] = 0;
 
-	inet_stats_print(&s, IPPROTO_UDP);
+	inet_stats_print(&s, dg_proto == UDP_PROTO ? IPPROTO_UDP : 0);
 
 	if (show_details && opt[0])
 		printf(" opt:\"%s\"", opt);
-- 
1.9.3

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

* Re: [PATCH iproute2] ss: fix display of raw sockets
  2015-07-15 12:50                 ` [PATCH iproute2] ss: fix display of raw sockets Nikolay Aleksandrov
@ 2015-07-20 21:58                   ` Stephen Hemminger
  0 siblings, 0 replies; 15+ messages in thread
From: Stephen Hemminger @ 2015-07-20 21:58 UTC (permalink / raw
  To: Nikolay Aleksandrov; +Cc: netdev, eric.dumazet, miham, vadim4j, davem

On Wed, 15 Jul 2015 05:50:42 -0700
Nikolay Aleksandrov <nikolay@cumulusnetworks.com> wrote:

> After commit 8250bc9ff4e5 ("ss: Unify inet sockets output") raw sockets
> are displayed as udp because dgram_show_line() is used for both and
> thus IPPROTO_UDP is used for both so proto_name() returns "udp".
> Fix this by checking dg_proto which is set according to the caller of
> dgram_show_line().
> 
> Reported-by: Miha Marolt <miham@beyondsemi.com>
> Signed-off-by: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
> ---
> note: use 0 instead of IPPROTO_RAW like Eric suggested
> 
>  misc/ss.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)

Applied, thanks.

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

end of thread, other threads:[~2015-07-20 21:58 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-09 14:13 [BUG] "$ ss -a" incorrectly displays raw sockets as udp sockets Miha Marolt
2015-07-09 14:50 ` Nikolay Aleksandrov
2015-07-09 14:55   ` Vadim Kochan
2015-07-09 14:57     ` Nikolay Aleksandrov
2015-07-09 15:09       ` Miha Marolt
2015-07-09 15:15         ` Vadim Kochan
2015-07-10  7:09           ` Miha Marolt
2015-07-10  7:16             ` Vadim Kochan
2015-07-15 12:10               ` Miha Marolt
2015-07-15 12:50                 ` [PATCH iproute2] ss: fix display of raw sockets Nikolay Aleksandrov
2015-07-20 21:58                   ` Stephen Hemminger
2015-07-09 15:14 ` [BUG] "$ ss -a" incorrectly displays raw sockets as udp sockets Eric Dumazet
2015-07-09 15:21   ` Eric Dumazet
2015-07-09 15:28     ` Vadim Kochan
2015-07-09 15:30       ` Nikolay Aleksandrov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.