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]
23 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
33 #include <libdllink.h>
35 extern dladm_status_t
dladm_door_fd(dladm_handle_t
, int *);
38 ibd_dladm_door_call(dladm_handle_t handle
, void *arg
, size_t asize
, void *rbuf
,
43 dladm_status_t status
= DLADM_STATUS_OK
;
46 darg
.data_size
= asize
;
52 /* The door descriptor is opened if it isn't already */
53 if ((status
= dladm_door_fd(handle
, &door_fd
)) != DLADM_STATUS_OK
)
56 if (door_call(door_fd
, &darg
) == -1)
57 return (DLADM_STATUS_FAILED
);
59 if (darg
.rbuf
!= rbuf
) {
61 * The size of the input rbuf is not big enough so that
62 * the door allocate the rbuf itself. In this case, simply
63 * think something wrong with the door call.
65 (void) munmap(darg
.rbuf
, darg
.rsize
);
66 return (DLADM_STATUS_TOOSMALL
);
69 if (darg
.rsize
!= rsize
)
70 return (DLADM_STATUS_FAILED
);
72 if ((((dlmgmt_retval_t
*)rbuf
)->lr_err
) == 0)
73 return (DLADM_STATUS_OK
);
75 return (DLADM_STATUS_FAILED
);
79 ibd_delete_link(dladm_handle_t dlh
, char *link
)
81 dlmgmt_door_getlinkid_t getlinkid
;
82 dlmgmt_getlinkid_retval_t retval
;
84 dladm_status_t status
;
85 char errmsg
[DLADM_STRSIZE
];
87 getlinkid
.ld_cmd
= DLMGMT_CMD_GETLINKID
;
88 (void) strlcpy(getlinkid
.ld_link
, link
, MAXLINKNAMELEN
);
90 if ((status
= ibd_dladm_door_call(dlh
, &getlinkid
, sizeof (getlinkid
),
91 &retval
, sizeof (retval
))) != DLADM_STATUS_OK
) {
92 (void) fprintf(stderr
,
93 "dladm_door_call failed: %s; linkname = %s\n",
94 dladm_status2str(status
, errmsg
), link
);
98 if (retval
.lr_class
!= DATALINK_CLASS_PHYS
) {
99 (void) fprintf(stderr
,
100 "Not a physical link: linkname = %s, class = 0x%x\n",
101 link
, (uint_t
)retval
.lr_class
);
105 linkid
= retval
.lr_linkid
;
107 if ((status
= dladm_remove_conf(dlh
, linkid
)) != DLADM_STATUS_OK
) {
108 (void) fprintf(stderr
, "dladm_remove_conf failed: %s\n",
109 dladm_status2str(status
, errmsg
));
113 if ((status
= dladm_destroy_datalink_id(dlh
, linkid
,
114 DLADM_OPT_ACTIVE
| DLADM_OPT_PERSIST
)) != DLADM_STATUS_OK
) {
115 (void) fprintf(stderr
, "dladm_destroy_datalink_id failed: %s\n",
116 dladm_status2str(status
, errmsg
));
123 main(int argc
, char *argv
[])
127 dladm_status_t status
;
128 char errmsg
[DLADM_STRSIZE
];
131 (void) fprintf(stderr
,
132 "Usage: ibd_delete_link linkname ...\n");
136 if ((status
= dladm_open(&dlh
)) != DLADM_STATUS_OK
) {
137 (void) fprintf(stderr
, "Failed to open dladm handle: %s\n",
138 dladm_status2str(status
, errmsg
));
142 for (i
= 1; i
< argc
; i
++) {
143 if (ibd_delete_link(dlh
, argv
[i
]) != DLADM_STATUS_OK
) {