File: genallocfile.pl

package info (click to toggle)
openswan 1%3A2.4.6%2Bdfsg.2-1.1%2Betch2
  • links: PTS
  • area: main
  • in suites: etch
  • size: 25,000 kB
  • ctags: 16,877
  • sloc: ansic: 121,112; sh: 19,782; xml: 9,699; asm: 4,422; perl: 4,087; makefile: 3,367; tcl: 713; exp: 657; yacc: 396; pascal: 328; lex: 289; sed: 265; awk: 124; lisp: 3
file content (84 lines) | stat: -rwxr-xr-x 1,803 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/perl

# create a file like:
#
#   {alloc,free}  edst spi proto src algo enckey authkey
#
# from pseudo-random data.

$operationCount=0;
$maxOperations=8194;

$proto="esp";
$src="192.1.2.23";
$algo="3des-md5-96";
$enckey="0x4043434545464649494a4a4c4c4f4f515152525454575758";
$authkey="0x87658765876587658765876587658765";


srand(19710421); # keep it pseudo-random, repeatable for now

&init_stuff;

$saCount=0;

@edst=();
@spi=();


while($operationCount < $maxOperations) {
  $operationCount++;

  # pick a random operation.

  $op=rand(4);

  if($op < 1 && $saCount > 0) {
    # generate a free with probability 25%, if there are any to free
    # pick an SA to free.
    
    $sanum=rand($saCount);
    $edst=$edst[$sanum];
    $spi=$spi[$sanum];
    
    #print "free $edst $spi $proto $src\n";
    print "ipsec spi --saref --af inet --edst $edst --spi $spi --proto $proto --del\n";
      
    if($sanum != $saCount-1) {
      # delete it, by copying one from end.
      $edst[$sanum]=$edst[$saCount-1];
      $spi[$sanum]=$spi[$saCount-1];
    }
    $saCount--;
  } else {
    # make a new one.

    $choice=int(rand(100));
    $edst=$edst_choices[$choice];
    $spi="0x".(int(rand(16777216))+1024);

    #print "alloc $edst $spi $proto $src\n";
    print "ipsec spi --saref --af inet --edst $edst --spi $spi --proto $proto --src $src --esp $algo --enckey $enckey --authkey $authkey\n";

    $edst[$saCount]=$edst;
    $spi[$saCount]=$spi;

    $saCount++;
  }
  if($maxSa < $saCount) {
  	$maxSa = $saCount;
  }
  print "echo saCount=$saCount $maxSa\n";
}

print "# maxSa = $maxSa\n";


sub init_stuff {
  # make up 100 random edst's

  for($i=0; $i<100; $i++) {
    $a=int(rand(256)); $b=int(rand(256)); $c=int(rand(256)); $d=int(rand(256));
    $edst_choices[$i]="$a.$b.$c.$d";
  }
}