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*10616SSebastien.Roy@Sun.COM * Copyright 2009 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 30*10616SSebastien.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 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 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 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 698275SEric Cheng dld_walk_flow_cb(mac_flowinfo_t *finfo, void *arg) 708275SEric Cheng { 718275SEric Cheng flowinfo_state_t *statep = arg; 728275SEric Cheng dld_flowinfo_t fi; 738275SEric Cheng 748275SEric Cheng if (statep->fi_bufsize < sizeof (dld_flowinfo_t)) 758275SEric Cheng return (ENOSPC); 768275SEric Cheng 778275SEric Cheng (void) strlcpy(fi.fi_flowname, finfo->fi_flow_name, 788275SEric Cheng sizeof (fi.fi_flowname)); 798275SEric Cheng fi.fi_linkid = finfo->fi_link_id; 808275SEric Cheng fi.fi_flow_desc = finfo->fi_flow_desc; 818275SEric Cheng fi.fi_resource_props = finfo->fi_resource_props; 828275SEric Cheng 838275SEric Cheng if (copyout(&fi, statep->fi_fl, sizeof (fi)) != 0) { 848275SEric Cheng return (EFAULT); 858275SEric Cheng } 868275SEric Cheng statep->fi_nflows++; 878275SEric Cheng statep->fi_bufsize -= sizeof (dld_flowinfo_t); 888275SEric Cheng statep->fi_fl += sizeof (dld_flowinfo_t); 898275SEric Cheng return (0); 908275SEric Cheng } 918275SEric Cheng 928275SEric Cheng /* 938275SEric Cheng * Implements flow walk ioctl. 948275SEric Cheng * Retrieves a specific flow or a list of flows from the specified link. 958275SEric Cheng * ENOSPC is returned a bigger buffer is needed. 968275SEric Cheng */ 978275SEric Cheng int 98*10616SSebastien.Roy@Sun.COM dld_walk_flow(dld_ioc_walkflow_t *wf, intptr_t uaddr, cred_t *credp) 998275SEric Cheng { 1008275SEric Cheng flowinfo_state_t state; 1018275SEric Cheng mac_flowinfo_t finfo; 1028275SEric Cheng int err = 0; 1038275SEric Cheng 104*10616SSebastien.Roy@Sun.COM /* For now, one can only view flows from the global zone. */ 105*10616SSebastien.Roy@Sun.COM if (crgetzoneid(credp) != GLOBAL_ZONEID) 106*10616SSebastien.Roy@Sun.COM return (EPERM); 107*10616SSebastien.Roy@Sun.COM 1088275SEric Cheng state.fi_bufsize = wf->wf_len; 1098275SEric Cheng state.fi_fl = (uchar_t *)uaddr + sizeof (*wf); 1108275SEric Cheng state.fi_nflows = 0; 1118275SEric Cheng 1128275SEric Cheng if (wf->wf_name[0] == '\0') { 1138275SEric Cheng err = mac_link_flow_walk(wf->wf_linkid, dld_walk_flow_cb, 1148275SEric Cheng &state); 1158275SEric Cheng } else { 1168275SEric Cheng err = mac_link_flow_info(wf->wf_name, &finfo); 1178275SEric Cheng if (err != 0) 1188275SEric Cheng return (err); 1198275SEric Cheng 1208275SEric Cheng err = dld_walk_flow_cb(&finfo, &state); 1218275SEric Cheng } 1228275SEric Cheng wf->wf_nflows = state.fi_nflows; 1238275SEric Cheng return (err); 1248275SEric Cheng } 125