Browse Source

ocserv: allow enabling proxy ARP

Signed-off-by: Nikos Mavrogiannopoulos <nmav@gnutls.org>
Nikos Mavrogiannopoulos 9 years ago
parent
commit
637bc76c06
4 changed files with 146 additions and 17 deletions
  1. 1
    1
      net/ocserv/Makefile
  2. 102
    13
      net/ocserv/README
  3. 1
    1
      net/ocserv/files/ocserv.conf.template
  4. 42
    2
      net/ocserv/files/ocserv.init

+ 1
- 1
net/ocserv/Makefile View File

@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
9 9
 
10 10
 PKG_NAME:=ocserv
11 11
 PKG_VERSION:=0.10.9
12
-PKG_RELEASE:=1
12
+PKG_RELEASE:=2
13 13
 PKG_USE_MIPS16:=0
14 14
 
15 15
 PKG_BUILD_DIR :=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)

+ 102
- 13
net/ocserv/README View File

@@ -1,17 +1,86 @@
1
+Setting up OpenConnect VPN server
2
+=================================
3
+
1 4
 The openconnect server expects to be configured using the uci interface.
2 5
 
3 6
 It is recommended to setup a dynamic DNS address with openwrt prior
4 7
 to starting the server. That is because during the first startup
5 8
 a certificate file which contain the setup dynamic DNS name will be
6
-created.
9
+created. You can always regenerate the certificate by deleting
10
+/etc/ocserv/server-key.pem.
11
+
12
+There are two approaches to setup the VPN. The proxy-arp approach (1)
13
+which provides clients with addresses of the LAN, and the "forwarding"
14
+approach (2) which provides clients with addresses of a separate private
15
+network. The former is suitable when you have "roadwarrior" type of clients
16
+connecting to the LAN, and the latter when you may need to connect
17
+multiple networks with the LAN.
18
+
19
+
20
+1. Proxy-ARP Approach
21
+=====================
22
+
23
+[This option is available since ocserv-0.10.9-2 package]
24
+
25
+To setup a server the provides access to LAN with network address
26
+10.100.2.0/255.255.255.0 add the following to /etc/config/ocserv.
27
+The following setup will assign the upper 62 addresses for VPN use.
28
+
29
+```
30
+----/etc/config/ocserv-------------------------------------------
31
+config ocserv 'config'
32
+	option port '443'
33
+	option dpd '120'
34
+	option max_clients '8'
35
+	option max_same '2'
36
+	option netmask '255.255.255.192'
37
+	option ipaddr '10.100.2.192'
38
+	option auth 'plain'
39
+	option default_domain 'lan'
40
+	option compression '1'
41
+	option proxy_arp '1'
42
+	option ping_leases '1'
43
+	option enable '1'
44
+
45
+config dns
46
+	option ip '10.100.2.1'
47
+
48
+config routes
49
+	option ip '10.100.2.0'
50
+	option netmask '255.255.255.0'
51
+
52
+config ocservusers
53
+	option name 'test'
54
+	option password '$5$unl8uKAGNsdTh9zm$PnUHEGhDc5VHbFE2EfWwW38Bub6Y6EZ5hrFwZE1r2F1'
55
+
56
+-----------------------------------------------------------------
57
+```
58
+
59
+This setup re-utilizes the addresses assigned to LAN for the VPN clients.
60
+To ensure that there are no conflicts with the DHCP server use the following
61
+commands. These will set the maximum address assigned by DHCP to be 10.100.2.191
62
+which is below the first VPN assigned address (10.100.2.192).
63
+
64
+```
65
+# uci set dhcp.lan.start=100
66
+# uci set dhcp.lan.limit=91
67
+```
68
+
69
+For simple networks like that you may also leave the 'netmask' and 'ipaddr'
70
+fields empty and ocserv on startup will set the necessary values.
71
+
72
+
73
+2. Forwarding Approach
74
+======================
7 75
 
8 76
 To setup a server the provides access to LAN with network address
9 77
 10.100.2.0/255.255.255.0 using the VPN address range
10 78
 10.100.3.0/255.255.255.0 add the following to /etc/config/ocserv:
11 79
 
80
+```
12 81
 ----/etc/config/ocserv-------------------------------------------
13 82
 config ocserv 'config'
14
-	option port '4443'
83
+	option port '443'
15 84
 	option dpd '120'
16 85
 	option max_clients '8'
17 86
 	option max_same '2'
@@ -34,19 +103,21 @@ config ocservusers
34 103
 	option password '$5$unl8uKAGNsdTh9zm$PnUHEGhDc5VHbFE2EfWwW38Bub6Y6EZ5hrFwZE1r2F1'
35 104
 
36 105
 -----------------------------------------------------------------
106
+```
37 107
 
38
-This configuration also adds the user "test" with password "test". The
39
-password is specified in the crypt(3) format.
40 108
 
41
-The server can be enabled and started using:
42
-# /etc/init.d/ocserv enable
43
-# /etc/init.d/ocserv start
109
+Setting up the firewall
110
+=======================
44 111
 
112
+Since the connected users will be assigned to other interfaces than the LAN
113
+one, it is required to assign the VPN clients to an interface, and enable
114
+forwarding for them. That is, you should setup an unmanaged interface (e.g.,
115
+called vpn), which will have assigned the 'vpns+' interfaces (i.e., all vpns
116
+interfaces). Then a zone called vpn should be setup to handle interactions
117
+with lan. An example, which alls all forwarding between LAN and VPN clients,
118
+follows.
45 119
 
46
-To simplify firewall configuration, you should setup an unmanaged interface
47
-(e.g., called vpn), and will have assigned the 'vpns+' interfaces. Then a zone
48
-called vpn should be setup to handle interactions with lan. An example
49
-follows:
120
+```
50 121
 ----/etc/config/network------------------------------------------
51 122
 config interface 'vpn'
52 123
         option proto 'none'
@@ -74,17 +145,35 @@ config rule
74 145
         option target 'ACCEPT'
75 146
         option src 'wan'
76 147
         option proto 'tcp'
77
-        option dest_port '4443'
148
+        option dest_port '443'
78 149
         option name 'vpn'
79 150
 
80 151
 config rule
81 152
         option target 'ACCEPT'
82 153
         option src 'wan'
83 154
         option proto 'udp'
84
-        option dest_port '4443'
155
+        option dest_port '443'
85 156
         option name 'vpn'
86 157
 -----------------------------------------------------------------
158
+```
159
+
160
+Note, that the last two rules, enable connections to port 443 from the
161
+Internet. That is the port used by OpenConnect VPN.
162
+
163
+
164
+Starting the server
165
+===================
166
+
167
+Note that both configurations above add the user "test" with password "test". The
168
+password is specified in the crypt(3) format.
169
+
170
+The server can be enabled and started using:
171
+# /etc/init.d/ocserv enable
172
+# /etc/init.d/ocserv start
87 173
 
174
+For any custom configuration options of ocserv you may add values in
175
+/etc/ocserv/ocserv.conf.local.
88 176
 
89 177
 There is a luci plugin to allow configuring the server from
90 178
 the web environment; see the package luci-app-ocserv.
179
+

+ 1
- 1
net/ocserv/files/ocserv.conf.template View File

@@ -275,7 +275,7 @@ ipv4-netmask = |NETMASK|
275 275
 
276 276
 # Prior to leasing any IP from the pool ping it to verify that
277 277
 # it is not in use by another (unrelated to this server) host.
278
-ping-leases = false
278
+ping-leases = |PING_LEASES|
279 279
 
280 280
 # Unset to assign the default MTU of the device
281 281
 # mtu = 

+ 42
- 2
net/ocserv/files/ocserv.init View File

