diff --git a/ansible/playbook.yaml b/ansible/playbook.yaml index e3b12a2..bb7c89b 100644 --- a/ansible/playbook.yaml +++ b/ansible/playbook.yaml @@ -126,6 +126,7 @@ vars: ansible_become: True roles: + - linfi - framework_laptop - hosts: homeserver diff --git a/ansible/roles/base/files/login.conf b/ansible/roles/base/files/login.conf index a0cc4da..4d91274 100644 --- a/ansible/roles/base/files/login.conf +++ b/ansible/roles/base/files/login.conf @@ -44,6 +44,7 @@ default:\ :pseudoterminals=unlimited:\ :kqueues=unlimited:\ :umtxp=unlimited:\ + :pipebuf=unlimited:\ :priority=0:\ :ignoretime@:\ :umask=022:\ diff --git a/ansible/roles/firewall/files/odofreebsd_pf.conf b/ansible/roles/firewall/files/odofreebsd_pf.conf index 628eda5..b787eae 100644 --- a/ansible/roles/firewall/files/odofreebsd_pf.conf +++ b/ansible/roles/firewall/files/odofreebsd_pf.conf @@ -1,5 +1,5 @@ -ext_if = "{ wlan0 }" -not_ext_if = "{ !wlan0 }" +ext_if = "{ linfi_host }" +not_ext_if = "{ !linfi_host }" jail_nat_v4 = "{ 10.215.1.0/24 }" not_jail_nat_v4 = "{ any, !10.215.1.0/24 }" rfc1918 = "{ 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 }" @@ -16,7 +16,7 @@ udp_pass_in = "{ 53 51820 }" set skip on lo # redirections -nat pass on $ext_if inet from $jail_nat_v4 to $not_jail_nat_v4 -> (wlan0) +nat pass on $ext_if inet from $jail_nat_v4 to $not_jail_nat_v4 -> (linfi_host) rdr pass on $not_ext_if proto {tcp, udp} from any to 10.215.1.1 port 53 -> 172.16.0.1 port 53 # Redirect jaeger ports to virtual machine. diff --git a/ansible/roles/linfi/files/devmatch_rc.conf b/ansible/roles/linfi/files/devmatch_rc.conf new file mode 100644 index 0000000..8a6799a --- /dev/null +++ b/ansible/roles/linfi/files/devmatch_rc.conf @@ -0,0 +1,2 @@ +devmatch_enable="YES" +devmatch_blocklist="if_iwm if_iwlwifi" diff --git a/ansible/roles/linfi/files/launch_linfi.bash b/ansible/roles/linfi/files/launch_linfi.bash new file mode 100644 index 0000000..5f01478 --- /dev/null +++ b/ansible/roles/linfi/files/launch_linfi.bash @@ -0,0 +1,238 @@ +#!/usr/local/bin/bash +# +set -euo pipefail +IFS=$'\n\t' +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +# Share a host directory to the guest via 9pfs. +# +# Inside the VM run: +# mount -t virtfs -o trans=virtio sharename /some/vm/path +# mount -t 9p -o cache=mmap -o msize=512000 sharename /mnt/9p +# mount -t 9p -o trans=virtio,cache=mmap,msize=512000 sharename /path/to/mountpoint +# bhyve_options="-s 28,virtio-9p,sharename=/" + +# Enable Sound +# bhyve_options="-s 16,hda,play=/dev/dsp,rec=/dev/dsp" + +# Example usage: +# +# doas bhyve_netgraph_bridge create-disk zdata/vm/poudriere /vm/poudriere 10 +# doas bhyve_netgraph_bridge start poudriere zdata/vm/poudriere /vm/poudriere /vm/iso/FreeBSD-13.2-RELEASE-amd64-bootonly.iso +# doas bhyve_netgraph_bridge start poudriere zdata/vm/poudriere /vm/poudriere + +: ${VERBOSE:="NO"} # or YES +: ${CPU_CORES:="1"} +: ${MEMORY:="1G"} +: ${NETWORK:="NAT"} # or RAW or BOTH +: ${IP_RANGE:="10.215.1.1/24"} # Ignored for RAW networks +: ${INTERFACE_NAME:="linfi_host"} # or the external interface like lagg0 for RAW networks +: ${BRIDGE_NAME:="bridge_$INTERFACE_NAME"} # or bridge_raw for RAW networks +: ${VNC_ENABLE:="NO"} +: ${VNC_LISTEN:="127.0.0.1:5900"} +: ${VNC_WIDTH:="1920"} +: ${VNC_HEIGHT:="1080"} + +if [ "$VERBOSE" = "YES" ]; then + set -x +fi + +############## Setup ######################### + +function cleanup { + for vm in "${vms[@]}"; do + log "Destroying bhyve vm $vm" + bhyvectl "--vm=$vm" --destroy + log "Destroyed bhyve vm $vm" + done +} +vms=() +for sig in EXIT; do + trap "set +e; sleep 10; cleanup" "$sig" +done + +function die { + local status_code="$1" + shift + (>&2 echo "${@}") + exit "$status_code" +} + +function log { + (>&2 echo "${@}") +} + +############## Program ######################### + +function main { + local cmd="$1" + shift 1 + if [ "$cmd" = "create-disk" ]; then + create_disk "${@}" + elif [ "$cmd" = "start" ]; then + start_vm "${@}" + else + die 1 "Unrecognized command $cmd" + fi +} + +function create_disk { + local zfs_path="$1" + local mount_path="$2" + local gigabytes="$3" + zfs create -o "mountpoint=$mount_path" "$zfs_path" + cp /usr/local/share/edk2-bhyve/BHYVE_UEFI_VARS.fd "${mount_path}/" + tee "${mount_path}/settings" <&2 echo "No available links on bridge $bridge_name") + exit 1 + fi + done +} + +function assert_bridge { + local host_interface_name="$1" + local bridge_name="$2" + + if ! ng_exists "${bridge_name}:"; then + ngctl -d -f - </dev/null 2>&1 +} + +function calculate_mac_address { + local name="$1" + local source + source=$(md5 -r -s "$name" | awk '{print $1}') + echo "06:${source:0:2}:${source:2:2}:${source:4:2}:${source:6:2}:${source:8:2}" +} + +function find_available_port { + local start_port="$1" + local port="$start_port" + while true; do + sockstat -P tcp -p 443 + port=$((port + 1)) + done +} + +function ngctlcat { + if [ "$VERBOSE" = "YES" ]; then + tee /dev/tty | ngctl -d -f - + else + ngctl -d -f - + fi +} + + +main "${@}" diff --git a/ansible/roles/linfi/files/linfi b/ansible/roles/linfi/files/linfi new file mode 100644 index 0000000..44e1eba --- /dev/null +++ b/ansible/roles/linfi/files/linfi @@ -0,0 +1,46 @@ +#!/bin/sh +# +# PROVIDE: linfi +# REQUIRE: LOGIN +# KEYWORD: shutdown nojail +. /etc/rc.subr +name=linfi +rcvar=${name}_enable +start_cmd="${name}_start" +stop_cmd="${name}_stop" +status_cmd="${name}_status" +load_rc_config $name + +tmux_name="linfi" + +linfi_start() { + /usr/local/bin/tmux new-session -d -s "$tmux_name" "/usr/bin/env VNC_ENABLE=YES VNC_LISTEN=0.0.0.0:5900 /usr/local/bin/bash /usr/local/bin/launch_linfi start linfi zroot/freebsd/current/vm/linfi /vm/linfi" + # /vm/.iso/alpine-extended-3.20.3-x86_64.iso +} + +linfi_status() { + if /usr/local/bin/tmux has-session -t $tmux_name 2>/dev/null; then + echo "$tmux_name is running." + else + echo "$tmux_name is not running." + return 1 + fi +} + +linfi_stop() { + /usr/local/bin/tmux has-session -t $tmux_name 2>/dev/null && ( + /usr/local/bin/tmux kill-session -t $tmux_name + sleep 10 + bhyvectl --vm=linfi --destroy + # kill `cat /var/run/linfi.pid` + ) + linfi_wait_for_end +} + +linfi_wait_for_end() { + while /usr/local/bin/tmux has-session -t $tmux_name 2>dev/null; do + sleep 1 + done +} + +run_rc_command "$1" diff --git a/ansible/roles/linfi/files/linfi_loader.conf b/ansible/roles/linfi/files/linfi_loader.conf new file mode 100644 index 0000000..a736ddd --- /dev/null +++ b/ansible/roles/linfi/files/linfi_loader.conf @@ -0,0 +1,3 @@ +vmm_load="YES" +pptdevs="1/0/0" +hw.vmm.amdvi.enable="1" diff --git a/ansible/roles/linfi/files/linfi_rc.conf b/ansible/roles/linfi/files/linfi_rc.conf new file mode 100644 index 0000000..c29e7f7 --- /dev/null +++ b/ansible/roles/linfi/files/linfi_rc.conf @@ -0,0 +1 @@ +linfi_enable="YES" diff --git a/ansible/roles/linfi/meta/main.yaml b/ansible/roles/linfi/meta/main.yaml new file mode 100644 index 0000000..4fc8499 --- /dev/null +++ b/ansible/roles/linfi/meta/main.yaml @@ -0,0 +1,3 @@ +dependencies: + - role: bhyve + when: 'os_flavor == "freebsd"' diff --git a/ansible/roles/linfi/tasks/common.yaml b/ansible/roles/linfi/tasks/common.yaml new file mode 100644 index 0000000..bef243a --- /dev/null +++ b/ansible/roles/linfi/tasks/common.yaml @@ -0,0 +1,55 @@ +# - name: Create directories +# file: +# name: "{{ item }}" +# state: directory +# mode: 0755 +# owner: root +# group: wheel +# loop: +# - /foo/bar + +# - name: Install scripts +# copy: +# src: "files/{{ item.src }}" +# dest: "{{ item.dest }}" +# mode: 0755 +# owner: root +# group: wheel +# loop: +# - src: foo.bash +# dest: /usr/local/bin/foo + +# - name: Install Configuration +# copy: +# src: "files/{{ item.src }}" +# dest: "{{ item.dest }}" +# mode: 0600 +# owner: root +# group: wheel +# loop: +# - src: foo.conf +# dest: /usr/local/etc/foo.conf + +# - name: Clone Source +# git: +# repo: "https://foo.bar/baz.git" +# dest: /foo/bar +# version: "v1.0.2" +# force: true +# diff: false + +- import_tasks: tasks/freebsd.yaml + when: 'os_flavor == "freebsd"' + +- import_tasks: tasks/linux.yaml + when: 'os_flavor == "linux"' + +- include_tasks: + file: tasks/peruser.yaml + apply: + become: yes + become_user: "{{ initialize_user }}" + when: users is defined + loop: "{{ users | dict2items | community.general.json_query('[?value.initialize==`true`].key') }}" + loop_control: + loop_var: initialize_user diff --git a/ansible/roles/linfi/tasks/freebsd.yaml b/ansible/roles/linfi/tasks/freebsd.yaml new file mode 100644 index 0000000..29748fb --- /dev/null +++ b/ansible/roles/linfi/tasks/freebsd.yaml @@ -0,0 +1,41 @@ +- name: Install loader.conf + copy: + src: "files/{{ item }}_loader.conf" + dest: "/boot/loader.conf.d/{{ item }}.conf" + mode: 0644 + owner: root + group: wheel + loop: + - linfi + +- name: Install scripts + copy: + src: "files/{{ item.src }}" + dest: "{{ item.dest }}" + mode: 0755 + owner: root + group: wheel + loop: + - src: launch_linfi.bash + dest: /usr/local/bin/launch_linfi + +- name: Install rc script + copy: + src: "files/{{ item.src }}" + dest: "/usr/local/etc/rc.d/{{ item.dest|default(item.src) }}" + owner: root + group: wheel + mode: 0755 + loop: + - src: linfi + +- name: Install service configuration + copy: + src: "files/{{ item }}_rc.conf" + dest: "/etc/rc.conf.d/{{ item }}" + mode: 0644 + owner: root + group: wheel + loop: + - linfi + - devmatch diff --git a/ansible/roles/linfi/tasks/linux.yaml b/ansible/roles/linfi/tasks/linux.yaml new file mode 100644 index 0000000..bbbb096 --- /dev/null +++ b/ansible/roles/linfi/tasks/linux.yaml @@ -0,0 +1,29 @@ +# - name: Build aur packages +# register: buildaur +# become_user: "{{ build_user.name }}" +# command: "aurutils-sync --no-view {{ item }}" +# args: +# creates: "/var/cache/pacman/custom/{{ item }}-*.pkg.tar.*" +# loop: +# - foo + +# - name: Update cache +# when: buildaur.changed +# pacman: +# name: [] +# state: present +# update_cache: true + +# - name: Install packages +# package: +# name: +# - foo +# state: present + +# - name: Enable services +# systemd: +# enabled: yes +# name: "{{ item }}" +# daemon_reload: yes +# loop: +# - foo.service diff --git a/ansible/roles/linfi/tasks/main.yaml b/ansible/roles/linfi/tasks/main.yaml new file mode 100644 index 0000000..6805b9d --- /dev/null +++ b/ansible/roles/linfi/tasks/main.yaml @@ -0,0 +1,2 @@ +- import_tasks: tasks/common.yaml + # when: foo is defined diff --git a/ansible/roles/linfi/tasks/peruser.yaml b/ansible/roles/linfi/tasks/peruser.yaml new file mode 100644 index 0000000..111e886 --- /dev/null +++ b/ansible/roles/linfi/tasks/peruser.yaml @@ -0,0 +1,29 @@ +- include_role: + name: per_user + +# - name: Create directories +# file: +# name: "{{ account_homedir.stdout }}/{{ item }}" +# state: directory +# mode: 0700 +# owner: "{{ account_name.stdout }}" +# group: "{{ group_name.stdout }}" +# loop: +# - ".config/foo" + +# - name: Copy files +# copy: +# src: "files/{{ item.src }}" +# dest: "{{ account_homedir.stdout }}/{{ item.dest }}" +# mode: 0600 +# owner: "{{ account_name.stdout }}" +# group: "{{ group_name.stdout }}" +# loop: +# - src: foo.conf +# dest: .config/foo/foo.conf + +- import_tasks: tasks/peruser_freebsd.yaml + when: 'os_flavor == "freebsd"' + +- import_tasks: tasks/peruser_linux.yaml + when: 'os_flavor == "linux"' diff --git a/ansible/roles/linfi/tasks/peruser_freebsd.yaml b/ansible/roles/linfi/tasks/peruser_freebsd.yaml new file mode 100644 index 0000000..e69de29 diff --git a/ansible/roles/linfi/tasks/peruser_linux.yaml b/ansible/roles/linfi/tasks/peruser_linux.yaml new file mode 100644 index 0000000..e69de29 diff --git a/ansible/roles/network/files/odofreebsd_network.conf b/ansible/roles/network/files/odofreebsd_network.conf index c80ac42..cbd09f6 100644 --- a/ansible/roles/network/files/odofreebsd_network.conf +++ b/ansible/roles/network/files/odofreebsd_network.conf @@ -1,4 +1,4 @@ -wlans_iwlwifi0="wlan0" -ifconfig_wlan0="WPA DHCP" -ifconfig_wlan0_ipv6="inet6 accept_rtadv" -ipv6_cpe_wanif="wlan0" +# wlans_iwlwifi0="wlan0" +# ifconfig_wlan0="WPA DHCP" +# ifconfig_wlan0_ipv6="inet6 accept_rtadv" +# ipv6_cpe_wanif="wlan0" diff --git a/ansible/roles/poudriere/files/poudriere.d/currentznver4-default-framework-pkglist b/ansible/roles/poudriere/files/poudriere.d/currentznver4-default-framework-pkglist index 30cf124..1f3fd57 100644 --- a/ansible/roles/poudriere/files/poudriere.d/currentznver4-default-framework-pkglist +++ b/ansible/roles/poudriere/files/poudriere.d/currentznver4-default-framework-pkglist @@ -1,3 +1,4 @@ +#sysutils/kubeswitch accessibility/wlsunset archivers/unrar archivers/unzip @@ -94,7 +95,6 @@ sysutils/fusefs-sshfs sysutils/helm sysutils/htop sysutils/kubectl -sysutils/kubeswitch sysutils/lscpu sysutils/lsof sysutils/moreutils diff --git a/router/launch_opnsense.bash b/router/launch_opnsense.bash index 1318ca9..7d40291 100644 --- a/router/launch_opnsense.bash +++ b/router/launch_opnsense.bash @@ -136,7 +136,7 @@ name ${host_interface_name}:ether $bridge_name EOF ifconfig "$(ngctl msg "${host_interface_name}:" getifname | grep Args | cut -d '"' -f 2)" name "${host_interface_name}" up - dhclient "${host_interface_name}" + dhclient -b "${host_interface_name}" # (set +e; service netif start wlan0) & fi }