Bug 436560

Summary: socket module SO_* constants incomplete
Product: [Fedora] Fedora Reporter: John Dennis <jdennis>
Component: pythonAssignee: James Antill <james.antill>
Status: CLOSED RAWHIDE QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: low Docs Contact:
Priority: low    
Version: rawhideCC: james.antill, katzj
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
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 05:26:21 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
patch to export missing SO_* constants none

Description John Dennis 2008-03-07 22:03:03 UTC
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 22:04:25 UTC
Created attachment 297256 [details]
patch to export missing SO_* constants

Comment 2 John Dennis 2008-03-07 22:55:20 UTC
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 05:26:21 UTC
 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 15:07:53 UTC
Thanks James for the quick response.