젠투의 OpenRC /etc/conf.d/net에있는 postup ()에서 SSID 정보에 어떻게 접근합니까? 무선 네트워크에 따라 openvpn을 시작하거나

연결된 무선 네트워크에 따라 openvpn을 시작하거나 중지하고 싶습니다.

그러나 postup ()env 에서 덤프 해도 해당 시점에 사용 가능한 것은 아닙니다 .${SSID}

net / wpa_supplicant.sh를 쳐다 보는 것은 도움이되지 않는 것 같아서 도움을 청합니다.



답변

원래 연결된 SSID를 기반으로 openvpn을 시작하지 않으려 고했습니다. 그러나 내가 도착한 더 좋은 해결책 은 IP보는 것 입니다.

/etc/conf.d/net :

postup() {
    # https://stackoverflow.com/questions/845694/how-do-i-find-my-computers-ip-address-using-the-bash-shell
    IP=$(ifconfig ${IFACE} | sed -n 's/.*inet addr:\([0-9.]\+\)\s.*/\1/p')
    OPENVPN=$(if [[ "${IFACE}" != "tun0" && ${IP%.*} != 192.168.[13] ]]; then echo "YES"; fi)

    sw-notify-send -i "${ICONS}/network-status.png" "${IFACE}" "$(ip addr show dev ${IFACE} | grep inet)"

    if [[ -n ${OPENVPN} ]]; then
        sw-notify-send -i "${ICONS}/network-status.png" "${IFACE}" "No IP range conflict detected for ${IP}, starting openvpn"
        /etc/init.d/openvpn -D restart
    fi
    return 0
}

편집 더 나아가, 이제이 논리를 dhcpcd 훅으로 옮겼습니다 . 이것이 작동하려면 특별한 DHCP 서버에서 고유 한 dhcp 옵션 값을 보내야합니다. 여기서 옵션 114 “default_url”을 사용하고 있습니다.

/etc/dhcpcd.enter-hook :

ACTION="stop"
COMMAND="openvpn.noroutes"

if [ "$reason" = "BOUND" ]; then
    if [ ! -z ${new_default_url} ]; then
        sw-notify-send $ifname "Detected DHCP default_url $new_default_url, skipping openvpn"
        exit 1
    fi

    OPENVPN=$(if [[ $ifname != "tun0" && ${new_network_number%.*} != 192.168.[13] ]]; then echo "YES"; fi)
    if [[ -n $OPENVPN ]]; then
        sw-notify-send $ifname "IP range for $new_ip_address is free, starting openvpn"
        COMMAND="openvpn"
    fi

    ACTION="restart"

    /etc/init.d/"${COMMAND}" -D "${ACTION}"
fi


답변