2 * NETLINK Kernel-user communication protocol.
4 * Authors: Alan Cox <alan@redhat.com>
5 * Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
14 #include <linux/config.h>
15 #include <linux/module.h>
17 #include <linux/kernel.h>
18 #include <linux/init.h>
19 #include <linux/major.h>
20 #include <linux/signal.h>
21 #include <linux/sched.h>
22 #include <linux/errno.h>
23 #include <linux/string.h>
24 #include <linux/stat.h>
25 #include <linux/socket.h>
27 #include <linux/fcntl.h>
28 #include <linux/termios.h>
29 #include <linux/sockios.h>
30 #include <linux/net.h>
32 #include <linux/malloc.h>
33 #include <asm/uaccess.h>
34 #include <linux/skbuff.h>
35 #include <linux/netdevice.h>
36 #include <linux/netlink.h>
37 #include <linux/proc_fs.h>
38 #include <linux/smp_lock.h>
44 #if defined(CONFIG_NETLINK_DEV) || defined(CONFIG_NETLINK_DEV_MODULE)
45 #define NL_EMULATE_DEV
48 #define BUG_TRAP(x) if (!(x)) { printk("Assertion (" #x ") failed at " __FILE__ "(%d):" __FUNCTION__ "\n", __LINE__); }
57 int (*handler
)(int unit
, struct sk_buff
*skb
);
58 wait_queue_head_t wait
;
59 struct netlink_callback
*cb
;
61 void (*data_ready
)(struct sock
*sk
, int bytes
);
64 static struct sock
*nl_table
[MAX_LINKS
];
65 static DECLARE_WAIT_QUEUE_HEAD(nl_table_wait
);
68 static struct socket
*netlink_kernel
[MAX_LINKS
];
71 static int netlink_dump(struct sock
*sk
);
72 static void netlink_destroy_callback(struct netlink_callback
*cb
);
74 atomic_t netlink_sock_nr
;
76 static rwlock_t nl_table_lock
= RW_LOCK_UNLOCKED
;
77 static atomic_t nl_table_users
= ATOMIC_INIT(0);
79 static void netlink_sock_destruct(struct sock
*sk
)
81 skb_queue_purge(&sk
->receive_queue
);
84 printk("Freeing alive netlink socket %p\n", sk
);
87 BUG_TRAP(atomic_read(&sk
->rmem_alloc
)==0);
88 BUG_TRAP(atomic_read(&sk
->wmem_alloc
)==0);
89 BUG_TRAP(sk
->protinfo
.af_netlink
->cb
==NULL
);
91 kfree(sk
->protinfo
.af_netlink
);
93 atomic_dec(&netlink_sock_nr
);
94 #ifdef NETLINK_REFCNT_DEBUG
95 printk(KERN_DEBUG
"NETLINK %p released, %d are still alive\n", sk
, atomic_read(&netlink_sock_nr
));
99 /* This lock without WQ_FLAG_EXCLUSIVE is good on UP and it is _very_ bad on SMP.
100 * Look, when several writers sleep and reader wakes them up, all but one
101 * immediately hit write lock and grab all the cpus. Exclusive sleep solves
102 * this, _but_ remember, it adds useless work on UP machines.
105 static void netlink_table_grab(void)
107 write_lock_bh(&nl_table_lock
);
109 if (atomic_read(&nl_table_users
)) {
110 DECLARE_WAITQUEUE(wait
, current
);
112 add_wait_queue_exclusive(&nl_table_wait
, &wait
);
114 set_current_state(TASK_UNINTERRUPTIBLE
);
115 if (atomic_read(&nl_table_users
) == 0)
117 write_unlock_bh(&nl_table_lock
);
119 write_lock_bh(&nl_table_lock
);
122 __set_current_state(TASK_RUNNING
);
123 remove_wait_queue(&nl_table_wait
, &wait
);
127 static __inline__
void netlink_table_ungrab(void)
129 write_unlock_bh(&nl_table_lock
);
130 wake_up(&nl_table_wait
);
133 static __inline__
void
134 netlink_lock_table(void)
136 /* read_lock() synchronizes us to netlink_table_grab */
138 read_lock(&nl_table_lock
);
139 atomic_inc(&nl_table_users
);
140 read_unlock(&nl_table_lock
);
143 static __inline__
void
144 netlink_unlock_table(void)
146 if (atomic_dec_and_test(&nl_table_users
))
147 wake_up(&nl_table_wait
);
150 static __inline__
struct sock
*netlink_lookup(int protocol
, u32 pid
)
154 read_lock(&nl_table_lock
);
155 for (sk
=nl_table
[protocol
]; sk
; sk
=sk
->next
) {
156 if (sk
->protinfo
.af_netlink
->pid
== pid
) {
158 read_unlock(&nl_table_lock
);
163 read_unlock(&nl_table_lock
);
167 extern struct proto_ops netlink_ops
;
169 static int netlink_insert(struct sock
*sk
, u32 pid
)
171 int err
= -EADDRINUSE
;
174 netlink_table_grab();
175 for (osk
=nl_table
[sk
->protocol
]; osk
; osk
=osk
->next
) {
176 if (osk
->protinfo
.af_netlink
->pid
== pid
)
181 if (sk
->protinfo
.af_netlink
->pid
== 0) {
182 sk
->protinfo
.af_netlink
->pid
= pid
;
183 sk
->next
= nl_table
[sk
->protocol
];
184 nl_table
[sk
->protocol
] = sk
;
189 netlink_table_ungrab();
193 static void netlink_remove(struct sock
*sk
)
197 netlink_table_grab();
198 for (skp
= &nl_table
[sk
->protocol
]; *skp
; skp
= &((*skp
)->next
)) {
205 netlink_table_ungrab();
208 static int netlink_create(struct socket
*sock
, int protocol
)
212 sock
->state
= SS_UNCONNECTED
;
214 if (sock
->type
!= SOCK_RAW
&& sock
->type
!= SOCK_DGRAM
)
215 return -ESOCKTNOSUPPORT
;
217 if (protocol
<0 || protocol
>= MAX_LINKS
)
218 return -EPROTONOSUPPORT
;
220 sock
->ops
= &netlink_ops
;
222 sk
= sk_alloc(PF_NETLINK
, GFP_KERNEL
, 1);
226 sock_init_data(sock
,sk
);
228 sk
->protinfo
.af_netlink
= kmalloc(sizeof(struct netlink_opt
), GFP_KERNEL
);
229 if (sk
->protinfo
.af_netlink
== NULL
) {
233 memset(sk
->protinfo
.af_netlink
, 0, sizeof(struct netlink_opt
));
235 spin_lock_init(&sk
->protinfo
.af_netlink
->cb_lock
);
236 init_waitqueue_head(&sk
->protinfo
.af_netlink
->wait
);
237 sk
->destruct
= netlink_sock_destruct
;
238 atomic_inc(&netlink_sock_nr
);
240 sk
->protocol
=protocol
;
244 static int netlink_release(struct socket
*sock
)
246 struct sock
*sk
= sock
->sk
;
253 spin_lock(&sk
->protinfo
.af_netlink
->cb_lock
);
254 if (sk
->protinfo
.af_netlink
->cb
) {
255 sk
->protinfo
.af_netlink
->cb
->done(sk
->protinfo
.af_netlink
->cb
);
256 netlink_destroy_callback(sk
->protinfo
.af_netlink
->cb
);
257 sk
->protinfo
.af_netlink
->cb
= NULL
;
260 spin_unlock(&sk
->protinfo
.af_netlink
->cb_lock
);
262 /* OK. Socket is unlinked, and, therefore,
263 no new packets will arrive */
267 wake_up_interruptible_all(&sk
->protinfo
.af_netlink
->wait
);
269 skb_queue_purge(&sk
->write_queue
);
275 static int netlink_autobind(struct socket
*sock
)
277 struct sock
*sk
= sock
->sk
;
279 s32 pid
= current
->pid
;
283 netlink_table_grab();
284 for (osk
=nl_table
[sk
->protocol
]; osk
; osk
=osk
->next
) {
285 if (osk
->protinfo
.af_netlink
->pid
== pid
) {
286 /* Bind collision, search negative pid values. */
290 netlink_table_ungrab();
294 netlink_table_ungrab();
296 err
= netlink_insert(sk
, pid
);
297 if (err
== -EADDRINUSE
)
299 sk
->protinfo
.af_netlink
->groups
= 0;
303 static int netlink_bind(struct socket
*sock
, struct sockaddr
*addr
, int addr_len
)
305 struct sock
*sk
= sock
->sk
;
307 struct sockaddr_nl
*nladdr
=(struct sockaddr_nl
*)addr
;
309 if (nladdr
->nl_family
!= AF_NETLINK
)
312 /* Only superuser is allowed to listen multicasts */
313 if (nladdr
->nl_groups
&& !capable(CAP_NET_ADMIN
))
316 if (sk
->protinfo
.af_netlink
->pid
) {
317 if (nladdr
->nl_pid
!= sk
->protinfo
.af_netlink
->pid
)
319 sk
->protinfo
.af_netlink
->groups
= nladdr
->nl_groups
;
323 if (nladdr
->nl_pid
== 0) {
324 err
= netlink_autobind(sock
);
326 sk
->protinfo
.af_netlink
->groups
= nladdr
->nl_groups
;
330 err
= netlink_insert(sk
, nladdr
->nl_pid
);
332 sk
->protinfo
.af_netlink
->groups
= nladdr
->nl_groups
;
336 static int netlink_connect(struct socket
*sock
, struct sockaddr
*addr
,
340 struct sock
*sk
= sock
->sk
;
341 struct sockaddr_nl
*nladdr
=(struct sockaddr_nl
*)addr
;
343 if (addr
->sa_family
== AF_UNSPEC
) {
344 sk
->protinfo
.af_netlink
->dst_pid
= 0;
345 sk
->protinfo
.af_netlink
->dst_groups
= 0;
348 if (addr
->sa_family
!= AF_NETLINK
)
351 /* Only superuser is allowed to send multicasts */
352 if (nladdr
->nl_groups
&& !capable(CAP_NET_ADMIN
))
355 if (!sk
->protinfo
.af_netlink
->pid
)
356 err
= netlink_autobind(sock
);
359 sk
->protinfo
.af_netlink
->dst_pid
= nladdr
->nl_pid
;
360 sk
->protinfo
.af_netlink
->dst_groups
= nladdr
->nl_groups
;
366 static int netlink_getname(struct socket
*sock
, struct sockaddr
*addr
, int *addr_len
, int peer
)
368 struct sock
*sk
= sock
->sk
;
369 struct sockaddr_nl
*nladdr
=(struct sockaddr_nl
*)addr
;
371 nladdr
->nl_family
= AF_NETLINK
;
372 *addr_len
= sizeof(*nladdr
);
375 nladdr
->nl_pid
= sk
->protinfo
.af_netlink
->dst_pid
;
376 nladdr
->nl_groups
= sk
->protinfo
.af_netlink
->dst_groups
;
378 nladdr
->nl_pid
= sk
->protinfo
.af_netlink
->pid
;
379 nladdr
->nl_groups
= sk
->protinfo
.af_netlink
->groups
;
384 static void netlink_overrun(struct sock
*sk
)
386 if (!test_and_set_bit(0, &sk
->protinfo
.af_netlink
->state
)) {
388 sk
->error_report(sk
);
392 int netlink_unicast(struct sock
*ssk
, struct sk_buff
*skb
, u32 pid
, int nonblock
)
396 int protocol
= ssk
->protocol
;
398 DECLARE_WAITQUEUE(wait
, current
);
400 timeo
= sock_sndtimeo(ssk
, nonblock
);
403 sk
= netlink_lookup(protocol
, pid
);
407 #ifdef NL_EMULATE_DEV
408 if (sk
->protinfo
.af_netlink
->handler
) {
410 len
= sk
->protinfo
.af_netlink
->handler(protocol
, skb
);
416 if (atomic_read(&sk
->rmem_alloc
) > sk
->rcvbuf
||
417 test_bit(0, &sk
->protinfo
.af_netlink
->state
)) {
419 if (ssk
->protinfo
.af_netlink
->pid
== 0)
426 __set_current_state(TASK_INTERRUPTIBLE
);
427 add_wait_queue(&sk
->protinfo
.af_netlink
->wait
, &wait
);
429 if ((atomic_read(&sk
->rmem_alloc
) > sk
->rcvbuf
||
430 test_bit(0, &sk
->protinfo
.af_netlink
->state
)) &&
432 timeo
= schedule_timeout(timeo
);
434 __set_current_state(TASK_RUNNING
);
435 remove_wait_queue(&sk
->protinfo
.af_netlink
->wait
, &wait
);
438 if (signal_pending(current
)) {
440 return sock_intr_errno(timeo
);
446 skb_set_owner_r(skb
, sk
);
447 skb_queue_tail(&sk
->receive_queue
, skb
);
448 sk
->data_ready(sk
, len
);
454 return -ECONNREFUSED
;
457 static __inline__
int netlink_broadcast_deliver(struct sock
*sk
, struct sk_buff
*skb
)
459 #ifdef NL_EMULATE_DEV
460 if (sk
->protinfo
.af_netlink
->handler
) {
462 sk
->protinfo
.af_netlink
->handler(sk
->protocol
, skb
);
466 if (atomic_read(&sk
->rmem_alloc
) <= sk
->rcvbuf
&&
467 !test_bit(0, &sk
->protinfo
.af_netlink
->state
)) {
469 skb_set_owner_r(skb
, sk
);
470 skb_queue_tail(&sk
->receive_queue
, skb
);
471 sk
->data_ready(sk
, skb
->len
);
477 void netlink_broadcast(struct sock
*ssk
, struct sk_buff
*skb
, u32 pid
,
478 u32 group
, int allocation
)
481 struct sk_buff
*skb2
= NULL
;
482 int protocol
= ssk
->protocol
;
485 /* While we sleep in clone, do not allow to change socket list */
487 netlink_lock_table();
489 for (sk
= nl_table
[protocol
]; sk
; sk
= sk
->next
) {
493 if (sk
->protinfo
.af_netlink
->pid
== pid
||
494 !(sk
->protinfo
.af_netlink
->groups
&group
))
504 if (atomic_read(&skb
->users
) != 1) {
505 skb2
= skb_clone(skb
, allocation
);
508 atomic_inc(&skb
->users
);
513 /* Clone failed. Notify ALL listeners. */
515 } else if (netlink_broadcast_deliver(sk
, skb2
)) {
522 netlink_unlock_table();
529 void netlink_set_err(struct sock
*ssk
, u32 pid
, u32 group
, int code
)
532 int protocol
= ssk
->protocol
;
534 read_lock(&nl_table_lock
);
535 for (sk
= nl_table
[protocol
]; sk
; sk
= sk
->next
) {
539 if (sk
->protinfo
.af_netlink
->pid
== pid
||
540 !(sk
->protinfo
.af_netlink
->groups
&group
))
544 sk
->error_report(sk
);
546 read_unlock(&nl_table_lock
);
549 static int netlink_sendmsg(struct socket
*sock
, struct msghdr
*msg
, int len
,
550 struct scm_cookie
*scm
)
552 struct sock
*sk
= sock
->sk
;
553 struct sockaddr_nl
*addr
=msg
->msg_name
;
559 if (msg
->msg_flags
&MSG_OOB
)
562 if (msg
->msg_namelen
) {
563 if (addr
->nl_family
!= AF_NETLINK
)
565 dst_pid
= addr
->nl_pid
;
566 dst_groups
= addr
->nl_groups
;
567 if (dst_groups
&& !capable(CAP_NET_ADMIN
))
570 dst_pid
= sk
->protinfo
.af_netlink
->dst_pid
;
571 dst_groups
= sk
->protinfo
.af_netlink
->dst_groups
;
574 if (!sk
->protinfo
.af_netlink
->pid
) {
575 err
= netlink_autobind(sock
);
581 if ((unsigned)len
> sk
->sndbuf
-32)
584 skb
= alloc_skb(len
, GFP_KERNEL
);
588 NETLINK_CB(skb
).pid
= sk
->protinfo
.af_netlink
->pid
;
589 NETLINK_CB(skb
).groups
= sk
->protinfo
.af_netlink
->groups
;
590 NETLINK_CB(skb
).dst_pid
= dst_pid
;
591 NETLINK_CB(skb
).dst_groups
= dst_groups
;
592 memcpy(NETLINK_CREDS(skb
), &scm
->creds
, sizeof(struct ucred
));
594 /* What can I do? Netlink is asynchronous, so that
595 we will have to save current capabilities to
596 check them, when this message will be delivered
597 to corresponding kernel module. --ANK (980802)
599 NETLINK_CB(skb
).eff_cap
= current
->cap_effective
;
602 if (memcpy_fromiovec(skb_put(skb
,len
), msg
->msg_iov
, len
)) {
608 atomic_inc(&skb
->users
);
609 netlink_broadcast(sk
, skb
, dst_pid
, dst_groups
, GFP_KERNEL
);
611 err
= netlink_unicast(sk
, skb
, dst_pid
, msg
->msg_flags
&MSG_DONTWAIT
);
617 static int netlink_recvmsg(struct socket
*sock
, struct msghdr
*msg
, int len
,
618 int flags
, struct scm_cookie
*scm
)
620 struct sock
*sk
= sock
->sk
;
621 int noblock
= flags
&MSG_DONTWAIT
;
631 skb
= skb_recv_datagram(sk
,flags
,noblock
,&err
);
635 msg
->msg_namelen
= 0;
639 msg
->msg_flags
|= MSG_TRUNC
;
643 skb
->h
.raw
= skb
->data
;
644 err
= skb_copy_datagram_iovec(skb
, 0, msg
->msg_iov
, copied
);
647 struct sockaddr_nl
*addr
= (struct sockaddr_nl
*)msg
->msg_name
;
648 addr
->nl_family
= AF_NETLINK
;
649 addr
->nl_pid
= NETLINK_CB(skb
).pid
;
650 addr
->nl_groups
= NETLINK_CB(skb
).dst_groups
;
651 msg
->msg_namelen
= sizeof(*addr
);
654 scm
->creds
= *NETLINK_CREDS(skb
);
655 skb_free_datagram(sk
, skb
);
657 if (sk
->protinfo
.af_netlink
->cb
658 && atomic_read(&sk
->rmem_alloc
) <= sk
->rcvbuf
/2)
662 if (skb_queue_len(&sk
->receive_queue
) <= sk
->rcvbuf
/2) {
663 if (skb_queue_len(&sk
->receive_queue
) == 0)
664 clear_bit(0, &sk
->protinfo
.af_netlink
->state
);
665 if (!test_bit(0, &sk
->protinfo
.af_netlink
->state
))
666 wake_up_interruptible(&sk
->protinfo
.af_netlink
->wait
);
668 return err
? : copied
;
671 void netlink_data_ready(struct sock
*sk
, int len
)
673 if (sk
->protinfo
.af_netlink
->data_ready
)
674 sk
->protinfo
.af_netlink
->data_ready(sk
, len
);
676 if (skb_queue_len(&sk
->receive_queue
) <= sk
->rcvbuf
/2) {
677 if (skb_queue_len(&sk
->receive_queue
) == 0)
678 clear_bit(0, &sk
->protinfo
.af_netlink
->state
);
679 if (!test_bit(0, &sk
->protinfo
.af_netlink
->state
))
680 wake_up_interruptible(&sk
->protinfo
.af_netlink
->wait
);
685 * We export these functions to other modules. They provide a
686 * complete set of kernel non-blocking support for message
691 netlink_kernel_create(int unit
, void (*input
)(struct sock
*sk
, int len
))
696 if (unit
<0 || unit
>=MAX_LINKS
)
699 if (!(sock
= sock_alloc()))
702 sock
->type
= SOCK_RAW
;
704 if (netlink_create(sock
, unit
) < 0) {
709 sk
->data_ready
= netlink_data_ready
;
711 sk
->protinfo
.af_netlink
->data_ready
= input
;
713 netlink_insert(sk
, 0);
717 static void netlink_destroy_callback(struct netlink_callback
*cb
)
725 * It looks a bit ugly.
726 * It would be better to create kernel thread.
729 static int netlink_dump(struct sock
*sk
)
731 struct netlink_callback
*cb
;
733 struct nlmsghdr
*nlh
;
736 skb
= sock_rmalloc(sk
, NLMSG_GOODSIZE
, 0, GFP_KERNEL
);
740 spin_lock(&sk
->protinfo
.af_netlink
->cb_lock
);
742 cb
= sk
->protinfo
.af_netlink
->cb
;
744 spin_unlock(&sk
->protinfo
.af_netlink
->cb_lock
);
749 len
= cb
->dump(skb
, cb
);
752 spin_unlock(&sk
->protinfo
.af_netlink
->cb_lock
);
753 skb_queue_tail(&sk
->receive_queue
, skb
);
754 sk
->data_ready(sk
, len
);
758 nlh
= __nlmsg_put(skb
, NETLINK_CB(cb
->skb
).pid
, cb
->nlh
->nlmsg_seq
, NLMSG_DONE
, sizeof(int));
759 nlh
->nlmsg_flags
|= NLM_F_MULTI
;
760 memcpy(NLMSG_DATA(nlh
), &len
, sizeof(len
));
761 skb_queue_tail(&sk
->receive_queue
, skb
);
762 sk
->data_ready(sk
, skb
->len
);
765 sk
->protinfo
.af_netlink
->cb
= NULL
;
766 spin_unlock(&sk
->protinfo
.af_netlink
->cb_lock
);
768 netlink_destroy_callback(cb
);
773 int netlink_dump_start(struct sock
*ssk
, struct sk_buff
*skb
,
774 struct nlmsghdr
*nlh
,
775 int (*dump
)(struct sk_buff
*skb
, struct netlink_callback
*),
776 int (*done
)(struct netlink_callback
*))
778 struct netlink_callback
*cb
;
781 cb
= kmalloc(sizeof(*cb
), GFP_KERNEL
);
785 memset(cb
, 0, sizeof(*cb
));
789 atomic_inc(&skb
->users
);
792 sk
= netlink_lookup(ssk
->protocol
, NETLINK_CB(skb
).pid
);
794 netlink_destroy_callback(cb
);
795 return -ECONNREFUSED
;
797 /* A dump is in progress... */
798 spin_lock(&sk
->protinfo
.af_netlink
->cb_lock
);
799 if (sk
->protinfo
.af_netlink
->cb
) {
800 spin_unlock(&sk
->protinfo
.af_netlink
->cb_lock
);
801 netlink_destroy_callback(cb
);
805 sk
->protinfo
.af_netlink
->cb
= cb
;
806 spin_unlock(&sk
->protinfo
.af_netlink
->cb_lock
);
812 void netlink_ack(struct sk_buff
*in_skb
, struct nlmsghdr
*nlh
, int err
)
815 struct nlmsghdr
*rep
;
816 struct nlmsgerr
*errmsg
;
820 size
= NLMSG_SPACE(sizeof(struct nlmsgerr
));
822 size
= NLMSG_SPACE(4 + NLMSG_ALIGN(nlh
->nlmsg_len
));
824 skb
= alloc_skb(size
, GFP_KERNEL
);
828 rep
= __nlmsg_put(skb
, NETLINK_CB(in_skb
).pid
, nlh
->nlmsg_seq
,
829 NLMSG_ERROR
, sizeof(struct nlmsgerr
));
830 errmsg
= NLMSG_DATA(rep
);
832 memcpy(&errmsg
->msg
, nlh
, err
? nlh
->nlmsg_len
: sizeof(struct nlmsghdr
));
833 netlink_unicast(in_skb
->sk
, skb
, NETLINK_CB(in_skb
).pid
, MSG_DONTWAIT
);
837 #ifdef NL_EMULATE_DEV
839 static rwlock_t nl_emu_lock
= RW_LOCK_UNLOCKED
;
842 * Backward compatibility.
845 int netlink_attach(int unit
, int (*function
)(int, struct sk_buff
*skb
))
847 struct sock
*sk
= netlink_kernel_create(unit
, NULL
);
850 sk
->protinfo
.af_netlink
->handler
= function
;
851 write_lock_bh(&nl_emu_lock
);
852 netlink_kernel
[unit
] = sk
->socket
;
853 write_unlock_bh(&nl_emu_lock
);
857 void netlink_detach(int unit
)
861 write_lock_bh(&nl_emu_lock
);
862 sock
= netlink_kernel
[unit
];
863 netlink_kernel
[unit
] = NULL
;
864 write_unlock_bh(&nl_emu_lock
);
869 int netlink_post(int unit
, struct sk_buff
*skb
)
873 read_lock(&nl_emu_lock
);
874 sock
= netlink_kernel
[unit
];
876 struct sock
*sk
= sock
->sk
;
877 memset(skb
->cb
, 0, sizeof(skb
->cb
));
879 read_unlock(&nl_emu_lock
);
881 netlink_broadcast(sk
, skb
, 0, ~0, GFP_ATOMIC
);
886 read_unlock(&nl_emu_lock
);
893 #ifdef CONFIG_PROC_FS
894 static int netlink_read_proc(char *buffer
, char **start
, off_t offset
,
895 int length
, int *eof
, void *data
)
903 len
+= sprintf(buffer
,"sk Eth Pid Groups "
904 "Rmem Wmem Dump Locks\n");
906 for (i
=0; i
<MAX_LINKS
; i
++) {
907 read_lock(&nl_table_lock
);
908 for (s
= nl_table
[i
]; s
; s
= s
->next
) {
909 len
+=sprintf(buffer
+len
,"%p %-3d %-6d %08x %-8d %-8d %p %d",
912 s
->protinfo
.af_netlink
->pid
,
913 s
->protinfo
.af_netlink
->groups
,
914 atomic_read(&s
->rmem_alloc
),
915 atomic_read(&s
->wmem_alloc
),
916 s
->protinfo
.af_netlink
->cb
,
917 atomic_read(&s
->refcnt
)
927 if(pos
>offset
+length
) {
928 read_unlock(&nl_table_lock
);
932 read_unlock(&nl_table_lock
);
937 *start
=buffer
+(offset
-begin
);
947 struct proto_ops netlink_ops
= {
950 release
: netlink_release
,
952 connect
: netlink_connect
,
953 socketpair
: sock_no_socketpair
,
954 accept
: sock_no_accept
,
955 getname
: netlink_getname
,
957 ioctl
: sock_no_ioctl
,
958 listen
: sock_no_listen
,
959 shutdown
: sock_no_shutdown
,
960 setsockopt
: sock_no_setsockopt
,
961 getsockopt
: sock_no_getsockopt
,
962 sendmsg
: netlink_sendmsg
,
963 recvmsg
: netlink_recvmsg
,
967 struct net_proto_family netlink_family_ops
= {
972 static int __init
netlink_proto_init(void)
974 struct sk_buff
*dummy_skb
;
976 if (sizeof(struct netlink_skb_parms
) > sizeof(dummy_skb
->cb
)) {
977 printk(KERN_CRIT
"netlink_init: panic\n");
980 sock_register(&netlink_family_ops
);
981 #ifdef CONFIG_PROC_FS
982 create_proc_read_entry("net/netlink", 0, 0, netlink_read_proc
, NULL
);
987 module_init(netlink_proto_init
);