Patch #1103116: AF_NETLINK sockets basic support.

This commit is contained in:
Martin v. Löwis 2006-01-14 18:12:57 +00:00
parent 015f72b254
commit 11017b172d
8 changed files with 160 additions and 6 deletions

View File

@ -68,6 +68,9 @@ depending on the results from DNS resolution and/or the host
configuration. For deterministic behavior use a numeric address in configuration. For deterministic behavior use a numeric address in
\var{host} portion. \var{host} portion.
\versionadded[2.5]{AF_NETLINK sockets are represented as
pairs \code{\var{pid}, \var{groups}}.}
All errors raise exceptions. The normal exceptions for invalid All errors raise exceptions. The normal exceptions for invalid
argument types and out-of-memory conditions can be raised; errors argument types and out-of-memory conditions can be raised; errors
related to socket or address semantics raise the error related to socket or address semantics raise the error

View File

@ -58,6 +58,7 @@ Steven Bethard
Stephen Bevan Stephen Bevan
Ron Bickers Ron Bickers
Dominic Binks Dominic Binks
Philippe Biondi
Stuart Bishop Stuart Bishop
Roy Bixler Roy Bixler
Martin Bless Martin Bless

View File

@ -216,6 +216,8 @@ Core and builtins
Extension Modules Extension Modules
----------------- -----------------
- Patch #1103116: Basic AF_NETLINK support.
- Bug #1402308, (possible) segfault when using mmap.mmap(-1, ...) - Bug #1402308, (possible) segfault when using mmap.mmap(-1, ...)
- Bug #1400822, _curses over{lay,write} doesn't work when passing 6 ints. - Bug #1400822, _curses over{lay,write} doesn't work when passing 6 ints.

View File

