📄 pfkey_v2_parser.c
字号:
? pfkey_safe_build(error = pfkey_lifetime_build(&extensions_reply[SADB_EXT_LIFETIME_CURRENT], SADB_EXT_LIFETIME_CURRENT, ipsp->ips_life.ipl_allocations.ipl_count, ipsp->ips_life.ipl_bytes.ipl_count, ipsp->ips_life.ipl_addtime.ipl_count, ipsp->ips_life.ipl_usetime.ipl_count, ipsp->ips_life.ipl_packets.ipl_count), extensions_reply) : 1) && (ipsp->ips_life.ipl_allocations.ipl_hard || ipsp->ips_life.ipl_bytes.ipl_hard || ipsp->ips_life.ipl_addtime.ipl_hard || ipsp->ips_life.ipl_usetime.ipl_hard || ipsp->ips_life.ipl_packets.ipl_hard ? pfkey_safe_build(error = pfkey_lifetime_build(&extensions_reply[SADB_EXT_LIFETIME_HARD], SADB_EXT_LIFETIME_HARD, ipsp->ips_life.ipl_allocations.ipl_hard, ipsp->ips_life.ipl_bytes.ipl_hard, ipsp->ips_life.ipl_addtime.ipl_hard, ipsp->ips_life.ipl_usetime.ipl_hard, ipsp->ips_life.ipl_packets.ipl_hard), extensions_reply) : 1) && (ipsp->ips_life.ipl_allocations.ipl_soft || ipsp->ips_life.ipl_bytes.ipl_soft || ipsp->ips_life.ipl_addtime.ipl_soft || ipsp->ips_life.ipl_usetime.ipl_soft || ipsp->ips_life.ipl_packets.ipl_soft ? pfkey_safe_build(error = pfkey_lifetime_build(&extensions_reply[SADB_EXT_LIFETIME_SOFT], SADB_EXT_LIFETIME_SOFT, ipsp->ips_life.ipl_allocations.ipl_soft, ipsp->ips_life.ipl_bytes.ipl_soft, ipsp->ips_life.ipl_addtime.ipl_soft, ipsp->ips_life.ipl_usetime.ipl_soft, ipsp->ips_life.ipl_packets.ipl_soft), extensions_reply) : 1) && pfkey_safe_build(error = pfkey_address_build(&extensions_reply[SADB_EXT_ADDRESS_SRC], SADB_EXT_ADDRESS_SRC, 0, /*extr->ips->ips_said.proto,*/ 0, extr->ips->ips_addr_s), extensions_reply) && pfkey_safe_build(error = pfkey_address_build(&extensions_reply[SADB_EXT_ADDRESS_DST], SADB_EXT_ADDRESS_DST, 0, /*extr->ips->ips_said.proto,*/ 0, extr->ips->ips_addr_d), extensions_reply) && (extr->ips->ips_addr_p ? pfkey_safe_build(error = pfkey_address_build(&extensions_reply[SADB_EXT_ADDRESS_PROXY], SADB_EXT_ADDRESS_PROXY, 0, /*extr->ips->ips_said.proto,*/ 0, extr->ips->ips_addr_p), extensions_reply) : 1)#if 0 /* FIXME: This won't work yet because the keys are not stored directly in the ipsec_sa. They are stored as contexts. */ && (extr->ips->ips_key_a_size ? pfkey_safe_build(error = pfkey_key_build(&extensions_reply[SADB_EXT_KEY_AUTH], SADB_EXT_KEY_AUTH, extr->ips->ips_key_a_size * 8, extr->ips->ips_key_a), extensions_reply) : 1) /* FIXME: This won't work yet because the keys are not stored directly in the ipsec_sa. They are stored as key schedules. */ && (extr->ips->ips_key_e_size ? pfkey_safe_build(error = pfkey_key_build(&extensions_reply[SADB_EXT_KEY_ENCRYPT], SADB_EXT_KEY_ENCRYPT, extr->ips->ips_key_e_size * 8, extr->ips->ips_key_e), extensions_reply) : 1)#endif && (extr->ips->ips_ident_s.data ? pfkey_safe_build(error = pfkey_ident_build(&extensions_reply[SADB_EXT_IDENTITY_SRC], SADB_EXT_IDENTITY_SRC, extr->ips->ips_ident_s.type, extr->ips->ips_ident_s.id, extr->ips->ips_ident_s.len, extr->ips->ips_ident_s.data), extensions_reply) : 1) && (extr->ips->ips_ident_d.data ? pfkey_safe_build(error = pfkey_ident_build(&extensions_reply[SADB_EXT_IDENTITY_DST], SADB_EXT_IDENTITY_DST, extr->ips->ips_ident_d.type, extr->ips->ips_ident_d.id, extr->ips->ips_ident_d.len, extr->ips->ips_ident_d.data), extensions_reply) : 1)#if 0 /* FIXME: This won't work yet because I have not finished it. */ && (extr->ips->ips_sens_ ? pfkey_safe_build(error = pfkey_sens_build(&extensions_reply[SADB_EXT_SENSITIVITY], extr->ips->ips_sens_dpd, extr->ips->ips_sens_sens_level, extr->ips->ips_sens_sens_len, extr->ips->ips_sens_sens_bitmap, extr->ips->ips_sens_integ_level, extr->ips->ips_sens_integ_len, extr->ips->ips_sens_integ_bitmap), extensions_reply) : 1)#endif )) { KLIPS_PRINT(debug_pfkey, "klips_debug:pfkey_get_parse: " "failed to build the get reply message extensions\n"); ipsec_sa_put(ipsp); spin_unlock_bh(&tdb_lock); SENDERR(-error); } ipsec_sa_put(ipsp); spin_unlock_bh(&tdb_lock); if((error = pfkey_msg_build(&pfkey_reply, extensions_reply, EXT_BITS_OUT))) { KLIPS_PRINT(debug_pfkey, "klips_debug:pfkey_get_parse: " "failed to build the get reply message\n"); SENDERR(-error); } if((error = pfkey_upmsg(sk->sk_socket, pfkey_reply))) { KLIPS_PRINT(debug_pfkey, "klips_debug:pfkey_get_parse: " "failed to send the get reply message\n"); SENDERR(-error); } KLIPS_PRINT(debug_pfkey, "klips_debug:pfkey_get_parse: " "succeeded in sending get reply message.\n"); errlab: if (pfkey_reply) { pfkey_msg_free(&pfkey_reply); } pfkey_extensions_free(extensions_reply); return error;}DEBUG_NO_STATIC intpfkey_acquire_parse(struct sock *sk, struct sadb_ext **extensions, struct pfkey_extracted_data* extr){ int error = 0; struct socket_list *pfkey_socketsp; uint8_t satype = ((struct sadb_msg*)extensions[SADB_EXT_RESERVED])->sadb_msg_satype; KLIPS_PRINT(debug_pfkey, "klips_debug:pfkey_acquire_parse: .\n"); /* XXX I don't know if we want an upper bound, since userspace may want to register itself for an satype > SADB_SATYPE_MAX. */ if((satype == 0) || (satype > SADB_SATYPE_MAX)) { KLIPS_PRINT(debug_pfkey, "klips_debug:pfkey_acquire_parse: " "SATYPE=%d invalid.\n", satype); SENDERR(EINVAL); } if(!(pfkey_registered_sockets[satype])) { KLIPS_PRINT(debug_pfkey, "klips_debug:pfkey_acquire_parse: " "no sockets registered for SAtype=%d(%s).\n", satype, satype2name(satype)); SENDERR(EPROTONOSUPPORT); } for(pfkey_socketsp = pfkey_registered_sockets[satype]; pfkey_socketsp; pfkey_socketsp = pfkey_socketsp->next) { if((error = pfkey_upmsg(pfkey_socketsp->socketp, ((struct sadb_msg*)extensions[SADB_EXT_RESERVED])))) { KLIPS_PRINT(debug_pfkey, "klips_debug:pfkey_acquire_parse: " "sending up acquire reply message for satype=%d(%s) to socket=0p%p failed with error=%d.\n", satype, satype2name(satype), pfkey_socketsp->socketp, error); SENDERR(-error); } KLIPS_PRINT(debug_pfkey, "klips_debug:pfkey_acquire_parse: " "sending up acquire reply message for satype=%d(%s) to socket=0p%p succeeded.\n", satype, satype2name(satype), pfkey_socketsp->socketp); } errlab: return error;}DEBUG_NO_STATIC intpfkey_register_parse(struct sock *sk, struct sadb_ext **extensions, struct pfkey_extracted_data* extr){ int error = 0; uint8_t satype = ((struct sadb_msg*)extensions[SADB_EXT_RESERVED])->sadb_msg_satype; KLIPS_PRINT(debug_pfkey, "klips_debug:pfkey_register_parse: .\n"); /* XXX I don't know if we want an upper bound, since userspace may want to register itself for an satype > SADB_SATYPE_MAX. */ if((satype == 0) || (satype > SADB_SATYPE_MAX)) { KLIPS_PRINT(debug_pfkey, "klips_debug:pfkey_register_parse: " "SATYPE=%d invalid.\n", satype); SENDERR(EINVAL); } if(!pfkey_list_insert_socket(sk->sk_socket, &(pfkey_registered_sockets[satype]))) { KLIPS_PRINT(debug_pfkey, "klips_debug:pfkey_register_parse: " "SATYPE=%02d(%s) successfully registered by KMd (pid=%d).\n", satype, satype2name(satype), key_pid(sk)); }; /* send up register msg with supported SATYPE algos */ error=pfkey_register_reply(satype, (struct sadb_msg*)extensions[SADB_EXT_RESERVED]); errlab: return error;}intpfkey_register_reply(int satype, struct sadb_msg *sadb_msg){ struct sadb_ext *extensions_reply[SADB_EXT_MAX+1]; struct sadb_msg *pfkey_reply = NULL; struct socket_list *pfkey_socketsp; struct supported_list *pfkey_supported_listp; unsigned int alg_num_a = 0, alg_num_e = 0; struct sadb_alg *alg_a = NULL, *alg_e = NULL, *alg_ap = NULL, *alg_ep = NULL; int error = 0; pfkey_extensions_init(extensions_reply); if((satype == 0) || (satype > SADB_SATYPE_MAX)) { KLIPS_PRINT(debug_pfkey, "klips_debug:pfkey_register_reply: " "SAtype=%d unspecified or unknown.\n", satype); SENDERR(EINVAL); } if(!(pfkey_registered_sockets[satype])) { KLIPS_PRINT(debug_pfkey, "klips_debug:pfkey_register_reply: " "no sockets registered for SAtype=%d(%s).\n", satype, satype2name(satype)); SENDERR(EPROTONOSUPPORT); } /* send up register msg with supported SATYPE algos */ pfkey_supported_listp = pfkey_supported_list[satype]; KLIPS_PRINT(debug_pfkey, "klips_debug:pfkey_register_reply: " "pfkey_supported_list[%d]=0p%p\n", satype, pfkey_supported_list[satype]); while(pfkey_supported_listp) { KLIPS_PRINT(debug_pfkey, "klips_debug:pfkey_register_reply: " "checking supported=0p%p\n", pfkey_supported_listp); if(pfkey_supported_listp->supportedp->supported_alg_exttype == SADB_EXT_SUPPORTED_AUTH) { KLIPS_PRINT(debug_pfkey, "klips_debug:pfkey_register_reply: " "adding auth alg.\n"); alg_num_a++; } if(pfkey_supported_listp->supportedp->supported_alg_exttype == SADB_EXT_SUPPORTED_ENCRYPT) { KLIPS_PRINT(debug_pfkey, "klips_debug:pfkey_register_reply: " "adding encrypt alg.\n"); alg_num_e++; } pfkey_supported_listp = pfkey_supported_listp->next; } if(alg_num_a) { KLIPS_PRINT(debug_pfkey, "klips_debug:pfkey_register_reply: " "allocating %lu bytes for auth algs.\n", (unsigned long) (alg_num_a * sizeof(struct sadb_alg))); if((alg_a = kmalloc(alg_num_a * sizeof(struct sadb_alg), GFP_ATOMIC) ) == NULL) { KLIPS_PRINT(debug_pfkey, "klips_debug:pfkey_register_reply: " "auth alg memory allocation error\n"); SENDERR(ENOMEM); } alg_ap = alg_a; } if(alg_num_e) { KLIPS_PRINT(debug_pfkey, "klips_debug:pfkey_register_reply: " "allocating %lu bytes for enc algs.\n", (unsigned long) (alg_num_e * sizeof(struct sadb_alg))); if((alg_e = kmalloc(alg_num_e * sizeof(struct sadb_alg), GFP_ATOMIC) ) == NULL) { KLIPS_PRINT(debug_pfkey, "klips_debug:pfkey_register_reply: " "enc alg memory allocation error\n"); SENDERR(ENOMEM); } alg_ep = alg_e; } pfkey_supported_listp = pfkey_supported_list[satype]; while(pfkey_supported_listp) { if(alg_num_a) { if(pfkey_supported_listp->supportedp->supported_alg_exttype == SADB_EXT_SUPPORTED_AUTH) { alg_ap->sadb_alg_id = pfkey_supported_listp->supportedp->supported_alg_id; alg_ap->sadb_alg_ivlen = pfkey_supported_listp->supportedp->supported_alg_ivlen; alg_ap->sadb_alg_minbits = pfkey_supported_listp->supportedp->supported_alg_minbits; alg_ap->sadb_alg_maxbits = pfkey_supported_listp->supportedp->supported_alg_maxbits; alg_ap->sadb_alg_reserved = 0; KLIPS_PRINT(debug_pfkey && sysctl_ipsec_debug_verbose, "klips_debug:pfkey_register_reply: " "adding auth=0p%p\n", alg_ap); alg_ap++; } } if(alg_num_e) { if(pfkey_supported_listp->supportedp->supported_alg_exttype == SADB_EXT_SUPPORTED_ENCRYPT) { alg_ep->sadb_alg_id = pfkey_supported_listp->supportedp->supported_alg_id; alg_ep->sadb_alg_ivlen = pfkey_supported_listp->supportedp->supported_alg_ivlen; alg_ep->sadb_alg_minbits = pfkey_supported_listp->supportedp->supported_alg_minbits; alg_ep->sadb_alg_maxbits = pfkey_supported_listp->supportedp->supported_alg_maxbits; alg_ep->sadb_alg_reserved = 0; KLIPS_PRINT(debug_pfkey && sysctl_ipsec_debug_verbose, "klips_debug:pfkey_register_reply: " "adding encrypt=0p%p\n", alg_ep); alg_ep++; } } KLIPS_PRINT(debug_pfkey, "klips_debug:pfkey_register_reply: " "found satype=%d(%s) exttype=%d id=%d ivlen=%d minbits=%d maxbits=%d.\n", satype, satype2name(satype), pfkey_supported_listp->supportedp->supported_alg_exttype, pfkey_supported_listp->supportedp->supported_alg_id, pfkey_supported_listp->supportedp->supported_alg_ivlen, pfkey_supported_listp->supportedp->supported_alg_minbits, pfkey_supported_listp->supportedp->supported_alg_maxbits); pfkey_supported_listp = pfkey_supported_listp->next; } if(!(pfkey_safe_build(error = pfkey_msg_hdr_build(&extensions_reply[0], SADB_REGISTER, satype, 0, sadb_msg? sadb_msg->sadb_msg_seq : ++pfkey_msg_seq, sadb_msg? sadb_msg->sadb_msg_pid: current->pid), extensions_reply) && (alg_num_a ? pfkey_safe_build(error = pfkey_supported_build(&extensions_reply[SADB_EXT_SUPPORTED_AUTH], SADB_EXT_SUPPORTED_AUTH, alg_num_a, alg_a), extensions_reply) : 1) && (alg_num_e ? pfkey_safe_build(error = pfkey_supported_build(&extensions_reply[SADB_EXT_SUPPORTED_ENCRYPT], SADB_EXT_SUPPORTED_ENCRYPT, alg_num_e, alg_e), extensions_reply) : 1))) { KLIPS_PRINT(debug_pfkey, "klips_debug:pfkey_register_reply: " "failed to build the register message extensions_reply\n"); SENDERR(-error); } if((error = pfkey_msg_build(&pfkey_reply, extensions_reply, EXT_BITS_OUT))) { KLIPS_PRINT(debug_pfkey, "klips_debug:pfkey_register_reply: " "failed to build the register message\n"); SENDERR(-error); } /* this should go to all registered sockets for that satype only */ for(pfkey_socketsp = pfkey_registered_sockets[satype]; pfkey_socketsp; pfkey_socketsp = pfkey_socketsp->next) { if((error = pfkey_upmsg(pfkey_socketsp->socketp, pfkey_reply))) { KLIPS_PRINT(debug_pfkey, "klips_debug:pfkey_register_reply: " "sending up acquire message for satype=%d(%s) to socket=0p%p failed with error=%d.\n", satype, satype2name(satype), pfkey_socketsp->socketp, error); SENDERR(-error); } KLIPS_PRINT(debug_pfkey, "klips_debug:pfkey_register_reply: " "sending up register message for satype=%d(%s) to socket=0p%p succeeded.\n", satype, satype2name(satype), pfkey_sockets
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -