~ubuntu-branches/ubuntu/precise/strongswan/precise

« back to all changes in this revision

Viewing changes to src/pluto/connections.c

  • Committer: Bazaar Package Importer
  • Author(s): Bhavani Shankar
  • Date: 2010-10-18 10:19:52 UTC
  • mfrom: (6.1.9 sid)
  • Revision ID: james.westby@ubuntu.com-20101018101952-zqd04yd4jvls81mj
Tags: 4.4.1-5ubuntu1
* Merge from debian unstable. Remaining change
  - Build depend on libnm-glib-dev instead of libnm-glib-vpn-dev to
    match the network manager package naming in Ubuntu

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
#include "nat_traversal.h"
64
64
#include "virtual.h"
65
65
#include "whack_attribute.h"
 
66
#include "modecfg.h"
66
67
 
67
68
static void flush_pending_by_connection(connection_t *c);  /* forward */
68
69
 
294
295
 
295
296
void delete_connection(connection_t *c, bool relations)
296
297
{
297
 
        connection_t *old_cur_connection
298
 
                = cur_connection == c? NULL : cur_connection;
 
298
        modecfg_attribute_t *ca;
 
299
        connection_t *old_cur_connection;
 
300
 
 
301
        old_cur_connection = cur_connection == c? NULL : cur_connection;
299
302
#ifdef DEBUG
300
303
        lset_t old_cur_debugging = cur_debugging;
301
304
#endif
366
369
 
367
370
        /* release virtual IP address lease if any */
368
371
        if (c->spd.that.modecfg && c->spd.that.pool &&
369
 
                !isanyaddr(&c->spd.that.host_srcip))
 
372
                !c->spd.that.host_srcip->is_anyaddr(c->spd.that.host_srcip))
370
373
        {
371
 
                host_t *vip;
372
 
 
373
 
                vip = host_create_from_sockaddr((sockaddr_t*)&c->spd.that.host_srcip);
374
374
                hydra->attributes->release_address(hydra->attributes, c->spd.that.pool,
375
 
                                                                                   vip, c->spd.that.id);
376
 
                vip->destroy(vip);
 
375
                                                                                   c->spd.that.host_srcip, c->spd.that.id);
 
376
        }
 
377
 
 
378
        /* release requested attributes if any */
 
379
        if (c->requested)
 
380
        {
 
381
                c->requested->destroy_function(c->requested,
 
382
                                                                          (void*)modecfg_attribute_destroy);
 
383
        }
 
384
 
 
385
        /* release other attributes if any */
 
386
        if (c->attributes)
 
387
        {
 
388
                while (c->attributes->remove_last(c->attributes, (void **)&ca) == SUCCESS)
 
389
                {
 
390
                        hydra->attributes->release(hydra->attributes, ca->handler,
 
391
                                                                           c->spd.that.id, ca->type, ca->value);
 
392
                        modecfg_attribute_destroy(ca);
 
393
                }
 
394
                c->attributes->destroy(c->attributes);
377
395
        }
378
396
 
379
397
        if (c->kind != CK_GOING_AWAY)
386
404
        cur_debugging = old_cur_debugging;
387
405
#endif
388
406
        free(c->name);
 
407
        DESTROY_IF(c->xauth_identity);
389
408
        DESTROY_IF(c->spd.this.id);
390
409
        DESTROY_IF(c->spd.this.ca);
391
410
        DESTROY_IF(c->spd.this.groups);
 
411
        DESTROY_IF(c->spd.this.host_srcip);
392
412
        free(c->spd.this.updown);
393
413
        free(c->spd.this.pool);
394
414
        DESTROY_IF(c->spd.that.id);
395
415
        DESTROY_IF(c->spd.that.ca);
396
416
        DESTROY_IF(c->spd.that.groups);
 
417
        DESTROY_IF(c->spd.that.host_srcip);
397
418
        free(c->spd.that.updown);
398
419
        free(c->spd.that.pool);
399
420
        if (c->requested_ca)
656
677
                        subnettot(&this->client, 0, client, sizeof(client));
657
678
                }
658
679
        }
659
 
        else if (this->modecfg && isanyaddr(&this->host_srcip))
 
680
        else if (this->modecfg && this->host_srcip->is_anyaddr(this->host_srcip))
