4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
27 * Flows ioctls implementation.
32 #include <sys/mac_provider.h>
33 #include <sys/mac_client.h>
34 #include <sys/mac_client_priv.h>
37 * Implements flow add, remove, modify ioctls.
40 dld_add_flow(datalink_id_t linkid
, char *flow_name
, flow_desc_t
*flow_desc
,
41 mac_resource_props_t
*mrp
)
43 return (mac_link_flow_add(linkid
, flow_name
, flow_desc
, mrp
));
47 dld_remove_flow(char *flow_name
)
49 return (mac_link_flow_remove(flow_name
));
53 dld_modify_flow(char *flow_name
, mac_resource_props_t
*mrp
)
55 return (mac_link_flow_modify(flow_name
, mrp
));
60 * Callback function and structure used by dld_walk_flow().
62 typedef struct flowinfo_state_s
{
69 dld_walk_flow_cb(mac_flowinfo_t
*finfo
, void *arg
)
71 flowinfo_state_t
*statep
= arg
;
74 if (statep
->fi_bufsize
< sizeof (dld_flowinfo_t
))
77 fi
= kmem_zalloc(sizeof (*fi
), KM_SLEEP
);
78 (void) strlcpy(fi
->fi_flowname
, finfo
->fi_flow_name
,
79 sizeof (fi
->fi_flowname
));
80 fi
->fi_linkid
= finfo
->fi_link_id
;
81 fi
->fi_flow_desc
= finfo
->fi_flow_desc
;
82 fi
->fi_resource_props
= finfo
->fi_resource_props
;
84 if (copyout(fi
, statep
->fi_fl
, sizeof (*fi
)) != 0) {
85 kmem_free(fi
, sizeof (*fi
));
88 kmem_free(fi
, sizeof (*fi
));
90 statep
->fi_bufsize
-= sizeof (dld_flowinfo_t
);
91 statep
->fi_fl
+= sizeof (dld_flowinfo_t
);
96 * Implements flow walk ioctl.
97 * Retrieves a specific flow or a list of flows from the specified link.
98 * ENOSPC is returned a bigger buffer is needed.
101 dld_walk_flow(dld_ioc_walkflow_t
*wf
, intptr_t uaddr
, cred_t
*credp
)
103 flowinfo_state_t state
;
104 mac_flowinfo_t
*finfo
;
107 /* For now, one can only view flows from the global zone. */
108 if (crgetzoneid(credp
) != GLOBAL_ZONEID
)
111 finfo
= kmem_zalloc(sizeof (*finfo
), KM_SLEEP
);
112 state
.fi_bufsize
= wf
->wf_len
;
113 state
.fi_fl
= (uchar_t
*)uaddr
+ sizeof (*wf
);
116 if (wf
->wf_name
[0] == '\0') {
117 err
= mac_link_flow_walk(wf
->wf_linkid
, dld_walk_flow_cb
,
120 err
= mac_link_flow_info(wf
->wf_name
, finfo
);
122 kmem_free(finfo
, sizeof (*finfo
));
125 err
= dld_walk_flow_cb(finfo
, &state
);
127 kmem_free(finfo
, sizeof (*finfo
));
128 wf
->wf_nflows
= state
.fi_nflows
;