Blame view
drivers/scsi/scsi_netlink.c
3.52 KB
84314fd47
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
/* * scsi_netlink.c - SCSI Transport Netlink Interface * * Copyright (C) 2006 James Smart, Emulex Corporation * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include <linux/time.h> #include <linux/jiffies.h> #include <linux/security.h> |
22447be7d
|
24 |
#include <linux/delay.h> |
5a0e3ad6a
|
25 |
#include <linux/slab.h> |
09703660e
|
26 |
#include <linux/export.h> |
84314fd47
|
27 28 29 30 31 32 33 34 |
#include <net/sock.h> #include <net/netlink.h> #include <scsi/scsi_netlink.h> #include "scsi_priv.h" struct sock *scsi_nl_sock = NULL; EXPORT_SYMBOL_GPL(scsi_nl_sock); |
84314fd47
|
35 |
/** |
eb44820c2
|
36 37 38 39 |
* scsi_nl_rcv_msg - Receive message handler. * @skb: socket receive buffer * * Description: Extracts message from a receive buffer. |
84314fd47
|
40 41 |
* Validates message header and calls appropriate transport message handler * |
84314fd47
|
42 43 44 45 46 47 48 |
* **/ static void scsi_nl_rcv_msg(struct sk_buff *skb) { struct nlmsghdr *nlh; struct scsi_nl_hdr *hdr; |
22447be7d
|
49 50 |
u32 rlen; int err, tport; |
84314fd47
|
51 |
|
e07ebea0c
|
52 |
while (skb->len >= NLMSG_HDRLEN) { |
84314fd47
|
53 |
err = 0; |
b529ccf27
|
54 |
nlh = nlmsg_hdr(skb); |
84314fd47
|
55 56 57 58 |
if ((nlh->nlmsg_len < (sizeof(*nlh) + sizeof(*hdr))) || (skb->len < nlh->nlmsg_len)) { printk(KERN_WARNING "%s: discarding partial skb ", |
cadbd4a5e
|
59 |
__func__); |
84314fd47
|
60 61 62 63 64 65 66 67 68 |
return; } rlen = NLMSG_ALIGN(nlh->nlmsg_len); if (rlen > skb->len) rlen = skb->len; if (nlh->nlmsg_type != SCSI_TRANSPORT_MSG) { err = -EBADMSG; |
22447be7d
|
69 |
goto next_msg; |
84314fd47
|
70 |
} |
e07ebea0c
|
71 |
hdr = nlmsg_data(nlh); |
84314fd47
|
72 73 74 75 76 |
if ((hdr->version != SCSI_NL_VERSION) || (hdr->magic != SCSI_NL_MAGIC)) { err = -EPROTOTYPE; goto next_msg; } |
90f62cf30
|
77 |
if (!netlink_capable(skb, CAP_SYS_ADMIN)) { |
84314fd47
|
78 79 80 81 82 83 84 |
err = -EPERM; goto next_msg; } if (nlh->nlmsg_len < (sizeof(*nlh) + hdr->msglen)) { printk(KERN_WARNING "%s: discarding partial message ", |
cadbd4a5e
|
85 |
__func__); |
22447be7d
|
86 |
goto next_msg; |
84314fd47
|
87 88 89 |
} /* |
22447be7d
|
90 |
* Deliver message to the appropriate transport |
84314fd47
|
91 |
*/ |
22447be7d
|
92 |
tport = hdr->transport; |
8289bab1d
|
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
if (tport == SCSI_NL_TRANSPORT) { switch (hdr->msgtype) { case SCSI_NL_SHOST_VENDOR: /* Locate the driver that corresponds to the message */ err = -ESRCH; break; default: err = -EBADR; break; } if (err) printk(KERN_WARNING "%s: Msgtype %d failed - err %d ", __func__, hdr->msgtype, err); } else |
22447be7d
|
109 |
err = -ENOENT; |
84314fd47
|
110 111 112 113 114 115 116 |
next_msg: if ((err) || (nlh->nlmsg_flags & NLM_F_ACK)) netlink_ack(skb, nlh, err); skb_pull(skb, rlen); } } |
22447be7d
|
117 |
/** |
b595076a1
|
118 |
* scsi_netlink_init - Called by SCSI subsystem to initialize |
22447be7d
|
119 |
* the SCSI transport netlink interface |
84314fd47
|
120 121 122 123 124 |
* **/ void scsi_netlink_init(void) { |
a31f2d17b
|
125 126 127 128 |
struct netlink_kernel_cfg cfg = { .input = scsi_nl_rcv_msg, .groups = SCSI_NL_GRP_CNT, }; |
84314fd47
|
129 |
|
b4b510290
|
130 |
scsi_nl_sock = netlink_kernel_create(&init_net, NETLINK_SCSITRANSPORT, |
9f00d9776
|
131 |
&cfg); |
84314fd47
|
132 |
if (!scsi_nl_sock) { |
25985edce
|
133 134 |
printk(KERN_ERR "%s: register of receive handler failed ", |
cadbd4a5e
|
135 |
__func__); |
22447be7d
|
136 |
return; |
84314fd47
|
137 138 139 140 141 142 143 |
} return; } /** |
eb44820c2
|
144 |
* scsi_netlink_exit - Called by SCSI subsystem to disable the SCSI transport netlink interface |
84314fd47
|
145 146 147 148 149 150 |
* **/ void scsi_netlink_exit(void) { if (scsi_nl_sock) { |
b7c6ba6eb
|
151 |
netlink_kernel_release(scsi_nl_sock); |
84314fd47
|
152 153 154 155 |
} return; } |