-
Notifications
You must be signed in to change notification settings - Fork 0
40 lines (34 loc) · 1.6 KB
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
# systemd service for "host" computer (e.g. a laptop that has internet access)
#
# accomplishes three main tasks:
# 1. configures wpa_supplicant to connect to the mid-adhoc adhoc network
# 2. configures an IP address
# 3. sets up internet sharing for isolated nodes in mid-adhoc
[Unit]
Description=Ad-hoc wireless network connectivity (%i)
Wants=network.target
Before=network.target
BindsTo=sys-subsystem-net-devices-%i.device
After=sys-subsystem-net-devices-%i.device
[Service]
Type=oneshot
RemainAfterExit=yes
EnvironmentFile=/etc/conf.d/mid-adhoc-host@%i
# configure connection to mid-adhoc via wpa_supplicant with logging
ExecStart=/usr/bin/rm -f /var/log/wpa_supplicant.log
ExecStart=/usr/bin/ip link set %i up
ExecStart=/usr/bin/wpa_supplicant -B -i %i -c /etc/wpa_supplicant/mid-adhoc-open.conf -f /var/log/wpa_supplicant.log -t -d
ExecStart=/usr/bin/ip addr add ${addr}/${mask} broadcast + dev %i
# setup internet sharing for ad-hoc network
# ExecStart=/usr/bin/sysctl -w net.ipv4.ip_forward=1
# ExecStart=/usr/bin/iptables -t nat -A POSTROUTING -o ${infra} -j MASQUERADE
# ExecStart=/usr/bin/iptables -A FORWARD -i ${infra} -o %i -m state --state RELATED,ESTABLISHED -j ACCEPT
# ExecStart=/usr/bin/iptables -A FORWARD -i %i -o ${infra} -j ACCEPT
# cleanup
# ExecStop=/usr/bin/iptables -t nat -D POSTROUTING -o ${infra} -j MASQUERADE
# ExecStop=/usr/bin/iptables -D FORWARD -i ${infra} -o %i -m state --state RELATED,ESTABLISHED -j ACCEPT
# ExecStop=/usr/bin/iptables -D FORWARD -i %i -o ${infra} -j ACCEPT
ExecStop=/usr/bin/ip addr flush dev %i
ExecStop=/usr/bin/ip link set %i down
[Install]
WantedBy=multi-user.target