updown 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  1. #!/bin/sh
  2. # default updown script
  3. #
  4. # Copyright (C) 2003-2004 Nigel Meteringham
  5. # Copyright (C) 2003-2004 Tuomo Soini
  6. # Copyright (C) 2002-2004 Michael Richardson
  7. # Copyright (C) 2005-2007 Andreas Steffen <andreas.steffen@strongswan.org>
  8. #
  9. # This program is free software; you can redistribute it and/or modify it
  10. # under the terms of the GNU General Public License as published by the
  11. # Free Software Foundation; either version 2 of the License, or (at your
  12. # option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
  13. #
  14. # This program is distributed in the hope that it will be useful, but
  15. # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  16. # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  17. # for more details.
  18. # CAUTION: Installing a new version of strongSwan will install a new
  19. # copy of this script, wiping out any custom changes you make. If
  20. # you need changes, make a copy of this under another name, and customize
  21. # that, and use the (left/right)updown parameters in ipsec.conf to make
  22. # strongSwan use yours instead of this default one.
  23. # PLUTO_VERSION
  24. # indicates what version of this interface is being
  25. # used. This document describes version 1.1. This
  26. # is upwardly compatible with version 1.0.
  27. #
  28. # PLUTO_VERB
  29. # specifies the name of the operation to be performed
  30. # (prepare-host, prepare-client, up-host, up-client,
  31. # down-host, or down-client). If the address family
  32. # for security gateway to security gateway communica-
  33. # tions is IPv6, then a suffix of -v6 is added to the
  34. # verb.
  35. #
  36. # PLUTO_CONNECTION
  37. # is the name of the connection for which we are
  38. # routing.
  39. #
  40. # PLUTO_INTERFACE
  41. # is the name of the ipsec interface to be used.
  42. #
  43. # PLUTO_REQID
  44. # is the requid of the AH|ESP policy
  45. #
  46. # PLUTO_PROTO
  47. # is the negotiated IPsec protocol, ah|esp
  48. #
  49. # PLUTO_IPCOMP
  50. # is not empty if IPComp was negotiated
  51. #
  52. # PLUTO_UNIQUEID
  53. # is the unique identifier of the associated IKE_SA
  54. #
  55. # PLUTO_ME
  56. # is the IP address of our host.
  57. #
  58. # PLUTO_MY_ID
  59. # is the ID of our host.
  60. #
  61. # PLUTO_MY_CLIENT
  62. # is the IP address / count of our client subnet. If
  63. # the client is just the host, this will be the
  64. # host's own IP address / max (where max is 32 for
  65. # IPv4 and 128 for IPv6).
  66. #
  67. # PLUTO_MY_SOURCEIP
  68. # PLUTO_MY_SOURCEIP4_$i
  69. # PLUTO_MY_SOURCEIP6_$i
  70. # contains IPv4/IPv6 virtual IP received from a responder,
  71. # $i enumerates from 1 to the number of IP per address family.
  72. # PLUTO_MY_SOURCEIP is a legacy variable and equal to the first
  73. # virtual IP, IPv4 or IPv6.
  74. #
  75. # PLUTO_MY_PROTOCOL
  76. # is the IP protocol that will be transported.
  77. #
  78. # PLUTO_MY_PORT
  79. # is the UDP/TCP port to which the IPsec SA is
  80. # restricted on our side. For ICMP/ICMPv6 this contains the
  81. # message type, and PLUTO_PEER_PORT the message code.
  82. #
  83. # PLUTO_PEER
  84. # is the IP address of our peer.
  85. #
  86. # PLUTO_PEER_ID
  87. # is the ID of our peer.
  88. #
  89. # PLUTO_PEER_CLIENT
  90. # is the IP address / count of the peer's client sub-
  91. # net. If the client is just the peer, this will be
  92. # the peer's own IP address / max (where max is 32
  93. # for IPv4 and 128 for IPv6).
  94. #
  95. # PLUTO_PEER_SOURCEIP
  96. # PLUTO_PEER_SOURCEIP4_$i
  97. # PLUTO_PEER_SOURCEIP6_$i
  98. # contains IPv4/IPv6 virtual IP sent to an initiator,
  99. # $i enumerates from 1 to the number of IP per address family.
  100. # PLUTO_PEER_SOURCEIP is a legacy variable and equal to the first
  101. # virtual IP, IPv4 or IPv6.
  102. #
  103. # PLUTO_PEER_PROTOCOL
  104. # is the IP protocol that will be transported.
  105. #
  106. # PLUTO_PEER_PORT
  107. # is the UDP/TCP port to which the IPsec SA is
  108. # restricted on the peer side. For ICMP/ICMPv6 this contains the
  109. # message code, and PLUTO_MY_PORT the message type.
  110. #
  111. # PLUTO_XAUTH_ID
  112. # is an optional user ID employed by the XAUTH protocol
  113. #
  114. # PLUTO_MARK_IN
  115. # is an optional XFRM mark set on the inbound IPsec SA
  116. #
  117. # PLUTO_MARK_OUT
  118. # is an optional XFRM mark set on the outbound IPsec SA
  119. #
  120. # PLUTO_IF_ID_IN
  121. # is an optional XFRM interface ID set on the inbound IPsec SA
  122. #
  123. # PLUTO_IF_ID_OUT
  124. # is an optional XFRM interface ID set on the outbound IPsec SA
  125. #
  126. # PLUTO_UDP_ENC
  127. # contains the remote UDP port in the case of ESP_IN_UDP
  128. # encapsulation
  129. #
  130. # PLUTO_DNS4_$i
  131. # PLUTO_DNS6_$i
  132. # contains IPv4/IPv6 DNS server attribute received from a
  133. # responder, $i enumerates from 1 to the number of servers per
  134. # address family.
  135. #
  136. # define a minimum PATH environment in case it is not set
  137. PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/sbin"
  138. export PATH
  139. # comment to disable logging VPN connections to syslog
  140. VPN_LOGGING=1
  141. #
  142. # tag put in front of each log entry:
  143. TAG=vpn
  144. #
  145. # syslog facility and priority used:
  146. FAC_PRIO=local0.notice
  147. #
  148. # to create a special vpn logging file, put the following line into
  149. # the syslog configuration file /etc/syslog.conf:
  150. #
  151. # local0.notice -/var/log/vpn
  152. # check interface version
  153. case "$PLUTO_VERSION" in
  154. 1.[0|1]) # Older release?!? Play it safe, script may be using new features.
  155. echo "$0: obsolete interface version \`$PLUTO_VERSION'," >&2
  156. echo "$0: called by obsolete release?" >&2
  157. exit 2
  158. ;;
  159. 1.*) ;;
  160. *) echo "$0: unknown interface version \`$PLUTO_VERSION'" >&2
  161. exit 2
  162. ;;
  163. esac
  164. # check parameter(s)
  165. case "$1:$*" in
  166. ':') # no parameters
  167. ;;
  168. iptables:iptables) # due to (left/right)firewall; for default script only
  169. ;;
  170. custom:*) # custom parameters (see above CAUTION comment)
  171. ;;
  172. *) echo "$0: unknown parameters \`$*'" >&2
  173. exit 2
  174. ;;
  175. esac
  176. IPSEC_POLICY="-m policy --pol ipsec --proto $PLUTO_PROTO --reqid $PLUTO_REQID"
  177. IPSEC_POLICY_IN="$IPSEC_POLICY --dir in"
  178. IPSEC_POLICY_OUT="$IPSEC_POLICY --dir out"
  179. # use protocol specific options to set ports
  180. case "$PLUTO_MY_PROTOCOL" in
  181. 1) # ICMP
  182. ICMP_TYPE_OPTION="--icmp-type"
  183. ;;
  184. 58) # ICMPv6
  185. ICMP_TYPE_OPTION="--icmpv6-type"
  186. ;;
  187. *)
  188. ;;
  189. esac
  190. # are there port numbers?
  191. if [ "$PLUTO_MY_PORT" != 0 ]
  192. then
  193. if [ -n "$ICMP_TYPE_OPTION" ]
  194. then
  195. S_MY_PORT="$ICMP_TYPE_OPTION $PLUTO_MY_PORT"
  196. D_MY_PORT="$ICMP_TYPE_OPTION $PLUTO_MY_PORT"
  197. else
  198. S_MY_PORT="--sport $PLUTO_MY_PORT"
  199. D_MY_PORT="--dport $PLUTO_MY_PORT"
  200. fi
  201. fi
  202. if [ "$PLUTO_PEER_PORT" != 0 ]
  203. then
  204. if [ -n "$ICMP_TYPE_OPTION" ]
  205. then
  206. # the syntax is --icmp[v6]-type type[/code], so add it to the existing option
  207. S_MY_PORT="$S_MY_PORT/$PLUTO_PEER_PORT"
  208. D_MY_PORT="$D_MY_PORT/$PLUTO_PEER_PORT"
  209. else
  210. S_PEER_PORT="--sport $PLUTO_PEER_PORT"
  211. D_PEER_PORT="--dport $PLUTO_PEER_PORT"
  212. fi
  213. fi
  214. # resolve octal escape sequences
  215. PLUTO_MY_ID=`printf "$PLUTO_MY_ID"`
  216. PLUTO_PEER_ID=`printf "$PLUTO_PEER_ID"`
  217. case "$PLUTO_VERB:$1" in
  218. up-host:)
  219. # connection to me coming up
  220. # If you are doing a custom version, firewall commands go here.
  221. ;;
  222. down-host:)
  223. # connection to me going down
  224. # If you are doing a custom version, firewall commands go here.
  225. ;;
  226. up-client:)
  227. # connection to my client subnet coming up
  228. # If you are doing a custom version, firewall commands go here.
  229. PLUTO_INTERFACE=ipsec0
  230. iptables -I FORWARD 1 -o $PLUTO_INTERFACE -p $PLUTO_PEER_PROTOCOL \
  231. -s $PLUTO_MY_CLIENT $S_MY_PORT \
  232. -d $PLUTO_PEER_CLIENT $D_PEER_PORT -j ACCEPT
  233. iptables -I FORWARD 1 -i $PLUTO_INTERFACE -p $PLUTO_MY_PROTOCOL \
  234. -s $PLUTO_PEER_CLIENT $S_PEER_PORT \
  235. -d $PLUTO_MY_CLIENT $D_MY_PORT -j ACCEPT
  236. ;;
  237. down-client:)
  238. # connection to my client subnet going down
  239. # If you are doing a custom version, firewall commands go here.
  240. PLUTO_INTERFACE=ipsec0
  241. iptables -D FORWARD -o $PLUTO_INTERFACE -p $PLUTO_PEER_PROTOCOL \
  242. -s $PLUTO_MY_CLIENT $S_MY_PORT \
  243. -d $PLUTO_PEER_CLIENT $D_PEER_PORT -j ACCEPT
  244. iptables -D FORWARD -i $PLUTO_INTERFACE -p $PLUTO_MY_PROTOCOL \
  245. -s $PLUTO_PEER_CLIENT $S_PEER_PORT \
  246. -d $PLUTO_MY_CLIENT $D_MY_PORT -j ACCEPT
  247. ;;
  248. up-host:iptables)
  249. # connection to me, with (left/right)firewall=yes, coming up
  250. # This is used only by the default updown script, not by your custom
  251. # ones, so do not mess with it; see CAUTION comment up at top.
  252. iptables -I INPUT 1 -i $PLUTO_INTERFACE -p $PLUTO_MY_PROTOCOL \
  253. -s $PLUTO_PEER_CLIENT $S_PEER_PORT \
  254. -d $PLUTO_ME $D_MY_PORT $IPSEC_POLICY_IN -j ACCEPT
  255. iptables -I OUTPUT 1 -o $PLUTO_INTERFACE -p $PLUTO_PEER_PROTOCOL \
  256. -s $PLUTO_ME $S_MY_PORT $IPSEC_POLICY_OUT \
  257. -d $PLUTO_PEER_CLIENT $D_PEER_PORT -j ACCEPT
  258. #
  259. # allow IPIP traffic because of the implicit SA created by the kernel if
  260. # IPComp is used (for small inbound packets that are not compressed)
  261. if [ -n "$PLUTO_IPCOMP" ]
  262. then
  263. iptables -I INPUT 1 -i $PLUTO_INTERFACE -p 4 \
  264. -s $PLUTO_PEER -d $PLUTO_ME $IPSEC_POLICY_IN -j ACCEPT
  265. fi
  266. #
  267. # log IPsec host connection setup
  268. if [ $VPN_LOGGING ]
  269. then
  270. if [ "$PLUTO_PEER_CLIENT" = "$PLUTO_PEER/32" ]
  271. then
  272. logger -t $TAG -p $FAC_PRIO \
  273. "+ $PLUTO_PEER_ID $PLUTO_PEER -- $PLUTO_ME"
  274. else
  275. logger -t $TAG -p $FAC_PRIO \
  276. "+ $PLUTO_PEER_ID $PLUTO_PEER_CLIENT == $PLUTO_PEER -- $PLUTO_ME"
  277. fi
  278. fi
  279. ;;
  280. down-host:iptables)
  281. # connection to me, with (left/right)firewall=yes, going down
  282. # This is used only by the default updown script, not by your custom
  283. # ones, so do not mess with it; see CAUTION comment up at top.
  284. iptables -D INPUT -i $PLUTO_INTERFACE -p $PLUTO_MY_PROTOCOL \
  285. -s $PLUTO_PEER_CLIENT $S_PEER_PORT \
  286. -d $PLUTO_ME $D_MY_PORT $IPSEC_POLICY_IN -j ACCEPT
  287. iptables -D OUTPUT -o $PLUTO_INTERFACE -p $PLUTO_PEER_PROTOCOL \
  288. -s $PLUTO_ME $S_MY_PORT $IPSEC_POLICY_OUT \
  289. -d $PLUTO_PEER_CLIENT $D_PEER_PORT -j ACCEPT
  290. #
  291. # IPIP exception teardown
  292. if [ -n "$PLUTO_IPCOMP" ]
  293. then
  294. iptables -D INPUT -i $PLUTO_INTERFACE -p 4 \
  295. -s $PLUTO_PEER -d $PLUTO_ME $IPSEC_POLICY_IN -j ACCEPT
  296. fi
  297. #
  298. # log IPsec host connection teardown
  299. if [ $VPN_LOGGING ]
  300. then
  301. if [ "$PLUTO_PEER_CLIENT" = "$PLUTO_PEER/32" ]
  302. then
  303. logger -t $TAG -p $FAC_PRIO -- \
  304. "- $PLUTO_PEER_ID $PLUTO_PEER -- $PLUTO_ME"
  305. else
  306. logger -t $TAG -p $FAC_PRIO -- \
  307. "- $PLUTO_PEER_ID $PLUTO_PEER_CLIENT == $PLUTO_PEER -- $PLUTO_ME"
  308. fi
  309. fi
  310. ;;
  311. up-client:iptables)
  312. # connection to client subnet, with (left/right)firewall=yes, coming up
  313. # This is used only by the default updown script, not by your custom
  314. # ones, so do not mess with it; see CAUTION comment up at top.
  315. if [ "$PLUTO_PEER_CLIENT" != "$PLUTO_MY_SOURCEIP/32" ]
  316. then
  317. iptables -I FORWARD 1 -o $PLUTO_INTERFACE -p $PLUTO_PEER_PROTOCOL \
  318. -s $PLUTO_MY_CLIENT $S_MY_PORT \
  319. -d $PLUTO_PEER_CLIENT $D_PEER_PORT $IPSEC_POLICY_OUT -j ACCEPT
  320. iptables -I FORWARD 1 -i $PLUTO_INTERFACE -p $PLUTO_MY_PROTOCOL \
  321. -s $PLUTO_PEER_CLIENT $S_PEER_PORT \
  322. -d $PLUTO_MY_CLIENT $D_MY_PORT $IPSEC_POLICY_IN -j ACCEPT
  323. fi
  324. #
  325. # a virtual IP requires an INPUT and OUTPUT rule on the host
  326. # or sometimes host access via the internal IP is needed
  327. if [ -n "$PLUTO_MY_SOURCEIP" -o -n "$PLUTO_HOST_ACCESS" ]
  328. then
  329. iptables -I INPUT 1 -i $PLUTO_INTERFACE -p $PLUTO_MY_PROTOCOL \
  330. -s $PLUTO_PEER_CLIENT $S_PEER_PORT \
  331. -d $PLUTO_MY_CLIENT $D_MY_PORT $IPSEC_POLICY_IN -j ACCEPT
  332. iptables -I OUTPUT 1 -o $PLUTO_INTERFACE -p $PLUTO_PEER_PROTOCOL \
  333. -s $PLUTO_MY_CLIENT $S_MY_PORT \
  334. -d $PLUTO_PEER_CLIENT $D_PEER_PORT $IPSEC_POLICY_OUT -j ACCEPT
  335. fi
  336. #
  337. # allow IPIP traffic because of the implicit SA created by the kernel if
  338. # IPComp is used (for small inbound packets that are not compressed).
  339. # INPUT is correct here even for forwarded traffic.
  340. if [ -n "$PLUTO_IPCOMP" ]
  341. then
  342. iptables -I INPUT 1 -i $PLUTO_INTERFACE -p 4 \
  343. -s $PLUTO_PEER -d $PLUTO_ME $IPSEC_POLICY_IN -j ACCEPT
  344. fi
  345. #
  346. # log IPsec client connection setup
  347. if [ $VPN_LOGGING ]
  348. then
  349. if [ "$PLUTO_PEER_CLIENT" = "$PLUTO_PEER/32" ]
  350. then
  351. logger -t $TAG -p $FAC_PRIO \
  352. "+ $PLUTO_PEER_ID $PLUTO_PEER -- $PLUTO_ME == $PLUTO_MY_CLIENT"
  353. else
  354. logger -t $TAG -p $FAC_PRIO \
  355. "+ $PLUTO_PEER_ID $PLUTO_PEER_CLIENT == $PLUTO_PEER -- $PLUTO_ME == $PLUTO_MY_CLIENT"
  356. fi
  357. fi
  358. ;;
  359. down-client:iptables)
  360. # connection to client subnet, with (left/right)firewall=yes, going down
  361. # This is used only by the default updown script, not by your custom
  362. # ones, so do not mess with it; see CAUTION comment up at top.
  363. if [ "$PLUTO_PEER_CLIENT" != "$PLUTO_MY_SOURCEIP/32" ]
  364. then
  365. iptables -D FORWARD -o $PLUTO_INTERFACE -p $PLUTO_PEER_PROTOCOL \
  366. -s $PLUTO_MY_CLIENT $S_MY_PORT \
  367. -d $PLUTO_PEER_CLIENT $D_PEER_PORT \
  368. $IPSEC_POLICY_OUT -j ACCEPT
  369. iptables -D FORWARD -i $PLUTO_INTERFACE -p $PLUTO_MY_PROTOCOL \
  370. -s $PLUTO_PEER_CLIENT $S_PEER_PORT \
  371. -d $PLUTO_MY_CLIENT $D_MY_PORT \
  372. $IPSEC_POLICY_IN -j ACCEPT
  373. fi
  374. #
  375. # a virtual IP requires an INPUT and OUTPUT rule on the host
  376. # or sometimes host access via the internal IP is needed
  377. if [ -n "$PLUTO_MY_SOURCEIP" -o -n "$PLUTO_HOST_ACCESS" ]
  378. then
  379. iptables -D INPUT -i $PLUTO_INTERFACE -p $PLUTO_MY_PROTOCOL \
  380. -s $PLUTO_PEER_CLIENT $S_PEER_PORT \
  381. -d $PLUTO_MY_CLIENT $D_MY_PORT \
  382. $IPSEC_POLICY_IN -j ACCEPT
  383. iptables -D OUTPUT -o $PLUTO_INTERFACE -p $PLUTO_PEER_PROTOCOL \
  384. -s $PLUTO_MY_CLIENT $S_MY_PORT \
  385. -d $PLUTO_PEER_CLIENT $D_PEER_PORT \
  386. $IPSEC_POLICY_OUT -j ACCEPT
  387. fi
  388. #
  389. # IPIP exception teardown
  390. if [ -n "$PLUTO_IPCOMP" ]
  391. then
  392. iptables -D INPUT -i $PLUTO_INTERFACE -p 4 \
  393. -s $PLUTO_PEER -d $PLUTO_ME $IPSEC_POLICY_IN -j ACCEPT
  394. fi
  395. #
  396. # log IPsec client connection teardown
  397. if [ $VPN_LOGGING ]
  398. then
  399. if [ "$PLUTO_PEER_CLIENT" = "$PLUTO_PEER/32" ]
  400. then
  401. logger -t $TAG -p $FAC_PRIO -- \
  402. "- $PLUTO_PEER_ID $PLUTO_PEER -- $PLUTO_ME == $PLUTO_MY_CLIENT"
  403. else
  404. logger -t $TAG -p $FAC_PRIO -- \
  405. "- $PLUTO_PEER_ID $PLUTO_PEER_CLIENT == $PLUTO_PEER -- $PLUTO_ME == $PLUTO_MY_CLIENT"
  406. fi
  407. fi
  408. ;;
  409. #
  410. # IPv6
  411. #
  412. up-host-v6:)
  413. # connection to me coming up
  414. # If you are doing a custom version, firewall commands go here.
  415. ;;
  416. down-host-v6:)
  417. # connection to me going down
  418. # If you are doing a custom version, firewall commands go here.
  419. ;;
  420. up-client-v6:)
  421. # connection to my client subnet coming up
  422. # If you are doing a custom version, firewall commands go here.
  423. ;;
  424. down-client-v6:)
  425. # connection to my client subnet going down
  426. # If you are doing a custom version, firewall commands go here.
  427. ;;
  428. up-host-v6:iptables)
  429. # connection to me, with (left/right)firewall=yes, coming up
  430. # This is used only by the default updown script, not by your custom
  431. # ones, so do not mess with it; see CAUTION comment up at top.
  432. ip6tables -I INPUT 1 -i $PLUTO_INTERFACE -p $PLUTO_MY_PROTOCOL \
  433. -s $PLUTO_PEER_CLIENT $S_PEER_PORT \
  434. -d $PLUTO_ME $D_MY_PORT $IPSEC_POLICY_IN -j ACCEPT
  435. ip6tables -I OUTPUT 1 -o $PLUTO_INTERFACE -p $PLUTO_PEER_PROTOCOL \
  436. -s $PLUTO_ME $S_MY_PORT $IPSEC_POLICY_OUT \
  437. -d $PLUTO_PEER_CLIENT $D_PEER_PORT -j ACCEPT
  438. #
  439. # allow IP6IP6 traffic because of the implicit SA created by the kernel if
  440. # IPComp is used (for small inbound packets that are not compressed)
  441. if [ -n "$PLUTO_IPCOMP" ]
  442. then
  443. ip6tables -I INPUT 1 -i $PLUTO_INTERFACE -p 41 \
  444. -s $PLUTO_PEER -d $PLUTO_ME $IPSEC_POLICY_IN -j ACCEPT
  445. fi
  446. #
  447. # log IPsec host connection setup
  448. if [ $VPN_LOGGING ]
  449. then
  450. if [ "$PLUTO_PEER_CLIENT" = "$PLUTO_PEER/128" ]
  451. then
  452. logger -t $TAG -p $FAC_PRIO \
  453. "+ $PLUTO_PEER_ID $PLUTO_PEER -- $PLUTO_ME"
  454. else
  455. logger -t $TAG -p $FAC_PRIO \
  456. "+ $PLUTO_PEER_ID $PLUTO_PEER_CLIENT == $PLUTO_PEER -- $PLUTO_ME"
  457. fi
  458. fi
  459. ;;
  460. down-host-v6:iptables)
  461. # connection to me, with (left/right)firewall=yes, going down
  462. # This is used only by the default updown script, not by your custom
  463. # ones, so do not mess with it; see CAUTION comment up at top.
  464. ip6tables -D INPUT -i $PLUTO_INTERFACE -p $PLUTO_MY_PROTOCOL \
  465. -s $PLUTO_PEER_CLIENT $S_PEER_PORT \
  466. -d $PLUTO_ME $D_MY_PORT $IPSEC_POLICY_IN -j ACCEPT
  467. ip6tables -D OUTPUT -o $PLUTO_INTERFACE -p $PLUTO_PEER_PROTOCOL \
  468. -s $PLUTO_ME $S_MY_PORT $IPSEC_POLICY_OUT \
  469. -d $PLUTO_PEER_CLIENT $D_PEER_PORT -j ACCEPT
  470. #
  471. # IP6IP6 exception teardown
  472. if [ -n "$PLUTO_IPCOMP" ]
  473. then
  474. ip6tables -D INPUT -i $PLUTO_INTERFACE -p 41 \
  475. -s $PLUTO_PEER -d $PLUTO_ME $IPSEC_POLICY_IN -j ACCEPT
  476. fi
  477. #
  478. # log IPsec host connection teardown
  479. if [ $VPN_LOGGING ]
  480. then
  481. if [ "$PLUTO_PEER_CLIENT" = "$PLUTO_PEER/128" ]
  482. then
  483. logger -t $TAG -p $FAC_PRIO -- \
  484. "- $PLUTO_PEER_ID $PLUTO_PEER -- $PLUTO_ME"
  485. else
  486. logger -t $TAG -p $FAC_PRIO -- \
  487. "- $PLUTO_PEER_ID $PLUTO_PEER_CLIENT == $PLUTO_PEER -- $PLUTO_ME"
  488. fi
  489. fi
  490. ;;
  491. up-client-v6:iptables)
  492. # connection to client subnet, with (left/right)firewall=yes, coming up
  493. # This is used only by the default updown script, not by your custom
  494. # ones, so do not mess with it; see CAUTION comment up at top.
  495. if [ "$PLUTO_PEER_CLIENT" != "$PLUTO_MY_SOURCEIP/128" ]
  496. then
  497. ip6tables -I FORWARD 1 -o $PLUTO_INTERFACE -p $PLUTO_PEER_PROTOCOL \
  498. -s $PLUTO_MY_CLIENT $S_MY_PORT \
  499. -d $PLUTO_PEER_CLIENT $D_PEER_PORT $IPSEC_POLICY_OUT -j ACCEPT
  500. ip6tables -I FORWARD 1 -i $PLUTO_INTERFACE -p $PLUTO_MY_PROTOCOL \
  501. -s $PLUTO_PEER_CLIENT $S_PEER_PORT \
  502. -d $PLUTO_MY_CLIENT $D_MY_PORT $IPSEC_POLICY_IN -j ACCEPT
  503. fi
  504. #
  505. # a virtual IP requires an INPUT and OUTPUT rule on the host
  506. # or sometimes host access via the internal IP is needed
  507. if [ -n "$PLUTO_MY_SOURCEIP" -o -n "$PLUTO_HOST_ACCESS" ]
  508. then
  509. ip6tables -I INPUT 1 -i $PLUTO_INTERFACE -p $PLUTO_MY_PROTOCOL \
  510. -s $PLUTO_PEER_CLIENT $S_PEER_PORT \
  511. -d $PLUTO_MY_CLIENT $D_MY_PORT $IPSEC_POLICY_IN -j ACCEPT
  512. ip6tables -I OUTPUT 1 -o $PLUTO_INTERFACE -p $PLUTO_PEER_PROTOCOL \
  513. -s $PLUTO_MY_CLIENT $S_MY_PORT \
  514. -d $PLUTO_PEER_CLIENT $D_PEER_PORT $IPSEC_POLICY_OUT -j ACCEPT
  515. fi
  516. #
  517. # allow IP6IP6 traffic because of the implicit SA created by the kernel if
  518. # IPComp is used (for small inbound packets that are not compressed).
  519. # INPUT is correct here even for forwarded traffic.
  520. if [ -n "$PLUTO_IPCOMP" ]
  521. then
  522. ip6tables -I INPUT 1 -i $PLUTO_INTERFACE -p 41 \
  523. -s $PLUTO_PEER -d $PLUTO_ME $IPSEC_POLICY_IN -j ACCEPT
  524. fi
  525. #
  526. # log IPsec client connection setup
  527. if [ $VPN_LOGGING ]
  528. then
  529. if [ "$PLUTO_PEER_CLIENT" = "$PLUTO_PEER/128" ]
  530. then
  531. logger -t $TAG -p $FAC_PRIO \
  532. "+ $PLUTO_PEER_ID $PLUTO_PEER -- $PLUTO_ME == $PLUTO_MY_CLIENT"
  533. else
  534. logger -t $TAG -p $FAC_PRIO \
  535. "+ $PLUTO_PEER_ID $PLUTO_PEER_CLIENT == $PLUTO_PEER -- $PLUTO_ME == $PLUTO_MY_CLIENT"
  536. fi
  537. fi
  538. ;;
  539. down-client-v6:iptables)
  540. # connection to client subnet, with (left/right)firewall=yes, going down
  541. # This is used only by the default updown script, not by your custom
  542. # ones, so do not mess with it; see CAUTION comment up at top.
  543. if [ "$PLUTO_PEER_CLIENT" != "$PLUTO_MY_SOURCEIP/128" ]
  544. then
  545. ip6tables -D FORWARD -o $PLUTO_INTERFACE -p $PLUTO_PEER_PROTOCOL \
  546. -s $PLUTO_MY_CLIENT $S_MY_PORT \
  547. -d $PLUTO_PEER_CLIENT $D_PEER_PORT \
  548. $IPSEC_POLICY_OUT -j ACCEPT
  549. ip6tables -D FORWARD -i $PLUTO_INTERFACE -p $PLUTO_MY_PROTOCOL \
  550. -s $PLUTO_PEER_CLIENT $S_PEER_PORT \
  551. -d $PLUTO_MY_CLIENT $D_MY_PORT \
  552. $IPSEC_POLICY_IN -j ACCEPT
  553. fi
  554. #
  555. # a virtual IP requires an INPUT and OUTPUT rule on the host
  556. # or sometimes host access via the internal IP is needed
  557. if [ -n "$PLUTO_MY_SOURCEIP" -o -n "$PLUTO_HOST_ACCESS" ]
  558. then
  559. ip6tables -D INPUT -i $PLUTO_INTERFACE -p $PLUTO_MY_PROTOCOL \
  560. -s $PLUTO_PEER_CLIENT $S_PEER_PORT \
  561. -d $PLUTO_MY_CLIENT $D_MY_PORT \
  562. $IPSEC_POLICY_IN -j ACCEPT
  563. ip6tables -D OUTPUT -o $PLUTO_INTERFACE -p $PLUTO_PEER_PROTOCOL \
  564. -s $PLUTO_MY_CLIENT $S_MY_PORT \
  565. -d $PLUTO_PEER_CLIENT $D_PEER_PORT \
  566. $IPSEC_POLICY_OUT -j ACCEPT
  567. fi
  568. #
  569. # IP6IP6 exception teardown
  570. if [ -n "$PLUTO_IPCOMP" ]
  571. then
  572. ip6tables -D INPUT -i $PLUTO_INTERFACE -p 41 \
  573. -s $PLUTO_PEER -d $PLUTO_ME $IPSEC_POLICY_IN -j ACCEPT
  574. fi
  575. #
  576. # log IPsec client connection teardown
  577. if [ $VPN_LOGGING ]
  578. then
  579. if [ "$PLUTO_PEER_CLIENT" = "$PLUTO_PEER/128" ]
  580. then
  581. logger -t $TAG -p $FAC_PRIO -- \
  582. "- $PLUTO_PEER_ID $PLUTO_PEER -- $PLUTO_ME == $PLUTO_MY_CLIENT"
  583. else
  584. logger -t $TAG -p $FAC_PRIO -- \
  585. "- $PLUTO_PEER_ID $PLUTO_PEER_CLIENT == $PLUTO_PEER -- $PLUTO_ME == $PLUTO_MY_CLIENT"
  586. fi
  587. fi
  588. ;;
  589. *) echo "$0: unknown verb \`$PLUTO_VERB' or parameter \`$1'" >&2
  590. exit 1
  591. ;;
  592. esac