diff options
Diffstat (limited to 'usr/src/lib/libinetutil')
-rw-r--r-- | usr/src/lib/libinetutil/common/ifspec.c | 91 | ||||
-rw-r--r-- | usr/src/lib/libinetutil/common/libinetutil.h | 4 | ||||
-rw-r--r-- | usr/src/lib/libinetutil/common/ofmt.c | 5 | ||||
-rw-r--r-- | usr/src/lib/libinetutil/common/ofmt.h | 2 |
4 files changed, 24 insertions, 78 deletions
diff --git a/usr/src/lib/libinetutil/common/ifspec.c b/usr/src/lib/libinetutil/common/ifspec.c index 157b497efd..7cf41591c5 100644 --- a/usr/src/lib/libinetutil/common/ifspec.c +++ b/usr/src/lib/libinetutil/common/ifspec.c @@ -19,12 +19,10 @@ * CDDL HEADER END */ /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 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 @@ -92,7 +90,7 @@ getppa(const char *bp, int bpsize, uint_t *ppa) for (tp = ep; tp >= bp && isdigit(*tp); tp--) /* Null body */; - if (*tp == '.' || *tp == ':') { + if (*tp == ':') { errno = EINVAL; return (-1); } @@ -103,75 +101,34 @@ getppa(const char *bp, int bpsize, uint_t *ppa) /* * 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. + * (e.g: bge0: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. */ boolean_t ifparse_ifspec(const char *ifname, ifspec_t *ifsp) { - char *mp, *ep, *lp, *tp; - char *ifnamecp; - size_t iflen; - boolean_t have_ppa = B_FALSE; + char *lp, *tp; + char ifnamecp[LIFNAMSIZ]; - iflen = strlen(ifname); - if (iflen > LIFNAMSIZ) { + /* snag a copy we can modify */ + if (strlcpy(ifnamecp, ifname, LIFNAMSIZ) >= LIFNAMSIZ) { errno = EINVAL; return (B_FALSE); } - /* snag a copy we can modify */ - ifnamecp = alloca(iflen + 1); - (void) strlcpy(ifnamecp, ifname, iflen + 1); - ifsp->ifsp_lunvalid = B_FALSE; /* * 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 + * dev[ppa][:lun] * * lun - logical unit number. - * - * Produce substrings for each grouping, starting first with modules, - * then lun, devname, and finally ppa. */ - /* Any modules? */ - mp = strchr(ifnamecp, '.'); - /* Any logical units? */ lp = strchr(ifnamecp, ':'); - - if (lp != NULL && mp != NULL && lp < mp) { - errno = EINVAL; - return (B_FALSE); - } - - ifsp->ifsp_modcnt = 0; - if (mp != NULL) { - *mp++ = '\0'; - if (lp != NULL) - *lp = '\0'; - while (mp != NULL && ifsp->ifsp_modcnt <= IFSP_MAXMODS) { - if ((ep = strchr(mp, '.')) != NULL) - *ep++ = '\0'; - (void) strlcpy(ifsp->ifsp_mods[ifsp->ifsp_modcnt++], - mp, LIFNAMSIZ); - mp = ep; - } - if (lp != NULL) - *lp = ':'; - if (ifsp->ifsp_modcnt > IFSP_MAXMODS) { - errno = E2BIG; - return (B_FALSE); - } - } - if (lp != NULL) { if (getlun(lp, strlen(lp), &ifsp->ifsp_lun) != 0) return (B_FALSE); @@ -180,25 +137,17 @@ ifparse_ifspec(const char *ifname, ifspec_t *ifsp) (void) strlcpy(ifsp->ifsp_devnm, ifnamecp, LIFNAMSIZ); - /* - * Find ppa - has to be part of devname or if modules exist part of - * last module name. - */ - if (ifsp->ifsp_modcnt != 0 && - getppa(ifsp->ifsp_mods[ifsp->ifsp_modcnt - 1], - strlen(ifsp->ifsp_mods[ifsp->ifsp_modcnt - 1]), - &ifsp->ifsp_ppa) == 0) { - have_ppa = B_TRUE; - } else if (ifsp->ifsp_modcnt == 0 && - getppa(ifsp->ifsp_devnm, strlen(ifsp->ifsp_devnm), - &ifsp->ifsp_ppa) == 0) { - have_ppa = B_TRUE; - - /* strip the ppa off of the device name if present */ - for (tp = &ifsp->ifsp_devnm[strlen(ifsp->ifsp_devnm) - 1]; - tp >= ifsp->ifsp_devnm && isdigit(*tp); tp--) - *tp = '\0'; + /* Find ppa */ + if (getppa(ifsp->ifsp_devnm, strlen(ifsp->ifsp_devnm), + &ifsp->ifsp_ppa) != 0) { + return (B_FALSE); + } + + /* strip the ppa off of the device name if present */ + for (tp = &ifsp->ifsp_devnm[strlen(ifsp->ifsp_devnm) - 1]; + tp >= ifsp->ifsp_devnm && isdigit(*tp); tp--) { + *tp = '\0'; } - return (have_ppa); + return (B_TRUE); } diff --git a/usr/src/lib/libinetutil/common/libinetutil.h b/usr/src/lib/libinetutil/common/libinetutil.h index 0bece07e07..bacf64938a 100644 --- a/usr/src/lib/libinetutil/common/libinetutil.h +++ b/usr/src/lib/libinetutil/common/libinetutil.h @@ -43,15 +43,11 @@ extern "C" { #if !defined(_KERNEL) && !defined(_BOOT) -#define IFSP_MAXMODS 9 /* Max modules that can be pushed on if */ - typedef struct { uint_t ifsp_ppa; /* Physical Point of Attachment */ uint_t ifsp_lun; /* Logical Unit number */ boolean_t ifsp_lunvalid; /* TRUE if lun is valid */ - int ifsp_modcnt; /* Number of modules to be pushed */ char ifsp_devnm[LIFNAMSIZ]; /* only the device name */ - char ifsp_mods[IFSP_MAXMODS][LIFNAMSIZ]; /* table of mods */ } ifspec_t; extern boolean_t ifparse_ifspec(const char *, ifspec_t *); diff --git a/usr/src/lib/libinetutil/common/ofmt.c b/usr/src/lib/libinetutil/common/ofmt.c index 2f9fe3f91d..ccae05091c 100644 --- a/usr/src/lib/libinetutil/common/ofmt.c +++ b/usr/src/lib/libinetutil/common/ofmt.c @@ -167,11 +167,12 @@ splitfree(split_t *sp) * Open a handle to be used for printing formatted output. */ ofmt_status_t -ofmt_open(const char *str, ofmt_field_t *template, uint_t flags, +ofmt_open(const char *str, const ofmt_field_t *template, uint_t flags, uint_t maxcols, ofmt_handle_t *ofmt) { split_t *sp; uint_t i, j, of_index; + const ofmt_field_t *ofp; ofmt_field_t *of; ofmt_state_t *os; int nfields = 0; @@ -192,7 +193,7 @@ ofmt_open(const char *str, ofmt_field_t *template, uint_t flags, } if (template == NULL) return (OFMT_ENOTEMPLATE); - for (of = template; of->of_name != NULL; of++) + for (ofp = template; ofp->of_name != NULL; ofp++) nfields++; /* * split str into the columns selected, or construct the diff --git a/usr/src/lib/libinetutil/common/ofmt.h b/usr/src/lib/libinetutil/common/ofmt.h index ff03b80ae0..a477847917 100644 --- a/usr/src/lib/libinetutil/common/ofmt.h +++ b/usr/src/lib/libinetutil/common/ofmt.h @@ -165,7 +165,7 @@ typedef struct ofmt_field_s { * for the handle are freed by ofmt_close(); */ typedef struct ofmt_state_s *ofmt_handle_t; -extern ofmt_status_t ofmt_open(const char *, ofmt_field_t *, uint_t, +extern ofmt_status_t ofmt_open(const char *, const ofmt_field_t *, uint_t, uint_t, ofmt_handle_t *); #define OFMT_PARSABLE 0x00000001 /* machine parsable mode */ |