📄 pfkey_v2_ext_process.c
字号:
SENDERR(EINVAL); } switch(pfkey_key->sadb_key_exttype) { case SADB_EXT_KEY_AUTH: KLIPS_PRINT(debug_pfkey, "klips_debug:pfkey_key_process: " "allocating %d bytes for authkey.\n", DIVUP(pfkey_key->sadb_key_bits, 8)); if(!(extr->ips->ips_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->ips->ips_key_bits_a = pfkey_key->sadb_key_bits; extr->ips->ips_key_a_size = DIVUP(pfkey_key->sadb_key_bits, 8); memcpy(extr->ips->ips_key_a, (char*)pfkey_key + sizeof(struct sadb_key), extr->ips->ips_key_a_size); break; case SADB_EXT_KEY_ENCRYPT: /* Key(s) */ KLIPS_PRINT(debug_pfkey, "klips_debug:pfkey_key_process: " "allocating %d bytes for enckey.\n", DIVUP(pfkey_key->sadb_key_bits, 8)); if(!(extr->ips->ips_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->ips->ips_key_bits_e = pfkey_key->sadb_key_bits; extr->ips->ips_key_e_size = DIVUP(pfkey_key->sadb_key_bits, 8); memcpy(extr->ips->ips_key_e, (char*)pfkey_key + sizeof(struct sadb_key), extr->ips->ips_key_e_size); break; default: SENDERR(EINVAL); } KLIPS_PRINT(debug_pfkey, "klips_debug:pfkey_key_process: " "success.\n");errlab: return error;}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->ips) { KLIPS_PRINT(debug_pfkey, "klips_debug:pfkey_ident_process: " "extr or extr->ips 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->ips->ips_ident_s.type = pfkey_ident->sadb_ident_type; extr->ips->ips_ident_s.id = pfkey_ident->sadb_ident_id; extr->ips->ips_ident_s.len = pfkey_ident->sadb_ident_len; if(data_len) { KLIPS_PRINT(debug_pfkey, "klips_debug:pfkey_ident_process: " "allocating %d bytes for ident_s.\n", data_len); if(!(extr->ips->ips_ident_s.data = kmalloc(data_len, GFP_KERNEL))) { SENDERR(ENOMEM); } memcpy(extr->ips->ips_ident_s.data, (char*)pfkey_ident + sizeof(struct sadb_ident), data_len); } else { extr->ips->ips_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->ips->ips_ident_d.type = pfkey_ident->sadb_ident_type; extr->ips->ips_ident_d.id = pfkey_ident->sadb_ident_id; extr->ips->ips_ident_d.len = pfkey_ident->sadb_ident_len; if(data_len) { KLIPS_PRINT(debug_pfkey, "klips_debug:pfkey_ident_process: " "allocating %d bytes for ident_d.\n", data_len); if(!(extr->ips->ips_ident_d.data = kmalloc(data_len, GFP_KERNEL))) { SENDERR(ENOMEM); } memcpy(extr->ips->ips_ident_d.data, (char*)pfkey_ident + sizeof(struct sadb_ident), data_len); } else { extr->ips->ips_ident_d.data = NULL; } break; default: SENDERR(EINVAL); }errlab: return error;}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;}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;}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;}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;}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;}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->ips) { KLIPS_PRINT(debug_pfkey, "klips_debug:pfkey_x_satype_process: " "extr or extr->ips is NULL, fatal\n"); SENDERR(EINVAL); } if(extr->ips2 == NULL) { extr->ips2 = ipsec_sa_alloc(&error); /* pass error var by pointer */ } if(extr->ips2 == NULL) { SENDERR(-error); } if(!(extr->ips2->ips_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->ips2->ips_said.proto, pfkey_x_satype->sadb_x_satype_satype, satype2name(pfkey_x_satype->sadb_x_satype_satype));errlab: return error;}#ifdef CONFIG_IPSEC_NAT_TRAVERSALintpfkey_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->ips) { KLIPS_PRINT(debug_pfkey, "klips_debug:pfkey_nat_t_type_process: " "extr or extr->ips 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 (older version) */ case ESPINUDP_WITH_NON_ESP: /* with Non-ESP */ extr->ips->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; }errlab: return error;}intpfkey_x_nat_t_port_process(struct sadb_ext *pfkey_ext, struct pfkey_extracted_data* extr){ int error = 0; struct sadb_x_nat_t_port *pfkey_x_nat_t_port = (struct sadb_x_nat_t_port *)pfkey_ext; if(!pfkey_x_nat_t_port) { printk("klips_debug:pfkey_x_nat_t_port_process: " "null pointer passed in\n"); SENDERR(EINVAL); } KLIPS_PRINT(debug_pfkey, "klips_debug:pfkey_x_nat_t_port_process: %d/%d.\n", pfkey_x_nat_t_port->sadb_x_nat_t_port_exttype, pfkey_x_nat_t_port->sadb_x_nat_t_port_port); if(!extr || !extr->ips) { KLIPS_PRINT(debug_pfkey, "klips_debug:pfkey_nat_t_type_process: " "extr or extr->ips is NULL, fatal\n"); SENDERR(EINVAL); } switch(pfkey_x_nat_t_port->sadb_x_nat_t_port_exttype) { case SADB_X_EXT_NAT_T_SPORT: extr->ips->ips_natt_sport = pfkey_x_nat_t_port->sadb_x_nat_t_port_port; break; case SADB_X_EXT_NAT_T_DPORT: extr->ips->ips_natt_dport = pfkey_x_nat_t_port->sadb_x_nat_t_port_port; break; default: KLIPS_PRINT(debug_pfkey, "klips_debug:pfkey_x_nat_t_port_process: " "unknown exttype %d.\n", pfkey_x_nat_t_port->sadb_x_nat_t_port_exttype); SENDERR(EINVAL); break; }errlab: return error;}#endifintpfkey_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_KLIPS_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_KLIPS_IPCOMP sysctl_ipsec_debug_ipcomp |= pfkey_x_debug->sadb_x_debug_ipcomp;#endif /* CONFIG_KLIPS_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_KLIPS_IPCOMP sysctl_ipsec_debug_ipcomp &= pfkey_x_debug->sadb_x_debug_ipcomp;#endif /* CONFIG_KLIPS_IPCOMP */ sysctl_ipsec_debug_verbose &= pfkey_x_debug->sadb_x_debug_verbose; }#else /* CONFIG_KLIPS_DEBUG */ printk("klips_debug:pfkey_x_debug_process: " "debugging not enabled\n"); SENDERR(EINVAL);#endif /* CONFIG_KLIPS_DEBUG */ errlab: return error;}/* * $Log: pfkey_v2_ext_process.c,v $ * Revision 1.20.2.1 2006/04/20 16:33:07 mcr * remove all of CONFIG_KLIPS_ALG --- one can no longer build without it. * Fix in-kernel module compilation. Sub-makefiles do not work. * * Revision 1.20 2005/04/29 05:10:22 mcr * removed from extraenous includes to make unit testing easier. * * Revision 1.19 2004/12/04 07:14:18 mcr * resolution to gcc3-ism was wrong. fixed to assign correct * variable. * * Revision 1.18 2004/12/03 21:25:57 mcr * compile time fixes for running on 2.6. * still experimental. * * Revision 1.17 2004/08/21 00:45:04 mcr * CONFIG_KLIPS_NAT was wrong, also need to include udp.h. * * Revision 1.16 2004/07/10 19:11:18 mcr * CONFIG_IPSEC -> CONFIG_KLIPS. * * Revision 1.15 2004/04/06 02:49:26 mcr * pullup of algo code from alg-branch. * * Revision 1.14 2004/02/03 03:13:59 mcr * no longer #ifdef out NON_ESP mode. That was a mistake. * * Revision 1.13 2003/12/15 18:13:12 mcr * when compiling with NAT traversal, don't assume that the * kernel has been patched, unless CONFIG_IPSEC_NAT_NON_ESP * is set. * * Revision 1.12.2.1 2003/12/22 15:25:52 jjo * Merged algo-0.8.1-rc11-test1 into alg-branch * * Revision 1.12 2003/12/10 01:14:27 mcr * NAT-traversal patches to KLIPS. * * Revision 1.11 2003/10/31 02:27:55 mcr * pulled up port-selector patches and sa_id elimination. * * Revision 1.10.4.2 2003/10/29 01:30:41 mcr * elimited "struct sa_id". * * Revision 1.10.4.1 2003/09/21 13:59:56 mcr * pre-liminary X.509 patch - does not yet pass tests. * * Revision 1.10 2003/02/06 01:51:41 rgb * Removed no longer relevant comment * * Revision 1.9 2003/01/30 02:32:44 rgb * * Transmit error code through to caller from callee for better diagnosis of problems. * * Revision 1.8 2002/12/13 22:42:22 mcr * restored sa_ref code * * Revision 1.7 2002/12/13 22:40:48 mcr * temporarily removed sadb_x_sa_ref reference for 2.xx * * Revision 1.6 2002/10/05 05:02:58 dhr * * C labels go on statements * * Revision 1.5 2002/09/20 15:41:08 rgb * Switch from pfkey_alloc_ipsec_sa() to ipsec_sa_alloc(). * Added sadb_x_sa_ref to struct sadb_sa. * * Revision 1.4 2002/09/20 05:02:02 rgb * Added memory allocation debugging. * * Revision 1.3 2002/07/24 18:44:54 rgb * Type fiddling to tame ia64 compiler. * * Revision 1.2 2002/05/27 18:55:03 rgb * Remove final vistiges of tdb references via IPSEC_KLIPS1_COMPAT. * * Revision 1.1 2002/05/14 02:33:51 rgb * Moved all the extension processing functions to pfkey_v2_ext_process.c. * * * Local variables: * c-file-style: "linux" * End: * */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -