3 *
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.
7 *
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.
12 *
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]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright 2015 Joyent, Inc.
24 * Copyright 2016 OmniTI Computer Consulting, Inc. All rights reserved.
25 */
26
27 #include <sys/types.h>
28 #include <sys/cred.h>
29 #include <sys/sysmacros.h>
30 #include <sys/conf.h>
31 #include <sys/cmn_err.h>
32 #include <sys/list.h>
33 #include <sys/ksynch.h>
34 #include <sys/kmem.h>
35 #include <sys/stream.h>
36 #include <sys/modctl.h>
37 #include <sys/ddi.h>
38 #include <sys/sunddi.h>
39 #include <sys/atomic.h>
40 #include <sys/stat.h>
41 #include <sys/modhash.h>
42 #include <sys/strsubr.h>
43 #include <sys/strsun.h>
337 /* ARGSUSED */
338 int
339 vnic_dev_create(datalink_id_t vnic_id, datalink_id_t linkid,
340 vnic_mac_addr_type_t *vnic_addr_type, int *mac_len, uchar_t *mac_addr,
341 int *mac_slot, uint_t mac_prefix_len, uint16_t vid, vrid_t vrid,
342 int af, mac_resource_props_t *mrp, uint32_t flags, vnic_ioc_diag_t *diag,
343 cred_t *credp)
344 {
345 vnic_t *vnic;
346 mac_register_t *mac;
347 int err;
348 boolean_t is_anchor = ((flags & VNIC_IOC_CREATE_ANCHOR) != 0);
349 char vnic_name[MAXNAMELEN];
350 const mac_info_t *minfop;
351 uint32_t req_hwgrp_flag = B_FALSE;
352
353 *diag = VNIC_IOC_DIAG_NONE;
354
355 rw_enter(&vnic_lock, RW_WRITER);
356
357 /* does a VNIC with the same id already exist? */
358 err = mod_hash_find(vnic_hash, VNIC_HASH_KEY(vnic_id),
359 (mod_hash_val_t *)&vnic);
360 if (err == 0) {
361 rw_exit(&vnic_lock);
362 return (EEXIST);
363 }
364
365 vnic = kmem_cache_alloc(vnic_cache, KM_NOSLEEP);
366 if (vnic == NULL) {
367 rw_exit(&vnic_lock);
368 return (ENOMEM);
369 }
370
371 bzero(vnic, sizeof (*vnic));
372
373 vnic->vn_ls = LINK_STATE_UNKNOWN;
374 vnic->vn_id = vnic_id;
375 vnic->vn_link_id = linkid;
376 vnic->vn_vrid = vrid;
377 vnic->vn_af = af;
|
3 *
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.
7 *
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.
12 *
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]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright 2018 Joyent, Inc.
24 * Copyright 2016 OmniTI Computer Consulting, Inc. All rights reserved.
25 */
26
27 #include <sys/types.h>
28 #include <sys/cred.h>
29 #include <sys/sysmacros.h>
30 #include <sys/conf.h>
31 #include <sys/cmn_err.h>
32 #include <sys/list.h>
33 #include <sys/ksynch.h>
34 #include <sys/kmem.h>
35 #include <sys/stream.h>
36 #include <sys/modctl.h>
37 #include <sys/ddi.h>
38 #include <sys/sunddi.h>
39 #include <sys/atomic.h>
40 #include <sys/stat.h>
41 #include <sys/modhash.h>
42 #include <sys/strsubr.h>
43 #include <sys/strsun.h>
337 /* ARGSUSED */
338 int
339 vnic_dev_create(datalink_id_t vnic_id, datalink_id_t linkid,
340 vnic_mac_addr_type_t *vnic_addr_type, int *mac_len, uchar_t *mac_addr,
341 int *mac_slot, uint_t mac_prefix_len, uint16_t vid, vrid_t vrid,
342 int af, mac_resource_props_t *mrp, uint32_t flags, vnic_ioc_diag_t *diag,
343 cred_t *credp)
344 {
345 vnic_t *vnic;
346 mac_register_t *mac;
347 int err;
348 boolean_t is_anchor = ((flags & VNIC_IOC_CREATE_ANCHOR) != 0);
349 char vnic_name[MAXNAMELEN];
350 const mac_info_t *minfop;
351 uint32_t req_hwgrp_flag = B_FALSE;
352
353 *diag = VNIC_IOC_DIAG_NONE;
354
355 rw_enter(&vnic_lock, RW_WRITER);
356
357 /* Does a VNIC with the same id already exist? */
358 err = mod_hash_find(vnic_hash, VNIC_HASH_KEY(vnic_id),
359 (mod_hash_val_t *)&vnic);
360 if (err == 0) {
361 rw_exit(&vnic_lock);
362 return (EEXIST);
363 }
364
365 vnic = kmem_cache_alloc(vnic_cache, KM_NOSLEEP);
366 if (vnic == NULL) {
367 rw_exit(&vnic_lock);
368 return (ENOMEM);
369 }
370
371 bzero(vnic, sizeof (*vnic));
372
373 vnic->vn_ls = LINK_STATE_UNKNOWN;
374 vnic->vn_id = vnic_id;
375 vnic->vn_link_id = linkid;
376 vnic->vn_vrid = vrid;
377 vnic->vn_af = af;
|