Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

#5716 closed enhancement (fixed)

[RFC][PATCH][gsoc2010] Enhancements in networking code

Reported by: atis.elsts Owned by: zooey
Priority: normal Milestone: R1
Component: Network & Internet Version: R1/alpha1
Keywords: gsoc2010 Cc:
Blocked By: Blocking:
Platform: All

Description

This patch fixes one bug and two TODOs in network related Haiku code.

Description:

  • connect() to INADDR_ANY should means the same as connect() INADDR_LOOPBACK:
    • fix this behaviour for TCP - it was not working because INADDR_LOOPBACK was used in wrong byte order;
    • move IPv4 specific code out of TCP module to IPv4 address family module;
    • support this behaviour for UDP too.
  • bind() and connect() should fail if the passed as argument has wrong address family. Note: this is stricter behaviour than in Linux kernel. See my tests for details.

Attachments (3)

bind_connect_enhancements.diff (7.6 KB ) - added by atis.elsts 14 years ago.
test_client.cpp (1.6 KB ) - added by atis.elsts 14 years ago.
test_server.cpp (2.4 KB ) - added by atis.elsts 14 years ago.

Download all attachments as: .zip

Change History (9)

by atis.elsts, 14 years ago

comment:1 by atis.elsts, 14 years ago

The patch also adds two new funcion pointers to struct net_datalink_module_info:

bool (*is_same_family)(const sockaddr *address);

and

void (*get_loopback_address)(sockaddr *result);

It implements is_same_family() function for IPv4, UNIX, and L2CAP address families, and get_loopback_address() function for IPv4 address family.

by atis.elsts, 14 years ago

Attachment: test_client.cpp added

by atis.elsts, 14 years ago

Attachment: test_server.cpp added

comment:2 by atis.elsts, 14 years ago

Tests:

The two test files attached, test_client.cpp and test_server.cpp, implement a server and client functionality respectively. I used behaviour on Linux as the reference behaviour for testing. Test results on Haiku are given after applying the patch.

  1. Test TCP connection to localhost with zero address as connect() parameter.

IPv4:

./test_server tcp 4

./test_client tcp 4 4

IPv6 (on Linux only ATM):

./test_server tcp 6

./test_client tcp 6 6

Result: success.

  1. Test UDP connection to localhost with zero address as connect() parameter.

IPv4:

./test_server udp 4

./test_client udp 4 4

IPv6 (on Linux only ATM):

./test_server udp 6

./test_client udp 6 6

Result: success.

  1. Check the behaviour of bind() with AF_INET6 address family on AF_INET socket.

TCP:

./test_server tcp 4 ::1

UDP:

./test_server udp 4 ::1

Result on Linux: Was expecting this to fail on Linux. But it did not fail! Probably because of the layout of sockaddr_in and sockaddr_in6. This seems rather strange behaviour of Linux, if not a bug then at least an unexected "feature". Strange things like this also work:

./test_server udp 4 0:0:1234:5678:9abc::def

so it's obvious that only the first 32 bits are used of the address passed from user. Probably a backwards compatibility feature? But then again, the applications that use (and rely on) something like this must be REALLY broken. It's probably safe to ignore this case.

Result on Haiku: bind() fails with "Address family not supported by protocol family" messages.

  1. Check the behaviour of connect() with AF_INET6 address family on AF_INET socket.

TCP:

./test_client tcp 4 6

UDP:

./test_client udp 4 6

Result on Linux: connect() fails with "Address family not supported by protocol" message.

Result on Haiku: connect() fails with "Address family not supported by protocol family" message.

comment:3 by mmadia, 14 years ago

Keywords: gsoc2010 added

comment:4 by zooey, 14 years ago

Owner: changed from nobody to zooey
Status: newin-progress

comment:5 by zooey, 14 years ago

Resolution: fixed
Status: in-progressclosed

Hi Atis,

decent stuff, got applied in hrev36192 - thanks!

Note: See TracTickets for help on using tickets.