ifspec.c revision c7e4935f5b755b4bbeaec416f1ad24337aeac7a4
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* This file contains a routine used to validate a ifconfig-style interface
* specification
*/
#include <stdlib.h>
#include <ctype.h>
#include <alloca.h>
#include <errno.h>
#include <string.h>
#include <libinetutil.h>
/*
* Given a token with a logical unit spec, return the logical unit converted
* to a uint_t.
*
* Returns: 0 for success, nonzero if an error occurred. errno is set if
* necessary.
*/
static int
{
/* A logical unit spec looks like: <token>:<unsigned int>\0 */
return (-1);
}
*sp++ = '\0';
/* Lun must be all digits */
/* Null body */;
return (-1);
}
return (0);
}
/*
* Given a single token ending with a ppa spec, return the ppa spec converted
* to a uint_t.
*
* Returns: 0 for success, nonzero if an error occurred. errno is set if
* necessary.
*/
static int
{
char *tp;
return (-1);
}
/* Null body */;
return (-1);
}
return (0);
}
/*
* Given an ifconfig-style inet relative-path interface specification
* (e.g: hme.[module].[module][PPA]:2), validate its form and decompose the
* contents into a dynamically allocated ifspec_t.
*
* Returns ifspec_t for success, NULL pointer if spec is malformed.
*/
{
char *ifnamecp;
return (B_FALSE);
}
/* snag a copy we can modify */
/*
* An interface name must have the format of:
* dev[.module[.module...]][ppa][:lun]
*
* where the ppa must be specified at the end of the interface name.
* e.g. ip.foo.tun0
*
* lun - logical unit number.
*
* Produce substrings for each grouping, starting first with modules,
* then lun, devname, and finally ppa.
*/
/* Any modules? */
/* Any logical units? */
return (B_FALSE);
}
ifsp->ifsp_modcnt = 0;
*mp++ = '\0';
*lp = '\0';
*ep++ = '\0';
}
*lp = ':';
return (B_FALSE);
}
}
return (B_FALSE);
}
/*
* Find ppa - has to be part of devname or if modules exist part of
* last module name.
*/
if (ifsp->ifsp_modcnt != 0 &&
} else if (ifsp->ifsp_modcnt == 0 &&
/* strip the ppa off of the device name if present */
*tp = '\0';
}
return (have_ppa);
}