HEAD: rearrange things a bit so we can have a libwvbase.so, which contains
[wvapps.git] / wvipsec / wvipsecguide.cc
blobd8b1152afcf3f487bb4fb2ace50b31ec0e412a7c
1 /*
2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
5 * WvIpSecGuide is a "gateway" object that groups all the routes
6 * belonging to one IPSec Tunnel.
7 */
9 #include "wvesp.h"
10 #include "wvipsecguide.h"
11 #include "wvipseckeeper.h"
12 #include "wvisakmp.h"
13 #include "wvcrypto.h"
14 #include "wvtundev.h"
15 #include <assert.h>
16 #include <time.h>
18 WvIpSecGuide::WvIpSecGuide(WvIpSecKeeper *_parent, const WvIPAddr &_gateway)
19 : WvNGRouteContainer(_parent), cfg(_parent->cfg), keeper(*_parent),
20 log("WvIpSecGuide", WvLog::Debug3)
22 log("Constructor\n");
24 isakmp = NULL;
25 esp = NULL;
27 WvIPAddr addr(cfg.get("Global", "IPAddr", "192.168.42.42"));
28 tundev = new WvTunDev(addr, 1400 /*mtu*/);
30 net() = _gateway;
31 gateway() = _gateway;
32 metric() = METRIC_TUNNEL;
33 ifcname() = tundev->ifcname;
35 keeper.selectlist.append(&selectlist, false);
37 last_probe_time = 0;
40 WvIpSecGuide::~WvIpSecGuide()
42 log("Destructor\n");
44 if (isakmp != NULL)
46 selectlist.unlink(isakmp);
47 delete isakmp;
48 isakmp = NULL;
51 if (esp != NULL)
53 delete esp;
54 esp = NULL;
57 delete tundev;
60 void WvIpSecGuide::changed_sa(int spi, WvCryptoEncoder *enc,
61 WvCryptoEncoder *dec, WvIsaKmp::actions action)
63 log("change_sa()\n");
65 switch (action)
67 case WvIsaKmp::Create:
68 if (esp)
69 selectlist.seterr("Multiple esp connections not supported!\n");
70 else
72 esp = new WvEsp(this, cfg);
73 esp->set_spi(spi);
74 esp->set_cryptcoders(enc, dec);
75 esp->set_tundev(tundev);
76 // shouldn't have to add to selectlist, cause that already happens
77 // and WvEsp isn't a stream anyways :)
79 break;
80 case WvIsaKmp::Change:
81 break;
82 case WvIsaKmp::Delete:
83 if (esp)
85 delete esp;
86 esp = NULL;
88 else
90 selectlist.seterr("Something fishy - trying to delete non-existant esp!\n");
92 break;
93 default:
94 log(WvLog::Error, "How did we get here??");
95 selectlist.seterr("Weasels are NOT funny!\n");
99 void WvIpSecGuide::create_routes()
104 void WvIpSecGuide::forget_my_routes()
109 void WvIpSecGuide::start_isakmp()
111 WvString localaddr = cfg.get("Global", "IPAddr", "192.168.42.42");
112 WvString remoteaddr = cfg.get("WvIpSec", "connection", "10.1.0.10");
113 WvString shared_secret = cfg.get("WvIpSec", "Preshared key", NULL);
115 isakmp = new WvIsaKmp(cfg, true, shared_secret, localaddr, remoteaddr);
116 isakmp->set_espcallback(WvIsaKmp::EspCallback(this, &WvIpSecGuide::changed_sa));
117 selectlist.append(isakmp, true);