2 * scsi_netlink.c - SCSI Transport Netlink Interface
4 * Copyright (C) 2006 James Smart, Emulex Corporation
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <linux/time.h>
22 #include <linux/jiffies.h>
23 #include <linux/security.h>
24 #include <linux/delay.h>
25 #include <linux/slab.h>
26 #include <linux/export.h>
28 #include <net/netlink.h>
30 #include <scsi/scsi_netlink.h>
31 #include "scsi_priv.h"
33 struct sock
*scsi_nl_sock
= NULL
;
34 EXPORT_SYMBOL_GPL(scsi_nl_sock
);
37 * scsi_nl_rcv_msg - Receive message handler.
38 * @skb: socket receive buffer
40 * Description: Extracts message from a receive buffer.
41 * Validates message header and calls appropriate transport message handler
46 scsi_nl_rcv_msg(struct sk_buff
*skb
)
49 struct scsi_nl_hdr
*hdr
;
53 while (skb
->len
>= NLMSG_HDRLEN
) {
57 if ((nlh
->nlmsg_len
< (sizeof(*nlh
) + sizeof(*hdr
))) ||
58 (skb
->len
< nlh
->nlmsg_len
)) {
59 printk(KERN_WARNING
"%s: discarding partial skb\n",
64 rlen
= NLMSG_ALIGN(nlh
->nlmsg_len
);
68 if (nlh
->nlmsg_type
!= SCSI_TRANSPORT_MSG
) {
73 hdr
= nlmsg_data(nlh
);
74 if ((hdr
->version
!= SCSI_NL_VERSION
) ||
75 (hdr
->magic
!= SCSI_NL_MAGIC
)) {
80 if (!netlink_capable(skb
, CAP_SYS_ADMIN
)) {
85 if (nlh
->nlmsg_len
< (sizeof(*nlh
) + hdr
->msglen
)) {
86 printk(KERN_WARNING
"%s: discarding partial message\n",
92 * Deliver message to the appropriate transport
94 tport
= hdr
->transport
;
95 if (tport
== SCSI_NL_TRANSPORT
) {
96 switch (hdr
->msgtype
) {
97 case SCSI_NL_SHOST_VENDOR
:
98 /* Locate the driver that corresponds to the message */
106 printk(KERN_WARNING
"%s: Msgtype %d failed - err %d\n",
107 __func__
, hdr
->msgtype
, err
);
113 if ((err
) || (nlh
->nlmsg_flags
& NLM_F_ACK
))
114 netlink_ack(skb
, nlh
, err
);
121 * scsi_netlink_init - Called by SCSI subsystem to initialize
122 * the SCSI transport netlink interface
126 scsi_netlink_init(void)
128 struct netlink_kernel_cfg cfg
= {
129 .input
= scsi_nl_rcv_msg
,
130 .groups
= SCSI_NL_GRP_CNT
,
133 scsi_nl_sock
= netlink_kernel_create(&init_net
, NETLINK_SCSITRANSPORT
,
136 printk(KERN_ERR
"%s: register of receive handler failed\n",
146 * scsi_netlink_exit - Called by SCSI subsystem to disable the SCSI transport netlink interface
150 scsi_netlink_exit(void)
153 netlink_kernel_release(scsi_nl_sock
);