~smoser/ubuntu/oneiric/openvpn/lp-794916

« back to all changes in this revision

Viewing changes to reliable.c

  • Committer: Bazaar Package Importer
  • Author(s): Alberto Gonzalez Iniesta
  • Date: 2008-08-16 13:34:24 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20080816133424-0i83yb6dw4hjglo1
Tags: 2.1~rc9-3
* debian/rules: run ./configure with path to 'route', for
  those build daemons without 'route'. (Closes: #495082)
* Created NEWS.Debian with info on new option script-security.
  (Closes: #494998)

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 *             packet encryption, packet authentication, and
6
6
 *             packet compression.
7
7
 *
8
 
 *  Copyright (C) 2002-2008 OpenVPN Solutions LLC <info@openvpn.net>
 
8
 *  Copyright (C) 2002-2008 Telethra, Inc. <sales@openvpn.net>
9
9
 *
10
10
 *  This program is free software; you can redistribute it and/or modify
11
11
 *  it under the terms of the GNU General Public License version 2
38
38
 
39
39
#include "memdbg.h"
40
40
 
 
41
/*
 
42
 * verify that test - base < extent while allowing for base or test wraparound
 
43
 */
 
44
static inline bool
 
45
reliable_pid_in_range (const packet_id_type test,
 
46
                       const packet_id_type base,
 
47
                       const unsigned int extent)
 
48
{
 
49
  if (test >= base)
 
50
    {
 
51
      if (test - base < extent)
 
52
        return true;
 
53
    }
 
54
  else
 
55
    {      
 
56
      const packet_id_type be = base + extent;
 
57
      if (test < be && be < base)
 
58
        return true;
 
59
    }
 
60
 
 
61
  return false;
 
62
}
 
63
 
 
64
/*
 
65
 * verify that p1 < p2  while allowing for p1 or p2 wraparound
 
66
 */
 
67
static inline bool
 
68
reliable_pid_min (const packet_id_type p1,
 
69
                  const packet_id_type p2)
 
70
{
 
71
  return !reliable_pid_in_range (p1, p2, 0x80000000);
 
72
}
 
73
 
41
74
/* check if a particular packet_id is present in ack */
42
75
static inline bool
43
76
reliable_ack_packet_id_present (struct reliable_ack *ack, packet_id_type pid)
330
363
{
331
364
  struct gc_arena gc = gc_new ();
332
365
  int i;
333
 
  if (id < rel->packet_id)
 
366
  if (reliable_pid_min (id, rel->packet_id))
334
367
    goto bad;
335
368
  for (i = 0; i < rel->size; ++i)
336
369
    {
352
385
reliable_wont_break_sequentiality (const struct reliable *rel, packet_id_type id)
353
386
{
354
387
  struct gc_arena gc = gc_new ();
355
 
  int ret;
356
 
 
357
 
  if ((int)id < (int)rel->packet_id + rel->size)
358
 
    {
359
 
      ret = true;
360
 
    }
361
 
  else
 
388
 
 
389
  const int ret = reliable_pid_in_range (id, rel->packet_id, rel->size);
 
390
 
 
391
  if (!ret)
362
392
    {
363
393
      dmsg (D_REL_LOW, "ACK " packet_id_format " breaks sequentiality: %s",
364
394
           (packet_id_print_type)id, reliable_print_ids (rel, &gc));
365
 
      ret = false;
366
395
    }
 
396
 
 
397
  dmsg (D_REL_DEBUG, "ACK RWBS rel->size=%d rel->packet_id=%08x id=%08x ret=%d\n", rel->size, rel->packet_id, id, ret);
 
398
 
367
399
  gc_free (&gc);
368
400
  return ret;
369
401
}
401
433
      const struct reliable_entry *e = &rel->array[i];
402
434
      if (e->active)
403
435
        {
404
 
          if (!min_id_defined || e->packet_id < min_id)
 
436
          if (!min_id_defined || reliable_pid_min (e->packet_id, min_id))
405
437
            {
406
438
              min_id_defined = true;
407
439
              min_id = e->packet_id;
409
441
        }
410
442
    }
411
443
 
412
 
  if (!min_id_defined || (int)(rel->packet_id - min_id) < rel->size)
 
444
  if (!min_id_defined || reliable_pid_in_range (rel->packet_id, min_id, rel->size))
413
445
    {
414
446
      ret = reliable_get_buf (rel);
415
447
    }
496
528
      struct reliable_entry *e = &rel->array[i];
497
529
      if (e->active && local_now >= e->next_try)
498
530
        {
499
 
          if (!best || e->packet_id < best->packet_id)
 
531
          if (!best || reliable_pid_min (e->packet_id, best->packet_id))
500
532
            best = e;
501
533
        }
502
534
    }
592
624
          e->packet_id = pid;
593
625
 
594
626
          /* check for replay */
595
 
          ASSERT (pid >= rel->packet_id);
 
627
          ASSERT (!reliable_pid_min (pid, rel->packet_id));
596
628
 
597
629
          e->opcode = opcode;
598
630
          e->next_try = 0;