Bug 436560 - socket module SO_* constants incomplete
socket module SO_* constants incomplete
Status: CLOSED RAWHIDE
Product: Fedora
Classification: Fedora
Component: python (Show other bugs)
rawhide
All Linux
low Severity low
: ---
: ---
Assigned To: James Antill
Fedora Extras Quality Assurance
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2008-03-07 17:03 EST by John Dennis
Modified: 2008-03-08 10:07 EST (History)
2 users (show)

See Also:
Fixed In Version: python-2.5.1-23.fc9
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2008-03-08 00:26:21 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
patch to export missing SO_* constants (2.02 KB, patch)
2008-03-07 17:04 EST, John Dennis
no flags Details | Diff

  None (edit)
Description John Dennis 2008-03-07 17:03:03 EST
The socket module via the _socket .so extension (Python/Modules/socketmodule.c)
exports a number of constants imported from <sys/socket.h>. Many of those
constants are in turn imported from <asm/socket.h>, in particular the SO_*
constants for use with getsockopt(). Because these constants are defined in an
asm header file they are architecture dependent.

If a SO_* constant is missing from the socket module one cannot hardcode the
value in your python program because it will vary depending on architecture. The
only way for a python program to correctly know the proper constant is if the
constant was obtained via compilation on the target system and then exported via
a CPython module.

We ran across this problem when trying to use SO_PEERCRED with getsockopt(),
it's not exported by the socket module so we hardcoded it to 17, which worked
for many architectures, but not all.

It's easy to export constants. I compiled a list of SO_ constants not currently
exported by the socket module, they are:

SO_SNDBUFFORCE
SO_RCVBUFFORCE
SO_NO_CHECK
SO_PRIORITY
SO_BSDCOMPAT
SO_PASSCRED
SO_PEERCRED
SO_SECURITY_AUTHENTICATION
SO_SECURITY_ENCRYPTION_TRANSPORT
SO_SECURITY_ENCRYPTION_NETWORK
SO_BINDTODEVICE
SO_ATTACH_FILTER
SO_DETACH_FILTER
SO_PEERNAME
SO_TIMESTAMP
SO_PEERSEC
SO_PASSSEC
SO_TIMESTAMPNS

and prepared a patch to socketmodule.c to export these missing constants. It's
important for the socket module to export them because there is no other way for
a noarch python program to get the arch specific value.
Comment 1 John Dennis 2008-03-07 17:04:25 EST
Created attachment 297256 [details]
patch to export missing SO_* constants
Comment 2 John Dennis 2008-03-07 17:55:20 EST
FYI: bug #436564 has a patch showing what has to be done if the SO_PEERCRED
constant is not exported. One has to determine all the arch specific values
(gathered from the kernel source code), get the arch from uname() and then
hardcode the constant based on the arch.
Comment 3 James Antill 2008-03-08 00:26:21 EST
 Note that I just added these to Fedora, so I can't guarantee that they'll even
get in upstream (and they certainly won't be in upstream for a while, at least).
 But then hasattr() is your friend :).

 I've tested python and random apps. I use ... and socket.SO_PEERCRED etc. is
there. Any bugs, you know where to find me :).
Comment 4 John Dennis 2008-03-08 10:07:53 EST
Thanks James for the quick response.

Note You need to log in before you can comment on or make changes to this bug.