OpenWRT v22.03.3 のOpenConnect VPN Serverパッケージ ocserv が、レポジトリで利用不能になっていたので、クロスコンパイル環境を構築してソースから自分で ビルド しました。
レポジトリから消えたocservパッケージ
Celeron J4125ミニPC上のVMware ESXi 8.0に、仮想マシンとして構築したOpenWRTルータ(OpenWrt v22.03.3を使用)へ、Cisco AnyConnect互換のOpenConnect VPN Serverパッケージ、 ocserv (GL-iNet GL-AR750Sへのインストール記事はこちら)をインストールしようとしたところ、パッケージが見つからないエラーに遭遇。
CLIから直接インストールしようとしてもやはりエラー。
1 2 3 4 |
# opkg install ocserv Unknown package 'ocserv'. Collected errors: * opkg_install_cmd: Cannot install package ocserv. |
調べてみると、使用する一部ライブラリとの依存性に問題があるとのことで、敢えて収録から外されている模様。
実際にはそのライブラリを使用していないことから、無効化するようレポジトリにあるMakefileは編集されていました。
ここまで来れば、数日後でパッケージも再び利用可能になるものですが、せっかくなので自分でコンパイルしてみようと思います。
OpenWRTクロスコンパイル環境を構築
OpenWRTのクロスコンパイル環境に今回使うUbuntu 18.04デスクトップPCは、何度か通常のパッケージビルドに使ったことがあるので、 build-essential など必要なパッケージはインストール済みです。
まず、OpenWRTソースレポジトリを git clone してその中へ。
1 2 3 4 5 6 7 8 9 |
~$ git clone https://git.openwrt.org/openwrt/openwrt.git/ Cloning into 'openwrt'... remote: Enumerating objects: 19729, done. remote: Counting objects: 100% (19729/19729), done. remote: Compressing objects: 100% (11144/11144), done. remote: Total 631107 (delta 12470), reused 12715 (delta 7887), pack-reused 611378 Receiving objects: 100% (631107/631107), 183.89 MiB | 1.73 MiB/s, done. Resolving deltas: 100% (440381/440381), done. ~$ cd openwrt |
次にフィードをアップデートの上、インストールします(所要5分程度)。ここで feeds/packages/net/ 内にocservのソースが現れます。
1 2 |
~/openwrt$ ./scripts/feeds update -a ~/openwrt$ ./scripts/feeds install -a |
Make環境をテキストベースUIで設定します。設定前は以下のようになっているので、
対象環境を x86_64 に指定して、パッケージカテゴリの Network へ進みます。
Network > VPN とサブカテゴリを進んだ中に ocserv パッケージがあるので、選択状態にします。
何度か試していて、 usign が見つからないエラーに遭遇したことがあったので、ここで Base system カテゴリにある usign にチェックが入っているか、念のため確認します。
Exit する前には、必ず Save で .config ファイルに出力するのを忘れずに。

