PageRenderTime 96ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/recipes/glibc/glibc-2.5/glibc-check_pf.patch

https://github.com/crystalfontz/openembedded
Patch | 343 lines | 335 code | 8 blank | 0 comment | 0 complexity | e497df65a067e5f744ffec7eafa679c4 MD5 | raw file
  1. From libc-ports-return-550-listarch-libc-ports=sources dot redhat dot com at sourceware dot org Tue Oct 31 17:37:21 2006
  2. Return-Path: <libc-ports-return-550-listarch-libc-ports=sources dot redhat dot com at sourceware dot org>
  3. Delivered-To: listarch-libc-ports at sources dot redhat dot com
  4. Received: (qmail 17273 invoked by alias); 31 Oct 2006 17:37:20 -0000
  5. Received: (qmail 17262 invoked by uid 22791); 31 Oct 2006 17:37:19 -0000
  6. X-Spam-Status: No, hits=-2.5 required=5.0 tests=AWL,BAYES_00,TW_CP
  7. X-Spam-Check-By: sourceware.org
  8. Received: from nevyn.them.org (HELO nevyn.them.org) (66.93.172.17) by sourceware.org (qpsmtpd/0.31.1) with ESMTP; Tue, 31 Oct 2006 17:37:11 +0000
  9. Received: from drow by nevyn.them.org with local (Exim 4.54) id 1GexXw-0007Dj-30; Tue, 31 Oct 2006 12:37:08 -0500
  10. Date: Tue, 31 Oct 2006 12:37:08 -0500
  11. From: Daniel Jacobowitz <drow at false dot org>
  12. To: Mike Frysinger <vapier at gentoo dot org>
  13. Cc: libc-ports at sourceware dot org, Philip Balister <philip dot balister at gmail dot com>
  14. Subject: Re: Problem with glibc-2.5 on ARM
  15. Message-ID: <20061031173708.GJ20468@nevyn.them.org>
  16. References: <499146270610241149ibe030e0nd9d6b177a95b346e@mail.gmail.com> <499146270610241254u7cadf63ej2edf05cedbc5266f@mail.gmail.com> <20061024195837.GA20181@nevyn.them.org> <200610291954.27022.vapier@gentoo.org>
  17. MIME-Version: 1.0
  18. Content-Type: text/plain; charset=us-ascii
  19. Content-Disposition: inline
  20. In-Reply-To: <200610291954 dot 27022 dot vapier at gentoo dot org>
  21. User-Agent: Mutt/1.5.13 (2006-08-11)
  22. X-IsSubscribed: yes
  23. Mailing-List: contact libc-ports-help at sourceware dot org; run by ezmlm
  24. Precedence: bulk
  25. List-Subscribe: <mailto:libc-ports-subscribe at sourceware dot org>
  26. List-Post: <mailto:libc-ports at sourceware dot org>
  27. List-Help: <mailto:libc-ports-help at sourceware dot org>, <http://sourceware dot org/lists dot html#faqs>
  28. Sender: libc-ports-owner at sourceware dot org
  29. Delivered-To: mailing list libc-ports at sourceware dot org
  30. On Sun, Oct 29, 2006 at 07:54:25PM -0500, Mike Frysinger wrote:
  31. > On Tuesday 24 October 2006 15:58, Daniel Jacobowitz wrote:
  32. > > ARM is going to need a slightly different version of that file, I
  33. > > guess.
  34. >
  35. > would declaring req with attribute packed not help ?
  36. > -mike
  37. Nope. "struct rtgenmsg" would still have size 4.
  38. Philip, are you still at all interested in this for the old ABI?
  39. I don't have time to test this patch right now, but I think it
  40. will work.
  41. --
  42. Daniel Jacobowitz
  43. CodeSourcery
  44. 2006-10-31 Daniel Jacobowitz <dan@codesourcery.com>
  45. * sysdeps/unix/sysv/linux/arm/check_pf.c: New file.
  46. * sysdeps/unix/sysv/linux/arm/eabi/check_pf.c: New file.
  47. Index: sysdeps/unix/sysv/linux/arm/check_pf.c
  48. ===================================================================
  49. RCS file: sysdeps/unix/sysv/linux/arm/check_pf.c
  50. diff -N sysdeps/unix/sysv/linux/arm/check_pf.c
  51. --- /dev/null 1 Jan 1970 00:00:00 -0000
  52. +++ sysdeps/unix/sysv/linux/arm/check_pf.c 31 Oct 2006 17:29:58 -0000
  53. @@ -0,0 +1,274 @@
  54. +/* Determine protocol families for which interfaces exist. ARM Linux version.
  55. + Copyright (C) 2003, 2006 Free Software Foundation, Inc.
  56. + This file is part of the GNU C Library.
  57. +
  58. + The GNU C Library is free software; you can redistribute it and/or
  59. + modify it under the terms of the GNU Lesser General Public
  60. + License as published by the Free Software Foundation; either
  61. + version 2.1 of the License, or (at your option) any later version.
  62. +
  63. + The GNU C Library is distributed in the hope that it will be useful,
  64. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  65. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  66. + Lesser General Public License for more details.
  67. +
  68. + You should have received a copy of the GNU Lesser General Public
  69. + License along with the GNU C Library; if not, write to the Free
  70. + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  71. + 02111-1307 USA. */
  72. +
  73. +#include <assert.h>
  74. +#include <errno.h>
  75. +#include <ifaddrs.h>
  76. +#include <netdb.h>
  77. +#include <stddef.h>
  78. +#include <string.h>
  79. +#include <time.h>
  80. +#include <unistd.h>
  81. +#include <sys/socket.h>
  82. +
  83. +#include <asm/types.h>
  84. +#include <linux/netlink.h>
  85. +#include <linux/rtnetlink.h>
  86. +
  87. +#include <not-cancel.h>
  88. +#include <kernel-features.h>
  89. +
  90. +
  91. +#ifndef IFA_F_TEMPORARY
  92. +# define IFA_F_TEMPORARY IFA_F_SECONDARY
  93. +#endif
  94. +#ifndef IFA_F_HOMEADDRESS
  95. +# define IFA_F_HOMEADDRESS 0
  96. +#endif
  97. +
  98. +
  99. +static int
  100. +make_request (int fd, pid_t pid, bool *seen_ipv4, bool *seen_ipv6,
  101. + struct in6addrinfo **in6ai, size_t *in6ailen)
  102. +{
  103. + struct req
  104. + {
  105. + struct nlmsghdr nlh;
  106. + struct rtgenmsg g;
  107. + } req;
  108. + struct sockaddr_nl nladdr;
  109. +
  110. + /* struct rtgenmsg consists of a single byte but the ARM ABI rounds
  111. + it up to a word. Clear the padding explicitly here. */
  112. + assert (sizeof (req.g) == 4);
  113. + memset (&req.g, '\0', sizeof (req.g));
  114. +
  115. + req.nlh.nlmsg_len = sizeof (req);
  116. + req.nlh.nlmsg_type = RTM_GETADDR;
  117. + req.nlh.nlmsg_flags = NLM_F_ROOT | NLM_F_MATCH | NLM_F_REQUEST;
  118. + req.nlh.nlmsg_pid = 0;
  119. + req.nlh.nlmsg_seq = time (NULL);
  120. + req.g.rtgen_family = AF_UNSPEC;
  121. +
  122. + memset (&nladdr, '\0', sizeof (nladdr));
  123. + nladdr.nl_family = AF_NETLINK;
  124. +
  125. + if (TEMP_FAILURE_RETRY (__sendto (fd, (void *) &req, sizeof (req), 0,
  126. + (struct sockaddr *) &nladdr,
  127. + sizeof (nladdr))) < 0)
  128. + return -1;
  129. +
  130. + *seen_ipv4 = false;
  131. + *seen_ipv6 = false;
  132. +
  133. + bool done = false;
  134. + char buf[4096];
  135. + struct iovec iov = { buf, sizeof (buf) };
  136. + struct in6ailist
  137. + {
  138. + struct in6addrinfo info;
  139. + struct in6ailist *next;
  140. + } *in6ailist = NULL;
  141. + size_t in6ailistlen = 0;
  142. +
  143. + do
  144. + {
  145. + struct msghdr msg =
  146. + {
  147. + (void *) &nladdr, sizeof (nladdr),
  148. + &iov, 1,
  149. + NULL, 0,
  150. + 0
  151. + };
  152. +
  153. + ssize_t read_len = TEMP_FAILURE_RETRY (__recvmsg (fd, &msg, 0));
  154. + if (read_len < 0)
  155. + return -1;
  156. +
  157. + if (msg.msg_flags & MSG_TRUNC)
  158. + return -1;
  159. +
  160. + struct nlmsghdr *nlmh;
  161. + for (nlmh = (struct nlmsghdr *) buf;
  162. + NLMSG_OK (nlmh, (size_t) read_len);
  163. + nlmh = (struct nlmsghdr *) NLMSG_NEXT (nlmh, read_len))
  164. + {
  165. + if (nladdr.nl_pid != 0 || (pid_t) nlmh->nlmsg_pid != pid
  166. + || nlmh->nlmsg_seq != req.nlh.nlmsg_seq)
  167. + continue;
  168. +
  169. + if (nlmh->nlmsg_type == RTM_NEWADDR)
  170. + {
  171. + struct ifaddrmsg *ifam = (struct ifaddrmsg *) NLMSG_DATA (nlmh);
  172. +
  173. + switch (ifam->ifa_family)
  174. + {
  175. + case AF_INET:
  176. + *seen_ipv4 = true;
  177. + break;
  178. + case AF_INET6:
  179. + *seen_ipv6 = true;
  180. +
  181. + if (ifam->ifa_flags & (IFA_F_DEPRECATED
  182. + | IFA_F_TEMPORARY
  183. + | IFA_F_HOMEADDRESS))
  184. + {
  185. + struct rtattr *rta = IFA_RTA (ifam);
  186. + size_t len = (nlmh->nlmsg_len
  187. + - NLMSG_LENGTH (sizeof (*ifam)));
  188. + void *local = NULL;
  189. + void *address = NULL;
  190. + while (RTA_OK (rta, len))
  191. + {
  192. + switch (rta->rta_type)
  193. + {
  194. + case IFA_LOCAL:
  195. + local = RTA_DATA (rta);
  196. + break;
  197. +
  198. + case IFA_ADDRESS:
  199. + address = RTA_DATA (rta);
  200. + break;
  201. + }
  202. +
  203. + rta = RTA_NEXT (rta, len);
  204. + }
  205. +
  206. + struct in6ailist *newp = alloca (sizeof (*newp));
  207. + newp->info.flags = (((ifam->ifa_flags & IFA_F_DEPRECATED)
  208. + ? in6ai_deprecated : 0)
  209. + | ((ifam->ifa_flags
  210. + & IFA_F_TEMPORARY)
  211. + ? in6ai_temporary : 0)
  212. + | ((ifam->ifa_flags
  213. + & IFA_F_HOMEADDRESS)
  214. + ? in6ai_homeaddress : 0));
  215. + memcpy (newp->info.addr, address ?: local,
  216. + sizeof (newp->info.addr));
  217. + newp->next = in6ailist;
  218. + in6ailist = newp;
  219. + ++in6ailistlen;
  220. + }
  221. + break;
  222. + default:
  223. + /* Ignore. */
  224. + break;
  225. + }
  226. + }
  227. + else if (nlmh->nlmsg_type == NLMSG_DONE)
  228. + /* We found the end, leave the loop. */
  229. + done = true;
  230. + }
  231. + }
  232. + while (! done);
  233. +
  234. + close_not_cancel_no_status (fd);
  235. +
  236. + if (in6ailist != NULL)
  237. + {
  238. + *in6ai = malloc (in6ailistlen * sizeof (**in6ai));
  239. + if (*in6ai == NULL)
  240. + return -1;
  241. +
  242. + *in6ailen = in6ailistlen;
  243. +
  244. + do
  245. + {
  246. + (*in6ai)[--in6ailistlen] = in6ailist->info;
  247. + in6ailist = in6ailist->next;
  248. + }
  249. + while (in6ailist != NULL);
  250. + }
  251. +
  252. + return 0;
  253. +}
  254. +
  255. +
  256. +/* We don't know if we have NETLINK support compiled in in our
  257. + Kernel. */
  258. +#if __ASSUME_NETLINK_SUPPORT == 0
  259. +/* Define in ifaddrs.h. */
  260. +extern int __no_netlink_support attribute_hidden;
  261. +#else
  262. +# define __no_netlink_support 0
  263. +#endif
  264. +
  265. +
  266. +void
  267. +attribute_hidden
  268. +__check_pf (bool *seen_ipv4, bool *seen_ipv6,
  269. + struct in6addrinfo **in6ai, size_t *in6ailen)
  270. +{
  271. + *in6ai = NULL;
  272. + *in6ailen = 0;
  273. +
  274. + if (! __no_netlink_support)
  275. + {
  276. + int fd = __socket (PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
  277. +
  278. + struct sockaddr_nl nladdr;
  279. + memset (&nladdr, '\0', sizeof (nladdr));
  280. + nladdr.nl_family = AF_NETLINK;
  281. +
  282. + socklen_t addr_len = sizeof (nladdr);
  283. +
  284. + if (fd >= 0
  285. + && __bind (fd, (struct sockaddr *) &nladdr, sizeof (nladdr)) == 0
  286. + && __getsockname (fd, (struct sockaddr *) &nladdr, &addr_len) == 0
  287. + && make_request (fd, nladdr.nl_pid, seen_ipv4, seen_ipv6,
  288. + in6ai, in6ailen) == 0)
  289. + /* It worked. */
  290. + return;
  291. +
  292. + if (fd >= 0)
  293. + __close (fd);
  294. +
  295. +#if __ASSUME_NETLINK_SUPPORT == 0
  296. + /* Remember that there is no netlink support. */
  297. + __no_netlink_support = 1;
  298. +#else
  299. + /* We cannot determine what interfaces are available. Be
  300. + pessimistic. */
  301. + *seen_ipv4 = true;
  302. + *seen_ipv6 = true;
  303. +#endif
  304. + }
  305. +
  306. +#if __ASSUME_NETLINK_SUPPORT == 0
  307. + /* No netlink. Get the interface list via getifaddrs. */
  308. + struct ifaddrs *ifa = NULL;
  309. + if (getifaddrs (&ifa) != 0)
  310. + {
  311. + /* We cannot determine what interfaces are available. Be
  312. + pessimistic. */
  313. + *seen_ipv4 = true;
  314. + *seen_ipv6 = true;
  315. + return;
  316. + }
  317. +
  318. + struct ifaddrs *runp;
  319. + for (runp = ifa; runp != NULL; runp = runp->ifa_next)
  320. + if (runp->ifa_addr->sa_family == PF_INET)
  321. + *seen_ipv4 = true;
  322. + else if (runp->ifa_addr->sa_family == PF_INET6)
  323. + *seen_ipv6 = true;
  324. +
  325. + (void) freeifaddrs (ifa);
  326. +#endif
  327. +}
  328. Index: sysdeps/unix/sysv/linux/arm/eabi/check_pf.c
  329. ===================================================================
  330. RCS file: sysdeps/unix/sysv/linux/arm/eabi/check_pf.c
  331. diff -N sysdeps/unix/sysv/linux/arm/eabi/check_pf.c
  332. --- /dev/null 1 Jan 1970 00:00:00 -0000
  333. +++ sysdeps/unix/sysv/linux/arm/eabi/check_pf.c 31 Oct 2006 17:29:58 -0000
  334. @@ -0,0 +1 @@
  335. +#include <sysdeps/unix/sysv/linux/check_pf.c>