Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
bpo-27584: Fixes for V6
Added news file.
socket.rst now reflects first Linux introduction of AF_VSOCK.
Fixed get_cid in test_socket.py.
Replaced PyLong_FromLong with PyLong_FromUnsignedLong in socketmodule.c
Got rid of extra AF_VSOCK #define.
Added sockaddr_vm to sock_addr.
  • Loading branch information
caavery committed Sep 5, 2017
commit 0f653c65ff30396f69d499218699ef1d5a036fd3
2 changes: 1 addition & 1 deletion Doc/library/socket.rst
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ created. Socket addresses are represented as follows:
their hosts. The sockets are represented as a ``(CID, port)`` tuple
where the context ID or CID and port are integers.

Availability: Linux >= 4.8. QEMU >= 2.8.
Availability: Linux >= 3.9.

.. versionadded:: 3.7

Expand Down
16 changes: 5 additions & 11 deletions Lib/test/test_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,13 @@
def get_cid():
if fcntl is None:
return None
if not os.path.exists("/dev/vsock"):
return None
try:
fd = open("/dev/vsock", "rb")
except:
return None
try:
r = fcntl.ioctl(fd, socket.IOCTL_VM_SOCKETS_GET_LOCAL_CID, " ")
except:
fd.close()
with open("/dev/vsock", "rb") as f:
r = fcntl.ioctl(f, socket.IOCTL_VM_SOCKETS_GET_LOCAL_CID, " ")
except OSError:
return None
fd.close()
return struct.unpack("I", r)[0]
else:
return struct.unpack("I", r)[0]

def _have_socket_can():
"""Check whether CAN sockets are supported on this host."""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
``AF_VSOCK`` has been added to the socket interface which allows
communication between virtual machines and their host.
6 changes: 3 additions & 3 deletions Modules/socketmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2642,7 +2642,7 @@ sock_setsockopt(PySocketSockObject *s, PyObject *args)

#ifdef AF_VSOCK
if (s->sock_family == AF_VSOCK) {
uint64_t vflag;
uint64_t vflag; // Must be set width of 64 bits
/* setsockopt(level, opt, flag) */
if (PyArg_ParseTuple(args, "iiK:setsockopt",
&level, &optname, &vflag)) {
Expand Down Expand Up @@ -2735,13 +2735,13 @@ sock_getsockopt(PySocketSockObject *s, PyObject *args)
if (buflen == 0) {
#ifdef AF_VSOCK
if (s->sock_family == AF_VSOCK) {
uint64_t vflag = 0;
uint64_t vflag = 0; // Must be set width of 64 bits
flagsize = sizeof vflag;
res = getsockopt(s->sock_fd, level, optname,
(void *)&vflag, &flagsize);
if (res < 0)
return s->errorhandler();
return PyLong_FromLong(vflag);
return PyLong_FromUnsignedLong(vflag);
}
#endif
flagsize = sizeof flag;
Expand Down
6 changes: 3 additions & 3 deletions Modules/socketmodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,6 @@ typedef int socklen_t;

#ifdef HAVE_LINUX_VM_SOCKETS_H
# include <linux/vm_sockets.h>
# ifndef AF_VSOCK
# define AF_VSOCK 40
# endif
#else
# undef AF_VSOCK
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think #undef AF_VSOCK is necessary. Please remove it.

Copy link
Copy Markdown
Contributor Author

@caavery caavery Aug 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It needs to be there. In the case that vm_sockets.h is not available in include/linux which is the case on the last build bot run. Not all of the bots have the newer kernel.That way the code dependent on vm_sockets.h (AF_VSOCK) will not try to compile.

checking for linux/vm_sockets.h... no

This is also the way its done it at the top of socketmodule.h with AF_NETLINK

I also noticed AF_CAN was not adding the #undef AF_CAN in socketmodule.h so I renamed linux/can.h, ran configure and make and sure enough any code conditionally compiling under #ifdef AF_CAN in socketmodule.c failed.

#endif
Expand Down Expand Up @@ -202,6 +199,9 @@ typedef union sock_addr {
#ifdef HAVE_SOCKADDR_ALG
struct sockaddr_alg alg;
#endif
#ifdef HAVE_LINUX_VM_SOCKETS_H
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please be consistent and use #ifdef AF_VSOCK in all places.

struct sockaddr_vm vm;
#endif
} sock_addr_t;

/* The object holding a socket. It holds some extra information,
Expand Down