Compare commits

...

10 Commits

Author SHA1 Message Date
Omar 775463c6f1
Merge 171bdb9e66 into 3d3a63d53b 2024-01-20 05:21:10 -07:00
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
Omar-AE 171bdb9e66 Now MAC filter deny is supported. (Only accept was supported.) 2022-10-12 19:35:42 +03:00
2 changed files with 85 additions and 55 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.
> 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 | |
| ------------ | ---------------------------------------------------------------------------------------------------------- |
@ -91,7 +91,7 @@ Internet----(eth0/wlan0)-Linux-(virtual interface)-----VM/container
### Provide Internet to an interface
```
```bash
sudo lnxrouter -i eth1
```
@ -99,7 +99,7 @@ no matter which interface (other than `eth1`) you're getting Internet from.
### Create WiFi hotspot
```
```bash
sudo lnxrouter --ap wlan0 MyAccessPoint -p MyPassPhrase
```
@ -111,14 +111,14 @@ Clients access Internet through only `isp5`
<details>
```
```bash
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:
>
> 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*
@ -128,8 +128,11 @@ sudo lnxrouter -i eth1 -o isp5 --no-dns --dhcp-dns 1.1.1.1 -6 --dhcp-dns6 [26
<details>
```
```bash
sudo lnxrouter -n -i eth1
```
```bash
sudo lnxrouter -n --ap wlan0 MyAccessPoint -p MyPassPhrase
```
@ -143,7 +146,7 @@ sudo lnxrouter -n --ap wlan0 MyAccessPoint -p MyPassPhrase
Create a bridge
```
```bash
sudo brctl addbr lxcbr5
```
@ -156,7 +159,7 @@ lxc.network.link = lxcbr5
lxc.network.hwaddr = xx:xx:xx:xx:xx:xx
```
```
```bash
sudo lnxrouter -i lxcbr5
```
@ -168,7 +171,7 @@ All clients' Internet traffic go through, for example, Tor (notice this example
<details>
```
```bash
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>
```
```bash
sudo lnxrouter -i eth1 \
--tp 9040 --dns 9053 \
--random-mac \
@ -211,13 +214,13 @@ sudo lnxrouter -i eth1 \
Create a bridge
```
```bash
sudo brctl addbr lxdbr5
```
Create and add a new LXD profile overriding container's `eth0`
```
```bash
lxc profile create profile5
lxc profile edit profile5
@ -235,13 +238,13 @@ name: profile5
lxc profile add <container> profile5
```
```
```bash
sudo lnxrouter -i lxdbr5 --tp 9040 --dns 9053
```
To remove that new profile from container
```
```bash
lxc profile remove <container> profile5
```
@ -249,13 +252,13 @@ lxc profile remove <container> profile5
Add new `eth0` to container overriding default `eth0`
```
```bash
lxc config device add <container> eth0 nic name=eth0 nictype=bridged parent=lxdbr5
```
To remove the customized `eth0` to restore default `eth0`
```
```bash
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.
```
```bash
sudo lnxrouter -i vboxnet5 --tp 9040 --dns 9053
```
@ -279,11 +282,11 @@ sudo lnxrouter -i vboxnet5 --tp 9040 --dns 9053
Create a bridge
```
```bash
sudo brctl addbr firejail5
```
```
```bash
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
```

View File

@ -1,6 +1,6 @@
#!/bin/bash
VERSION=0.7.1
VERSION=0.7.3
PROGNAME="$(basename "$0")"
export LC_ALL=C
@ -196,8 +196,9 @@ define_global_variables(){
CHANNEL=default
HOTSPOT20=0 # For enabling Hotspot 2.0
WPA_VERSION=2
MAC_FILTER=0
MAC_FILTER=3 # 3 is not valid
MAC_FILTER_ACCEPT=/etc/hostapd/hostapd.accept
MAC_FILTER_DENY=/etc/hostapd/hostapd.deny
IEEE80211N=0
REQUIREHT=0
IEEE80211AC=0
@ -379,13 +380,34 @@ parse_user_options(){
shift
HIDDEN=1
;;
--mac-filter)
shift
MAC_FILTER=1
;;
--mac-filter-accept)
shift
MAC_FILTER_ACCEPT="$1"
if [ "$MAC_FILTER_TYPE" == "deny" ]
then
printf "ERROR: Can't use --mac-filter-accept and --mac-filter-deny together.\n"
exit 1
fi
MAC_FILTER_TYPE=accept
MAC_FILTER=1
MAC_FILTER_FILE=$MAC_FILTER_ACCEPT
;;
--mac-filter-deny)
shift
if [ "$MAC_FILTER_TYPE" == "accept" ]
then
printf "ERROR: Can't use --mac-filter-accept and --mac-filter-deny together.\n"
exit 1
fi
MAC_FILTER_TYPE=deny
MAC_FILTER=0
MAC_FILTER_FILE=$MAC_FILTER_DENY
;;
--mac-filter-file)
shift
MAC_FILTER_FILE="$1"
shift
;;
@ -630,11 +652,7 @@ can_transmit_to_channel() {
CHANNEL_NUM=$2
if [[ $USE_IWCONFIG -eq 0 ]]; then
if [[ $FREQ_BAND == 2.4 ]]; then
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
CHANNEL_INFO=$(get_adapter_info "${IFACE}" | grep -E " [0-9]+(\.[0-9]+){0,1} MHz \[${CHANNEL_NUM}\]")
[[ -z "${CHANNEL_INFO}" ]] && return 1
[[ "${CHANNEL_INFO}" == *no\ IR* ]] && return 1
[[ "${CHANNEL_INFO}" == *disabled* ]] && return 1
@ -665,9 +683,6 @@ ieee80211_frequency_to_channel() {
fi
}
is_5ghz_frequency() {
[[ $1 =~ ^(49[0-9]{2})|(5[0-9]{3})$ ]]
}
is_interface_wifi_connected() {
if [[ $USE_IWCONFIG -eq 0 ]]; then
@ -691,36 +706,40 @@ get_interface_mac() {
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
local device_path
local pci_id
local pci_full
local pci_path
local driver
local bus_id=""
local device_type_and_bus_id="unknown"
local driver=""
local device_fullname=""
device_path="$(readlink -f /sys/class/net/$1)"
pci_path=$device_path/../..
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
pci_full="$( lspci -D -nn -s "$pci_id" )"
echo -n " PCI: $pci_full"
else
echo -n " PCI: $pci_id"
device_fullname="$( lspci -D -nn -s "$bus_id" | awk '{$1="" ; print $0}' )"
fi
elif [[ "$device_path" == *"/virtual/"* ]]; then
echo " virtual interface"
device_type_and_bus_id="virtual interface"
fi
if [[ -d "$pci_path/driver" ]] ; then
driver=$(readlink -f "$pci_path/driver" | sed 's/\//\n/g' | tail -n 1)
echo -n " System-already-loaded driver: $driver"
fi
echo "$device_type_and_bus_id"
[[ -n "$driver" ]] && echo "System-already-loaded driver: $driver"
[[ -n "$device_fullname" ]] && echo "$device_fullname"
echo ""
# TODO usb
}
@ -1700,7 +1719,7 @@ prepare_wifi_interface() {
# TODO move this to check_wifi_settings() ?
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}")
echo "${WIFI_IFACE} already working in channel ${WIFI_IFACE_CHANNEL} (${WIFI_IFACE_FREQ} MHz)"
@ -1802,8 +1821,15 @@ write_hostapd_conf() {
if [[ $MAC_FILTER -eq 1 ]]; then
cat <<- EOF >> "$CONFDIR/hostapd.conf"
macaddr_acl=${MAC_FILTER}
accept_mac_file=${MAC_FILTER_ACCEPT}
macaddr_acl=1
accept_mac_file=${MAC_FILTER_FILE}
EOF
fi
if [[ $MAC_FILTER -eq 0 ]]; then
cat <<- EOF >> "$CONFDIR/hostapd.conf"
macaddr_acl=0
deny_mac_file=${MAC_FILTER_FILE}
EOF
fi
@ -2081,7 +2107,8 @@ echo
echo "PID: $$"
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
NEW_MACADDR="$(generate_random_mac)"