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 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
27 * This file contains a routine used to validate a ifconfig-style interface
36 #include <libinetutil.h>
39 * Given a token with a logical unit spec, return the logical unit converted
42 * Returns: 0 for success, nonzero if an error occurred. errno is set if
46 getlun(const char *bp
, int bpsize
, uint_t
*lun
)
48 char *ep
= (char *)&bp
[bpsize
- 1];
49 char *sp
= strchr(bp
, ':'), *tp
;
51 /* A logical unit spec looks like: <token>:<unsigned int>\0 */
52 if (isdigit(*bp
) || !isdigit(*ep
) || sp
== NULL
||
53 strchr(sp
+ 1, ':') != NULL
) {
60 /* Lun must be all digits */
61 for (tp
= sp
; tp
< ep
&& isdigit(*tp
); tp
++)
73 * Given a single token ending with a ppa spec, return the ppa spec converted
76 * Returns: 0 for success, nonzero if an error occurred. errno is set if
80 getppa(const char *bp
, int bpsize
, uint_t
*ppa
)
82 char *ep
= (char *)&bp
[bpsize
- 1];
90 for (tp
= ep
; tp
>= bp
&& isdigit(*tp
); tp
--)
103 * Given an ifconfig-style inet relative-path interface specification
104 * (e.g: bge0:2), validate its form and decompose the contents into a
105 * dynamically allocated ifspec_t.
107 * Returns ifspec_t for success, NULL pointer if spec is malformed.
110 ifparse_ifspec(const char *ifname
, ifspec_t
*ifsp
)
113 char ifnamecp
[LIFNAMSIZ
];
115 /* snag a copy we can modify */
116 if (strlcpy(ifnamecp
, ifname
, LIFNAMSIZ
) >= LIFNAMSIZ
) {
121 ifsp
->ifsp_lunvalid
= B_FALSE
;
124 * An interface name must have the format of:
127 * lun - logical unit number.
130 /* Any logical units? */
131 lp
= strchr(ifnamecp
, ':');
133 if (getlun(lp
, strlen(lp
), &ifsp
->ifsp_lun
) != 0)
135 ifsp
->ifsp_lunvalid
= B_TRUE
;
138 (void) strlcpy(ifsp
->ifsp_devnm
, ifnamecp
, LIFNAMSIZ
);
141 if (getppa(ifsp
->ifsp_devnm
, strlen(ifsp
->ifsp_devnm
),
142 &ifsp
->ifsp_ppa
) != 0) {
146 /* strip the ppa off of the device name if present */
147 for (tp
= &ifsp
->ifsp_devnm
[strlen(ifsp
->ifsp_devnm
) - 1];
148 tp
>= ifsp
->ifsp_devnm
&& isdigit(*tp
); tp
--) {