132 mac_prop_id_t, uint_t, dladm_status_t *);
133 static dladm_status_t i_dladm_get_public_prop(dladm_handle_t, datalink_id_t,
134 char *, uint_t, uint_t *, void *, size_t);
135
136 static dladm_status_t i_dladm_set_private_prop(dladm_handle_t, datalink_id_t,
137 const char *, char **, uint_t, uint_t);
138 static dladm_status_t i_dladm_get_priv_prop(dladm_handle_t, datalink_id_t,
139 const char *, char **, uint_t *, dladm_prop_type_t,
140 uint_t);
141 static dladm_status_t i_dladm_macprop(dladm_handle_t, void *, boolean_t);
142 static const char *dladm_perm2str(uint_t, char *);
143 static link_attr_t *dladm_name2prop(const char *);
144 static link_attr_t *dladm_id2prop(mac_prop_id_t);
145
146 static pd_getf_t get_zone, get_autopush, get_rate_mod, get_rate,
147 get_speed, get_channel, get_powermode, get_radio,
148 get_duplex, get_link_state, get_binary, get_uint32,
149 get_flowctl, get_maxbw, get_cpus, get_priority,
150 get_tagmode, get_range, get_stp, get_bridge_forward,
151 get_bridge_pvid, get_protection, get_rxrings,
152 get_txrings, get_cntavail,
153 get_allowedips, get_allowedcids, get_pool,
154 get_rings_range, get_linkmode_prop;
155
156 static pd_setf_t set_zone, set_rate, set_powermode, set_radio,
157 set_public_prop, set_resource, set_stp_prop,
158 set_bridge_forward, set_bridge_pvid;
159
160 static pd_checkf_t check_zone, check_autopush, check_rate, check_hoplimit,
161 check_encaplim, check_uint32, check_maxbw, check_cpus,
162 check_stp_prop, check_bridge_pvid, check_allowedips,
163 check_allowedcids, check_rings,
164 check_pool, check_prop;
165
166 struct prop_desc {
167 /*
168 * link property name
169 */
170 char *pd_name;
171
172 /*
173 * default property value, can be set to { "", NULL }
174 */
175 val_desc_t pd_defval;
176
177 /*
178 * list of optional property values, can be NULL.
179 *
180 * This is set to non-NULL if there is a list of possible property
181 * values. pd_optval would point to the array of possible values.
182 */
183 val_desc_t *pd_optval;
346
347 { MAC_PROP_RESOURCE_EFF, sizeof (mac_resource_props_t),
348 "resource-effective"},
349
350 { MAC_PROP_RXRINGSRANGE, sizeof (mac_propval_range_t), "rxrings"},
351
352 { MAC_PROP_TXRINGSRANGE, sizeof (mac_propval_range_t), "txrings"},
353
354 { MAC_PROP_MAX_TX_RINGS_AVAIL, sizeof (uint_t),
355 "txrings-available"},
356
357 { MAC_PROP_MAX_RX_RINGS_AVAIL, sizeof (uint_t),
358 "rxrings-available"},
359
360 { MAC_PROP_MAX_RXHWCLNT_AVAIL, sizeof (uint_t), "rxhwclnt-available"},
361
362 { MAC_PROP_MAX_TXHWCLNT_AVAIL, sizeof (uint_t), "txhwclnt-available"},
363
364 { MAC_PROP_IB_LINKMODE, sizeof (uint32_t), "linkmode"},
365
366 { MAC_PROP_PRIVATE, 0, "driver-private"}
367 };
368
369 typedef struct bridge_public_prop_s {
370 const char *bpp_name;
371 int bpp_code;
372 } bridge_public_prop_t;
373
374 static const bridge_public_prop_t bridge_prop[] = {
375 { "stp", PT_CFG_NON_STP },
376 { "stp_priority", PT_CFG_PRIO },
377 { "stp_cost", PT_CFG_COST },
378 { "stp_edge", PT_CFG_EDGE },
379 { "stp_p2p", PT_CFG_P2P },
380 { "stp_mcheck", PT_CFG_MCHECK },
381 { NULL, 0 }
382 };
383
384 static val_desc_t link_duplex_vals[] = {
385 { "half", LINK_DUPLEX_HALF },
665 DATALINK_CLASS_PHYS|DATALINK_CLASS_AGGR|
666 DATALINK_CLASS_ETHERSTUB|DATALINK_CLASS_SIMNET, DL_ETHER },
667
668 { "stp_p2p", { "auto", P2P_AUTO },
669 stp_p2p_vals, VALCNT(stp_p2p_vals),
670 set_stp_prop, NULL, get_stp, NULL, PD_AFTER_PERM,
671 DATALINK_CLASS_PHYS|DATALINK_CLASS_AGGR|
672 DATALINK_CLASS_ETHERSTUB|DATALINK_CLASS_SIMNET, DL_ETHER },
673
674 { "stp_mcheck", { "0", 0 },
675 link_01_vals, VALCNT(link_01_vals),
676 set_stp_prop, NULL, get_stp, check_stp_prop, PD_AFTER_PERM,
677 DATALINK_CLASS_PHYS|DATALINK_CLASS_AGGR|
678 DATALINK_CLASS_ETHERSTUB|DATALINK_CLASS_SIMNET, DL_ETHER },
679
680 { "protection", { "--", RESET_VAL },
681 link_protect_vals, VALCNT(link_protect_vals),
682 set_resource, NULL, get_protection, check_prop, 0,
683 DATALINK_CLASS_ALL, DATALINK_ANY_MEDIATYPE },
684
685 { "allowed-ips", { "--", 0 },
686 NULL, 0, set_resource, NULL,
687 get_allowedips, check_allowedips, PD_CHECK_ALLOC,
688 DATALINK_CLASS_ALL, DATALINK_ANY_MEDIATYPE },
689
690 { "allowed-dhcp-cids", { "--", 0 },
691 NULL, 0, set_resource, NULL,
692 get_allowedcids, check_allowedcids, PD_CHECK_ALLOC,
693 DATALINK_CLASS_ALL, DATALINK_ANY_MEDIATYPE },
694
695 { "rxrings", { "--", RESET_VAL }, NULL, 0,
696 set_resource, get_rings_range, get_rxrings, check_rings, 0,
697 DATALINK_CLASS_ALL, DATALINK_ANY_MEDIATYPE },
698
699 { "rxrings-effective", { "--", 0 },
700 NULL, 0, NULL, NULL,
701 get_rxrings, NULL, 0,
702 DATALINK_CLASS_ALL, DATALINK_ANY_MEDIATYPE },
703
704 { "txrings", { "--", RESET_VAL }, NULL, 0,
708 { "txrings-effective", { "--", 0 },
709 NULL, 0, NULL, NULL,
710 get_txrings, NULL, 0,
711 DATALINK_CLASS_ALL, DATALINK_ANY_MEDIATYPE },
712
713 { "txrings-available", { "", 0 }, NULL, 0,
714 NULL, NULL, get_cntavail, NULL, 0,
715 DATALINK_CLASS_ALL, DATALINK_ANY_MEDIATYPE },
716
717 { "rxrings-available", { "", 0 }, NULL, 0,
718 NULL, NULL, get_cntavail, NULL, 0,
719 DATALINK_CLASS_ALL, DATALINK_ANY_MEDIATYPE },
720
721 { "rxhwclnt-available", { "", 0 }, NULL, 0,
722 NULL, NULL, get_cntavail, NULL, 0,
723 DATALINK_CLASS_ALL, DATALINK_ANY_MEDIATYPE },
724
725 { "txhwclnt-available", { "", 0 }, NULL, 0,
726 NULL, NULL, get_cntavail, NULL, 0,
727 DATALINK_CLASS_ALL, DATALINK_ANY_MEDIATYPE },
728
729 };
730
731 #define DLADM_MAX_PROPS (sizeof (prop_table) / sizeof (prop_desc_t))
732
733 static resource_prop_t rsrc_prop_table[] = {
734 {"maxbw", extract_maxbw},
735 {"priority", extract_priority},
736 {"cpus", extract_cpus},
737 {"cpus-effective", extract_cpus},
738 {"pool", extract_pool},
739 {"pool-effective", extract_pool},
740 {"protection", extract_protection},
741 {"allowed-ips", extract_allowedips},
742 {"allowed-dhcp-cids", extract_allowedcids},
743 {"rxrings", extract_rxrings},
744 {"rxrings-effective", extract_rxrings},
745 {"txrings", extract_txrings},
746 {"txrings-effective", extract_txrings}
747 };
748 #define DLADM_MAX_RSRC_PROP (sizeof (rsrc_prop_table) / \
2228 mrp->mrp_mask |= MRP_TX_RINGS;
2229
2230 return (DLADM_STATUS_OK);
2231 }
2232
2233 /* ARGSUSED */
2234 static dladm_status_t
2235 get_cntavail(dladm_handle_t handle, prop_desc_t *pdp, datalink_id_t linkid,
2236 char **prop_val, uint_t *val_cnt, datalink_media_t media, uint_t flags,
2237 uint_t *perm_flags)
2238 {
2239 if (flags & DLD_PROP_DEFAULT)
2240 return (DLADM_STATUS_NOTDEFINED);
2241
2242 return (get_uint32(handle, pdp, linkid, prop_val, val_cnt, media,
2243 flags, perm_flags));
2244 }
2245
2246 /* ARGSUSED */
2247 static dladm_status_t
2248 set_resource(dladm_handle_t handle, prop_desc_t *pdp,
2249 datalink_id_t linkid, val_desc_t *vdp, uint_t val_cnt,
2250 uint_t flags, datalink_media_t media)
2251 {
2252 mac_resource_props_t mrp;
2253 dladm_status_t status = DLADM_STATUS_OK;
2254 dld_ioc_macprop_t *dip;
2255 int i;
2256
2257 bzero(&mrp, sizeof (mac_resource_props_t));
2258 dip = i_dladm_buf_alloc_by_name(0, linkid, "resource",
2259 flags, &status);
2260
2261 if (dip == NULL)
2262 return (status);
2263
2264 for (i = 0; i < DLADM_MAX_RSRC_PROP; i++) {
2265 resource_prop_t *rp = &rsrc_prop_table[i];
2266
2267 if (strcmp(pdp->pd_name, rp->rp_name) != 0)
|
132 mac_prop_id_t, uint_t, dladm_status_t *);
133 static dladm_status_t i_dladm_get_public_prop(dladm_handle_t, datalink_id_t,
134 char *, uint_t, uint_t *, void *, size_t);
135
136 static dladm_status_t i_dladm_set_private_prop(dladm_handle_t, datalink_id_t,
137 const char *, char **, uint_t, uint_t);
138 static dladm_status_t i_dladm_get_priv_prop(dladm_handle_t, datalink_id_t,
139 const char *, char **, uint_t *, dladm_prop_type_t,
140 uint_t);
141 static dladm_status_t i_dladm_macprop(dladm_handle_t, void *, boolean_t);
142 static const char *dladm_perm2str(uint_t, char *);
143 static link_attr_t *dladm_name2prop(const char *);
144 static link_attr_t *dladm_id2prop(mac_prop_id_t);
145
146 static pd_getf_t get_zone, get_autopush, get_rate_mod, get_rate,
147 get_speed, get_channel, get_powermode, get_radio,
148 get_duplex, get_link_state, get_binary, get_uint32,
149 get_flowctl, get_maxbw, get_cpus, get_priority,
150 get_tagmode, get_range, get_stp, get_bridge_forward,
151 get_bridge_pvid, get_protection, get_rxrings,
152 get_txrings, get_cntavail, get_macaddr,
153 get_allowedips, get_allowedcids, get_pool,
154 get_rings_range, get_linkmode_prop;
155
156 static pd_setf_t set_zone, set_rate, set_powermode, set_radio,
157 set_public_prop, set_resource, set_stp_prop,
158 set_bridge_forward, set_bridge_pvid, set_macaddr;
159
160 static pd_checkf_t check_zone, check_autopush, check_rate, check_hoplimit,
161 check_encaplim, check_uint32, check_maxbw, check_cpus,
162 check_stp_prop, check_bridge_pvid, check_allowedips,
163 check_allowedcids, check_rings, check_macaddr,
164 check_pool, check_prop;
165
166 struct prop_desc {
167 /*
168 * link property name
169 */
170 char *pd_name;
171
172 /*
173 * default property value, can be set to { "", NULL }
174 */
175 val_desc_t pd_defval;
176
177 /*
178 * list of optional property values, can be NULL.
179 *
180 * This is set to non-NULL if there is a list of possible property
181 * values. pd_optval would point to the array of possible values.
182 */
183 val_desc_t *pd_optval;
346
347 { MAC_PROP_RESOURCE_EFF, sizeof (mac_resource_props_t),
348 "resource-effective"},
349
350 { MAC_PROP_RXRINGSRANGE, sizeof (mac_propval_range_t), "rxrings"},
351
352 { MAC_PROP_TXRINGSRANGE, sizeof (mac_propval_range_t), "txrings"},
353
354 { MAC_PROP_MAX_TX_RINGS_AVAIL, sizeof (uint_t),
355 "txrings-available"},
356
357 { MAC_PROP_MAX_RX_RINGS_AVAIL, sizeof (uint_t),
358 "rxrings-available"},
359
360 { MAC_PROP_MAX_RXHWCLNT_AVAIL, sizeof (uint_t), "rxhwclnt-available"},
361
362 { MAC_PROP_MAX_TXHWCLNT_AVAIL, sizeof (uint_t), "txhwclnt-available"},
363
364 { MAC_PROP_IB_LINKMODE, sizeof (uint32_t), "linkmode"},
365
366 { MAC_PROP_MACADDRESS, sizeof (mac_addrprop_t), "mac-address"},
367
368 { MAC_PROP_PRIVATE, 0, "driver-private"}
369 };
370
371 typedef struct bridge_public_prop_s {
372 const char *bpp_name;
373 int bpp_code;
374 } bridge_public_prop_t;
375
376 static const bridge_public_prop_t bridge_prop[] = {
377 { "stp", PT_CFG_NON_STP },
378 { "stp_priority", PT_CFG_PRIO },
379 { "stp_cost", PT_CFG_COST },
380 { "stp_edge", PT_CFG_EDGE },
381 { "stp_p2p", PT_CFG_P2P },
382 { "stp_mcheck", PT_CFG_MCHECK },
383 { NULL, 0 }
384 };
385
386 static val_desc_t link_duplex_vals[] = {
387 { "half", LINK_DUPLEX_HALF },
667 DATALINK_CLASS_PHYS|DATALINK_CLASS_AGGR|
668 DATALINK_CLASS_ETHERSTUB|DATALINK_CLASS_SIMNET, DL_ETHER },
669
670 { "stp_p2p", { "auto", P2P_AUTO },
671 stp_p2p_vals, VALCNT(stp_p2p_vals),
672 set_stp_prop, NULL, get_stp, NULL, PD_AFTER_PERM,
673 DATALINK_CLASS_PHYS|DATALINK_CLASS_AGGR|
674 DATALINK_CLASS_ETHERSTUB|DATALINK_CLASS_SIMNET, DL_ETHER },
675
676 { "stp_mcheck", { "0", 0 },
677 link_01_vals, VALCNT(link_01_vals),
678 set_stp_prop, NULL, get_stp, check_stp_prop, PD_AFTER_PERM,
679 DATALINK_CLASS_PHYS|DATALINK_CLASS_AGGR|
680 DATALINK_CLASS_ETHERSTUB|DATALINK_CLASS_SIMNET, DL_ETHER },
681
682 { "protection", { "--", RESET_VAL },
683 link_protect_vals, VALCNT(link_protect_vals),
684 set_resource, NULL, get_protection, check_prop, 0,
685 DATALINK_CLASS_ALL, DATALINK_ANY_MEDIATYPE },
686
687 { "mac-address", { "", 0 }, NULL, 0,
688 set_macaddr, NULL, get_macaddr, check_macaddr, PD_CHECK_ALLOC,
689 DATALINK_CLASS_PHYS|DATALINK_CLASS_AGGR|DATALINK_CLASS_VNIC|
690 DATALINK_CLASS_SIMNET, DATALINK_ANY_MEDIATYPE },
691
692 { "allowed-ips", { "--", 0 },
693 NULL, 0, set_resource, NULL,
694 get_allowedips, check_allowedips, PD_CHECK_ALLOC,
695 DATALINK_CLASS_ALL, DATALINK_ANY_MEDIATYPE },
696
697 { "allowed-dhcp-cids", { "--", 0 },
698 NULL, 0, set_resource, NULL,
699 get_allowedcids, check_allowedcids, PD_CHECK_ALLOC,
700 DATALINK_CLASS_ALL, DATALINK_ANY_MEDIATYPE },
701
702 { "rxrings", { "--", RESET_VAL }, NULL, 0,
703 set_resource, get_rings_range, get_rxrings, check_rings, 0,
704 DATALINK_CLASS_ALL, DATALINK_ANY_MEDIATYPE },
705
706 { "rxrings-effective", { "--", 0 },
707 NULL, 0, NULL, NULL,
708 get_rxrings, NULL, 0,
709 DATALINK_CLASS_ALL, DATALINK_ANY_MEDIATYPE },
710
711 { "txrings", { "--", RESET_VAL }, NULL, 0,
715 { "txrings-effective", { "--", 0 },
716 NULL, 0, NULL, NULL,
717 get_txrings, NULL, 0,
718 DATALINK_CLASS_ALL, DATALINK_ANY_MEDIATYPE },
719
720 { "txrings-available", { "", 0 }, NULL, 0,
721 NULL, NULL, get_cntavail, NULL, 0,
722 DATALINK_CLASS_ALL, DATALINK_ANY_MEDIATYPE },
723
724 { "rxrings-available", { "", 0 }, NULL, 0,
725 NULL, NULL, get_cntavail, NULL, 0,
726 DATALINK_CLASS_ALL, DATALINK_ANY_MEDIATYPE },
727
728 { "rxhwclnt-available", { "", 0 }, NULL, 0,
729 NULL, NULL, get_cntavail, NULL, 0,
730 DATALINK_CLASS_ALL, DATALINK_ANY_MEDIATYPE },
731
732 { "txhwclnt-available", { "", 0 }, NULL, 0,
733 NULL, NULL, get_cntavail, NULL, 0,
734 DATALINK_CLASS_ALL, DATALINK_ANY_MEDIATYPE },
735 };
736
737 #define DLADM_MAX_PROPS (sizeof (prop_table) / sizeof (prop_desc_t))
738
739 static resource_prop_t rsrc_prop_table[] = {
740 {"maxbw", extract_maxbw},
741 {"priority", extract_priority},
742 {"cpus", extract_cpus},
743 {"cpus-effective", extract_cpus},
744 {"pool", extract_pool},
745 {"pool-effective", extract_pool},
746 {"protection", extract_protection},
747 {"allowed-ips", extract_allowedips},
748 {"allowed-dhcp-cids", extract_allowedcids},
749 {"rxrings", extract_rxrings},
750 {"rxrings-effective", extract_rxrings},
751 {"txrings", extract_txrings},
752 {"txrings-effective", extract_txrings}
753 };
754 #define DLADM_MAX_RSRC_PROP (sizeof (rsrc_prop_table) / \
2234 mrp->mrp_mask |= MRP_TX_RINGS;
2235
2236 return (DLADM_STATUS_OK);
2237 }
2238
2239 /* ARGSUSED */
2240 static dladm_status_t
2241 get_cntavail(dladm_handle_t handle, prop_desc_t *pdp, datalink_id_t linkid,
2242 char **prop_val, uint_t *val_cnt, datalink_media_t media, uint_t flags,
2243 uint_t *perm_flags)
2244 {
2245 if (flags & DLD_PROP_DEFAULT)
2246 return (DLADM_STATUS_NOTDEFINED);
2247
2248 return (get_uint32(handle, pdp, linkid, prop_val, val_cnt, media,
2249 flags, perm_flags));
2250 }
2251
2252 /* ARGSUSED */
2253 static dladm_status_t
2254 get_macaddr(dladm_handle_t handle, prop_desc_t *pdp, datalink_id_t linkid,
2255 char **prop_val, uint_t *val_cnt, datalink_media_t media, uint_t flags,
2256 uint_t *perm_flags)
2257 {
2258 mac_addrprop_t addrprop;
2259 dladm_status_t status;
2260
2261 status = i_dladm_get_public_prop(handle, linkid, pdp->pd_name,
2262 flags, perm_flags, &addrprop, sizeof (addrprop));
2263 if (status != DLADM_STATUS_OK)
2264 return (status);
2265
2266 (void) _link_ntoa(addrprop.ma_addr, prop_val[0], addrprop.ma_len,
2267 IFT_OTHER);
2268
2269 *val_cnt = 1;
2270
2271 return (DLADM_STATUS_OK);
2272 }
2273
2274 /* ARGSUSED */
2275 static dladm_status_t
2276 set_macaddr(dladm_handle_t handle, prop_desc_t *pdp, datalink_id_t linkid,
2277 val_desc_t *vdp, uint_t val_cnt, uint_t flags, datalink_media_t media)
2278 {
2279 if (val_cnt != 1)
2280 return (DLADM_STATUS_BADVALCNT);
2281
2282 return (set_public_prop(handle, pdp, linkid, vdp, val_cnt,
2283 flags, media));
2284 }
2285
2286 /* ARGSUSED */
2287 static dladm_status_t
2288 check_macaddr(dladm_handle_t handle, prop_desc_t *pdp, datalink_id_t linkid,
2289 char **prop_val, uint_t *val_cntp, uint_t flags, val_desc_t **vdpp,
2290 datalink_media_t media)
2291 {
2292 mac_addrprop_t *addrprop;
2293 val_desc_t *vdp = *vdpp;
2294 uint_t val_cnt = *val_cntp;
2295 uchar_t *macaddr;
2296 int maclen;
2297 dladm_status_t status = DLADM_STATUS_OK;
2298
2299 if (val_cnt != 1)
2300 return (DLADM_STATUS_BADVALCNT);
2301
2302 macaddr = _link_aton(*prop_val, &maclen);
2303 if (macaddr == NULL)
2304 return (DLADM_STATUS_BADVAL);
2305
2306 addrprop = malloc(sizeof (mac_addrprop_t));
2307 if (addrprop == NULL) {
2308 status = DLADM_STATUS_NOMEM;
2309 goto out;
2310 }
2311
2312 (void) memcpy(addrprop->ma_addr, macaddr, maclen);
2313 addrprop->ma_len = maclen;
2314
2315 vdp->vd_val = (uintptr_t)addrprop;
2316
2317 out:
2318 free(macaddr);
2319 return (status);
2320 }
2321
2322 /* ARGSUSED */
2323 static dladm_status_t
2324 set_resource(dladm_handle_t handle, prop_desc_t *pdp,
2325 datalink_id_t linkid, val_desc_t *vdp, uint_t val_cnt,
2326 uint_t flags, datalink_media_t media)
2327 {
2328 mac_resource_props_t mrp;
2329 dladm_status_t status = DLADM_STATUS_OK;
2330 dld_ioc_macprop_t *dip;
2331 int i;
2332
2333 bzero(&mrp, sizeof (mac_resource_props_t));
2334 dip = i_dladm_buf_alloc_by_name(0, linkid, "resource",
2335 flags, &status);
2336
2337 if (dip == NULL)
2338 return (status);
2339
2340 for (i = 0; i < DLADM_MAX_RSRC_PROP; i++) {
2341 resource_prop_t *rp = &rsrc_prop_table[i];
2342
2343 if (strcmp(pdp->pd_name, rp->rp_name) != 0)
|