From 223d3fb192965618707a55b7b423d35f61fcf545 Mon Sep 17 00:00:00 2001 From: gonzalo- Date: Sun, 31 Oct 2021 15:16:53 +0100 Subject: [PATCH 1/3] add openbsd connection share --- scripts/openbsd_connection_share.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 scripts/openbsd_connection_share.sh diff --git a/scripts/openbsd_connection_share.sh b/scripts/openbsd_connection_share.sh new file mode 100644 index 00000000..0def9f27 --- /dev/null +++ b/scripts/openbsd_connection_share.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +USB_IFACE=$(ifconfig urndis0 | grep urndis0 | awk '{print $1}' | tr -d ':') +USB_IP=${2:-10.0.0.1} + +if [ "${USB_IFACE}" == "urndis0" ]; then + ifconfig ${USB_IFACE} ${USB_IP} + sysctl -w net.inet.ip.forwarding=1 + pfctl -e + echo "match out on egress inet from ${USB_IFACE}:network to any nat-to (egress:0)" | pfctl -f - + echo "sharing connecting from upstream interface to usb interface ${USB_IFACE} ..." +else + echo "can't find usb interface with ip $USB_IP" + exit 1 +fi From 359e501d3a409146b1809755be1a7e38d7d99b2a Mon Sep 17 00:00:00 2001 From: gonzalo- Date: Sun, 31 Oct 2021 15:18:50 +0100 Subject: [PATCH 2/3] Update openbsd_connection_share.sh let's use USB_IFACE instead on the error message. --- scripts/openbsd_connection_share.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/openbsd_connection_share.sh b/scripts/openbsd_connection_share.sh index 0def9f27..277202de 100644 --- a/scripts/openbsd_connection_share.sh +++ b/scripts/openbsd_connection_share.sh @@ -10,6 +10,6 @@ if [ "${USB_IFACE}" == "urndis0" ]; then echo "match out on egress inet from ${USB_IFACE}:network to any nat-to (egress:0)" | pfctl -f - echo "sharing connecting from upstream interface to usb interface ${USB_IFACE} ..." else - echo "can't find usb interface with ip $USB_IP" + echo "can't find usb interface with ip ${USB_IFACE}" exit 1 fi From 6117133bbcff1bd3833db4ec0a3ffd8ced9ed8a7 Mon Sep 17 00:00:00 2001 From: gonzalo Date: Thu, 11 Nov 2021 14:51:54 +0100 Subject: [PATCH 3/3] lets reload pf.conf, and check for root just-in-case --- scripts/openbsd_connection_share.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/openbsd_connection_share.sh b/scripts/openbsd_connection_share.sh index 277202de..fd20f44d 100644 --- a/scripts/openbsd_connection_share.sh +++ b/scripts/openbsd_connection_share.sh @@ -3,11 +3,16 @@ USB_IFACE=$(ifconfig urndis0 | grep urndis0 | awk '{print $1}' | tr -d ':') USB_IP=${2:-10.0.0.1} +if test $(whoami) != root; then + doas "$0" "$@" + exit $? +fi + if [ "${USB_IFACE}" == "urndis0" ]; then ifconfig ${USB_IFACE} ${USB_IP} sysctl -w net.inet.ip.forwarding=1 - pfctl -e echo "match out on egress inet from ${USB_IFACE}:network to any nat-to (egress:0)" | pfctl -f - + pfctl -f /etc/pf.conf echo "sharing connecting from upstream interface to usb interface ${USB_IFACE} ..." else echo "can't find usb interface with ip ${USB_IFACE}"