diff options
author | meem <none@none> | 2008-02-05 16:37:18 -0800 |
---|---|---|
committer | meem <none@none> | 2008-02-05 16:37:18 -0800 |
commit | f7d61273153286ce87ee33b9834053a95b15fc39 (patch) | |
tree | 9d39f190b405751c5a4612b97447c59c276c9304 /usr | |
parent | 9e6eda553d3d6d77b83da5c596c89990d82bd485 (diff) | |
download | illumos-gate-f7d61273153286ce87ee33b9834053a95b15fc39.tar.gz |
6522970 ifparse (ifconfig cousin) should also known about DHCPv6
6636949 ifconfig's logical interface handling can be improved
6636958 ifconfig's Perror() logic is bloated, inconsistent, and unconstified
6636965 dhcpagent`lookup_pif_by_index() can be eliminated
6636971 dhcpagent`unplumb_lif() spuriously clears lif_flags
6636981 dhcpagent`insert_pif() could be simplified a bit
6636992 ifparse has grown stale
Diffstat (limited to 'usr')
-rw-r--r-- | usr/src/cmd/cmd-inet/sbin/dhcpagent/interface.c | 110 | ||||
-rw-r--r-- | usr/src/cmd/cmd-inet/sbin/dhcpagent/interface.h | 3 | ||||
-rw-r--r-- | usr/src/cmd/cmd-inet/sbin/dhcpagent/request.c | 29 | ||||
-rw-r--r-- | usr/src/cmd/cmd-inet/sbin/ifparse/ifparse.c | 75 | ||||
-rw-r--r-- | usr/src/cmd/cmd-inet/usr.sbin/ifconfig/ifconfig.c | 139 | ||||
-rw-r--r-- | usr/src/cmd/cmd-inet/usr.sbin/ifconfig/ifconfig.h | 10 |
6 files changed, 129 insertions, 237 deletions
diff --git a/usr/src/cmd/cmd-inet/sbin/dhcpagent/interface.c b/usr/src/cmd/cmd-inet/sbin/dhcpagent/interface.c index e20ff9f175..5d0f251253 100644 --- a/usr/src/cmd/cmd-inet/sbin/dhcpagent/interface.c +++ b/usr/src/cmd/cmd-inet/sbin/dhcpagent/interface.c @@ -19,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -79,6 +79,7 @@ insert_pif(const char *pname, boolean_t isv6, int *error) dhcp_pif_t *pif; struct lifreq lifr; dlpi_handle_t dh = NULL; + int fd = isv6 ? v6_sock_fd : v4_sock_fd; if ((pif = calloc(1, sizeof (*pif))) == NULL) { dhcpmsg(MSG_ERR, "insert_pif: cannot allocate pif entry for " @@ -98,20 +99,43 @@ insert_pif(const char *pname, boolean_t isv6, int *error) goto failure; } - /* We do not use DLPI with DHCPv6 */ - if (!isv6) { - int rc; - dlpi_info_t dlinfo; + /* + * This is a bit gross, but IP has a confused interface. We must + * assume that the zeroth LIF is plumbed, and must query there to get + * the interface index number. + */ + (void) strlcpy(lifr.lifr_name, pname, LIFNAMSIZ); - /* - * Do the allocations necessary for IPv4 DHCP. - * - * 1. open the interface using DLPI - * 2. get the interface hardware type and hardware length - * 3. get the interface hardware address - */ + if (ioctl(fd, SIOCGLIFINDEX, &lifr) == -1) { + *error = (errno == ENXIO) ? DHCP_IPC_E_INVIF : DHCP_IPC_E_INT; + dhcpmsg(MSG_ERR, "insert_pif: SIOCGLIFINDEX for %s", pname); + goto failure; + } + pif->pif_index = lifr.lifr_index; + + if (ioctl(fd, SIOCGLIFMTU, &lifr) == -1) { + *error = (errno == ENXIO) ? DHCP_IPC_E_INVIF : DHCP_IPC_E_INT; + dhcpmsg(MSG_ERR, "insert_pif: SIOCGLIFMTU for %s", pname); + goto failure; + } + pif->pif_max = lifr.lifr_mtu; + + if (pif->pif_max < DHCP_DEF_MAX_SIZE) { + dhcpmsg(MSG_ERROR, "insert_pif: MTU of %s is too small to " + "support DHCP (%u < %u)", pname, pif->pif_max, + DHCP_DEF_MAX_SIZE); + *error = DHCP_IPC_E_INVIF; + goto failure; + } + + /* + * For IPv4, use DLPI to determine the hardware type, hardware + * address, and hardware address length. + */ + if (!isv6) { + int rc; + dlpi_info_t dlinfo; - /* step 1 */ if ((rc = dlpi_open(pname, &dh, 0)) != DLPI_SUCCESS) { dhcpmsg(MSG_ERROR, "insert_pif: dlpi_open: %s", dlpi_strerror(rc)); @@ -126,9 +150,7 @@ insert_pif(const char *pname, boolean_t isv6, int *error) goto failure; } - /* step 2 */ - rc = dlpi_info(dh, &dlinfo, 0); - if (rc != DLPI_SUCCESS) { + if ((rc = dlpi_info(dh, &dlinfo, 0)) != DLPI_SUCCESS) { dhcpmsg(MSG_ERROR, "insert_pif: dlpi_info: %s", dlpi_strerror(rc)); *error = DHCP_IPC_E_INVIF; @@ -141,7 +163,6 @@ insert_pif(const char *pname, boolean_t isv6, int *error) dhcpmsg(MSG_DEBUG, "insert_pif: %s: hwtype %d, hwlen %d", pname, pif->pif_hwtype, pif->pif_hwlen); - /* step 3 */ if (pif->pif_hwlen > 0) { pif->pif_hwaddr = malloc(pif->pif_hwlen); if (pif->pif_hwaddr == NULL) { @@ -158,39 +179,9 @@ insert_pif(const char *pname, boolean_t isv6, int *error) dh = NULL; } - /* - * This is a bit gross, but IP has a confused interface. We must - * assume that the zeroth LIF is plumbed, and must query there to get - * the interface index number. - */ - (void) strlcpy(lifr.lifr_name, pname, LIFNAMSIZ); - - if (ioctl(isv6 ? v6_sock_fd : v4_sock_fd, SIOCGLIFINDEX, &lifr) == -1) { - *error = (errno == ENXIO) ? DHCP_IPC_E_INVIF : DHCP_IPC_E_INT; - dhcpmsg(MSG_ERR, "insert_pif: SIOCGLIFINDEX for %s", pname); - goto failure; - } - pif->pif_index = lifr.lifr_index; - - if (ioctl(isv6 ? v6_sock_fd : v4_sock_fd, SIOCGLIFMTU, &lifr) == -1) { - *error = (errno == ENXIO) ? DHCP_IPC_E_INVIF : DHCP_IPC_E_INT; - dhcpmsg(MSG_ERR, "insert_pif: SIOCGLIFMTU for %s", pname); - goto failure; - } - pif->pif_max = lifr.lifr_mtu; - - if (pif->pif_max < DHCP_DEF_MAX_SIZE) { - dhcpmsg(MSG_ERROR, "insert_pif: MTU of %s is too small to " - "support DHCP (%u < %u)", pname, pif->pif_max, - DHCP_DEF_MAX_SIZE); - *error = DHCP_IPC_E_INVIF; - goto failure; - } - insque(pif, isv6 ? &v6root : &v4root); return (pif); - failure: if (dh != NULL) dlpi_close(dh); @@ -243,27 +234,6 @@ release_pif(dhcp_pif_t *pif) } /* - * lookup_pif_by_index(): Looks up PIF entries given regular ifIndex. - * - * input: uint_t: the interface index - * boolean_t: B_TRUE if using DHCPv6, B_FALSE otherwise - * output: dhcp_pif_t *: the matching PIF, or NULL if not found - */ - -dhcp_pif_t * -lookup_pif_by_index(uint_t ifindex, boolean_t isv6) -{ - dhcp_pif_t *pif; - - for (pif = isv6 ? v6root : v4root; pif != NULL; pif = pif->pif_next) { - if (pif->pif_index == ifindex) - break; - } - - return (pif); -} - -/* * lookup_pif_by_uindex(): Looks up PIF entries given truncated index and * previous PIF pointer (or NULL for list start). * Caller is expected to iterate through all @@ -582,8 +552,6 @@ remove_lif(dhcp_lif_t *lif) dlp->dl_lifs = NULL; else if (dlp->dl_lifs == lif) dlp->dl_lifs = lifnext; - if (lif->lif_flags & IFF_DHCPRUNNING) - clear_lif_dhcp(lif); if (lif->lif_declined != NULL) { dlp->dl_smach->dsm_lif_down--; lif->lif_declined = NULL; @@ -1012,7 +980,7 @@ unplumb_lif(dhcp_lif_t *lif) } lif->lif_plumbed = B_FALSE; } - lif->lif_flags = 0; + /* * Special case: if we're "unplumbing" the main LIF for DHCPv4, then * just canonize it and remove it from the lease. diff --git a/usr/src/cmd/cmd-inet/sbin/dhcpagent/interface.h b/usr/src/cmd/cmd-inet/sbin/dhcpagent/interface.h index f68e849ec9..a59e3ea68d 100644 --- a/usr/src/cmd/cmd-inet/sbin/dhcpagent/interface.h +++ b/usr/src/cmd/cmd-inet/sbin/dhcpagent/interface.h @@ -19,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -166,7 +166,6 @@ extern dhcp_pif_t *v6root; dhcp_pif_t *insert_pif(const char *, boolean_t, int *); void hold_pif(dhcp_pif_t *); void release_pif(dhcp_pif_t *); -dhcp_pif_t *lookup_pif_by_index(uint_t, boolean_t); dhcp_pif_t *lookup_pif_by_uindex(uint16_t, dhcp_pif_t *, boolean_t); dhcp_pif_t *lookup_pif_by_name(const char *, boolean_t); void pif_status(dhcp_pif_t *, boolean_t); diff --git a/usr/src/cmd/cmd-inet/sbin/dhcpagent/request.c b/usr/src/cmd/cmd-inet/sbin/dhcpagent/request.c index 9782d1480c..a8c05de986 100644 --- a/usr/src/cmd/cmd-inet/sbin/dhcpagent/request.c +++ b/usr/src/cmd/cmd-inet/sbin/dhcpagent/request.c @@ -19,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. * * REQUESTING state of the client state machine. @@ -992,19 +992,11 @@ dhcp_acknak_global(iu_eh_t *ehp, int fd, short events, iu_event_id_t id, if (plp == NULL) return; - pif = lookup_pif_by_index(plp->ifindex, isv6); - if (pif == NULL) { - dhcpmsg(MSG_VERBOSE, "dhcp_acknak_global: ignored packet " - "received on v%d ifIndex %d", isv6 ? 6 : 4, plp->ifindex); - free_pkt_entry(plp); - return; - } - recv_type = pkt_recv_type(plp); pname = pkt_type_to_string(recv_type, isv6); /* - * Find the corresponding state machine. + * Find the corresponding state machine and pif. * * Note that DHCPv6 Reconfigure would be special: it's not the reply to * any transaction, and thus we would need to search on transaction ID @@ -1012,19 +1004,24 @@ dhcp_acknak_global(iu_eh_t *ehp, int fd, short events, iu_event_id_t id, * is not yet supported. */ xid = pkt_get_xid(plp->pkt, isv6); - if (!isv6 && !pkt_v4_match(recv_type, DHCP_PACK|DHCP_PNAK)) { - reason = "not ACK or NAK"; - goto drop; - } for (dsmp = lookup_smach_by_xid(xid, NULL, isv6); dsmp != NULL; dsmp = lookup_smach_by_xid(xid, dsmp, isv6)) { - if (dsmp->dsm_lif->lif_pif == pif) + pif = dsmp->dsm_lif->lif_pif; + if (pif->pif_index == plp->ifindex) break; } if (dsmp == NULL) { - reason = "unknown state machine"; + dhcpmsg(MSG_VERBOSE, "dhcp_acknak_global: ignored v%d %s packet" + " on ifindex %d: unknown state machine", isv6 ? 6 : 4, + pname, plp->ifindex); + free_pkt_entry(plp); + return; + } + + if (!isv6 && !pkt_v4_match(recv_type, DHCP_PACK|DHCP_PNAK)) { + reason = "not ACK or NAK"; goto drop; } diff --git a/usr/src/cmd/cmd-inet/sbin/ifparse/ifparse.c b/usr/src/cmd/cmd-inet/sbin/ifparse/ifparse.c index fbaf842d3c..47e1202b32 100644 --- a/usr/src/cmd/cmd-inet/sbin/ifparse/ifparse.c +++ b/usr/src/cmd/cmd-inet/sbin/ifparse/ifparse.c @@ -1,5 +1,5 @@ /* - * Copyright 2000-2003 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* @@ -12,8 +12,7 @@ /* * Ifparse splits up an ifconfig command line, and was written for use - * with the networking boot script /etc/init.d/network (which is in the - * source tree as usr/src/cmd/initpkg/init.d/network). + * with the networking boot scripts; see $SRC/cmd/svc/shell/net_include.sh * * Ifparse can extract selected parts of the ifconfig command line, * such as failover address configuration ("ifparse -f"), or everything @@ -98,7 +97,8 @@ typedef enum { AF_UNSPEC, AF_INET, AF_INET6, AF_ANY } ac_t; -#define NEXTARG (-1) +#define NEXTARG (-1) /* command takes an argument */ +#define OPTARG (-2) /* command takes an optional argument */ #define END_OF_TABLE (-1) @@ -131,9 +131,9 @@ boolean_t addint = _B_FALSE; /* * The parser table is based on that in ifconfig. A command may or - * may not have an argument, as indicated by whether NEXTARG is in the - * second column. Some commands can only be used with certain address - * families, as indicated in the third column. The fourth column + * may not have an argument, as indicated by whether NEXTARG/OPTARG is + * in the second column. Some commands can only be used with certain + * address families, as indicated in the third column. The fourth column * contains flags that control parser action. * * Ifparse buffers logical interface configuration commands such as "set", @@ -207,14 +207,13 @@ struct cmd { { "encaplimit", NEXTARG, AF_ANY, PARSELOG0 }, { "-encaplimit", 0, AF_ANY, PARSELOG0 }, { "thoplimit", NEXTARG, AF_ANY, PARSELOG0 }, -#ifdef DEBUG - { "getnd", NEXTARG, AF_INET6, PARSELOG0 }, - { "setnd", NEXTARG, AF_INET6, PARSELOG0 }, - { "delnd", NEXTARG, AF_INET6, PARSELOG0 }, -#endif -/* XXX for testing SIOCT* ioctls. Remove */ { "set", NEXTARG, AF_ANY, PARSESET }, { "destination", NEXTARG, AF_ANY, 0 }, + { "zone", NEXTARG, AF_ANY, 0 }, + { "-zone", 0, AF_ANY, 0 }, + { "all-zones", 0, AF_ANY, 0 }, + { "ether", OPTARG, AF_ANY, PARSENOW }, + { "usesrc", NEXTARG, AF_ANY, PARSENOW }, { 0 /* ether addr */, 0, AF_UNSPEC, PARSELOG0 }, { 0 /* set */, 0, AF_ANY, PARSESET }, { 0 /* destination */, 0, AF_ANY, 0 }, @@ -274,10 +273,8 @@ parse_dump_buf(void) * If we get to the end of the command, and haven't seen a * "failover" or "-failover" flag, the command is movable. */ - if (!((parsemode == PARSEFIXED) && - (parsetype & PARSEMOVABLE) != 0) && - (parsemode & parsetype) != 0 && - parsedumplen != 0) { + if (!((parsemode == PARSEFIXED) && (parsetype & PARSEMOVABLE) != 0) && + (parsemode & parsetype) != 0 && parsedumplen != 0) { unsigned i; if (parsebuf[parsedumplen] == ' ') @@ -361,7 +358,7 @@ parsedump(char *cmd, int param, int flags, char *arg) } else cmdname = ""; } else { - cmdarg = (param == NEXTARG) ? arg : NULL; + cmdarg = (param == 0) ? NULL : arg; cmdname = cmd; } @@ -433,32 +430,22 @@ parsedump(char *cmd, int param, int flags, char *arg) static int ifparse(int argc, char *argv[], struct afswtch *afp) { - int af; + int af = afp->af_af; - if (argc == 0) { + if (argc == 0) return (0); - } - - af = afp->af_af; if (strcmp(*argv, "auto-dhcp") == 0 || strcmp(*argv, "dhcp") == 0) { - if (af == AF_INET) { - if ((parsemode & PARSEFIXED) != NULL) { - while (argc) { - (void) fputs(*argv++, stdout); - if (--argc != 0) - (void) fputc(' ', stdout); - else - (void) fputc('\n', stdout); - } + if ((parsemode & PARSEFIXED) != NULL) { + while (argc) { + (void) fputs(*argv++, stdout); + if (--argc != 0) + (void) fputc(' ', stdout); + else + (void) fputc('\n', stdout); } - return (0); - } else { - (void) fprintf(stderr, "ifparse: dhcp not supported " - "for inet6\n"); - - return (1); } + return (0); } while (argc > 0) { @@ -504,15 +491,17 @@ ifparse(int argc, char *argv[], struct afswtch *afp) p++; /* got src, do dst */ assert(p->c_parseflags != END_OF_TABLE); } - if (p->c_parameter == NEXTARG) { + + if (p->c_parameter == NEXTARG || p->c_parameter == OPTARG) { argc--, argv++; - if (argc == 0) { + if (argc == 0 && p->c_parameter == NEXTARG) { (void) fprintf(stderr, "ifparse: no argument for %s\n", p->c_name); return (1); } } + /* * Dump the command if: * @@ -523,8 +512,8 @@ ifparse(int argc, char *argv[], struct afswtch *afp) * the address families match */ if ((p->c_af == AF_ANY) || (af == p->c_af)) - parsedump(p->c_name, p->c_parameter, - p->c_parseflags, *argv); + parsedump(p->c_name, p->c_parameter, p->c_parseflags, + *argv); argc--, argv++; } parse_dump_buf(); @@ -539,7 +528,7 @@ static void usage(void) { (void) fprintf(stderr, - "usage: ifparse [ -fs ] <addr_family> <commands>\n"); + "usage: ifparse [ -fs ] <addr_family> <commands>\n"); } int diff --git a/usr/src/cmd/cmd-inet/usr.sbin/ifconfig/ifconfig.c b/usr/src/cmd/cmd-inet/usr.sbin/ifconfig/ifconfig.c index 877d275947..1e5dfb3497 100644 --- a/usr/src/cmd/cmd-inet/usr.sbin/ifconfig/ifconfig.c +++ b/usr/src/cmd/cmd-inet/usr.sbin/ifconfig/ifconfig.c @@ -185,7 +185,6 @@ static int setifdhcp(const char *caller, const char *ifname, static int ip_domux2fd(int *, int *, int *, int *, int *); static int ip_plink(int, int, int, int, int); static int modop(char *arg, char op); -static int get_lun(char *); static void selectifs(int argc, char *argv[], int af, struct lifreq *lifrp); static int updownifs(iface_t *ifs, int up); @@ -284,6 +283,12 @@ struct cmd { { "all-zones", 0, setallzones, 0, AF_ANY }, { "ether", OPTARG, setifether, 0, AF_ANY }, { "usesrc", NEXTARG, setifsrc, 0, AF_ANY }, + + /* + * NOTE: any additions to this table must also be applied to ifparse + * (usr/src/cmd/cmd-inet/sbin/ifparse/ifparse.c) + */ + { 0, 0, setifaddr, 0, AF_ANY }, { 0, 0, setifdstaddr, 0, AF_ANY }, { 0, 0, 0, 0, 0 }, @@ -3483,15 +3488,11 @@ in6_status(int force, uint64_t flags) lifr.lifr_ifinfo.lir_maxmtu); } } - /* If there is a groupname, print it for lun 0 alone */ + /* If there is a groupname, print it for only the physical interface */ if (strchr(name, ':') == NULL) { - (void) memset(lifr.lifr_groupname, 0, - sizeof (lifr.lifr_groupname)); - if (ioctl(s, SIOCGLIFGROUPNAME, (caddr_t)&lifr) >= 0) { - if (strlen(lifr.lifr_groupname) > 0) { - (void) printf("\n\tgroupname %s", - lifr.lifr_groupname); - } + if (ioctl(s, SIOCGLIFGROUPNAME, &lifr) >= 0 && + lifr.lifr_groupname[0] != '\0') { + (void) printf("\n\tgroupname %s", lifr.lifr_groupname); } } (void) putchar('\n'); @@ -3523,7 +3524,7 @@ in_configinfo(int force, uint64_t flags) Perror0_exit("in_configinfo: SIOCGLIFADDR"); } sin = (struct sockaddr_in *)&lifr.lifr_addr; - if (get_lun(name) != 0) { + if (strchr(name, ':') != NULL) { (void) printf(" addif %s ", inet_ntoa(sin->sin_addr)); } else { (void) printf(" set %s ", inet_ntoa(sin->sin_addr)); @@ -3587,15 +3588,11 @@ in_configinfo(int force, uint64_t flags) } } - /* If there is a groupname, print it for lun 0 alone */ - if (get_lun(name) == 0) { - (void) memset(lifr.lifr_groupname, 0, - sizeof (lifr.lifr_groupname)); - if (ioctl(s, SIOCGLIFGROUPNAME, (caddr_t)&lifr) >= 0) { - if (strlen(lifr.lifr_groupname) > 0) { - (void) printf(" group %s ", - lifr.lifr_groupname); - } + /* If there is a groupname, print it for only the physical interface */ + if (strchr(name, ':') == NULL) { + if (ioctl(s, SIOCGLIFGROUPNAME, &lifr) >= 0 && + lifr.lifr_groupname[0] != '\0') { + (void) printf(" group %s ", lifr.lifr_groupname); } } @@ -3634,7 +3631,7 @@ in6_configinfo(int force, uint64_t flags) Perror0_exit("in6_configinfo: SIOCGLIFADDR"); } sin6 = (struct sockaddr_in6 *)&lifr.lifr_addr; - if (get_lun(name) != 0) { + if (strchr(name, ':') != NULL) { (void) printf(" addif %s/%d ", inet_ntop(AF_INET6, (void *)&sin6->sin6_addr, abuf, sizeof (abuf)), @@ -3697,15 +3694,11 @@ in6_configinfo(int force, uint64_t flags) lifr.lifr_addrlen); } - /* If there is a groupname, print it for lun 0 alone */ - if (get_lun(name) == 0) { - (void) memset(lifr.lifr_groupname, 0, - sizeof (lifr.lifr_groupname)); - if (ioctl(s, SIOCGLIFGROUPNAME, (caddr_t)&lifr) >= 0) { - if (strlen(lifr.lifr_groupname) > 0) { - (void) printf(" group %s ", - lifr.lifr_groupname); - } + /* If there is a groupname, print it for only the physical interface */ + if (strchr(name, ':') == NULL) { + if (ioctl(s, SIOCGLIFGROUPNAME, &lifr) >= 0 && + lifr.lifr_groupname[0] != '\0') { + (void) printf(" group %s ", lifr.lifr_groupname); } } @@ -3718,25 +3711,6 @@ in6_configinfo(int force, uint64_t flags) } } -/* ARGSUSED */ -static int -get_lun(char *rsrc) -{ - char resource[LIFNAMSIZ]; - char *cp; - - (void) strcpy(resource, rsrc); - - /* remove LIF component */ - cp = strchr(resource, ':'); - if (cp) { - cp++; - return (atoi(cp)); - } - - return (0); -} - /* * We need to plink both the arp-device stream and the arp-ip-device stream. * However the muxid is stored only in IP. Plumbing 2 streams individually @@ -3840,7 +3814,7 @@ plumb_one_device(int af) /* * This difference between the way we behave for EEXIST * and that with other errors exists to preserve legacy - * behaviour. Earlier when foreachinterface() and matcif() + * behaviour. Earlier when foreachinterface() and matchif() * were doing the duplicate interface name checks, for * already existing interfaces, inetplumb() returned "0". * To preserve this behaviour, Perror0() and return are @@ -4136,42 +4110,13 @@ inetplumb(char *arg, int64_t param) } void -Perror0(char *cmd) +Perror0(const char *cmd) { - int save_errno; - - save_errno = errno; - (void) fprintf(stderr, "ifconfig: "); - errno = save_errno; - switch (errno) { - - case ENXIO: - (void) fprintf(stderr, "%s: %s: no such interface\n", - cmd, lifr.lifr_name); - break; - - case EPERM: - (void) fprintf(stderr, "%s: %s: permission denied\n", - cmd, lifr.lifr_name); - break; - - case EEXIST: - (void) fprintf(stderr, "%s: %s: already exists\n", - cmd, lifr.lifr_name); - break; - - default: { - char buf[BUFSIZ]; - - (void) snprintf(buf, sizeof (buf), "%s: %s", - cmd, lifr.lifr_name); - perror(buf); - } - } + Perror2(cmd, lifr.lifr_name); } void -Perror0_exit(char *cmd) +Perror0_exit(const char *cmd) { Perror0(cmd); exit(1); @@ -4179,31 +4124,25 @@ Perror0_exit(char *cmd) } void -Perror2(char *cmd, char *str) +Perror2(const char *cmd, const char *str) { - int save_errno; + int error = errno; - save_errno = errno; - (void) fprintf(stderr, "ifconfig: "); - errno = save_errno; - switch (errno) { + (void) fprintf(stderr, "ifconfig: %s: ", cmd); + switch (error) { case ENXIO: - (void) fprintf(stderr, "%s: %s: no such interface\n", - cmd, str); + (void) fprintf(stderr, "%s: no such interface\n", str); break; - case EPERM: - (void) fprintf(stderr, "%s: %s: permission denied\n", - cmd, str); + (void) fprintf(stderr, "%s: permission denied\n", str); break; - - default: { - char buf[BUFSIZ]; - - (void) snprintf(buf, sizeof (buf), "%s: %s", cmd, str); - perror(buf); - } + case EEXIST: + (void) fprintf(stderr, "%s: already exists\n", str); + break; + default: + errno = error; + perror(str); } } @@ -4211,7 +4150,7 @@ Perror2(char *cmd, char *str) * Print out error message (Perror2()) and exit */ void -Perror2_exit(char *cmd, char *str) +Perror2_exit(const char *cmd, const char *str) { Perror2(cmd, str); exit(1); diff --git a/usr/src/cmd/cmd-inet/usr.sbin/ifconfig/ifconfig.h b/usr/src/cmd/cmd-inet/usr.sbin/ifconfig/ifconfig.h index 49af9e8f0a..0ac600001f 100644 --- a/usr/src/cmd/cmd-inet/usr.sbin/ifconfig/ifconfig.h +++ b/usr/src/cmd/cmd-inet/usr.sbin/ifconfig/ifconfig.h @@ -1,5 +1,5 @@ /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* @@ -30,10 +30,10 @@ extern int getnetmaskbyaddr(struct in_addr, struct in_addr *); extern int debug; -extern void Perror0(char *); -extern void Perror0_exit(char *); -extern void Perror2(char *, char *); -extern void Perror2_exit(char *, char *); +extern void Perror0(const char *); +extern void Perror0_exit(const char *); +extern void Perror2(const char *, const char *); +extern void Perror2_exit(const char *, const char *); extern void Perrdlpi(const char *, const char *, int); extern void Perrdlpi_exit(const char *, const char *, int); |