~ubuntu-branches/ubuntu/saucy/openvpn/saucy

« back to all changes in this revision

Viewing changes to ping.c

  • Committer: Bazaar Package Importer
  • Author(s): Alberto Gonzalez Iniesta
  • Date: 2005-01-05 19:03:11 UTC
  • mto: (1.4.1) (10.1.1 lenny)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20050105190311-d0uioiqtor5xbzre
Tags: upstream-1.99+2.rc6
ImportĀ upstreamĀ versionĀ 1.99+2.rc6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  OpenVPN -- An application to securely tunnel IP networks
 
3
 *             over a single TCP/UDP port, with support for SSL/TLS-based
 
4
 *             session authentication and key exchange,
 
5
 *             packet encryption, packet authentication, and
 
6
 *             packet compression.
 
7
 *
 
8
 *  Copyright (C) 2002-2004 James Yonan <jim@yonan.net>
 
9
 *
 
10
 *  This program is free software; you can redistribute it and/or modify
 
11
 *  it under the terms of the GNU General Public License as published by
 
12
 *  the Free Software Foundation; either version 2 of the License, or
 
13
 *  (at your option) any later version.
 
14
 *
 
15
 *  This program is distributed in the hope that it will be useful,
 
16
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
 *  GNU General Public License for more details.
 
19
 *
 
20
 *  You should have received a copy of the GNU General Public License
 
21
 *  along with this program (see the file COPYING included with this
 
22
 *  distribution); if not, write to the Free Software Foundation, Inc.,
 
23
 *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
24
 */
 
25
 
 
26
#ifdef WIN32
 
27
#include "config-win32.h"
 
28
#else
 
29
#include "config.h"
 
30
#endif
 
31
 
 
32
#include "syshead.h"
 
33
 
 
34
#include "ping.h"
 
35
 
 
36
#include "memdbg.h"
 
37
 
 
38
#include "ping-inline.h"
 
39
 
 
40
/*
 
41
 * This random string identifies an OpenVPN ping packet.
 
42
 * It should be of sufficient length and randomness
 
43
 * so as not to collide with other tunnel data.
 
44
 *
 
45
 * PING_STRING_SIZE must be sizeof (ping_string)
 
46
 */
 
47
const uint8_t ping_string[] = {
 
48
  0x2a, 0x18, 0x7b, 0xf3, 0x64, 0x1e, 0xb4, 0xcb,
 
49
  0x07, 0xed, 0x2d, 0x0a, 0x98, 0x1f, 0xc7, 0x48
 
50
};
 
51
 
 
52
/*
 
53
 * Should we exit or restart due to ping (or other authenticated packet)
 
54
 * not received in n seconds?
 
55
 */
 
56
void
 
57
check_ping_restart_dowork (struct context *c)
 
58
{
 
59
  struct gc_arena gc = gc_new ();
 
60
  switch (c->options.ping_rec_timeout_action)
 
61
    {
 
62
    case PING_EXIT:
 
63
      msg (M_INFO, "%sInactivity timeout (--ping-exit), exiting",
 
64
           format_common_name (c, &gc));
 
65
      c->sig->signal_received = SIGTERM;
 
66
      c->sig->signal_text = "ping-exit";
 
67
      break;
 
68
    case PING_RESTART:
 
69
      msg (M_INFO, "%sInactivity timeout (--ping-restart), restarting",
 
70
           format_common_name (c, &gc));
 
71
      c->sig->signal_received = SIGUSR1; /* SOFT-SIGUSR1 -- Ping Restart */
 
72
      c->sig->signal_text = "ping-restart";
 
73
      break;
 
74
    default:
 
75
      ASSERT (0);
 
76
    }
 
77
  gc_free (&gc);
 
78
}
 
79
 
 
80
/*
 
81
 * Should we ping the remote?
 
82
 */
 
83
void
 
84
check_ping_send_dowork (struct context *c)
 
85
{
 
86
  c->c2.buf = c->c2.buffers->aux_buf;
 
87
  ASSERT (buf_init (&c->c2.buf, FRAME_HEADROOM (&c->c2.frame)));
 
88
  ASSERT (buf_safe (&c->c2.buf, MAX_RW_SIZE_TUN (&c->c2.frame)));
 
89
  ASSERT (buf_write (&c->c2.buf, ping_string, sizeof (ping_string)));
 
90
 
 
91
  /*
 
92
   * We will treat the ping like any other outgoing packet,
 
93
   * encrypt, sign, etc.
 
94
   */
 
95
  encrypt_sign (c, true);
 
96
  dmsg (D_PACKET_CONTENT, "SENT PING");  
 
97