図6.configファイル書き出し
続いてのツールインストールでは、小一時間掛かりました。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
~/openwrt$ make tools/install make[2]: Entering directory '~/openwrt/scripts/config' cc -O2 -c -o conf.o conf.c cc conf.o confdata.o expr.o lexer.lex.o menu.o parser.tab.o preprocess.o symbol.o util.o -o conf make[2]: Leaving directory '~/openwrt/scripts/config' time: target/linux/prereq#0.12#0.03#0.16 make[1] tools/install make[2] -C tools/flock compile make[2] -C tools/xz compile make[2] -C tools/sed compile make[2] -C tools/tar compile make[2] -C tools/patch compile make[2] -C tools/m4 compile make[2] -C tools/autoconf compile make[2] -C tools/autoconf-archive compile make[2] -C tools/ninja compile make[2] -C tools/meson compile make[2] -C tools/pkgconf compile make[2] -C tools/automake compile make[2] -C tools/missing-macros compile make[2] -C tools/libtool compile make[2] -C tools/flex compile make[2] -C tools/bison compile make[2] -C tools/bc compile make[2] -C tools/libressl compile make[2] -C tools/expat compile make[2] -C tools/zlib compile make[2] -C tools/zstd compile make[2] -C tools/cmake compile make[2] -C tools/cpio compile make[2] -C tools/dosfstools compile make[2] -C tools/e2fsprogs compile make[2] -C tools/fakeroot compile make[2] -C tools/findutils compile make[2] -C tools/firmware-utils compile make[2] -C tools/gengetopt compile make[2] -C tools/libdeflate compile make[2] -C tools/lzma compile make[2] -C tools/make-ext4fs compile make[2] -C tools/mkimage compile make[2] -C tools/mklibs compile make[2] -C tools/mtd-utils compile make[2] -C tools/mtools compile make[2] -C tools/padjffs2 compile make[2] -C tools/patch-image compile make[2] -C tools/patchelf compile make[2] -C tools/quilt compile make[2] -C tools/squashfskit4 compile make[2] -C tools/sstrip compile make[2] -C tools/zip compile make[2] -C tools/gmp compile make[2] -C tools/mpfr compile make[2] -C tools/mpc compile make[2] -C tools/elfutils compile |
ツールチェインのインストールもしっかり1時間掛かりました。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
~/openwrt$ make toolchain/install make[2]: Entering directory '~/openwrt/scripts/config' make[2]: 'conf' is up to date. make[2]: Leaving directory '~/openwrt/scripts/config' make[1] toolchain/install make[2] tools/compile make[3] -C tools/flock compile make[3] -C tools/xz compile make[3] -C tools/sed compile make[3] -C tools/tar compile make[3] -C tools/patch compile make[3] -C tools/m4 compile make[3] -C tools/autoconf compile make[3] -C tools/autoconf-archive compile make[3] -C tools/ninja compile make[3] -C tools/meson compile make[3] -C tools/pkgconf compile make[3] -C tools/automake compile make[3] -C tools/missing-macros compile make[3] -C tools/libtool compile make[3] -C tools/flex compile make[3] -C tools/bison compile make[3] -C tools/bc compile make[3] -C tools/libressl compile make[3] -C tools/expat compile make[3] -C tools/zlib compile make[3] -C tools/zstd compile make[3] -C tools/cmake compile make[3] -C tools/cpio compile make[3] -C tools/dosfstools compile make[3] -C tools/e2fsprogs compile make[3] -C tools/fakeroot compile make[3] -C tools/findutils compile make[3] -C tools/firmware-utils compile make[3] -C tools/gengetopt compile make[3] -C tools/libdeflate compile make[3] -C tools/lzma compile make[3] -C tools/make-ext4fs compile make[3] -C tools/mkimage compile make[3] -C tools/mklibs compile make[3] -C tools/mtd-utils compile make[3] -C tools/mtools compile make[3] -C tools/padjffs2 compile make[3] -C tools/patch-image compile make[3] -C tools/patchelf compile make[3] -C tools/quilt compile make[3] -C tools/squashfskit4 compile make[3] -C tools/sstrip compile make[3] -C tools/zip compile make[3] -C tools/gmp compile make[3] -C tools/mpfr compile make[3] -C tools/mpc compile make[3] -C tools/elfutils compile make[2] -C toolchain/gdb compile make[2] -C toolchain/binutils compile make[2] -C toolchain/gcc/initial compile make[2] -C toolchain/kernel-headers compile make[2] -C toolchain/musl compile make[2] -C toolchain/gcc/final compile make[2] -C toolchain/fortify-headers compile make[2] -C toolchain/nasm compile |
パッケージをビルド
ocserv の前に、依存関係にある base-files をコンパイルします(所要10分)。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
~/openwrt$ make package/base-files/compile make[2]: Entering directory '~/openwrt/scripts/config' make[2]: 'conf' is up to date. make[2]: Leaving directory '~/openwrt/scripts/config' make[1] package/base-files/compile make[2] -C package/libs/toolchain compile make[2] -C package/libs/libnl-tiny compile make[2] -C package/libs/libjson-c compile make[2] -C package/utils/lua compile make[2] -C package/libs/libubox compile make[2] -C package/system/ubus compile make[2] -C package/system/uci compile make[2] -C package/network/config/netifd compile make[2] -C package/firmware/linux-firmware compile make[2] -C package/kernel/gpio-button-hotplug compile make[2] -C package/kernel/linux compile make[2] -C package/system/ubox compile make[2] -C package/libs/ncurses host-compile make[2] -C package/libs/zlib compile make[2] -C package/libs/ncurses compile make[2] -C package/utils/util-linux compile make[2] -C package/system/fstools compile make[2] -C package/system/fwtool host-compile make[2] -C package/system/fwtool compile make[2] -C package/libs/libjson-c host-compile make[2] -C package/libs/libubox host-compile make[2] -C package/system/usign host-compile make[2] -C package/system/ucert host-compile make[2] -C package/utils/jsonfilter compile make[2] -C package/system/openwrt-keyring compile make[2] -C package/system/usign compile make[2] -C package/base-files compile |
そしてようやく ocserv パッケージの番です。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
~/openwrt$ make package/ocserv/compile make[2]: Entering directory '~/openwrt/scripts/config' make[2]: 'conf' is up to date. make[2]: Leaving directory '~/openwrt/scripts/config' make[1] package/ocserv/compile make[2] -C package/libs/gettext-full host-compile make[2] -C package/libs/toolchain compile make[2] -C package/libs/gmp compile make[2] -C package/libs/nettle compile make[2] -C feeds/packages/libs/gnutls compile make[2] -C feeds/packages/libs/libev compile make[2] -C package/firmware/linux-firmware compile make[2] -C package/kernel/gpio-button-hotplug compile make[2] -C package/kernel/linux compile make[2] -C package/libs/ncurses host-compile make[2] -C package/libs/zlib compile make[2] -C package/libs/ncurses compile make[2] -C package/libs/readline compile make[2] -C feeds/packages/libs/libhttp-parser compile make[2] -C feeds/packages/libs/protobuf compile make[2] -C feeds/packages/libs/protobuf-c compile make[2] -C feeds/packages/net/ocserv compile |
30分後、以下の場所にパッケージファイルが出来上がっていました。
1 2 |
~/openwrt$ ls -l bin/packages/x86_64/packages/ocserv* -rw-r--r-- 1 user user 262373 Jan 13 12:30 bin/packages/x86_64/packages/ocserv_1.1.6-2_x86_64.ipk |
パッケージのインストール
ブラウザでOpenWRT LuCiを開き、メニューのStstem内にあるSoftwareページから、出来上がったパッケージをアップロード・インストールすることができます。
今回は初めてのビルドに試行錯誤を繰り返しているうちに、公式レポジトリの方が早くパッケージを利用可能に戻していました。
参考)