Linux 2.3.1pre3
[davej-history.git] / net / netlink / af_netlink.c
blob042b4773a67f756806e52e800cb728eeb60105fb
1 /*
2 * NETLINK Kernel-user communication protocol.
4 * Authors: Alan Cox <alan@cymru.net>
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/major.h>
19 #include <linux/signal.h>
20 #include <linux/sched.h>
21 #include <linux/errno.h>
22 #include <linux/string.h>
23 #include <linux/stat.h>
24 #include <linux/socket.h>
25 #include <linux/un.h>
26 #include <linux/fcntl.h>
27 #include <linux/termios.h>
28 #include <linux/sockios.h>
29 #include <linux/net.h>
30 #include <linux/fs.h>
31 #include <linux/malloc.h>
32 #include <asm/uaccess.h>
33 #include <linux/skbuff.h>
34 #include <linux/netdevice.h>
35 #include <linux/netlink.h>
36 #include <linux/proc_fs.h>
37 #include <net/sock.h>
38 #include <net/scm.h>
40 #define Nprintk(a...)
42 #if defined(CONFIG_NETLINK_DEV) || defined(CONFIG_NETLINK_DEV_MODULE)
43 #define NL_EMULATE_DEV
44 #endif
46 static struct sock *nl_table[MAX_LINKS];
47 static atomic_t nl_table_lock[MAX_LINKS];
48 static struct wait_queue *nl_table_wait;
50 #ifdef NL_EMULATE_DEV
51 static struct socket *netlink_kernel[MAX_LINKS];
52 #endif
54 static int netlink_dump(struct sock *sk);
55 static void netlink_destroy_callback(struct netlink_callback *cb);
57 /* Netlink table lock. It protects against sk list changes
58 during uninterruptible sleeps in netlink_broadcast.
60 These lock MUST NOT be used from bh/irq on SMP kernels, because
61 It would result in race in netlink_wait_on_table.
64 extern __inline__ void
65 netlink_wait_on_table(int protocol)
67 while (atomic_read(&nl_table_lock[protocol]))
68 sleep_on(&nl_table_wait);
71 extern __inline__ void
72 netlink_lock_table(int protocol)
74 atomic_inc(&nl_table_lock[protocol]);
77 extern __inline__ void
78 netlink_unlock_table(int protocol)
80 #if 0
81 /* F...g gcc does not eat it! */
83 if (atomic_dec_and_test(&nl_table_lock[protocol]))
84 wake_up(&nl_table_wait);
85 #else
86 atomic_dec(&nl_table_lock[protocol]);
87 if (!atomic_read(&nl_table_lock[protocol]))
88 wake_up(&nl_table_wait);
89 #endif
92 static __inline__ void netlink_lock(struct sock *sk)
94 atomic_inc(&sk->protinfo.af_netlink.locks);
97 static __inline__ void netlink_unlock(struct sock *sk)
99 atomic_dec(&sk->protinfo.af_netlink.locks);
102 static __inline__ int netlink_locked(struct sock *sk)
104 return atomic_read(&sk->protinfo.af_netlink.locks);
107 static __inline__ struct sock *netlink_lookup(int protocol, u32 pid)
109 struct sock *sk;
111 for (sk=nl_table[protocol]; sk; sk=sk->next) {
112 if (sk->protinfo.af_netlink.pid == pid) {
113 netlink_lock(sk);
114 return sk;
118 return NULL;
121 extern struct proto_ops netlink_ops;
123 static void netlink_insert(struct sock *sk)
125 sk->next = nl_table[sk->protocol];
126 nl_table[sk->protocol] = sk;
129 static void netlink_remove(struct sock *sk)
131 struct sock **skp;
132 for (skp = &nl_table[sk->protocol]; *skp; skp = &((*skp)->next)) {
133 if (*skp == sk) {
134 start_bh_atomic();
135 *skp = sk->next;
136 end_bh_atomic();
137 return;
142 static int netlink_create(struct socket *sock, int protocol)
144 struct sock *sk;
146 sock->state = SS_UNCONNECTED;
148 if (sock->type != SOCK_RAW && sock->type != SOCK_DGRAM)
149 return -ESOCKTNOSUPPORT;
151 if (protocol<0 || protocol >= MAX_LINKS)
152 return -EPROTONOSUPPORT;
154 sock->ops = &netlink_ops;
156 sk = sk_alloc(PF_NETLINK, GFP_KERNEL, 1);
157 if (!sk)
158 return -ENOMEM;
160 sock_init_data(sock,sk);
161 sk->destruct = NULL;
163 sk->protocol=protocol;
164 return 0;
167 static int netlink_release(struct socket *sock, struct socket *peer)
169 struct sock *sk = sock->sk;
171 if (!sk)
172 return 0;
174 /* Wait on table before removing socket */
175 netlink_wait_on_table(sk->protocol);
176 netlink_remove(sk);
178 if (sk->protinfo.af_netlink.cb) {
179 netlink_unlock(sk);
180 sk->protinfo.af_netlink.cb->done(sk->protinfo.af_netlink.cb);
181 netlink_destroy_callback(sk->protinfo.af_netlink.cb);
182 sk->protinfo.af_netlink.cb = NULL;
185 /* OK. Socket is unlinked, and, therefore,
186 no new packets will arrive */
187 sk->state_change(sk);
188 sk->dead = 1;
190 skb_queue_purge(&sk->receive_queue);
191 skb_queue_purge(&sk->write_queue);
193 /* IMPORTANT! It is the major unpleasant feature of this
194 transport (and AF_UNIX datagram, when it will be repaired).
196 Someone could wait on our sock->wait now.
197 We cannot release socket until waiter will remove itself
198 from wait queue. I choose the most conservetive way of solving
199 the problem.
201 We waked up this queue above, so that we need only to wait
202 when the readers release us.
205 while (netlink_locked(sk)) {
206 current->counter = 0;
207 schedule();
210 if (sk->socket) {
211 sk->socket = NULL;
212 sock->sk = NULL;
215 if (atomic_read(&sk->rmem_alloc) || atomic_read(&sk->wmem_alloc)) {
216 printk(KERN_DEBUG "netlink_release: impossible event. Please, report.\n");
217 return 0;
220 sk_free(sk);
221 return 0;
224 static int netlink_autobind(struct socket *sock)
226 struct sock *sk = sock->sk;
227 struct sock *osk;
229 sk->protinfo.af_netlink.groups = 0;
230 sk->protinfo.af_netlink.pid = current->pid;
232 retry:
233 for (osk=nl_table[sk->protocol]; osk; osk=osk->next) {
234 if (osk->protinfo.af_netlink.pid == sk->protinfo.af_netlink.pid) {
235 /* Bind collision, search negative pid values. */
236 if (sk->protinfo.af_netlink.pid > 0)
237 sk->protinfo.af_netlink.pid = -4096;
238 sk->protinfo.af_netlink.pid--;
239 goto retry;
243 netlink_insert(sk);
244 return 0;
247 static int netlink_bind(struct socket *sock, struct sockaddr *addr, int addr_len)
249 struct sock *sk = sock->sk;
250 struct sock *osk;
251 struct sockaddr_nl *nladdr=(struct sockaddr_nl *)addr;
253 if (nladdr->nl_family != AF_NETLINK)
254 return -EINVAL;
256 /* Only superuser is allowed to listen multicasts */
257 if (nladdr->nl_groups && !capable(CAP_NET_ADMIN))
258 return -EPERM;
260 if (sk->protinfo.af_netlink.pid) {
261 if (nladdr->nl_pid != sk->protinfo.af_netlink.pid)
262 return -EINVAL;
263 sk->protinfo.af_netlink.groups = nladdr->nl_groups;
264 return 0;
267 if (nladdr->nl_pid == 0) {
268 netlink_autobind(sock);
269 sk->protinfo.af_netlink.groups = nladdr->nl_groups;
270 return 0;
273 for (osk=nl_table[sk->protocol]; osk; osk=osk->next) {
274 if (osk->protinfo.af_netlink.pid == nladdr->nl_pid)
275 return -EADDRINUSE;
278 sk->protinfo.af_netlink.pid = nladdr->nl_pid;
279 sk->protinfo.af_netlink.groups = nladdr->nl_groups;
280 netlink_insert(sk);
281 return 0;
284 static int netlink_connect(struct socket *sock, struct sockaddr *addr,
285 int alen, int flags)
287 struct sock *sk = sock->sk;
288 struct sockaddr_nl *nladdr=(struct sockaddr_nl*)addr;
290 if (addr->sa_family == AF_UNSPEC)
292 sk->protinfo.af_netlink.dst_pid = 0;
293 sk->protinfo.af_netlink.dst_groups = 0;
294 return 0;
296 if (addr->sa_family != AF_NETLINK)
297 return -EINVAL;
299 /* Only superuser is allowed to send multicasts */
300 if (nladdr->nl_groups && !capable(CAP_NET_ADMIN))
301 return -EPERM;
303 sk->protinfo.af_netlink.dst_pid = nladdr->nl_pid;
304 sk->protinfo.af_netlink.dst_groups = nladdr->nl_groups;
306 if (!sk->protinfo.af_netlink.pid)
307 netlink_autobind(sock);
308 return 0;
311 static int netlink_getname(struct socket *sock, struct sockaddr *addr, int *addr_len, int peer)
313 struct sock *sk = sock->sk;
314 struct sockaddr_nl *nladdr=(struct sockaddr_nl *)addr;
316 nladdr->nl_family = AF_NETLINK;
317 *addr_len = sizeof(*nladdr);
319 if (peer) {
320 nladdr->nl_pid = sk->protinfo.af_netlink.dst_pid;
321 nladdr->nl_groups = sk->protinfo.af_netlink.dst_groups;
322 } else {
323 nladdr->nl_pid = sk->protinfo.af_netlink.pid;
324 nladdr->nl_groups = sk->protinfo.af_netlink.groups;
326 return 0;
329 int netlink_unicast(struct sock *ssk, struct sk_buff *skb, u32 pid, int nonblock)
331 struct sock *sk;
332 int len = skb->len;
333 int protocol = ssk->protocol;
334 DECLARE_WAITQUEUE(wait, current);
336 retry:
337 for (sk = nl_table[protocol]; sk; sk = sk->next) {
338 if (sk->protinfo.af_netlink.pid != pid)
339 continue;
341 netlink_lock(sk);
343 #ifdef NL_EMULATE_DEV
344 if (sk->protinfo.af_netlink.handler) {
345 skb_orphan(skb);
346 len = sk->protinfo.af_netlink.handler(protocol, skb);
347 netlink_unlock(sk);
348 return len;
350 #endif
352 if (!nonblock) {
353 add_wait_queue(sk->sleep, &wait);
354 current->state = TASK_INTERRUPTIBLE;
357 if (atomic_read(&sk->rmem_alloc) > sk->rcvbuf) {
358 if (nonblock) {
359 netlink_unlock(sk);
360 kfree_skb(skb);
361 return -EAGAIN;
364 schedule();
366 current->state = TASK_RUNNING;
367 remove_wait_queue(sk->sleep, &wait);
368 netlink_unlock(sk);
370 if (signal_pending(current)) {
371 kfree_skb(skb);
372 return -ERESTARTSYS;
374 goto retry;
377 if (!nonblock) {
378 current->state = TASK_RUNNING;
379 remove_wait_queue(sk->sleep, &wait);
382 skb_orphan(skb);
383 skb_set_owner_r(skb, sk);
384 skb_queue_tail(&sk->receive_queue, skb);
385 sk->data_ready(sk, len);
386 netlink_unlock(sk);
387 return len;
389 kfree_skb(skb);
390 return -ECONNREFUSED;
393 static __inline__ int netlink_broadcast_deliver(struct sock *sk, struct sk_buff *skb)
395 #ifdef NL_EMULATE_DEV
396 if (sk->protinfo.af_netlink.handler) {
397 skb_orphan(skb);
398 sk->protinfo.af_netlink.handler(sk->protocol, skb);
399 return 0;
400 } else
401 #endif
402 if (atomic_read(&sk->rmem_alloc) <= sk->rcvbuf) {
403 Nprintk("broadcast_deliver %d\n", skb->len);
404 skb_orphan(skb);
405 skb_set_owner_r(skb, sk);
406 skb_queue_tail(&sk->receive_queue, skb);
407 sk->data_ready(sk, skb->len);
408 return 0;
410 return -1;
413 void netlink_broadcast(struct sock *ssk, struct sk_buff *skb, u32 pid,
414 u32 group, int allocation)
416 struct sock *sk;
417 struct sk_buff *skb2 = NULL;
418 int protocol = ssk->protocol;
419 int failure = 0;
421 /* While we sleep in clone, do not allow to change socket list */
423 if (allocation == GFP_KERNEL)
424 netlink_lock_table(protocol);
426 for (sk = nl_table[protocol]; sk; sk = sk->next) {
427 if (ssk == sk)
428 continue;
430 if (sk->protinfo.af_netlink.pid == pid ||
431 !(sk->protinfo.af_netlink.groups&group))
432 continue;
434 if (failure) {
435 sk->err = ENOBUFS;
436 sk->state_change(sk);
437 continue;
440 netlink_lock(sk);
441 if (skb2 == NULL) {
442 if (atomic_read(&skb->users) != 1) {
443 skb2 = skb_clone(skb, allocation);
444 } else {
445 skb2 = skb;
446 atomic_inc(&skb->users);
449 if (skb2 == NULL) {
450 sk->err = ENOBUFS;
451 sk->state_change(sk);
452 /* Clone failed. Notify ALL listeners. */
453 failure = 1;
454 } else if (netlink_broadcast_deliver(sk, skb2)) {
455 sk->err = ENOBUFS;
456 sk->state_change(sk);
457 } else
458 skb2 = NULL;
459 netlink_unlock(sk);
462 if (allocation == GFP_KERNEL)
463 netlink_unlock_table(protocol);
465 if (skb2)
466 kfree_skb(skb2);
467 kfree_skb(skb);
470 void netlink_set_err(struct sock *ssk, u32 pid, u32 group, int code)
472 struct sock *sk;
473 int protocol = ssk->protocol;
475 Nprintk("seterr");
476 for (sk = nl_table[protocol]; sk; sk = sk->next) {
477 if (ssk == sk)
478 continue;
480 if (sk->protinfo.af_netlink.pid == pid ||
481 !(sk->protinfo.af_netlink.groups&group))
482 continue;
484 sk->err = code;
485 sk->state_change(sk);
489 static int netlink_sendmsg(struct socket *sock, struct msghdr *msg, int len,
490 struct scm_cookie *scm)
492 struct sock *sk = sock->sk;
493 struct sockaddr_nl *addr=msg->msg_name;
494 u32 dst_pid;
495 u32 dst_groups;
496 struct sk_buff *skb;
498 if (msg->msg_flags&MSG_OOB)
499 return -EOPNOTSUPP;
501 if (msg->msg_flags&~(MSG_DONTWAIT|MSG_NOSIGNAL|MSG_ERRQUEUE))
502 return -EINVAL;
504 if (msg->msg_namelen) {
505 if (addr->nl_family != AF_NETLINK)
506 return -EINVAL;
507 dst_pid = addr->nl_pid;
508 dst_groups = addr->nl_groups;
509 if (dst_groups && !capable(CAP_NET_ADMIN))
510 return -EPERM;
511 } else {
512 dst_pid = sk->protinfo.af_netlink.dst_pid;
513 dst_groups = sk->protinfo.af_netlink.dst_groups;
516 if (!sk->protinfo.af_netlink.pid)
517 netlink_autobind(sock);
519 skb = sock_wmalloc(sk, len, 0, GFP_KERNEL);
520 if (skb==NULL)
521 return -ENOBUFS;
523 NETLINK_CB(skb).pid = sk->protinfo.af_netlink.pid;
524 NETLINK_CB(skb).groups = sk->protinfo.af_netlink.groups;
525 NETLINK_CB(skb).dst_pid = dst_pid;
526 NETLINK_CB(skb).dst_groups = dst_groups;
527 memcpy(NETLINK_CREDS(skb), &scm->creds, sizeof(struct ucred));
529 /* What can I do? Netlink is asynchronous, so that
530 we will have to save current capabilities to
531 check them, when this message will be delivered
532 to corresponding kernel module. --ANK (980802)
534 NETLINK_CB(skb).eff_cap = current->cap_effective;
536 if (memcpy_fromiovec(skb_put(skb,len), msg->msg_iov, len)) {
537 kfree_skb(skb);
538 return -EFAULT;
541 if (dst_groups) {
542 atomic_inc(&skb->users);
543 netlink_broadcast(sk, skb, dst_pid, dst_groups, GFP_KERNEL);
545 return netlink_unicast(sk, skb, dst_pid, msg->msg_flags&MSG_DONTWAIT);
548 static int netlink_recvmsg(struct socket *sock, struct msghdr *msg, int len,
549 int flags, struct scm_cookie *scm)
551 struct sock *sk = sock->sk;
552 int noblock = flags&MSG_DONTWAIT;
553 int copied;
554 struct sk_buff *skb;
555 int err;
557 if (flags&(MSG_OOB|MSG_PEEK))
558 return -EOPNOTSUPP;
560 skb = skb_recv_datagram(sk,flags,noblock,&err);
561 if (skb==NULL)
562 return err;
564 msg->msg_namelen = 0;
566 copied = skb->len;
567 if (len < copied) {
568 msg->msg_flags |= MSG_TRUNC;
569 copied = len;
572 skb->h.raw = skb->data;
573 err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
575 if (msg->msg_name) {
576 struct sockaddr_nl *addr = (struct sockaddr_nl*)msg->msg_name;
577 addr->nl_family = AF_NETLINK;
578 addr->nl_pid = NETLINK_CB(skb).pid;
579 addr->nl_groups = NETLINK_CB(skb).dst_groups;
580 msg->msg_namelen = sizeof(*addr);
583 scm->creds = *NETLINK_CREDS(skb);
584 skb_free_datagram(sk, skb);
586 if (sk->protinfo.af_netlink.cb
587 && atomic_read(&sk->rmem_alloc) <= sk->rcvbuf/2)
588 netlink_dump(sk);
589 return err ? : copied;
593 * We export these functions to other modules. They provide a
594 * complete set of kernel non-blocking support for message
595 * queueing.
598 struct sock *
599 netlink_kernel_create(int unit, void (*input)(struct sock *sk, int len))
601 struct socket *sock;
602 struct sock *sk;
604 if (unit<0 || unit>=MAX_LINKS)
605 return NULL;
607 if (!(sock = sock_alloc()))
608 return NULL;
610 sock->type = SOCK_RAW;
612 if (netlink_create(sock, unit) < 0) {
613 sock_release(sock);
614 return NULL;
616 sk = sock->sk;
617 if (input)
618 sk->data_ready = input;
620 netlink_insert(sk);
621 return sk;
624 static void netlink_destroy_callback(struct netlink_callback *cb)
626 if (cb->skb)
627 kfree_skb(cb->skb);
628 kfree(cb);
632 * It looks a bit ugly.
633 * It would be better to create kernel thread.
636 static int netlink_dump(struct sock *sk)
638 struct netlink_callback *cb;
639 struct sk_buff *skb;
640 struct nlmsghdr *nlh;
641 int len;
643 skb = sock_rmalloc(sk, NLMSG_GOODSIZE, 0, GFP_KERNEL);
644 if (!skb)
645 return -ENOBUFS;
647 cb = sk->protinfo.af_netlink.cb;
649 len = cb->dump(skb, cb);
651 if (len > 0) {
652 skb_queue_tail(&sk->receive_queue, skb);
653 sk->data_ready(sk, len);
654 return 0;
657 nlh = __nlmsg_put(skb, NETLINK_CB(cb->skb).pid, cb->nlh->nlmsg_seq, NLMSG_DONE, sizeof(int));
658 nlh->nlmsg_flags |= NLM_F_MULTI;
659 memcpy(NLMSG_DATA(nlh), &len, sizeof(len));
660 skb_queue_tail(&sk->receive_queue, skb);
661 sk->data_ready(sk, skb->len);
663 cb->done(cb);
664 sk->protinfo.af_netlink.cb = NULL;
665 netlink_destroy_callback(cb);
666 netlink_unlock(sk);
667 return 0;
670 int netlink_dump_start(struct sock *ssk, struct sk_buff *skb,
671 struct nlmsghdr *nlh,
672 int (*dump)(struct sk_buff *skb, struct netlink_callback*),
673 int (*done)(struct netlink_callback*))
675 struct netlink_callback *cb;
676 struct sock *sk;
678 cb = kmalloc(sizeof(*cb), GFP_KERNEL);
679 if (cb == NULL)
680 return -ENOBUFS;
682 memset(cb, 0, sizeof(*cb));
683 cb->dump = dump;
684 cb->done = done;
685 cb->nlh = nlh;
686 atomic_inc(&skb->users);
687 cb->skb = skb;
689 sk = netlink_lookup(ssk->protocol, NETLINK_CB(skb).pid);
690 if (sk == NULL) {
691 netlink_destroy_callback(cb);
692 return -ECONNREFUSED;
694 /* A dump is in progress... */
695 if (sk->protinfo.af_netlink.cb) {
696 netlink_destroy_callback(cb);
697 netlink_unlock(sk);
698 return -EBUSY;
700 sk->protinfo.af_netlink.cb = cb;
701 netlink_dump(sk);
702 return 0;
705 void netlink_ack(struct sk_buff *in_skb, struct nlmsghdr *nlh, int err)
707 struct sk_buff *skb;
708 struct nlmsghdr *rep;
709 struct nlmsgerr *errmsg;
710 int size;
712 if (err == 0)
713 size = NLMSG_SPACE(sizeof(struct nlmsgerr));
714 else
715 size = NLMSG_SPACE(4 + NLMSG_ALIGN(nlh->nlmsg_len));
717 skb = alloc_skb(size, GFP_KERNEL);
718 if (!skb)
719 return;
721 rep = __nlmsg_put(skb, NETLINK_CB(in_skb).pid, nlh->nlmsg_seq,
722 NLMSG_ERROR, sizeof(struct nlmsgerr));
723 errmsg = NLMSG_DATA(rep);
724 errmsg->error = err;
725 memcpy(&errmsg->msg, nlh, err ? nlh->nlmsg_len : sizeof(struct nlmsghdr));
726 netlink_unicast(in_skb->sk, skb, NETLINK_CB(in_skb).pid, MSG_DONTWAIT);
730 #ifdef NL_EMULATE_DEV
732 * Backward compatibility.
735 int netlink_attach(int unit, int (*function)(int, struct sk_buff *skb))
737 struct sock *sk = netlink_kernel_create(unit, NULL);
738 if (sk == NULL)
739 return -ENOBUFS;
740 sk->protinfo.af_netlink.handler = function;
741 netlink_kernel[unit] = sk->socket;
742 return 0;
745 void netlink_detach(int unit)
747 struct socket *sock = netlink_kernel[unit];
749 netlink_kernel[unit] = NULL;
750 synchronize_bh();
752 sock_release(sock);
755 int netlink_post(int unit, struct sk_buff *skb)
757 struct socket *sock = netlink_kernel[unit];
758 barrier();
759 if (sock) {
760 memset(skb->cb, 0, sizeof(skb->cb));
761 netlink_broadcast(sock->sk, skb, 0, ~0, GFP_ATOMIC);
762 return 0;
764 return -EUNATCH;;
767 #endif
770 #ifdef CONFIG_PROC_FS
771 static int netlink_read_proc(char *buffer, char **start, off_t offset,
772 int length, int *eof, void *data)
774 off_t pos=0;
775 off_t begin=0;
776 int len=0;
777 int i;
778 struct sock *s;
780 len+= sprintf(buffer,"sk Eth Pid Groups "
781 "Rmem Wmem Dump Locks\n");
783 for (i=0; i<MAX_LINKS; i++) {
784 for (s = nl_table[i]; s; s = s->next) {
785 len+=sprintf(buffer+len,"%p %-3d %-6d %08x %-8d %-8d %p %d",
787 s->protocol,
788 s->protinfo.af_netlink.pid,
789 s->protinfo.af_netlink.groups,
790 atomic_read(&s->rmem_alloc),
791 atomic_read(&s->wmem_alloc),
792 s->protinfo.af_netlink.cb,
793 atomic_read(&s->protinfo.af_netlink.locks)
796 buffer[len++]='\n';
798 pos=begin+len;
799 if(pos<offset) {
800 len=0;
801 begin=pos;
803 if(pos>offset+length)
804 goto done;
807 *eof = 1;
809 done:
810 *start=buffer+(offset-begin);
811 len-=(offset-begin);
812 if(len>length)
813 len=length;
814 if(len<0)
815 len=0;
816 return len;
818 #endif
820 struct proto_ops netlink_ops = {
821 PF_NETLINK,
823 sock_no_dup,
824 netlink_release,
825 netlink_bind,
826 netlink_connect,
827 sock_no_socketpair,
828 sock_no_accept,
829 netlink_getname,
830 datagram_poll,
831 sock_no_ioctl,
832 sock_no_listen,
833 sock_no_shutdown,
834 sock_no_setsockopt,
835 sock_no_getsockopt,
836 sock_no_fcntl,
837 netlink_sendmsg,
838 netlink_recvmsg
841 struct net_proto_family netlink_family_ops = {
842 PF_NETLINK,
843 netlink_create
846 void netlink_proto_init(struct net_proto *pro)
848 #ifdef CONFIG_PROC_FS
849 struct proc_dir_entry *ent;
850 #endif
851 struct sk_buff *dummy_skb;
853 if (sizeof(struct netlink_skb_parms) > sizeof(dummy_skb->cb)) {
854 printk(KERN_CRIT "netlink_proto_init: panic\n");
855 return;
857 sock_register(&netlink_family_ops);
858 #ifdef CONFIG_PROC_FS
859 ent = create_proc_entry("net/netlink", 0, 0);
860 ent->read_proc = netlink_read_proc;
861 #endif