xref: /onnv-gate/usr/src/uts/common/io/dld/dld_flow.c (revision 11878:ac93462db6d7)
18275SEric Cheng /*
28275SEric Cheng  * CDDL HEADER START
38275SEric Cheng  *
48275SEric Cheng  * The contents of this file are subject to the terms of the
58275SEric Cheng  * Common Development and Distribution License (the "License").
68275SEric Cheng  * You may not use this file except in compliance with the License.
78275SEric Cheng  *
88275SEric Cheng  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
98275SEric Cheng  * or http://www.opensolaris.org/os/licensing.
108275SEric Cheng  * See the License for the specific language governing permissions
118275SEric Cheng  * and limitations under the License.
128275SEric Cheng  *
138275SEric Cheng  * When distributing Covered Code, include this CDDL HEADER in each
148275SEric Cheng  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
158275SEric Cheng  * If applicable, add the following below this CDDL HEADER, with the
168275SEric Cheng  * fields enclosed by brackets "[]" replaced with your own identifying
178275SEric Cheng  * information: Portions Copyright [yyyy] [name of copyright owner]
188275SEric Cheng  *
198275SEric Cheng  * CDDL HEADER END
208275SEric Cheng  */
218275SEric Cheng /*
22*11878SVenu.Iyer@Sun.COM  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
238275SEric Cheng  * Use is subject to license terms.
248275SEric Cheng  */
258275SEric Cheng 
268275SEric Cheng /*
278275SEric Cheng  * Flows ioctls implementation.
288275SEric Cheng  */
298275SEric Cheng 
3010616SSebastien.Roy@Sun.COM #include <sys/cred.h>
318275SEric Cheng #include <sys/dld.h>
328275SEric Cheng #include <sys/mac_provider.h>
338275SEric Cheng #include <sys/mac_client.h>
348275SEric Cheng #include <sys/mac_client_priv.h>
358275SEric Cheng 
368275SEric Cheng /*
378275SEric Cheng  * Implements flow add, remove, modify ioctls.
388275SEric Cheng  */
398275SEric Cheng int
dld_add_flow(datalink_id_t linkid,char * flow_name,flow_desc_t * flow_desc,mac_resource_props_t * mrp)408275SEric Cheng dld_add_flow(datalink_id_t linkid, char *flow_name, flow_desc_t *flow_desc,
418275SEric Cheng     mac_resource_props_t *mrp)
428275SEric Cheng {
438275SEric Cheng 	return (mac_link_flow_add(linkid, flow_name, flow_desc, mrp));
448275SEric Cheng }
458275SEric Cheng 
468275SEric Cheng int
dld_remove_flow(char * flow_name)478275SEric Cheng dld_remove_flow(char *flow_name)
488275SEric Cheng {
498275SEric Cheng 	return (mac_link_flow_remove(flow_name));
508275SEric Cheng }
518275SEric Cheng 
528275SEric Cheng int
dld_modify_flow(char * flow_name,mac_resource_props_t * mrp)538275SEric Cheng dld_modify_flow(char *flow_name, mac_resource_props_t *mrp)
548275SEric Cheng {
558275SEric Cheng 	return (mac_link_flow_modify(flow_name, mrp));
568275SEric Cheng }
578275SEric Cheng 
588275SEric Cheng 
598275SEric Cheng /*
608275SEric Cheng  * Callback function and structure used by dld_walk_flow().
618275SEric Cheng  */
628275SEric Cheng typedef struct flowinfo_state_s {
638275SEric Cheng 	int			fi_bufsize;
648275SEric Cheng 	int			fi_nflows;
658275SEric Cheng 	uchar_t			*fi_fl;
668275SEric Cheng } flowinfo_state_t;
678275SEric Cheng 
688275SEric Cheng static int
dld_walk_flow_cb(mac_flowinfo_t * finfo,void * arg)698275SEric Cheng dld_walk_flow_cb(mac_flowinfo_t *finfo, void *arg)
708275SEric Cheng {
718275SEric Cheng 	flowinfo_state_t		*statep = arg;
72*11878SVenu.Iyer@Sun.COM 	dld_flowinfo_t			*fi;
738275SEric Cheng 
748275SEric Cheng 	if (statep->fi_bufsize < sizeof (dld_flowinfo_t))
758275SEric Cheng 		return (ENOSPC);
768275SEric Cheng 
77*11878SVenu.Iyer@Sun.COM 	fi = kmem_zalloc(sizeof (*fi), KM_SLEEP);
78*11878SVenu.Iyer@Sun.COM 	(void) strlcpy(fi->fi_flowname, finfo->fi_flow_name,
79*11878SVenu.Iyer@Sun.COM 	    sizeof (fi->fi_flowname));
80*11878SVenu.Iyer@Sun.COM 	fi->fi_linkid = finfo->fi_link_id;
81*11878SVenu.Iyer@Sun.COM 	fi->fi_flow_desc = finfo->fi_flow_desc;
82*11878SVenu.Iyer@Sun.COM 	fi->fi_resource_props = finfo->fi_resource_props;
838275SEric Cheng 
84*11878SVenu.Iyer@Sun.COM 	if (copyout(fi, statep->fi_fl, sizeof (*fi)) != 0) {
85*11878SVenu.Iyer@Sun.COM 		kmem_free(fi, sizeof (*fi));
868275SEric Cheng 		return (EFAULT);
878275SEric Cheng 	}
88*11878SVenu.Iyer@Sun.COM 	kmem_free(fi, sizeof (*fi));
898275SEric Cheng 	statep->fi_nflows++;
908275SEric Cheng 	statep->fi_bufsize -= sizeof (dld_flowinfo_t);
918275SEric Cheng 	statep->fi_fl += sizeof (dld_flowinfo_t);
928275SEric Cheng 	return (0);
938275SEric Cheng }
948275SEric Cheng 
958275SEric Cheng /*
968275SEric Cheng  * Implements flow walk ioctl.
978275SEric Cheng  * Retrieves a specific flow or a list of flows from the specified link.
988275SEric Cheng  * ENOSPC is returned a bigger buffer is needed.
998275SEric Cheng  */
1008275SEric Cheng int
dld_walk_flow(dld_ioc_walkflow_t * wf,intptr_t uaddr,cred_t * credp)10110616SSebastien.Roy@Sun.COM dld_walk_flow(dld_ioc_walkflow_t *wf, intptr_t uaddr, cred_t *credp)
1028275SEric Cheng {
1038275SEric Cheng 	flowinfo_state_t	state;
104*11878SVenu.Iyer@Sun.COM 	mac_flowinfo_t		*finfo;
1058275SEric Cheng 	int			err = 0;
1068275SEric Cheng 
10710616SSebastien.Roy@Sun.COM 	/* For now, one can only view flows from the global zone. */
10810616SSebastien.Roy@Sun.COM 	if (crgetzoneid(credp) != GLOBAL_ZONEID)
10910616SSebastien.Roy@Sun.COM 		return (EPERM);
11010616SSebastien.Roy@Sun.COM 
111*11878SVenu.Iyer@Sun.COM 	finfo = kmem_zalloc(sizeof (*finfo), KM_SLEEP);
1128275SEric Cheng 	state.fi_bufsize = wf->wf_len;
1138275SEric Cheng 	state.fi_fl = (uchar_t *)uaddr + sizeof (*wf);
1148275SEric Cheng 	state.fi_nflows = 0;
1158275SEric Cheng 
1168275SEric Cheng 	if (wf->wf_name[0] == '\0') {
1178275SEric Cheng 		err = mac_link_flow_walk(wf->wf_linkid, dld_walk_flow_cb,
1188275SEric Cheng 		    &state);
1198275SEric Cheng 	} else {
120*11878SVenu.Iyer@Sun.COM 		err = mac_link_flow_info(wf->wf_name, finfo);
121*11878SVenu.Iyer@Sun.COM 		if (err != 0) {
122*11878SVenu.Iyer@Sun.COM 			kmem_free(finfo, sizeof (*finfo));
1238275SEric Cheng 			return (err);
124*11878SVenu.Iyer@Sun.COM 		}
125*11878SVenu.Iyer@Sun.COM 		err = dld_walk_flow_cb(finfo, &state);
1268275SEric Cheng 	}
127*11878SVenu.Iyer@Sun.COM 	kmem_free(finfo, sizeof (*finfo));
1288275SEric Cheng 	wf->wf_nflows = state.fi_nflows;
1298275SEric Cheng 	return (err);
1308275SEric Cheng }
131