My kernel module's proto_ops structure is defined as such ...
Code:
static const struct proto_ops my_proto_ops = {
...
.bind = my_bind,
.listen = my_listen,
...
};
And I have function callbacks for each of these ...
Code:
static int my_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
{
...
}
static int my_listen(struct socket *sock, int backlog)
{
...
}
In my net_proto_family structure's create function I have this line ...
Code:
static int my_create(struct net *net, struct socket *sock, int protocol, int kern)
{
//...
sock->ops = &my_proto_ops;
printk(KERN_INFO "my_proto_ops.bind = %p\n", my_proto_ops.bind);
printk(KERN_INFO "my_proto_ops.listen = %p\n", my_proto_ops.listen);
//...
}
which prints this output in /var/log/messages when run ...
my_proto_ops.bind = ffffffffa00001c5
my_proto_ops.listen = ffffffffa00000000
What I don't understand is why I see bind w/ a valid address, and the listen is null. This is exactly what I run into when I'm running my kernel module, my_bind is called, but my_listen fails with ...
BUG: unable to handle kernel NULL pointer dereference at 0000000000000040
IP: [<ffffffff81417397>] sys_listen+0x29/0x70
PGD 1edd7067 PUD 1f099067 PMD 0
Oops: 0000 [#1] SMP
last sysfs file: /sys/devices/virtio-pci/virtio0/net/net0/broadcast
CPU 0
my_bind() exits successfully when run, but then it crashes and my_listen is never even called, which seems to be the case as my_proto_ops.listen is null so it therefore can't be called. But I don't see how as "my_proto_ops.listen = my_listen," and "sock->ops = &my_proto_ops" in the create function.
Can anyone help clarify what might be going on? Any help much appreciated.