@ -7,7 +7,7 @@ This module provides an interface to Berkeley socket IPC.
Limitations: Limitations:
- Only AF_INET, AF_INET6 and AF_UNIX address families are supported in a - Only AF_INET, AF_INET6 and AF_UNIX address families are supported in a
portable manner, though AF_PACKET is supported under Linux. portable manner, though AF_PACKET and AF_NETLINK are supported under Linux.
- No read/write operations (use sendall/recv or makefile instead). - No read/write operations (use sendall/recv or makefile instead).
- Additional restrictions apply on some non-Unix platforms (compensated - Additional restrictions apply on some non-Unix platforms (compensated
for by socket.py). for by socket.py).
@ -954,6 +954,14 @@ makesockaddr(int sockfd, struct sockaddr *addr, int addrlen, int proto)
} }
#endif /* AF_UNIX */ #endif /* AF_UNIX */
#if defined(AF_NETLINK)
case AF_NETLINK:
{
struct sockaddr_nl *a = (struct sockaddr_nl *) addr;
return Py_BuildValue("ii", a->nl_pid, a->nl_groups);
}
#endif /* AF_NETLINK */
#ifdef ENABLE_IPV6 #ifdef ENABLE_IPV6
case AF_INET6: case AF_INET6:
{ {
@ -1090,6 +1098,31 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
} }
#endif /* AF_UNIX */ #endif /* AF_UNIX */
#if defined(AF_NETLINK)
case AF_NETLINK:
{
struct sockaddr_nl* addr;
int pid, groups;
addr = (struct sockaddr_nl *)&(s->sock_addr).nl;
if (!PyTuple_Check(args)) {
PyErr_Format(
PyExc_TypeError,
"getsockaddrarg: "
"AF_NETLINK address must be tuple, not %.500s",
args->ob_type->tp_name);
return 0;
}
if (!PyArg_ParseTuple(args, "II:getsockaddrarg", &pid, &groups))
return 0;
addr->nl_family = AF_NETLINK;
addr->nl_pid = pid;
addr->nl_groups = groups;
*addr_ret = (struct sockaddr *) addr;
*len_ret = sizeof(*addr);
return 1;
}
#endif
case AF_INET: case AF_INET:
{ {
struct sockaddr_in* addr; struct sockaddr_in* addr;
@ -1286,6 +1319,13 @@ getsockaddrlen(PySocketSockObject *s, socklen_t *len_ret)
return 1; return 1;
} }
#endif /* AF_UNIX */ #endif /* AF_UNIX */
#if defined(AF_NETLINK)
case AF_NETLINK:
{
*len_ret = sizeof (struct sockaddr_nl);
return 1;
}
#endif
case AF_INET: case AF_INET:
{ {
@ -3947,6 +3987,18 @@ init_socket(void)
#ifdef AF_NETLINK #ifdef AF_NETLINK
/* */ /* */
PyModule_AddIntConstant(m, "AF_NETLINK", AF_NETLINK); PyModule_AddIntConstant(m, "AF_NETLINK", AF_NETLINK);
PyModule_AddIntConstant(m, "NETLINK_ROUTE", NETLINK_ROUTE);
PyModule_AddIntConstant(m, "NETLINK_SKIP", NETLINK_SKIP);
PyModule_AddIntConstant(m, "NETLINK_USERSOCK", NETLINK_USERSOCK);
PyModule_AddIntConstant(m, "NETLINK_FIREWALL", NETLINK_FIREWALL);
PyModule_AddIntConstant(m, "NETLINK_TCPDIAG", NETLINK_TCPDIAG);
PyModule_AddIntConstant(m, "NETLINK_NFLOG", NETLINK_NFLOG);
PyModule_AddIntConstant(m, "NETLINK_XFRM", NETLINK_XFRM);
PyModule_AddIntConstant(m, "NETLINK_ARPD", NETLINK_ARPD);
PyModule_AddIntConstant(m, "NETLINK_ROUTE6", NETLINK_ROUTE6);
PyModule_AddIntConstant(m, "NETLINK_IP6_FW", NETLINK_IP6_FW);
PyModule_AddIntConstant(m, "NETLINK_DNRTMSG", NETLINK_DNRTMSG);
PyModule_AddIntConstant(m, "NETLINK_TAPBASE", NETLINK_TAPBASE);
#endif #endif
#ifdef AF_ROUTE #ifdef AF_ROUTE
/* Alias to emulate 4.4BSD */ /* Alias to emulate 4.4BSD */

View File

@ -32,6 +32,12 @@
# undef AF_UNIX # undef AF_UNIX
#endif #endif
#ifdef HAVE_LINUX_NETLINK_H
# include <linux/netlink.h>
#else
# undef AF_NETLINK
#endif
#ifdef HAVE_BLUETOOTH_BLUETOOTH_H #ifdef HAVE_BLUETOOTH_BLUETOOTH_H
#include <bluetooth/bluetooth.h> #include <bluetooth/bluetooth.h>
#include <bluetooth/rfcomm.h> #include <bluetooth/rfcomm.h>
@ -78,6 +84,9 @@ typedef union sock_addr {
#ifdef AF_UNIX #ifdef AF_UNIX
struct sockaddr_un un; struct sockaddr_un un;
#endif #endif
#ifdef AF_NETLINK
struct sockaddr_nl nl;
#endif
#ifdef ENABLE_IPV6 #ifdef ENABLE_IPV6
struct sockaddr_in6 in6; struct sockaddr_in6 in6;
struct sockaddr_storage storage; struct sockaddr_storage storage;

77
configure vendored
View File

@ -1,5 +1,5 @@
#! /bin/sh #! /bin/sh
# From configure.in Revision: 41975 . # From configure.in Revision: 41984 .
# Guess values for system-dependent variables and create Makefiles. # Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.59 for python 2.5. # Generated by GNU Autoconf 2.59 for python 2.5.
# #
@ -4609,8 +4609,9 @@ done
for ac_header in curses.h dlfcn.h fcntl.h grp.h shadow.h langinfo.h \
libintl.h ncurses.h poll.h pthread.h \ for ac_header in asm/types.h curses.h dlfcn.h fcntl.h grp.h \
shadow.h langinfo.h libintl.h ncurses.h poll.h pthread.h \
stropts.h termios.h thread.h \ stropts.h termios.h thread.h \
unistd.h utime.h \ unistd.h utime.h \
sys/audioio.h sys/bsdtty.h sys/file.h sys/loadavg.h sys/lock.h sys/mkdev.h \ sys/audioio.h sys/bsdtty.h sys/file.h sys/loadavg.h sys/lock.h sys/mkdev.h \
@ -5519,6 +5520,76 @@ fi
done done
# On Linux, netlink.h requires asm/types.h
for ac_header in linux/netlink.h
do
as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
echo "$as_me:$LINENO: checking for $ac_header" >&5
echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
if eval "test \"\${$as_ac_Header+set}\" = set"; then
echo $ECHO_N "(cached) $ECHO_C" >&6
else
cat >conftest.$ac_ext <<_ACEOF
/* confdefs.h. */
_ACEOF
cat confdefs.h >>conftest.$ac_ext
cat >>conftest.$ac_ext <<_ACEOF
/* end confdefs.h. */
#ifdef HAVE_ASM_TYPES_H
#include <asm/types.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#include <$ac_header>
_ACEOF
rm -f conftest.$ac_objext
if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
(eval $ac_compile) 2>conftest.er1
ac_status=$?
grep -v '^ *+' conftest.er1 >conftest.err
rm -f conftest.er1
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } &&
{ ac_try='test -z "$ac_c_werror_flag"
|| test ! -s conftest.err'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); }; } &&
{ ac_try='test -s conftest.$ac_objext'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); }; }; then
eval "$as_ac_Header=yes"
else
echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
eval "$as_ac_Header=no"
fi
rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
fi
echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
if test `eval echo '${'$as_ac_Header'}'` = yes; then
cat >>confdefs.h <<_ACEOF
#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1
_ACEOF
fi
done
# checks for typedefs # checks for typedefs
was_it_defined=no was_it_defined=no
echo "$as_me:$LINENO: checking for clock_t in time.h" >&5 echo "$as_me:$LINENO: checking for clock_t in time.h" >&5

View File

@ -994,8 +994,8 @@ dnl AC_MSG_RESULT($cpp_type)
# checks for header files # checks for header files
AC_HEADER_STDC AC_HEADER_STDC
AC_CHECK_HEADERS(curses.h dlfcn.h fcntl.h grp.h shadow.h langinfo.h \ AC_CHECK_HEADERS(asm/types.h curses.h dlfcn.h fcntl.h grp.h \
libintl.h ncurses.h poll.h pthread.h \ shadow.h langinfo.h libintl.h ncurses.h poll.h pthread.h \
stropts.h termios.h thread.h \ stropts.h termios.h thread.h \
unistd.h utime.h \ unistd.h utime.h \
sys/audioio.h sys/bsdtty.h sys/file.h sys/loadavg.h sys/lock.h sys/mkdev.h \ sys/audioio.h sys/bsdtty.h sys/file.h sys/loadavg.h sys/lock.h sys/mkdev.h \
@ -1014,6 +1014,16 @@ AC_CHECK_HEADERS(term.h,,,[
#endif #endif
]) ])
# On Linux, netlink.h requires asm/types.h
AC_CHECK_HEADERS(linux/netlink.h,,,[
#ifdef HAVE_ASM_TYPES_H
#include <asm/types.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
])
# checks for typedefs # checks for typedefs
was_it_defined=no was_it_defined=no
AC_MSG_CHECKING(for clock_t in time.h) AC_MSG_CHECKING(for clock_t in time.h)

View File

@ -37,6 +37,9 @@
/* Define this if your time.h defines altzone. */ /* Define this if your time.h defines altzone. */
#undef HAVE_ALTZONE #undef HAVE_ALTZONE
/* Define to 1 if you have the <asm/types.h> header file. */
#undef HAVE_ASM_TYPES_H
/* Define to 1 if you have the `bind_textdomain_codeset' function. */ /* Define to 1 if you have the `bind_textdomain_codeset' function. */
#undef HAVE_BIND_TEXTDOMAIN_CODESET #undef HAVE_BIND_TEXTDOMAIN_CODESET
@ -290,6 +293,9 @@
/* Define if you have the 'link' function. */ /* Define if you have the 'link' function. */
#undef HAVE_LINK #undef HAVE_LINK
/* Define to 1 if you have the <linux/netlink.h> header file. */
#undef HAVE_LINUX_NETLINK_H
/* Define this if you have the type long long. */ /* Define this if you have the type long long. */
#undef HAVE_LONG_LONG #undef HAVE_LONG_LONG