📄 pfkey_v2_parser.c
字号:
} sap = (unsigned char **)&(extr->tdb2->tdb_addr_d); extr->tdb2->tdb_addr_d_size = saddr_len; break; case SADB_X_EXT_ADDRESS_SRC_FLOW: KLIPS_PRINT(debug_pfkey, "klips_debug:pfkey_address_process: " "found src flow address.\n"); if(pfkey_alloc_eroute(&(extr->eroute)) == ENOMEM) { SENDERR(ENOMEM); } sap = (unsigned char **)&(extr->eroute->er_eaddr.sen_ip_src); break; case SADB_X_EXT_ADDRESS_DST_FLOW: KLIPS_PRINT(debug_pfkey, "klips_debug:pfkey_address_process: " "found dst flow address.\n"); if(pfkey_alloc_eroute(&(extr->eroute)) == ENOMEM) { SENDERR(ENOMEM); } sap = (unsigned char **)&(extr->eroute->er_eaddr.sen_ip_dst); break; case SADB_X_EXT_ADDRESS_SRC_MASK: KLIPS_PRINT(debug_pfkey, "klips_debug:pfkey_address_process: " "found src mask address.\n"); if(pfkey_alloc_eroute(&(extr->eroute)) == ENOMEM) { SENDERR(ENOMEM); } sap = (unsigned char **)&(extr->eroute->er_emask.sen_ip_src); break; case SADB_X_EXT_ADDRESS_DST_MASK: KLIPS_PRINT(debug_pfkey, "klips_debug:pfkey_address_process: " "found dst mask address.\n"); if(pfkey_alloc_eroute(&(extr->eroute)) == ENOMEM) { SENDERR(ENOMEM); } sap = (unsigned char **)&(extr->eroute->er_emask.sen_ip_dst); break; 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: 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;#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->%s\n", buf1, buf2); } }#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;#if 0 KLIPS_PRINT(debug_pfkey, "klips_debug:pfkey_address_process: " "tdbp->tdb_said.dst.s_addr=%08x, ((struct sockaddr_in*)(tdbp->tdb_addr_d))->sin_addr.s_addr=%08x,\n", tdbp->tdb_said.dst.s_addr, ((struct sockaddr_in*)(tdbp->tdb_addr_d))->sin_addr.s_addr );#endif 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; 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: extr->tdb->tdb_ident_type_s = pfkey_ident->sadb_ident_type; extr->tdb->tdb_ident_id_s = pfkey_ident->sadb_ident_id; extr->tdb->tdb_ident_len_s = pfkey_ident->sadb_ident_len - (sizeof(struct sadb_ident) / IPSEC_PFKEYv2_ALIGN); if(extr->tdb->tdb_ident_len_s) { if(!(extr->tdb->tdb_ident_data_s = kmalloc(pfkey_ident->sadb_ident_len * IPSEC_PFKEYv2_ALIGN, GFP_KERNEL))) { SENDERR(ENOMEM); } memcpy(extr->tdb->tdb_ident_data_s, (char*)pfkey_ident + sizeof(struct sadb_ident), pfkey_ident->sadb_ident_len * IPSEC_PFKEYv2_ALIGN); } else { extr->tdb->tdb_ident_data_s = NULL; } break; case SADB_EXT_IDENTITY_DST: /* Identity(ies) */ extr->tdb->tdb_ident_type_d = pfkey_ident->sadb_ident_type; extr->tdb->tdb_ident_id_d = pfkey_ident->sadb_ident_id; extr->tdb->tdb_ident_len_d = pfkey_ident->sadb_ident_len - sizeof(struct sadb_ident) / IPSEC_PFKEYv2_ALIGN; if(extr->tdb->tdb_ident_len_d) { if(!(extr->tdb->tdb_ident_data_d = kmalloc(pfkey_ident->sadb_ident_len * IPSEC_PFKEYv2_ALIGN, GFP_KERNEL))) { SENDERR(ENOMEM); } memcpy(extr->tdb->tdb_ident_data_d, (char*)pfkey_ident + sizeof(struct sadb_ident), pfkey_ident->sadb_ident_len * IPSEC_PFKEYv2_ALIGN); } else { extr->tdb->tdb_ident_data_d = 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_tdb(&(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;}DEBUG_NO_STATIC intpfkey_tdb_init(struct tdb *tdbp, struct sadb_ext **extensions){ int i; int error = 0; char sa[SATOA_BUF]; size_t sa_len; char ipaddr_txt[ADDRTOA_BUF];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -