On Sun, Mar 09, 2014 at 05:06:15PM +0000, Anton Ivanov wrote: > >>+ return -1; > >>+ } > >>+ > >>+ freeaddrinfo(result); > >>+ > >>+ memset(&hints, 0, sizeof(hints)); > >>+ > >>+ if (s->ipv6) { > >>+ hints.ai_family = AF_INET6; > >>+ } else { > >>+ hints.ai_family = AF_INET; > >>+ } > >>+ if (s->udp) { > >>+ hints.ai_socktype = SOCK_DGRAM; > >>+ hints.ai_protocol = 0; > >>+ } else { > >>+ hints.ai_socktype = SOCK_RAW; > >>+ hints.ai_protocol = IPPROTO_L2TP; > >Hang on, this is bogus. This is a *userspace* L2TP implementation! > > > >We don't want a kernel L2TP driver to handle this socket. Luckily this > >never happens anyway since net/l2tp/l2tp_ip.c only registers its socket > >type for <AF_INET, SOCK_DGRAM, IPPROTO_L2TP> and <AF_INET6, SOCK_DGRAM, > >IPPROTO_L2TP>. > > > >When we create this socket with <AF_INET, SOCK_RAW, IPPROTO_L2TP> what > >really happens is that the kernel falls back to the IPv4 raw socket > >driver due to a wildcard match. > > > >In other words, we shouldn't use IPPROTO_L2TP. Just use 0. > > > > This is not passed to socket directly - both setups share a call to > getaddinfo() after that and use whatever it returns. > > If you pass family, RAW, 0 to getaddrinfo it returns family, DGRAM, > 0. So when you use it later on the socket is setup incorrectly. > > If you pass RAW, PROTO_L2TPV3 it returns the correct values to setup > the socket. Bug for bug canceling each other out :(
That doesn't match what I see. Can you double-check your test and figure out what is happening? Here is my test: $ grep -r SOCK_RAW /usr/include/ /usr/include/bits/socket_type.h: SOCK_RAW = 3, /* Raw protocol interface. */ $ ./a src ai_family 2 ai_socketype 3 ai_protocol 0 dst ai_family 2 ai_socketype 3 ai_protocol 0 $ cat a.c #include <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <netdb.h> int main(int argc, char **argv) { int fd, gairet; struct addrinfo hints; struct addrinfo * result = NULL; memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_INET; hints.ai_socktype = SOCK_RAW; hints.ai_protocol = 0; gairet = getaddrinfo("localhost", NULL, &hints, &result); if ((gairet !=0) || (result == NULL)) { fprintf(stderr, "could not resolve src, errno = %s\n", gai_strerror(gairet)); return 1; } printf("src ai_family %d ai_socketype %d ai_protocol %d\n", result->ai_family, result->ai_socktype, result->ai_protocol); freeaddrinfo(result); memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_INET; hints.ai_socktype = SOCK_RAW; hints.ai_protocol = 0; gairet = getaddrinfo("8.8.8.8", NULL, &hints, &result); if ((gairet !=0) || (result == NULL)) { fprintf(stderr, "could not resolve dst, errno = %s\n", gai_strerror(gairet)); return 1; } printf("dst ai_family %d ai_socketype %d ai_protocol %d\n", result->ai_family, result->ai_socktype, result->ai_protocol); freeaddrinfo(result); return 0; }