From aa0f5b38aec14428b4b80e06f90ff781f8bca5f1 Mon Sep 17 00:00:00 2001 From: Rene Mayrhofer Date: Mon, 22 May 2006 05:12:18 +0000 Subject: Import initial strongswan 2.7.0 version into SVN. --- programs/spi/spi.c | 1689 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1689 insertions(+) create mode 100644 programs/spi/spi.c (limited to 'programs/spi/spi.c') diff --git a/programs/spi/spi.c b/programs/spi/spi.c new file mode 100644 index 000000000..369d556c7 --- /dev/null +++ b/programs/spi/spi.c @@ -0,0 +1,1689 @@ +/* + * All-in-one program to set Security Association parameters + * Copyright (C) 1996 John Ioannidis. + * Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Richard Guy Briggs. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. See . + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +char spi_c_version[] = "RCSID $Id: spi.c,v 1.7 2004/10/14 20:03:26 as Exp $"; + +#include +#include +#include +/* #include */ +#include +/* #include */ /* new */ +#include +#include +#include +#include + +/* #include */ + +#include +#include +/* #include */ +#include + +#include +#include +#include +#include +#include +#include +#if 0 +#include /* CONFIG_IPSEC_PFKEYv2 */ +#endif + #include + #include + #include + #include + +#include "freeswan/radij.h" +#include "freeswan/ipsec_encap.h" +#include "freeswan/ipsec_xform.h" +#include "freeswan/ipsec_ipe4.h" +#include "freeswan/ipsec_ah.h" +#include "freeswan/ipsec_esp.h" +#include "freeswan/ipsec_sa.h" /* IPSEC_SAREF_NULL */ + +/* + * Manual conn support for ipsec_alg (modular algos). + * Rather ugly to include from pluto dir but avoids + * code duplication. + */ +#ifndef NO_KERNEL_ALG +#include "../pluto/alg_info.h" +#include "../pluto/constants.h" +struct connection; +#include "../pluto/kernel_alg.h" +#endif /* NO_KERNEL_ALG */ + +char *program_name; +int debug = 0; +int saref = 0; +char *command; +extern char *optarg; +extern int optind, opterr, optopt; +char scratch[2]; +char *iv = NULL, *enckey = NULL, *authkey = NULL; +size_t ivlen = 0, enckeylen = 0, authkeylen = 0; +ip_address edst, dst, src; +int address_family = 0; +unsigned char proto = 0; +int alg = 0; + +#ifndef NO_KERNEL_ALG +/* + * Manual connection support for modular algos (ipsec_alg) --Juanjo. + */ +#define XF_OTHER_ALG (XF_CLR-1) /* define magic XF_ symbol for alg_info's */ +#include +const char *alg_string = NULL; /* algorithm string */ +struct alg_info_esp *alg_info = NULL; /* algorithm info got from string */ +struct esp_info *esp_info = NULL; /* esp info from 1st (only) element */ +const char *alg_err; /* auxiliar for parsing errors */ +int proc_read_ok = 0; /* /proc/net/pf_key_support read ok */ +#endif /* NO_KERNEL_ALG */ + +int replay_window = 0; +char sa[SATOT_BUF]; + +extern unsigned int pfkey_lib_debug; /* used by libfreeswan/pfkey_v2_build */ +int pfkey_sock; +fd_set pfkey_socks; +uint32_t pfkey_seq = 0; +enum life_severity { + life_soft = 0, + life_hard = 1, + life_maxsever = 2 +}; +enum life_type { + life_alloc = 0, + life_bytes = 1, + life_addtime = 2, + life_usetime = 3, + life_packets = 4, + life_maxtype = 5 +}; + +#define streql(_a,_b) (!strcmp((_a),(_b))) + +static const char *usage_string = "\ +Usage:\n\ + in the following, is: --af --edst --spi --proto \n\ + OR: --said <.|:>@\n\ + is: --life -=[,...]\n\ +spi --clear\n\ +spi --help\n\ +spi --version\n\ +spi\n\ +spi --del \n\ +spi --ip4 --src --dst \n\ +spi --ip6 --src --dst \n\ +spi --ah [ ][ --replay_window ] --authkey \n\ + where is one of: hmac-md5-96 | hmac-sha1-96\n\ +spi --esp [ ][ --replay_window ] --enckey --authkey \n\ + where is one of: 3des-md5-96 | 3des-sha1-96\n\ +spi --esp [ ][ --replay_window ] --enckey \n\ + where is: 3des\n\ +spi --comp \n\ + where is: deflate\n\ +[ --debug ] is optional to any spi command.\n\ +[ --label