net/bluetooth/bnep/sock.c

Source file repositories/reference/linux-study-clean/net/bluetooth/bnep/sock.c

File Facts

System
Linux kernel
Corpus path
net/bluetooth/bnep/sock.c
Extension
.c
Size
5664 bytes
Lines
258
Domain
Networking Core
Bucket
Sockets, Protocols, Packet Path, And Network Policy
Inferred role
Networking Core: operation-table or driver-model contract
Status
pattern implementation candidate

Why This File Exists

Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.

Dependency Surface

Detected Declarations

Annotated Snippet

static const struct proto_ops bnep_sock_ops = {
	.family		= PF_BLUETOOTH,
	.owner		= THIS_MODULE,
	.release	= bnep_sock_release,
	.ioctl		= bnep_sock_ioctl,
#ifdef CONFIG_COMPAT
	.compat_ioctl	= bnep_sock_compat_ioctl,
#endif
	.bind		= sock_no_bind,
	.getname	= sock_no_getname,
	.sendmsg	= sock_no_sendmsg,
	.recvmsg	= sock_no_recvmsg,
	.listen		= sock_no_listen,
	.shutdown	= sock_no_shutdown,
	.connect	= sock_no_connect,
	.socketpair	= sock_no_socketpair,
	.accept		= sock_no_accept,
	.mmap		= sock_no_mmap
};

static struct proto bnep_proto = {
	.name		= "BNEP",
	.owner		= THIS_MODULE,
	.obj_size	= sizeof(struct bt_sock)
};

static int bnep_sock_create(struct net *net, struct socket *sock, int protocol,
			    int kern)
{
	struct sock *sk;

	BT_DBG("sock %p", sock);

	if (sock->type != SOCK_RAW)
		return -ESOCKTNOSUPPORT;

	sk = bt_sock_alloc(net, sock, &bnep_proto, protocol, GFP_ATOMIC, kern);
	if (!sk)
		return -ENOMEM;

	sock->ops = &bnep_sock_ops;
	sock->state = SS_UNCONNECTED;

	bt_sock_link(&bnep_sk_list, sk);
	return 0;
}

static const struct net_proto_family bnep_sock_family_ops = {
	.family = PF_BLUETOOTH,
	.owner	= THIS_MODULE,
	.create = bnep_sock_create
};

int __init bnep_sock_init(void)
{
	int err;

	err = proto_register(&bnep_proto, 0);
	if (err < 0)
		return err;

	err = bt_sock_register(BTPROTO_BNEP, &bnep_sock_family_ops);
	if (err < 0) {
		BT_ERR("Can't register BNEP socket");
		goto error;
	}

	err = bt_procfs_init(&init_net, "bnep", &bnep_sk_list, NULL);
	if (err < 0) {
		BT_ERR("Failed to create BNEP proc file");
		bt_sock_unregister(BTPROTO_BNEP);
		goto error;
	}

	BT_INFO("BNEP socket layer initialized");

	return 0;

error:
	proto_unregister(&bnep_proto);
	return err;
}

void __exit bnep_sock_cleanup(void)
{
	bt_procfs_cleanup(&init_net, "bnep");
	bt_sock_unregister(BTPROTO_BNEP);
	proto_unregister(&bnep_proto);
}

Annotation

Implementation Notes