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

📄 pfkey_v2_parser.c

📁 FREESWAN VPN源代码包
💻 C
📖 第 1 页 / 共 5 页
字号:
		break;#ifdef NAT_TRAVERSAL	case SADB_X_EXT_NAT_T_OA:		KLIPS_PRINT(debug_pfkey,			    "klips_debug:pfkey_address_process: "			    "found NAT-OA address.\n");		sap = (unsigned char **)&(extr->tdb->ips_natt_oa);		extr->tdb->ips_natt_oa_size = saddr_len;		break;#endif	default:		KLIPS_PRINT(debug_pfkey,			    "klips_debug:pfkey_address_process: "			    "unrecognised ext_type=%d.\n",			    pfkey_address->sadb_address_exttype);		SENDERR(EINVAL);	}		switch(pfkey_address->sadb_address_exttype) {	case SADB_EXT_ADDRESS_SRC:	case SADB_EXT_ADDRESS_DST:	case SADB_EXT_ADDRESS_PROXY:	case SADB_X_EXT_ADDRESS_DST2:#ifdef NAT_TRAVERSAL	case SADB_X_EXT_NAT_T_OA:#endif		if(!(*sap = kmalloc(saddr_len, GFP_KERNEL))) {			SENDERR(ENOMEM);		}		memcpy(*sap, s, saddr_len);		break;	default:		if(s->sa_family	!= AF_INET) {			KLIPS_PRINT(debug_pfkey,				    "klips_debug:pfkey_address_process: "				    "s->sa_family=%d not supported.\n",				    s->sa_family);			SENDERR(EPFNOSUPPORT);		}		(unsigned int)(*sap) = ((struct sockaddr_in*)s)->sin_addr.s_addr;		if (portp != 0)			*portp = ((struct sockaddr_in*)s)->sin_port;#ifdef CONFIG_IPSEC_DEBUG		if(extr->eroute) {			char buf1[64], buf2[64];			if (debug_pfkey) {				subnettoa(extr->eroute->er_eaddr.sen_ip_src,					  extr->eroute->er_emask.sen_ip_src, 0, buf1, sizeof(buf1));				subnettoa(extr->eroute->er_eaddr.sen_ip_dst,					  extr->eroute->er_emask.sen_ip_dst, 0, buf2, sizeof(buf2));				KLIPS_PRINT(debug_pfkey,					    "klips_debug:pfkey_address_parse: "					    "extr->eroute set to %s:%d->%s:%d\n",					    buf1,					    ntohs(extr->eroute->er_eaddr.sen_sport),					    buf2,					    ntohs(extr->eroute->er_eaddr.sen_dport));			}		}#endif /* CONFIG_IPSEC_DEBUG */	}	tdbp = extr->tdb;	switch(pfkey_address->sadb_address_exttype) {	case SADB_X_EXT_ADDRESS_DST2:		tdbp = extr->tdb2;	case SADB_EXT_ADDRESS_DST:		if(s->sa_family == AF_INET) {			tdbp->tdb_said.dst.s_addr = ((struct sockaddr_in*)(tdbp->tdb_addr_d))->sin_addr.s_addr;			addrtoa(((struct sockaddr_in*)(tdbp->tdb_addr_d))->sin_addr,				0,				ipaddr_txt,				sizeof(ipaddr_txt));			KLIPS_PRINT(debug_pfkey,				    "klips_debug:pfkey_address_process: "				    "tdb_said.dst set to %s.\n",				    ipaddr_txt);		} else {			KLIPS_PRINT(debug_pfkey,				    "klips_debug:pfkey_address_process: "				    "uh, tdb_said.dst doesn't do address family=%d yet, said will be invalid.\n",				    s->sa_family);		}	default:	}		/* XXX check if port!=0 */		KLIPS_PRINT(debug_pfkey,		    "klips_debug:pfkey_address_process: successful.\n"); errlab:	return error;}DEBUG_NO_STATIC intpfkey_key_process(struct sadb_ext *pfkey_ext, struct pfkey_extracted_data* extr){        int error = 0;        struct sadb_key *pfkey_key = (struct sadb_key *)pfkey_ext;		KLIPS_PRINT(debug_pfkey,		    "klips_debug:pfkey_key_process: .\n");	if(!extr || !extr->tdb) {		KLIPS_PRINT(debug_pfkey,			    "klips_debug:pfkey_key_process: "			    "extr or extr->tdb is NULL, fatal\n");		SENDERR(EINVAL);	}        switch(pfkey_key->sadb_key_exttype) {        case SADB_EXT_KEY_AUTH:		if(!(extr->tdb->tdb_key_a = kmalloc(DIVUP(pfkey_key->sadb_key_bits, 8), GFP_KERNEL))) {			KLIPS_PRINT(debug_pfkey,				    "klips_debug:pfkey_key_process: "				    "memory allocation error.\n");			SENDERR(ENOMEM);		}                extr->tdb->tdb_key_bits_a = pfkey_key->sadb_key_bits;                extr->tdb->tdb_key_a_size = DIVUP(pfkey_key->sadb_key_bits, 8);		memcpy(extr->tdb->tdb_key_a,		       (char*)pfkey_key + sizeof(struct sadb_key),		       extr->tdb->tdb_key_a_size);		break;	case SADB_EXT_KEY_ENCRYPT: /* Key(s) */		if(!(extr->tdb->tdb_key_e = kmalloc(DIVUP(pfkey_key->sadb_key_bits, 8), GFP_KERNEL))) {			KLIPS_PRINT(debug_pfkey,				    "klips_debug:pfkey_key_process: "				    "memory allocation error.\n");			SENDERR(ENOMEM);		}		extr->tdb->tdb_key_bits_e = pfkey_key->sadb_key_bits;		extr->tdb->tdb_key_e_size = DIVUP(pfkey_key->sadb_key_bits, 8);		memcpy(extr->tdb->tdb_key_e,		       (char*)pfkey_key + sizeof(struct sadb_key),		       extr->tdb->tdb_key_e_size);		break;	default:		SENDERR(EINVAL); 	}	KLIPS_PRINT(debug_pfkey,		    "klips_debug:pfkey_key_process: "		    "success.\n");errlab:	return error;}DEBUG_NO_STATIC intpfkey_ident_process(struct sadb_ext *pfkey_ext, struct pfkey_extracted_data* extr){        int error = 0;        struct sadb_ident *pfkey_ident = (struct sadb_ident *)pfkey_ext;	int data_len;	KLIPS_PRINT(debug_pfkey,		    "klips_debug:pfkey_ident_process: .\n");	if(!extr || !extr->tdb) {		KLIPS_PRINT(debug_pfkey,			    "klips_debug:pfkey_ident_process: "			    "extr or extr->tdb is NULL, fatal\n");		SENDERR(EINVAL);	}	switch(pfkey_ident->sadb_ident_exttype) {	case SADB_EXT_IDENTITY_SRC:		data_len = pfkey_ident->sadb_ident_len * IPSEC_PFKEYv2_ALIGN - sizeof(struct sadb_ident);				extr->tdb->tdb_ident_s.type = pfkey_ident->sadb_ident_type;		extr->tdb->tdb_ident_s.id = pfkey_ident->sadb_ident_id;		extr->tdb->tdb_ident_s.len = pfkey_ident->sadb_ident_len;		if(data_len) {			if(!(extr->tdb->tdb_ident_s.data			     = kmalloc(data_len, GFP_KERNEL))) {                                SENDERR(ENOMEM);                        }			memcpy(extr->tdb->tdb_ident_s.data,                               (char*)pfkey_ident + sizeof(struct sadb_ident),			       data_len);                } else {			extr->tdb->tdb_ident_s.data = NULL;                }                break;	case SADB_EXT_IDENTITY_DST: /* Identity(ies) */		data_len = pfkey_ident->sadb_ident_len * IPSEC_PFKEYv2_ALIGN - sizeof(struct sadb_ident);				extr->tdb->tdb_ident_d.type = pfkey_ident->sadb_ident_type;		extr->tdb->tdb_ident_d.id = pfkey_ident->sadb_ident_id;		extr->tdb->tdb_ident_d.len = pfkey_ident->sadb_ident_len;		if(data_len) {			if(!(extr->tdb->tdb_ident_d.data			     = kmalloc(data_len, GFP_KERNEL))) {                                SENDERR(ENOMEM);                        }			memcpy(extr->tdb->tdb_ident_d.data,                               (char*)pfkey_ident + sizeof(struct sadb_ident),			       data_len);                } else {			extr->tdb->tdb_ident_d.data = NULL;                }                break;	default:		SENDERR(EINVAL); 	}errlab:	return error;}DEBUG_NO_STATIC intpfkey_sens_process(struct sadb_ext *pfkey_ext, struct pfkey_extracted_data* extr){        int error = 0;		KLIPS_PRINT(debug_pfkey,		    "klips_debug:pfkey_sens_process: "		    "Sorry, I can't process exttype=%d yet.\n",		    pfkey_ext->sadb_ext_type);        SENDERR(EINVAL); /* don't process these yet */ errlab:        return error;}DEBUG_NO_STATIC intpfkey_prop_process(struct sadb_ext *pfkey_ext, struct pfkey_extracted_data* extr){        int error = 0;		KLIPS_PRINT(debug_pfkey,		    "klips_debug:pfkey_prop_process: "		    "Sorry, I can't process exttype=%d yet.\n",		    pfkey_ext->sadb_ext_type);	SENDERR(EINVAL); /* don't process these yet */	 errlab:	return error;}DEBUG_NO_STATIC intpfkey_supported_process(struct sadb_ext *pfkey_ext, struct pfkey_extracted_data* extr){        int error = 0;	KLIPS_PRINT(debug_pfkey,		    "klips_debug:pfkey_supported_process: "		    "Sorry, I can't process exttype=%d yet.\n",		    pfkey_ext->sadb_ext_type);	SENDERR(EINVAL); /* don't process these yet */errlab:	return error;}DEBUG_NO_STATIC intpfkey_spirange_process(struct sadb_ext *pfkey_ext, struct pfkey_extracted_data* extr){        int error = 0;	KLIPS_PRINT(debug_pfkey,		    "klips_debug:pfkey_spirange_process: .\n");/* errlab: */	return error;}DEBUG_NO_STATIC intpfkey_x_kmprivate_process(struct sadb_ext *pfkey_ext, struct pfkey_extracted_data* extr){	int error = 0;	KLIPS_PRINT(debug_pfkey,		    "klips_debug:pfkey_x_kmprivate_process: "		    "Sorry, I can't process exttype=%d yet.\n",		    pfkey_ext->sadb_ext_type);	SENDERR(EINVAL); /* don't process these yet */errlab:	return error;}DEBUG_NO_STATIC intpfkey_x_satype_process(struct sadb_ext *pfkey_ext, struct pfkey_extracted_data* extr){	int error = 0;	struct sadb_x_satype *pfkey_x_satype = (struct sadb_x_satype *)pfkey_ext;	KLIPS_PRINT(debug_pfkey,		    "klips_debug:pfkey_x_satype_process: .\n");	if(!extr || !extr->tdb) {		KLIPS_PRINT(debug_pfkey,			    "klips_debug:pfkey_x_satype_process: "			    "extr or extr->tdb is NULL, fatal\n");		SENDERR(EINVAL);	}	if(pfkey_alloc_ipsec_sa(&(extr->tdb2)) == ENOMEM) {		SENDERR(ENOMEM);	}	if(!(extr->tdb2->tdb_said.proto = satype2proto(pfkey_x_satype->sadb_x_satype_satype))) {		KLIPS_PRINT(debug_pfkey,			    "klips_debug:pfkey_x_satype_process: "			    "proto lookup from satype=%d failed.\n",			    pfkey_x_satype->sadb_x_satype_satype);		SENDERR(EINVAL);	}	KLIPS_PRINT(debug_pfkey,		    "klips_debug:pfkey_x_satype_process: "		    "protocol==%d decoded from satype==%d(%s).\n",		    extr->tdb2->tdb_said.proto,		    pfkey_x_satype->sadb_x_satype_satype,		    satype2name(pfkey_x_satype->sadb_x_satype_satype));errlab:	return error;}DEBUG_NO_STATIC intpfkey_x_debug_process(struct sadb_ext *pfkey_ext, struct pfkey_extracted_data* extr){	int error = 0;	struct sadb_x_debug *pfkey_x_debug = (struct sadb_x_debug *)pfkey_ext;	if(!pfkey_x_debug) {		printk("klips_debug:pfkey_x_debug_process: "		       "null pointer passed in\n");		SENDERR(EINVAL);	}	KLIPS_PRINT(debug_pfkey,		    "klips_debug:pfkey_x_debug_process: .\n");#ifdef CONFIG_IPSEC_DEBUG		if(pfkey_x_debug->sadb_x_debug_netlink >>		   (sizeof(pfkey_x_debug->sadb_x_debug_netlink) * 8 - 1)) {			pfkey_x_debug->sadb_x_debug_netlink &=				~(1 << (sizeof(pfkey_x_debug->sadb_x_debug_netlink) * 8 -1));			debug_tunnel  |= pfkey_x_debug->sadb_x_debug_tunnel;			debug_netlink |= pfkey_x_debug->sadb_x_debug_netlink;			debug_xform   |= pfkey_x_debug->sadb_x_debug_xform;			debug_eroute  |= pfkey_x_debug->sadb_x_debug_eroute;			debug_spi     |= pfkey_x_debug->sadb_x_debug_spi;			debug_radij   |= pfkey_x_debug->sadb_x_debug_radij;			debug_esp     |= pfkey_x_debug->sadb_x_debug_esp;			debug_ah      |= pfkey_x_debug->sadb_x_debug_ah;			debug_rcv     |= pfkey_x_debug->sadb_x_debug_rcv;			debug_pfkey   |= pfkey_x_debug->sadb_x_debug_pfkey;#ifdef CONFIG_IPSEC_IPCOMP			sysctl_ipsec_debug_ipcomp  |= pfkey_x_debug->sadb_x_debug_ipcomp;#endif /* CONFIG_IPSEC_IPCOMP */			sysctl_ipsec_debug_verbose |= pfkey_x_debug->sadb_x_debug_verbose;			KLIPS_PRINT(debug_pfkey,				    "klips_debug:pfkey_x_debug_process: "				    "set\n");		} else {			KLIPS_PRINT(debug_pfkey,				    "klips_debug:pfkey_x_debug_process: "				    "unset\n");			debug_tunnel  &= pfkey_x_debug->sadb_x_debug_tunnel;			debug_netlink &= pfkey_x_debug->sadb_x_debug_netlink;			debug_xform   &= pfkey_x_debug->sadb_x_debug_xform;			debug_eroute  &= pfkey_x_debug->sadb_x_debug_eroute;			debug_spi     &= pfkey_x_debug->sadb_x_debug_spi;			debug_radij   &= pfkey_x_debug->sadb_x_debug_radij;			debug_esp     &= pfkey_x_debug->sadb_x_debug_esp;			debug_ah      &= pfkey_x_debug->sadb_x_debug_ah;			debug_rcv     &= pfkey_x_debug->sadb_x_debug_rcv;			debug_pfkey   &= pfkey_x_debug->sadb_x_debug_pfkey;#ifdef CONFIG_IPSEC_IPCOMP			sysctl_ipsec_debug_ipcomp  &= pfkey_x_debug->sadb_x_debug_ipcomp;#endif /* CONFIG_IPSEC_IPCOMP */			sysctl_ipsec_debug_verbose &= pfkey_x_debug->sadb_x_debug_verbose;		}#else /* CONFIG_IPSEC_DEBUG */		printk("klips_debug:pfkey_x_debug_process: "		       "debugging not enabled\n");		SENDERR(EINVAL);#endif /* CONFIG_IPSEC_DEBUG */	errlab:	return error;}#ifdef CONFIG_IPSEC_NAT_TRAVERSALDEBUG_NO_STATIC intpfkey_x_nat_t_type_process(struct sadb_ext *pfkey_ext, struct pfkey_extracted_data* extr){	int error = 0;	struct sadb_x_nat_t_type *pfkey_x_nat_t_type = (struct sadb_x_nat_t_type *)pfkey_ext;	if(!pfkey_x_nat_t_type) {		printk("klips_debug:pfkey_x_nat_t_type_process: "		       "null pointer passed in\n");		SENDERR(EINVAL);	}	KLIPS_PRINT(debug_pfkey,		    "klips_debug:pfkey_x_nat_t_type_process: %d.\n",			pfkey_x_nat_t_type->sadb_x_nat_t_type_type);	if(!extr || !extr->tdb) {		KLIPS_PRINT(debug_pfkey,			    "klips_debug:pfkey_nat_t_type_process: "			    "extr or extr->tdb is NULL, fatal\n");		SENDERR(EINVAL);	}	switch(pfkey_x_nat_t_type->sadb_x_nat_t_type_type) {		case ESPINUDP_WITH_NON_IKE: /* with Non-IKE */		case ESPINUDP_WITH_NON_ESP: /* with Non-ESP */			extr->tdb->ips_natt_type = pfkey_x_nat_t_type->sadb_x_nat_t_type_type;			break;		default:			KLIPS_PRINT(debug_pfkey,			    "klips_debug:pfkey_x_nat_t_type_process: "			    "unknown type %d.\n",			    pfkey_x_nat_t_type->sadb_x_nat_t_type_type);			SENDERR(EINVAL);			break;	}

⌨️ 快捷键说明

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