Skip to content

Commit cd8fd6a

Browse files
committed
Merge pull request #119 from rudijs/fragment-option
Add openvpn.conf gerneration -f fragment directive option
2 parents ed51116 + 9ea4815 commit cd8fd6a

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

bin/ovpn_genconfig

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ usage() {
5151
echo " -a Authenticate packets with HMAC using the given message digest algorithm (auth)."
5252
echo " -z Enable comp-lzo compression."
5353
echo " -2 Enable two factor authentication using Google Authenticator."
54+
echo " -f Set the fragment directive."
5455
}
5556

5657
if [ "$DEBUG" == "1" ]; then
@@ -80,7 +81,7 @@ OVPN_AUTH=''
8081
[ -r "$OVPN_ENV" ] && source "$OVPN_ENV"
8182

8283
# Parse arguments
83-
while getopts ":a:C:T:r:s:du:cp:n:DNm:tz2" opt; do
84+
while getopts ":a:C:T:r:s:du:cp:n:DNmf:tz2" opt; do
8485
case $opt in
8586
a)
8687
OVPN_AUTH="$OPTARG"
@@ -130,6 +131,9 @@ while getopts ":a:C:T:r:s:du:cp:n:DNm:tz2" opt; do
130131
2)
131132
OVPN_OTP_AUTH=1
132133
;;
134+
f)
135+
OVPN_FRAGMENT=$OPTARG
136+
;;
133137
\?)
134138
set +x
135139
echo "Invalid option: -$OPTARG" >&2
@@ -177,6 +181,7 @@ export OVPN_CLIENT_TO_CLIENT OVPN_PUSH OVPN_NAT OVPN_DNS OVPN_MTU OVPN_DEVICE
177181
export OVPN_TLS_CIPHER OVPN_CIPHER OVPN_AUTH
178182
export OVPN_COMP_LZO
179183
export OVPN_OTP_AUTH
184+
export OVPN_FRAGMENT
180185

181186
# Preserve config
182187
if [ -f "$OVPN_ENV" ]; then
@@ -223,6 +228,8 @@ EOF
223228
[ -n "$OVPN_CLIENT_TO_CLIENT" ] && echo "client-to-client" >> "$conf"
224229
[ -n "$OVPN_COMP_LZO" ] && echo "comp-lzo" >> "$conf"
225230

231+
[ -n "$OVPN_FRAGMENT" ] && echo "fragment $OVPN_FRAGMENT" >> "$conf"
232+
226233
[ "$OVPN_DNS" == "1" ] && for i in "${OVPN_DNS_SERVERS[@]}"; do
227234
echo "push dhcp-option DNS $i" >> "$conf"
228235
done

tests/openvpn_conf_options.test.sh

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/bin/bash
2+
3+
OVPN_DATA=opvn-data
4+
5+
IMG=kylemanna/openvpn
6+
7+
# Function to fail
8+
abort() { cat <<< "$@" 1>&2; exit 1; }
9+
10+
#
11+
# Create a docker container with the config data
12+
#
13+
sudo docker run --name $OVPN_DATA -v /etc/openvpn busybox
14+
15+
#
16+
# Generate openvpn.config file
17+
#
18+
SERV_IP=$(ip -4 -o addr show scope global | awk '{print $4}' | sed -e 's:/.*::' | head -n1)
19+
sudo docker run --volumes-from $OVPN_DATA --rm $IMG ovpn_genconfig -u udp://$SERV_IP -f 1400
20+
21+
#
22+
# grep for config lines from openvpn.conf
23+
# add more tests for more configs as required
24+
#
25+
26+
# 1. verb config
27+
CONFIG_REQUIRED_VERB="verb 3"
28+
CONFIG_MATCH_VERB=$(sudo docker run --rm -it --volumes-from $OVPN_DATA busybox grep verb /etc/openvpn/openvpn.conf)
29+
30+
# 2. fragment config
31+
CONFIG_REQUIRED_FRAGMENT="fragment 1400"
32+
CONFIG_MATCH_FRAGMENT=$(sudo docker run --rm -it --volumes-from $OVPN_DATA busybox grep fragment /etc/openvpn/openvpn.conf)
33+
34+
#
35+
# Clean up
36+
#
37+
# sudo docker rm -f $OVPN_DATA
38+
39+
#
40+
# Tests
41+
#
42+
43+
if [[ $CONFIG_MATCH_VERB =~ $CONFIG_REQUIRED_VERB ]]
44+
then
45+
echo "==> Config match found: $CONFIG_REQUIRED_VERB == $CONFIG_MATCH_VERB"
46+
else
47+
abort "==> Config match not found: $CONFIG_REQUIRED_VERB != $CONFIG_MATCH_VERB"
48+
fi
49+
50+
if [[ $CONFIG_MATCH_FRAGMENT =~ $CONFIG_REQUIRED_FRAGMENT ]]
51+
then
52+
echo "==> Config match found: $CONFIG_REQUIRED_FRAGMENT == $CONFIG_MATCH_FRAGMENT"
53+
else
54+
abort "==> Config match not found: $CONFIG_REQUIRED_FRAGMENT != $CONFIG_MATCH_FRAGMENT"
55+
fi

0 commit comments

Comments
 (0)