Ticket #351 (closed defect: fixed)

Opened 12 months ago

Last modified 5 weeks ago

Send Packet in UMPA - BSD

Reported by: luis Owned by: kosma
Priority: medium Milestone: UMPA 0.3 - L2
Component: UMPA Version: current svn
Keywords: Cc: ignotus, nopper

Description (last modified by kosma) (diff)

When I trying to send packets with UMPA in BSD/Mac OS X it got a traceback:

Traceback (most recent call last):
  File "tcp.py", line 72, in <module>
    sock.send(packet)
  File "/Users/luis/Documents/Projects/umit/umit-svn/branch/UMPA/umpa/_sockets.py", line 78, in send
    sent_bits.append(self._sock.sendto(packet.get_raw(),("127.0.0.1", 0)
socket.error: [Errno 22] Invalid argument

Attachments

Change History

  Changed 12 months ago by getxsick

This error doesn't occur if we comment this line:

        self._sock.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)

Propably I need to check how we deal with IP_HDRINCL for BSD systems...

  Changed 12 months ago by luis

  • description modified (diff)

  Changed 2 months ago by kosma

  • owner changed from getxsick to kosma
  • status changed from new to assigned
  • milestone changed from UMPA 0.3 - L2+UDP fix to UMPA 0.5

  Changed 2 months ago by kosma

  • milestone changed from UMPA 0.5 to UMPA 0.3 - L2+UDP fix

  Changed 2 months ago by kosma

This is an excerpt from the ip(4) manpage on my FreeBSD system:

     The following errors may occur when attempting to send IP datagrams via a
     ``raw socket'' with the IP_HDRINCL option set:

     [EINVAL]           The user-supplied ip_len field was not equal to the
                        length of the datagram written to the socket.

Apparently BSD is much more strict than Linux when it comes to IP_HDRINCL. I'm investigating the issue.

  Changed 2 months ago by kosma

  • description modified (diff)

I've found the culprit. From ip(4) manpage on a FreeBSD box:

The ip_len and ip_off fields must be provided in host byte order .  All
other fields must be provided in network byte order.

To make things worse, this awkward behavior isn't even specific to one OS. Code sample from hping2:

#if defined OSTYPE_FREEBSD || defined OSTYPE_NETBSD || defined OSTYPE_BSDI
/* FreeBSD */
/* NetBSD */
        ip->tot_len     = packetsize;
#else
/* Linux */
/* OpenBSD */
        ip->tot_len     = htons(packetsize);
#endif

Well... can it get even crazier?

  • Linux - network order, values ignored
  • OpenBSD2.1 - network order, values madantory
  • FreeBSD/NetBSD/MacOS X/OpenBSD2.0 - host order, values mandatory

I'll try to find a not-too-ugly fix for this issue,

  Changed 2 months ago by getxsick

Hm,

it's common situation. Simple use sys.platform in the fix and don't forget about suitable tests (written first would be better)

  Changed 8 weeks ago by kosma

Fixed in r5597 (link-layer-integration branch). Tested under FreeBSD; needs testing under OpenBSD and Mac OS X.

follow-up: ↓ 10   Changed 8 weeks ago by getxsick

I don't know if anyone from our community has an access to OpenBSD. Do you?

in reply to: ↑ 9   Changed 8 weeks ago by kosma

Replying to getxsick:

I don't know if anyone from our community has an access to OpenBSD. Do you?

I'm installing a virtual machine right now.

  Changed 7 weeks ago by getxsick

So, has anyone tested it under OpenBSD and MacOSX?

  Changed 7 weeks ago by luis

Yeah I tested sending packets under OSX. It works

follow-up: ↓ 14   Changed 7 weeks ago by getxsick

kosma, how about openbsd? AFAIR you mentioned on IRC that it's tested and works...

in reply to: ↑ 13   Changed 7 weeks ago by kosma

Replying to getxsick:

kosma, how about openbsd? AFAIR you mentioned on IRC that it's tested and works...

Yes, tested and working.

  Changed 7 weeks ago by getxsick

Nice! Please close the ticket, merge the branch and lets make a 0.3 release. We are 11 days late with the release. Please put some effort to finish it ASAP.

  Changed 7 weeks ago by getxsick

Well, I created one more ticket for the release (check #401 out). Please, close the #351 after merging r5597 (and other related or a whole branch) to the trunk.

  Changed 5 weeks ago by kosma

  • status changed from assigned to closed
  • resolution set to fixed

r5597 merged. Closing.

  Changed 5 weeks ago by kosma

(merged in r5651)

Add/Change #351 (Send Packet in UMPA - BSD)

Author



Action
as closed
Next status will be 'reopened'
 
Note: See TracTickets for help on using tickets.