view usr/src/uts/common/io/bpf/bpf_mac.c @ 10639:368f1335a058

PSARC/2009/232 Solaris Packet Capture PSARC/2009/403 kstats for ipnet 6824047 every downcall function should have a "notsupported" function 6822740 RFE: provide PF_PACKET for developers on OpenSolaris 6822741 RFE: Solaris needs BPF to improve the packet capture story 6867683 RFE: need to be able to retrieve physical interface flags
author Darren Reed <Darren.Reed@Sun.COM>
date Thu, 24 Sep 2009 07:28:12 -0700
parents
children bfcb8daf999a
line wrap: on
line source

/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */

/*
 * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

#include <sys/types.h>
#include <sys/stream.h>
#include <net/bpf.h>
#include <net/bpfdesc.h>

/*
 * This file provides the link to the functions required from the mac
 * module. It is currently in bpf, rather than mac (like ipnet_bpf)
 * because of the mac/dls split. The bpf driver needs to know when
 * interfaces appear and disappear and the best place for that is in
 * dls. Unfortunately all of the other functions used here are found
 * in the mac module, making it seem ill suited to being at home in
 * dls. Similarly it has even less purpose being in mac as it is
 * today.
 */
static int	mac_bpf_open(const char *, uintptr_t *, zoneid_t);
static void	mac_bpf_close(uintptr_t);
static const char *mac_bpf_name(uintptr_t);
static int	mac_bpf_type(uintptr_t);
static void	mac_bpf_sdu_get(uintptr_t, uint_t *);
static int	mac_bpf_tx(uintptr_t, mblk_t *);
static uintptr_t mac_bpf_promisc_add(uintptr_t, int, void *, uintptr_t *, int);
static void	mac_bpf_promisc_remove(uintptr_t);
static int	mac_bpf_client_open(uintptr_t, uintptr_t *);
static void	mac_bpf_client_close(uintptr_t);
static const char *mac_bpf_client_name(uintptr_t);
static int	mac_bpf_getlinkid(const char *, datalink_id_t *, zoneid_t);

bpf_provider_t bpf_mac = {
	BPR_MAC,
	mac_bpf_open,
	mac_bpf_close,
	mac_bpf_name,
	mac_bpf_type,
	mac_bpf_sdu_get,
	mac_bpf_tx,
	mac_bpf_promisc_add,
	mac_bpf_promisc_remove,
	mac_bpf_getlinkid,
	mac_bpf_client_close,
	mac_bpf_client_name,
	mac_bpf_client_open
};

/*ARGSUSED*/
static int
mac_bpf_open(const char *name, uintptr_t *mhandlep, zoneid_t zoneid)
{
	return (mac_open(name, (mac_handle_t *)mhandlep));
}

static void
mac_bpf_close(uintptr_t mhandle)
{
	mac_close((mac_handle_t)mhandle);
}

static const char *
mac_bpf_name(uintptr_t mhandle)
{
	return (mac_name((mac_handle_t)mhandle));
}

static int
mac_bpf_type(uintptr_t mhandle)
{
	return (mac_type((mac_handle_t)mhandle));
}

static void
mac_bpf_sdu_get(uintptr_t mhandle, uint_t *mtup)
{
	mac_sdu_get((mac_handle_t)mhandle, NULL, mtup);
}

static int
mac_bpf_tx(uintptr_t chandle, mblk_t *pkt)
{
	/*
	 * If the mac layer cannot deliver a packet as requested by BPF then
	 * simply have the mac layer drop it. BPF isn't interested in doing
	 * any amount of retry - that's left to the application.
	 */
	return (mac_tx((mac_client_handle_t)chandle, pkt, 0,
	    MAC_DROP_ON_NO_DESC, NULL));
}

static uintptr_t
mac_bpf_promisc_add(uintptr_t chandle, int how, void *arg, uintptr_t *promisc,
    int flags)
{
	return (mac_promisc_add((mac_client_handle_t)chandle, how, bpf_mtap,
	    arg, (mac_promisc_handle_t *)promisc, flags));
}

static void
mac_bpf_promisc_remove(uintptr_t phandle)
{
	mac_promisc_remove((mac_promisc_handle_t)phandle);
}

static int
mac_bpf_client_open(uintptr_t mhandle, uintptr_t *chandlep)
{
	return (mac_client_open((mac_handle_t)mhandle,
	    (mac_client_handle_t *)chandlep,  NULL,
	    MAC_OPEN_FLAGS_USE_DATALINK_NAME));
}

static void
mac_bpf_client_close(uintptr_t chandle)
{
	mac_client_close((mac_client_handle_t)chandle, 0);
}

static const char *
mac_bpf_client_name(uintptr_t chandle)
{
	return (mac_client_name((mac_client_handle_t)chandle));
}

/*ARGSUSED*/
static int
mac_bpf_getlinkid(const char *name, datalink_id_t *idp, zoneid_t zoneid)
{
	int error;

	/*
	 * If at first we don't succeed, try again, just in case it is in
	 * hiding. The first call requires the datalink management daemon
	 * (the authorative source of information about name to id mapping)
	 * to be present and answering upcalls, the seond does not.
	 */
	error = dls_mgmt_get_linkid(name, idp);
	if (error != 0)
		error = dls_devnet_macname2linkid(name, idp);

	return (error);
}