Compare commits

...

4 Commits

Author SHA1 Message Date
garywill a663d9052b update readme 2023-01-07 09:10:05 +08:00
garywill e3941c560f text 2023-01-07 09:08:18 +08:00
garywill 7ec589b1c2 add some notice 2023-01-07 09:07:18 +08:00
Cabbache 10ca7249cb Updated --virt-name to make interface name predictable 2023-01-07 01:02:04 +00:00
2 changed files with 45 additions and 31 deletions

View File

@ -138,7 +138,7 @@ sudo lnxrouter -i lxcbr5
### Transparent proxy
All clients' Internet traffic go through, for example, Tor
All clients' Internet traffic go through, for example, Tor (notice this example is NOT an anonymity use)
<details>
@ -155,6 +155,10 @@ TransPort [fd00:5:6:7::1]:9040
DNSPort [fd00:5:6:7::1]:9053
```
> **Warn**: Tor's anonymity relies on a purpose-made browser. Using Tor like this (sharing Tor's network to LAN clients) will NOT ensure anonymity.
>
> Although we use Tor as example here, Linux-router does NOT ensure nor is NOT aiming at anonymity.
</details>
### Clients-in-sandbox network
@ -173,7 +177,7 @@ sudo lnxrouter -i eth1 \
</details>
> This script comes with no warrenty. Use on your own risk
> Linux-router comes with no warranty. Use on your own risk
### Use as transparent proxy for LXD
@ -323,8 +327,8 @@ Options:
--random-mac Use random MAC address
--tp <port> Transparent proxy,
redirect non-LAN TCP and UDP traffic to port.
(usually used with '--dns')
redirect non-LAN TCP and UDP(not tested) traffic to
port. (usually used with '--dns')
WiFi hotspot options:
--ap <wifi interface> <SSID>
@ -337,6 +341,7 @@ Options:
--no-virt Do not create virtual interface
Using this you can't use same wlan interface
for both Internet and AP
--virt-name <name> Set name of virtual interface
-c <channel> Channel number (default: 1)
--country <code> Set two-letter country code for regularity
(example: US)

View File

@ -73,8 +73,8 @@ Options:
--random-mac Use random MAC address
--tp <port> Transparent proxy,
redirect non-LAN TCP and UDP traffic to port.
(usually used with '--dns')
redirect non-LAN TCP and UDP(not tested) traffic to
port. (usually used with '--dns')
WiFi hotspot options:
--ap <wifi interface> <SSID>
@ -87,7 +87,7 @@ Options:
--no-virt Do not create virtual interface
Using this you can't use same wlan interface
for both Internet and AP
--virt-name <name> Naming convension for virtual interface
--virt-name <name> Set name of virtual interface
-c <channel> Channel number (default: 1)
--country <code> Set two-letter country code for regularity
(example: US)
@ -198,7 +198,7 @@ define_global_variables(){
# script variables
VWIFI_IFACE= # virtual wifi interface name, if created
VIRT_PREFIX= # prefix to use for naming virtual interface
VIRT_NAME= # name to use for virtual interface if --virt-name is used
AP_IFACE= # can be VWIFI_IFACE or WIFI_IFACE
USE_IWCONFIG=0 # some device can't use iw
@ -409,7 +409,7 @@ parse_user_options(){
;;
--virt-name)
shift
VIRT_PREFIX="$1"
VIRT_NAME="$1"
shift
;;
@ -518,6 +518,10 @@ is_interface() {
[[ -d "/sys/class/net/${1}" ]]
}
is_vface_name_allocated(){
is_interface "$1" || [[ -f "$COMMON_CONFDIR/vfaces/${1}" ]]
}
get_interface_phy_device() { # only for wifi interface
local x
for x in /sys/class/ieee80211/*; do
@ -664,24 +668,19 @@ get_interface_pci_info() { # pci id / model / virtual
# TODO current driver
}
alloc_new_vface_name() { # only for wifi
local i=0
local v_iface_name=
local v_iface_name="$VIRT_NAME"
if [[ -z $VIRT_NAME ]]; then
while :; do
if [[ -z $VIRT_PREFIX ]]; then
v_iface_name="x$i${WIFI_IFACE}"
else
v_iface_name="$VIRT_PREFIX$i"
i=$((i + 1))
is_vface_name_allocated ${v_iface_name} || break
done
fi
if ! is_interface ${v_iface_name} && [[ ! -f $COMMON_CONFDIR/vfaces/${v_iface_name} ]]; then
mkdir -p $COMMON_CONFDIR/vfaces
touch $COMMON_CONFDIR/vfaces/${v_iface_name}
echo "${v_iface_name}"
return
fi
i=$((i + 1))
done
}
dealloc_vface_name() {
@ -1038,7 +1037,7 @@ allow_dhcp() {
# TODO: use 'DNAT' instead of '--to-ports' to support other IP
start_redsocks() {
echo
echo "iptables: transparent proxy non-LAN TCP/UDP traffic to port ${TP_PORT}"
echo "iptables: transparent proxy non-LAN TCP and UDP(not tested) traffic to port ${TP_PORT}"
if [[ $NO4 -eq 0 ]]; then
iptb 4 n nat N lrt${$}${SUBNET_IFACE}-TP || die
iptb 4 n nat A lrt${$}${SUBNET_IFACE}-TP -d 0.0.0.0/8 -j RETURN || die
@ -1224,7 +1223,7 @@ cleanup() {
#kill -9 -$pgid
}
# NOTE function die() is designed not to be used before init_trap() executed
# NOTE function die() is designed NOT to be used before init_trap() executed
die() { # SIGUSR2
echo "Error occured"
[[ -n "$1" ]] && echo -e "\nERROR: $1\n" >&2
@ -1587,12 +1586,16 @@ check_wifi_settings() {
echo "WARN: If AP doesn't work, read https://github.com/oblique/create_ap/blob/master/howto/realtek.md" >&2
fi
if [[ -z $VIRT_PREFIX ]]; then
if [[ -z $VIRT_NAME ]]; then
if [[ ${#WIFI_IFACE} -gt 13 ]]; then
echo "WARN: $WIFI_IFACE has ${#WIFI_IFACE} characters which might be too long. If AP doesn't work, see --virt-name and https://github.com/garywill/linux-router/issues/44" >&2
fi
elif [[ ${#VIRT_PREFIX} -gt 14 ]]; then
echo "WARN: option --virt-name $VIRT_PREFIX has ${#VIRT_PREFIX} characters which might be too long, consider making it shorter in case of errors" >&2
elif [[ ${#VIRT_NAME} -gt 15 ]]; then
echo "WARN: option --virt-name $VIRT_NAME has ${#VIRT_NAME} characters which might be too long, consider making it shorter in case of errors" >&2
fi
if [[ ! -z $VIRT_NAME ]] && is_vface_name_allocated $VIRT_NAME; then
echo "WARN: interface $VIRT_NAME aleady exists, this will cause an error"
fi
}
@ -1671,8 +1674,14 @@ prepare_wifi_interface() {
echo "${VWIFI_IFACE} created"
else
VWIFI_IFACE=
if [[ ! -z ${VIRT_NAME} ]] && [[ ${#VIRT_NAME} -gt 15 ]]; then
die "Failed creating virtual WiFi interface. This is likely because you have set a long name for your virtual interface using --virt-name, try making it shorter'"
elif [[ -z ${VIRT_NAME} ]] && [[ ${#WIFI_IFACE} -gt 13 ]]; then
die "Failed creating virtual WiFi interface. This is likely because your interface name is too long. Try using '--virt-name <shorter interface name>'"
else
die "Failed creating virtual WiFi interface. Maybe your WiFi adapter does not fully support virtual interfaces. Try again with '--no-virt'"
fi
fi
AP_IFACE=${VWIFI_IFACE}
else # no virtual wifi interface, use wifi device interface itself