⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ipsec_init.c

📁 网上下到的一个很详细介绍VPN基础知识的资料
💻 C
📖 第 1 页 / 共 3 页
字号:
			{				tdbp2 = tdbp;				while(tdbp2) {					sa_len = satoa(tdbp2->tdb_said, 0, sa, SATOA_BUF);					len += sprintf(buffer + len, "%s ",						       sa_len ? sa : " (error)");					tdbp2 = tdbp2->tdb_onext;				}				len += sprintf(buffer + len, "\n");				pos = begin + len;				if(pos < offset) {					len = 0;					begin = pos;				}				if (pos > offset + length) {					goto done_spigrp_i;				}			}		}	} done_spigrp_i:		spin_unlock_bh(&tdb_lock);	*start = buffer + (offset - begin);	/* Start of wanted data */	len -= (offset - begin);			/* Start slop */	if (len > length)		len = length;	return len;}#ifndef PROC_FS_2325DEBUG_NO_STATIC#endif /* PROC_FS_2325 */intipsec_tncfg_get_info(char *buffer, char **start, off_t offset, int length#ifndef PROC_NO_DUMMY, int dummy#endif /* !PROC_NO_DUMMY */){	int len = 0;	off_t pos = 0, begin = 0;	int i;	char name[9];	struct device *dev, *privdev;	struct ipsecpriv *priv;	KLIPS_PRINT(debug_tunnel & DB_TN_PROCFS,		    "klips_debug:ipsec_tncfg_get_info: "		    "buffer=0x%p, *start=0x%x, offset=%d, length=%d\n",		    buffer,		    (u_int)*start,		    (int)offset,		    length);	for(i = 0; i < IPSEC_NUM_IF; i++) {		sprintf(name, "ipsec%d", i);		dev = ipsec_dev_get(name);		if(dev) {			priv = (struct ipsecpriv *)(dev->priv);			len += sprintf(buffer + len, "%s",				       dev->name);			if(priv) {				privdev = (struct device *)(priv->dev);				len += sprintf(buffer + len, " -> %s",					       privdev ? privdev->name : "NULL");				len += sprintf(buffer + len, " mtu=%d(%d) -> %d",					       dev->mtu,					       priv->mtu,					       privdev ? privdev->mtu : 0);			} else {				KLIPS_PRINT(debug_tunnel & DB_TN_PROCFS,					    "klips_debug:ipsec_tncfg_get_info: device '%s' has no private data space!\n",					    dev->name);			}			len += sprintf(buffer + len, "\n");			pos = begin + len;			if(pos < offset) {				len = 0;				begin = pos;			}			else if (pos > offset + length)	{				break;			}		}	}	*start = buffer + (offset - begin);	/* Start of wanted data */	len -= (offset - begin);			/* Start slop */	if (len > length)		len = length;	return len;}#ifndef PROC_FS_2325DEBUG_NO_STATIC#endif /* PROC_FS_2325 */intipsec_version_get_info(char *buffer, char **start, off_t offset, int length#ifndef PROC_NO_DUMMY, int dummy#endif /* !PROC_NO_DUMMY */){	int len = 0;	off_t begin = 0;	KLIPS_PRINT(debug_tunnel & DB_TN_PROCFS,		    "klips_debug:ipsec_version_get_info: "		    "buffer=0x%p, *start=0x%x, offset=%d, length=%d\n",		    buffer,		    (u_int)*start,		    (int)offset,		    length);	len += sprintf(buffer + len, "FreeS/WAN version: %s\n", freeswan_version);#if 0	KLIPS_PRINT(debug_tunnel & DB_TN_PROCFS,		    "klips_debug:ipsec_version_get_info: "		    "ipsec_init version: %s\n",		    ipsec_init_c_version);	KLIPS_PRINT(debug_tunnel & DB_TN_PROCFS,		    "klips_debug:ipsec_version_get_info: "		    "ipsec_tunnel version: %s\n",		    ipsec_tunnel_c_version);	KLIPS_PRINT(debug_tunnel & DB_TN_PROCFS,		    "klips_debug:ipsec_version_get_info: "		    "ipsec_netlink version: %s\n",		    ipsec_netlink_c_version);	KLIPS_PRINT(debug_tunnel & DB_TN_PROCFS,		    "klips_debug:ipsec_version_get_info: "		    "radij_c_version: %s\n",		    radij_c_version);#endif	*start = buffer + (offset - begin);	/* Start of wanted data */	len -= (offset - begin);			/* Start slop */	if (len > length)		len = length;	return len;}#ifdef CONFIG_IPSEC_DEBUG#ifndef PROC_FS_2325DEBUG_NO_STATIC#endif /* PROC_FS_2325 */intipsec_klipsdebug_get_info(char *buffer, char **start, off_t offset, int length#ifndef PROC_NO_DUMMY, int dummy#endif /* !PROC_NO_DUMMY */){	int len = 0;	off_t begin = 0;	KLIPS_PRINT(debug_tunnel & DB_TN_PROCFS,		    "klips_debug:ipsec_klipsdebug_get_info: "		    "buffer=0x%p, *start=0x%x, offset=%d, length=%d\n",		    buffer,		    (u_int)*start,		    (int)offset,		    length);	len += sprintf(buffer + len, "debug_tunnel=%08x.\n", debug_tunnel);	len += sprintf(buffer + len, "debug_netlink=%08x.\n", debug_netlink);	len += sprintf(buffer + len, "debug_xform=%08x.\n", debug_xform);	len += sprintf(buffer + len, "debug_eroute=%08x.\n", debug_eroute);	len += sprintf(buffer + len, "debug_spi=%08x.\n", debug_spi);	len += sprintf(buffer + len, "debug_radij=%08x.\n", debug_radij);	len += sprintf(buffer + len, "debug_esp=%08x.\n", debug_esp);	len += sprintf(buffer + len, "debug_ah=%08x.\n", debug_ah);	len += sprintf(buffer + len, "debug_rcv=%08x.\n", debug_rcv);	len += sprintf(buffer + len, "debug_pfkey=%08x.\n", debug_pfkey);	*start = buffer + (offset - begin);	/* Start of wanted data */	len -= (offset - begin);			/* Start slop */	if (len > length)		len = length;	return len;}#endif /* CONFIG_IPSEC_DEBUG */#ifndef PROC_FS_2325struct proc_dir_entry ipsec_eroute ={	0,	12, "ipsec_eroute",	S_IFREG | S_IRUGO, 1, 0, 0, 0,	&proc_net_inode_operations,	ipsec_eroute_get_info,	NULL, NULL, NULL, NULL, NULL};struct proc_dir_entry ipsec_spi ={	0,	9, "ipsec_spi",	S_IFREG | S_IRUGO, 1, 0, 0, 0,	&proc_net_inode_operations,	ipsec_spi_get_info,	NULL, NULL, NULL, NULL, NULL};struct proc_dir_entry ipsec_spigrp ={	0,	12, "ipsec_spigrp",	S_IFREG | S_IRUGO, 1, 0, 0, 0,	&proc_net_inode_operations,	ipsec_spigrp_get_info,	NULL, NULL, NULL, NULL, NULL};struct proc_dir_entry ipsec_tncfg ={	0,	11, "ipsec_tncfg",	S_IFREG | S_IRUGO, 1, 0, 0, 0,	&proc_net_inode_operations,	ipsec_tncfg_get_info,	NULL, NULL, NULL, NULL, NULL};struct proc_dir_entry ipsec_version ={	0,	13, "ipsec_version",	S_IFREG | S_IRUGO, 1, 0, 0, 0,	&proc_net_inode_operations,	ipsec_version_get_info,	NULL, NULL, NULL, NULL, NULL};#ifdef CONFIG_IPSEC_DEBUGstruct proc_dir_entry ipsec_klipsdebug ={	0,	16, "ipsec_klipsdebug",	S_IFREG | S_IRUGO, 1, 0, 0, 0,	&proc_net_inode_operations,	ipsec_klipsdebug_get_info,	NULL, NULL, NULL, NULL, NULL};#endif /* CONFIG_IPSEC_DEBUG */#endif /* !PROC_FS_2325 */#endif /* CONFIG_PROC_FS */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_PROC_FS#  ifndef PROC_FS_2325#    ifdef PROC_FS_21	error |= proc_register(proc_net, &ipsec_eroute);	error |= proc_register(proc_net, &ipsec_spi);	error |= proc_register(proc_net, &ipsec_spigrp);	error |= proc_register(proc_net, &ipsec_tncfg);	error |= proc_register(proc_net, &ipsec_version);#      ifdef CONFIG_IPSEC_DEBUG	error |= proc_register(proc_net, &ipsec_klipsdebug);#      endif /* CONFIG_IPSEC_DEBUG */#    else /* PROC_FS_21 */	error |= proc_register_dynamic(&proc_net, &ipsec_eroute);	error |= proc_register_dynamic(&proc_net, &ipsec_spi);	error |= proc_register_dynamic(&proc_net, &ipsec_spigrp);	error |= proc_register_dynamic(&proc_net, &ipsec_tncfg);	error |= proc_register_dynamic(&proc_net, &ipsec_version);#      ifdef CONFIG_IPSEC_DEBUG	error |= proc_register_dynamic(&proc_net, &ipsec_klipsdebug);#      endif /* CONFIG_IPSEC_DEBUG */#    endif /* PROC_FS_21 */#  else /* !PROC_FS_2325 */	proc_net_create ("ipsec_eroute", 0, ipsec_eroute_get_info);	proc_net_create ("ipsec_spi", 0, ipsec_spi_get_info);	proc_net_create ("ipsec_spigrp", 0, ipsec_spigrp_get_info);	proc_net_create ("ipsec_tncfg", 0, ipsec_tncfg_get_info);	proc_net_create ("ipsec_version", 0, ipsec_version_get_info);#    ifdef CONFIG_IPSEC_DEBUG	proc_net_create ("ipsec_klipsdebug", 0, ipsec_klipsdebug_get_info);#    endif /* CONFIG_IPSEC_DEBUG */#  endif /* !PROC_FS_2325 */#endif          /* CONFIG_PROC_FS */	KLIPS_PRINT(1, "klips_info:ipsec_init: "		    "KLIPS startup, FreeS/WAN IPSec version: %s\n",		    freeswan_version);#ifndef SPINLOCK	tdb_lock.lock = 0;	eroute_lock.lock = 0;#endif /* !SPINLOCK */	error |= ipsec_tdbinit();	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                                                                          	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#endif#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_tdbcleanup(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();#ifdef CONFIG_PROC_FS#  ifndef PROC_FS_2325#    ifdef CONFIG_IPSEC_DEBUG	if (proc_net_unregister(ipsec_klipsdebug.low_ino) != 0)		printk("klips_debug:ipsec_cleanup: "		       "cannot unregister /proc/net/ipsec_klipsdebug\n");#    endif /* CONFIG_IPSEC_DEBUG */	if (proc_net_unregister(ipsec_version.low_ino) != 0)		printk("klips_debug:ipsec_cleanup: "		       "cannot unregister /proc/net/ipsec_version\n");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -