Beispiel #1
0
static void sock_init(struct sock *sk, int family, int type,
		int protocol, const struct sock_family_ops *f_ops,
		const struct sock_proto_ops *p_ops,
		const struct net_pack_out_ops *o_ops) {
	assert(sk != NULL);
	assert(f_ops != NULL);
	assert(p_ops != NULL);

	dlist_head_init(&sk->lnk);
	sock_opt_init(&sk->opt, family, type, protocol);
	skb_queue_init(&sk->rx_queue);
	skb_queue_init(&sk->tx_queue);
	sk->rx_data_len = 0;
	sock_set_state(sk, SS_UNKNOWN);
	sk->shutdown_flag = 0;
	sk->p_sk = sk->p_sk; /* setup in sock_alloc() */
	sk->f_ops = f_ops;
	sk->p_ops = p_ops;
	sk->o_ops = o_ops;
	sk->src_addr = sk->dst_addr = NULL;
	sk->addr_len = 0;
	sk->err = 0;

	idesc_init(&sk->idesc, &task_idx_ops_socket, FS_MAY_READ | FS_MAY_WRITE);
	sock_xattr_init(sk);
	security_sock_create(sk);
}
Beispiel #2
0
static struct idesc *tun_dev_open(struct node *node, struct file_desc *file_desc, int flags) {
	struct net_device *netdev;
	struct tun *tun;

	netdev = tun_netdev_by_node(node);
	if (!netdev) {
		return err_ptr(ENOENT);
	}

	tun = netdev_priv(netdev, struct tun);
	tun_user_lock(tun);

	waitq_init(&tun->wq);

	tun_krnl_lock(tun);
	{
		skb_queue_init(&tun->rx_q);
	}
	tun_krnl_unlock(tun);

	file_desc->file_info = netdev;

	return &file_desc->idesc;
}