diff options
author | Timo Teräs <timo.teras@iki.fi> | 2014-04-14 10:31:45 +0300 |
---|---|---|
committer | Timo Teräs <timo.teras@iki.fi> | 2014-04-14 10:41:20 +0300 |
commit | 224118a61689b5c5b0ccf4588a74b6a47611f040 (patch) | |
tree | 663df6b16f6595afed3b498f18a313a18791859e | |
parent | d648f949e0de07cd3f1dd39816c7cade4aecd148 (diff) | |
download | alpine_aports-224118a61689b5c5b0ccf4588a74b6a47611f040.tar.bz2 alpine_aports-224118a61689b5c5b0ccf4588a74b6a47611f040.tar.xz alpine_aports-224118a61689b5c5b0ccf4588a74b6a47611f040.zip |
main/musl: cherry-pick fixes from upstream git, and port getent.c from netbsd
fixes important memmem bug, getent is a whole lot faster. additionally
the netlink patch is optimized a bit.
-rw-r--r-- | main/musl/0004-e94d0692-to-83c98aac.patch | 59 | ||||
-rw-r--r-- | main/musl/1002-reimplement-if_nameindex-and-getifaddrs-using-netlin.patch | 247 | ||||
-rw-r--r-- | main/musl/APKBUILD | 37 | ||||
-rwxr-xr-x | main/musl/getent | 41 | ||||
-rw-r--r-- | main/musl/getent.c | 437 | ||||
-rwxr-xr-x | main/musl/ldconfig | 2 |
6 files changed, 606 insertions, 217 deletions
diff --git a/main/musl/0004-e94d0692-to-83c98aac.patch b/main/musl/0004-e94d0692-to-83c98aac.patch new file mode 100644 index 0000000000..88cf625fc8 --- /dev/null +++ b/main/musl/0004-e94d0692-to-83c98aac.patch | |||
@@ -0,0 +1,59 @@ | |||
1 | diff --git a/src/internal/syscall.h b/src/internal/syscall.h | ||
2 | index 88fc89c..dcfae00 100644 | ||
3 | --- a/src/internal/syscall.h | ||
4 | +++ b/src/internal/syscall.h | ||
5 | @@ -10,7 +10,7 @@ typedef long syscall_arg_t; | ||
6 | #endif | ||
7 | |||
8 | #if defined(__PIC__) && (100*__GNUC__+__GNUC_MINOR__ >= 303) | ||
9 | -__attribute__((visibility("protected"))) | ||
10 | +__attribute__((visibility("hidden"))) | ||
11 | #endif | ||
12 | long __syscall_ret(unsigned long), __syscall(syscall_arg_t, ...), | ||
13 | __syscall_cp(syscall_arg_t, syscall_arg_t, syscall_arg_t, syscall_arg_t, | ||
14 | diff --git a/src/math/modfl.c b/src/math/modfl.c | ||
15 | index f736bba..4b03a4b 100644 | ||
16 | --- a/src/math/modfl.c | ||
17 | +++ b/src/math/modfl.c | ||
18 | @@ -3,7 +3,12 @@ | ||
19 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
20 | long double modfl(long double x, long double *iptr) | ||
21 | { | ||
22 | - return modf(x, (double *)iptr); | ||
23 | + double d; | ||
24 | + long double r; | ||
25 | + | ||
26 | + r = modf(x, &d); | ||
27 | + *iptr = d; | ||
28 | + return r; | ||
29 | } | ||
30 | #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 | ||
31 | #if LDBL_MANT_DIG == 64 | ||
32 | diff --git a/src/math/sincosl.c b/src/math/sincosl.c | ||
33 | index 2c60080..d3ac1c4 100644 | ||
34 | --- a/src/math/sincosl.c | ||
35 | +++ b/src/math/sincosl.c | ||
36 | @@ -4,7 +4,10 @@ | ||
37 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
38 | void sincosl(long double x, long double *sin, long double *cos) | ||
39 | { | ||
40 | - sincos(x, (double *)sin, (double *)cos); | ||
41 | + double sind, cosd; | ||
42 | + sincos(x, &sind, &cosd); | ||
43 | + *sin = sind; | ||
44 | + *cos = cosd; | ||
45 | } | ||
46 | #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 | ||
47 | void sincosl(long double x, long double *sin, long double *cos) | ||
48 | diff --git a/src/string/memmem.c b/src/string/memmem.c | ||
49 | index 5211d75..a5a249f 100644 | ||
50 | --- a/src/string/memmem.c | ||
51 | +++ b/src/string/memmem.c | ||
52 | @@ -139,6 +139,7 @@ void *memmem(const void *h0, size_t k, const void *n0, size_t l) | ||
53 | /* Use faster algorithms for short needles */ | ||
54 | h = memchr(h0, *n, k); | ||
55 | if (!h || l==1) return (void *)h; | ||
56 | + k -= h - (const unsigned char *)h0; | ||
57 | if (l==2) return twobyte_memmem(h, k, n); | ||
58 | if (l==3) return threebyte_memmem(h, k, n); | ||
59 | if (l==4) return fourbyte_memmem(h, k, n); | ||
diff --git a/main/musl/1002-reimplement-if_nameindex-and-getifaddrs-using-netlin.patch b/main/musl/1002-reimplement-if_nameindex-and-getifaddrs-using-netlin.patch index f740e20672..f8df5dc399 100644 --- a/main/musl/1002-reimplement-if_nameindex-and-getifaddrs-using-netlin.patch +++ b/main/musl/1002-reimplement-if_nameindex-and-getifaddrs-using-netlin.patch | |||
@@ -1,85 +1,55 @@ | |||
1 | From 274b49ab1c7296fc13076b3ed8ca30050487a343 Mon Sep 17 00:00:00 2001 | 1 | From c3d5cce5c550896fd8e9cf856f66f5f264b49ef7 Mon Sep 17 00:00:00 2001 |
2 | From: =?UTF-8?q?Timo=20Ter=C3=A4s?= <timo.teras@iki.fi> | 2 | From: =?UTF-8?q?Timo=20Ter=C3=A4s?= <timo.teras@iki.fi> |
3 | Date: Tue, 8 Apr 2014 14:03:16 +0000 | 3 | Date: Tue, 8 Apr 2014 14:03:16 +0000 |
4 | Subject: [PATCH] reimplement if_nameindex and getifaddrs using netlink | 4 | Subject: [PATCH] reimplement if_nameindex and getifaddrs using netlink |
5 | 5 | ||
6 | --- | 6 | --- |
7 | src/network/__netlink.c | 68 ++++++++++ | 7 | src/network/__netlink.c | 38 ++++++ |
8 | src/network/__netlink.h | 143 ++++++++++++++++++++ | 8 | src/network/__netlink.h | 99 ++++++++++++++ |
9 | src/network/getifaddrs.c | 322 ++++++++++++++++++++++++--------------------- | 9 | src/network/getifaddrs.c | 325 +++++++++++++++++++++++++-------------------- |
10 | src/network/if_nameindex.c | 105 +++++++++------ | 10 | src/network/if_nameindex.c | 107 +++++++++------ |
11 | 4 files changed, 451 insertions(+), 187 deletions(-) | 11 | 4 files changed, 382 insertions(+), 187 deletions(-) |
12 | create mode 100644 src/network/__netlink.c | 12 | create mode 100644 src/network/__netlink.c |
13 | create mode 100644 src/network/__netlink.h | 13 | create mode 100644 src/network/__netlink.h |
14 | 14 | ||
15 | diff --git a/src/network/__netlink.c b/src/network/__netlink.c | 15 | diff --git a/src/network/__netlink.c b/src/network/__netlink.c |
16 | new file mode 100644 | 16 | new file mode 100644 |
17 | index 0000000..d0c9fab | 17 | index 0000000..e75f374 |
18 | --- /dev/null | 18 | --- /dev/null |
19 | +++ b/src/network/__netlink.c | 19 | +++ b/src/network/__netlink.c |
20 | @@ -0,0 +1,68 @@ | 20 | @@ -0,0 +1,38 @@ |
21 | +#define _GNU_SOURCE | ||
22 | +#include <errno.h> | 21 | +#include <errno.h> |
23 | +#include <string.h> | 22 | +#include <string.h> |
24 | +#include <stdlib.h> | ||
25 | +#include <unistd.h> | ||
26 | +#include <sys/socket.h> | 23 | +#include <sys/socket.h> |
27 | +#include <sys/param.h> | ||
28 | +#include "__netlink.h" | 24 | +#include "__netlink.h" |
29 | + | 25 | + |
30 | +struct __netlink_handle { | 26 | +int __netlink_enumerate(int fd, unsigned int seq, int type, int af, |
31 | + int fd; | 27 | + int (*cb)(void *ctx, struct nlmsghdr *h), void *ctx) |
32 | + unsigned int seq; | ||
33 | + size_t bufsize; | ||
34 | +}; | ||
35 | + | ||
36 | +struct __netlink_handle *__netlink_open(int type) | ||
37 | +{ | ||
38 | + struct __netlink_handle *nh; | ||
39 | + int bufsize = getpagesize(); | ||
40 | + /* required buffer size is MIN(8192,pagesize)-sizeof(struct skb_shared_info) | ||
41 | + * the estimate for skb_shared_info size is conservative, but gives enough | ||
42 | + * space to fit struct __netlink_handle including malloc overhead in one page . */ | ||
43 | + if (bufsize > 8192) bufsize = 8192; | ||
44 | + bufsize -= 128; | ||
45 | + nh = malloc(sizeof(struct __netlink_handle) + bufsize); | ||
46 | + if (!nh) return 0; | ||
47 | + nh->fd = socket(PF_NETLINK, SOCK_RAW|SOCK_CLOEXEC, type); | ||
48 | + if (nh->fd < 0) { free(nh); return 0; } | ||
49 | + nh->seq = 1; | ||
50 | + nh->bufsize = bufsize; | ||
51 | + return nh; | ||
52 | +} | ||
53 | + | ||
54 | +void __netlink_close(struct __netlink_handle *nh) | ||
55 | +{ | ||
56 | + close(nh->fd); | ||
57 | + free(nh); | ||
58 | +} | ||
59 | + | ||
60 | +int __netlink_enumerate(struct __netlink_handle *nh, int type, int (*cb)(void *ctx, struct nlmsghdr *h), void *ctx) | ||
61 | +{ | 28 | +{ |
62 | + struct nlmsghdr *h; | 29 | + struct nlmsghdr *h; |
63 | + void *buf = (void*)(nh+1); | 30 | + union { |
64 | + struct { | 31 | + uint8_t buf[8192]; |
65 | + struct nlmsghdr nlh; | 32 | + struct { |
66 | + struct rtgenmsg g; | 33 | + struct nlmsghdr nlh; |
67 | + } *req = buf; | 34 | + struct rtgenmsg g; |
35 | + } req; | ||
36 | + struct nlmsghdr reply; | ||
37 | + } u; | ||
68 | + int r, ret = 0; | 38 | + int r, ret = 0; |
69 | + | 39 | + |
70 | + memset(req, 0, NETLINK_ALIGN(sizeof(*req))); | 40 | + memset(&u.req, 0, sizeof(u.req)); |
71 | + req->nlh.nlmsg_len = sizeof(*req); | 41 | + u.req.nlh.nlmsg_len = sizeof(u.req); |
72 | + req->nlh.nlmsg_type = type; | 42 | + u.req.nlh.nlmsg_type = type; |
73 | + req->nlh.nlmsg_flags = NLM_F_ROOT | NLM_F_MATCH | NLM_F_REQUEST; | 43 | + u.req.nlh.nlmsg_flags = NLM_F_ROOT | NLM_F_MATCH | NLM_F_REQUEST; |
74 | + req->nlh.nlmsg_seq = nh->seq++; | 44 | + u.req.nlh.nlmsg_seq = seq; |
75 | + req->g.rtgen_family = AF_UNSPEC; | 45 | + u.req.g.rtgen_family = af; |
76 | + r = send(nh->fd, req, sizeof(*req), 0); | 46 | + r = send(fd, &u.req, sizeof(u.req), 0); |
77 | + if (r < 0) return r; | 47 | + if (r < 0) return r; |
78 | + | 48 | + |
79 | + while (1) { | 49 | + while (1) { |
80 | + r = recv(nh->fd, buf, nh->bufsize, MSG_DONTWAIT); | 50 | + r = recv(fd, u.buf, sizeof(u.buf), MSG_DONTWAIT); |
81 | + if (r <= 0) return -1; | 51 | + if (r <= 0) return -1; |
82 | + for (h = (struct nlmsghdr*) buf; NLMSG_OK(h, (void*)((uint8_t*)buf+r)); h = NLMSG_NEXT(h)) { | 52 | + for (h = &u.reply; NLMSG_OK(h, (void*)&u.buf[r]); h = NLMSG_NEXT(h)) { |
83 | + if (h->nlmsg_type == NLMSG_DONE) return ret; | 53 | + if (h->nlmsg_type == NLMSG_DONE) return ret; |
84 | + if (h->nlmsg_type == NLMSG_ERROR) return -1; | 54 | + if (h->nlmsg_type == NLMSG_ERROR) return -1; |
85 | + if (!ret) ret = cb(ctx, h); | 55 | + if (!ret) ret = cb(ctx, h); |
@@ -88,10 +58,10 @@ index 0000000..d0c9fab | |||
88 | +} | 58 | +} |
89 | diff --git a/src/network/__netlink.h b/src/network/__netlink.h | 59 | diff --git a/src/network/__netlink.h b/src/network/__netlink.h |
90 | new file mode 100644 | 60 | new file mode 100644 |
91 | index 0000000..94728f3 | 61 | index 0000000..40b12a2 |
92 | --- /dev/null | 62 | --- /dev/null |
93 | +++ b/src/network/__netlink.h | 63 | +++ b/src/network/__netlink.h |
94 | @@ -0,0 +1,143 @@ | 64 | @@ -0,0 +1,99 @@ |
95 | +#include <stdint.h> | 65 | +#include <stdint.h> |
96 | + | 66 | + |
97 | +/* linux/netlink.h */ | 67 | +/* linux/netlink.h */ |
@@ -147,44 +117,10 @@ index 0000000..94728f3 | |||
147 | + | 117 | + |
148 | +/* linux/if_link.h */ | 118 | +/* linux/if_link.h */ |
149 | + | 119 | + |
150 | +enum { | 120 | +#define IFLA_ADDRESS 1 |
151 | + IFLA_UNSPEC, | 121 | +#define IFLA_BROADCAST 2 |
152 | + IFLA_ADDRESS, | 122 | +#define IFLA_IFNAME 3 |
153 | + IFLA_BROADCAST, | 123 | +#define IFLA_STATS 7 |
154 | + IFLA_IFNAME, | ||
155 | + IFLA_MTU, | ||
156 | + IFLA_LINK, | ||
157 | + IFLA_QDISC, | ||
158 | + IFLA_STATS, | ||
159 | + IFLA_COST, | ||
160 | + IFLA_PRIORITY, | ||
161 | + IFLA_MASTER, | ||
162 | + IFLA_WIRELESS, | ||
163 | + IFLA_PROTINFO, | ||
164 | + IFLA_TXQLEN, | ||
165 | + IFLA_MAP, | ||
166 | + IFLA_WEIGHT, | ||
167 | + IFLA_OPERSTATE, | ||
168 | + IFLA_LINKMODE, | ||
169 | + IFLA_LINKINFO, | ||
170 | + IFLA_NET_NS_PID, | ||
171 | + IFLA_IFALIAS, | ||
172 | + IFLA_NUM_VF, | ||
173 | + IFLA_VFINFO_LIST, | ||
174 | + IFLA_STATS64, | ||
175 | + IFLA_VF_PORTS, | ||
176 | + IFLA_PORT_SELF, | ||
177 | + IFLA_AF_SPEC, | ||
178 | + IFLA_GROUP, | ||
179 | + IFLA_NET_NS_FD, | ||
180 | + IFLA_EXT_MASK, | ||
181 | + IFLA_PROMISCUITY, | ||
182 | + IFLA_NUM_TX_QUEUES, | ||
183 | + IFLA_NUM_RX_QUEUES, | ||
184 | + IFLA_CARRIER, | ||
185 | + IFLA_PHYS_PORT_ID, | ||
186 | + __IFLA_MAX | ||
187 | +}; | ||
188 | + | 124 | + |
189 | +/* linux/if_addr.h */ | 125 | +/* linux/if_addr.h */ |
190 | + | 126 | + |
@@ -196,50 +132,40 @@ index 0000000..94728f3 | |||
196 | + uint32_t ifa_index; | 132 | + uint32_t ifa_index; |
197 | +}; | 133 | +}; |
198 | + | 134 | + |
199 | +enum { | 135 | +#define IFA_ADDRESS 1 |
200 | + IFA_UNSPEC, | 136 | +#define IFA_LOCAL 2 |
201 | + IFA_ADDRESS, | 137 | +#define IFA_LABEL 3 |
202 | + IFA_LOCAL, | 138 | +#define IFA_BROADCAST 4 |
203 | + IFA_LABEL, | ||
204 | + IFA_BROADCAST, | ||
205 | + IFA_ANYCAST, | ||
206 | + IFA_CACHEINFO, | ||
207 | + IFA_MULTICAST, | ||
208 | + __IFA_MAX | ||
209 | +}; | ||
210 | + | 139 | + |
211 | +/* musl */ | 140 | +/* musl */ |
212 | + | 141 | + |
213 | +#define NETLINK_ALIGN(len) (((len)+3) & ~3) | 142 | +#define NETLINK_ALIGN(len) (((len)+3) & ~3) |
214 | +#define NLMSG_DATA(nlh) ((void*)((char*)(nlh)+NETLINK_ALIGN(sizeof(struct nlmsghdr)))) | 143 | +#define NLMSG_DATA(nlh) ((void*)((char*)(nlh)+sizeof(struct nlmsghdr))) |
215 | +#define NLMSG_DATALEN(nlh) ((nlh)->nlmsg_len-NETLINK_ALIGN(sizeof(struct nlmsghdr))) | 144 | +#define NLMSG_DATALEN(nlh) ((nlh)->nlmsg_len-sizeof(struct nlmsghdr)) |
216 | +#define NLMSG_DATAEND(nlh) ((char*)(nlh)+(nlh)->nlmsg_len) | 145 | +#define NLMSG_DATAEND(nlh) ((char*)(nlh)+(nlh)->nlmsg_len) |
217 | +#define NLMSG_NEXT(nlh) (struct nlmsghdr*)((char*)(nlh)+NETLINK_ALIGN((nlh)->nlmsg_len)) | 146 | +#define NLMSG_NEXT(nlh) (struct nlmsghdr*)((char*)(nlh)+NETLINK_ALIGN((nlh)->nlmsg_len)) |
218 | +#define NLMSG_OK(nlh,end) (NLMSG_DATA(nlh) <= (end) && \ | 147 | +#define NLMSG_OK(nlh,end) (NLMSG_DATA(nlh) <= (end) && \ |
219 | + (nlh)->nlmsg_len >= sizeof(struct nlmsghdr) && \ | 148 | + (nlh)->nlmsg_len >= sizeof(struct nlmsghdr) && \ |
220 | + (void*)NLMSG_NEXT(nlh) <= (end)) | 149 | + (void*)NLMSG_NEXT(nlh) <= (end)) |
221 | + | 150 | + |
222 | +#define RTA_DATA(rta) ((void*)((char*)(rta)+NETLINK_ALIGN(sizeof(struct rtattr)))) | 151 | +#define RTA_DATA(rta) ((void*)((char*)(rta)+sizeof(struct rtattr))) |
223 | +#define RTA_DATALEN(rta) ((rta)->rta_len-NETLINK_ALIGN(sizeof(struct rtattr))) | 152 | +#define RTA_DATALEN(rta) ((rta)->rta_len-sizeof(struct rtattr)) |
224 | +#define RTA_DATAEND(rta) ((char*)(rta)+(rta)->rta_len) | 153 | +#define RTA_DATAEND(rta) ((char*)(rta)+(rta)->rta_len) |
225 | +#define RTA_NEXT(rta) (struct rtattr*)((char*)(rta)+NETLINK_ALIGN((rta)->rta_len)) | 154 | +#define RTA_NEXT(rta) (struct rtattr*)((char*)(rta)+NETLINK_ALIGN((rta)->rta_len)) |
226 | +#define RTA_OK(rta,end) (RTA_DATA(rta) <= (void*)(end) && \ | 155 | +#define RTA_OK(rta,end) (RTA_DATA(rta) <= (void*)(end) && \ |
227 | + (rta)->rta_len >= sizeof(struct rtattr) && \ | 156 | + (rta)->rta_len >= sizeof(struct rtattr) && \ |
228 | + (void*)RTA_NEXT(rta) <= (void*)(end)) | 157 | + (void*)RTA_NEXT(rta) <= (void*)(end)) |
229 | + | 158 | + |
230 | +#define NLMSG_RTA(nlh,len) ((void*)((char*)(nlh)+NETLINK_ALIGN(sizeof(struct nlmsghdr))+NETLINK_ALIGN(len))) | 159 | +#define NLMSG_RTA(nlh,len) ((void*)((char*)(nlh)+sizeof(struct nlmsghdr)+NETLINK_ALIGN(len))) |
231 | +#define NLMSG_RTAOK(rta,nlh) RTA_OK(rta,NLMSG_DATAEND(nlh)) | 160 | +#define NLMSG_RTAOK(rta,nlh) RTA_OK(rta,NLMSG_DATAEND(nlh)) |
232 | + | 161 | + |
233 | +struct __netlink_handle; | 162 | +int __netlink_enumerate(int fd, unsigned int seq, int type, int af, |
234 | + | 163 | + int (*cb)(void *ctx, struct nlmsghdr *h), void *ctx); |
235 | +struct __netlink_handle *__netlink_open(int type); | ||
236 | +void __netlink_close(struct __netlink_handle *h); | ||
237 | +int __netlink_enumerate(struct __netlink_handle *h, int type, int (*cb)(void *ctx, struct nlmsghdr *h), void *ctx); | ||
238 | diff --git a/src/network/getifaddrs.c b/src/network/getifaddrs.c | 164 | diff --git a/src/network/getifaddrs.c b/src/network/getifaddrs.c |
239 | index 5a94cc7..5b1ebe7 100644 | 165 | index 5a94cc7..9d4bd5b 100644 |
240 | --- a/src/network/getifaddrs.c | 166 | --- a/src/network/getifaddrs.c |
241 | +++ b/src/network/getifaddrs.c | 167 | +++ b/src/network/getifaddrs.c |
242 | @@ -1,181 +1,209 @@ | 168 | @@ -1,181 +1,212 @@ |
243 | -/* (C) 2013 John Spencer. released under musl's standard MIT license. */ | 169 | -/* (C) 2013 John Spencer. released under musl's standard MIT license. */ |
244 | -#undef _GNU_SOURCE | 170 | -#undef _GNU_SOURCE |
245 | #define _GNU_SOURCE | 171 | #define _GNU_SOURCE |
@@ -257,14 +183,16 @@ index 5a94cc7..5b1ebe7 100644 | |||
257 | -#include <sys/ioctl.h> | 183 | -#include <sys/ioctl.h> |
258 | -#include <sys/socket.h> | 184 | -#include <sys/socket.h> |
259 | +#include <ifaddrs.h> | 185 | +#include <ifaddrs.h> |
186 | +#include <syscall.h> | ||
260 | +#include <net/if.h> | 187 | +#include <net/if.h> |
261 | +#include "__netlink.h" | 188 | +#include "__netlink.h" |
262 | 189 | ||
263 | -typedef union { | 190 | -typedef union { |
264 | - struct sockaddr_in6 v6; | 191 | - struct sockaddr_in6 v6; |
265 | +/* getifaddrs() uses PF_PACKET to relay hardware addresses. | 192 | +/* getifaddrs() reports hardware addresses with PF_PACKET that implies |
266 | + * But Infiniband socket address length is longer, so use this hack | 193 | + * struct sockaddr_ll. But e.g. Infiniband socket address length is |
267 | + * (like glibc) to return it anyway. */ | 194 | + * longer than sockaddr_ll.ssl_addr[8] can hold. Use this hack struct |
195 | + * to extend ssl_addr - callers should be able to still use it. */ | ||
268 | +struct sockaddr_ll_hack { | 196 | +struct sockaddr_ll_hack { |
269 | + unsigned short sll_family, sll_protocol; | 197 | + unsigned short sll_family, sll_protocol; |
270 | + int sll_ifindex; | 198 | + int sll_ifindex; |
@@ -336,10 +264,21 @@ index 5a94cc7..5b1ebe7 100644 | |||
336 | + if (!ctx->first) ctx->first = add; | 264 | + if (!ctx->first) ctx->first = add; |
337 | + if (ctx->last) ctx->last->ifa.ifa_next = &add->ifa; | 265 | + if (ctx->last) ctx->last->ifa.ifa_next = &add->ifa; |
338 | + ctx->last = add; | 266 | + ctx->last = add; |
267 | +} | ||
268 | + | ||
269 | +static struct sockaddr* copy_lladdr(union sockany *sa, struct rtattr *rta, struct ifinfomsg *ifi) | ||
270 | +{ | ||
271 | + if (RTA_DATALEN(rta) > sizeof(sa->ll.sll_addr)) return 0; | ||
272 | + sa->ll.sll_family = AF_PACKET; | ||
273 | + sa->ll.sll_ifindex = ifi->ifi_index; | ||
274 | + sa->ll.sll_hatype = ifi->ifi_type; | ||
275 | + sa->ll.sll_halen = RTA_DATALEN(rta); | ||
276 | + memcpy(sa->ll.sll_addr, RTA_DATA(rta), RTA_DATALEN(rta)); | ||
277 | + return &sa->sa; | ||
339 | } | 278 | } |
340 | 279 | ||
341 | -static void ipv6netmask(unsigned prefix_length, struct sockaddr_in6 *sa) | 280 | -static void ipv6netmask(unsigned prefix_length, struct sockaddr_in6 *sa) |
342 | +static struct sockaddr* copy_lladdr(union sockany *sa, struct rtattr *rta, struct ifinfomsg *ifi) | 281 | +static uint8_t *sockany_addr(int af, union sockany *sa, int *len) |
343 | { | 282 | { |
344 | - unsigned char* hb = sa->sin6_addr.s6_addr; | 283 | - unsigned char* hb = sa->sin6_addr.s6_addr; |
345 | - unsigned onebytes = prefix_length / 8; | 284 | - unsigned onebytes = prefix_length / 8; |
@@ -351,17 +290,6 @@ index 5a94cc7..5b1ebe7 100644 | |||
351 | - unsigned char x = -1; | 290 | - unsigned char x = -1; |
352 | - x <<= 8 - bits; | 291 | - x <<= 8 - bits; |
353 | - hb[onebytes] = x; | 292 | - hb[onebytes] = x; |
354 | + if (RTA_DATALEN(rta) > sizeof(sa->ll.sll_addr)) return 0; | ||
355 | + sa->ll.sll_family = AF_PACKET; | ||
356 | + sa->ll.sll_ifindex = ifi->ifi_index; | ||
357 | + sa->ll.sll_hatype = ifi->ifi_type; | ||
358 | + sa->ll.sll_halen = RTA_DATALEN(rta); | ||
359 | + memcpy(sa->ll.sll_addr, RTA_DATA(rta), RTA_DATALEN(rta)); | ||
360 | + return &sa->sa; | ||
361 | +} | ||
362 | + | ||
363 | +static uint8_t *sockany_addr(int af, union sockany *sa, int *len) | ||
364 | +{ | ||
365 | + switch (af) { | 293 | + switch (af) { |
366 | + case AF_INET: *len = 4; return (uint8_t*) &sa->v4.sin_addr; | 294 | + case AF_INET: *len = 4; return (uint8_t*) &sa->v4.sin_addr; |
367 | + case AF_INET6: *len = 16; return (uint8_t*) &sa->v6.sin6_addr; | 295 | + case AF_INET6: *len = 16; return (uint8_t*) &sa->v6.sin6_addr; |
@@ -583,24 +511,25 @@ index 5a94cc7..5b1ebe7 100644 | |||
583 | +int getifaddrs(struct ifaddrs **ifap) | 511 | +int getifaddrs(struct ifaddrs **ifap) |
584 | +{ | 512 | +{ |
585 | + struct ifaddrs_ctx _ctx, *ctx = &_ctx; | 513 | + struct ifaddrs_ctx _ctx, *ctx = &_ctx; |
586 | + struct __netlink_handle *nh; | 514 | + int r = 0, fd; |
587 | + int r = 0; | 515 | + |
516 | + fd = socket(PF_NETLINK, SOCK_RAW|SOCK_CLOEXEC, NETLINK_ROUTE); | ||
517 | + if (fd < 0) return -1; | ||
588 | + | 518 | + |
589 | + nh = __netlink_open(NETLINK_ROUTE); | ||
590 | + if (!nh) return -1; | ||
591 | + memset(ctx, 0, sizeof(*ctx)); | 519 | + memset(ctx, 0, sizeof(*ctx)); |
592 | + if (__netlink_enumerate(nh, RTM_GETLINK, __handle_link, ctx)) r = -1; | 520 | + if (__netlink_enumerate(fd, 1, RTM_GETLINK, AF_UNSPEC, __handle_link, ctx)) r = -1; |
593 | + if (__netlink_enumerate(nh, RTM_GETADDR, __handle_addr, ctx)) r = -1; | 521 | + if (__netlink_enumerate(fd, 1, RTM_GETADDR, AF_UNSPEC, __handle_addr, ctx)) r = -1; |
594 | + __netlink_close(nh); | 522 | + __syscall(SYS_close,fd); |
523 | + | ||
595 | + if (r == 0) *ifap = &ctx->first->ifa; | 524 | + if (r == 0) *ifap = &ctx->first->ifa; |
596 | + else freeifaddrs(&ctx->first->ifa); | 525 | + else freeifaddrs(&ctx->first->ifa); |
597 | + return r; | 526 | + return r; |
598 | +} | 527 | +} |
599 | diff --git a/src/network/if_nameindex.c b/src/network/if_nameindex.c | 528 | diff --git a/src/network/if_nameindex.c b/src/network/if_nameindex.c |
600 | index 53b80b2..d4e8b2d 100644 | 529 | index 53b80b2..cb5587c 100644 |
601 | --- a/src/network/if_nameindex.c | 530 | --- a/src/network/if_nameindex.c |
602 | +++ b/src/network/if_nameindex.c | 531 | +++ b/src/network/if_nameindex.c |
603 | @@ -1,55 +1,80 @@ | 532 | @@ -1,55 +1,82 @@ |
604 | #define _GNU_SOURCE | 533 | #define _GNU_SOURCE |
605 | #include <net/if.h> | 534 | #include <net/if.h> |
606 | -#include <stdlib.h> | 535 | -#include <stdlib.h> |
@@ -611,6 +540,7 @@ index 53b80b2..d4e8b2d 100644 | |||
611 | +#include <unistd.h> | 540 | +#include <unistd.h> |
612 | +#include <stdlib.h> | 541 | +#include <stdlib.h> |
613 | +#include <string.h> | 542 | +#include <string.h> |
543 | +#include <syscall.h> | ||
614 | +#include "__netlink.h" | 544 | +#include "__netlink.h" |
615 | + | 545 | + |
616 | +struct ifnamemap { | 546 | +struct ifnamemap { |
@@ -618,14 +548,14 @@ index 53b80b2..d4e8b2d 100644 | |||
618 | + unsigned char namelen; | 548 | + unsigned char namelen; |
619 | + char name[IFNAMSIZ]; | 549 | + char name[IFNAMSIZ]; |
620 | +}; | 550 | +}; |
621 | 551 | + | |
622 | -static void *do_nameindex(int s, size_t n) | ||
623 | +struct ifnameindexctx { | 552 | +struct ifnameindexctx { |
624 | + unsigned int num; | 553 | + unsigned int num; |
625 | + unsigned int str_bytes; | 554 | + unsigned int str_bytes; |
626 | + struct ifnamemap *list; | 555 | + struct ifnamemap *list; |
627 | +}; | 556 | +}; |
628 | + | 557 | |
558 | -static void *do_nameindex(int s, size_t n) | ||
629 | +static int __handle_link(void *pctx, struct nlmsghdr *h) | 559 | +static int __handle_link(void *pctx, struct nlmsghdr *h) |
630 | { | 560 | { |
631 | - size_t i, len, k; | 561 | - size_t i, len, k; |
@@ -649,6 +579,10 @@ index 53b80b2..d4e8b2d 100644 | |||
649 | + struct ifinfomsg *ifim = NLMSG_DATA(h); | 579 | + struct ifinfomsg *ifim = NLMSG_DATA(h); |
650 | + struct rtattr *rta; | 580 | + struct rtattr *rta; |
651 | + struct ifnamemap *e; | 581 | + struct ifnamemap *e; |
582 | + | ||
583 | + for (rta = NLMSG_RTA(h, sizeof(*ifim)); NLMSG_RTAOK(rta, h); rta = RTA_NEXT(rta)) { | ||
584 | + if (rta->rta_type != IFLA_IFNAME) continue; | ||
585 | + if (RTA_DATALEN(rta) > IFNAMSIZ) return -ENOBUFS; | ||
652 | 586 | ||
653 | - n = conf.ifc_len / sizeof(struct ifreq); | 587 | - n = conf.ifc_len / sizeof(struct ifreq); |
654 | - for (i=k=0; i<n; i++) { | 588 | - for (i=k=0; i<n; i++) { |
@@ -658,10 +592,6 @@ index 53b80b2..d4e8b2d 100644 | |||
658 | - } | 592 | - } |
659 | - idx[i-k].if_index = conf.ifc_req[i].ifr_ifindex; | 593 | - idx[i-k].if_index = conf.ifc_req[i].ifr_ifindex; |
660 | - idx[i-k].if_name = conf.ifc_req[i].ifr_name; | 594 | - idx[i-k].if_name = conf.ifc_req[i].ifr_name; |
661 | + for (rta = NLMSG_RTA(h, sizeof(*ifim)); NLMSG_RTAOK(rta, h); rta = RTA_NEXT(rta)) { | ||
662 | + if (rta->rta_type != IFLA_IFNAME) continue; | ||
663 | + if (RTA_DATALEN(rta) > IFNAMSIZ) return -ENOBUFS; | ||
664 | + | ||
665 | + ctx->num++; | 595 | + ctx->num++; |
666 | + ctx->str_bytes += RTA_DATALEN(rta) + 1; | 596 | + ctx->str_bytes += RTA_DATALEN(rta) + 1; |
667 | + e = realloc(ctx->list, sizeof(struct ifnamemap[ctx->num])); | 597 | + e = realloc(ctx->list, sizeof(struct ifnamemap[ctx->num])); |
@@ -690,15 +620,16 @@ index 53b80b2..d4e8b2d 100644 | |||
690 | - __syscall(SYS_close, s); | 620 | - __syscall(SYS_close, s); |
691 | + struct ifnameindexctx _ctx, *ctx = &_ctx; | 621 | + struct ifnameindexctx _ctx, *ctx = &_ctx; |
692 | + struct if_nameindex *ifs = NULL; | 622 | + struct if_nameindex *ifs = NULL; |
693 | + struct __netlink_handle *nh; | 623 | + int fd, r, i; |
694 | + int r, i; | ||
695 | + char *p; | 624 | + char *p; |
696 | + | 625 | + |
697 | + nh = __netlink_open(NETLINK_ROUTE); | 626 | + fd = socket(PF_NETLINK, SOCK_RAW|SOCK_CLOEXEC, NETLINK_ROUTE); |
698 | + if (!nh) goto err; | 627 | + if (fd < 0) goto err; |
628 | + | ||
699 | + memset(ctx, 0, sizeof(*ctx)); | 629 | + memset(ctx, 0, sizeof(*ctx)); |
700 | + r = __netlink_enumerate(nh, RTM_GETLINK, __handle_link, ctx); | 630 | + r = __netlink_enumerate(fd, 1, RTM_GETLINK, AF_UNSPEC, __handle_link, ctx); |
701 | + __netlink_close(nh); | 631 | + __syscall(SYS_close,fd); |
632 | + | ||
702 | + if (r < 0) goto err; | 633 | + if (r < 0) goto err; |
703 | + | 634 | + |
704 | + ifs = malloc(sizeof(struct if_nameindex[ctx->num+1]) + ctx->str_bytes); | 635 | + ifs = malloc(sizeof(struct if_nameindex[ctx->num+1]) + ctx->str_bytes); |
@@ -722,5 +653,5 @@ index 53b80b2..d4e8b2d 100644 | |||
722 | + return ifs; | 653 | + return ifs; |
723 | } | 654 | } |
724 | -- | 655 | -- |
725 | 1.9.1 | 656 | 1.9.2 |
726 | 657 | ||
diff --git a/main/musl/APKBUILD b/main/musl/APKBUILD index 9ec126bdd1..b02b7f06d1 100644 --- a/main/musl/APKBUILD +++ b/main/musl/APKBUILD | |||
@@ -2,7 +2,7 @@ | |||
2 | # Maintainer: Timo Teräs <timo.teras@iki.fi> | 2 | # Maintainer: Timo Teräs <timo.teras@iki.fi> |
3 | pkgname=musl | 3 | pkgname=musl |
4 | pkgver=1.0.0 | 4 | pkgver=1.0.0 |
5 | pkgrel=8 | 5 | pkgrel=9 |
6 | pkgdesc="the musl c library (libc) implementation" | 6 | pkgdesc="the musl c library (libc) implementation" |
7 | url="http://www.musl-libc.org/" | 7 | url="http://www.musl-libc.org/" |
8 | arch="all" | 8 | arch="all" |
@@ -17,14 +17,15 @@ source="http://www.musl-libc.org/releases/musl-$pkgver.tar.gz | |||
17 | 0001-v1.0.0-to-2b74315d.patch | 17 | 0001-v1.0.0-to-2b74315d.patch |
18 | 0002-2b74315d-to-b9b2db2f.patch | 18 | 0002-2b74315d-to-b9b2db2f.patch |
19 | 0003-b9b2db2f-to-e94d0692.patch | 19 | 0003-b9b2db2f-to-e94d0692.patch |
20 | 0004-e94d0692-to-83c98aac.patch | ||
21 | |||
20 | 1001-add-basic-dns-record-parsing-functions.patch | 22 | 1001-add-basic-dns-record-parsing-functions.patch |
21 | 1002-reimplement-if_nameindex-and-getifaddrs-using-netlin.patch | 23 | 1002-reimplement-if_nameindex-and-getifaddrs-using-netlin.patch |
22 | 24 | ||
23 | getopt_long.c | 25 | getopt_long.c |
24 | __stack_chk_fail_local.c | 26 | __stack_chk_fail_local.c |
25 | getconf.c | 27 | getconf.c |
26 | getent | 28 | getent.c |
27 | ldconfig | ||
28 | " | 29 | " |
29 | 30 | ||
30 | _builddir="$srcdir"/musl-$pkgver | 31 | _builddir="$srcdir"/musl-$pkgver |
@@ -66,8 +67,9 @@ build() { | |||
66 | ${CROSS_COMPILE}gcc $CPPFLAGS $CFLAGS -c "$srcdir"/__stack_chk_fail_local.c -o __stack_chk_fail_local.o || return 1 | 67 | ${CROSS_COMPILE}gcc $CPPFLAGS $CFLAGS -c "$srcdir"/__stack_chk_fail_local.c -o __stack_chk_fail_local.o || return 1 |
67 | ${CROSS_COMPILE}ar r libssp_nonshared.a __stack_chk_fail_local.o || return 1 | 68 | ${CROSS_COMPILE}ar r libssp_nonshared.a __stack_chk_fail_local.o || return 1 |
68 | 69 | ||
69 | # getconf | 70 | # getconf/getent |
70 | ${CROSS_COMPILE}gcc $CPPFLAGS $CFLAGS "$srcdir"/getconf.c -o getconf || return 1 | 71 | ${CROSS_COMPILE}gcc $CPPFLAGS $CFLAGS "$srcdir"/getconf.c -o getconf || return 1 |
72 | ${CROSS_COMPILE}gcc $CPPFLAGS $CFLAGS "$srcdir"/getent.c -o getent || return 1 | ||
71 | 73 | ||
72 | # note: not autotools | 74 | # note: not autotools |
73 | LDFLAGS="$LDFLAGS -Wl,-soname,libc.musl-${CARCH}.so.1" \ | 75 | LDFLAGS="$LDFLAGS -Wl,-soname,libc.musl-${CARCH}.so.1" \ |
@@ -100,12 +102,15 @@ package() { | |||
100 | 102 | ||
101 | utils() { | 103 | utils() { |
102 | replaces="uclibc-utils" | 104 | replaces="uclibc-utils" |
103 | mkdir -p "$subpkgdir"/usr/bin | 105 | mkdir -p "$subpkgdir"/usr/bin "$subpkgdir"/sbin |
104 | mv "$pkgdir"/usr/bin/ldd "$subpkgdir"/usr/bin | 106 | mv "$pkgdir"/usr/bin/ldd "$subpkgdir"/usr/bin |
105 | find "$pkgdir" -type d -delete 2>/dev/null | 107 | find "$pkgdir" -type d -delete 2>/dev/null |
106 | install -D "$srcdir"/getent "$subpkgdir"/usr/bin/getent | 108 | install -D "$_builddir"/getent "$subpkgdir"/usr/bin/getent |
107 | install -D "$_builddir"/getconf "$subpkgdir"/usr/bin/getconf | 109 | install -D "$_builddir"/getconf "$subpkgdir"/usr/bin/getconf |
108 | install -D "$srcdir"/ldconfig "$subpkgdir"/sbin/ldconfig | 110 | cat <<EOF > "$subpkgdir"/sbin/ldconfig |
111 | #!/bin/sh | ||
112 | exit 0 | ||
113 | EOF | ||
109 | } | 114 | } |
110 | 115 | ||
111 | crosstool() { | 116 | crosstool() { |
@@ -119,32 +124,32 @@ md5sums="e54664fdf211d27737e328c4462b545e musl-1.0.0.tar.gz | |||
119 | d081fc3424229c639e636be2dd00d221 0001-v1.0.0-to-2b74315d.patch | 124 | d081fc3424229c639e636be2dd00d221 0001-v1.0.0-to-2b74315d.patch |
120 | 48fa02a48a33bbcb8149edf6540d02f9 0002-2b74315d-to-b9b2db2f.patch | 125 | 48fa02a48a33bbcb8149edf6540d02f9 0002-2b74315d-to-b9b2db2f.patch |
121 | d0a6498cede60e70c468d9a44b968abe 0003-b9b2db2f-to-e94d0692.patch | 126 | d0a6498cede60e70c468d9a44b968abe 0003-b9b2db2f-to-e94d0692.patch |
127 | 1bd1787e961189215e0a60e9ed863529 0004-e94d0692-to-83c98aac.patch | ||
122 | a3810683ef61ac27e2f6ec9801280c81 1001-add-basic-dns-record-parsing-functions.patch | 128 | a3810683ef61ac27e2f6ec9801280c81 1001-add-basic-dns-record-parsing-functions.patch |
123 | d7775d12bb7903094a384626e8b060be 1002-reimplement-if_nameindex-and-getifaddrs-using-netlin.patch | 129 | 83c3bd2a50b1de5ef948704d3f4e0583 1002-reimplement-if_nameindex-and-getifaddrs-using-netlin.patch |
124 | 61c6c1e84ed1df82abbe6d75e90cf21c getopt_long.c | 130 | 61c6c1e84ed1df82abbe6d75e90cf21c getopt_long.c |
125 | 0df687757221bbb0fc1aa67f1bd646f9 __stack_chk_fail_local.c | 131 | 0df687757221bbb0fc1aa67f1bd646f9 __stack_chk_fail_local.c |
126 | 7b391300396e58fe9073866b5a80cfe8 getconf.c | 132 | 7b391300396e58fe9073866b5a80cfe8 getconf.c |
127 | ef81489a6258501cf45db58dfc6d5211 getent | 133 | 2b941c4251cac44988a4abfc50e21267 getent.c" |
128 | 33e4fd94e2560e008e2c3b431d0e3419 ldconfig" | ||
129 | sha256sums="1ad7f45d2972daff19c9e6a92714e6d70f4aad003cd8c3d1e6113432114c1a32 musl-1.0.0.tar.gz | 134 | sha256sums="1ad7f45d2972daff19c9e6a92714e6d70f4aad003cd8c3d1e6113432114c1a32 musl-1.0.0.tar.gz |
130 | aa632b635d472d5a6a49800899ce34cddc89a63a489690faa683d08622b9cd60 0001-v1.0.0-to-2b74315d.patch | 135 | aa632b635d472d5a6a49800899ce34cddc89a63a489690faa683d08622b9cd60 0001-v1.0.0-to-2b74315d.patch |
131 | edc0cebaabd16f894d91c1860bfb70d3f2d9a70cf558c5455689610374447f7d 0002-2b74315d-to-b9b2db2f.patch | 136 | edc0cebaabd16f894d91c1860bfb70d3f2d9a70cf558c5455689610374447f7d 0002-2b74315d-to-b9b2db2f.patch |
132 | 8ee26d42062a4bc91a7fc95fe3f257b9ffcbef600a6344257f7681f358a4a012 0003-b9b2db2f-to-e94d0692.patch | 137 | 8ee26d42062a4bc91a7fc95fe3f257b9ffcbef600a6344257f7681f358a4a012 0003-b9b2db2f-to-e94d0692.patch |
138 | 48a906fd2390b9d9015807c2d3d200c96fa4983faf229661d7158b62ae5dcfd2 0004-e94d0692-to-83c98aac.patch | ||
133 | 758390768b1bc4159d56908ca332b9640cd0552ed3b4b2b8d4a6d499c54c11a1 1001-add-basic-dns-record-parsing-functions.patch | 139 | 758390768b1bc4159d56908ca332b9640cd0552ed3b4b2b8d4a6d499c54c11a1 1001-add-basic-dns-record-parsing-functions.patch |
134 | 3809a7758c0c138a03fae7ad8e27a1c34090c44260a93fcbbb8966994755f450 1002-reimplement-if_nameindex-and-getifaddrs-using-netlin.patch | 140 | 1c25880095e869b827f02997e864fdf4bf157a4e923e52d97dbd05e657aedb70 1002-reimplement-if_nameindex-and-getifaddrs-using-netlin.patch |
135 | d9b644ec20bc33e81a7c52b9fcf7973d835923a69faf50f03db45534b811bd96 getopt_long.c | 141 | d9b644ec20bc33e81a7c52b9fcf7973d835923a69faf50f03db45534b811bd96 getopt_long.c |
136 | 299a7d75a09de3e2e11e7fb4acc3182e4a14e868093d2f30938fce9bfcff13da __stack_chk_fail_local.c | 142 | 299a7d75a09de3e2e11e7fb4acc3182e4a14e868093d2f30938fce9bfcff13da __stack_chk_fail_local.c |
137 | 530ea449f93d53fafcb377fa0a23a7564f2961e49c07a8fdef6c960110317301 getconf.c | 143 | 530ea449f93d53fafcb377fa0a23a7564f2961e49c07a8fdef6c960110317301 getconf.c |
138 | d6996273f5aaaed429058257e4646b243d9e3a4d8609522f802762453f5be4cb getent | 144 | 68373a55e89ce85c562d941ccf588337d6cc6c9c17689d695f65cd7607134bbe getent.c" |
139 | 306c6ca7407560340797866e077e053627ad409277d1b9da58106fce4cf717cb ldconfig" | ||
140 | sha512sums="c76cbfe60cbe9b1ceb1faedddf2dcce0f11c942c8f74e4f217efe63e8e1d7be70fcb6cf1182eeaee90441152c4493d678682cb247a0dbc7537d24f943a7bbdf8 musl-1.0.0.tar.gz | 145 | sha512sums="c76cbfe60cbe9b1ceb1faedddf2dcce0f11c942c8f74e4f217efe63e8e1d7be70fcb6cf1182eeaee90441152c4493d678682cb247a0dbc7537d24f943a7bbdf8 musl-1.0.0.tar.gz |
141 | e04f0f9de2859d18cb13aa8bfd839cc757aa9d835f133e46b48a760c7e689a92c641abe1e84dcaab6134c22500603e66d9a880f9b80b77e36a063348f5879878 0001-v1.0.0-to-2b74315d.patch | 146 | e04f0f9de2859d18cb13aa8bfd839cc757aa9d835f133e46b48a760c7e689a92c641abe1e84dcaab6134c22500603e66d9a880f9b80b77e36a063348f5879878 0001-v1.0.0-to-2b74315d.patch |
142 | 19c09e09d61ba31caeece27ea4241be4f14f73ab958da7f37fc4f0c8391fcaa912a750a2b79c29b3fec24ad22995244c91d1f0372d9b8481c99411e2442c2d4e 0002-2b74315d-to-b9b2db2f.patch | 147 | 19c09e09d61ba31caeece27ea4241be4f14f73ab958da7f37fc4f0c8391fcaa912a750a2b79c29b3fec24ad22995244c91d1f0372d9b8481c99411e2442c2d4e 0002-2b74315d-to-b9b2db2f.patch |
143 | 352b7c0693ebe6093e71d4e9cb704ff569e0e0ae2dcc576d3dc4883e7dddd1ffbc09d8365cceabbeec6b974496dddb9ed7bfacaa244c92c2735caf08c843593a 0003-b9b2db2f-to-e94d0692.patch | 148 | 352b7c0693ebe6093e71d4e9cb704ff569e0e0ae2dcc576d3dc4883e7dddd1ffbc09d8365cceabbeec6b974496dddb9ed7bfacaa244c92c2735caf08c843593a 0003-b9b2db2f-to-e94d0692.patch |
149 | 13b22003bb8b40786e524df42ec9560d56f45265a531faf82e2285cc0c2e893937f4c32159ec75b99c7953dbeeef15b24c2e8dbe2145728e9b011ae8952a81f5 0004-e94d0692-to-83c98aac.patch | ||
144 | dad965258daf69371b844f76bfe5a914b0eca0ca76f3fc340b8fd7acf598b5f87bbe6d68b1f43ed0293ee0ed3bfd85d5173ccc169aa6265646248d5b8a906708 1001-add-basic-dns-record-parsing-functions.patch | 150 | dad965258daf69371b844f76bfe5a914b0eca0ca76f3fc340b8fd7acf598b5f87bbe6d68b1f43ed0293ee0ed3bfd85d5173ccc169aa6265646248d5b8a906708 1001-add-basic-dns-record-parsing-functions.patch |
145 | d2477eca267dae1da25c5612e519a95048a7d651ed2f98b247c735bfd940aa2042624821e03c1f3ed6bc832ffcd0c1342f04bece80fd4aa37729ada222889e9c 1002-reimplement-if_nameindex-and-getifaddrs-using-netlin.patch | 151 | 72cf33738d2cf31f6ec02312bc494d754c17470b519172bb8bd7e2e29ac3b119023088a2b3fbc0dbc2fddd0078ccbae62096106cae361f8c31d6a9950043af25 1002-reimplement-if_nameindex-and-getifaddrs-using-netlin.patch |
146 | 140f3f20d30bd95ebce8c41b8cc7f616c6cbedf4ea06c729c21014e74f6043796825cc40ebc5180620ea38173afdba23f09ebf6d8b11fa05440b14d23764fca9 getopt_long.c | 152 | 140f3f20d30bd95ebce8c41b8cc7f616c6cbedf4ea06c729c21014e74f6043796825cc40ebc5180620ea38173afdba23f09ebf6d8b11fa05440b14d23764fca9 getopt_long.c |
147 | 062bb49fa54839010acd4af113e20f7263dde1c8a2ca359b5fb2661ef9ed9d84a0f7c3bc10c25dcfa10bb3c5a4874588dff636ac43d5dbb3d748d75400756d0b __stack_chk_fail_local.c | 153 | 062bb49fa54839010acd4af113e20f7263dde1c8a2ca359b5fb2661ef9ed9d84a0f7c3bc10c25dcfa10bb3c5a4874588dff636ac43d5dbb3d748d75400756d0b __stack_chk_fail_local.c |
148 | d638cdd02371351190fd0545fb83f44b822fa8c930e9fb47ef93d32a1aaee27641f875e10fa2e9833f1a56dfc2055fb89932a89c88da3e2eb17529bca58f5182 getconf.c | 154 | d638cdd02371351190fd0545fb83f44b822fa8c930e9fb47ef93d32a1aaee27641f875e10fa2e9833f1a56dfc2055fb89932a89c88da3e2eb17529bca58f5182 getconf.c |
149 | 4d92f934d760cf5157d80f19fd766be6b673c65317229b32ac824d9d192f6abcc414e2382b2416dfd5c2f757b46ced98c18e4762bf91f5a48647e0ee61813b06 getent | 155 | b35de9847353b273516162ed4828a810c6130fc5b7de44ee4433003b3f99647b25792d9b1c40dfc67069add11f3fb850e5c35d4f1912dccac108059bbbdfd5a2 getent.c" |
150 | 69f097faa9ccb981e78c3a914ad68a51771637d9aecd2dbc807003ac30663e6d921091a48ff529dfff27a6cd55b0808f91683118acf7acdf406d37266e622b17 ldconfig" | ||
diff --git a/main/musl/getent b/main/musl/getent deleted file mode 100755 index d11befaf8d..0000000000 --- a/main/musl/getent +++ /dev/null | |||
@@ -1,41 +0,0 @@ | |||
1 | #!/bin/sh | ||
2 | # $Header: /var/cvs/uClibc/extra/scripts/getent,v 1.2 2005/02/02 14:18:01 solar Exp $ | ||
3 | # | ||
4 | # Closely (not perfectly) emulate the behavior of glibc's getent utility | ||
5 | # | ||
6 | #passwd|shadow|group|aliases|hosts|networks|ethers|netgroup|protocols|services|rpc | ||
7 | # only returns the first match (by design) | ||
8 | # dns based search is not supported (hosts,networks) | ||
9 | # case-insensitive matches not supported (ethers; others?) | ||
10 | # may return false-positives (hosts,protocols,rpc,services,ethers) | ||
11 | |||
12 | export PATH="${PATH}:/bin:/usr/bin" | ||
13 | |||
14 | file="/etc/$1" | ||
15 | case $1 in | ||
16 | passwd|group|shadow) | ||
17 | match="^$2:" ;; | ||
18 | networks|netgroup) | ||
19 | match="^[[:space:]]*$2\>" ;; | ||
20 | hosts|protocols|rpc|services|ethers) | ||
21 | match="\<$2\>" ;; | ||
22 | aliases) | ||
23 | match="^[[:space:]]*$2[[:space:]]*:" ;; | ||
24 | ""|-h|--help) | ||
25 | echo "USAGE: $0 database [key]" | ||
26 | exit 0 ;; | ||
27 | *) | ||
28 | echo "$0: Unknown database: $1" 1>&2 | ||
29 | exit 1 ;; | ||
30 | esac | ||
31 | |||
32 | if [ ! -f "$file" ] ; then | ||
33 | echo "$0: Could not find database file for $1" 1>&2 | ||
34 | exit 1 | ||
35 | fi | ||
36 | |||
37 | if [ $# -eq 1 ] ; then | ||
38 | exec cat "$file" | ||
39 | else | ||
40 | sed "s/#.*//; /$match/q; d" "$file" | grep . || exit 2 | ||
41 | fi | ||
diff --git a/main/musl/getent.c b/main/musl/getent.c new file mode 100644 index 0000000000..1f97f8f32a --- /dev/null +++ b/main/musl/getent.c | |||
@@ -0,0 +1,437 @@ | |||
1 | /*- | ||
2 | * Copyright (c) 2004-2006 The NetBSD Foundation, Inc. | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This code is derived from software contributed to The NetBSD Foundation | ||
6 | * by Luke Mewburn. | ||
7 | * Timo Teräs cleaned up the code for use in Alpine Linux with musl libc. | ||
8 | * | ||
9 | * Redistribution and use in source and binary forms, with or without | ||
10 | * modification, are permitted provided that the following conditions | ||
11 | * are met: | ||
12 | * 1. Redistributions of source code must retain the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer. | ||
14 | * 2. Redistributions in binary form must reproduce the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer in the | ||
16 | * documentation and/or other materials provided with the distribution. | ||
17 | * | ||
18 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
19 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
20 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
21 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
22 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
28 | * POSSIBILITY OF SUCH DAMAGE. | ||
29 | */ | ||
30 | |||
31 | #include <sys/socket.h> | ||
32 | #include <sys/param.h> | ||
33 | #include <ctype.h> | ||
34 | #include <errno.h> | ||
35 | #include <limits.h> | ||
36 | #include <netdb.h> | ||
37 | #include <pwd.h> | ||
38 | #include <grp.h> | ||
39 | #include <stdio.h> | ||
40 | #include <stdarg.h> | ||
41 | #include <stdbool.h> | ||
42 | #include <stdlib.h> | ||
43 | #include <string.h> | ||
44 | #include <unistd.h> | ||
45 | #include <paths.h> | ||
46 | #include <err.h> | ||
47 | |||
48 | #include <arpa/inet.h> | ||
49 | #include <arpa/nameser.h> | ||
50 | |||
51 | #include <net/if.h> | ||
52 | #include <net/ethernet.h> | ||
53 | #include <netinet/ether.h> | ||
54 | #include <netinet/in.h> | ||
55 | |||
56 | enum { | ||
57 | RV_OK = 0, | ||
58 | RV_USAGE = 1, | ||
59 | RV_NOTFOUND = 2, | ||
60 | RV_NOENUM = 3 | ||
61 | }; | ||
62 | |||
63 | static int usage(const char *); | ||
64 | |||
65 | static int parsenum(const char *word, unsigned long *result) | ||
66 | { | ||
67 | unsigned long num; | ||
68 | char *ep; | ||
69 | |||
70 | if (!isdigit((unsigned char)word[0])) | ||
71 | return 0; | ||
72 | errno = 0; | ||
73 | num = strtoul(word, &ep, 10); | ||
74 | if (num == ULONG_MAX && errno == ERANGE) | ||
75 | return 0; | ||
76 | if (*ep != '\0') | ||
77 | return 0; | ||
78 | *result = num; | ||
79 | return 1; | ||
80 | } | ||
81 | |||
82 | /* | ||
83 | * printfmtstrings -- | ||
84 | * vprintf(format, ...), | ||
85 | * then the aliases (beginning with prefix, separated by sep), | ||
86 | * then a newline | ||
87 | */ | ||
88 | __attribute__ ((format (printf, 4, 5))) | ||
89 | static void printfmtstrings(char *strings[], const char *prefix, const char *sep, | ||
90 | const char *fmt, ...) | ||
91 | { | ||
92 | va_list ap; | ||
93 | const char *curpref; | ||
94 | size_t i; | ||
95 | |||
96 | va_start(ap, fmt); | ||
97 | (void)vprintf(fmt, ap); | ||
98 | va_end(ap); | ||
99 | |||
100 | curpref = prefix; | ||
101 | for (i = 0; strings[i] != NULL; i++) { | ||
102 | (void)printf("%s%s", curpref, strings[i]); | ||
103 | curpref = sep; | ||
104 | } | ||
105 | (void)printf("\n"); | ||
106 | } | ||
107 | |||
108 | static int ethers(int argc, char *argv[]) | ||
109 | { | ||
110 | char hostname[MAXHOSTNAMELEN + 1], *hp; | ||
111 | struct ether_addr ea, *eap; | ||
112 | int i, rv; | ||
113 | |||
114 | if (argc == 2) { | ||
115 | warnx("Enumeration not supported on ethers"); | ||
116 | return RV_NOENUM; | ||
117 | } | ||
118 | |||
119 | rv = RV_OK; | ||
120 | for (i = 2; i < argc; i++) { | ||
121 | if ((eap = ether_aton(argv[i])) == NULL) { | ||
122 | eap = &ea; | ||
123 | hp = argv[i]; | ||
124 | if (ether_hostton(hp, eap) != 0) { | ||
125 | rv = RV_NOTFOUND; | ||
126 | break; | ||
127 | } | ||
128 | } else { | ||
129 | hp = hostname; | ||
130 | if (ether_ntohost(hp, eap) != 0) { | ||
131 | rv = RV_NOTFOUND; | ||
132 | break; | ||
133 | } | ||
134 | } | ||
135 | (void)printf("%-17s %s\n", ether_ntoa(eap), hp); | ||
136 | } | ||
137 | return rv; | ||
138 | } | ||
139 | |||
140 | static void groupprint(const struct group *gr) | ||
141 | { | ||
142 | printfmtstrings(gr->gr_mem, ":", ",", "%s:%s:%u", | ||
143 | gr->gr_name, gr->gr_passwd, gr->gr_gid); | ||
144 | } | ||
145 | |||
146 | static int group(int argc, char *argv[]) | ||
147 | { | ||
148 | struct group *gr; | ||
149 | unsigned long id; | ||
150 | int i, rv; | ||
151 | |||
152 | rv = RV_OK; | ||
153 | if (argc == 2) { | ||
154 | while ((gr = getgrent()) != NULL) | ||
155 | groupprint(gr); | ||
156 | } else { | ||
157 | for (i = 2; i < argc; i++) { | ||
158 | if (parsenum(argv[i], &id)) | ||
159 | gr = getgrgid((gid_t)id); | ||
160 | else | ||
161 | gr = getgrnam(argv[i]); | ||
162 | if (gr == NULL) { | ||
163 | rv = RV_NOTFOUND; | ||
164 | break; | ||
165 | } | ||
166 | groupprint(gr); | ||
167 | } | ||
168 | } | ||
169 | endgrent(); | ||
170 | return rv; | ||
171 | } | ||
172 | |||
173 | static void hostsprint(const struct hostent *he) | ||
174 | { | ||
175 | char buf[INET6_ADDRSTRLEN]; | ||
176 | |||
177 | if (inet_ntop(he->h_addrtype, he->h_addr, buf, sizeof(buf)) == NULL) | ||
178 | (void)strlcpy(buf, "# unknown", sizeof(buf)); | ||
179 | printfmtstrings(he->h_aliases, " ", " ", "%-16s %s", buf, he->h_name); | ||
180 | } | ||
181 | |||
182 | static int hosts(int argc, char *argv[]) | ||
183 | { | ||
184 | struct hostent *he; | ||
185 | char addr[IN6ADDRSZ]; | ||
186 | int i, rv; | ||
187 | |||
188 | sethostent(1); | ||
189 | rv = RV_OK; | ||
190 | if (argc == 2) { | ||
191 | while ((he = gethostent()) != NULL) | ||
192 | hostsprint(he); | ||
193 | } else { | ||
194 | for (i = 2; i < argc; i++) { | ||
195 | if (inet_pton(AF_INET6, argv[i], (void *)addr) > 0) | ||
196 | he = gethostbyaddr(addr, IN6ADDRSZ, AF_INET6); | ||
197 | else if (inet_pton(AF_INET, argv[i], (void *)addr) > 0) | ||
198 | he = gethostbyaddr(addr, INADDRSZ, AF_INET); | ||
199 | else | ||
200 | he = gethostbyname(argv[i]); | ||
201 | if (he == NULL) { | ||
202 | rv = RV_NOTFOUND; | ||
203 | break; | ||
204 | } | ||
205 | hostsprint(he); | ||
206 | } | ||
207 | } | ||
208 | endhostent(); | ||
209 | return rv; | ||
210 | } | ||
211 | |||
212 | static void networksprint(const struct netent *ne) | ||
213 | { | ||
214 | char buf[INET6_ADDRSTRLEN]; | ||
215 | struct in_addr ianet; | ||
216 | |||
217 | ianet = inet_makeaddr(ne->n_net, 0); | ||
218 | if (inet_ntop(ne->n_addrtype, &ianet, buf, sizeof(buf)) == NULL) | ||
219 | (void)strlcpy(buf, "# unknown", sizeof(buf)); | ||
220 | printfmtstrings(ne->n_aliases, " ", " ", "%-16s %s", ne->n_name, buf); | ||
221 | } | ||
222 | |||
223 | static int networks(int argc, char *argv[]) | ||
224 | { | ||
225 | struct netent *ne; | ||
226 | in_addr_t net; | ||
227 | int i, rv; | ||
228 | |||
229 | setnetent(1); | ||
230 | rv = RV_OK; | ||
231 | if (argc == 2) { | ||
232 | while ((ne = getnetent()) != NULL) | ||
233 | networksprint(ne); | ||
234 | } else { | ||
235 | for (i = 2; i < argc; i++) { | ||
236 | net = inet_network(argv[i]); | ||
237 | if (net != INADDR_NONE) | ||
238 | ne = getnetbyaddr(net, AF_INET); | ||
239 | else | ||
240 | ne = getnetbyname(argv[i]); | ||
241 | if (ne != NULL) { | ||
242 | rv = RV_NOTFOUND; | ||
243 | break; | ||
244 | } | ||
245 | networksprint(ne); | ||
246 | } | ||
247 | } | ||
248 | endnetent(); | ||
249 | return rv; | ||
250 | } | ||
251 | |||
252 | static void passwdprint(struct passwd *pw) | ||
253 | { | ||
254 | (void)printf("%s:%s:%u:%u:%s:%s:%s\n", | ||
255 | pw->pw_name, pw->pw_passwd, pw->pw_uid, | ||
256 | pw->pw_gid, pw->pw_gecos, pw->pw_dir, pw->pw_shell); | ||
257 | } | ||
258 | |||
259 | static int passwd(int argc, char *argv[]) | ||
260 | { | ||
261 | struct passwd *pw; | ||
262 | unsigned long id; | ||
263 | int i, rv; | ||
264 | |||
265 | rv = RV_OK; | ||
266 | if (argc == 2) { | ||
267 | while ((pw = getpwent()) != NULL) | ||
268 | passwdprint(pw); | ||
269 | } else { | ||
270 | for (i = 2; i < argc; i++) { | ||
271 | if (parsenum(argv[i], &id)) | ||
272 | pw = getpwuid((uid_t)id); | ||
273 | else | ||
274 | pw = getpwnam(argv[i]); | ||
275 | if (pw == NULL) { | ||
276 | rv = RV_NOTFOUND; | ||
277 | break; | ||
278 | } | ||
279 | passwdprint(pw); | ||
280 | } | ||
281 | } | ||
282 | endpwent(); | ||
283 | return rv; | ||
284 | } | ||
285 | |||
286 | static void protocolsprint(struct protoent *pe) | ||
287 | { | ||
288 | printfmtstrings(pe->p_aliases, " ", " ", | ||
289 | "%-16s %5d", pe->p_name, pe->p_proto); | ||
290 | } | ||
291 | |||
292 | static int protocols(int argc, char *argv[]) | ||
293 | { | ||
294 | struct protoent *pe; | ||
295 | unsigned long id; | ||
296 | int i, rv; | ||
297 | |||
298 | setprotoent(1); | ||
299 | rv = RV_OK; | ||
300 | if (argc == 2) { | ||
301 | while ((pe = getprotoent()) != NULL) | ||
302 | protocolsprint(pe); | ||
303 | } else { | ||
304 | for (i = 2; i < argc; i++) { | ||
305 | if (parsenum(argv[i], &id)) | ||
306 | pe = getprotobynumber((int)id); | ||
307 | else | ||
308 | pe = getprotobyname(argv[i]); | ||
309 | if (pe == NULL) { | ||
310 | rv = RV_NOTFOUND; | ||
311 | break; | ||
312 | } | ||
313 | protocolsprint(pe); | ||
314 | } | ||
315 | } | ||
316 | endprotoent(); | ||
317 | return rv; | ||
318 | } | ||
319 | |||
320 | static void servicesprint(struct servent *se) | ||
321 | { | ||
322 | printfmtstrings(se->s_aliases, " ", " ", | ||
323 | "%-16s %5d/%s", | ||
324 | se->s_name, ntohs(se->s_port), se->s_proto); | ||
325 | |||
326 | } | ||
327 | |||
328 | static int services(int argc, char *argv[]) | ||
329 | { | ||
330 | struct servent *se; | ||
331 | unsigned long id; | ||
332 | char *proto; | ||
333 | int i, rv; | ||
334 | |||
335 | setservent(1); | ||
336 | rv = RV_OK; | ||
337 | if (argc == 2) { | ||
338 | while ((se = getservent()) != NULL) | ||
339 | servicesprint(se); | ||
340 | } else { | ||
341 | for (i = 2; i < argc; i++) { | ||
342 | proto = strchr(argv[i], '/'); | ||
343 | if (proto != NULL) | ||
344 | *proto++ = '\0'; | ||
345 | if (parsenum(argv[i], &id)) | ||
346 | se = getservbyport(htons(id), proto); | ||
347 | else | ||
348 | se = getservbyname(argv[i], proto); | ||
349 | if (se == NULL) { | ||
350 | rv = RV_NOTFOUND; | ||
351 | break; | ||
352 | } | ||
353 | servicesprint(se); | ||
354 | } | ||
355 | } | ||
356 | endservent(); | ||
357 | return rv; | ||
358 | } | ||
359 | |||
360 | static int shells(int argc, char *argv[]) | ||
361 | { | ||
362 | const char *sh; | ||
363 | int i, rv; | ||
364 | |||
365 | setusershell(); | ||
366 | rv = RV_OK; | ||
367 | if (argc == 2) { | ||
368 | while ((sh = getusershell()) != NULL) | ||
369 | (void)printf("%s\n", sh); | ||
370 | } else { | ||
371 | for (i = 2; i < argc; i++) { | ||
372 | setusershell(); | ||
373 | while ((sh = getusershell()) != NULL) { | ||
374 | if (strcmp(sh, argv[i]) == 0) { | ||
375 | (void)printf("%s\n", sh); | ||
376 | break; | ||
377 | } | ||
378 | } | ||
379 | if (sh == NULL) { | ||
380 | rv = RV_NOTFOUND; | ||
381 | break; | ||
382 | } | ||
383 | } | ||
384 | } | ||
385 | endusershell(); | ||
386 | return rv; | ||
387 | } | ||
388 | |||
389 | static struct getentdb { | ||
390 | const char *name; | ||
391 | int (*callback)(int, char *[]); | ||
392 | } databases[] = { | ||
393 | { "ethers", ethers, }, | ||
394 | { "group", group, }, | ||
395 | { "hosts", hosts, }, | ||
396 | { "networks", networks, }, | ||
397 | { "passwd", passwd, }, | ||
398 | { "protocols", protocols, }, | ||
399 | { "services", services, }, | ||
400 | { "shells", shells, }, | ||
401 | |||
402 | { NULL, NULL, }, | ||
403 | }; | ||
404 | |||
405 | static int usage(const char *arg0) | ||
406 | { | ||
407 | struct getentdb *curdb; | ||
408 | size_t i; | ||
409 | |||
410 | (void)fprintf(stderr, "Usage: %s database [key ...]\n", arg0); | ||
411 | (void)fprintf(stderr, "\tdatabase may be one of:"); | ||
412 | for (i = 0, curdb = databases; curdb->name != NULL; curdb++, i++) { | ||
413 | if (i % 7 == 0) | ||
414 | (void)fputs("\n\t\t", stderr); | ||
415 | (void)fprintf(stderr, "%s%s", i % 7 == 0 ? "" : " ", | ||
416 | curdb->name); | ||
417 | } | ||
418 | (void)fprintf(stderr, "\n"); | ||
419 | exit(RV_USAGE); | ||
420 | /* NOTREACHED */ | ||
421 | } | ||
422 | |||
423 | int | ||
424 | main(int argc, char *argv[]) | ||
425 | { | ||
426 | struct getentdb *curdb; | ||
427 | |||
428 | if (argc < 2) | ||
429 | usage(argv[0]); | ||
430 | for (curdb = databases; curdb->name != NULL; curdb++) | ||
431 | if (strcmp(curdb->name, argv[1]) == 0) | ||
432 | return (*curdb->callback)(argc, argv); | ||
433 | |||
434 | warn("Unknown database `%s'", argv[1]); | ||
435 | usage(argv[0]); | ||
436 | /* NOTREACHED */ | ||
437 | } | ||
diff --git a/main/musl/ldconfig b/main/musl/ldconfig deleted file mode 100755 index 039e4d0069..0000000000 --- a/main/musl/ldconfig +++ /dev/null | |||
@@ -1,2 +0,0 @@ | |||
1 | #!/bin/sh | ||
2 | exit 0 | ||