Compare commits

..

No commits in common. "5dcfacc418f0b620d7a60dd679951d7b4e392477" and "8527e1a9b6bada6f128b1fec0e34578b143c5301" have entirely different histories.

2 changed files with 48 additions and 148 deletions

View File

@ -6,6 +6,7 @@ It wraps `iptables`, `dnsmasq` etc. stuff. Use in one command, restore in one co
[Linux-Router News & Developer Notes 📰](https://github.com/garywill/linux-router/issues/28) | [More tools and projects 🛠️](https://garywill.github.io) | [🍻 Buy me a coffee ❤️](https://github.com/garywill/receiving/blob/master/receiving_methods.md) [Linux-Router News & Developer Notes 📰](https://github.com/garywill/linux-router/issues/28) | [More tools and projects 🛠️](https://garywill.github.io) | [🍻 Buy me a coffee ❤️](https://github.com/garywill/receiving/blob/master/receiving_methods.md)
> [Read this readme in web doc reader](https://garywill.github.io/proj-doc/linux-router/) ( also available in 中文, Español, Русский язык ... )
## Features ## Features
@ -66,13 +67,13 @@ Internet----(eth0/wlan0)-Linux-(virtual interface)-----VM/container
1-file-script. Release on [Linux-router repo on Github](https://github.com/garywill/linux-router). Just download and run the bash script (meet the dependencies). In this case use without installation. 1-file-script. Release on [Linux-router repo on Github](https://github.com/garywill/linux-router). Just download and run the bash script (meet the dependencies). In this case use without installation.
> I'm currently not packaging for any distro. If you do, open a PR and add the link (can be with a version badge) to list here > I'm currently not packaging for any distro. If you do, open a PR and add the link (can be with a version badge) to list here:
| Linux distro | | | Linux distro | |
| ------------ | ---------------------------------------------------------------------------------------------------------- | | ------------ | ---------------------------------------------------------------------------------------------------------- |
| Any | download [1-file-script](https://raw.githubusercontent.com/garywill/linux-router/master/lnxrouter) and run without installation | | Any | download [1-file-script](https://raw.githubusercontent.com/garywill/linux-router/master/lnxrouter) and run without installation |
### Dependencies ## Dependencies
- bash - bash
- procps or procps-ng - procps or procps-ng
@ -368,7 +369,7 @@ Options:
Using this you can't use same wlan interface Using this you can't use same wlan interface
for both Internet and AP for both Internet and AP
--virt-name <name> Set name of virtual interface --virt-name <name> Set name of virtual interface
-c <channel> Specify channel (default: use current, or 1 / 36) -c <channel> Channel number (default: 1)
--country <code> Set two-letter country code for regularity --country <code> Set two-letter country code for regularity
(example: US) (example: US)
--freq-band <GHz> Set frequency band: 2.4 or 5 (default: 2.4) --freq-band <GHz> Set frequency band: 2.4 or 5 (default: 2.4)
@ -382,28 +383,13 @@ Options:
(defaults to /etc/hostapd/hostapd.accept) (defaults to /etc/hostapd/hostapd.accept)
--hostapd-debug <level> 1 or 2. Passes -d or -dd to hostapd --hostapd-debug <level> 1 or 2. Passes -d or -dd to hostapd
--isolate-clients Disable wifi communication between clients --isolate-clients Disable wifi communication between clients
--no-haveged Do not run haveged automatically when needed
--hs20 Enable Hotspot 2.0
WiFi 4 (802.11n) configs:
--wifi4 Enable IEEE 802.11n (HT)
--req-ht Require station HT (High Throughput) mode
--ht-capab <HT caps> HT capabilities (default: [HT40+])
WiFi 5 (802.11ac) configs:
--wifi5 Enable IEEE 802.11ac (VHT)
--req-vht Require station VHT (Very High Thoughtput) mode
--vht-capab <VHT caps> VHT capabilities
--vht-ch-width <index> Index of VHT channel width: --ieee80211n Enable IEEE 802.11n (HT)
0 for 20MHz or 40MHz (default) --ieee80211ac Enable IEEE 802.11ac (VHT)
1 for 80MHz --ht_capab <HT> HT capabilities (default: [HT40+])
2 for 160MHz --vht_capab <VHT> VHT capabilities
3 for 80+80MHz (Non-contigous 160MHz)
--vht-seg0-ch <channel> Channel index of VHT center frequency for primary --no-haveged Do not run haveged automatically when needed
segment. Use with '--vht-ch-width'
--vht-seg1-ch <channel> Channel index of VHT center frequency for secondary
(second 80MHz) segment. Use with '--vht-ch-width 3'
Instance managing: Instance managing:
--daemon Run in background --daemon Run in background
@ -415,7 +401,15 @@ Options:
--stop <id> Stop a running instance --stop <id> Stop a running instance
For <id> you can use PID or subnet interface name. For <id> you can use PID or subnet interface name.
You can get them with '--list-running' You can get them with '--list-running'
```
</details>
## Notice
<details>
```
Notice 1: This script assume your host's default policy won't forward Notice 1: This script assume your host's default policy won't forward
packets, so the script won't explictly ban forwarding in any packets, so the script won't explictly ban forwarding in any
mode. In some unexpected case (eg. mistaken configurations) may mode. In some unexpected case (eg. mistaken configurations) may
@ -452,20 +446,6 @@ Visit [**my homepage** 🏡](https://garywill.github.io) to see **more tools and
- 🍃 Also some [unfulfilled enhancements in the Issues](https://github.com/garywill/linux-router/issues?q=is%3Aissue+is%3Aopen+label%3Aenhancement) - 🍃 Also some [unfulfilled enhancements in the Issues](https://github.com/garywill/linux-router/issues?q=is%3Aissue+is%3Aopen+label%3Aenhancement)
- 🙋‍♂️ Contributions are not limited to coding. There're [some posts and questions](https://github.com/garywill/linux-router/issues) that need more people to answer - 🙋‍♂️ Contributions are not limited to coding. There're [some posts and questions](https://github.com/garywill/linux-router/issues) that need more people to answer
## Notice
<details>
```
Notice 1: This script assume your host's default policy won't forward
packets, so the script won't explictly ban forwarding in any
mode. In some unexpected case (eg. mistaken configurations) may
cause unwanted packets leakage between 2 networks, which you
should be aware of if you want isolated network
```
</details>
## TODO ## TODO
Sooner is better: Sooner is better:

140
lnxrouter
View File

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
VERSION=0.7.1b VERSION=0.6.7
PROGNAME="$(basename $0)" PROGNAME="$(basename $0)"
export LC_ALL=C export LC_ALL=C
@ -88,7 +88,7 @@ Options:
Using this you can't use same wlan interface Using this you can't use same wlan interface
for both Internet and AP for both Internet and AP
--virt-name <name> Set name of virtual interface --virt-name <name> Set name of virtual interface
-c <channel> Specify channel (default: use current, or 1 / 36) -c <channel> Channel number (default: 1)
--country <code> Set two-letter country code for regularity --country <code> Set two-letter country code for regularity
(example: US) (example: US)
--freq-band <GHz> Set frequency band: 2.4 or 5 (default: 2.4) --freq-band <GHz> Set frequency band: 2.4 or 5 (default: 2.4)
@ -102,28 +102,13 @@ Options:
(defaults to /etc/hostapd/hostapd.accept) (defaults to /etc/hostapd/hostapd.accept)
--hostapd-debug <level> 1 or 2. Passes -d or -dd to hostapd --hostapd-debug <level> 1 or 2. Passes -d or -dd to hostapd
--isolate-clients Disable wifi communication between clients --isolate-clients Disable wifi communication between clients
--no-haveged Do not run haveged automatically when needed
--hs20 Enable Hotspot 2.0
WiFi 4 (802.11n) configs:
--wifi4 Enable IEEE 802.11n (HT)
--req-ht Require station HT (High Throughput) mode
--ht-capab <HT caps> HT capabilities (default: [HT40+])
WiFi 5 (802.11ac) configs:
--wifi5 Enable IEEE 802.11ac (VHT)
--req-vht Require station VHT (Very High Thoughtput) mode
--vht-capab <VHT caps> VHT capabilities
--vht-ch-width <index> Index of VHT channel width: --ieee80211n Enable IEEE 802.11n (HT)
0 for 20MHz or 40MHz (default) --ieee80211ac Enable IEEE 802.11ac (VHT)
1 for 80MHz --ht_capab <HT> HT capabilities (default: [HT40+])
2 for 160MHz --vht_capab <VHT> VHT capabilities
3 for 80+80MHz (Non-contigous 160MHz)
--vht-seg0-ch <channel> Channel index of VHT center frequency for primary --no-haveged Do not run haveged automatically when needed
segment. Use with '--vht-ch-width'
--vht-seg1-ch <channel> Channel index of VHT center frequency for secondary
(second 80MHz) segment. Use with '--vht-ch-width 3'
Instance managing: Instance managing:
--daemon Run in background --daemon Run in background
@ -194,19 +179,13 @@ define_global_variables(){
HIDDEN=0 # hidden wifi hotspot HIDDEN=0 # hidden wifi hotspot
WIFI_IFACE= WIFI_IFACE=
CHANNEL=default CHANNEL=default
HOTSPOT20=0 # For enabling Hotspot 2.0
WPA_VERSION=2 WPA_VERSION=2
MAC_FILTER=0 MAC_FILTER=0
MAC_FILTER_ACCEPT=/etc/hostapd/hostapd.accept MAC_FILTER_ACCEPT=/etc/hostapd/hostapd.accept
IEEE80211N=0 IEEE80211N=0
REQUIREHT=0
IEEE80211AC=0 IEEE80211AC=0
REQUIREVHT=0
HT_CAPAB='[HT40+]' HT_CAPAB='[HT40+]'
VHT_CAPAB= VHT_CAPAB=
VHTCHANNELWIDTH=0
VHTSEG0CHINDEX=0
VHTSEG1CHINDEX=0
DRIVER=nl80211 DRIVER=nl80211
NO_VIRT=0 # not use virtual interface NO_VIRT=0 # not use virtual interface
COUNTRY= COUNTRY=
@ -394,10 +373,6 @@ parse_user_options(){
CHANNEL="$1" CHANNEL="$1"
shift shift
;; ;;
--hs20)
shift
HOTSPOT20=1
;;
-w) -w)
shift shift
WPA_VERSION="$1" WPA_VERSION="$1"
@ -405,47 +380,24 @@ parse_user_options(){
shift shift
;; ;;
--wifi4|--ieee80211n) --ieee80211n)
shift shift
IEEE80211N=1 IEEE80211N=1
;; ;;
--req-ht|--require-ht) --ieee80211ac)
shift
REQUIREHT=1
;;
--wifi5|--ieee80211ac)
shift shift
IEEE80211AC=1 IEEE80211AC=1
;; ;;
--req-vht|--require-vht) --ht_capab)
shift
REQUIREVHT=1
;;
--ht-capab)
shift shift
HT_CAPAB="$1" HT_CAPAB="$1"
shift shift
;; ;;
--vht-capab) --vht_capab)
shift shift
VHT_CAPAB="$1" VHT_CAPAB="$1"
shift shift
;; ;;
--vht-ch-width|--vht-channel-width)
shift
VHTCHANNELWIDTH="$1"
shift
;;
--vht-seg0-ch|--vht-seg0-channel)
shift
VHTSEG0CHINDEX="$1"
shift
;;
--vht-seg1-ch|--vht-seg1-channel)
shift
VHTSEG1CHINDEX="$1"
shift
;;
--driver) --driver)
shift shift
DRIVER="$1" DRIVER="$1"
@ -1554,7 +1506,7 @@ daemonizing_check(){
check_wifi_settings() { check_wifi_settings() {
if ! ( which iw > /dev/null 2>&1 && iw dev $WIFI_IFACE info > /dev/null 2>&1 ); then if ! ( which iw > /dev/null 2>&1 && iw dev $WIFI_IFACE info > /dev/null 2>&1 ); then
echo "WARN: Can't use 'iw' to operate interfce '$WIFI_IFACE', trying 'iwconfig' (not as good as 'iw') ... (Did you spell the interface name right?)" >&2 echo "WARN: Can't use 'iw' to operate interfce '$WIFI_IFACE', trying 'iwconfig' (not as good as 'iw') ..." >&2
USE_IWCONFIG=1 USE_IWCONFIG=1
fi fi
@ -1570,6 +1522,14 @@ check_wifi_settings() {
exit 1 exit 1
fi fi
if [[ $CHANNEL == default ]]; then
if [[ $FREQ_BAND == 2.4 ]]; then
CHANNEL=1
else
CHANNEL=36
fi
fi
if [[ $FREQ_BAND != 5 && $CHANNEL -gt 14 ]]; then if [[ $FREQ_BAND != 5 && $CHANNEL -gt 14 ]]; then
echo "Channel number is greater than 14, assuming 5GHz frequency band" echo "Channel number is greater than 14, assuming 5GHz frequency band"
FREQ_BAND=5 FREQ_BAND=5
@ -1688,21 +1648,20 @@ prepare_wifi_interface() {
if [[ $NO_VIRT -eq 0 ]]; then if [[ $NO_VIRT -eq 0 ]]; then
## Will generate virtual wifi interface ## Will generate virtual wifi interface
# TODO move this to check_wifi_settings() ?
if is_interface_wifi_connected ${WIFI_IFACE}; then if is_interface_wifi_connected ${WIFI_IFACE}; then
WIFI_IFACE_FREQ=$(iw dev ${WIFI_IFACE} link | grep -i freq | awk '{print $2}') WIFI_IFACE_FREQ=$(iw dev ${WIFI_IFACE} link | grep -i freq | awk '{print $2}')
WIFI_IFACE_CHANNEL=$(ieee80211_frequency_to_channel ${WIFI_IFACE_FREQ}) WIFI_IFACE_CHANNEL=$(ieee80211_frequency_to_channel ${WIFI_IFACE_FREQ})
echo "${WIFI_IFACE} already in channel ${WIFI_IFACE_CHANNEL} (${WIFI_IFACE_FREQ} MHz)"
echo "${WIFI_IFACE} already working in channel ${WIFI_IFACE_CHANNEL} (${WIFI_IFACE_FREQ} MHz)" if is_5ghz_frequency $WIFI_IFACE_FREQ; then
FREQ_BAND=5
if [[ $CHANNEL == default ]]; then else
echo "Use wifi adapter current channel $WIFI_IFACE_CHANNEL as target channel" FREQ_BAND=2.4
CHANNEL=$WIFI_IFACE_CHANNEL
fi fi
if [[ $WIFI_IFACE_CHANNEL -ne $CHANNEL ]]; then if [[ $WIFI_IFACE_CHANNEL -ne $CHANNEL ]]; then
echo "WARN: Wifi adapter already working in channel ${WIFI_IFACE_CHANNEL}, which is different than target channel $CHANNEL" >&2 echo "Channel fallback to ${WIFI_IFACE_CHANNEL}"
CHANNEL=$WIFI_IFACE_CHANNEL
else
echo
fi fi
fi fi
@ -1728,15 +1687,6 @@ prepare_wifi_interface() {
else # no virtual wifi interface, use wifi device interface itself else # no virtual wifi interface, use wifi device interface itself
AP_IFACE=${WIFI_IFACE} AP_IFACE=${WIFI_IFACE}
fi fi
if [[ $CHANNEL == default ]]; then
echo "Channel not specified, use default"
if [[ $FREQ_BAND == 2.4 ]]; then
CHANNEL=1
else
CHANNEL=36
fi
fi
} }
decide_subnet_interface() { decide_subnet_interface() {
@ -1798,10 +1748,6 @@ write_hostapd_conf() {
EOF EOF
fi fi
if [[ $HOTSPOT20 -eq 1 ]]; then
echo "hs20=1" >> "$CONFDIR/hostapd.conf"
fi
if [[ $IEEE80211N -eq 1 ]]; then if [[ $IEEE80211N -eq 1 ]]; then
cat <<- EOF >> "$CONFDIR/hostapd.conf" cat <<- EOF >> "$CONFDIR/hostapd.conf"
ieee80211n=1 ieee80211n=1
@ -1809,40 +1755,14 @@ write_hostapd_conf() {
EOF EOF
fi fi
if [[ $REQUIREHT -eq 1 ]]; then
echo "require_ht=1" >> "$CONFDIR/hostapd.conf"
fi
if [[ $IEEE80211AC -eq 1 ]]; then if [[ $IEEE80211AC -eq 1 ]]; then
echo "ieee80211ac=1" >> "$CONFDIR/hostapd.conf" echo "ieee80211ac=1" >> "$CONFDIR/hostapd.conf"
fi fi
if [[ $REQUIREVHT -eq 1 ]]; then
echo "require_vht=1" >> "$CONFDIR/hostapd.conf"
fi
if [[ -n "$VHT_CAPAB" ]]; then if [[ -n "$VHT_CAPAB" ]]; then
echo "vht_capab=${VHT_CAPAB}" >> "$CONFDIR/hostapd.conf" echo "vht_capab=${VHT_CAPAB}" >> "$CONFDIR/hostapd.conf"
fi fi
if [[ $VHTCHANNELWIDTH -gt 0 ]]; then
cat <<- EOF >> "$CONFDIR/hostapd.conf"
vht_oper_chwidth=${VHTCHANNELWIDTH}
EOF
fi
if [[ $VHTSEG0CHINDEX -gt 0 ]]; then
cat <<- EOF >> "$CONFDIR/hostapd.conf"
vht_oper_centr_freq_seg0_idx=${VHTSEG0CHINDEX}
EOF
fi
if [[ $VHTSEG1CHINDEX -gt 0 ]]; then
cat <<- EOF >> "$CONFDIR/hostapd.conf"
vht_oper_centr_freq_seg1_idx=${VHTSEG1CHINDEX}
EOF
fi
if [[ $IEEE80211N -eq 1 ]] || [[ $IEEE80211AC -eq 1 ]]; then if [[ $IEEE80211N -eq 1 ]] || [[ $IEEE80211AC -eq 1 ]]; then
echo "wmm_enabled=1" >> "$CONFDIR/hostapd.conf" echo "wmm_enabled=1" >> "$CONFDIR/hostapd.conf"
fi fi