Skip to content

Commit f118711

Browse files
committed
fix Docker builds: rootless-containers#259
Signed-off-by: fassl <[email protected]>
1 parent a0095d1 commit f118711

File tree

3 files changed

+27
-22
lines changed

3 files changed

+27
-22
lines changed

Dockerfile.buildtests

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ ARG LIBSLIRP_COMMIT=v4.6.1
22

33
# Alpine
44
FROM alpine:3 AS buildtest-alpine3-static
5-
RUN apk add --no-cache git build-base autoconf automake libtool linux-headers glib-dev glib-static libcap-static libcap-dev libseccomp-dev libseccomp-static git meson
5+
RUN apk add --no-cache git build-base autoconf automake libtool linux-headers glib-dev glib-static libcap-static libcap-dev libseccomp-dev openssl-dev openssl-libs-static libseccomp-static git meson
66
RUN git clone https://gitlab.freedesktop.org/slirp/libslirp.git /libslirp
77
WORKDIR /libslirp
88
ARG LIBSLIRP_COMMIT
@@ -14,7 +14,7 @@ RUN ./autogen.sh && ./configure LDFLAGS="-static" && make && cp -f slirp4netns /
1414
# Ubuntu
1515
FROM ubuntu:18.04 AS buildtest-ubuntu1804-common
1616
ENV DEBIAN_FRONTEND=noninteractive
17-
RUN apt update && apt install -y automake autotools-dev make gcc libglib2.0-dev libcap-dev libseccomp-dev git ninja-build python3-pip
17+
RUN apt update && apt install -y automake autotools-dev make gcc libglib2.0-dev libcap-dev libseccomp-dev libssl-dev git ninja-build python3-pip
1818
RUN pip3 install meson
1919
RUN git clone https://gitlab.freedesktop.org/slirp/libslirp.git /libslirp
2020
WORKDIR /libslirp
@@ -32,7 +32,7 @@ RUN ./configure && make && cp -f slirp4netns /
3232

3333
# openSUSE (dynamic only)
3434
FROM opensuse/leap:15 AS buildtest-opensuse15-common
35-
RUN zypper install -y --no-recommends autoconf automake gcc glib2-devel git make libcap-devel libseccomp-devel ninja python3-pip
35+
RUN zypper install -y --no-recommends autoconf automake gcc glib2-devel git make libcap-devel libseccomp-devel libopenssl-devel ninja python3-pip
3636
RUN pip3 install meson
3737
RUN git clone https://gitlab.freedesktop.org/slirp/libslirp.git /libslirp
3838
WORKDIR /libslirp

Dockerfile.tests

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ ARG LIBSLIRP_COMMIT=v4.6.1
22

33
FROM ubuntu:20.04 AS build
44
ENV DEBIAN_FRONTEND=noninteractive
5-
RUN apt update && apt install -y automake autotools-dev make gcc libglib2.0-dev libcap-dev libseccomp-dev git ninja-build python3-pip
5+
RUN apt update && apt install -y automake autotools-dev make gcc libglib2.0-dev libcap-dev libseccomp-dev git ninja-build python3-pip libssl-dev
66
RUN pip3 install meson
77
RUN git clone https://gitlab.freedesktop.org/slirp/libslirp.git /libslirp
88
WORKDIR /libslirp

main.c

+23-18
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <sys/types.h>
1414
#include <sys/wait.h>
1515
#include <sys/timex.h>
16+
#include <time.h>
1617
#include <linux/if_tun.h>
1718
#include <arpa/inet.h>
1819
#include <net/if.h>
@@ -222,11 +223,12 @@ struct in6_ifreq {
222223

223224
static const char *pseudo_random_global_id(const char *device)
224225
{
225-
static char id[40];
226-
char tmp[40];
226+
static char id[INET6_ADDRSTRLEN];
227+
char tmp[INET6_ADDRSTRLEN - 10];
227228
unsigned char eui64[16];
228229
unsigned char hash[SHA_DIGEST_LENGTH];
229230
struct ntptimeval ntv;
231+
time_t tv;
230232
struct ifreq ifr;
231233
unsigned char mac[18];
232234
int sockfd;
@@ -246,16 +248,19 @@ static const char *pseudo_random_global_id(const char *device)
246248
strncpy(ifr.ifr_name, device, sizeof(ifr.ifr_name) - 1);
247249

248250
if (ioctl(sockfd, SIOCGIFHWADDR, &ifr) < 0) {
249-
int rand = open("/dev/urandom", O_RDONLY);
250-
if (rand == -1) {
251-
rand = open("/dev/random", O_RDONLY);
252-
}
253-
if (rand == -1) {
251+
int rand = open("/dev/urandom", O_RDONLY);
252+
if (rand == -1) {
253+
rand = open("/dev/random", O_RDONLY);
254+
}
255+
if (rand == -1) {
254256
perror("cannot get dev hwaddr and cannot open random");
255257
return NULL;
256-
}
257-
read(rand, &mac, sizeof(mac));
258-
close(rand);
258+
}
259+
if (read(rand, &mac, sizeof(mac)) != sizeof(mac)) {
260+
perror("cannot get dev hwaddr and cannot read random");
261+
return NULL;
262+
}
263+
close(rand);
259264
}
260265
else {
261266
strncpy(mac, ifr.ifr_ifru.ifru_addr.sa_data, sizeof(mac));
@@ -269,10 +274,10 @@ static const char *pseudo_random_global_id(const char *device)
269274
/*
270275
* 1) Obtain the current time of day in 64-bit NTP format [NTP].
271276
*/
272-
if (ntp_gettime(&ntv) == -1) {
273-
perror("cannot get ntp time");
274-
return NULL;
275-
}
277+
time(&tv);
278+
ntv.time.tv_sec = tv;
279+
// TODO: check NTP format
280+
ntv.time.tv_usec = 0;
276281

277282
/*
278283
* 2) Obtain an EUI-64 identifier from the system running this
@@ -320,7 +325,7 @@ static const char *pseudo_random_global_id(const char *device)
320325
* ID to create a Local IPv6 address prefix.
321326
*/
322327

323-
sprintf(id, "fd00:%s::/64", tmp);
328+
snprintf(id, sizeof(id), "fd00:%s::/64", tmp);
324329

325330
return id;
326331
}
@@ -1032,11 +1037,11 @@ static int parse_cidr6(struct in6_addr *network, struct in6_addr *netmask,
10321037

10331038
for (int i = 0; i < 4; i++, prefix -= 32) {
10341039
if (prefix >= 32) {
1035-
netmask->__in6_u.__u6_addr32[i] = 0xffffffff;
1040+
netmask->s6_addr32[i] = 0xffffffff;
10361041
} else if (prefix > 0) {
1037-
netmask->__in6_u.__u6_addr32[i] = htonl(~((1 << (32 - prefix)) - 1));
1042+
netmask->s6_addr32[i] = htonl(~((1 << (32 - prefix)) - 1));
10381043
} else {
1039-
netmask->__in6_u.__u6_addr32[i] = 0;
1044+
netmask->s6_addr32[i] = 0;
10401045
}
10411046
}
10421047

0 commit comments

Comments
 (0)