Release 4.12 drivers/scsi/scsi_netlink.c
  
  
  
/*
 *  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>
#include <linux/delay.h>
#include <linux/slab.h>
#include <linux/export.h>
#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);
/**
 * scsi_nl_rcv_msg - Receive message handler.
 * @skb:                socket receive buffer
 *
 * Description: Extracts message from a receive buffer.
 *    Validates message header and calls appropriate transport message handler
 *
 *
 **/
static void
scsi_nl_rcv_msg(struct sk_buff *skb)
{
	struct nlmsghdr *nlh;
	struct scsi_nl_hdr *hdr;
	u32 rlen;
	int err, tport;
	while (skb->len >= NLMSG_HDRLEN) {
		err = 0;
		nlh = nlmsg_hdr(skb);
		if ((nlh->nlmsg_len < (sizeof(*nlh) + sizeof(*hdr))) ||
		    (skb->len < nlh->nlmsg_len)) {
			printk(KERN_WARNING "%s: discarding partial skb\n",
				 __func__);
			return;
		}
		rlen = NLMSG_ALIGN(nlh->nlmsg_len);
		if (rlen > skb->len)
			rlen = skb->len;
		if (nlh->nlmsg_type != SCSI_TRANSPORT_MSG) {
			err = -EBADMSG;
			goto next_msg;
		}
		hdr = nlmsg_data(nlh);
		if ((hdr->version != SCSI_NL_VERSION) ||
		    (hdr->magic != SCSI_NL_MAGIC)) {
			err = -EPROTOTYPE;
			goto next_msg;
		}
		if (!netlink_capable(skb, CAP_SYS_ADMIN)) {
			err = -EPERM;
			goto next_msg;
		}
		if (nlh->nlmsg_len < (sizeof(*nlh) + hdr->msglen)) {
			printk(KERN_WARNING "%s: discarding partial message\n",
				 __func__);
			goto next_msg;
		}
		/*
                 * Deliver message to the appropriate transport
                 */
		tport = hdr->transport;
		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\n",
				       __func__, hdr->msgtype, err);
		}
		else
			err = -ENOENT;
next_msg:
		if ((err) || (nlh->nlmsg_flags & NLM_F_ACK))
			netlink_ack(skb, nlh, err, NULL);
		skb_pull(skb, rlen);
	}
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| James Smart | 268 | 84.28% | 2 | 22.22% | 
| Eric W. Biedermann | 40 | 12.58% | 2 | 22.22% | 
| Arnaldo Carvalho de Melo | 3 | 0.94% | 1 | 11.11% | 
| Johannes Berg | 2 | 0.63% | 1 | 11.11% | 
| Harvey Harrison | 2 | 0.63% | 1 | 11.11% | 
| Hong Zhi Guo | 2 | 0.63% | 1 | 11.11% | 
| Eric Paris | 1 | 0.31% | 1 | 11.11% | 
| Total | 318 | 100.00% | 9 | 100.00% | 
/**
 * scsi_netlink_init - Called by SCSI subsystem to initialize
 *      the SCSI transport netlink interface
 *
 **/
void
scsi_netlink_init(void)
{
	struct netlink_kernel_cfg cfg = {
		.input	= scsi_nl_rcv_msg,
		.groups	= SCSI_NL_GRP_CNT,
        };
	scsi_nl_sock = netlink_kernel_create(&init_net, NETLINK_SCSITRANSPORT,
					     &cfg);
	if (!scsi_nl_sock) {
		printk(KERN_ERR "%s: register of receive handler failed\n",
				__func__);
		return;
	}
	return;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Eric W. Biedermann | 30 | 56.60% | 1 | 33.33% | 
| James Smart | 23 | 43.40% | 2 | 66.67% | 
| Total | 53 | 100.00% | 3 | 100.00% | 
/**
 * scsi_netlink_exit - Called by SCSI subsystem to disable the SCSI transport netlink interface
 *
 **/
void
scsi_netlink_exit(void)
{
	if (scsi_nl_sock) {
		netlink_kernel_release(scsi_nl_sock);
	}
	return;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| James Smart | 13 | 68.42% | 1 | 50.00% | 
| Eric W. Biedermann | 6 | 31.58% | 1 | 50.00% | 
| Total | 19 | 100.00% | 2 | 100.00% | 
Overall Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| James Smart | 341 | 78.21% | 2 | 16.67% | 
| Eric W. Biedermann | 78 | 17.89% | 2 | 16.67% | 
| Paul Gortmaker | 3 | 0.69% | 1 | 8.33% | 
| Tejun Heo | 3 | 0.69% | 1 | 8.33% | 
| Arnaldo Carvalho de Melo | 3 | 0.69% | 1 | 8.33% | 
| Johannes Berg | 2 | 0.46% | 1 | 8.33% | 
| Harvey Harrison | 2 | 0.46% | 1 | 8.33% | 
| Hong Zhi Guo | 2 | 0.46% | 1 | 8.33% | 
| Eric Paris | 1 | 0.23% | 1 | 8.33% | 
| Rob Landley | 1 | 0.23% | 1 | 8.33% | 
| Total | 436 | 100.00% | 12 | 100.00% | 
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.