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

📄 pfkey_v2.c

📁 ipsec vpn
💻 C
📖 第 1 页 / 共 5 页
字号:
                        printk(" stamp:%ld.%ld", skb->stamp.tv_sec, skb->stamp.tv_usec);#endif			printk(" dev:0p%p", skb->dev);			if(skb->dev) {				if(skb->dev->name) {					printk(" dev->name:%s", skb->dev->name);				} else {					printk(" dev->name:NULL?");				}			} else {				printk(" dev:NULL");			}			printk(" h:0p%p", skb->h.raw);			printk(" nh:0p%p", skb->nh.raw);			printk(" mac:0p%p", skb->mac.raw);			printk(" dst:0p%p", skb->dst);			if(sysctl_ipsec_debug_verbose) {				int i;								printk(" cb");				for(i=0; i<48; i++) {					printk(":%2x", skb->cb[i]);				}			}			printk(" len:%d", skb->len);			printk(" csum:%d", skb->csum);#ifndef NETDEV_23			printk(" used:%d", skb->used);			printk(" is_clone:%d", skb->is_clone);#endif /* NETDEV_23 */			printk(" cloned:%d", skb->cloned);			printk(" pkt_type:%d", skb->pkt_type);			printk(" ip_summed:%d", skb->ip_summed);			printk(" priority:%d", skb->priority);			printk(" protocol:%d", skb->protocol);#ifdef HAVE_SOCK_SECURITY			printk(" security:%d", skb->security);#endif			printk(" truesize:%d", skb->truesize);			printk(" head:0p%p", skb->head);			printk(" data:0p%p", skb->data);			printk(" tail:0p%p", skb->tail);			printk(" end:0p%p", skb->end);			if(sysctl_ipsec_debug_verbose) {				unsigned char* i;				printk(" data");				for(i = skb->head; i < skb->end; i++) {					printk(":%2x", (unsigned char)(*(i)));				}			}			printk(" destructor:0p%p", skb->destructor);			printk("\n");		}#endif /* CONFIG_KLIPS_DEBUG */#endif /* NET_21 */		KLIPS_PRINT(debug_pfkey,			    "klips_debug:pfkey_destroy_socket: "			    "skb=0p%p freed.\n",			    skb);		ipsec_kfree_skb(skb);	}#ifdef NET_26	sock_set_flag(sk, SOCK_DEAD);#else	sk->dead = 1;#endif	sk_free(sk);	KLIPS_PRINT(debug_pfkey,		    "klips_debug:pfkey_destroy_socket: destroyed.\n");}intpfkey_upmsg(struct socket *sock, struct sadb_msg *pfkey_msg){	int error = 0;	struct sk_buff * skb = NULL;	struct sock *sk;	if(sock == NULL) {		KLIPS_PRINT(debug_pfkey,			    "klips_debug:pfkey_upmsg: "			    "NULL socket passed in.\n");		return -EINVAL;	}	if(pfkey_msg == NULL) {		KLIPS_PRINT(debug_pfkey,			    "klips_debug:pfkey_upmsg: "			    "NULL pfkey_msg passed in.\n");		return -EINVAL;	}#ifdef NET_21	sk = sock->sk;#else /* NET_21 */	sk = sock->data;#endif /* NET_21 */	if(sk == NULL) {		KLIPS_PRINT(debug_pfkey,			    "klips_debug:pfkey_upmsg: "			    "NULL sock passed in.\n");		return -EINVAL;	}	KLIPS_PRINT(debug_pfkey,		    "klips_debug:pfkey_upmsg: "		    "allocating %d bytes...\n",		    (int)(pfkey_msg->sadb_msg_len * IPSEC_PFKEYv2_ALIGN));	if(!(skb = alloc_skb(pfkey_msg->sadb_msg_len * IPSEC_PFKEYv2_ALIGN, GFP_ATOMIC) )) {		KLIPS_PRINT(debug_pfkey,			    "klips_debug:pfkey_upmsg: "			    "no buffers left to send up a message.\n");		return -ENOBUFS;	}	KLIPS_PRINT(debug_pfkey,		    "klips_debug:pfkey_upmsg: "		    "...allocated at 0p%p.\n",		    skb);		skb->dev = NULL;		if(skb_tailroom(skb) < pfkey_msg->sadb_msg_len * IPSEC_PFKEYv2_ALIGN) {		printk(KERN_WARNING "klips_error:pfkey_upmsg: "		       "tried to skb_put %ld, %d available.  This should never happen, please report.\n",		       (unsigned long int)pfkey_msg->sadb_msg_len * IPSEC_PFKEYv2_ALIGN,		       skb_tailroom(skb));		ipsec_kfree_skb(skb);		return -ENOBUFS;	}	skb->h.raw = skb_put(skb, pfkey_msg->sadb_msg_len * IPSEC_PFKEYv2_ALIGN);	memcpy(skb->h.raw, pfkey_msg, pfkey_msg->sadb_msg_len * IPSEC_PFKEYv2_ALIGN);#ifndef NET_21	skb->free = 1;#endif /* !NET_21 */	if((error = sock_queue_rcv_skb(sk, skb)) < 0) {		skb->sk=NULL;		KLIPS_PRINT(debug_pfkey,			    "klips_debug:pfkey_upmsg: "			    "error=%d calling sock_queue_rcv_skb with skb=0p%p.\n",			    error,			    skb);		ipsec_kfree_skb(skb);		return error;	}	return error;}#ifdef NET_26_12_SKALLOCstatic struct proto key_proto = {	.name	  = "KEY",	.owner	  = THIS_MODULE,	.obj_size = sizeof(struct sock),	};#endifDEBUG_NO_STATIC intpfkey_create(struct socket *sock, int protocol){	struct sock *sk;	if(sock == NULL) {		KLIPS_PRINT(debug_pfkey,			    "klips_debug:pfkey_create: "			    "socket NULL.\n");		return -EINVAL;	}	KLIPS_PRINT(debug_pfkey,		    "klips_debug:pfkey_create: "		    "sock=0p%p type:%d state:%d flags:%ld protocol:%d\n",		    sock,		    sock->type,		    (unsigned int)(sock->state),		    sock->flags, protocol);	if(sock->type != SOCK_RAW) {		KLIPS_PRINT(debug_pfkey,			    "klips_debug:pfkey_create: "			    "only SOCK_RAW supported.\n");		return -ESOCKTNOSUPPORT;	}	if(protocol != PF_KEY_V2) {		KLIPS_PRINT(debug_pfkey,			    "klips_debug:pfkey_create: "			    "protocol not PF_KEY_V2.\n");		return -EPROTONOSUPPORT;	}	if((current->uid != 0)) {		KLIPS_PRINT(debug_pfkey,			    "klips_debug:pfkey_create: "			    "must be root to open pfkey sockets.\n");		return -EACCES;	}#ifdef NET_21	sock->state = SS_UNCONNECTED;#endif /* NET_21 */	KLIPS_INC_USE;#ifdef NET_21#ifdef NET_26#ifdef NET_26_12_SKALLOC	sk=(struct sock *)sk_alloc(PF_KEY, GFP_KERNEL, &key_proto, 1);#else	sk=(struct sock *)sk_alloc(PF_KEY, GFP_KERNEL, 1, NULL);#endif#else	/* 2.4 interface */	sk=(struct sock *)sk_alloc(PF_KEY, GFP_KERNEL, 1);#endif#else /* NET_21 */	/* 2.2 interface */	sk=(struct sock *)sk_alloc(GFP_KERNEL);#endif /* NET_21 */	if(sk == NULL)	{		KLIPS_PRINT(debug_pfkey,			    "klips_debug:pfkey_create: "			    "Out of memory trying to allocate.\n");		KLIPS_DEC_USE;		return -ENOMEM;	}#ifndef NET_21	memset(sk, 0, sizeof(*sk));#endif /* !NET_21 */#ifdef NET_21	sock_init_data(sock, sk);	sk->sk_destruct = NULL;	sk->sk_reuse = 1;	sock->ops = &pfkey_ops;	sk->sk_family = PF_KEY;/*	sk->num = protocol; */	sk->sk_protocol = protocol;	key_pid(sk) = current->pid;	KLIPS_PRINT(debug_pfkey,		    "klips_debug:pfkey_create: "		    "sock->fasync_list=0p%p sk->sleep=0p%p.\n",		    sock->fasync_list,		    sk->sk_sleep);#else /* NET_21 */	sk->type=sock->type;	init_timer(&sk->timer);	skb_queue_head_init(&sk->sk_write_queue);	skb_queue_head_init(&sk->sk_receive_queue);	skb_queue_head_init(&sk->back_log);	sk->sk_rcvbuf=SK_RMEM_MAX;	sk->sk_sndbuf=SK_WMEM_MAX;	sk->sk_allocation=GFP_KERNEL;	sk->sk_state=TCP_CLOSE;	sk->sk_priority=SOPRI_NORMAL;	sk->sk_state_change=pfkey_state_change;	sk->sk_data_ready=pfkey_data_ready;	sk->sk_write_space=pfkey_write_space;	sk->sk_error_report=pfkey_state_change;#ifndef NET_26	sk->mtu=4096;	sk->socket=sock;#endif	sock->data=(void *)sk;	sk->sk_sleep=sock->wait;#endif /* NET_21 */	pfkey_insert_socket(sk);	pfkey_list_insert_socket(sock, &pfkey_open_sockets);	KLIPS_PRINT(debug_pfkey,		    "klips_debug:pfkey_create: "		    "Socket sock=0p%p sk=0p%p initialised.\n", sock, sk);	return 0;}#ifndef NET_21DEBUG_NO_STATIC intpfkey_dup(struct socket *newsock, struct socket *oldsock){	struct sock *sk;	if(newsock==NULL) {		KLIPS_PRINT(debug_pfkey,			    "klips_debug:pfkey_dup: "			    "No new socket attached.\n");		return -EINVAL;	}			if(oldsock==NULL) {		KLIPS_PRINT(debug_pfkey,			    "klips_debug:pfkey_dup: "			    "No old socket attached.\n");		return -EINVAL;	}		#ifdef NET_21	sk=oldsock->sk;#else /* NET_21 */	sk=oldsock->data;#endif /* NET_21 */		/* May not have data attached */	if(sk==NULL) {		KLIPS_PRINT(debug_pfkey,			    "klips_debug:pfkey_dup: "			    "No sock attached to old socket.\n");		return -EINVAL;	}			KLIPS_PRINT(debug_pfkey,		    "klips_debug:pfkey_dup: .\n");	return pfkey_create(newsock, sk->protocol);}#endif /* !NET_21 */DEBUG_NO_STATIC int#ifdef NETDEV_23pfkey_release(struct socket *sock)#else /* NETDEV_23 */pfkey_release(struct socket *sock, struct socket *peersock)#endif /* NETDEV_23 */{	struct sock *sk;	int i;	if(sock==NULL) {		KLIPS_PRINT(debug_pfkey,			    "klips_debug:pfkey_release: "			    "No socket attached.\n");		return 0; /* -EINVAL; */	}		#ifdef NET_21	sk=sock->sk;#else /* NET_21 */	sk=sock->data;#endif /* NET_21 */		/* May not have data attached */	if(sk==NULL) {		KLIPS_PRINT(debug_pfkey,			    "klips_debug:pfkey_release: "			    "No sk attached to sock=0p%p.\n", sock);		return 0; /* -EINVAL; */	}	write_lock_bh(&pfkey_sock_lock);	KLIPS_PRINT(debug_pfkey,		    "klips_debug:pfkey_release: "		    "sock=0p%p sk=0p%p\n", sock, sk);#ifdef NET_21	if(sock_flag(sk, SOCK_DEAD))#endif /* NET_21 */		if(sk->sk_state_change) {			sk->sk_state_change(sk);		}#ifdef NET_21	sock->sk = NULL;#else /* NET_21 */	sock->data = NULL;#endif /* NET_21 */	/* Try to flush out this socket. Throw out buffers at least */	pfkey_destroy_socket(sk);	pfkey_list_remove_socket(sock, &pfkey_open_sockets);	for(i = SADB_SATYPE_UNSPEC; i <= SADB_SATYPE_MAX; i++) {		pfkey_list_remove_socket(sock, &(pfkey_registered_sockets[i]));	}	KLIPS_DEC_USE;	KLIPS_PRINT(debug_pfkey,		    "klips_debug:pfkey_release: "		    "succeeded.\n");	write_unlock_bh(&pfkey_sock_lock);	return 0;}#ifndef NET_21DEBUG_NO_STATIC intpfkey_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len){	KLIPS_PRINT(debug_pfkey,		    "klips_debug:pfkey_bind: "		    "operation not supported.\n");	return -EINVAL;}DEBUG_NO_STATIC intpfkey_connect(struct socket *sock, struct sockaddr *uaddr, int addr_len, int flags){	KLIPS_PRINT(debug_pfkey,		    "klips_debug:pfkey_connect: "		    "operation not supported.\n");	return -EINVAL;}DEBUG_NO_STATIC intpfkey_socketpair(struct socket *a, struct socket *b){	KLIPS_PRINT(debug_pfkey,		    "klips_debug:pfkey_socketpair: "		    "operation not supported.\n");	return -EINVAL;}DEBUG_NO_STATIC intpfkey_accept(struct socket *sock, struct socket *newsock, int flags){	KLIPS_PRINT(debug_pfkey,		    "klips_debug:pfkey_aaccept: "		    "operation not supported.\n");	return -EINVAL;}DEBUG_NO_STATIC intpfkey_getname(struct socket *sock, struct sockaddr *uaddr, int *uaddr_len,		int peer){	struct sockaddr *ska = (struct sockaddr*)uaddr;		KLIPS_PRINT(debug_pfkey,		    "klips_debug:pfkey_getname: .\n");	ska->sa_family = PF_KEY;	*uaddr_len = sizeof(*ska);	return 0;}DEBUG_NO_STATIC intpfkey_select(struct socket *sock, int sel_type, select_table *wait){		KLIPS_PRINT(debug_pfkey,		    "klips_debug:pfkey_select: "		    ".sock=0p%p sk=0p%p sel_type=%d\n",		    sock,		    sock->data,		    sel_type);	if(sock == NULL) {		KLIPS_PRINT(debug_pfkey,			    "klips_debug:pfkey_select: "			    "Null socket passed in.\n");		return -EINVAL;	}	return datagram_select(sock->data, sel_type, wait);}DEBUG_NO_STATIC intpfkey_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg){	KLIPS_PRINT(debug_pfkey,		    "klips_debug:pfkey_ioctl: "		    "not supported.\n");	return -EINVAL;

⌨️ 快捷键说明

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