darwin.network_cmds: convert to Meson and use mkAppleDerivation

This commit is contained in:
Randy Eckenrode 2024-09-22 10:03:56 -04:00
parent 4b4270cca3
commit 822a865209
No known key found for this signature in database
GPG Key ID: 64C1CD4EC2A600D9
6 changed files with 1133 additions and 57 deletions

View File

@ -311,9 +311,7 @@ developerToolsPackages_11_3_1 // macosPackages_11_0_1 // {
basic_cmds = callPackage ./basic_cmds/package.nix { };
developer_cmds = callPackage ./developer_cmds/package.nix { };
diskdev_cmds = callPackage ./diskdev_cmds/package.nix { };
network_cmds = if isSdk10_12 then
applePackage "network_cmds" "osx-10.11.6" "sha256-I89CLIswGheewOjiNZwQTgWvWbhm0qtB5+KUqzxnQ5M=" {}
else macosPackages_11_0_1.network_cmds;
network_cmds = callPackage ./network_cmds/package.nix { };
file_cmds = callPackage ./file_cmds/package.nix { };
shell_cmds = applePackage "shell_cmds" "osx-10.11.6" "sha256-kmEOprkiJGMVcl7yHkGX8ymk/5KjE99gWuF8j2hK5hY=" {};
system_cmds = applePackage "system_cmds" "macos-14.3" "sha256-qFp9nkzsq9uQ7zoyfvO+3gvDlc7kaPvn6luvmO/Io30=" {};

View File

@ -1,54 +0,0 @@
{ lib, appleDerivation, xcbuildHook
, Librpcsvc, xnu, libpcap, developer_cmds }:
appleDerivation {
nativeBuildInputs = [ xcbuildHook ];
buildInputs = [ xnu Librpcsvc libpcap developer_cmds ];
# Work around error from <stdio.h> on aarch64-darwin:
# error: 'TARGET_OS_IPHONE' is not defined, evaluates to 0 [-Werror,-Wundef-prefix=TARGET_OS_]
env.NIX_CFLAGS_COMPILE = "-Wno-error=undef-prefix -I./unbound -I${xnu}/Library/Frameworks/System.framework/Headers/";
# "spray" requires some files that aren't compiling correctly in xcbuild.
# "rtadvd" seems to fail with some missing constants.
# "traceroute6" and "ping6" require ipsec which doesn't build correctly
# "unbound" doesnt build against supported versions of OpenSSL or LibreSSL
patchPhase = ''
substituteInPlace network_cmds.xcodeproj/project.pbxproj \
--replace "7294F0EA0EE8BAC80052EC88 /* PBXTargetDependency */," "" \
--replace "7216D34D0EE89FEC00AE70E4 /* PBXTargetDependency */," "" \
--replace "72CD1D9C0EE8C47C005F825D /* PBXTargetDependency */," "" \
--replace "7216D2C20EE89ADF00AE70E4 /* PBXTargetDependency */," "" \
--replace "71D958C51A9455A000C9B286 /* PBXTargetDependency */," ""
'';
# temporary install phase until xcodebuild has "install" support
installPhase = ''
for f in Products/Release/*; do
if [ -f $f ]; then
install -D $f $out/bin/$(basename $f)
fi
done
for n in 1 5; do
mkdir -p $out/share/man/man$n
install */*.$n $out/share/man/man$n
done
# TODO: patch files to load from $out/ instead of /usr/
# mkdir -p $out/etc/
# install rtadvd.tproj/rtadvd.conf ip6addrctl.tproj/ip6addrctl.conf $out/etc/
# mkdir -p $out/local/OpenSourceVersions/
# install network_cmds.plist $out/local/OpenSourceVersions/
# mkdir -p $out/System/Library/LaunchDaemons
# install kdumpd.tproj/com.apple.kdumpd.plist $out/System/Library/LaunchDaemons
'';
meta = {
platforms = lib.platforms.darwin;
maintainers = with lib.maintainers; [ matthewbauer ];
};
}

View File

@ -0,0 +1,379 @@
# Build settings based on the upstream Xcode project.
# See: https://github.com/apple-oss-distributions/network_cmds/blob/main/network_cmds.xcodeproj/project.pbxproj
# Project settings
project('network_cmds', 'c', version : '@version@')
add_global_arguments(
'-DTARGET_OS_OSX=1', # Needed for static builds.
# Many programs use old prototypes
'-Wno-deprecated-non-prototype',
# Suppresses suffixing symbols with '$UNIX2003', which causes link failures.
'-D__DARWIN_ONLY_UNIX_CONFORMANCE=1',
# Use 64-bit inode symbols without an '$INODE64' suffix, which causes link failures.
'-D__DARWIN_ONLY_64_BIT_INO_T=1',
# Per the Xcode project
'-DUSE_RFC2292BIS=1',
'-D__APPLE_USE_RFC_3542=1',
'-D__APPLE_API_OBSOLETE=1',
language : 'c',
)
# Generators
rpcgen_bin = find_program('rpcgen')
rpcgen = generator(
rpcgen_bin,
arguments : [ '-c', '-o', '@OUTPUT@', '@INPUT@' ],
output : '@BASENAME@_xdr.c',
)
rpcgen_header = generator(
rpcgen_bin,
arguments : [ '-h', '-o', '@OUTPUT@', '@INPUT@' ],
output : '@BASENAME@.h',
)
# Dependencies
cc = meson.get_compiler('c')
libipsec = cc.find_library('ipsec')
libresolv = cc.find_library('resolv')
libpcap = dependency('pcap')
openssl = dependency('openssl')
# Internal Libraries
corecrypto = declare_dependency(
dependencies : [ openssl ],
include_directories : 'compat',
link_with : static_library(
'corecrypto',
include_directories : 'compat',
sources : [
'compat/corecrypto/ccdigest.c',
'compat/corecrypto/ccsha1.c',
'compat/corecrypto/ccsha2.c',
],
),
)
libnetwork_cmds = declare_dependency(
include_directories : 'network_cmds_lib',
link_with : static_library(
'network_cmds',
include_directories : 'network_cmds_lib',
sources : [
'network_cmds_lib/network_cmds_lib.c',
'network_cmds_lib/network_cmds_lib_test.c',
],
),
)
# Binaries
executable(
'arp',
dependencies : [ libnetwork_cmds ],
install : true,
sources : [ 'arp.tproj/arp.c' ],
)
install_man(
'arp.tproj/arp.8',
'arp.tproj/arp4.4',
)
executable(
'cfilutil',
dependencies : [ corecrypto ],
install : true,
sources : [
'cfilutil/cfilstat.c',
'cfilutil/cfilutil.c',
],
)
install_man('cfilutil/cfilutil.1')
executable(
'dnctl',
install : true,
sources : [ 'dnctl/dnctl.c' ],
)
install_man('dnctl/dnctl.8')
executable(
'ecnprobe',
dependencies : [ libnetwork_cmds, libpcap ],
install : true,
sources : [
'ecnprobe/capture.c',
'ecnprobe/ecn.c',
'ecnprobe/ecn_probe.c',
'ecnprobe/gmt2local.c',
'ecnprobe/history.c',
'ecnprobe/inet.c',
'ecnprobe/session.c',
'ecnprobe/support.c',
],
)
install_man('ecnprobe/ecnprobe.1')
executable(
'frame_delay',
install : true,
sources : [ 'frame_delay/frame_delay.c' ],
)
install_man('frame_delay/frame_delay.8')
executable(
'ifconfig',
c_args : [
'-DUSE_BONDS',
'-DUSE_VLANS',
'-DTARGET_OS_IPHONE=0', # Silence error related to undefined target macro
],
install : true,
sources : [
'ifconfig.tproj/af_inet.c',
'ifconfig.tproj/af_inet6.c',
'ifconfig.tproj/af_link.c',
'ifconfig.tproj/ifbond.c',
'ifconfig.tproj/ifbridge.c',
'ifconfig.tproj/ifclone.c',
'ifconfig.tproj/ifconfig.c',
'ifconfig.tproj/iffake.c',
'ifconfig.tproj/ifmedia.c',
'ifconfig.tproj/ifvlan.c',
'ifconfig.tproj/nexus.c',
],
)
install_man('ifconfig.tproj/ifconfig.8')
executable(
'ip6addrctl',
install : true,
sources : [ 'ip6addrctl.tproj/ip6addrctl.c' ],
)
install_man('ip6addrctl.tproj/ip6addrctl.8')
executable(
'kdumpd',
dependencies : [ libnetwork_cmds ],
install : true,
sources : [
'kdumpd.tproj/kdumpd.c',
'kdumpd.tproj/kdumpsubs.c',
],
)
install_man('kdumpd.tproj/kdumpd.8')
executable(
'mnc',
install : true,
sources : [
'mnc.tproj/mnc_main.c',
'mnc.tproj/mnc_multicast.c',
'mnc.tproj/mnc_opts.c',
],
)
install_man('mnc.tproj/mnc.1')
executable(
'mptcp_client',
install : true,
sources : [
'mptcp_client/conn_lib.c',
'mptcp_client/mptcp_client.c',
],
)
install_man('mptcp_client/mptcp_client.1')
executable(
'mtest',
install : true,
sources : [ 'mtest.tproj/mtest.c' ],
)
install_man('mtest.tproj/mtest.8')
executable(
'ndp',
c_args : [
'-DINET6',
'-DISPEC_DEBUG',
'-DKAME_SCOPEID',
],
install : true,
sources : [ 'ndp.tproj/ndp.c' ],
)
install_man('ndp.tproj/ndp.8')
executable(
'netstat',
c_args : [
'-DINET6',
'-DIPSEC',
],
dependencies : [ libnetwork_cmds ],
install : true,
sources : [
# 'netstat.tproj/bpf.c',
'netstat.tproj/data.c',
'netstat.tproj/if.c',
'netstat.tproj/inet.c',
'netstat.tproj/inet6.c',
'netstat.tproj/ipsec.c',
'netstat.tproj/main.c',
'netstat.tproj/mbuf.c',
'netstat.tproj/mcast.c',
'netstat.tproj/misc.c',
'netstat.tproj/mptcp.c',
'netstat.tproj/route.c',
'netstat.tproj/systm.c',
'netstat.tproj/tp_astring.c',
'netstat.tproj/unix.c',
'netstat.tproj/vsock.c',
],
)
install_man('netstat.tproj/netstat.1')
executable(
'ping',
dependencies : [ libnetwork_cmds ],
install : true,
sources : [
'ecnprobe/gmt2local.c',
'ping.tproj/ping.c'
],
)
install_man('ping.tproj/ping.8')
executable(
'ping6',
dependencies : [ libnetwork_cmds, libresolv ],
install : true,
sources : [
'ecnprobe/gmt2local.c',
'ping6.tproj/md5.c',
'ping6.tproj/ping6.c',
],
)
install_man('ping6.tproj/ping6.8')
executable(
'pktapctl',
install : true,
sources : [ 'pktapctl/pktapctl.c' ],
)
install_man('pktapctl/pktapctl.8')
executable(
'pktmnglr',
install : true,
sources : [ 'pktmnglr/packet_mangler.c' ],
)
executable(
'rarpd',
c_args : [ '-DTFTP_DIR="tftpboot"' ],
install : true,
sources : [ 'rarpd.tproj/rarpd.c' ],
)
install_man('rarpd.tproj/rarpd.8')
executable(
'route',
c_args : [
'-DINET6',
'-DIPSEC',
],
dependencies : [ libnetwork_cmds ],
install : true,
sources : [ 'route.tproj/route.c' ],
)
install_man('route.tproj/route.8')
# Depends on a bunch of IPv6 stuff from later SDKs (>11.3). Package once those become the default.
# executable(
# 'rtadvd',
# c_args : [
# '-DINET6',
# '-DHAVE_GETIFADDRS',
# ],
# install : true,
# sources : [
# 'rtadvd.tproj/advcap.c',
# 'rtadvd.tproj/config.c',
# 'rtadvd.tproj/dump.c',
# 'rtadvd.tproj/if.c',
# 'rtadvd.tproj/rrenum.c',
# 'rtadvd.tproj/rtadvd.c',
# 'rtadvd.tproj/rtadvd_logging.c',
# 'rtadvd.tproj/timer.c',
# ],
# )
# install_man(
# 'rtadvd.tproj/rtadvd.8',
# 'rtadvd.tproj/rtadvd.conf.5',
# )
executable(
'rtsol',
c_args : [
'-DINET6',
'-DHAVE_GETIFADDRS',
],
install : true,
sources : [
'rtsol.tproj/dump.c',
'rtsol.tproj/if.c',
'rtsol.tproj/probe.c',
'rtsol.tproj/rtsock.c',
'rtsol.tproj/rtsol.c',
'rtsol.tproj/rtsold.c',
],
)
install_man('rtsol.tproj/rtsol.8')
executable(
'spray',
install : true,
sources : [
'spray.tproj/spray.c',
rpcgen_header.process('spray.tproj/spray.x'),
rpcgen.process('spray.tproj/spray.x'),
],
)
install_man('spray.tproj/spray.8')
executable(
'traceroute',
c_args : [ '-DHAVE_SOCKADDR_SA_LEN' ],
dependencies : [ libnetwork_cmds, libpcap ],
install : true,
sources : [
'traceroute.tproj/as.c',
'traceroute.tproj/findsaddr-socket.c',
'traceroute.tproj/ifaddrlist.c',
'traceroute.tproj/traceroute.c',
'traceroute.tproj/version.c',
],
)
install_man('traceroute.tproj/traceroute.8')
executable(
'traceroute6',
c_args : [
'-include', 'net/if_var.h', # Fix missing definition of `IFNAMSIZE`
'-DINET6',
'-DIPSEC',
],
dependencies : [ libipsec, libnetwork_cmds, libpcap ],
include_directories : 'traceroute.tproj',
install : true,
sources : [
'traceroute.tproj/as.c',
'traceroute6.tproj/traceroute6.c'
],
)
install_man('traceroute6.tproj/traceroute6.8')

