diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2023-06-15 17:59:06 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2023-06-16 15:40:11 +0100 |
commit | 609fc157180778025b2f416736839a7935217731 (patch) | |
tree | 493497d19c1d82190bcf39a18c7dfe8031f60d0e | |
parent | 3ee077f991e7810bf515783058be940a4b8f6adc (diff) | |
download | poky-609fc157180778025b2f416736839a7935217731.tar.gz |
runqemu/qemu-helper: Drop tunctl
ip tuntap provides the functionality that we obtained from tunctl. We only
needed tunctl when ifconfig was more available than ip. That isn't the case
now so we can drop tunctl and all the hoops we need to jump through to build
and provide it.
(From OE-Core rev: 2abfbca690ff00cb58ce08a65cde006578ee3de9)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | meta/lib/oeqa/selftest/cases/oescripts.py | 4 | ||||
-rw-r--r-- | meta/recipes-devtools/qemu/nativesdk-qemu-helper_1.0.bb | 7 | ||||
-rw-r--r-- | meta/recipes-devtools/qemu/qemu-helper-native_1.0.bb | 9 | ||||
-rw-r--r-- | meta/recipes-devtools/qemu/qemu-helper/tunctl.c | 158 | ||||
-rwxr-xr-x | scripts/runqemu-gen-tapdevs | 26 | ||||
-rwxr-xr-x | scripts/runqemu-ifdown | 12 | ||||
-rwxr-xr-x | scripts/runqemu-ifup | 26 |
7 files changed, 17 insertions, 225 deletions
diff --git a/meta/lib/oeqa/selftest/cases/oescripts.py b/meta/lib/oeqa/selftest/cases/oescripts.py index 5b0691a9ff..36acc006ca 100644 --- a/meta/lib/oeqa/selftest/cases/oescripts.py +++ b/meta/lib/oeqa/selftest/cases/oescripts.py | |||
@@ -123,8 +123,8 @@ class OEGitproxyTests(OEScriptTests): | |||
123 | class OeRunNativeTest(OESelftestTestCase): | 123 | class OeRunNativeTest(OESelftestTestCase): |
124 | def test_oe_run_native(self): | 124 | def test_oe_run_native(self): |
125 | bitbake("qemu-helper-native -c addto_recipe_sysroot") | 125 | bitbake("qemu-helper-native -c addto_recipe_sysroot") |
126 | result = runCmd("oe-run-native qemu-helper-native tunctl -h") | 126 | result = runCmd("oe-run-native qemu-helper-native qemu-oe-bridge-helper", ignore_status=True) |
127 | self.assertIn("Delete: tunctl -d device-name [-f tun-clone-device]", result.output) | 127 | self.assertIn("No bridge helper found", result.output) |
128 | 128 | ||
129 | class OEListPackageconfigTests(OEScriptTests): | 129 | class OEListPackageconfigTests(OEScriptTests): |
130 | #oe-core.scripts.List_all_the_PACKAGECONFIG's_flags | 130 | #oe-core.scripts.List_all_the_PACKAGECONFIG's_flags |
diff --git a/meta/recipes-devtools/qemu/nativesdk-qemu-helper_1.0.bb b/meta/recipes-devtools/qemu/nativesdk-qemu-helper_1.0.bb index 2a5bcfb909..b100659a8c 100644 --- a/meta/recipes-devtools/qemu/nativesdk-qemu-helper_1.0.bb +++ b/meta/recipes-devtools/qemu/nativesdk-qemu-helper_1.0.bb | |||
@@ -6,8 +6,7 @@ RDEPENDS:${PN} = "nativesdk-qemu nativesdk-unfs3 nativesdk-pseudo \ | |||
6 | 6 | ||
7 | PR = "r9" | 7 | PR = "r9" |
8 | 8 | ||
9 | LIC_FILES_CHKSUM = "file://${WORKDIR}/tunctl.c;endline=4;md5=ff3a09996bc5fff6bc5d4e0b4c28f999 \ | 9 | LIC_FILES_CHKSUM = "file://${COREBASE}/scripts/runqemu;beginline=5;endline=10;md5=ac2b489a58739c7628a2604698db5e7f" |
10 | file://${COREBASE}/scripts/runqemu;beginline=5;endline=10;md5=ac2b489a58739c7628a2604698db5e7f" | ||
11 | 10 | ||
12 | 11 | ||
13 | SRC_URI = "file://${COREBASE}/scripts/runqemu \ | 12 | SRC_URI = "file://${COREBASE}/scripts/runqemu \ |
@@ -18,7 +17,6 @@ SRC_URI = "file://${COREBASE}/scripts/runqemu \ | |||
18 | file://${COREBASE}/scripts/oe-find-native-sysroot \ | 17 | file://${COREBASE}/scripts/oe-find-native-sysroot \ |
19 | file://${COREBASE}/scripts/runqemu-extract-sdk \ | 18 | file://${COREBASE}/scripts/runqemu-extract-sdk \ |
20 | file://${COREBASE}/scripts/runqemu-export-rootfs \ | 19 | file://${COREBASE}/scripts/runqemu-export-rootfs \ |
21 | file://tunctl.c \ | ||
22 | " | 20 | " |
23 | 21 | ||
24 | S = "${WORKDIR}" | 22 | S = "${WORKDIR}" |
@@ -26,12 +24,11 @@ S = "${WORKDIR}" | |||
26 | inherit nativesdk | 24 | inherit nativesdk |
27 | 25 | ||
28 | do_compile() { | 26 | do_compile() { |
29 | ${CC} tunctl.c -o tunctl | 27 | : |
30 | } | 28 | } |
31 | 29 | ||
32 | do_install() { | 30 | do_install() { |
33 | install -d ${D}${bindir} | 31 | install -d ${D}${bindir} |
34 | install -m 0755 ${WORKDIR}${COREBASE}/scripts/oe-* ${D}${bindir}/ | 32 | install -m 0755 ${WORKDIR}${COREBASE}/scripts/oe-* ${D}${bindir}/ |
35 | install -m 0755 ${WORKDIR}${COREBASE}/scripts/runqemu* ${D}${bindir}/ | 33 | install -m 0755 ${WORKDIR}${COREBASE}/scripts/runqemu* ${D}${bindir}/ |
36 | install tunctl ${D}${bindir}/ | ||
37 | } | 34 | } |
diff --git a/meta/recipes-devtools/qemu/qemu-helper-native_1.0.bb b/meta/recipes-devtools/qemu/qemu-helper-native_1.0.bb index 6053b71717..4d64ea4b93 100644 --- a/meta/recipes-devtools/qemu/qemu-helper-native_1.0.bb +++ b/meta/recipes-devtools/qemu/qemu-helper-native_1.0.bb | |||
@@ -3,25 +3,20 @@ LICENSE = "GPL-2.0-only" | |||
3 | RDEPENDS:${PN} = "qemu-system-native" | 3 | RDEPENDS:${PN} = "qemu-system-native" |
4 | PR = "r1" | 4 | PR = "r1" |
5 | 5 | ||
6 | LIC_FILES_CHKSUM = "file://${WORKDIR}/tunctl.c;endline=4;md5=ff3a09996bc5fff6bc5d4e0b4c28f999" | 6 | LIC_FILES_CHKSUM = "file://${WORKDIR}/qemu-oe-bridge-helper.c;endline=4;md5=ae00a3bab86f2caaa8462eacda77f4d7" |
7 | 7 | ||
8 | SRC_URI = "\ | 8 | SRC_URI = "file://qemu-oe-bridge-helper.c" |
9 | file://tunctl.c \ | ||
10 | file://qemu-oe-bridge-helper.c \ | ||
11 | " | ||
12 | 9 | ||
13 | S = "${WORKDIR}" | 10 | S = "${WORKDIR}" |
14 | 11 | ||
15 | inherit native | 12 | inherit native |
16 | 13 | ||
17 | do_compile() { | 14 | do_compile() { |
18 | ${CC} ${CFLAGS} ${LDFLAGS} -Wall tunctl.c -o tunctl | ||
19 | ${CC} ${CFLAGS} ${LDFLAGS} -Wall qemu-oe-bridge-helper.c -o qemu-oe-bridge-helper | 15 | ${CC} ${CFLAGS} ${LDFLAGS} -Wall qemu-oe-bridge-helper.c -o qemu-oe-bridge-helper |
20 | } | 16 | } |
21 | 17 | ||
22 | do_install() { | 18 | do_install() { |
23 | install -d ${D}${bindir} | 19 | install -d ${D}${bindir} |
24 | install tunctl ${D}${bindir}/ | ||
25 | install qemu-oe-bridge-helper ${D}${bindir}/ | 20 | install qemu-oe-bridge-helper ${D}${bindir}/ |
26 | } | 21 | } |
27 | 22 | ||
diff --git a/meta/recipes-devtools/qemu/qemu-helper/tunctl.c b/meta/recipes-devtools/qemu/qemu-helper/tunctl.c deleted file mode 100644 index d745dd06cb..0000000000 --- a/meta/recipes-devtools/qemu/qemu-helper/tunctl.c +++ /dev/null | |||
@@ -1,158 +0,0 @@ | |||
1 | /* Copyright 2002 Jeff Dike | ||
2 | * Licensed under the GPL | ||
3 | */ | ||
4 | |||
5 | #include <stdio.h> | ||
6 | #include <stdlib.h> | ||
7 | #include <string.h> | ||
8 | #include <errno.h> | ||
9 | #include <fcntl.h> | ||
10 | #include <unistd.h> | ||
11 | #include <pwd.h> | ||
12 | #include <grp.h> | ||
13 | #include <net/if.h> | ||
14 | #include <sys/ioctl.h> | ||
15 | #include <linux/if_tun.h> | ||
16 | |||
17 | /* TUNSETGROUP appeared in 2.6.23 */ | ||
18 | #ifndef TUNSETGROUP | ||
19 | #define TUNSETGROUP _IOW('T', 206, int) | ||
20 | #endif | ||
21 | |||
22 | static void Usage(char *name, int status) | ||
23 | { | ||
24 | fprintf(stderr, "Create: %s [-b] [-u owner] [-g group] [-t device-name] " | ||
25 | "[-f tun-clone-device]\n", name); | ||
26 | fprintf(stderr, "Delete: %s -d device-name [-f tun-clone-device]\n\n", | ||
27 | name); | ||
28 | fprintf(stderr, "The default tun clone device is /dev/net/tun - some systems" | ||
29 | " use\n/dev/misc/net/tun instead\n\n"); | ||
30 | fprintf(stderr, "-b will result in brief output (just the device name)\n"); | ||
31 | exit(status); | ||
32 | } | ||
33 | |||
34 | int main(int argc, char **argv) | ||
35 | { | ||
36 | struct ifreq ifr; | ||
37 | struct passwd *pw; | ||
38 | struct group *gr; | ||
39 | uid_t owner = -1; | ||
40 | gid_t group = -1; | ||
41 | int tap_fd, opt, delete = 0, brief = 0; | ||
42 | char *tun = "", *file = "/dev/net/tun", *name = argv[0], *end; | ||
43 | |||
44 | while((opt = getopt(argc, argv, "bd:f:t:u:g:h")) > 0){ | ||
45 | switch(opt) { | ||
46 | case 'b': | ||
47 | brief = 1; | ||
48 | break; | ||
49 | case 'd': | ||
50 | delete = 1; | ||
51 | tun = optarg; | ||
52 | break; | ||
53 | case 'f': | ||
54 | file = optarg; | ||
55 | break; | ||
56 | case 'u': | ||
57 | pw = getpwnam(optarg); | ||
58 | if(pw != NULL){ | ||
59 | owner = pw->pw_uid; | ||
60 | break; | ||
61 | } | ||
62 | owner = strtol(optarg, &end, 0); | ||
63 | if(*end != '\0'){ | ||
64 | fprintf(stderr, "'%s' is neither a username nor a numeric uid.\n", | ||
65 | optarg); | ||
66 | Usage(name, 1); | ||
67 | } | ||
68 | break; | ||
69 | case 'g': | ||
70 | gr = getgrnam(optarg); | ||
71 | if(gr != NULL){ | ||
72 | group = gr->gr_gid; | ||
73 | break; | ||
74 | } | ||
75 | group = strtol(optarg, &end, 0); | ||
76 | if(*end != '\0'){ | ||
77 | fprintf(stderr, "'%s' is neither a groupname nor a numeric group.\n", | ||
78 | optarg); | ||
79 | Usage(name, 1); | ||
80 | } | ||
81 | break; | ||
82 | |||
83 | case 't': | ||
84 | tun = optarg; | ||
85 | break; | ||
86 | case 'h': | ||
87 | Usage(name, 0); | ||
88 | break; | ||
89 | default: | ||
90 | Usage(name, 1); | ||
91 | } | ||
92 | } | ||
93 | |||
94 | argv += optind; | ||
95 | argc -= optind; | ||
96 | |||
97 | if(argc > 0) | ||
98 | Usage(name, 1); | ||
99 | |||
100 | if((tap_fd = open(file, O_RDWR)) < 0){ | ||
101 | fprintf(stderr, "Failed to open '%s' : ", file); | ||
102 | perror(""); | ||
103 | exit(1); | ||
104 | } | ||
105 | |||
106 | memset(&ifr, 0, sizeof(ifr)); | ||
107 | |||
108 | ifr.ifr_flags = IFF_TAP | IFF_NO_PI; | ||
109 | strncpy(ifr.ifr_name, tun, sizeof(ifr.ifr_name) - 1); | ||
110 | if(ioctl(tap_fd, TUNSETIFF, (void *) &ifr) < 0){ | ||
111 | perror("TUNSETIFF"); | ||
112 | exit(1); | ||
113 | } | ||
114 | |||
115 | if(delete){ | ||
116 | if(ioctl(tap_fd, TUNSETPERSIST, 0) < 0){ | ||
117 | perror("disabling TUNSETPERSIST"); | ||
118 | exit(1); | ||
119 | } | ||
120 | printf("Set '%s' nonpersistent\n", ifr.ifr_name); | ||
121 | } | ||
122 | else { | ||
123 | /* emulate behaviour prior to TUNSETGROUP */ | ||
124 | if(owner == -1 && group == -1) { | ||
125 | owner = geteuid(); | ||
126 | } | ||
127 | |||
128 | if(owner != -1) { | ||
129 | if(ioctl(tap_fd, TUNSETOWNER, owner) < 0){ | ||
130 | perror("TUNSETOWNER"); | ||
131 | exit(1); | ||
132 | } | ||
133 | } | ||
134 | if(group != -1) { | ||
135 | if(ioctl(tap_fd, TUNSETGROUP, group) < 0){ | ||
136 | perror("TUNSETGROUP"); | ||
137 | exit(1); | ||
138 | } | ||
139 | } | ||
140 | |||
141 | if(ioctl(tap_fd, TUNSETPERSIST, 1) < 0){ | ||
142 | perror("enabling TUNSETPERSIST"); | ||
143 | exit(1); | ||
144 | } | ||
145 | |||
146 | if(brief) | ||
147 | printf("%s\n", ifr.ifr_name); | ||
148 | else { | ||
149 | printf("Set '%s' persistent and owned by", ifr.ifr_name); | ||
150 | if(owner != -1) | ||
151 | printf(" uid %d", owner); | ||
152 | if(group != -1) | ||
153 | printf(" gid %d", group); | ||
154 | printf("\n"); | ||
155 | } | ||
156 | } | ||
157 | return(0); | ||
158 | } | ||
diff --git a/scripts/runqemu-gen-tapdevs b/scripts/runqemu-gen-tapdevs index ffb82adce6..4f8ea979d2 100755 --- a/scripts/runqemu-gen-tapdevs +++ b/scripts/runqemu-gen-tapdevs | |||
@@ -1,11 +1,7 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | # | 2 | # |
3 | # Create a "bank" of tap network devices that can be used by the | 3 | # Create a "bank" of tap network devices that can be used by the |
4 | # runqemu script. This script needs to be run as root, and will | 4 | # runqemu script. This script needs to be run as root |
5 | # use the tunctl binary from the build system sysroot. Note: many Linux | ||
6 | # distros these days still use an older version of tunctl which does not | ||
7 | # support the group permissions option, hence the need to use the build | ||
8 | # system provided version. | ||
9 | # | 5 | # |
10 | # Copyright (C) 2010 Intel Corp. | 6 | # Copyright (C) 2010 Intel Corp. |
11 | # | 7 | # |
@@ -62,29 +58,17 @@ if [ ! -x "$RUNQEMU_IFUP" ]; then | |||
62 | exit 1 | 58 | exit 1 |
63 | fi | 59 | fi |
64 | 60 | ||
65 | TUNCTL=$STAGING_BINDIR_NATIVE/tunctl | ||
66 | ip_supports_tuntap=false | ||
67 | if interfaces=`ip tuntap list` 2>/dev/null; then | 61 | if interfaces=`ip tuntap list` 2>/dev/null; then |
68 | ip_supports_tuntap=true | ||
69 | interfaces=`echo "$interfaces |cut -f1 -d:` | 62 | interfaces=`echo "$interfaces |cut -f1 -d:` |
70 | elif [[ ! -x "$TUNCTL" || -d "$TUNCTL" ]]; then | ||
71 | echo "Error: $TUNCTL is not an executable" | ||
72 | usage | ||
73 | elif interfaces=`ip link` 2>/dev/null; then | ||
74 | interfaces=`echo "$interfaces" | sed '/^[0-9]\+: \(docker[0-9]\+\):.*/!d; s//\1/'` | ||
75 | else | 63 | else |
76 | echo "Failed to call 'ip link'" >&2 | 64 | echo "Failed to call 'ip tuntap list'" >&2 |
77 | exit 1 | 65 | exit 1 |
78 | fi | 66 | fi |
79 | 67 | ||
80 | # Ensure we start with a clean slate | 68 | # Ensure we start with a clean slate |
81 | for tap in $interfaces; do | 69 | for tap in $interfaces; do |
82 | echo "Note: Destroying pre-existing tap interface $tap..." | 70 | echo "Note: Destroying pre-existing tap interface $tap..." |
83 | if $ip_supports_tuntap; then | 71 | ip tuntap del $tap mode tap |
84 | ip tuntap del $tap mode tap | ||
85 | else | ||
86 | $TUNCTL -d $tap | ||
87 | fi | ||
88 | done | 72 | done |
89 | rm -f /etc/runqemu-nosudo | 73 | rm -f /etc/runqemu-nosudo |
90 | 74 | ||
@@ -95,8 +79,8 @@ fi | |||
95 | echo "Creating $COUNT tap devices for UID: $TUID GID: $GID..." | 79 | echo "Creating $COUNT tap devices for UID: $TUID GID: $GID..." |
96 | for ((index=0; index < $COUNT; index++)); do | 80 | for ((index=0; index < $COUNT; index++)); do |
97 | echo "Creating tap$index" | 81 | echo "Creating tap$index" |
98 | if ! ifup=`$RUNQEMU_IFUP $TUID $GID $STAGING_BINDIR_NATIVE 2>&1`; then | 82 | if ! ifup=`$RUNQEMU_IFUP $TUID $GID 2>&1`; then |
99 | echo "Error running tunctl: $ifup" | 83 | echo "Error bringing up interface: $ifup" |
100 | exit 1 | 84 | exit 1 |
101 | fi | 85 | fi |
102 | done | 86 | done |
diff --git a/scripts/runqemu-ifdown b/scripts/runqemu-ifdown index f72166b32b..98ac7f07b3 100755 --- a/scripts/runqemu-ifdown +++ b/scripts/runqemu-ifdown | |||
@@ -1,8 +1,7 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | # | 2 | # |
3 | # QEMU network configuration script to bring down tap devices. This | 3 | # QEMU network configuration script to bring down tap devices. This |
4 | # utility needs to be run as root, and will use the tunctl binary | 4 | # utility needs to be run as root, and will use the ip utility |
5 | # from the native sysroot. | ||
6 | # | 5 | # |
7 | # If you find yourself calling this script a lot, you can add the | 6 | # If you find yourself calling this script a lot, you can add the |
8 | # the following to your /etc/sudoers file to be able to run this | 7 | # the following to your /etc/sudoers file to be able to run this |
@@ -34,13 +33,8 @@ TAP=$1 | |||
34 | STAGING_BINDIR_NATIVE=$2 | 33 | STAGING_BINDIR_NATIVE=$2 |
35 | 34 | ||
36 | if !ip tuntap del $TAP mode tap 2>/dev/null; then | 35 | if !ip tuntap del $TAP mode tap 2>/dev/null; then |
37 | TUNCTL=$STAGING_BINDIR_NATIVE/tunctl | 36 | echo "Error: Unable to run up tuntap del" |
38 | if [ ! -e "$TUNCTL" ]; then | 37 | exit 1 |
39 | echo "Error: Unable to find tunctl binary in '$STAGING_BINDIR_NATIVE', please bitbake qemu-helper-native" | ||
40 | exit 1 | ||
41 | fi | ||
42 | |||
43 | $TUNCTL -d $TAP | ||
44 | fi | 38 | fi |
45 | 39 | ||
46 | IFCONFIG=`which ip 2> /dev/null` | 40 | IFCONFIG=`which ip 2> /dev/null` |
diff --git a/scripts/runqemu-ifup b/scripts/runqemu-ifup index 5fdcddeeda..237bf2a07b 100755 --- a/scripts/runqemu-ifup +++ b/scripts/runqemu-ifup | |||
@@ -1,10 +1,7 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | # | 2 | # |
3 | # QEMU network interface configuration script. This utility needs to | 3 | # QEMU network interface configuration script. This utility needs to |
4 | # be run as root, and will use the tunctl binary from a native sysroot. | 4 | # be run as root, and will use the ip utility |
5 | # Note: many Linux distros these days still use an older version of | ||
6 | # tunctl which does not support the group permissions option, hence | ||
7 | # the need to use build system's version. | ||
8 | # | 5 | # |
9 | # If you find yourself calling this script a lot, you can add the | 6 | # If you find yourself calling this script a lot, you can add the |
10 | # the following to your /etc/sudoers file to be able to run this | 7 | # the following to your /etc/sudoers file to be able to run this |
@@ -39,7 +36,6 @@ fi | |||
39 | 36 | ||
40 | USERID="-u $1" | 37 | USERID="-u $1" |
41 | GROUP="-g $2" | 38 | GROUP="-g $2" |
42 | STAGING_BINDIR_NATIVE=$3 | ||
43 | 39 | ||
44 | if taps=$(ip tuntap list 2>/dev/null); then | 40 | if taps=$(ip tuntap list 2>/dev/null); then |
45 | tap_no=$(( $(echo "$taps" |sort -r |sed 's/^tap//; s/:.*//; q') + 1 )) | 41 | tap_no=$(( $(echo "$taps" |sort -r |sed 's/^tap//; s/:.*//; q') + 1 )) |
@@ -47,24 +43,8 @@ if taps=$(ip tuntap list 2>/dev/null); then | |||
47 | fi | 43 | fi |
48 | 44 | ||
49 | if [ -z $TAP ]; then | 45 | if [ -z $TAP ]; then |
50 | TUNCTL=$STAGING_BINDIR_NATIVE/tunctl | 46 | echo "Error: Unable to find a tap device to use" |
51 | if [ ! -x "$TUNCTL" ]; then | 47 | exit 1 |
52 | echo "Error: Unable to find tunctl binary in '$STAGING_BINDIR_NATIVE', please bitbake qemu-helper-native" | ||
53 | exit 1 | ||
54 | fi | ||
55 | |||
56 | TAP=`$TUNCTL -b $GROUP 2>&1` | ||
57 | STATUS=$? | ||
58 | if [ $STATUS -ne 0 ]; then | ||
59 | # If tunctl -g fails, try using tunctl -u, for older host kernels | ||
60 | # which do not support the TUNSETGROUP ioctl | ||
61 | TAP=`$TUNCTL -b $USERID 2>&1` | ||
62 | STATUS=$? | ||
63 | if [ $STATUS -ne 0 ]; then | ||
64 | echo "tunctl failed:" | ||
65 | exit 1 | ||
66 | fi | ||
67 | fi | ||
68 | fi | 48 | fi |
69 | 49 | ||
70 | IFCONFIG=`which ip 2> /dev/null` | 50 | IFCONFIG=`which ip 2> /dev/null` |