summaryrefslogtreecommitdiff
path: root/roles/ws/minet/files/minet_helpers.sh
blob: 1b82e4a56a4858ee975e9e75759869ea5654fa96 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# These are helper functions for the Minimalistic Network Manager
# Author: Christian Pointner <equinox@chaos-at-home.org>

activate_interface()
{
  echo 2 > /proc/sys/net/ipv6/conf/default/use_tempaddr
  modprobe $2
  while true; do
    ip link set up dev $1 >/dev/null 2>&1
    if [ $? -eq 0 ]; then
      break
    fi
    echo -n "."
    sleep 1
    echo 2 > /proc/sys/net/ipv6/conf/$1/use_tempaddr
  done
  if [ $2 = "eth0" ]; then
    sleep 2
    ethtool -s $2 advertise 0x008
  fi
  echo ""
}

deactivate_interface()
{
  ip link set down dev $1 >/dev/null 2>&1
  modprobe -r $2
}

wpa_select_ssid()
{
  NET=$(wpa_cli -i$1 list_networks | awk "BEGIN { FS = \"\\t\" } ; \$2 == \"$2\" { print(\$1) }")
  if [ -n "$NET" ]; then
    wpa_cli -i$1 select_network $NET
  else
    echo "SSID '$2' is not in wpa_supplicant.conf - ignoring it..."
  fi
}

create_6to4()
{
  IPV6_ADDR=`printf "2002:%02x%02x:%02x%02x::1" \`echo "$2" | tr "." " "\``

  ip tunnel add mode sit remote 192.88.99.1 name $1
  ip link set dev $1 up
  ip addr add dev $1 $IPV6_ADDR/48
  ip -6 route add default dev $1
}

destroy_6to4()
{
  ip tunnel del name $1
}