View File

@ -0,0 +1,438 @@
{
lib,
apple-sdk_11,
developer_cmds,
fetchurl,
libpcap,
libresolv,
mkAppleDerivation,
openssl,
pkg-config,
stdenvNoCC,
unifdef,
}:
let
# Newer releases of ifconfig use `ioctls` and undocumented APIs newer than 11.x.
# Use files from an older release for now.
old_ifconfig = {
ifconfig = fetchurl {
url = "https://github.com/apple-oss-distributions/network_cmds/raw/2e18102a14ab72b25caf3a5007c92b9f23e723fc/ifconfig.tproj/ifconfig.c";
hash = "sha256-yuUpdRHRwYLnivuaQuh8HJdLj/8ppq+K1NFqA8Bg+1k=";
};
af_inet = fetchurl {
url = "https://github.com/apple-oss-distributions/network_cmds/raw/2e18102a14ab72b25caf3a5007c92b9f23e723fc/ifconfig.tproj/af_inet.c";
hash = "sha256-sqcCEzhTur43DG6Ac/1Rt8Kx0umWhDzlV58t+6FlzNU=";
};
af_inet6 = fetchurl {
url = "https://github.com/apple-oss-distributions/network_cmds/raw/2e18102a14ab72b25caf3a5007c92b9f23e723fc/ifconfig.tproj/af_inet6.c";
hash = "sha256-jp0R0Ncwvp9G/lIzKW6wBTAiO8yNyII5c49feTanbIo=";
};
af_link = fetchurl {
url = "https://github.com/apple-oss-distributions/network_cmds/raw/2e18102a14ab72b25caf3a5007c92b9f23e723fc/ifconfig.tproj/af_link.c";
hash = "sha256-5rXJg5azy9SjK675Djt4K1PaczsoVjQ/Lls/u5Kk1+A=";
};
};
# Newer releases of netstat use struct members that arent present with the 11.x headers.
# Use files from an older release for now.
old_netstat = {
"if" = fetchurl {
url = "https://github.com/apple-oss-distributions/network_cmds/raw/2e18102a14ab72b25caf3a5007c92b9f23e723fc/netstat.tproj/if.c";
hash = "sha256-P87rexLkoV1BCyUghVrkGoG6r9rAoWynfpvlwIj7A40=";
};
main = fetchurl {
url = "https://github.com/apple-oss-distributions/network_cmds/raw/2e18102a14ab72b25caf3a5007c92b9f23e723fc/netstat.tproj/main.c";
hash = "sha256-e3n54l6Wo+G5koMhGMfOTo8+QIkJRurr2fBOjg/nFgI=";
};
};
xnu = apple-sdk_11.sourceRelease "xnu";
privateHeaders = stdenvNoCC.mkDerivation {
name = "network_cmds-deps-private-headers";
nativeBuildInputs = [ unifdef ];
buildCommand = ''
# Different strategies are needed to make private headers available to network_cmds:
# - If the headers can be used as-is, copy them;
# - If the required symbols are hidden behind a 'PRIVATE' define, `unifdef` is used to expose only those symbols
# for that header. Processing the header avoids exposing unwanted private symbols and requiring more headers;
# - If the symbol is hidden behind a kernel-related define, grep them out of the header. Otherwise,
# the required headers can conflict with system-related headers and require many, many more headers be copied.
install -D -t "$out/include" \
'${xnu}/osfmk/kern/cs_blobs.h'
install -D -t "$out/firehose" \
'${xnu}/libkern/firehose/tracepoint_private.h'
install -D -t "$out/include/net" \
'${xnu}/bsd/net/if_bond_internal.h' \
'${xnu}/bsd/net/if_bond_var.h' \
'${xnu}/bsd/net/if_fake_var.h' \
'${xnu}/bsd/net/if_vlan_var.h' \
'${xnu}/bsd/net/lacp.h' \
'${xnu}/bsd/net/net_perf.h'
mkdir -p "$out/include/net/classq" "$out/include/net/pktsched"
# IFNET constants are defined as enums, so they have to be pre-processed and grepped from the file.
cat <<EOF > "$out/include/net/if.h"
#pragma once
#include <uuid/uuid.h>
$(sed \
-e 's/^\s*\(IFNET_[^=]*\)=\s*\([^,]*\),*/#define \1\2/' \
'${xnu}/bsd/net/if.h' | grep '^#define IFNET_')
#include_next <net/if.h>
#include <netinet/in.h>
#define ifreq ifreq_private
$(sed -n \
-e '/^#define IFEF_TXSTART/p' \
-e '/^#define IFLPRF/p' \
-e '/^#define IFNAMSIZ\s/p' \
-e '/^#define IFRLOGF/p' \
-e '/^#define IFRTYPE/p' \
-e '/^#define IF_DESCSIZE\s/p' \
-e '/^#define IF_NAMESIZE\s/p' \
-e '/^#define NAT64_MAX_NUM_PREFIXES\s/p' \
-e '/^#define ifr_fastlane_capable\s/p' \
-e '/^#define ifr_fastlane_enabled\s/p' \
-e '/^#define ifr_qosmarking_enabled\s/p' \
-e '/^#define ifr_qosmarking_mode\s/p' \
-e '/^struct if_agentidsreq\s*{/,/^};/p' \
-e '/^struct if_clat46req\s*{/,/^};/p' \
-e '/^struct if_descreq\s*{/,/^};/p' \
-e '/^struct if_ipv6_address\s*{/,/^};/p' \
-e '/^struct if_linkparamsreq\s*{/,/^};/p' \
-e '/^struct if_qstatsreq\s*{/,/^};/p' \
-e '/^struct if_nat64req\s*{/,/^};/p' \
-e '/^struct if_nexusreq\s*{/,/^};/p' \
-e '/^struct if_throttlereq\s*{/,/^};/p' \
-e '/^struct ipv6_prefix\s*{/,/^};/p' \
-e '/^struct ifreq\s*{/,/^};/p' \
'${xnu}/bsd/net/if.h')
#undef ifreq
EOF
unifdef -x 1 -DPRIVATE -m "$out/include/net/if.h"
cat <<EOF > "$out/include/net/content_filter.h"
#pragma once
#include <uuid/uuid.h>
#include <net/content_filter_impl.h>
EOF
cat <<EOF > "$out/include/net/if_var.h"
#pragma once
#include_next <net/if_var.h>
$(sed -n \
-e '/^#define IFNAMSIZ\s/p' \
-e '/^#define IF_NETEM/p' \
-e '/^struct if_bandwidths\s*{/,/^};/p' \
-e '/^struct if_data_extended\s*{/,/^};/p' \
-e '/^struct if_interface_state\s*{/,/^};/p' \
-e '/^struct if_latencies\s*{/,/^};/p' \
-e '/^struct if_linkparamsreq\s*{/,/^};/p' \
-e '/^struct if_netem_params\s*{/,/^};/p' \
-e '/^struct if_netif_stats\s*{/,/^};/p' \
-e '/^struct if_packet_stats\s*{/,/^};/p' \
-e '/^struct if_rxpoll_stats\s*{/,/^};/p' \
-e '/^struct if_traffic_class\s*{/,/^};/p' \
'${xnu}/bsd/net/if_var.h')
EOF
cat <<EOF > "$out/include/net/route.h"
#pragma once
#include_next <net/route.h>
$(sed -n \
-e '/^struct rt_msghdr_ext\s*{/,/^};/p' \
-e '/^struct rt_reach_info\s*{/,/^};/p' \
'${xnu}/bsd/net/route.h')
EOF
install -D -t "$out/include/netinet" \
'${xnu}/bsd/netinet/ip_flowid.h'
cat <<EOF > "$out/include/netinet/in.h"
#pragma once
#include_next <netinet/in.h>
$(sed -n \
-e '/^#define _DSCP/p' \
-e '/^#define IP_NO/p' \
-e '/^union sockaddr_in_4_6\s*{/,/^};/p' \
'${xnu}/bsd/netinet/in.h')
#include <uuid/uuid.h>
EOF
cat <<EOF > "$out/include/netinet/tcp.h"
#pragma once
$(sed -n \
-e '/^struct tcp_info\s*{/,/^};/p' \
-e '/^struct tcp_conn_status\s*{/,/^};/p' \
-e '/^typedef struct conninfo_tcp\s*{/,/} conninfo_tcp_t;/p' \
'${xnu}/bsd/netinet/tcp.h')
#include_next <netinet/tcp.h>
EOF
install -D -t "$out/include/netinet6" \
'${xnu}/bsd/netinet6/in6_pcb.h' \
'${xnu}/bsd/netinet6/ip6_var.h'
cat <<EOF > "$out/include/netinet6/in6.h"
#pragma once
$(sed -n \
-e '/^#define IPV6_/p' \
'${xnu}/bsd/netinet6/in6.h')
#include_next <netinet6/in6.h>
EOF
cat <<EOF > "$out/include/netinet6/in6_var.h"
#pragma once
$(sed -n \
-e '/^#define IN6_CGA/p' \
-e '/^#define SIOCSETROUTERMODE_IN6\s/p' \
-e '/^struct in6_cga_modifier\s*{/,/^};/p' \
-e '/^struct in6_cga_nodecfg\s*{/,/^};/p' \
-e '/^struct in6_cga_prepare\s*{/,/^};/p' \
'${xnu}/bsd/netinet6/in6_var.h')
#include_next <netinet6/in6_var.h>
EOF
mkdir -p "$out/include/netinet6"
cat <<EOF > "$out/include/netinet6/nd6.h"
#pragma once
$(sed -n \
-e '/^#define ND6_IFF/p' \
'${xnu}/bsd/netinet6/nd6.h')
#include_next <netinet6/nd6.h>
EOF
install -D -t "$out/include/os" \
'${xnu}/libkern/os/log_private.h'
declare -a privateHeaders=(
net/classq/classq.h
net/classq/if_classq.h
net/if_bridgevar.h
net/if_llreach.h
net/if_mib.h
net/if_ports_used.h
net/net_api_stats.h
net/network_agent.h
net/ntstat.h
net/packet_mangler.h
net/pktap.h
net/pktsched/pktsched.h
net/pktsched/pktsched_fq_codel.h
net/radix.h
netinet/igmp_var.h
netinet/in_pcb.h
netinet/in_stat.h
netinet/ip_dummynet.h
netinet/mptcp_var.h
netinet/tcp_var.h
netinet6/mld6_var.h
sys/mbuf.h
)
mkdir -p "$out/include/sys"
for header in "''${privateHeaders[@]}"; do
unifdef -x 1 -DPRIVATE -o "$out/include/$header" '${xnu}/bsd/'$header
done
unifdef -x 1 -DPRIVATE -o "$out/include/net/content_filter_impl.h" '${xnu}/bsd/net/content_filter.h'
cat <<EOF > "$out/include/sys/kern_control.h"
#pragma once
$(sed -n \
-e '/^#define MAX_KCTL_NAME\s/p' \
-e '/^struct kctlstat\s*{/,/^};/p' \
-e '/^struct xkctl_reg\s*{/,/^};/p' \
-e '/^struct xkctlpcb\s*{/,/^};/p' \
'${xnu}/bsd/sys/kern_control.h')
#include_next <sys/kern_control.h>
EOF
cat <<EOF > "$out/include/sys/kern_event.h"
#pragma once
$(sed -n \
-e '/^struct kevtstat\s*{/,/^};/p' \
-e '/^struct xkevtpcb\s*{/,/^};/p' \
'${xnu}/bsd/sys/kern_event.h')
#include_next <sys/kern_event.h>
EOF
cat <<EOF > "$out/include/sys/socket.h"
#pragma once
#include <sys/param.h>
#include <sys/_types/_socklen_t.h>
$(sed -n \
-e '/^#define AF_MULTIPATH\s/p' \
-e '/^#define CIAUX_TCP\s/p' \
-e '/^#define NET_RT_/p' \
-e '/^#define SO_RECV/p' \
-e '/^#define SO_TRAFFIC_CLASS\s/,/^#define SO_TC_MAX/p' \
-e '/^typedef.*sae_associd_t/p' \
-e '/^typedef.*sae_connid_t/p' \
-e '/^struct so_aidreq\s*{/,/^};/p' \
-e '/^struct so_cidreq\s*{/,/^};/p' \
-e '/^struct so_cinforeq\s*{/,/^};/p' \
-e '/^struct so_cordreq\s*{/,/^};/p' \
'${xnu}/bsd/sys/socket.h')
#include_next <sys/socket.h>
EOF
cat <<EOF > "$out/include/sys/socketvar.h"
#pragma once
$(sed -n \
-e '/^#define SO_TC_STATS_MAX\s/p' \
-e '/^#define XSO_/p' \
-e '/^struct data_stats\s*{/,/^};/p' \
-e '/^struct soextbkidlestat\s*{/,/^};/p' \
-e '/^struct xsocket_n\s*{/,/^};/p' \
-e '/^struct xsockbuf_n\s*{/,/^};/p' \
-e '/^struct xsockstat_n\s*{/,/^};/p' \
'${xnu}/bsd/sys/socketvar.h')
#include_next <sys/socketvar.h>
EOF
cat <<EOF > "$out/include/sys/sockio.h"
#pragma once
#define ifreq ifreq_private
$(sed -n \
-e '/^#define SIOCGASSOCIDS\s/p' \
-e '/^#define SIOCGCONNIDS\s/p' \
-e '/^#define SIOCGCONNINFO\s/p' \
-e '/^#define SIOCGIFAGENTDATA\s/p' \
-e '/^#define SIOCGIFAGENTIDS\s/p' \
-e '/^#define SIOCGIFCLAT46ADDR\s/p' \
-e '/^#define SIOCGIFDELEGATE\s/p' \
-e '/^#define SIOCGIFDESC\s/p' \
-e '/^#define SIOCGIFEFLAGS\s/p' \
-e '/^#define SIOCGIFGETRTREFCNT\s/p' \
-e '/^#define SIOCGIFINTERFACESTATE\s/p' \
-e '/^#define SIOCGIFLINKPARAMS\s/p' \
-e '/^#define SIOCGIFLINKQUALITYMETRIC\s/p' \
-e '/^#define SIOCGIFLOG\s/p' \
-e '/^#define SIOCGIFLOWPOWER\s/p' \
-e '/^#define SIOCGIFMPKLOG\s/p' \
-e '/^#define SIOCGIFNAT64PREFIX\s/p' \
-e '/^#define SIOCGIFNEXUS\s/p' \
-e '/^#define SIOCGIFQUEUESTATS\s/p' \
-e '/^#define SIOCGIFTHROTTLE\s/p' \
-e '/^#define SIOCGIFTIMESTAMPENABLED\s/p' \
-e '/^#define SIOCGIFTYPE\s/p' \
-e '/^#define SIOCGIFXFLAGS\s/p' \
-e '/^#define SIOCGSTARTDELAY\s/p' \
-e '/^#define SIOCSECNMODE\s/p' \
-e '/^#define SIOCSETROUTERMODE\s/p' \
-e '/^#define SIOCSFASTLANECAPABLE\s/p' \
-e '/^#define SIOCSFASTLEENABLED\s/p' \
-e '/^#define SIOCSIF2KCL\s/p' \
-e '/^#define SIOCSIFDESC\s/p' \
-e '/^#define SIOCSIFDISABLEOUTPUT\s/p' \
-e '/^#define SIOCSIFEXPENSIVE\s/p' \
-e '/^#define SIOCSIFINTERFACESTATE\s/p' \
-e '/^#define SIOCSIFLINKPARAMS\s/p' \
-e '/^#define SIOCSIFLOG\s/p' \
-e '/^#define SIOCSIFLOWPOWER\s/p' \
-e '/^#define SIOCSIFMPKLOG\s/p' \
-e '/^#define SIOCSIFPROBECONNECTIVITY\s/p' \
-e '/^#define SIOCSIFSUBFAMILY\s/p' \
-e '/^#define SIOCSIFTHROTTLE\s/p' \
-e '/^#define SIOCSIFTIMESTAMPDISABLE\s/p' \
-e '/^#define SIOCSIFTIMESTAMPENABLE\s/p' \
-e '/^#define SIOCSQOSMARKINGENABLED\s/p' \
-e '/^#define SIOCSQOSMARKINGMODE\s/p' \
'${xnu}/bsd/sys/sockio.h')
#undef ifreq
#include_next <sys/sockio.h>
EOF
cat <<EOF > "$out/include/sys/sys_domain.h"
#pragma once
$(sed -n \
-e '/^#define AF_SYS/p' \
-e '/^#define SYSPROTO/p' \
-e '/^struct xsystmgen\s*{/,/^};/p' \
'${xnu}/bsd/sys/sys_domain.h')
#include_next <sys/sys_domain.h>
EOF
cat <<EOF > "$out/include/sys/syslimits.h"
#pragma once
$(grep '^#define LINE_MAX\s' '${xnu}/bsd/sys/syslimits.h')
#include_next <sys/syslimits.h>
EOF
cat <<EOF > "$out/include/sys/unpcb.h"
#pragma once
#include_next <sys/unpcb.h>
$(sed -n \
-e '/^#define xu_addr/p' \
-e '/^struct xunpcb64_list_entry\s*{/,/^};/p' \
-e '/^struct xunpcb64\s*{/,/^};/p' \
'${xnu}/bsd/sys/unpcb.h')
'';
};
in
mkAppleDerivation {
releaseName = "network_cmds";
outputs = [
"out"
"man"
];
xcodeHash = "sha256-luDJ4tYCvCAH/pSROdF9NtF/Ogb2Rd0ZyizG2SciloU=";
patches = [
# Some private headers depend on corecrypto, which we cant use.
# Use the headers from the ld64 port, which delegates to OpenSSL.
./patches/0007-Add-OpenSSL-based-CoreCrypto-digest-functions.patch
];
postPatch = ''
# Fix invalid pointer conversion error from trying to pass `NULL` to a `size_t`.
substituteInPlace ndp.tproj/ndp.c --replace-fail 'NULL, NULL);' 'NULL, 0);'
# Copy older files that are more compatible with the current SDK.
${lib.concatLines (
lib.mapAttrsToList (name: path: "cp '${path}' 'ifconfig.tproj/${name}.c'") old_ifconfig
)}
${lib.concatLines (
lib.mapAttrsToList (name: path: "cp '${path}' 'netstat.tproj/${name}.c'") old_netstat
)}
# Use private struct ifreq instead of the one defined in the system header.
substituteInPlace ifconfig.tproj/ifconfig.c \
--replace-fail $'struct\tifreq' 'struct ifreq' \
--replace-fail 'struct ifreq' 'struct ifreq_private'
substituteInPlace ifconfig.tproj/ifvlan.c \
--replace-fail 'struct ifreq' 'struct ifreq_private'
substituteInPlace ifconfig.tproj/ifconfig.h \
--replace-fail 'struct ifreq' 'struct ifreq_private'
substituteInPlace netstat.tproj/if.c \
--replace-fail 'struct ifreq' 'struct ifreq_private'
'';
env.NIX_CFLAGS_COMPILE = "-I${privateHeaders}/include";
nativeBuildInputs = [
developer_cmds
pkg-config
];
buildInputs = [
apple-sdk_11
libpcap
libresolv
openssl
];
meta.description = "Network commands for Darwin";
}

View File

@ -0,0 +1,311 @@
From 36767c7345161baf0ab125f95c8557f8e24f25db Mon Sep 17 00:00:00 2001
From: Randy Eckenrode <randy@largeandhighquality.com>
Date: Tue, 9 Apr 2024 19:28:17 -0400
Subject: [PATCH 7/8] Add OpenSSL-based CoreCrypto digest functions
---
compat/CommonCrypto/CommonDigest.h | 6 +++
compat/CommonCrypto/CommonDigestSPI.c | 21 +++++++++++
compat/CommonCrypto/CommonDigestSPI.h | 14 +++++++
compat/corecrypto/api_defines.h | 10 +++++
compat/corecrypto/ccdigest.c | 53 +++++++++++++++++++++++++++
compat/corecrypto/ccdigest.h | 27 ++++++++++++++
compat/corecrypto/ccdigest_private.h | 19 ++++++++++
compat/corecrypto/ccsha1.c | 22 +++++++++++
compat/corecrypto/ccsha1.h | 9 +++++
compat/corecrypto/ccsha2.c | 22 +++++++++++
compat/corecrypto/ccsha2.h | 9 +++++
11 files changed, 212 insertions(+)
create mode 100644 compat/CommonCrypto/CommonDigest.h
create mode 100644 compat/CommonCrypto/CommonDigestSPI.c
create mode 100644 compat/CommonCrypto/CommonDigestSPI.h
create mode 100644 compat/corecrypto/api_defines.h
create mode 100644 compat/corecrypto/ccdigest.c
create mode 100644 compat/corecrypto/ccdigest.h
create mode 100644 compat/corecrypto/ccdigest_private.h
create mode 100644 compat/corecrypto/ccsha1.c
create mode 100644 compat/corecrypto/ccsha1.h
create mode 100644 compat/corecrypto/ccsha2.c
create mode 100644 compat/corecrypto/ccsha2.h
diff --git a/compat/CommonCrypto/CommonDigest.h b/compat/CommonCrypto/CommonDigest.h
new file mode 100644
index 0000000..a60eba7
--- /dev/null
+++ b/compat/CommonCrypto/CommonDigest.h
@@ -0,0 +1,5 @@
+// SPDX-License-Identifier: APSL-2.0
+// CoreCrypto compatibility shims written by Randy Eckenrode © 2024
+
+#pragma once
+
diff --git a/compat/CommonCrypto/CommonDigestSPI.c b/compat/CommonCrypto/CommonDigestSPI.c
new file mode 100644
index 0000000..41269fc
--- /dev/null
+++ b/compat/CommonCrypto/CommonDigestSPI.c
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: APSL-2.0
+// CoreCrypto compatibility shims written by Randy Eckenrode © 2024
+
+#include "CommonDigestSPI.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <corecrypto/ccsha2.h>
+
+void CCDigest(int type, const uint8_t* bytes, size_t count, uint8_t* digest) {
+ if (type != kCCDigestSHA256) {
+ abort();
+ }
+ const struct ccdigest_info* di = ccsha256_di();
+
+ ccdigest_di_decl(_di, ctx);
+ ccdigest_init(di, ctx);
+ ccdigest_update(di, ctx, count, bytes);
+ ccdigest_final(di, ctx, digest);
+}
diff --git a/compat/CommonCrypto/CommonDigestSPI.h b/compat/CommonCrypto/CommonDigestSPI.h
new file mode 100644
index 0000000..172742a
--- /dev/null
+++ b/compat/CommonCrypto/CommonDigestSPI.h
@@ -0,0 +1,14 @@
+// SPDX-License-Identifier: APSL-2.0
+// CoreCrypto compatibility shims written by Randy Eckenrode © 2024
+
+#pragma once
+
+#include <stdint.h>
+
+#include <corecrypto/ccdigest.h>
+#include <cs_blobs.h>
+
+
+#define kCCDigestSHA256 10
+
+EXTERN_C void CCDigest(int type, const uint8_t* bytes, size_t count, uint8_t* digest);
diff --git a/compat/corecrypto/api_defines.h b/compat/corecrypto/api_defines.h
new file mode 100644
index 0000000..13d1e7a
--- /dev/null
+++ b/compat/corecrypto/api_defines.h
@@ -0,0 +1,10 @@
+// SPDX-License-Identifier: APSL-2.0
+// CoreCrypto compatibility shims written by Randy Eckenrode © 2024
+
+#pragma once
+
+#ifdef __cplusplus
+#define EXTERN_C extern "C"
+#else
+#define EXTERN_C
+#endif
diff --git a/compat/corecrypto/ccdigest.c b/compat/corecrypto/ccdigest.c
new file mode 100644
index 0000000..e29dcb8
--- /dev/null
+++ b/compat/corecrypto/ccdigest.c
@@ -0,0 +1,53 @@
+// SPDX-License-Identifier: APSL-2.0
+// CoreCrypto compatibility shims written by Randy Eckenrode © 2024
+
+#include "ccdigest.h"
+#include "ccdigest_private.h"
+
+#include <stdlib.h>
+
+#include <openssl/err.h>
+
+
+struct ccdigest_context* _ccdigest_context_new(void)
+{
+ struct ccdigest_context* ctx = malloc(sizeof(struct ccdigest_context));
+ ctx->context = EVP_MD_CTX_new();
+ return ctx;
+}
+
+struct ccdigest_info* _ccdigest_newprovider(const char* name)
+{
+ struct ccdigest_info* di = malloc(sizeof(struct ccdigest_info));
+ di->provider = EVP_MD_fetch(NULL, name, NULL);
+ return di;
+}
+
+void ccdigest_init(const struct ccdigest_info* di, struct ccdigest_context* ctx)
+{
+ if (!EVP_DigestInit_ex2(ctx->context, di->provider, NULL)) {
+ ERR_print_errors_fp(stderr);
+ abort();
+ }
+}
+
+void ccdigest_update(
+ const struct ccdigest_info* _di,
+ struct ccdigest_context* ctx,
+ size_t count,
+ const void* bytes
+)
+{
+ if (!EVP_DigestUpdate(ctx->context, bytes, count)) {
+ ERR_print_errors_fp(stderr);
+ abort();
+ }
+}
+
+void ccdigest_final(const struct ccdigest_info* _di, struct ccdigest_context* ctx, uint8_t* digest)
+{
+ if (!EVP_DigestFinal_ex(ctx->context, digest, NULL)) {
+ ERR_print_errors_fp(stderr);
+ abort();
+ }
+}
diff --git a/compat/corecrypto/ccdigest.h b/compat/corecrypto/ccdigest.h
new file mode 100644
index 0000000..9af2394
--- /dev/null
+++ b/compat/corecrypto/ccdigest.h
@@ -0,0 +1,27 @@
+// SPDX-License-Identifier: APSL-2.0
+// CoreCrypto compatibility shims written by Randy Eckenrode © 2024
+
+#pragma once
+
+#include <stddef.h>
+#include <stdint.h>
+
+#include "api_defines.h"
+
+
+struct ccdigest_info;
+struct ccdigest_context;
+
+EXTERN_C struct ccdigest_context* _ccdigest_context_new(void);
+
+#define ccdigest_di_decl(_di, ctxvar) \
+ struct ccdigest_context* (ctxvar) = _ccdigest_context_new()
+
+EXTERN_C void ccdigest_init(const struct ccdigest_info* di, struct ccdigest_context* ctx);
+EXTERN_C void ccdigest_update(
+ const struct ccdigest_info* _di,
+ struct ccdigest_context* ctx,
+ size_t count,
+ const void* bytes
+);
+EXTERN_C void ccdigest_final(const struct ccdigest_info* _di, struct ccdigest_context* ctx, uint8_t* digest);
diff --git a/compat/corecrypto/ccdigest_private.h b/compat/corecrypto/ccdigest_private.h
new file mode 100644
index 0000000..0ea9759
--- /dev/null
+++ b/compat/corecrypto/ccdigest_private.h
@@ -0,0 +1,19 @@
+// SPDX-License-Identifier: APSL-2.0
+// CoreCrypto compatibility shims written by Randy Eckenrode © 2024
+
+#pragma once
+
+#include "api_defines.h"
+
+#include <openssl/evp.h>
+
+
+struct ccdigest_info {
+ EVP_MD* provider;
+};
+
+struct ccdigest_context {
+ EVP_MD_CTX* context;
+};
+
+EXTERN_C struct ccdigest_info* _ccdigest_newprovider(const char* name);
diff --git a/compat/corecrypto/ccsha1.c b/compat/corecrypto/ccsha1.c
new file mode 100644
index 0000000..e02b2b6
--- /dev/null
+++ b/compat/corecrypto/ccsha1.c
@@ -0,0 +1,22 @@
+// SPDX-License-Identifier: APSL-2.0
+// CoreCrypto compatibility shims written by Randy Eckenrode © 2024
+
+#include "ccsha1.h"
+
+#include <assert.h>
+
+#include <cs_blobs.h>
+
+#include "ccdigest_private.h"
+
+
+static struct ccdigest_info* di = NULL;
+
+const struct ccdigest_info* ccsha1_di(void)
+{
+ if (!di) {
+ di = _ccdigest_newprovider("SHA-1");
+ assert(EVP_MD_get_size(di->provider) == CS_SHA1_LEN);
+ }
+ return di;
+}
diff --git a/compat/corecrypto/ccsha1.h b/compat/corecrypto/ccsha1.h
new file mode 100644
index 0000000..8e3f85f
--- /dev/null
+++ b/compat/corecrypto/ccsha1.h
@@ -0,0 +1,9 @@
+// SPDX-License-Identifier: APSL-2.0
+// CoreCrypto compatibility shims written by Randy Eckenrode © 2024
+
+#pragma once
+
+#include <corecrypto/ccdigest.h>
+
+
+EXTERN_C const struct ccdigest_info* ccsha1_di(void);
diff --git a/compat/corecrypto/ccsha2.c b/compat/corecrypto/ccsha2.c
new file mode 100644
index 0000000..6504503
--- /dev/null
+++ b/compat/corecrypto/ccsha2.c
@@ -0,0 +1,22 @@
+// SPDX-License-Identifier: APSL-2.0
+// CoreCrypto compatibility shims written by Randy Eckenrode © 2024
+
+#include "ccsha2.h"
+
+#include <assert.h>
+
+#include <cs_blobs.h>
+
+#include "ccdigest_private.h"
+
+
+static struct ccdigest_info* di = NULL;
+
+const struct ccdigest_info* ccsha256_di(void)
+{
+ if (!di) {
+ di = _ccdigest_newprovider("SHA-256");
+ assert(EVP_MD_get_size(di->provider) == CS_SHA256_LEN);
+ }
+ return di;
+}
diff --git a/compat/corecrypto/ccsha2.h b/compat/corecrypto/ccsha2.h
new file mode 100644
index 0000000..9f30e03
--- /dev/null
+++ b/compat/corecrypto/ccsha2.h
@@ -0,0 +1,10 @@
+// SPDX-License-Identifier: APSL-2.0
+// CoreCrypto compatibility shims written by Randy Eckenrode © 2024
+
+#pragma once
+
+#include <corecrypto/ccdigest.h>
+
+#define CCSHA256_OUTPUT_SIZE 32
+
+EXTERN_C const struct ccdigest_info* ccsha256_di(void);
--
2.44.1

View File

@ -50,5 +50,9 @@
"libutil": {
"hash": "sha256-4PFuk+CTLwvd/Ll9GLBkiIM0Sh/CVaiKwh5m1noheRs=",
"version": "47.30.1"
},
"network_cmds": {
"hash": "sha256-PChAbC/4cHa0lbojElR2PHOUo+cDvsoNdiorle0IXss=",
"version": "606.40.2"
}
}