📄 pfkey_v2.c
字号:
#endif release: pfkey_release, bind: sock_no_bind, connect: sock_no_connect, socketpair: sock_no_socketpair, accept: sock_no_accept, getname: sock_no_getname, poll: datagram_poll, ioctl: sock_no_ioctl, listen: sock_no_listen, shutdown: pfkey_shutdown, setsockopt: sock_no_setsockopt, getsockopt: sock_no_getsockopt, sendmsg: pfkey_sendmsg, recvmsg: pfkey_recvmsg, mmap: sock_no_mmap,};#else /* NET_21 */struct proto_ops pfkey_proto_ops = { PF_KEY, pfkey_create, pfkey_dup, pfkey_release, pfkey_bind, pfkey_connect, pfkey_socketpair, pfkey_accept, pfkey_getname, pfkey_select, pfkey_ioctl, pfkey_listen, pfkey_shutdown, pfkey_setsockopt, pfkey_getsockopt, pfkey_fcntl, pfkey_sendmsg, pfkey_recvmsg};#endif /* NET_21 */ #ifdef CONFIG_PROC_FS#ifndef PROC_FS_2325DEBUG_NO_STATIC#endif /* PROC_FS_2325 */intpfkey_get_info(char *buffer, char **start, off_t offset, int length#ifndef PROC_NO_DUMMY, int dummy#endif /* !PROC_NO_DUMMY */){ const int max_content = length > 0? length-1 : 0; /* limit of useful snprintf output */#ifdef NET_26 struct hlist_node *node;#endif off_t begin=0; int len=0; struct sock *sk; #ifdef CONFIG_KLIPS_DEBUG if(!sysctl_ipsec_debug_verbose) {#endif /* CONFIG_KLIPS_DEBUG */ len += ipsec_snprintf(buffer, length, " sock pid socket next prev e n p sndbf Flags Type St\n");#ifdef CONFIG_KLIPS_DEBUG } else { len += ipsec_snprintf(buffer, length, " sock pid d sleep socket next prev e r z n p sndbf stamp Flags Type St\n"); }#endif /* CONFIG_KLIPS_DEBUG */ sk_for_each(sk, node, &pfkey_sock_list) {#ifdef CONFIG_KLIPS_DEBUG if(!sysctl_ipsec_debug_verbose) {#endif /* CONFIG_KLIPS_DEBUG */ len += ipsec_snprintf(buffer+len, length-len, "%8p %5d %8p %d %d %5d %08lX %8X %2X\n", sk, key_pid(sk), sk->sk_socket, sk->sk_err, sk->sk_protocol, sk->sk_sndbuf, sk->sk_socket->flags, sk->sk_socket->type, sk->sk_socket->state);#ifdef CONFIG_KLIPS_DEBUG } else { len += ipsec_snprintf(buffer+len, length-len, "%8p %5d %d %8p %8p %d %d %d %d %5d %d.%06d %08lX %8X %2X\n", sk, key_pid(sk), sock_flag(sk, SOCK_DEAD), sk->sk_sleep, sk->sk_socket, sk->sk_err, sk->sk_reuse,#ifdef HAVE_SOCK_ZAPPED sock_flag(sk, SOCK_ZAPPED),#else sk->sk_zapped,#endif sk->sk_protocol, sk->sk_sndbuf, (unsigned int)sk->sk_stamp.tv_sec, (unsigned int)sk->sk_stamp.tv_usec, sk->sk_socket->flags, sk->sk_socket->type, sk->sk_socket->state); }#endif /* CONFIG_KLIPS_DEBUG */ if (len >= max_content) { /* we've done all that can fit -- stop loop */ len = max_content; /* truncate crap */ break; } else { const off_t pos = begin + len; /* file position of end of what we've generated */ if (pos <= offset) { /* all is before first interesting character: * discard, but note where we are. */ len = 0; begin = pos; } } } *start = buffer + (offset - begin); /* Start of wanted data */ return len - (offset - begin);}#ifndef PROC_FS_2325DEBUG_NO_STATIC#endif /* PROC_FS_2325 */intpfkey_supported_get_info(char *buffer, char **start, off_t offset, int length#ifndef PROC_NO_DUMMY, int dummy#endif /* !PROC_NO_DUMMY */){ /* limit of useful snprintf output */ const int max_content = length > 0? length-1 : 0; off_t begin=0; int len=0; int satype; struct supported_list *ps; len += ipsec_snprintf(buffer, length, "satype exttype alg_id ivlen minbits maxbits name\n"); for(satype = SADB_SATYPE_UNSPEC; satype <= SADB_SATYPE_MAX; satype++) { ps = pfkey_supported_list[satype]; while(ps) { struct ipsec_alg_supported *alg = ps->supportedp; unsigned char *n = alg->ias_name; if(n == NULL) n = "unknown"; len += ipsec_snprintf(buffer+len, length-len, " %2d %2d %2d %3d %3d %3d %20s\n", satype, alg->ias_exttype, alg->ias_id, alg->ias_ivlen, alg->ias_keyminbits, alg->ias_keymaxbits, n); if (len >= max_content) { /* we've done all that can fit -- stop loop */ len = max_content; /* truncate crap */ break; } else { const off_t pos = begin + len; /* file position of end of what we've generated */ if (pos <= offset) { /* all is before first interesting character: * discard, but note where we are. */ len = 0; begin = pos; } } ps = ps->next; } } *start = buffer + (offset - begin); /* Start of wanted data */ return len - (offset - begin);}#ifndef PROC_FS_2325DEBUG_NO_STATIC#endif /* PROC_FS_2325 */intpfkey_registered_get_info(char *buffer, char **start, off_t offset, int length#ifndef PROC_NO_DUMMY, int dummy#endif /* !PROC_NO_DUMMY */){ const int max_content = length > 0? length-1 : 0; /* limit of useful snprintf output */ off_t begin=0; int len=0; int satype; struct socket_list *pfkey_sockets; len += ipsec_snprintf(buffer, length, "satype socket pid sk\n"); for(satype = SADB_SATYPE_UNSPEC; satype <= SADB_SATYPE_MAX; satype++) { pfkey_sockets = pfkey_registered_sockets[satype]; while(pfkey_sockets) {#ifdef NET_21 len += ipsec_snprintf(buffer+len, length-len, " %2d %8p %5d %8p\n", satype, pfkey_sockets->socketp, key_pid(pfkey_sockets->socketp->sk), pfkey_sockets->socketp->sk);#else /* NET_21 */ len += ipsec_snprintf(buffer+len, " %2d %8p N/A %8p\n", satype, pfkey_sockets->socketp,#if 0 key_pid((pfkey_sockets->socketp)->data),#endif (pfkey_sockets->socketp)->data);#endif /* NET_21 */ if (len >= max_content) { /* we've done all that can fit -- stop loop (could stop two) */ len = max_content; /* truncate crap */ break; } else { const off_t pos = begin + len; /* file position of end of what we've generated */ if (pos <= offset) { /* all is before first interesting character: * discard, but note where we are. */ len = 0; begin = pos; } } pfkey_sockets = pfkey_sockets->next; } } *start = buffer + (offset - begin); /* Start of wanted data */ return len - (offset - begin);}#ifndef PROC_FS_2325struct proc_dir_entry proc_net_pfkey ={ 0, 6, "pf_key", S_IFREG | S_IRUGO, 1, 0, 0, 0, &proc_net_inode_operations, pfkey_get_info};struct proc_dir_entry proc_net_pfkey_supported ={ 0, 16, "pf_key_supported", S_IFREG | S_IRUGO, 1, 0, 0, 0, &proc_net_inode_operations, pfkey_supported_get_info};struct proc_dir_entry proc_net_pfkey_registered ={ 0, 17, "pf_key_registered", S_IFREG | S_IRUGO, 1, 0, 0, 0, &proc_net_inode_operations, pfkey_registered_get_info};#endif /* !PROC_FS_2325 */#endif /* CONFIG_PROC_FS */DEBUG_NO_STATIC intsupported_add_all(int satype, struct ipsec_alg_supported supported[], int size){ int i; int error = 0; KLIPS_PRINT(debug_pfkey, "klips_debug:init_pfkey: " "sizeof(supported_init_<satype=%d>)[%d]/sizeof(struct ipsec_alg_supported)[%d]=%d.\n", satype, size, (int)sizeof(struct ipsec_alg_supported), (int)(size/sizeof(struct ipsec_alg_supported))); for(i = 0; i < size / sizeof(struct ipsec_alg_supported); i++) { unsigned char *n = supported[i].ias_name; if(n == NULL) n="unknown"; KLIPS_PRINT(debug_pfkey, "klips_debug:init_pfkey: " "i=%d inserting satype=%d exttype=%d id=%d ivlen=%d minbits=%d maxbits=%d name=%s.\n", i, satype, supported[i].ias_exttype, supported[i].ias_id, supported[i].ias_ivlen, supported[i].ias_keyminbits, supported[i].ias_keymaxbits, n); error |= pfkey_list_insert_supported(&(supported[i]), &(pfkey_supported_list[satype])); } return error;}DEBUG_NO_STATIC intsupported_remove_all(int satype){ int error = 0; struct ipsec_alg_supported*supportedp; while(pfkey_supported_list[satype]) { unsigned char *n; supportedp = pfkey_supported_list[satype]->supportedp; n = supportedp->ias_name; if(n == NULL) n="unknown"; KLIPS_PRINT(debug_pfkey, "klips_debug:init_pfkey: " "removing satype=%d exttype=%d id=%d ivlen=%d minbits=%d maxbits=%d name=%s.\n", satype, supportedp->ias_exttype, supportedp->ias_id, supportedp->ias_ivlen, supportedp->ias_keyminbits, supportedp->ias_keymaxbits, n); error |= pfkey_list_remove_supported(supportedp, &(pfkey_supported_list[satype])); } return error;}intpfkey_init(void){ int error = 0; int i; static struct ipsec_alg_supported supported_init_ah[] = {#ifdef CONFIG_KLIPS_AUTH_HMAC_MD5 {SADB_EXT_SUPPORTED_AUTH, SADB_AALG_MD5HMAC, 0, 128, 128},#endif /* CONFIG_KLIPS_AUTH_HMAC_MD5 */#ifdef CONFIG_KLIPS_AUTH_HMAC_SHA1 {SADB_EXT_SUPPORTED_AUTH, SADB_AALG_SHA1HMAC, 0, 160, 160}#endif /* CONFIG_KLIPS_AUTH_HMAC_SHA1 */ }; static struct ipsec_alg_supported supported_init_esp[] = {#ifdef CONFIG_KLIPS_AUTH_HMAC_MD5 {SADB_EXT_SUPPORTED_AUTH, SADB_AALG_MD5HMAC, 0, 128, 128},#endif /* CONFIG_KLIPS_AUTH_HMAC_MD5 */#ifdef CONFIG_KLIPS_AUTH_HMAC_SHA1 {SADB_EXT_SUPPORTED_AUTH, SADB_AALG_SHA1HMAC, 0, 160, 160},#endif /* CONFIG_KLIPS_AUTH_HMAC_SHA1 */#ifdef CONFIG_KLIPS_ENC_3DES {SADB_EXT_SUPPORTED_ENCRYPT, SADB_EALG_3DESCBC, 64, 168, 168},#endif /* CONFIG_KLIPS_ENC_3DES */ }; static struct ipsec_alg_supported supported_init_ipip[] = { {SADB_EXT_SUPPORTED_ENCRYPT, SADB_X_TALG_IPv4_in_IPv4, 0, 32, 32}#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) , {SADB_EXT_SUPPORTED_ENCRYPT, SADB_X_TALG_IPv6_in_IPv4, 0, 128, 32} , {SADB_EXT_SUPPORTED_ENCRYPT, SADB_X_TALG_IPv4_in_IPv6, 0, 32, 128} , {SADB_EXT_SUPPORTED_ENCRYPT, SADB_X_TALG_IPv6_in_IPv6, 0, 128, 128}#endif /* defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) */ };#ifdef CONFIG_KLIPS_IPCOMP static struct ipsec_alg_supported supported_init_ipcomp[] = { {SADB_EXT_SUPPORTED_ENCRYPT, SADB_X_CALG_DEFLATE, 0, 1, 1} };#endif /* CONFIG_KLIPS_IPCOMP */#if 0 printk(KERN_INFO "klips_info:pfkey_init: " "FreeS/WAN: initialising PF_KEYv2 domain sockets.\n");#endif for(i = SADB_SATYPE_UNSPEC; i <= SADB_SATYPE_MAX; i++) { pfkey_registered_sockets[i] = NULL; pfkey_supported_list[i] = NULL; } error |= supported_add_all(SADB_SATYPE_AH, supported_init_ah, sizeof(supported_init_ah)); error |= supported_add_all(SADB_SATYPE_ESP, supported_init_esp, sizeof(supported_init_esp));#ifdef CONFIG_KLIPS_IPCOMP error |= supported_add_all(SADB_X_SATYPE_COMP, supported_init_ipcomp, sizeof(supported_init_ipcomp));#endif /* CONFIG_KLIPS_IPCOMP */ error |= supported_add_all(SADB_X_SATYPE_IPIP, supported_init_ipip, sizeof(supported_init_ipip));#ifdef NET_21 error |= sock_register(&pfkey_family_ops);#else /* NET_21 */ error |= sock_register(pfkey_proto_ops.family, &pfkey_proto_ops);#endif /* NET_21 */#ifdef CONFIG_PROC_FS# ifndef PROC_FS_2325# ifdef PROC_FS_21 error |= proc_register(proc_net, &proc_net_pfkey); error |= proc_register(proc_net, &proc_net_pfkey_supported); error |= proc_register(proc_net, &proc_net_pfkey_registered);# else /* PROC_FS_21 */ error |= proc_register_dynamic(&proc_net, &proc_net_pfkey); error |= proc_register_dynamic(&proc_net, &proc_net_pfkey_supported); error |= proc_register_dynamic(&proc_net, &proc_net_pfkey_registered);# endif /* PROC_FS_21 */# else /* !PROC_FS_2325 */ proc_net_create ("pf_key", 0, pfkey_get_info); proc_net_create ("pf_key_supported", 0, pfkey_supported_get_info); proc_net_create ("pf_key_registered", 0, pfkey_registered_get_info);# endif /* !PROC_FS_2325 */#endif /* CONFIG_PROC_FS */ return error;}intpfkey_cleanup(void){ int error = 0; printk(KERN_INFO "klips_info:pfkey_cleanup: " "shutting down PF_KEY domain sockets.\n");#ifdef NET_21 error |= sock_unregister(PF_KEY);#else /* NET_21 */ error |= sock_unregister(pfkey_proto_ops.family);#endif /* NET_21 */ error |= supported_remove_all(SADB_SATYPE_AH); error |= supported_remove_all(SADB_SATYPE_ESP);#ifdef CONFIG_KLIPS_IPCOMP error |= supported_remove_all(SADB_X_SATYPE_COMP);#endif /* CONFIG_KLIPS_IPCOMP */ error |= supported_remove_all(SADB_X_SATYPE_IPIP);#ifdef CONFIG_PROC_FS# ifndef PROC_FS_2325 if (proc_net_unregister(proc_net_pfkey.low_ino) != 0) printk("klips_debug:pfkey_cleanup: " "cannot unregister /proc/net/pf_key\n"); if (proc_net_unregister(proc_net_pfkey_supported.low_ino) != 0) printk("klips_debug:pfkey_cleanup: " "cannot unregister /proc/net/pf_key_supported\n"); if (proc_net_unregister(proc_net_pfkey_registered.low_ino) != 0) printk("klips_debug:pfkey_cleanup: " "cannot unregister /proc/net/pf_key_registered\n");# else /* !PROC_FS_2325 */ proc_net_remove ("pf_key"); proc_net_remove ("pf_key_supported");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -