--- glibc-2.4/sysdeps/unix/sysv/linux/check_pf.c 2006-01-08 03:21:15.000000000 -0500 +++ glibc-2.5/sysdeps/unix/sysv/linux/check_pf.c 2006-09-24 12:50:22.000000000 -0400 @@ -17,9 +17,11 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ +#include #include #include #include +#include #include #include #include @@ -29,16 +31,30 @@ #include #include +#include #include +#ifndef IFA_F_TEMPORARY +# define IFA_F_TEMPORARY IFA_F_SECONDARY +#endif +#ifndef IFA_F_HOMEADDRESS +# define IFA_F_HOMEADDRESS 0 +#endif + + static int -make_request (int fd, pid_t pid, bool *seen_ipv4, bool *seen_ipv6) +make_request (int fd, pid_t pid, bool *seen_ipv4, bool *seen_ipv6, + struct in6addrinfo **in6ai, size_t *in6ailen) { - struct + struct req { struct nlmsghdr nlh; struct rtgenmsg g; + /* struct rtgenmsg consists of a single byte. This means there + are three bytes of padding included in the REQ definition. + We make them explicit here. */ + char pad[3]; } req; struct sockaddr_nl nladdr; @@ -49,6 +65,9 @@ req.nlh.nlmsg_seq = time (NULL); req.g.rtgen_family = AF_UNSPEC; + assert (sizeof (req) - offsetof (struct req, pad) == 3); + memset (req.pad, '\0', sizeof (req.pad)); + memset (&nladdr, '\0', sizeof (nladdr)); nladdr.nl_family = AF_NETLINK; @@ -63,6 +82,12 @@ bool done = false; char buf[4096]; struct iovec iov = { buf, sizeof (buf) }; + struct in6ailist + { + struct in6addrinfo info; + struct in6ailist *next; + } *in6ailist = NULL; + size_t in6ailistlen = 0; do { @@ -101,6 +126,47 @@ break; case AF_INET6: *seen_ipv6 = true; + + if (ifam->ifa_flags & (IFA_F_DEPRECATED + | IFA_F_TEMPORARY + | IFA_F_HOMEADDRESS)) + { + struct rtattr *rta = IFA_RTA (ifam); + size_t len = (nlmh->nlmsg_len + - NLMSG_LENGTH (sizeof (*ifam))); + void *local = NULL; + void *address = NULL; + while (RTA_OK (rta, len)) + { + switch (rta->rta_type) + { + case IFA_LOCAL: + local = RTA_DATA (rta); + break; + + case IFA_ADDRESS: + address = RTA_DATA (rta); + break; + } + + rta = RTA_NEXT (rta, len); + } + + struct in6ailist *newp = alloca (sizeof (*newp)); + newp->info.flags = (((ifam->ifa_flags & IFA_F_DEPRECATED) + ? in6ai_deprecated : 0) + | ((ifam->ifa_flags + & IFA_F_TEMPORARY) + ? in6ai_temporary : 0) + | ((ifam->ifa_flags + & IFA_F_HOMEADDRESS) + ? in6ai_homeaddress : 0)); + memcpy (newp->info.addr, address ?: local, + sizeof (newp->info.addr)); + newp->next = in6ailist; + in6ailist = newp; + ++in6ailistlen; + } break; default: /* Ignore. */ @@ -110,12 +176,27 @@ else if (nlmh->nlmsg_type == NLMSG_DONE) /* We found the end, leave the loop. */ done = true; - else ; } } while (! done); - __close (fd); + close_not_cancel_no_status (fd); + + if (in6ailist != NULL) + { + *in6ai = malloc (in6ailistlen * sizeof (**in6ai)); + if (*in6ai == NULL) + return -1; + + *in6ailen = in6ailistlen; + + do + { + (*in6ai)[--in6ailistlen] = in6ailist->info; + in6ailist = in6ailist->next; + } + while (in6ailist != NULL); + } return 0; } @@ -133,8 +214,12 @@ void attribute_hidden -__check_pf (bool *seen_ipv4, bool *seen_ipv6) +__check_pf (bool *seen_ipv4, bool *seen_ipv6, + struct in6addrinfo **in6ai, size_t *in6ailen) { + *in6ai = NULL; + *in6ailen = 0; + if (! __no_netlink_support) { int fd = __socket (PF_NETLINK, SOCK_RAW, NETLINK_ROUTE); @@ -148,7 +233,8 @@ if (fd >= 0 && __bind (fd, (struct sockaddr *) &nladdr, sizeof (nladdr)) == 0 && __getsockname (fd, (struct sockaddr *) &nladdr, &addr_len) == 0 - && make_request (fd, nladdr.nl_pid, seen_ipv4, seen_ipv6) == 0) + && make_request (fd, nladdr.nl_pid, seen_ipv4, seen_ipv6, + in6ai, in6ailen) == 0) /* It worked. */ return; @@ -178,9 +264,6 @@ return; } - *seen_ipv4 = false; - *seen_ipv6 = false; - struct ifaddrs *runp; for (runp = ifa; runp != NULL; runp = runp->ifa_next) if (runp->ifa_addr->sa_family == PF_INET)