Compare commits

..

8 Commits

Author SHA1 Message Date
garywill 3d3a63d53b version 0.7.3 2024-01-19 14:33:25 +08:00
garywill 0274cd339b Merge branch 2024-01-19 14:26:36 +08:00
garywill 32f168ec8c can_transmit_to_channel() ignores freq value just focus on channel number 2024-01-19 13:50:34 +08:00
Zehka f42dc4314d regex fixes 2024-01-16 13:26:52 +01:00
Zehka 78d481d083 also ignore trailing \.0+ for iw phy info 2024-01-16 00:59:41 +01:00
Zehka 34e326f303 Remove trailing .0 from iw reported frequency
Signed-off-by: Zehka <git@zehka.net>
2024-01-16 00:32:56 +01:00
garywill cbaa19db72 improve pci info format 2024-01-14 20:25:06 +08:00
garywill a86517294b readme 2024-01-14 20:20:50 +08:00
2 changed files with 48 additions and 47 deletions

View File

@ -66,7 +66,7 @@ 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 | |
| ------------ | ---------------------------------------------------------------------------------------------------------- | | ------------ | ---------------------------------------------------------------------------------------------------------- |
@ -91,7 +91,7 @@ Internet----(eth0/wlan0)-Linux-(virtual interface)-----VM/container
### Provide Internet to an interface ### Provide Internet to an interface
``` ```bash
sudo lnxrouter -i eth1 sudo lnxrouter -i eth1
``` ```
@ -99,7 +99,7 @@ no matter which interface (other than `eth1`) you're getting Internet from.
### Create WiFi hotspot ### Create WiFi hotspot
``` ```bash
sudo lnxrouter --ap wlan0 MyAccessPoint -p MyPassPhrase sudo lnxrouter --ap wlan0 MyAccessPoint -p MyPassPhrase
``` ```
@ -111,14 +111,14 @@ Clients access Internet through only `isp5`
<details> <details>
``` ```bash
sudo lnxrouter -i eth1 -o isp5 --no-dns --dhcp-dns 1.1.1.1 -6 --dhcp-dns6 [2606:4700:4700::1111] sudo lnxrouter -i eth1 -o isp5 --no-dns --dhcp-dns 1.1.1.1 -6 --dhcp-dns6 [2606:4700:4700::1111]
``` ```
> In this case of usage, it's recommended to: > In this case of usage, it's recommended to:
> >
> 1. Stop serving local DNS > 1. Stop serving local DNS
> 2. Tell clients which DNS to use ISP5's DNS. (Or, a safe public DNS, like above example) > 2. Tell clients which DNS to use (ISP5's DNS. Or, a safe public DNS, like above example)
> Also, read *Notice 1* > Also, read *Notice 1*
@ -128,8 +128,11 @@ sudo lnxrouter -i eth1 -o isp5 --no-dns --dhcp-dns 1.1.1.1 -6 --dhcp-dns6 [26
<details> <details>
``` ```bash
sudo lnxrouter -n -i eth1 sudo lnxrouter -n -i eth1
```
```bash
sudo lnxrouter -n --ap wlan0 MyAccessPoint -p MyPassPhrase sudo lnxrouter -n --ap wlan0 MyAccessPoint -p MyPassPhrase
``` ```
@ -143,7 +146,7 @@ sudo lnxrouter -n --ap wlan0 MyAccessPoint -p MyPassPhrase
Create a bridge Create a bridge
``` ```bash
sudo brctl addbr lxcbr5 sudo brctl addbr lxcbr5
``` ```
@ -156,7 +159,7 @@ lxc.network.link = lxcbr5
lxc.network.hwaddr = xx:xx:xx:xx:xx:xx lxc.network.hwaddr = xx:xx:xx:xx:xx:xx
``` ```
``` ```bash
sudo lnxrouter -i lxcbr5 sudo lnxrouter -i lxcbr5
``` ```
@ -168,7 +171,7 @@ All clients' Internet traffic go through, for example, Tor (notice this example
<details> <details>
``` ```bash
sudo lnxrouter -i eth1 --tp 9040 --dns 9053 -g 192.168.55.1 -6 --p6 fd00:5:6:7:: sudo lnxrouter -i eth1 --tp 9040 --dns 9053 -g 192.168.55.1 -6 --p6 fd00:5:6:7::
``` ```
@ -193,7 +196,7 @@ To not give our infomation to clients. Clients can still access Internet.
<details> <details>
``` ```bash
sudo lnxrouter -i eth1 \ sudo lnxrouter -i eth1 \
--tp 9040 --dns 9053 \ --tp 9040 --dns 9053 \
--random-mac \ --random-mac \
@ -211,13 +214,13 @@ sudo lnxrouter -i eth1 \
Create a bridge Create a bridge
``` ```bash
sudo brctl addbr lxdbr5 sudo brctl addbr lxdbr5
``` ```
Create and add a new LXD profile overriding container's `eth0` Create and add a new LXD profile overriding container's `eth0`
``` ```bash
lxc profile create profile5 lxc profile create profile5
lxc profile edit profile5 lxc profile edit profile5
@ -235,13 +238,13 @@ name: profile5
lxc profile add <container> profile5 lxc profile add <container> profile5
``` ```
``` ```bash
sudo lnxrouter -i lxdbr5 --tp 9040 --dns 9053 sudo lnxrouter -i lxdbr5 --tp 9040 --dns 9053
``` ```
To remove that new profile from container To remove that new profile from container
``` ```bash
lxc profile remove <container> profile5 lxc profile remove <container> profile5
``` ```
@ -249,13 +252,13 @@ lxc profile remove <container> profile5
Add new `eth0` to container overriding default `eth0` Add new `eth0` to container overriding default `eth0`
``` ```bash
lxc config device add <container> eth0 nic name=eth0 nictype=bridged parent=lxdbr5 lxc config device add <container> eth0 nic name=eth0 nictype=bridged parent=lxdbr5
``` ```
To remove the customized `eth0` to restore default `eth0` To remove the customized `eth0` to restore default `eth0`
``` ```bash
lxc config device remove <container> eth0 lxc config device remove <container> eth0
``` ```
@ -267,7 +270,7 @@ lxc config device remove <container> eth0
In VirtualBox's global settings, create a host-only network `vboxnet5` with DHCP disabled. In VirtualBox's global settings, create a host-only network `vboxnet5` with DHCP disabled.
``` ```bash
sudo lnxrouter -i vboxnet5 --tp 9040 --dns 9053 sudo lnxrouter -i vboxnet5 --tp 9040 --dns 9053
``` ```
@ -279,11 +282,11 @@ sudo lnxrouter -i vboxnet5 --tp 9040 --dns 9053
Create a bridge Create a bridge
``` ```bash
sudo brctl addbr firejail5 sudo brctl addbr firejail5
``` ```
``` ```bash
sudo lnxrouter -i firejail5 -g 192.168.55.1 --tp 9040 --dns 9053 sudo lnxrouter -i firejail5 -g 192.168.55.1 --tp 9040 --dns 9053
firejail --net=firejail5 --dns=192.168.55.1 --blacklist=/var/run/nscd firejail --net=firejail5 --dns=192.168.55.1 --blacklist=/var/run/nscd
``` ```

View File

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
VERSION=0.7.1 VERSION=0.7.3
PROGNAME="$(basename "$0")" PROGNAME="$(basename "$0")"
export LC_ALL=C export LC_ALL=C
@ -630,11 +630,7 @@ can_transmit_to_channel() {
CHANNEL_NUM=$2 CHANNEL_NUM=$2
if [[ $USE_IWCONFIG -eq 0 ]]; then if [[ $USE_IWCONFIG -eq 0 ]]; then
if [[ $FREQ_BAND == 2.4 ]]; then CHANNEL_INFO=$(get_adapter_info "${IFACE}" | grep -E " [0-9]+(\.[0-9]+){0,1} MHz \[${CHANNEL_NUM}\]")
CHANNEL_INFO=$(get_adapter_info "${IFACE}" | grep " 24[0-9][0-9] MHz \[${CHANNEL_NUM}\]")
else
CHANNEL_INFO=$(get_adapter_info "${IFACE}" | grep " \(49[0-9][0-9]\|5[0-9]\{3\}\) MHz \[${CHANNEL_NUM}\]")
fi
[[ -z "${CHANNEL_INFO}" ]] && return 1 [[ -z "${CHANNEL_INFO}" ]] && return 1
[[ "${CHANNEL_INFO}" == *no\ IR* ]] && return 1 [[ "${CHANNEL_INFO}" == *no\ IR* ]] && return 1
[[ "${CHANNEL_INFO}" == *disabled* ]] && return 1 [[ "${CHANNEL_INFO}" == *disabled* ]] && return 1
@ -665,9 +661,6 @@ ieee80211_frequency_to_channel() {
fi fi
} }
is_5ghz_frequency() {
[[ $1 =~ ^(49[0-9]{2})|(5[0-9]{3})$ ]]
}
is_interface_wifi_connected() { is_interface_wifi_connected() {
if [[ $USE_IWCONFIG -eq 0 ]]; then if [[ $USE_IWCONFIG -eq 0 ]]; then
@ -691,36 +684,40 @@ get_interface_mac() {
cat "/sys/class/net/${1}/address" cat "/sys/class/net/${1}/address"
} }
get_interface_pci_info() { # pci id / model / virtual show_interface_pci_info() { # pci id / model / virtual
is_interface "$1" || return is_interface "$1" || return
local device_path local device_path
local pci_id local bus_id=""
local pci_full local device_type_and_bus_id="unknown"
local driver=""
local pci_path local device_fullname=""
local driver
device_path="$(readlink -f /sys/class/net/$1)" device_path="$(readlink -f /sys/class/net/$1)"
pci_path=$device_path/../..
if [[ "$device_path" == "/sys/devices/pci"* ]]; then if [[ "$device_path" == "/sys/devices/pci"* ]]; then
pci_id="$(echo "$device_path" | sed 's/\//\n/g' | tail -n 3 |sed -n 1p)" local pci_path
pci_path=$device_path/../..
if [[ -d "$pci_path/driver" ]] ; then
driver=$(readlink -f "$pci_path/driver" | sed 's/\//\n/g' | tail -n 1)
fi
bus_id="$(echo "$device_path" | sed 's/\//\n/g' | tail -n 3 |sed -n 1p)"
device_type_and_bus_id="PCI: $bus_id"
if which lspci >/dev/null 2>&1 ; then if which lspci >/dev/null 2>&1 ; then
pci_full="$( lspci -D -nn -s "$pci_id" )" device_fullname="$( lspci -D -nn -s "$bus_id" | awk '{$1="" ; print $0}' )"
echo -n " PCI: $pci_full"
else
echo -n " PCI: $pci_id"
fi fi
elif [[ "$device_path" == *"/virtual/"* ]]; then elif [[ "$device_path" == *"/virtual/"* ]]; then
echo " virtual interface" device_type_and_bus_id="virtual interface"
fi fi
if [[ -d "$pci_path/driver" ]] ; then echo "$device_type_and_bus_id"
driver=$(readlink -f "$pci_path/driver" | sed 's/\//\n/g' | tail -n 1) [[ -n "$driver" ]] && echo "System-already-loaded driver: $driver"
echo -n " System-already-loaded driver: $driver" [[ -n "$device_fullname" ]] && echo "$device_fullname"
fi
echo "" echo ""
# TODO usb # TODO usb
} }
@ -1700,7 +1697,7 @@ prepare_wifi_interface() {
# TODO move this to check_wifi_settings() ? # 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}' | sed 's/\.00*$//g') # NOTE we assume integer currently, which can be right, or wrong in the future
WIFI_IFACE_CHANNEL=$(ieee80211_frequency_to_channel "${WIFI_IFACE_FREQ}") WIFI_IFACE_CHANNEL=$(ieee80211_frequency_to_channel "${WIFI_IFACE_FREQ}")
echo "${WIFI_IFACE} already working in channel ${WIFI_IFACE_CHANNEL} (${WIFI_IFACE_FREQ} MHz)" echo "${WIFI_IFACE} already working in channel ${WIFI_IFACE_CHANNEL} (${WIFI_IFACE_FREQ} MHz)"
@ -2081,7 +2078,8 @@ echo
echo "PID: $$" echo "PID: $$"
TARGET_IFACE="$(decide_target_interface)" || exit 1 # judge wired (-i CONN_IFACE) or wireless hotspot (--ap $WIFI_IFACE) TARGET_IFACE="$(decide_target_interface)" || exit 1 # judge wired (-i CONN_IFACE) or wireless hotspot (--ap $WIFI_IFACE)
echo "Target interface is ${TARGET_IFACE} ($(get_interface_mac "$TARGET_IFACE")) $(get_interface_pci_info "$TARGET_IFACE")" echo "Target interface is ${TARGET_IFACE} ($(get_interface_mac "$TARGET_IFACE")) "
show_interface_pci_info "$TARGET_IFACE"
if [[ "$MAC_USE_RANDOM" -eq 1 ]] ; then if [[ "$MAC_USE_RANDOM" -eq 1 ]] ; then
NEW_MACADDR="$(generate_random_mac)" NEW_MACADDR="$(generate_random_mac)"