660
681
        {
661
682
                /* we are mode config client, or a server with a pool */
662
683
                client_sep = "===";
738
759
static void unshare_connection_strings(connection_t *c)
739
760
{
740
761
        c->name = clone_str(c->name);
 
762
        if (c->xauth_identity)
 
763
        {
 
764
                c->xauth_identity = c->xauth_identity->clone(c->xauth_identity);
 
765
        }
741
766
        c->spd.this.id = c->spd.this.id->clone(c->spd.this.id);
742
767
        c->spd.this.pool = clone_str(c->spd.this.pool);
743
768
        c->spd.this.updown = clone_str(c->spd.this.updown);
 
769
        c->spd.this.host_srcip = c->spd.this.host_srcip->clone(c->spd.this.host_srcip);
744
770
        scx_share(c->spd.this.sc);
745
771
        cert_share(c->spd.this.cert);
746
772
        if (c->spd.this.ca)
754
780
        c->spd.that.id = c->spd.that.id->clone(c->spd.that.id);
755
781
        c->spd.that.pool = clone_str(c->spd.that.pool);
756
782
        c->spd.that.updown = clone_str(c->spd.that.updown);
 
783
        c->spd.that.host_srcip = c->spd.that.host_srcip->clone(c->spd.that.host_srcip);
757
784
        scx_share(c->spd.that.sc);
758
785
        cert_share(c->spd.that.cert);
759
786
        if (c->spd.that.ca)
902
929
        /* the rest is simple copying of corresponding fields */
903
930
        dst->host_addr = src->host_addr;
904
931
        dst->host_nexthop = src->host_nexthop;
905
 
        dst->host_srcip = src->host_srcip;
 
932
        dst->host_srcip = host_create_from_sockaddr((sockaddr_t*)&src->host_srcip);
906
933
        dst->has_natip = src->has_natip;
907
934
        dst->client = src->client;
908
935
        dst->protocol = src->protocol;
927
954
        /* if host sourceip is defined but no client is present
928
955
         * behind the host then set client to sourceip/32
929
956
         */
930
 
        if (addrbytesptr(&dst->host_srcip, NULL) &&
931
 
                !isanyaddr(&dst->host_srcip) && !dst->has_natip && !dst->has_client)
 
957
        if (!dst->host_srcip->is_anyaddr(dst->host_srcip) &&
 
958
                !dst->has_natip && !dst->has_client)
932
959
        {
933
 
                err_t ugh = addrtosubnet(&dst->host_srcip, &dst->client);
 
960
                ip_address addr;
 
961
                err_t ugh;
 
962
 
 
963
                addr = *(ip_address*)dst->host_srcip->get_sockaddr(dst->host_srcip);
 
964
                ugh = addrtosubnet(&addr, &dst->client);
934
965
 
935
966
                if (ugh)
936
967
                {
1110
1141
                        }
1111
1142
                }
1112
1143
 
 
1144
                if (wm->xauth_identity)
 
1145
                {
 
1146
                        c->xauth_identity
 
1147
                                        = identification_create_from_string(wm->xauth_identity);
 
1148
                }
 
1149
 
1113
1150
                c->sa_ike_life_seconds = wm->sa_ike_life_seconds;
1114
1151
                c->sa_ipsec_life_seconds = wm->sa_ipsec_life_seconds;
1115
1152
                c->sa_rekey_margin = wm->sa_rekey_margin;
1211
1248
                        c->spd.that.modecfg = TRUE;
1212
1249
                        c->spd.that.has_client = FALSE;
1213
1250
                        /* reset the host_srcip so that it gets assigned in modecfg */
1214
 
                        anyaddr(AF_INET, &c->spd.that.host_srcip);
 
1251
                        DESTROY_IF(c->spd.that.host_srcip);
 
1252
                        c->spd.that.host_srcip = host_create_any(AF_INET);
1215
1253
                }
1216
1254
 
1217
1255
                if (c->ikev1)
3046
3084
        /* the connection is now oriented so that we are able to determine
3047
3085
         * whether we are a mode config server with a virtual IP to send.
3048
3086
         */
3049
 
        if (!isanyaddr(&c->spd.that.host_srcip) && !c->spd.that.has_natip)
 
3087
        if (!c->spd.that.host_srcip->is_anyaddr(c->spd.that.host_srcip) &&
 
3088
            !c->spd.that.has_natip)
3050
3089
        {
3051
3090
                c->spd.that.modecfg = TRUE;
3052
3091
        }
3693
3732
                        }
3694
3733
                        else
3695
3734
                        {
 
3735
                                host_t *vip = c->spd.that.host_srcip;
 
3736
 
3696
3737
                                if (!peer_net_is_host && !(sr->that.modecfg && c->spd.that.modecfg &&
3697
 
                                                subnetisaddr(peer_net, &c->spd.that.host_srcip)))
 
3738
                                                subnetisaddr(peer_net, (ip_address*)vip->get_sockaddr(vip))))
3698
3739
                                {
3699
3740
                                        continue;
3700
3741
                                }