summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2006-01-14 18:12:57 +0000
committerMartin v. Löwis <martin@v.loewis.de>2006-01-14 18:12:57 +0000
commit11017b172dc2525079fe8a6f17650b2fc048c9e6 (patch)
treeca1c91cb4a3752fdff3c277f8e85958024bc84e0
parent015f72b254019027c73a2f13925c77d0dbcdb028 (diff)
downloadcpython-git-11017b172dc2525079fe8a6f17650b2fc048c9e6.tar.gz
Patch #1103116: AF_NETLINK sockets basic support.
-rw-r--r--Doc/lib/libsocket.tex3
-rw-r--r--Misc/ACKS1
-rw-r--r--Misc/NEWS2
-rw-r--r--Modules/socketmodule.c54
-rw-r--r--Modules/socketmodule.h9
-rwxr-xr-xconfigure77
-rw-r--r--configure.in14
-rw-r--r--pyconfig.h.in6
8 files changed, 160 insertions, 6 deletions
diff --git a/Doc/lib/libsocket.tex b/Doc/lib/libsocket.tex
index e3d9a92a85..4d3a00aec1 100644
--- a/Doc/lib/libsocket.tex
+++ b/Doc/lib/libsocket.tex
@@ -68,6 +68,9 @@ depending on the results from DNS resolution and/or the host
configuration. For deterministic behavior use a numeric address in
\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
argument types and out-of-memory conditions can be raised; errors
related to socket or address semantics raise the error
diff --git a/Misc/ACKS b/Misc/ACKS
index ad77e038bd..2cf964f341 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -58,6 +58,7 @@ Steven Bethard
Stephen Bevan
Ron Bickers
Dominic Binks
+Philippe Biondi
Stuart Bishop
Roy Bixler
Martin Bless
diff --git a/Misc/NEWS b/Misc/NEWS
index 4a1339fb50..a7e76e611a 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -216,6 +216,8 @@ Core and builtins
Extension Modules
-----------------
+- Patch #1103116: Basic AF_NETLINK support.
+
- Bug #1402308, (possible) segfault when using mmap.mmap(-1, ...)
- Bug #1400822, _curses over{lay,write} doesn't work when passing 6 ints.
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index 038bd1fa88..7259432a67 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -7,7 +7,7 @@ This module provides an interface to Berkeley socket IPC.
Limitations:
- 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).
- Additional restrictions apply on some non-Unix platforms (compensated
for by socket.py).
@@ -954,6 +954,14 @@ makesockaddr(int sockfd, struct sockaddr *addr, int addrlen, int proto)
}
#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
case AF_INET6:
{
@@ -1090,6 +1098,31 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
}
#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:
{
struct sockaddr_in* addr;
@@ -1286,6 +1319,13 @@ getsockaddrlen(PySocketSockObject *s, socklen_t *len_ret)
return 1;
}
#endif /* AF_UNIX */
+#if defined(AF_NETLINK)
+ case AF_NETLINK:
+ {
+ *len_ret = sizeof (struct sockaddr_nl);
+ return 1;
+ }
+#endif
case AF_INET:
{
@@ -3947,6 +3987,18 @@ init_socket(void)
#ifdef 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
#ifdef AF_ROUTE
/* Alias to emulate 4.4BSD */
diff --git a/Modules/socketmodule.h b/Modules/socketmodule.h
index 384d595154..0c5bfade08 100644
--- a/Modules/socketmodule.h
+++ b/Modules/socketmodule.h
@@ -32,6 +32,12 @@
# undef AF_UNIX
#endif
+#ifdef HAVE_LINUX_NETLINK_H
+# include <linux/netlink.h>
+#else
+# undef AF_NETLINK
+#endif
+
#ifdef HAVE_BLUETOOTH_BLUETOOTH_H
#include <bluetooth/bluetooth.h>
#include <bluetooth/rfcomm.h>
@@ -78,6 +84,9 @@ typedef union sock_addr {
#ifdef AF_UNIX
struct sockaddr_un un;
#endif
+#ifdef AF_NETLINK
+ struct sockaddr_nl nl;
+#endif
#ifdef ENABLE_IPV6
struct sockaddr_in6 in6;
struct sockaddr_storage storage;
diff --git a/configure b/configure
index 38817f855d..0d4fad3661 100755
--- a/configure
+++ b/configure
@@ -1,5 +1,5 @@
#! /bin/sh
-# From configure.in Revision: 41975 .
+# From configure.in Revision: 41984 .
# Guess values for system-dependent variables and create Makefiles.
# 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 \
unistd.h utime.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
+# 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
was_it_defined=no
echo "$as_me:$LINENO: checking for clock_t in time.h" >&5
diff --git a/configure.in b/configure.in
index 7ab92e087a..17483b7835 100644
--- a/configure.in
+++ b/configure.in
@@ -994,8 +994,8 @@ dnl AC_MSG_RESULT($cpp_type)
# checks for header files
AC_HEADER_STDC
-AC_CHECK_HEADERS(curses.h dlfcn.h fcntl.h grp.h shadow.h langinfo.h \
-libintl.h ncurses.h poll.h pthread.h \
+AC_CHECK_HEADERS(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 \
unistd.h utime.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
])
+# 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
was_it_defined=no
AC_MSG_CHECKING(for clock_t in time.h)
diff --git a/pyconfig.h.in b/pyconfig.h.in
index 7b24f37a8c..cab9bf5e21 100644
--- a/pyconfig.h.in
+++ b/pyconfig.h.in
@@ -37,6 +37,9 @@
/* Define this if your time.h defines 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. */
#undef HAVE_BIND_TEXTDOMAIN_CODESET
@@ -290,6 +293,9 @@
/* Define if you have the 'link' function. */
#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. */
#undef HAVE_LONG_LONG