@@ -13,11 +13,47 @@ setup_config() {
13 13
 	config_get udp          $1 udp "1"
14 14
 	config_get auth         $1 auth "plain"
15 15
 	config_get cisco_compat $1 cisco_compat "1"
16
-	config_get ipaddr       $1 ipaddr "192.168.100.0"
17
-	config_get netmask      $1 netmask "255.255.255.0"
16
+	config_get ipaddr       $1 ipaddr ""
17
+	config_get netmask      $1 netmask ""
18 18
 	config_get ip6addr      $1 ip6addr ""
19
+	config_get proxy_arp    $1 proxy_arp "0"
20
+	config_get ping_leases  $1 ping_leases "0"
19 21
 	config_get default_domain  $1 default_domain ""
20 22
 
23
+	# Enable proxy arp, and make sure that ping leases is set to true in that case,
24
+	# to prevent conflicts.
25
+	if test "$proxy_arp" = 1;then
26
+		local ip
27
+		# IP address is empty. Auto-configure LAN + VPN.
28
+		if test -z "$ipaddr";then
29
+			local mask
30
+			mask=$(uci get network.lan.netmask)
31
+			if test "$mask" = "255.255.255.0";then
32
+				uci set dhcp.lan.start=100
33
+				uci set dhcp.lan.limit=91
34
+			fi
35
+			ip=$(uci get network.lan.ipaddr)
36
+			ipaddr="$(echo $ip|cut -d . -f1,2,3).192"
37
+			netmask="255.255.255.192"
38
+			uci set ocserv.config.ipaddr="$ipaddr"
39
+			uci set ocserv.config.netmask="$netmask"
40
+			uci commit
41
+		fi
42
+
43
+		if test -z "$ip6addr";then
44
+			ip6addr=$(uci get network.lan.ip6addr 2>/dev/null)
45
+			test -n "$ip6addr" && uci set ocserv.config.ip6addr="$ip6addr"
46
+			uci commit
47
+		fi
48
+
49
+		ping_leases=1
50
+		test -n "$ipaddr" && sysctl -w "net.ipv4.conf.$(uci get network.lan.ifname).proxy_arp"=1 >/dev/null
51
+		test -n "$ip6addr" && sysctl -w "net.ipv6.conf.$(uci get network.lan.ifname).proxy_ndp"=1 >/dev/null
52
+	else
53
+		test "$ipaddr" = "" && ipaddr="192.168.100.0"
54
+		test "$netmask" = "" && ipaddr="255.255.255.0"
55
+	fi
56
+
21 57
 	enable_default_domain="#"
22 58
 	enable_udp="#"
23 59
 	enable_compression="#"
@@ -25,6 +61,8 @@ setup_config() {
25 61
 	test $predictable_ips = "1" && predictable_ips="true"
26 62
 	test $cisco_compat = "0" && cisco_compat="false"
27 63
 	test $cisco_compat = "1" && cisco_compat="true"
64
+	test $ping_leases = "0" && ping_leases="false"
65
+	test $ping_leases = "1" && ping_leases="true"
28 66
 	test $udp = "1" && enable_udp=""
29 67
 	test $compression = "1" && enable_compression=""
30 68
 	test -z $default_domain && enable_default_domain=""
@@ -47,6 +85,7 @@ setup_config() {
47 85
 	    -e "s/|DEFAULT_DOMAIN|/$default_domain/g" \
48 86
 	    -e "s/|ENABLE_DEFAULT_DOMAIN|/$enable_default_domain/g" \
49 87
 	    -e "s/|CISCO_COMPAT|/$cisco_compat/g" \
88
+	    -e "s/|PING_LEASES|/$ping_leases/g" \
50 89
 	    -e "s/|UDP|/$enable_udp/g" \
51 90
 	    -e "s/|COMPRESSION|/$enable_compression/g" \
52 91
 	    -e "s/|IPV4ADDR|/$ipaddr/g" \
@@ -164,3 +203,4 @@ start_service() {
164 203
 	procd_set_param respawn
165 204
 	procd_close_instance
166 205
 }
206
+