📄 ipsec_init.c
字号:
/* * @(#) Initialization code. * Copyright (C) 1996, 1997 John Ioannidis. * Copyright (C) 1998, 1999, 2000, 2001 Richard Guy Briggs <rgb@freeswan.org> * 2001 Michael Richardson <mcr@freeswan.org> * * 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 <http://www.fsf.org/copyleft/gpl.txt>. * * 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. * * /proc system code was split out into ipsec_proc.c after rev. 1.70. * */char ipsec_init_c_version[] = "RCSID $Id: ipsec_init.c,v 1.2 2002/09/05 03:27:08 ken Exp $";#include <linux/config.h>#include <linux/version.h>#include <linux/module.h>#include <linux/kernel.h> /* printk() */#include "ipsec_param.h"#ifdef MALLOC_SLAB# include <linux/slab.h> /* kmalloc() */#else /* MALLOC_SLAB */# include <linux/malloc.h> /* kmalloc() */#endif /* MALLOC_SLAB */#include <linux/errno.h> /* error codes */#include <linux/types.h> /* size_t */#include <linux/interrupt.h> /* mark_bh */#include <linux/netdevice.h> /* struct device, and other headers */#include <linux/etherdevice.h> /* eth_type_trans */#include <linux/ip.h> /* struct iphdr */#include <linux/in.h> /* struct sockaddr_in */#include <linux/skbuff.h>#include <freeswan.h>#ifdef NET_21# include <asm/uaccess.h># include <linux/in6.h>#endif /* NET_21 */#include <asm/checksum.h>#include <net/ip.h>#ifdef CONFIG_PROC_FS# include <linux/proc_fs.h>#endif /* CONFIG_PROC_FS */#ifdef NETLINK_SOCK# include <linux/netlink.h>#else# include <net/netlink.h>#endif#include "radij.h"#include "ipsec_life.h"#include "ipsec_stats.h"#include "ipsec_sa.h"#include "ipsec_encap.h"#include "ipsec_radij.h"#include "ipsec_netlink.h"#include "ipsec_xform.h"#include "ipsec_tunnel.h"#include "ipsec_rcv.h"#include "ipsec_ah.h"#include "ipsec_esp.h"#ifdef CONFIG_IPSEC_IPCOMP# include "ipcomp.h"#endif /* CONFIG_IPSEC_IPCOMP */#include "ipsec_proto.h"#include "ipsec_alg.h"#include <pfkeyv2.h>#include <pfkey.h>#if !defined(CONFIG_IPSEC_ESP) && !defined(CONFIG_IPSEC_AH)#error "kernel configuration must include ESP or AH"#endif/* * seems to be present in 2.4.10 (Linus), but also in some RH and other * distro kernels of a lower number. */#ifdef MODULE_LICENSEMODULE_LICENSE("Dual BSD/GPL");#endif#ifdef CONFIG_IPSEC_DEBUGint debug_eroute = 0;int debug_spi = 0;int debug_netlink = 0;#endif /* CONFIG_IPSEC_DEBUG */int ipsec_device_event(struct notifier_block *dnot, unsigned long event, void *ptr);/* * the following structure is required so that we receive * event notifications when network devices are enabled and * disabled (ifconfig up and down). */static struct notifier_block ipsec_dev_notifier={ ipsec_device_event, NULL, 0};#ifdef CONFIG_SYSCTLextern int ipsec_sysctl_register(void);extern void ipsec_sysctl_unregister(void);#endif/* void */intipsec_init(void){ int error = 0;#ifdef CONFIG_IPSEC_ENC_3DES extern int des_check_key; /* turn off checking of keys */ des_check_key=0;#endif /* CONFIG_IPSEC_ENC_3DES */ KLIPS_PRINT(1, "klips_info:ipsec_init: " "KLIPS startup, FreeS/WAN IPSec version: %s\n", ipsec_version_code()); error |= ipsec_proc_init();#ifndef SPINLOCK tdb_lock.lock = 0; eroute_lock.lock = 0;#endif /* !SPINLOCK */ error |= ipsec_sadb_init(); error |= ipsec_radijinit(); error |= pfkey_init(); error |= register_netdevice_notifier(&ipsec_dev_notifier);#ifdef CONFIG_IPSEC_ESP inet_add_protocol(&esp_protocol);#endif /* CONFIG_IPSEC_ESP */#ifdef CONFIG_IPSEC_AH inet_add_protocol(&ah_protocol);#endif /* CONFIG_IPSEC_AH */#if 0#ifdef CONFIG_IPSEC_IPCOMP inet_add_protocol(&comp_protocol);#endif /* CONFIG_IPSEC_IPCOMP */#endif error |= ipsec_tunnel_init_devices();#ifdef CONFIG_SYSCTL error |= ipsec_sysctl_register();#endif #ifdef CONFIG_IPSEC_ALG ipsec_alg_init();#endif return error;} /* void */intipsec_cleanup(void){ int error = 0;#ifdef CONFIG_SYSCTL ipsec_sysctl_unregister();#endif KLIPS_PRINT(debug_netlink, /* debug_tunnel & DB_TN_INIT, */ "klips_debug:ipsec_cleanup: " "calling ipsec_tunnel_cleanup_devices.\n"); error |= ipsec_tunnel_cleanup_devices();#if 0#ifdef CONFIG_IPSEC_IPCOMP if (inet_del_protocol(&comp_protocol) < 0) printk(KERN_INFO "klips_debug:ipsec_cleanup: " "comp close: can't remove protocol\n");#endif /* CONFIG_IPSEC_IPCOMP */#endif /* 0 */#ifdef CONFIG_IPSEC_AH if (inet_del_protocol(&ah_protocol) < 0) printk(KERN_INFO "klips_debug:ipsec_cleanup: " "ah close: can't remove protocol\n");#endif /* CONFIG_IPSEC_AH */#ifdef CONFIG_IPSEC_ESP if (inet_del_protocol(&esp_protocol) < 0) printk(KERN_INFO "klips_debug:ipsec_cleanup: " "esp close: can't remove protocol\n");#endif /* CONFIG_IPSEC_ESP */ error |= unregister_netdevice_notifier(&ipsec_dev_notifier); KLIPS_PRINT(debug_netlink, /* debug_tunnel & DB_TN_INIT, */ "klips_debug:ipsec_cleanup: " "calling ipsec_tdbcleanup.\n"); error |= ipsec_sadb_cleanup(0); KLIPS_PRINT(debug_netlink, /* debug_tunnel & DB_TN_INIT, */ "klips_debug:ipsec_cleanup: " "calling ipsec_radijcleanup.\n"); error |= ipsec_radijcleanup(); KLIPS_PRINT(debug_pfkey, /* debug_tunnel & DB_TN_INIT, */ "klips_debug:ipsec_cleanup: " "calling pfkey_cleanup.\n"); error |= pfkey_cleanup(); ipsec_proc_cleanup(); return error;}#ifdef MODULEintinit_module(void){ int error = 0; error |= ipsec_init(); return error;}intcleanup_module(void){ int error = 0; KLIPS_PRINT(debug_netlink, /* debug_tunnel & DB_TN_INIT, */ "klips_debug:cleanup_module: " "calling ipsec_cleanup.\n"); error |= ipsec_cleanup(); KLIPS_PRINT(1, "klips_info:cleanup_module: " "ipsec module unloaded.\n"); return error;}#endif /* MODULE *//* * $Log: ipsec_init.c,v $ * Revision 1.2 2002/09/05 03:27:08 ken * Applied freeswan-alg-0.8.0-BASE-klips.diff * * Revision 1.1.1.1 2002/09/05 03:13:17 ken * 1.98b * * Revision 1.80 2002/03/24 07:34:08 rgb * Sanity check for at least one of AH or ESP configured. * * Revision 1.79 2002/02/05 22:55:15 mcr * added MODULE_LICENSE declaration. * This macro does not appear in all kernel versions (see comment). * * Revision 1.78 2002/01/29 17:17:55 mcr * moved include of ipsec_param.h to after include of linux/kernel.h * otherwise, it seems that some option that is set in ipsec_param.h * screws up something subtle in the include path to kernel.h, and * it complains on the snprintf() prototype. * * Revision 1.77 2002/01/29 04:00:51 mcr * more excise of kversions.h header. * * Revision 1.76 2002/01/29 02:13:17 mcr * introduction of ipsec_kversion.h means that include of * ipsec_param.h must preceed any decisions about what files to * include to deal with differences in kernel source. * * Revision 1.75 2001/11/26 09:23:48 rgb * Merge MCR's ipsec_sa, eroute, proc and struct lifetime changes. * * Revision 1.74 2001/11/22 05:44:11 henry * new version stuff * * Revision 1.71.2.2 2001/10/22 20:51:00 mcr * explicitely set des_check_key. * * Revision 1.71.2.1 2001/09/25 02:19:39 mcr * /proc manipulation code moved to new ipsec_proc.c * * Revision 1.73 2001/11/06 19:47:17 rgb * Changed lifetime_packets to uint32 from uint64. * * Revision 1.72 2001/10/18 04:45:19 rgb * 2.4.9 kernel deprecates linux/malloc.h in favour of linux/slab.h, * lib/freeswan.h version macros moved to lib/kversions.h. * Other compiler directive cleanups. * * Revision 1.71 2001/09/20 15:32:45 rgb * Minor pfkey lifetime fixes. * * Revision 1.70 2001/07/06 19:51:21 rgb * Added inbound policy checking code for IPIP SAs. * * Revision 1.69 2001/06/14 19:33:26 rgb * Silence startup message for console, but allow it to be logged. * Update copyright date. * * Revision 1.68 2001/05/29 05:14:36 rgb * Added PMTU to /proc/net/ipsec_tncfg output. See 'man 5 ipsec_tncfg'. * * Revision 1.67 2001/05/04 16:34:52 rgb * Rremove erroneous checking of return codes for proc_net_* in 2.4. * * Revision 1.66 2001/05/03 19:40:34 rgb * Check error return codes in startup and shutdown. * * Revision 1.65 2001/02/28 05:03:27 rgb * Clean up and rationalise startup messages.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -